X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Ftpop.c;h=977e6d526bd9c78da4dc40340fa9698cbc032383;hb=3e5387b39fceb47f91fe5d13e8d26f7c5c9a2407;hp=fc9f99a1fbde98134723f7464d0a09d85fa4a373;hpb=ac7a8d6d17e3080b94233fb5ab099591b9dc757b;p=libfirm diff --git a/ir/tr/tpop.c b/ir/tr/tpop.c index fc9f99a1f..977e6d526 100644 --- a/ir/tr/tpop.c +++ b/ir/tr/tpop.c @@ -1,99 +1,207 @@ /* - * Project: libFIRM - * File name: ir/tr/tpop.c - * Purpose: Opcode of types. - * Author: Goetz Lindenmaier - * Modified by: - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 2001-2003 Universität Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. */ +/** + * @file + * @brief Opcode of types. + * @author Goetz Lindenmaier, Michael Beck + */ +#include "config.h" -#ifdef HAVE_CONFIG_H -# include -#endif - -# include "xmalloc.h" -# include "tpop_t.h" -# include "type_t.h" +#include "xmalloc.h" +#include "tpop_t.h" +#include "type_t.h" +#include "ident.h" -tp_op *type_class; tp_op *get_tpop_class (void) { return type_class; } -tp_op *type_struct; tp_op *get_tpop_struct (void) { return type_struct; } -tp_op *type_method; tp_op *get_tpop_method (void) { return type_method; } -tp_op *type_union; tp_op *get_tpop_union (void) { return type_union; } -tp_op *type_array; tp_op *get_tpop_array (void) { return type_array; } -tp_op *type_enumeration; tp_op *get_tpop_enumeration(void) { return type_enumeration; } -tp_op *type_pointer; tp_op *get_tpop_pointer (void) { return type_pointer; } -tp_op *type_primitive; tp_op *get_tpop_primitive (void) { return type_primitive; } -tp_op *type_id; tp_op *get_tpop_id (void) { return type_id; } -tp_op *tpop_none; tp_op *get_tpop_none (void) { return tpop_none; } -tp_op *tpop_unknown; tp_op *get_tpop_unknown (void) { return tpop_unknown; } +const tp_op *type_class; const tp_op *get_tpop_class (void) { return type_class; } +const tp_op *type_struct; const tp_op *get_tpop_struct (void) { return type_struct; } +const tp_op *type_method; const tp_op *get_tpop_method (void) { return type_method; } +const tp_op *type_union; const tp_op *get_tpop_union (void) { return type_union; } +const tp_op *type_array; const tp_op *get_tpop_array (void) { return type_array; } +const tp_op *type_enumeration; const tp_op *get_tpop_enumeration(void) { return type_enumeration; } +const tp_op *type_pointer; const tp_op *get_tpop_pointer (void) { return type_pointer; } +const tp_op *type_primitive; const tp_op *get_tpop_primitive (void) { return type_primitive; } +const tp_op *tpop_code; const tp_op *get_tpop_code_type (void) { return tpop_code; } +const tp_op *tpop_none; const tp_op *get_tpop_none (void) { return tpop_none; } +const tp_op *tpop_unknown; const tp_op *get_tpop_unknown (void) { return tpop_unknown; } -tp_op * -new_tpop (tp_opcode code, ident *name, size_t attr_size) +const tp_op * +new_tpop(tp_opcode code, ident *name, unsigned flags, size_t attr_size, const tp_op_ops *ops) { - tp_op *res; + tp_op *res = XMALLOC(tp_op); + res->code = code; + res->name = name; + res->flags = flags; + res->attr_size = attr_size; - res = (tp_op *) xmalloc (sizeof (tp_op)); - res->code = code; - res->name = name; - res->attr_size = attr_size; - return res; -} + if (ops) + res->ops = *ops; + else + memset(&res->ops, 0, sizeof(res->ops)); -INLINE void -free_tpop(tp_op* tpop) { - free(tpop); + return res; } -void -init_tpop(void) +void free_tpop(const tp_op *tpop) { - type_class = new_tpop (tpo_class , id_from_str("class" , 5), sizeof (cls_attr)); - type_struct = new_tpop (tpo_struct , id_from_str("struct" , 6), sizeof (stc_attr)); - type_method = new_tpop (tpo_method , id_from_str("method" , 6), sizeof (mtd_attr)); - type_union = new_tpop (tpo_union , id_from_str("union" , 5), sizeof (uni_attr)); - type_array = new_tpop (tpo_array , id_from_str("array" , 5), sizeof (arr_attr)); - type_enumeration = new_tpop (tpo_enumeration, id_from_str("enumeration" ,11), sizeof (enm_attr)); - type_pointer = new_tpop (tpo_pointer , id_from_str("pointer" , 7), sizeof (ptr_attr)); - type_primitive = new_tpop (tpo_primitive , id_from_str("primitive" , 9), /* sizeof (pri_attr) */ 0); - type_id = new_tpop (tpo_id , id_from_str("type_id" , 7), /* sizeof (id_attr) */ 0); - tpop_none = new_tpop (tpo_none , id_from_str("tpop_none" , 9), /* sizeof (non_attr) */ 0); - tpop_unknown = new_tpop (tpo_unknown , id_from_str("tpop_unknown",12), /* sizeof (ukn_attr) */ 0); + xfree((void *)tpop); } -/* Finalize the topo module. - * Frees all type opcodes. */ -void finish_tpop(void) { - free_tpop(type_class ); type_class = NULL; - free_tpop(type_struct ); type_struct = NULL; - free_tpop(type_method ); type_method = NULL; - free_tpop(type_union ); type_union = NULL; - free_tpop(type_array ); type_array = NULL; - free_tpop(type_enumeration); type_enumeration = NULL; - free_tpop(type_pointer ); type_pointer = NULL; - free_tpop(type_primitive ); type_primitive = NULL; - free_tpop(type_id ); type_id = NULL; - free_tpop(tpop_none ); tpop_none = NULL; - free_tpop(tpop_unknown ); tpop_unknown = NULL; -} +static const tp_op_ops + /** tpop operations for class types */ + class_ops = { + free_class_attrs, + free_class_entities, + NULL, + set_class_mode, + set_class_size, + get_class_n_members, + get_class_member, + get_class_member_index + }, + /** tpop operations for struct types */ + struct_ops = { + free_struct_attrs, + free_struct_entities, + NULL, + set_struct_mode, + set_struct_size, + get_struct_n_members, + get_struct_member, + get_struct_member_index + }, + /** tpop operations for method types */ + method_ops = { + free_method_attrs, + free_method_entities, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL + }, + /** tpop operations for union types */ + union_ops = { + free_union_attrs, + free_union_entities, + NULL, + NULL, + set_union_size, + get_union_n_members, + get_union_member, + get_union_member_index + }, + /** tpop operations for array types */ + array_ops = { + free_array_attrs, + free_array_entities, + free_array_automatic_entities, + NULL, + set_array_size, + NULL, + NULL, + NULL + }, + /** tpop operations for enumeration types */ + enum_ops = { + free_enumeration_attrs, + free_enumeration_entities, + NULL, + set_enumeration_mode, + NULL, + NULL, + NULL, + NULL + }, + /** tpop operations for pointer types */ + pointer_ops = { + free_pointer_attrs, + free_pointer_entities, + NULL, + set_pointer_mode, + NULL, + NULL, + NULL, + NULL + }, + /** tpop operations for pseudo types */ + pseudo_ops = { + NULL, + NULL, + NULL, + NULL, + set_default_size, + NULL, + NULL, + NULL + }, + /** tpop operations for primitive types */ + null_ops = { + NULL, + NULL, + NULL, + NULL, + set_default_size, + NULL, + NULL, + NULL + }; -/* Returns the string for the tp_opcode. */ -const char *get_tpop_name (tp_op *op) { - return get_id_str(op->name); +void init_tpop(void) +{ +#define ID(s) new_id_from_chars(s, sizeof(s) - 1) + type_class = new_tpop(tpo_class , ID("class"), TP_OP_FLAG_COMPOUND, sizeof(cls_attr), &class_ops); + type_struct = new_tpop(tpo_struct , ID("struct"), TP_OP_FLAG_COMPOUND, sizeof(stc_attr), &struct_ops); + type_method = new_tpop(tpo_method , ID("method"), 0, sizeof(mtd_attr), &method_ops); + type_union = new_tpop(tpo_union , ID("union"), TP_OP_FLAG_COMPOUND, sizeof(uni_attr), &union_ops); + type_array = new_tpop(tpo_array , ID("array"), 0, sizeof(arr_attr), &array_ops); + type_enumeration = new_tpop(tpo_enumeration, ID("enumeration"), 0, sizeof(enm_attr), &enum_ops); + type_pointer = new_tpop(tpo_pointer , ID("pointer"), 0, sizeof(ptr_attr), &pointer_ops); + type_primitive = new_tpop(tpo_primitive , ID("primitive"), 0, sizeof(pri_attr), &null_ops); + tpop_code = new_tpop(tpo_code , ID("code"), 0, 0, &null_ops); + tpop_none = new_tpop(tpo_none , ID("None"), 0, 0, &pseudo_ops); + tpop_unknown = new_tpop(tpo_unknown , ID("Unknown"), 0, 0, &pseudo_ops); +#undef ID } -tp_opcode (get_tpop_code)(tp_op *op){ - return __get_tpop_code(op); +void finish_tpop(void) +{ + free_tpop(type_class ); type_class = NULL; + free_tpop(type_struct ); type_struct = NULL; + free_tpop(type_method ); type_method = NULL; + free_tpop(type_union ); type_union = NULL; + free_tpop(type_array ); type_array = NULL; + free_tpop(type_enumeration); type_enumeration = NULL; + free_tpop(type_pointer ); type_pointer = NULL; + free_tpop(type_primitive ); type_primitive = NULL; + free_tpop(tpop_code ); tpop_code = NULL; + free_tpop(tpop_none ); tpop_none = NULL; + free_tpop(tpop_unknown ); tpop_unknown = NULL; } -ident *(get_tpop_ident)(tp_op *op){ - return __get_tpop_ident(op); +const char *get_tpop_name(const tp_op *op) +{ + return get_id_str(op->name); } -/* returns the attribute size of the operator. */ -int (get_tpop_attr_size)(tp_op *op) { - return __get_tpop_attr_size(op); +tp_opcode (get_tpop_code)(const tp_op *op) +{ + return _get_tpop_code(op); }