1 /* GDC -- D front-end for GCC
2 Copyright (C) 2004 David Friedman
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef GCC_DCMPLR_IRSTATE_H
20 #define GCC_DCMPLR_IRSTATE_H
22 // Due to the inlined functions, "dc-gcc-includes.h" needs to
23 // be included before this header is included.
29 #include "declaration.h"
30 #include "statement.h"
31 #include "expression.h"
32 #include "aggregate.h"
35 // IRBase contains the core functionality of IRState. The actual IRState class
36 // extends this with lots of code generation utilities.
38 // Currently, each function gets its own IRState when emitting code. There is
39 // also a global IRState.
41 // Most toElem calls don't actually need the IRState because they create GCC
42 // expression trees rather than emit instructions.
44 struct IRBase
: Object
52 // This is used by LabelStatement to find the LabelDsymbol that
53 // GotoStatements refer to.
54 FuncDeclaration
* func
; // %% make this a stack
56 static IRState
* startFunction(FuncDeclaration
* decl
);
59 static Array deferredFuncDecls
;
60 bool shouldDeferFunction(FuncDeclaration
* decl
);
62 static void initFunctionStart(tree fn_decl
, const Loc
& loc
);
70 void pushStatementList();
71 tree
popStatementList();
76 // It is only valid to call this while the function in which the label is defined
78 tree
getLabelTree(LabelDsymbol
* label
);
81 // ** Loops (and case statements)
85 Statement
* statement
;
86 // expand_start_case doesn't return a nesting structure, so
87 // we have to generate our own label for 'break'
90 tree overrideContinueLabel
;
95 Statement
* statement
;
103 tree condition
; // only need this if it is not okay to convert an IfStatement's condition after converting it's branches...
114 Array loops
; // of Flow
116 // These routines don't generate code. They are for tracking labeled loops.
117 Flow
* getLoopForLabel(Identifier
* ident
, bool want_continue
= false);
119 Flow
* beginFlow(Statement
* stmt
, nesting
* loop
);
121 //typedef enum { Break = 0x1, Continue = 0x2 } FlowLabel;
122 Flow
* beginFlow(Statement
* stmt
/*, int labels*/);
125 Flow
* currentFlow() { return (Flow
*) loops
.tos(); }
126 void doLabel(tree t_label
);
128 // ** DECL_CONTEXT support
130 tree
getLocalContext() { return func
? func
->toSymbol()->Stree
: NULL_TREE
; }
132 // ** "Binding contours"
134 /* Definitions for IRBase scope code:
135 "Scope": A container for binding contours. Each user-declared
136 function has a toplevel scope. Every ScopeStatement creates
137 a new scope. (And for now, until the emitLocalVar crash is
138 solved, this also creates a default binding contour.)
140 "Binding countour": Same as GCC's definition, whatever that is.
141 Each user-declared variable will have a binding contour that begins
142 where the variable is declared and ends at it's containing scope.
144 Array scopes
; // of unsigned*
149 void startBindings();
155 unsigned volatileDepth
;
156 bool inVolatile() { return volatileDepth
!= 0; }
157 void pushVolatile() { ++volatileDepth
; }
158 void popVolatile() { --volatileDepth
; }