FreeBASIC  0.91.0
ir.bas
Go to the documentation of this file.
1 '' intermediate representation - core module
2 ''
3 '' chng: dec/2006 written [v1ctor]
4 
5 #include once "fb.bi"
6 #include once "fbint.bi"
7 #include once "ir.bi"
8 #include once "emit.bi"
9 
10 dim shared ir as IRCTX
11 
12 sub irInit( )
13  select case( env.clopt.backend )
14  case FB_BACKEND_GCC
15  ir.vtbl = irhlc_vtbl
16  case FB_BACKEND_LLVM
17  ir.vtbl = irllvm_vtbl
18  case else
19  assert( env.clopt.backend = FB_BACKEND_GAS )
20  ir.vtbl = irtac_vtbl
21  end select
22  ir.vtbl.init( )
23 end sub
24 
25 sub irEnd( )
26  ir.vtbl.end( )
27 end sub
28 
29 #if __FB_DEBUG__
30 function vregDump( byval v as IRVREG ptr ) as string
31  dim as string s
32  dim as string regname
33 
34  if( v = NULL ) then
35  return "<NULL>"
36  end if
37 
38  static as zstring ptr vregtypes(IR_VREGTYPE_IMM to IR_VREGTYPE_OFS) = _
39  { _
40  @"imm", @"var", @"idx", @"ptr", @"reg", @"ofs" _
41  }
42 
43  #if 0
44  s += "[" + hex( v, 8 ) + "] "
45  #endif
46 
47  s += *vregtypes(v->typ)
48 
49  select case( v->typ )
50  case IR_VREGTYPE_IMM
51  s += " "
52  if( typeGetClass( v->dtype ) = FB_DATACLASS_FPOINT ) then
53  s += str( v->value.f )
54  else
55  s += str( v->value.i )
56  end if
57 
58  case IR_VREGTYPE_REG
59  if( env.clopt.backend = FB_BACKEND_GAS ) then
60  regname = emitDumpRegName( v->dtype, v->reg )
61  if( len( regname ) > 0 ) then
62  s += " " + ucase( regname )
63  else
64  s += " " + str( v->reg )
65  end if
66  else
67  ''s += " reg="
68  s += " " + str( v->reg )
69  end if
70  end select
71 
72  if( v->typ <> IR_VREGTYPE_REG ) then
73  if( v->ofs ) then
74  if( (env.clopt.backend = FB_BACKEND_GAS) and (v->sym <> NULL) ) then
75  s += " """ + *symbGetName( v->sym ) + """ [" + *symbGetMangledName( v->sym ) + str( v->ofs ) + "]"
76  else
77  s += " ofs=" + str( v->ofs )
78  end if
79  end if
80  if( v->mult ) then
81  s += " mult=" + str( v->mult )
82  end if
83  end if
84 
85  s += " " + typeDump( v->dtype, v->subtype )
86 
87  if( v->typ <> IR_VREGTYPE_REG ) then
88  if( v->vidx ) then
89  s += " vidx=<" + vregDump( v->vidx ) + ">"
90  end if
91  end if
92 
93  if( ISLONGINT( v->dtype ) ) then
94  s += " vaux=<" + vregDump( v->vaux ) + ">"
95  end if
96 
97  function = s
98 end function
99 #endif
100