Rev 593 | Rev 2288 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
465 | serge | 1 | |
593 | mikedld | 2 | |
3 | |||
4 | |||
168 | serge | 5 | |
6 | |||
7 | { common |
||
8 | if ~ arg eq |
||
9 | reverse |
||
10 | pushd arg |
||
11 | common |
||
12 | end if |
||
13 | call proc } |
||
14 | |||
15 | |||
16 | { common |
||
17 | if ~ arg eq |
||
18 | reverse |
||
19 | pushd arg |
||
20 | common |
||
21 | end if |
||
22 | call [proc] } |
||
23 | |||
24 | |||
25 | { common |
||
26 | size@ccall = 0 |
||
27 | if ~ arg eq |
||
28 | reverse |
||
29 | pushd arg |
||
30 | size@ccall = size@ccall+4 |
||
31 | common |
||
32 | end if |
||
33 | call proc |
||
34 | if size@ccall |
||
35 | add esp,size@ccall |
||
36 | end if } |
||
37 | |||
38 | |||
39 | { common |
||
40 | size@ccall = 0 |
||
41 | if ~ arg eq |
||
42 | reverse |
||
43 | pushd arg |
||
44 | size@ccall = size@ccall+4 |
||
45 | common |
||
46 | end if |
||
47 | call [proc] |
||
48 | if size@ccall |
||
49 | add esp,size@ccall |
||
50 | end if } |
||
51 | |||
52 | |||
53 | { common |
||
54 | match name params, args> |
||
55 | \{ define@proc name, |
||
56 | |||
57 | |||
58 | |||
59 | |||
60 | { if parmbytes | localbytes |
||
61 | push ebp |
||
62 | mov ebp,esp |
||
63 | if localbytes |
||
64 | sub esp,localbytes |
||
65 | end if |
||
66 | end if |
||
67 | irps reg, reglist \{ push reg \} } |
||
68 | |||
69 | |||
70 | |||
71 | |||
72 | { irps reg, reglist \{ reverse pop reg \} |
||
73 | if parmbytes | localbytes |
||
74 | leave |
||
75 | end if |
||
76 | if (flag and 10000b) | (parmbytes=0) |
||
213 | diamond | 77 | retn |
168 | serge | 78 | else |
79 | retn parmbytes |
||
80 | end if } |
||
81 | |||
82 | |||
83 | { local params,flag,regs,parmbytes,localbytes,current |
||
84 | if used name |
||
85 | name: |
||
86 | match =stdcall args, statement \{ params equ args |
||
87 | flag = 11b \} |
||
88 | match =stdcall, statement \{ params equ |
||
89 | flag = 11b \} |
||
90 | match =c args, statement \{ params equ args |
||
91 | flag = 10001b \} |
||
92 | match =c, statement \{ params equ |
||
93 | flag = 10001b \} |
||
94 | match =params, params \{ params equ statement |
||
95 | flag = 0 \} |
||
96 | virtual at ebp+8 |
||
97 | match =uses reglist=,args, params \{ regs equ reglist |
||
98 | params equ args \} |
||
99 | match =regs =uses reglist, regs params \{ regs equ reglist |
||
100 | params equ \} |
||
101 | match =regs, regs \{ regs equ \} |
||
102 | match =,args, params \{ defargs@proc args \} |
||
103 | match =args@proc args, args@proc params \{ defargs@proc args \} |
||
104 | parmbytes = $ - (ebp+8) |
||
105 | end virtual |
||
106 | name # % = parmbytes/4 |
||
107 | all@vars equ |
||
108 | current = 0 |
||
109 | match prologue:reglist, prologue@proc: |
||
110 | macro locals |
||
111 | \{ virtual at ebp-localbytes+current |
||
112 | macro label . \\{ deflocal@proc .,:, \\} |
||
113 | struc db [val] \\{ \common deflocal@proc .,db,val \\} |
||
114 | struc dw [val] \\{ \common deflocal@proc .,dw,val \\} |
||
115 | struc dp [val] \\{ \common deflocal@proc .,dp,val \\} |
||
116 | struc dd [val] \\{ \common deflocal@proc .,dd,val \\} |
||
117 | struc dt [val] \\{ \common deflocal@proc .,dt,val \\} |
||
118 | struc dq [val] \\{ \common deflocal@proc .,dq,val \\} |
||
119 | struc rb cnt \\{ deflocal@proc .,rb cnt, \\} |
||
120 | struc rw cnt \\{ deflocal@proc .,rw cnt, \\} |
||
121 | struc rp cnt \\{ deflocal@proc .,rp cnt, \\} |
||
122 | struc rd cnt \\{ deflocal@proc .,rd cnt, \\} |
||
123 | struc rt cnt \\{ deflocal@proc .,rt cnt, \\} |
||
124 | struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} |
||
125 | macro endl |
||
126 | \{ purge label |
||
127 | restruc db,dw,dp,dd,dt,dq |
||
128 | restruc rb,rw,rp,rd,rt,rq |
||
129 | restruc byte,word,dword,pword,tword,qword |
||
130 | current = $-(ebp-localbytes) |
||
131 | end virtual \} |
||
132 | macro ret operand |
||
133 | \{ match any, operand \\{ retn operand \\} |
||
134 | match , operand \\{ match epilogue:reglist, epilogue@proc: |
||
135 | \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} |
||
136 | macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 |
||
137 | end if \} } |
||
138 | |||
139 | |||
140 | { common |
||
141 | if ~ arg eq |
||
142 | forward |
||
143 | local ..arg,current@arg |
||
144 | match argname:type, arg |
||
145 | \{ current@arg equ argname |
||
146 | label ..arg type |
||
147 | argname equ ..arg |
||
148 | if dqword eq type |
||
149 | dd ?,?,?,? |
||
150 | else if tbyte eq type |
||
151 | dd ?,?,? |
||
152 | else if qword eq type | pword eq type |
||
153 | dd ?,? |
||
154 | else |
||
155 | dd ? |
||
156 | end if \} |
||
157 | match =current@arg,current@arg |
||
158 | \{ current@arg equ arg |
||
159 | arg equ ..arg |
||
160 | ..arg dd ? \} |
||
161 | common |
||
162 | args@proc equ current@arg |
||
163 | forward |
||
164 | restore current@arg |
||
165 | common |
||
166 | end if } |
||
167 | |||
168 | |||
169 | { common |
||
170 | match vars, all@vars \{ all@vars equ all@vars, \} |
||
171 | all@vars equ all@vars name |
||
172 | forward |
||
173 | local ..var,..tmp |
||
174 | ..var def val |
||
175 | match =?, val \{ ..tmp equ \} |
||
176 | match any =dup (=?), val \{ ..tmp equ \} |
||
177 | match tmp : value, ..tmp : val |
||
178 | \{ tmp: end virtual |
||
179 | initlocal@proc ..var,def value |
||
180 | virtual at tmp\} |
||
181 | common |
||
182 | match first rest, ..var, \{ name equ first \} } |
||
183 | |||
184 | |||
185 | { virtual at name |
||
186 | def |
||
187 | size@initlocal = $ - name |
||
188 | end virtual |
||
189 | position@initlocal = 0 |
||
190 | while size@initlocal > position@initlocal |
||
191 | virtual at name |
||
192 | def |
||
193 | if size@initlocal - position@initlocal < 2 |
||
194 | current@initlocal = 1 |
||
195 | load byte@initlocal byte from name+position@initlocal |
||
196 | else if size@initlocal - position@initlocal < 4 |
||
197 | current@initlocal = 2 |
||
198 | load word@initlocal word from name+position@initlocal |
||
199 | else |
||
200 | current@initlocal = 4 |
||
201 | load dword@initlocal dword from name+position@initlocal |
||
202 | end if |
||
203 | end virtual |
||
204 | if current@initlocal = 1 |
||
205 | mov byte [name+position@initlocal],byte@initlocal |
||
206 | else if current@initlocal = 2 |
||
207 | mov word [name+position@initlocal],word@initlocal |
||
208 | else |
||
209 | mov dword [name+position@initlocal],dword@initlocal |
||
210 | end if |
||
211 | position@initlocal = position@initlocal + current@initlocal |
||
212 | end while } |
||
213 | |||
214 | |||
215 | { purge ret,locals,endl |
||
216 | finish@proc |
||
217 | purge finish@proc |
||
218 | restore regs@proc |
||
219 | match all,args@proc \{ restore all \} |
||
220 | restore args@proc |
||
221 | match all,all@vars \{ restore all \} } |
||
222 | |||
223 | |||
224 | { common |
||
225 | locals |
||
226 | forward done@local equ |
||
227 | match varname[count]:vartype, var |
||
228 | \{ match =BYTE, vartype \\{ varname rb count |
||
229 | restore done@local \\} |
||
230 | match =WORD, vartype \\{ varname rw count |
||
231 | restore done@local \\} |
||
232 | match =DWORD, vartype \\{ varname rd count |
||
233 | restore done@local \\} |
||
234 | match =PWORD, vartype \\{ varname rp count |
||
235 | restore done@local \\} |
||
236 | match =QWORD, vartype \\{ varname rq count |
||
237 | restore done@local \\} |
||
238 | match =TBYTE, vartype \\{ varname rt count |
||
239 | restore done@local \\} |
||
240 | match =DQWORD, vartype \\{ label varname dqword |
||
241 | rq count+count |
||
242 | restore done@local \\} |
||
243 | match , done@local \\{ virtual |
||
244 | varname vartype |
||
245 | end virtual |
||
246 | rb count*sizeof.\#vartype |
||
247 | restore done@local \\} \} |
||
248 | match :varname:vartype, done@local:var |
||
249 | \{ match =BYTE, vartype \\{ varname db ? |
||
250 | restore done@local \\} |
||
251 | match =WORD, vartype \\{ varname dw ? |
||
252 | restore done@local \\} |
||
253 | match =DWORD, vartype \\{ varname dd ? |
||
254 | restore done@local \\} |
||
255 | match =PWORD, vartype \\{ varname dp ? |
||
256 | restore done@local \\} |
||
257 | match =QWORD, vartype \\{ varname dq ? |
||
258 | restore done@local \\} |
||
259 | match =TBYTE, vartype \\{ varname dt ? |
||
260 | restore done@local \\} |
||
261 | match =DQWORD, vartype \\{ label varname dqword |
||
262 | dq ?,? |
||
263 | restore done@local \\} |
||
264 | match , done@local \\{ varname vartype |
||
265 | restore done@local \\} \} |
||
266 | match ,done@local |
||
267 | \{ var |
||
268 | restore done@local \} |
||
269 | common |
||
270 | endl }>> |
||
271 |