Rev 7294 | Rev 8969 | 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 | |||
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 | { local loc |
||
7294 | dunkaist | 61 | loc = (localbytes+3) and (not 3) |
62 | parmbase@proc equ ebp+8 |
||
63 | localbase@proc equ ebp-loc |
||
64 | if parmbytes | localbytes |
||
65 | push ebp |
||
2288 | clevermous | 66 | mov ebp, esp |
67 | if localbytes |
||
68 | sub esp, loc |
||
7294 | dunkaist | 69 | end if |
2288 | clevermous | 70 | end if |
71 | irps reg, reglist \{ push reg \} } |
||
72 | |||
73 | |||
74 | |||
75 | |||
76 | { irps reg, reglist \{ reverse pop reg \} |
||
77 | if parmbytes | localbytes |
||
78 | leave |
||
79 | end if |
||
80 | if flag and 10000b |
||
7294 | dunkaist | 81 | retn |
2288 | clevermous | 82 | else |
83 | retn parmbytes |
||
84 | end if } |
||
85 | |||
86 | |||
7294 | dunkaist | 87 | |
88 | |||
2288 | clevermous | 89 | { local params,flag,regs,parmbytes,localbytes,current |
90 | if used name |
||
91 | name: |
||
92 | match =stdcall args, statement \{ params equ args |
||
93 | flag = 11b \} |
||
94 | match =stdcall, statement \{ params equ |
||
95 | flag = 11b \} |
||
96 | match =c args, statement \{ params equ args |
||
97 | flag = 10001b \} |
||
98 | match =c, statement \{ params equ |
||
99 | flag = 10001b \} |
||
100 | match =params, params \{ params equ statement |
||
101 | flag = 0 \} |
||
102 | match =uses reglist=,args, params \{ regs equ reglist |
||
103 | params equ args \} |
||
104 | match =regs =uses reglist, regs params \{ regs equ reglist |
||
105 | params equ \} |
||
106 | match =regs, regs \{ regs equ \} |
||
107 | match prologue:reglist, prologue@proc: |
||
7294 | dunkaist | 108 | virtual at parmbase@proc |
109 | match =,args, params \{ defargs@proc args \} |
||
2288 | clevermous | 110 | match =args@proc args, args@proc params \{ defargs@proc args \} |
111 | parmbytes = $-(parmbase@proc) |
||
7294 | dunkaist | 112 | end virtual |
2288 | clevermous | 113 | name # % = parmbytes/4 |
114 | all@vars equ |
||
115 | current = 0 |
||
116 | macro locals |
||
117 | \{ virtual at localbase@proc+current |
||
7294 | dunkaist | 118 | macro label def \\{ match . type,def> \\\{ deflocal@proc .,label, |
119 | struc db [val] \\{ \common deflocal@proc .,db,val \\} |
||
2288 | clevermous | 120 | struc du [val] \\{ \common deflocal@proc .,du,val \\} |
7294 | dunkaist | 121 | struc dw [val] \\{ \common deflocal@proc .,dw,val \\} |
2288 | clevermous | 122 | struc dp [val] \\{ \common deflocal@proc .,dp,val \\} |
123 | struc dd [val] \\{ \common deflocal@proc .,dd,val \\} |
||
124 | struc dt [val] \\{ \common deflocal@proc .,dt,val \\} |
||
125 | struc dq [val] \\{ \common deflocal@proc .,dq,val \\} |
||
126 | struc rb cnt \\{ deflocal@proc .,rb cnt, \\} |
||
127 | struc rw cnt \\{ deflocal@proc .,rw cnt, \\} |
||
128 | struc rp cnt \\{ deflocal@proc .,rp cnt, \\} |
||
129 | struc rd cnt \\{ deflocal@proc .,rd cnt, \\} |
||
130 | struc rt cnt \\{ deflocal@proc .,rt cnt, \\} |
||
131 | struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} |
||
132 | macro endl |
||
133 | \{ purge label |
||
134 | restruc db,du,dw,dp,dd,dt,dq |
||
7294 | dunkaist | 135 | restruc rb,rw,rp,rd,rt,rq |
2288 | clevermous | 136 | current = $-(localbase@proc) |
7294 | dunkaist | 137 | end virtual \} |
2288 | clevermous | 138 | macro ret operand |
139 | \{ match any, operand \\{ retn operand \\} |
||
140 | match , operand \\{ match epilogue:reglist, epilogue@proc: |
||
7294 | dunkaist | 141 | macro finish@proc |
142 | \{ localbytes = current |
||
143 | match close:reglist, close@proc: |
||
144 | end if \} } |
||
145 | |||
2288 | clevermous | 146 | |
147 | { common |
||
148 | if ~ arg eq |
||
149 | forward |
||
150 | local ..arg,current@arg |
||
151 | match argname:type, arg |
||
152 | \{ current@arg equ argname |
||
153 | label ..arg type |
||
154 | argname equ ..arg |
||
155 | if dqword eq type |
||
156 | dd ?,?,?,? |
||
157 | else if tbyte eq type |
||
158 | dd ?,?,? |
||
159 | else if qword eq type | pword eq type |
||
160 | dd ?,? |
||
161 | else |
||
162 | dd ? |
||
163 | end if \} |
||
164 | match =current@arg,current@arg |
||
165 | \{ current@arg equ arg |
||
166 | arg equ ..arg |
||
167 | ..arg dd ? \} |
||
168 | common |
||
169 | args@proc equ current@arg |
||
170 | forward |
||
171 | restore current@arg |
||
172 | common |
||
173 | end if } |
||
174 | |||
175 | |||
7294 | dunkaist | 176 | |
177 | |||
2288 | clevermous | 178 | { common |
179 | match vars, all@vars \{ all@vars equ all@vars, \} |
||
180 | all@vars equ all@vars name |
||
181 | forward |
||
182 | local ..var,..tmp |
||
183 | ..var def val |
||
184 | match =?, val \{ ..tmp equ \} |
||
185 | match any =?, val \{ ..tmp equ \} |
||
7294 | dunkaist | 186 | match any (=?), val \{ ..tmp equ \} |
187 | match =label, def \{ ..tmp equ \} |
||
188 | match tmp : value, ..tmp : val |
||
2288 | clevermous | 189 | \{ tmp: end virtual |
190 | initlocal@proc ..var,def value |
||
191 | virtual at tmp\} |
||
192 | common |
||
193 | match first rest, ..var, \{ name equ first \} } |
||
194 | |||
195 | |||
7294 | dunkaist | 196 | |
197 | |||
2288 | clevermous | 198 | { virtual at name |
199 | def |
||
200 | size@initlocal = $ - name |
||
201 | end virtual |
||
202 | position@initlocal = 0 |
||
203 | while size@initlocal > position@initlocal |
||
204 | virtual at name |
||
205 | def |
||
206 | if size@initlocal - position@initlocal < 2 |
||
207 | current@initlocal = 1 |
||
208 | load byte@initlocal byte from name+position@initlocal |
||
209 | else if size@initlocal - position@initlocal < 4 |
||
210 | current@initlocal = 2 |
||
211 | load word@initlocal word from name+position@initlocal |
||
212 | else |
||
213 | current@initlocal = 4 |
||
214 | load dword@initlocal dword from name+position@initlocal |
||
215 | end if |
||
216 | end virtual |
||
217 | if current@initlocal = 1 |
||
218 | mov byte [name+position@initlocal], byte@initlocal |
||
219 | else if current@initlocal = 2 |
||
220 | mov word [name+position@initlocal], word@initlocal |
||
221 | else |
||
222 | mov dword [name+position@initlocal], dword@initlocal |
||
223 | end if |
||
224 | position@initlocal = position@initlocal + current@initlocal |
||
225 | end while } |
||
226 | |||
227 | |||
228 | { purge ret,locals,endl |
||
229 | finish@proc |
||
230 | purge finish@proc |
||
231 | restore regs@proc |
||
232 | match all,args@proc \{ restore all \} |
||
233 | restore args@proc |
||
234 | match all,all@vars \{ restore all \} } |
||
235 | |||
236 | |||
237 | { common |
||
238 | locals |
||
239 | forward done@local equ |
||
240 | match varname[count]:vartype, var |
||
241 | \{ match =BYTE, vartype \\{ varname rb count |
||
242 | restore done@local \\} |
||
243 | match =WORD, vartype \\{ varname rw count |
||
244 | restore done@local \\} |
||
245 | match =DWORD, vartype \\{ varname rd count |
||
246 | restore done@local \\} |
||
247 | match =PWORD, vartype \\{ varname rp count |
||
248 | restore done@local \\} |
||
249 | match =QWORD, vartype \\{ varname rq count |
||
250 | restore done@local \\} |
||
251 | match =TBYTE, vartype \\{ varname rt count |
||
252 | restore done@local \\} |
||
253 | match =DQWORD, vartype \\{ label varname dqword |
||
254 | rq count+count |
||
255 | restore done@local \\} |
||
256 | match , done@local \\{ virtual |
||
257 | varname vartype |
||
258 | end virtual |
||
259 | rb count*sizeof.\#vartype |
||
260 | restore done@local \\} \} |
||
261 | match :varname:vartype, done@local:var |
||
262 | \{ match =BYTE, vartype \\{ varname db ? |
||
263 | restore done@local \\} |
||
264 | match =WORD, vartype \\{ varname dw ? |
||
265 | restore done@local \\} |
||
266 | match =DWORD, vartype \\{ varname dd ? |
||
267 | restore done@local \\} |
||
268 | match =PWORD, vartype \\{ varname dp ? |
||
269 | restore done@local \\} |
||
270 | match =QWORD, vartype \\{ varname dq ? |
||
271 | restore done@local \\} |
||
272 | match =TBYTE, vartype \\{ varname dt ? |
||
273 | restore done@local \\} |
||
274 | match =DQWORD, vartype \\{ label varname dqword |
||
275 | dq ?,? |
||
276 | restore done@local \\} |
||
277 | match , done@local \\{ varname vartype |
||
278 | restore done@local \\} \} |
||
279 | match ,done@local |
||
280 | \{ var |
||
281 | restore done@local \} |
||
282 | common |
||
283 | endl }>> |
||
284 |