[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
|
---|
[c850687] | 11 | // Last Modified By : Andrew Beach
|
---|
[0dd18fd] | 12 | // Last Modified On : Fri Aug 18 15:39:00 2017
|
---|
| 13 | // Update Count : 7
|
---|
[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<<
|
---|
[51b73452] | 20 |
|
---|
[bf2438c] | 21 | #include "CodeGenerator.h" // for CodeGenerator, doSemicolon, oper...
|
---|
| 22 | #include "GenType.h" // for genPrettyType
|
---|
| 23 | #include "Parser/LinkageSpec.h" // for isBuiltin, isGeneratable
|
---|
| 24 | #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode
|
---|
| 25 | #include "SynTree/Declaration.h" // for Declaration
|
---|
| 26 | #include "SynTree/Type.h" // for Type
|
---|
[51b73452] | 27 |
|
---|
| 28 | using namespace std;
|
---|
| 29 |
|
---|
| 30 | namespace CodeGen {
|
---|
[c850687] | 31 | void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks ) {
|
---|
| 32 | CodeGen::CodeGenerator cgv( os, pretty, generateC, lineMarks );
|
---|
[e6512c8] | 33 | for ( auto & dcl : translationUnit ) {
|
---|
| 34 | if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
|
---|
[0dd18fd] | 35 | cgv.updateLocation( dcl );
|
---|
[e6512c8] | 36 | dcl->accept(cgv);
|
---|
| 37 | if ( doSemicolon( dcl ) ) {
|
---|
[51587aa] | 38 | os << ";";
|
---|
| 39 | } // if
|
---|
| 40 | os << std::endl;
|
---|
| 41 | } // if
|
---|
| 42 | } // for
|
---|
| 43 | }
|
---|
[262f085f] | 44 |
|
---|
| 45 | void generate( BaseSyntaxNode * node, std::ostream & os ) {
|
---|
| 46 | if ( Type * type = dynamic_cast< Type * >( node ) ) {
|
---|
| 47 | os << CodeGen::genPrettyType( type, "" );
|
---|
| 48 | } else {
|
---|
[c850687] | 49 | CodeGen::CodeGenerator cgv( os, true, false, false );
|
---|
[262f085f] | 50 | node->accept( cgv );
|
---|
| 51 | }
|
---|
| 52 | os << std::endl;
|
---|
| 53 | }
|
---|
[51b73452] | 54 | } // namespace CodeGen
|
---|
[51587aa] | 55 |
|
---|
| 56 | // Local Variables: //
|
---|
| 57 | // tab-width: 4 //
|
---|
| 58 | // mode: c++ //
|
---|
| 59 | // compile-command: "make install" //
|
---|
| 60 | // End: //
|
---|