Skip to content

Commit 39aee26

Browse files
committed
fbc: add "__thiscall" calling convention, -gen gcc only
- adds the keyword '__thiscall' - emits '__thiscall' or __'attribute__((thiscall))' in -gen gcc - emits x86_thiscallcc in -gen llvm (not tested) - ignored in -gen gas, (i.e. no change in emitted code even if thiscall is present) - must be explicitly specified in the procedure declaration - default use of "thiscall" calling convention still platform dependant (e.g. win x86 32-bit) compared to default usage in g++ - recommend user to '#define thiscall __thiscall' depending on target platform
1 parent 947a9f4 commit 39aee26

File tree

11 files changed

+34
-1
lines changed

11 files changed

+34
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Version 1.08.0
6767
- '-w suffix' or '-w pedantic' command line option enabled 'Suffix ignored' warning for built-in in string functions
6868
- __FB_UNIQUEID_PUSH__(), __FB_UNIQUEID__(), __FB_UNIQUEID_POP__(), __FB_ARG_LEFTOF__(), __FB_ARG_RIGHTOF__(), __FB_JOIN__() builtin macros
6969
- __FB_ARG_COUNT__() builtin macro
70+
- __thiscall keyword to specify the 'thiscall' calling convention (-gen gcc only)
7071
- __FB_QUOTE__(), __FB_UNQUOTE__(), __FB_EVAL__() builtin macros
7172
- rtlib: REDIM [PRESERVE] will generate run time error if attempting to resize static (fixed length) arrays.
7273
- gas64 emitter for x86_64 (SARG), added '-gen gas64' command line option to select

src/compiler/ast-node-call.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ function astLoadCALL( byval n as ASTNODE ptr ) as IRVREG ptr
204204

205205
'' cdecl: pushed arguments must be popped by caller
206206
'' pascal/stdcall: callee does it instead
207+
'' thiscall: could be either depending on target !!! TODO !!!
207208
argbytes = symbCalcArgLen( l->dtype, l->subtype, arg->arg.mode )
208209
if( symbGetProcMode( proc ) = FB_FUNCMODE_CDECL ) then
209210
bytestopop += argbytes

src/compiler/fbint.bi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ enum FB_TOKEN
346346
FB_TK_PASCAL
347347
FB_TK_CDECL
348348
FB_TK_STDCALL
349+
FB_TK_THISCALL
349350
FB_TK_ALIAS
350351
FB_TK_LIB
351352
FB_TK_OVERLOAD

src/compiler/ir-hlc.bas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,13 @@ private function hEmitProcHeader _
555555
'' Linux GCC only accepts this
556556
ln += " __attribute__((stdcall))"
557557
end select
558+
case FB_FUNCMODE_THISCALL
559+
select case( env.clopt.target )
560+
case FB_COMPTARGET_WIN32, FB_COMPTARGET_XBOX
561+
ln += " __thiscall"
562+
case else
563+
ln += " __attribute__((thiscall))"
564+
end select
558565
end select
559566
end if
560567

src/compiler/ir-llvm.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ private function hEmitProcCallConv( byval proc as FBSYMBOL ptr ) as string
367367
select case as const( symbGetProcMode( proc ) )
368368
case FB_FUNCMODE_STDCALL, FB_FUNCMODE_STDCALL_MS, FB_FUNCMODE_PASCAL
369369
function = "x86_stdcallcc "
370+
case FB_FUNCMODE_THISCALL
371+
function = "x86_thiscall "
370372
end select
371373
end function
372374

src/compiler/parser-proc.bas

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ function cProcCallingConv( byval default as FB_FUNCMODE ) as FB_FUNCMODE
509509
default = env.target.fbcall
510510
end if
511511

512-
'' (CDECL|STDCALL|PASCAL)?
512+
'' (CDECL|STDCALL|PASCAL|THISCALL)?
513513
select case as const lexGetToken( )
514514
case FB_TK_CDECL
515515
function = FB_FUNCMODE_CDECL
@@ -525,6 +525,10 @@ function cProcCallingConv( byval default as FB_FUNCMODE ) as FB_FUNCMODE
525525
function = FB_FUNCMODE_PASCAL
526526
lexSkipToken( LEXCHECK_POST_SUFFIX )
527527

528+
case FB_TK_THISCALL
529+
function = FB_FUNCMODE_THISCALL
530+
lexSkipToken( )
531+
528532
case else
529533
select case as const parser.mangling
530534
case FB_MANGLING_BASIC, FB_MANGLING_RTLIB

src/compiler/symb-keyword.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ dim shared kwdTb( 0 to FB_TOKENS-1 ) as SYMBKWD => _
108108
( @"FUNCTION" , FB_TK_FUNCTION , FB_TKCLASS_KEYWORD ), _
109109
( @"CDECL" , FB_TK_CDECL , FB_TKCLASS_KEYWORD ), _
110110
( @"STDCALL" , FB_TK_STDCALL , FB_TKCLASS_KEYWORD ), _
111+
( @"__THISCALL" , FB_TK_THISCALL , FB_TKCLASS_KEYWORD ), _
111112
( @"PASCAL" , FB_TK_PASCAL , FB_TKCLASS_KEYWORD ), _
112113
( @"ALIAS" , FB_TK_ALIAS , FB_TKCLASS_KEYWORD ), _
113114
( @"LIB" , FB_TK_LIB , FB_TKCLASS_KEYWORD ), _

src/compiler/symb-proc.bas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,8 @@ private sub hProcModeToStr( byref s as string, byval proc as FBSYMBOL ptr )
29282928
select case( symbGetProcMode( proc ) )
29292929
case FB_FUNCMODE_STDCALL, FB_FUNCMODE_STDCALL_MS
29302930
s += " stdcall"
2931+
case FB_FUNCMODE_THISCALL
2932+
s += " thiscall"
29312933
case FB_FUNCMODE_PASCAL
29322934
s += " pascal"
29332935
end select
@@ -2941,6 +2943,8 @@ private sub hProcModeToStr( byref s as string, byval proc as FBSYMBOL ptr )
29412943
case else
29422944
s += " stdcall"
29432945
end select
2946+
case FB_FUNCMODE_THISCALL
2947+
s += " thiscall"
29442948
case FB_FUNCMODE_PASCAL
29452949
if( env.target.fbcall <> FB_FUNCMODE_PASCAL ) then
29462950
s += " pascal"

src/compiler/symb.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,7 @@ function symbDumpToStr _
25802580
case FB_FUNCMODE_STDCALL_MS : s += " stdcallms"
25812581
case FB_FUNCMODE_PASCAL : s += " pascal"
25822582
case FB_FUNCMODE_CDECL : s += " cdecl"
2583+
case FB_FUNCMODE_THISCALL : s += " thiscall"
25832584
end select
25842585

25852586
if( verbose ) then

src/compiler/symb.bi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ enum FB_FUNCMODE
217217
FB_FUNCMODE_STDCALL_MS '' ms/vb-style: don't include the @n suffix
218218
FB_FUNCMODE_CDECL
219219
FB_FUNCMODE_PASCAL
220+
FB_FUNCMODE_THISCALL
220221

221222
'' Symbolic constant to represent FBCALL, telling cProcCallingConv()
222223
'' and the RTL procedure definitions to use env.target.fbcall which

0 commit comments

Comments
 (0)