+ return res;
+}
+
+/**
+ * Completes an incomplete irprog.
+ *
+ * @param irp the (yet incomplete) irp
+ * @param module_name the (module) name for this irp
+ */
+static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name)
+{
+#define IDENT(x) new_id_from_chars(x, sizeof(x) - 1)
+
+ irp->name = new_id_from_str(module_name);
+ irp->segment_types[IR_SEGMENT_GLOBAL]
+ = new_type_class(IDENT("GlobalType"));
+ irp->segment_types[IR_SEGMENT_THREAD_LOCAL]
+ = new_type_struct(IDENT("ThreadLocal"));
+ irp->segment_types[IR_SEGMENT_CONSTRUCTORS]
+ = new_type_class(IDENT("Constructors"));
+ irp->segment_types[IR_SEGMENT_DESTRUCTORS]
+ = new_type_class(IDENT("Destructors"));
+
+ /* Set these flags for debugging. */
+ irp->segment_types[IR_SEGMENT_GLOBAL]->flags |= tf_segment|tf_global_type;
+ irp->segment_types[IR_SEGMENT_THREAD_LOCAL]->flags |= tf_segment|tf_tls_type;
+ irp->segment_types[IR_SEGMENT_CONSTRUCTORS]->flags |= tf_segment|tf_constructors;
+ irp->segment_types[IR_SEGMENT_DESTRUCTORS]->flags |= tf_segment|tf_destructors;
+
+ /* The global type is a class, but we cannot derive from it, so set
+ the final property to assist optimizations that checks for it. */
+ set_class_final(irp->segment_types[IR_SEGMENT_GLOBAL], 1);