Skip to content

Commit 2c61ff2

Browse files
authored
Merge pull request #624 from reuk/irep-ids-improvements
Replace irep_ids_convert program with preprocessor
2 parents 32a68db + 494d772 commit 2c61ff2

File tree

9 files changed

+887
-937
lines changed

9 files changed

+887
-937
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ src/ansi-c/gcc_builtin_headers_ia32-2.inc
3131
src/ansi-c/gcc_builtin_headers_ia32.inc
3232
src/ansi-c/gcc_builtin_headers_mips.inc
3333
src/ansi-c/gcc_builtin_headers_power.inc
34-
src/util/irep_ids.h
35-
src/util/irep_ids.inc
3634

3735
# regression/test files
3836
*.out

src/util/Makefile

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,9 @@ INCLUDES= -I ..
3030
include ../config.inc
3131
include ../common
3232

33-
CLEANFILES = util$(LIBEXT) \
34-
irep_ids.h irep_ids.inc \
35-
irep_ids_convert$(EXEEXT) irep_ids_convert$(OBJEXT) irep_ids_convert.d
33+
CLEANFILES = util$(LIBEXT)
3634

3735
all: util$(LIBEXT)
3836

39-
###############################################################################
40-
41-
irep_ids.h: irep_ids.txt irep_ids_convert$(EXEEXT)
42-
./irep_ids_convert$(EXEEXT) header < $< > $@
43-
44-
irep_ids.inc: irep_ids.txt irep_ids_convert$(EXEEXT)
45-
./irep_ids_convert$(EXEEXT) table < $< > $@
46-
47-
irep_ids.cpp: irep_ids.inc irep_ids.h
48-
49-
irep_ids_convert$(EXEEXT): irep_ids_convert.cpp
50-
$(LINKNATIVE)
51-
52-
generated_files: irep_ids.h irep_ids.inc
53-
54-
# Most of the others will need irep_ids.h,
55-
# which we first need to generate.
56-
$(OBJ): irep_ids.h
57-
5837
util$(LIBEXT): $(OBJ)
5938
$(LINKLIB)

src/util/dstring.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Author: Daniel Kroening, kroening@kroening.com
1313

1414
#include "string_container.h"
1515

16-
class dstringt
16+
// Marked final to disable inheritance.
17+
// No virtual destructor, so runtime-polymorphic use would be unsafe.
18+
class dstringt final
1719
{
1820
public:
1921
// this is safe for static objects
@@ -25,12 +27,12 @@ class dstringt
2527
}
2628

2729
// this is safe for static objects
28-
// the 2nd argument is to avoid accidental conversions
2930
#ifdef __GNUC__
3031
constexpr
3132
#endif
32-
dstringt(unsigned _no, unsigned):no(_no)
33+
static dstringt make_from_table_index(unsigned no)
3334
{
35+
return dstringt(no);
3436
}
3537

3638
#if 0
@@ -135,7 +137,14 @@ class dstringt
135137
return no;
136138
}
137139

138-
protected:
140+
private:
141+
#ifdef __GNUC__
142+
constexpr
143+
#endif
144+
explicit dstringt(unsigned _no):no(_no)
145+
{
146+
}
147+
139148
unsigned no;
140149

141150
// the reference returned is guaranteed to be stable

src/util/irep.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Author: Daniel Kroening, kroening@kroening.com
1414
#include <cassert>
1515
#include <iosfwd>
1616

17-
#define USE_DSTRING
17+
#include "irep_ids.h"
18+
1819
#define SHARING
1920
// #define HASH_CODE
2021
#define USE_MOVE
@@ -26,12 +27,6 @@ Author: Daniel Kroening, kroening@kroening.com
2627
#include <map>
2728
#endif
2829

29-
#ifdef USE_DSTRING
30-
#include "dstring.h"
31-
#endif
32-
33-
#include "irep_ids.h"
34-
3530
#ifdef USE_DSTRING
3631
typedef dstringt irep_idt;
3732
typedef dstringt irep_namet;

src/util/irep_ids.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,32 @@ Author: Daniel Kroening, kroening@kroening.com
1313

1414
const char *irep_ids_table[]=
1515
{
16-
#include "irep_ids.inc"
17-
NULL
16+
#define IREP_ID_ONE(id) #id,
17+
#define IREP_ID_TWO(id, str) #str,
18+
19+
#include "irep_ids.def"
20+
21+
NULL,
1822
};
1923

24+
#ifdef USE_DSTRING
25+
26+
#define IREP_ID_ONE(the_id) \
27+
const dstringt ID_##the_id=dstringt::make_from_table_index( \
28+
static_cast<unsigned>(idt::id_##the_id));
29+
#define IREP_ID_TWO(the_id, str) \
30+
const dstringt ID_##the_id=dstringt::make_from_table_index( \
31+
static_cast<unsigned>(idt::id_##the_id));
32+
33+
#else
34+
35+
#define IREP_ID_ONE(the_id) const std::string ID_##the_id(#the_id);
36+
#define IREP_ID_TWO(the_id, str) const std::string ID_##the_id(#the_id);
37+
38+
#endif
39+
40+
#include "irep_ids.def" // NOLINT(build/include)
41+
2042
/*******************************************************************\
2143
2244
Function: initialize_string_container

0 commit comments

Comments
 (0)