Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 395
    • Issues 395
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 22
    • Merge requests 22
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Wiki
  • Tutorials
  • adding a traversal

adding a traversal · Changes

Page history
Added beginnings of Coding-Style.md, fixed safe proposal based on latest... authored Feb 22, 2025 by Quinten Cabo's avatar Quinten Cabo
Added beginnings of Coding-Style.md, fixed safe proposal based on latest discussion and fixed of adding a traversal tutorial with TRAVOpt and so on
Hide whitespace changes
Inline Side-by-side
tutorials/adding-a-traversal.md
View page @ d3340cbf
......@@ -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.
......
Clone repository
  • concepts
    • Deprecated Modules
    • Globals
    • Named Tuples
    • Overloading
    • Preprocessor
    • Primitive functions
    • Runetime Representations
    • input stdin
    • phm xt
    • ref counting methods
    • type famlies
    • type patterns
  • error messages
    • Anthropomorphic error essages
    • Colored error messages
    • Empty file error
View All Pages