2 * Copyright (C) 1995-2007 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.
40 #include "seqnumbers.h"
43 * A entry in the sequence number table.
46 ident *filename; /**< the filename */
47 unsigned lineno; /**< the line number */
50 static set *seqnos = NULL;
52 /** hash a seqno entry */
53 #define HASH(key) (HASH_PTR((key).filename) ^ (key).lineno)
56 * Compare two seqno entries.
58 static int seqno_cmp(const void *elt, const void *key, size_t size)
60 seqno_t e1 = (seqno_t)elt;
61 seqno_t e2 = (seqno_t)key;
64 return (e1->filename != e2->filename) | (e1->lineno - e2->lineno);
68 * Create a new sequence number from a filename and a line number.
70 seqno_t firm_seqno_enter(const char *filename, unsigned lineno)
74 key.filename = new_id_from_str(filename);
77 return set_insert(seqnos, &key, sizeof(key), HASH(key));
81 * Create a new sequence number from a filename ident and a line number.
83 seqno_t firm_seqno_enter_id(ident *filename, unsigned lineno)
87 key.filename = filename;
90 return set_insert(seqnos, &key, sizeof(key), HASH(key));
94 * Retrieve filename and line number form a sequence number
96 const char *firm_seqno_retrieve(seqno_t seqno, unsigned *lineno)
98 if (seqnos && seqno) {
99 *lineno = seqno->lineno;
100 return get_id_str(seqno->filename);
107 * Creates the seqno pool.
109 void firm_seqno_init(void)
114 seqnos = new_set(seqno_cmp, 8);
118 * Terminates the seqno pool.
119 * Sequence numbers cannot be resolved anymore.
121 void firm_seqno_term(void)