#define CODE_HASH_ENTER(ENTRY) ((ENTRY).enter)
#define CODE_HASH_LEAVE(ENTRY) ((ENTRY).leave)
-void code_push_statement(code_t *code, prog_section_statement_t *stmt, int linenum)
+void code_push_statement(code_t *code, prog_section_statement_t *stmt, lex_ctx_t ctx)
{
vec_push(code->statements, *stmt);
- vec_push(code->linenums, linenum);
+ vec_push(code->linenums, (int)ctx.line);
+ vec_push(code->columnnums, (int)ctx.column);
}
void code_pop_statement(code_t *code)
{
vec_pop(code->statements);
vec_pop(code->linenums);
+ vec_pop(code->columnnums);
}
code_t *code_init() {
+ static lex_ctx_t empty_ctx = {0, 0, 0};
static prog_section_function_t empty_function = {0,0,0,0,0,0,0,{0,0,0,0,0,0,0,0}};
static prog_section_statement_t empty_statement = {0,{0},{0},{0}};
static prog_section_def_t empty_def = {0, 0, 0};
vec_push(code->chars, '\0');
vec_push(code->functions, empty_function);
- code_push_statement(code, &empty_statement, 0);
+ code_push_statement(code, &empty_statement, empty_ctx);
vec_push(code->defs, empty_def);
vec_push(code->fields, empty_def);
size += sizeof(code_header->globals.length);
size += sizeof(code_header->fields.length);
size += sizeof(code_header->statements.length);
- size += sizeof(code->linenums[0]) * vec_size(code->linenums);
+ size += sizeof(code->linenums[0]) * vec_size(code->linenums);
+ size += sizeof(code->columnnums[0]) * vec_size(code->columnnums);
} else {
size += sizeof(prog_header_t);
size += sizeof(prog_section_statement_t) * vec_size(code->statements);
vec_free(code->statements);
vec_free(code->linenums);
+ vec_free(code->columnnums);
vec_free(code->defs);
vec_free(code->fields);
vec_free(code->functions);
if (!fp)
return false;
- util_endianswap(&version, 1, sizeof(version));
- util_endianswap(code->linenums, vec_size(code->linenums), sizeof(code->linenums[0]));
-
-
- if (fs_file_write("LNOF", 4, 1, fp) != 1 ||
- fs_file_write(&version, sizeof(version), 1, fp) != 1 ||
- fs_file_write(&code_header.defs.length, sizeof(code_header.defs.length), 1, fp) != 1 ||
- fs_file_write(&code_header.globals.length, sizeof(code_header.globals.length), 1, fp) != 1 ||
- fs_file_write(&code_header.fields.length, sizeof(code_header.fields.length), 1, fp) != 1 ||
- fs_file_write(&code_header.statements.length, sizeof(code_header.statements.length), 1, fp) != 1 ||
- fs_file_write(code->linenums, sizeof(code->linenums[0]), vec_size(code->linenums), fp) != vec_size(code->linenums))
+ util_endianswap(&version, 1, sizeof(version));
+ util_endianswap(code->linenums, vec_size(code->linenums), sizeof(code->linenums[0]));
+ util_endianswap(code->columnnums, vec_size(code->columnnums), sizeof(code->columnnums[0]));
+
+ if (fs_file_write("LNOF", 4, 1, fp) != 1 ||
+ fs_file_write(&version, sizeof(version), 1, fp) != 1 ||
+ fs_file_write(&code_header.defs.length, sizeof(code_header.defs.length), 1, fp) != 1 ||
+ fs_file_write(&code_header.globals.length, sizeof(code_header.globals.length), 1, fp) != 1 ||
+ fs_file_write(&code_header.fields.length, sizeof(code_header.fields.length), 1, fp) != 1 ||
+ fs_file_write(&code_header.statements.length, sizeof(code_header.statements.length), 1, fp) != 1 ||
+ fs_file_write(code->linenums, sizeof(code->linenums[0]), vec_size(code->linenums), fp) != vec_size(code->linenums) ||
+ fs_file_write(code->columnnums, sizeof(code->columnnums[0]), vec_size(code->columnnums), fp) != vec_size(code->columnnums))
{
con_err("failed to write lno file\n");
}
void code_cleanup(code_t *code) {
vec_free(code->statements);
vec_free(code->linenums);
+ vec_free(code->columnnums);
vec_free(code->defs);
vec_free(code->fields);
vec_free(code->functions);
stmt.o2.s1 = 0;
stmt.o3.s1 = 0;
if (stmt.o1.s1 != 1)
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* no further instructions can be in this block */
return true;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]);
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
stmt.opcode = INSTR_BITAND;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]);
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]);
stmt.o3.s1 = ir_value_code_addr(func->owner->vinstr_temp[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
stmt.opcode = INSTR_SUB_F;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[0]);
stmt.o2.s1 = ir_value_code_addr(func->owner->vinstr_temp[0]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* instruction generated */
continue;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]);
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
++stmt.o1.s1;
++stmt.o2.s1;
++stmt.o3.s1;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
++stmt.o1.s1;
++stmt.o2.s1;
++stmt.o3.s1;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* instruction generated */
continue;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]);
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
++stmt.o1.s1;
++stmt.o2.s1;
++stmt.o3.s1;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
++stmt.o1.s1;
++stmt.o2.s1;
++stmt.o3.s1;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* instruction generated */
continue;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]) + j;
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]) + j;
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]) + j;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
stmt.opcode = INSTR_BITAND;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]) + j;
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]) + j;
stmt.o3.s1 = ir_value_code_addr(func->owner->vinstr_temp[0]) + j;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
}
stmt.opcode = INSTR_SUB_V;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[0]);
stmt.o2.s1 = ir_value_code_addr(func->owner->vinstr_temp[0]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* instruction generated */
continue;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]);
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
++stmt.o1.s1;
++stmt.o3.s1;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
++stmt.o1.s1;
++stmt.o3.s1;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* instruction generated */
continue;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]);
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
++stmt.o1.s1;
++stmt.o3.s1;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
++stmt.o1.s1;
++stmt.o3.s1;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* instruction generated */
continue;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]) + j;
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]) + j;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
stmt.opcode = INSTR_BITAND;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[1]) + j;
stmt.o2.s1 = ir_value_code_addr(instr->_ops[2]);
stmt.o3.s1 = ir_value_code_addr(func->owner->vinstr_temp[0]) + j;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
}
stmt.opcode = INSTR_SUB_V;
stmt.o1.s1 = ir_value_code_addr(instr->_ops[0]);
stmt.o2.s1 = ir_value_code_addr(func->owner->vinstr_temp[0]);
stmt.o3.s1 = ir_value_code_addr(instr->_ops[0]);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* instruction generated */
continue;
stmt.opcode = INSTR_IF;
stmt.o2.s1 = (ontrue->code_start) - vec_size(code->statements);
if (stmt.o2.s1 != 1)
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
}
if (onfalse->generated) {
stmt.opcode = INSTR_IFNOT;
stmt.o2.s1 = (onfalse->code_start) - vec_size(code->statements);
if (stmt.o2.s1 != 1)
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
}
if (!ontrue->generated) {
if (onfalse->generated)
ontrue = tmp;
}
stidx = vec_size(code->statements);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
/* on false we jump, so add ontrue-path */
if (!gen_blocks_recursive(code, func, ontrue))
return false;
stmt.o2.s1 = 0;
stmt.o3.s1 = 0;
if (stmt.o1.s1 != 1)
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
return true;
}
else if (stidx+2 == vec_size(code->statements) && code->statements[stidx].o2.s1 == 1) {
stmt.opcode = type_store_instr[param->vtype];
stmt.o1.u1 = ir_value_code_addr(param);
stmt.o2.u1 = OFS_PARM0 + 3 * p;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
}
/* Now handle extparams */
first = vec_size(instr->params);
stmt.opcode = type_store_instr[param->vtype];
stmt.o1.u1 = ir_value_code_addr(param);
stmt.o2.u1 = ir_value_code_addr(targetparam);
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
}
stmt.opcode = INSTR_CALL0 + vec_size(instr->params);
stmt.o1.u1 = ir_value_code_addr(instr->_ops[1]);
stmt.o2.u1 = 0;
stmt.o3.u1 = 0;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
retvalue = instr->_ops[0];
if (retvalue && retvalue->store != store_return &&
stmt.o1.u1 = OFS_RETURN;
stmt.o2.u1 = ir_value_code_addr(retvalue);
stmt.o3.u1 = 0;
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
}
continue;
}
}
}
- code_push_statement(code, &stmt, instr->context.line);
+ code_push_statement(code, &stmt, instr->context);
}
return true;
}
retst->opcode = INSTR_DONE;
++opts_optimizationcount[OPTIM_VOID_RETURN];
} else {
+ lex_ctx_t last;
+
stmt.opcode = INSTR_DONE;
- stmt.o1.u1 = 0;
- stmt.o2.u1 = 0;
- stmt.o3.u1 = 0;
- code_push_statement(code, &stmt, vec_last(code->linenums));
+ stmt.o1.u1 = 0;
+ stmt.o2.u1 = 0;
+ stmt.o3.u1 = 0;
+ last.line = vec_last(code->linenums);
+ last.column = vec_last(code->columnnums);
+
+ code_push_statement(code, &stmt, last);
}
return true;
}
}
stmt.o1.u1 = ir_value_code_addr(ep);
stmt.o2.u1 = ir_value_code_addr(self->locals[i]);
- code_push_statement(code, &stmt, self->context.line);
+ code_push_statement(code, &stmt, self->context);
}
return true;
if (i < 8) {
stmt.o1.u1 = OFS_PARM0 + 3*i;
stmt.o2.u1 = ir_value_code_addr(self->locals[i]);
- code_push_statement(code, &stmt, self->context.line);
+ code_push_statement(code, &stmt, self->context);
continue;
}
ext = i - 8;
stmt.o1.u1 = ir_value_code_addr(ep);
stmt.o2.u1 = ir_value_code_addr(self->locals[i]);
- code_push_statement(code, &stmt, self->context.line);
+ code_push_statement(code, &stmt, self->context);
}
return true;
/* DP errors if the last instruction is not an INSTR_DONE. */
if (vec_last(self->code->statements).opcode != INSTR_DONE)
{
+ lex_ctx_t last;
+
stmt.opcode = INSTR_DONE;
- stmt.o1.u1 = 0;
- stmt.o2.u1 = 0;
- stmt.o3.u1 = 0;
- code_push_statement(self->code, &stmt, vec_last(self->code->linenums));
+ stmt.o1.u1 = 0;
+ stmt.o2.u1 = 0;
+ stmt.o3.u1 = 0;
+ last.line = vec_last(self->code->linenums);
+ last.column = vec_last(self->code->columnnums);
+
+ code_push_statement(self->code, &stmt, last);
}
if (OPTS_OPTION_BOOL(OPTION_PP_ONLY))