From: Peter Johnson Date: Wed, 31 May 2006 06:25:28 +0000 (-0000) Subject: Change yasm_value macros into functions. Fix up the prototype of X-Git-Tag: v0.6.0~172^2~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=23be1d813f39f9cd79f5e16c5891e011eb7d80c2;p=yasm Change yasm_value macros into functions. Fix up the prototype of yasm_value_init_sym (which was out of date). svn path=/branches/new-optimizer/; revision=1546 --- diff --git a/libyasm/value.c b/libyasm/value.c index 1a0c8b61..375d3a13 100644 --- a/libyasm/value.c +++ b/libyasm/value.c @@ -46,6 +46,58 @@ #include "expr-int.h" #include "bc-int.h" +void +yasm_value_initialize(/*@out@*/ yasm_value *value, + /*@null@*/ /*@kept@*/ yasm_expr *e, unsigned int size) +{ + value->abs = e; + value->rel = NULL; + value->wrt = NULL; + value->seg_of = 0; + value->rshift = 0; + value->curpos_rel = 0; + value->ip_rel = 0; + value->section_rel = 0; + value->size = size; +} + +void +yasm_value_init_sym(/*@out@*/ yasm_value *value, /*@null@*/ yasm_symrec *sym, + unsigned int size) +{ + value->abs = NULL; + value->rel = sym; + value->wrt = NULL; + value->seg_of = 0; + value->rshift = 0; + value->curpos_rel = 0; + value->ip_rel = 0; + value->section_rel = 0; + value->size = size; +} + +void +yasm_value_init_copy(yasm_value *value, const yasm_value *orig) +{ + value->abs = orig->abs ? yasm_expr_copy(orig->abs) : NULL; + value->rel = orig->rel; + value->wrt = orig->wrt; + value->seg_of = orig->seg_of; + value->rshift = orig->rshift; + value->curpos_rel = orig->curpos_rel; + value->ip_rel = orig->ip_rel; + value->section_rel = orig->section_rel; + value->size = orig->size; +} + +void +yasm_value_delete(yasm_value *value) +{ + yasm_expr_destroy((value)->abs); + value->abs = NULL; + value->rel = NULL; +} + static int value_finalize_scan(yasm_value *value, yasm_expr *e, int ssym_not_ok) { diff --git a/libyasm/value.h b/libyasm/value.h index 8687f9c8..6aef6011 100644 --- a/libyasm/value.h +++ b/libyasm/value.h @@ -54,9 +54,17 @@ void yasm_value_initialize(/*@out@*/ yasm_value *value, * initialized. * \param value value to be initialized * \param sym symrec + * \param size value size (in bits) */ void yasm_value_init_sym(/*@out@*/ yasm_value *value, - /*@null@*/ yasm_symrec *sym); + /*@null@*/ yasm_symrec *sym, unsigned int size); + +/** Initialize a #yasm_value as a copy of another yasm_value. Any expressions + * within orig are copied, so it's safe to delete the copy. + * \param value value (copy to create) + * \param orig original value + */ +void yasm_value_init_copy(yasm_value *value, const yasm_value *orig); /** Frees any memory inside value; does not free value itself. * \param value value @@ -125,40 +133,4 @@ int yasm_value_output_basic */ void yasm_value_print(const yasm_value *value, FILE *f, int indent_level); - -#ifndef YASM_DOXYGEN -#define yasm_value_initialize(value, e, sz) \ - do { \ - (value)->abs = e; \ - (value)->rel = NULL; \ - (value)->wrt = NULL; \ - (value)->seg_of = 0; \ - (value)->rshift = 0; \ - (value)->curpos_rel = 0; \ - (value)->ip_rel = 0; \ - (value)->section_rel = 0; \ - (value)->size = sz; \ - } while(0) - -#define yasm_value_init_sym(value, sym, sz) \ - do { \ - (value)->abs = NULL; \ - (value)->rel = sym; \ - (value)->wrt = NULL; \ - (value)->seg_of = 0; \ - (value)->rshift = 0; \ - (value)->curpos_rel = 0; \ - (value)->ip_rel = 0; \ - (value)->section_rel = 0; \ - (value)->size = sz; \ - } while(0) - -#define yasm_value_delete(value) \ - do { \ - yasm_expr_destroy((value)->abs); \ - (value)->abs = NULL; \ - (value)->rel = NULL; \ - } while(0) -#endif - #endif