home *** CD-ROM | disk | FTP | other *** search
- /*
- pro_util.c
- $Revision: 1.5 $ $Date: 1993/07/19 22:40:18 $
- $Source: /cmplrs.src/v4.00/libdwarf/RCS/pro_util.c,v $
-
- utility functions
- */
-
- #include <string.h>
- #include "pro_incl.h"
-
- #define MORE_BYTES 0x80
- #define DATA_MASK 0x7f
- #define DIGIT_WIDTH 7
- #define SIGN_BIT 0x40
-
-
- /*-------------------------------------------------------------
- Encode val as a leb128. This encodes it as an unsigned
- number.
- ---------------------------------------------------------------*/
- char *
- _dwarf_pro_encode_leb128(Dwarf_Unsigned val, int *nbytes)
- {
- char *a, *b ;
-
- *nbytes = 0;
- a = (char *) _dwarf_p_get_alloc(NULL,sizeof(Dwarf_Unsigned)*2);
- /* assuming a doesnt go beyond this size */
- b = a;
- do
- {
- *a = val & DATA_MASK;
- val >>= DIGIT_WIDTH;
- if (val != 0)
- *a |= MORE_BYTES;
- a++;
- (*nbytes)++;
- }
- while (val);
- return b;
- }
-
-
- char *
- _dwarf_pro_encode_signed_leb128 (
- Dwarf_Signed value,
- int *nbytes
- )
- {
- char *ret_string, *str;
- Dwarf_Signed sign = - (value < 0);
- int more = 1;
-
- if (nbytes != NULL) *nbytes = 0;
- ret_string = str = (char *)_dwarf_p_get_alloc(NULL, sizeof(Dwarf_Signed) * 2);
- if (ret_string == NULL) return(NULL);
-
- do
- {
- char byte = value & DATA_MASK;
- value >>= DIGIT_WIDTH;
-
- /*
- * Remaining chunks would just contain the sign bit, and this chunk
- * has already captured at least one sign bit.
- */
- if (value == sign && (byte & SIGN_BIT) == (sign & SIGN_BIT))
- more = 0;
- else
- byte |= MORE_BYTES;
- *str = byte;
- str++;
- if (nbytes != NULL) (*nbytes)++;
- }
- while (more);
- return(ret_string);
- }
-
-
- /* Essentially a stub for now. */
- void
- _dwarf_p_dealloc (
- Dwarf_P_Debug dbg,
- Dwarf_Small *ptr
- )
- {
- dwarf_p_dealloc(ptr,DW_DLA_STRING);
- }
-