-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmk_vocabulary
executable file
·127 lines (86 loc) · 1.95 KB
/
mk_vocabulary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#! /usr/bin/perl
use strict;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 1;
sub print_list;
# vocabulary definitions
my $prim = $ARGV[0];
# type definitions
my $type = $ARGV[1];
# generated C header file
my $dst = $ARGV[2];
my $vocab;
my $types;
open my $f, $prim or die "$prim: $!\n";
while(<$f>) {
next if /^\s*(#|$)/;
my @i = split /\s+/;
push @$vocab, { str => $i[0], name => $i[1] ? $i[1] : $i[0] };
}
close $f;
open my $f, $type or die "$type: $!\n";
while(<$f>) {
next if /^\s*(#|$)/;
my @i = split /\s+/;
push @$types, { str => $i[0], name => $i[1] ? $i[1] : $i[0] };
}
close $f;
open my $f, ">", $dst or die "$dst: $!\n";
print $f <<"----"
#define GFXBOOT_MAGIC 0x60ad7a42a91251L
#ifdef WITH_PRIM_NAMES
const char *prim_names[] = {
----
;
my $list;
push @$list, "\"$_->{str}\"" for @$vocab;
print_list $f, $list, 8;
print $f "\n};\n#endif\n\n";
print $f "enum {\n";
my $list;
push @$list, "prim_idx_$_->{name}" for @$vocab;
print_list $f, $list, 4;
print $f "\n};\n\n";
print $f "#ifdef WITH_PRIM_HEADERS\n";
my $list;
push @$list, "gfx_prim_$_->{name}" for @$vocab;
print $f "static void $_(void);\n" for @$list;
print $f "\nstatic void (*gfx_prim_list[])(void) = {\n";
print_list $f, $list, 4;
print $f "\n};\n#endif\n\n";
print $f "#ifdef WITH_TYPE_NAMES\nconst char *type_name[] = {\n";
my $list;
push @$list, "\"$_->{str}\"" for @$types;
print_list $f, $list, 8;
print $f "\n};\n#endif\n\n";
print $f <<"----"
#define TYPE_EXPECTS_DATA(a) ((a) >= t_comment)
typedef enum {
----
;
my $list;
push @$list, "t_$_->{name}" for @$types;
print_list $f, $list, 4;
print $f "\n} type_t;\n";
close $f;
sub print_list
{
my $f = $_[0];
my $list = $_[1];
my $cols = $_[2];
my $cnt = 0;
for (@$list) {
print $f "," if $cnt;
if($cnt % $cols) {
print $f " ";
}
else {
print $f "\n" if $cnt;
print $f " ";
}
print $f "$_";
$cnt++;
}
}