Subversion Repositories Kolibri OS

Rev

Rev 1635 | Rev 2465 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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