예제 #1
0
 def test_parse_bitcode_error(self):
     with self.assertRaises(RuntimeError) as cm:
         llvm.parse_bitcode(b"")
     self.assertIn("LLVM bitcode parsing error", str(cm.exception))
     # for llvm < 9
     if llvm.llvm_version_info[0] < 9:
         self.assertIn("Invalid bitcode signature", str(cm.exception))
     else:
         self.assertIn(
             "file too small to contain bitcode header", str(cm.exception),
         )
예제 #2
0
파일: util.py 프로젝트: dbwodlf3/SMC
def readModule(filePath) -> llvm.ModuleRef:
    """This function for getting llvm Module Referecne from ll or bc file.

    Parameters:
        filePath (str): llvm ir file.

    Returns:
        llvmlite.binding.ModuleRef
    """
    #
    try:
        ll_file = False
        ll_file = open(filePath, "r")
    except:
        try:
            bc_file = False
            bc_file = open(filePath, "rb")
        except:
            pass
    finally:
        if (ll_file):
            return llvm.parse_assembly(ll_file.read())
        elif (bc_file):
            return llvm.parse_bitcode(bc_file.read())
        else:
            return print("CAN'T READ FILE!!")
예제 #3
0
    def test_bitcode_roundtrip(self):
        bc = self.module(asm=asm_mul).as_bitcode()
        mod = llvm.parse_bitcode(bc)
        self.assertEqual(mod.as_bitcode(), bc)

        mod.get_function("mul")
        mod.get_global_variable("mul_glob")
예제 #4
0
 def _unserialize(cls, codegen, state):
     name, kind, data = state
     self = codegen.create_library(name)
     assert isinstance(self, cls)
     if kind == 'bitcode':
         # No need to re-run optimizations, just make the module ready
         self._final_module = ll.parse_bitcode(data)
         self._finalize_final_module()
         return self
     elif kind == 'object':
         object_code, shared_bitcode = data
         self.enable_object_caching()
         self._set_compiled_object(object_code)
         self._shared_module = ll.parse_bitcode(shared_bitcode)
         self._finalize_final_module()
         return self
     else:
         raise ValueError("unsupported serialization kind %r" % (kind,))
예제 #5
0
파일: codegen.py 프로젝트: rxist525/numba
 def _unserialize(cls, codegen, state):
     name, kind, data = state
     self = codegen.create_library(name)
     assert isinstance(self, cls)
     if kind == 'bitcode':
         # No need to re-run optimizations, just make the module ready
         self._final_module = ll.parse_bitcode(data)
         self._finalize_final_module()
         return self
     elif kind == 'object':
         object_code, shared_bitcode = data
         self.enable_object_caching()
         self._set_compiled_object(object_code)
         self._shared_module = ll.parse_bitcode(shared_bitcode)
         self._finalize_final_module()
         return self
     else:
         raise ValueError("unsupported serialization kind %r" % (kind,))
예제 #6
0
    def test_bitcode_roundtrip(self):
        # create a new context to avoid struct renaming
        context1 = llvm.create_context()
        bc = self.module(context=context1).as_bitcode()
        context2 = llvm.create_context()
        mod = llvm.parse_bitcode(bc, context2)
        self.assertEqual(mod.as_bitcode(), bc)

        mod.get_function("sum")
        mod.get_global_variable("glob")
예제 #7
0
def verify(module):
    try:
        module_ref = llvm.parse_assembly(str(module))
        module_bc = llvm.parse_bitcode(module_ref.as_bitcode())
        module_bc.verify()
    except RuntimeError:
        traceback.print_exc()
        print(module)
        sys.exit()
    return module_bc
예제 #8
0
 def test_parse_bitcode_error(self):
     with self.assertRaises(RuntimeError) as cm:
         llvm.parse_bitcode(b"")
     self.assertIn("LLVM bitcode parsing error", str(cm.exception))
     self.assertIn("Invalid bitcode signature", str(cm.exception))
예제 #9
0
 def test_bitcode_roundtrip(self):
     bc = self.module().as_bitcode()
     mod = llvm.parse_bitcode(bc)
     self.assertEqual(mod.as_bitcode(), bc)
     mod.get_function("sum")
     mod.get_global_variable("glob")
def verify(module):
    module_bc = llvm.parse_bitcode(module.as_bitcode())
    module_bc.verify()
    return module_bc
예제 #11
0
import llvmlite.binding as llvm
import pygraphviz
import networkx

mod = llvm.parse_bitcode(open("curl-7.54.0/src/.libs/curl.0.4.opt.bc", 'r').read())
mod.verify()
graph = ""
for func in mod.functions:
  graph += llvm.get_function_cfg(func)
graph2 = pygraphviz.AGraph(graph)
graph3 = networkx.Graph(graph2)
networkx.draw(graph3)
예제 #12
0
 def compile(self):
     with open(self.file, "rb") as f:
         llmodule = llvm.parse_bitcode(f.read())
     llmodule.verify()
     return self.target.link([self.target.assemble(llmodule)])
예제 #13
0
 def compile_bc(self, bc):
     """
     Compile a module from LLVM bitcode.
     """
     mod = llvm.parse_bitcode(bc)
     return self.finalize_compilation(mod)