00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <ctype.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #ifdef TARG_MIPS
00027 #include "mips.h"
00028 #else
00029 #include "i386.h"
00030 #endif
00031
00032 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
00033
00034 static const char *reg_names[] = REGISTER_NAMES;
00035
00036
00037
00038 static const char *
00039 strip_reg_name (const char *name)
00040 {
00041 if (name[0] == '%' || name[0] == '#')
00042 name++;
00043 return name;
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 int
00055 gs_decode_reg_name (const char *asmspec)
00056 {
00057 if (asmspec != 0)
00058 {
00059 int i;
00060
00061
00062 asmspec = strip_reg_name (asmspec);
00063
00064
00065 for (i = strlen (asmspec) - 1; i >= 0; i--)
00066 if (! isdigit (asmspec[i]))
00067 break;
00068 if (asmspec[0] != 0 && i < 0)
00069 {
00070 i = atoi (asmspec);
00071 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
00072 return i;
00073 else
00074 return -2;
00075 }
00076
00077 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
00078 if (reg_names[i][0]
00079 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
00080 return i;
00081
00082 #ifdef ADDITIONAL_REGISTER_NAMES
00083 {
00084 static const struct { const char *const name; const int number; } table[]
00085 = ADDITIONAL_REGISTER_NAMES;
00086
00087 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
00088 if (! strcmp (asmspec, table[i].name))
00089 return table[i].number;
00090 }
00091 #endif
00092
00093 if (!strcmp (asmspec, "memory"))
00094 return -4;
00095
00096 if (!strcmp (asmspec, "cc"))
00097 return -3;
00098
00099 return -2;
00100 }
00101
00102 return -1;
00103 }