libyasm
Macros | Functions
intnum.h File Reference

YASM integer number interface. More...

Go to the source code of this file.

Functions

YASM_LIB_DECL void yasm_intnum_initialize (void)
 Initialize intnum internal data structures. More...
 
YASM_LIB_DECL void yasm_intnum_cleanup (void)
 Clean up internal intnum allocations. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_dec (char *str)
 Create a new intnum from a decimal string. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_bin (char *str)
 Create a new intnum from a binary string. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_oct (char *str)
 Create a new intnum from an octal string. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_hex (char *str)
 Create a new intnum from a hexidecimal string. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_charconst_nasm (const char *str)
 Convert character constant to integer value, using NASM rules. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_charconst_tasm (const char *str)
 Convert character constant to integer value, using TASM rules. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_uint (unsigned long i)
 Create a new intnum from an unsigned integer value. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_int (long i)
 Create a new intnum from an signed integer value. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_leb128 (const unsigned char *ptr, int sign, unsigned long *size)
 Create a new intnum from LEB128-encoded form. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_create_sized (unsigned char *ptr, int sign, size_t srcsize, int bigendian)
 Create a new intnum from a little-endian or big-endian buffer. More...
 
YASM_LIB_DECL yasm_intnumyasm_intnum_copy (const yasm_intnum *intn)
 Duplicate an intnum. More...
 
YASM_LIB_DECL void yasm_intnum_destroy (yasm_intnum *intn)
 Destroy (free allocated memory for) an intnum. More...
 
YASM_LIB_DECL int yasm_intnum_calc (yasm_intnum *acc, yasm_expr_op op, yasm_intnum *operand)
 Floating point calculation function: acc = acc op operand. More...
 
YASM_LIB_DECL int yasm_intnum_compare (const yasm_intnum *intn1, const yasm_intnum *intn2)
 Compare two intnums. More...
 
YASM_LIB_DECL void yasm_intnum_zero (yasm_intnum *intn)
 Zero an intnum. More...
 
YASM_LIB_DECL void yasm_intnum_set (yasm_intnum *intn, const yasm_intnum *val)
 Set an intnum to the value of another intnum. More...
 
YASM_LIB_DECL void yasm_intnum_set_uint (yasm_intnum *intn, unsigned long val)
 Set an intnum to an unsigned integer. More...
 
YASM_LIB_DECL void yasm_intnum_set_int (yasm_intnum *intn, long val)
 Set an intnum to an signed integer. More...
 
YASM_LIB_DECL int yasm_intnum_is_zero (const yasm_intnum *acc)
 Simple value check for 0. More...
 
YASM_LIB_DECL int yasm_intnum_is_pos1 (const yasm_intnum *acc)
 Simple value check for 1. More...
 
YASM_LIB_DECL int yasm_intnum_is_neg1 (const yasm_intnum *acc)
 Simple value check for -1. More...
 
YASM_LIB_DECL int yasm_intnum_sign (const yasm_intnum *acc)
 Simple sign check. More...
 
YASM_LIB_DECL unsigned long yasm_intnum_get_uint (const yasm_intnum *intn)
 Convert an intnum to an unsigned 32-bit value. More...
 
YASM_LIB_DECL long yasm_intnum_get_int (const yasm_intnum *intn)
 Convert an intnum to a signed 32-bit value. More...
 
YASM_LIB_DECL void yasm_intnum_get_sized (const yasm_intnum *intn, unsigned char *ptr, size_t destsize, size_t valsize, int shift, int bigendian, int warn)
 Output yasm_intnum to buffer in little-endian or big-endian. More...
 
YASM_LIB_DECL int yasm_intnum_check_size (const yasm_intnum *intn, size_t size, size_t rshift, int rangetype)
 Check to see if intnum will fit without overflow into size bits. More...
 
YASM_LIB_DECL int yasm_intnum_in_range (const yasm_intnum *intn, long low, long high)
 Check to see if intnum will fit into a particular numeric range. More...
 
YASM_LIB_DECL unsigned long yasm_intnum_get_leb128 (const yasm_intnum *intn, unsigned char *ptr, int sign)
 Output yasm_intnum to buffer in LEB128-encoded form. More...
 
YASM_LIB_DECL unsigned long yasm_intnum_size_leb128 (const yasm_intnum *intn, int sign)
 Calculate number of bytes LEB128-encoded form of yasm_intnum will take. More...
 
YASM_LIB_DECL unsigned long yasm_get_sleb128 (long v, unsigned char *ptr)
 Output integer to buffer in signed LEB128-encoded form. More...
 
YASM_LIB_DECL unsigned long yasm_size_sleb128 (long v)
 Calculate number of bytes signed LEB128-encoded form of integer will take. More...
 
YASM_LIB_DECL unsigned long yasm_get_uleb128 (unsigned long v, unsigned char *ptr)
 Output integer to buffer in unsigned LEB128-encoded form. More...
 
YASM_LIB_DECL unsigned long yasm_size_uleb128 (unsigned long v)
 Calculate number of bytes unsigned LEB128-encoded form of integer will take. More...
 
YASM_LIB_DECL char * yasm_intnum_get_str (const yasm_intnum *intn)
 Get an intnum as a signed decimal string. More...
 
YASM_LIB_DECL void yasm_intnum_print (const yasm_intnum *intn, FILE *f)
 Print an intnum. More...
 

Detailed Description

YASM integer number interface.

Definition in file intnum.h.

Function Documentation

YASM_LIB_DECL unsigned long yasm_get_sleb128 ( long  v,
unsigned char *  ptr 
)

Output integer to buffer in signed LEB128-encoded form.

Parameters
vinteger
ptrpointer to storage for output bytes
Returns
Number of bytes generated.
YASM_LIB_DECL unsigned long yasm_get_uleb128 ( unsigned long  v,
unsigned char *  ptr 
)

Output integer to buffer in unsigned LEB128-encoded form.

Parameters
vinteger
ptrpointer to storage for output bytes
Returns
Number of bytes generated.
YASM_LIB_DECL int yasm_intnum_calc ( yasm_intnum acc,
yasm_expr_op  op,
yasm_intnum operand 
)

Floating point calculation function: acc = acc op operand.

Note
Not all operations in yasm_expr_op may be supported; unsupported operations will result in an error.
Parameters
accintnum accumulator
opoperation
operandintnum operand
Returns
Nonzero if error occurred.
YASM_LIB_DECL int yasm_intnum_check_size ( const yasm_intnum intn,
size_t  size,
size_t  rshift,
int  rangetype 
)

Check to see if intnum will fit without overflow into size bits.

Parameters
intnintnum
sizenumber of bits of output space
rshiftright shift
rangetypesigned/unsigned range selection: 0 => (0, unsigned max); 1 => (signed min, signed max); 2 => (signed min, unsigned max)
Returns
Nonzero if intnum will fit.
YASM_LIB_DECL void yasm_intnum_cleanup ( void  )

Clean up internal intnum allocations.

YASM_LIB_DECL int yasm_intnum_compare ( const yasm_intnum intn1,
const yasm_intnum intn2 
)

Compare two intnums.

Parameters
intn1first intnum
intn2second intnum
Returns
-1 if intn1 < intn2, 0 if intn1 == intn2, 1 if intn1 > intn2.
YASM_LIB_DECL yasm_intnum* yasm_intnum_copy ( const yasm_intnum intn)

Duplicate an intnum.

Parameters
intnintnum
Returns
Newly allocated intnum with the same value as intn.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_bin ( char *  str)

Create a new intnum from a binary string.

Parameters
strbinary string
Returns
Newly allocated intnum.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_charconst_nasm ( const char *  str)

Convert character constant to integer value, using NASM rules.

NASM syntax supports automatic conversion from strings such as 'abcd' to a 32-bit integer value (little endian order). This function performs those conversions.

Parameters
strcharacter constant string
Returns
Newly allocated intnum.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_charconst_tasm ( const char *  str)

Convert character constant to integer value, using TASM rules.

TASM syntax supports automatic conversion from strings such as 'abcd' to a 32-bit integer value (big endian order). This function performs those conversions.

Parameters
strcharacter constant string
Returns
Newly allocated intnum.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_dec ( char *  str)

Create a new intnum from a decimal string.

Parameters
strdecimal string
Returns
Newly allocated intnum.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_hex ( char *  str)

Create a new intnum from a hexidecimal string.

Parameters
strhexidecimal string
Returns
Newly allocated intnum.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_int ( long  i)

Create a new intnum from an signed integer value.

Parameters
isigned integer value
Returns
Newly allocated intnum.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_leb128 ( const unsigned char *  ptr,
int  sign,
unsigned long *  size 
)

Create a new intnum from LEB128-encoded form.

Parameters
ptrpointer to start of LEB128 encoded form
signsigned (1) or unsigned (0) LEB128 format
sizenumber of bytes read from ptr (output)
Returns
Newly allocated intnum. Number of bytes read returned into bytes_read parameter.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_oct ( char *  str)

Create a new intnum from an octal string.

Parameters
stroctal string
Returns
Newly allocated intnum.
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_sized ( unsigned char *  ptr,
int  sign,
size_t  srcsize,
int  bigendian 
)

Create a new intnum from a little-endian or big-endian buffer.

In little endian, the LSB is in ptr[0].

Parameters
ptrpointer to start of buffer
signsigned (1) or unsigned (0) source
srcsizesource buffer size (in bytes)
bigendianendianness (nonzero=big, zero=little)
YASM_LIB_DECL yasm_intnum* yasm_intnum_create_uint ( unsigned long  i)

Create a new intnum from an unsigned integer value.

Parameters
iunsigned integer value
Returns
Newly allocated intnum.
YASM_LIB_DECL void yasm_intnum_destroy ( yasm_intnum intn)

Destroy (free allocated memory for) an intnum.

Parameters
intnintnum
YASM_LIB_DECL long yasm_intnum_get_int ( const yasm_intnum intn)

Convert an intnum to a signed 32-bit value.

The value is in "standard" C format (eg, of unknown endian).

Note
Parameter intnum is truncated to fit into 32 bits. Use intnum_check_size() to check for overflow.
Parameters
intnintnum
Returns
Signed 32-bit value of intn.
YASM_LIB_DECL unsigned long yasm_intnum_get_leb128 ( const yasm_intnum intn,
unsigned char *  ptr,
int  sign 
)

Output yasm_intnum to buffer in LEB128-encoded form.

Parameters
intnintnum
ptrpointer to storage for output bytes
signsignedness of LEB128 encoding (0=unsigned, 1=signed)
Returns
Number of bytes generated.
YASM_LIB_DECL void yasm_intnum_get_sized ( const yasm_intnum intn,
unsigned char *  ptr,
size_t  destsize,
size_t  valsize,
int  shift,
int  bigendian,
int  warn 
)

Output yasm_intnum to buffer in little-endian or big-endian.

Puts the value into the least significant bits of the destination, or may be shifted into more significant bits by the shift parameter. The destination bits are cleared before being set. [0] should be the first byte output to the file.

Parameters
intnintnum
ptrpointer to storage for size bytes of output
destsizedestination size (in bytes)
valsizesize (in bits)
shiftleft shift (in bits); may be negative to specify right shift (standard warnings include truncation to boundary)
bigendianendianness (nonzero=big, zero=little)
warnenables standard warnings (value doesn't fit into valsize bits): <0=signed warnings, >0=unsigned warnings, 0=no warn
YASM_LIB_DECL char* yasm_intnum_get_str ( const yasm_intnum intn)

Get an intnum as a signed decimal string.

The returned string will contain a leading '-' if the intnum is negative.

Parameters
intnintnum
Returns
Newly allocated string containing the decimal representation of the intnum.
YASM_LIB_DECL unsigned long yasm_intnum_get_uint ( const yasm_intnum intn)

Convert an intnum to an unsigned 32-bit value.

The value is in "standard" C format (eg, of unknown endian).

Note
Parameter intnum is truncated to fit into 32 bits. Use intnum_check_size() to check for overflow.
Parameters
intnintnum
Returns
Unsigned 32-bit value of intn.
YASM_LIB_DECL int yasm_intnum_in_range ( const yasm_intnum intn,
long  low,
long  high 
)

Check to see if intnum will fit into a particular numeric range.

Parameters
intnintnum
lowlow end of range (inclusive)
highhigh end of range (inclusive)
Returns
Nonzero if intnum is within range.
YASM_LIB_DECL void yasm_intnum_initialize ( void  )

Initialize intnum internal data structures.

YASM_LIB_DECL int yasm_intnum_is_neg1 ( const yasm_intnum acc)

Simple value check for -1.

Parameters
accintnum
Returns
Nonzero if acc==-1.
YASM_LIB_DECL int yasm_intnum_is_pos1 ( const yasm_intnum acc)

Simple value check for 1.

Parameters
accintnum
Returns
Nonzero if acc==1.
YASM_LIB_DECL int yasm_intnum_is_zero ( const yasm_intnum acc)

Simple value check for 0.

Parameters
accintnum
Returns
Nonzero if acc==0.
YASM_LIB_DECL void yasm_intnum_print ( const yasm_intnum intn,
FILE *  f 
)

Print an intnum.

For debugging purposes.

Parameters
ffile
intnintnum
YASM_LIB_DECL void yasm_intnum_set ( yasm_intnum intn,
const yasm_intnum val 
)

Set an intnum to the value of another intnum.

Parameters
intnintnum
valintnum to get value from
YASM_LIB_DECL void yasm_intnum_set_int ( yasm_intnum intn,
long  val 
)

Set an intnum to an signed integer.

Parameters
intnintnum
valinteger value
YASM_LIB_DECL void yasm_intnum_set_uint ( yasm_intnum intn,
unsigned long  val 
)

Set an intnum to an unsigned integer.

Parameters
intnintnum
valinteger value
YASM_LIB_DECL int yasm_intnum_sign ( const yasm_intnum acc)

Simple sign check.

Parameters
accintnum
Returns
-1 if negative, 0 if zero, +1 if positive
YASM_LIB_DECL unsigned long yasm_intnum_size_leb128 ( const yasm_intnum intn,
int  sign 
)

Calculate number of bytes LEB128-encoded form of yasm_intnum will take.

Parameters
intnintnum
signsignedness of LEB128 encoding (0=unsigned, 1=signed)
Returns
Number of bytes.
YASM_LIB_DECL void yasm_intnum_zero ( yasm_intnum intn)

Zero an intnum.

Parameters
intnintnum
YASM_LIB_DECL unsigned long yasm_size_sleb128 ( long  v)

Calculate number of bytes signed LEB128-encoded form of integer will take.

Parameters
vinteger
Returns
Number of bytes.
YASM_LIB_DECL unsigned long yasm_size_uleb128 ( unsigned long  v)

Calculate number of bytes unsigned LEB128-encoded form of integer will take.

Parameters
vinteger
Returns
Number of bytes.