// ****************************************** // MAIN PROGRAM // ****************************************** 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); assert(project != NULL); vector<SgType*> memberTypes; vector<string> memberNames; string name = "a"; for (int i = 0; i < 10; i++) { memberTypes.push_back(SgTypeInt::createType()); name = "_" + name; memberNames.push_back(name); } // Build the initializer SgExprListExp* initializerList = new SgExprListExp(SOURCE_POSITION); initializerList->set_endOfConstruct(SOURCE_POSITION); SgAggregateInitializer* structureInitializer = new SgAggregateInitializer(SOURCE_POSITION,initializerList); structureInitializer->set_endOfConstruct(SOURCE_POSITION); // Build the data member initializers for the structure (one SgAssignInitializer for each data member) for (unsigned int i = 0; i < memberNames.size(); i++) { // Set initial value to "i" SgIntVal* value = new SgIntVal(SOURCE_POSITION,i); value->set_endOfConstruct(SOURCE_POSITION); SgAssignInitializer* memberInitializer = new SgAssignInitializer(SOURCE_POSITION,value); memberInitializer->set_endOfConstruct(SOURCE_POSITION); structureInitializer->append_initializer(memberInitializer); memberInitializer->set_parent(structureInitializer); } // Access the first file and add a struct with data members specified SgSourceFile* file = isSgSourceFile((*project)[0]); ROSE_ASSERT(file != NULL); SgVariableDeclaration* variableDeclaration = buildStructVariable(file->get_globalScope(),memberTypes,memberNames,"X","x",structureInitializer); file->get_globalScope()->prepend_declaration(variableDeclaration); variableDeclaration->set_parent(file->get_globalScope()); AstTests::runAllTests(project); // Code generation phase (write out new application "rose_<input file name>") return backend(project); }