2 if (cpu=="i586") cpu="i386";
6 print "Unsupported cpu: "cpu;
9 print "# Purify V0.2" > out;
22 /^[ \t]call ([mc]alloc|free|realloc|f?read|mem(move|mem|set)|str(n?cpy|dup|cat)|fgets|getcwd|[lf]?stat|readdir)$/ {
24 print "\t\tcall Purify_"$2 >> out; next;
28 print "\t\tpushl $4" >> out
29 print "\t\tpushl %esp" >> out;
30 print "\t\tcall _Purify_Push" >> out;
31 print "\t\taddl $8,%esp" >> out;
36 print "\t\tpushl $4" >> out
37 print "\t\tpushl %esp" >> out;
38 print "\t\tcall _Purify_Pop" >> out;
39 print "\t\taddl $8,%esp" >> out;
42 /^[ \t]*subl.*,%esp$/ {
45 print "\t\tpushl "a[1] >> out
46 print "\t\tpushl %esp" >> out;
47 print "\t\tcall _Purify_Alloca" >> out;
48 print "\t\taddl $8,%esp" >> out;
51 /^[ \t]*movl.*,%esp$/ {
54 print "\t\tpushl "a[1] >> out
55 print "\t\tpushl %esp" >> out;
56 print "\t\tcall _Purify_MoveSP" >> out;
57 print "\t\taddl $8,%esp" >> out;
60 /^[ \t]*((lea|jmp)|.*%st[(][0-9]+[)])/ { print >> out; next }
61 /^[ \t]*[a-z]+ .*([^(]+)?[(][^)]+[)]/ {
63 #print $0 " NR="NR" line="line
65 if (match($2,/^([^(,]+)?[(][^)]+[)]/))
67 arg1=substr($2,RSTART,RLENGTH);
73 arg1=substr($2,RSTART,RLENGTH);
77 arg2=substr($2,RSTART+RLENGTH+1);
78 check2=match(arg2,/[(]/);
80 #print "arg1="arg1" c1="check1" arg2="arg2" c2="check2
84 print "Warning: unsupported double indirect access "NR
91 if (match($1,/^movs/))
93 else if (match($1,/^or/))
104 else if (match ($1,/^(inc|dec)/))
116 if (check1 || check2)
118 print "\t\tpushl %eax" >> out
120 print "\t\tpushl $4" >> out
121 else if (size == "w")
122 print "\t\tpushl $2" >> out
124 print "\t\tpushl $1" >> out
125 print "\t\tleal "arg",%eax" >> out
126 print "\t\tpushl %eax" >> out
128 print "\t\tcall _Purify_CheckRead" >> out;
130 print "\t\tcall _Purify_CheckWrite" >> out;
131 print "\t\taddl $8,%esp" >> out;
132 print "\t\tpopl %eax" >> out
143 if (funcname == "main")
145 print "\t\tcall _Purify_Init" >> out;
146 print "\t\tpushl $10240" >> out;
147 print "\t\tpushl %esp" >> out;
148 print "\t\tcall _Purify_InitStack" >> out;
149 print "\t\taddl $8,%esp" >> out;
161 print "\t\tcall _Purify_LeaveFunction" >> out
164 print "\t\tcall _Purify_Exit" >> out;
170 if (section==".text")
172 print ".section\t.rodata" >> out;
173 print ".L"funcname":" >> out;
174 print "\t\t.string \""funcname"\"" >> out;
175 restore_section(".rodata");
181 funcname=substr($2,RSTART,RLENGTH);
189 print "\t\tpushl %ebp" >> out;
190 print "\t\tpushl $"line >> out;
191 print "\t\tpushl $.L"funcname >> out;
192 print "\t\tpushl $.Lfilename" >> out;
193 print "\t\tcall _Purify_EnterFunction" >> out;
194 print "\t\taddl $16,%esp" >> out;
199 print "\t\tmovl $"line",Purify_Lineno" >> out;
202 /^.stabs "\/[^"]+",100/ {
204 path=substr($2,RSTART+1,RLENGTH-2);
206 /^.stabs "[^\/][^"]+",100/ {
208 filename=substr($2,RSTART+1,RLENGTH-2);
210 print ".section\t.rodata" >> out;
211 print ".Lfilename:" >> out;
212 print "\t\t.string \""path filename"\"" >> out;
213 restore_section(".rodata");
216 /^[ \t]*\./ { print >> out; next }
217 /^[ \t]*.*[(][^)]+[)]/ {
218 print "Warning: Unsupported memory access found in line "line" ("NR")"
224 function restore_section(sect) {
227 if (section==".text" || section==".data")
228 print section >> out;
229 else if (section!="")
230 print ".section "section >> out;