Skip to content
Snippets Groups Projects
Commit 2d654ff4 authored by Jan Hoenig's avatar Jan Hoenig
Browse files

backup

parent 4a8659e8
Branches
Tags
No related merge requests found
...@@ -10,12 +10,10 @@ from ..types import DataType ...@@ -10,12 +10,10 @@ from ..types import DataType
from ..astnodes import Indexed from ..astnodes import Indexed
def generateLLVM(ast_node): def generateLLVM(ast_node, module=ir.Module(), builder=ir.IRBuilder()):
""" """
Prints the ast as llvm code Prints the ast as llvm code
""" """
module = ir.Module()
builder = ir.IRBuilder()
printer = LLVMPrinter(module, builder) printer = LLVMPrinter(module, builder)
return printer._print(ast_node) return printer._print(ast_node)
...@@ -111,10 +109,10 @@ class LLVMPrinter(Printer): ...@@ -111,10 +109,10 @@ class LLVMPrinter(Printer):
def _print_KernelFunction(self, function): def _print_KernelFunction(self, function):
return_type = self.void return_type = self.void
# TODO argument in their own call? # TODO argument in their own call? -> nope
parameter_type = [] parameter_type = []
for parameter in function.parameters: for parameter in function.parameters:
# TODO what bout ptr shape and stride argument? # TODO what about ptr shape and stride argument?
if parameter.isFieldArgument: if parameter.isFieldArgument:
parameter_type.append(self.fp_pointer) parameter_type.append(self.fp_pointer)
else: else:
......
import llvmlite.binding as llvm import llvmlite.binding as llvm
import llvmlite.ir as ir
import logging.config import logging.config
import ctypes as ct
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -65,7 +68,22 @@ class Eval(object): ...@@ -65,7 +68,22 @@ class Eval(object):
with open('gen.o', 'wb') as f: with open('gen.o', 'wb') as f:
f.write(target_machine.emit_object(llvmmod)) f.write(target_machine.emit_object(llvmmod))
# fptr = CFUNCTYPE(c_double, c_double, c_double)(ee.get_function_address('add2')) fptr = {}
# TODO cpujit has its own string version
types = {str(ir.DoubleType()): ct.c_double,
str(ir.IntType(64)): ct.c_int64, # TODO int width?
str(ir.FloatType()): ct.c_float,
str(ir.VoidType()): None, # TODO thats a void pointer use None???
str(ir.DoubleType().as_pointer()): ct.POINTER(ct.c_double),
str(ir.IntType(64).as_pointer()): ct.POINTER(ct.c_int), # TODO int width?
str(ir.FloatType().as_pointer()): ct.POINTER(ct.c_float),
#ir.VoidType().as_pointer(): ct.c_void_p, # TODO there is no void pointer in llvmlite?
} # TODO Aggregate types
for function in module.functions:
if not function.is_declaration:
print(function.name)
print(type(function))
fptr[function.name] = ct.CFUNCTYPE(types[str(function.ftype.return_type)], *[types[str(arg)] for arg in function.ftype.args])(ee.get_function_address(function.name))
# result = fptr(2, 3) # result = fptr(2, 3)
# print(result) # print(result)
return 0 return fptr
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment