20 dim as ASTNODE
ptr l =
any, r =
any, ll =
any
43 if( astIsBOP( n, AST_OP_ADD ) )
then
46 if( astIsUOP(
l, AST_OP_NEG )
and astIsCONST( r ) )
then
48 if( astIsVAR( ll ) )
then
62 byval n
as ASTNODE
ptr, _
63 byref accumval
as ASTNODE
ptr, _
64 byval sign
as integer _
67 dim as ASTNODE
ptr l =
any, r =
any
68 dim as integer dtype =
any, o =
any, rsign =
any
74 if( n->
class <> AST_NODECLASS_BOP )
then
81 case AST_OP_ADD, AST_OP_SUB
86 if( o = AST_OP_SUB )
then
92 if( astIsCONST( r ) )
then
97 if( o = AST_OP_ADD )
then
109 accumval =
astNewUOP( AST_OP_NEG, accumval )
131 byval n
as ASTNODE
ptr, _
132 byref accumval
as ASTNODE
ptr _
135 dim as ASTNODE
ptr l =
any, r =
any
136 dim as integer dtype =
any
142 if( astIsBOP( n, AST_OP_MUL ) )
then
146 if( astIsCONST( r ) )
then
149 accumval =
astNewBOP( AST_OP_MUL, accumval, r )
170 dim as ASTNODE
ptr l =
any, r =
any, accumval =
any
171 dim as integer o =
any
186 if( n->
class = AST_NODECLASS_BOP )
then
188 if( astIsCONST( r ) )
then
193 case AST_OP_ADD, AST_OP_SUB
218 dim as ASTNODE
ptr l =
any, r =
any, accumval =
any
233 if( n->
class = AST_NODECLASS_BOP )
then
239 select case as const astGetDataType( n )
240 case FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR, _
264 byval n
as ASTNODE
ptr, _
265 byref accumval
as ASTNODE
ptr _
268 dim as ASTNODE
ptr l =
any, r =
any
269 dim as integer dtype =
any
275 if( astIsBOP( n, AST_OP_ADD ) )
then
279 if( astIsCONST( r ) )
then
281 accumval =
astNewBOP( AST_OP_ADD, accumval, r )
301 dim as ASTNODE
ptr accumval =
any
369 if( n->
class = AST_NODECLASS_BOP )
then
370 if( astIsCONST( n->r ) )
then
371 if( n->op.op = AST_OP_MUL )
then
393 dim as integer optimize =
any, c =
any
394 dim as ASTNODE
ptr l = n->
l
405 if( astIsBOP(
l, AST_OP_MUL ) )
then
406 dim as ASTNODE
ptr lr =
l->r
407 if( astIsCONST( lr ) )
then
409 if( irGetOption( IR_OPT_ADDRCISC ) )
then
413 c = astConstGetInt( lr )
414 if( (c >= 1)
and (c <= 9) )
then
415 select case as const( c )
426 dim as FBSYMBOL
ptr s = astGetSymbol( n->r )
427 if( symbIsParam( s ) )
then
429 elseif( symbIsLocal( s ) )
then
430 if( symbIsStatic( s ) = FALSE )
then
457 if( (typeGetClass( astGetDataType(
l ) ) <> FB_DATACLASS_INTEGER)
or _
458 (typeGetSize( astGetDataType(
l ) ) <> env.pointersize) )
then
466 byval n
as ASTNODE
ptr, _
467 byval ofs
as longint _
470 select case as const n->
class
471 case AST_NODECLASS_VAR
475 case AST_NODECLASS_IDX
479 case AST_NODECLASS_DEREF
483 case AST_NODECLASS_LINK
484 if( n->link.ret_left )
then
490 case AST_NODECLASS_FIELD, AST_NODECLASS_IIF
493 case AST_NODECLASS_CONV
507 if (n->
cast.doconv = FALSE)
then
520 dim as ASTNODE
ptr l = n->
l
521 dim as longint ofs = 0
524 case AST_NODECLASS_OFFSET
529 case AST_NODECLASS_ADDROF
535 assert( astIsDEREF(n) )
550 dim as integer dtype = astGetFullType( n )
551 dim as FBSYMBOL
ptr subtype = n->subtype
563 dim as ASTNODE
ptr l =
any, r =
any, accumval =
any
564 dim as longint c =
any
583 case AST_NODECLASS_IDX, AST_NODECLASS_DEREF
590 if( n->
class = AST_NODECLASS_IDX )
then
591 n->idx.ofs += c * n->idx.mult
598 if( astIsCONST( n->
l ) )
then
601 if( n->
class = AST_NODECLASS_IDX )
then
602 n->idx.ofs += c * n->idx.mult
608 if( n->
class = AST_NODECLASS_IDX )
then
622 dim as ASTNODE
ptr l =
any
631 if( astIsFIELD( n ) )
then
698 dim as ASTNODE
ptr ll =
l->
l
700 if( astIsDEREF(
l )
and (ll <> NULL) )
then
701 if( ll->
class = AST_NODECLASS_BOP )
then
702 assert( astIsBOP( ll, AST_OP_ADD ) )
703 dim as ASTNODE
ptr lll = ll->
l
704 if( lll->
class = AST_NODECLASS_ADDROF )
then
705 dim as ASTNODE
ptr llll = lll->
l
706 if( astIsFIELD( llll ) )
then
707 dim as ASTNODE
ptr lllll = llll->
l
708 dim as ASTNODE
ptr llllll = lllll->
l
709 if( astIsDEREF( lllll )
and (llllll <> NULL) )
then
732 byval n
as ASTNODE
ptr _
735 dim as ASTNODE
ptr l =
any, r =
any, n_old =
any
736 dim as integer op =
any, rop =
any
743 if( n->
class = AST_NODECLASS_BOP )
then
746 case AST_OP_ADD, AST_OP_SUB
749 select case astGetDataType( n )
750 case FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR, _
755 if( r->
class = AST_NODECLASS_BOP )
then
758 case AST_OP_ADD, AST_OP_SUB
759 if( op = AST_OP_SUB )
then
760 if( rop = AST_OP_SUB )
then
766 if( rop = AST_OP_SUB )
then
806 byval n
as ASTNODE
ptr _
809 dim as ASTNODE
ptr l =
any, r =
any, n_old =
any
816 if( astIsBOP( n, AST_OP_MUL ) )
then
818 if( astIsBOP( r, AST_OP_MUL ) )
then
852 byval n
as ASTNODE
ptr, _
853 byval const_val
as integer _
856 dim as ASTNODE
ptr l =
any, l_cpy =
any
857 dim as integer dtype =
any, bits =
any
862 if(
l->
class <> AST_NODECLASS_VAR )
then
866 dtype = astGetFullType(
l )
868 bits = typeGetBits( dtype ) - 1
871 bits = typeGetBits( FB_DATATYPE_INTEGER ) - 1
876 if( const_val = 1 )
then
884 AST_CONVOPT_SIGNCONV )
895 AST_CONVOPT_SIGNCONV )
898 n->op.op = AST_OP_SHR
899 astConstGetInt( n->r ) = const_val
903 function hToPow2(
byval v
as ulongint )
as integer
905 for i
as integer = 1
to 63
906 if( v = (1ull
shl i) )
then
915 dim as ASTNODE
ptr l =
any, r =
any
916 dim as integer op =
any, exponent =
any
917 dim as longint value =
any
927 if( n->
class = AST_NODECLASS_BOP )
then
931 case AST_OP_MUL, AST_OP_INTDIV, AST_OP_MOD
935 if( typeGetClass( n->dtype ) <> FB_DATACLASS_INTEGER )
then
941 if( astIsCONST( r ) = FALSE )
then
944 value = astConstGetInt( r )
946 ((value < 0)
and typeIsSigned( astGetFullType( r ) )) )
then
952 if( exponent <= 0 )
then
958 if( exponent > typeGetBits( n->
l->dtype ) )
then
962 n->op.op = AST_OP_SHL
963 astConstGetInt( r ) = exponent
966 if( exponent > typeGetBits( n->
l->dtype ) )
then
970 if( typeIsSigned( n->
l->dtype ) = FALSE )
then
971 n->op.op = AST_OP_SHR
972 astConstGetInt( r ) = exponent
979 if( typeIsSigned( astGetDataType( n->
l ) ) )
then
983 n->op.op = AST_OP_AND
984 astConstGetInt( r ) -= 1
1005 byval n
as ASTNODE
ptr _
1008 dim as ASTNODE
ptr l =
any, r =
any
1009 dim as integer op =
any
1010 dim as longint v =
any
1011 dim as integer keep_l =
any, keep_r =
any
1047 if( n->
class = AST_NODECLASS_BOP )
then
1056 if( typeGetClass( astGetDataType( n ) ) = FB_DATACLASS_INTEGER )
then
1057 if( astIsCONST( r ) )
then
1058 v = astConstGetInt( r )
1060 select case as const op
1063 if( keep_l = FALSE )
then
1069 n->op.op = AST_OP_AND
1071 elseif( v = 1 )
then
1078 if( ( v = 1 )
or ( ( v = -1 )
and ( typeIsSigned( astGetDataType( r ) ) <> FALSE ) ) )
then
1079 if( keep_l = FALSE )
then
1080 astConstGetInt( r ) = 0
1095 case AST_OP_ADD, AST_OP_SUB, _
1096 AST_OP_SHR, AST_OP_SHL, _
1106 if( keep_l = FALSE )
then
1118 elseif( v = -1 )
then
1119 if( keep_l = FALSE )
then
1131 elseif( v = 0 )
then
1132 if( keep_l = FALSE )
then
1141 elseif( astIsCONST(
l ) )
then
1142 v = astConstGetInt(
l )
1144 select case as const op
1145 case AST_OP_MUL, AST_OP_INTDIV, AST_OP_MOD, _
1146 AST_OP_SHR, AST_OP_SHL
1148 if( keep_r = FALSE )
then
1166 byval n
as ASTNODE
ptr _
1169 dim as ASTNODE
ptr m =
any
1170 dim as ASTNODE
ptr l =
any, r =
any
1171 dim as integer op =
any
1172 dim as longint v =
any
1180 if(
l <> NULL )
then
1186 if( r <> NULL )
then
1191 if( typeGetClass( astGetDataType( n ) ) = FB_DATACLASS_INTEGER )
then
1192 if( astIsUOP( n, AST_OP_NOT ) )
then
1193 if( astIsUOP(
l, AST_OP_NOT ) )
then
1199 elseif( astIsBOP(
l, AST_OP_XOR ) )
then
1200 if( typeGetClass( astGetDataType( n ) ) = FB_DATACLASS_INTEGER )
then
1201 if( astIsCONST(
l->
l ) )
then
1204 astConstGetInt(
l->
l ) =
not astConstGetInt(
l->
l )
1207 elseif( astIsCONST(
l->r ) )
then
1210 astConstGetInt(
l->r ) =
not astConstGetInt(
l->r )
1216 elseif( n->
class = AST_NODECLASS_BOP )
then
1217 if( typeGetClass( astGetDataType( n ) ) = FB_DATACLASS_INTEGER )
then
1220 case AST_OP_OR, AST_OP_AND, AST_OP_XOR
1222 if( op = AST_OP_AND )
then
1224 elseif( op = AST_OP_OR )
then
1239 if( astIsUOP(
l, AST_OP_NOT)
and astIsUOP(r, AST_OP_NOT) )
then
1246 if( op <> AST_OP_XOR )
then
1263 elseif( astIsCONST(
l )
and astisUOP(r, AST_OP_NOT) )
then
1269 v = astConstGetInt(
l )
1271 astConstGetInt(
l ) =
not v
1273 if( op <> AST_OP_XOR )
then
1281 elseif( astIsConst( r )
and astIsUOP(
l, AST_OP_NOT) )
then
1287 v = astConstGetInt( r )
1289 astConstGetInt( r ) =
not v
1291 if( op <> AST_OP_XOR )
then
1299 elseif( (op = AST_OP_XOR)
and astIsUOP(
l, AST_OP_NOT) )
then
1306 elseif( (op = AST_OP_XOR)
and astIsUOP(r, AST_OP_NOT) )
then
1323 dim as ASTNODE
ptr l =
any, r =
any
1324 dim as integer dorem =
any
1349 if( n->
class = AST_NODECLASS_BOP )
then
1350 select case astGetDataType( n )
1351 case FB_DATATYPE_SINGLE, FB_DATATYPE_DOUBLE
1353 if( r->
class = AST_NODECLASS_CONV )
then
1355 if( n->
l->
class <> AST_NODECLASS_CONV )
then
1356 select case astGetDataType( r )
1357 case FB_DATATYPE_SINGLE, FB_DATATYPE_DOUBLE
1368 select case( typeGetSize( astGetDataType(
l ) ) )
1372 select case(
l->
class )
1373 case AST_NODECLASS_VAR, AST_NODECLASS_IDX, _
1374 AST_NODECLASS_FIELD, AST_NODECLASS_DEREF
1376 if( typeIsSigned( astGetDataType(
l ) ) )
then
1402 byval lnk
as ASTNODE
ptr, _
1403 byval dst
as ASTNODE
ptr, _
1404 byval n
as ASTNODE
ptr, _
1405 byval is_wstr
as integer _
1419 if( n->
l <> NULL )
then
1420 if( n->
l->
class = AST_NODECLASS_BOP )
then
1427 if( n->
class = AST_NODECLASS_BOP )
then
1428 if( n->
l <> NULL )
then
1430 if( lnk = NULL )
then
1431 if( is_wstr = FALSE )
then
1437 if( is_wstr = FALSE )
then
1449 if( n->r <> NULL )
then
1450 if( is_wstr = FALSE )
then
1465 if( lnk = NULL )
then
1466 if( is_wstr = FALSE )
then
1472 if( is_wstr = FALSE )
then
1491 byval l as ASTNODE
ptr, _
1492 byval r
as ASTNODE
ptr _
1495 dim as FBSYMBOL
ptr sym =
any
1499 if( r->
class = AST_NODECLASS_BOP )
then
1500 select case l->
class
1501 case AST_NODECLASS_VAR, AST_NODECLASS_IDX
1502 sym = astGetSymbol(
l )
1503 if( sym <> NULL )
then
1504 if (symbIsParamBydescOrByref(sym) = FALSE)
then
1509 case AST_NODECLASS_FIELD, AST_NODECLASS_IIF
1510 select case l->
l->
class
1511 case AST_NODECLASS_VAR, AST_NODECLASS_IDX
1515 sym = astGetSymbol(
l )
1516 if( sym <> NULL )
then
1527 byval n
as ASTNODE
ptr, _
1528 byval l as ASTNODE
ptr, _
1529 byval r
as ASTNODE
ptr _
1532 dim as integer optimize =
any, is_wstr =
any
1537 if( r->
class = AST_NODECLASS_BOP )
then
1538 dim as FBSYMBOL
ptr sym
1541 select case as const l->
class
1542 case AST_NODECLASS_VAR, AST_NODECLASS_IDX
1546 sym = astGetSymbol(
l )
1547 if( sym <> NULL )
then
1548 if (symbIsParamBydescOrByref(sym) = FALSE)
then
1554 case AST_NODECLASS_FIELD, AST_NODECLASS_IIF
1555 select case as const l->
l->
class
1556 case AST_NODECLASS_VAR, AST_NODECLASS_IDX
1559 sym = astGetSymbol(
l )
1560 if( sym <> NULL )
then
1569 is_wstr = ( astGetDataType( n ) = FB_DATATYPE_WCHAR )
1586 if( is_wstr = FALSE )
then
1602 if( is_wstr = FALSE )
then
1614 dim as ASTNODE
ptr l =
any, r =
any
1615 dim as integer dtype =
any, dclass =
any
1625 select case n->
class
1627 case AST_NODECLASS_ASSIGN
1630 case AST_NODECLASS_LINK, AST_NODECLASS_LOOP
1642 dtype = astGetFullType( n )
1645 select case typeGet( dtype )
1646 case FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR, _
1651 dclass = typeGetClass( dtype )
1652 if( dclass = FB_DATACLASS_INTEGER )
then
1653 if( irGetOption( IR_OPT_CPUSELFBOPS ) = FALSE )
then
1657 if( irGetOption( IR_OPT_FPUSELFBOPS ) = FALSE )
then
1659 if( astIsCONST( r ) )
then
1660 if( dclass = FB_DATACLASS_FPOINT )
then
1661 if( typeGetClass( astGetDataType( r ) ) <> FB_DATACLASS_FPOINT )
then
1672 if( typeGetSize( dtype ) = 1 )
then
1679 dim as ASTNODE
ptr t =
l
1680 if(
l->
class = AST_NODECLASS_CONV )
then
1681 if(
l->
cast.doconv = FALSE )
then
1686 select case as const t->
class
1687 case AST_NODECLASS_VAR, AST_NODECLASS_IDX, AST_NODECLASS_DEREF
1689 case AST_NODECLASS_FIELD, AST_NODECLASS_IIF
1691 if( astGetDataType( t->
l ) = FB_DATATYPE_BITFIELD )
then
1700 select case r->
class
1701 case AST_NODECLASS_UOP
1703 case AST_NODECLASS_BOP
1706 select case as const r->op.op
1707 case AST_OP_EQ, AST_OP_GT, AST_OP_LT, AST_OP_NE, AST_OP_LE, AST_OP_GE
1716 if( typeGetClass( astGetDataType( r ) ) <> FB_DATACLASS_INTEGER )
then
1726 r->op.options
and=
not AST_OPOPT_ALLOCRES
1744 byval n
as ASTNODE
ptr _
1751 dim as ASTNODE
ptr l =
any, r =
any
1752 dim as integer dtype =
any, dclass =
any
1760 if n->
class <> AST_NODECLASS_ASSIGN
then
1781 byval n
as ASTNODE
ptr _
1784 dim as ASTNODE
ptr l =
any, r =
any
1785 dim as integer dtype =
any, dclass =
any
1793 if n->
class <> AST_NODECLASS_BOP
then
1806 select case as const n->op.op
1807 case AST_OP_EQ, AST_OP_LE, AST_OP_GE
1809 case AST_OP_NE, AST_OP_GT, AST_OP_LT
1825 byval n
as ASTNODE
ptr _
1828 dim as ASTNODE
ptr l =
any, r =
any
1829 dim as single v =
Any
1836 if( astIsBOP( n, AST_OP_DIV ) )
then
1838 if( astIsCONST(
l ) )
then
1839 if( (astGetDataType(
l ) = FB_DATATYPE_SINGLE)
andalso (astConstGetFloat(
l ) = 1.0) )
then
1841 if( astIsUOP( r, AST_OP_SQRT ) )
then
1844 n->
class = AST_NODECLASS_UOP
1845 n->op.op = AST_OP_RSQRT
1848 elseif( astGetDataType( r ) = FB_DATATYPE_SINGLE )
then
1860 if(
l <> NULL )
then
1865 if( r <> NULL )
then
1876 var old_warn_convoverflow = ast.warn_convoverflow
1877 ast.warn_convoverflow = FALSE
1906 if( (irGetOption( IR_OPT_FPUCONV ) = FALSE)
and _
1907 (env.clopt.backend = FB_BACKEND_GAS) )
then
1911 if( irGetOption( IR_OPT_NOINLINEOPS ) = FALSE )
then
1912 if( env.clopt.fpmode = FB_FPMODE_FAST )
then
1917 ast.warn_convoverflow = old_warn_convoverflow