Skip to content
Snippets Groups Projects
Commit fc7e815a authored by Michael Kuron's avatar Michael Kuron :mortar_board:
Browse files

Remove llvmlite dependency for walberla codegen

parent e2a168b4
No related merge requests found
import ctypes import ctypes
import sympy as sp import sympy as sp
import numpy as np import numpy as np
import llvmlite.ir as ir try:
import llvmlite.ir as ir
except ImportError as e:
ir = None
_ir_importerror = e
from sympy.core.cache import cacheit from sympy.core.cache import cacheit
from pystencils.cache import memorycache from pystencils.cache import memorycache
...@@ -170,6 +174,8 @@ toCtypes.map = { ...@@ -170,6 +174,8 @@ toCtypes.map = {
def ctypes_from_llvm(data_type): def ctypes_from_llvm(data_type):
if not ir:
raise _ir_importerror
if isinstance(data_type, ir.PointerType): if isinstance(data_type, ir.PointerType):
ctype = ctypes_from_llvm(data_type.pointee) ctype = ctypes_from_llvm(data_type.pointee)
if ctype is None: if ctype is None:
...@@ -203,25 +209,28 @@ def to_llvm_type(data_type): ...@@ -203,25 +209,28 @@ def to_llvm_type(data_type):
:param data_type: Subclass of Type :param data_type: Subclass of Type
:return: llvmlite type object :return: llvmlite type object
""" """
if not ir:
raise _ir_importerror
if isinstance(data_type, PointerType): if isinstance(data_type, PointerType):
return to_llvm_type(data_type.baseType).as_pointer() return to_llvm_type(data_type.baseType).as_pointer()
else: else:
return to_llvm_type.map[data_type.numpyDtype] return to_llvm_type.map[data_type.numpyDtype]
to_llvm_type.map = { if ir:
np.dtype(np.int8): ir.IntType(8), to_llvm_type.map = {
np.dtype(np.int16): ir.IntType(16), np.dtype(np.int8): ir.IntType(8),
np.dtype(np.int32): ir.IntType(32), np.dtype(np.int16): ir.IntType(16),
np.dtype(np.int64): ir.IntType(64), np.dtype(np.int32): ir.IntType(32),
np.dtype(np.int64): ir.IntType(64),
np.dtype(np.uint8): ir.IntType(8),
np.dtype(np.uint16): ir.IntType(16), np.dtype(np.uint8): ir.IntType(8),
np.dtype(np.uint32): ir.IntType(32), np.dtype(np.uint16): ir.IntType(16),
np.dtype(np.uint64): ir.IntType(64), np.dtype(np.uint32): ir.IntType(32),
np.dtype(np.uint64): ir.IntType(64),
np.dtype(np.float32): ir.FloatType(),
np.dtype(np.float64): ir.DoubleType(), np.dtype(np.float32): ir.FloatType(),
} np.dtype(np.float64): ir.DoubleType(),
}
def peelOffType(dtype, typeToPeelOff): def peelOffType(dtype, typeToPeelOff):
while type(dtype) is typeToPeelOff: while type(dtype) is typeToPeelOff:
......
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