3 Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2.1 of the GNU Lesser General Public License
7 as published by the Free Software Foundation.
9 This program is distributed in the hope that it would be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 Further, this software is distributed without any warranty that it is
14 free of the rightful claim of any third person regarding infringement
15 or the like. Any license provided herein, whether implied or
16 otherwise, applies only to this software file. Patent licenses, if
17 any, provided herein do not apply to combinations of this program with
18 other software, or any other product whatsoever.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this program; if not, write the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
25 Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
26 Mountain View, CA 94043, or:
30 For further information regarding this notice, see:
32 http://oss.sgi.com/projects/GenInfo/NoticeExplan
39 #include "dwarf_incl.h"
47 _dwarf_decode_u_leb128(Dwarf_Small
* leb128
, Dwarf_Word
* leb128_length
)
50 Dwarf_Word word_number
;
51 Dwarf_Unsigned number
;
53 Dwarf_Sword byte_length
;
55 /* The following unrolls-the-loop for the first few bytes and
56 unpacks into 32 bits to make this as fast as possible.
57 word_number is assumed big enough that the shift has a defined
59 if ((*leb128
& 0x80) == 0) {
60 if (leb128_length
!= NULL
)
63 } else if ((*(leb128
+ 1) & 0x80) == 0) {
64 if (leb128_length
!= NULL
)
67 word_number
= *leb128
& 0x7f;
68 word_number
|= (*(leb128
+ 1) & 0x7f) << 7;
70 } else if ((*(leb128
+ 2) & 0x80) == 0) {
71 if (leb128_length
!= NULL
)
74 word_number
= *leb128
& 0x7f;
75 word_number
|= (*(leb128
+ 1) & 0x7f) << 7;
76 word_number
|= (*(leb128
+ 2) & 0x7f) << 14;
78 } else if ((*(leb128
+ 3) & 0x80) == 0) {
79 if (leb128_length
!= NULL
)
82 word_number
= *leb128
& 0x7f;
83 word_number
|= (*(leb128
+ 1) & 0x7f) << 7;
84 word_number
|= (*(leb128
+ 2) & 0x7f) << 14;
85 word_number
|= (*(leb128
+ 3) & 0x7f) << 21;
89 /* The rest handles long numbers Because the 'number' may be larger
90 than the default int/unsigned, we must cast the 'byte' before
91 the shift for the shift to have a defined result. */
97 number
|= ((Dwarf_Unsigned
) (byte
& 0x7f)) << shift
;
99 if ((byte
& 0x80) == 0) {
100 if (leb128_length
!= NULL
)
101 *leb128_length
= byte_length
;
118 _dwarf_decode_s_leb128(Dwarf_Small
* leb128
, Dwarf_Word
* leb128_length
)
120 Dwarf_Signed number
= 0;
122 Dwarf_Sword shift
= 0;
123 unsigned char byte
= *leb128
;
124 Dwarf_Sword byte_length
= 1;
126 /* byte_length being the number of bytes of data absorbed so far in
127 turning the leb into a Dwarf_Signed. */
131 number
|= ((Dwarf_Signed
) ((byte
& 0x7f))) << shift
;
134 if ((byte
& 0x80) == 0) {
142 if ((shift
< sizeof(Dwarf_Signed
) * BITSINBYTE
) && sign
) {
143 number
|= -((Dwarf_Signed
) 1 << shift
);
146 if (leb128_length
!= NULL
)
147 *leb128_length
= byte_length
;