- place some panic()'s instead of assert(0)
[r25439]
#include "irprog.h"
#include "irgraph_t.h"
#include "ircons.h"
#include "irprog.h"
#include "irgraph_t.h"
#include "ircons.h"
#include "error.h"
#include "adt/set.h"
#include "error.h"
#include "adt/set.h"
-#define LEXERROR ((unsigned) ~0)
+#define SYMERROR ((unsigned) ~0)
tt_volatility
} typetag_t;
tt_volatility
} typetag_t;
-typedef struct lex_entry
- const char *str;
- typetag_t typetag;
- unsigned code;
-} lex_entry;
+ const char *str; /**< The name of this symbol. */
+ typetag_t typetag; /**< The type tag of this symbol. */
+ unsigned code; /**< The value of this symbol. */
+} symbol_t;
typedef struct id_entry
{
typedef struct id_entry
{
-/** A set of lex_entry elements. */
-static set *lexset;
+/** The symbol table, a set of symbol_t elements. */
+static set *symtbl;
-static unsigned hash(const char *str, int len)
+/**
+ * Calculate a hash value for a string.
+ */
+static unsigned string_hash(const char *str, int len)
{
return str[0] * 27893 ^ str[len-1] * 81 ^ str[len >> 1];
}
{
return str[0] * 27893 ^ str[len-1] * 81 ^ str[len >> 1];
}
-static int lex_cmp(const void *elt, const void *key, size_t size)
+/**
+ * Compare two symbol table entries.
+ */
+static int symbol_cmp(const void *elt, const void *key, size_t size)
- const lex_entry *entry = (const lex_entry *) elt;
- const lex_entry *keyentry = (const lex_entry *) key;
+ const symbol_t *entry = (const symbol_t *) elt;
+ const symbol_t *keyentry = (const symbol_t *) key;
(void) size;
return strcmp(entry->str, keyentry->str);
}
(void) size;
return strcmp(entry->str, keyentry->str);
}
return entry->id - keyentry->id;
}
return entry->id - keyentry->id;
}
-/** Initializes the lexer. May be called more than once without problems. */
-static void init_lexer(void)
+/** Initializes the symbol table. May be called more than once without problems. */
+static void symtbl_init(void)
/* Only initialize once */
/* Only initialize once */
- if(lexset != NULL) return;
+ if(symtbl != NULL)
+ return;
- lexset = new_set(lex_cmp, 32);
+ symtbl = new_set(symbol_cmp, 32);
#define INSERT(s, tt, cod) \
key.str = (s); \
key.typetag = (tt); \
key.code = (cod); \
#define INSERT(s, tt, cod) \
key.str = (s); \
key.typetag = (tt); \
key.code = (cod); \
- set_insert(lexset, &key, sizeof(key), hash(s, sizeof(s)-1))
+ set_insert(symtbl, &key, sizeof(key), string_hash(s, sizeof(s)-1))
#define INSERTENUM(tt, e) INSERT(#e, tt, e)
#define INSERTENUM(tt, e) INSERT(#e, tt, e)
-/** Returns the according enum entry for the given string and tag, or LEXERROR if none was found. */
-static unsigned lex(const char *str, typetag_t typetag)
+/** Returns the according symbol value for the given string and tag, or SYMERROR if none was found. */
+static unsigned symbol(const char *str, typetag_t typetag)
- entry = set_find(lexset, &key, sizeof(key), hash(str, strlen(str)));
+ entry = set_find(symtbl, &key, sizeof(key), string_hash(str, strlen(str)));
if (entry && entry->typetag == typetag) {
return entry->code;
}
if (entry && entry->typetag == typetag) {
return entry->code;
}
}
static void *get_id(io_env_t *env, long id)
}
static void *get_id(io_env_t *env, long id)
- // TODO: inheritance stuff not supported yet
+ /* TODO: inheritance stuff not supported yet */
printf("Inheritance of classes not supported yet!\n");
break;
printf("Inheritance of classes not supported yet!\n");
break;
static void export_entity(io_env_t *env, ir_entity *ent)
{
ir_type *owner = get_entity_owner(ent);
static void export_entity(io_env_t *env, ir_entity *ent)
{
ir_type *owner = get_entity_owner(ent);
- fprintf(env->file, "\tentity %ld \"%s\" %ld %ld %d %d %s %s %s %s %s\n",
+ fprintf(env->file, "\tentity %ld \"%s\" %ld %ld %d %u %s %s %s %s %s\n",
get_entity_nr(ent),
get_entity_name(ent),
get_type_nr(get_entity_type(ent)),
get_type_nr(owner),
get_entity_offset(ent),
get_entity_nr(ent),
get_entity_name(ent),
get_type_nr(get_entity_type(ent)),
get_type_nr(owner),
get_entity_offset(ent),
- (int) get_entity_offset_bits_remainder(ent),
+ (unsigned) get_entity_offset_bits_remainder(ent),
get_allocation_name(get_entity_allocation(ent)),
get_visibility_name(get_entity_visibility(ent)),
get_variability_name(get_entity_variability(ent)),
get_allocation_name(get_entity_allocation(ent)),
get_visibility_name(get_entity_visibility(ent)),
get_variability_name(get_entity_variability(ent)),
unsigned opcode = get_irn_opcode(irn);
char buf[1024];
unsigned opcode = get_irn_opcode(irn);
char buf[1024];
- if(env->ignoreblocks && opcode == iro_Block) return;
+ if(env->ignoreblocks && opcode == iro_Block)
+ return;
for(i = -1; i < n; i++)
{
ir_node *pred = get_irn_n(irn, i);
for(i = -1; i < n; i++)
{
ir_node *pred = get_irn_n(irn, i);
+ if(pred == NULL) {
+ /* Anchor node may ave NULL predecessors */
+ assert(is_Anchor(irn));
fprintf(env->file, "%ld ", get_irn_node_nr(pred));
fprintf(env->file, "%ld ", get_irn_node_nr(pred));
}
fprintf(env->file, "] { ");
}
fprintf(env->file, "] { ");
+/**
+ * Read and decode an enum constant.
+ */
static unsigned read_enum(io_env_t *env, typetag_t typetag)
{
static char buf[128];
static unsigned read_enum(io_env_t *env, typetag_t typetag)
{
static char buf[128];
- unsigned code = lex(read_str_to(env, buf, sizeof(buf)), typetag);
- if(code != LEXERROR) return code;
+ unsigned code = symbol(read_str_to(env, buf, sizeof(buf)), typetag);
+ if(code != SYMERROR)
+ return code;
printf("Invalid %s: \"%s\" in %i:%i\n", get_typetag_name(typetag), buf, env->line, env->col);
return 0;
printf("Invalid %s: \"%s\" in %i:%i\n", get_typetag_name(typetag), buf, env->line, env->col);
return 0;
ident *id = new_id_from_str(name);
ident *id = new_id_from_str(name);
- switch(lex(tpop, tt_tpo))
+ switch(symbol(tpop, tt_tpo))
- switch(lex(nodename, tt_iro))
+ switch(symbol(nodename, tt_iro))
if(!newnode)
{
notsupported:
if(!newnode)
{
notsupported:
- printf("Node type not supported yet: %s in line %i:%i\n", nodename, env->line, env->col);
- assert(0 && "Invalid node type");
+ panic("Node type not supported yet: %s in line %i:%i\n", nodename, env->line, env->col);
io_env_t *env = &ioenv;
int i, n;
io_env_t *env = &ioenv;
int i, n;
memset(env, 0, sizeof(*env));
env->idset = new_set(id_cmp, 128);
memset(env, 0, sizeof(*env));
env->idset = new_set(id_cmp, 128);