summaryrefslogtreecommitdiff
path: root/libyasm/bitvect.c
diff options
context:
space:
mode:
authorPeter Johnson <peter@tortall.net>2003-10-02 05:03:50 +0000
committerPeter Johnson <peter@tortall.net>2003-10-02 05:03:50 +0000
commit55438b722983d01811f5edf1ecfc86df3d2dd31c (patch)
treee944694581a253d32d593b69f0bdabde8be02dbc /libyasm/bitvect.c
parent18b2af8355f76ea9fb1c883488d4ca8046766453 (diff)
downloadyasm-55438b722983d01811f5edf1ecfc86df3d2dd31c.tar.gz
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
Diffstat (limited to 'libyasm/bitvect.c')
-rw-r--r--libyasm/bitvect.c106
1 files changed, 46 insertions, 60 deletions
diff --git a/libyasm/bitvect.c b/libyasm/bitvect.c
index fa8f700e..751a449a 100644
--- a/libyasm/bitvect.c
+++ b/libyasm/bitvect.c
@@ -1721,71 +1721,51 @@ charptr BitVector_to_Dec(wordptr addr)
return(result);
}
-static wordptr from_Dec_term = NULL;
-static wordptr from_Dec_base = NULL;
-static wordptr from_Dec_prod = NULL;
-static wordptr from_Dec_rank = NULL;
-static wordptr from_Dec_temp = NULL;
+struct BitVector_from_Dec_static_data {
+ wordptr term;
+ wordptr base;
+ wordptr prod;
+ wordptr rank;
+ wordptr temp;
+};
-ErrCode BitVector_from_Dec_static_Boot(N_word bits)
+BitVector_from_Dec_static_data *BitVector_from_Dec_static_Boot(N_word bits)
{
+ BitVector_from_Dec_static_data *data;
+
+ data = yasm_xmalloc(sizeof(BitVector_from_Dec_static_data));
+
if (bits > 0)
{
- BitVector_from_Dec_static_Shutdown();
- from_Dec_term = BitVector_Create(BITS,FALSE);
- if (from_Dec_term == NULL)
- {
- return(ErrCode_Null);
- }
- from_Dec_base = BitVector_Create(BITS,FALSE);
- if (from_Dec_base == NULL)
- {
- BitVector_Destroy(from_Dec_term);
- return(ErrCode_Null);
- }
- from_Dec_prod = BitVector_Create(bits,FALSE);
- if (from_Dec_prod == NULL)
- {
- BitVector_Destroy(from_Dec_term);
- BitVector_Destroy(from_Dec_base);
- return(ErrCode_Null);
- }
- from_Dec_rank = BitVector_Create(bits,FALSE);
- if (from_Dec_rank == NULL)
- {
- BitVector_Destroy(from_Dec_term);
- BitVector_Destroy(from_Dec_base);
- BitVector_Destroy(from_Dec_prod);
- return(ErrCode_Null);
- }
- from_Dec_temp = BitVector_Create(bits,FALSE);
- if (from_Dec_temp == NULL)
- {
- BitVector_Destroy(from_Dec_term);
- BitVector_Destroy(from_Dec_base);
- BitVector_Destroy(from_Dec_prod);
- BitVector_Destroy(from_Dec_rank);
- return(ErrCode_Null);
- }
+ data->term = BitVector_Create(BITS,FALSE);
+ data->base = BitVector_Create(BITS,FALSE);
+ data->prod = BitVector_Create(bits,FALSE);
+ data->rank = BitVector_Create(bits,FALSE);
+ data->temp = BitVector_Create(bits,FALSE);
+ } else {
+ data->term = NULL;
+ data->base = NULL;
+ data->prod = NULL;
+ data->rank = NULL;
+ data->temp = NULL;
}
- return(ErrCode_Ok);
+ return data;
}
-void BitVector_from_Dec_static_Shutdown(void)
+void BitVector_from_Dec_static_Shutdown(BitVector_from_Dec_static_data *data)
{
- if (from_Dec_term != NULL)
- BitVector_Destroy(from_Dec_term);
- if (from_Dec_base != NULL)
- BitVector_Destroy(from_Dec_base);
- if (from_Dec_prod != NULL)
- BitVector_Destroy(from_Dec_prod);
- if (from_Dec_rank != NULL)
- BitVector_Destroy(from_Dec_rank);
- if (from_Dec_temp != NULL)
- BitVector_Destroy(from_Dec_temp);
+ if (data) {
+ BitVector_Destroy(data->term);
+ BitVector_Destroy(data->base);
+ BitVector_Destroy(data->prod);
+ BitVector_Destroy(data->rank);
+ BitVector_Destroy(data->temp);
+ }
+ yasm_xfree(data);
}
-ErrCode BitVector_from_Dec_static(wordptr addr, charptr string)
+ErrCode BitVector_from_Dec_static(BitVector_from_Dec_static_data *data,
+ wordptr addr, charptr string)
{
ErrCode error = ErrCode_Ok;
N_word bits = bits_(addr);
@@ -1794,11 +1774,11 @@ ErrCode BitVector_from_Dec_static(wordptr addr, charptr string)
boolean minus;
boolean shift;
boolean carry;
- wordptr term = from_Dec_term;
- wordptr base = from_Dec_base;
- wordptr prod = from_Dec_prod;
- wordptr rank = from_Dec_rank;
- wordptr temp = from_Dec_temp;
+ wordptr term;
+ wordptr base;
+ wordptr prod;
+ wordptr rank;
+ wordptr temp;
N_word accu;
N_word powr;
N_word count;
@@ -1807,6 +1787,12 @@ ErrCode BitVector_from_Dec_static(wordptr addr, charptr string)
if (bits > 0)
{
+ term = data->term;
+ base = data->base;
+ prod = data->prod;
+ rank = data->rank;
+ temp = data->temp;
+
length = strlen((char *) string);
if (length == 0) return(ErrCode_Pars);
digit = (int) *string;