Added array support back.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of SourcePawn.
6 * SourcePawn is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * SourcePawn. If not, see http://www.gnu.org/licenses/.
18 #ifndef _include_sp2_hir_h_
19 #define _include_sp2_hir_h_
22 #include "../PoolAllocator.h"
23 #include "../Opcodes.h"
33 /* Special LValue types */ \
41 // Forward declarations.
42 #define _(name) class H##name;
48 class HIR : public PoolObject
52 #define _(name) k##name,
68 virtual bool isLValue() const {
72 virtual HOp op() const = 0;
73 virtual void accept(HIRVisitor *visitor) = 0;
76 ScopedRoot<Type> type_;
79 class BytecodeEmitter;
85 virtual void visit##name(H##name *hir) { \
92 typedef PoolList<HIR *> HIRList;
94 #define DEFINE_HIR(name) \
95 virtual HOp op() const { \
98 virtual void accept(HIRVisitor *visitor) { \
99 visitor->visit##name(this); \
102 class HInteger : public HIR
105 HInteger(Type *type, int value)
120 class HConvert : public HIR
123 HConvert(Type *type, Opcode op, HIR *in)
131 Opcode opcode() const {
143 class HLValue : public HIR
151 // Pushes a reference to the LValue on the stack.
152 virtual void bind(HIRVisitor *visitor, BytecodeEmitter &emitter_) = 0;
154 // Given a stack layout of the form:
158 // Emits a store to the reference.
159 virtual void store(BytecodeEmitter &emitter_) = 0;
160 virtual void load(BytecodeEmitter &emitter_) = 0;
162 bool isLValue() const {
167 class HLocal : public HLValue
170 HLocal(VariableSymbol *sym)
171 : HLValue(sym->type()),
178 // Pushes a reference to the LValue on the stack.
179 void bind(HIRVisitor *visitor, BytecodeEmitter &emitter_);
180 void store(BytecodeEmitter &emitter_);
181 void load(BytecodeEmitter &emitter_);
184 VariableSymbol *sym_;
187 class HIndex : public HLValue
190 HIndex(Type *type, HIR *left, HIR *right)
199 void bind(HIRVisitor *visitor, BytecodeEmitter &emitter_);
200 void store(BytecodeEmitter &emitter_);
201 void load(BytecodeEmitter &emitter_);
208 class HGlobal : public HLValue
212 : HLValue(sym->type()),
219 void bind(HIRVisitor *visitor, BytecodeEmitter &emitter_);
220 void store(BytecodeEmitter &emitter_);
221 void load(BytecodeEmitter &emitter_);
223 Symbol *sym() const {
231 class HBinary : public HIR
234 HBinary(Type *type, TokenKind token, HIR *left, HIR *right)
243 TokenKind token() const {
259 class HFloat : public HIR
262 HFloat(Type *type, float value)
269 float value() const {
277 class HStore : public HIR
280 HStore(HLValue *lval, HIR *rval)
289 HLValue *lval() const {
301 class HCall : public HIR
304 HCall(Type *type, HIR *callee, HIRList *args)
313 HIR *callee() const {
316 HIRList *args() const {
327 void EmitHIR(Zone *zone, BytecodeEmitter &emitter, HIR *hir);
331 #endif // _include_sp2_hir_h_