void cpp_from_cloog::process( clast_stmt *stmt ) { if (CLAST_STMT_IS_A(stmt, stmt_root)) { process( reinterpret_cast<clast_root*>(stmt) ); } else if (CLAST_STMT_IS_A(stmt, stmt_block)) { process( reinterpret_cast<clast_block*>(stmt) ); } else if (CLAST_STMT_IS_A(stmt, stmt_ass)) { process( reinterpret_cast<clast_assignment*>(stmt) ); } else if (CLAST_STMT_IS_A(stmt, stmt_guard)) { process( reinterpret_cast<clast_guard*>(stmt) ); } else if (CLAST_STMT_IS_A(stmt, stmt_for)) { process( reinterpret_cast<clast_for*>(stmt) ); } else if (CLAST_STMT_IS_A(stmt, stmt_user)) { process( reinterpret_cast<clast_user_stmt*>(stmt) ); } else throw std::runtime_error("Unexpected statement type."); }
static void traverseClast (struct clast_stmt* s, std::vector<const char*>& its) { // Traverse the clast. for ( ; s; s = s->next) { if (CLAST_STMT_IS_A(s, stmt_for) || CLAST_STMT_IS_A(s, stmt_parfor) || CLAST_STMT_IS_A(s, stmt_vectorfor)) { struct clast_for* f = (struct clast_for*) s; std::vector<const char*>::const_iterator i; for (i = its.begin(); i != its.end(); ++i) if (*i == f->iterator) break; if (i == its.end()) its.push_back(f->iterator); traverseClast (((struct clast_for*)s)->body, its); } else if (CLAST_STMT_IS_A(s, stmt_guard)) traverseClast (((struct clast_guard*)s)->then, its); else if (CLAST_STMT_IS_A(s, stmt_block)) traverseClast (((struct clast_block*)s)->body, its); } }
void ClastVisitor::visit(const clast_stmt *stmt) { if (CLAST_STMT_IS_A(stmt, stmt_root)) assert(false && "No second root statement expected"); else if (CLAST_STMT_IS_A(stmt, stmt_ass)) return visitAssignment((const clast_assignment *)stmt); else if (CLAST_STMT_IS_A(stmt, stmt_user)) return visitUser((const clast_user_stmt *)stmt); else if (CLAST_STMT_IS_A(stmt, stmt_block)) return visitBlock((const clast_block *)stmt); else if (CLAST_STMT_IS_A(stmt, stmt_for)) return visitFor((const clast_for *)stmt); else if (CLAST_STMT_IS_A(stmt, stmt_guard)) return visitGuard((const clast_guard *)stmt); if (stmt->next) visit(stmt->next); }
void cpp_from_cloog::process( clast_user_stmt* stmt ) { vector<expression_ptr> index; clast_stmt *index_stmt = stmt->substitutions; while(index_stmt) { assert(CLAST_STMT_IS_A(index_stmt, stmt_ass)); clast_expr *index_expr = reinterpret_cast<clast_assignment*>(index_stmt)->RHS; index.push_back( process(index_expr) ); index_stmt = index_stmt->next; } if (m_stmt_func) { m_stmt_func(stmt->statement->name, index, m_ctx); } else { state s; ostringstream text; text << stmt->statement->name; text << "("; for(auto expr : index) { expr->generate(s, text); text << ","; } text << ")"; m_ctx->add( make_shared<comment_statement>(text.str()) ); } }