ast_construction
AST construction
Synopsis
Declared in <src/docs/mrdocs/rose/ast_construction.h>
struct ast_construction;
Description
AST construction is a fundamental operation needed for building ROSE source‐to‐source translators. Several levels of interfaces are available in ROSE for users to build AST from scratch. High‐level interfaces are recommended whenever possible for their simplicity. Low‐level interfaces can give users maximum freedom to manipulate details in AST trees.
This tutorial demonstrates how to create AST fragments for common language constructs (such as variable declarations, functions, function calls, etc.) and how to insert them into an existing AST tree.
Building a variable declaration using the high‐level AST construction and manipulation interfaces defined in the SageBuilder and SageInterface namespaces.
Full listing: tutorial/addVariableDeclaration2.C
The high‐level construction builds a variable declaration node using buildVariableDeclaration() and inserts it into the AST with prependStatement(). Scope pointers, symbol tables, and source file position information are handled transparently.
Building the variable declaration using low‐level member functions of SAGE III node classes. The low‐level approach requires manual handling of scope, parent pointers, and symbol tables.
Full listing: tutorial/addVariableDeclaration.C
A translator using the high‐level AST builder interface can be used to add an assignment statement before the last statement in a main() function.
Full listing: tutorial/addExpression.C
Adding an assignment statement before the last statement in a main() function using the high‐level AST builder interface.
Full listing: tutorial/addAssignmentStmt.C
Adding a function at the top of a global scope using both high‐level and low‐level constructions.
Full listing: tutorial/addFunctionDeclaration2.C
Stack
Full listing: tutorial/addFunctionDeclaration3.C
Full listing: tutorial/addFunctionDeclaration.C
Adding function calls to instrument code using the AST string‐based rewrite mechanism or the AST builder interface.
Full listing: tutorial/addFunctionCalls.C
This tutorial demonstrates how to repackage global variables into a struct to support Charm++. The translator also updates all references to global variables so that they reference the variables indirectly through the struct. This is a preprocessing step required to use Charm++ and AMPI.
The example uses low‐level AST manipulation at the level of the IR. More concise versions using SageInterface and SageBuilder functions should be considered for high‐level manipulation.
The following example repackages global variables in an application into a struct.
Full listing: tutorial/CharmSupport.C
(Part 2)
This part shows the continuation of the repackaging of global variables into a struct.
Full listing: tutorial/CharmSupport.C
The third part of the example, continuing the transformation of global variables into a struct.
Full listing: tutorial/CharmSupport.C
(Part 4)
This part completes the transformation and repackaging of global variables into a struct.
Full listing: tutorial/CharmSupport.C
This is the final part of the global variable repackaging and struct manipulation process.
Full listing: tutorial/CharmSupport.C
Example source code used as input to the translator for repackaging global variables into a struct.
Full listing: tutorial/inputCode_ExampleCharmSupport.C
Repackaging
The output of the input after the translator repackages the global variables into a struct.
Full listing: tutorial/rose_inputCode_ExampleCharmSupport.C
Created with MrDocs