llvm.org GIT mirror llvm / 551ccae
Changes For Bug 352 Move include/Config and include/Support into include/llvm/Config, include/llvm/ADT and include/llvm/Support. From here on out, all LLVM public header files must be under include/llvm/. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16137 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Spencer 15 years ago
424 changed file(s) with 772 addition(s) and 7668 deletion(s). Raw diff Collapse all Expand all
77 dnl NOTE: This relies upon undocumented autoconf behavior.
88 if test ${srcdir} != "."
99 then
10 if test -f ${srcdir}/include/Config/config.h
10 if test -f ${srcdir}/include/llvm/Config/config.h
1111 then
1212 AC_MSG_ERROR([Already configured in ${srcdir}])
1313 fi
2626 done
2727
2828 dnl Configure header files
29 AC_CONFIG_HEADERS(include/Config/config.h)
29 AC_CONFIG_HEADERS(include/llvm/Config/config.h)
3030
3131 dnl Configure other output file
3232 AC_CONFIG_FILES(Makefile.config
33 include/Support/DataTypes.h
34 include/Support/ThreadSupport.h
35 include/Support/hash_map
36 include/Support/hash_set
37 include/Support/iterator)
33 include/llvm/Support/DataTypes.h
34 include/llvm/Support/ThreadSupport.h
35 include/llvm/ADT/hash_map
36 include/llvm/ADT/hash_set
37 include/llvm/ADT/iterator)
3838
3939 dnl Do special configuration of Makefiles
4040 AC_CONFIG_MAKEFILE(Makefile)
15431543
15441544 if test ${srcdir} != "."
15451545 then
1546 if test -f ${srcdir}/include/Config/config.h
1546 if test -f ${srcdir}/include/llvm/Config/config.h
15471547 then
15481548 { { echo "$as_me:$LINENO: error: Already configured in ${srcdir}" >&5
15491549 echo "$as_me: error: Already configured in ${srcdir}" >&2;}
15651565 fi
15661566 done
15671567
1568 ac_config_headers="$ac_config_headers include/Config/config.h"
1569
1570
1571 ac_config_files="$ac_config_files Makefile.config include/Support/DataTypes.h include/Support/ThreadSupport.h include/Support/hash_map include/Support/hash_set include/Support/iterator"
1568 ac_config_headers="$ac_config_headers include/llvm/Config/config.h"
1569
1570
1571 ac_config_files="$ac_config_files Makefile.config include/llvm/Support/DataTypes.h include/llvm/Support/ThreadSupport.h include/llvm/ADT/hash_map include/llvm/ADT/hash_set include/llvm/ADT/iterator"
15721572
15731573
15741574 ac_config_commands="$ac_config_commands Makefile"
2444924449 case "$ac_config_target" in
2445024450 # Handling of arguments.
2445124451 "Makefile.config" ) CONFIG_FILES="$CONFIG_FILES Makefile.config" ;;
24452 "include/Support/DataTypes.h" ) CONFIG_FILES="$CONFIG_FILES include/Support/DataTypes.h" ;;
24453 "include/Support/ThreadSupport.h" ) CONFIG_FILES="$CONFIG_FILES include/Support/ThreadSupport.h" ;;
24454 "include/Support/hash_map" ) CONFIG_FILES="$CONFIG_FILES include/Support/hash_map" ;;
24455 "include/Support/hash_set" ) CONFIG_FILES="$CONFIG_FILES include/Support/hash_set" ;;
24456 "include/Support/iterator" ) CONFIG_FILES="$CONFIG_FILES include/Support/iterator" ;;
24452 "include/llvm/Support/DataTypes.h" ) CONFIG_FILES="$CONFIG_FILES include/llvm/Support/DataTypes.h" ;;
24453 "include/llvm/Support/ThreadSupport.h" ) CONFIG_FILES="$CONFIG_FILES include/llvm/Support/ThreadSupport.h" ;;
24454 "include/llvm/ADT/hash_map" ) CONFIG_FILES="$CONFIG_FILES include/llvm/ADT/hash_map" ;;
24455 "include/llvm/ADT/hash_set" ) CONFIG_FILES="$CONFIG_FILES include/llvm/ADT/hash_set" ;;
24456 "include/llvm/ADT/iterator" ) CONFIG_FILES="$CONFIG_FILES include/llvm/ADT/iterator" ;;
2445724457 "lib/System/platform" ) CONFIG_LINKS="$CONFIG_LINKS lib/System/platform:lib/System/$platform_type" ;;
2445824458 "Makefile" ) CONFIG_COMMANDS="$CONFIG_COMMANDS Makefile" ;;
2445924459 "Makefile.common" ) CONFIG_COMMANDS="$CONFIG_COMMANDS Makefile.common" ;;
2450624506 "tools/Makefile" ) CONFIG_COMMANDS="$CONFIG_COMMANDS tools/Makefile" ;;
2450724507 "utils/Makefile" ) CONFIG_COMMANDS="$CONFIG_COMMANDS utils/Makefile" ;;
2450824508 "projects/Makefile" ) CONFIG_COMMANDS="$CONFIG_COMMANDS projects/Makefile" ;;
24509 "include/Config/config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS include/Config/config.h" ;;
24509 "include/llvm/Config/config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS include/llvm/Config/config.h" ;;
2451024510 *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
2451124511 echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
2451224512 { (exit 1); exit 1; }; };;
+0
-47
include/Config/alloca.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * Description:
9 * This header file includes the infamous alloc.h header file if the
10 * autoconf system has found it. It hides all of the autoconf details
11 * from the rest of the application source code.
12 */
13
14 #ifndef _CONFIG_ALLOC_H
15 #define _CONFIG_ALLOC_H
16
17 #include "Config/config.h"
18
19 /*
20 * This is a modified version of that suggested by the Autoconf manual.
21 * 1) The #pragma is indented so that pre-ANSI C compilers ignore it.
22 * 2) If alloca.h cannot be found, then try stdlib.h. Some platforms
23 * (notably FreeBSD) defined alloca() there.
24 */
25 #ifdef _MSC_VER
26 /* noop on Visual C++ */
27 #elif defined(HAVE_ALLOCA_H)
28 #include
29 #elif !defined(__GNUC__)
30 # ifdef _AIX
31 # pragma alloca
32 # else
33 # ifndef alloca
34 char * alloca ();
35 # endif
36 # endif
37 #else
38 # ifdef HAVE_STDLIB_H
39 # include
40 # else
41 # error "The function alloca() is required but not found!"
42 # endif
43 #endif
44
45 #endif
46
+0
-240
include/Config/config.h.in less more
None /* include/Config/config.h.in. Generated from autoconf/configure.ac by autoheader. */
1
2 /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
3 systems. This function is required for `alloca.c' support on those systems.
4 */
5 #undef CRAY_STACKSEG_END
6
7 /* Define to 1 if using `alloca.c'. */
8 #undef C_ALLOCA
9
10 /* Define to 1 if you have `alloca', as a function or macro. */
11 #undef HAVE_ALLOCA
12
13 /* Define to 1 if you have and it should be used (not on Ultrix).
14 */
15 #undef HAVE_ALLOCA_H
16
17 /* Define to 1 if you have the `backtrace' function. */
18 #undef HAVE_BACKTRACE
19
20 /* Define to 1 if you have the header file. */
21 #undef HAVE_DLFCN_H
22
23 /* Define if dlopen() is available on this platform. */
24 #undef HAVE_DLOPEN
25
26 /* Define to 1 if you have the header file. */
27 #undef HAVE_EXECINFO_H
28
29 /* Define to 1 if you have the header file. */
30 #undef HAVE_FCNTL_H
31
32 /* Define to 1 if your compiler defines finite in the header file.
33 */
34 #undef HAVE_FINITE_IN_IEEEFP_H
35
36 /* Define to 1 if you have the `getcwd' function. */
37 #undef HAVE_GETCWD
38
39 /* Define to 1 if you have the `getpagesize' function. */
40 #undef HAVE_GETPAGESIZE
41
42 /* Define to 1 if you have the `getrusage' function. */
43 #undef HAVE_GETRUSAGE
44
45 /* Define to 1 if you have the `gettimeofday' function. */
46 #undef HAVE_GETTIMEOFDAY
47
48 /* Define to 1 if the system has the type `int64_t'. */
49 #undef HAVE_INT64_T
50
51 /* Define to 1 if you have the header file. */
52 #undef HAVE_INTTYPES_H
53
54 /* Define to 1 if you have the `isatty' function. */
55 #undef HAVE_ISATTY
56
57 /* Define to 1 if your compiler defines isinf in the header file. */
58 #undef HAVE_ISINF_IN_CMATH
59
60 /* Define to 1 if your compiler defines isinf in the header file. */
61 #undef HAVE_ISINF_IN_MATH_H
62
63 /* Define to 1 if your compiler defines isnan in the header file. */
64 #undef HAVE_ISNAN_IN_CMATH
65
66 /* Define to 1 if your compiler defines isnan in the header file. */
67 #undef HAVE_ISNAN_IN_MATH_H
68
69 /* Define to 1 if you have the `elf' library (-lelf). */
70 #undef HAVE_LIBELF
71
72 /* Define to 1 if you have the header file. */
73 #undef HAVE_LIMITS_H
74
75 /* Define to 1 if you have the header file. */
76 #undef HAVE_LINK_H
77
78 /* Define if you can use -Wl,-R. to pass -R. to the linker, in order to add
79 the current directory to the dynamic linker search path. */
80 #undef HAVE_LINK_R
81
82 /* Define if mallinfo() is available on this platform. */
83 #undef HAVE_MALLINFO
84
85 /* Define to 1 if you have the header file. */
86 #undef HAVE_MALLOC_H
87
88 /* Define to 1 if you have the header file. */
89 #undef HAVE_MEMORY_H
90
91 /* Define to 1 if you have the `mkstemp' function. */
92 #undef HAVE_MKSTEMP
93
94 /* Define to 1 if you have a working `mmap' system call. */
95 #undef HAVE_MMAP
96
97 /* Define if mmap() uses MAP_ANONYMOUS to map anonymous pages, or undefine if
98 it uses MAP_ANON */
99 #undef HAVE_MMAP_ANONYMOUS
100
101 /* Define if mmap() can map files into memory */
102 #undef HAVE_MMAP_FILE
103
104 /* define if the compiler implements namespaces */
105 #undef HAVE_NAMESPACES
106
107 /* Define to have the %a format string */
108 #undef HAVE_PRINTF_A
109
110 /* Define to 1 if you have the header file. */
111 #undef HAVE_STDINT_H
112
113 /* Define to 1 if you have the header file. */
114 #undef HAVE_STDLIB_H
115
116 /* Define to 1 if your compiler defines std::isinf in the header file.
117 */
118 #undef HAVE_STD_ISINF_IN_CMATH
119
120 /* Define to 1 if your compiler defines std::isnan in the header file.
121 */
122 #undef HAVE_STD_ISNAN_IN_CMATH
123
124 /* Define to 1 if you have the `strdup' function. */
125 #undef HAVE_STRDUP
126
127 /* Define to 1 if you have the header file. */
128 #undef HAVE_STRINGS_H
129
130 /* Define to 1 if you have the header file. */
131 #undef HAVE_STRING_H
132
133 /* Define to 1 if you have the `strtoll' function. */
134 #undef HAVE_STRTOLL
135
136 /* Define to 1 if you have the `strtoq' function. */
137 #undef HAVE_STRTOQ
138
139 /* Define to 1 if you have the header file. */
140 #undef HAVE_SYS_MMAN_H
141
142 /* Define to 1 if you have the header file. */
143 #undef HAVE_SYS_RESOURCE_H
144
145 /* Define to 1 if you have the header file. */
146 #undef HAVE_SYS_STAT_H
147
148 /* Define to 1 if you have the header file. */
149 #undef HAVE_SYS_TIME_H
150
151 /* Define to 1 if you have the header file. */
152 #undef HAVE_SYS_TYPES_H
153
154 /* Define to 1 if you have that is POSIX.1 compatible. */
155 #undef HAVE_SYS_WAIT_H
156
157 /* Define to 1 if the system has the type `uint64_t'. */
158 #undef HAVE_UINT64_T
159
160 /* Define to 1 if you have the header file. */
161 #undef HAVE_UNISTD_H
162
163 /* Define to 1 if you have the header file. */
164 #undef HAVE_WINDOWS_H
165
166 /* Installation directory for binary executables */
167 #undef LLVM_BINDIR
168
169 /* Time at which LLVM was configured */
170 #undef LLVM_CONFIGTIME
171
172 /* Installation directory for documentation */
173 #undef LLVM_DATADIR
174
175 /* Installation directory for config files */
176 #undef LLVM_ETCDIR
177
178 /* Installation directory for include files */
179 #undef LLVM_INCLUDEDIR
180
181 /* Installation directory for .info files */
182 #undef LLVM_INFODIR
183
184 /* Installation directory for libraries */
185 #undef LLVM_LIBDIR
186
187 /* Installation directory for man pages */
188 #undef LLVM_MANDIR
189
190 /* Installation prefix directory */
191 #undef LLVM_PREFIX
192
193 /* Define to the address where bug reports for this package should be sent. */
194 #undef PACKAGE_BUGREPORT
195
196 /* Define to the full name of this package. */
197 #undef PACKAGE_NAME
198
199 /* Define to the full name and version of this package. */
200 #undef PACKAGE_STRING
201
202 /* Define to the one symbol short name of this package. */
203 #undef PACKAGE_TARNAME
204
205 /* Define to the version of this package. */
206 #undef PACKAGE_VERSION
207
208 /* Define as the return type of signal handlers (`int' or `void'). */
209 #undef RETSIGTYPE
210
211 /* Extension that shared libraries have, e.g., ".so". */
212 #undef SHLIBEXT
213
214 /* If using the C implementation of alloca, define if you know the
215 direction of stack growth for your system; otherwise it will be
216 automatically deduced at run-time.
217 STACK_DIRECTION > 0 => grows toward higher addresses
218 STACK_DIRECTION < 0 => grows toward lower addresses
219 STACK_DIRECTION = 0 => direction of growth unknown */
220 #undef STACK_DIRECTION
221
222 /* Define to 1 if you have the ANSI C header files. */
223 #undef STDC_HEADERS
224
225 /* Define to 1 if you can safely include both and . */
226 #undef TIME_WITH_SYS_TIME
227
228 /* Define to 1 if your declares `struct tm'. */
229 #undef TM_IN_SYS_TIME
230
231 /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
232 `char[]'. */
233 #undef YYTEXT_POINTER
234
235 /* Define to `int' if does not define. */
236 #undef pid_t
237
238 /* Define to `unsigned' if does not define. */
239 #undef size_t
+0
-23
include/Config/dlfcn.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * Description:
9 * This header file is the autoconf replacement for dlfcn.h (if it lives
10 * on the system).
11 */
12
13 #ifndef _CONFIG_DLFCN_H
14 #define _CONFIG_DLFCN_H
15
16 #include "Config/config.h"
17
18 #ifdef HAVE_DLFCN_H
19 #include
20 #endif
21
22 #endif
+0
-23
include/Config/fcntl.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * Description:
9 * This header file is the autoconf replacement for fcntl.h (if it lives
10 * on the system).
11 */
12
13 #ifndef _CONFIG_FCNTL_H
14 #define _CONFIG_FCNTL_H
15
16 #include "Config/config.h"
17
18 #ifdef HAVE_FCNTL_H
19 #include
20 #endif
21
22 #endif
+0
-23
include/Config/limits.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * Description:
9 * This header file is the autoconf replacement for limits.h (if it lives
10 * on the system).
11 */
12
13 #ifndef _CONFIG_LIMITS_H
14 #define _CONFIG_LIMITS_H
15
16 #include "Config/config.h"
17
18 #ifdef HAVE_LIMITS_H
19 #include
20 #endif
21
22 #endif
+0
-25
include/Config/malloc.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * Description:
9 * This header file includes the infamous malloc.h header file if the
10 * autoconf system has found it. It hides all of the autoconf details
11 * from the rest of the application source code.
12 */
13
14 #ifndef _SUPPORT_MALLOC_H
15 #define _SUPPORT_MALLOC_H
16
17 #include "Config/config.h"
18
19 #ifdef HAVE_MALLOC_H
20 #include
21 #endif
22
23 #endif
24
+0
-23
include/Config/memory.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * Description:
9 * This header file is the autoconf replacement for memory.h (if it lives
10 * on the system).
11 */
12
13 #ifndef _CONFIG_MEMORY_H
14 #define _CONFIG_MEMORY_H
15
16 #include "Config/config.h"
17
18 #ifdef HAVE_MEMORY_H
19 #include
20 #endif
21
22 #endif
+0
-49
include/Config/pagesize.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * This header file provides a platform-independent way of quering page size.
9 */
10
11 #ifndef PAGESIZE_H
12 #define PAGESIZE_H
13
14 #include "Config/unistd.h"
15 #include
16
17 namespace llvm {
18
19 /* Compatibility chart:
20 *
21 * Linux/x86: _SC_PAGESIZE, _SC_PAGE_SIZE
22 * MacOS X/PowerPC: v. 10.2: NBPG,
23 * v. 10.3: _SC_PAGESIZE
24 * Solaris/Sparc: _SC_PAGESIZE, _SC_PAGE_SIZE
25 */
26
27 /**
28 * GetPageSize - wrapper to return page size in bytes for various
29 * architecture/OS combinations
30 */
31 unsigned GetPageSize() {
32 #ifdef _SC_PAGESIZE
33 return sysconf(_SC_PAGESIZE);
34 #elif defined(_SC_PAGE_SIZE)
35 return sysconf(_SC_PAGE_SIZE);
36 #elif defined(NBPG)
37 #ifndef CLSIZE
38 #define CLSIZE 1
39 #endif
40 return NBPG * CLSIZE;
41 #else
42 return 4096; /* allocate 4KB as a fall-back */
43 #endif
44 }
45
46 }
47
48 #endif
+0
-23
include/Config/stdint.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * Description:
9 * This header file is the autoconf replacement for stdint.h (if it lives
10 * on the system).
11 */
12
13 #ifndef _CONFIG_STDINT_H
14 #define _CONFIG_STDINT_H
15
16 #include "Config/config.h"
17
18 #ifdef HAVE_STDINT_H
19 #include
20 #endif
21
22 #endif
+0
-32
include/Config/sys/mman.h less more
None /*===-- Config/sys/mman.h - Autoconf sys/mman.h wrapper -----------*- C -*-===//
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by the LLVM research group and is distributed under
5 * the University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===//
8 *
9 * Description:
10 * This header file includes the headers needed for the mmap() system/
11 * function call. It also defines some macros so that all of our calls
12 * to mmap() can act (more or less) the same, regardless of platform.
13 *
14 *===----------------------------------------------------------------------===//
15 */
16
17 #ifndef _CONFIG_MMAN_H
18 #define _CONFIG_MMAN_H
19
20 #include "Config/config.h"
21
22 #if defined(HAVE_SYS_MMAN_H) && !defined(_MSC_VER)
23 #include
24 #endif
25
26 #ifndef HAVE_MMAP_ANONYMOUS
27 #define MAP_ANONYMOUS MAP_ANON
28 #endif
29
30 #endif
31
+0
-34
include/Config/sys/resource.h less more
None /*===-- Config/sys/resource.h -----------------------------------*- C++ -*-===//
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by the LLVM research group and is distributed under
5 * the University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===//
8 *
9 * This header file is the autoconf replacement for sys/resource.h (if it
10 * lives on the system).
11 *
12 *===----------------------------------------------------------------------===//
13 */
14
15 #ifndef _CONFIG_SYS_RESOURCE_H
16 #define _CONFIG_SYS_RESOURCE_H
17
18 #include "Config/config.h"
19
20 #if defined(HAVE_SYS_RESOURCE_H) && !defined(_MSC_VER)
21
22 /*
23 * In LLVM, we use sys/resource.h to use getrusage() and maybe some other
24 * stuff. Some man pages say that you also need sys/time.h and unistd.h.
25 * So, to be paranoid, we will try to include all three if possible.
26 */
27 #include "Config/sys/time.h"
28 #include
29 #include "Config/unistd.h"
30
31 #endif
32
33 #endif
+0
-29
include/Config/sys/stat.h less more
None /*===-- Config/sys/stat.h -----------------------------------*- ----C++ -*-===//
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by the LLVM research group and is distributed under
5 * the University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===//
8 * This header file includes the headers needed for the stat() system
9 * call.
10 *
11 *===----------------------------------------------------------------------===//
12 */
13
14 #ifndef _CONFIG_SYS_STAT_H
15 #define _CONFIG_SYS_STAT_H
16
17 #include "Config/config.h"
18
19 #ifdef HAVE_SYS_STAT_H
20 #include
21 #endif
22
23 #if defined(_MSC_VER)
24 #define S_ISREG(X) ((X) & _S_IFREG)
25 #endif
26
27 #endif
28
+0
-24
include/Config/sys/time.h less more
None /*===-- Config/sys/time.h ---------------------------------------*- C++ -*-===//
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by the LLVM research group and is distributed under
5 * the University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===//
8 * This header file is the autoconf replacement for sys/time.h (if it
9 * lives on the system).
10 *
11 *===----------------------------------------------------------------------===//
12 */
13
14 #ifndef _CONFIG_SYS_TIME_H
15 #define _CONFIG_SYS_TIME_H
16
17 #include "Config/config.h"
18
19 #if defined(HAVE_SYS_TIME_H) && !defined(_MSC_VER)
20 #include
21 #endif
22
23 #endif
+0
-25
include/Config/sys/types.h less more
None /*===-- Config/sys/types.h --------------------------------------*- C++ -*-===//
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by the LLVM research group and is distributed under
5 * the University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===//
8 * This header file is the autoconf substitute for sys/types.h. It
9 * includes it for us if it exists on this system.
10 *
11 *===----------------------------------------------------------------------===//
12 */
13
14 #ifndef _CONFIG_SYS_TYPES_H
15 #define _CONFIG_SYS_TYPES_H
16
17 #include "Config/config.h"
18
19 #ifdef HAVE_SYS_TYPES_H
20 #include
21 #endif
22
23 #endif
24
+0
-24
include/Config/sys/wait.h less more
None /*===-- Config/sys/wait.h ---------------------------------------*- C++ -*-===//
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file was developed by the LLVM research group and is distributed under
5 * the University of Illinois Open Source License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===//
8 * This header file includes the headers needed for the wait() system
9 * call.
10 *===----------------------------------------------------------------------===//
11 */
12
13 #ifndef _CONFIG_SYS_WAIT_H
14 #define _CONFIG_SYS_WAIT_H
15
16 #include "Config/config.h"
17
18 #ifdef HAVE_SYS_WAIT_H
19 #include
20 #endif
21
22 #endif
23
+0
-33
include/Config/time.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 *===----------------------------------------------------------------------===//
7 *
8 * Description:
9 * This header file is the autoconf replacement for time.h (if it lives
10 * on the system).
11 *
12 * The added benefit of this header file is that it removes the
13 * "time with sys/time" problem.
14 *
15 * According to the autoconf manual, some systems have a sys/time.h that
16 * includes time.h, but time.h is not written to handle multiple
17 * inclusion. This means that a program including sys/time.h cannot
18 * also include time.h.
19 *
20 * This header file fixes that problem.
21 */
22
23 #ifndef _CONFIG_TIME_H
24 #define _CONFIG_TIME_H
25
26 #include "Config/config.h"
27
28 #ifdef HAVE_TIME_H
29 #include
30 #endif
31
32 #endif
+0
-28
include/Config/unistd.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 *===----------------------------------------------------------------------===//
7 *
8 * Description:
9 * This header file is the autoconf replacement for unistd.h (if it lives
10 * on the system).
11 */
12
13 #ifndef _CONFIG_UNISTD_H
14 #define _CONFIG_UNISTD_H
15
16 #include "Config/config.h"
17
18 #if defined(HAVE_UNISTD_H) && !defined(_MSC_VER)
19 #include
20 #endif
21
22 #ifdef _WIN32
23 #include
24 #include
25 #endif
26
27 #endif
+0
-25
include/Config/windows.h less more
None /*
1 * The LLVM Compiler Infrastructure
2 *
3 * This file was developed by the LLVM research group and is distributed under
4 * the University of Illinois Open Source License. See LICENSE.TXT for details.
5 *
6 ******************************************************************************
7 *
8 * Description:
9 * This header file is the autoconf replacement for windows.h (if it lives
10 * on the system).
11 */
12
13 #ifndef LLVM_CONFIG_WINDOWS_H
14 #define LLVM_CONFIG_WINDOWS_H
15
16 #include "Config/config.h"
17
18 #ifdef HAVE_WINDOWS_H
19 #include
20 #undef min
21 #undef max
22 #endif
23
24 #endif
+0
-217
include/Support/Annotation.h less more
None //===-- Support/Annotation.h - Annotation classes ---------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the declarations for two classes: Annotation & Annotable.
10 // Using these two simple classes, anything that derives from Annotable can have
11 // Annotation subclasses attached to them, ready for easy retrieval.
12 //
13 // Annotations are designed to be easily attachable to various classes.
14 //
15 // The AnnotationManager class is essential for using these classes. It is
16 // responsible for turning Annotation name strings into tokens [unique id #'s]
17 // that may be used to search for and create annotations.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef SUPPORT_ANNOTATION_H
22 #define SUPPORT_ANNOTATION_H
23
24 #include
25 #include
26
27 namespace llvm {
28
29 class AnnotationID;
30 class Annotation;
31 class Annotable;
32 class AnnotationManager;
33
34 //===----------------------------------------------------------------------===//
35 //
36 // AnnotationID - This class is a thin wrapper around an unsigned integer that
37 // is used to hopefully prevent errors using AnnotationID's. They may be copied
38 // freely around and passed byvalue with little or no overhead.
39 //
40 class AnnotationID {
41 friend class AnnotationManager;
42 unsigned ID;
43
44 AnnotationID(); // Default ctor is disabled
45 inline AnnotationID(unsigned i) : ID(i) {} // Only creatable from AnnMgr
46 public:
47 inline AnnotationID(const AnnotationID &A) : ID(A.ID) {}
48
49 inline bool operator==(const AnnotationID &A) const {
50 return A.ID == ID;
51 }
52 inline bool operator<(const AnnotationID &A) const {
53 return ID < A.ID;
54 }
55 };
56
57
58 //===----------------------------------------------------------------------===//
59 //
60 // Annotation Class - This class serves as a base class for any specific
61 // annotations that you might need. Simply subclass this to add extra
62 // information to the annotations.
63 //
64 class Annotation {
65 friend class Annotable; // Annotable manipulates Next list
66 AnnotationID ID; // ID number, as obtained from AnnotationManager
67 Annotation *Next; // The next annotation in the linked list
68 public:
69 inline Annotation(AnnotationID id) : ID(id), Next(0) {}
70 virtual ~Annotation(); // Designed to be subclassed
71
72 // getID - Return the unique ID# of this annotation
73 inline AnnotationID getID() const { return ID; }
74
75 // getNext - Return the next annotation in the list...
76 inline Annotation *getNext() const { return Next; }
77 };
78
79
80 //===----------------------------------------------------------------------===//
81 //
82 // Annotable - This class is used as a base class for all objects that would
83 // like to have annotation capability. One notable subclass is Value, which
84 // means annotations can be attached to almost everything in LLVM.
85 //
86 // Annotable objects keep their annotation list sorted as annotations are
87 // inserted and deleted. This is used to ensure that annotations with identical
88 // ID#'s are stored sequentially.
89 //
90 class Annotable {
91 mutable Annotation *AnnotationList;
92
93 Annotable(const Annotable &); // Do not implement
94 void operator=(const Annotable &); // Do not implement
95 public:
96 Annotable() : AnnotationList(0) {}
97 ~Annotable();
98
99 // getAnnotation - Search the list for annotations of the specified ID. The
100 // pointer returned is either null (if no annotations of the specified ID
101 // exist), or it points to the first element of a potentially list of elements
102 // with identical ID #'s.
103 //
104 Annotation *getAnnotation(AnnotationID ID) const {
105 for (Annotation *A = AnnotationList; A; A = A->getNext())
106 if (A->getID() == ID) return A;
107 return 0;
108 }
109
110 // getOrCreateAnnotation - Search through the annotation list, if there is
111 // no annotation with the specified ID, then use the AnnotationManager to
112 // create one.
113 //
114 inline Annotation *getOrCreateAnnotation(AnnotationID ID) const;
115
116 // addAnnotation - Insert the annotation into the list in a sorted location.
117 //
118 void addAnnotation(Annotation *A) const {
119 assert(A->Next == 0 && "Annotation already in list?!?");
120
121 Annotation **AL = &AnnotationList;
122 while (*AL && (*AL)->ID < A->getID()) // Find where to insert annotation
123 AL = &((*AL)->Next);
124 A->Next = *AL; // Link the annotation in
125 *AL = A;
126 }
127
128 // unlinkAnnotation - Remove the first annotation of the specified ID... and
129 // then return the unlinked annotation. The annotation object is not deleted.
130 //
131 inline Annotation *unlinkAnnotation(AnnotationID ID) const {
132 for (Annotation **A = &AnnotationList; *A; A = &((*A)->Next))
133 if ((*A)->getID() == ID) {
134 Annotation *Ret = *A;
135 *A = Ret->Next;
136 Ret->Next = 0;
137 return Ret;
138 }
139 return 0;
140 }
141
142 // deleteAnnotation - Delete the first annotation of the specified ID in the
143 // list. Unlink unlinkAnnotation, this actually deletes the annotation object
144 //
145 bool deleteAnnotation(AnnotationID ID) const {
146 Annotation *A = unlinkAnnotation(ID);
147 delete A;
148 return A != 0;
149 }
150 };
151
152
153 //===----------------------------------------------------------------------===//
154 //
155 // AnnotationManager - This class is primarily responsible for maintaining a
156 // one-to-one mapping between string Annotation names and Annotation ID numbers.
157 //
158 // Compared to the rest of the Annotation system, these mapping methods are
159 // relatively slow, so they should be avoided by locally caching Annotation
160 // ID #'s. These methods are safe to call at any time, even by static ctors, so
161 // they should be used by static ctors most of the time.
162 //
163 // This class also provides support for annotations that are created on demand
164 // by the Annotable::getOrCreateAnnotation method. To get this to work, simply
165 // register an annotation handler
166 //
167 struct AnnotationManager {
168 typedef Annotation *(*Factory)(AnnotationID, const Annotable *, void*);
169
170 //===--------------------------------------------------------------------===//
171 // Basic ID <-> Name map functionality
172
173 static AnnotationID getID(const std::string &Name); // Name -> ID
174 static const std::string &getName(AnnotationID ID); // ID -> Name
175
176 // getID - Name -> ID + registration of a factory function for demand driven
177 // annotation support.
178 static AnnotationID getID(const std::string &Name, Factory Fact,
179 void *Data = 0);
180
181 //===--------------------------------------------------------------------===//
182 // Annotation creation on demand support...
183
184 // registerAnnotationFactory - This method is used to register a callback
185 // function used to create an annotation on demand if it is needed by the
186 // Annotable::getOrCreateAnnotation method.
187 //
188 static void registerAnnotationFactory(AnnotationID ID, Factory Func,
189 void *ExtraData = 0);
190
191 // createAnnotation - Create an annotation of the specified ID for the
192 // specified object, using a register annotation creation function.
193 //
194 static Annotation *createAnnotation(AnnotationID ID, const Annotable *Obj);
195 };
196
197
198
199 // getOrCreateAnnotation - Search through the annotation list, if there is
200 // no annotation with the specified ID, then use the AnnotationManager to
201 // create one.
202 //
203 inline Annotation *Annotable::getOrCreateAnnotation(AnnotationID ID) const {
204 Annotation *A = getAnnotation(ID); // Fast path, check for preexisting ann
205 if (A) return A;
206
207 // No annotation found, ask the annotation manager to create an annotation...
208 A = AnnotationManager::createAnnotation(ID, this);
209 assert(A && "AnnotationManager could not create annotation!");
210 addAnnotation(A);
211 return A;
212 }
213
214 } // End namespace llvm
215
216 #endif
+0
-272
include/Support/BitSetVector.h less more
None //===-- BitVectorSet.h - A bit-vector representation of sets ----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This is an implementation of the bit-vector representation of sets. Unlike
10 // vector, this allows much more efficient parallel set operations on
11 // bits, by using the bitset template. The bitset template unfortunately can
12 // only represent sets with a size chosen at compile-time. We therefore use a
13 // vector of bitsets. The maxmimum size of our sets (i.e., the size of the
14 // universal set) can be chosen at creation time.
15 //
16 // External functions:
17 //
18 // bool Disjoint(const BitSetVector& set1, const BitSetVector& set2):
19 // Tests if two sets have an empty intersection.
20 // This is more efficient than !(set1 & set2).any().
21 //
22 //===----------------------------------------------------------------------===//
23
24 #ifndef SUPPORT_BITSETVECTOR_H
25 #define SUPPORT_BITSETVECTOR_H
26
27 #include
28 #include
29 #include
30 #include
31
32 namespace llvm {
33
34 class BitSetVector {
35 enum { BITSET_WORDSIZE = sizeof(long)*8 };
36
37 // Types used internal to the representation
38 typedef std::bitset bitword;
39 typedef bitword::reference reference;
40
41 // Data used in the representation
42 std::vector bitsetVec;
43 unsigned maxSize;
44
45 private:
46 // Utility functions for the representation
47 static unsigned NumWords(unsigned Size) {
48 return (Size+BITSET_WORDSIZE-1)/BITSET_WORDSIZE;
49 }
50 static unsigned LastWordSize(unsigned Size) { return Size % BITSET_WORDSIZE; }
51
52 // Clear the unused bits in the last word.
53 // The unused bits are the high (BITSET_WORDSIZE - LastWordSize()) bits
54 void ClearUnusedBits() {
55 unsigned long usedBits = (1U << LastWordSize(size())) - 1;
56 bitsetVec.back() &= bitword(usedBits);
57 }
58
59 const bitword& getWord(unsigned i) const { return bitsetVec[i]; }
60 bitword& getWord(unsigned i) { return bitsetVec[i]; }
61
62 friend bool Disjoint(const BitSetVector& set1,
63 const BitSetVector& set2);
64
65 BitSetVector(); // do not implement!
66
67 public:
68 class iterator;
69 ///
70 /// Constructor: create a set of the maximum size maxSetSize.
71 /// The set is initialized to empty.
72 ///
73 BitSetVector(unsigned maxSetSize)
74 : bitsetVec(NumWords(maxSetSize)), maxSize(maxSetSize) { }
75
76 /// size - Return the number of bits tracked by this bit vector...
77 unsigned size() const { return maxSize; }
78
79 ///
80 /// Modifier methods: reset, set for entire set, operator[] for one element.
81 ///
82 void reset() {
83 for (unsigned i=0, N = bitsetVec.size(); i < N; ++i)
84 bitsetVec[i].reset();
85 }
86 void set() {
87 for (unsigned i=0, N = bitsetVec.size(); i < N; ++i) // skip last word
88 bitsetVec[i].set();
89 ClearUnusedBits();
90 }
91 reference operator[](unsigned n) {
92 assert(n < size() && "BitSetVector: Bit number out of range");
93 unsigned ndiv = n / BITSET_WORDSIZE, nmod = n % BITSET_WORDSIZE;
94 return bitsetVec[ndiv][nmod];
95 }
96 iterator begin() { return iterator::begin(*this); }
97 iterator end() { return iterator::end(*this); }
98
99 ///
100 /// Comparison operations: equal, not equal
101 ///
102 bool operator == (const BitSetVector& set2) const {
103 assert(maxSize == set2.maxSize && "Illegal == comparison");
104 for (unsigned i = 0; i < bitsetVec.size(); ++i)
105 if (getWord(i) != set2.getWord(i))
106 return false;
107 return true;
108 }
109 bool operator != (const BitSetVector& set2) const {
110 return ! (*this == set2);
111 }
112
113 ///
114 /// Set membership operations: single element, any, none, count
115 ///
116 bool test(unsigned n) const {
117 assert(n < size() && "BitSetVector: Bit number out of range");
118 unsigned ndiv = n / BITSET_WORDSIZE, nmod = n % BITSET_WORDSIZE;
119 return bitsetVec[ndiv].test(nmod);
120 }
121 bool any() const {
122 for (unsigned i = 0; i < bitsetVec.size(); ++i)
123 if (bitsetVec[i].any())
124 return true;
125 return false;
126 }
127 bool none() const {
128 return ! any();
129 }
130 unsigned count() const {
131 unsigned n = 0;
132 for (unsigned i = 0; i < bitsetVec.size(); ++i)
133 n += bitsetVec[i].count();
134 return n;
135 }
136 bool all() const {
137 return (count() == size());
138 }
139
140 ///
141 /// Set operations: intersection, union, disjoint union, complement.
142 ///
143 BitSetVector operator& (const BitSetVector& set2) const {
144 assert(maxSize == set2.maxSize && "Illegal intersection");
145 BitSetVector result(maxSize);
146 for (unsigned i = 0; i < bitsetVec.size(); ++i)
147 result.getWord(i) = getWord(i) & set2.getWord(i);
148 return result;
149 }
150 BitSetVector operator| (const BitSetVector& set2) const {
151 assert(maxSize == set2.maxSize && "Illegal intersection");
152 BitSetVector result(maxSize);
153 for (unsigned i = 0; i < bitsetVec.size(); ++i)
154 result.getWord(i) = getWord(i) | set2.getWord(i);
155 return result;
156 }
157 BitSetVector operator^ (const BitSetVector& set2) const {
158 assert(maxSize == set2.maxSize && "Illegal intersection");
159 BitSetVector result(maxSize);
160 for (unsigned i = 0; i < bitsetVec.size(); ++i)
161 result.getWord(i) = getWord(i) ^ set2.getWord(i);
162 return result;
163 }
164 BitSetVector operator~ () const {
165 BitSetVector result(maxSize);
166 for (unsigned i = 0; i < bitsetVec.size(); ++i)
167 (result.getWord(i) = getWord(i)).flip();
168 result.ClearUnusedBits();
169 return result;
170 }
171
172 ///
173 /// Printing and debugging support
174 ///
175 void print(std::ostream &O) const;
176 void dump() const { print(std::cerr); }
177
178 public:
179 //
180 // An iterator to enumerate the bits in a BitSetVector.
181 // Eventually, this needs to inherit from bidirectional_iterator.
182 // But this iterator may not be as useful as I once thought and
183 // may just go away.
184 //
185 class iterator {
186 unsigned currentBit;
187 unsigned currentWord;
188 BitSetVector* bitvec;
189 iterator(unsigned B, unsigned W, BitSetVector& _bitvec)
190 : currentBit(B), currentWord(W), bitvec(&_bitvec) { }
191 public:
192 iterator(BitSetVector& _bitvec)
193 : currentBit(0), currentWord(0), bitvec(&_bitvec) { }
194 iterator(const iterator& I)
195 : currentBit(I.currentBit),currentWord(I.currentWord),bitvec(I.bitvec) { }
196 iterator& operator=(const iterator& I) {
197 currentWord = I.currentWord;
198 currentBit = I.currentBit;
199 bitvec = I.bitvec;
200 return *this;
201 }
202
203 // Increment and decrement operators (pre and post)
204 iterator& operator++() {
205 if (++currentBit == BITSET_WORDSIZE)
206 { currentBit = 0; if (currentWord < bitvec->size()) ++currentWord; }
207 return *this;
208 }
209 iterator& operator--() {
210 if (currentBit == 0) {
211 currentBit = BITSET_WORDSIZE-1;
212 currentWord = (currentWord == 0)? bitvec->size() : --currentWord;
213 }
214 else
215 --currentBit;
216 return *this;
217 }
218 iterator operator++(int) { iterator copy(*this); ++*this; return copy; }
219 iterator operator--(int) { iterator copy(*this); --*this; return copy; }
220
221 // Dereferencing operators
222 reference operator*() {
223 assert(currentWord < bitvec->size() &&
224 "Dereferencing iterator past the end of a BitSetVector");
225 return bitvec->getWord(currentWord)[currentBit];
226 }
227
228 // Comparison operator
229 bool operator==(const iterator& I) {
230 return (I.bitvec == bitvec &&
231 I.currentWord == currentWord && I.currentBit == currentBit);
232 }
233
234 protected:
235 static iterator begin(BitSetVector& _bitvec) { return iterator(_bitvec); }
236 static iterator end(BitSetVector& _bitvec) { return iterator(0,
237 _bitvec.size(), _bitvec); }
238 friend class BitSetVector;
239 };
240 };
241
242
243 inline void BitSetVector::print(std::ostream& O) const
244 {
245 for (std::vector::const_iterator
246 I=bitsetVec.begin(), E=bitsetVec.end(); I != E; ++I)
247 O << "<" << (*I) << ">" << (I+1 == E? "\n" : ", ");
248 }
249
250 inline std::ostream& operator<< (std::ostream& O, const BitSetVector& bset)
251 {
252 bset.print(O);
253 return O;
254 };
255
256
257 ///
258 /// Optimized versions of fundamental comparison operations
259 ///
260 inline bool Disjoint(const BitSetVector& set1,
261 const BitSetVector& set2)
262 {
263 assert(set1.size() == set2.size() && "Illegal intersection");
264 for (unsigned i = 0; i < set1.bitsetVec.size(); ++i)
265 if ((set1.getWord(i) & set2.getWord(i)).any())
266 return false;
267 return true;
268 }
269
270 } // End llvm namespace
271 #endif
+0
-301
include/Support/Casting.h less more
None //===-- Support/Casting.h - Allow flexible, checked, casts ------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the isa(), cast(), dyn_cast(), cast_or_null(),
10 // and dyn_cast_or_null() templates.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SUPPORT_CASTING_H
15 #define SUPPORT_CASTING_H
16
17 namespace llvm {
18
19 //===----------------------------------------------------------------------===//
20 // isa Support Templates
21 //===----------------------------------------------------------------------===//
22
23 template struct isa_impl_cl;
24
25 // Define a template that can be specialized by smart pointers to reflect the
26 // fact that they are automatically dereferenced, and are not involved with the
27 // template selection process... the default implementation is a noop.
28 //
29 template struct simplify_type {
30 typedef From SimpleType; // The real type this represents...
31
32 // An accessor to get the real value...
33 static SimpleType &getSimplifiedValue(From &Val) { return Val; }
34 };
35
36 template struct simplify_type {
37 typedef const From SimpleType;
38 static SimpleType &getSimplifiedValue(const From &Val) {
39 return simplify_type::getSimplifiedValue(static_cast(Val));
40 }
41 };
42
43
44 // isa - Return true if the parameter to the template is an instance of the
45 // template type argument. Used like this:
46 //
47 // if (isa(myVal)) { ... }
48 //
49 template
50 inline bool isa_impl(const From &Val) {
51 return To::classof(&Val);
52 }
53
54 template
55 struct isa_impl_wrap {
56 // When From != SimplifiedType, we can simplify the type some more by using
57 // the simplify_type template.
58 static bool doit(const From &Val) {
59 return isa_impl_cl::template
60 isa(simplify_type::getSimplifiedValue(Val));
61 }
62 };
63
64 template
65 struct isa_impl_wrap {
66 // When From == SimpleType, we are as simple as we are going to get.
67 static bool doit(const FromTy &Val) {
68 return isa_impl(Val);
69 }
70 };
71
72 // isa_impl_cl - Use class partial specialization to transform types to a single
73 // canonical form for isa_impl.
74 //
75 template
76 struct isa_impl_cl {
77 template
78 static bool isa(const FromCl &Val) {
79 return isa_impl_wrap
80 typename simplify_type::SimpleType>::doit(Val);
81 }
82 };
83
84 // Specialization used to strip const qualifiers off of the FromCl type...
85 template
86 struct isa_impl_cl {
87 template
88 static bool isa(const FromCl &Val) {
89 return isa_impl_cl::template isa(Val);
90 }
91 };
92
93 // Define pointer traits in terms of base traits...
94 template
95 struct isa_impl_cl {
96 template
97 static bool isa(FromCl *Val) {
98 return isa_impl_cl::template isa(*Val);
99 }
100 };
101
102 // Define reference traits in terms of base traits...
103 template
104 struct isa_impl_cl {
105 template
106 static bool isa(FromCl &Val) {
107 return isa_impl_cl::template isa(&Val);
108 }
109 };
110
111 template
112 inline bool isa(const Y &Val) {
113 return isa_impl_cl::template isa(Val);
114 }
115
116 //===----------------------------------------------------------------------===//
117 // cast Support Templates
118 //===----------------------------------------------------------------------===//
119
120 template struct cast_retty;
121
122
123 // Calculate what type the 'cast' function should return, based on a requested
124 // type of To and a source type of From.
125 template struct cast_retty_impl {
126 typedef To& ret_type; // Normal case, return Ty&
127 };
128 template struct cast_retty_impl {
129 typedef const To &ret_type; // Normal case, return Ty&
130 };
131
132 template struct cast_retty_impl {
133 typedef To* ret_type; // Pointer arg case, return Ty*
134 };
135
136 template struct cast_retty_impl {
137 typedef const To* ret_type; // Constant pointer arg case, return const Ty*
138 };
139
140 template struct cast_retty_impl {
141 typedef const To* ret_type; // Constant pointer arg case, return const Ty*
142 };
143
144
145 template
146 struct cast_retty_wrap {
147 // When the simplified type and the from type are not the same, use the type
148 // simplifier to reduce the type, then reuse cast_retty_impl to get the
149 // resultant type.
150 typedef typename cast_retty::ret_type ret_type;
151 };
152
153 template
154 struct cast_retty_wrap {
155 // When the simplified type is equal to the from type, use it directly.
156 typedef typename cast_retty_impl::ret_type ret_type;
157 };
158
159 template
160 struct cast_retty {
161 typedef typename cast_retty_wrap
162 typename simplify_type::SimpleType>::ret_type ret_type;
163 };
164
165 // Ensure the non-simple values are converted using the simplify_type template
166 // that may be specialized by smart pointers...
167 //
168 template struct cast_convert_val {
169 // This is not a simple type, use the template to simplify it...
170 static typename cast_retty::ret_type doit(const From &Val) {
171 return cast_convert_val
172 typename simplify_type::SimpleType>::doit(
173 simplify_type::getSimplifiedValue(Val));
174 }
175 };
176
177 template struct cast_convert_val {
178 // This _is_ a simple type, just cast it.
179 static typename cast_retty::ret_type doit(const FromTy &Val) {
180 return reinterpret_cast::ret_type>(
181 const_cast(Val));
182 }
183 };
184
185
186
187 // cast - Return the argument parameter cast to the specified type. This
188 // casting operator asserts that the type is correct, so it does not return null
189 // on failure. But it will correctly return NULL when the input is NULL.
190 // Used Like this:
191 //
192 // cast(myVal)->getParent()
193 //
194 template
195 inline typename cast_retty::ret_type cast(const Y &Val) {
196 assert(isa(Val) && "cast() argument of incompatible type!");
197 return cast_convert_val
198 typename simplify_type::SimpleType>::doit(Val);
199 }
200
201 // cast_or_null - Functionally identical to cast, except that a null value is
202 // accepted.
203 //
204 template
205 inline typename cast_retty::ret_type cast_or_null(Y *Val) {
206 if (Val == 0) return 0;
207 assert(isa(Val) && "cast_or_null() argument of incompatible type!");
208 return cast(Val);
209 }
210
211
212 // dyn_cast - Return the argument parameter cast to the specified type. This
213 // casting operator returns null if the argument is of the wrong type, so it can
214 // be used to test for a type as well as cast if successful. This should be
215 // used in the context of an if statement like this:
216 //
217 // if (const Instruction *I = dyn_cast(myVal)) { ... }
218 //
219
220 template
221 inline typename cast_retty::ret_type dyn_cast(Y Val) {
222 return isa(Val) ? cast(Val) : 0;
223 }
224
225 // dyn_cast_or_null - Functionally identical to dyn_cast, except that a null
226 // value is accepted.
227 //
228 template
229 inline typename cast_retty::ret_type dyn_cast_or_null(Y Val) {
230 return (Val && isa(Val)) ? cast(Val) : 0;
231 }
232
233
234 #ifdef DEBUG_CAST_OPERATORS
235 #include
236
237 struct bar {
238 bar() {}
239 private:
240 bar(const bar &);
241 };
242 struct foo {
243 void ext() const;
244 /* static bool classof(const bar *X) {
245 cerr << "Classof: " << X << "\n";
246 return true;
247 }*/
248 };
249
250 template <> inline bool isa_impl(const bar &Val) {
251 cerr << "Classof: " << &Val << "\n";
252 return true;
253 }
254
255
256 bar *fub();
257 void test(bar &B1, const bar *B2) {
258 // test various configurations of const
259 const bar &B3 = B1;
260 const bar *const B4 = B2;
261
262 // test isa
263 if (!isa(B1)) return;
264 if (!isa(B2)) return;
265 if (!isa(B3)) return;
266 if (!isa(B4)) return;
267
268 // test cast
269 foo &F1 = cast(B1);
270 const foo *F3 = cast(B2);
271 const foo *F4 = cast(B2);
272 const foo &F8 = cast(B3);
273 const foo *F9 = cast(B4);
274 foo *F10 = cast(fub());
275
276 // test cast_or_null
277 const foo *F11 = cast_or_null(B2);
278 const foo *F12 = cast_or_null(B2);
279 const foo *F13 = cast_or_null(B4);
280 const foo *F14 = cast_or_null(fub()); // Shouldn't print.
281
282 // These lines are errors...
283 //foo *F20 = cast(B2); // Yields const foo*
284 //foo &F21 = cast(B3); // Yields const foo&
285 //foo *F22 = cast(B4); // Yields const foo*
286 //foo &F23 = cast_or_null(B1);
287 //const foo &F24 = cast_or_null(B3);
288 }
289
290 bar *fub() { return 0; }
291 void main() {
292 bar B;
293 test(B, &B);
294 }
295
296 #endif
297
298 } // End llvm namespace
299
300 #endif
+0
-1049
include/Support/CommandLine.h less more
None //===- Support/CommandLine.h - Flexible Command line parser -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This class implements a command line argument processor that is useful when
10 // creating a tool. It provides a simple, minimalistic interface that is easily
11 // extensible and supports nonlocal (library) command line options.
12 //
13 // Note that rather than trying to figure out what this code does, you should
14 // read the library documentation located in docs/CommandLine.html or looks at
15 // the many example usages in tools/*/*.cpp
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef SUPPORT_COMMANDLINE_H
20 #define SUPPORT_COMMANDLINE_H
21
22 #include "Support/type_traits.h"
23 #include
24 #include
25 #include
26 #include
27 #include
28
29 namespace llvm {
30
31 /// cl Namespace - This namespace contains all of the command line option
32 /// processing machinery. It is intentionally a short name to make qualified
33 /// usage concise.
34 namespace cl {
35
36 //===----------------------------------------------------------------------===//
37 // ParseCommandLineOptions - Command line option processing entry point.
38 //
39 void ParseCommandLineOptions(int &argc, char **argv,
40 const char *Overview = 0);
41
42 //===----------------------------------------------------------------------===//
43 // ParseEnvironmentOptions - Environment variable option processing alternate
44 // entry point.
45 //
46 void ParseEnvironmentOptions(const char *progName, const char *envvar,
47 const char *Overview = 0);
48
49 //===----------------------------------------------------------------------===//
50 // Flags permitted to be passed to command line arguments
51 //
52
53 enum NumOccurrences { // Flags for the number of occurrences allowed
54 Optional = 0x01, // Zero or One occurrence
55 ZeroOrMore = 0x02, // Zero or more occurrences allowed
56 Required = 0x03, // One occurrence required
57 OneOrMore = 0x04, // One or more occurrences required
58
59 // ConsumeAfter - Indicates that this option is fed anything that follows the
60 // last positional argument required by the application (it is an error if
61 // there are zero positional arguments, and a ConsumeAfter option is used).
62 // Thus, for example, all arguments to LLI are processed until a filename is
63 // found. Once a filename is found, all of the succeeding arguments are
64 // passed, unprocessed, to the ConsumeAfter option.
65 //
66 ConsumeAfter = 0x05,
67
68 OccurrencesMask = 0x07,
69 };
70
71 enum ValueExpected { // Is a value required for the option?
72 ValueOptional = 0x08, // The value can appear... or not
73 ValueRequired = 0x10, // The value is required to appear!
74 ValueDisallowed = 0x18, // A value may not be specified (for flags)
75 ValueMask = 0x18,
76 };
77
78 enum OptionHidden { // Control whether -help shows this option
79 NotHidden = 0x20, // Option included in --help & --help-hidden
80 Hidden = 0x40, // -help doesn't, but --help-hidden does
81 ReallyHidden = 0x60, // Neither --help nor --help-hidden show this arg
82 HiddenMask = 0x60,
83 };
84
85 // Formatting flags - This controls special features that the option might have
86 // that cause it to be parsed differently...
87 //
88 // Prefix - This option allows arguments that are otherwise unrecognized to be
89 // matched by options that are a prefix of the actual value. This is useful for
90 // cases like a linker, where options are typically of the form '-lfoo' or
91 // '-L../../include' where -l or -L are the actual flags. When prefix is
92 // enabled, and used, the value for the flag comes from the suffix of the
93 // argument.
94 //
95 // Grouping - With this option enabled, multiple letter options are allowed to
96 // bunch together with only a single hyphen for the whole group. This allows
97 // emulation of the behavior that ls uses for example: ls -la === ls -l -a
98 //
99
100 enum FormattingFlags {
101 NormalFormatting = 0x000, // Nothing special
102 Positional = 0x080, // Is a positional argument, no '-' required
103 Prefix = 0x100, // Can this option directly prefix its value?
104 Grouping = 0x180, // Can this option group with other options?
105 FormattingMask = 0x180, // Union of the above flags.
106 };
107
108 enum MiscFlags { // Miscellaneous flags to adjust argument
109 CommaSeparated = 0x200, // Should this cl::list split between commas?
110 PositionalEatsArgs = 0x400, // Should this positional cl::list eat -args?
111 MiscMask = 0x600, // Union of the above flags.
112 };
113
114
115
116 //===----------------------------------------------------------------------===//
117 // Option Base class
118 //
119 class alias;
120 class Option {
121 friend void cl::ParseCommandLineOptions(int &, char **, const char *);
122 friend class alias;
123
124 // handleOccurrences - Overriden by subclasses to handle the value passed into
125 // an argument. Should return true if there was an error processing the
126 // argument and the program should exit.
127 //
128 virtual bool handleOccurrence(unsigned pos, const char *ArgName,
129 const std::string &Arg) = 0;
130
131 virtual enum NumOccurrences getNumOccurrencesFlagDefault() const {
132 return Optional;
133 }
134 virtual enum ValueExpected getValueExpectedFlagDefault() const {
135 return ValueOptional;
136 }
137 virtual enum OptionHidden getOptionHiddenFlagDefault() const {
138 return NotHidden;
139 }
140 virtual enum FormattingFlags getFormattingFlagDefault() const {
141 return NormalFormatting;
142 }
143
144 int NumOccurrences; // The number of times specified
145 int Flags; // Flags for the argument
146 unsigned Position; // Position of last occurrence of the option
147 public:
148 const char *ArgStr; // The argument string itself (ex: "help", "o")
149 const char *HelpStr; // The descriptive text message for --help
150 const char *ValueStr; // String describing what the value of this option is
151
152 inline enum NumOccurrences getNumOccurrencesFlag() const {
153 int NO = Flags & OccurrencesMask;
154 return NO ? static_cast(NO)
155 : getNumOccurrencesFlagDefault();
156 }
157 inline enum ValueExpected getValueExpectedFlag() const {
158 int VE = Flags & ValueMask;
159 return VE ? static_cast(VE)
160 : getValueExpectedFlagDefault();
161 }
162 inline enum OptionHidden getOptionHiddenFlag() const {
163 int OH = Flags & HiddenMask;
164 return OH ? static_cast(OH)
165 : getOptionHiddenFlagDefault();
166 }
167 inline enum FormattingFlags getFormattingFlag() const {
168 int OH = Flags & FormattingMask;
169 return OH ? static_cast(OH)
170 : getFormattingFlagDefault();
171 }
172 inline unsigned getMiscFlags() const {
173 return Flags & MiscMask;
174 }
175 inline unsigned getPosition() const { return Position; }
176
177 // hasArgStr - Return true if the argstr != ""
178 bool hasArgStr() const { return ArgStr[0] != 0; }
179
180 //-------------------------------------------------------------------------===
181 // Accessor functions set by OptionModifiers
182 //
183 void setArgStr(const char *S) { ArgStr = S; }
184 void setDescription(const char *S) { HelpStr = S; }
185 void setValueStr(const char *S) { ValueStr = S; }
186
187 void setFlag(unsigned Flag, unsigned FlagMask) {
188 if (Flags & FlagMask) {
189 error(": Specified two settings for the same option!");
190 exit(1);
191 }
192
193 Flags |= Flag;
194 }
195
196 void setNumOccurrencesFlag(enum NumOccurrences Val) {
197 setFlag(Val, OccurrencesMask);
198 }
199 void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
200 void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
201 void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
202 void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
203 void setPosition(unsigned pos) { Position = pos; }
204 protected:
205 Option() : NumOccurrences(0), Flags(0), Position(0),
206 ArgStr(""), HelpStr(""), ValueStr("") {}
207
208 public:
209 // addArgument - Tell the system that this Option subclass will handle all
210 // occurrences of -ArgStr on the command line.
211 //
212 void addArgument(const char *ArgStr);
213 void removeArgument(const char *ArgStr);
214
215 // Return the width of the option tag for printing...
216 virtual unsigned getOptionWidth() const = 0;
217
218 // printOptionInfo - Print out information about this option. The
219 // to-be-maintained width is specified.
220 //
221 virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
222
223 // addOccurrence - Wrapper around handleOccurrence that enforces Flags
224 //
225 bool addOccurrence(unsigned pos, const char *ArgName,
226 const std::string &Value);
227
228 // Prints option name followed by message. Always returns true.
229 bool error(std::string Message, const char *ArgName = 0);
230
231 public:
232 inline int getNumOccurrences() const { return NumOccurrences; }
233 virtual ~Option() {}
234 };
235
236
237 //===----------------------------------------------------------------------===//
238 // Command line option modifiers that can be used to modify the behavior of
239 // command line option parsers...
240 //
241
242 // desc - Modifier to set the description shown in the --help output...
243 struct desc {
244 const char *Desc;
245 desc(const char *Str) : Desc(Str) {}
246 void apply(Option &O) const { O.setDescription(Desc); }
247 };
248
249 // value_desc - Modifier to set the value description shown in the --help
250 // output...
251 struct value_desc {
252 const char *Desc;
253 value_desc(const char *Str) : Desc(Str) {}
254 void apply(Option &O) const { O.setValueStr(Desc); }
255 };
256
257 // init - Specify a default (initial) value for the command line argument, if
258 // the default constructor for the argument type does not give you what you
259 // want. This is only valid on "opt" arguments, not on "list" arguments.
260 //
261 template
262 struct initializer {
263 const Ty &Init;
264 initializer(const Ty &Val) : Init(Val) {}
265
266 template
267 void apply(Opt &O) const { O.setInitialValue(Init); }
268 };
269
270 template
271 initializer init(const Ty &Val) {
272 return initializer(Val);
273 }
274
275
276 // location - Allow the user to specify which external variable they want to
277 // store the results of the command line argument processing into, if they don't
278 // want to store it in the option itself.
279 //
280 template
281 struct LocationClass {
282 Ty &Loc;
283 LocationClass(Ty &L) : Loc(L) {}
284
285 template
286 void apply(Opt &O) const { O.setLocation(O, Loc); }
287 };
288
289 template
290 LocationClass location(Ty &L) { return LocationClass(L); }
291
292
293 //===----------------------------------------------------------------------===//
294 // Enum valued command line option
295 //
296 #define clEnumVal(ENUMVAL, DESC) #ENUMVAL, (int)ENUMVAL, DESC
297 #define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, (int)ENUMVAL, DESC
298 #define clEnumValEnd ((void*)0)
299
300 // values - For custom data types, allow specifying a group of values together
301 // as the values that go into the mapping that the option handler uses. Note
302 // that the values list must always have a 0 at the end of the list to indicate
303 // that the list has ended.
304 //
305 template
306 class ValuesClass {
307 // Use a vector instead of a map, because the lists should be short,
308 // the overhead is less, and most importantly, it keeps them in the order
309 // inserted so we can print our option out nicely.
310 std::vector > > Values;
311 void processValues(va_list Vals);
312 public:
313 ValuesClass(const char *EnumName, DataType Val, const char *Desc,
314 va_list ValueArgs) {
315 // Insert the first value, which is required.
316 Values.push_back(std::make_pair(EnumName, std::make_pair(Val, Desc)));
317
318 // Process the varargs portion of the values...
319 while (const char *EnumName = va_arg(ValueArgs, const char *)) {
320 DataType EnumVal = static_cast(va_arg(ValueArgs, int));
321 const char *EnumDesc = va_arg(ValueArgs, const char *);
322 Values.push_back(std::make_pair(EnumName, // Add value to value map
323 std::make_pair(EnumVal, EnumDesc)));
324 }
325 }
326
327 template
328 void apply(Opt &O) const {
329 for (unsigned i = 0, e = Values.size(); i != e; ++i)
330 O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
331 Values[i].second.second);
332 }
333 };
334
335 template
336 ValuesClass values(const char *Arg, DataType Val, const char *Desc,
337 ...) {
338 va_list ValueArgs;
339 va_start(ValueArgs, Desc);
340 ValuesClass Vals(Arg, Val, Desc, ValueArgs);
341 va_end(ValueArgs);
342 return Vals;
343 }
344
345
346 //===----------------------------------------------------------------------===//
347 // parser class - Parameterizable parser for different data types. By default,
348 // known data types (string, int, bool) have specialized parsers, that do what
349 // you would expect. The default parser, used for data types that are not
350 // built-in, uses a mapping table to map specific options to values, which is
351 // used, among other things, to handle enum types.
352
353 //--------------------------------------------------
354 // generic_parser_base - This class holds all the non-generic code that we do
355 // not need replicated for every instance of the generic parser. This also
356 // allows us to put stuff into CommandLine.cpp
357 //
358 struct generic_parser_base {
359 virtual ~generic_parser_base() {} // Base class should have virtual-dtor
360
361 // getNumOptions - Virtual function implemented by generic subclass to
362 // indicate how many entries are in Values.
363 //
364 virtual unsigned getNumOptions() const = 0;
365
366 // getOption - Return option name N.
367 virtual const char *getOption(unsigned N) const = 0;
368
369 // getDescription - Return description N
370 virtual const char *getDescription(unsigned N) const = 0;
371
372 // Return the width of the option tag for printing...
373 virtual unsigned getOptionWidth(const Option &O) const;
374
375 // printOptionInfo - Print out information about this option. The
376 // to-be-maintained width is specified.
377 //
378 virtual void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
379
380 void initialize(Option &O) {
381 // All of the modifiers for the option have been processed by now, so the
382 // argstr field should be stable, copy it down now.
383 //
384 hasArgStr = O.hasArgStr();
385
386 // If there has been no argstr specified, that means that we need to add an
387 // argument for every possible option. This ensures that our options are
388 // vectored to us.
389 //
390 if (!hasArgStr)
391 for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
392 O.addArgument(getOption(i));
393 }
394
395 enum ValueExpected getValueExpectedFlagDefault() const {
396 // If there is an ArgStr specified, then we are of the form:
397 //
398 // -opt=O2 or -opt O2 or -optO2
399 //
400 // In which case, the value is required. Otherwise if an arg str has not
401 // been specified, we are of the form:
402 //
403 // -O2 or O2 or -la (where -l and -a are separate options)
404 //
405 // If this is the case, we cannot allow a value.
406 //
407 if (hasArgStr)
408 return ValueRequired;
409 else
410 return ValueDisallowed;
411 }
412
413 // findOption - Return the option number corresponding to the specified
414 // argument string. If the option is not found, getNumOptions() is returned.
415 //
416 unsigned findOption(const char *Name);
417
418 protected:
419 bool hasArgStr;
420 };
421
422 // Default parser implementation - This implementation depends on having a
423 // mapping of recognized options to values of some sort. In addition to this,
424 // each entry in the mapping also tracks a help message that is printed with the
425 // command line option for --help. Because this is a simple mapping parser, the
426 // data type can be any unsupported type.
427 //
428 template
429 class parser : public generic_parser_base {
430 protected:
431 std::vector
432 std::pair > > Values;
433 public:
434 typedef DataType parser_data_type;
435
436 // Implement virtual functions needed by generic_parser_base
437 unsigned getNumOptions() const { return Values.size(); }
438 const char *getOption(unsigned N) const { return Values[N].first; }
439 const char *getDescription(unsigned N) const {
440 return Values[N].second.second;
441 }
442
443 // parse - Return true on error.
444 bool parse(Option &O, const char *ArgName, const std::string &Arg,
445 DataType &V) {
446 std::string ArgVal;
447 if (hasArgStr)
448 ArgVal = Arg;
449 else
450 ArgVal = ArgName;
451
452 for (unsigned i = 0, e = Values.size(); i != e; ++i)
453 if (ArgVal == Values[i].first) {
454 V = Values[i].second.first;
455 return false;
456 }
457
458 return O.error(": Cannot find option named '" + ArgVal + "'!");
459 }
460
461 // addLiteralOption - Add an entry to the mapping table...
462 template
463 void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
464 assert(findOption(Name) == Values.size() && "Option already exists!");
465 Values.push_back(std::make_pair(Name,
466 std::make_pair(static_cast(V),HelpStr)));
467 }
468
469 // removeLiteralOption - Remove the specified option.
470 //
471 void removeLiteralOption(const char *Name) {
472 unsigned N = findOption(Name);
473 assert(N != Values.size() && "Option not found!");
474 Values.erase(Values.begin()+N);
475 }
476 };
477
478 //--------------------------------------------------
479 // basic_parser - Super class of parsers to provide boilerplate code
480 //
481 struct basic_parser_impl { // non-template implementation of basic_parser
482 virtual ~basic_parser_impl() {}
483
484 enum ValueExpected getValueExpectedFlagDefault() const {
485 return ValueRequired;
486 }
487
488 void initialize(Option &O) {}
489
490 // Return the width of the option tag for printing...
491 unsigned getOptionWidth(const Option &O) const;
492
493 // printOptionInfo - Print out information about this option. The
494 // to-be-maintained width is specified.
495 //
496 void printOptionInfo(const Option &O, unsigned GlobalWidth) const;
497
498 // getValueName - Overload in subclass to provide a better default value.
499 virtual const char *getValueName() const { return "value"; }
500 };
501
502 // basic_parser - The real basic parser is just a template wrapper that provides
503 // a typedef for the provided data type.
504 //
505 template
506 struct basic_parser : public basic_parser_impl {
507 typedef DataType parser_data_type;
508 };
509
510
511 //--------------------------------------------------
512 // parser
513 //
514 template<>
515 struct parser : public basic_parser {
516
517 // parse - Return true on error.
518 bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val);
519
520 enum ValueExpected getValueExpectedFlagDefault() const {
521 return ValueOptional;
522 }
523
524 // getValueName - Do not print = at all
525 virtual const char *getValueName() const { return 0; }
526 };
527
528
529 //--------------------------------------------------
530 // parser
531 //
532 template<>
533 struct parser : public basic_parser {
534
535 // parse - Return true on error.
536 bool parse(Option &O, const char *ArgName, const std::string &Arg, int &Val);
537
538 // getValueName - Overload in subclass to provide a better default value.
539 virtual const char *getValueName() const { return "int"; }
540 };
541
542
543 //--------------------------------------------------
544 // parser
545 //
546 template<>
547 struct parser : public basic_parser {
548
549 // parse - Return true on error.
550 bool parse(Option &O, const char *AN, const std::string &Arg, unsigned &Val);
551
552 // getValueName - Overload in subclass to provide a better default value.
553 virtual const char *getValueName() const { return "uint"; }
554 };
555
556
557 //--------------------------------------------------
558 // parser
559 //
560 template<>
561 struct parser : public basic_parser {
562 // parse - Return true on error.
563 bool parse(Option &O, const char *AN, const std::string &Arg, double &Val);
564
565 // getValueName - Overload in subclass to provide a better default value.
566 virtual const char *getValueName() const { return "number"; }
567 };
568
569
570 //--------------------------------------------------
571 // parser
572 //
573 template<>
574 struct parser : public basic_parser {
575 // parse - Return true on error.
576 bool parse(Option &O, const char *AN, const std::string &Arg, float &Val);
577
578 // getValueName - Overload in subclass to provide a better default value.
579 virtual const char *getValueName() const { return "number"; }
580 };
581
582
583 //--------------------------------------------------
584 // parser
585 //
586 template<>
587 struct parser : public basic_parser {
588 // parse - Return true on error.
589 bool parse(Option &O, const char *AN, const std::string &Arg,
590 std::string &Value) {
591 Value = Arg;
592 return false;
593 }
594
595 // getValueName - Overload in subclass to provide a better default value.
596 virtual const char *getValueName() const { return "string"; }
597 };
598
599 //===----------------------------------------------------------------------===//
600 // applicator class - This class is used because we must use partial
601 // specialization to handle literal string arguments specially (const char* does
602 // not correctly respond to the apply method). Because the syntax to use this
603 // is a pain, we have the 'apply' method below to handle the nastiness...
604 //
605 template struct applicator {
606 template
607 static void opt(const Mod &M, Opt &O) { M.apply(O); }
608 };
609
610 // Handle const char* as a special case...
611 template struct applicator {
612 template
613 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
614 };
615 template struct applicator {
616 template
617 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
618 };
619 template<> struct applicator {
620 template
621 static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
622 };
623
624 template<> struct applicator {
625 static void opt(NumOccurrences NO, Option &O) { O.setNumOccurrencesFlag(NO); }
626 };
627 template<> struct applicator {
628 static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
629 };
630 template<> struct applicator {
631 static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
632 };
633 template<> struct applicator {
634 static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
635 };
636 template<> struct applicator {
637 static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
638 };
639
640 // apply method - Apply a modifier to an option in a type safe way.
641 template
642 void apply(const Mod &M, Opt *O) {
643 applicator::opt(M, *O);
644 }
645
646
647 //===----------------------------------------------------------------------===//
648 // opt_storage class
649
650 // Default storage class definition: external storage. This implementation
651 // assumes the user will specify a variable to store the data into with the
652 // cl::location(x) modifier.
653 //
654 template
655 class opt_storage {
656 DataType *Location; // Where to store the object...
657
658 void check() {
659 assert(Location != 0 && "cl::location(...) not specified for a command "
660 "line option with external storage, "
661 "or cl::init specified before cl::location()!!");
662 }
663 public:
664 opt_storage() : Location(0) {}
665
666 bool setLocation(Option &O, DataType &L) {
667 if (Location)
668 return O.error(": cl::location(x) specified more than once!");
669 Location = &L;
670 return false;
671 }
672
673 template
674 void setValue(const T &V) {
675 check();
676 *Location = V;
677 }
678
679 DataType &getValue() { check(); return *Location; }
680 const DataType &getValue() const { check(); return *Location; }
681 };
682
683
684 // Define how to hold a class type object, such as a string. Since we can
685 // inherit from a class, we do so. This makes us exactly compatible with the
686 // object in all cases that it is used.
687 //
688 template
689 struct opt_storage : public DataType {
690
691 template
692 void setValue(const T &V) { DataType::operator=(V); }
693
694 DataType &getValue() { return *this; }
695 const DataType &getValue() const { return *this; }
696 };
697
698 // Define a partial specialization to handle things we cannot inherit from. In
699 // this case, we store an instance through containment, and overload operators
700 // to get at the value.
701 //
702 template
703 struct opt_storage {
704 DataType Value;
705
706 // Make sure we initialize the value with the default constructor for the
707 // type.
708 opt_storage() : Value(DataType()) {}
709
710 template
711 void setValue(const T &V) { Value = V; }
712 DataType &getValue() { return Value; }
713 DataType getValue() const { return Value; }
714
715 // If the datatype is a pointer, support -> on it.
716 DataType operator->() const { return Value; }
717 };
718
719
720 //===----------------------------------------------------------------------===//
721 // opt - A scalar command line option.
722 //
723 template
724 class ParserClass = parser >
725 class opt : public Option,
726 public opt_storage
727 is_class::value> {
728 ParserClass Parser;
729
730 virtual bool handleOccurrence(unsigned pos, const char *ArgName,
731 const std::string &Arg) {
732 typename ParserClass::parser_data_type Val;
733 if (Parser.parse(*this, ArgName, Arg, Val))
734 return true; // Parse error!
735 setValue(Val);
736 setPosition(pos);
737 return false;
738 }
739
740 virtual enum ValueExpected getValueExpectedFlagDefault() const {
741 return Parser.getValueExpectedFlagDefault();
742 }
743
744 // Forward printing stuff to the parser...
745 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
746 virtual void printOptionInfo(unsigned GlobalWidth) const {
747 Parser.printOptionInfo(*this, GlobalWidth);
748 }
749
750 void done() {
751 addArgument(ArgStr);
752 Parser.initialize(*this);
753 }
754 public:
755 // setInitialValue - Used by the cl::init modifier...
756 void setInitialValue(const DataType &V) { this->setValue(V); }
757
758 ParserClass &getParser() { return Parser; }
759
760 operator DataType() const { return this->getValue(); }
761
762 template
763 DataType &operator=(const T &Val) {
764 this->setValue(Val);
765 return this->getValue();
766 }
767
768 // One option...
769 template
770 opt(const M0t &M0) {
771 apply(M0, this);
772 done();
773 }
774
775 // Two options...
776 template
777 opt(const M0t &M0, const M1t &M1) {
778 apply(M0, this); apply(M1, this);
779 done();
780 }
781
782 // Three options...
783 template
784 opt(const M0t &M0, const M1t &M1, const M2t &M2) {
785 apply(M0, this); apply(M1, this); apply(M2, this);
786 done();
787 }
788 // Four options...
789 template
790 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
791 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
792 done();
793 }
794 // Five options...
795 template
796 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
797 const M4t &M4) {
798 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
799 apply(M4, this);
800 done();
801 }
802 // Six options...
803 template
804 class M4t, class M5t>
805 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
806 const M4t &M4, const M5t &M5) {
807 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
808 apply(M4, this); apply(M5, this);
809 done();
810 }
811 // Seven options...
812 template
813 class M4t, class M5t, class M6t>
814 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
815 const M4t &M4, const M5t &M5, const M6t &M6) {
816 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
817 apply(M4, this); apply(M5, this); apply(M6, this);
818 done();
819 }
820 // Eight options...
821 template
822 class M4t, class M5t, class M6t, class M7t>
823 opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
824 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
825 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
826 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
827 done();
828 }
829 };
830
831 //===----------------------------------------------------------------------===//
832 // list_storage class
833
834 // Default storage class definition: external storage. This implementation
835 // assumes the user will specify a variable to store the data into with the
836 // cl::location(x) modifier.
837 //
838 template
839 class list_storage {
840 StorageClass *Location; // Where to store the object...
841
842 public:
843 list_storage() : Location(0) {}
844
845 bool setLocation(Option &O, StorageClass &L) {
846 if (Location)
847 return O.error(": cl::location(x) specified more than once!");
848 Location = &L;
849 return false;
850 }
851
852 template
853 void addValue(const T &V) {
854 assert(Location != 0 && "cl::location(...) not specified for a command "
855 "line option with external storage!");
856 Location->push_back(V);
857 }
858 };
859
860
861 // Define how to hold a class type object, such as a string. Since we can
862 // inherit from a class, we do so. This makes us exactly compatible with the
863 // object in all cases that it is used.
864 //
865 template
866 struct list_storage : public std::vector {
867
868 template
869 void addValue(const T &V) { push_back(V); }
870 };
871
872
873 //===----------------------------------------------------------------------===//
874 // list - A list of command line options.
875 //
876 template
877 class ParserClass = parser >
878 class list : public Option, public list_storage {
879 std::vector Positions;
880 ParserClass Parser;
881
882 virtual enum NumOccurrences getNumOccurrencesFlagDefault() const {
883 return ZeroOrMore;
884 }
885 virtual enum ValueExpected getValueExpectedFlagDefault() const {
886 return Parser.getValueExpectedFlagDefault();
887 }
888
889 virtual bool handleOccurrence(unsigned pos, const char *ArgName,
890 const std::string &Arg) {
891 typename ParserClass::parser_data_type Val;
892 if (Parser.parse(*this, ArgName, Arg, Val))
893 return true; // Parse Error!
894 addValue(Val);
895 setPosition(pos);
896 Positions.push_back(pos);
897 return false;
898 }
899
900 // Forward printing stuff to the parser...
901 virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
902 virtual void printOptionInfo(unsigned GlobalWidth) const {
903 Parser.printOptionInfo(*this, GlobalWidth);
904 }
905
906 void done() {
907 addArgument(ArgStr);
908 Parser.initialize(*this);
909 }
910 public:
911 ParserClass &getParser() { return Parser; }
912
913 unsigned getPosition(unsigned optnum) {
914 assert(optnum < this->size() && "Invalid option index");
915 return Positions[optnum];
916 }
917
918 // One option...
919 template
920 list(const M0t &M0) {
921 apply(M0, this);
922 done();
923 }
924 // Two options...
925 template
926 list(const M0t &M0, const M1t &M1) {
927 apply(M0, this); apply(M1, this);
928 done();
929 }
930 // Three options...
931 template
932 list(const M0t &M0, const M1t &M1, const M2t &M2) {
933 apply(M0, this); apply(M1, this); apply(M2, this);
934 done();
935 }
936 // Four options...
937 template
938 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) {
939 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
940 done();
941 }
942 // Five options...
943 template
944 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
945 const M4t &M4) {
946 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
947 apply(M4, this);
948 done();
949 }
950 // Six options...
951 template
952 class M4t, class M5t>
953 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
954 const M4t &M4, const M5t &M5) {
955 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
956 apply(M4, this); apply(M5, this);
957 done();
958 }
959 // Seven options...
960 template
961 class M4t, class M5t, class M6t>
962 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
963 const M4t &M4, const M5t &M5, const M6t &M6) {
964 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
965 apply(M4, this); apply(M5, this); apply(M6, this);
966 done();
967 }
968 // Eight options...
969 template
970 class M4t, class M5t, class M6t, class M7t>
971 list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
972 const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) {
973 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
974 apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
975 done();
976 }
977 };
978
979 //===----------------------------------------------------------------------===//
980 // Aliased command line option (alias this name to a preexisting name)
981 //
982
983 class alias : public Option {
984 Option *AliasFor;
985 virtual bool handleOccurrence(unsigned pos, const char *ArgName,
986 const std::string &Arg) {
987 return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
988 }
989 // Aliases default to be hidden...
990 virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}
991
992 // Handle printing stuff...
993 virtual unsigned getOptionWidth() const;
994 virtual void printOptionInfo(unsigned GlobalWidth) const;
995
996 void done() {
997 if (!hasArgStr())
998 error(": cl::alias must have argument name specified!");
999 if (AliasFor == 0)
1000 error(": cl::alias must have an cl::aliasopt(option) specified!");
1001 addArgument(ArgStr);
1002 }
1003 public:
1004 void setAliasFor(Option &O) {
1005 if (AliasFor)
1006 error(": cl::alias must only have one cl::aliasopt(...) specified!");
1007 AliasFor = &O;
1008 }
1009
1010 // One option...
1011 template
1012 alias(const M0t &M0) : AliasFor(0) {
1013 apply(M0, this);
1014 done();
1015 }
1016 // Two options...
1017 template
1018 alias(const M0t &M0, const M1t &M1) : AliasFor(0) {
1019 apply(M0, this); apply(M1, this);
1020 done();
1021 }
1022 // Three options...
1023 template
1024 alias(const M0t &M0, const M1t &M1, const M2t &M2) : AliasFor(0) {
1025 apply(M0, this); apply(M1, this); apply(M2, this);
1026 done();
1027 }
1028 // Four options...
1029 template
1030 alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
1031 : AliasFor(0) {
1032 apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
1033 done();
1034 }
1035 };
1036
1037 // aliasfor - Modifier to set the option an alias aliases.
1038 struct aliasopt {
1039 Option &Opt;
1040 aliasopt(Option &O) : Opt(O) {}
1041 void apply(alias &A) const { A.setAliasFor(Opt); }
1042 };
1043
1044 } // End namespace cl
1045
1046 } // End namespace llvm
1047
1048 #endif
+0
-102
include/Support/DOTGraphTraits.h less more
None //===-- Support/DotGraphTraits.h - Customize .dot output --------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a template class that can be used to customize dot output
10 // graphs generated by the GraphWriter.h file. The default implementation of
11 // this file will produce a simple, but not very polished graph. By
12 // specializing this template, lots of customization opportunities are possible.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef SUPPORT_DOTGRAPHTRAITS_H
17 #define SUPPORT_DOTGRAPHTRAITS_H
18
19 #include
20
21 namespace llvm {
22
23 /// DefaultDOTGraphTraits - This class provides the default implementations of
24 /// all of the DOTGraphTraits methods. If a specialization does not need to
25 /// override all methods here it should inherit so that it can get the default
26 /// implementations.
27 ///
28 struct DefaultDOTGraphTraits {
29 /// getGraphName - Return the label for the graph as a whole. Printed at the
30 /// top of the graph.
31 ///
32 static std::string getGraphName(const void *Graph) { return ""; }
33
34 /// getGraphProperties - Return any custom properties that should be included
35 /// in the top level graph structure for dot.
36 ///
37 static std::string getGraphProperties(const void *Graph) {
38 return "";
39 }
40
41 /// getNodeLabel - Given a node and a pointer to the top level graph, return
42 /// the label to print in the node.
43 static std::string getNodeLabel(const void *Node, const void *Graph) {
44 return "";
45 }
46
47 /// If you want to specify custom node attributes, this is the place to do so
48 ///
49 static std::string getNodeAttributes(const void *Node) { return ""; }
50
51 /// If you want to override the dot attributes printed for a particular edge,
52 /// override this method.
53 template
54 static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
55 return "";
56 }
57
58 /// getEdgeSourceLabel - If you want to label the edge source itself,
59 /// implement this method.
60 template
61 static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
62 return "";
63 }
64
65 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
66 /// should actually target another edge source, not a node. If this method is
67 /// implemented, getEdgeTarget should be implemented.
68 template
69 static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
70 return false;
71 }
72
73 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
74 /// called to determine which outgoing edge of Node is the target of this
75 /// edge.
76 template
77 static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
78 return I;
79 }
80
81 /// addCustomGraphFeatures - If a graph is made up of more than just
82 /// straight-forward nodes and edges, this is the place to put all of the
83 /// custom stuff necessary. The GraphWriter object, instantiated with your
84 /// GraphType is passed in as an argument. You may call arbitrary methods on
85 /// it to add things to the output graph.
86 ///
87 template
88 static void addCustomGraphFeatures(const void *Graph, GraphWriter &GW) {}
89 };
90
91
92 /// DOTGraphTraits - Template class that can be specialized to customize how
93 /// graphs are converted to 'dot' graphs. When specializing, you may inherit
94 /// from DefaultDOTGraphTraits if you don't need to override everything.
95 ///
96 template
97 class DOTGraphTraits : public DefaultDOTGraphTraits {};
98
99 } // End llvm namespace
100
101 #endif
+0
-64
include/Support/DataTypes.h.in less more
None //===-- include/Support/DataTypes.h - Define fixed size types ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains definitions to figure out the size of _HOST_ data types.
10 // This file is important because different host OS's define different macros,
11 // which makes portability tough. This file exports the following definitions:
12 //
13 // [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types
14 // [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values.
15 //
16 // No library is required when using these functinons.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef SUPPORT_DATATYPES_H
21 #define SUPPORT_DATATYPES_H
22
23 // Note that this header's correct operation depends on __STDC_LIMIT_MACROS
24 // being defined. We would define it here, but in order to prevent Bad Things
25 // happening when system headers or C++ STL headers include stdint.h before
26 // we define it here, we define it on the g++ command line (in Makefile.rules).
27 #if !defined(__STDC_LIMIT_MACROS)
28 # error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
29 #endif
30
31 #ifndef _MSC_VER
32 // Note that includes , if this is a C99 system.
33 @INCLUDE_INTTYPES_H@
34 @INCLUDE_SYS_TYPES_H@
35 @INCLUDE_STDINT_H@
36 #else
37 // Visual C++ doesn't provide standard integer headers, but it does provide
38 // built-in data types.
39 typedef __int64 int64_t;
40 typedef unsigned __int64 uint64_t;
41 typedef signed int int32_t;
42 typedef unsigned int uint32_t;
43 typedef signed int ssize_t;
44 #define INT8_MAX 127
45 #define INT8_MIN -128
46 #define UINT8_MAX 255
47 #define INT16_MAX 32767
48 #define INT16_MIN -32768
49 #define UINT16_MAX 65535
50 #define INT32_MAX 2147483647
51 #define INT32_MIN -2147483648
52 #define UINT32_MAX 4294967295U
53 #endif
54
55 #if !defined(INT64_MAX)
56 /* We couldn't determine INT64_MAX; default it. */
57 # define INT64_MAX 9223372036854775807LL
58 #endif
59 #if !defined(UINT64_MAX)
60 # define UINT64_MAX 0xffffffffffffffffULL
61 #endif
62
63 #endif /* SUPPORT_DATATYPES_H */
+0
-67
include/Support/Debug.h less more
None //===- Debug.h - An easy way to add debug output to your code ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a handle way of adding debugging information to your
10 // code, without it being enabled all of the time, and without having to add
11 // command line options to enable it.
12 //
13 // In particular, just wrap your code with the DEBUG() macro, and it will be
14 // enabled automatically if you specify '-debug' on the command-line.
15 // Alternatively, you can also use the SET_DEBUG_TYPE("foo") macro to specify
16 // that your debug code belongs to class "foo". Then, on the command line, you
17 // can specify '-debug-only=foo' to enable JUST the debug information for the
18 // foo class.
19 //
20 // When compiling in release mode, the -debug-* options and all code in DEBUG()
21 // statements disappears, so it does not effect the runtime of the code.
22 //
23 //===----------------------------------------------------------------------===//
24
25 #ifndef SUPPORT_DEBUG_H
26 #define SUPPORT_DEBUG_H
27
28 // Unsurprisingly, most users of this macro use std::cerr too.
29 #include
30
31 namespace llvm {
32
33 // DebugFlag - This boolean is set to true if the '-debug' command line option
34 // is specified. This should probably not be referenced directly, instead, use
35 // the DEBUG macro below.
36 //
37 extern bool DebugFlag;
38
39 // isCurrentDebugType - Return true if the specified string is the debug type
40 // specified on the command line, or if none was specified on the command line
41 // with the -debug-only=X option.
42 //
43 bool isCurrentDebugType(const char *Type);
44
45 // DEBUG macro - This macro should be used by passes to emit debug information.
46 // In the '-debug' option is specified on the commandline, and if this is a
47 // debug build, then the code specified as the option to the macro will be
48 // executed. Otherwise it will not be. Example:
49 //
50 // DEBUG(cerr << "Bitset contains: " << Bitset << "\n");
51 //
52
53 #ifndef DEBUG_TYPE
54 #define DEBUG_TYPE ""
55 #endif
56
57 #ifdef NDEBUG
58 #define DEBUG(X)
59 #else
60 #define DEBUG(X) \
61 do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0)
62 #endif
63
64 } // End llvm namespace
65
66 #endif
+0
-73
include/Support/DenseMap.h less more
None //===- DenseMap.h - A dense map implmentation -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a dense map. A dense map template takes two
10 // types. The first is the mapped type and the second is a functor
11 // that maps its argument to a size_t. On instantiation a "null" value
12 // can be provided to be used as a "does not exist" indicator in the
13 // map. A member function grow() is provided that given the value of
14 // the maximally indexed key (the argument of the functor) makes sure
15 // the map has enough space for it.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef SUPPORT_DENSEMAP_H
20 #define SUPPORT_DENSEMAP_H
21
22 #include
23
24 namespace llvm {
25
26 struct IdentityFunctor : std::unary_function {
27 unsigned operator()(unsigned Index) const {
28 return Index;
29 }
30 };
31
32 template
33 class DenseMap {
34 typedef typename ToIndexT::argument_type IndexT;
35 typedef std::vector StorageT;
36 StorageT storage_;
37 T nullVal_;
38 ToIndexT toIndex_;
39
40 public:
41 DenseMap() : nullVal_(T()) { }
42
43 explicit DenseMap(const T& val) : nullVal_(val) { }
44
45 typename StorageT::reference operator[](IndexT n) {
46 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
47 return storage_[toIndex_(n)];
48 }
49
50 typename StorageT::const_reference operator[](IndexT n) const {
51 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
52 return storage_[toIndex_(n)];
53 }
54
55 void clear() {
56 storage_.clear();
57 }
58
59 void grow(IndexT n) {
60 unsigned NewSize = toIndex_(n) + 1;
61 if (NewSize > storage_.size())
62 storage_.resize(NewSize, nullVal_);
63 }
64
65 typename StorageT::size_type size() const {
66 return storage_.size();
67 }
68 };
69
70 } // End llvm namespace
71
72 #endif
+0
-230
include/Support/DepthFirstIterator.h less more
None //===- Support/DepthFirstIterator.h - Depth First iterator ------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file builds on the Support/GraphTraits.h file to build generic depth
10 // first graph iterator. This file exposes the following functions/types:
11 //
12 // df_begin/df_end/df_iterator
13 // * Normal depth-first iteration - visit a node and then all of its children.
14 //
15 // idf_begin/idf_end/idf_iterator
16 // * Depth-first iteration on the 'inverse' graph.
17 //
18 // df_ext_begin/df_ext_end/df_ext_iterator
19 // * Normal depth-first iteration - visit a node and then all of its children.
20 // This iterator stores the 'visited' set in an external set, which allows
21 // it to be more efficient, and allows external clients to use the set for
22 // other purposes.
23 //
24 // idf_ext_begin/idf_ext_end/idf_ext_iterator
25 // * Depth-first iteration on the 'inverse' graph.
26 // This iterator stores the 'visited' set in an external set, which allows
27 // it to be more efficient, and allows external clients to use the set for
28 // other purposes.
29 //
30 //===----------------------------------------------------------------------===//
31
32 #ifndef SUPPORT_DEPTHFIRSTITERATOR_H
33 #define SUPPORT_DEPTHFIRSTITERATOR_H
34
35 #include "Support/GraphTraits.h"
36 #include "Support/iterator"
37 #include
38 #include
39
40 namespace llvm {
41
42 // df_iterator_storage - A private class which is used to figure out where to
43 // store the visited set.
44 template // Non-external set
45 class df_iterator_storage {
46 public:
47 SetType Visited;
48 };
49
50 template
51 class df_iterator_storage {
52 public:
53 df_iterator_storage(SetType &VSet) : Visited(VSet) {}
54 df_iterator_storage(const df_iterator_storage &S) : Visited(S.Visited) {}
55 SetType &Visited;
56 };
57
58
59 // Generic Depth First Iterator
60 template
61 std::set::NodeType*>,
62 bool ExtStorage = false, class GT = GraphTraits >
63 class df_iterator : public forward_iterator,
64 public df_iterator_storage {
65 typedef forward_iterator super;
66
67 typedef typename GT::NodeType NodeType;
68 typedef typename GT::ChildIteratorType ChildItTy;
69
70 // VisitStack - Used to maintain the ordering. Top = current block
71 // First element is node pointer, second is the 'next child' to visit
72 std::vector > VisitStack;
73 private:
74 inline df_iterator(NodeType *Node) {
75 this->Visited.insert(Node);
76 VisitStack.push_back(std::make_pair(Node, GT::child_begin(Node)));
77 }
78 inline df_iterator() { /* End is when stack is empty */ }
79
80 inline df_iterator(NodeType *Node, SetType &S)
81 : df_iterator_storage(S) {
82 if (!S.count(Node)) {
83 this->Visited.insert(Node);
84 VisitStack.push_back(std::make_pair(Node, GT::child_begin(Node)));
85 }
86 }
87 inline df_iterator(SetType &S)
88 : df_iterator_storage(S) {
89 // End is when stack is empty
90 }
91
92 public:
93 typedef typename super::pointer pointer;
94 typedef df_iterator _Self;
95
96 // Provide static begin and end methods as our public "constructors"
97 static inline _Self begin(GraphT G) {
98 return _Self(GT::getEntryNode(G));
99 }
100 static inline _Self end(GraphT G) { return _Self(); }
101
102 // Static begin and end methods as our public ctors for external iterators
103 static inline _Self begin(GraphT G, SetType &S) {
104 return _Self(GT::getEntryNode(G), S);
105 }
106 static inline _Self end(GraphT G, SetType &S) { return _Self(S); }
107
108 inline bool operator==(const _Self& x) const {
109 return VisitStack.size() == x.VisitStack.size() &&
110 VisitStack == x.VisitStack;
111 }
112 inline bool operator!=(const _Self& x) const { return !operator==(x); }
113
114 inline pointer operator*() const {
115 return VisitStack.back().first;
116 }
117
118 // This is a nonstandard operator-> that dereferences the pointer an extra
119 // time... so that you can actually call methods ON the Node, because
120 // the contained type is a pointer. This allows BBIt->getTerminator() f.e.
121 //
122 inline NodeType *operator->() const { return operator*(); }
123
124 inline _Self& operator++() { // Preincrement
125 do {
126 std::pair &Top = VisitStack.back();
127 NodeType *Node = Top.first;
128 ChildItTy &It = Top.second;
129
130 while (It != GT::child_end(Node)) {
131 NodeType *Next = *It++;
132 if (!this->Visited.count(Next)) { // Has our next sibling been visited?
133 // No, do it now.
134 this->Visited.insert(Next);
135 VisitStack.push_back(std::make_pair(Next, GT::child_begin(Next)));
136 return *this;
137 }
138 }
139
140 // Oops, ran out of successors... go up a level on the stack.
141 VisitStack.pop_back();
142 } while (!VisitStack.empty());
143 return *this;
144 }
145
146 inline _Self operator++(int) { // Postincrement
147 _Self tmp = *this; ++*this; return tmp;
148 }
149
150 // nodeVisited - return true if this iterator has already visited the
151 // specified node. This is public, and will probably be used to iterate over
152 // nodes that a depth first iteration did not find: ie unreachable nodes.
153 //
154 inline bool nodeVisited(NodeType *Node) const {
155 return this->Visited.count(Node) != 0;
156 }
157 };
158
159
160 // Provide global constructors that automatically figure out correct types...
161 //
162 template
163 df_iterator df_begin(T G) {
164 return df_iterator::begin(G);
165 }
166
167 template
168 df_iterator df_end(T G) {
169 return df_iterator::end(G);
170 }
171
172 // Provide global definitions of external depth first iterators...
173 template ::NodeType*> >
174 struct df_ext_iterator : public df_iterator {
175 df_ext_iterator(const df_iterator &V)
176 : df_iterator(V) {}
177 };
178
179 template
180 df_ext_iterator df_ext_begin(T G, SetTy &S) {
181 return df_ext_iterator::begin(G, S);
182 }
183
184 template
185 df_ext_iterator df_ext_end(T G, SetTy &S) {
186 return df_ext_iterator::end(G, S);
187 }
188
189
190 // Provide global definitions of inverse depth first iterators...
191 template ::NodeType*>,
192 bool External = false>
193 struct idf_iterator : public df_iterator, SetTy, External> {
194 idf_iterator(const df_iterator, SetTy, External> &V)
195 : df_iterator, SetTy, External>(V) {}
196 };
197
198 template
199 idf_iterator idf_begin(T G) {
200 return idf_iterator::begin(G);
201 }
202
203 template
204 idf_iterator idf_end(T G){
205 return idf_iterator::end(G);
206 }
207
208 // Provide global definitions of external inverse depth first iterators...
209 template ::NodeType*> >
210 struct idf_ext_iterator : public idf_iterator {
211 idf_ext_iterator(const idf_iterator &V)
212 : idf_iterator(V) {}
213 idf_ext_iterator(const df_iterator, SetTy, true> &V)
214 : idf_iterator(V) {}
215 };
216
217 template
218 idf_ext_iterator idf_ext_begin(T G, SetTy &S) {
219 return idf_ext_iterator::begin(G, S);
220 }
221
222 template
223 idf_ext_iterator idf_ext_end(T G, SetTy &S) {
224 return idf_ext_iterator::end(G, S);
225 }
226
227 } // End llvm namespace
228
229 #endif
+0
-40
include/Support/DynamicLinker.h less more
None //===-- DynamicLinker.h - System-indep. DynamicLinker interface -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Lightweight interface to dynamic library linking and loading, and dynamic
10 // symbol lookup functionality, in whatever form the operating system
11 // provides it.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SUPPORT_DYNAMICLINKER_H
16 #define SUPPORT_DYNAMICLINKER_H
17
18 #include
19
20 namespace llvm {
21
22 /// LinkDynamicObject - Load the named file as a dynamic library
23 /// and link it with the currently running process. Returns false
24 /// on success, true if there is an error (and sets ErrorMessage
25 /// if it is not NULL). Analogous to dlopen().
26 ///
27 bool LinkDynamicObject (const char *filename, std::string *ErrorMessage);
28
29 /// GetAddressOfSymbol - Returns the address of the named symbol in
30 /// the currently running process, as reported by the dynamic linker,
31 /// or NULL if the symbol does not exist or some other error has
32 /// occurred.
33 ///
34 void *GetAddressOfSymbol (const char *symbolName);
35 void *GetAddressOfSymbol (const std::string &symbolName);
36
37 } // End llvm namespace
38
39 #endif // SUPPORT_DYNAMICLINKER_H
+0
-295
include/Support/ELF.h less more
None //===-- Support/ELF.h - ELF constants and data structures -------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header contains common, non-processor-specific data structures and
10 // constants for the ELF file format.
11 //
12 // The details of the ELF32 bits in this file are largely based on
13 // the Tool Interface Standard (TIS) Executable and Linking Format
14 // (ELF) Specification Version 1.2, May 1995. The ELF64 stuff is not
15 // standardized, as far as I can tell. It was largely based on information
16 // I found in OpenBSD header files.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #include "Support/DataTypes.h"
21 #include
22 #include
23
24 namespace llvm {
25
26 namespace ELF {
27
28 typedef uint32_t Elf32_Addr; // Program address
29 typedef uint16_t Elf32_Half;
30 typedef uint32_t Elf32_Off; // File offset
31 typedef int32_t Elf32_Sword;
32 typedef uint32_t Elf32_Word;
33
34 typedef uint64_t Elf64_Addr;
35 typedef uint64_t Elf64_Off;
36 typedef int32_t Elf64_Shalf;
37 typedef int32_t Elf64_Sword;
38 typedef uint32_t Elf64_Word;
39 typedef int64_t Elf64_Sxword;
40 typedef uint64_t Elf64_Xword;
41 typedef uint32_t Elf64_Half;
42 typedef uint16_t Elf64_Quarter;
43
44 // Object file magic string.
45 static const char ElfMagic[] = { 0x7f, 'E', 'L', 'F', '\0' };
46
47 struct Elf32_Ehdr {
48 unsigned char e_ident[16]; // ELF Identification bytes
49 Elf32_Half e_type; // Type of file (see ET_* below)
50 Elf32_Half e_machine; // Required architecture for this file (see EM_*)
51 Elf32_Word e_version; // Must be equal to 1
52 Elf32_Addr e_entry; // Address to jump to in order to start program
53 Elf32_Off e_phoff; // Program header table's file offset, in bytes
54 Elf32_Off e_shoff; // Section header table's file offset, in bytes
55 Elf32_Word e_flags; // Processor-specific flags
56 Elf32_Half e_ehsize; // Size of ELF header, in bytes
57 Elf32_Half e_phentsize; // Size of an entry in the program header table
58 Elf32_Half e_phnum; // Number of entries in the program header table
59 Elf32_Half e_shentsize; // Size of an entry in the section header table
60 Elf32_Half e_shnum; // Number of entries in the section header table
61 Elf32_Half e_shstrndx; // Sect hdr table index of sect name string table
62 bool checkMagic () const {
63 return (memcmp (e_ident, ElfMagic, strlen (ElfMagic))) == 0;
64 }
65 unsigned char getFileClass () const { return e_ident[4]; }
66 unsigned char getDataEncoding () { return e_ident[5]; }
67 };
68
69 // 64-bit ELF header. Fields are the same as for ELF32, but with different
70 // types (see above).
71 struct Elf64_Ehdr {
72 unsigned char e_ident[16];
73 Elf64_Quarter e_type;
74 Elf64_Quarter e_machine;
75 Elf64_Half e_version;
76 Elf64_Addr e_entry;
77 Elf64_Off e_phoff;
78 Elf64_Off e_shoff;
79 Elf64_Half e_flags;
80 Elf64_Quarter e_ehsize;
81 Elf64_Quarter e_phentsize;
82 Elf64_Quarter e_phnum;
83 Elf64_Quarter e_shentsize;
84 Elf64_Quarter e_shnum;
85 Elf64_Quarter e_shstrndx;
86 };
87
88 // File types
89 enum {
90 ET_NONE = 0, // No file type
91 ET_REL = 1, // Relocatable file
92 ET_EXEC = 2, // Executable file
93 ET_DYN = 3, // Shared object file
94 ET_CORE = 4, // Core file
95 ET_LOPROC = 0xff00, // Beginning of processor-specific codes
96 ET_HIPROC = 0xffff // Processor-specific
97 };
98
99 // Machine architectures
100 enum {
101 EM_NONE = 0, // No machine
102 EM_M32 = 1, // AT&T WE 32100
103 EM_SPARC = 2, // SPARC
104 EM_386 = 3, // Intel 386
105 EM_68K = 4, // Motorola 68000
106 EM_88K = 5, // Motorola 88000
107 EM_486 = 6, // Intel 486 (deprecated)
108 EM_860 = 7, // Intel 80860
109 EM_MIPS = 8, // MIPS R3000
110 EM_PPC = 20, // PowerPC
111 EM_ARM = 40, // ARM
112 EM_ALPHA = 41, // DEC Alpha
113 EM_SPARCV9 = 43 // SPARC V9
114 };
115
116 // Object file classes.
117 enum {
118 ELFCLASS32 = 1, // 32-bit object file
119 ELFCLASS64 = 2 // 64-bit object file
120 };
121
122 // Object file byte orderings.
123 enum {
124 ELFDATA2LSB = 1, // Little-endian object file
125 ELFDATA2MSB = 2 // Big-endian object file
126 };
127
128 // Section header.
129 struct Elf32_Shdr {
130 Elf32_Word sh_name; // Section name (index into string table)
131 Elf32_Word sh_type; // Section type (SHT_*)
132 Elf32_Word sh_flags; // Section flags (SHF_*)
133 Elf32_Addr sh_addr; // Address where section is to be loaded
134 Elf32_Off sh_offset; // File offset of section data, in bytes
135 Elf32_Word sh_size; // Size of section, in bytes
136 Elf32_Word sh_link; // Section type-specific header table index link
137 Elf32_Word sh_info; // Section type-specific extra information
138 Elf32_Word sh_addralign; // Section address alignment
139 Elf32_Word sh_entsize; // Size of records contained within the section
140 };
141
142 // Section header for ELF64 - same fields as ELF32, different types.
143 struct Elf64_Shdr {
144 Elf64_Half sh_name;
145 Elf64_Half sh_type;
146 Elf64_Xword sh_flags;
147 Elf64_Addr sh_addr;
148 Elf64_Off sh_offset;
149 Elf64_Xword sh_size;
150 Elf64_Half sh_link;
151 Elf64_Half sh_info;
152 Elf64_Xword sh_addralign;
153 Elf64_Xword sh_entsize;
154 };
155
156 // Special section indices.
157 enum {
158 SHN_UNDEF = 0, // Undefined, missing, irrelevant, or meaningless
159 SHN_LORESERVE = 0xff00, // Lowest reserved index
160 SHN_LOPROC = 0xff00, // Lowest processor-specific index
161 SHN_HIPROC = 0xff1f, // Highest processor-specific index
162 SHN_ABS = 0xfff1, // Symbol has absolute value; does not need relocation
163 SHN_COMMON = 0xfff2, // FORTRAN COMMON or C external global variables
164 SHN_HIRESERVE = 0xffff // Highest reserved index
165 };
166
167 // Section types.
168 enum {
169 SHT_NULL = 0, // No associated section (inactive entry).
170 SHT_PROGBITS = 1, // Program-defined contents.
171 SHT_SYMTAB = 2, // Symbol table.
172 SHT_STRTAB = 3, // String table.
173 SHT_RELA = 4, // Relocation entries; explicit addends.
174 SHT_HASH = 5, // Symbol hash table.
175 SHT_DYNAMIC = 6, // Information for dynamic linking.
176 SHT_NOTE = 7, // Information about the file.
177 SHT_NOBITS = 8, // Data occupies no space in the file.
178 SHT_REL = 9, // Relocation entries; no explicit addends.
179 SHT_SHLIB = 10, // Reserved.
180 SHT_DYNSYM = 11, // Symbol table.
181 SHT_LOPROC = 0x70000000, // Lowest processor architecture-specific type.
182 SHT_HIPROC = 0x7fffffff, // Highest processor architecture-specific type.
183 SHT_LOUSER = 0x80000000, // Lowest type reserved for applications.
184 SHT_HIUSER = 0xffffffff // Highest type reserved for applications.
185 };
186
187 // Section flags.
188 enum {
189 SHF_WRITE = 0x1, // Section data should be writable during execution.
190 SHF_ALLOC = 0x2, // Section occupies memory during program execution.
191 SHF_EXECINSTR = 0x4, // Section contains executable machine instructions.
192 SHF_MASKPROC = 0xf0000000 // Bits indicating processor-specific flags.
193 };
194
195 // Symbol table entries.
196 struct Elf32_Sym {
197 Elf32_Word st_name; // Symbol name (index into string table)
198 Elf32_Addr st_value; // Value or address associated with the symbol
199 Elf32_Word st_size; // Size of the symbol
200 unsigned char st_info; // Symbol's type and binding attributes
201 unsigned char st_other; // Must be zero; reserved
202 Elf32_Half st_shndx; // Which section (header table index) it's defined in
203
204 // These accessors and mutators correspond to the ELF32_ST_BIND,
205 // ELF32_ST_TYPE, and ELF32_ST_INFO macros defined in the ELF specification:
206 unsigned char getBinding () const { return st_info >> 4; }
207 unsigned char getType () const { return st_info & 0x0f; }
208 void setBinding (unsigned char b) { setBindingAndType (b, getType ()); }
209 void setType (unsigned char t) { setBindingAndType (getBinding (), t); }
210 void setBindingAndType (unsigned char b, unsigned char t) {
211 st_info = (b << 4) + (t & 0x0f);
212 }
213 };
214
215 // Symbol bindings.
216 enum {
217 STB_LOCAL = 0, // Local symbol, not visible outside obj file containing def
218 STB_GLOBAL = 1, // Global symbol, visible to all object files being combined
219 STB_WEAK = 2, // Weak symbol, like global but lower-precedence
220 STB_LOPROC = 13, // Lowest processor-specific binding type
221 STB_HIPROC = 15 // Highest processor-specific binding type
222 };
223
224 // Symbol types.
225 enum {
226 STT_NOTYPE = 0, // Symbol's type is not specified
227 STT_OBJECT = 1, // Symbol is a data object (variable, array, etc.)
228 STT_FUNC = 2, // Symbol is executable code (function, etc.)
229 STT_SECTION = 3, // Symbol refers to a section
230 STT_FILE = 4, // Local, absolute symbol that refers to a file
231 STT_LOPROC = 13, // Lowest processor-specific symbol type
232 STT_HIPROC = 15 // Highest processor-specific symbol type
233 };
234
235 // Relocation entry, without explicit addend.
236 struct Elf32_Rel {
237 Elf32_Addr r_offset; // Location (file byte offset, or program virtual addr)
238 Elf32_Word r_info; // Symbol table index and type of relocation to apply
239
240 // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
241 // and ELF32_R_INFO macros defined in the ELF specification:
242 Elf32_Word getSymbol () const { return (r_info >> 8); }
243 unsigned char getType () const { return (unsigned char) (r_info & 0x0ff); }
244 void setSymbol (Elf32_Word s) { setSymbolAndType (s, getType ()); }
245 void setType (unsigned char t) { setSymbolAndType (getSymbol(), t); }
246 void setSymbolAndType (Elf32_Word s, unsigned char t) {
247 r_info = (s << 8) + t;
248 };
249 };
250
251 // Relocation entry with explicit addend.
252 struct Elf32_Rela {
253 Elf32_Addr r_offset; // Location (file byte offset, or program virtual addr)
254 Elf32_Word r_info; // Symbol table index and type of relocation to apply
255 Elf32_Sword r_addend; // Compute value for relocatable field by adding this
256
257 // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
258 // and ELF32_R_INFO macros defined in the ELF specification:
259 Elf32_Word getSymbol () const { return (r_info >> 8); }
260 unsigned char getType () const { return (unsigned char) (r_info & 0x0ff); }
261 void setSymbol (Elf32_Word s) { setSymbolAndType (s, getType ()); }
262 void setType (unsigned char t) { setSymbolAndType (getSymbol(), t); }
263 void setSymbolAndType (Elf32_Word s, unsigned char t) {
264 r_info = (s << 8) + t;
265 };
266 };
267
268 // Program header.
269 struct Elf32_Phdr {
270 Elf32_Word p_type; // Type of segment
271 Elf32_Off p_offset; // File offset where segment is located, in bytes
272 Elf32_Addr p_vaddr; // Virtual address of beginning of segment
273 Elf32_Addr p_paddr; // Physical address of beginning of segment (OS-specific)
274 Elf32_Word p_filesz; // Num. of bytes in file image of segment (may be zero)
275 Elf32_Word p_memsz; // Num. of bytes in mem image of segment (may be zero)
276 Elf32_Word p_flags; // Segment flags
277 Elf32_Word p_align; // Segment alignment constraint
278 };
279
280 enum {
281 PT_NULL = 0, // Unused segment.
282 PT_LOAD = 1, // Loadable segment.
283 PT_DYNAMIC = 2, // Dynamic linking information.
284 PT_INTERP = 3, // Interpreter pathname.
285 PT_NOTE = 4, // Auxiliary information.
286 PT_SHLIB = 5, // Reserved.
287 PT_PHDR = 6, // The program header table itself.
288 PT_LOPROC = 0x70000000, // Lowest processor-specific program hdr entry type.
289 PT_HIPROC = 0x7fffffff // Highest processor-specific program hdr entry type.
290 };
291
292 } // end namespace ELF
293
294 } // end namespace llvm
+0
-116
include/Support/EquivalenceClasses.h less more
None //===-- Support/EquivalenceClasses.h ----------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Generic implementation of equivalence classes and implementation of
10 // union-find algorithms A not-so-fancy implementation: 2 level tree i.e root
11 // and one more level Overhead of a union = size of the equivalence class being
12 // attached Overhead of a find = 1.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef SUPPORT_EQUIVALENCECLASSES_H
17 #define SUPPORT_EQUIVALENCECLASSES_H
18
19 #include
20 #include
21 #include
22
23 namespace llvm {
24
25 template
26 class EquivalenceClasses {
27 // Maps each element to the element that is the leader of its
28 // equivalence class.
29 std::map Elem2LeaderMap;
30
31 // Maintains the set of leaders
32 std::set LeaderSet;
33
34 // Caches the equivalence class for each leader
35 std::map > LeaderToEqClassMap;
36
37 // Make Element2 the leader of the union of classes Element1 and Element2
38 // Element1 and Element2 are presumed to be leaders of their respective
39 // equivalence classes.
40 void attach(ElemTy Element1, ElemTy Element2) {
41 for (typename std::map::iterator ElemI =
42 Elem2LeaderMap.begin(), ElemE = Elem2LeaderMap.end();
43 ElemI != ElemE; ++ElemI) {
44 if (ElemI->second == Element1)
45 Elem2LeaderMap[ElemI->first] = Element2;
46 }
47 }
48
49 public:
50 // If an element has not yet in any class, make it a separate new class.
51 // Return the leader of the class containing the element.
52 ElemTy addElement (ElemTy NewElement) {
53 typename std::map::iterator ElemI =
54 Elem2LeaderMap.find(NewElement);
55 if (ElemI == Elem2LeaderMap.end()) {
56 Elem2LeaderMap[NewElement] = NewElement;
57 LeaderSet.insert(NewElement);
58 return NewElement;
59 }
60 else
61 return ElemI->second;
62 }
63
64 ElemTy findClass(ElemTy Element) const {
65 typename std::map::const_iterator I =
66 Elem2LeaderMap.find(Element);
67 return (I == Elem2LeaderMap.end())? (ElemTy) 0 : I->second;
68 }
69
70 /// Attach the set with Element1 to the set with Element2 adding Element1 and
71 /// Element2 to the set of equivalence classes if they are not there already.
72 /// Implication: Make Element1 the element in the smaller set.
73 /// Take Leader[Element1] out of the set of leaders.
74 void unionSetsWith(ElemTy Element1, ElemTy Element2) {
75 // If either Element1 or Element2 does not already exist, include it
76 const ElemTy& leader1 = addElement(Element1);
77 const ElemTy& leader2 = addElement(Element2);
78 assert(leader1 != (ElemTy) 0 && leader2 != (ElemTy) 0);
79 if (leader1 != leader2) {
80 attach(leader1, leader2);
81 LeaderSet.erase(leader1);
82 }
83 }
84
85 // Returns a vector containing all the elements in the equivalence class
86 // including Element1
87 const std::set & getEqClass(ElemTy Element1) {
88 assert(Elem2LeaderMap.find(Element1) != Elem2LeaderMap.end());
89 const ElemTy classLeader = Elem2LeaderMap[Element1];
90
91 std::set & EqClass = LeaderToEqClassMap[classLeader];
92
93 // If the EqClass vector is empty, it has not been computed yet: do it now
94 if (EqClass.empty()) {
95 for (typename std::map::iterator
96 ElemI = Elem2LeaderMap.begin(), ElemE = Elem2LeaderMap.end();
97 ElemI != ElemE; ++ElemI)
98 if (ElemI->second == classLeader)
99 EqClass.insert(ElemI->first);
100 assert(! EqClass.empty()); // must at least include the leader
101 }
102
103 return EqClass;
104 }
105
106 std::set& getLeaderSet() { return LeaderSet; }
107 const std::set& getLeaderSet() const { return LeaderSet; }
108
109 std::map& getLeaderMap() { return Elem2LeaderMap;}
110 const std::map& getLeaderMap() const { return Elem2LeaderMap;}
111 };
112
113 } // End llvm namespace
114
115 #endif
+0
-170
include/Support/FileUtilities.h less more
None //===- Support/FileUtilities.h - File System Utilities ----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a family of utility functions which are useful for doing
10 // various things with files.
11 //
12 //===----------------------------------------------------------------------===//
13
14