145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \file libyasm/intnum.h 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \brief YASM integer number interface. 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \license 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2001-2007 Peter Johnson 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met: 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - Redistributions of source code must retain the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - Redistributions in binary form must reproduce the above copyright 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer in the 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * documentation and/or other materials provided with the distribution. 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \endlicense 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_INTNUM_H 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_INTNUM_H 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_LIB_DECL 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LIB_DECL 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Initialize intnum internal data structures. */ 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_initialize(void); 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Clean up internal intnum allocations. */ 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_cleanup(void); 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new intnum from a decimal string. 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str decimal string 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_dec(char *str); 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new intnum from a binary string. 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str binary string 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_bin(char *str); 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new intnum from an octal string. 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str octal string 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_oct(char *str); 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new intnum from a hexidecimal string. 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str hexidecimal string 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_hex(char *str); 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Convert character constant to integer value, using NASM rules. NASM syntax 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * supports automatic conversion from strings such as 'abcd' to a 32-bit 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * integer value (little endian order). This function performs those conversions. 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str character constant string 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_charconst_nasm(const char *str); 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Convert character constant to integer value, using TASM rules. TASM syntax 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * supports automatic conversion from strings such as 'abcd' to a 32-bit 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * integer value (big endian order). This function performs those conversions. 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str character constant string 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_charconst_tasm(const char *str); 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new intnum from an unsigned integer value. 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param i unsigned integer value 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_uint(unsigned long i); 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new intnum from an signed integer value. 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param i signed integer value 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_int(long i); 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new intnum from LEB128-encoded form. 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr pointer to start of LEB128 encoded form 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param sign signed (1) or unsigned (0) LEB128 format 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param size number of bytes read from ptr (output) 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum. Number of bytes read returned into 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * bytes_read parameter. 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_leb128 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (const unsigned char *ptr, int sign, /*@out@*/ unsigned long *size); 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new intnum from a little-endian or big-endian buffer. 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * In little endian, the LSB is in ptr[0]. 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr pointer to start of buffer 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param sign signed (1) or unsigned (0) source 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param srcsize source buffer size (in bytes) 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param bigendian endianness (nonzero=big, zero=little) 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_create_sized 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (unsigned char *ptr, int sign, size_t srcsize, int bigendian); 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Duplicate an intnum. 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated intnum with the same value as intn. 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_intnum *yasm_intnum_copy(const yasm_intnum *intn); 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Destroy (free allocated memory for) an intnum. 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_destroy(/*@only@*/ yasm_intnum *intn); 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Floating point calculation function: acc = acc op operand. 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Not all operations in yasm_expr_op may be supported; unsupported 14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * operations will result in an error. 14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param acc intnum accumulator 14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param op operation 14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param operand intnum operand 14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero if error occurred. 14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_intnum_calc(yasm_intnum *acc, yasm_expr_op op, yasm_intnum *operand); 15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Compare two intnums. 15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn1 first intnum 15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn2 second intnum 15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return -1 if intn1 < intn2, 0 if intn1 == intn2, 1 if intn1 > intn2. 15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_intnum_compare(const yasm_intnum *intn1, const yasm_intnum *intn2); 15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Zero an intnum. 16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_zero(yasm_intnum *intn); 16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Set an intnum to the value of another intnum. 16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val intnum to get value from 16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_set(yasm_intnum *intn, const yasm_intnum *val); 17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Set an intnum to an unsigned integer. 17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val integer value 17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_set_uint(yasm_intnum *intn, unsigned long val); 17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Set an intnum to an signed integer. 18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val integer value 18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_set_int(yasm_intnum *intn, long val); 18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Simple value check for 0. 18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param acc intnum 18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero if acc==0. 18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_intnum_is_zero(const yasm_intnum *acc); 19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Simple value check for 1. 19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param acc intnum 19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero if acc==1. 19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_intnum_is_pos1(const yasm_intnum *acc); 19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Simple value check for -1. 20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param acc intnum 20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero if acc==-1. 20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_intnum_is_neg1(const yasm_intnum *acc); 20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Simple sign check. 20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param acc intnum 20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return -1 if negative, 0 if zero, +1 if positive 21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_intnum_sign(const yasm_intnum *acc); 21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Convert an intnum to an unsigned 32-bit value. The value is in "standard" 21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * C format (eg, of unknown endian). 21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Parameter intnum is truncated to fit into 32 bits. Use 21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * intnum_check_size() to check for overflow. 21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Unsigned 32-bit value of intn. 22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_intnum_get_uint(const yasm_intnum *intn); 22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Convert an intnum to a signed 32-bit value. The value is in "standard" C 22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * format (eg, of unknown endian). 22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Parameter intnum is truncated to fit into 32 bits. Use 22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * intnum_check_size() to check for overflow. 22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Signed 32-bit value of intn. 23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orglong yasm_intnum_get_int(const yasm_intnum *intn); 23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Output #yasm_intnum to buffer in little-endian or big-endian. Puts the 23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * value into the least significant bits of the destination, or may be shifted 23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * into more significant bits by the shift parameter. The destination bits are 23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * cleared before being set. [0] should be the first byte output to the file. 23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr pointer to storage for size bytes of output 24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param destsize destination size (in bytes) 24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param valsize size (in bits) 24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param shift left shift (in bits); may be negative to specify right 24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * shift (standard warnings include truncation to boundary) 24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param bigendian endianness (nonzero=big, zero=little) 24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param warn enables standard warnings (value doesn't fit into valsize 24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * bits): <0=signed warnings, >0=unsigned warnings, 0=no warn 24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 24945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_get_sized(const yasm_intnum *intn, unsigned char *ptr, 25045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t destsize, size_t valsize, int shift, 25145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int bigendian, int warn); 25245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 25345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Check to see if intnum will fit without overflow into size bits. 25445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 25545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param size number of bits of output space 25645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param rshift right shift 25745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param rangetype signed/unsigned range selection: 25845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 0 => (0, unsigned max); 25945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1 => (signed min, signed max); 26045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 2 => (signed min, unsigned max) 26145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero if intnum will fit. 26245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 26345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 26445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_intnum_check_size(const yasm_intnum *intn, size_t size, 26545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t rshift, int rangetype); 26645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 26745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Check to see if intnum will fit into a particular numeric range. 26845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 26945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param low low end of range (inclusive) 27045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param high high end of range (inclusive) 27145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero if intnum is within range. 27245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 27345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 27445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_intnum_in_range(const yasm_intnum *intn, long low, long high); 27545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 27645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Output #yasm_intnum to buffer in LEB128-encoded form. 27745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 27845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr pointer to storage for output bytes 27945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param sign signedness of LEB128 encoding (0=unsigned, 1=signed) 28045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Number of bytes generated. 28145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 28245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 28345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_intnum_get_leb128(const yasm_intnum *intn, 28445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned char *ptr, int sign); 28545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 28645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Calculate number of bytes LEB128-encoded form of #yasm_intnum will take. 28745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 28845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param sign signedness of LEB128 encoding (0=unsigned, 1=signed) 28945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Number of bytes. 29045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 29145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 29245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_intnum_size_leb128(const yasm_intnum *intn, int sign); 29345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 29445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Output integer to buffer in signed LEB128-encoded form. 29545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param v integer 29645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr pointer to storage for output bytes 29745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Number of bytes generated. 29845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 29945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 30045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_get_sleb128(long v, unsigned char *ptr); 30145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 30245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Calculate number of bytes signed LEB128-encoded form of integer will take. 30345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param v integer 30445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Number of bytes. 30545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 30645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 30745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_size_sleb128(long v); 30845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 30945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Output integer to buffer in unsigned LEB128-encoded form. 31045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param v integer 31145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr pointer to storage for output bytes 31245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Number of bytes generated. 31345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 31445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 31545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_get_uleb128(unsigned long v, unsigned char *ptr); 31645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 31745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Calculate number of bytes unsigned LEB128-encoded form of integer will take. 31845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param v integer 31945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Number of bytes. 32045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 32145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 32245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_size_uleb128(unsigned long v); 32345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 32445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get an intnum as a signed decimal string. The returned string will 32545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * contain a leading '-' if the intnum is negative. 32645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 32745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated string containing the decimal representation of 32845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * the intnum. 32945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 33045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 33145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ char *yasm_intnum_get_str(const yasm_intnum *intn); 33245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 33345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Print an intnum. For debugging purposes. 33445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f file 33545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn intnum 33645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 33745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 33845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_intnum_print(const yasm_intnum *intn, FILE *f); 33945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 34045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 341