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