source: src/CodeGen/Generate.cc@ a0c7dc36

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since a0c7dc36 was a984e65, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Remove TraitDecl prior to CodeGen, add debug codegen for TraitDecl

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[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
[a984e65]23#include "Common/PassVisitor.h" // for PassVisitor
[bf2438c]24#include "Parser/LinkageSpec.h" // for isBuiltin, isGeneratable
25#include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode
26#include "SynTree/Declaration.h" // for Declaration
27#include "SynTree/Type.h" // for Type
[51b73452]28
29using namespace std;
30
31namespace CodeGen {
[a984e65]32 namespace {
33 /// Removes misc. nodes that should not exist in CodeGen
34 struct TreeCleaner {
35 void visit( CompoundStmt * stmt );
36
37 static bool shouldClean( Declaration * );
38 };
39
40 void cleanTree( std::list< Declaration * > & translationUnit ) {
41 PassVisitor<TreeCleaner> cleaner;
42 filter( translationUnit, [](Declaration * decl) { return TreeCleaner::shouldClean(decl); }, false );
43 acceptAll( translationUnit, cleaner );
44 } // cleanTree
45 } // namespace
46
[c850687]47 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks ) {
[a984e65]48 cleanTree( translationUnit );
49
[c850687]50 CodeGen::CodeGenerator cgv( os, pretty, generateC, lineMarks );
[e6512c8]51 for ( auto & dcl : translationUnit ) {
52 if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
[0dd18fd]53 cgv.updateLocation( dcl );
[e6512c8]54 dcl->accept(cgv);
55 if ( doSemicolon( dcl ) ) {
[51587aa]56 os << ";";
57 } // if
58 os << std::endl;
59 } // if
60 } // for
61 }
[262f085f]62
63 void generate( BaseSyntaxNode * node, std::ostream & os ) {
64 if ( Type * type = dynamic_cast< Type * >( node ) ) {
65 os << CodeGen::genPrettyType( type, "" );
66 } else {
[c850687]67 CodeGen::CodeGenerator cgv( os, true, false, false );
[262f085f]68 node->accept( cgv );
69 }
70 os << std::endl;
71 }
[a984e65]72
73 namespace {
74 void TreeCleaner::visit( CompoundStmt * cstmt ) {
75 filter( cstmt->kids, [](Statement * stmt) {
76 if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( stmt ) ) {
77 return shouldClean( declStmt->decl );
78 }
79 return false;
80 }, false );
81 }
82
83 bool TreeCleaner::shouldClean( Declaration * decl ) {
84 return dynamic_cast< TraitDecl * >( decl );
85 }
86 } // namespace
[51b73452]87} // namespace CodeGen
[51587aa]88
89// Local Variables: //
90// tab-width: 4 //
91// mode: c++ //
92// compile-command: "make install" //
93// End: //
Note: See TracBrowser for help on using the repository browser.