source: src/CodeGen/CodeGenerator.h @ 6c4ff37

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 6c4ff37 was 6c4ff37, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

rename CodeGenerator2 -> CodeGenerator?, CodeGenerator? refactoring and output reformatting, fix bug where while loop body label does not print

  • Property mode set to 100644
File size: 3.5 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 : Rob Schluntz
12// Last Modified On : Tue Jun 02 11:45:20 2015
13// Update Count     : 9
14//
15
16#ifndef CODEGENV_H
17#define CODEGENV_H
18
19#include <strstream>
20#include <list>
21
22#include "SynTree/SynTree.h"
23#include "SynTree/Visitor.h"
24#include "SymTab/Indexer.h"
25
26namespace CodeGen {
27        class CodeGenerator : public Visitor {
28          public:
29                static int tabsize;
30
31                CodeGenerator( std::ostream &os );
32                CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false );
33                CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false );
34
35                CodeGenerator( CodeGenerator & );
36
37                //*** Declaration
38                virtual void visit( StructDecl * );
39                virtual void visit( FunctionDecl * );
40                virtual void visit( ObjectDecl * );
41                virtual void visit( UnionDecl *aggregateDecl );
42                virtual void visit( EnumDecl *aggregateDecl );
43                virtual void visit( ContextDecl *aggregateDecl );
44                virtual void visit( TypedefDecl *typeDecl );
45                virtual void visit( TypeDecl *typeDecl );
46
47                //*** Initializer
48                virtual void visit( SingleInit * );
49                virtual void visit( ListInit * );
50
51                //*** Constant
52                virtual void visit( Constant * );
53
54                //*** Expression
55                virtual void visit( ApplicationExpr *applicationExpr );
56                virtual void visit( UntypedExpr *untypedExpr );
57                virtual void visit( NameExpr *nameExpr );
58                virtual void visit( AddressExpr *addressExpr );
59                virtual void visit( CastExpr *castExpr );
60                virtual void visit( UntypedMemberExpr *memberExpr );
61                virtual void visit( MemberExpr *memberExpr );
62                virtual void visit( VariableExpr *variableExpr );
63                virtual void visit( ConstantExpr *constantExpr ); 
64                virtual void visit( SizeofExpr *sizeofExpr );
65                virtual void visit( LogicalExpr *logicalExpr );
66                virtual void visit( ConditionalExpr *conditionalExpr );
67                virtual void visit( CommaExpr *commaExpr );
68                virtual void visit( TupleExpr *tupleExpr );
69                virtual void visit( TypeExpr *typeExpr );
70
71                //*** Statements
72                virtual void visit( CompoundStmt * );
73                virtual void visit( ExprStmt * );
74                virtual void visit( IfStmt * );
75                virtual void visit( SwitchStmt * );
76                virtual void visit( CaseStmt * );
77                virtual void visit( BranchStmt * );
78                virtual void visit( ReturnStmt * );
79                virtual void visit( WhileStmt * );
80                virtual void visit( ForStmt * );
81                virtual void visit( NullStmt * );
82                virtual void visit( DeclStmt * ); 
83
84                template< class Iterator > void genCommaList( Iterator begin, Iterator end );
85          private:
86                int cur_indent;
87                bool insideFunction;
88                std::ostream &output;
89
90                static std::string printLabels ( std::list < Label > & );
91                void handleStorageClass( Declaration *decl );
92                void handleAggregate( AggregateDecl *aggDecl );
93                void handleTypedef( NamedTypeDecl *namedType );
94
95        };
96       
97        template< class Iterator >
98        void CodeGenerator::genCommaList( Iterator begin, Iterator end ) {
99                if ( begin == end ) return;
100
101                for ( ;; ) {
102                        (*begin++)->accept( *this );
103                        if ( begin == end ) return;
104                        output << ", ";
105                } // for
106        }
107 
108        inline bool doSemicolon( Declaration* decl ) {
109                if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) {
110                        return ! func->get_statements();
111                } // if
112                return true;
113        }
114} // namespace CodeGen
115
116#endif // CODEGENV_H
117
118// Local Variables: //
119// tab-width: 4 //
120// mode: c++ //
121// compile-command: "make install" //
122// End: //
Note: See TracBrowser for help on using the repository browser.