Re-add line and column information to bytecode.
authorDavid Anderson <dvander@alliedmods.net>
Mon Nov 19 02:12:13 2012 -0800 (2012-11-19)
changeset 2210c588a96837c
parent 220 5df4a112967d
child 222 0cde1379b29f
Re-add line and column information to bytecode.
src/compiler/HIR.cpp
src/compiler/HIR.h
src/compiler/SemanticAnalysis.cpp
src/compiler/SemanticAnalysis.h
     1.1 --- a/src/compiler/HIR.cpp	Mon Nov 19 01:13:44 2012 -0800
     1.2 +++ b/src/compiler/HIR.cpp	Mon Nov 19 02:12:13 2012 -0800
     1.3 @@ -16,6 +16,7 @@
     1.4   * You should have received a copy of the GNU General Public License along with
     1.5   * JITCraft. If not, see http://www.gnu.org/licenses/.
     1.6   */
     1.7 +#include "AST.h"
     1.8  #include "HIR.h"
     1.9  #include "BytecodeEmitter.h"
    1.10  #include "../Heap-inl.h"
    1.11 @@ -73,8 +74,9 @@
    1.12      
    1.13      assert(call->args()->length() == fun->parameters()->length());
    1.14  
    1.15 +    __ note_position(call->node()->pos());
    1.16 +
    1.17      unsigned argc = call->args()->length();
    1.18 -
    1.19      for (size_t i = call->args()->length() - 1; i < call->args()->length(); i--) {
    1.20          HIR *hir = call->args()->at(i);
    1.21          hir->accept(this);
    1.22 @@ -174,6 +176,7 @@
    1.23  void
    1.24  HIndex::bind(HIRVisitor *visitor, BytecodeEmitter &emitter_)
    1.25  {
    1.26 +    __ note_position(node()->pos());
    1.27      left_->accept(visitor);
    1.28      right_->accept(visitor);
    1.29  }
    1.30 @@ -326,6 +329,9 @@
    1.31      //
    1.32      Opcode op = TokenToOpcode(binary->token());
    1.33  
    1.34 +    if (op == OP_DIV)
    1.35 +        __ note_position(binary->node()->pos());
    1.36 +
    1.37      if (op >= OP_ADD && op <= OP_NE) {
    1.38          if (binary->type()->isFloat())
    1.39              op = Opcode(int(op) + int(OP_ADD_F - OP_ADD));
     2.1 --- a/src/compiler/HIR.h	Mon Nov 19 01:13:44 2012 -0800
     2.2 +++ b/src/compiler/HIR.h	Mon Nov 19 02:12:13 2012 -0800
     2.3 @@ -45,6 +45,7 @@
     2.4  #undef _
     2.5  
     2.6  class HIRVisitor;
     2.7 +class AstNode;
     2.8  
     2.9  class HIR : public PoolObject
    2.10  {
    2.11 @@ -57,14 +58,18 @@
    2.12      };
    2.13  
    2.14    public:
    2.15 -    HIR(Type *type)
    2.16 -      : type_(type)
    2.17 +    HIR(AstNode *node, Type *type)
    2.18 +      : node_(node),
    2.19 +        type_(type)
    2.20      {
    2.21      }
    2.22  
    2.23      Handle<Type> type() {
    2.24          return type_;
    2.25      }
    2.26 +    AstNode *node() const {
    2.27 +        return node_;
    2.28 +    }
    2.29  
    2.30      virtual bool isLValue() const {
    2.31          return false;
    2.32 @@ -74,6 +79,7 @@
    2.33      virtual void accept(HIRVisitor *visitor) = 0;
    2.34  
    2.35    private:
    2.36 +    AstNode *node_;
    2.37      ScopedRoot<Type> type_;
    2.38  };
    2.39  
    2.40 @@ -103,8 +109,8 @@
    2.41  class HInteger : public HIR
    2.42  {
    2.43    public:
    2.44 -    HInteger(Type *type, int value)
    2.45 -      : HIR(type),
    2.46 +    HInteger(AstNode *node, Type *type, int value)
    2.47 +      : HIR(node, type),
    2.48          value_(value)
    2.49      {
    2.50      }
    2.51 @@ -121,8 +127,8 @@
    2.52  class HConvert : public HIR
    2.53  {
    2.54    public:
    2.55 -    HConvert(Type *type, Opcode op, HIR *in)
    2.56 -      : HIR(type),
    2.57 +    HConvert(AstNode *node, Type *type, Opcode op, HIR *in)
    2.58 +      : HIR(node, type),
    2.59          op_(op),
    2.60          in_(in)
    2.61      {
    2.62 @@ -144,8 +150,8 @@
    2.63  class HLValue : public HIR
    2.64  {
    2.65    public:
    2.66 -    HLValue(Type *type)
    2.67 -      : HIR(type)
    2.68 +    HLValue(AstNode *node, Type *type)
    2.69 +      : HIR(node, type)
    2.70      {
    2.71      }
    2.72  
    2.73 @@ -175,8 +181,8 @@
    2.74  class HLocal : public HLValue
    2.75  {
    2.76    public:
    2.77 -    HLocal(VariableSymbol *sym)
    2.78 -      : HLValue(sym->type()),
    2.79 +    HLocal(AstNode *node, VariableSymbol *sym)
    2.80 +      : HLValue(node, sym->type()),
    2.81          sym_(sym)
    2.82      {
    2.83      }
    2.84 @@ -197,8 +203,8 @@
    2.85  class HIndex : public HLValue
    2.86  {
    2.87    public:
    2.88 -    HIndex(Type *type, HIR *left, HIR *right)
    2.89 -      : HLValue(type),
    2.90 +    HIndex(AstNode *node, Type *type, HIR *left, HIR *right)
    2.91 +      : HLValue(node, type),
    2.92          left_(left),
    2.93          right_(right)
    2.94      {
    2.95 @@ -220,8 +226,8 @@
    2.96  class HGlobal : public HLValue
    2.97  {
    2.98    public:
    2.99 -    HGlobal(Symbol *sym)
   2.100 -      : HLValue(sym->type()),
   2.101 +    HGlobal(AstNode *node, Symbol *sym)
   2.102 +      : HLValue(node, sym->type()),
   2.103          sym_(sym)
   2.104      {
   2.105      }
   2.106 @@ -245,8 +251,8 @@
   2.107  class HBinary : public HIR
   2.108  {
   2.109    public:
   2.110 -    HBinary(Type *type, TokenKind token, HIR *left, HIR *right)
   2.111 -      : HIR(type),
   2.112 +    HBinary(AstNode *node, Type *type, TokenKind token, HIR *left, HIR *right)
   2.113 +      : HIR(node, type),
   2.114          token_(token),
   2.115          left_(left),
   2.116          right_(right)
   2.117 @@ -273,8 +279,8 @@
   2.118  class HFloat : public HIR
   2.119  {
   2.120    public:
   2.121 -    HFloat(Type *type, float value)
   2.122 -      : HIR(type),
   2.123 +    HFloat(AstNode *node, Type *type, float value)
   2.124 +      : HIR(node, type),
   2.125          value_(value)
   2.126      {
   2.127      }
   2.128 @@ -291,16 +297,16 @@
   2.129  class HStore : public HIR
   2.130  {
   2.131    public:
   2.132 -    HStore(HLValue *lval, HIR *rval)
   2.133 -      : HIR(lval->type()),
   2.134 +    HStore(AstNode *node, HLValue *lval, HIR *rval)
   2.135 +      : HIR(node, lval->type()),
   2.136          kind_(TOK_ASSIGN),
   2.137          lval_(lval),
   2.138          rval_(rval)
   2.139      {
   2.140      }
   2.141  
   2.142 -    HStore(TokenKind kind, HLValue *lval, HIR *rval)
   2.143 -      : HIR(lval->type()),
   2.144 +    HStore(AstNode *node, TokenKind kind, HLValue *lval, HIR *rval)
   2.145 +      : HIR(node, lval->type()),
   2.146          kind_(kind),
   2.147          lval_(lval),
   2.148          rval_(rval)
   2.149 @@ -328,8 +334,8 @@
   2.150  class HPostIncDec : public HIR
   2.151  {
   2.152    public:
   2.153 -    HPostIncDec(TokenKind kind, HLValue *lval, HIR *rval)
   2.154 -      : HIR(lval->type()),
   2.155 +    HPostIncDec(AstNode *node, TokenKind kind, HLValue *lval, HIR *rval)
   2.156 +      : HIR(node, lval->type()),
   2.157          kind_(kind),
   2.158          lval_(lval),
   2.159          rval_(rval)
   2.160 @@ -357,8 +363,8 @@
   2.161  class HCall : public HIR
   2.162  {
   2.163    public:
   2.164 -    HCall(Type *type, HIR *callee, HIRList *args)
   2.165 -      : HIR(type),
   2.166 +    HCall(AstNode *node, Type *type, HIR *callee, HIRList *args)
   2.167 +      : HIR(node, type),
   2.168          callee_(callee),
   2.169          args_(args)
   2.170      {
     3.1 --- a/src/compiler/SemanticAnalysis.cpp	Mon Nov 19 01:13:44 2012 -0800
     3.2 +++ b/src/compiler/SemanticAnalysis.cpp	Mon Nov 19 02:12:13 2012 -0800
     3.3 @@ -193,6 +193,7 @@
     3.4  
     3.5      for (size_t i = 0; i < node->statements()->length(); i++) {
     3.6          Statement *stmt = node->statements()->at(i);
     3.7 +        __ note_position(stmt->pos());
     3.8          stmt->accept(this);
     3.9          assert(__ stackDepth() == 0);
    3.10      }
    3.11 @@ -395,7 +396,7 @@
    3.12      if (!left || !right)
    3.13          return;
    3.14  
    3.15 -    hir_ = binary(node->token(), left, right);
    3.16 +    hir_ = binary(node, node->token(), left, right);
    3.17  }
    3.18  
    3.19  bool
    3.20 @@ -432,18 +433,18 @@
    3.21      Scope *in = sym->scope();
    3.22      switch (in->kind()) {
    3.23        case Scope::GLOBAL:
    3.24 -        hir_ = new (pool_) HGlobal(sym);
    3.25 +        hir_ = new (pool_) HGlobal(proxy, sym);
    3.26          return;
    3.27  
    3.28        case Scope::FUNCTION:
    3.29          assert(var->storage() == VariableSymbol::Arg);
    3.30 -        hir_ = new (pool_) HLocal(var);
    3.31 +        hir_ = new (pool_) HLocal(proxy, var);
    3.32          return;
    3.33  
    3.34        default:
    3.35          assert(in->kind() == Scope::BLOCK);
    3.36          assert(var->storage() == VariableSymbol::Local);
    3.37 -        hir_ = new (pool_) HLocal(var);
    3.38 +        hir_ = new (pool_) HLocal(proxy, var);
    3.39          return;
    3.40      }
    3.41  }
    3.42 @@ -452,14 +453,14 @@
    3.43  SemanticAnalysis::visitIntegerLiteral(IntegerLiteral *lit)
    3.44  {
    3.45      Local<Type> type(zone_, zone_->types()->getPrimitive(PrimitiveType_Int32));
    3.46 -    hir_ = new (pool_) HInteger(type, lit->value());
    3.47 +    hir_ = new (pool_) HInteger(lit, type, lit->value());
    3.48  }
    3.49  
    3.50  void
    3.51  SemanticAnalysis::visitFloatLiteral(FloatLiteral *node)
    3.52  {
    3.53      Local<Type> type(zone_, zone_->types()->getPrimitive(PrimitiveType_Float));
    3.54 -    hir_ = new (pool_) HFloat(type, (float)node->value());
    3.55 +    hir_ = new (pool_) HFloat(node, type, (float)node->value());
    3.56  }
    3.57  
    3.58  void
    3.59 @@ -530,7 +531,7 @@
    3.60              return;
    3.61      }
    3.62  
    3.63 -    hir_ = new (pool_) HCall(fun->returnType(), callee, args);
    3.64 +    hir_ = new (pool_) HCall(node, fun->returnType(), callee, args);
    3.65  }
    3.66  
    3.67  void
    3.68 @@ -544,7 +545,7 @@
    3.69      if ((hir = coerce(hir, lval->type(), Coerce_Assign)) == NULL)
    3.70          return;
    3.71  
    3.72 -    hir_ = new (pool_) HStore(node->token(), lval, hir);
    3.73 +    hir_ = new (pool_) HStore(node, node->token(), lval, hir);
    3.74  }
    3.75  
    3.76  void
    3.77 @@ -593,7 +594,8 @@
    3.78          return;
    3.79      }
    3.80  
    3.81 -    hir_ = new (pool_) HIndex(ArrayType::cast(left->type())->contained(),
    3.82 +    hir_ = new (pool_) HIndex(node,
    3.83 +                              ArrayType::cast(left->type())->contained(),
    3.84                                left,
    3.85                                right);
    3.86  }
    3.87 @@ -612,14 +614,14 @@
    3.88  
    3.89      HIR *rval;
    3.90      if (lval->type()->isInt32())
    3.91 -        rval = new (pool_) HInteger(lval->type(), 1);
    3.92 +        rval = new (pool_) HInteger(node, lval->type(), 1);
    3.93      else
    3.94 -        rval = new (pool_) HFloat(lval->type(), 1.0);
    3.95 +        rval = new (pool_) HFloat(node, lval->type(), 1.0);
    3.96  
    3.97      if (node->postfix())
    3.98 -        hir_ = new (pool_) HPostIncDec(node->token(), lval, rval);
    3.99 +        hir_ = new (pool_) HPostIncDec(node, node->token(), lval, rval);
   3.100      else
   3.101 -        hir_ = new (pool_) HStore(node->token(), lval, rval);
   3.102 +        hir_ = new (pool_) HStore(node, node->token(), lval, rval);
   3.103  }
   3.104  
   3.105  Type *
   3.106 @@ -730,15 +732,17 @@
   3.107      Handle<Type> from = hir->type();
   3.108  
   3.109      if (from->isInt32() && to->isFloat())
   3.110 -        return new (pool_) HConvert(to, OP_CVT_I2F, hir);
   3.111 +        return new (pool_) HConvert(hir->node(), to, OP_CVT_I2F, hir);
   3.112      if (from->isInt32() && to->isBool())
   3.113 -        return new (pool_) HConvert(to, OP_CVT_I2B, hir);
   3.114 +        return new (pool_) HConvert(hir->node(), to, OP_CVT_I2B, hir);
   3.115      
   3.116      if (to->isArray()) {
   3.117          if (!typeCheckArray(SourcePosition(), from, to, kind))
   3.118              return NULL;
   3.119          return hir;
   3.120      }
   3.121 +
   3.122 +    assert(from == to);
   3.123      
   3.124      return hir;
   3.125  }
   3.126 @@ -755,7 +759,7 @@
   3.127  }
   3.128  
   3.129  HIR *
   3.130 -SemanticAnalysis::binary(TokenKind token, HIR *left, HIR *right)
   3.131 +SemanticAnalysis::binary(AstNode *node, TokenKind token, HIR *left, HIR *right)
   3.132  {
   3.133      Local<Type> coercion(zone_, coercionType(token, left, right));
   3.134      if (!coercion)
   3.135 @@ -777,7 +781,7 @@
   3.136        case TOK_SHR:
   3.137        case TOK_USHR:
   3.138        case TOK_SHL:
   3.139 -        return new (pool_) HBinary(left->type(), token, left, right);
   3.140 +        return new (pool_) HBinary(node, left->type(), token, left, right);
   3.141  
   3.142        case TOK_EQUALS:
   3.143        case TOK_NOTEQUALS:
   3.144 @@ -789,7 +793,7 @@
   3.145        case TOK_OR:
   3.146        {
   3.147          Local<Type> result(zone_, zone_->types()->getPrimitive(PrimitiveType_Bool));
   3.148 -        return new (pool_) HBinary(result, token, left, right);
   3.149 +        return new (pool_) HBinary(node, result, token, left, right);
   3.150        }
   3.151  
   3.152        default:
   3.153 @@ -857,7 +861,7 @@
   3.154      if (!left || !right)
   3.155          return;
   3.156  
   3.157 -    HIR *hir = binary(bin->token(), left, right);
   3.158 +    HIR *hir = binary(bin, bin->token(), left, right);
   3.159      if (!hir)
   3.160          return;
   3.161      if ((hir = coerce(hir, boolType, Coerce_Assign)) == NULL)
     4.1 --- a/src/compiler/SemanticAnalysis.h	Mon Nov 19 01:13:44 2012 -0800
     4.2 +++ b/src/compiler/SemanticAnalysis.h	Mon Nov 19 02:12:13 2012 -0800
     4.3 @@ -66,13 +66,10 @@
     4.4  #if 0
     4.5      void visitFunctionTypeStatement(FunctionTypeStatement *node);
     4.6      void visitImportStatement(ImportStatement *node);
     4.7 -    void visitExpressionStatement(ExpressionStatement *node);
     4.8      void visitEnumStatement(EnumStatement *node);
     4.9      void visitStructureStatement(StructureStatement *node);
    4.10      void visitSwitchStatement(SwitchStatement *node);
    4.11  
    4.12 -    void visitBinaryExpression(BinaryExpression *node);
    4.13 -    void visitCallExpression(CallExpression *node);
    4.14      void visitStringLiteral(StringLiteral *node);
    4.15      void visitUnaryExpression(UnaryExpression *node);
    4.16      void visitTernaryExpression(TernaryExpression *node);
    4.17 @@ -97,7 +94,7 @@
    4.18                        BytecodeEmitter::Label *fallthrough);
    4.19      void set(VariableSymbol *sym);
    4.20      HIR *eval(Expression *expr);
    4.21 -    HIR *binary(TokenKind token, HIR *left, HIR *right);
    4.22 +    HIR *binary(AstNode *node, TokenKind token, HIR *left, HIR *right);
    4.23      HIR *coerce(HIR *from, Handle<Type> to, CoercionKind kind);
    4.24      Type *coercionType(TokenKind token, HIR *left, HIR *right);
    4.25      HLValue *lvalue(Expression *expr);