I am new to P4. I want to change IR in the front-end e.g. changing node number. I made a new pass (class) in frontend.cpp by inheriting Visitor to change IR by this pass. Also, I found this code in compiler design slides for changing Visitor but I am not sure about the way of using it for changing IR. I would be very grateful if you can give me some hints. Thank you in advance.
The node numbers are generated internally by the constructors are are used only for debugging.
I donāt see what benefit you have in changing them.
The frontend.cpp is a sequence of passes that are applied to the program. Each pass consumes a program and produces another program. If you insert your pass in that sequence it will be executed when its turn comes. You donāt need to call āapplyā - the frontend does that for all passes in the sequence.
Thank you so much. I mentioned changing the node number as a simple example for starting or my main goal is changing node type and adding the new nodes (adding some p4 codes by changing IR). I made this code in frontend.cpp and have this error. I would be very grateful if you can give me some hints (I have read most of the codes in ir directory and tried to define v1 in node.h)
class newpass : public Visitor {
public:
const IR::Node* node;
IR::Visitor v1;
const IR::Node* intermediate = node->v1;
};
/home/serpico/Desktop/p4c/frontends/p4/frontend.cpp:116:9: error: āVisitorā in namespace āIRā does not name a type
116 | IR::Visitor v1;
| ^~~
/home/serpico/Desktop/p4c/frontends/p4/frontend.cpp:117:42: error: āconst class IR::Nodeā has no member named āv1ā
117 | const IR::Node* intermediate = node->v1;