Re-add line and column information to bytecode.
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 */ \
42 // Forward declarations.
43 #define _(name) class H##name;
50 class HIR : public PoolObject
54 #define _(name) k##name,
61 HIR(AstNode *node, Type *type)
70 AstNode *node() const {
74 virtual bool isLValue() const {
78 virtual HOp op() const = 0;
79 virtual void accept(HIRVisitor *visitor) = 0;
83 ScopedRoot<Type> type_;
86 class BytecodeEmitter;
92 virtual void visit##name(H##name *hir) { \
99 typedef PoolList<HIR *> HIRList;
101 #define DEFINE_HIR(name) \
102 virtual HOp op() const { \
105 virtual void accept(HIRVisitor *visitor) { \
106 visitor->visit##name(this); \
109 class HInteger : public HIR
112 HInteger(AstNode *node, Type *type, int value)
127 class HConvert : public HIR
130 HConvert(AstNode *node, Type *type, Opcode op, HIR *in)
138 Opcode opcode() const {
150 class HLValue : public HIR
153 HLValue(AstNode *node, Type *type)
158 // Pushes a reference to the LValue on the stack.
159 virtual void bind(HIRVisitor *visitor, BytecodeEmitter &emitter_) = 0;
161 // Duplicates a stack reference.
162 virtual void hold(BytecodeEmitter &emitter_) = 0;
164 // Reorders the stack for a post-increment operation:
165 // REF VAL -> VAL REF VAL
166 virtual void swapAndPick(BytecodeEmitter &emitter_) = 0;
168 // Given a stack layout of the form:
172 // Emits a store to the reference.
173 virtual void store(BytecodeEmitter &emitter_) = 0;
174 virtual void load(BytecodeEmitter &emitter_) = 0;
176 bool isLValue() const {
181 class HLocal : public HLValue
184 HLocal(AstNode *node, VariableSymbol *sym)
185 : HLValue(node, sym->type()),
192 // Pushes a reference to the LValue on the stack.
193 void bind(HIRVisitor *visitor, BytecodeEmitter &emitter_);
194 void hold(BytecodeEmitter &emitter_);
195 void swapAndPick(BytecodeEmitter &emitter_);
196 void store(BytecodeEmitter &emitter_);
197 void load(BytecodeEmitter &emitter_);
200 VariableSymbol *sym_;
203 class HIndex : public HLValue
206 HIndex(AstNode *node, Type *type, HIR *left, HIR *right)
207 : HLValue(node, type),
215 void bind(HIRVisitor *visitor, BytecodeEmitter &emitter_);
216 void hold(BytecodeEmitter &emitter_);
217 void swapAndPick(BytecodeEmitter &emitter_);
218 void store(BytecodeEmitter &emitter_);
219 void load(BytecodeEmitter &emitter_);
226 class HGlobal : public HLValue
229 HGlobal(AstNode *node, Symbol *sym)
230 : HLValue(node, sym->type()),
237 void bind(HIRVisitor *visitor, BytecodeEmitter &emitter_);
238 void hold(BytecodeEmitter &emitter_);
239 void swapAndPick(BytecodeEmitter &emitter_);
240 void store(BytecodeEmitter &emitter_);
241 void load(BytecodeEmitter &emitter_);
243 Symbol *sym() const {
251 class HBinary : public HIR
254 HBinary(AstNode *node, Type *type, TokenKind token, HIR *left, HIR *right)
263 TokenKind token() const {
279 class HFloat : public HIR
282 HFloat(AstNode *node, Type *type, float value)
289 float value() const {
297 class HStore : public HIR
300 HStore(AstNode *node, HLValue *lval, HIR *rval)
301 : HIR(node, lval->type()),
308 HStore(AstNode *node, TokenKind kind, HLValue *lval, HIR *rval)
309 : HIR(node, lval->type()),
318 HLValue *lval() const {
324 TokenKind kind() const {
334 class HPostIncDec : public HIR
337 HPostIncDec(AstNode *node, TokenKind kind, HLValue *lval, HIR *rval)
338 : HIR(node, lval->type()),
345 DEFINE_HIR(PostIncDec);
347 HLValue *lval() const {
353 TokenKind kind() const {
363 class HCall : public HIR
366 HCall(AstNode *node, Type *type, HIR *callee, HIRList *args)
375 HIR *callee() const {
378 HIRList *args() const {
389 void EmitHIR(Zone *zone, BytecodeEmitter &emitter, HIR *hir);
393 #endif // _include_sp2_hir_h_