# HG changeset patch # User David Anderson # Date 1353319933 28800 # Node ID 0c588a96837c99e953f8ca19e893aa6e12a85f30 # Parent 5df4a112967dc8e72ada22c4b9d01f25a06424c3 Re-add line and column information to bytecode. diff -r 5df4a112967d -r 0c588a96837c src/compiler/HIR.cpp --- a/src/compiler/HIR.cpp Mon Nov 19 01:13:44 2012 -0800 +++ b/src/compiler/HIR.cpp Mon Nov 19 02:12:13 2012 -0800 @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License along with * JITCraft. If not, see http://www.gnu.org/licenses/. */ +#include "AST.h" #include "HIR.h" #include "BytecodeEmitter.h" #include "../Heap-inl.h" @@ -73,8 +74,9 @@ assert(call->args()->length() == fun->parameters()->length()); + __ note_position(call->node()->pos()); + unsigned argc = call->args()->length(); - for (size_t i = call->args()->length() - 1; i < call->args()->length(); i--) { HIR *hir = call->args()->at(i); hir->accept(this); @@ -174,6 +176,7 @@ void HIndex::bind(HIRVisitor *visitor, BytecodeEmitter &emitter_) { + __ note_position(node()->pos()); left_->accept(visitor); right_->accept(visitor); } @@ -326,6 +329,9 @@ // Opcode op = TokenToOpcode(binary->token()); + if (op == OP_DIV) + __ note_position(binary->node()->pos()); + if (op >= OP_ADD && op <= OP_NE) { if (binary->type()->isFloat()) op = Opcode(int(op) + int(OP_ADD_F - OP_ADD)); diff -r 5df4a112967d -r 0c588a96837c src/compiler/HIR.h --- a/src/compiler/HIR.h Mon Nov 19 01:13:44 2012 -0800 +++ b/src/compiler/HIR.h Mon Nov 19 02:12:13 2012 -0800 @@ -45,6 +45,7 @@ #undef _ class HIRVisitor; +class AstNode; class HIR : public PoolObject { @@ -57,14 +58,18 @@ }; public: - HIR(Type *type) - : type_(type) + HIR(AstNode *node, Type *type) + : node_(node), + type_(type) { } Handle type() { return type_; } + AstNode *node() const { + return node_; + } virtual bool isLValue() const { return false; @@ -74,6 +79,7 @@ virtual void accept(HIRVisitor *visitor) = 0; private: + AstNode *node_; ScopedRoot type_; }; @@ -103,8 +109,8 @@ class HInteger : public HIR { public: - HInteger(Type *type, int value) - : HIR(type), + HInteger(AstNode *node, Type *type, int value) + : HIR(node, type), value_(value) { } @@ -121,8 +127,8 @@ class HConvert : public HIR { public: - HConvert(Type *type, Opcode op, HIR *in) - : HIR(type), + HConvert(AstNode *node, Type *type, Opcode op, HIR *in) + : HIR(node, type), op_(op), in_(in) { @@ -144,8 +150,8 @@ class HLValue : public HIR { public: - HLValue(Type *type) - : HIR(type) + HLValue(AstNode *node, Type *type) + : HIR(node, type) { } @@ -175,8 +181,8 @@ class HLocal : public HLValue { public: - HLocal(VariableSymbol *sym) - : HLValue(sym->type()), + HLocal(AstNode *node, VariableSymbol *sym) + : HLValue(node, sym->type()), sym_(sym) { } @@ -197,8 +203,8 @@ class HIndex : public HLValue { public: - HIndex(Type *type, HIR *left, HIR *right) - : HLValue(type), + HIndex(AstNode *node, Type *type, HIR *left, HIR *right) + : HLValue(node, type), left_(left), right_(right) { @@ -220,8 +226,8 @@ class HGlobal : public HLValue { public: - HGlobal(Symbol *sym) - : HLValue(sym->type()), + HGlobal(AstNode *node, Symbol *sym) + : HLValue(node, sym->type()), sym_(sym) { } @@ -245,8 +251,8 @@ class HBinary : public HIR { public: - HBinary(Type *type, TokenKind token, HIR *left, HIR *right) - : HIR(type), + HBinary(AstNode *node, Type *type, TokenKind token, HIR *left, HIR *right) + : HIR(node, type), token_(token), left_(left), right_(right) @@ -273,8 +279,8 @@ class HFloat : public HIR { public: - HFloat(Type *type, float value) - : HIR(type), + HFloat(AstNode *node, Type *type, float value) + : HIR(node, type), value_(value) { } @@ -291,16 +297,16 @@ class HStore : public HIR { public: - HStore(HLValue *lval, HIR *rval) - : HIR(lval->type()), + HStore(AstNode *node, HLValue *lval, HIR *rval) + : HIR(node, lval->type()), kind_(TOK_ASSIGN), lval_(lval), rval_(rval) { } - HStore(TokenKind kind, HLValue *lval, HIR *rval) - : HIR(lval->type()), + HStore(AstNode *node, TokenKind kind, HLValue *lval, HIR *rval) + : HIR(node, lval->type()), kind_(kind), lval_(lval), rval_(rval) @@ -328,8 +334,8 @@ class HPostIncDec : public HIR { public: - HPostIncDec(TokenKind kind, HLValue *lval, HIR *rval) - : HIR(lval->type()), + HPostIncDec(AstNode *node, TokenKind kind, HLValue *lval, HIR *rval) + : HIR(node, lval->type()), kind_(kind), lval_(lval), rval_(rval) @@ -357,8 +363,8 @@ class HCall : public HIR { public: - HCall(Type *type, HIR *callee, HIRList *args) - : HIR(type), + HCall(AstNode *node, Type *type, HIR *callee, HIRList *args) + : HIR(node, type), callee_(callee), args_(args) { diff -r 5df4a112967d -r 0c588a96837c src/compiler/SemanticAnalysis.cpp --- a/src/compiler/SemanticAnalysis.cpp Mon Nov 19 01:13:44 2012 -0800 +++ b/src/compiler/SemanticAnalysis.cpp Mon Nov 19 02:12:13 2012 -0800 @@ -193,6 +193,7 @@ for (size_t i = 0; i < node->statements()->length(); i++) { Statement *stmt = node->statements()->at(i); + __ note_position(stmt->pos()); stmt->accept(this); assert(__ stackDepth() == 0); } @@ -395,7 +396,7 @@ if (!left || !right) return; - hir_ = binary(node->token(), left, right); + hir_ = binary(node, node->token(), left, right); } bool @@ -432,18 +433,18 @@ Scope *in = sym->scope(); switch (in->kind()) { case Scope::GLOBAL: - hir_ = new (pool_) HGlobal(sym); + hir_ = new (pool_) HGlobal(proxy, sym); return; case Scope::FUNCTION: assert(var->storage() == VariableSymbol::Arg); - hir_ = new (pool_) HLocal(var); + hir_ = new (pool_) HLocal(proxy, var); return; default: assert(in->kind() == Scope::BLOCK); assert(var->storage() == VariableSymbol::Local); - hir_ = new (pool_) HLocal(var); + hir_ = new (pool_) HLocal(proxy, var); return; } } @@ -452,14 +453,14 @@ SemanticAnalysis::visitIntegerLiteral(IntegerLiteral *lit) { Local type(zone_, zone_->types()->getPrimitive(PrimitiveType_Int32)); - hir_ = new (pool_) HInteger(type, lit->value()); + hir_ = new (pool_) HInteger(lit, type, lit->value()); } void SemanticAnalysis::visitFloatLiteral(FloatLiteral *node) { Local type(zone_, zone_->types()->getPrimitive(PrimitiveType_Float)); - hir_ = new (pool_) HFloat(type, (float)node->value()); + hir_ = new (pool_) HFloat(node, type, (float)node->value()); } void @@ -530,7 +531,7 @@ return; } - hir_ = new (pool_) HCall(fun->returnType(), callee, args); + hir_ = new (pool_) HCall(node, fun->returnType(), callee, args); } void @@ -544,7 +545,7 @@ if ((hir = coerce(hir, lval->type(), Coerce_Assign)) == NULL) return; - hir_ = new (pool_) HStore(node->token(), lval, hir); + hir_ = new (pool_) HStore(node, node->token(), lval, hir); } void @@ -593,7 +594,8 @@ return; } - hir_ = new (pool_) HIndex(ArrayType::cast(left->type())->contained(), + hir_ = new (pool_) HIndex(node, + ArrayType::cast(left->type())->contained(), left, right); } @@ -612,14 +614,14 @@ HIR *rval; if (lval->type()->isInt32()) - rval = new (pool_) HInteger(lval->type(), 1); + rval = new (pool_) HInteger(node, lval->type(), 1); else - rval = new (pool_) HFloat(lval->type(), 1.0); + rval = new (pool_) HFloat(node, lval->type(), 1.0); if (node->postfix()) - hir_ = new (pool_) HPostIncDec(node->token(), lval, rval); + hir_ = new (pool_) HPostIncDec(node, node->token(), lval, rval); else - hir_ = new (pool_) HStore(node->token(), lval, rval); + hir_ = new (pool_) HStore(node, node->token(), lval, rval); } Type * @@ -730,15 +732,17 @@ Handle from = hir->type(); if (from->isInt32() && to->isFloat()) - return new (pool_) HConvert(to, OP_CVT_I2F, hir); + return new (pool_) HConvert(hir->node(), to, OP_CVT_I2F, hir); if (from->isInt32() && to->isBool()) - return new (pool_) HConvert(to, OP_CVT_I2B, hir); + return new (pool_) HConvert(hir->node(), to, OP_CVT_I2B, hir); if (to->isArray()) { if (!typeCheckArray(SourcePosition(), from, to, kind)) return NULL; return hir; } + + assert(from == to); return hir; } @@ -755,7 +759,7 @@ } HIR * -SemanticAnalysis::binary(TokenKind token, HIR *left, HIR *right) +SemanticAnalysis::binary(AstNode *node, TokenKind token, HIR *left, HIR *right) { Local coercion(zone_, coercionType(token, left, right)); if (!coercion) @@ -777,7 +781,7 @@ case TOK_SHR: case TOK_USHR: case TOK_SHL: - return new (pool_) HBinary(left->type(), token, left, right); + return new (pool_) HBinary(node, left->type(), token, left, right); case TOK_EQUALS: case TOK_NOTEQUALS: @@ -789,7 +793,7 @@ case TOK_OR: { Local result(zone_, zone_->types()->getPrimitive(PrimitiveType_Bool)); - return new (pool_) HBinary(result, token, left, right); + return new (pool_) HBinary(node, result, token, left, right); } default: @@ -857,7 +861,7 @@ if (!left || !right) return; - HIR *hir = binary(bin->token(), left, right); + HIR *hir = binary(bin, bin->token(), left, right); if (!hir) return; if ((hir = coerce(hir, boolType, Coerce_Assign)) == NULL) diff -r 5df4a112967d -r 0c588a96837c src/compiler/SemanticAnalysis.h --- a/src/compiler/SemanticAnalysis.h Mon Nov 19 01:13:44 2012 -0800 +++ b/src/compiler/SemanticAnalysis.h Mon Nov 19 02:12:13 2012 -0800 @@ -66,13 +66,10 @@ #if 0 void visitFunctionTypeStatement(FunctionTypeStatement *node); void visitImportStatement(ImportStatement *node); - void visitExpressionStatement(ExpressionStatement *node); void visitEnumStatement(EnumStatement *node); void visitStructureStatement(StructureStatement *node); void visitSwitchStatement(SwitchStatement *node); - void visitBinaryExpression(BinaryExpression *node); - void visitCallExpression(CallExpression *node); void visitStringLiteral(StringLiteral *node); void visitUnaryExpression(UnaryExpression *node); void visitTernaryExpression(TernaryExpression *node); @@ -97,7 +94,7 @@ BytecodeEmitter::Label *fallthrough); void set(VariableSymbol *sym); HIR *eval(Expression *expr); - HIR *binary(TokenKind token, HIR *left, HIR *right); + HIR *binary(AstNode *node, TokenKind token, HIR *left, HIR *right); HIR *coerce(HIR *from, Handle to, CoercionKind kind); Type *coercionType(TokenKind token, HIR *left, HIR *right); HLValue *lvalue(Expression *expr);