Exemplo n.º 1
0
 def visit_expr_indexed_fieldref(self, e):
     from .model_pretty_printer import ModelPrettyPrinter
     if isinstance(e.root, ExprArraySubscriptModel) and e.root.rhs.fm in self.index_set:
         actual_root = e.root.lhs.fm.field_l[int(e.root.rhs.fm.get_val())]
         self._expr = ExprFieldRefModel(e.get_target(actual_root))
     else:
         ConstraintCopyBuilder.visit_expr_indexed_fieldref(self, e)
Exemplo n.º 2
0
 def visit_expr_fieldref(self, e : ExprFieldRefModel):
     if self.phase != 1:
         return
     
     if e.fm in self.index_set:
         # Replace the index with the appropriate literal value
         self._expr = ExprLiteralModel(int(e.fm.get_val()), False, 32)
     else:
         ConstraintCopyBuilder.visit_expr_fieldref(self, e)
Exemplo n.º 3
0
    def visit_expr_array_subscript(self, s : ExprArraySubscriptModel):
        if self.phase != 1:
            return

        if isinstance(s.rhs, ExprFieldRefModel) and s.rhs.fm in self.index_set:
            # Convert this index into a direct reference
            self._expr = ExprFieldRefModel(
                s.lhs.fm.field_l[int(s.rhs.fm.get_val())])
        else:
            ConstraintCopyBuilder.visit_expr_array_subscript(self, s)
Exemplo n.º 4
0
    def test_simple(self):
        a = FieldScalarModel("a", 16, False, True)
        b = FieldScalarModel("b", 16, False, True)
        c = FieldScalarModel("c", 16, False, True)
        l = ExprLiteralModel(10, False, 8)
        ab_c = ConstraintBlockModel("ab_c", [
            ConstraintImpliesModel(
                ExprBinModel(ExprFieldRefModel(a), BinExprType.Lt,
                             ExprFieldRefModel(b)),
                [
                    ConstraintExprModel(
                        ExprBinModel(ExprFieldRefModel(c), BinExprType.Eq, l))
                ])
        ])

        copy = ConstraintCopyBuilder.copy(ab_c)
        self.assertEquals(1, len(copy))
        self.assertIsNot(ab_c, copy[0])