Subversion Repositories Kolibri OS

Rev

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