3 * File name: ir/debug/seqnumbers.c
4 * Purpose: Implements simple sequence numbers for Firm debug info.
9 * Copyright: (c) 2001-2005 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 * Sequence numbers for Firm.
18 * A sequence number is an unique number representing a filename
19 * and a line number. The number 0 represents empty information.
20 * This module is an optional "snap-in" for the Firm debug info.
30 #include "seqnumbers.h"
33 * A entry in the sequence number table.
36 ident *filename; /**< the filename */
37 unsigned lineno; /**< the line number */
40 static set *seqnos = NULL;
42 /** hash a seqno entry */
43 #define HASH(key) (HASH_PTR((key).filename) ^ (key).lineno)
46 * Compare two seqno entries.
48 static int seqno_cmp(const void *elt, const void *key, size_t size)
50 seqno_t e1 = (seqno_t)elt;
51 seqno_t e2 = (seqno_t)key;
53 return (e1->filename != e2->filename) | (e1->lineno - e2->lineno);
57 * Create a new sequence number from a filename and a line number.
59 seqno_t firm_seqno_enter(const char *filename, unsigned lineno)
63 key.filename = new_id_from_str(filename);
66 return set_insert(seqnos, &key, sizeof(key), HASH(key));
70 * Create a new sequence number from a filename ident and a line number.
72 seqno_t firm_seqno_enter_id(ident *filename, unsigned lineno)
76 key.filename = filename;
79 return set_insert(seqnos, &key, sizeof(key), HASH(key));
83 * Retrieve filename and line number form a sequence number
85 const char *firm_seqno_retrieve(seqno_t seqno, unsigned *lineno)
87 if (seqnos && seqno) {
88 *lineno = seqno->lineno;
89 return get_id_str(seqno->filename);
96 * Creates the seqno pool.
98 void firm_seqno_init(void)
103 seqnos = new_set(seqno_cmp, 8);
107 * Terminates the seqno pool.
108 * Sequence numbers cannot be resolved anymore.
110 void firm_seqno_term(void)