1.1 --- a/jitcraft/BytecodeCompiler.cpp Wed Jul 11 01:12:54 2012 -0700
1.2 +++ b/jitcraft/BytecodeCompiler.cpp Thu Jul 12 00:38:00 2012 -0700
1.3 @@ -199,6 +199,7 @@
1.4 }
1.5 } else {
1.6 IndexExpression *index = node->lvalue()->toIndexExpression();
1.7 + __ note_position(index->pos());
1.8
1.9 // Note: Eventually, watch out for a whole here. An expression like:
1.10 //
1.11 @@ -226,6 +227,7 @@
1.12 visitForALU(node->type(), node->expression());
1.13
1.14 TokenKind alu = TokenKind(int(node->token()) - (TOK_ASSIGN_ADD - TOK_PLUS));
1.15 + __ note_position(node->pos());
1.16 __ binary(TokenToOpcode(alu));
1.17 }
1.18
1.19 @@ -233,6 +235,7 @@
1.20 if (node->expression()->type()->isArray()) {
1.21 // Unlike references, which can only be computed from a NamePRoxy,
1.22 // arrays can be computed from multiple lvalue types.
1.23 + __ note_position(node->pos());
1.24 __ arraycopy();
1.25 } else if (node->lvalue()->isNameProxy()) {
1.26 NameProxy *proxy = node->lvalue()->toNameProxy();
1.27 @@ -305,6 +308,8 @@
1.28 }
1.29 } else {
1.30 IndexExpression *index = expr->toIndexExpression();
1.31 + __ note_position(index->pos());
1.32 +
1.33 index->left()->accept(this);
1.34 index->right()->accept(this);
1.35
1.36 @@ -332,6 +337,7 @@
1.37 __ int_(1);
1.38 }
1.39
1.40 + __ note_position(node->pos());
1.41 if (node->token() == TOK_INCREMENT)
1.42 __ binary(OP_ADD);
1.43 else
1.44 @@ -374,6 +380,8 @@
1.45 Opcode op = TokenToOpcode(node->token());
1.46 if (node->type()->isFloat())
1.47 op = (Opcode)(int(op) + (OP_ADD_F - OP_ADD));
1.48 +
1.49 + __ note_position(node->pos());
1.50 __ binary(op);
1.51 }
1.52
1.53 @@ -382,6 +390,7 @@
1.54 {
1.55 node->left()->accept(this);
1.56 node->right()->accept(this);
1.57 + __ note_position(node->pos());
1.58 __ bounds();
1.59
1.60 if (node->type()->isArray())
1.61 @@ -558,6 +567,7 @@
1.62 assert(array->nelements() >= node->string()->length());
1.63 memcpy(array->chars(), node->string()->raw(), node->string()->length() * sizeof(char));
1.64
1.65 + __ note_position(node->pos());
1.66 __ object(array);
1.67 }
1.68
1.69 @@ -570,10 +580,12 @@
1.70 Local<Type> type(zone_, var->type());
1.71 if (type->isArray()) {
1.72 Local<ArrayMap> map(zone_, BuildArrayMap(zone_, type));
1.73 + __ note_position(node->pos());
1.74 __ newarray_lifo(map);
1.75
1.76 if (node->initialization()) {
1.77 node->initialization()->accept(this);
1.78 + __ note_position(node->pos());
1.79 __ arraycopy();
1.80 }
1.81 } else {
1.82 @@ -622,11 +634,13 @@
1.83 // :TODO: test with functions and globals
1.84 // Compute a reference to the name.
1.85 Variable *var = arg->toNameProxy()->binding()->toVariable();
1.86 + __ note_position(node->pos());
1.87 __ newref(var);
1.88 } else if (arg->isIndexExpression()) {
1.89 IndexExpression *expr = arg->toIndexExpression();
1.90 expr->left()->accept(this);
1.91 expr->right()->accept(this);
1.92 + __ note_position(expr->pos());
1.93 __ bounds();
1.94 __ arrayref_lifo();
1.95 } else {
1.96 @@ -634,6 +648,7 @@
1.97 // this type. Make an indirect one, by taking the top of the
1.98 // stack and boxing it up.
1.99 arg->accept(this);
1.100 + __ note_position(node->pos());
1.101 __ slotref_lifo();
1.102 }
1.103 } else {
1.104 @@ -643,6 +658,7 @@
1.105
1.106 NamedFunction *fun = node->callee()->toNameProxy()->binding()->toNamedFunction();
1.107
1.108 + __ note_position(node->pos());
1.109 if (fun->isNative())
1.110 __ callnative(fun->slot(), node->arguments()->length());
1.111 else
1.112 @@ -712,6 +728,8 @@
1.113 // Note: No need to record a life slot here, since it's part of the Frame.
1.114 AutoEnterScope functionScope(this, node->scope());
1.115
1.116 + // Set the initial line, because line mappings are deltas.
1.117 + __ setFirstLine(node->pos().line);
1.118 locals_ = FixedArray::New(zone_, node->scope()->maxContainedLocals(), Heap::Tenure_Old);
1.119
1.120 node->body()->accept(this);
1.121 @@ -774,8 +792,26 @@
1.122 assert(cursor == safepoints->raw() + gcmapSize);
1.123 }
1.124
1.125 - Local<Code> code(zone_, Code::New(zone_, bytes, locals_, objects, __ maxStackDepth(),
1.126 - moduleData_->module, safepoints));
1.127 + Local<ByteArray> sourcemap(zone_);
1.128 + if (__ sourcemapLength()) {
1.129 + sourcemap = ByteArray::New(zone_, __ sourcemapLength(), Heap::Tenure_Old);
1.130 + if (!sourcemap)
1.131 + return NULL;
1.132 +
1.133 + memcpy(sourcemap->raw(), __ sourcemap(), __ sourcemapLength());
1.134 + }
1.135 +
1.136 + Local<Code> code(zone_);
1.137 +
1.138 + code = Code::New(zone_,
1.139 + bytes,
1.140 + locals_,
1.141 + objects,
1.142 + __ maxStackDepth(),
1.143 + moduleData_->module,
1.144 + safepoints,
1.145 + sourcemap,
1.146 + node->pos().line);
1.147 if (!code)
1.148 return NULL;
1.149