26 const IR::V1Program *global;
27 class SubstActionArgs :
public Transform {
28 const IR::ActionFunction *function;
29 const IR::Primitive *callsite;
30 const IR::Node *postorder(IR::ActionArg *arg)
override {
31 for (
unsigned i = 0; i < function->args.size(); ++i)
32 if (function->args[i] == getOriginal())
return callsite->operands[i];
33 BUG(
"Action arg not argument of action");
38 SubstActionArgs(
const IR::ActionFunction *f,
const IR::Primitive *c)
39 : function(f), callsite(c) {}
42 const IR::V1Program *preorder(IR::V1Program *gl)
override {
return global = gl; }
43 const IR::Node *preorder(IR::Primitive *p)
override {
44 if (
auto af = global->get<IR::ActionFunction>(p->name)) {
45 SubstActionArgs saa(af, p);
46 saa.setCalledBy(
this);
47 return af->action.clone()->apply(saa);