1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

Update asm format for sourcemaps to use pairs for sourcemap entries.

This commit is contained in:
Calvin Rose 2018-02-12 12:28:58 -05:00
parent af6e6ded35
commit e124029ae3

View File

@ -76,62 +76,62 @@ struct DstAssembler {
* prefix tree. */ * prefix tree. */
static const DstInstructionDef dst_ops[] = { static const DstInstructionDef dst_ops[] = {
{"add", DOP_ADD}, {"add", DOP_ADD},
{"add-immediate", DOP_ADD_IMMEDIATE}, {"addim", DOP_ADD_IMMEDIATE},
{"add-integer", DOP_ADD_INTEGER}, {"addi", DOP_ADD_INTEGER},
{"add-real", DOP_ADD_REAL}, {"addr", DOP_ADD_REAL},
{"band", DOP_BAND}, {"band", DOP_BAND},
{"bnot", DOP_BNOT}, {"bnot", DOP_BNOT},
{"bor", DOP_BOR}, {"bor", DOP_BOR},
{"bxor", DOP_BXOR}, {"bxor", DOP_BXOR},
{"call", DOP_CALL}, {"call", DOP_CALL},
{"closure", DOP_CLOSURE}, {"clo", DOP_CLOSURE},
{"compare", DOP_COMPARE}, {"cmp", DOP_COMPARE},
{"divide", DOP_DIVIDE}, {"div", DOP_DIVIDE},
{"divide-immediate", DOP_DIVIDE_IMMEDIATE}, {"divim", DOP_DIVIDE_IMMEDIATE},
{"divide-integer", DOP_DIVIDE_INTEGER}, {"divi", DOP_DIVIDE_INTEGER},
{"divide-real", DOP_DIVIDE_REAL}, {"divr", DOP_DIVIDE_REAL},
{"equals", DOP_EQUALS}, {"eq", DOP_EQUALS},
{"error", DOP_ERROR}, {"err", DOP_ERROR},
{"get", DOP_GET}, {"get", DOP_GET},
{"get-index", DOP_GET_INDEX}, {"geti", DOP_GET_INDEX},
{"greater-than", DOP_GREATER_THAN}, {"gt", DOP_GREATER_THAN},
{"jump", DOP_JUMP}, {"jmp", DOP_JUMP},
{"jump-if", DOP_JUMP_IF}, {"jmpi", DOP_JUMP_IF},
{"jump-if-not", DOP_JUMP_IF_NOT}, {"jmpn", DOP_JUMP_IF_NOT},
{"less-than", DOP_LESS_THAN}, {"lt", DOP_LESS_THAN},
{"load-constant", DOP_LOAD_CONSTANT}, {"lc", DOP_LOAD_CONSTANT},
{"load-false", DOP_LOAD_FALSE}, {"lf", DOP_LOAD_FALSE},
{"load-integer", DOP_LOAD_INTEGER}, {"li", DOP_LOAD_INTEGER},
{"load-nil", DOP_LOAD_NIL}, {"ln", DOP_LOAD_NIL},
{"load-self", DOP_LOAD_SELF}, {"ls", DOP_LOAD_SELF},
{"load-true", DOP_LOAD_TRUE}, {"lt", DOP_LOAD_TRUE},
{"load-upvalue", DOP_LOAD_UPVALUE}, {"lu", DOP_LOAD_UPVALUE},
{"move-far", DOP_MOVE_FAR}, {"movf", DOP_MOVE_FAR},
{"move-near", DOP_MOVE_NEAR}, {"movn", DOP_MOVE_NEAR},
{"multiply", DOP_MULTIPLY}, {"mul", DOP_MULTIPLY},
{"multiply-immediate", DOP_MULTIPLY_IMMEDIATE}, {"mulim", DOP_MULTIPLY_IMMEDIATE},
{"multiply-integer", DOP_MULTIPLY_INTEGER}, {"muli", DOP_MULTIPLY_INTEGER},
{"multiply-real", DOP_MULTIPLY_REAL}, {"mulr", DOP_MULTIPLY_REAL},
{"noop", DOP_NOOP}, {"noop", DOP_NOOP},
{"push", DOP_PUSH}, {"push", DOP_PUSH},
{"push-array", DOP_PUSH_ARRAY}, {"pusha", DOP_PUSH_ARRAY},
{"push2", DOP_PUSH_2}, {"push2", DOP_PUSH_2},
{"push3", DOP_PUSH_3}, {"push3", DOP_PUSH_3},
{"put", DOP_PUT}, {"put", DOP_PUT},
{"put-index", DOP_PUT_INDEX}, {"puti", DOP_PUT_INDEX},
{"return", DOP_RETURN}, {"ret", DOP_RETURN},
{"return-nil", DOP_RETURN_NIL}, {"retn", DOP_RETURN_NIL},
{"set-upvalue", DOP_SET_UPVALUE}, {"setu", DOP_SET_UPVALUE},
{"shift-left", DOP_SHIFT_LEFT}, {"sl", DOP_SHIFT_LEFT},
{"shift-left-immediate", DOP_SHIFT_LEFT_IMMEDIATE}, {"slim", DOP_SHIFT_LEFT_IMMEDIATE},
{"shift-right", DOP_SHIFT_RIGHT}, {"sr", DOP_SHIFT_RIGHT},
{"shift-right-immediate", DOP_SHIFT_RIGHT_IMMEDIATE}, {"srim", DOP_SHIFT_RIGHT_IMMEDIATE},
{"shift-right-unsigned", DOP_SHIFT_RIGHT_UNSIGNED}, {"sru", DOP_SHIFT_RIGHT_UNSIGNED},
{"shift-right-unsigned-immediate", DOP_SHIFT_RIGHT_UNSIGNED_IMMEDIATE}, {"sruim", DOP_SHIFT_RIGHT_UNSIGNED_IMMEDIATE},
{"subtract", DOP_SUBTRACT}, {"sub", DOP_SUBTRACT},
{"tailcall", DOP_TAILCALL}, {"tcall", DOP_TAILCALL},
{"transfer", DOP_TRANSFER}, {"tran", DOP_TRANSFER},
{"typecheck", DOP_TYPECHECK}, {"tchck", DOP_TYPECHECK}
}; };
/* Check a dst string against a bunch of test_strings. Return the /* Check a dst string against a bunch of test_strings. Return the
@ -653,21 +653,23 @@ static DstAssembleResult dst_asm1(DstAssembler *parent, Dst source, int flags) {
/* Check for source mapping */ /* Check for source mapping */
x = dst_get(s, dst_csymbolv("sourcemap")); x = dst_get(s, dst_csymbolv("sourcemap"));
if (dst_seq_view(x, &arr, &count)) { if (dst_seq_view(x, &arr, &count)) {
dst_asm_assert(&a, count == 2 * def->bytecode_length, "sourcemap must have twice the length of the bytecode"); dst_asm_assert(&a, count == def->bytecode_length, "sourcemap must have the same length as the bytecode");
def->sourcemap = malloc(sizeof(int32_t) * 2 * count); def->sourcemap = malloc(sizeof(int32_t) * 2 * count);
for (i = 0; i < count; i += 2) { for (i = 0; i < count; i++) {
Dst start = arr[i]; const Dst *tup;
Dst end = arr[i + 1]; Dst entry = arr[i];
if (!(dst_checktype(start, DST_INTEGER) || if (!dst_checktype(entry, DST_TUPLE)) {
dst_unwrap_integer(start) < 0)) { dst_asm_error(&a, "expected tuple");
dst_asm_error(&a, "expected positive integer");
} }
if (!(dst_checktype(end, DST_INTEGER) || tup = dst_unwrap_tuple(entry);
dst_unwrap_integer(end) < 0)) { if (!dst_checktype(tup[0], DST_INTEGER)) {
dst_asm_error(&a, "expected positive integer"); dst_asm_error(&a, "expected integer");
} }
def->sourcemap[i] = dst_unwrap_integer(start); if (!dst_checktype(tup[1], DST_INTEGER)) {
def->sourcemap[i+1] = dst_unwrap_integer(end); dst_asm_error(&a, "expected integer");
}
def->sourcemap[2*i] = dst_unwrap_integer(tup[0]);
def->sourcemap[2*i+1] = dst_unwrap_integer(tup[1]);
} }
} }
@ -825,11 +827,14 @@ Dst dst_disasm(DstFuncDef *def) {
/* Add source map */ /* Add source map */
if (NULL != def->sourcemap) { if (NULL != def->sourcemap) {
DstArray *sourcemap = dst_array(def->bytecode_length * 2); DstArray *sourcemap = dst_array(def->bytecode_length);
for (i = 0; i < def->bytecode_length * 2; i++) { for (i = 0; i < def->bytecode_length * 2; i += 2) {
sourcemap->data[i] = dst_wrap_integer(def->sourcemap[i]); Dst *t = dst_tuple_begin(2);
t[0] = dst_wrap_integer(def->sourcemap[i]);
t[1] = dst_wrap_integer(def->sourcemap[i + 1]);
sourcemap->data[i / 2] = dst_wrap_tuple(dst_tuple_end(t));
} }
sourcemap->count = def->bytecode_length * 2; sourcemap->count = def->bytecode_length;
dst_table_put(ret, dst_csymbolv("sourcemap"), dst_wrap_array(sourcemap)); dst_table_put(ret, dst_csymbolv("sourcemap"), dst_wrap_array(sourcemap));
} }