From 7ebf4d268ee91952a26424e0b7362da35ecff196 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 12 Jun 2006 05:29:22 +0000 Subject: [PATCH] Add yasm_intnum_set_int(). svn path=/branches/new-optimizer/; revision=1573 --- libyasm/intnum.c | 21 +++++++++++++++++++++ libyasm/intnum.h | 6 ++++++ 2 files changed, 27 insertions(+) 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. -- 2.40.0