Exemplo n.º 1
0
    def testAdd(self):
        ty = Type.int8()
        mod = self.module
        g = Global.add(mod, ty, 'x')
        self.assertEqual('x', g.name)

        g2 = Global.get(mod, 'x')
        self.assertEqual('x', g2.name)
Exemplo n.º 2
0
    def testAdd(self):
        ty = Type.int8()
        mod = self.module
        g = Global.add(mod, ty, 'x')
        self.assertEqual('x', g.name)

        g2 = Global.get(mod, 'x')
        self.assertEqual('x', g2.name)
Exemplo n.º 3
0
    def testAddAlias(self):
        ty = Type.int8()
        x = Global.add(self.module, ty, 'x')
        x.initializer = Value.const_int(ty, 1, True)
        pty = Type.pointer(ty)
        y = Global.add_alias(self.module, pty, x, 'y')

        g = list(GlobalIterator(self.module))
        self.assertEqual([x], g)
Exemplo n.º 4
0
    def testAddAlias(self):
        ty = Type.int8()
        x = Global.add(self.module, ty, 'x')
        x.initializer = Value.const_int(ty, 1, True)
        pty = Type.pointer(ty)
        y = Global.add_alias(self.module, pty, x, 'y')

        g = list(GlobalIterator(self.module))
        self.assertEqual([x], g)
Exemplo n.º 5
0
    def testDelete(self):
        ty = Type.int8()
        x = Global.add(self.module, ty, 'x')
        x.initializer = Value.const_int(ty, 1, True)
        y = Global.add(self.module, ty, 'y')
        y.initializer = Value.const_int(ty, 2, True)

        y.delete()
        g = list(GlobalIterator(self.module))
        self.assertEqual([x], g)
Exemplo n.º 6
0
    def testDelete(self):
        ty = Type.int8()
        x = Global.add(self.module, ty, 'x')
        x.initializer = Value.const_int(ty, 1, True)
        y = Global.add(self.module, ty, 'y')
        y.initializer = Value.const_int(ty, 2, True)   

        y.delete()
        g = list(GlobalIterator(self.module))
        self.assertEqual([x], g)
Exemplo n.º 7
0
    def testIter(self):
        ty = Type.int8()
        x = Global.add(self.module, ty, 'x')
        x.initializer = Value.const_int(ty, 1, True)
        y = Global.add(self.module, ty, 'y')
        y.initializer = Value.const_int(ty, 2, True)

        g = list(GlobalIterator(self.module))
        self.assertEqual([x, y], g)

        g = list(GlobalIterator(self.module, reverse=True))
        self.assertEqual([y, x], g)
Exemplo n.º 8
0
    def testIter(self):
        ty = Type.int8()
        x = Global.add(self.module, ty, 'x')
        x.initializer = Value.const_int(ty, 1, True)
        y = Global.add(self.module, ty, 'y')
        y.initializer = Value.const_int(ty, 2, True)

        g = list(GlobalIterator(self.module))
        self.assertEqual([x, y], g)

        g = list(GlobalIterator(self.module, reverse=True))
        self.assertEqual([y, x], g)
Exemplo n.º 9
0
def create_global_load_save_module():
    mod = Module.CreateWithName('module')
    ty = Type.int8(mod.context)
    x = Global.add(mod, ty, 'x')
    x.initializer = Value.const_int(ty, 0, True)

    def create_store():
        ft = Type.function(Type.void(), [ty], False)
        f = mod.add_function('store', ft)
        bb = f.append_basic_block('body')
        bldr = Builder.create(mod.context)
        bldr.position_at_end(bb)

        xt = f.get_param(0)
        bldr.store(xt, x)
        bldr.ret_void()

    def create_load():
        ft = Type.function(ty, [], False)
        f = mod.add_function('load', ft)
        bb = f.append_basic_block('body')
        bldr = Builder.create(mod.context)
        bldr.position_at_end(bb)

        xt = bldr.load(x, "xt")
        bldr.ret(xt)
        
    create_store()
    create_load()
    return mod
Exemplo n.º 10
0
def create_global_load_save_module():
    mod = Module.CreateWithName('module')
    ty = Type.int8(mod.context)
    x = Global.add(mod, ty, 'x')
    x.initializer = Value.const_int(ty, 0, True)

    def create_store():
        ft = Type.function(Type.void(), [ty], False)
        f = mod.add_function('store', ft)
        bb = f.append_basic_block('body')
        bldr = Builder.create(mod.context)
        bldr.position_at_end(bb)

        xt = f.get_param(0)
        bldr.store(xt, x)
        bldr.ret_void()

    def create_load():
        ft = Type.function(ty, [], False)
        f = mod.add_function('load', ft)
        bb = f.append_basic_block('body')
        bldr = Builder.create(mod.context)
        bldr.position_at_end(bb)

        xt = bldr.load(x, "xt")
        bldr.ret(xt)

    create_store()
    create_load()
    return mod
Exemplo n.º 11
0
    def testInit(self):
        ty = Type.int8()
        mod = self.module
        g = Global.add(mod, ty, 'x')
        g.initializer = Value.const_int(ty, 4, True)
        v = g.initializer

        self.assertEqual(4, v.get_signext_value())
Exemplo n.º 12
0
    def testInit(self):
        ty = Type.int8()
        mod = self.module
        g = Global.add(mod, ty, 'x')
        g.initializer = Value.const_int(ty, 4, True)
        v = g.initializer

        self.assertEqual(4, v.get_signext_value())
Exemplo n.º 13
0
 def testAddGlobal(self):
     mod = Module.CreateWithName('module')
     ty = Type.int8(context=mod.context)
     a = Value.const_int(ty, 1, True)
     g = Global.add(mod, ty, 'x')
     g.initializer = Value.const_int(ty, 4, True)
     bldr = Builder.create()
     c = bldr.add(g.initializer, a, 'tmp1')
     self.assertEqual(5, c.get_signext_value())
Exemplo n.º 14
0
 def testAddGlobal(self):
     mod = Module.CreateWithName('module')
     ty = Type.int8(context=mod.context)
     a = Value.const_int(ty, 1, True)
     g = Global.add(mod, ty, 'x')
     g.initializer = Value.const_int(ty, 4, True)
     bldr = Builder.create()
     c = bldr.add(g.initializer, a, 'tmp1')
     self.assertEqual(5, c.get_signext_value())
Exemplo n.º 15
0
    def testName(self):
        # constants cannot be named. 
        ty = Type.int8(context=self.module.context)
        v = Global.add(self.module, ty, 'x')

        self.assertEqual('x', v.name)
        v.name = 'one'
        self.assertEqual('one', v.name)
        self.assertTrue(v.is_constant())
        self.assertFalse(v.is_undef())
Exemplo n.º 16
0
    def testName(self):
        # constants cannot be named.
        ty = Type.int8(context=self.module.context)
        v = Global.add(self.module, ty, 'x')

        self.assertEqual('x', v.name)
        v.name = 'one'
        self.assertEqual('one', v.name)
        self.assertTrue(v.is_constant())
        self.assertFalse(v.is_undef())
Exemplo n.º 17
0
    def testAddGlobalVal(self):
        mod = Module.CreateWithName('module')
        ty = Type.int8(context=mod.context)
        a = Value.const_int(ty, 1, True)
        g = Global.add(mod, ty, 'x')
        g.initializer = Value.const_int(ty, 4, True)
        g.set_const(True)

        t = g.type
        self.assertTrue(g.is_const())

        bldr = Builder.create()
        # Build instruction  %tmp1 = add i8 %tmp0, 1
        c = bldr.add(bldr.load(g, "tmp0"), a, 'tmp1')
        self.assertEqual('i8', c.type.name)
        self.assertEqual('tmp1', c.name)
Exemplo n.º 18
0
    def testAddGlobalVal(self):
        mod = Module.CreateWithName('module')
        ty = Type.int8(context=mod.context)
        a = Value.const_int(ty, 1, True)
        g = Global.add(mod, ty, 'x')
        g.initializer = Value.const_int(ty, 4, True)
        g.set_const(True)

        t = g.type
        self.assertTrue(g.is_const())

        bldr = Builder.create()
        # Build instruction  %tmp1 = add i8 %tmp0, 1
        c = bldr.add(bldr.load(g, "tmp0"), a, 'tmp1')
        self.assertEqual('i8', c.type.name)
        self.assertEqual('tmp1', c.name)
Exemplo n.º 19
0
def create_timestwo_module_with_global():
    mod = Module.CreateWithName('module')
    ty = Type.int8(mod.context)
    k = Global.add(mod, ty, 'k')
    k.initializer = Value.const_int(ty, 2, True)
    
    ft = Type.function(ty, [ty], False)
    f = mod.add_function('timestwo', ft)
    bb = f.append_basic_block('body')
    bldr = Builder.create(mod.context)
    bldr.position_at_end(bb)

    x = f.get_param(0)
    two = bldr.load(k, "two")
    y = bldr.mul(x, two, 'res')
    bldr.ret(y)    
    return (mod, f)
Exemplo n.º 20
0
def create_timestwo_module_with_global():
    mod = Module.CreateWithName('module')
    ty = Type.int8(mod.context)
    k = Global.add(mod, ty, 'k')
    k.initializer = Value.const_int(ty, 2, True)

    ft = Type.function(ty, [ty], False)
    f = mod.add_function('timestwo', ft)
    bb = f.append_basic_block('body')
    bldr = Builder.create(mod.context)
    bldr.position_at_end(bb)

    x = f.get_param(0)
    two = bldr.load(k, "two")
    y = bldr.mul(x, two, 'res')
    bldr.ret(y)
    return (mod, f)
Exemplo n.º 21
0
def create_global_load_save_array_module():
    mod = Module.CreateWithName('module')
    ty = Type.int8(mod.context)
    array_ty = Type.array(ty, 2)
    x = Global.add(mod, array_ty, 'x')
    v = Value.const_int(ty, 0, True)
    ptr_ty = Type.int64(mod.context)
    v0 = Value.const_int(ptr_ty, 0, True)
    x.initializer = Value.const_array(ty, [v, v])

    def create_store():
        ft = Type.function(Type.void(), [ty, ptr_ty], False)
        f = mod.add_function('store', ft)
        bb = f.append_basic_block('body')
        bldr = Builder.create(mod.context)
        bldr.position_at_end(bb)

        xt = f.get_param(0)
        offset = f.get_param(1)
        elem_ptr = bldr.gep(x, [v0, offset], 'elem')
        bldr.store(xt, elem_ptr)
        bldr.ret_void()

    def create_load():
        ft = Type.function(ty, [ptr_ty], False)
        f = mod.add_function('load', ft)
        bb = f.append_basic_block('body')
        bldr = Builder.create(mod.context)
        bldr.position_at_end(bb)

        offset = f.get_param(0)
        elem_ptr = bldr.gep(x, [v0, offset], 'elem')
        y = bldr.load(elem_ptr, 'y')
        bldr.ret(y)

    create_store()
    create_load()
    return mod
Exemplo n.º 22
0
def create_global_load_save_array_module():
    mod = Module.CreateWithName('module')
    ty = Type.int8(mod.context)
    array_ty = Type.array(ty, 2)
    x = Global.add(mod, array_ty, 'x')
    v = Value.const_int(ty, 0, True)
    ptr_ty = Type.int64(mod.context)
    v0 = Value.const_int(ptr_ty, 0, True)
    x.initializer = Value.const_array(ty, [v, v])

    def create_store():
        ft = Type.function(Type.void(), [ty, ptr_ty], False)
        f = mod.add_function('store', ft)
        bb = f.append_basic_block('body')
        bldr = Builder.create(mod.context)
        bldr.position_at_end(bb)

        xt = f.get_param(0)
        offset = f.get_param(1)
        elem_ptr = bldr.gep(x, [v0, offset], 'elem')
        bldr.store(xt, elem_ptr)
        bldr.ret_void()

    def create_load():
        ft = Type.function(ty, [ptr_ty], False)
        f = mod.add_function('load', ft)
        bb = f.append_basic_block('body')
        bldr = Builder.create(mod.context)
        bldr.position_at_end(bb)
        
        offset = f.get_param(0)
        elem_ptr = bldr.gep(x, [v0, offset], 'elem')
        y = bldr.load(elem_ptr, 'y')
        bldr.ret(y)

    create_store()
    create_load()
    return mod