2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Implements simple sequence numbers for Firm debug info.
23 * @author Michael Beck
27 * Sequence numbers for Firm.
29 * A sequence number is an unique number representing a filename
30 * and a line number. The number 0 represents empty information.
31 * This module is an optional "snap-in" for the Firm debug info.
38 #include "seqnumbers.h"
41 * A entry in the sequence number table.
44 ident *filename; /**< the filename */
45 unsigned lineno; /**< the line number */
48 static set *seqnos = NULL;
50 /** hash a seqno entry */
51 #define HASH(key) (HASH_PTR((key).filename) ^ (key).lineno)
54 * Compare two seqno entries.
56 static int seqno_cmp(const void *elt, const void *key, size_t size)
58 seqno_t e1 = (seqno_t)elt;
59 seqno_t e2 = (seqno_t)key;
62 return (e1->filename != e2->filename) | (e1->lineno - e2->lineno);
66 * Create a new sequence number from a filename and a line number.
68 seqno_t firm_seqno_enter(const char *filename, unsigned lineno)
72 key.filename = new_id_from_str(filename);
75 return set_insert(seqnos, &key, sizeof(key), HASH(key));
79 * Create a new sequence number from a filename ident and a line number.
81 seqno_t firm_seqno_enter_id(ident *filename, unsigned lineno)
85 key.filename = filename;
88 return set_insert(seqnos, &key, sizeof(key), HASH(key));
92 * Retrieve filename and line number form a sequence number
94 const char *firm_seqno_retrieve(seqno_t seqno, unsigned *lineno)
96 if (seqnos && seqno) {
97 *lineno = seqno->lineno;
98 return get_id_str(seqno->filename);
105 * Creates the seqno pool.
107 void firm_seqno_init(void)
112 seqnos = new_set(seqno_cmp, 8);
116 * Terminates the seqno pool.
117 * Sequence numbers cannot be resolved anymore.
119 void firm_seqno_term(void)