Skip to content
Merged
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Version 1.06.0
[changed]
- Adjusted warning text for "mixed bool/nonbool operands" warning
- test-suite uses libfbcunit for unit testing framework
- SELECT CASE AS CONST respects data type and will show overflow warnings on out-of-range constants
- boolean: don't allow NEG unary op '-' on boolean data types

[added]
- -noobjinfo option to disable the writing/reading of compile-time library and other linking options from/to .o and .a files. This also disables the use of fbextra.x (the supplemental linker script) for discarding the .fbctinf sections, which is useful when using the gold linker that doesn't support this kind of linker script.
Expand Down Expand Up @@ -54,6 +56,8 @@ Version 1.06.0
- #875: Fix bug where boolean variable to single/double conversion gives wrong sign on -gen gas -fpu x87 & sse
- #872: Fix broken boolean bitfield runtime assignments from unsigned values
- Fixed inline asm procedure name mangling bug (missing underscore prefix) with -gen gcc -asm intel on dos/win32
- #878: Fix fbc-64bit hangs on 'Case True' + 'Case False' inside 'Select Case As const'
- Fix SELECT CASE AS CONST to allow both signed & unsigned case range values


Version 1.05.0
Expand Down
34 changes: 17 additions & 17 deletions src/compiler/ast-node-branch.bas
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private function astNewJMPTB _
byval labels1 as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
) as ASTNODE ptr

dim as ASTNODE ptr n = any, tree = any
Expand Down Expand Up @@ -124,8 +124,8 @@ private function astNewJMPTB _
n->jmptb.labels = labels
n->jmptb.labelcount = labelcount
n->jmptb.deflabel = deflabel
n->jmptb.minval = minval
n->jmptb.maxval = maxval
n->jmptb.bias = bias
n->jmptb.span = span

function = astNewLINK( tree, n )
end function
Expand All @@ -139,7 +139,7 @@ function astLoadJMPTB( byval n as ASTNODE ptr ) as IRVREG ptr
if( ast.doemit ) then
irEmitJMPTB( v1, n->sym, n->jmptb.values, n->jmptb.labels, _
n->jmptb.labelcount, n->jmptb.deflabel, _
n->jmptb.minval, n->jmptb.maxval )
n->jmptb.bias, n->jmptb.span )
end if

deallocate( n->jmptb.values )
Expand All @@ -148,11 +148,11 @@ function astLoadJMPTB( byval n as ASTNODE ptr ) as IRVREG ptr
function = NULL
end function

'' Pre-calculate -minval * sizeof(ptr) as Long value, because the offset in an
'' Pre-calculate -bias * sizeof(ptr) as Long value, because the offset in an
'' x86 IDX expression is signed 32bit.
private function hPrecalcMinvalOffset( byval minval as ulongint, byval dtype as integer ) as longint
private function hPrecalcBiasOffset( byval bias as ulongint, byval dtype as integer ) as longint
astBeginHideWarnings( )
var t = astNewCONSTi( minval, dtype )
var t = astNewCONSTi( bias, dtype )
t = astNewUOP( AST_OP_NEG, t )
t = astNewBOP( AST_OP_MUL, t, astNewCONSTi( env.pointersize, dtype ) )
function = astConstFlushToInt( t, FB_DATATYPE_LONG )
Expand All @@ -166,8 +166,8 @@ function astBuildJMPTB _
byval labels1 as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
) as ASTNODE ptr

dim as ASTNODE ptr tree = any, l = any
Expand Down Expand Up @@ -219,26 +219,26 @@ function astBuildJMPTB _

'' if( expr < minval or expr > maxval ) then goto deflabel
'' optimised to:
'' if( cunsg(expr - minval) > (maxval - minval) ) then goto deflabel
'' if( cunsg(expr - bias) > (span) ) then goto deflabel
tree = astNewLINK( tree, _
astNewBOP( AST_OP_GT, _
astNewBOP( AST_OP_SUB, _
astNewVAR( tempvar ), _
astNewCONSTi( minval, dtype ) ), _
astNewCONSTi( maxval - minval, dtype ), _
astNewCONSTi( bias, dtype ) ), _
astNewCONSTi( span, dtype ), _
deflabel, AST_OPOPT_NONE ) )

'' Do
'' goto table[expr - minval]
'' goto table[expr - bias]
'' by using an IDX
'' goto [table + expr * sizeof(ptr) + -minval * sizeof(ptr)]
'' goto [table + expr * sizeof(ptr) + -bias * sizeof(ptr)]
'' goto [table + expr*4 + 16]
'' goto [table + expr*4 - 16]
'' instead of DEREF-BOP-ADDROF (IDX gives better code currently).
tree = astNewLINK( tree, _
astNewBRANCH( AST_OP_JUMPPTR, NULL, _
astNewIDX( _
astNewVAR( tbsym, hPrecalcMinvalOffset( minval, dtype ) ), _
astNewVAR( tbsym, hPrecalcBiasOffset( bias, dtype ) ), _
astNewBOP( AST_OP_MUL, _
astNewVAR( tempvar ), _
astNewCONSTi( env.pointersize, dtype ) ) ) ) )
Expand All @@ -248,7 +248,7 @@ function astBuildJMPTB _

tree = astNewLINK( tree, _
astNewJMPTB( astNewVAR( tempvar ), tbsym, _
values1, labels1, labelcount, deflabel, minval, maxval ) )
values1, labels1, labelcount, deflabel, bias, span ) )

function = tree
end function
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/ast-node-uop.bas
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ function astNewUOP _
if( typeGetDtAndPtrOnly( o->dtype ) = FB_DATATYPE_BOOLEAN ) then
if( op = AST_OP_NOT ) then
do_promote = FALSE
elseif( op = AST_OP_NEG ) then
'' allow it or test suite can't compile
else
'' no other operation allowed with booleans
exit function
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/ast.bi
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ type AST_NODE_JMPTB
labelcount as integer

deflabel as FBSYMBOL ptr
minval as ulongint
maxval as ulongint
bias as ulongint
span as ulongint
end type

type AST_NODE_DBG
Expand Down Expand Up @@ -731,8 +731,8 @@ declare function astBuildJMPTB _
byval labels1 as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
) as ASTNODE ptr

declare function astNewLOOP _
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/emit.bas
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ sub emitFlush( )
cast( EMIT_JTBCB, emit.opFnTb[EMIT_OP_JMPTB] )( n->jtb.tbsym, _
n->jtb.values, n->jtb.labels, _
n->jtb.labelcount, n->jtb.deflabel, _
n->jtb.minval, n->jtb.maxval )
n->jtb.bias, n->jtb.span )

deallocate( n->jtb.values )
deallocate( n->jtb.labels )
Expand Down Expand Up @@ -1460,8 +1460,8 @@ function emitJMPTB _
byval labels1 as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
) as EMIT_NODE ptr

dim as EMIT_NODE ptr n = any
Expand All @@ -1485,8 +1485,8 @@ function emitJMPTB _
n->jtb.labels = labels
n->jtb.labelcount = labelcount
n->jtb.deflabel = deflabel
n->jtb.minval = minval
n->jtb.maxval = maxval
n->jtb.bias = bias
n->jtb.span = span

function = n
end function
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/emit.bi
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ type EMIT_JTBNODE
labelcount as integer

deflabel as FBSYMBOL ptr
minval as ulongint
maxval as ulongint
bias as ulongint
span as ulongint
end type

type EMIT_MEMNODE
Expand Down Expand Up @@ -250,8 +250,8 @@ type EMIT_JTBCB as sub _
byval labels1 as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
)

type EMIT_MEMCB as sub( byval dvreg as IRVREG ptr, _
Expand Down Expand Up @@ -422,8 +422,8 @@ declare function emitJMPTB _
byval labels1 as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
) as EMIT_NODE ptr

declare function emitCALL _
Expand Down
47 changes: 24 additions & 23 deletions src/compiler/emit_x86.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,8 @@ private sub _emitJMPTB _
byval labels1 as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
)

dim as string deflabelname, tb
Expand All @@ -1231,7 +1231,9 @@ private sub _emitJMPTB _
tb = *symbGetMangledName( tbsym )

''
'' Emit entries for each value from minval to maxval.
'' Emit entries for each value from 0 to span.
'' minval = bias
'' maxval = register(bias+span)
'' Each value that is in the values1 array uses the corresponding label
'' from the labels1 array; all other values use the default label.
''
Expand All @@ -1244,27 +1246,26 @@ private sub _emitJMPTB _
''

outEx( tb + ":" + NEWLINE )
if( minval <= maxval ) then
var i = 0
var value = minval
do
assert( i < labelcount )

dim as FBSYMBOL ptr label
if( value = values1[i] ) then
label = labels1[i]
i += 1
else
label = deflabel
end if
outp( *_getTypeString( FB_DATATYPE_UINT ) + " " + *symbGetMangledName( label ) )

if( value = maxval ) then
exit do
end if
value += 1
loop
end if
var i = 0
var value = 0
do
assert( i < labelcount )

dim as FBSYMBOL ptr label
if( value = values1[i] ) then
label = labels1[i]
i += 1
else
label = deflabel
end if
outp( *_getTypeString( FB_DATATYPE_UINT ) + " " + *symbGetMangledName( label ) )

if( value = span ) then
exit do
end if
value += 1
loop

end sub

Expand Down
60 changes: 27 additions & 33 deletions src/compiler/ir-hlc.bas
Original file line number Diff line number Diff line change
Expand Up @@ -3043,8 +3043,8 @@ private sub _emitJmpTb _
byval labels as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
)

dim as string tb, temp, ln
Expand All @@ -3068,50 +3068,44 @@ private sub _emitJmpTb _

tb = *symbUniqueId( )

l = exprNewIMMi( maxval - minval + 1 )
l = exprNewIMMi( span + 1 )
hWriteLine( "static const void* " + tb + "[" + exprFlush( l ) + "] = {", TRUE )
sectionIndent( )

if( minval <= maxval ) then
var i = 0
var value = minval
do
assert( i < labelcount )
var i = 0
var value = 0
do
assert( i < labelcount )

dim as FBSYMBOL ptr label
if( value = values[i] ) then
label = labels[i]
i += 1
else
label = deflabel
end if
hWriteLine( "&&" + *symbGetMangledName( label ) + ",", TRUE )
dim as FBSYMBOL ptr label
if( value = values[i] ) then
label = labels[i]
i += 1
else
label = deflabel
end if
hWriteLine( "&&" + *symbGetMangledName( label ) + ",", TRUE )

if( value = maxval ) then
exit do
end if
value += 1
loop
end if
if( value = span ) then
exit do
end if
value += 1
loop

sectionUnindent( )
hWriteLine( "};", TRUE )

if( minval > 0 ) then
'' if( temp < minval ) goto deflabel
l = exprNewTEXT( dtype, NULL, temp )
l = exprNewBOP( AST_OP_LT, l, exprNewIMMi( minval, dtype ) )
hWriteLine( "if( " + exprFlush( l ) + " ) goto " + *symbGetMangledName( deflabel ) + ";", TRUE )
end if

'' if( temp > maxval ) then goto deflabel
'' if( (temp-bias) > span ) then goto deflabel
l = exprNewTEXT( dtype, NULL, temp )
l = exprNewBOP( AST_OP_GT, l, exprNewIMMi( maxval, dtype ) )
if( bias <> 0 ) then
l = exprNewBOP( AST_OP_SUB, l, exprNewIMMi( bias, dtype ) )
end if
l = exprNewBOP( AST_OP_GT, l, exprNewIMMi( span, dtype ) )
hWriteLine( "if( " + exprFlush( l ) + " ) goto " + *symbGetMangledName( deflabel ) + ";", TRUE )

'' l = jumptable[l - minval]
'' l = jumptable[l - bias]
l = exprNewTEXT( dtype, NULL, temp )
l = exprNewBOP( AST_OP_SUB, l, exprNewIMMi( minval, dtype ) )
l = exprNewBOP( AST_OP_SUB, l, exprNewIMMi( bias, dtype ) )
hWriteLine( "goto *" + tb + "[" + exprFlush( l ) + "];", TRUE )

end sub
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/ir-llvm.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1993,8 +1993,8 @@ private sub _emitJmpTb _
byval labels as FBSYMBOL ptr ptr, _
byval labelcount as integer, _
byval deflabel as FBSYMBOL ptr, _
byval minval as ulongint, _
byval maxval as ulongint _
byval bias as ulongint, _
byval span as ulongint _
)

hAstCommand( "jmptb " + vregPretty( v1 ) )
Expand All @@ -2013,7 +2013,7 @@ private sub _emitJmpTb _

ctx.indent += 1
for i as integer = 0 to labelcount - 1
ln = dtype + " " & values[i] & ", "
ln = dtype + " " & (values[i]+bias) & ", "
ln += "label %" + *symbGetMangledName( labels[i] )
hWriteLine( ln )
next
Expand Down
Loading