+ if (ops->init) {
+ ops->init(C);
+ }
+
+ assert(ops->call != NULL);
+ assert(ops->compile != NULL);
+
+ /* build up predefs in a temporary PSI_Data for validation */
+ memset(&T, 0, sizeof(T));
+ psi_data_ctor_with_dtors(&T, error, flags);
+
+ for (predef_type = &psi_predef_types[0]; predef_type->type_tag; ++predef_type) {
+ struct psi_decl_type *type = psi_decl_type_init(predef_type->type_tag, predef_type->type_name);
+ struct psi_decl_var *var = psi_decl_var_init(predef_type->alias, 0, 0); /* FIXME: indirection */
+ struct psi_decl_arg *def = psi_decl_arg_init(type, var);
+
+ T.types = psi_plist_add(T.types, &def);
+ }
+ for (predef_const = &psi_predef_consts[0]; predef_const->type_tag; ++predef_const) {
+ struct psi_impl_def_val *val = psi_impl_def_val_init(predef_const->val_type_tag, predef_const->val_text);
+ struct psi_const_type *type = psi_const_type_init(predef_const->type_tag, predef_const->type_name);
+ struct psi_const *constant = psi_const_init(type, predef_const->var_name, val);
+
+ T.consts = psi_plist_add(T.consts, &constant);
+ }
+ for (predef_struct = &psi_predef_structs[0]; predef_struct->type_tag; ++predef_struct) {
+ struct psi_predef_struct *member;
+ struct psi_plist *dargs = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
+ struct psi_decl_struct *dstruct = psi_decl_struct_init(predef_struct->var_name, dargs);
+
+ dstruct->size = predef_struct->size;
+ dstruct->align = predef_struct->offset;
+ for (member = &predef_struct[1]; member->type_tag; ++member) {
+ struct psi_decl_type *type;
+ struct psi_decl_var *dvar;
+ struct psi_decl_arg *darg;
+
+ type = psi_decl_type_init(member->type_tag, member->type_name);
+ dvar = psi_decl_var_init(member->var_name, member->pointer_level, member->array_size);
+ darg = psi_decl_arg_init(type, dvar);
+ darg->layout = psi_layout_init(member->offset, member->size);
+ dstruct->args = psi_plist_add(dstruct->args, &darg);
+ }
+
+ T.structs = psi_plist_add(T.structs, &dstruct);
+ predef_struct = member;
+ }
+ for (predef_union = &psi_predef_unions[0]; predef_union->type_tag; ++predef_union) {
+ struct psi_predef_union *member;
+ struct psi_plist *dargs = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
+ struct psi_decl_union *dunion = psi_decl_union_init(predef_union->var_name, dargs);
+
+ dunion->size = predef_union->size;
+ dunion->align = predef_union->offset;
+ for (member = &predef_union[1]; member->type_tag; ++member) {
+ struct psi_decl_type *type;
+ struct psi_decl_var *dvar;
+ struct psi_decl_arg *darg;
+
+ type = psi_decl_type_init(member->type_tag, member->type_name);
+ dvar = psi_decl_var_init(member->var_name, member->pointer_level, member->array_size);
+ darg = psi_decl_arg_init(type, dvar);
+ darg->layout = psi_layout_init(member->offset, member->size);
+ dunion->args = psi_plist_add(dunion->args, &darg);
+ }
+
+ T.unions = psi_plist_add(T.unions, &dunion);
+ predef_union = member;
+ }
+ for (predef_decl = &psi_predef_decls[0]; predef_decl->type_tag; ++predef_decl) {
+ struct psi_predef_decl *farg;
+ struct psi_decl_type *ftype = psi_decl_type_init(predef_decl->type_tag, predef_decl->type_name);
+ struct psi_decl_var *fname = psi_decl_var_init(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size);
+ struct psi_decl_arg *func = psi_decl_arg_init(ftype, fname);
+ struct psi_plist *args = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
+ struct psi_decl *decl = psi_decl_init(psi_decl_abi_init("default"), func, args);
+
+ for (farg = &predef_decl[1]; farg->type_tag; ++farg) {
+ struct psi_decl_type *arg_type = psi_decl_type_init(farg->type_tag, farg->type_name);
+ struct psi_decl_var *arg_var = psi_decl_var_init(farg->var_name, farg->pointer_level, farg->array_size);
+ struct psi_decl_arg *darg = psi_decl_arg_init(arg_type, arg_var);
+ decl->args = psi_plist_add(decl->args, &darg);
+ }