PIPS
newgen_generic_mapping.h
Go to the documentation of this file.
1 /*
2 
3  $Id: newgen_generic_mapping.h 1357 2016-03-02 08:18:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of NewGen.
8 
9  NewGen is free software: you can redistribute it and/or modify it under the
10  terms of the GNU General Public License as published by the Free Software
11  Foundation, either version 3 of the License, or any later version.
12 
13  NewGen is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16  License for more details.
17 
18  You should have received a copy of the GNU General Public License along with
19  NewGen. If not, see <http://www.gnu.org/licenses/>.
20 
21 */
22 /*
23  * These are the functions defined in the Newgen mapping library.
24  *
25  * This is a temporary implementation used for the Pips Project. The
26  * general notion of mapping (i.e., functions) is going to be implemented
27  * shortly inside Newgen.
28  *
29  * This version uses pointers to statements as keys in hash_tables which
30  * causes bugs when code in unloaded on and then reloaded from disk.
31  * Francois Irigoin, 1 February 1993
32  *
33  * a useful macro which generates the declaration of a static variable of type
34  * statement_mapping, and related functions :
35  * set_**_map
36  * load_statement_**_map
37  * store_statement_**_map
38  * reset_**_map
39  *
40  * BA, august 26, 1993
41  *
42  * this macro is redefined here as GENERIC_CURRENT_MAPPING, which uses
43  * that type as a parameter, to allow other mappings than statement's ones.
44  * I need entity_mapping, control_mapping
45  * there is no way to define macros inside the macro, so I cannot
46  * generate the usual macros:-(, The code defining them will have to be
47  * replicated (done in mapping.h).
48  *
49  * FC, Feb 21, 1994
50  */
51 
52 #ifndef GENERIC_MAPPING_INCLUDED
53 #define GENERIC_MAPPING_INCLUDED
54 
55 /* PIPS level:
56  *
57  * GENERIC_MAPPING(PREFIX, name, result, type)
58  *
59  * This macros are obsolete. Declare the mappings in newgen instead,
60  * and use the generic functions!
61  *
62  * name: name of the mapping
63  * result: type of the result
64  * type: type of the mapping key
65  * // CTYPE: type of the mapping key in capital letters
66  *
67  * a static variable 'name'_map of type 'type' is declared
68  * and can be accessed thru the definefd functions.
69  *
70  * the mapping is 'name' = 'type' -> 'result'
71  */
72 #define GENERIC_MAPPING(PREFIX, name, result, type) \
73 static type##_mapping name##_map = hash_table_undefined; \
74 PREFIX bool __attribute__ ((unused)) name##_map_undefined_p() { \
75  return name##_map == hash_table_undefined; \
76 } \
77 PREFIX void __attribute__ ((unused)) set_##name##_map(type##_mapping m) { \
78  message_assert("mapping undefined", name##_map == hash_table_undefined); \
79  name##_map = m; \
80 } \
81 PREFIX type##_mapping __attribute__ ((unused)) get_##name##_map() { \
82  return name##_map; \
83 } \
84 PREFIX void __attribute__ ((unused)) reset_##name##_map() { \
85  name##_map = hash_table_undefined; \
86 } \
87 PREFIX void __attribute__ ((unused)) free_##name##_map() { \
88  hash_table_free(name##_map); name##_map = hash_table_undefined; \
89 } \
90 PREFIX void __attribute__ ((unused)) make_##name##_map() { \
91  name##_map = hash_table_make(hash_pointer, HASH_DEFAULT_SIZE); \
92 } \
93 PREFIX result __attribute__ ((unused)) load_##type##_##name(type s) { \
94  result t; \
95  message_assert("key defined", s != type##_undefined); \
96  t = (result)(intptr_t) hash_get((hash_table) (name##_map), (void*) (s)); \
97  if (t ==(result)(intptr_t) HASH_UNDEFINED_VALUE) \
98  t = result##_undefined; \
99  return t; \
100 } \
101 PREFIX void __attribute__ ((unused)) delete_##type##_##name(type s) { \
102  message_assert("key defined", s != type##_undefined); \
103  (void) hash_del((hash_table) (name##_map), (void*) (s)); \
104 } \
105 PREFIX bool __attribute__ ((unused)) type##_##name##_undefined_p(type s) { \
106  return(load_##type##_##name(s)==result##_undefined); \
107 } \
108 PREFIX void __attribute__ ((unused)) store_##type##_##name(type s, result t) { \
109  message_assert("key defined", s != type##_undefined); \
110  message_assert("value defined", t != result##_undefined); \
111  hash_put((hash_table) name##_map, (void*) s, (void*)(intptr_t) t); \
112 } \
113 PREFIX void __attribute__ ((unused)) update_##type##_##name(type s, result t) { \
114  message_assert("key defined", s != type##_undefined); \
115  message_assert("value defined", t != result##_undefined); \
116  hash_update((hash_table) name##_map, (void*) s, (void*)(intptr_t) t); \
117 }
118 
119 #define GENERIC_CURRENT_MAPPING(name, result, type) \
120  GENERIC_MAPPING(extern, name, result, type)
121 
122 /* to allow mappings local to a file.
123  * it seems not to make sense, but I like the interface.
124  * FC 27/12/94
125  */
126 #define GENERIC_LOCAL_MAPPING(name, result, type) \
127  GENERIC_MAPPING(static, name, result, type)
128 
129 /* end GENERIC_MAPPING_INCLUDED */
130 #endif