gambas-source-code/main/lib/jit/gb.jit/.src/CCompilation.class
gambas 3dd1fd493e Fix the JIT compiler: '_init' method, Lock instruction, Object datatype, and DO / REPEAT loops at the beginning of a function now work correctly.
[INTERPRETER]
* BUG: JIT compiler does not run static initializers anymore when loading a class. Otherwise bytecode can be modified before being compiled, leading to a JIT compiler crash.

[COMPILER]
* BUG: Fix LOCK subroutine meta-information.

[GB.JIT]
* NEW: Don't display abortion debugging message if there is no compilation to abort.
* BUG: Object variables are correctly managed now.
* BUG: DO...LOOP and REPEAT...UNTIL at the beginning of the function now is correctly compiled in all cases.
2019-04-04 22:58:06 +02:00

129 lines
2.5 KiB
Text

' Gambas class file
Static Public All As New Collection
Static Private $sCompiler As String
Static Private $aFlags As String[]
Public Name As String
Public PathSO As String
Private $sResult As String
Private $fTime As Float
Private $hProcess As Process
Static Private Sub Init()
Dim sFlag As String
Dim sCompiler As String
sCompiler = Env["GB_JIT_CC"]
If Not sCompiler Then sCompiler = "gcc"
$sCompiler = System.Find(sCompiler)
If Not $sCompiler Then Error.Raise("Compiler not found")
sFlag = Env["GB_JIT_CFLAGS"]
If Not sFlag Then sFlag = "-O3"
$aFlags = Split(sFlag, " ")
End
Public Sub _new(sName As String, sPathSO As String, fTime As Float)
Name = sName
PathSO = sPathSO
$fTime = fTime
All[sName] = Me
End
Public Sub Run(sInput As String, Optional sOutput As String, sOption As String)
Dim aExec As String[]
'Dim I As Integer
If Not $sCompiler Then Init
aExec = [$sCompiler]
If sOption Then aExec.Insert(Split(sOption, " "))
aExec.Insert($aFlags)
aExec.Add(sInput)
If sOutput Then
aExec.Add("-o")
aExec.Add(sOutput)
Endif
' For I = 0 To aExec.Max
' aExec[I] = Shell$(aExec[I])
' Next
If Jit.Debug Then Error "gb.jit: run: "; aExec.Join(" ")
$hProcess = Exec aExec For Read As "Compiler"
'$hProcess.Ignore = True
'System._Breakpoint
End
Public Sub Compiler_Read()
Dim sData As String
sData = Read #$hProcess, -1024
$sResult &= sData
End
Public Sub Compiler_Error(({Error}) As String)
$sResult &= {Error}
End
Public Sub Compiler_Kill()
If $hProcess.Value = 0 Then
$fTime = Timer - $fTime
Jit._Time += $fTime
If Jit.Debug Then Error "gb.jit: compilation of '"; Name; "' done in "; Format($fTime, "0.000"); " s"
Else
If Jit.Debug Then Error "gb.jit: compilation of '"; Name; "' returns "; $hProcess.Value
Endif
$hProcess = Null
' Shell "objdump -S " & Shell(sPathSO) To sResult
' Error sResult
End
Public Sub Wait() As String
If $hProcess Then
If Jit.Debug Then Error "gb.jit: waiting for compilation of '"; Name; "'..."
$hProcess.Wait
If Jit.Debug Then Error "gb.jit: compilation of '"; Name; "' is available"
Endif
If Not Exist(PathSO) Then
Error "gb.jit: error: unable to compile JIT code of '"; Name; "':\n"
Error $sResult
Return
Endif
Return PathSO
End
Public Sub Kill()
If $hProcess Then
If Jit.Debug Then Error "gb.jit: abort compilation of '"; Name; "'"
$hProcess.Kill
Endif
End