Ejemplo n.º 1
0
    def test_FixExpr(self):
        init_state = MetaState({self.x: IntegerInterval(0)})
        init_label, init_env = self.label(init_state)

        invar = BoxState({self.x: IntegerInterval([0, 4])})
        end_invar = BoxState({self.x: IntegerInterval([1, 5])})

        loop_state = MetaState({
            self.x: BinaryArithExpr(
                operators.ADD_OP, self.x, IntegerInterval(1)),
        })
        loop_label, loop_env = self.label(loop_state, invar)

        bool_expr = BinaryBoolExpr(
            operators.LESS_OP, self.x, IntegerInterval(5))
        bool_labsem = self.label(bool_expr, end_invar)
        bool_label, _ = bool_labsem

        expr = FixExpr(bool_expr, loop_state, self.x, init_state)

        bound = IntegerInterval(5)
        label = self.context.Label(expr, bound, invar)
        label_expr = FixExpr(bool_labsem, loop_env, self.x, init_env)
        env = {label: label_expr}
        test_value = LabelSemantics(label, env)
        self.compare(expr, test_value)
Ejemplo n.º 2
0
 def test_visit_WhileFlow(self):
     flow = self.stmt_parse('while (x < z) {y = y * x; x = x + 1;}')
     state = MetaState({
         self.x: self.x,
         self.y: self.y,
         self.z: self.z,
     })
     state = state.visit_WhileFlow(flow)
     self.assertEqual(state, self._loop_compare_state())
Ejemplo n.º 3
0
 def test_visit_ForFlow(self):
     flow = self.stmt_parse('for (x = x; x < z; x = x + 1) {y = y * x;}')
     state = MetaState({
         self.x: self.x,
         self.y: self.y,
         self.z: self.z,
     })
     state = state.visit_ForFlow(flow)
     self.assertEqual(state, self._loop_compare_state())
Ejemplo n.º 4
0
 def test_visit_AssignFlow(self):
     flow = self.stmt_parse('z = x * y;')
     state = MetaState({
         self.x: self.expr_parse('x + 1'),
         self.y: self.expr_parse('y + 2'),
     })
     state = state.visit_AssignFlow(flow)
     compare_state = MetaState({
         self.x: self.expr_parse('x + 1'),
         self.y: self.expr_parse('y + 2'),
         self.z: self.expr_parse('(x + 1) * (y + 2)'),
     })
     self.assertEqual(state, compare_state)
Ejemplo n.º 5
0
 def test_visit_IfFlow(self):
     flow = self.stmt_parse('if (x < z) {x = x + 1;} else {x = x - 1;}')
     state = MetaState({
         self.x: self.y,
         self.z: self.z,
     })
     state = state.visit_IfFlow(flow)
     compare_state = MetaState({
         self.x:
         self.expr_parse('y < z ? y + 1 : y - 1'),
         self.z:
         self.z,
     })
     self.assertEqual(state, compare_state)
Ejemplo n.º 6
0
 def test_update_expr(self):
     flow = self.stmt_parse('a[x] = 1;')
     state = MetaState({
         self.a: self.a,
         self.x: self.y,
     })
     state = state.visit_AssignFlow(flow)
     compare_state = MetaState({
         self.a:
         UpdateExpr(self.a, [self.y], self.expr_parse('1')),
         self.x:
         self.y,
     })
     self.assertEqual(state, compare_state)
Ejemplo n.º 7
0
 def test_access_expr(self):
     flow = self.stmt_parse('x = a[y];')
     state = MetaState({
         self.a: self.a,
         self.x: self.x,
         self.y: self.y,
     })
     state = state.visit_AssignFlow(flow)
     compare_state = MetaState({
         self.a: self.a,
         self.x: AccessExpr(self.a, [self.y]),
         self.y: self.y,
     })
     self.assertEqual(state, compare_state)
Ejemplo n.º 8
0
 def test_FixExpr(self):
     bool_expr = BinaryBoolExpr(operators.LESS_OP, self.x, self.y)
     loop_state = MetaState({
         self.x: BinaryArithExpr(
             operators.ADD_OP, self.x, IntegerInterval(1)),
         self.y: self.y,
     })
     init_state = MetaState({
         self.x: self.x, self.y: self.y,
     })
     test_expr = FixExpr(bool_expr, loop_state, self.x, init_state)
     test_value = IntegerInterval(3)
     value = arith_eval(test_expr, self.state)
     self.assertEqual(test_value, value)
Ejemplo n.º 9
0
 def test_access_expr_multi(self):
     flow = self.stmt_parse('x = b[y, z];')
     state = MetaState({
         self.b: self.b,
         self.x: self.x,
         self.y: self.y,
         self.z: self.z,
     })
     state = state.visit_AssignFlow(flow)
     subs = [self.y, self.z]
     compare_state = MetaState({
         self.b: self.b,
         self.x: AccessExpr(self.b, subs),
         self.y: self.y,
         self.z: self.z,
     })
     self.assertEqual(state, compare_state)
Ejemplo n.º 10
0
    def _loop_compare_state(self):
        init_state = MetaState({
            self.x: self.x,
            self.z: self.z,
        })
        fix_loop_state = MetaState({
            self.x: self.expr_parse('x + 1'),
            self.z: self.z,
        })

        fix_expr_x = FixExpr(self.expr_parse('x < z'), fix_loop_state, self.x,
                             init_state)

        init_state = init_state.immu_update(self.y, self.y)
        fix_loop_state = fix_loop_state.immu_update(self.y,
                                                    self.expr_parse('y * x'))

        fix_expr_y = FixExpr(self.expr_parse('x < z'), fix_loop_state, self.y,
                             init_state)

        fix_compare_state = MetaState({
            self.x: fix_expr_x,
            self.y: fix_expr_y,
            self.z: self.z,
        })
        return fix_compare_state
Ejemplo n.º 11
0
 def test_MetaState(self):
     meta_state = MetaState({
         self.x: BinaryArithExpr(
             operators.ADD_OP, self.x, IntegerInterval(1)),
         self.y: BinaryArithExpr(
             operators.MULTIPLY_OP, self.x, IntegerInterval(2)),
     })
     test_state = BoxState(x=[2, 3], y=[2, 4])
     state = arith_eval(meta_state, self.state)
     self.assertEqual(test_state, state)
Ejemplo n.º 12
0
 def test_update_expr_multi(self):
     flow = self.stmt_parse('b[x, y] = 1;')
     state = MetaState({
         self.b: self.b,
         self.x: self.y,
         self.y: self.z,
         self.z: self.x,
     })
     state = state.visit_AssignFlow(flow)
     subs = [self.y, self.z]
     compare_state = MetaState({
         self.b:
         UpdateExpr(self.b, subs, self.expr_parse('1')),
         self.x:
         self.y,
         self.y:
         self.z,
         self.z:
         self.x,
     })
     self.assertEqual(state, compare_state)
Ejemplo n.º 13
0
 def test_MetaState(self):
     meta_state = MetaState({self.x: self.x, self.y: self.y})
     env = {
         self.x: self.x_label,
         self.y: self.y_label,
         self.x_label: self.x,
         self.y_label: self.y,
     }
     bound = BoxState(x=self.state[self.x], y=self.state[self.y])
     label = self.context.Label(meta_state, bound, None)
     test_value = LabelSemantics(label, env)
     self.compare(meta_state, test_value)
Ejemplo n.º 14
0
 def test_visit_SkipFlow(self):
     state = MetaState({self.x: self.x})
     compare_state = state.visit_SkipFlow(stmt_parse('skip;'))
     self.assertEqual(state, compare_state)
Ejemplo n.º 15
0
 def test_visit_CompositionalFlow(self):
     flow = self.stmt_parse('x = x + 1; x = x * 2;')
     state = MetaState({self.x: self.x}).visit_CompositionalFlow(flow)
     compare_state = MetaState({self.x: self.expr_parse('(x + 1) * 2')})
     self.assertEqual(state, compare_state)