示例#1
0
def cg_load_bitcode_from_file(file_name):
    try:
        with open(file_name, "rb") as fin:
            mod = Module.from_bitcode(fin)
    except:
        log.debug("Failed to load bitcode: " + file_name)
        return None
    log.debug("Loaded bitcode from file: " + file_name)
    return mod
示例#2
0
def bitey_reconstruct(md, bitcode):
    name, = md

    mod = new_module(name)
    llvm_module = Module.from_bitcode(BytesIO(bitcode))
    engine = ExecutionEngine.new(llvm_module)
    make_all_wrappers(llvm_module, engine, mod)

    return mod
示例#3
0
文件: bind.py 项目: efrainra/blaze
def wrap_llvm_bitcode(bitcode, py_module):
    '''
    Given a byte-string of LLVM bitcode and a Python module,
    populate the module with ctypes bindings for public methods
    in the bitcode.
    '''
    llvm_module = Module.from_bitcode(io.BytesIO(bitcode))
    engine = llvm.ee.ExecutionEngine.new(llvm_module)
    wrap_llvm_module(llvm_module, engine, py_module)
    setattr(py_module, '_llvm_module', llvm_module)
    setattr(py_module, '_llvm_engine', engine)
示例#4
0
def wrap_llvm_bitcode(bitcode, py_module):
    '''
    Given a byte-string of LLVM bitcode and a Python module,
    populate the module with ctypes bindings for public methods
    in the bitcode.
    '''
    llvm_module = Module.from_bitcode(io.BytesIO(bitcode))
    engine = llvm.ee.ExecutionEngine.new(llvm_module)
    wrap_llvm_module(llvm_module, engine, py_module)
    setattr(py_module, '_llvm_module', llvm_module)
    setattr(py_module, '_llvm_engine', engine)
示例#5
0
文件: test_asm.py 项目: B-Rich/llvmpy
    def test_bitcode_roundtrip(self):
        m = self.create_module()

        testasm_bc = os.path.join(self.tmpdir, 'testasm.bc')
        with open(testasm_bc, "wb") as fout:
            m.to_bitcode(fout)

        # read it back into a module
        with open(testasm_bc, "rb") as fin:
            m2 = Module.from_bitcode(fin)
            # The default `m.id` is '<string>'.
            m2.id = m.id # Copy the name from `m`

        with open(testasm_bc, "rb") as fin:
            m3 = Module.from_bitcode(fin.read())
            # The default `m.id` is '<string>'.
            m3.id = m.id # Copy the name from `m`

        self.assertEqual(str(m2).strip(), str(m).strip())
        self.assertEqual(str(m3).strip(), str(m).strip())
示例#6
0
    def test_bitcode_roundtrip(self):
        m = self.create_module()

        testasm_bc = os.path.join(self.tmpdir, 'testasm.bc')
        with open(testasm_bc, "wb") as fout:
            m.to_bitcode(fout)

        # read it back into a module
        with open(testasm_bc, "rb") as fin:
            m2 = Module.from_bitcode(fin)
            # The default `m.id` is '<string>'.
            m2.id = m.id  # Copy the name from `m`

        with open(testasm_bc, "rb") as fin:
            m3 = Module.from_bitcode(fin.read())
            # The default `m.id` is '<string>'.
            m3.id = m.id  # Copy the name from `m`

        self.assertEqual(str(m2).strip(), str(m).strip())
        self.assertEqual(str(m3).strip(), str(m).strip())
示例#7
0
    def test_bitcode(self):
        # create a module
        m = Module.new('module1')
        m.add_global_variable(Type.int(), 'i')

        # write it's assembly representation to a file
        asm = str(m)

        testasm_bc = os.path.join(self.tmpdir, 'testasm.bc')
        with open(testasm_bc, "wb") as fout:
            m.to_bitcode(fout)

        # read it back into a module
        with open(testasm_bc, "rb") as fin:
            m2 = Module.from_bitcode(fin)
            # The default `m.id` is '<string>'.
            m2.id = m.id  # Copy the name from `m`

        self.assertEqual(str(m2).strip(), asm.strip())
示例#8
0
    def test_bitcode(self):
        # create a module
        m = Module.new("module1")
        m.add_global_variable(Type.int(), "i")

        # write it's assembly representation to a file
        asm = str(m)

        testasm_bc = os.path.join(self.tmpdir, "testasm.bc")
        with open(testasm_bc, "wb") as fout:
            m.to_bitcode(fout)

        # read it back into a module
        with open(testasm_bc, "rb") as fin:
            m2 = Module.from_bitcode(fin)
            # The default `m.id` is '<string>'.
            m2.id = m.id  # Copy the name from `m`

        self.assertEqual(str(m2).strip(), asm.strip())