File tree 2 files changed +32
-7
lines changed
2 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -13,13 +13,6 @@ def process_diagnostic(diag):
13
13
engine .process = process_diagnostic
14
14
15
15
llmod = Module .from_string ("" .join (fileinput .input ()).expandtabs (), engine = engine ).llvm_ir
16
-
17
- # Add main so that the result can be executed with lli
18
- llmain = ll .Function (llmod , ll .FunctionType (ll .VoidType (), []), "main" )
19
- llbuilder = ll .IRBuilder (llmain .append_basic_block ("entry" ))
20
- llbuilder .call (llmod .get_global (llmod .name + ".__modinit__" ), [])
21
- llbuilder .ret_void ()
22
-
23
16
print (llmod )
24
17
25
18
if __name__ == "__main__" :
Original file line number Diff line number Diff line change
1
+ import sys , fileinput
2
+ from ctypes import CFUNCTYPE
3
+ from pythonparser import diagnostic
4
+ from llvmlite import binding as llvm
5
+ from .. import Module
6
+
7
+ llvm .initialize ()
8
+ llvm .initialize_native_target ()
9
+ llvm .initialize_native_asmprinter ()
10
+ llvm .check_jit_execution ()
11
+
12
+ def main ():
13
+ def process_diagnostic (diag ):
14
+ print ("\n " .join (diag .render ()))
15
+ if diag .level in ("fatal" , "error" ):
16
+ exit (1 )
17
+
18
+ engine = diagnostic .Engine ()
19
+ engine .process = process_diagnostic
20
+
21
+ llmod = Module .from_string ("" .join (fileinput .input ()).expandtabs (), engine = engine ).llvm_ir
22
+
23
+ lltarget = llvm .Target .from_default_triple ()
24
+ llmachine = lltarget .create_target_machine ()
25
+ llparsedmod = llvm .parse_assembly (str (llmod ))
26
+ lljit = llvm .create_mcjit_compiler (llparsedmod , llmachine )
27
+ lljit .finalize_object ()
28
+ llmain = lljit .get_pointer_to_global (llparsedmod .get_function (llmod .name + ".__modinit__" ))
29
+ CFUNCTYPE (None )(llmain )()
30
+
31
+ if __name__ == "__main__" :
32
+ main ()
You can’t perform that action at this time.
0 commit comments