def lower_next(done_stage: vast.IntConst, ns: NextState): """ done_stage is the index of the final stage which just holds the all the values in the register. """ # The computation is finished; transition to the done stage. if isinstance(ns, Done): return vast.Rvalue(done_stage) elif isinstance(ns, DirectNext): return vast.Rvalue(vast.IntConst(ns.state)) elif isinstance(ns, CondNext): return vast.Cond( vast.Rvalue(vast.Identifier(ns.cond.name)), vast.IntConst(ns.on_true), vast.IntConst(ns.on_false), ) else: raise ValueError("Malformed AST, expected next: %s" % ns.pretty())
def visit_Cond(self, node): cond = self.visit(node.condition) true_value = self.visit(node.true_value) false_value = self.visit(node.false_value) return vast.Cond(cond, true_value, false_value)