forked from rose-compiler/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addArbitraryTextForUnparser.C
50 lines (38 loc) · 1.48 KB
/
addArbitraryTextForUnparser.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Example ROSE Translator: used within ROSE/tutorial
#include "rose.h"
using namespace std;
class visitorTraversal : public AstSimpleProcessing
{
public:
virtual void visit(SgNode* n);
};
void visitorTraversal::visit(SgNode* n)
{
SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(n);
if (functionDeclaration != NULL)
{
// This is an example of a XYZ tool specific annotation
string compilerSpecificDirective = "\n#if XYZ_TOOL \n \"builtin\"\n#endif\n";
SageInterface::addTextForUnparser(functionDeclaration,compilerSpecificDirective,AstUnparseAttribute::e_before);
}
SgValueExp* valueExp = isSgValueExp(n);
if (valueExp != NULL)
{
// Add a backend specific compiler directive
string compilerSpecificDirective = "\n#if CRAY \n cray_specific_attribute \n#endif\n";
SageInterface::addTextForUnparser(valueExp,compilerSpecificDirective,AstUnparseAttribute::e_before);
}
}
// Typical main function for ROSE translator
int main( int argc, char * argv[] )
{
// Initialize and check compatibility. See Rose::initialize
ROSE_INITIALIZE;
// Build the AST used by ROSE
SgProject* project = frontend(argc,argv);
// Build the traversal object
visitorTraversal exampleTraversal;
// Call the traversal starting at the project node of the AST
exampleTraversal.traverseInputFiles(project,preorder);
return backend(project);
}