class Assert(Statement): "Instantiation of a run-time assertion." parser = qmasm.AssertParser() def __init__(self, filename, lineno, expr): super(Assert, self).__init__(filename, lineno) self.expr = expr self.ast = self.parser.parse(expr) self.ast.compile() def as_str(self, prefix=""): if prefix == "": ast = self.ast else: ast = copy.deepcopy(self.ast) ast.apply_prefix(prefix, None) ast.compile() return "!assert " + str(ast) def update_qmi(self, prefix, next_prefix, problem): if prefix == "": ast = self.ast else: ast = copy.deepcopy(self.ast) ast.apply_prefix(prefix, next_prefix) ast.compile() problem.assertions.append(ast)
def append_assertions_from_statements(self): "Convert user-specified chains, anti-chains, and pins to assertions." # Convert pending assertions to actual assertions. # TODO: Quote variables containing special characters. ap = qmasm.AssertParser() for s1, op, s2 in self.pending_asserts: ast = ap.parse(s1 + " " + op + " " + s2) ast.compile() self.assertions.append(ast)