- if ((tp->type_op == type_primitive) ||
- (tp->type_op == type_enumeration) ||
- (tp->type_op == type_pointer) ) {
- /* For pointer, primitive and enumeration size depends on the mode. */
- assert((get_mode_size_bytes(m) != -1) && "unorthodox modes not implemented");
- tp->size = get_mode_size_bytes(m);
+ switch (get_type_tpop_code(tp)) {
+ case tpo_primitive:
+ /* For primitive size depends on the mode. */
+ tp->size = get_mode_size_bits(m);
+ tp->mode = m;
+ break;
+ case tpo_enumeration:
+ case tpo_pointer:
+ /* For pointer and enumeration size depends on the mode, but only byte size allowed. */
+ assert((get_mode_size_bits(m) & 7) == 0 && "unorthodox modes not implemented");
+ tp->size = get_mode_size_bits(m);
+ tp->mode = m;
+ break;
+ case tpo_struct:
+ case tpo_class:
+ /* for classes and structs we allow to set a mode if the layout is fixed AND the size matches */
+ assert(get_type_state(tp) == layout_fixed &&
+ tp->size == get_mode_size_bits(m) &&
+ "mode don't match struct/class layout");