]> granicus.if.org Git - yasm/commitdiff
Add yasm_intnum_set_int().
authorPeter Johnson <peter@tortall.net>
Mon, 12 Jun 2006 05:29:22 +0000 (05:29 -0000)
committerPeter Johnson <peter@tortall.net>
Mon, 12 Jun 2006 05:29:22 +0000 (05:29 -0000)
svn path=/branches/new-optimizer/; revision=1573

libyasm/intnum.c
libyasm/intnum.h

index 94b8e733ca89479cbaec146719cba5251a6ecde1..8b1074be07e85eb995cfc420885219f22a2e78ac 100644 (file)
@@ -594,6 +594,27 @@ yasm_intnum_set_uint(yasm_intnum *intn, unsigned long val)
     intn->val.ul = val;
 }
 
+void
+yasm_intnum_set_int(yasm_intnum *intn, long val)
+{
+    /* positive numbers can go through the uint() function */
+    if (i >= 0) {
+       yasm_intnum_set_uint(intn, (unsigned long)i);
+       return;
+    }
+
+    BitVector_Empty(conv_bv);
+    BitVector_Chunk_Store(conv_bv, 32, 0, (unsigned long)(-i));
+    BitVector_Negate(conv_bv, conv_bv);
+
+    if (intn->type == INTNUM_BV)
+       BitVector_Copy(intn->val.bv, conv_bv);
+    else {
+       intn->val.bv = BitVector_Clone(conv_bv);
+       intn->type = INTNUM_BV;
+    }
+}
+
 int
 yasm_intnum_is_zero(const yasm_intnum *intn)
 {
index 90535154eafe984bccee16ff3f79b1832f9df5f5..f6c44c6ece82dbc0c66609c29da0e31c9c08e115 100644 (file)
@@ -136,6 +136,12 @@ void yasm_intnum_zero(yasm_intnum *intn);
  */
 void yasm_intnum_set_uint(yasm_intnum *intn, unsigned long val);
 
+/** Set an intnum to an signed integer.
+ * \param intn     intnum
+ * \param val      integer value
+ */
+void yasm_intnum_set_int(yasm_intnum *intn, long val);
+
 /** Simple value check for 0.
  * \param acc      intnum
  * \return Nonzero if acc==0.