source: src/CodeGen/CodeGenerator.h @ 44b7088

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 44b7088 was 2a4b088, checked in by Aaron Moss <a3moss@…>, 8 years ago

Make offsetof expressions work

  • Property mode set to 100644
File size: 3.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//
[6c4ff37]7// CodeGenerator.h --
[51587aa]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[cda48b6]11// Last Modified By : Rob Schluntz
[d60ccbf]12// Last Modified On : Wed Aug 12 14:27:14 2015
13// Update Count     : 27
[51587aa]14//
15
[51b7345]16#ifndef CODEGENV_H
17#define CODEGENV_H
18
19#include <list>
20
21#include "SynTree/SynTree.h"
22#include "SynTree/Visitor.h"
23#include "SymTab/Indexer.h"
24
25namespace CodeGen {
[6c4ff37]26        class CodeGenerator : public Visitor {
[51587aa]27          public:
28                static int tabsize;
29
[6c4ff37]30                CodeGenerator( std::ostream &os );
31                CodeGenerator( std::ostream &os, std::string, int indent = 0, bool infun = false );
32                CodeGenerator( std::ostream &os, char *, int indent = 0, bool infun = false );
[51587aa]33
34                //*** Declaration
35                virtual void visit( StructDecl * );
36                virtual void visit( FunctionDecl * );
37                virtual void visit( ObjectDecl * );
38                virtual void visit( UnionDecl *aggregateDecl );
39                virtual void visit( EnumDecl *aggregateDecl );
40                virtual void visit( ContextDecl *aggregateDecl );
41                virtual void visit( TypedefDecl *typeDecl );
42                virtual void visit( TypeDecl *typeDecl );
43
44                //*** Initializer
45                virtual void visit( SingleInit * );
46                virtual void visit( ListInit * );
47
48                //*** Constant
49                virtual void visit( Constant * );
50
51                //*** Expression
52                virtual void visit( ApplicationExpr *applicationExpr );
53                virtual void visit( UntypedExpr *untypedExpr );
54                virtual void visit( NameExpr *nameExpr );
55                virtual void visit( AddressExpr *addressExpr );
56                virtual void visit( CastExpr *castExpr );
57                virtual void visit( UntypedMemberExpr *memberExpr );
58                virtual void visit( MemberExpr *memberExpr );
59                virtual void visit( VariableExpr *variableExpr );
60                virtual void visit( ConstantExpr *constantExpr ); 
61                virtual void visit( SizeofExpr *sizeofExpr );
[47534159]62                virtual void visit( AlignofExpr *alignofExpr );
[2a4b088]63                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
[25a054f]64                virtual void visit( OffsetofExpr *offsetofExpr );
[51587aa]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 );
[7f5566b]70                virtual void visit( AsmExpr * );
[51587aa]71
72                //*** Statements
73                virtual void visit( CompoundStmt * );
74                virtual void visit( ExprStmt * );
[7f5566b]75                virtual void visit( AsmStmt * );
[51587aa]76                virtual void visit( IfStmt * );
77                virtual void visit( SwitchStmt * );
78                virtual void visit( CaseStmt * );
79                virtual void visit( BranchStmt * );
80                virtual void visit( ReturnStmt * );
81                virtual void visit( WhileStmt * );
82                virtual void visit( ForStmt * );
83                virtual void visit( NullStmt * );
84                virtual void visit( DeclStmt * ); 
85
86                template< class Iterator > void genCommaList( Iterator begin, Iterator end );
[cda48b6]87
88                struct Indenter {
89                        Indenter(CodeGenerator &cg) : cg(cg) {}
90                        CodeGenerator & cg;
91                        std::ostream& operator()(std::ostream & os);
92                };
[51587aa]93          private:
[cda48b6]94
95                Indenter indent;
[51587aa]96                int cur_indent;
97                bool insideFunction;
[6c4ff37]98                std::ostream &output;
[51587aa]99
[e45215c]100                void printDesignators( std::list< Expression * > & );
[51587aa]101                static std::string printLabels ( std::list < Label > & );
102                void handleStorageClass( Declaration *decl );
103                void handleAggregate( AggregateDecl *aggDecl );
104                void handleTypedef( NamedTypeDecl *namedType );
105
106        };
107       
108        template< class Iterator >
[6c4ff37]109        void CodeGenerator::genCommaList( Iterator begin, Iterator end ) {
[51587aa]110                if ( begin == end ) return;
111
112                for ( ;; ) {
113                        (*begin++)->accept( *this );
114                        if ( begin == end ) return;
[6c4ff37]115                        output << ", ";
[51587aa]116                } // for
[17cd4eb]117        }
[51b7345]118 
[51587aa]119        inline bool doSemicolon( Declaration* decl ) {
120                if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) {
121                        return ! func->get_statements();
122                } // if
123                return true;
[17cd4eb]124        }
[51b7345]125} // namespace CodeGen
126
[51587aa]127#endif // CODEGENV_H
[51b7345]128
[51587aa]129// Local Variables: //
130// tab-width: 4 //
131// mode: c++ //
132// compile-command: "make install" //
133// End: //
Note: See TracBrowser for help on using the repository browser.