From: Peter Johnson Date: Mon, 12 Jun 2006 05:29:22 +0000 (-0000) Subject: Add yasm_intnum_set_int(). X-Git-Tag: v0.6.0~172^2~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ebf4d268ee91952a26424e0b7362da35ecff196;p=yasm Add yasm_intnum_set_int(). svn path=/branches/new-optimizer/; revision=1573 --- diff --git a/libyasm/intnum.c b/libyasm/intnum.c index 94b8e733..8b1074be 100644 --- a/libyasm/intnum.c +++ b/libyasm/intnum.c @@ -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) { diff --git a/libyasm/intnum.h b/libyasm/intnum.h index 90535154..f6c44c6e 100644 --- a/libyasm/intnum.h +++ b/libyasm/intnum.h @@ -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.