+int get_type_alignment_bytes(type *tp) {
+ int align = get_type_alignment_bits(tp);
+
+ return align < 0 ? align : (align + 7) >> 3;
+}
+
+int get_type_alignment_bits(type *tp) {
+ int align = 8;
+
+ if (tp->align > 0)
+ return tp->align;
+
+ /* alignment NOT set calculate it "on demand" */
+ if (tp->mode)
+ align = get_mode_size_bits(tp->mode);
+ else if (is_Array_type(tp))
+ align = get_type_alignment_bits(get_array_element_type(tp));
+ else if (is_compound_type(tp)) {
+ int i, n = get_compound_n_members(tp);
+
+ align = 0;
+ for (i = 0; i < n; ++i) {
+ type *t = get_entity_type(get_compound_member(tp, i));
+ int a = get_type_alignment_bits(t);
+
+ if (a > align)
+ align = a;
+ }
+ }
+ else if (is_Method_type(tp))
+ align = 0;
+
+ /* write back */
+ tp->align = align;
+
+ return align;
+}
+
+void
+set_type_alignment_bits(type *tp, int align) {
+ assert(tp && tp->kind == k_type);
+ /* Methods don't have an alignment. */
+ if (tp->type_op != type_method) {
+ tp->align = align;
+ }
+}
+
+void
+set_type_alignment_bytes(type *tp, int align) {
+ set_type_alignment_bits(tp, 8*align);
+}
+
+/* Returns a human readable string for the enum entry. */
+const char *get_type_state_name(type_state s) {
+#define X(a) case a: return #a;
+ switch (s) {
+ X(layout_undefined);
+ X(layout_fixed);
+ }
+ return "<unknown>";
+#undef X
+}
+
+
+type_state (get_type_state)(const type *tp) {
+ return _get_type_state(tp);