source: src/CodeGen/CodeGenerator.h@ 65cec25

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 65cec25 was f7cb0bc, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

refactor indenter from CodeGen and CurrentObject

  • Property mode set to 100644
File size: 5.3 KB
Line 
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//
7// CodeGenerator.h --
8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
11// Last Modified By : Andrew Beach
12// Last Modified On : Thu Jun 8 15:48:00 2017
13// Update Count : 52
14//
15
16#ifndef CODEGENV_H
17#define CODEGENV_H
18
19#include <list>
20
21#include "SynTree/Declaration.h"
22#include "SynTree/SynTree.h"
23#include "SynTree/Visitor.h"
24
25#include "SymTab/Indexer.h"
26
27#include "Common/Indenter.h"
28#include "Common/utility.h"
29
30namespace CodeGen {
31 class CodeGenerator : public Visitor {
32 public:
33 static int tabsize;
34
35 CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false );
36 CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false );
37 CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false );
38
39 //*** Declaration
40 virtual void visit( StructDecl * );
41 virtual void visit( FunctionDecl * );
42 virtual void visit( ObjectDecl * );
43 virtual void visit( UnionDecl *aggregateDecl );
44 virtual void visit( EnumDecl *aggregateDecl );
45 virtual void visit( TraitDecl *aggregateDecl );
46 virtual void visit( TypedefDecl *typeDecl );
47 virtual void visit( TypeDecl *typeDecl );
48
49 //*** Initializer
50 virtual void visit( Designation * );
51 virtual void visit( SingleInit * );
52 virtual void visit( ListInit * );
53 virtual void visit( ConstructorInit * );
54
55 //*** Constant
56 virtual void visit( Constant * );
57
58 //*** Expression
59 virtual void visit( ApplicationExpr *applicationExpr );
60 virtual void visit( UntypedExpr *untypedExpr );
61 virtual void visit( RangeExpr * rangeExpr );
62 virtual void visit( NameExpr *nameExpr );
63 virtual void visit( AddressExpr *addressExpr );
64 virtual void visit( CastExpr *castExpr );
65 virtual void visit( UntypedMemberExpr *memberExpr );
66 virtual void visit( MemberExpr *memberExpr );
67 virtual void visit( VariableExpr *variableExpr );
68 virtual void visit( ConstantExpr *constantExpr );
69 virtual void visit( SizeofExpr *sizeofExpr );
70 virtual void visit( AlignofExpr *alignofExpr );
71 virtual void visit( UntypedOffsetofExpr *offsetofExpr );
72 virtual void visit( OffsetofExpr *offsetofExpr );
73 virtual void visit( OffsetPackExpr *offsetPackExpr );
74 virtual void visit( LogicalExpr *logicalExpr );
75 virtual void visit( ConditionalExpr *conditionalExpr );
76 virtual void visit( CommaExpr *commaExpr );
77 virtual void visit( CompoundLiteralExpr *compLitExpr );
78 virtual void visit( UntypedTupleExpr *tupleExpr );
79 virtual void visit( TupleExpr *tupleExpr );
80 virtual void visit( TupleIndexExpr * tupleExpr );
81 virtual void visit( TypeExpr *typeExpr );
82 virtual void visit( AsmExpr * );
83 virtual void visit( StmtExpr * );
84
85 //*** Statements
86 virtual void visit( CompoundStmt * );
87 virtual void visit( ExprStmt * );
88 virtual void visit( AsmStmt * );
89 virtual void visit( AsmDecl * ); // special: statement in declaration context
90 virtual void visit( IfStmt * );
91 virtual void visit( SwitchStmt * );
92 virtual void visit( CaseStmt * );
93 virtual void visit( BranchStmt * );
94 virtual void visit( ReturnStmt * );
95 virtual void visit( ThrowStmt * );
96 virtual void visit( WhileStmt * );
97 virtual void visit( ForStmt * );
98 virtual void visit( NullStmt * );
99 virtual void visit( DeclStmt * );
100
101 void genAttributes( std::list< Attribute * > & attributes );
102
103 template< class Iterator > void genCommaList( Iterator begin, Iterator end );
104
105 struct LabelPrinter {
106 LabelPrinter(CodeGenerator &cg) : cg(cg), labels( 0 ) {}
107 LabelPrinter & operator()( std::list< Label > & l );
108 CodeGenerator & cg;
109 std::list< Label > * labels;
110 };
111
112 struct LineMarker {
113 CodeLocation const & loc;
114 bool toPrint;
115
116 LineMarker(CodeLocation const & loc, bool toPrint);
117 };
118
119 LineMarker lineDirective(BaseSyntaxNode const * node);
120
121 void asmName( DeclarationWithType *decl );
122
123 void extension( Expression *expr );
124 void extension( Declaration *decl );
125 private:
126 Indenter indent;
127 bool insideFunction;
128 std::ostream &output;
129 LabelPrinter printLabels;
130 bool pretty = false; // pretty print
131 bool genC = false; // true if output has to be C code
132 bool lineMarks = false;
133
134 void handleStorageClass( DeclarationWithType *decl );
135 void handleAggregate( AggregateDecl *aggDecl, const std::string & kind );
136 void handleTypedef( NamedTypeDecl *namedType );
137 std::string mangleName( DeclarationWithType * decl );
138 }; // CodeGenerator
139
140 template< class Iterator >
141 void CodeGenerator::genCommaList( Iterator begin, Iterator end ) {
142 if ( begin == end ) return;
143 for ( ;; ) {
144 (*begin++)->accept( *this );
145 if ( begin == end ) break;
146 output << ", "; // separator
147 } // for
148 } // genCommaList
149
150 inline bool doSemicolon( Declaration* decl ) {
151 if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) {
152 return ! func->get_statements();
153 } // if
154 return true;
155 } // doSemicolon
156
157 /// returns C-compatible name of declaration
158 std::string genName( DeclarationWithType * decl );
159
160 std::ostream & operator<<(std::ostream &,
161 CodeGenerator::LineMarker const &);
162} // namespace CodeGen
163
164#endif // CODEGENV_H
165
166// Local Variables: //
167// tab-width: 4 //
168// mode: c++ //
169// compile-command: "make install" //
170// End: //
Note: See TracBrowser for help on using the repository browser.