Tuesday, April 8, 2014

SPOTC

programFile
:'Transformer' ID '{' transformBody (';' transformBody)* '}';
transformBody
:transformScope '{' transformStatement+ '}'
|'Include Code' '{' sourceCode '}';
transformScope
:'Within' '(' highLevelConstruct ID ')';
highLevelConstruct
:'Function'
|'Struct'
|'Union'
|'File'
|'Project';
transformStatement
: operation
| subTransform;
operation
:actionVariable ';'
|actionStatement ';'
|actionFunction ';'
|highLevelConstruct ID '=' actionRetrieve ';';
subTransform
:transformLocation '{' operation+ '}';
actionVariable
:'AddVariable' '(' typeName ',' ID (',' initializedVal)? ')'
|'DeleteVariable' '(' ID ')'
|'RenameVariable' '(' oldName=ID ',' newName=ID ')';
actionStatement
:'AddCallStatement' '(' ID (',' callArgumentList)? ')'
|'AddCommentStatement''('ID')'
|'AddStatement' '(' statementType ')';
actionFunction
:'RenameFunction' '(' oldName=ID ',' newName=ID ')';
actionRetrieve
:'GetFunction' '(' ID ')'
|'GetFunctions' '(' prefix =ID? '*'? ')'
|'GetStruct' '(' ID ')'
|'GetVariable' '(' ID ')';
transformLocation
: locationKeyword '(' statementType ')';
locationKeyword
:'Around'
|'After'
|'Before'
|'Within';
statementType
:assignmentStatement
|callStatement
|ifStatementWhole
|doStatement
|whileStatement
|forStatement
|declareStatement;
view raw gistfile1.g4 hosted with ❤ by GitHub

class ProfilingMetaFile: public MetaFile{
public:
ProfilingMetaFile(SgNode* astNode);
virtual bool translateDefinition();
};
bool ProfilingMetaFile::translateDefinition(){
for(int i=0; i<functionList.size(); i++){
pushScopeStack(functionList[i]->getFunctionBodyScope());
functionList[i]->functionNormalization();
vector<SgFunctionCallExp*> funCallList = functionList[i]->getFunctionCallList();
for(int j=0; j<funCallList.size(); j++){
string callerName = functionList[i]->getName();
string calleeName = get_name(funCallList[j]);
SgStatement* targetStmt = functionList[i]->getStmtsContainFunctionCall(funCallList[j]);
string identifier = callerName + ":" + calleeName;
insertStatementBefore(targetStmt, buildFunctionCallStmt("profiling", new SgTypeVoid(),\
buildParaList(identifier)));
insertStatementAfter(targetStmt, buildFunctionCallStmt("profiling", new SgTypeVoid(),\
buildParaList(identifier)));
}
popScopeStack();
}
}
view raw gistfile1.cpp hosted with ❤ by GitHub

No comments:

Post a Comment