diff options
author | Jannis Harder <jix@jixco.de> | 2012-07-27 17:57:23 +0200 |
---|---|---|
committer | Jannis Harder <jix@jixco.de> | 2012-07-31 13:01:22 +0200 |
commit | 8da658af79b51133699effefcc848fdb0e366fc2 (patch) | |
tree | f6549cd267f8a6f3beb30d8dbd4a12bc6e86e8b1 /libyasm | |
parent | 662fa69efcd60312b16fe84759877b789260bbaa (diff) | |
download | yasm-8da658af79b51133699effefcc848fdb0e366fc2.tar.gz |
Overrides and dummy value finalization for bin
- Added support for overriding certain functions
- Override value_finalize with dummy function for the bin objfmt
Diffstat (limited to 'libyasm')
-rw-r--r-- | libyasm/section.c | 7 | ||||
-rw-r--r-- | libyasm/section.h | 10 | ||||
-rw-r--r-- | libyasm/value.c | 11 |
3 files changed, 28 insertions, 0 deletions
diff --git a/libyasm/section.c b/libyasm/section.c index 9242fb01..7198beb7 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -241,6 +241,11 @@ 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) { @@ -485,6 +490,8 @@ 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 2c7faa4d..5bdd4419 100644 --- a/libyasm/section.h +++ b/libyasm/section.h @@ -45,6 +45,15 @@ 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 */ @@ -54,6 +63,7 @@ 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 3ab73c1c..47873cf7 100644 --- a/libyasm/value.c +++ b/libyasm/value.c @@ -459,9 +459,20 @@ 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() */ |