-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgnuify
executable file
·183 lines (157 loc) · 4.44 KB
/
gnuify
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/gawk -f
#
# Rewrite the interpreter source in $1 to use GNU C extensions, writing the
# modified file to stdout.
#
# Author: [email protected]
#
# Last edited: 2006-10-18 10:14:33 by piumarta on emilia.local
# Copyright (C) 1996-2004 by Ian Piumarta and other authors/contributors
# listed elsewhere in this file.
# All rights reserved.
#
# This file is part of Unix Squeak.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
BEGIN {
print "/* This file has been post-processed for GNU C */\n\n";
# print "copying first section of file" > "/dev/stderr";
stage= 0;
}
/#include "sq.h"/ {
print "#include \"sqGnu.h\"\n";
next;
}
# An inlining comment means the interpreter was not inlined
/inline\: true/ {
# print NR, $0 > "/dev/stderr";
# print "" > "/dev/stderr";
# print "*** interpreter was not inlined: bailing out! ***" > "/dev/stderr";
# print "" > "/dev/stderr";
stage= -1;
}
(stage == 0) && /^int interpret\(void\) \{/ {
# print "interpret: adding static register assignments" > "/dev/stderr";
stage= 1;
print;
next;
}
(stage == 0) && /^sqInt interpret\(void\) \{/ {
# print "interpret: adding static register assignments" > "/dev/stderr";
stage= 1;
print;
next;
}
(stage == 1) && /^ char\* localIP;/ {
print " register char* localIP IP_REG;";
next;
}
(stage == 1) && /^register struct foo \* foo = &fum;/ {
print " register struct foo * foo GP_REG= &fum;";
next;
}
(stage == 1) && /^ char\* localSP;/ {
print " register char* localSP SP_REG;";
next;
}
(stage == 1) && /^ int currentBytecode;/ {
print " register int currentBytecode CB_REG;";
next;
}
(stage == 1) && /^ sqInt currentBytecode;/ {
print " register int currentBytecode CB_REG;";
next;
}
(stage == 1) && /^$/ {
# print "interpret: adding bytecode dispatch table" > "/dev/stderr";
print " JUMP_TABLE;\n";
# print "interpret: rewriting case labels and outer breaks" > "/dev/stderr";
stage= 2;
FS=" ";
# FS="[ :]+";
next;
}
(stage == 2) && /^ case / {
print " CASE(" (($NF) + 0) ")";
# print " CASE(" $3 ")";
next;
}
(stage == 2) && /^ break;/ {
print " BREAK;";
next;
}
(stage == 2) && /^\}/ {
stage= -1;
print;
next;
}
(stage == 3) && /^int primitiveResponse\(/ {
print;
# print "primitiveResponse: adding primitive dispatch table" > "/dev/stderr";
print " PRIM_TABLE;\n";
# print "primitiveResponse: rewriting case labels" > "/dev/stderr";
stage= 4;
FS=" ";
# FS="[ :]+";
next;
}
(stage == 3) && /^sqInt primitiveResponse\(/ {
print;
# print "primitiveResponse: adding primitive dispatch table" > "/dev/stderr";
print " PRIM_TABLE;\n";
# print "primitiveResponse: rewriting case labels" > "/dev/stderr";
stage= 4;
FS=" ";
# FS="[ :]+";
next;
}
(stage == 4) && /^ switch \(primitiveIndex\) \{/ {
# print "primitiveResponse: adding primitive dispatch" > "/dev/stderr";
print " PRIM_DISPATCH;";
print;
next;
}
(stage == 4) && /^ switch \(foo->primitiveIndex\) \{/ {
# print "primitiveResponse: adding primitive dispatch" > "/dev/stderr";
print " PRIM_DISPATCH;";
print;
next;
}
(stage == 4) && /^ case / {
print " CASE(" (($NF) + 0) ")";
# print " CASE(" $3 ")";
next;
}
(stage == 4) && /^\}/ {
# print "copying last section of file" > "/dev/stderr";
stage= -1;
FS=" ";
print;
next;
}
# default
{
print;
next;
}
END {
if (stage != -1) {
print "#error GNUIFICATION FAILED (", stage, ")"
}
}