Example #1
0
    def testCreateGenericIntValue(self):
        ty = Type.int8()
        gv = GenericValue.of_int(ty, 4, True)
        self.assertEqual(4, gv.to_int(True))

        gv = GenericValue.of_int(ty, 128 + 4, False)
        self.assertEqual(132, gv.to_int(False))
Example #2
0
    def testCreateGenericIntValue(self):
        ty = Type.int8()
        gv = GenericValue.of_int(ty, 4, True)
        self.assertEqual(4, gv.to_int(True))

        gv = GenericValue.of_int(ty, 128 + 4, False)
        self.assertEqual(132, gv.to_int(False))
Example #3
0
 def testLessThanZero(self):
     mod, _ = create_lessthanzero_module()
     ee = ExecutionEngine.create_interpreter(mod)
     ty = Type.int8(context=mod.context)
     f = mod.get_function('lessthanzero')
     x = GenericValue.of_int(ty, 3, True)
     y = ee.run_function(f, [x])
     self.assertEqual(0, y.to_int(True) & 1)
     
     x = GenericValue.of_int(ty, -3, True)
     y = ee.run_function(f, [x])
     self.assertEqual(1, y.to_int(True) & 1)
Example #4
0
    def testLessThanZero(self):
        mod, _ = create_lessthanzero_module()
        ee = ExecutionEngine.create_interpreter(mod)
        ty = Type.int8(context=mod.context)
        f = mod.get_function('lessthanzero')
        x = GenericValue.of_int(ty, 3, True)
        y = ee.run_function(f, [x])
        self.assertEqual(0, y.to_int(True) & 1)

        x = GenericValue.of_int(ty, -3, True)
        y = ee.run_function(f, [x])
        self.assertEqual(1, y.to_int(True) & 1)
Example #5
0
    def testAbs(self):
        mod, _ = create_abs_module()
        ee = ExecutionEngine.create_interpreter(mod)
        ty = Type.int8(context=mod.context)
        f = mod.get_function('abs')

        x = GenericValue.of_int(ty, 3, True)
        y = ee.run_function(f, [x])
        self.assertEqual(3, y.to_int(True))

        x = GenericValue.of_int(ty, -3, True)
        y = ee.run_function(f, [x])
        self.assertEqual(3, y.to_int(True) & 255)
Example #6
0
    def testAbs(self):
        mod, _ = create_abs_module()
        ee = ExecutionEngine.create_interpreter(mod)
        ty = Type.int8(context=mod.context)
        f = mod.get_function('abs')

        x = GenericValue.of_int(ty, 3, True)
        y = ee.run_function(f, [x])
        self.assertEqual(3, y.to_int(True))

        x = GenericValue.of_int(ty, -3, True)
        y = ee.run_function(f, [x])
        self.assertEqual(3, y.to_int(True) & 255)
Example #7
0
    def testGlobalArrayLoadStore(self):
        mod = create_global_load_save_array_module()
        ee = ExecutionEngine.create_interpreter(mod)
        load = mod.get_function('load')
        ptr_ty = Type.int64(context=mod.context)
        offset = GenericValue.of_int(ptr_ty, 1, True)
        x0 = ee.run_function(load, [offset])
        self.assertEqual(0, x0.to_int(True))

        ty = Type.int8(context=mod.context)
        y = GenericValue.of_int(ty, 4, True)
        store = mod.get_function('store')
        ee.run_function(store, [y, offset])
        x = ee.run_function(load, [offset])
        self.assertEqual(4, x.to_int(True))
Example #8
0
    def testGlobalArrayLoadStore(self):
        mod = create_global_load_save_array_module()
        ee = ExecutionEngine.create_interpreter(mod)
        load = mod.get_function('load')
        ptr_ty = Type.int64(context=mod.context)
        offset = GenericValue.of_int(ptr_ty, 1, True)
        x0 = ee.run_function(load, [offset])
        self.assertEqual(0, x0.to_int(True))

        ty = Type.int8(context=mod.context)
        y = GenericValue.of_int(ty, 4, True)
        store = mod.get_function('store')
        ee.run_function(store, [y, offset])
        x = ee.run_function(load, [offset])
        self.assertEqual(4, x.to_int(True))
Example #9
0
 def testTimesTwoWithFunction(self):
     mod = create_timestwo_module_with_function()
     ee = ExecutionEngine.create_interpreter(mod)
     ty = Type.int8(context=mod.context)
     f = mod.get_function('caller')
     x = GenericValue.of_int(ty, 3, True)
     y = ee.run_function(f, [x])
     self.assertEqual(6, y.to_int(True))
Example #10
0
 def testCumsum(self):
     mod, _ = create_cumsum_module()
     ee = ExecutionEngine.create_interpreter(mod)
     ty = Type.int8(context=mod.context)
     f = mod.get_function('cumsum')
     x = GenericValue.of_int(ty, 10, True)
     y = ee.run_function(f, [x])
     self.assertEqual(55, y.to_int(True))
Example #11
0
 def testTimesTwoWithFunction(self):
     mod = create_timestwo_module_with_function()
     ee = ExecutionEngine.create_interpreter(mod)
     ty = Type.int8(context=mod.context)
     f = mod.get_function('caller')
     x = GenericValue.of_int(ty, 3, True)
     y = ee.run_function(f, [x])
     self.assertEqual(6, y.to_int(True))
Example #12
0
 def testCumsum(self):
     mod, _ = create_cumsum_module()
     ee = ExecutionEngine.create_interpreter(mod)
     ty = Type.int8(context=mod.context)
     f = mod.get_function('cumsum')
     x = GenericValue.of_int(ty, 10, True)
     y = ee.run_function(f, [x])
     self.assertEqual(55, y.to_int(True))
Example #13
0
 def testTimesTwoC(self):
     mod = parse_bitcode('timestwo.c')
     ee = ExecutionEngine.create_interpreter(mod)
     ty = Type.int32(context=mod.context)
     f = mod.get_function('timestwo')
     x = GenericValue.of_int(ty, 3, True)
     y = ee.run_function(f, [x])
     
     self.assertEqual(6, y.to_int(True))
Example #14
0
    def testTimesTwoC(self):
        mod = parse_bitcode('timestwo.c')
        ee = ExecutionEngine.create_interpreter(mod)
        ty = Type.int32(context=mod.context)
        f = mod.get_function('timestwo')
        x = GenericValue.of_int(ty, 3, True)
        y = ee.run_function(f, [x])

        self.assertEqual(6, y.to_int(True))
Example #15
0
 def testCreateGenericDouble(self):
     ty = Type.double()
     gv = GenericValue.of_float(ty, 3.5)
     x = gv.to_float(ty)
     self.assertTrue(x - 3.5 < 0.001 and
                     3.5 - x < 0.001)
Example #16
0
 def testCreateGenericDouble(self):
     ty = Type.double()
     gv = GenericValue.of_float(ty, 3.5)
     x = gv.to_float(ty)
     self.assertTrue(x - 3.5 < 0.001 and 3.5 - x < 0.001)