- switch(atomic_type->atype) {
- case ATOMIC_TYPE_SCHAR:
- case ATOMIC_TYPE_CHAR:
- return mode_Bs;
- case ATOMIC_TYPE_UCHAR:
- return mode_Bu;
- case ATOMIC_TYPE_SHORT:
- return mode_Hs;
- case ATOMIC_TYPE_USHORT:
- return mode_Hu;
- case ATOMIC_TYPE_LONG:
- case ATOMIC_TYPE_INT:
- return mode_Is;
- case ATOMIC_TYPE_ULONG:
- case ATOMIC_TYPE_UINT:
- return mode_Iu;
- case ATOMIC_TYPE_LONGLONG:
- return mode_Ls;
- case ATOMIC_TYPE_ULONGLONG:
- return mode_Lu;
- case ATOMIC_TYPE_FLOAT:
- return mode_F;
- case ATOMIC_TYPE_DOUBLE:
- return mode_D;
- case ATOMIC_TYPE_LONG_DOUBLE:
- return mode_E;
- case ATOMIC_TYPE_BOOL:
- return mode_b;
+ static ir_mode *s_modes[16 + 1] = {0, };
+ ir_mode *res;
+
+ if (size <= 0 || size > 16)
+ return NULL;
+
+ res = s_modes[size];
+ if (res == NULL) {
+ unsigned bits;
+ char name[32];
+
+ bits = size * 8;
+ snprintf(name, sizeof(name), "i%u", bits);
+ res = new_ir_mode(name, irms_int_number, bits, 1, irma_twos_complement,
+ bits <= machine_size ? machine_size : bits );
+
+ s_modes[size] = res;
+ }
+ return res;
+}
+
+/**
+ * Return the unsigned integer mode of size bytes.
+ *
+ * @param size the size
+ */
+static ir_mode *get_umode(unsigned size)
+{
+ static ir_mode *u_modes[16 + 1] = {0, };
+ ir_mode *res;
+
+ if (size <= 0 || size > 16)
+ return NULL;
+
+ res = u_modes[size];
+ if (res == NULL) {
+ unsigned bits;
+ char name[32];
+
+ bits = size * 8;
+ snprintf(name, sizeof(name), "u%u", bits);
+ res = new_ir_mode(name, irms_int_number, bits, 0, irma_twos_complement,
+ bits <= machine_size ? machine_size : bits );
+
+ u_modes[size] = res;
+ }
+ return res;
+}
+
+/**
+ * Return the pointer mode of size bytes.
+ *
+ * @param size the size
+ */
+static ir_mode *get_ptrmode(unsigned size, char *name)
+{
+ static ir_mode *p_modes[16 + 1] = {0, };
+ ir_mode *res;
+
+ if (size <= 0 || size > 16)
+ return NULL;
+
+ res = p_modes[size];
+ if (res == NULL) {
+ unsigned bits;
+ char buf[32];
+
+ bits = size * 8;
+ if (name == NULL) {
+ snprintf(buf, sizeof(buf), "p%u", bits);
+ name = buf;
+ }
+ res = new_ir_mode(name, irms_reference, bits, 0, irma_twos_complement,
+ bits <= machine_size ? machine_size : bits);
+
+ p_modes[size] = res;
+
+ set_reference_mode_signed_eq(res, get_smode(size));
+ set_reference_mode_unsigned_eq(res, get_umode(size));
+ }
+ return res;
+}
+
+static ir_mode *_atomic_modes[ATOMIC_TYPE_LAST];
+
+static ir_mode *mode_int, *mode_uint;
+
+/**
+ * Initialises the atomic modes depending on the machine size.
+ */
+static void init_atomic_modes(void) {
+ unsigned int_size = machine_size < 32 ? 2 : 4;
+ unsigned long_size = machine_size < 64 ? 4 : 8;
+ unsigned llong_size = machine_size < 32 ? 4 : 8;
+
+ /* firm has no real void... */
+ _atomic_modes[ATOMIC_TYPE_VOID] = mode_T;
+ _atomic_modes[ATOMIC_TYPE_CHAR] = char_is_signed ? get_smode(1) : get_umode(1);
+ _atomic_modes[ATOMIC_TYPE_SCHAR] = get_smode(1);
+ _atomic_modes[ATOMIC_TYPE_UCHAR] = get_umode(1);
+ _atomic_modes[ATOMIC_TYPE_SHORT] = get_smode(2);
+ _atomic_modes[ATOMIC_TYPE_USHORT] = get_umode(2);
+ _atomic_modes[ATOMIC_TYPE_INT] = get_smode(int_size);
+ _atomic_modes[ATOMIC_TYPE_UINT] = get_umode(int_size);
+ _atomic_modes[ATOMIC_TYPE_LONG] = get_smode(long_size);
+ _atomic_modes[ATOMIC_TYPE_ULONG] = get_umode(long_size);
+ _atomic_modes[ATOMIC_TYPE_LONGLONG] = get_smode(llong_size);
+ _atomic_modes[ATOMIC_TYPE_ULONGLONG] = get_umode(llong_size);
+ _atomic_modes[ATOMIC_TYPE_FLOAT] = mode_F;
+ _atomic_modes[ATOMIC_TYPE_DOUBLE] = mode_D;
+ _atomic_modes[ATOMIC_TYPE_LONG_DOUBLE] = mode_E;
+