122 byval dtype as integer, _
123 byval subtype as FBSYMBOL
ptr _
126 declare sub hEmitStruct(
byval s
as FBSYMBOL
ptr,
byval is_ptr
as integer )
130 byval op as integer, _
131 byval proc as FBSYMBOL
ptr, _
132 byval ex
as integer _
144 dim shared as const zstring ptr dtypeName(0
to FB_DATATYPES-1) = _
178 irSetOption( IR_OPT_FPUIMMEDIATES
or IR_OPT_NOINLINEOPS )
181 if( fbCpuTypeIs64bit( ) )
then
295 byval s
as zstring ptr, _
296 byval noline
as integer =
FALSE _
301 if( env.clopt.debug
and (noline =
FALSE) )
then
319 hWriteLine(
"#define __FB_STATIC_ASSERT( expr ) extern int __$fb_structsizecheck[(expr) ? 1 : -1]", TRUE )
335 byref ln as string, _
336 byval proc as FBSYMBOL
ptr, _
337 byval in_front
as integer _
340 dim as integer priority =
any
342 if(
proc->stats
and (FB_SYMBSTATS_GLOBALCTOR
or FB_SYMBSTATS_GLOBALDTOR) )
then
343 if( in_front =
FALSE )
then
346 ln +=
"__attribute__(( "
347 if(
proc->stats
and FB_SYMBSTATS_GLOBALCTOR )
then
353 priority = symbGetProcPriority(
proc )
354 if( priority <> 0 )
then
355 ln +=
"( " +
str( priority ) +
" )"
367 byval proc as FBSYMBOL
ptr, _
371 dim as string ln, mangled
373 if( options = 0 )
then
379 if( env.clopt.
export and (env.target.options
and FB_TARGETOPT_EXPORT) )
then
380 if( symbIsExport(
proc ) )
then
381 ln +=
"__declspec( dllexport ) "
385 if( symbIsPrivate(
proc ) )
then
392 symbGetProcRealSubtype(
proc ) )
408 if( fbCpuTypeIsX86( ) )
then
409 select case( symbGetProcMode(
proc ) )
410 case FB_FUNCMODE_STDCALL, FB_FUNCMODE_STDCALL_MS, FB_FUNCMODE_PASCAL
411 select case( env.clopt.target )
412 case FB_COMPTARGET_WIN32, FB_COMPTARGET_XBOX
417 ln +=
" __attribute__((stdcall))"
439 dim as FBSYMBOL
ptr hidden = NULL
442 hidden = symbGetSubType(
proc )
443 ln +=
hEmitType( typeAddrOf( symbGetType( hidden ) ), hidden )
446 ln +=
hEmitType( typeAddrOf( symbGetType( hidden ) ), symbGetSubtype( hidden ) )
450 if( symbGetProcParams(
proc ) > 0 )
then
457 if( (hidden = NULL)
and (
param = NULL) )
then
462 if( symbGetParamMode(
param ) = FB_PARAMMODE_VARARG )
then
489 select case( symbGetProcMode(
proc ) )
490 case FB_FUNCMODE_STDCALL_MS, FB_FUNCMODE_PASCAL
494 if( env.target.options
and FB_TARGETOPT_UNDERSCORE )
then
495 mangled =
"_" + mangled
497 ln +=
" asm(""" + mangled +
""")"
508 if( symbIsStruct(
sym ) )
then
509 if( symbGetUDTIsUnion(
sym ) )
then
530 symbSetIsEmitted( s )
541 sub hEmitUDT(
byval s
as FBSYMBOL
ptr,
byval is_ptr
as integer )
548 if( symbGetIsEmitted( s ) )
then
552 if( symbIsLocal( s ) )
then
555 section = 1 + symbGetScope( s )
560 if( symbGetScope( s ) = FB_MAINSCOPE )
then
578 select case as const symbGetClass( s )
579 case FB_SYMBCLASS_ENUM
582 case FB_SYMBCLASS_STRUCT
585 case FB_SYMBCLASS_PROC
586 if( symbGetIsFuncPtr( s ) )
then
588 symbSetIsEmitted( s )
603 select case( symbGetClass(
sym ) )
604 case FB_SYMBCLASS_VAR, FB_SYMBCLASS_FIELD
605 if( (symbGetIsDynamic(
sym ) =
FALSE)
and _
606 (symbGetArrayDimensions(
sym ) <> 0) )
then
607 dim as FBVARDIM
ptr d = symbGetArrayFirstDim(
sym )
610 s +=
"[" +
str( d->upper - d->lower + 1 ) +
"]"
618 dim as longint length = 0
619 select case( symbGetType(
sym ) )
620 case FB_DATATYPE_FIXSTR, FB_DATATYPE_CHAR
621 length = symbGetStrLen(
sym )
622 case FB_DATATYPE_WCHAR
623 length = symbGetWstrLen(
sym )
625 if( length > 0 )
then
626 s +=
"[" +
str( length ) +
"]"
636 if( symbGetIsAccessed(
sym ) =
FALSE )
then
638 if( symbIsExtern(
sym ) )
then
644 if( ((symbGetAttrib(
sym )
and (FB_SYMBATTRIB_COMMON
or FB_SYMBATTRIB_PUBLIC
or FB_SYMBATTRIB_EXTERN)) = 0)
and _
645 ((
not symbIsLocal(
sym ))
or symbIsStatic(
sym )) )
then
653 if( symbIsImport(
sym ) )
then
654 ln +=
" __attribute__((dllimport))"
658 if( symbGetAttrib(
sym )
and (FB_SYMBATTRIB_COMMON
or FB_SYMBATTRIB_PUBLIC
or FB_SYMBATTRIB_EXTERN) )
then
660 if( symbIsCommon(
sym ) )
then
661 ln +=
" __attribute__((common))"
662 elseif( symbIsExtern(
sym ) )
then
677 if( symbGetVarIsAllocated( s ) )
then
681 symbSetVarIsAllocated( s )
684 if( symbGetIsLiteral( s ) )
then
689 if( symbGetIsInitialized( s )
and (symbIsLocal( s ) =
FALSE or symbIsStatic( s )) )
then
691 if( symbIsExtern( s ) )
then
696 if( symbIsLocal( s ) =
FALSE )
then
697 if( symbGetIsAccessed( s ) =
FALSE )
then
699 if( symbIsPublic( s ) =
FALSE )
then
705 astTypeIniFlush( s->var_.initree, s, AST_INIOPT_ISINI
or AST_INIOPT_ISSTATIC )
707 s->var_.initree = NULL
712 if( symbGetIsDynamic( s ) )
then
717 if( symbGetLen( s ) <= 0 )
then
725 dim as integer count =
any
726 dim as FBSYMBOL
ptr param =
any
733 params +=
"temp_ppparam$" +
str( count )
745 hWriteLine(
"#define " + params +
" __builtin_" + params, TRUE )
751 if( symbGetIsAccessed( s ) =
FALSE )
then
761 if( symbGetIsIrHlcBuiltin( s ) )
then
769 if( symbGetIsGccBuiltin( s ) )
then
780 byval fld
as FBSYMBOL
ptr _
781 )
as FBSYMBOL
ptr ptr
783 dim as FBSYMBOL
ptr ptr anonnode =
any
784 dim as FBSYMBOL
ptr parent =
any
792 if( *anonnode =
parent )
then
806 byval baseparent
as FBSYMBOL
ptr, _
807 byval parent as FBSYMBOL
ptr _
810 if(
parent = baseparent )
then
818 assert( symbIsStruct(
parent ) )
819 if( symbGetUDTIsUnion(
parent ) )
then
839 byval s
as FBSYMBOL
ptr, _
840 byval is_ptr
as integer _
844 dim as integer skip =
any,
dtype =
any, align =
any
845 dim as FBSYMBOL
ptr subtype =
any, fld =
any
846 dim as FBSYMBOL
ptr ptr anonnode =
any
849 if( symbGetIsBeingEmitted( s ) )
then
857 if( symbGetIsAccessed( s ) =
FALSE )
then
858 symbSetIsAccessed( s )
865 symbSetIsBeingEmitted( s )
870 hEmitUDT( symbGetSubtype( fld ), typeIsPtr( symbGetType( fld ) ) )
876 if( symbGetIsEmitted( s ) )
then
881 symbSetIsEmitted( s )
889 if( (env.clopt.target = FB_COMPTARGET_WIN32)
and _
890 (symbGetUDTAlign( s ) > 0) )
then
891 ln +=
"__attribute__((gcc_struct)) "
903 if( fld->
parent = s )
then
934 if( symbGetType( fld ) = FB_DATATYPE_BITFIELD )
then
935 skip = (symbGetSubtype( fld )->bitfld.bitpos <> 0)
940 if( skip =
FALSE )
then
941 dtype = symbGetType( fld )
942 subtype = symbGetSubtype( fld )
944 ln +=
" " + *symbGetName( fld )
948 align = symbGetUDTAlign( s )
958 if( typeGet(
dtype ) = FB_DATATYPE_STRUCT )
then
959 skip
or= (align >= symbGetUDTAlign(
subtype ))
962 if( skip =
FALSE )
then
963 ln +=
" __attribute__((packed, aligned(" +
str( align ) +
")))"
982 symbResetIsBeingEmitted( s )
992 sub hEmitDecls(
byval s
as FBSYMBOL
ptr,
byval procs
as integer )
994 select case as const( symbGetClass( s ) )
995 case FB_SYMBCLASS_NAMESPACE
996 hEmitDecls( symbGetNamespaceTbHead( s ), procs )
998 case FB_SYMBCLASS_STRUCT
999 hEmitDecls( symbGetCompSymbTb( s ).head, procs )
1001 case FB_SYMBCLASS_SCOPE
1002 hEmitDecls( symbGetScopeSymbTbHead( s ), procs )
1004 case FB_SYMBCLASS_VAR
1011 if( symbGetType( s ) = FB_DATATYPE_STRUCT )
then
1012 if( symbGetSubtype( s ) = ast.
data.desc )
then
1019 case FB_SYMBCLASS_PROC
1020 if( procs =
FALSE )
then
1024 if( symbGetIsFuncPtr( s ) =
FALSE )
then
1035 var s = astGetLastDataStmtSymbol( )
1036 do while( s <> NULL )
1038 s = s->var_.
data.prev
1044 byref fname
as string, _
1045 byval rtype
as integer, _
1046 byval ptype
as integer _
1049 dim as string rtype_str, rtype_suffix
1051 case FB_DATATYPE_LONG
1054 case FB_DATATYPE_LONGINT
1059 dim as string ptype_str, ptype_suffix
1061 case FB_DATATYPE_SINGLE
1065 case FB_DATATYPE_DOUBLE
1066 ptype_str =
"double"
1070 if( env.clopt.asmsyntax = FB_ASMSYNTAX_INTEL )
then
1076 hWriteLine(
"static inline " + rtype_str +
" fb_" + fname +
"( " + ptype_str +
" value )", TRUE )
1079 hWriteLine(
"volatile " + rtype_str +
" result;", TRUE )
1082 hWriteLine(
"""fld" + ptype_suffix +
" %1;""" , TRUE )
1083 hWriteLine(
"""fistp" + rtype_suffix +
" %0;""", TRUE )
1096 byref fname
as string, _
1097 byval rtype
as integer, _
1098 byval ptype
as integer _
1101 dim as string resulttype, callname
1104 case FB_DATATYPE_LONG
1105 resulttype =
"int32"
1106 case FB_DATATYPE_LONGINT
1107 resulttype =
"int64"
1111 case FB_DATATYPE_SINGLE
1113 case FB_DATATYPE_DOUBLE
1117 hWriteLine(
"#define fb_" + fname +
"( value ) ((" + resulttype +
")__builtin_" + callname +
"( value ))", TRUE )
1123 byref fname
as string, _
1124 byval rtype
as integer, _
1125 byval ptype
as integer _
1128 if( fbCpuTypeIsX86( ) )
then
1158 if( symbGetIsAccessed( PROCLOOKUP( FTOSL ) )
or _
1159 symbGetIsAccessed( PROCLOOKUP( FTOUL ) )
or _
1160 symbGetIsAccessed( PROCLOOKUP( FTOUI ) ) )
then
1161 hWriteFTOI(
"ftosl", FB_DATATYPE_LONGINT, FB_DATATYPE_SINGLE )
1164 if( symbGetIsAccessed( PROCLOOKUP( FTOUL ) ) )
then
1165 hWriteLine(
"#define fb_ftoul( v ) ((uint64)fb_ftosl( v ))", TRUE )
1168 if( symbGetIsAccessed( PROCLOOKUP( FTOUI ) ) )
then
1169 hWriteLine(
"#define fb_ftoui( v ) ((uint32)fb_ftosl( v ))", TRUE )
1172 if( symbGetIsAccessed( PROCLOOKUP( FTOSI ) )
or _
1173 symbGetIsAccessed( PROCLOOKUP( FTOSS ) )
or _
1174 symbGetIsAccessed( PROCLOOKUP( FTOUS ) )
or _
1175 symbGetIsAccessed( PROCLOOKUP( FTOSB ) )
or _
1176 symbGetIsAccessed( PROCLOOKUP( FTOUB ) ) )
then
1177 hWriteFTOI(
"ftosi", FB_DATATYPE_LONG, FB_DATATYPE_SINGLE )
1180 if( symbGetIsAccessed( PROCLOOKUP( FTOSS ) ) )
then
1181 hWriteLine(
"#define fb_ftoss( v ) ((int16)fb_ftosi( v ))", TRUE )
1184 if( symbGetIsAccessed( PROCLOOKUP( FTOUS ) ) )
then
1185 hWriteLine(
"#define fb_ftous( v ) ((uint16)fb_ftosi( v ))", TRUE )
1188 if( symbGetIsAccessed( PROCLOOKUP( FTOSB ) ) )
then
1189 hWriteLine(
"#define fb_ftosb( v ) ((int8)fb_ftosi( v ))", TRUE )
1192 if( symbGetIsAccessed( PROCLOOKUP( FTOUB ) ) )
then
1193 hWriteLine(
"#define fb_ftoub( v ) ((uint8)fb_ftosi( v ))", TRUE )
1197 if( symbGetIsAccessed( PROCLOOKUP( DTOSL ) )
or _
1198 symbGetIsAccessed( PROCLOOKUP( DTOUL ) )
or _
1199 symbGetIsAccessed( PROCLOOKUP( DTOUI ) ) )
then
1200 hWriteFTOI(
"dtosl", FB_DATATYPE_LONGINT, FB_DATATYPE_DOUBLE )
1203 if( symbGetIsAccessed( PROCLOOKUP( DTOUL ) ) )
then
1204 hWriteLine(
"#define fb_dtoul( v ) ((uint64)fb_dtosl( v ))", TRUE )
1207 if( symbGetIsAccessed( PROCLOOKUP( DTOUI ) ) )
then
1208 hWriteLine(
"#define fb_dtoui( v ) ((uint32)fb_dtosl( v ))", TRUE )
1211 if( symbGetIsAccessed( PROCLOOKUP( DTOSI ) )
or _
1212 symbGetIsAccessed( PROCLOOKUP( DTOSS ) )
or _
1213 symbGetIsAccessed( PROCLOOKUP( DTOUS ) )
or _
1214 symbGetIsAccessed( PROCLOOKUP( DTOSB ) )
or _
1215 symbGetIsAccessed( PROCLOOKUP( DTOUB ) ) )
then
1216 hWriteFTOI(
"dtosi", FB_DATATYPE_LONG, FB_DATATYPE_DOUBLE )
1219 if( symbGetIsAccessed( PROCLOOKUP( DTOSS ) ) )
then
1220 hWriteLine(
"#define fb_dtoss( v ) ((int16)fb_dtosi( v ))", TRUE )
1223 if( symbGetIsAccessed( PROCLOOKUP( DTOUS ) ) )
then
1224 hWriteLine(
"#define fb_dtous( v ) ((uint16)fb_dtosi( v ))", TRUE )
1227 if( symbGetIsAccessed( PROCLOOKUP( DTOSB ) ) )
then
1228 hWriteLine(
"#define fb_dtosb( v ) ((int8)fb_dtosi( v ))", TRUE )
1231 if( symbGetIsAccessed( PROCLOOKUP( DTOUB ) ) )
then
1232 hWriteLine(
"#define fb_dtoub( v ) ((uint8)fb_dtosi( v ))", TRUE )
1244 env.outf.num =
freefile
1245 if(
open( env.outf.
name,
for binary,
access read write,
as #env.outf.num ) <> 0 )
then
1258 if( env.clopt.debug )
then
1259 _emitDBG( AST_OP_DBG_LINEINI, NULL, 0 )
1262 hWriteLine(
"// Compilation of " + env.inf.
name +
" started at " +
time( ) +
" on " +
date( ), TRUE )
1265 hWriteLine(
"typedef signed char int8;", TRUE )
1266 hWriteLine(
"typedef unsigned char uint8;", TRUE )
1267 hWriteLine(
"typedef signed short int16;", TRUE )
1268 hWriteLine(
"typedef unsigned short uint16;", TRUE )
1269 hWriteLine(
"typedef signed int int32;", TRUE )
1270 hWriteLine(
"typedef unsigned int uint32;", TRUE )
1271 hWriteLine(
"typedef signed long long int64;", TRUE )
1272 hWriteLine(
"typedef unsigned long long uint64;", TRUE )
1273 if( fbCpuTypeIs64bit( ) )
then
1274 hWriteLine(
"typedef struct { char *data; int64 len; int64 size; } FBSTRING;", TRUE )
1276 hWriteLine(
"typedef struct { char *data; int32 len; int32 size; } FBSTRING;", TRUE )
1319 hWriteLine(
"// Total compilation time: " +
str( tottime ) +
" seconds.", TRUE )
1328 if(
close( #env.outf.num ) <> 0 )
then
1338 if( cachenode = NULL )
then
1346 if( node = NULL )
then
1356 byval opt
as IR_OPTIONVALUE _
1360 case IR_OPTIONVALUE_MAXMEMBLOCKLEN
1371 proc->
proc.ext->dbg.iniline = lexLineNum( )
1375 proc->
proc.ext->dbg.endline = lexLineNum( )
1385 dim as FBSYMBOL
ptr desc =
any
1401 select case( symbGetClass(
sym ) )
1403 case FB_SYMBCLASS_SCOPE
1407 case FB_SYMBCLASS_VAR
1429 desc = symbGetArrayDescriptor(
sym )
1447 byval dtype as integer, _
1448 byval subtype as FBSYMBOL
ptr, _
1449 byval vtype
as integer _
1452 dim as IRVREG
ptr v =
any
1471 byval dtype as integer, _
1472 byval subtype as FBSYMBOL
ptr _
1481 byval dtype as integer, _
1482 byval subtype as FBSYMBOL
ptr, _
1483 byval value
as longint _
1486 dim as IRVREG
ptr vr =
any
1496 byval dtype as integer, _
1497 byval subtype as FBSYMBOL
ptr, _
1498 byval value
as double _
1501 dim as IRVREG
ptr vr =
any
1512 byval dtype as integer, _
1513 byval subtype as FBSYMBOL
ptr, _
1514 byval symbol
as FBSYMBOL
ptr, _
1515 byval ofs
as longint _
1530 byval dtype as integer, _
1531 byval subtype as FBSYMBOL
ptr, _
1532 byval symbol
as FBSYMBOL
ptr, _
1533 byval ofs
as longint, _
1534 byval mult
as integer, _
1535 byval vidx
as IRVREG
ptr _
1551 byval dtype as integer, _
1552 byval subtype as FBSYMBOL
ptr, _
1553 byval ofs
as longint, _
1554 byval vidx
as IRVREG
ptr _
1569 byval dtype as integer, _
1570 byval subtype as FBSYMBOL
ptr, _
1571 byval symbol
as FBSYMBOL
ptr, _
1572 byval ofs
as longint _
1587 byval vreg
as IRVREG
ptr, _
1588 byval dtype as integer, _
1589 byval subtype as FBSYMBOL
ptr _
1592 if( vreg <> NULL )
then
1600 if( vreg = NULL )
then
1605 if( vreg->typ = IR_VREGTYPE_REG )
then
1606 if( vreg->reg <> INVALID )
then
1615 if( vreg->vidx <> NULL )
then
1622 byval dtype as integer, _
1623 byval subtype as FBSYMBOL
ptr _
1627 dim as integer ptrcount =
any
1629 ptrcount = typeGetPtrCnt(
dtype )
1632 select case as const(
dtype )
1633 case FB_DATATYPE_STRUCT, FB_DATATYPE_ENUM
1637 elseif(
dtype = FB_DATATYPE_ENUM )
then
1643 case FB_DATATYPE_FUNCTION
1644 assert( ptrcount > 0 )
1649 case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
1654 case FB_DATATYPE_FIXSTR
1659 case FB_DATATYPE_BITFIELD
1666 if( ptrcount > 0 )
then
1667 s +=
string( ptrcount,
"*" )
1675 byval class_
as integer, _
1676 byval dtype as integer, _
1677 byval subtype as FBSYMBOL
ptr _
1709 byval dtype as integer, _
1710 byval subtype as FBSYMBOL
ptr, _
1711 byval s
as zstring ptr _
1724 byval i
as longint, _
1732 if( typeGetSize(
dtype ) = 8 )
then
1733 dtype =
iif( typeIsSigned(
dtype ), FB_DATATYPE_LONGINT, FB_DATATYPE_ULONGINT )
1735 dtype =
iif( typeIsSigned(
dtype ), FB_DATATYPE_LONG, FB_DATATYPE_ULONG )
1746 byval f as double, _
1747 byval dtype as integer _
1760 if( symbIsParamBydescOrByref(
sym ) )
then
1764 select case( symbGetClass(
sym ) )
1765 case FB_SYMBCLASS_VAR, FB_SYMBCLASS_FIELD
1767 if( symbGetIsDynamic(
sym ) )
then
1771 if( symbGetArrayDimensions(
sym ) <> 0 )
then
1779 select case( symbGetType(
sym ) )
1780 case FB_DATATYPE_FIXSTR, FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
1789 byval dtype as integer, _
1790 byval subtype as FBSYMBOL
ptr, _
1803 if( (typeGetClass(
l->
dtype ) = typeGetClass(
dtype ))
and _
1804 (typeIsSigned(
l->
dtype ) = typeIsSigned(
dtype ))
and _
1805 (
not typeIsPtr(
l->
dtype ))
and (
not typeIsPtr(
dtype ))
and _
1806 (typeGetSize(
l->
dtype ) = typeGetSize(
dtype )) )
then
1813 if( (typeGetPtrCnt(
dtype ) > 0)
and (typeGetPtrCnt(
l->
dtype ) > 0) )
then
1828 dim as integer dtype =
any
1829 dim as FBSYMBOL
ptr subtype =
any
1831 if( symbIsLabel(
sym ) )
then
1835 dtype = typeAddrOf( FB_DATATYPE_VOID )
1837 elseif( symbIsProc(
sym ) )
then
1842 dtype = typeAddrOf( FB_DATATYPE_FUNCTION )
1845 dtype = FB_DATATYPE_INVALID
1857 if(
dtype = FB_DATATYPE_INVALID )
then
1866 byval op as integer, _
1867 byval a
as integer, _
1868 byval asubtype
as FBSYMBOL
ptr, _
1869 byval b
as integer, _
1870 byval bsubtype
as FBSYMBOL
ptr _
1875 case AST_OP_EQ, AST_OP_NE, AST_OP_GT, AST_OP_LT, AST_OP_GE, AST_OP_LE
1876 return FB_DATATYPE_LONG
1896 if( (a = FB_DATATYPE_DOUBLE)
or (b = FB_DATATYPE_DOUBLE) )
then
1897 return FB_DATATYPE_DOUBLE
1899 if( (a = FB_DATATYPE_SINGLE)
or (b = FB_DATATYPE_SINGLE) )
then
1900 return FB_DATATYPE_SINGLE
1905 if( typeGetSize( a ) <= 4 )
then
1906 a =
iif( typeIsSigned( a ), FB_DATATYPE_LONG, FB_DATATYPE_ULONG )
1908 if( typeGetSize( b ) <= 4 )
then
1909 b =
iif( typeIsSigned( b ), FB_DATATYPE_LONG, FB_DATATYPE_ULONG )
1913 if( (
not typeIsSigned( a ))
or (
not typeIsSigned( b )) )
then
1920 if( (typeGetSize( a ) = 8)
or (typeGetSize( b ) = 8) )
then
1921 a =
iif( typeIsSigned( a ), FB_DATATYPE_LONGINT, FB_DATATYPE_ULONGINT )
1922 b =
iif( typeIsSigned( b ), FB_DATATYPE_LONGINT, FB_DATATYPE_ULONGINT )
1926 if( (
not typeIsSigned( a ))
or (
not typeIsSigned( b )) )
then
1936 byval op as integer, _
1941 dim as integer dtype =
any, solved_out =
any
1952 solved_out = (
l->
op = AST_OP_DEREF)
1962 solved_out = (
l->
op = AST_OP_ADDROF)
1966 assert( typeGetPtrCnt(
dtype ) > 0 )
1969 case AST_OP_NEG, AST_OP_NOT
1974 solved_out = (
l->
op =
op)
1983 if( solved_out )
then
1998 byval op as integer, _
2004 dim as integer dtype =
any
2043 function = entry->
expr
2052 byval dtype as integer, _
2053 byval value
as longint _
2058 if( typeIsSigned(
dtype ) )
then
2065 if( typeGetSize(
dtype ) = 8 )
then
2066 if( value = -9223372036854775808ull )
then
2071 if( value = -2147483648u )
then
2076 if( typeGetSize(
dtype ) = 8 )
then
2077 s =
str(
culngint( value ) ) +
"ull"
2079 s =
str(
culng( value ) ) +
"u"
2088 byval dtype as integer, _
2089 byval value
as double _
2093 dim as ulong expval =
any
2096 expval =
cast(
ulong ptr, @value )[1]
2098 select case( expval )
2100 case &h7FF00000UL, &hFFF00000UL
2101 if(
dtype = FB_DATATYPE_DOUBLE )
then
2102 if( expval
and &h80000000ul )
then
2103 s +=
"(-__builtin_inf())"
2105 s +=
"__builtin_inf()"
2108 if( expval
and &h80000000ul )
then
2109 s +=
"(-__builtin_inff())"
2111 s +=
"__builtin_inff()"
2116 case &h7FF80000UL, &hFFF80000UL
2117 if(
dtype = FB_DATATYPE_DOUBLE )
then
2118 if( expval
and &h80000000ul )
then
2119 s +=
"(-__builtin_nan( """" ))"
2121 s +=
"__builtin_nan( """" )"
2124 if( expval
and &h80000000ul )
then
2125 s +=
"(-__builtin_nanf( """" ))"
2127 s +=
"__builtin_nanf( """" )"
2132 if(
dtype = FB_DATATYPE_DOUBLE )
then
2135 s =
str(
csng( value ) )
2141 if(
instr( s,
any "e." ) = 0 )
then
2146 if(
dtype = FB_DATATYPE_SINGLE )
then
2157 byref ln as string, _
2158 byval z
as zstring ptr, _
2159 byval length
as longint _
2162 dim as integer ch =
any
2176 for i
as integer = 0
to length - 2
2181 ln += $
"\x" +
hex( ch, 2 )
2190 elseif( ch =
asc(
"?" ) )
then
2194 if( (*z)[i+1] =
asc(
"?" ) )
then
2195 assert( (i+2) < length )
2196 select case( (*z)[i+2] )
2197 case asc(
"=" ),
asc(
"/" ),
asc(
"'" ), _
2198 asc(
"(" ),
asc(
")" ),
asc(
"!" ), _
2199 asc(
"<" ),
asc(
">" ),
asc(
"-" )
2215 byref ln as string, _
2216 byval w
as wstring ptr, _
2217 byval length
as longint _
2220 dim as integer ch =
any
2221 dim as integer wcharsize =
any
2226 wcharsize = typeGetSize( FB_DATATYPE_WCHAR )
2230 for i
as integer = 0
to length - 2
2234 ln += $
"\x" +
hex( ch, wcharsize * 2 )
2238 elseif( ch =
asc(
"?" ) )
then
2240 if( (*w)[i+1] =
asc(
"?" ) )
then
2241 assert( (i+2) < length )
2242 select case( (*w)[i+2] )
2243 case asc(
"=" ),
asc(
"/" ),
asc(
"'" ), _
2244 asc(
"(" ),
asc(
")" ),
asc(
"!" ), _
2245 asc(
"<" ),
asc(
">" ),
asc(
"-" )
2258 select case as const(
op )
2299 dim as FBSYMBOL
ptr sym =
any
2301 select case as const( n->
class )
2306 if( typeGetClass( n->
dtype ) = FB_DATACLASS_FPOINT )
then
2316 if( symbGetIsLiteral(
sym ) )
then
2317 if( symbGetType(
sym ) = FB_DATATYPE_WCHAR )
then
2323 if( symbIsLabel(
sym ) )
then
2325 elseif( symbIsProc(
sym ) )
then
2338 select case( n->
op )
2354 if( need_parens )
then
2358 if( need_parens )
then
2367 if( need_parens )
then
2373 if( need_parens )
then
2383 byval need_parens
as integer =
FALSE _
2396 static as integer level
2401 select case as const( n->
class )
2403 s =
"TEXT( " + *n->
text +
" )"
2406 if( typeGetClass( n->
dtype ) = FB_DATACLASS_FPOINT )
then
2416 if( symbGetIsLiteral( n->
sym ) )
then
2417 if( symbGetType( n->
sym ) = FB_DATATYPE_WCHAR )
then
2423 if( symbIsLabel( n->
sym ) )
then
2425 elseif( symbIsProc( n->
sym ) )
then
2438 select case( n->
op )
2459 select case( n->
class )
2473 byval sym as FBSYMBOL
ptr, _
2474 byval ofs
as longint _
2483 symbIsProc(
sym )
or symbIsLabel(
sym )) =
FALSE )
then
2499 byval vreg
as IRVREG
ptr, _
2500 byval is_lvalue
as integer =
FALSE _
2504 dim as integer dtype =
any, have_offset =
any
2505 dim as FBSYMBOL
ptr subtype =
any
2507 select case as const( vreg->typ )
2508 case IR_VREGTYPE_VAR, IR_VREGTYPE_IDX, IR_VREGTYPE_PTR
2509 if( vreg->
sym = NULL )
then
2519 if( vreg->vidx )
then
2523 if( vreg->ofs <> 0 )
then
2537 assert( symbIsProc( vreg->
sym ) =
FALSE )
2538 assert( symbIsLabel( vreg->
sym ) =
FALSE )
2564 have_offset = ((vreg->ofs <> 0)
or (vreg->vidx <> NULL))
2572 dim as integer do_deref = have_offset
or is_carray
2574 dim as integer is_ptr = typeIsPtr( symbGetType( vreg->
sym ) )
2575 dim as integer symdtype = symbGetType( vreg->
sym )
2576 dim as FBSYMBOL
ptr symsubtype = symbGetSubtype( vreg->
sym )
2579 if( symbIsParamByRef( vreg->
sym )
or symbIsImport( vreg->
sym )
or is_carray )
then
2581 symdtype = typeAddrOf( symdtype )
2587 if( (vreg->
dtype <> symdtype)
or (vreg->
subtype <> symsubtype) )
then
2592 do_deref
or= (typeGetClass( vreg->
dtype ) <> typeGetClass( symdtype ))
2595 select case( typeGet( vreg->
dtype ) )
2596 case FB_DATATYPE_STRING, FB_DATATYPE_STRUCT
2599 select case( typeGet( symdtype ) )
2600 case FB_DATATYPE_STRING, FB_DATATYPE_STRUCT
2606 if( do_deref =
FALSE )
then
2614 if( is_ptr =
FALSE )
then
2617 if( have_offset )
then
2620 if( vreg->vidx <> NULL )
then
2623 if( vreg->ofs <> 0 )
then
2634 case IR_VREGTYPE_OFS
2639 case IR_VREGTYPE_IMM
2651 if( typeGetClass(
dtype ) = FB_DATACLASS_FPOINT )
then
2657 case IR_VREGTYPE_REG
2672 if( is_lvalue =
FALSE )
then
2690 byval vr as IRVREG
ptr, _
2692 byval has_sidefx
as integer =
FALSE _
2695 static as string ln, tempvar
2698 if( irIsREG(
vr ) )
then
2699 if( has_sidefx )
then
2715 tempvar =
"vr$" +
str(
vr->reg )
2718 ln +=
" " + tempvar +
" = "
2744 if( typeIsPtr(
l->
dtype )
or typeIsPtr(
r->
dtype ) )
then
2761 byval op as integer, _
2762 byval v1
as IRVREG
ptr, _
2763 byval v2
as IRVREG
ptr, _
2764 byval vr as IRVREG
ptr, _
2765 byval ex
as FBSYMBOL
ptr _
2777 select case as const(
op )
2778 case AST_OP_EQ, AST_OP_NE, AST_OP_GT, AST_OP_LT, AST_OP_GE, AST_OP_LE
2779 if(
vr = NULL )
then
2792 if(
vr = NULL )
then
2796 select case as const(
op )
2797 case AST_OP_EQ, AST_OP_NE, AST_OP_GT, AST_OP_LT, AST_OP_GE, AST_OP_LE
2802 case AST_OP_ADD, AST_OP_SUB, AST_OP_MUL, AST_OP_DIV, AST_OP_INTDIV, _
2803 AST_OP_MOD, AST_OP_SHL, AST_OP_SHR, AST_OP_AND, AST_OP_OR, _
2805 dim as integer is_ptr_arith = ((
op = AST_OP_ADD)
or (
op = AST_OP_SUB))
2808 if( is_ptr_arith
and typeIsPtr( v1->
dtype ) )
then
2811 if( is_ptr_arith
and typeIsPtr( v2->
dtype ) )
then
2818 if(
op = AST_OP_DIV )
then
2840 byval op as integer, _
2841 byval v1
as IRVREG
ptr, _
2842 byval vr as IRVREG
ptr _
2848 if(
vr = NULL )
then
2877 byval op as integer, _
2878 byval v1
as IRVREG
ptr, _
2879 byval vr as IRVREG
ptr _
2890 if( (v1->typ = IR_VREGTYPE_VAR)
and (v1->
sym <> NULL) )
then
2891 if( symbIsLabel( v1->
sym ) )
then
2923 byref s
as string, _
2924 byval bytestopop
as integer, _
2925 byval vr as IRVREG
ptr, _
2926 byval level as integer _
2941 if( arg->
param andalso (arg->
param->
param.mode <> FB_PARAMMODE_VARARG) )
then
2966 if(
vr = NULL )
then
2978 byval proc as FBSYMBOL
ptr, _
2979 byval bytestopop
as integer, _
2980 byval vr as IRVREG
ptr, _
2981 byval level as integer _
2993 byval v1
as IRVREG
ptr, _
2994 byval vr as IRVREG
ptr, _
2995 byval bytestopop
as integer, _
2996 byval level as integer _
3011 assert(
op = AST_OP_JMP )
3017 byval v1
as IRVREG
ptr, _
3018 byval tbsym
as FBSYMBOL
ptr, _
3019 byval values
as ulongint ptr, _
3020 byval labels
as FBSYMBOL
ptr ptr, _
3021 byval labelcount
as integer, _
3022 byval deflabel
as FBSYMBOL
ptr, _
3023 byval minval
as ulongint, _
3024 byval maxval
as ulongint _
3027 dim as string tb, temp,
ln
3028 dim as FBSYMBOL
ptr label =
any
3030 dim as integer i =
any
3033 assert( v1->typ = IR_VREGTYPE_VAR )
3036 if( labelcount <= 0 )
then
3052 for value
as ulongint = minval
to maxval
3053 assert( i < labelcount )
3054 if( value = values[i] )
then
3066 if( minval > 0 )
then
3087 byval op as integer, _
3088 byval v1
as IRVREG
ptr, _
3089 byval v2
as IRVREG
ptr, _
3090 byval bytes
as longint _
3094 case AST_OP_MEMCLEAR
3103 dim as FBSYMBOL
ptr array =
any
3115 assert( symbIsVar(
sym ) )
3116 array =
sym->var_.desc.array
3118 if( symbIsStatic( array )
and symbHasDtor( array ) )
then
3129 byval op as integer, _
3130 byval proc as FBSYMBOL
ptr, _
3131 byval ex
as integer _
3134 if(
op = AST_OP_DBG_LINEINI )
then
3146 if(
len( s ) > 0 )
then
3147 if(
right( s, 1 ) =
"\" )
then
3148 s +=
"not_an_escape"
3155 dim as string mangled
3166 if( env.target.options
and FB_TARGETOPT_UNDERSCORE )
then
3167 mangled =
"_" + mangled
3170 if( symbIsProc(
sym ) )
then
3171 if( symbGetProcMode(
sym ) = FB_FUNCMODE_STDCALL )
then
3196 if( env.clopt.asmsyntax = FB_ASMSYNTAX_INTEL )
then
3222 if( env.clopt.asmsyntax = FB_ASMSYNTAX_INTEL )
then
3245 if( env.clopt.asmsyntax = FB_ASMSYNTAX_INTEL )
then
3261 ctx.
asm_line +=
", ""eax"", ""ebx"", ""ecx"", ""edx"", ""esp"", ""edi"", ""esi"""
3262 if( env.clopt.fputype = FB_FPUTYPE_SSE )
then
3263 ctx.
asm_line +=
", ""mm0"", ""mm1"", ""mm2"", ""mm3"", ""mm4"", ""mm5"", ""mm6"", ""mm7"""
3264 ctx.
asm_line +=
", ""xmm0"", ""xmm1"", ""xmm2"", ""xmm3"", ""xmm4"", ""xmm5"", ""xmm6"", ""xmm7"""
3320 byval varlength
as longint, _
3321 byval literal
as zstring ptr, _
3322 byval litlength
as longint _
3329 if( litlength > varlength )
then
3331 litlength = varlength
3342 byval varlength
as longint, _
3343 byval literal
as wstring ptr, _
3344 byval litlength
as longint _
3347 dim as uinteger ch =
any
3348 dim as integer wcharsize =
any
3358 wcharsize = typeGetSize( FB_DATATYPE_WCHAR )
3361 if( litlength > varlength )
then
3363 litlength = varlength
3366 for i
as integer = 0
to litlength - 1
3376 ctx.
varini += $
"\x" +
hex( ch, wcharsize * 2 )
3404 if(
right(
ctx.
varini, 2 ) =
", " )
then
3423 ctx.
fbctinf +=
"__attribute__((used, section(""." + FB_INFOSEC_NAME +
"""))) "
3443 byval proc as FBSYMBOL
ptr, _
3444 byval initlabel
as FBSYMBOL
ptr _
3447 dim as string mangled
3451 if( env.clopt.debug )
then
3457 if( symbIsNaked(
proc ) )
then
3459 hWriteLine(
"__asm__( "".globl " + mangled +
""" );" )
3460 hWriteLine(
"__asm__( """ + mangled +
":"" );" )
3469 select case( symbGetProcMode(
proc ) )
3470 case FB_FUNCMODE_STDCALL_MS, FB_FUNCMODE_PASCAL
3486 byval proc as FBSYMBOL
ptr, _
3487 byval initlabel
as FBSYMBOL
ptr, _
3488 byval exitlabel
as FBSYMBOL
ptr _
3491 dim as string mangled
3495 if( symbIsNaked(
proc ) )
then
3497 if( env.clopt.target = FB_COMPTARGET_LINUX )
then
3499 hWriteLine(
"__asm__( "".size " + mangled +
", .-" + mangled +
""" );", TRUE )
3513 byval param as FBSYMBOL
ptr, _
3514 byval vr as IRVREG
ptr, _
3515 byval udtlen
as longint, _
3516 byval level as integer _