]> granicus.if.org Git - yasm/commitdiff
Allocate single static temporary bitvect for conversions (as most conversions
authorPeter Johnson <peter@tortall.net>
Wed, 9 Jan 2002 03:26:05 +0000 (03:26 -0000)
committerPeter Johnson <peter@tortall.net>
Wed, 9 Jan 2002 03:26:05 +0000 (03:26 -0000)
will be <=32 bits in size).

svn path=/trunk/yasm/; revision=434

frontends/yasm/yasm.c
libyasm/intnum.c
libyasm/intnum.h
src/intnum.c
src/intnum.h
src/main.c

index 52ea1691190cf049d5b215e724aceb76959024c1..783d46005ed50247a03ca8d7e33b89df1ce31978 100644 (file)
@@ -28,6 +28,7 @@
 #include "globals.h"
 #include "options.h"
 #include "errwarn.h"
+#include "intnum.h"
 #include "floatnum.h"
 #include "symrec.h"
 
@@ -182,6 +183,7 @@ main(int argc, char *argv[])
        symrec_delete_all();
        line_shutdown();
        floatnum_shutdown();
+       intnum_shutdown();
        BitVector_Shutdown();
        return EXIT_FAILURE;
     }
@@ -219,6 +221,7 @@ main(int argc, char *argv[])
     line_shutdown();
 
     floatnum_shutdown();
+    intnum_shutdown();
 
     BitVector_Shutdown();
     return EXIT_SUCCESS;
index 75c747035844d606b871d4edffeefc0cdab90f14..ba99f4794502310fe21647bd523b880a6cdf18fd 100644 (file)
@@ -42,24 +42,35 @@ struct intnum {
     unsigned char origsize;    /* original (parsed) size, in bits */
 };
 
+/* static bitvect used for conversions */
+static /*@only@*/ /*@null@*/ wordptr conv_bv = NULL;
+
+void
+intnum_shutdown(void)
+{
+    if (conv_bv) {
+       BitVector_Destroy(conv_bv);
+       conv_bv = NULL;
+    }
+}
+
 intnum *
 intnum_new_dec(char *str)
 {
     intnum *intn = xmalloc(sizeof(intnum));
-    wordptr bv;
 
     intn->origsize = 0;            /* no reliable way to figure this out */
 
-    bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
-    if (BitVector_from_Dec(bv, (unsigned char *)str) == ErrCode_Ovfl)
+    if (!conv_bv)
+       conv_bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
+    if (BitVector_from_Dec(conv_bv, (unsigned char *)str) == ErrCode_Ovfl)
        Warning(_("Numeric constant too large for internal format"));
-    if (Set_Max(bv) < 32) {
+    if (Set_Max(conv_bv) < 32) {
        intn->type = INTNUM_UL;
-       intn->val.ul = BitVector_Chunk_Read(bv, 32, 0);
-       BitVector_Destroy(bv);
+       intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
     } else {
        intn->type = INTNUM_BV;
-       intn->val.bv = bv;
+       intn->val.bv = BitVector_Clone(conv_bv);
     }
 
     return intn;
@@ -69,22 +80,21 @@ intnum *
 intnum_new_bin(char *str)
 {
     intnum *intn = xmalloc(sizeof(intnum));
-    wordptr bv;
 
     intn->origsize = (unsigned char)strlen(str);
 
     if(intn->origsize > BITVECT_ALLOC_SIZE)
        Warning(_("Numeric constant too large for internal format"));
 
-    bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
-    BitVector_from_Bin(bv, (unsigned char *)str);
-    if (Set_Max(bv) < 32) {
+    if (!conv_bv)
+       conv_bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
+    BitVector_from_Bin(conv_bv, (unsigned char *)str);
+    if (Set_Max(conv_bv) < 32) {
        intn->type = INTNUM_UL;
-       intn->val.ul = BitVector_Chunk_Read(bv, 32, 0);
-       BitVector_Destroy(bv);
+       intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
     } else {
        intn->type = INTNUM_BV;
-       intn->val.bv = bv;
+       intn->val.bv = BitVector_Clone(conv_bv);
     }
 
     return intn;
@@ -94,22 +104,21 @@ intnum *
 intnum_new_oct(char *str)
 {
     intnum *intn = xmalloc(sizeof(intnum));
-    wordptr bv;
 
     intn->origsize = strlen(str)*3;
 
     if(intn->origsize > BITVECT_ALLOC_SIZE)
        Warning(_("Numeric constant too large for internal format"));
 
-    bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
-    BitVector_from_Oct(bv, (unsigned char *)str);
-    if (Set_Max(bv) < 32) {
+    if (!conv_bv)
+       conv_bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
+    BitVector_from_Oct(conv_bv, (unsigned char *)str);
+    if (Set_Max(conv_bv) < 32) {
        intn->type = INTNUM_UL;
-       intn->val.ul = BitVector_Chunk_Read(bv, 32, 0);
-       BitVector_Destroy(bv);
+       intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
     } else {
        intn->type = INTNUM_BV;
-       intn->val.bv = bv;
+       intn->val.bv = BitVector_Clone(conv_bv);
     }
 
     return intn;
@@ -119,22 +128,21 @@ intnum *
 intnum_new_hex(char *str)
 {
     intnum *intn = xmalloc(sizeof(intnum));
-    wordptr bv;
 
     intn->origsize = strlen(str)*4;
 
     if(intn->origsize > BITVECT_ALLOC_SIZE)
        Warning(_("Numeric constant too large for internal format"));
 
-    bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
-    BitVector_from_Hex(bv, (unsigned char *)str);
-    if (Set_Max(bv) < 32) {
+    if (!conv_bv)
+       conv_bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
+    BitVector_from_Hex(conv_bv, (unsigned char *)str);
+    if (Set_Max(conv_bv) < 32) {
        intn->type = INTNUM_UL;
-       intn->val.ul = BitVector_Chunk_Read(bv, 32, 0);
-       BitVector_Destroy(bv);
+       intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
     } else {
        intn->type = INTNUM_BV;
-       intn->val.bv = bv;
+       intn->val.bv = BitVector_Clone(conv_bv);
     }
 
     return intn;
index 4c00e4543247a378309dfbae827b52953a469044..5ebb4747eb61a13a381c00ea8c16cc3c3e265833 100644 (file)
@@ -22,6 +22,9 @@
 #ifndef YASM_INTNUM_H
 #define YASM_INTNUM_H
 
+/* Clean up internal allocations */
+void intnum_shutdown(void);
+
 /*@only@*/ intnum *intnum_new_dec(char *str);
 /*@only@*/ intnum *intnum_new_bin(char *str);
 /*@only@*/ intnum *intnum_new_oct(char *str);
index 75c747035844d606b871d4edffeefc0cdab90f14..ba99f4794502310fe21647bd523b880a6cdf18fd 100644 (file)
@@ -42,24 +42,35 @@ struct intnum {
     unsigned char origsize;    /* original (parsed) size, in bits */
 };
 
+/* static bitvect used for conversions */
+static /*@only@*/ /*@null@*/ wordptr conv_bv = NULL;
+
+void
+intnum_shutdown(void)
+{
+    if (conv_bv) {
+       BitVector_Destroy(conv_bv);
+       conv_bv = NULL;
+    }
+}
+
 intnum *
 intnum_new_dec(char *str)
 {
     intnum *intn = xmalloc(sizeof(intnum));
-    wordptr bv;
 
     intn->origsize = 0;            /* no reliable way to figure this out */
 
-    bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
-    if (BitVector_from_Dec(bv, (unsigned char *)str) == ErrCode_Ovfl)
+    if (!conv_bv)
+       conv_bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
+    if (BitVector_from_Dec(conv_bv, (unsigned char *)str) == ErrCode_Ovfl)
        Warning(_("Numeric constant too large for internal format"));
-    if (Set_Max(bv) < 32) {
+    if (Set_Max(conv_bv) < 32) {
        intn->type = INTNUM_UL;
-       intn->val.ul = BitVector_Chunk_Read(bv, 32, 0);
-       BitVector_Destroy(bv);
+       intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
     } else {
        intn->type = INTNUM_BV;
-       intn->val.bv = bv;
+       intn->val.bv = BitVector_Clone(conv_bv);
     }
 
     return intn;
@@ -69,22 +80,21 @@ intnum *
 intnum_new_bin(char *str)
 {
     intnum *intn = xmalloc(sizeof(intnum));
-    wordptr bv;
 
     intn->origsize = (unsigned char)strlen(str);
 
     if(intn->origsize > BITVECT_ALLOC_SIZE)
        Warning(_("Numeric constant too large for internal format"));
 
-    bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
-    BitVector_from_Bin(bv, (unsigned char *)str);
-    if (Set_Max(bv) < 32) {
+    if (!conv_bv)
+       conv_bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
+    BitVector_from_Bin(conv_bv, (unsigned char *)str);
+    if (Set_Max(conv_bv) < 32) {
        intn->type = INTNUM_UL;
-       intn->val.ul = BitVector_Chunk_Read(bv, 32, 0);
-       BitVector_Destroy(bv);
+       intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
     } else {
        intn->type = INTNUM_BV;
-       intn->val.bv = bv;
+       intn->val.bv = BitVector_Clone(conv_bv);
     }
 
     return intn;
@@ -94,22 +104,21 @@ intnum *
 intnum_new_oct(char *str)
 {
     intnum *intn = xmalloc(sizeof(intnum));
-    wordptr bv;
 
     intn->origsize = strlen(str)*3;
 
     if(intn->origsize > BITVECT_ALLOC_SIZE)
        Warning(_("Numeric constant too large for internal format"));
 
-    bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
-    BitVector_from_Oct(bv, (unsigned char *)str);
-    if (Set_Max(bv) < 32) {
+    if (!conv_bv)
+       conv_bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
+    BitVector_from_Oct(conv_bv, (unsigned char *)str);
+    if (Set_Max(conv_bv) < 32) {
        intn->type = INTNUM_UL;
-       intn->val.ul = BitVector_Chunk_Read(bv, 32, 0);
-       BitVector_Destroy(bv);
+       intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
     } else {
        intn->type = INTNUM_BV;
-       intn->val.bv = bv;
+       intn->val.bv = BitVector_Clone(conv_bv);
     }
 
     return intn;
@@ -119,22 +128,21 @@ intnum *
 intnum_new_hex(char *str)
 {
     intnum *intn = xmalloc(sizeof(intnum));
-    wordptr bv;
 
     intn->origsize = strlen(str)*4;
 
     if(intn->origsize > BITVECT_ALLOC_SIZE)
        Warning(_("Numeric constant too large for internal format"));
 
-    bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
-    BitVector_from_Hex(bv, (unsigned char *)str);
-    if (Set_Max(bv) < 32) {
+    if (!conv_bv)
+       conv_bv = BitVector_Create(BITVECT_ALLOC_SIZE, FALSE);
+    BitVector_from_Hex(conv_bv, (unsigned char *)str);
+    if (Set_Max(conv_bv) < 32) {
        intn->type = INTNUM_UL;
-       intn->val.ul = BitVector_Chunk_Read(bv, 32, 0);
-       BitVector_Destroy(bv);
+       intn->val.ul = BitVector_Chunk_Read(conv_bv, 32, 0);
     } else {
        intn->type = INTNUM_BV;
-       intn->val.bv = bv;
+       intn->val.bv = BitVector_Clone(conv_bv);
     }
 
     return intn;
index 4c00e4543247a378309dfbae827b52953a469044..5ebb4747eb61a13a381c00ea8c16cc3c3e265833 100644 (file)
@@ -22,6 +22,9 @@
 #ifndef YASM_INTNUM_H
 #define YASM_INTNUM_H
 
+/* Clean up internal allocations */
+void intnum_shutdown(void);
+
 /*@only@*/ intnum *intnum_new_dec(char *str);
 /*@only@*/ intnum *intnum_new_bin(char *str);
 /*@only@*/ intnum *intnum_new_oct(char *str);
index 52ea1691190cf049d5b215e724aceb76959024c1..783d46005ed50247a03ca8d7e33b89df1ce31978 100644 (file)
@@ -28,6 +28,7 @@
 #include "globals.h"
 #include "options.h"
 #include "errwarn.h"
+#include "intnum.h"
 #include "floatnum.h"
 #include "symrec.h"
 
@@ -182,6 +183,7 @@ main(int argc, char *argv[])
        symrec_delete_all();
        line_shutdown();
        floatnum_shutdown();
+       intnum_shutdown();
        BitVector_Shutdown();
        return EXIT_FAILURE;
     }
@@ -219,6 +221,7 @@ main(int argc, char *argv[])
     line_shutdown();
 
     floatnum_shutdown();
+    intnum_shutdown();
 
     BitVector_Shutdown();
     return EXIT_SUCCESS;