... | ... | @@ -240,7 +240,9 @@ There is also a template for your traversal `.c` file, here it is: |
|
|
*
|
|
|
* description:
|
|
|
* Longer traversal description goes here with examples.
|
|
|
*
|
|
|
*
|
|
|
* example:
|
|
|
*
|
|
|
* @{
|
|
|
**********************************************************/
|
|
|
|
... | ... | @@ -332,7 +334,8 @@ node * |
|
|
TEMPmodule (node *arg_node, info *arg_info)
|
|
|
{
|
|
|
DBUG_ENTER ();
|
|
|
|
|
|
|
|
|
DBUG_ASSERT (NODE_TYPE (arg_node) == N_module, "called with non-module node");
|
|
|
MODULE_FUNS (arg_node) = TRAVopt (MODULE_FUNS (arg_node), arg_info);
|
|
|
|
|
|
DBUG_RETURN (arg_node);
|
... | ... | @@ -410,6 +413,13 @@ You should define accessor macros for all the fields of your info struct. |
|
|
You can actually alter the AST by returning a modified node.
|
|
|
Think if you need to make a copy of the node before returning it.
|
|
|
Special recursive copy functions are generated from `ast.xml` which can copy nodes correctly.
|
|
|
|
|
|
## General Tips
|
|
|
|
|
|
- Use `TRAVopt` instead of `TRAVdo` if the node you traverse is maybe `NULL`.
|
|
|
- Flags should be a question. For example call them `IsSafe` instead of `Safe`.
|
|
|
- The description of a traversal should be in the .c file because this is where the is.
|
|
|
|
|
|
# Step 6: Register your phase in the compiler
|
|
|
|
|
|
Once your traversal compiles, and you are happy, you can actually add it the compiler.
|
... | ... | |