libyasm/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.
YASM_LIB_DECL void yasm_intnum_cleanup (void)
 Clean up internal intnum allocations.
YASM_LIB_DECL yasm_intnumyasm_intnum_create_dec (char *str)
 Create a new intnum from a decimal string.
YASM_LIB_DECL yasm_intnumyasm_intnum_create_bin (char *str)
 Create a new intnum from a binary string.
YASM_LIB_DECL yasm_intnumyasm_intnum_create_oct (char *str)
 Create a new intnum from an octal string.
YASM_LIB_DECL yasm_intnumyasm_intnum_create_hex (char *str)
 Create a new intnum from a hexidecimal string.
YASM_LIB_DECL yasm_intnumyasm_intnum_create_charconst_nasm (const char *str)
 Convert character constant to integer value, using NASM rules.
YASM_LIB_DECL yasm_intnumyasm_intnum_create_charconst_tasm (const char *str)
 Convert character constant to integer value, using TASM rules.
YASM_LIB_DECL yasm_intnumyasm_intnum_create_uint (unsigned long i)
 Create a new intnum from an unsigned integer value.
YASM_LIB_DECL yasm_intnumyasm_intnum_create_int (long i)
 Create a new intnum from an signed integer value.
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.
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.
YASM_LIB_DECL yasm_intnumyasm_intnum_copy (const yasm_intnum *intn)
 Duplicate an intnum.
YASM_LIB_DECL void yasm_intnum_destroy (yasm_intnum *intn)
 Destroy (free allocated memory for) an intnum.
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.
YASM_LIB_DECL int yasm_intnum_compare (const yasm_intnum *intn1, const yasm_intnum *intn2)
 Compare two intnums.
YASM_LIB_DECL void yasm_intnum_zero (yasm_intnum *intn)
 Zero an intnum.
YASM_LIB_DECL void yasm_intnum_set (yasm_intnum *intn, const yasm_intnum *val)
 Set an intnum to the value of another intnum.
YASM_LIB_DECL void yasm_intnum_set_uint (yasm_intnum *intn, unsigned long val)
 Set an intnum to an unsigned integer.
YASM_LIB_DECL void yasm_intnum_set_int (yasm_intnum *intn, long val)
 Set an intnum to an signed integer.
YASM_LIB_DECL int yasm_intnum_is_zero (const yasm_intnum *acc)
 Simple value check for 0.
YASM_LIB_DECL int yasm_intnum_is_pos1 (const yasm_intnum *acc)
 Simple value check for 1.
YASM_LIB_DECL int yasm_intnum_is_neg1 (const yasm_intnum *acc)
 Simple value check for -1.
YASM_LIB_DECL int yasm_intnum_sign (const yasm_intnum *acc)
 Simple sign check.
YASM_LIB_DECL unsigned long yasm_intnum_get_uint (const yasm_intnum *intn)
 Convert an intnum to an unsigned 32-bit value.
YASM_LIB_DECL long yasm_intnum_get_int (const yasm_intnum *intn)
 Convert an intnum to a signed 32-bit value.
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.
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.
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.
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.
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.
YASM_LIB_DECL unsigned long yasm_get_sleb128 (long v, unsigned char *ptr)
 Output integer to buffer in signed LEB128-encoded form.
YASM_LIB_DECL unsigned long yasm_size_sleb128 (long v)
 Calculate number of bytes signed LEB128-encoded form of integer will take.
YASM_LIB_DECL unsigned long yasm_get_uleb128 (unsigned long v, unsigned char *ptr)
 Output integer to buffer in unsigned LEB128-encoded form.
YASM_LIB_DECL unsigned long yasm_size_uleb128 (unsigned long v)
 Calculate number of bytes unsigned LEB128-encoded form of integer will take.
YASM_LIB_DECL char * yasm_intnum_get_str (const yasm_intnum *intn)
 Get an intnum as a signed decimal string.
YASM_LIB_DECL void yasm_intnum_print (const yasm_intnum *intn, FILE *f)
 Print an intnum.

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:
v integer
ptr pointer 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:
v integer
ptr pointer 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:
acc intnum accumulator
op operation
operand intnum 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:
intn intnum
size number of bits of output space
rshift right shift
rangetype signed/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:
intn1 first intnum
intn2 second 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:
intn intnum
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:
str binary 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:
str character 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:
str character 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:
str decimal 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:
str hexidecimal 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:
i signed 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:
ptr pointer to start of LEB128 encoded form
sign signed (1) or unsigned (0) LEB128 format
size number 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:
str octal 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:
ptr pointer to start of buffer
sign signed (1) or unsigned (0) source
srcsize source buffer size (in bytes)
bigendian endianness (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:
i unsigned integer value
Returns:
Newly allocated intnum.
YASM_LIB_DECL void yasm_intnum_destroy ( yasm_intnum intn  ) 

Destroy (free allocated memory for) an intnum.

Parameters:
intn intnum
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:
intn intnum
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:
intn intnum
ptr pointer to storage for output bytes
sign signedness 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:
intn intnum
ptr pointer to storage for size bytes of output
destsize destination size (in bytes)
valsize size (in bits)
shift left shift (in bits); may be negative to specify right shift (standard warnings include truncation to boundary)
bigendian endianness (nonzero=big, zero=little)
warn enables 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:
intn intnum
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:
intn intnum
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:
intn intnum
low low end of range (inclusive)
high high 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:
acc intnum
Returns:
Nonzero if acc==-1.
YASM_LIB_DECL int yasm_intnum_is_pos1 ( const yasm_intnum acc  ) 

Simple value check for 1.

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

Simple value check for 0.

Parameters:
acc intnum
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:
f file
intn intnum
YASM_LIB_DECL void yasm_intnum_set ( yasm_intnum intn,
const yasm_intnum val 
)

Set an intnum to the value of another intnum.

Parameters:
intn intnum
val intnum 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:
intn intnum
val integer value
YASM_LIB_DECL void yasm_intnum_set_uint ( yasm_intnum intn,
unsigned long  val 
)

Set an intnum to an unsigned integer.

Parameters:
intn intnum
val integer value
YASM_LIB_DECL int yasm_intnum_sign ( const yasm_intnum acc  ) 

Simple sign check.

Parameters:
acc intnum
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:
intn intnum
sign signedness 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:
intn intnum
YASM_LIB_DECL unsigned long yasm_size_sleb128 ( long  v  ) 

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

Parameters:
v integer
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:
v integer
Returns:
Number of bytes.
Generated on Thu Sep 9 01:20:24 2010 for libyasm by  doxygen 1.6.3