yasm/libyasm/bytecode.c

387 lines
11 KiB
C
Raw Permalink Normal View History

/*
* Bytecode utility functions
*
* Copyright (C) 2001-2007 Peter Johnson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "util.h"
#include "libyasm-stdint.h"
#include "coretype.h"
#include "errwarn.h"
#include "intnum.h"
#include "expr.h"
Massive cleanup of relocation and WRT handling. Closes #49 and lays the groundwork for further features and possible cleanups. Note: this commit changes the way in which relocations in the COFF/Win32/Win64 target can be forced to reference a different symbol than is being pointed to; instead of the ambiguous "trap+(trap.end-trap)" to get the reloc to point at trap.end but reference the trap symbol, after this commit "trap.end wrt trap" is the way to say this. This also reads a lot more clearly and is not ambiguous. This should really only affect people who write .pdata sections for Win64. See the objfmts/win64/tests/win64-dataref.asm testcase for an example of usage. This cleanup adds a new data structure, yasm_value, which is used for all expressions that can be potentially relocatable. This data structure splits the absolute portion of the expression away from the relative portion and any modifications to the relative portion (SEG, WRT, PC-relative, etc). A large amount of code in the new value module breaks a general expression into its absolute and relative parts (yasm_value_finalize_expr) and provides a common set of code for writing out non-relocated values (yasm_value_output_basic). All bytecode handling in both libyasm and the architecture modules was rewritten to use yasm_values when appropriate (e.g. data values, immediates, and effective addresses). The yasm_output_expr_func is now yasm_output_value_func and all users and implementors (mainly in object formats) have been updated to handle yasm_values. Simultaneously with this change, yasm_effaddr and yasm_immval full structure definitions have been moved from bc-int.h to bytecode.h. The data hiding provided by bc-int.h was relatively minimal and probably overkill. Also, great simplifications have been made to x86 effective address expression handling. svn path=/trunk/yasm/; revision=1419
2006-03-19 04:18:10 +00:00
#include "value.h"
#include "symrec.h"
#include "bytecode.h"
void
yasm_bc_set_multiple(yasm_bytecode *bc, yasm_expr *e)
{
if (bc->multiple)
bc->multiple = yasm_expr_create_tree(bc->multiple, YASM_EXPR_MUL, e,
e->line);
else
bc->multiple = e;
}
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
void
yasm_bc_finalize_common(yasm_bytecode *bc, yasm_bytecode *prev_bc)
{
}
int
yasm_bc_calc_len_common(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
void *add_span_data)
{
yasm_internal_error(N_("bytecode length cannot be calculated"));
/*@unreached@*/
return 0;
}
int
yasm_bc_expand_common(yasm_bytecode *bc, int span, long old_val, long new_val,
/*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres)
{
yasm_internal_error(N_("bytecode does not have any dependent spans"));
/*@unreached@*/
return 0;
}
int
yasm_bc_tobytes_common(yasm_bytecode *bc, unsigned char **buf,
unsigned char *bufstart, void *d,
yasm_output_value_func output_value,
/*@null@*/ yasm_output_reloc_func output_reloc)
{
yasm_internal_error(N_("bytecode cannot be converted to bytes"));
/*@unreached@*/
return 0;
}
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
void
yasm_bc_transform(yasm_bytecode *bc, const yasm_bytecode_callback *callback,
void *contents)
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
{
if (bc->callback)
bc->callback->destroy(bc->contents);
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
bc->callback = callback;
bc->contents = contents;
}
yasm_bytecode *
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
yasm_bc_create_common(const yasm_bytecode_callback *callback, void *contents,
unsigned long line)
{
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
yasm_bytecode *bc = yasm_xmalloc(sizeof(yasm_bytecode));
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
bc->callback = callback;
bc->section = NULL;
bc->multiple = (yasm_expr *)NULL;
bc->len = 0;
bc->mult_int = 1;
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
bc->line = line;
bc->offset = ~0UL; /* obviously incorrect / uninitialized value */
bc->symrecs = NULL;
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
bc->contents = contents;
return bc;
}
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
yasm_section *
yasm_bc_get_section(yasm_bytecode *bc)
{
return bc->section;
}
void
yasm_bc__add_symrec(yasm_bytecode *bc, yasm_symrec *sym)
{
if (!bc->symrecs) {
bc->symrecs = yasm_xmalloc(2*sizeof(yasm_symrec *));
bc->symrecs[0] = sym;
bc->symrecs[1] = NULL;
} else {
/* Very inefficient implementation for large numbers of symbols. But
* that would be very unusual, so use the simple algorithm instead.
*/
size_t count = 1;
while (bc->symrecs[count])
count++;
bc->symrecs = yasm_xrealloc(bc->symrecs,
(count+2)*sizeof(yasm_symrec *));
bc->symrecs[count] = sym;
bc->symrecs[count+1] = NULL;
}
}
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
void
yasm_bc_destroy(yasm_bytecode *bc)
{
if (!bc)
return;
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
if (bc->callback)
bc->callback->destroy(bc->contents);
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
yasm_expr_destroy(bc->multiple);
if (bc->symrecs)
yasm_xfree(bc->symrecs);
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
yasm_xfree(bc);
}
void
yasm_bc_print(const yasm_bytecode *bc, FILE *f, int indent_level)
{
if (!bc->callback)
fprintf(f, "%*s_Empty_\n", indent_level, "");
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
else
bc->callback->print(bc->contents, f, indent_level);
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
fprintf(f, "%*sMultiple=", indent_level, "");
if (!bc->multiple)
fprintf(f, "nil (1)");
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
else
yasm_expr_print(bc->multiple, f);
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
fprintf(f, "\n%*sLength=%lu\n", indent_level, "", bc->len);
fprintf(f, "%*sLine Index=%lu\n", indent_level, "", bc->line);
fprintf(f, "%*sOffset=%lx\n", indent_level, "", bc->offset);
}
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
void
yasm_bc_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc)
{
if (bc->callback)
bc->callback->finalize(bc, prev_bc);
Massive cleanup of relocation and WRT handling. Closes #49 and lays the groundwork for further features and possible cleanups. Note: this commit changes the way in which relocations in the COFF/Win32/Win64 target can be forced to reference a different symbol than is being pointed to; instead of the ambiguous "trap+(trap.end-trap)" to get the reloc to point at trap.end but reference the trap symbol, after this commit "trap.end wrt trap" is the way to say this. This also reads a lot more clearly and is not ambiguous. This should really only affect people who write .pdata sections for Win64. See the objfmts/win64/tests/win64-dataref.asm testcase for an example of usage. This cleanup adds a new data structure, yasm_value, which is used for all expressions that can be potentially relocatable. This data structure splits the absolute portion of the expression away from the relative portion and any modifications to the relative portion (SEG, WRT, PC-relative, etc). A large amount of code in the new value module breaks a general expression into its absolute and relative parts (yasm_value_finalize_expr) and provides a common set of code for writing out non-relocated values (yasm_value_output_basic). All bytecode handling in both libyasm and the architecture modules was rewritten to use yasm_values when appropriate (e.g. data values, immediates, and effective addresses). The yasm_output_expr_func is now yasm_output_value_func and all users and implementors (mainly in object formats) have been updated to handle yasm_values. Simultaneously with this change, yasm_effaddr and yasm_immval full structure definitions have been moved from bc-int.h to bytecode.h. The data hiding provided by bc-int.h was relatively minimal and probably overkill. Also, great simplifications have been made to x86 effective address expression handling. svn path=/trunk/yasm/; revision=1419
2006-03-19 04:18:10 +00:00
if (bc->multiple) {
yasm_value val;
if (yasm_value_finalize_expr(&val, bc->multiple, prev_bc, 0))
yasm_error_set(YASM_ERROR_TOO_COMPLEX,
N_("multiple expression too complex"));
else if (val.rel)
yasm_error_set(YASM_ERROR_NOT_ABSOLUTE,
N_("multiple expression not absolute"));
/* Finalize creates NULL output if value=0, but bc->multiple is NULL
* if value=1 (this difference is to make the common case small).
* However, this means we need to set bc->multiple explicitly to 0
* here if val.abs is NULL.
*/
if (val.abs)
bc->multiple = val.abs;
else
bc->multiple = yasm_expr_create_ident(
yasm_expr_int(yasm_intnum_create_uint(0)), bc->line);
Massive cleanup of relocation and WRT handling. Closes #49 and lays the groundwork for further features and possible cleanups. Note: this commit changes the way in which relocations in the COFF/Win32/Win64 target can be forced to reference a different symbol than is being pointed to; instead of the ambiguous "trap+(trap.end-trap)" to get the reloc to point at trap.end but reference the trap symbol, after this commit "trap.end wrt trap" is the way to say this. This also reads a lot more clearly and is not ambiguous. This should really only affect people who write .pdata sections for Win64. See the objfmts/win64/tests/win64-dataref.asm testcase for an example of usage. This cleanup adds a new data structure, yasm_value, which is used for all expressions that can be potentially relocatable. This data structure splits the absolute portion of the expression away from the relative portion and any modifications to the relative portion (SEG, WRT, PC-relative, etc). A large amount of code in the new value module breaks a general expression into its absolute and relative parts (yasm_value_finalize_expr) and provides a common set of code for writing out non-relocated values (yasm_value_output_basic). All bytecode handling in both libyasm and the architecture modules was rewritten to use yasm_values when appropriate (e.g. data values, immediates, and effective addresses). The yasm_output_expr_func is now yasm_output_value_func and all users and implementors (mainly in object formats) have been updated to handle yasm_values. Simultaneously with this change, yasm_effaddr and yasm_immval full structure definitions have been moved from bc-int.h to bytecode.h. The data hiding provided by bc-int.h was relatively minimal and probably overkill. Also, great simplifications have been made to x86 effective address expression handling. svn path=/trunk/yasm/; revision=1419
2006-03-19 04:18:10 +00:00
}
Move generation of arch instruction bytecodes from on-the-fly during the initial parse stage to a new pass between parse and optimization. This should allow for more accurate generation of arch bytecodes and other future code simplifications in arch. This change necessitated changing how bytecodes are extended from the base yasm_bytecode structure; the original method did not allow for bytecodes to be reliably changed from one type to another, as reallocation of the base structure to fit the new type could result in the entire structure being relocated on the heap, and thus all the pointer references to the original bytecode being lost. After this commit, the yasm_bytecode base structure has a void pointer to any extension data. This change rippled across all bytecode-creating source files, and comprises the majority of this commit. * bc-int.h (yasm_bytecode): Add contents pointer. (yasm_bytecode_callback): Make destroy() and print() take void *contents instead of bytecode pointer. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (yasm_bc_transform): New; transforms a bytecode of any type into a different type. * bytecode.c (bytecode_data, bytecode_reserve, bytecode_incbin) (bytecode_align): Remove bc base structure. (bc_data_destroy, bc_data_print): Update to match yasm_bytecode_callback. (bc_reserve_destroy, bc_reserve_print): Likewise. (bc_incbin_destroy, bc_incbin_print): Likewise. (bc_align_destroy, bc_align_print): Likewise. (yasm_bc_create_common): Take a pointer to contents instead of datasize. (bc_data_resolve, bc_data_tobytes, yasm_bc_create_data): Update to use contents pointer. (bc_reserve_resolve, bc_reserve_tobytes, yasm_bc_create_reserve): Likewise. (bc_incbin_resolve, bc_incbin_tobytes, yasm_bc_create_incbin): Likewise. (yasm_bc_create_align): Likewise. (yasm_bc_destroy, yasm_bc_print): Update to match yasm_bytecode_callback. * section.c (yasm_object_get_general, yasm_object_create_absolute): Pass a NULL pointer instead of yasm_bytecode size to yasm_bc_create_common(). * stabs-dbgfmt.c (stabs_bc_str, stabs_bc_stab): Remove. (stabs_bc_str_destroy, stabs_bc_str_print): Update. (stabs_bc_stab_destroy, stabs_bc_stab_print): Likewise. (stabs_bc_str_callback, stabs_bc_stab_callback): Add common finalize(). (stabs_dbgfmt_append_bcstr): Update to use contents pointer. (stabs_dbgfmt_append_stab, stabs_dbgfmt_generate): Likewise. (stabs_bc_stab_tobytes, stabs_bc_str_tobytes): Likewise. * lc3barch.h (lc3b_insn): Move here from lc3bbc.c. (lc3b_new_insn_data, yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bbc.c (lc3b_insn): Remove (moved). (lc3b_bc_insn_destroy, lc3b_bc_insn_print): Update. (lc3b_bc_callback_insn): Add common finalize(). (lc3b_bc_insn_resolve, lc3b_insn_tobytes): Use contents pointer. (yasm_lc3b__bc_create_insn): Remove. (yasm_lc3b__bc_transform_insn): New. * lc3bid.re (yasm_lc3b__parse_insn): Directly create lc3b_insn. * x86arch.h (x86_insn, x86_jmp): Move here from x86bc.c (x86_new_insn_data, x86_new_jmp_data): Remove. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86bc.c (x86_insn, x86_jmp): Remove (moved). (x86_bc_insn_destroy, x86_bc_insn_print): Update. (x86_bc_jmp_destroy, x86_bc_jmp_print): Likewise. (x86_bc_callback_insn, x86_bc_callback_jmp): Add common finalize(). (x86_bc_insn_resolve, x86_insn_tobytes): Use contents pointer. (x86_bc_jmp_resolve, x86_jmp_tobytes): Likewise. (yasm_x86__bc_create_insn, yasm_x86__bc_create_jmp): Remove. (yasm_x86__bc_transform_insn, yasm_x86__bc_transform_jmp): New. * x86id.re (yasm_x86__parse_insn, x86_parse_jmp): Directly create bytecode contents. * bc-int.h (yasm_bytecode_callback): Add new finalize() that will finalize a bytecode after the parse stage. (yasm_bc_finalize_common): New; common version of bytecode callback finalize function. * bytecode.h (yasm_bc_finalize): New wrapper around callback finalize(). * bytecode.c (yasm_bc_finalize): Implementation. (yasm_bc_finalize_common): Likewise. (bc_data_callback, bc_data_reserve_callback, bc_incbin_callback) (bc_align_callback): Add yasm_bc_finalize_common() as finalize() function. * section.h (yasm_object_finalize): New; finalizes an entire object. * section.c (yasm_object_finalize): Implementation. * yasm.c (main): Call yasm_object_finalize() after parse. * bc-int.h (yasm_effaddr): Add segreg. * bytecode.h (yasm_ea_set_segreg): New function to set segreg. * bytecode.c (yasm_ea_set_segreg): Implement. * x86bc.c (yasm_x86__ea_create_reg, x86_ea_print, x86_bc_insn_resolve) (x86_bc_insn_tobytes): Use new EA segreg location. * coretype.h: Move yasm_insn_operands definition from arch.h to here, as it is now used in prototypes in bytecode.h. * bytecode.c (bytecode_insn): New instruction bytecode. (bc_insn_destroy, bc_insn_print, bc_insn_finalize, bc_insn_resolve) (bc_insn_tobytes): New callback support functions. (bc_insn_callback): New. (yasm_bc_create_insn, yasm_bc_insn_add_prefix, yasm_bc_insn_add_seg_prefix): New parser-callable functions. * bytecode.h (yasm_bc_create_insn, yasm_bc_insn_add_prefix) (yasm_bc_insn_add_seg_prefix): Likewise. * nasm-bison.y: Call new insn bytecode functions rather than arch functions. * arch.h (YASM_ARCH_VERSION): Bump version. (yasm_arch): Rename and extend parse_insn to finalize_insn. Remove parse_prefix, parse_seg_prefix, and parse_seg_override. (yasm_arch_parse_insn): Rename to yasm_arch_finalize_insn. (yasm_arch_parse_prefix, yasm_arch_parse_seg_prefix) (yasm_arch_parse_seg_override): Remove. * lc3barch.c (yasm_lc3b_LTX_arch): Update to match new yasm_arch. * lc3barch.h (yasm_lc3b__parse_insn): Rename to yasm_lc3b__finalize_insn. * lc3bid.re (yasm_lc3b__parse_insn): Likewise. * x86arch.c (x86_parse_prefix, x86_parse_seg_prefix) (x86_parse_seg_override): Remove. (yasm_x86_LTX_arch): Update to match new yasm_arch. * x86arch.h (yasm_x86__parse_insn): Rename to yasm_x86__finalize_insn. * x86id.re (yasm_x86__parse_insn): Likewise. (x86_new_jmp): Rename to x86_finalize_jmp. * x86arch.h (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): New. * x86bc.c (yasm_x86__bc_apply_prefixes, yasm_x86__ea_init): Likewise. svn path=/trunk/yasm/; revision=1177
2004-11-14 23:17:17 +00:00
}
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
/*@null@*/ yasm_intnum *
yasm_calc_bc_dist(yasm_bytecode *precbc1, yasm_bytecode *precbc2)
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
{
unsigned long dist2, dist1;
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
yasm_intnum *intn;
Massive cleanup of relocation and WRT handling. Closes #49 and lays the groundwork for further features and possible cleanups. Note: this commit changes the way in which relocations in the COFF/Win32/Win64 target can be forced to reference a different symbol than is being pointed to; instead of the ambiguous "trap+(trap.end-trap)" to get the reloc to point at trap.end but reference the trap symbol, after this commit "trap.end wrt trap" is the way to say this. This also reads a lot more clearly and is not ambiguous. This should really only affect people who write .pdata sections for Win64. See the objfmts/win64/tests/win64-dataref.asm testcase for an example of usage. This cleanup adds a new data structure, yasm_value, which is used for all expressions that can be potentially relocatable. This data structure splits the absolute portion of the expression away from the relative portion and any modifications to the relative portion (SEG, WRT, PC-relative, etc). A large amount of code in the new value module breaks a general expression into its absolute and relative parts (yasm_value_finalize_expr) and provides a common set of code for writing out non-relocated values (yasm_value_output_basic). All bytecode handling in both libyasm and the architecture modules was rewritten to use yasm_values when appropriate (e.g. data values, immediates, and effective addresses). The yasm_output_expr_func is now yasm_output_value_func and all users and implementors (mainly in object formats) have been updated to handle yasm_values. Simultaneously with this change, yasm_effaddr and yasm_immval full structure definitions have been moved from bc-int.h to bytecode.h. The data hiding provided by bc-int.h was relatively minimal and probably overkill. Also, great simplifications have been made to x86 effective address expression handling. svn path=/trunk/yasm/; revision=1419
2006-03-19 04:18:10 +00:00
if (precbc1->section != precbc2->section)
return NULL;
Massive cleanup of relocation and WRT handling. Closes #49 and lays the groundwork for further features and possible cleanups. Note: this commit changes the way in which relocations in the COFF/Win32/Win64 target can be forced to reference a different symbol than is being pointed to; instead of the ambiguous "trap+(trap.end-trap)" to get the reloc to point at trap.end but reference the trap symbol, after this commit "trap.end wrt trap" is the way to say this. This also reads a lot more clearly and is not ambiguous. This should really only affect people who write .pdata sections for Win64. See the objfmts/win64/tests/win64-dataref.asm testcase for an example of usage. This cleanup adds a new data structure, yasm_value, which is used for all expressions that can be potentially relocatable. This data structure splits the absolute portion of the expression away from the relative portion and any modifications to the relative portion (SEG, WRT, PC-relative, etc). A large amount of code in the new value module breaks a general expression into its absolute and relative parts (yasm_value_finalize_expr) and provides a common set of code for writing out non-relocated values (yasm_value_output_basic). All bytecode handling in both libyasm and the architecture modules was rewritten to use yasm_values when appropriate (e.g. data values, immediates, and effective addresses). The yasm_output_expr_func is now yasm_output_value_func and all users and implementors (mainly in object formats) have been updated to handle yasm_values. Simultaneously with this change, yasm_effaddr and yasm_immval full structure definitions have been moved from bc-int.h to bytecode.h. The data hiding provided by bc-int.h was relatively minimal and probably overkill. Also, great simplifications have been made to x86 effective address expression handling. svn path=/trunk/yasm/; revision=1419
2006-03-19 04:18:10 +00:00
dist1 = yasm_bc_next_offset(precbc1);
dist2 = yasm_bc_next_offset(precbc2);
if (dist2 < dist1) {
intn = yasm_intnum_create_uint(dist1 - dist2);
yasm_intnum_calc(intn, YASM_EXPR_NEG, NULL);
return intn;
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
}
dist2 -= dist1;
return yasm_intnum_create_uint(dist2);
}
unsigned long
yasm_bc_next_offset(yasm_bytecode *precbc)
{
return precbc->offset + precbc->len*precbc->mult_int;
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
}
Add core TASM syntax support. Contributed by: Samuel Thibault <samuel.thibault@ens-lyon.org> It is built on top of the NASM parser and preproc, with the following notable extensions for TASM syntax: - case insensitive symbols and filenames, - support for segment and size of labels, which permits to avoid giving them on each memory dereference, - support for data reservation (i.e. e.g. "var dd ?"), - support for multiples (i.e. e.g. "var dd 1 dup 10"), - little endian string integer constants, - additional expression operators: shl, shr, and, or, low, high, - additional offset keyword, - additional fword and df, - support for doubled quotes within quotes, - support for array-like and structure-like notations: t[eax] and [var].field, - support for tasm directives: macro, rept, irp, locals, proc, struc, segment, assume. Notes: - Almost all extensions are only effective when tasm_compatible_mode is set, so we should have very reduced possible breakage. - Because the "and" keyword can be an expression operator and an instruction name, the data pseudo-instructions explicitly switch the lexer state to INSTRUCTION state to fix the ambiguity. - In gen_x86_insn.py, several instructions (namely lds and lea) now take relaxed memory sizes. The reason is that in the case of tasm, the size of the actual pointed data is passed up to there, and thus any type of data should be accepted. With all of this, loadlin can be compiled by yasm with quite reduced modifications. A new TASM-like frontend is also included. svn path=/trunk/yasm/; revision=2130
2008-10-07 05:38:11 +00:00
int
yasm_bc_elem_size(yasm_bytecode *bc)
{
if (!bc->callback) {
yasm_internal_error(N_("got empty bytecode in yasm_bc_elem_size"));
return 0;
} else if (!bc->callback->elem_size)
return 0;
else
return bc->callback->elem_size(bc);
}
int
yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
void *add_span_data)
{
int retval = 0;
bc->len = 0;
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
if (!bc->callback)
yasm_internal_error(N_("got empty bytecode in yasm_bc_calc_len"));
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
else
retval = bc->callback->calc_len(bc, add_span, add_span_data);
/* Check for multiples */
bc->mult_int = 1;
if (bc->multiple) {
/*@dependent@*/ /*@null@*/ const yasm_intnum *num;
num = yasm_expr_get_intnum(&bc->multiple, 0);
if (num) {
if (yasm_intnum_sign(num) < 0) {
yasm_error_set(YASM_ERROR_VALUE, N_("multiple is negative"));
retval = -1;
} else
bc->mult_int = yasm_intnum_get_int(num);
} else {
if (yasm_expr__contains(bc->multiple, YASM_EXPR_FLOAT)) {
yasm_error_set(YASM_ERROR_VALUE,
N_("expression must not contain floating point value"));
retval = -1;
} else {
yasm_value value;
yasm_value_initialize(&value, bc->multiple, 0);
add_span(add_span_data, bc, 0, &value, 0, 0);
bc->mult_int = 0; /* assume 0 to start */
}
}
}
/* If we got an error somewhere along the line, clear out any calc len */
if (retval < 0)
bc->len = 0;
return retval;
}
int
yasm_bc_expand(yasm_bytecode *bc, int span, long old_val, long new_val,
/*@out@*/ long *neg_thres, /*@out@*/ long *pos_thres)
{
if (span == 0) {
bc->mult_int = new_val;
return 1;
}
if (!bc->callback) {
yasm_internal_error(N_("got empty bytecode in yasm_bc_expand"));
/*@unreached@*/
return -1;
} else
return bc->callback->expand(bc, span, old_val, new_val, neg_thres,
pos_thres);
}
/*@null@*/ /*@only@*/ unsigned char *
yasm_bc_tobytes(yasm_bytecode *bc, unsigned char *buf, unsigned long *bufsize,
/*@out@*/ int *gap, void *d,
yasm_output_value_func output_value,
/*@null@*/ yasm_output_reloc_func output_reloc)
/*@sets *buf@*/
{
/*@only@*/ /*@null@*/ unsigned char *mybuf = NULL;
unsigned char *bufstart;
unsigned char *origbuf, *destbuf;
long i;
int error = 0;
long mult;
if (yasm_bc_get_multiple(bc, &mult, 1) || mult == 0) {
*bufsize = 0;
return NULL;
}
bc->mult_int = mult;
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
/* special case for reserve bytecodes */
if (bc->callback->special == YASM_BC_SPECIAL_RESERVE) {
*bufsize = bc->len*bc->mult_int;
*gap = 1;
return NULL; /* we didn't allocate a buffer */
}
*gap = 0;
if (*bufsize < bc->len*bc->mult_int) {
mybuf = yasm_xmalloc(bc->len*bc->mult_int);
destbuf = mybuf;
} else
destbuf = buf;
bufstart = destbuf;
*bufsize = bc->len*bc->mult_int;
Massive libyasm / module interface update - Phase 1 As yasm has evolved, various minor additions have been made to libyasm to support the new features. These minor additions have accumulated, and some contain significant redundancies. In addition, the core focus of yasm has begun to move away from the front-end commandline program "yasm" to focusing on libyasm, a collection of reusable routines for use in all sorts of programs dealing with code at the assembly level, and the modules that provide specific features for parsing such code. This libyasm/module update focuses on cleaning up much of the cruft that has accumulated in libyasm, standardizing function names, eliminating redundancies, making many of the core objects more reusable for future extensions, and starting to make libyasm and the modules thread-safe by eliminating static variables. Specific changes include: - Making a symbol table data structure (no longer global). It follows a factory model for creating symrecs. - Label symbols now refer only to bytecodes; bytecodes have a pointer to their containing section. - Standardizing on *_create() and *_destroy() for allocation/deallocation. - Adding a standardized callback mechanism for all data structures that allow associated data. Allowed the removal of objfmt and dbgfmt-specific data callbacks in their interfaces. - Unmodularizing linemgr, but allowing multiple linemap instances (linemgr is now renamed linemap). - Remove references to lindex; all virtual lines (from linemap) are now just "line"s. - Eliminating the bytecode "type" enum, instead adding a standardized callback mechanism for custom (and standard internal) bytecode types. This will make it much easier to add new bytecodes, and eliminate the possibility of type collisions. This also allowed the removal of the of_data and df_data bytecodes, as objfmts and dbgfmts can now easily implement their own bytecodes, and the cleanup of arch's bytecode usage. - Remove the bytecodehead and sectionhead pseudo-containers, instead making true containers: section now implements all the functions of bytecodehead, and the new object data structure implements all the functions of sectionhead. - Add object data structure: it's a container that contains sections, a symbol table, and a line mapping for a single object. Every former use of sectionhead now takes an object. - Make arch interface and all standard architectures thread-safe: yasm_arch_module is the module interface; it contains a create() function that returns a yasm_arch * to store local yasm_arch data; all yasm_arch_module functions take the yasm_arch *. - Make nasm parser thread-safe. To be done in phase 2: making other module interfaces thread-safe. Note that while the module interface may be thread-safe, not all modules may be written in such a fashion (hopefully all the "standard" ones will be, but this is yet to be determined). svn path=/trunk/yasm/; revision=1058
2003-10-02 05:03:50 +00:00
if (!bc->callback)
yasm_internal_error(N_("got empty bytecode in bc_tobytes"));
else for (i=0; i<bc->mult_int; i++) {
origbuf = destbuf;
error = bc->callback->tobytes(bc, &destbuf, bufstart, d, output_value,
output_reloc);
if (!error && ((unsigned long)(destbuf - origbuf) != bc->len))
yasm_internal_error(
N_("written length does not match optimized length"));
}
return mybuf;
}
int
yasm_bc_get_multiple(yasm_bytecode *bc, long *multiple, int calc_bc_dist)
{
/*@dependent@*/ /*@null@*/ const yasm_intnum *num;
*multiple = 1;
if (bc->multiple) {
num = yasm_expr_get_intnum(&bc->multiple, calc_bc_dist);
if (!num) {
yasm_error_set(YASM_ERROR_VALUE,
N_("could not determine multiple"));
return 1;
}
if (yasm_intnum_sign(num) < 0) {
yasm_error_set(YASM_ERROR_VALUE, N_("multiple is negative"));
return 1;
}
*multiple = yasm_intnum_get_int(num);
}
return 0;
}
const yasm_expr *
yasm_bc_get_multiple_expr(const yasm_bytecode *bc)
{
return bc->multiple;
}
yasm_insn *
yasm_bc_get_insn(yasm_bytecode *bc)
{
if (bc->callback->special != YASM_BC_SPECIAL_INSN)
return NULL;
return (yasm_insn *)bc->contents;
}