[51587aa] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[35b1bf4] | 7 | // Generate.cc -- |
---|
[51587aa] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[07de76b] | 11 | // Last Modified By : Peter A. Buhr |
---|
[60a8062] | 12 | // Last Modified On : Sun Feb 16 03:01:51 2020 |
---|
| 13 | // Update Count : 9 |
---|
[51587aa] | 14 | // |
---|
[3268a58] | 15 | #include "Generate.h" |
---|
[51587aa] | 16 | |
---|
[bf2438c] | 17 | #include <iostream> // for ostream, endl, operator<< |
---|
| 18 | #include <list> // for list |
---|
| 19 | #include <string> // for operator<< |
---|
[51b7345] | 20 | |
---|
[0bd3faf] | 21 | #include "CodeGeneratorNew.hpp" // for CodeGenerator, doSemicolon, ... |
---|
[bf2438c] | 22 | #include "GenType.h" // for genPrettyType |
---|
[51b7345] | 23 | |
---|
| 24 | using namespace std; |
---|
| 25 | |
---|
| 26 | namespace CodeGen { |
---|
[8941b6b] | 27 | |
---|
| 28 | namespace { |
---|
| 29 | bool shouldClean( ast::Decl const * decl ) { |
---|
| 30 | return dynamic_cast<ast::TraitDecl const *>( decl ); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | /// Removes various nodes that should not exist in CodeGen. |
---|
[0bd3faf] | 34 | struct TreeCleaner final { |
---|
[8941b6b] | 35 | ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt ) { |
---|
| 36 | auto mutStmt = ast::mutate( stmt ); |
---|
| 37 | erase_if( mutStmt->kids, []( ast::Stmt const * stmt ){ |
---|
| 38 | auto declStmt = dynamic_cast<ast::DeclStmt const *>( stmt ); |
---|
| 39 | return ( declStmt ) ? shouldClean( declStmt->decl ) : false; |
---|
| 40 | } ); |
---|
| 41 | return mutStmt; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | ast::Stmt const * postvisit( ast::ImplicitCtorDtorStmt const * stmt ) { |
---|
| 45 | return stmt->callStmt; |
---|
| 46 | } |
---|
| 47 | }; |
---|
| 48 | } // namespace |
---|
| 49 | |
---|
| 50 | void generate( ast::TranslationUnit & translationUnit, std::ostream & os, bool doIntrinsics, |
---|
| 51 | bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) { |
---|
| 52 | erase_if( translationUnit.decls, shouldClean ); |
---|
[0bd3faf] | 53 | ast::Pass<TreeCleaner>::run( translationUnit ); |
---|
[8941b6b] | 54 | |
---|
[0bd3faf] | 55 | ast::Pass<CodeGenerator> cgv( os, |
---|
[8941b6b] | 56 | Options( pretty, generateC, lineMarks, printExprTypes ) ); |
---|
| 57 | for ( auto & decl : translationUnit.decls ) { |
---|
| 58 | if ( decl->linkage.is_generatable && (doIntrinsics || !decl->linkage.is_builtin ) ) { |
---|
| 59 | cgv.core.updateLocation( decl ); |
---|
| 60 | decl->accept( cgv ); |
---|
| 61 | if ( doSemicolon( decl ) ) { |
---|
| 62 | os << ";"; |
---|
| 63 | } |
---|
| 64 | os << cgv.core.endl; |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
[51b7345] | 69 | } // namespace CodeGen |
---|
[51587aa] | 70 | |
---|
| 71 | // Local Variables: // |
---|
| 72 | // tab-width: 4 // |
---|
| 73 | // mode: c++ // |
---|
| 74 | // compile-command: "make install" // |
---|
| 75 | // End: // |
---|