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