From bd283fe52305f9afc4fe1f41fb7c06f1634ef4bd Mon Sep 17 00:00:00 2001 From: Denis Denisov Date: Mon, 4 May 2020 09:36:45 +0300 Subject: Revert optimizations added in #68 (#146) --- libyasm/coretype.h | 1 - libyasm/expr.c | 134 ++++------------------------------------------------- libyasm/section.c | 7 --- libyasm/section.h | 10 ---- libyasm/value.c | 11 ----- 5 files changed, 10 insertions(+), 153 deletions(-) (limited to 'libyasm') diff --git a/libyasm/coretype.h b/libyasm/coretype.h index c4b82cce..624e3c44 100644 --- a/libyasm/coretype.h +++ b/libyasm/coretype.h @@ -233,7 +233,6 @@ typedef enum yasm_expr_op { YASM_EXPR_NOR, /**< Bitwise NOR. */ YASM_EXPR_SHL, /**< Shift left (logical). */ YASM_EXPR_SHR, /**< Shift right (logical). */ - YASM_EXPR_LOGIC, /**< Start of logic operations (not an op). */ YASM_EXPR_LOR, /**< Logical OR. */ YASM_EXPR_LAND, /**< Logical AND. */ YASM_EXPR_LNOT, /**< Logical negation. */ diff --git a/libyasm/expr.c b/libyasm/expr.c index 1aad79df..c2c868ed 100644 --- a/libyasm/expr.c +++ b/libyasm/expr.c @@ -846,120 +846,6 @@ expr_expand_equ(yasm_expr *e, yasm__exprhead *eh) return e; } -static yasm_expr * -expr_simplify_seg(yasm_expr *e) -{ - yasm_expr *sube, *seg; - - if (e->op != YASM_EXPR_SEG && e->op != YASM_EXPR_WRT) - return e; - if (e->terms[0].type != YASM_EXPR_EXPR) - return e; - sube = e->terms[0].data.expn; - - seg = yasm_expr_extract_deep_segoff(&sube); - if (!seg) - return e; - - if (e->op == YASM_EXPR_SEG) { - e->op = YASM_EXPR_IDENT; - yasm_expr_destroy(sube); - e->terms[0].data.expn = seg; - } else if (e->op == YASM_EXPR_WRT) { - yasm_expr *old_base, *new_base; - yasm_expr *wrt, *off; - unsigned long line = e->line; - - off = e; - wrt = yasm_expr_extract_wrt(&off); - - assert(wrt != NULL); - - old_base = yasm_xmalloc(sizeof(yasm_expr)); - old_base->op = YASM_EXPR_MUL; - old_base->line = line; - old_base->numterms = 2; - old_base->terms[0].type = YASM_EXPR_INT; - old_base->terms[0].data.intn = yasm_intnum_create_int(16); - old_base->terms[1].type = YASM_EXPR_EXPR; - old_base->terms[1].data.expn = seg; - - new_base = yasm_xmalloc(sizeof(yasm_expr)); - new_base->op = YASM_EXPR_MUL; - new_base->line = line; - new_base->numterms = 2; - new_base->terms[0].type = YASM_EXPR_INT; - new_base->terms[0].data.intn = yasm_intnum_create_int(-16); - new_base->terms[1].type = YASM_EXPR_EXPR; - new_base->terms[1].data.expn = wrt; - - e = yasm_xmalloc(sizeof(yasm_expr)+sizeof(yasm_expr__item)); - e->op = YASM_EXPR_ADD; - e->line = line; - e->numterms = 3; - e->terms[0].type = YASM_EXPR_EXPR; - e->terms[0].data.expn = off; - e->terms[1].type = YASM_EXPR_EXPR; - e->terms[1].data.expn = old_base; - e->terms[2].type = YASM_EXPR_EXPR; - e->terms[2].data.expn = new_base; - } - - return e; -} - -static yasm_expr * -expr_lift_segoff(yasm_expr *e, int calc_bc_dist) -{ - yasm_expr *retval = NULL; - int i; - - if (e->op < YASM_EXPR_LOGIC || e->op == YASM_EXPR_SEGOFF) { - i = e->op == YASM_EXPR_SEGOFF ? 1 : 0; - for (; inumterms; i++) { - if (e->terms[i].type == YASM_EXPR_EXPR && - e->terms[i].data.expn->op == YASM_EXPR_SEGOFF) { - yasm_expr *sub = e->terms[i].data.expn; - e->terms[i] = sub->terms[1]; - retval = sub; - retval->op = YASM_EXPR_SEGOFF; - retval->line = e->line; - retval->numterms = 2; - break; - } - } - } - - if (retval != NULL && e->op == YASM_EXPR_SEGOFF) { - yasm_intnum *diff; - yasm_expr *helper; - e->op = YASM_EXPR_IDENT; - e->numterms = 1; - retval->op = YASM_EXPR_IDENT; - retval->numterms = 1; - helper = yasm_xmalloc(sizeof(yasm_expr)); - helper->op = YASM_EXPR_SUB; - helper->numterms = 2; - helper->terms[0].type = YASM_EXPR_EXPR; - helper->terms[0].data.expn = yasm_expr_copy(e); - helper->terms[1].type = YASM_EXPR_EXPR; - helper->terms[1].data.expn = yasm_expr_copy(retval); - diff = yasm_expr_get_intnum(&helper, calc_bc_dist); - if (diff != NULL && yasm_intnum_is_zero(diff)) { - yasm_expr_destroy(retval); - retval = NULL; - } else { - retval->op = YASM_EXPR_SEGOFF; - retval->numterms = 2; - } - yasm_expr_destroy(helper); - e->op = YASM_EXPR_SEGOFF; - e->numterms = 2; - } - - return retval; -} - static yasm_expr * expr_level_tree(yasm_expr *e, int fold_const, int simplify_ident, int simplify_reg_mul, int calc_bc_dist, @@ -967,10 +853,8 @@ expr_level_tree(yasm_expr *e, int fold_const, int simplify_ident, void *expr_xform_extra_data) { int i; - yasm_expr *seg; e = expr_xform_neg(e); - e = expr_simplify_seg(e); /* traverse terms */ for (i=0; inumterms; i++) { @@ -982,11 +866,18 @@ expr_level_tree(yasm_expr *e, int fold_const, int simplify_ident, expr_xform_extra, expr_xform_extra_data); } + /* Check for SEG of SEG:OFF, if we match, simplify to just the segment */ + if (e->op == YASM_EXPR_SEG && e->terms[0].type == YASM_EXPR_EXPR && + e->terms[0].data.expn->op == YASM_EXPR_SEGOFF) { + e->op = YASM_EXPR_IDENT; + e->terms[0].data.expn->op = YASM_EXPR_IDENT; + /* Destroy the second (offset) term */ + e->terms[0].data.expn->numterms = 1; + expr_delete_term(&e->terms[0].data.expn->terms[1], 1); + } + /* do callback */ e = expr_level_op(e, fold_const, simplify_ident, simplify_reg_mul); - seg = expr_lift_segoff(e, calc_bc_dist); - if (seg) - e = expr_level_op(e, fold_const, simplify_ident, simplify_reg_mul); if (calc_bc_dist || expr_xform_extra) { if (calc_bc_dist) e = expr_xform_bc_dist(e); @@ -995,11 +886,6 @@ expr_level_tree(yasm_expr *e, int fold_const, int simplify_ident, e = expr_level_tree(e, fold_const, simplify_ident, simplify_reg_mul, 0, NULL, NULL); } - if (seg) { - seg->terms[1].type = YASM_EXPR_EXPR; - seg->terms[1].data.expn = e; - e = seg; - } return e; } diff --git a/libyasm/section.c b/libyasm/section.c index 47e730c3..ba582bfa 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -241,11 +241,6 @@ yasm_object_create(const char *src_filename, const char *obj_filename, /* Initialize things to NULL in case of error */ object->dbgfmt = NULL; - /* Initialize override structure */ - object->overrides = yasm_xmalloc(sizeof(yasm_overrides)); - - object->overrides->value_finalize = NULL; - /* Initialize the object format */ object->objfmt = yasm_objfmt_create(objfmt_module, object); if (!object->objfmt) { @@ -494,8 +489,6 @@ yasm_object_destroy(yasm_object *object) if (object->arch) yasm_arch_destroy(object->arch); - yasm_xfree(object->overrides); - yasm_xfree(object); } diff --git a/libyasm/section.h b/libyasm/section.h index 5bdd4419..2c7faa4d 100644 --- a/libyasm/section.h +++ b/libyasm/section.h @@ -45,15 +45,6 @@ struct yasm_reloc { /*@dependent@*/ yasm_symrec *sym; /**< Relocated symbol */ }; -/** Structure of functions that can be overridden - */ -typedef struct yasm_overrides { - /** TODO: documentation - */ - int - (*value_finalize)(yasm_value *value, yasm_bytecode *precbc); -} yasm_overrides; - /** An object. This is the internal representation of an object file. */ struct yasm_object { /*@owned@*/ char *src_filename; /**< Source filename */ @@ -63,7 +54,6 @@ struct yasm_object { /*@owned@*/ yasm_arch *arch; /**< Target architecture */ /*@owned@*/ yasm_objfmt *objfmt; /**< Object format */ /*@owned@*/ yasm_dbgfmt *dbgfmt; /**< Debug format */ - /*@owned@*/ yasm_overrides *overrides; /**< Function overrides */ /** Currently active section. Used by some directives. NULL if no * section active. diff --git a/libyasm/value.c b/libyasm/value.c index 47873cf7..3ab73c1c 100644 --- a/libyasm/value.c +++ b/libyasm/value.c @@ -459,20 +459,9 @@ yasm_value_finalize_expr(yasm_value *value, yasm_expr *e, int yasm_value_finalize(yasm_value *value, yasm_bytecode *precbc) { - yasm_object *object = NULL; if (!value->abs) return 0; - if (precbc != NULL) - object = yasm_section_get_object(precbc->section); - - if (object && object->overrides->value_finalize) { - int result; - result = object->overrides->value_finalize(value, precbc); - if (result != -1) - return result; - } - value->abs = yasm_expr__level_tree(value->abs, 1, 1, 0, 0, NULL, NULL); /* quit early if there was an issue in simplify() */ -- cgit v1.2.1