[svn:parrot] r39831 - trunk/compilers/imcc
petdance at svn.parrot.org
petdance at svn.parrot.org
Tue Jun 30 02:29:32 UTC 2009
Author: petdance
Date: Tue Jun 30 02:29:31 2009
New Revision: 39831
URL: https://trac.parrot.org/parrot/changeset/39831
Log:
Rewrote IMCC_int_from_reg to not be all cut & paste
Modified:
trunk/compilers/imcc/pbc.c
Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c Mon Jun 29 10:09:07 2009 (r39830)
+++ trunk/compilers/imcc/pbc.c Tue Jun 30 02:29:31 2009 (r39831)
@@ -1765,23 +1765,31 @@
{
ASSERT_ARGS(IMCC_int_from_reg)
INTVAL i;
-
- errno = 0;
+ const char *digits;
+ int base;
if (r->type & VT_CONSTP)
r = r->reg;
- if (r->name[0] == '0' && (r->name[1] == 'x' || r->name[1] == 'X'))
- i = strtoul(r->name + 2, NULL, 16);
-
- else if (r->name[0] == '0' && (r->name[1] == 'O' || r->name[1] == 'o'))
- i = strtoul(r->name + 2, NULL, 8);
-
- else if (r->name[0] == '0' && (r->name[1] == 'b' || r->name[1] == 'B'))
- i = strtoul(r->name + 2, NULL, 2);
+ digits = r->name;
+ base = 10;
+ errno = 0;
+
+ if (digits[0] == '0') {
+ switch (toupper(digits[1])) {
+ case 'B': base = 2; break;
+ case 'O': base = 8; break;
+ case 'X': base = 16; break;
+ default: break;
+ }
+ }
- else
- i = strtol(r->name, NULL, 10);
+ if ( base == 10 ) {
+ i = strtol(digits, NULL, base);
+ }
+ else {
+ i = strtoul(digits + 2, NULL, base);
+ }
/*
* TODO
@@ -2121,7 +2129,6 @@
ARGIN(const Instruction *ins))
{
ASSERT_ARGS(e_pbc_emit)
- op_info_t *op_info;
int ok = 0;
int op, i;
@@ -2256,6 +2263,7 @@
}
else if (ins->opname && *ins->opname) {
SymReg *addr, *r;
+ op_info_t *op_info;
opcode_t last_label = 1;
#if IMC_TRACE_HIGH
More information about the parrot-commits
mailing list