reorganize
This commit is contained in:
parent
1009daf3fa
commit
f9d7195413
25 changed files with 0 additions and 2535 deletions
|
|
@ -1,3 +0,0 @@
|
|||
from .builder import *
|
||||
from .executor import CExecutor
|
||||
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,68 +0,0 @@
|
|||
'''
|
||||
This is mostly a convenience module for testing with ctypes.
|
||||
'''
|
||||
|
||||
from llvm.core import Type, Module
|
||||
import llvm.ee as le
|
||||
import ctypes as ct
|
||||
|
||||
MAP_CTYPES = {
|
||||
'void' : None,
|
||||
'bool' : ct.c_bool,
|
||||
'char' : ct.c_char,
|
||||
'uchar' : ct.c_ubyte,
|
||||
'short' : ct.c_short,
|
||||
'ushort' : ct.c_ushort,
|
||||
'int' : ct.c_int,
|
||||
'uint' : ct.c_uint,
|
||||
'long' : ct.c_long,
|
||||
'ulong' : ct.c_ulong,
|
||||
|
||||
'int8' : ct.c_int8,
|
||||
'uint8' : ct.c_uint8,
|
||||
'int16' : ct.c_int16,
|
||||
'uint16' : ct.c_uint16,
|
||||
'int32' : ct.c_int32,
|
||||
'uint32' : ct.c_uint32,
|
||||
'int64' : ct.c_int64,
|
||||
'uint64' : ct.c_uint64,
|
||||
|
||||
'float' : ct.c_float,
|
||||
'double' : ct.c_double,
|
||||
'longdouble' : ct.c_longdouble,
|
||||
}
|
||||
|
||||
class CExecutor(object):
|
||||
'''a convenient class for creating ctype functions from LLVM modules
|
||||
'''
|
||||
def __init__(self, mod_or_engine):
|
||||
if isinstance(mod_or_engine, Module):
|
||||
self.engine = le.EngineBuilder.new(mod_or_engine).opt(3).create()
|
||||
else:
|
||||
self.engine = mod_or_engine
|
||||
|
||||
def get_ctype_function(self, fn, *typeinfo):
|
||||
'''create a ctype function from a LLVM function
|
||||
|
||||
typeinfo : string of types (see `MAP_CTYPES`) or
|
||||
list of ctypes datatype.
|
||||
First value is the return type.
|
||||
A function that takes no argument and return nothing
|
||||
should use `"void"` or `None`.
|
||||
'''
|
||||
if len(typeinfo)==1 and isinstance(typeinfo[0], str):
|
||||
types = [ MAP_CTYPES[s.strip()] for s in typeinfo[0].split(',') ]
|
||||
if not types:
|
||||
retty = None
|
||||
argtys = []
|
||||
else:
|
||||
retty = types[0]
|
||||
argtys = types[1:]
|
||||
else:
|
||||
retty = typeinfo[0]
|
||||
argtys = typeinfo[1:]
|
||||
|
||||
prototype = ct.CFUNCTYPE(retty, *argtys)
|
||||
fnptr = self.engine.get_pointer_to_function(fn)
|
||||
return prototype(fnptr)
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
from .builder import CExternal
|
||||
import llvm.core as lc
|
||||
from . import shortnames as types
|
||||
|
||||
class LibC(CExternal):
|
||||
printf = lc.Type.function(types.int, [types.char_p], True)
|
||||
# TODO a lot more to add
|
||||
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
from llvm.core import Type
|
||||
|
||||
void = Type.void()
|
||||
char = Type.int(8)
|
||||
short = Type.int(16)
|
||||
int = Type.int(32)
|
||||
int16 = short
|
||||
int32 = int
|
||||
int64 = Type.int(64)
|
||||
|
||||
float = Type.float()
|
||||
double = Type.double()
|
||||
|
||||
# pointers
|
||||
|
||||
pointer = Type.pointer
|
||||
|
||||
void_p = pointer(char)
|
||||
char_p = pointer(char)
|
||||
|
||||
# platform dependent
|
||||
|
||||
def _determine_pointer_size():
|
||||
from ctypes import sizeof, c_void_p
|
||||
return sizeof(c_void_p) * 8
|
||||
|
||||
pointer_size = _determine_pointer_size()
|
||||
|
||||
intp = {32: int32, 64: int64}[pointer_size]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue