* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: Pfe_HexDec.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
PyObject
* long_format( PyObject
* aa
, int base
, int addL
)/*{{{*/
#define ABS(x) ((x) < 0 ? -(x) : (x))
register PyLongObject
*a
= (PyLongObject
*)aa
;
const int size_a
= ABS(a
->ob_size
);
if (a
== NULL
|| !PyLong_Check(a
)) {
assert(base
>= 2 && base
<= 36);
/* Compute a rough upper bound for the length of the string */
i
= 5 + (addL
? 1 : 0) + (size_a
*SHIFT
+ bits
-1) / bits
;
str
= (PyStringObject
*) PyString_FromStringAndSize((char *)0, i
);
p
= PyString_AS_STRING(str
) + i
;
else if ((base
& (base
- 1)) == 0) {
/* JRH: special case for power-of-2 bases */
int accumbits
= 0; /* # of bits in accum */
int basebits
= 1; /* # of bits in base-1 */
for (i
= 0; i
< size_a
; ++i
) {
accum
|= (twodigits
)a
->ob_digit
[i
] << accumbits
;
assert(accumbits
>= basebits
);
char cdigit
= (char)(accum
& (base
- 1));
cdigit
+= (cdigit
< 10) ? '0' : 'a'-10;
assert(p
> PyString_AS_STRING(str
));
} while (i
< size_a
-1 ? accumbits
>= basebits
:
if (p
!= PyString_AS_STRING(str
)) {
char *q
= PyString_AS_STRING(str
);
} while ((*q
++ = *p
++) != '\0');
_PyString_Resize((PyObject
**)&str
,
(int) (q
- PyString_AS_STRING(str
)));
PyObject
* long_hex_repr( PyObject
* v
)/*{{{*/
return long_format(v
,16,1);
PyObject
* long_hex_str( PyObject
* v
)/*{{{*/
return long_format(v
,16,0);
int_hex_print( PyIntObject
* v
, FILE* fp
, int flags
)/*{{{*/
fprintf(fp
,"0x%lx",v
->ob_ival
);
PyObject
* int_hex_repr( PyIntObject
* v
)/*{{{*/
PyOS_snprintf(buf
, sizeof(buf
), "0x%lx", v
->ob_ival
);
return PyString_FromString(buf
);
extern PyTypeObject PyInt_Type
;
extern PyTypeObject PyLong_Type
;
static printfunc int_dec_print
= 0;
static reprfunc long_dec_repr
;
static reprfunc long_dec_str
;
static reprfunc int_dec_repr
;
static reprfunc int_dec_str
;
long_dec_repr
= PyLong_Type
.tp_repr
;
long_dec_str
= PyLong_Type
.tp_str
;
int_dec_repr
= PyInt_Type
.tp_repr
;
int_dec_str
= PyInt_Type
.tp_str
;
int_dec_print
= PyInt_Type
.tp_print
;
PyLong_Type
.tp_repr
= (reprfunc
)long_hex_repr
;
PyLong_Type
.tp_str
= (reprfunc
)long_hex_str
;
PyInt_Type
.tp_repr
= (reprfunc
)int_hex_repr
;
PyInt_Type
.tp_str
= (reprfunc
)int_hex_repr
;
PyInt_Type
.tp_print
= (printfunc
)int_hex_print
;
PyLong_Type
.tp_repr
= (reprfunc
)long_dec_repr
;
PyLong_Type
.tp_str
= (reprfunc
)long_dec_str
;
PyInt_Type
.tp_repr
= (reprfunc
)int_dec_repr
;
PyInt_Type
.tp_str
= (reprfunc
)int_dec_repr
;
PyInt_Type
.tp_print
= (printfunc
)int_dec_print
;