From bc652be79ef74c200faeb48a63bda5279b291800 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 29 Dec 2016 16:56:12 +0000 Subject: [PATCH] Completely remove vcode bookmarks --- src/eval.c | 15 +++++++-------- src/lower.c | 29 +++++++---------------------- src/vcode.c | 50 +++++++++++--------------------------------------- src/vcode.h | 19 +++++-------------- 4 files changed, 30 insertions(+), 83 deletions(-) diff --git a/src/eval.c b/src/eval.c index a522db3e..80e0056d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -799,17 +799,17 @@ static void eval_op_bounds(int op, eval_state_t *state) break; else if (reg->integer < low || reg->integer > high) { if (state->flags & EVAL_BOUNDS) { - const loc_t *loc = tree_loc(vcode_get_bookmark(op).tree); - switch ((bounds_kind_t)vcode_get_subkind(op)) { case BOUNDS_ARRAY_TO: - error_at(loc, "array index %"PRIi64" outside bounds %"PRIi64 - " to %"PRIi64, reg->integer, low, high); + error_at(&(state->last_loc), "array index %"PRIi64" outside " + "bounds %"PRIi64" to %"PRIi64, + reg->integer, low, high); break; case BOUNDS_ARRAY_DOWNTO: - error_at(loc, "array index %"PRIi64" outside bounds %"PRIi64 - " downto %"PRIi64, reg->integer, high, low); + error_at(&(state->last_loc), "array index %"PRIi64" outside " + "bounds %"PRIi64" downto %"PRIi64, + reg->integer, high, low); break; default: @@ -1406,8 +1406,7 @@ static void eval_op_array_size(int op, eval_state_t *state) if (rlen->integer != llen->integer) { if (state->flags & EVAL_BOUNDS) { - vcode_bookmark_t where = vcode_get_bookmark(op); - error_at(tree_loc(where.tree), "length of target %"PRIi64" does not " + error_at(&(state->last_loc), "length of target %"PRIi64" does not " "match length of value %"PRIi64, llen->integer, rlen->integer); } diff --git a/src/lower.c b/src/lower.c index ef18a538..0e1fa90d 100644 --- a/src/lower.c +++ b/src/lower.c @@ -507,15 +507,6 @@ static vcode_reg_t lower_wrap(type_t type, vcode_reg_t data) return lower_wrap_with_new_bounds(type, data, data); } -static vcode_bookmark_t lower_bookmark(tree_t where) -{ - vcode_bookmark_t b = { - .tree = where - }; - - return b; -} - static bounds_kind_t lower_type_bounds_kind(type_t type) { if (type_is_enum(type)) @@ -592,18 +583,16 @@ static void lower_check_scalar_bounds(vcode_reg_t value, type_t type, else emit_debug_info(tree_loc(where)); - const vcode_bookmark_t index1 = lower_bookmark(where); - const bounds_kind_t kind = lower_type_bounds_kind(type); const char *prefix = kind == BOUNDS_ENUM ? type_pp(type) : NULL; char *hint_str LOCAL = lower_get_hint_string(where, prefix); vcode_reg_t low_reg, high_reg; if (lower_scalar_has_static_bounds(type, &low_reg, &high_reg)) - emit_bounds(value, lower_bounds(type), kind, index1, hint_str); + emit_bounds(value, lower_bounds(type), kind, hint_str); else { vcode_reg_t kind_reg = emit_const(vtype_offset(), kind); - emit_dynamic_bounds(value, low_reg, high_reg, kind_reg, index1, hint_str); + emit_dynamic_bounds(value, low_reg, high_reg, kind_reg, hint_str); } } @@ -1782,8 +1771,7 @@ static void lower_check_array_bounds(type_t type, int dim, vcode_reg_t array, char *hint_str LOCAL = lower_get_hint_string(where, NULL); - const vcode_bookmark_t index = lower_bookmark(where); - emit_dynamic_bounds(value, min_reg, max_reg, kind_reg, index, hint_str); + emit_dynamic_bounds(value, min_reg, max_reg, kind_reg, hint_str); } static vcode_reg_t lower_array_ref_offset(tree_t ref, vcode_reg_t array) @@ -3147,7 +3135,7 @@ static void lower_check_array_sizes(tree_t t, type_t ltype, type_t rtype, vcode_reg_t llen_reg = lower_array_len(ltype, 0, lval); vcode_reg_t rlen_reg = lower_array_len(rtype, 0, rval); - emit_array_size(llen_reg, rlen_reg, lower_bookmark(t)); + emit_array_size(llen_reg, rlen_reg); } static void lower_find_matching_refs(tree_t ref, void *context) @@ -4033,8 +4021,7 @@ static void lower_check_indexes(type_t type, vcode_reg_t array, tree_t hint) vcode_reg_t right_reg = lower_array_right(type, i, array); if (type_is_enum(index)) - emit_index_check(left_reg, right_reg, vbounds, - BOUNDS_INDEX_TO, lower_bookmark(hint)); + emit_index_check(left_reg, right_reg, vbounds, BOUNDS_INDEX_TO); else { range_t rindex = type_dim(index, 0); bounds_kind_t bkind = rindex.kind == RANGE_TO @@ -4053,8 +4040,7 @@ static void lower_check_indexes(type_t type, vcode_reg_t array, tree_t hint) } if (lower_is_const(rindex.left) && lower_is_const(rindex.right)) { - emit_index_check(rlow_reg, rhigh_reg, vbounds, - bkind, lower_bookmark(hint)); + emit_index_check(rlow_reg, rhigh_reg, vbounds, bkind); } else { vcode_reg_t bleft = lower_reify_expr(rindex.left); @@ -4063,8 +4049,7 @@ static void lower_check_indexes(type_t type, vcode_reg_t array, tree_t hint) vcode_reg_t bmin = bkind == BOUNDS_INDEX_TO ? bleft : bright; vcode_reg_t bmax = bkind == BOUNDS_INDEX_TO ? bright : bleft; - emit_dynamic_index_check(rlow_reg, rhigh_reg, bmin, bmax, - bkind, lower_bookmark(hint)); + emit_dynamic_index_check(rlow_reg, rhigh_reg, bmin, bmax, bkind); } } } diff --git a/src/vcode.c b/src/vcode.c index 0ec698dd..c100473b 100644 --- a/src/vcode.c +++ b/src/vcode.c @@ -71,10 +71,6 @@ DECLARE_AND_DEFINE_ARRAY(vcode_type); (x == VCODE_OP_COVER_STMT || x == VCODE_OP_COVER_COND) #define OP_HAS_COMMENT(x) \ (x == VCODE_OP_COMMENT) -#define OP_HAS_BOOKMARK(x) \ - (x == VCODE_OP_BOUNDS \ - || x == VCODE_OP_DYNAMIC_BOUNDS || x == VCODE_OP_ARRAY_SIZE \ - || x == VCODE_OP_INDEX_CHECK) #define OP_HAS_HINT(x) \ (x == VCODE_OP_BOUNDS || x == VCODE_OP_DYNAMIC_BOUNDS) #define OP_HAS_TARGET(x) \ @@ -97,7 +93,6 @@ typedef struct { unsigned subkind; // OP_HAS_SUBKIND }; union { - vcode_bookmark_t bookmark; // OP_HAS_BOOKMARK loc_t loc; // OP_HAS_LOC vcode_block_array_t targets; // OP_HAS_TARGET }; @@ -962,13 +957,6 @@ uint32_t vcode_get_tag(int op) return o->tag; } -vcode_bookmark_t vcode_get_bookmark(int op) -{ - op_t *o = vcode_op_data(op); - assert(OP_HAS_BOOKMARK(o->kind)); - return o->bookmark; -} - const loc_t *vcode_get_loc(int op) { op_t *o = vcode_op_data(op); @@ -976,12 +964,6 @@ const loc_t *vcode_get_loc(int op) return &(o->loc); } -uint32_t vcode_get_index(int op) -{ - // TODO: remove this? - return tree_index(vcode_get_bookmark(op).tree); -} - const char *vcode_get_hint(int op) { op_t *o = vcode_op_data(op); @@ -2077,15 +2059,14 @@ void vcode_dump(void) case VCODE_OP_COVER_STMT: { - printf("%s %u", vcode_op_string(op->kind), - tree_index(op->bookmark.tree)); + printf("%s %u", vcode_op_string(op->kind), op->tag); } break; case VCODE_OP_COVER_COND: { printf("%s %u sub %u ", vcode_op_string(op->kind), - tree_index(op->bookmark.tree), op->subkind); + op->tag, op->subkind); vcode_dump_reg(op->args.items[0]); } break; @@ -3436,7 +3417,7 @@ vcode_reg_t emit_sub(vcode_reg_t lhs, vcode_reg_t rhs) } void emit_bounds(vcode_reg_t reg, vcode_type_t bounds, bounds_kind_t kind, - vcode_bookmark_t where, const char *hint) + const char *hint) { if (reg == VCODE_INVALID_REG) return; @@ -3449,7 +3430,6 @@ void emit_bounds(vcode_reg_t reg, vcode_type_t bounds, bounds_kind_t kind, vcode_add_arg(op, reg); op->type = bounds; op->subkind = kind; - op->bookmark = where; op->hint = hint ? xstrdup(hint) : NULL; const vtype_kind_t tkind = vtype_kind(bounds); @@ -4468,8 +4448,7 @@ void emit_needs_last_value(vcode_signal_t sig) } void emit_dynamic_bounds(vcode_reg_t reg, vcode_reg_t low, vcode_reg_t high, - vcode_reg_t kind, vcode_bookmark_t where, - const char *hint) + vcode_reg_t kind, const char *hint) { int64_t lconst, hconst; if (vcode_reg_const(low, &lconst) && vcode_reg_const(high, &hconst)) { @@ -4481,7 +4460,7 @@ void emit_dynamic_bounds(vcode_reg_t reg, vcode_reg_t low, vcode_reg_t high, int64_t kconst; if (vcode_reg_const(kind, &kconst)) { - emit_bounds(reg, vtype_int(lconst, hconst), kconst, where, hint); + emit_bounds(reg, vtype_int(lconst, hconst), kconst, hint); return; } } @@ -4495,7 +4474,6 @@ void emit_dynamic_bounds(vcode_reg_t reg, vcode_reg_t low, vcode_reg_t high, vcode_add_arg(op, low); vcode_add_arg(op, high); vcode_add_arg(op, kind); - op->bookmark = where; op->hint = hint ? xstrdup(hint) : NULL; VCODE_ASSERT(vtype_eq(vcode_reg_type(low), vcode_reg_type(high)), @@ -4506,7 +4484,7 @@ void emit_dynamic_bounds(vcode_reg_t reg, vcode_reg_t low, vcode_reg_t high, "bounds check needs debug info"); } -void emit_array_size(vcode_reg_t llen, vcode_reg_t rlen, vcode_bookmark_t where) +void emit_array_size(vcode_reg_t llen, vcode_reg_t rlen) { if (rlen == llen) return; @@ -4514,11 +4492,10 @@ void emit_array_size(vcode_reg_t llen, vcode_reg_t rlen, vcode_bookmark_t where) op_t *op = vcode_add_op(VCODE_OP_ARRAY_SIZE); vcode_add_arg(op, llen); vcode_add_arg(op, rlen); - op->bookmark = where; } static op_t *emit_index_check_null(vcode_reg_t rlow, vcode_reg_t rhigh, - bounds_kind_t kind, vcode_bookmark_t where) + bounds_kind_t kind) { int64_t rlow_const, rhigh_const; const bool null = @@ -4535,14 +4512,13 @@ static op_t *emit_index_check_null(vcode_reg_t rlow, vcode_reg_t rhigh, vcode_add_arg(op, rlow); vcode_add_arg(op, rhigh); op->subkind = kind; - op->bookmark = where; op->type = VCODE_INVALID_TYPE; return op; } void emit_index_check(vcode_reg_t rlow, vcode_reg_t rhigh, vcode_type_t bounds, - bounds_kind_t kind, vcode_bookmark_t where) + bounds_kind_t kind) { if (vtype_includes(bounds, vcode_reg_data(rlow)->bounds) && vtype_includes(bounds, vcode_reg_data(rhigh)->bounds)) { @@ -4550,7 +4526,7 @@ void emit_index_check(vcode_reg_t rlow, vcode_reg_t rhigh, vcode_type_t bounds, return; } - op_t *op = emit_index_check_null(rlow, rhigh, kind, where); + op_t *op = emit_index_check_null(rlow, rhigh, kind); if (op != NULL) op->type = bounds; @@ -4560,9 +4536,9 @@ void emit_index_check(vcode_reg_t rlow, vcode_reg_t rhigh, vcode_type_t bounds, void emit_dynamic_index_check(vcode_reg_t rlow, vcode_reg_t rhigh, vcode_reg_t blow, vcode_reg_t bhigh, - bounds_kind_t kind, vcode_bookmark_t where) + bounds_kind_t kind) { - op_t *op = emit_index_check_null(rlow, rhigh, kind, where); + op_t *op = emit_index_check_null(rlow, rhigh, kind); if (op != NULL) { vcode_add_arg(op, blow); vcode_add_arg(op, bhigh); @@ -4780,8 +4756,6 @@ static void vcode_write_unit(vcode_unit_t unit, fbuf_t *f, write_u32(op->type, f); if (OP_HAS_ADDRESS(op->kind)) write_u32(op->address, f); - if (OP_HAS_BOOKMARK(op->kind)) - write_u32(tree_index(op->bookmark.tree), f); if (OP_HAS_FUNC(op->kind)) ident_write(op->func, ident_wr_ctx); if (OP_HAS_SUBKIND(op->kind)) @@ -4972,8 +4946,6 @@ static bool vcode_read_unit(fbuf_t *f, tree_rd_ctx_t tree_ctx, op->type = read_u32(f); if (OP_HAS_ADDRESS(op->kind)) op->address = read_u32(f); - if (OP_HAS_BOOKMARK(op->kind)) - op->bookmark.tree = tree_read_recall(tree_ctx, read_u32(f)); if (OP_HAS_FUNC(op->kind)) op->func = ident_read(ident_rd_ctx); if (OP_HAS_SUBKIND(op->kind)) diff --git a/src/vcode.h b/src/vcode.h index 3e2b309a..e1468bb0 100644 --- a/src/vcode.h +++ b/src/vcode.h @@ -171,11 +171,6 @@ typedef struct { vcode_block_t block; } vcode_state_t; -typedef union { - tree_t tree; - type_t type; -} vcode_bookmark_t; - typedef struct { ident_t name; image_kind_t kind; @@ -279,8 +274,6 @@ ident_t vcode_get_func(int op); int64_t vcode_get_value(int op); double vcode_get_real(int op); vcode_cmp_t vcode_get_cmp(int op); -uint32_t vcode_get_index(int op); -vcode_bookmark_t vcode_get_bookmark(int op); const loc_t *vcode_get_loc(int op); const char *vcode_get_hint(int op); vcode_block_t vcode_get_target(int op, int nth); @@ -355,15 +348,14 @@ vcode_reg_t emit_load_indirect(vcode_reg_t reg); void emit_store(vcode_reg_t reg, vcode_var_t var); void emit_store_indirect(vcode_reg_t reg, vcode_reg_t ptr); void emit_bounds(vcode_reg_t reg, vcode_type_t bounds, bounds_kind_t kind, - vcode_bookmark_t where, const char *hint); + const char *hint); void emit_dynamic_bounds(vcode_reg_t reg, vcode_reg_t low, vcode_reg_t high, - vcode_reg_t kind, vcode_bookmark_t where, - const char *hint); + vcode_reg_t kind, const char *hint); void emit_index_check(vcode_reg_t rlow, vcode_reg_t rhigh, vcode_type_t bounds, - bounds_kind_t kind, vcode_bookmark_t where); + bounds_kind_t kind); void emit_dynamic_index_check(vcode_reg_t rlow, vcode_reg_t rhigh, vcode_reg_t blow, vcode_reg_t bhigh, - bounds_kind_t kind, vcode_bookmark_t where); + bounds_kind_t kind); vcode_reg_t emit_index(vcode_var_t var, vcode_reg_t offset); vcode_reg_t emit_cast(vcode_type_t type, vcode_reg_t bounds, vcode_reg_t reg); void emit_return(vcode_reg_t reg); @@ -431,8 +423,7 @@ vcode_reg_t emit_bit_vec_op(bit_vec_op_kind_t kind, vcode_reg_t lhs_data, vcode_reg_t emit_value(vcode_reg_t string, vcode_reg_t len, vcode_reg_t map); vcode_reg_t emit_last_event(vcode_reg_t signal, vcode_reg_t len); void emit_needs_last_value(vcode_signal_t sig); -void emit_array_size(vcode_reg_t llen, vcode_reg_t rlen, - vcode_bookmark_t index); +void emit_array_size(vcode_reg_t llen, vcode_reg_t rlen); vcode_reg_t emit_bit_shift(bit_shift_kind_t kind, vcode_reg_t data, vcode_reg_t len, vcode_reg_t dir, vcode_reg_t shift, vcode_type_t result); -- 2.39.2