26 byval op as integer, _
27 byval v1
as IRVREG
ptr, _
28 byval vr
as IRVREG
ptr _
33 byval op as integer, _
34 byval v1
as IRVREG
ptr, _
35 byval v2
as IRVREG
ptr, _
36 byval vr
as IRVREG
ptr _
41 byval op as integer, _
42 byval v1
as IRVREG
ptr, _
43 byval v2
as IRVREG
ptr, _
44 byval vr
as IRVREG
ptr, _
45 byval label
as FBSYMBOL
ptr _
50 byval op as integer, _
51 byval v1
as IRVREG
ptr, _
52 byval v2
as IRVREG
ptr _
57 byval op as integer, _
58 byval v1
as IRVREG
ptr, _
59 byval vr
as IRVREG
ptr _
64 byval op as integer, _
65 byval v1
as IRVREG
ptr, _
66 byval v2
as IRVREG
ptr _
71 byval op as integer, _
72 byval proc as FBSYMBOL
ptr, _
73 byval bytestopop
as integer, _
74 byval v1
as IRVREG
ptr, _
75 byval vr
as IRVREG
ptr _
80 byval op as integer, _
81 byval label
as FBSYMBOL
ptr _
86 byval op as integer, _
87 byval v1
as IRVREG
ptr, _
93 byval op as integer, _
94 byval v1
as IRVREG
ptr, _
95 byval vr
as IRVREG
ptr _
100 byval op as integer, _
101 byval v1
as IRVREG
ptr, _
102 byval v2
as IRVREG
ptr, _
103 byval bytes
as integer, _
104 byval extra
as any ptr _
109 byval op as integer, _
110 byval proc as FBSYMBOL
ptr, _
111 byval ex
as integer _
114 declare sub hFlushLIT(
byval op as integer,
byval text
as zstring ptr )
118 byval vreg
as IRVREG
ptr, _
119 byval force
as integer =
FALSE _
124 byval vreg
as IRVREG
ptr, _
125 byval force
as integer =
FALSE _
137 byval op as integer, _
138 byval v1
as IRVREG
ptr, _
139 byval v2
as IRVREG
ptr, _
140 byval vr
as IRVREG
ptr, _
141 byval wrapline
as integer =
FALSE _
143 declare function tacvregDump(
byval tacvreg
as IRTACVREG
ptr )
as string
144 declare sub tacDump(
byval tac
as IRTAC
ptr )
155 dim shared regTB(0
to EMIT_REGCLASSES-1)
as REGCLASS
ptr
166 for i
as integer = 0
to EMIT_REGCLASSES-1
186 function = emitOpen( )
193 byval tottime
as double _
203 byval opt
as IR_OPTIONVALUE _
206 function = emitGetOptionValue( opt )
211 dim as IRVREG
ptr vi =
any
213 if( vreg =
NULL )
then
217 select case vreg->typ
218 case IR_VREGTYPE_IDX, IR_VREGTYPE_PTR
230 if( vi->typ = IR_VREGTYPE_IMM )
then
234 regTB(FB_DATACLASS_INTEGER)->ensure(
regTB(FB_DATACLASS_INTEGER), vi,
NULL, typeGetSize( FB_DATATYPE_INTEGER ) )
238 #macro hGetVREG( vreg, dt, dc, t )
239 if( vreg <>
NULL )
then
242 dt = typeGet( vreg->dtype )
243 if( dt = FB_DATATYPE_POINTER )
then
244 dt = FB_DATATYPE_ULONG
247 dc = symb_dtypeTB(dt).
class
251 dt = FB_DATATYPE_INVALID
259 sub hRelink(
byval vreg
as IRVREG
ptr,
byval tvreg
as IRTACVREG
ptr )
260 if( vreg->tacvhead =
NULL )
then
261 vreg->tacvhead = tvreg
263 vreg->tacvtail->
next = tvreg
265 vreg->tacvtail = tvreg
270 #macro hRelinkVreg(v,t)
271 t->v.reg.parent =
NULL
278 if( v->vidx <>
NULL )
then
279 t->v.idx.vreg = v->vidx
286 if( v->vaux <>
NULL )
then
287 t->v.aux.vreg = v->vaux
299 byval op as integer, _
300 byval v1
as IRVREG
ptr, _
301 byval v2
as IRVREG
ptr, _
302 byval vr
as IRVREG
ptr, _
303 byval ex1
as FBSYMBOL
ptr =
NULL, _
304 byval ex2
as integer = 0 _
335 byval proc as FBSYMBOL
ptr _
338 emitProcBegin(
proc )
345 byval proc as FBSYMBOL
ptr _
354 byval proc as FBSYMBOL
ptr, _
355 byval sym
as FBSYMBOL
ptr _
358 emitProcAllocArg(
proc, sym )
364 byval proc as FBSYMBOL
ptr, _
365 byval sym
as FBSYMBOL
ptr _
368 emitProcAllocLocal(
proc, sym )
375 )
as const zstring ptr
377 function = emitProcGetFrameRegName( )
384 byval s
as FBSYMBOL
ptr _
394 byval s
as FBSYMBOL
ptr _
402 emitProcAllocStaticVars( head_sym )
408 byval label
as FBSYMBOL
ptr _
420 byval bytestopop
as integer _
432 byval proc as FBSYMBOL
ptr, _
433 byval initlabel
as FBSYMBOL
ptr _
436 dim as integer class_
441 for class_ = 0
to EMIT_REGCLASSES-1
445 emitProcHeader(
proc, initlabel )
451 byval proc as FBSYMBOL
ptr, _
452 byval initlabel
as FBSYMBOL
ptr, _
453 byval exitlabel
as FBSYMBOL
ptr _
456 dim as integer bytestopop =
any
461 if( symbGetProcMode(
proc ) = FB_FUNCMODE_CDECL )
then
471 if( (symbGetProcMode(
proc ) <> FB_FUNCMODE_CDECL)
or _
472 (env.target.options
and FB_TARGETOPT_CALLEEPOPSHIDDENPTR) )
then
473 bytestopop += env.pointersize
477 emitProcFooter(
proc, bytestopop, initlabel, exitlabel )
484 byval s
as FBSYMBOL
ptr _
494 byval s
as FBSYMBOL
ptr _
504 byval op as integer, _
505 byval v1
as IRVREG
ptr, _
506 byval v2
as IRVREG
ptr, _
507 byval vr
as IRVREG
ptr, _
508 byval ex
as FBSYMBOL
ptr _
518 byval op as integer, _
519 byval v1
as IRVREG
ptr, _
520 byval vr
as IRVREG
ptr _
528 select case( typeGetClass( v1->dtype ) )
529 case FB_DATACLASS_INTEGER
531 case FB_DATACLASS_FPOINT
536 sub _emitStore(
byval v1
as IRVREG
ptr,
byval v2
as IRVREG
ptr )
552 byval v1
as IRVREG
ptr _
562 byval v1
as IRVREG
ptr, _
563 byval vr
as IRVREG
ptr _
573 byval op as integer, _
574 byval v1
as IRVREG
ptr _
584 byval param
as FBSYMBOL
ptr, _
585 byval vr
as IRVREG
ptr, _
586 byval udtlen
as longint, _
587 byval level
as integer _
590 if( udtlen = 0 )
then
601 byval op as integer, _
602 byval v1
as IRVREG
ptr, _
603 byval vr
as IRVREG
ptr _
613 byval l as FBSYMBOL
ptr _
623 byval proc as FBSYMBOL
ptr, _
624 byval bytestopop
as integer, _
625 byval vr
as IRVREG
ptr, _
626 byval level
as integer _
636 byval v1
as IRVREG
ptr, _
637 byval vr
as IRVREG
ptr, _
638 byval bytestopop
as integer, _
639 byval level
as integer _
649 byval bytes
as integer _
666 byval v1
as IRVREG
ptr, _
667 byval tbsym
as FBSYMBOL
ptr, _
668 byval values
as ulongint ptr, _
669 byval labels
as FBSYMBOL
ptr ptr, _
670 byval labelcount
as integer, _
671 byval deflabel
as FBSYMBOL
ptr, _
672 byval minval
as ulongint, _
673 byval maxval
as ulongint _
677 emitJMPTB( tbsym, values, labels, labelcount, deflabel, minval, maxval )
684 byval op as integer, _
685 byval v1
as IRVREG
ptr, _
686 byval v2
as IRVREG
ptr, _
687 byval bytes
as longint _
701 byval op as integer, _
702 byval proc as FBSYMBOL
ptr, _
703 byval ex
as integer _
724 if( symbGetOfs( sym ) > 0 )
then
726 elseif( symbGetOfs( sym ) < 0 )
then
744 var dtype = symbGetType( sym )
745 if( ISLONGINT( dtype ) )
then
746 emitVARINI64( dtype, value )
762 byval totlgt
as longint, _
763 byval litstr
as zstring ptr, _
764 byval litlgt
as longint _
767 dim as const zstring ptr s
770 if( totlgt = 0 )
then
776 if( litlgt > totlgt )
then
779 s =
hEscape(
left( *litstr, totlgt ) )
787 if( litlgt < totlgt )
then
796 byval totlgt
as longint, _
797 byval litstr
as wstring ptr, _
798 byval litlgt
as longint _
805 if( totlgt = 0 )
then
811 if( litlgt > totlgt )
then
814 s =
hEscapeW(
left( *litstr, totlgt ) )
820 wclen = typeGetSize( FB_DATATYPE_WCHAR )
824 if( litlgt < totlgt )
then
859 byval dtype
as integer, _
860 byval subtype
as FBSYMBOL
ptr, _
861 byval vtype
as integer _
864 dim as IRVREG
ptr v =
any
869 v->dtype = typeGet( dtype )
878 if( env.clopt.fputype = FB_FPUTYPE_FPU )
then
879 v->regFamily = IR_REG_FPU_STACK
881 v->regFamily = IR_REG_SSE
895 byval dtype
as integer, _
896 byval subtype
as FBSYMBOL
ptr _
899 dim as IRVREG
ptr vr =
any
901 vr =
hNewVR( dtype, subtype, IR_VREGTYPE_REG )
904 if( ISLONGINT( dtype ) )
then
905 vr->vaux =
hNewVR( FB_DATATYPE_INTEGER,
NULL, IR_VREGTYPE_REG )
914 byval dtype
as integer, _
915 byval subtype
as FBSYMBOL
ptr, _
916 byval value
as longint _
919 dim as IRVREG
ptr vr =
any
921 vr =
hNewVR( dtype, subtype, IR_VREGTYPE_IMM )
923 if( ISLONGINT( dtype ) )
then
925 vr->value.i =
cuint( value )
928 vr->vaux =
hNewVR( FB_DATATYPE_INTEGER,
NULL, IR_VREGTYPE_IMM )
929 vr->vaux->value.i =
cint( value
shr 32 )
939 byval dtype
as integer, _
940 byval subtype
as FBSYMBOL
ptr, _
941 byval value
as double _
944 dim as IRVREG
ptr vr =
any
945 dim as FBSYMBOL
ptr s =
any
948 if( irGetOption( IR_OPT_FPUIMMEDIATES ) )
then
949 vr =
hNewVR( dtype, subtype, IR_VREGTYPE_IMM )
954 vr = irAllocVRVAR( dtype, subtype, s, symbGetOfs( s ) )
963 byval dtype
as integer, _
964 byval subtype
as FBSYMBOL
ptr, _
965 byval symbol
as FBSYMBOL
ptr, _
966 byval ofs
as longint _
969 dim as IRVREG
ptr vr =
any, va =
any
973 vr =
hNewVR( dtype, subtype, IR_VREGTYPE_VAR )
979 if( ISLONGINT( dtype ) )
then
980 va =
hNewVR( FB_DATATYPE_INTEGER,
NULL, IR_VREGTYPE_VAR )
992 byval dtype
as integer, _
993 byval subtype
as FBSYMBOL
ptr, _
994 byval symbol
as FBSYMBOL
ptr, _
995 byval ofs
as longint, _
996 byval mult
as integer, _
997 byval vidx
as IRVREG
ptr _
1000 dim as IRVREG
ptr vr =
any, va =
any
1002 vr =
hNewVR( dtype, subtype, IR_VREGTYPE_IDX )
1010 if( ISLONGINT( dtype ) )
then
1011 va =
hNewVR( FB_DATATYPE_INTEGER,
NULL, IR_VREGTYPE_IDX )
1023 byval dtype
as integer, _
1024 byval subtype
as FBSYMBOL
ptr, _
1025 byval ofs
as longint, _
1026 byval vidx
as IRVREG
ptr _
1029 dim as IRVREG
ptr vr =
any, va =
any
1031 vr =
hNewVR( dtype, subtype, IR_VREGTYPE_PTR )
1038 if( ISLONGINT( dtype ) )
then
1039 va =
hNewVR( FB_DATATYPE_INTEGER,
NULL, IR_VREGTYPE_IDX )
1051 byval dtype
as integer, _
1052 byval subtype
as FBSYMBOL
ptr, _
1053 byval symbol
as FBSYMBOL
ptr, _
1054 byval ofs
as longint _
1057 dim as IRVREG
ptr vr =
any
1059 vr =
hNewVR( dtype, subtype, IR_VREGTYPE_OFS )
1071 byval vreg
as IRVREG
ptr, _
1072 byval dtype
as integer, _
1073 byval subtype
as FBSYMBOL
ptr _
1076 if( vreg <>
NULL )
then
1077 vreg->dtype = typeGet( dtype )
1078 vreg->subtype = subtype
1087 dim as string free, used
1088 dim as integer reg =
any
1091 reg =
regTB(FB_DATACLASS_INTEGER)->getFirst(
regTB(FB_DATACLASS_INTEGER) )
1092 while( reg <> INVALID )
1094 if(
regTB(FB_DATACLASS_INTEGER)->isFree(
regTB(FB_DATACLASS_INTEGER), reg ) )
then
1095 if(
len( free ) > 0 )
then free +=
", "
1098 if(
len( used ) > 0 )
then used +=
", "
1102 reg =
regTB(FB_DATACLASS_INTEGER)->getNext(
regTB(FB_DATACLASS_INTEGER), reg )
1105 print ,
"used: " & used &
" | free: " & free
1110 byval op as integer, _
1111 byval v1
as IRVREG
ptr, _
1112 byval v2
as IRVREG
ptr, _
1113 byval vr
as IRVREG
ptr, _
1114 byval wrapline
as integer =
FALSE _
1119 if( astGetOpId(
op ) <>
NULL )
then
1120 s = *astGetOpId(
op )
1126 select case(
len( s ) )
1128 s =
left( s, MAXLEN )
1130 s +=
space( MAXLEN -
len( s ) )
1134 #macro hDumpVr( id, v )
1135 if( v <>
NULL )
then
1154 if( wrapline =
FALSE )
then
1158 if( (wrapline =
FALSE)
and (
len( s ) > 79) )
then
1167 if( tacvreg =
NULL )
then
1170 function =
"IRTACVREG( " & _
1171 "vreg=" &
vregDump( tacvreg->vreg ) &
", " & _
1172 "parent=" &
vregDump( tacvreg->parent ) &
", " & _
1177 if( tac =
NULL )
then
1178 print "IRTAC: <NULL>"
1181 print "IRTAC: pos=" & tac->
pos &
", op=" & tac->
op
1197 byval vold
as IRVREG
ptr, _
1198 byval vnew
as IRVREG
ptr _
1201 dim as IRTACVREG
ptr t =
any
1202 dim as IRVREG
ptr v =
any
1209 if( t->parent )
then
1210 assert( (t->parent->vidx = vold)
or (t->parent->vaux = vold) )
1211 if( t->parent->vidx = vold )
then
1212 t->parent->vidx = vnew
1214 t->parent->vaux = vnew
1219 loop while( t <>
NULL )
1221 vnew->tacvhead = vold->tacvhead
1222 vnew->tacvtail = vold->tacvtail
1223 vnew->taclast = vold->taclast
1230 byval t
as IRTAC
ptr _
1233 dim as IRVREG
ptr v1 =
any, v2 =
any, vr =
any
1234 dim as integer v1_dtype =
any, v1_dclass =
any, v1_typ =
any
1235 dim as integer v2_dtype =
any, v2_dclass =
any, v2_typ =
any
1236 dim as integer vr_dtype =
any, vr_dclass =
any, vr_typ =
any
1237 dim as integer op =
any
1244 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
1245 hGetVREG( v2, v2_dtype, v2_dclass, v2_typ )
1246 hGetVREG( vr, vr_dtype, vr_dclass, vr_typ )
1248 select case astGetOpClass(
op )
1249 case AST_NODECLASS_UOP
1251 if( vr_dtype = v1_dtype )
then
1252 if( irGetDistance( v1 ) = IR_MAXDIST )
then
1258 case AST_NODECLASS_BOP, AST_NODECLASS_COMP
1259 dim as integer v1rename =
any, v2rename =
any
1261 if( vr =
NULL )
then
1266 if( v1_dclass <> v2_dclass )
then
1272 if( vr_dtype = v1_dtype )
then
1273 if( irGetDistance( v1 ) = IR_MAXDIST )
then
1280 if( astGetOpIsCommutative(
op ) )
then
1282 if( vr_dtype = v2_dtype )
then
1283 if( v2_typ <> IR_VREGTYPE_IMM )
then
1284 if( irGetDistance( v2 ) = IR_MAXDIST )
then
1292 if( v1rename
and v2rename )
then
1293 if( irIsREG( v1 ) =
FALSE )
then
1301 elseif( v2rename )
then
1315 dim as IRVREG
ptr v1, v2, vr
1336 select case as const astGetOpClass(
op )
1337 case AST_NODECLASS_UOP
1340 case AST_NODECLASS_BOP
1343 case AST_NODECLASS_COMP
1346 case AST_NODECLASS_ASSIGN
1349 case AST_NODECLASS_LOAD
1352 case AST_NODECLASS_CONV
1355 case AST_NODECLASS_STACK
1358 case AST_NODECLASS_CALL
1361 case AST_NODECLASS_BRANCH
1364 case AST_NODECLASS_ADDROF
1367 case AST_NODECLASS_MEM
1370 case AST_NODECLASS_DBG
1373 case AST_NODECLASS_LIT
1378 if( env.clopt.fputype >= FB_FPUTYPE_SSE )
then
1380 if( astGetOpClass(
op ) <> AST_NODECLASS_CALL )
then
1382 if( vr->regFamily = IR_REG_FPU_STACK )
then vr->regFamily = IR_REG_SSE
1388 loop while( t <>
NULL )
1405 byval op as integer, _
1406 byval label
as FBSYMBOL
ptr _
1409 select case as const op
1430 dim as integer class_, reg
1433 for class_ = 0
to EMIT_REGCLASSES-1
1436 reg =
regTB(class_)->getFirst(
regTB(class_) )
1437 do until( reg = INVALID )
1441 assert( emitIsRegPreserved( class_, reg ) )
1449 reg =
regTB(class_)->getNext(
regTB(class_), reg )
1457 dim as integer vr_dclass =
any, vr_dtype =
any, vr_typ =
any
1458 dim as integer preserved1 =
any, preserved2 =
any
1459 dim as integer freg1 =
any, freg2 =
any
1460 dim as IRVREG origvreg =
any, origvaux =
any, destvreg =
any
1472 hGetVREG( vr, vr_dtype, vr_dclass, vr_typ )
1474 assert( irIsREG( vr ) )
1476 preserved1 = emitIsRegPreserved( vr_dclass, vr->reg )
1477 if( ISLONGINT( vr_dtype ) )
then
1478 assert( irIsREG( vr->vaux ) )
1479 origvaux = *vr->vaux
1480 origvreg.vaux = @origvaux
1481 preserved2 = emitIsRegPreserved( vr_dclass, vr->vaux->reg )
1486 if( preserved1
and preserved2 )
then
1492 if( preserved1 =
FALSE )
then
1494 freg1 = emitGetFreePreservedReg( vr_dclass, vr_dtype )
1495 if( freg1 = INVALID )
then
1499 vr->reg =
regTB(vr_dclass)->allocateReg(
regTB(vr_dclass), freg1, vr,
NULL )
1502 if( preserved2 =
FALSE )
then
1506 freg2 = emitGetFreePreservedReg( FB_DATACLASS_INTEGER, FB_DATATYPE_INTEGER )
1507 if( freg2 = INVALID )
then
1509 if( preserved1 =
FALSE )
then
1511 regTB(vr_dclass)->free(
regTB(vr_dclass), vr->reg )
1512 vr->reg = origvreg.reg
1516 vr->vaux->reg =
regTB(FB_DATACLASS_INTEGER)->allocateReg(
regTB(FB_DATACLASS_INTEGER), freg2, vr->vaux, vr )
1519 if( (
not preserved1)
and (
not preserved2) )
then
1522 elseif( preserved1 =
FALSE )
then
1524 if( ISLONGINT( vr_dtype ) )
then
1528 destvreg.dtype = FB_DATATYPE_INTEGER
1529 destvreg.vaux =
NULL
1531 origvreg.dtype = FB_DATATYPE_INTEGER
1532 origvreg.vaux =
NULL
1534 emitMOV( @destvreg, @origvreg )
1540 emitMOV( vr->vaux, @origvaux )
1544 if( preserved1 =
FALSE )
then
1545 regTB(vr_dclass)->free(
regTB(vr_dclass), origvreg.reg )
1547 if( preserved2 =
FALSE )
then
1548 regTB(FB_DATACLASS_INTEGER)->free(
regTB(FB_DATACLASS_INTEGER), origvaux.reg )
1555 dim as integer npreg =
any, reg =
any
1556 dim as IRVREG
ptr vr =
any, vauxparent =
any
1559 for class_
as integer = 0
to EMIT_REGCLASSES-1
1563 if( class_ = FB_DATACLASS_INTEGER )
then
1564 if( ptrvreg <>
NULL )
then
1566 select case ptrvreg->typ
1567 case IR_VREGTYPE_REG
1568 npreg = ptrvreg->reg
1570 case IR_VREGTYPE_IDX, IR_VREGTYPE_PTR
1571 ptrvreg = ptrvreg->vidx
1572 if( ptrvreg <>
NULL )
then
1573 npreg = ptrvreg->reg
1582 reg =
regTB(class_)->getFirst(
regTB(class_) )
1583 do until( reg = INVALID )
1586 (reg <> npreg) )
then
1589 vr =
regTB(class_)->getVreg(
regTB(class_), reg, vauxparent )
1590 assert( irIsREG( vr )
and (vr->reg = reg) )
1595 if( vauxparent )
then
1596 assert( vauxparent->vaux = vr )
1603 irStoreVR( vr,
NULL )
1608 reg =
regTB(class_)->getNext(
regTB(class_), reg )
1617 byval op as integer, _
1618 byval proc as FBSYMBOL
ptr, _
1619 byval bytestopop
as integer, _
1620 byval v1
as IRVREG
ptr, _
1621 byval vr
as IRVREG
ptr _
1624 dim as integer vr_dclass, vr_dtype, vr_typ, vr_reg, vr_reg2
1625 dim as IRVREG
ptr va
1637 if(
op = AST_OP_CALLPTR )
then
1642 hGetVREG( v1, vr_dtype, vr_dclass, vr_typ )
1644 if( vr_typ = IR_VREGTYPE_REG )
then
1645 regTB(vr_dclass)->ensure(
regTB(vr_dclass), v1,
NULL, typeGetSize( vr_dtype ) )
1649 if(
op = AST_OP_CALLPTR )
then
1661 if( vr <>
NULL )
then
1662 hGetVREG( vr, vr_dtype, vr_dclass, vr_typ )
1664 emitGetResultReg( vr_dtype, vr_dclass, vr_reg, vr_reg2 )
1667 if( ISLONGINT( vr_dtype ) )
then
1669 va->reg =
regTB(vr_dclass)->allocateReg(
regTB(vr_dclass), vr_reg2, va, vr )
1670 va->typ = IR_VREGTYPE_REG
1673 vr->reg =
regTB(vr_dclass)->allocateReg(
regTB(vr_dclass), vr_reg, vr,
NULL )
1674 vr->typ = IR_VREGTYPE_REG
1685 byval op as integer, _
1686 byval v1
as IRVREG
ptr, _
1687 byval ex
as integer _
1690 dim as integer v1_typ, v1_dtype, v1_dclass
1691 dim as IRVREG
ptr va
1694 if(
op = AST_OP_STACKALIGN )
then
1700 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
1705 if( v1_typ = IR_VREGTYPE_REG )
then
1707 if( ISLONGINT( v1_dtype ) )
then
1709 regTB(v1_dclass)->ensure(
regTB(v1_dclass), va, v1, typeGetSize( FB_DATATYPE_INTEGER ) )
1710 v1_dtype = FB_DATATYPE_INTEGER
1712 regTB(v1_dclass)->ensure(
regTB(v1_dclass), v1,
NULL, typeGetSize( v1_dtype ) )
1733 byval op as integer, _
1734 byval v1
as IRVREG
ptr, _
1735 byval vr
as IRVREG
ptr _
1738 dim as integer v1_typ, v1_dtype, v1_dclass
1739 dim as integer vr_typ, vr_dtype, vr_dclass
1740 dim as IRVREG
ptr va
1742 dim as integer v1vector
1743 v1vector = v1->vector
1746 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
1747 hGetVREG( vr, vr_dtype, vr_dclass, vr_typ )
1753 if ( vr <>
NULL )
then
1756 if( ISLONGINT( vr_dtype ) )
then
1758 regTB(vr_dclass)->ensure(
regTB(vr_dclass), va, vr, typeGetSize( FB_DATATYPE_INTEGER ) )
1759 vr_dtype = FB_DATATYPE_INTEGER
1761 regTB(vr_dclass)->ensure(
regTB(vr_dclass), vr,
NULL, typeGetSize( vr_dtype ) )
1766 if( vr <>
NULL )
then
1768 if( ISLONGINT( v1_dtype ) )
then
1770 regTB(v1_dclass)->ensure(
regTB(v1_dclass), va, v1, typeGetSize( FB_DATATYPE_INTEGER ) )
1771 v1_dtype = FB_DATATYPE_INTEGER
1774 if(
op = AST_OP_SWZ_REPEAT )
then
1779 regTB(v1_dclass)->ensure(
regTB(v1_dclass), v1,
NULL, typeGetSize( v1_dtype ) )
1781 if(
op = AST_OP_SWZ_REPEAT )
then
1782 v1->vector = v1vector
1787 select case as const op
1805 case AST_OP_CONVFD2FS
1833 case AST_OP_SWZ_REPEAT
1839 if ( vr <>
NULL )
then
1854 byval op as integer, _
1855 byval v1
as IRVREG
ptr, _
1856 byval v2
as IRVREG
ptr, _
1857 byval vr
as IRVREG
ptr _
1860 dim as integer v1_typ, v1_dtype, v1_dclass
1861 dim as integer v2_typ, v2_dtype, v2_dclass
1862 dim as integer vr_typ, vr_dtype, vr_dclass
1863 dim as IRVREG
ptr va
1866 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
1867 hGetVREG( v2, v2_dtype, v2_dclass, v2_typ )
1868 hGetVREG( vr, vr_dtype, vr_dclass, vr_typ )
1875 if( vr =
NULL )
then
1876 if( v2_typ <> IR_VREGTYPE_IMM )
then
1878 if( ISLONGINT( v2_dtype ) )
then
1880 regTB(v2_dclass)->ensure(
regTB(v2_dclass), va, v2, typeGetSize( FB_DATATYPE_INTEGER ) )
1881 v2_dtype = FB_DATATYPE_INTEGER
1883 regTB(v2_dclass)->ensure(
regTB(v2_dclass), v2,
NULL, typeGetSize( v2_dtype ) )
1886 if( v2_typ = IR_VREGTYPE_REG )
then
1888 if( ISLONGINT( v2_dtype ) )
then
1890 regTB(v2_dclass)->ensure(
regTB(v2_dclass), va, v2, typeGetSize( FB_DATATYPE_INTEGER ) )
1891 v2_dtype = FB_DATATYPE_INTEGER
1893 regTB(v2_dclass)->ensure(
regTB(v2_dclass), v2,
NULL, typeGetSize( v2_dtype ) )
1898 if( ISLONGINT( v1_dtype ) )
then
1900 regTB(v1_dclass)->ensure(
regTB(v1_dclass), va, v1, typeGetSize( FB_DATATYPE_INTEGER ) )
1901 v1_dtype = FB_DATATYPE_INTEGER
1903 regTB(v1_dclass)->ensure(
regTB(v1_dclass), v1,
NULL, typeGetSize( v1_dtype ) )
1907 select case as const op
1944 if ( vr <>
NULL )
then
1946 if( (v1 <> vr) )
then
1948 if( ISLONGINT( vr_dtype ) )
then
1950 regTB(vr_dclass)->ensure(
regTB(vr_dclass), va, vr, typeGetSize( FB_DATATYPE_INTEGER ) )
1951 vr_dtype = FB_DATATYPE_INTEGER
1953 regTB(vr_dclass)->ensure(
regTB(vr_dclass), vr,
NULL, typeGetSize( vr_dtype ) )
1968 byval op as integer, _
1969 byval v1
as IRVREG
ptr, _
1970 byval v2
as IRVREG
ptr, _
1971 byval vr
as IRVREG
ptr, _
1972 byval label
as FBSYMBOL
ptr _
1976 dim as integer v1_typ, v1_dtype, v1_dclass
1977 dim as integer v2_typ, v2_dtype, v2_dclass
1978 dim as integer vr_typ, vr_dtype, vr_dclass
1979 dim as IRVREG
ptr va
1980 dim as integer doload
1983 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
1984 hGetVREG( v2, v2_dtype, v2_dclass, v2_typ )
1985 hGetVREG( vr, vr_dtype, vr_dclass, vr_typ )
1993 if( vr =
NULL )
then
1994 if( v2_dclass = FB_DATACLASS_INTEGER )
then
1995 if( v2_typ <> IR_VREGTYPE_IMM )
then
1996 if( v1_dclass <> FB_DATACLASS_FPOINT )
then
2003 if( (v2_typ = IR_VREGTYPE_REG)
or doload )
then
2005 if( ISLONGINT( v2_dtype ) )
then
2007 regTB(v2_dclass)->ensure(
regTB(v2_dclass), va, v2, typeGetSize( FB_DATATYPE_INTEGER ) )
2008 v2_dtype = FB_DATATYPE_INTEGER
2010 regTB(v2_dclass)->ensure(
regTB(v2_dclass), v2,
NULL, typeGetSize( v2_dtype ) )
2011 v2_typ = IR_VREGTYPE_REG
2016 if( (vr <>
NULL)
and (vr = v1) )
then
2018 elseif( v1_dclass = FB_DATACLASS_FPOINT )
then
2020 elseif( v1_typ = IR_VREGTYPE_IMM)
then
2022 elseif( v2_typ <> IR_VREGTYPE_REG )
then
2023 if( v2_typ <> IR_VREGTYPE_IMM )
then
2028 if( (v1_typ = IR_VREGTYPE_REG)
or doload )
then
2030 if( ISLONGINT( v1_dtype ) )
then
2032 regTB(v1_dclass)->ensure(
regTB(v1_dclass), va, v1, typeGetSize( FB_DATATYPE_INTEGER ) )
2033 v1_dtype = FB_DATATYPE_INTEGER
2035 regTB(v1_dclass)->ensure(
regTB(v1_dclass), v1,
NULL, typeGetSize( v1_dtype ) )
2039 if( vr <>
NULL )
then
2041 vr->reg =
regTB(vr_dclass)->_allocate(
regTB(vr_dclass), vr,
NULL, typeGetSize( vr_dtype ) )
2042 vr->typ = IR_VREGTYPE_REG
2047 select case as const op
2049 emitEQ( vr, label, v1, v2 )
2051 emitNE( vr, label, v1, v2 )
2053 emitGT( vr, label, v1, v2 )
2055 emitLT( vr, label, v1, v2 )
2057 emitLE( vr, label, v1, v2 )
2059 emitGE( vr, label, v1, v2 )
2065 if( vr <>
NULL )
then
2072 dim as IRVREG
ptr vr =
any, vauxparent =
any
2073 dim as integer reg =
any
2076 for class_
as integer = 0
to EMIT_REGCLASSES-1
2078 reg =
regTB(class_)->getFirst(
regTB(class_) )
2079 do until( reg = INVALID )
2083 vr =
regTB(class_)->getVreg(
regTB(class_), reg, vauxparent )
2084 assert( irIsREG( vr ) )
2085 assert( vr->reg = reg )
2088 irStoreVR( vr, vauxparent )
2092 reg =
regTB(class_)->getNext(
regTB(class_), reg )
2100 byval op as integer, _
2101 byval v1
as IRVREG
ptr, _
2102 byval v2
as IRVREG
ptr _
2105 dim as integer v1_typ, v1_dtype, v1_dclass
2106 dim as integer v2_typ, v2_dtype, v2_dclass
2107 dim as IRVREG
ptr va
2110 if(
op = AST_OP_SPILLREGS )
then
2116 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
2117 hGetVREG( v2, v2_dtype, v2_dclass, v2_typ )
2123 if( (v2_typ = IR_VREGTYPE_REG)
or _
2124 ((v2_typ <> IR_VREGTYPE_IMM)
and (v1_dclass = FB_DATACLASS_INTEGER)) )
then
2126 if( ISLONGINT( v2_dtype ) )
then
2128 regTB(v2_dclass)->ensure(
regTB(v2_dclass), va, v2, typeGetSize( FB_DATATYPE_INTEGER ) )
2129 v2_dtype = FB_DATATYPE_INTEGER
2131 regTB(v2_dclass)->ensure(
regTB(v2_dclass), v2,
NULL, typeGetSize( v2_dtype ) )
2146 byval op as integer, _
2147 byval v1
as IRVREG
ptr, _
2148 byval vr
as IRVREG
ptr _
2151 dim as integer v1_typ, v1_dtype, v1_dclass, v1_reg
2152 dim as IRVREG
ptr va
2155 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
2163 if( ISLONGINT( v1_dtype ) )
then
2165 regTB(v1_dclass)->ensure(
regTB(v1_dclass), va, v1, typeGetSize( FB_DATATYPE_INTEGER ) )
2166 v1_dtype = FB_DATATYPE_INTEGER
2168 regTB(v1_dclass)->ensure(
regTB(v1_dclass), v1,
NULL, typeGetSize( v1_dtype ) )
2171 if( v1_typ = IR_VREGTYPE_REG )
then
2173 if( ISLONGINT( v1_dtype ) )
then
2175 regTB(v1_dclass)->ensure(
regTB(v1_dclass), va, v1, typeGetSize( FB_DATATYPE_INTEGER ) )
2177 v1_reg =
regTB(v1_dclass)->ensure(
regTB(v1_dclass), v1,
NULL, typeGetSize( FB_DATATYPE_INTEGER ) )
2179 v1_reg =
regTB(v1_dclass)->ensure(
regTB(v1_dclass), v1,
NULL, typeGetSize( v1_dtype ) )
2185 dim as integer vr_reg, vr_reg2
2187 emitGetResultReg( v1_dtype, v1_dclass, vr_reg, vr_reg2 )
2189 if( vr_reg <> v1_reg )
then
2191 if( ISLONGINT( v1_dtype ) )
then
2193 va->reg =
regTB(v1_dclass)->allocateReg(
regTB(v1_dclass), vr_reg2, va, vr )
2194 va->typ = IR_VREGTYPE_REG
2197 vr->reg =
regTB(v1_dclass)->allocateReg(
regTB(v1_dclass), vr_reg, vr,
NULL )
2198 vr->typ = IR_VREGTYPE_REG
2201 if( ast.
proc.curr->sym->
proc.returnMethod <> FB_RETURN_SSE )
then
2202 vr->regFamily = IR_REG_FPU_STACK
2221 byval op as integer, _
2222 byval v1
as IRVREG
ptr, _
2223 byval v2
as IRVREG
ptr _
2226 dim as integer v1_typ, v1_dtype, v1_dclass
2227 dim as integer v2_typ, v2_dtype, v2_dclass
2228 dim as integer reuse
2229 dim as IRVREG
ptr va
2232 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
2233 hGetVREG( v2, v2_dtype, v2_dclass, v2_typ )
2241 if( (v1_dclass = v2_dclass)
and (v2_typ = IR_VREGTYPE_REG) )
then
2244 if( v2_dclass = FB_DATACLASS_FPOINT )
then
2245 if( irGetOption( IR_OPT_FPUCONV ) )
then
2246 v1->regFamily = v2->regFamily
2247 if( v2->regFamily = IR_REG_FPU_STACK )
then exit sub
2251 v1->typ = IR_VREGTYPE_REG
2252 regTB(v1_dclass)->setOwner(
regTB(v1_dclass), v1->reg, v1,
NULL )
2258 if( irGetDistance( v2 ) = IR_MAXDIST )
then
2260 select case typeGetSize( v1_dtype )
2264 select case typeGetSize( v2_dtype )
2276 v1->typ = IR_VREGTYPE_REG
2277 regTB(v1_dclass)->setOwner(
regTB(v1_dclass), v1->reg, v1,
NULL )
2279 if( v2_typ = IR_VREGTYPE_REG )
then
2281 if( ISLONGINT( v2_dtype ) )
then
2283 regTB(v2_dclass)->ensure(
regTB(v2_dclass), va, v2, typeGetSize( FB_DATATYPE_INTEGER ) )
2284 v2_dtype = FB_DATATYPE_INTEGER
2286 regTB(v2_dclass)->ensure(
regTB(v2_dclass), v2,
NULL, typeGetSize( v2_dtype ) )
2290 if( ISLONGINT( v1_dtype ) )
then
2292 va->reg =
regTB(v1_dclass)->_allocate(
regTB(v1_dclass), va, v1, typeGetSize( FB_DATATYPE_INTEGER ) )
2293 va->typ = IR_VREGTYPE_REG
2294 v1_dtype = FB_DATATYPE_INTEGER
2296 v1->reg =
regTB(v1_dclass)->_allocate(
regTB(v1_dclass), v1,
NULL, typeGetSize( v1_dtype ) )
2297 v1->typ = IR_VREGTYPE_REG
2304 if( reuse =
FALSE )
then
2318 byval op as integer, _
2319 byval v1
as IRVREG
ptr, _
2320 byval vr
as IRVREG
ptr _
2323 dim as integer v1_typ, v1_dtype, v1_dclass
2324 dim as integer vr_typ, vr_dtype, vr_dclass
2327 hGetVREG( v1, v1_dtype, v1_dclass, v1_typ )
2328 hGetVREG( vr, vr_dtype, vr_dclass, vr_typ )
2334 if( v1_typ = IR_VREGTYPE_REG )
then
2335 regTB(v1_dclass)->ensure(
regTB(v1_dclass), v1,
NULL, typeGetSize( v1_dtype ) )
2338 if( vr_typ = IR_VREGTYPE_REG )
then
2339 regTB(vr_dclass)->ensure(
regTB(vr_dclass), vr,
NULL, typeGetSize( vr_dtype ) )
2359 byval op as integer, _
2360 byval v1
as IRVREG
ptr, _
2361 byval v2
as IRVREG
ptr, _
2362 byval bytes
as integer, _
2363 byval extra
as any ptr _
2371 select case as const op
2378 case AST_OP_MEMCLEAR
2381 case AST_OP_STKCLEAR
2394 byval op as integer, _
2395 byval proc as FBSYMBOL
ptr, _
2396 byval ex
as integer _
2399 select case as const op
2400 case AST_OP_DBG_LINEINI
2403 case AST_OP_DBG_LINEEND
2406 case AST_OP_DBG_SCOPEINI
2409 case AST_OP_DBG_SCOPEEND
2417 case AST_OP_LIT_COMMENT
2431 byval vreg
as IRVREG
ptr, _
2432 byval force
as integer =
FALSE _
2435 dim as IRVREG
ptr vidx
2437 if( vreg =
NULL )
then
2442 if( vidx <>
NULL )
then
2443 if( vidx->reg <> INVALID )
then
2454 byval vreg
as IRVREG
ptr, _
2455 byval force
as integer =
FALSE _
2458 dim as integer dclass, dist
2459 dim as IRVREG
ptr vaux
2461 if( vreg =
NULL )
then
2469 if( vreg->typ <> IR_VREGTYPE_REG )
then
2473 if( vreg->reg = INVALID )
then
2479 if( force =
FALSE )
then
2480 dist = irGetDistance( vreg )
2483 if( dist = IR_MAXDIST )
then
2485 if( vreg->vaux <>
NULL )
then
2487 if( vaux->reg <> INVALID )
then
2492 dclass = typeGetClass(vreg->dtype)
2493 regTB(dclass)->free(
regTB(dclass), vreg->reg )
2502 byval vreg
as IRVREG
ptr _
2509 if( vreg =
NULL )
then
2522 dist = vreg->taclast->
pos - t->
pos
2526 function = IR_MAXDIST
2535 byval reg
as integer, _
2536 byval vreg
as IRVREG
ptr, _
2537 byval vauxparent
as IRVREG
ptr _
2542 if( vreg->typ <> IR_VREGTYPE_REG )
then
2545 if( vauxparent =
NULL )
then
2546 rvreg.typ = IR_VREGTYPE_REG
2547 rvreg.dtype = vreg->dtype
2549 rvreg.vaux = vreg->vaux
2550 rvreg.regFamily = vreg->regFamily
2557 vreg->typ = IR_VREGTYPE_REG
2562 if( (env.clopt.fputype >= FB_FPUTYPE_SSE)
and (vauxparent <>
NULL) )
then
2563 vreg->regFamily = IR_REG_SSE
2570 byval vreg
as IRVREG
ptr, _
2571 byval vauxparent
as IRVREG
ptr _
2574 dim as IRVREG origvreg =
any, origvaux =
any
2575 dim as integer vr_dclass =
any
2577 if( vauxparent )
then
2578 assert( vauxparent->vaux = vreg )
2589 assert( irIsREG( vreg ) )
2590 assert(
iif( vreg->vaux, irIsREG( vreg->vaux ), TRUE ) )
2594 if( ISLONGINT( vreg->dtype ) )
then
2596 origvaux = *vreg->vaux
2597 origvreg.vaux = @origvaux
2600 if( irGetDistance( vreg ) <> IR_MAXDIST )
then
2602 vreg->typ = IR_VREGTYPE_VAR
2604 vreg->ofs = symbGetOfs( vreg->sym )
2606 if( ISLONGINT( vreg->dtype ) )
then
2608 vreg->vaux->reg = INVALID
2609 vreg->vaux->typ = IR_VREGTYPE_VAR
2610 vreg->vaux->ofs = vreg->ofs + 4
2612 if( env.clopt.fputype >= FB_FPUTYPE_SSE )
then
2613 vreg->regFamily = IR_REG_SSE
2620 if( ISLONGINT( origvreg.dtype ) )
then
2621 regTB(FB_DATACLASS_INTEGER)->free(
regTB(FB_DATACLASS_INTEGER), origvaux.reg )
2623 vr_dclass = typeGetClass( origvreg.dtype )
2624 regTB(vr_dclass)->free(
regTB(vr_dclass), origvreg.reg )
2631 byval reg
as integer _
2636 rvreg.typ = IR_VREGTYPE_REG
2637 rvreg.dtype = FB_DATATYPE_DOUBLE