Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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