From afeb29b89ab969ecee5964968cf25d7dd5d28e32 Mon Sep 17 00:00:00 2001 From: coderJeff Date: Wed, 30 Jun 2021 05:48:10 -0400 Subject: [PATCH 1/3] fbc: internal restructure of fbctools table - internal changes to prepare for new options on fbc's tools and invocation - name FBCTOOLS_* in the enum FBCTOOL - add enum FBCTOOLFLAG to specify tool options - add FBCTOOLINFO structure to track additional information for each tool --- changelog.txt | 1 + src/compiler/fbc.bas | 51 +++++++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/changelog.txt b/changelog.txt index b279a3b744..b3782ec503 100644 --- a/changelog.txt +++ b/changelog.txt @@ -14,6 +14,7 @@ Version 1.09.0 - fbc: internal function fbcQueryGcc() to ask gcc for the correct as & ld to use (TeeEmCee) - rtlib: freebsd: minimum thread stacksize 8192 KiB - sf.net #666: allow overload 'as string' with 'as zstring ptr' parameters +- fbc: internal changes to restructure fbctools table [added] - fbc: add '-z fbrt' command line option to link against libfbrt*.a instead of libfb*.a diff --git a/src/compiler/fbc.bas b/src/compiler/fbc.bas index 4fb97c108c..6f69ae16eb 100644 --- a/src/compiler/fbc.bas +++ b/src/compiler/fbc.bas @@ -113,12 +113,13 @@ type FBCCTX objinf as FBC_OBJINF end type -enum +enum FBCTOOL FBCTOOL_AS = 0 FBCTOOL_AR FBCTOOL_LD FBCTOOL_GCC FBCTOOL_LLC + FBCTOOL_CLANG FBCTOOL_DLLTOOL FBCTOOL_GORC FBCTOOL_WINDRES @@ -131,13 +132,37 @@ enum FBCTOOL__COUNT end enum -static shared as zstring * 16 toolnames(0 to FBCTOOL__COUNT-1) = _ +enum FBCTOOLFLAG + FBCTOOLFLAG_INVALID = 0 '' tool is disabled + FBCTOOLFLAG_ASSUME_EXISTS = 1 '' assume the tool exists + FBCTOOLFLAG_CAN_USE_ENVIRON = 2 '' allow path to tool to specified by environment variable + + FBCTOOLFLAG_DEFAULT = FBCTOOLFLAG_ASSUME_EXISTS or FBCTOOLFLAG_CAN_USE_ENVIRON +end enum + +type FBCTOOLINFO + name as zstring * 16 + flags as FBCTOOLFLAG +end type + +'' must be same order as enum FBCTOOL +static shared as FBCTOOLINFO fbctoolTB(0 to FBCTOOL__COUNT-1) = _ { _ - "as", "ar", "ld", "gcc", "llc", "dlltool", "GoRC", "windres", "cxbe", "dxe3gen", _ - "emcc", _ - "emar", _ - "emcc", _ - "emcc" _ + /' FBCTOOL_AS '/ ( "as" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_AR '/ ( "ar" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_LD '/ ( "ld" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_GCC '/ ( "gcc" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_LLC '/ ( "llc" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_CLANG '/ ( "clang" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_DLLTOOL '/ ( "dlltool", FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_GORC '/ ( "GoRC" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_WINDRES '/ ( "windres", FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_CXBE '/ ( "cxbe" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_DXEGEN '/ ( "dxe3gen", FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_EMAS '/ ( "emcc" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_EMAR '/ ( "emar" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_EMLD '/ ( "emcc" , FBCTOOLFLAG_DEFAULT ), _ + /' FBCTOOL_EMCC '/ ( "emcc" , FBCTOOLFLAG_DEFAULT ) _ } declare sub fbcFindBin _ @@ -399,10 +424,12 @@ private sub fbcFindBin _ relying_on_system = FALSE '' a) Use the path from the corresponding environment variable if it's set - path = environ( ucase( toolnames(tool) ) ) + if( (fbctoolTB(tool).flags and FBCTOOLFLAG_CAN_USE_ENVIRON) <> 0 ) then + path = environ( ucase( fbctoolTB(tool).name ) ) + end if if( len( path ) = 0 ) then '' b) Try bin/ directory - path = fbc.binpath + toolnames(tool) + FB_HOST_EXEEXT + path = fbc.binpath + fbctoolTB(tool).name + FB_HOST_EXEEXT #ifndef ENABLE_STANDALONE if( (hFileExists( path ) = FALSE) and _ @@ -419,9 +446,9 @@ private sub fbcFindBin _ if( hFileExists( path ) = FALSE ) then '' d) Rely on PATH if( fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_JS ) then - path = fbc.targetprefix + toolnames(tool) + FB_HOST_EXEEXT + path = fbc.targetprefix + fbctoolTB(tool).name + FB_HOST_EXEEXT else - path = toolnames(tool) + path = fbctoolTB(tool).name end if relying_on_system = TRUE end if @@ -839,7 +866,7 @@ private function hLinkFiles( ) as integer if( fbGetOption( FB_COMPOPT_OBJINFO ) and _ (fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_DARWIN) and _ (fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_SOLARIS) and _ - ( fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_JS ) and _ + ( fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_JS ) and _ (not fbcIsUsingGoldLinker( )) ) then ldcline += " -T """ + fbc.libpath + (FB_HOST_PATHDIV + "fbextra.x""") end if From 279e2bfbfc55ad7e7cb0ec8e2255925922e5fb66 Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 2 Aug 2021 20:23:46 -0400 Subject: [PATCH 2/3] fbc: internal restructure of fbctools table and fbcFindBin - refactor fbcFindBin() to solve out variables lasttool, last_relying_on_system, and lastpath and store in fbcToolTB() --- changelog.txt | 2 +- src/compiler/fbc.bas | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/changelog.txt b/changelog.txt index b3782ec503..82fee9ab63 100644 --- a/changelog.txt +++ b/changelog.txt @@ -14,7 +14,7 @@ Version 1.09.0 - fbc: internal function fbcQueryGcc() to ask gcc for the correct as & ld to use (TeeEmCee) - rtlib: freebsd: minimum thread stacksize 8192 KiB - sf.net #666: allow overload 'as string' with 'as zstring ptr' parameters -- fbc: internal changes to restructure fbctools table +- fbc: internal changes to restructure fbctools table, cache search results in fbctoolTB() [added] - fbc: add '-z fbrt' command line option to link against libfbrt*.a instead of libfb*.a diff --git a/src/compiler/fbc.bas b/src/compiler/fbc.bas index 6f69ae16eb..69b19600fb 100644 --- a/src/compiler/fbc.bas +++ b/src/compiler/fbc.bas @@ -136,6 +136,8 @@ enum FBCTOOLFLAG FBCTOOLFLAG_INVALID = 0 '' tool is disabled FBCTOOLFLAG_ASSUME_EXISTS = 1 '' assume the tool exists FBCTOOLFLAG_CAN_USE_ENVIRON = 2 '' allow path to tool to specified by environment variable + FBCTOOLFLAG_FOUND = 4 '' tool was checked for + FBCTOOLFLAG_RELYING_ON_SYSTEM = 8 '' tool is expected to be on system PATH FBCTOOLFLAG_DEFAULT = FBCTOOLFLAG_ASSUME_EXISTS or FBCTOOLFLAG_CAN_USE_ENVIRON end enum @@ -143,6 +145,7 @@ end enum type FBCTOOLINFO name as zstring * 16 flags as FBCTOOLFLAG + path as zstring * (FB_MAXPATHLEN + 1) end type '' must be same order as enum FBCTOOL @@ -411,13 +414,10 @@ private sub fbcFindBin _ byref relying_on_system as integer _ ) - static as integer lasttool = -1, last_relying_on_system - static as string lastpath - '' Re-use path from last time if possible - if( lasttool = tool ) then - path = lastpath - relying_on_system = last_relying_on_system + if( ( fbctoolTB( tool ).flags and FBCTOOLFLAG_FOUND ) <> 0 ) then + path = fbctoolTB( tool ).path + relying_on_system = ((fbctoolTB( tool ).flags and FBCTOOLFLAG_RELYING_ON_SYSTEM) <> 0 ) exit sub end if @@ -455,9 +455,12 @@ private sub fbcFindBin _ #endif end if - lasttool = tool - lastpath = path - last_relying_on_system = relying_on_system + + fbctoolTB( tool ).path = path + fbctoolTB( tool ).flags or= FBCTOOLFLAG_FOUND + fbctoolTB( tool ).flags = iif( relying_on_system, _ + fbctoolTB( tool ).flags or FBCTOOLFLAG_RELYING_ON_SYSTEM, _ + fbctoolTB( tool ).flags and not FBCTOOLFLAG_RELYING_ON_SYSTEM ) end sub private function fbcRunBin _ From 4de0f76e0de631edfb3c8f2528576211bbbd048e Mon Sep 17 00:00:00 2001 From: coderJeff Date: Mon, 2 Aug 2021 20:25:31 -0400 Subject: [PATCH 3/3] fbc: internal restructure of fbctools table and fbcFindBin() - refactor fbcFindBin() to solve out relying_on_system parameter --- changelog.txt | 2 +- src/compiler/fbc.bas | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/changelog.txt b/changelog.txt index 82fee9ab63..e6c7515120 100644 --- a/changelog.txt +++ b/changelog.txt @@ -14,7 +14,7 @@ Version 1.09.0 - fbc: internal function fbcQueryGcc() to ask gcc for the correct as & ld to use (TeeEmCee) - rtlib: freebsd: minimum thread stacksize 8192 KiB - sf.net #666: allow overload 'as string' with 'as zstring ptr' parameters -- fbc: internal changes to restructure fbctools table, cache search results in fbctoolTB() +- fbc: internal changes to restructure fbctools table, cache search results in fbctoolTB(), solve out fbcFindBin() parameters [added] - fbc: add '-z fbrt' command line option to link against libfbrt*.a instead of libfb*.a diff --git a/src/compiler/fbc.bas b/src/compiler/fbc.bas index 69b19600fb..6f589de05b 100644 --- a/src/compiler/fbc.bas +++ b/src/compiler/fbc.bas @@ -148,6 +148,10 @@ type FBCTOOLINFO path as zstring * (FB_MAXPATHLEN + 1) end type +#define fbctoolGetFlags( tool, f ) ((fbctoolTB( tool ).flags and (f)) <> 0) +#define fbctoolSetFlags( tool, f ) fbctoolTB( tool ).flags or= f +#define fbctoolUnsetFlags( tool, f ) fbctoolTB( tool ).flags and= not f + '' must be same order as enum FBCTOOL static shared as FBCTOOLINFO fbctoolTB(0 to FBCTOOL__COUNT-1) = _ { _ @@ -171,8 +175,7 @@ static shared as FBCTOOLINFO fbctoolTB(0 to FBCTOOL__COUNT-1) = _ declare sub fbcFindBin _ ( _ byval tool as integer, _ - byref path as string, _ - byref relying_on_system as integer = FALSE _ + byref path as string _ ) #macro safeKill(f) @@ -410,18 +413,16 @@ end sub private sub fbcFindBin _ ( _ byval tool as integer, _ - byref path as string, _ - byref relying_on_system as integer _ + byref path as string _ ) '' Re-use path from last time if possible - if( ( fbctoolTB( tool ).flags and FBCTOOLFLAG_FOUND ) <> 0 ) then + if( fbctoolGetFlags( tool, FBCTOOLFLAG_FOUND ) ) then path = fbctoolTB( tool ).path - relying_on_system = ((fbctoolTB( tool ).flags and FBCTOOLFLAG_RELYING_ON_SYSTEM) <> 0 ) exit sub end if - relying_on_system = FALSE + fbctoolUnsetFlags( tool, FBCTOOLFLAG_RELYING_ON_SYSTEM ) '' a) Use the path from the corresponding environment variable if it's set if( (fbctoolTB(tool).flags and FBCTOOLFLAG_CAN_USE_ENVIRON) <> 0 ) then @@ -450,17 +451,13 @@ private sub fbcFindBin _ else path = fbctoolTB(tool).name end if - relying_on_system = TRUE + fbctoolSetFlags( tool, FBCTOOLFLAG_RELYING_ON_SYSTEM ) end if #endif end if - fbctoolTB( tool ).path = path - fbctoolTB( tool ).flags or= FBCTOOLFLAG_FOUND - fbctoolTB( tool ).flags = iif( relying_on_system, _ - fbctoolTB( tool ).flags or FBCTOOLFLAG_RELYING_ON_SYSTEM, _ - fbctoolTB( tool ).flags and not FBCTOOLFLAG_RELYING_ON_SYSTEM ) + fbctoolSetFlags( tool, FBCTOOLFLAG_FOUND ) end sub private function fbcRunBin _ @@ -470,10 +467,10 @@ private function fbcRunBin _ byref ln as string _ ) as integer - dim as integer result = any, relying_on_system = any + dim as integer result = any dim as string path - fbcFindBin( tool, path, relying_on_system ) + fbcFindBin( tool, path ) if( fbc.verbose ) then print *action + ": ", path + " " + ln @@ -486,7 +483,7 @@ private function fbcRunBin _ result = exec( path, ln ) #else '' Found at bin/? - if( relying_on_system = FALSE ) then + if( fbctoolGetFlags( tool, FBCTOOLFLAG_RELYING_ON_SYSTEM ) = FALSE ) then result = exec( path, ln ) else result = shell( path + " " + ln )