Skip to content

Commit

Permalink
Merge pull request #334 from jayrm/fbctools
Browse files Browse the repository at this point in the history
fbc internal changes to track binary tools used by fbc
  • Loading branch information
jayrm authored Aug 7, 2021
2 parents 27f305a + 4de0f76 commit dfdee71
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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
Expand Down
87 changes: 57 additions & 30 deletions src/compiler/fbc.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -131,20 +132,50 @@ 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_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

type FBCTOOLINFO
name as zstring * 16
flags as FBCTOOLFLAG
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) = _
{ _
"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 _
( _
byval tool as integer, _
byref path as string, _
byref relying_on_system as integer = FALSE _
byref path as string _
)

#macro safeKill(f)
Expand Down Expand Up @@ -382,27 +413,24 @@ end sub
private sub fbcFindBin _
( _
byval tool as integer, _
byref path as string, _
byref relying_on_system as integer _
byref path as string _
)

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( fbctoolGetFlags( tool, FBCTOOLFLAG_FOUND ) ) then
path = fbctoolTB( tool ).path
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
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 _
Expand All @@ -419,18 +447,17 @@ 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
fbctoolSetFlags( tool, FBCTOOLFLAG_RELYING_ON_SYSTEM )
end if
#endif
end if

lasttool = tool
lastpath = path
last_relying_on_system = relying_on_system
fbctoolTB( tool ).path = path
fbctoolSetFlags( tool, FBCTOOLFLAG_FOUND )
end sub

private function fbcRunBin _
Expand All @@ -440,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
Expand All @@ -456,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 )
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dfdee71

Please sign in to comment.