-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathresgen.pl
157 lines (124 loc) · 2.18 KB
/
resgen.pl
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/perl
#
# Generate static initialisers for a resident image
#
# Consume each line of input
#
@functions = ();
while(<STDIN>) {
# Ignore comments
#
next if(/^#/);
# ='<module_name>'
#
if(/^=\s*(\w\w*)/) {
$base = $1;
next;
}
# <class>:<method>
# <class>::<method>
#
if(/^\s*(\w\w*)::?(\w\w*)/) {
push(@functions,"_M_$1_$2");
next;
}
# <function_name>
#
if(/\w\w*/) {
push(@functions,$&);
next;
}
}
@functions = sort(@functions);
# Print out list of functions
#
#$n = 0;
#foreach $fn (@functions) {
# print "Function $n $fn\n";
# $n++;
#}
open(STDOUT,">$ARGV[0]");
# Print table of names
#
print <<END;
/*
* Table of exported names
*/
static char * namePointers_$base\[\] = {
END
foreach $fn (@functions) {
print "\t\"_$fn\",\n";
}
print <<END;
};
END
# Print table of ordinals
#
print <<END;
/*
* Table of ordinals
*/
static br_uint_16 nameOrdinals_$base\[\] = {
END
$n = 0;
foreach $fn (@functions) {
print "\t$n,\n";
$n++;
}
print <<END;
};
END
# Print table of entry points
#
print <<END;
/*
* Table of ordinals
*/
static void * functionPointers_$base\[\] = {
END
$n = 0;
foreach $fn (@functions) {
printf("\t%-64s, /* %d */\n", $fn ,$n);
$n++;
}
print <<END;
};
static br_image Image_$base = {
{0},
"$base", /* Identifier */
BR_IMG_RESIDENT, /* Image type */
0, /* Reference count */
1, /* Ordinal base */
BR_ASIZE(functionPointers_$base), /* Number of functions */
functionPointers_$base, /* Table of functions */
BR_ASIZE(namePointers_$base), /* Number of names */
namePointers_$base, /* Table of names */
nameOrdinals_$base, /* Table of name ordinals */
0, /* Number of imports */
NULL, /* Table of imports */
0, /* Number of sections */
NULL, /* Table of sections */
NULL, /* Type pointer */
};
END
close(STDOUT);
# Generate librarian scripts for import libraries
#
open(STDOUT,">$ARGV[1]");
# Microsoft LIB
#
if($ARGV[2] eq "m") {
print "LIBRARY $base\n";
print "EXPORTS\n";
foreach $fn (@functions) {
print "${fn}\n";
}
}
# Watcom WLIB
#
if($ARGV[2] eq "w") {
foreach $fn (@functions) {
print "++_${fn}.$base\n";
}
}
close(STDOUT);