gambas-source-code/comp/src/gb.jit/.src/_Jit.module
gambas d797a545b6 [COMPILER]
* NEW: Work on JIT continues...
* NEW: Better panic errors.

[INTERPRETER]
* NEW: Remove the old JIT stuff.
* NEW: Calls gb.jit at runtime if needed. If a fast function has no jit implementation, the bytecode version is used.
* NEW: Start defining the JIT interface needed by the JIT functions.
* NEW: The common static character buffer is now twice the size of the maximum symbol length, to avoid possible overflows.

[GB.JIT]
* NEW: Compilation starts to work.
* NEW: Debugging messages.
2018-05-26 16:50:00 +02:00

65 lines
1.5 KiB
Text

' Gambas module file
Export
Private $sCompiler As String
Private Sub FindCompiler()
$sCompiler = System.Find("gcc")
End
Public Sub Compile() As String
Dim sFile As String
Dim sDir As String
Dim sName As String
Dim sPath As String
Dim hFile As File
Dim sResult As String
Dim sPathO As String
Dim sPathSO As String
sName = Component.FindFromPath("..")
sDir = File.Dir(Temp$()) &/ "jit"
Try Mkdir sDir
sPath = sDir &/ sName & ".c"
Error "gb.jit: generating "; sPath
hFile = Open sPath For Output Create
Print #hFile, File.Load("jit.h");
sDir = "../.jit"
For Each sFile In Dir(sDir, "*.c")
Print #hFile, File.Load(sDir &/ sFile);
Next
Close #hFile
sPathO = File.SetExt(sPath, "o")
sPathSO = File.SetExt(sPath, "so")
FindCompiler
'gcc -c -fPIC -o foo.o foo.c
'Exec [$sCompiler, "-c", "-fPIC", "-o", File.SetExt(sPath, "o"), sPath] To sResult
Shell $sCompiler & " -c -fPIC -o " & Shell(sPathO) & " " & Shell(sPath) & " 2>&1" To sResult
If Not Exist(sPathO) Then
Error "gb.jit: warning: unable to compile JIT code:"
Error sResult
Return
Endif
'gcc -shared -o libfoo.so foo.o
'Exec [$sCompiler, "-shared", "-o", File.SetExt(sPath, "so"), File.SetExt(sPath, "o")] To sResult
Shell $sCompiler & " -shared -o " & Shell(sPathSO) & " " & Shell(sPathO) & " 2>&1" To sResult
If Not Exist(sPathSO) Then
Error "gb.jit: warning: unable to link JIT code:"
Error sResult
Return
Endif
Return File.SetExt(sPath, "so")
End