FreeBASIC  0.91.0
ir.bi
Go to the documentation of this file.
1 #ifndef __IR_BI__
2 #define __IR_BI__
3 
4 const IR_INITADDRNODES = 2048
6 
7 const IR_MAXDIST = 2147483647
8 
9 '' when changing, update vregDump():vregtypes()
10 enum IRVREGTYPE_ENUM
17 end enum
18 
19 '' sections
20 enum IR_SECTION
29 end enum
30 
31 enum IR_REGFAMILY
34 end enum
35 
36 enum IR_OPTIONVALUE
38 end enum
39 
40 
41 ''
42 type IRVREG_ as IRVREG
43 type IRTAC_ as IRTAC
44 
45 type IRTACVREG
46  vreg as IRVREG_ ptr
47  parent as IRVREG_ ptr '' pointer to parent if idx or aux
48  next as IRTACVREG ptr '' next in tac (-> vr, v1 or v2)
49 end type
50 
51 type IRTACVREG_GRP
52  reg as IRTACVREG
53  idx as IRTACVREG '' index
54  aux as IRTACVREG '' auxiliary
55 end type
56 
57 type IRTAC
58  pos as integer
59 
60  op as AST_OP '' opcode
61 
62  vr as IRTACVREG_GRP '' result
63  v1 as IRTACVREG_GRP '' operand 1
64  v2 as IRTACVREG_GRP '' operand 2
65 
66  ex1 as FBSYMBOL ptr '' extra field, used by call/jmp
67  ex2 as integer '' /
68 end type
69 
70 type IRVREG
71  typ as IRVREGTYPE_ENUM '' VAR, IMM, IDX, etc
72 
73  dtype as FB_DATATYPE '' CHAR, INTEGER, ...
74  subtype as FBSYMBOL ptr
75 
76  reg as integer '' reg
78  vector as integer
79 
80  value as FBVALUE '' imm value (hi-word of longint's at vaux->value)
81 
82  sym as FBSYMBOL ptr '' symbol
83  ofs as longint '' +offset
84  mult as integer '' multipler, only valid for IDX and PTR under ir-tac
85 
86  vidx as IRVREG ptr '' index vreg
87  vaux as IRVREG ptr '' aux vreg (used with longint's)
88 
89  tacvhead as IRTACVREG ptr '' back-link to tac table
90  tacvtail as IRTACVREG ptr '' /
91  taclast as IRTAC ptr '' /
92 end type
93 
94 '' if changed, update the _vtbl symbols at ir-*.bas::*_ctor
95 type IR_VTBL
96  init as sub( )
97  end as sub( )
98 
99  emitBegin as function _
100  ( _
101  ) as integer
102 
103  emitEnd as sub _
104  ( _
105  byval tottime as double _
106  )
107 
108  getOptionValue as function _
109  ( _
110  byval opt as IR_OPTIONVALUE _
111  ) as integer
112 
113  procBegin as sub _
114  ( _
115  byval proc as FBSYMBOL ptr _
116  )
117 
118  procEnd as sub _
119  ( _
120  byval proc as FBSYMBOL ptr _
121  )
122 
123  procAllocArg as sub _
124  ( _
125  byval proc as FBSYMBOL ptr, _
126  byval sym as FBSYMBOL ptr _
127  )
128 
129  procAllocLocal as sub _
130  ( _
131  byval proc as FBSYMBOL ptr, _
132  byval sym as FBSYMBOL ptr _
133  )
134 
135  procGetFrameRegName as function _
136  ( _
137  ) as const zstring ptr
138 
139  scopeBegin as sub _
140  ( _
141  byval s as FBSYMBOL ptr _
142  )
143 
144  scopeEnd as sub _
145  ( _
146  byval s as FBSYMBOL ptr _
147  )
148 
149  procAllocStaticVars as sub( byval head_sym as FBSYMBOL ptr )
150 
151  emitConvert as sub( byval v1 as IRVREG ptr, byval v2 as IRVREG ptr )
152 
153  emitLabel as sub _
154  ( _
155  byval label as FBSYMBOL ptr _
156  )
157 
158  emitLabelNF as sub _
159  ( _
160  byval l as FBSYMBOL ptr _
161  )
162 
163  emitReturn as sub _
164  ( _
165  byval bytestopop as integer _
166  )
167 
168  emitProcBegin as sub _
169  ( _
170  byval proc as FBSYMBOL ptr, _
171  byval initlabel as FBSYMBOL ptr _
172  )
173 
174  emitProcEnd as sub _
175  ( _
176  byval proc as FBSYMBOL ptr, _
177  byval initlabel as FBSYMBOL ptr, _
178  byval exitlabel as FBSYMBOL ptr _
179  )
180 
181  emitPushArg as sub _
182  ( _
183  byval param as FBSYMBOL ptr, _
184  byval vr as IRVREG ptr, _
185  byval udtlen as longint, _
186  byval level as integer _
187  )
188 
189  emitAsmBegin as sub( )
190  emitAsmText as sub( byval text as zstring ptr )
191  emitAsmSymb as sub( byval sym as FBSYMBOL ptr )
192  emitAsmEnd as sub( )
193 
194  emitComment as sub _
195  ( _
196  byval text as zstring ptr _
197  )
198 
199  emitBop as sub _
200  ( _
201  byval op as integer, _
202  byval v1 as IRVREG ptr, _
203  byval v2 as IRVREG ptr, _
204  byval vr as IRVREG ptr, _
205  byval ex as FBSYMBOL ptr _
206  )
207 
208  emitUop as sub _
209  ( _
210  byval op as integer, _
211  byval v1 as IRVREG ptr, _
212  byval vr as IRVREG ptr _
213  )
214 
215  emitStore as sub( byval v1 as IRVREG ptr, byval v2 as IRVREG ptr )
216 
217  emitSpillRegs as sub _
218  ( _
219  )
220 
221  emitLoad as sub _
222  ( _
223  byval v1 as IRVREG ptr _
224  )
225 
226  emitLoadRes as sub _
227  ( _
228  byval v1 as IRVREG ptr, _
229  byval vr as IRVREG ptr _
230  )
231 
232  emitStack as sub _
233  ( _
234  byval op as integer, _
235  byval v1 as IRVREG ptr _
236  )
237 
238  emitAddr as sub _
239  ( _
240  byval op as integer, _
241  byval v1 as IRVREG ptr, _
242  byval vr as IRVREG ptr _
243  )
244 
245  emitCall as sub _
246  ( _
247  byval proc as FBSYMBOL ptr, _
248  byval bytestopop as integer, _
249  byval vr as IRVREG ptr, _
250  byval level as integer _
251  )
252 
253  emitCallPtr as sub _
254  ( _
255  byval v1 as IRVREG ptr, _
256  byval vr as IRVREG ptr, _
257  byval bytestopop as integer, _
258  byval level as integer _
259  )
260 
261  emitStackAlign as sub _
262  ( _
263  byval bytes as integer _
264  )
265 
266  emitJumpPtr as sub( byval v1 as IRVREG ptr )
267  emitBranch as sub( byval op as integer, byval label as FBSYMBOL ptr )
268 
269  emitJmpTb as sub _
270  ( _
271  byval v1 as IRVREG ptr, _
272  byval tbsym as FBSYMBOL ptr, _
273  byval values as ulongint ptr, _
274  byval labels as FBSYMBOL ptr ptr, _
275  byval labelcount as integer, _
276  byval deflabel as FBSYMBOL ptr, _
277  byval minval as ulongint, _
278  byval maxval as ulongint _
279  )
280 
281  emitMem as sub _
282  ( _
283  byval op as integer, _
284  byval v1 as IRVREG ptr, _
285  byval v2 as IRVREG ptr, _
286  byval bytes as longint _
287  )
288 
289  emitScopeBegin as sub _
290  ( _
291  byval s as FBSYMBOL ptr _
292  )
293 
294  emitScopeEnd as sub _
295  ( _
296  byval s as FBSYMBOL ptr _
297  )
298 
299  emitDECL as sub( byval sym as FBSYMBOL ptr )
300 
301  emitDBG as sub _
302  ( _
303  byval op as integer, _
304  byval proc as FBSYMBOL ptr, _
305  byval ex as integer _
306  )
307 
308  emitVarIniBegin as sub( byval sym as FBSYMBOL ptr )
309  emitVarIniEnd as sub( byval sym as FBSYMBOL ptr )
310  emitVarIniI as sub( byval sym as FBSYMBOL ptr, byval value as longint )
311  emitVarIniF as sub( byval sym as FBSYMBOL ptr, byval value as double )
312  emitVarIniOfs as sub( byval sym as FBSYMBOL ptr, byval ofs as longint )
313 
314  emitVarIniStr as sub _
315  ( _
316  byval totlgt as longint, _
317  byval litstr as zstring ptr, _
318  byval litlgt as longint _
319  )
320 
321  emitVarIniWstr as sub _
322  ( _
323  byval totlgt as longint, _
324  byval litstr as wstring ptr, _
325  byval litlgt as longint _
326  )
327 
328  emitVarIniPad as sub( byval bytes as longint )
329  emitVarIniScopeBegin as sub( )
330  emitVarIniScopeEnd as sub( )
331 
332  emitFbctinfBegin as sub( )
333  emitFbctinfString as sub( byval s as zstring ptr )
334  emitFbctinfEnd as sub( )
335 
336  allocVreg as function _
337  ( _
338  byval dtype as integer, _
339  byval subtype as FBSYMBOL ptr _
340  ) as IRVREG ptr
341 
342  allocVrImm as function _
343  ( _
344  byval dtype as integer, _
345  byval subtype as FBSYMBOL ptr, _
346  byval value as longint _
347  ) as IRVREG ptr
348 
349  allocVrImmF as function _
350  ( _
351  byval dtype as integer, _
352  byval subtype as FBSYMBOL ptr, _
353  byval value as double _
354  ) as IRVREG ptr
355 
356  allocVrVar as function _
357  ( _
358  byval dtype as integer, _
359  byval subtype as FBSYMBOL ptr, _
360  byval symbol as FBSYMBOL ptr, _
361  byval ofs as longint _
362  ) as IRVREG ptr
363 
364  allocVrIdx as function _
365  ( _
366  byval dtype as integer, _
367  byval subtype as FBSYMBOL ptr, _
368  byval symbol as FBSYMBOL ptr, _
369  byval ofs as longint, _
370  byval mult as integer, _
371  byval vidx as IRVREG ptr _
372  ) as IRVREG ptr
373 
374  allocVrPtr as function _
375  ( _
376  byval dtype as integer, _
377  byval subtype as FBSYMBOL ptr, _
378  byval ofs as longint, _
379  byval vidx as IRVREG ptr _
380  ) as IRVREG ptr
381 
382  allocVrOfs as function _
383  ( _
384  byval dtype as integer, _
385  byval subtype as FBSYMBOL ptr, _
386  byval symbol as FBSYMBOL ptr, _
387  byval ofs as longint _
388  ) as IRVREG ptr
389 
390  setVregDataType as sub _
391  ( _
392  byval vreg as IRVREG ptr, _
393  byval dtype as integer, _
394  byval subtype as FBSYMBOL ptr _
395  )
396 
397  getDistance as function _
398  ( _
399  byval vreg as IRVREG ptr _
400  ) as uinteger
401 
402  loadVr as sub _
403  ( _
404  byval reg as integer, _
405  byval vreg as IRVREG ptr, _
406  byval vauxparent as IRVREG ptr _
407  )
408 
409  storeVr as sub _
410  ( _
411  byval vreg as IRVREG ptr, _
412  byval vauxparent as IRVREG ptr _
413  )
414 
415  xchgTOS as sub _
416  ( _
417  byval reg as integer _
418  )
419 end type
420 
421 enum IR_OPT
422  IR_OPT_FPUCONV = &h00000001 '' Should float operands always be converted?
423  IR_OPT_FPUIMMEDIATES = &h00000002 '' Floating-point immediates allowed?
424  IR_OPT_FPUBOPFLAGS = &h00000004 '' Do float BOPs set flags for conditional jumps (x86)?
425  IR_OPT_FPUSELFBOPS = &h00000008 '' Are float self-BOPs available?
426 
427  IR_OPT_CPUBOPFLAGS = &h00000100 '' Integer BOPs set flags for conditional jumps (x86)?
428  IR_OPT_CPUSELFBOPS = &h00000200 '' Integer self-BOPs available?
429  IR_OPT_64BITCPUREGS = &h00000400 '' 64-bit wide registers?
430 
431  IR_OPT_ADDRCISC = &h00010000 '' complex addressing modes (base+idx*disp)
432  IR_OPT_NOINLINEOPS = &h00020000 '' "Complex" math operators unavailable?
433 end enum
434 
435 type IRCTX
436  inited as integer
437  vtbl as IR_VTBL
438  options as IR_OPT
439 end type
440 
441 ''
442 ''
443 ''
444 extern as IR_VTBL irtac_vtbl
445 extern as IR_VTBL irhlc_vtbl
446 extern as IR_VTBL irllvm_vtbl
447 declare sub irInit( )
448 declare sub irEnd( )
449 #if __FB_DEBUG__
450 declare function vregDump( byval v as IRVREG ptr ) as string
451 #endif
452 
453 ''
454 '' macros
455 ''
456 #define irGetOption( op ) ((ir.options and op) <> 0)
457 
458 #define irSetOption( op ) ir.options or= op
459 
460 #define irGetOptionValue( opt ) ir.vtbl.getOptionValue( opt )
461 
462 #define irAllocVreg(dtype, stype) ir.vtbl.allocVreg( dtype, stype )
463 
464 #define irSetVregDataType(v, dtype, stype) ir.vtbl.setVregDataType( v, dtype, stype )
465 
466 #define irAllocVrImm(dtype, stype, value) ir.vtbl.allocVrImm( dtype, stype, value )
467 
468 #define irAllocVrImmF(dtype, stype, value) ir.vtbl.allocVrImmF( dtype, stype, value )
469 
470 #define irAllocVrVar(dtype, stype, sym, ofs) ir.vtbl.allocVrVar( dtype, stype, sym, ofs )
471 
472 #define irAllocVrIdx(dtype, stype, sym, ofs, mult, vidx) ir.vtbl.allocVrIdx( dtype, stype, sym, ofs, mult, vidx )
473 
474 #define irAllocVrPtr(dtype, stype, ofs, vidx) ir.vtbl.allocVrPtr( dtype, stype, ofs, vidx )
475 
476 #define irAllocVrOfs(dtype, stype, sym, ofs) ir.vtbl.allocVrOfs( dtype, stype, sym, ofs )
477 
478 #define irProcBegin(proc) ir.vtbl.procBegin( proc )
479 
480 #define irProcEnd(proc) ir.vtbl.procEnd( proc )
481 
482 #define irScopeBegin(s) ir.vtbl.scopeBegin( s )
483 
484 #define irScopeEnd(s) ir.vtbl.scopeEnd( s )
485 
486 #define irProcAllocArg(proc, s) ir.vtbl.procAllocArg( proc, s )
487 
488 #define irProcAllocLocal(proc, s) ir.vtbl.procAllocLocal( proc, s )
489 
490 #define irProcAllocStaticVars(head_sym) ir.vtbl.procAllocStaticVars( head_sym )
491 
492 #define irProcGetFrameRegName() ir.vtbl.procGetFrameRegName( )
493 
494 #define irEmitBegin() ir.vtbl.emitBegin( )
495 
496 #define irEmitEnd(tottime) ir.vtbl.emitEnd( tottime )
497 
498 #define irEmitPROCBEGIN(proc, initlabel) ir.vtbl.emitProcBegin( proc, initlabel )
499 
500 #define irEmitPROCEND(proc, initlabel, exitlabel) ir.vtbl.emitProcEnd( proc, initlabel, exitlabel )
501 
502 #define irEmitVARINIBEGIN(sym) ir.vtbl.emitVarIniBegin( sym )
503 #define irEmitVARINIEND(sym) ir.vtbl.emitVarIniEnd( sym )
504 #define irEmitVARINIi(sym, value) ir.vtbl.emitVarIniI( sym, value )
505 #define irEmitVARINIf(sym, value) ir.vtbl.emitVarIniF( sym, value )
506 #define irEmitVARINIOFS(sym, ofs) ir.vtbl.emitVarIniOfs( sym, ofs )
507 #define irEmitVARINISTR(totlgt, litstr, litlgt) ir.vtbl.emitVarIniStr( totlgt, litstr, litlgt )
508 #define irEmitVARINIWSTR(totlgt, litstr, litlgt) ir.vtbl.emitVarIniWstr( totlgt, litstr, litlgt )
509 #define irEmitVARINIPAD(bytes) ir.vtbl.emitVarIniPad( bytes )
510 #define irEmitVARINISCOPEBEGIN( ) ir.vtbl.emitVarIniScopeBegin( )
511 #define irEmitVARINISCOPEEND( ) ir.vtbl.emitVarIniScopeEnd( )
512 
513 #define irEmitFBCTINFBEGIN( ) ir.vtbl.emitFbctinfBegin( )
514 #define irEmitFBCTINFSTRING( s ) ir.vtbl.emitFbctinfString( s )
515 #define irEmitFBCTINFEND( ) ir.vtbl.emitFbctinfEnd( )
516 
517 #define irEmitCONVERT( v1, v2 ) ir.vtbl.emitConvert( v1, v2 )
518 
519 #define irEmitLABEL(label) ir.vtbl.emitLabel( label )
520 
521 #define irEmitRETURN(bytestopop) ir.vtbl.emitReturn( bytestopop )
522 
523 #define irEmitPUSHARG( param, vr, plen, level ) ir.vtbl.emitPushArg( param, vr, plen, level )
524 
525 #define irEmitAsmBegin( ) ir.vtbl.emitAsmBegin( )
526 #define irEmitAsmText( text ) ir.vtbl.emitAsmText( text )
527 #define irEmitAsmSymb( sym ) ir.vtbl.emitAsmSymb( sym )
528 #define irEmitAsmEnd( ) ir.vtbl.emitAsmEnd( )
529 
530 #define irEmitCOMMENT(text) ir.vtbl.emitComment( text )
531 
532 #define irEmitJMPTB( v1, tbsym, values, labels, labelcount, deflabel, minval, maxval ) ir.vtbl.emitJmpTb( v1, tbsym, values, labels, labelcount, deflabel, minval, maxval )
533 
534 #define irGetDistance(vreg) ir.vtbl.getDistance( vreg )
535 
536 #define irLoadVR(reg, vreg, vauxparent) ir.vtbl.loadVR( reg, vreg, vauxparent )
537 
538 #define irStoreVR(vreg, vauxparent) ir.vtbl.storeVR( vreg, vauxparent )
539 
540 #define irXchgTOS(reg) ir.vtbl.xchgTOS( reg )
541 
542 #define irEmitBOP( op, v1, v2, vr, ex ) ir.vtbl.emitBop( op, v1, v2, vr, ex )
543 
544 #define irEmitUOP(op, v1, vr) ir.vtbl.emitUop( op, v1, vr )
545 
546 #define irEmitSTORE(v1, v2) ir.vtbl.emitStore( v1, v2 )
547 
548 #define irEmitSPILLREGS() ir.vtbl.emitSpillRegs( )
549 
550 #define irEmitLOAD(v1) ir.vtbl.emitLoad( v1 )
551 
552 #define irEmitLOADRES(v1, vr) ir.vtbl.emitLoadRes( v1, vr )
553 
554 #define irEmitSTACK(op, v1) ir.vtbl.emitStack( op, v1 )
555 
556 #define irEmitPUSH(v1) ir.vtbl.emitStack( AST_OP_PUSH, v1 )
557 
558 #define irEmitPOP(v1) ir.vtbl.emitStack( AST_OP_POP, v1 )
559 
560 #define irEmitADDR(op, v1, vr) ir.vtbl.emitAddr( op, v1, vr )
561 
562 #define irEmitLABELNF(s) ir.vtbl.emitLabelNF( s )
563 
564 #define irEmitCALLFUNCT(proc, bytestopop, vr, level) ir.vtbl.emitCall( proc, bytestopop, vr, level )
565 
566 #define irEmitCALLPTR(v1, vr, bytestopop, level) ir.vtbl.emitCallPtr( v1, vr, bytestopop, level )
567 
568 #define irEmitSTACKALIGN(bytes) ir.vtbl.emitStackAlign( bytes )
569 
570 #define irEmitJUMPPTR(v1) ir.vtbl.emitJumpPtr( v1 )
571 
572 #define irEmitBRANCH(op, label) ir.vtbl.emitBranch( op, label )
573 
574 #define irEmitMEM(op, v1, v2, bytes) ir.vtbl.emitMem( op, v1, v2, bytes )
575 
576 #define irEmitSCOPEBEGIN(s) ir.vtbl.emitScopeBegin( s )
577 
578 #define irEmitSCOPEEND(s) ir.vtbl.emitScopeEnd( s )
579 
580 #define irEmitDBG(op, proc, ex) ir.vtbl.emitDBG( op, proc, ex )
581 
582 #define irEmitDECL( sym ) ir.vtbl.emitDECL( sym )
583 
584 
585 #define irIsREG(v) (v->typ = IR_VREGTYPE_REG)
586 
587 #define irIsIMM(v) (v->typ = IR_VREGTYPE_IMM)
588 
589 #define irIsVAR(v) (v->typ = IR_VREGTYPE_VAR)
590 
591 #define irIsIDX(v) (v->typ = IR_VREGTYPE_IDX)
592 
593 #define irIsPTR(v) (v->typ = IR_VREGTYPE_PTR)
594 
595 #define irGetVRType(v) v->typ
596 
597 #define irGetVRDataType(v) v->dtype
598 
599 #define irGetVRSubType(v) v->subtype
600 
601 #define irGetVROfs(v) v->ofs
602 
603 #define irGetVRValueI(v) v->value.int
604 
605 #define ISLONGINT(t) ((t = FB_DATATYPE_LONGINT) or (t = FB_DATATYPE_ULONGINT))
606 
607 
608 ''
609 '' inter-module globals
610 ''
611 extern ir as IRCTX
612 
613 
614 #endif '' __IR_BI__
615