X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fexternal%2Fread.c;h=fac1e87b33d79adbb54ad798e6bd58d37681f0f2;hb=f4479a465ed166eead2717c3633d632e9710d8c3;hp=7a418aeea01fe2b8e7335e4e7a5fa7871bb3ce59;hpb=8a953adb0fdd8f7e8cad68baa26bb6a8e8f829b0;p=libfirm diff --git a/ir/external/read.c b/ir/external/read.c index 7a418aeea..fac1e87b3 100644 --- a/ir/external/read.c +++ b/ir/external/read.c @@ -1,25 +1,33 @@ -/* -*- c -*- */ - /* - * Project: libFIRM - * File name: ir/external/read.c - * Purpose: Read descriptions of external effects - * Author: Florian - * Modified by: Boris Boesler - * Created: 11.10.2004 - * CVS-ID: $Id$ - * Copyright: (c) 1999-2004 Universität Karlsruhe - * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE. + * Copyright (C) 1995-2007 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 Read descriptions of external effects + * @author Florian, Boris Boesler + * @date 11.10.2004 + * @version $Id$ + */ #ifdef HAVE_CONFIG_H # include "config.h" #endif -/* get prototype for alloca somehow */ -#ifdef HAVE_ALLOCA_H -# include -#endif #ifdef HAVE_STDLIB_H # include #endif @@ -91,7 +99,7 @@ static const char *effect_string[] = { }; #endif /* defined VERBOSE_PRINTING */ -static const ident* +static ident* getNodeModuleIdent (xmlNodePtr node) { const char *mod_str = (const char*) xmlGetProp (node, BAD_CAST "module"); @@ -99,7 +107,7 @@ getNodeModuleIdent (xmlNodePtr node) if (NULL == mod_str) { return (NULL); } else { - const ident *res = new_id_from_str (mod_str); + ident *res = new_id_from_str (mod_str); return (res); } } @@ -165,7 +173,7 @@ getNodeOwnerStr (xmlNodePtr node) static const char *getNodeEntityStr (xmlNodePtr node) { - const char *ent_str = (char*) xmlGetProp (node, BAD_CAST "entity"); + const char *ent_str = (char*) xmlGetProp (node, BAD_CAST "ir_entity"); assert (ent_str); return (ent_str); @@ -177,7 +185,7 @@ static const char */ # ifdef NEEDED static -type_t *getTypeByIdent (const ident *id) +type_t *getTypeByIdent (ident *id) { type_t *curr = types; // @@@ TODO module -> types @@ -194,7 +202,7 @@ type_t *getTypeByIdent (const ident *id) # ifdef NEEDED static -type_t *getTypeById (const ident *id) +type_t *getTypeById (ident *id) { type_t *curr = types; // which ones? @@ -211,7 +219,7 @@ type_t *getTypeById (const ident *id) # ifdef NEEDED static -entity_t *getEntityByIdents (const ident *name, const ident *tp_ident) +entity_t *getEntityByIdents (ident *name, ident *tp_ident) { entity_t *curr = entities; // TODO module -> entities @@ -228,7 +236,7 @@ entity_t *getEntityByIdents (const ident *name, const ident *tp_ident) # endif /* defined NEEDED */ static -entity_t *getEntityById (const ident *id) +entity_t *getEntityById (ident *id) { entity_t *curr = entities; @@ -244,7 +252,7 @@ entity_t *getEntityById (const ident *id) # ifdef NEEDED static -proc_t *getEffectByName (const ident *proc_ident) +proc_t *getEffectByName (ident *proc_ident) { proc_t *curr_effs = procs; @@ -336,7 +344,7 @@ parseValref (xmlDocPtr doc, xmlNodePtr valelm) static eff_t* parseSelect (xmlDocPtr doc, xmlNodePtr selelm) { - const ident *entity_id = new_id_from_str(getNodeEntityStr (selelm)); + ident *entity_id = new_id_from_str(getNodeEntityStr (selelm)); entity_t *ent; xmlNodePtr child; eff_t *valref = NULL; @@ -347,8 +355,8 @@ parseSelect (xmlDocPtr doc, xmlNodePtr selelm) VERBOSE_PRINT ((stdout, "select node \t0x%08x\n", (int) selelm)); ent = getEntityById (entity_id); - assert(ent && "entity not found"); - VERBOSE_PRINT ((stdout, "select entity %s\n", get_id_str(ent -> ent_ident))); + assert(ent && "ir_entity not found"); + VERBOSE_PRINT ((stdout, "select ir_entity %s\n", get_id_str(ent -> ent_ident))); child = selelm->xmlChildrenNode; @@ -369,7 +377,7 @@ parseSelect (xmlDocPtr doc, xmlNodePtr selelm) static eff_t* parseLoad (xmlDocPtr doc, xmlNodePtr loadelm) { - const ident *id; + ident *id; xmlNodePtr child; eff_t *sel; eff_t *load = NEW (eff_t); @@ -383,7 +391,7 @@ parseLoad (xmlDocPtr doc, xmlNodePtr loadelm) if(NODE_NAME (child, select)) { sel = parseSelect (doc, child); load-> effect.load.ent = sel-> effect.select.ent; - VERBOSE_PRINT ((stdout, "load entity \t%s\n", + VERBOSE_PRINT ((stdout, "load ir_entity \t%s\n", get_id_str(load -> effect.load.ent -> ent_ident))); } else { @@ -436,8 +444,8 @@ parseStore (xmlDocPtr doc, xmlNodePtr storeelm) static eff_t* parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm) { - const ident *id; - const ident *type_id; + ident *id; + ident *type_id; eff_t *alloc = NEW (eff_t); /* ...! */ alloc->kind = eff_alloc; @@ -457,7 +465,7 @@ parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm) static eff_t* parseCall (xmlDocPtr doc, xmlNodePtr callelm) { - const ident *id; + ident *id; xmlNodePtr child; eff_t *sel; xmlNodePtr arg; @@ -496,7 +504,7 @@ parseCall (xmlDocPtr doc, xmlNodePtr callelm) free (sel); if (0 != n_args) { - const ident **args = (const ident**) xmalloc(n_args * sizeof(const ident*)); + ident **args = (ident**) xmalloc(n_args * sizeof(ident*)); int i = 0; while (NULL != arg) { @@ -515,9 +523,9 @@ parseCall (xmlDocPtr doc, xmlNodePtr callelm) static eff_t* parseJoin (xmlDocPtr doc, xmlNodePtr joinelm) { - const ident *id; + ident *id; int n_ins; - const ident **ins; + ident **ins; int i; xmlNodePtr child; eff_t *join = NEW (eff_t); @@ -536,7 +544,7 @@ parseJoin (xmlDocPtr doc, xmlNodePtr joinelm) child = child->next; } - ins = (const ident **) xmalloc (n_ins * sizeof (const ident *) ); + ins = (ident **) xmalloc (n_ins * sizeof (ident *) ); i = 0; child = get_valid_child(joinelm); @@ -557,7 +565,7 @@ parseJoin (xmlDocPtr doc, xmlNodePtr joinelm) static eff_t* parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm) { - const ident *id; + ident *id; eff_t *unknown = NEW (eff_t); unknown->kind = eff_unknown; @@ -639,7 +647,7 @@ parseType (xmlDocPtr doc, xmlNodePtr typeelm) types = type; } -/** parse an entity node and insert it into the list */ +/** parse an ir_entity node and insert it into the list */ static void parseEntity (xmlDocPtr doc, xmlNodePtr entelm) { @@ -647,7 +655,7 @@ parseEntity (xmlDocPtr doc, xmlNodePtr entelm) /* parse it */ const char *ent_id = getNodeId (entelm); - /* fprintf (stdout, "entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */ + /* fprintf (stdout, "ir_entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */ VERBOSE_PRINT ((stdout, "ent = \"%s.%s\"\n", getNodeTypeStr (entelm), getNodeEntityStr (entelm))); @@ -730,7 +738,7 @@ parseEffect (xmlDocPtr doc, xmlNodePtr effelm) static -void read_extern (const char *filename) +int read_extern (const char *filename) { /* xmlNsPtr ns = NULL; */ /* no namespace for us */ xmlDocPtr doc; /* whole document */ @@ -743,7 +751,8 @@ void read_extern (const char *filename) LIBXML_TEST_VERSION xmlKeepBlanksDefault (0); VERBOSE_PRINT((stdout, "read file %s\n", filename)); doc = xmlParseFile (filename); - CHECK (doc, "xmlParseFile"); + if (! doc) + return 0; cur = xmlDocGetRootElement (doc); CHECK (cur, "xmlDocGetRootElement"); @@ -768,7 +777,7 @@ void read_extern (const char *filename) while (cur != NULL) { if (NODE_NAME (cur, type)) { parseType (doc, cur); - } else if (NODE_NAME (cur, entity)) { + } else if (NODE_NAME (cur, ir_entity)) { parseEntity (doc, cur); } else if (NODE_NAME (cur, effect)) { parseEffect (doc, cur); @@ -793,6 +802,8 @@ void read_extern (const char *filename) module -> next = modules; modules = module; + + return 1; } /********************************************************************/ @@ -979,7 +990,7 @@ void free_data(void) /********************************************************************/ static -type_t *find_type_in_module(module_t *module, const ident *typeid) +type_t *find_type_in_module(module_t *module, ident *typeid) { type_t *type; @@ -1003,7 +1014,7 @@ static void add_value_to_proc(proc_t *proc, eff_t *eff) } -eff_t *find_valueid_in_proc_effects(const ident *id, proc_t *proc) +eff_t *find_valueid_in_proc_effects(ident *id, proc_t *proc) { eff_t *val; @@ -1052,9 +1063,9 @@ static void create_abstract_return(ir_graph *irg, proc_t *proc, eff_t *eff) static void create_abstract_arg(ir_graph *irg, proc_t *proc, eff_t *eff) { ir_node *arg; - entity *ent; + ir_entity *ent; ir_mode *mode; - type *typ; + ir_type *typ; int num; VERBOSE_PRINT((stdout, "create effect:arg %d in %s\n", @@ -1078,7 +1089,7 @@ static void create_abstract_arg(ir_graph *irg, proc_t *proc, eff_t *eff) static void create_abstract_load(ir_graph *irg, proc_t *proc, eff_t *eff) { ir_node *sel, *load; - entity *ent; + ir_entity *ent; ir_mode *mode; eff_t *addr; @@ -1120,7 +1131,7 @@ static void create_abstract_load(ir_graph *irg, proc_t *proc, eff_t *eff) static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff) { ir_node *sel, *store; - entity *ent; + ir_entity *ent; eff_t *addr, *val; VERBOSE_PRINT((stdout, "create store in %s\n", @@ -1128,7 +1139,7 @@ static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff) if(eff -> effect.store.ent) { ent = eff -> effect.store.ent -> f_ent; - VERBOSE_PRINT((stdout, "store to entity %s\n", get_entity_name(ent))); + VERBOSE_PRINT((stdout, "store to ir_entity %s\n", get_entity_name(ent))); } else { VERBOSE_PRINT((stdout, "store to memory\n")); @@ -1163,7 +1174,7 @@ static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff) static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff) { - type *ftype; + ir_type *ftype; ir_node *alloc; type_t *xtype; symconst_symbol sym; @@ -1176,7 +1187,7 @@ static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff) ftype = xtype -> f_tp; sym.type_p = ftype; - alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_size), ftype, + alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_type_size), ftype, heap_alloc); set_store(new_Proj(alloc, mode_M, 0)); eff -> firmnode = new_Proj(alloc, mode_P, 2); @@ -1202,11 +1213,11 @@ static void create_abstract_unknown(ir_graph *irg, proc_t *proc, eff_t *eff) static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff) { ir_node *sel, *call; - entity *ent; + ir_entity *ent; eff_t *addr; ir_node **irns; int i, num; - type *mtype; + ir_type *mtype; int mik; /* is method somehow known? */ VERBOSE_PRINT((stdout, "create call in %s\n", @@ -1223,7 +1234,7 @@ static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff) addr = find_valueid_in_proc_effects(eff -> effect.call.valrefid, proc); assert(addr && "no address for load"); - /* if addr is Unknown, set propper mode */ + /* if addr is Unknown, set proper mode */ if(iro_Unknown == get_irn_opcode(addr -> firmnode)) { set_irn_mode(addr -> firmnode, mode_P); } @@ -1231,16 +1242,16 @@ static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff) if(ent) { /* the address */ sel = new_simpleSel(get_store(), addr -> firmnode, ent); - /* mthod type */ + /* method type */ mtype = get_entity_type(ent); - mik = true; + mik = 1; } else { /* the address */ sel = addr -> firmnode; - /* mthod type */ + /* method type */ mtype = get_unknown_type(); - mik = false; + mik = 0; } /* the args */ @@ -1397,17 +1408,17 @@ static void create_abstract_raise (ir_graph *irg, proc_t *proc, eff_t *eff) } -static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent) +static void create_abstract_firm(module_t *module, proc_t *proc, ir_entity *fent) { eff_t *eff; ir_graph *irg; int i, num; - /* test entity */ + /* test ir_entity */ assert(visibility_external_allocated == get_entity_visibility(fent) && peculiarity_existent == get_entity_peculiarity(fent) - && "not an abstract entity"); - /* create irg in entity */ + && "not an abstract ir_entity"); + /* create irg in ir_entity */ irg = new_pseudo_ir_graph(fent, 0); set_irg_inline_property(irg, irg_inline_forbidden); @@ -1457,7 +1468,7 @@ static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent) } } - /* close irg in entity */ + /* close irg in ir_entity */ /* Now we can mature the end block as all it's predecessors are known. */ mature_immBlock (get_irg_end_block(irg)); @@ -1465,7 +1476,7 @@ static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent) VERBOSE_PRINT((stdout, "verify graph\n")); irg_vrfy(irg); VERBOSE_PRINT((stdout, "finalize construction\n")); - finalize_cons (irg); + irg_finalize_cons (irg); } /********************************************************************/ @@ -1474,10 +1485,10 @@ static void assign_firm_entity(module_t *module, entity_t *xmlent) { int i, num; type_t *typ; - type *type; - entity *ent; + ir_type *type; + ir_entity *ent; - VERBOSE_PRINT((stdout, "assign entity %s to typeid %s\n", + VERBOSE_PRINT((stdout, "assign ir_entity %s to typeid %s\n", get_id_str(xmlent -> ent_ident), get_id_str(xmlent -> owner))); @@ -1490,7 +1501,7 @@ static void assign_firm_entity(module_t *module, entity_t *xmlent) ent = NULL; for(i = 0; i < num; i++) { ent = get_class_member(type, i); - VERBOSE_PRINT((stdout, "compare entity %s and %s\n", + VERBOSE_PRINT((stdout, "compare ir_entity %s and %s\n", get_id_str(xmlent -> ent_ident), get_entity_name(ent))); if(get_entity_ident(ent) == xmlent -> ent_ident) { @@ -1498,7 +1509,7 @@ static void assign_firm_entity(module_t *module, entity_t *xmlent) } ent = NULL; } - assert(ent && "did not find a entity"); + assert(ent && "did not find a ir_entity"); xmlent -> f_ent = ent; } @@ -1508,7 +1519,7 @@ static void assign_firm_entity(module_t *module, entity_t *xmlent) static void assign_firm_type(type_t *xmltype) { int i; - type *typ = NULL; + ir_type *typ = NULL; int num; VERBOSE_PRINT((stdout, "assign firm type to type %s\n", @@ -1541,9 +1552,9 @@ static void create_abstract_proc_effect(module_t *module, proc_t *proc) { int i, num; - type *class_typ = NULL; + ir_type *class_typ = NULL; type_t *type; - entity *fent; + ir_entity *fent; /* find the class of a procedure */ VERBOSE_PRINT((stdout, "do find owner id %s\n", get_id_str(proc -> ownerid))); @@ -1574,7 +1585,7 @@ void create_abstract_proc_effect(module_t *module, proc_t *proc) assert(is_Class_type(class_typ) && "is not a class type"); type -> f_tp = class_typ; - /* find entity for procedure in class */ + /* find ir_entity for procedure in class */ VERBOSE_PRINT((stdout, "find method %s\n", get_id_str(proc -> proc_ident))); @@ -1635,12 +1646,13 @@ void create_abstract_module(module_t *module) } -void create_abstraction(const char *filename) +int create_abstraction(const char *filename) { module_t *module; /* read and parse XML file */ - read_extern(filename); + if (! read_extern(filename)) + return 0; /* finished reading and parsing here */ /* build FIRM graphs */ @@ -1659,6 +1671,8 @@ void create_abstraction(const char *filename) entities = NULL; procs = NULL; modules = NULL; + + return 1; } @@ -1677,6 +1691,25 @@ void free_abstraction(void) { /* * $Log$ + * Revision 1.27 2007/02/02 12:38:35 matze + * entity is ir_entity now + * + * Revision 1.26 2006/12/15 12:37:40 matze + * fix warnings + * + * Revision 1.25 2006/06/09 11:26:35 firm + * renamed type to ir_type + * + * Revision 1.24 2006/05/29 13:34:49 beck + * renamed symconst_size to symconst_type_size + * + * Revision 1.22 2005/08/16 10:18:35 beck + * create_abstraction() now returns an error code if the file could not + * be opened. + * + * Revision 1.21 2005/03/10 10:05:38 goetz + * chanmged method name + * * Revision 1.20 2005/01/05 14:28:35 beck * renames all is_x*_type() functions to is_X*_type() to prevent name clash with EDG frontend *