llvm.org GIT mirror llvm / 1f6efa3
Merge System into Support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120298 91177308-0d34-0410-b5e6-96231b3b80d8 Michael J. Spencer 8 years ago
350 changed file(s) with 12512 addition(s) and 12538 deletion(s). Raw diff Collapse all Expand all
275275 include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR})
276276
277277 if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
278 SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/System/Solaris.h")
278 SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h")
279279 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
280280
281281 include(AddLLVM)
291291 endif()
292292
293293 add_subdirectory(lib/Support)
294 add_subdirectory(lib/System)
295
296 # Everything else depends on Support and System:
294
295 # Everything else depends on Support:
297296 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} )
298297
299298 set(LLVM_TABLEGEN "tblgen" CACHE
345344 set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
346345 file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
347346 if( asmp_file )
348 set(LLVM_ENUM_ASM_PRINTERS
347 set(LLVM_ENUM_ASM_PRINTERS
349348 "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
350349 endif()
351350 if( EXISTS ${td}/InstPrinter/CMakeLists.txt )
353352 endif()
354353 if( EXISTS ${td}/AsmParser/CMakeLists.txt )
355354 add_subdirectory(lib/Target/${t}/AsmParser)
356 set(LLVM_ENUM_ASM_PARSERS
355 set(LLVM_ENUM_ASM_PARSERS
357356 "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
358357 endif()
359358 if( EXISTS ${td}/Disassembler/CMakeLists.txt )
99 LEVEL := .
1010
1111 # Top-Level LLVM Build Stages:
12 # 1. Build lib/System and lib/Support, which are used by utils (tblgen).
12 # 1. Build lib/Support, which is used by utils (tblgen).
1313 # 2. Build utils, which is used by VMCore.
1414 # 3. Build VMCore, which builds the Intrinsics.inc file used by libs.
1515 # 4. Build libs, which are needed by llvm-config.
2626 ifneq ($(findstring llvmCore, $(RC_ProjectName)),llvmCore) # Normal build (not "Apple-style").
2727
2828 ifeq ($(BUILD_DIRS_ONLY),1)
29 DIRS := lib/System lib/Support utils
29 DIRS := lib/Support utils
3030 OPTIONAL_DIRS :=
3131 else
32 DIRS := lib/System lib/Support utils lib/VMCore lib tools/llvm-shlib \
32 DIRS := lib/Support utils lib/VMCore lib tools/llvm-shlib \
3333 tools/llvm-config tools runtime docs unittests
3434 OPTIONAL_DIRS := projects bindings
3535 endif
158158 $(Echo) Eliminating files constructed by configure
159159 $(Verb) $(RM) -f \
160160 $(TopDistDir)/include/llvm/Config/config.h \
161 $(TopDistDir)/include/llvm/System/DataTypes.h
161 $(TopDistDir)/include/llvm/Support/DataTypes.h
162162
163163 clang-only: all
164164 tools-only: all
177177 include/llvm/Config/AsmPrinters.def \
178178 include/llvm/Config/AsmParsers.def \
179179 include/llvm/Config/Disassemblers.def \
180 include/llvm/System/DataTypes.h \
180 include/llvm/Support/DataTypes.h \
181181 tools/llvmc/src/Base.td
182182 FilesToConfigPATH := $(addprefix $(LLVM_OBJ_ROOT)/,$(FilesToConfig))
183183
633633 endif
634634
635635 ifeq ($(HOST_OS),SunOS)
636 CPP.BaseFlags += -include llvm/System/Solaris.h
636 CPP.BaseFlags += -include llvm/Support/Solaris.h
637637 endif
638638
639639 ifeq ($(HOST_OS),AuroraUX)
640 CPP.BaseFlags += -include llvm/System/Solaris.h
640 CPP.BaseFlags += -include llvm/Support/Solaris.h
641641 endif # !HOST_OS - AuroraUX.
642642
643643 LD.Flags += -L$(LibDir) -L$(LLVMLibDir)
318318 AC_SUBST(NOLINKALL,$llvm_cv_no_link_all_option)
319319
320320 dnl Set the "LLVM_ON_*" variables based on llvm_cv_platform_type
321 dnl This is used by lib/System to determine the basic kind of implementation
321 dnl This is used by lib/Support to determine the basic kind of implementation
322322 dnl to use.
323323 case $llvm_cv_platform_type in
324324 Unix)
16241624 AC_CONFIG_FILES([include/llvm/Config/AsmPrinters.def])
16251625 AC_CONFIG_FILES([include/llvm/Config/AsmParsers.def])
16261626 AC_CONFIG_FILES([include/llvm/Config/Disassemblers.def])
1627 AC_CONFIG_HEADERS([include/llvm/System/DataTypes.h])
1627 AC_CONFIG_HEADERS([include/llvm/Support/DataTypes.h])
16281628
16291629 dnl Configure the makefile's configuration data
16301630 AC_CONFIG_FILES([Makefile.config])
276276 )
277277
278278 configure_file(
279 ${LLVM_MAIN_INCLUDE_DIR}/llvm/System/DataTypes.h.cmake
280 ${LLVM_BINARY_DIR}/include/llvm/System/DataTypes.h
279 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
280 ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h
281281 )
282282
2091920919
2092020920 ac_config_files="$ac_config_files include/llvm/Config/Disassemblers.def"
2092120921
20922 ac_config_headers="$ac_config_headers include/llvm/System/DataTypes.h"
20922 ac_config_headers="$ac_config_headers include/llvm/Support/DataTypes.h"
2092320923
2092420924
2092520925 ac_config_files="$ac_config_files Makefile.config"
2154521545 "include/llvm/Config/AsmPrinters.def") CONFIG_FILES="$CONFIG_FILES include/llvm/Config/AsmPrinters.def" ;;
2154621546 "include/llvm/Config/AsmParsers.def") CONFIG_FILES="$CONFIG_FILES include/llvm/Config/AsmParsers.def" ;;
2154721547 "include/llvm/Config/Disassemblers.def") CONFIG_FILES="$CONFIG_FILES include/llvm/Config/Disassemblers.def" ;;
21548 "include/llvm/System/DataTypes.h") CONFIG_HEADERS="$CONFIG_HEADERS include/llvm/System/DataTypes.h" ;;
21548 "include/llvm/Support/DataTypes.h") CONFIG_HEADERS="$CONFIG_HEADERS include/llvm/Support/DataTypes.h" ;;
2154921549 "Makefile.config") CONFIG_FILES="$CONFIG_FILES Makefile.config" ;;
2155021550 "llvm.spec") CONFIG_FILES="$CONFIG_FILES llvm.spec" ;;
2155121551 "tools/llvmc/src/Base.td") CONFIG_FILES="$CONFIG_FILES tools/llvmc/src/Base.td" ;;
1414 #ifndef LLVM_ADT_EQUIVALENCECLASSES_H
1515 #define LLVM_ADT_EQUIVALENCECLASSES_H
1616
17 #include "llvm/System/DataTypes.h"
17 #include "llvm/Support/DataTypes.h"
1818 #include
1919 #include
2020
1515 #ifndef LLVM_ADT_FOLDINGSET_H
1616 #define LLVM_ADT_FOLDINGSET_H
1717
18 #include "llvm/System/DataTypes.h"
18 #include "llvm/Support/DataTypes.h"
1919 #include "llvm/ADT/SmallVector.h"
2020 #include "llvm/ADT/StringRef.h"
2121
1515
1616 #include "llvm/Support/Allocator.h"
1717 #include "llvm/ADT/FoldingSet.h"
18 #include "llvm/System/DataTypes.h"
18 #include "llvm/Support/DataTypes.h"
1919 #include
2020
2121 namespace llvm {
1515
1616 #include "llvm/Support/Allocator.h"
1717 #include "llvm/ADT/FoldingSet.h"
18 #include "llvm/System/DataTypes.h"
18 #include "llvm/Support/DataTypes.h"
1919 #include
2020 #include
2121
1717 #include
1818 #include
1919 #include
20 #include "llvm/System/DataTypes.h"
20 #include "llvm/Support/DataTypes.h"
2121 #include "llvm/Support/PointerLikeTypeTraits.h"
2222
2323 namespace llvm {
1616
1717 #include "llvm/ADT/ilist.h"
1818 #include "llvm/ADT/ilist_node.h"
19 #include "llvm/System/DataTypes.h"
19 #include "llvm/Support/DataTypes.h"
2020 #include "llvm/Support/MathExtras.h"
2121 #include "llvm/Support/raw_ostream.h"
2222 #include
2525 #ifndef LLVM_ADT_STATISTIC_H
2626 #define LLVM_ADT_STATISTIC_H
2727
28 #include "llvm/System/Atomic.h"
28 #include "llvm/Support/Atomic.h"
2929
3030 namespace llvm {
3131 class raw_ostream;
1313 #ifndef LLVM_ADT_STRINGEXTRAS_H
1414 #define LLVM_ADT_STRINGEXTRAS_H
1515
16 #include "llvm/System/DataTypes.h"
16 #include "llvm/Support/DataTypes.h"
1717 #include "llvm/ADT/APFloat.h"
1818 #include "llvm/ADT/StringRef.h"
1919 #include
1010 #define LLVM_ADT_TWINE_H
1111
1212 #include "llvm/ADT/StringRef.h"
13 #include "llvm/System/DataTypes.h"
13 #include "llvm/Support/DataTypes.h"
1414 #include
1515 #include
1616
2828 #include "llvm/ADT/DenseMap.h"
2929 #include "llvm/Support/ValueHandle.h"
3030 #include "llvm/Support/type_traits.h"
31 #include "llvm/System/Mutex.h"
31 #include "llvm/Support/Mutex.h"
3232
3333 #include
3434
5656 #include "llvm/ADT/STLExtras.h"
5757 #include "llvm/Support/CallSite.h"
5858 #include "llvm/Support/ValueHandle.h"
59 #include "llvm/System/IncludeFile.h"
59 #include "llvm/Support/IncludeFile.h"
6060 #include
6161
6262 namespace llvm {
1414 #ifndef LLVM_ANALYSIS_DIBUILDER_H
1515 #define LLVM_ANALYSIS_DIBUILDER_H
1616
17 #include "llvm/System/DataTypes.h"
17 #include "llvm/Support/DataTypes.h"
1818 #include "llvm/ADT/StringRef.h"
1919
2020 namespace llvm {
2323 #include "llvm/Pass.h"
2424 #include "llvm/Instructions.h"
2525 #include "llvm/Function.h"
26 #include "llvm/System/DataTypes.h"
26 #include "llvm/Support/DataTypes.h"
2727 #include "llvm/Support/ValueHandle.h"
2828 #include "llvm/Support/Allocator.h"
2929 #include "llvm/Support/ConstantRange.h"
1414 #ifndef LLVM_ANALYSIS_VALUETRACKING_H
1515 #define LLVM_ANALYSIS_VALUETRACKING_H
1616
17 #include "llvm/System/DataTypes.h"
17 #include "llvm/Support/DataTypes.h"
1818 #include
1919
2020 namespace llvm {
1717 #include "llvm/SymbolTableListTraits.h"
1818 #include "llvm/ADT/ilist.h"
1919 #include "llvm/ADT/Twine.h"
20 #include "llvm/System/DataTypes.h"
20 #include "llvm/Support/DataTypes.h"
2121
2222 namespace llvm {
2323
5757 /// tables. The type of a BasicBlock is "Type::LabelTy" because the basic block
5858 /// represents a label to which a branch can jump.
5959 ///
60 /// A well formed basic block is formed of a list of non-terminating
61 /// instructions followed by a single TerminatorInst instruction.
62 /// TerminatorInst's may not occur in the middle of basic blocks, and must
60 /// A well formed basic block is formed of a list of non-terminating
61 /// instructions followed by a single TerminatorInst instruction.
62 /// TerminatorInst's may not occur in the middle of basic blocks, and must
6363 /// terminate the blocks. The BasicBlock class allows malformed basic blocks to
6464 /// occur because it may be useful in the intermediate stage of constructing or
6565 /// modifying a program. However, the verifier will ensure that basic blocks
8989 public:
9090 /// getContext - Get the context in which this basic block lives.
9191 LLVMContext &getContext() const;
92
92
9393 /// Instruction iterators...
9494 typedef InstListType::iterator iterator;
9595 typedef InstListType::const_iterator const_iterator;
9797 /// Create - Creates a new BasicBlock. If the Parent parameter is specified,
9898 /// the basic block is automatically inserted at either the end of the
9999 /// function (if InsertBefore is 0), or before the specified basic block.
100 static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "",
100 static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "",
101101 Function *Parent = 0,BasicBlock *InsertBefore = 0) {
102102 return new BasicBlock(Context, Name, Parent, InsertBefore);
103103 }
113113 /// and BlockAddress's).
114114 User *use_back() { return cast(*use_begin());}
115115 const User *use_back() const { return cast(*use_begin());}
116
116
117117 /// getTerminator() - If this is a well formed basic block, then this returns
118118 /// a pointer to the terminator instruction. If it is not, then you get a
119119 /// null pointer back.
120120 ///
121121 TerminatorInst *getTerminator();
122122 const TerminatorInst *getTerminator() const;
123
124 /// Returns a pointer to the first instructon in this block that is not a
123
124 /// Returns a pointer to the first instructon in this block that is not a
125125 /// PHINode instruction. When adding instruction to the beginning of the
126126 /// basic block, they should be added before the returned value, not before
127127 /// the first instruction, which might be PHI.
136136 const Instruction* getFirstNonPHIOrDbg() const {
137137 return const_cast(this)->getFirstNonPHIOrDbg();
138138 }
139
139
140140 /// removeFromParent - This method unlinks 'this' from the containing
141141 /// function, but does not delete it.
142142 ///
146146 /// and deletes it.
147147 ///
148148 void eraseFromParent();
149
149
150150 /// moveBefore - Unlink this basic block from its current function and
151151 /// insert it into the function that MovePos lives in, right before MovePos.
152152 void moveBefore(BasicBlock *MovePos);
153
153
154154 /// moveAfter - Unlink this basic block from its current function and
155155 /// insert it into the function that MovePos lives in, right after MovePos.
156156 void moveAfter(BasicBlock *MovePos);
157
157
158158
159159 /// getSinglePredecessor - If this basic block has a single predecessor block,
160160 /// return the block, otherwise return a null pointer.
165165
166166 /// getUniquePredecessor - If this basic block has a unique predecessor block,
167167 /// return the block, otherwise return a null pointer.
168 /// Note that unique predecessor doesn't mean single edge, there can be
169 /// multiple edges from the unique predecessor to this block (for example
168 /// Note that unique predecessor doesn't mean single edge, there can be
169 /// multiple edges from the unique predecessor to this block (for example
170170 /// a switch statement with multiple cases having the same destination).
171171 BasicBlock *getUniquePredecessor();
172172 const BasicBlock *getUniquePredecessor() const {
246246 /// hasAddressTaken - returns true if there are any uses of this basic block
247247 /// other than direct branches, switches, etc. to it.
248248 bool hasAddressTaken() const { return getSubclassDataFromValue() != 0; }
249
249
250250 private:
251251 /// AdjustBlockAddressRefCount - BasicBlock stores the number of BlockAddress
252252 /// objects using it. This is almost always 0, sometimes one, possibly but
1818
1919 #include "llvm/ADT/ilist.h"
2020 #include "llvm/ADT/ilist_node.h"
21 #include "llvm/System/Path.h"
21 #include "llvm/Support/Path.h"
2222 #include
2323 #include
2424
1818 #define LLVM_BITCODE_BITCODES_H
1919
2020 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/System/DataTypes.h"
21 #include "llvm/Support/DataTypes.h"
2222 #include
2323
2424 namespace llvm {
1616 #define LLVM_CODEGEN_ASMPRINTER_H
1717
1818 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/System/DataTypes.h"
19 #include "llvm/Support/DataTypes.h"
2020
2121 namespace llvm {
2222 class BlockAddress;
1515 #define LLVM_CODEGEN_BINARYOBJECT_H
1616
1717 #include "llvm/CodeGen/MachineRelocation.h"
18 #include "llvm/System/DataTypes.h"
18 #include "llvm/Support/DataTypes.h"
1919
2020 #include
2121 #include
1717 #define LLVM_CODEGEN_JITCODEEMITTER_H
1818
1919 #include
20 #include "llvm/System/DataTypes.h"
20 #include "llvm/Support/DataTypes.h"
2121 #include "llvm/Support/MathExtras.h"
2222 #include "llvm/CodeGen/MachineCodeEmitter.h"
2323 #include "llvm/ADT/DenseMap.h"
1414 #ifndef LLVM_CODEGEN_MACHO_RELOCATION_H
1515 #define LLVM_CODEGEN_MACHO_RELOCATION_H
1616
17 #include "llvm/System/DataTypes.h"
17 #include "llvm/Support/DataTypes.h"
1818
1919 namespace llvm {
2020
1616 #ifndef LLVM_CODEGEN_MACHINECODEEMITTER_H
1717 #define LLVM_CODEGEN_MACHINECODEEMITTER_H
1818
19 #include "llvm/System/DataTypes.h"
19 #include "llvm/Support/DataTypes.h"
2020 #include "llvm/Support/DebugLoc.h"
2121
2222 namespace llvm {
1616 #ifndef EE_MACHINE_CODE_INFO_H
1717 #define EE_MACHINE_CODE_INFO_H
1818
19 #include "llvm/System/DataTypes.h"
19 #include "llvm/Support/DataTypes.h"
2020
2121 namespace llvm {
2222
1515
1616 #include "llvm/ADT/SmallVector.h"
1717 //#include "llvm/ADT/IndexedMap.h"
18 #include "llvm/System/DataTypes.h"
18 #include "llvm/Support/DataTypes.h"
1919 #include
2020 #include
2121
1515 #ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H
1616 #define LLVM_CODEGEN_MACHINEMEMOPERAND_H
1717
18 #include "llvm/System/DataTypes.h"
18 #include "llvm/Support/DataTypes.h"
1919
2020 namespace llvm {
2121
3838 #include "llvm/Support/Dwarf.h"
3939 #include "llvm/Support/DebugLoc.h"
4040 #include "llvm/Support/ValueHandle.h"
41 #include "llvm/System/DataTypes.h"
41 #include "llvm/Support/DataTypes.h"
4242 #include "llvm/ADT/DenseMap.h"
4343 #include "llvm/ADT/PointerIntPair.h"
4444 #include "llvm/ADT/SmallPtrSet.h"
1313 #ifndef LLVM_CODEGEN_MACHINEOPERAND_H
1414 #define LLVM_CODEGEN_MACHINEOPERAND_H
1515
16 #include "llvm/System/DataTypes.h"
16 #include "llvm/Support/DataTypes.h"
1717 #include
1818
1919 namespace llvm {
1313 #ifndef LLVM_CODEGEN_MACHINERELOCATION_H
1414 #define LLVM_CODEGEN_MACHINERELOCATION_H
1515
16 #include "llvm/System/DataTypes.h"
16 #include "llvm/Support/DataTypes.h"
1717 #include
1818
1919 namespace llvm {
1616 #define LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H
1717
1818 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
19 #include "llvm/System/DataTypes.h"
19 #include "llvm/Support/DataTypes.h"
2020
2121 #include
2222 #include
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/System/IncludeFile.h"
14 #include "llvm/Support/IncludeFile.h"
1515 #include "llvm/CodeGen/LiveInterval.h"
1616 #include "llvm/ADT/SmallPtrSet.h"
1717
2828 #include "llvm/CodeGen/ValueTypes.h"
2929 #include "llvm/CodeGen/MachineMemOperand.h"
3030 #include "llvm/Support/MathExtras.h"
31 #include "llvm/System/DataTypes.h"
31 #include "llvm/Support/DataTypes.h"
3232 #include "llvm/Support/DebugLoc.h"
3333 #include
3434
1717
1818 #include
1919 #include
20 #include "llvm/System/DataTypes.h"
20 #include "llvm/Support/DataTypes.h"
2121 #include "llvm/Support/MathExtras.h"
2222
2323 namespace llvm {
2020 #include "llvm/ADT/SmallVector.h"
2121 #include "llvm/ADT/StringMap.h"
2222 #include "llvm/ADT/StringSet.h"
23 #include "llvm/System/Path.h"
23 #include "llvm/Support/Path.h"
2424
2525 #include
2626 #include
1717
1818 #include "llvm/ADT/IntrusiveRefCntPtr.h"
1919 #include "llvm/ADT/StringSet.h"
20 #include "llvm/System/Path.h"
20 #include "llvm/Support/Path.h"
2121
2222 #include
2323 #include
1818 #define LLVM_DERIVED_TYPES_H
1919
2020 #include "llvm/Type.h"
21 #include "llvm/System/DataTypes.h"
21 #include "llvm/Support/DataTypes.h"
2222
2323 namespace llvm {
2424
2121 #include "llvm/ADT/StringRef.h"
2222 #include "llvm/ADT/ValueMap.h"
2323 #include "llvm/Support/ValueHandle.h"
24 #include "llvm/System/Mutex.h"
24 #include "llvm/Support/Mutex.h"
2525 #include "llvm/Target/TargetMachine.h"
2626
2727 namespace llvm {
1515 #define GENERIC_VALUE_H
1616
1717 #include "llvm/ADT/APInt.h"
18 #include "llvm/System/DataTypes.h"
18 #include "llvm/Support/DataTypes.h"
1919
2020 namespace llvm {
2121
1414 #ifndef LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
1515 #define LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
1616
17 #include "llvm/System/DataTypes.h"
17 #include "llvm/Support/DataTypes.h"
1818 #include "llvm/Support/DebugLoc.h"
1919
2020 #include
99 #ifndef LLVM_EXECUTION_ENGINE_JIT_MEMMANAGER_H
1010 #define LLVM_EXECUTION_ENGINE_JIT_MEMMANAGER_H
1111
12 #include "llvm/System/DataTypes.h"
12 #include "llvm/Support/DataTypes.h"
1313 #include
1414
1515 namespace llvm {
2121 #include "llvm/IntrinsicInst.h"
2222 #include "llvm/InlineAsm.h"
2323 #include "llvm/Analysis/Verifier.h"
24 #include "llvm/System/Alarm.h"
25 #include "llvm/System/DynamicLibrary.h"
26 #include "llvm/System/Memory.h"
27 #include "llvm/System/Mutex.h"
28 #include "llvm/System/Path.h"
29 #include "llvm/System/Process.h"
30 #include "llvm/System/Program.h"
31 #include "llvm/System/Signals.h"
32 #include "llvm/System/TimeValue.h"
24 #include "llvm/Support/Alarm.h"
25 #include "llvm/Support/DynamicLibrary.h"
26 #include "llvm/Support/Memory.h"
27 #include "llvm/Support/Mutex.h"
28 #include "llvm/Support/Path.h"
29 #include "llvm/Support/Process.h"
30 #include "llvm/Support/Program.h"
31 #include "llvm/Support/Signals.h"
32 #include "llvm/Support/TimeValue.h"
3333 #include "llvm/Support/Dwarf.h"
3434 #include "llvm/Support/MathExtras.h"
3535 #include
88 #ifndef EDINSTINFO_H
99 #define EDINSTINFO_H
1010
11 #include "llvm/System/DataTypes.h"
11 #include "llvm/Support/DataTypes.h"
1212
1313 namespace llvm {
1414
1616 #include "llvm/Support/Casting.h"
1717 #include "llvm/MC/MCFixup.h"
1818 #include "llvm/MC/MCInst.h"
19 #include "llvm/System/DataTypes.h"
19 #include "llvm/Support/DataTypes.h"
2020 #include // FIXME: Shouldn't be needed.
2121
2222 namespace llvm {
88 #ifndef MCDISASSEMBLER_H
99 #define MCDISASSEMBLER_H
1010
11 #include "llvm/System/DataTypes.h"
11 #include "llvm/Support/DataTypes.h"
1212
1313 namespace llvm {
1414
1010 #define LLVM_MC_MCEXPR_H
1111
1212 #include "llvm/Support/Casting.h"
13 #include "llvm/System/DataTypes.h"
13 #include "llvm/Support/DataTypes.h"
1414
1515 namespace llvm {
1616 class MCAsmInfo;
99 #ifndef LLVM_MC_MCFIXUP_H
1010 #define LLVM_MC_MCFIXUP_H
1111
12 #include "llvm/System/DataTypes.h"
12 #include "llvm/Support/DataTypes.h"
1313 #include
1414
1515 namespace llvm {
1717
1818 #include "llvm/ADT/SmallVector.h"
1919 #include "llvm/ADT/StringRef.h"
20 #include "llvm/System/DataTypes.h"
20 #include "llvm/Support/DataTypes.h"
2121
2222 namespace llvm {
2323 class raw_ostream;
1111
1212 #include "llvm/ADT/Triple.h"
1313 #include "llvm/Support/raw_ostream.h"
14 #include "llvm/System/DataTypes.h"
14 #include "llvm/Support/DataTypes.h"
1515 #include
1616
1717 namespace llvm {
1616 #include "llvm/ADT/StringRef.h"
1717 #include "llvm/MC/MCParser/MCAsmLexer.h"
1818 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/System/DataTypes.h"
19 #include "llvm/Support/DataTypes.h"
2020 #include
2121 #include
2222
1010 #define LLVM_MC_MCASMLEXER_H
1111
1212 #include "llvm/ADT/StringRef.h"
13 #include "llvm/System/DataTypes.h"
13 #include "llvm/Support/DataTypes.h"
1414 #include "llvm/Support/SMLoc.h"
1515
1616 namespace llvm {
99 #ifndef LLVM_MC_MCASMPARSER_H
1010 #define LLVM_MC_MCASMPARSER_H
1111
12 #include "llvm/System/DataTypes.h"
12 #include "llvm/Support/DataTypes.h"
1313
1414 namespace llvm {
1515 class AsmToken;
1313 #ifndef LLVM_MC_MCSTREAMER_H
1414 #define LLVM_MC_MCSTREAMER_H
1515
16 #include "llvm/System/DataTypes.h"
16 #include "llvm/Support/DataTypes.h"
1717 #include "llvm/MC/MCDirectives.h"
1818
1919 namespace llvm {
1313 #ifndef LLVM_MC_MCVALUE_H
1414 #define LLVM_MC_MCVALUE_H
1515
16 #include "llvm/System/DataTypes.h"
16 #include "llvm/Support/DataTypes.h"
1717 #include "llvm/MC/MCSymbol.h"
1818 #include
1919
1919 #include "llvm/GlobalAlias.h"
2020 #include "llvm/Metadata.h"
2121 #include "llvm/ADT/OwningPtr.h"
22 #include "llvm/System/DataTypes.h"
22 #include "llvm/Support/DataTypes.h"
2323 #include
2424
2525 namespace llvm {
2121 #ifndef LLVM_OBJECT_MACHOFORMAT_H
2222 #define LLVM_OBJECT_MACHOFORMAT_H
2323
24 #include "llvm/System/DataTypes.h"
24 #include "llvm/Support/DataTypes.h"
2525
2626 namespace llvm {
2727 namespace object {
1414 #define LLVM_OBJECT_OBJECT_FILE_H
1515
1616 #include "llvm/ADT/StringRef.h"
17 #include "llvm/System/DataTypes.h"
17 #include "llvm/Support/DataTypes.h"
1818
1919 namespace llvm {
2020
2323 #include "Pass.h"
2424 #include "llvm/PassRegistry.h"
2525 #include "llvm/InitializePasses.h"
26 #include "llvm/System/Atomic.h"
26 #include "llvm/Support/Atomic.h"
2727 #include
2828
2929 namespace llvm {
0 //===-- llvm/System/AIXDataTypesFix.h - Fix datatype defs ------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file overrides default system-defined types and limits which cannot be
10 // done in DataTypes.h.in because it is processed by autoheader first, which
11 // comments out any #undef statement
12 //
13 //===----------------------------------------------------------------------===//
14
15 // No include guards desired!
16
17 #ifndef SUPPORT_DATATYPES_H
18 #error "AIXDataTypesFix.h must only be included via DataTypes.h!"
19 #endif
20
21 // GCC is strict about defining large constants: they must have LL modifier.
22 // These will be defined properly at the end of DataTypes.h
23 #undef INT64_MAX
24 #undef INT64_MIN
0 //===- llvm/System/Alarm.h - Alarm Generation support ----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides an operating system independent interface to alarm(2)
10 // type functionality. The Alarm class allows a one-shot alarm to be set up
11 // at some number of seconds in the future. When the alarm triggers, a method
12 // is called to process the event
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_SYSTEM_ALARM_H
17 #define LLVM_SYSTEM_ALARM_H
18
19 namespace llvm {
20 namespace sys {
21
22 /// This function registers an alarm to trigger some number of \p seconds in
23 /// the future. When that time arrives, the AlarmStatus function will begin
24 /// to return 1 instead of 0. The user must poll the status of the alarm by
25 /// making occasional calls to AlarmStatus. If the user sends an interrupt
26 /// signal, AlarmStatus will begin returning -1, even if the alarm event
27 /// occurred.
28 /// @returns nothing
29 void SetupAlarm(
30 unsigned seconds ///< Number of seconds in future when alarm arrives
31 );
32
33 /// This function terminates the alarm previously set up
34 /// @returns nothing
35 void TerminateAlarm();
36
37 /// This function acquires the status of the alarm.
38 /// @returns -1=cancelled, 0=untriggered, 1=triggered
39 int AlarmStatus();
40
41 /// Sleep for n seconds. Warning: mixing calls to Sleep() and other *Alarm
42 /// calls may be a bad idea on some platforms (source: Linux man page).
43 /// @returns nothing.
44 void Sleep(unsigned n);
45
46
47 } // End sys namespace
48 } // End llvm namespace
49
50 #endif
1515
1616 #include "llvm/Support/AlignOf.h"
1717 #include "llvm/Support/MathExtras.h"
18 #include "llvm/System/DataTypes.h"
18 #include "llvm/Support/DataTypes.h"
1919 #include
2020 #include
2121 #include
0 //===- llvm/System/Atomic.h - Atomic Operations -----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the llvm::sys atomic operations.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SYSTEM_ATOMIC_H
14 #define LLVM_SYSTEM_ATOMIC_H
15
16 #include "llvm/Support/DataTypes.h"
17
18 namespace llvm {
19 namespace sys {
20 void MemoryFence();
21
22 #ifdef _MSC_VER
23 typedef long cas_flag;
24 #else
25 typedef uint32_t cas_flag;
26 #endif
27 cas_flag CompareAndSwap(volatile cas_flag* ptr,
28 cas_flag new_value,
29 cas_flag old_value);
30 cas_flag AtomicIncrement(volatile cas_flag* ptr);
31 cas_flag AtomicDecrement(volatile cas_flag* ptr);
32 cas_flag AtomicAdd(volatile cas_flag* ptr, cas_flag val);
33 cas_flag AtomicMul(volatile cas_flag* ptr, cas_flag val);
34 cas_flag AtomicDiv(volatile cas_flag* ptr, cas_flag val);
35 }
36 }
37
38 #endif
2222 #ifndef LLVM_SUPPORT_WIN_COFF_H
2323 #define LLVM_SUPPORT_WIN_COFF_H
2424
25 #include "llvm/System/DataTypes.h"
25 #include "llvm/Support/DataTypes.h"
2626 #include
2727
2828 namespace llvm {
3232 #define LLVM_SUPPORT_CONSTANT_RANGE_H
3333
3434 #include "llvm/ADT/APInt.h"
35 #include "llvm/System/DataTypes.h"
35 #include "llvm/Support/DataTypes.h"
3636
3737 namespace llvm {
3838
0 /*===-- include/Support/DataTypes.h - Define fixed size types -----*- C -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file is distributed under the University of Illinois Open Source *|
5 |* 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 *|
12 |* definitions: *|
13 |* *|
14 |* [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
15 |* [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values. *|
16 |* *|
17 |* No library is required when using these functinons. *|
18 |* *|
19 |*===----------------------------------------------------------------------===*/
20
21 /* Please leave this file C-compatible. */
22
23 #ifndef SUPPORT_DATATYPES_H
24 #define SUPPORT_DATATYPES_H
25
26 #cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
27 #cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H}
28 #cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H}
29 #cmakedefine HAVE_UINT64_T ${HAVE_UINT64_T}
30 #cmakedefine HAVE_U_INT64_T ${HAVE_U_INT64_T}
31
32 #ifdef __cplusplus
33 #include
34 #else
35 #include
36 #endif
37
38 #ifndef _MSC_VER
39
40 /* Note that this header's correct operation depends on __STDC_LIMIT_MACROS
41 being defined. We would define it here, but in order to prevent Bad Things
42 happening when system headers or C++ STL headers include stdint.h before we
43 define it here, we define it on the g++ command line (in Makefile.rules). */
44 #if !defined(__STDC_LIMIT_MACROS)
45 # error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
46 #endif
47
48 #if !defined(__STDC_CONSTANT_MACROS)
49 # error "Must #define __STDC_CONSTANT_MACROS before " \
50 "#including Support/DataTypes.h"
51 #endif
52
53 /* Note that includes , if this is a C99 system. */
54 #ifdef HAVE_SYS_TYPES_H
55 #include
56 #endif
57
58 #ifdef HAVE_INTTYPES_H
59 #include
60 #endif
61
62 #ifdef HAVE_STDINT_H
63 #include
64 #endif
65
66 #ifdef _AIX
67 #include "llvm/Support/AIXDataTypesFix.h"
68 #endif
69
70 /* Handle incorrect definition of uint64_t as u_int64_t */
71 #ifndef HAVE_UINT64_T
72 #ifdef HAVE_U_INT64_T
73 typedef u_int64_t uint64_t;
74 #else
75 # error "Don't have a definition for uint64_t on this platform"
76 #endif
77 #endif
78
79 #ifdef _OpenBSD_
80 #define INT8_MAX 127
81 #define INT8_MIN -128
82 #define UINT8_MAX 255
83 #define INT16_MAX 32767
84 #define INT16_MIN -32768
85 #define UINT16_MAX 65535
86 #define INT32_MAX 2147483647
87 #define INT32_MIN -2147483648
88 #define UINT32_MAX 4294967295U
89 #endif
90
91 #else /* _MSC_VER */
92 /* Visual C++ doesn't provide standard integer headers, but it does provide
93 built-in data types. */
94 #include
95 #include
96 #include
97 #ifdef __cplusplus
98 #include
99 #else
100 #include
101 #endif
102 typedef __int64 int64_t;
103 typedef unsigned __int64 uint64_t;
104 typedef signed int int32_t;
105 typedef unsigned int uint32_t;
106 typedef short int16_t;
107 typedef unsigned short uint16_t;
108 typedef signed char int8_t;
109 typedef unsigned char uint8_t;
110 typedef signed int ssize_t;
111 #ifndef INT8_MAX
112 # define INT8_MAX 127
113 #endif
114 #ifndef INT8_MIN
115 # define INT8_MIN -128
116 #endif
117 #ifndef UINT8_MAX
118 # define UINT8_MAX 255
119 #endif
120 #ifndef INT16_MAX
121 # define INT16_MAX 32767
122 #endif
123 #ifndef INT16_MIN
124 # define INT16_MIN -32768
125 #endif
126 #ifndef UINT16_MAX
127 # define UINT16_MAX 65535
128 #endif
129 #ifndef INT32_MAX
130 # define INT32_MAX 2147483647
131 #endif
132 #ifndef INT32_MIN
133 # define INT32_MIN -2147483648
134 #endif
135 #ifndef UINT32_MAX
136 # define UINT32_MAX 4294967295U
137 #endif
138 /* Certain compatibility updates to VC++ introduce the `cstdint'
139 * header, which defines the INT*_C macros. On default installs they
140 * are absent. */
141 #ifndef INT8_C
142 # define INT8_C(C) C##i8
143 #endif
144 #ifndef UINT8_C
145 # define UINT8_C(C) C##ui8
146 #endif
147 #ifndef INT16_C
148 # define INT16_C(C) C##i16
149 #endif
150 #ifndef UINT16_C
151 # define UINT16_C(C) C##ui16
152 #endif
153 #ifndef INT32_C
154 # define INT32_C(C) C##i32
155 #endif
156 #ifndef UINT32_C
157 # define UINT32_C(C) C##ui32
158 #endif
159 #ifndef INT64_C
160 # define INT64_C(C) C##i64
161 #endif
162 #ifndef UINT64_C
163 # define UINT64_C(C) C##ui64
164 #endif
165 #endif /* _MSC_VER */
166
167 /* Set defaults for constants which we cannot find. */
168 #if !defined(INT64_MAX)
169 # define INT64_MAX 9223372036854775807LL
170 #endif
171 #if !defined(INT64_MIN)
172 # define INT64_MIN ((-INT64_MAX)-1)
173 #endif
174 #if !defined(UINT64_MAX)
175 # define UINT64_MAX 0xffffffffffffffffULL
176 #endif
177
178 #if __GNUC__ > 3
179 #define END_WITH_NULL __attribute__((sentinel))
180 #else
181 #define END_WITH_NULL
182 #endif
183
184 #ifndef HUGE_VALF
185 #define HUGE_VALF (float)HUGE_VAL
186 #endif
187
188 #endif /* SUPPORT_DATATYPES_H */
0 /*===-- include/System/DataTypes.h - Define fixed size types -----*- C -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file is distributed under the University of Illinois Open Source *|
5 |* 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 *|
12 |* definitions: *|
13 |* *|
14 |* [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
15 |* [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values. *|
16 |* *|
17 |* No library is required when using these functions. *|
18 |* *|
19 |*===----------------------------------------------------------------------===*/
20
21 /* Please leave this file C-compatible. */
22
23 #ifndef SUPPORT_DATATYPES_H
24 #define SUPPORT_DATATYPES_H
25
26 #undef HAVE_SYS_TYPES_H
27 #undef HAVE_INTTYPES_H
28 #undef HAVE_STDINT_H
29 #undef HAVE_UINT64_T
30 #undef HAVE_U_INT64_T
31
32 #ifdef __cplusplus
33 #include
34 #else
35 #include
36 #endif
37
38 /* Note that this header's correct operation depends on __STDC_LIMIT_MACROS
39 being defined. We would define it here, but in order to prevent Bad Things
40 happening when system headers or C++ STL headers include stdint.h before we
41 define it here, we define it on the g++ command line (in Makefile.rules). */
42 #if !defined(__STDC_LIMIT_MACROS)
43 # error "Must #define __STDC_LIMIT_MACROS before #including System/DataTypes.h"
44 #endif
45
46 #if !defined(__STDC_CONSTANT_MACROS)
47 # error "Must #define __STDC_CONSTANT_MACROS before " \
48 "#including System/DataTypes.h"
49 #endif
50
51 /* Note that includes , if this is a C99 system. */
52 #ifdef HAVE_SYS_TYPES_H
53 #include
54 #endif
55
56 #ifdef HAVE_INTTYPES_H
57 #include
58 #endif
59
60 #ifdef HAVE_STDINT_H
61 #include
62 #endif
63
64 #ifdef _AIX
65 #include "llvm/System/AIXDataTypesFix.h"
66 #endif
67
68 /* Handle incorrect definition of uint64_t as u_int64_t */
69 #ifndef HAVE_UINT64_T
70 #ifdef HAVE_U_INT64_T
71 typedef u_int64_t uint64_t;
72 #else
73 # error "Don't have a definition for uint64_t on this platform"
74 #endif
75 #endif
76
77 #ifdef _OpenBSD_
78 #define INT8_MAX 127
79 #define INT8_MIN -128
80 #define UINT8_MAX 255
81 #define INT16_MAX 32767
82 #define INT16_MIN -32768
83 #define UINT16_MAX 65535
84 #define INT32_MAX 2147483647
85 #define INT32_MIN -2147483648
86 #define UINT32_MAX 4294967295U
87 #endif
88
89 /* Set defaults for constants which we cannot find. */
90 #if !defined(INT64_MAX)
91 # define INT64_MAX 9223372036854775807LL
92 #endif
93 #if !defined(INT64_MIN)
94 # define INT64_MIN ((-INT64_MAX)-1)
95 #endif
96 #if !defined(UINT64_MAX)
97 # define UINT64_MAX 0xffffffffffffffffULL
98 #endif
99
100 #if __GNUC__ > 3
101 #define END_WITH_NULL __attribute__((sentinel))
102 #else
103 #define END_WITH_NULL
104 #endif
105
106 #ifndef HUGE_VALF
107 #define HUGE_VALF (float)HUGE_VAL
108 #endif
109
110 #endif /* SUPPORT_DATATYPES_H */
0 //===- llvm/Support/Disassembler.h ------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the necessary glue to call external disassembler
10 // libraries.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_DISASSEMBLER_H
15 #define LLVM_SYSTEM_DISASSEMBLER_H
16
17 #include "llvm/Support/DataTypes.h"
18 #include
19
20 namespace llvm {
21 namespace sys {
22
23 /// This function returns true, if there is possible to use some external
24 /// disassembler library. False otherwise.
25 bool hasDisassembler();
26
27 /// This function provides some "glue" code to call external disassembler
28 /// libraries.
29 std::string disassembleBuffer(uint8_t* start, size_t length, uint64_t pc = 0);
30
31 }
32 }
33
34 #endif // LLVM_SYSTEM_DISASSEMBLER_H
0 //===-- llvm/System/DynamicLibrary.h - Portable Dynamic Library -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the sys::DynamicLibrary class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SYSTEM_DYNAMIC_LIBRARY_H
14 #define LLVM_SYSTEM_DYNAMIC_LIBRARY_H
15
16 #include
17
18 namespace llvm {
19 namespace sys {
20
21 /// This class provides a portable interface to dynamic libraries which also
22 /// might be known as shared libraries, shared objects, dynamic shared
23 /// objects, or dynamic link libraries. Regardless of the terminology or the
24 /// operating system interface, this class provides a portable interface that
25 /// allows dynamic libraries to be loaded and searched for externally
26 /// defined symbols. This is typically used to provide "plug-in" support.
27 /// It also allows for symbols to be defined which don't live in any library,
28 /// but rather the main program itself, useful on Windows where the main
29 /// executable cannot be searched.
30 class DynamicLibrary {
31 DynamicLibrary(); // DO NOT IMPLEMENT
32 public:
33 /// This function allows a library to be loaded without instantiating a
34 /// DynamicLibrary object. Consequently, it is marked as being permanent
35 /// and will only be unloaded when the program terminates. This returns
36 /// false on success or returns true and fills in *ErrMsg on failure.
37 /// @brief Open a dynamic library permanently.
38 ///
39 /// NOTE: This function is not thread safe.
40 ///
41 static bool LoadLibraryPermanently(const char *filename,
42 std::string *ErrMsg = 0);
43
44 /// This function will search through all previously loaded dynamic
45 /// libraries for the symbol \p symbolName. If it is found, the addressof
46 /// that symbol is returned. If not, null is returned. Note that this will
47 /// search permanently loaded libraries (LoadLibraryPermanently) as well
48 /// as ephemerally loaded libraries (constructors).
49 /// @throws std::string on error.
50 /// @brief Search through libraries for address of a symbol
51 ///
52 /// NOTE: This function is not thread safe.
53 ///
54 static void *SearchForAddressOfSymbol(const char *symbolName);
55
56 /// @brief Convenience function for C++ophiles.
57 ///
58 /// NOTE: This function is not thread safe.
59 ///
60 static void *SearchForAddressOfSymbol(const std::string &symbolName) {
61 return SearchForAddressOfSymbol(symbolName.c_str());
62 }
63
64 /// This functions permanently adds the symbol \p symbolName with the
65 /// value \p symbolValue. These symbols are searched before any
66 /// libraries.
67 /// @brief Add searchable symbol/value pair.
68 ///
69 /// NOTE: This function is not thread safe.
70 ///
71 static void AddSymbol(const char *symbolName, void *symbolValue);
72
73 /// @brief Convenience function for C++ophiles.
74 ///
75 /// NOTE: This function is not thread safe.
76 ///
77 static void AddSymbol(const std::string &symbolName, void *symbolValue) {
78 AddSymbol(symbolName.c_str(), symbolValue);
79 }
80 };
81
82 } // End sys namespace
83 } // End llvm namespace
84
85 #endif // LLVM_SYSTEM_DYNAMIC_LIBRARY_H
1919 #ifndef LLVM_SUPPORT_ELF_H
2020 #define LLVM_SUPPORT_ELF_H
2121
22 #include "llvm/System/DataTypes.h"
22 #include "llvm/Support/DataTypes.h"
2323 #include
2424
2525 namespace llvm {
1414 #define LLVM_SUPPORT_ENDIAN_H
1515
1616 #include "llvm/Config/config.h"
17 #include "llvm/System/Host.h"
18 #include "llvm/System/SwapByteOrder.h"
17 #include "llvm/Support/Host.h"
18 #include "llvm/Support/SwapByteOrder.h"
1919 #include "llvm/Support/type_traits.h"
2020
2121 namespace llvm {
0 //===- llvm/System/Errno.h - Portable+convenient errno handling -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares some portable and convenient functions to deal with errno.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SYSTEM_ERRNO_H
14 #define LLVM_SYSTEM_ERRNO_H
15
16 #include
17
18 namespace llvm {
19 namespace sys {
20
21 /// Returns a string representation of the errno value, using whatever
22 /// thread-safe variant of strerror() is available. Be sure to call this
23 /// immediately after the function that set errno, or errno may have been
24 /// overwritten by an intervening call.
25 std::string StrError();
26
27 /// Like the no-argument version above, but uses \p errnum instead of errno.
28 std::string StrError(int errnum);
29
30 } // namespace sys
31 } // namespace llvm
32
33 #endif // LLVM_SYSTEM_ERRNO_H
0 //===- llvm/System/FEnv.h - Host floating-point exceptions ------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides an operating system independent interface to
10 // floating-point exception interfaces.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_FENV_H
15 #define LLVM_SYSTEM_FENV_H
16
17 #include "llvm/Config/config.h"
18 #include
19 #ifdef HAVE_FENV_H
20 #include
21 #endif
22
23 // FIXME: Clang's #include handling apparently doesn't work for libstdc++'s
24 // fenv.h; see PR6907 for details.
25 #if defined(__clang__) && defined(_GLIBCXX_FENV_H)
26 #undef HAVE_FENV_H
27 #endif
28
29 namespace llvm {
30 namespace sys {
31
32 /// llvm_fenv_clearexcept - Clear the floating-point exception state.
33 static inline void llvm_fenv_clearexcept() {
34 #ifdef HAVE_FENV_H
35 feclearexcept(FE_ALL_EXCEPT);
36 #endif
37 errno = 0;
38 }
39
40 /// llvm_fenv_testexcept - Test if a floating-point exception was raised.
41 static inline bool llvm_fenv_testexcept() {
42 int errno_val = errno;
43 if (errno_val == ERANGE || errno_val == EDOM)
44 return true;
45 #ifdef HAVE_FENV_H
46 if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
47 return true;
48 #endif
49 return false;
50 }
51
52 } // End sys namespace
53 } // End llvm namespace
54
55 #endif
1414 #ifndef LLVM_SUPPORT_FILEUTILITIES_H
1515 #define LLVM_SUPPORT_FILEUTILITIES_H
1616
17 #include "llvm/System/Path.h"
17 #include "llvm/Support/Path.h"
1818
1919 namespace llvm {
2020
2525 #include "llvm/Support/DOTGraphTraits.h"
2626 #include "llvm/Support/raw_ostream.h"
2727 #include "llvm/ADT/GraphTraits.h"
28 #include "llvm/System/Path.h"
28 #include "llvm/Support/Path.h"
2929 #include
3030 #include
3131
0 //===- llvm/System/Host.h - Host machine characteristics --------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Methods for querying the nature of the host machine.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SYSTEM_HOST_H
14 #define LLVM_SYSTEM_HOST_H
15
16 #include "llvm/ADT/StringMap.h"
17 #include
18
19 namespace llvm {
20 namespace sys {
21
22 inline bool isLittleEndianHost() {
23 union {
24 int i;
25 char c;
26 };
27 i = 1;
28 return c;
29 }
30
31 inline bool isBigEndianHost() {
32 return !isLittleEndianHost();
33 }
34
35 /// getHostTriple() - Return the target triple of the running
36 /// system.
37 ///
38 /// The target triple is a string in the format of:
39 /// CPU_TYPE-VENDOR-OPERATING_SYSTEM
40 /// or
41 /// CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
42 std::string getHostTriple();
43
44 /// getHostCPUName - Get the LLVM name for the host CPU. The particular format
45 /// of the name is target dependent, and suitable for passing as -mcpu to the
46 /// target which matches the host.
47 ///
48 /// \return - The host CPU name, or empty if the CPU could not be determined.
49 std::string getHostCPUName();
50
51 /// getHostCPUFeatures - Get the LLVM names for the host CPU features.
52 /// The particular format of the names are target dependent, and suitable for
53 /// passing as -mattr to the target which matches the host.
54 ///
55 /// \param Features - A string mapping feature names to either
56 /// true (if enabled) or false (if disabled). This routine makes no guarantees
57 /// about exactly which features may appear in this map, except that they are
58 /// all valid LLVM feature names.
59 ///
60 /// \return - True on success.
61 bool getHostCPUFeatures(StringMap &Features);
62 }
63 }
64
65 #endif
0 //===- llvm/System/IncludeFile.h - Ensure Linking Of Library ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the FORCE_DEFINING_FILE_TO_BE_LINKED and DEFINE_FILE_FOR
10 // macros.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_INCLUDEFILE_H
15 #define LLVM_SYSTEM_INCLUDEFILE_H
16
17 /// This macro is the public interface that IncludeFile.h exports. This gives
18 /// us the option to implement the "link the definition" capability in any
19 /// manner that we choose. All header files that depend on a specific .cpp
20 /// file being linked at run time should use this macro instead of the
21 /// IncludeFile class directly.
22 ///
23 /// For example, foo.h would use:
24 /// FORCE_DEFINING_FILE_TO_BE_LINKED(foo)
25 ///
26 /// And, foo.cp would use:
27 /// DEFINING_FILE_FOR(foo)
28 #ifdef __GNUC__
29 // If the `used' attribute is available, use it to create a variable
30 // with an initializer that will force the linking of the defining file.
31 #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
32 namespace llvm { \
33 extern const char name ## LinkVar; \
34 __attribute__((used)) static const char *const name ## LinkObj = \
35 &name ## LinkVar; \
36 }
37 #else
38 // Otherwise use a constructor call.
39 #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
40 namespace llvm { \
41 extern const char name ## LinkVar; \
42 static const IncludeFile name ## LinkObj ( &name ## LinkVar ); \
43 }
44 #endif
45
46 /// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
47 /// be used in a .cpp file to define the name referenced in a header file that
48 /// will cause linkage of the .cpp file. It should only be used at extern level.
49 #define DEFINING_FILE_FOR(name) \
50 namespace llvm { const char name ## LinkVar = 0; }
51
52 namespace llvm {
53
54 /// This class is used in the implementation of FORCE_DEFINING_FILE_TO_BE_LINKED
55 /// macro to make sure that the implementation of a header file is included
56 /// into a tool that uses the header. This is solely
57 /// to overcome problems linking .a files and not getting the implementation
58 /// of compilation units we need. This is commonly an issue with the various
59 /// Passes but also occurs elsewhere in LLVM. We like to use .a files because
60 /// they link faster and provide the smallest executables. However, sometimes
61 /// those executables are too small, if the program doesn't reference something
62 /// that might be needed, especially by a loaded share object. This little class
63 /// helps to resolve that problem. The basic strategy is to use this class in
64 /// a header file and pass the address of a variable to the constructor. If the
65 /// variable is defined in the header file's corresponding .cpp file then all
66 /// tools/libraries that \#include the header file will require the .cpp as
67 /// well.
68 /// For example:
69 /// extern int LinkMyCodeStub;
70 /// static IncludeFile LinkMyModule(&LinkMyCodeStub);
71 /// @brief Class to ensure linking of corresponding object file.
72 struct IncludeFile {
73 explicit IncludeFile(const void *);
74 };
75
76 }
77
78 #endif
0 LLVM System Interface Library
1 -------------------------------------------------------------------------------
2 The LLVM System Interface Library is licensed under the Illinois Open Source
3 License and has the following additional copyright:
4
5 Copyright (C) 2004 eXtensible Systems, Inc.
1313 #ifndef LLVM_SUPPORT_MACHO_H
1414 #define LLVM_SUPPORT_MACHO_H
1515
16 #include "llvm/System/DataTypes.h"
16 #include "llvm/Support/DataTypes.h"
1717
1818 // NOTE: The enums in this file are intentially named to be different than those
1919 // in the headers in /usr/include/mach (on darwin systems) to avoid conflicts
1313 #ifndef LLVM_SUPPORT_MANAGED_STATIC_H
1414 #define LLVM_SUPPORT_MANAGED_STATIC_H
1515
16 #include "llvm/System/Atomic.h"
17 #include "llvm/System/Threading.h"
16 #include "llvm/Support/Atomic.h"
17 #include "llvm/Support/Threading.h"
1818
1919 namespace llvm {
2020
1313 #ifndef LLVM_SUPPORT_MATHEXTRAS_H
1414 #define LLVM_SUPPORT_MATHEXTRAS_H
1515
16 #include "llvm/System/SwapByteOrder.h"
16 #include "llvm/Support/SwapByteOrder.h"
1717
1818 namespace llvm {
1919
0 //===- llvm/System/Memory.h - Memory Support --------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the llvm::sys::Memory class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SYSTEM_MEMORY_H
14 #define LLVM_SYSTEM_MEMORY_H
15
16 #include "llvm/Support/DataTypes.h"
17 #include
18
19 namespace llvm {
20 namespace sys {
21
22 /// This class encapsulates the notion of a memory block which has an address
23 /// and a size. It is used by the Memory class (a friend) as the result of
24 /// various memory allocation operations.
25 /// @see Memory
26 /// @brief Memory block abstraction.
27 class MemoryBlock {
28 public:
29 MemoryBlock() : Address(0), Size(0) { }
30 MemoryBlock(void *addr, size_t size) : Address(addr), Size(size) { }
31 void *base() const { return Address; }
32 size_t size() const { return Size; }
33 private:
34 void *Address; ///< Address of first byte of memory area
35 size_t Size; ///< Size, in bytes of the memory area
36 friend class Memory;
37 };
38
39 /// This class provides various memory handling functions that manipulate
40 /// MemoryBlock instances.
41 /// @since 1.4
42 /// @brief An abstraction for memory operations.
43 class Memory {
44 public:
45 /// This method allocates a block of Read/Write/Execute memory that is
46 /// suitable for executing dynamically generated code (e.g. JIT). An
47 /// attempt to allocate \p NumBytes bytes of virtual memory is made.
48 /// \p NearBlock may point to an existing allocation in which case
49 /// an attempt is made to allocate more memory near the existing block.
50 ///
51 /// On success, this returns a non-null memory block, otherwise it returns
52 /// a null memory block and fills in *ErrMsg.
53 ///
54 /// @brief Allocate Read/Write/Execute memory.
55 static MemoryBlock AllocateRWX(size_t NumBytes,
56 const MemoryBlock *NearBlock,
57 std::string *ErrMsg = 0);
58
59 /// This method releases a block of Read/Write/Execute memory that was
60 /// allocated with the AllocateRWX method. It should not be used to
61 /// release any memory block allocated any other way.
62 ///
63 /// On success, this returns false, otherwise it returns true and fills
64 /// in *ErrMsg.
65 /// @brief Release Read/Write/Execute memory.
66 static bool ReleaseRWX(MemoryBlock &block, std::string *ErrMsg = 0);
67
68
69 /// InvalidateInstructionCache - Before the JIT can run a block of code
70 /// that has been emitted it must invalidate the instruction cache on some
71 /// platforms.
72 static void InvalidateInstructionCache(const void *Addr, size_t Len);
73
74 /// setExecutable - Before the JIT can run a block of code, it has to be
75 /// given read and executable privilege. Return true if it is already r-x
76 /// or the system is able to change its previlege.
77 static bool setExecutable (MemoryBlock &M, std::string *ErrMsg = 0);
78
79 /// setWritable - When adding to a block of code, the JIT may need
80 /// to mark a block of code as RW since the protections are on page
81 /// boundaries, and the JIT internal allocations are not page aligned.
82 static bool setWritable (MemoryBlock &M, std::string *ErrMsg = 0);
83
84 /// setRangeExecutable - Mark the page containing a range of addresses
85 /// as executable.
86 static bool setRangeExecutable(const void *Addr, size_t Size);
87
88 /// setRangeWritable - Mark the page containing a range of addresses
89 /// as writable.
90 static bool setRangeWritable(const void *Addr, size_t Size);
91 };
92 }
93 }
94
95 #endif
1414 #define LLVM_SUPPORT_MEMORYBUFFER_H
1515
1616 #include "llvm/ADT/StringRef.h"
17 #include "llvm/System/DataTypes.h"
17 #include "llvm/Support/DataTypes.h"
1818 #include
1919
2020 namespace llvm {
99 #ifndef MEMORYOBJECT_H
1010 #define MEMORYOBJECT_H
1111
12 #include "llvm/System/DataTypes.h"
12 #include "llvm/Support/DataTypes.h"
1313
1414 namespace llvm {
1515
0 //===- llvm/System/Mutex.h - Mutex Operating System Concept -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the llvm::sys::Mutex class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SYSTEM_MUTEX_H
14 #define LLVM_SYSTEM_MUTEX_H
15
16 #include "llvm/Support/Threading.h"
17 #include
18
19 namespace llvm
20 {
21 namespace sys
22 {
23 /// @brief Platform agnostic Mutex class.
24 class MutexImpl
25 {
26 /// @name Constructors
27 /// @{
28 public:
29
30 /// Initializes the lock but doesn't acquire it. if \p recursive is set
31 /// to false, the lock will not be recursive which makes it cheaper but
32 /// also more likely to deadlock (same thread can't acquire more than
33 /// once).
34 /// @brief Default Constructor.
35 explicit MutexImpl(bool recursive = true);
36
37 /// Releases and removes the lock
38 /// @brief Destructor
39 ~MutexImpl();
40
41 /// @}
42 /// @name Methods
43 /// @{
44 public:
45
46 /// Attempts to unconditionally acquire the lock. If the lock is held by
47 /// another thread, this method will wait until it can acquire the lock.
48 /// @returns false if any kind of error occurs, true otherwise.
49 /// @brief Unconditionally acquire the lock.
50 bool acquire();
51
52 /// Attempts to release the lock. If the lock is held by the current
53 /// thread, the lock is released allowing other threads to acquire the
54 /// lock.
55 /// @returns false if any kind of error occurs, true otherwise.
56 /// @brief Unconditionally release the lock.
57 bool release();
58
59 /// Attempts to acquire the lock without blocking. If the lock is not
60 /// available, this function returns false quickly (without blocking). If
61 /// the lock is available, it is acquired.
62 /// @returns false if any kind of error occurs or the lock is not
63 /// available, true otherwise.
64 /// @brief Try to acquire the lock.
65 bool tryacquire();
66
67 //@}
68 /// @name Platform Dependent Data
69 /// @{
70 private:
71 void* data_; ///< We don't know what the data will be
72
73 /// @}
74 /// @name Do Not Implement
75 /// @{
76 private:
77 MutexImpl(const MutexImpl & original);
78 void operator=(const MutexImpl &);
79 /// @}
80 };
81
82
83 /// SmartMutex - A mutex with a compile time constant parameter that
84 /// indicates whether this mutex should become a no-op when we're not
85 /// running in multithreaded mode.
86 template
87 class SmartMutex : public MutexImpl {
88 unsigned acquired;
89 bool recursive;
90 public:
91 explicit SmartMutex(bool rec = true) :
92 MutexImpl(rec), acquired(0), recursive(rec) { }
93
94 bool acquire() {
95 if (!mt_only || llvm_is_multithreaded()) {
96 return MutexImpl::acquire();
97 } else {
98 // Single-threaded debugging code. This would be racy in
99 // multithreaded mode, but provides not sanity checks in single
100 // threaded mode.
101 assert((recursive || acquired == 0) && "Lock already acquired!!");
102 ++acquired;
103 return true;
104 }
105 }
106
107 bool release() {
108 if (!mt_only || llvm_is_multithreaded()) {
109 return MutexImpl::release();
110 } else {
111 // Single-threaded debugging code. This would be racy in
112 // multithreaded mode, but provides not sanity checks in single
113 // threaded mode.
114 assert(((recursive && acquired) || (acquired == 1)) &&
115 "Lock not acquired before release!");
116 --acquired;
117 return true;
118 }
119 }
120
121 bool tryacquire() {
122 if (!mt_only || llvm_is_multithreaded())
123 return MutexImpl::tryacquire();
124 else return true;
125 }
126
127 private:
128 SmartMutex(const SmartMutex & original);
129 void operator=(const SmartMutex &);
130 };
131
132 /// Mutex - A standard, always enforced mutex.
133 typedef SmartMutex Mutex;
134
135 template
136 class SmartScopedLock {
137 SmartMutex& mtx;
138
139 public:
140 SmartScopedLock(SmartMutex& m) : mtx(m) {
141 mtx.acquire();
142 }
143
144 ~SmartScopedLock() {
145 mtx.release();
146 }
147 };
148
149 typedef SmartScopedLock ScopedLock;
150 }
151 }
152
153 #endif
1414 #ifndef LLVM_SUPPORT_MUTEXGUARD_H
1515 #define LLVM_SUPPORT_MUTEXGUARD_H
1616
17 #include "llvm/System/Mutex.h"
17 #include "llvm/Support/Mutex.h"
1818
1919 namespace llvm {
2020 /// Instances of this class acquire a given Mutex Lock when constructed and
0 //===- llvm/System/Path.h - Path Operating System Concept -------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the llvm::sys::Path class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SYSTEM_PATH_H
14 #define LLVM_SYSTEM_PATH_H
15
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/TimeValue.h"
18 #include
19 #include
20 #include
21
22 namespace llvm {
23 namespace sys {
24
25 /// This structure provides basic file system information about a file. It
26 /// is patterned after the stat(2) Unix operating system call but made
27 /// platform independent and eliminates many of the unix-specific fields.
28 /// However, to support llvm-ar, the mode, user, and group fields are
29 /// retained. These pertain to unix security and may not have a meaningful
30 /// value on non-Unix platforms. However, the other fields should
31 /// always be applicable on all platforms. The structure is filled in by
32 /// the PathWithStatus class.
33 /// @brief File status structure
34 class FileStatus {
35 public:
36 uint64_t fileSize; ///< Size of the file in bytes
37 TimeValue modTime; ///< Time of file's modification
38 uint32_t mode; ///< Mode of the file, if applicable
39 uint32_t user; ///< User ID of owner, if applicable
40 uint32_t group; ///< Group ID of owner, if applicable
41 uint64_t uniqueID; ///< A number to uniquely ID this file
42 bool isDir : 1; ///< True if this is a directory.
43 bool isFile : 1; ///< True if this is a file.
44
45 FileStatus() : fileSize(0), modTime(0,0), mode(0777), user(999),
46 group(999), uniqueID(0), isDir(false), isFile(false) { }
47
48 TimeValue getTimestamp() const { return modTime; }
49 uint64_t getSize() const { return fileSize; }
50 uint32_t getMode() const { return mode; }
51 uint32_t getUser() const { return user; }
52 uint32_t getGroup() const { return group; }
53 uint64_t getUniqueID() const { return uniqueID; }
54 };
55
56 /// This class provides an abstraction for the path to a file or directory
57 /// in the operating system's filesystem and provides various basic operations
58 /// on it. Note that this class only represents the name of a path to a file
59 /// or directory which may or may not be valid for a given machine's file
60 /// system. The class is patterned after the java.io.File class with various
61 /// extensions and several omissions (not relevant to LLVM). A Path object
62 /// ensures that the path it encapsulates is syntactically valid for the
63 /// operating system it is running on but does not ensure correctness for
64 /// any particular file system. That is, a syntactically valid path might
65 /// specify path components that do not exist in the file system and using
66 /// such a Path to act on the file system could produce errors. There is one
67 /// invalid Path value which is permitted: the empty path. The class should
68 /// never allow a syntactically invalid non-empty path name to be assigned.
69 /// Empty paths are required in order to indicate an error result in some
70 /// situations. If the path is empty, the isValid operation will return
71 /// false. All operations will fail if isValid is false. Operations that
72 /// change the path will either return false if it would cause a syntactically
73 /// invalid path name (in which case the Path object is left unchanged) or
74 /// throw an std::string exception indicating the error. The methods are
75 /// grouped into four basic categories: Path Accessors (provide information
76 /// about the path without accessing disk), Disk Accessors (provide
77 /// information about the underlying file or directory), Path Mutators
78 /// (change the path information, not the disk), and Disk Mutators (change
79 /// the disk file/directory referenced by the path). The Disk Mutator methods
80 /// all have the word "disk" embedded in their method name to reinforce the
81 /// notion that the operation modifies the file system.
82 /// @since 1.4
83 /// @brief An abstraction for operating system paths.
84 class Path {
85 /// @name Constructors
86 /// @{
87 public:
88 /// Construct a path to the root directory of the file system. The root
89 /// directory is a top level directory above which there are no more
90 /// directories. For example, on UNIX, the root directory is /. On Windows
91 /// it is file:///. Other operating systems may have different notions of
92 /// what the root directory is or none at all. In that case, a consistent
93 /// default root directory will be used.
94 static Path GetRootDirectory();
95
96 /// Construct a path to a unique temporary directory that is created in
97 /// a "standard" place for the operating system. The directory is
98 /// guaranteed to be created on exit from this function. If the directory
99 /// cannot be created, the function will throw an exception.
100 /// @returns an invalid path (empty) on error
101 /// @param ErrMsg Optional place for an error message if an error occurs
102 /// @brief Constrct a path to an new, unique, existing temporary
103 /// directory.
104 static Path GetTemporaryDirectory(std::string* ErrMsg = 0);
105
106 /// Construct a vector of sys::Path that contains the "standard" system
107 /// library paths suitable for linking into programs.
108 /// @brief Construct a path to the system library directory
109 static void GetSystemLibraryPaths(std::vector& Paths);
110
111 /// Construct a vector of sys::Path that contains the "standard" bitcode
112 /// library paths suitable for linking into an llvm program. This function
113 /// *must* return the value of LLVM_LIB_SEARCH_PATH as well as the value
114 /// of LLVM_LIBDIR. It also must provide the System library paths as
115 /// returned by GetSystemLibraryPaths.
116 /// @see GetSystemLibraryPaths
117 /// @brief Construct a list of directories in which bitcode could be
118 /// found.
119 static void GetBitcodeLibraryPaths(std::vector& Paths);
120
121 /// Find the path to a library using its short name. Use the system
122 /// dependent library paths to locate the library.
123 /// @brief Find a library.
124 static Path FindLibrary(std::string& short_name);
125
126 /// Construct a path to the default LLVM configuration directory. The
127 /// implementation must ensure that this is a well-known (same on many
128 /// systems) directory in which llvm configuration files exist. For
129 /// example, on Unix, the /etc/llvm directory has been selected.
130 /// @brief Construct a path to the default LLVM configuration directory
131 static Path GetLLVMDefaultConfigDir();
132
133 /// Construct a path to the LLVM installed configuration directory. The
134 /// implementation must ensure that this refers to the "etc" directory of
135 /// the LLVM installation. This is the location where configuration files
136 /// will be located for a particular installation of LLVM on a machine.
137 /// @brief Construct a path to the LLVM installed configuration directory
138 static Path GetLLVMConfigDir();
139
140 /// Construct a path to the current user's home directory. The
141 /// implementation must use an operating system specific mechanism for
142 /// determining the user's home directory. For example, the environment
143 /// variable "HOME" could be used on Unix. If a given operating system
144 /// does not have the concept of a user's home directory, this static
145 /// constructor must provide the same result as GetRootDirectory.
146 /// @brief Construct a path to the current user's "home" directory
147 static Path GetUserHomeDirectory();
148
149 /// Construct a path to the current directory for the current process.
150 /// @returns The current working directory.
151 /// @brief Returns the current working directory.
152 static Path GetCurrentDirectory();
153
154 /// Return the suffix commonly used on file names that contain an
155 /// executable.
156 /// @returns The executable file suffix for the current platform.
157 /// @brief Return the executable file suffix.
158 static StringRef GetEXESuffix();
159
160 /// Return the suffix commonly used on file names that contain a shared
161 /// object, shared archive, or dynamic link library. Such files are
162 /// linked at runtime into a process and their code images are shared
163 /// between processes.
164 /// @returns The dynamic link library suffix for the current platform.
165 /// @brief Return the dynamic link library suffix.
166 static StringRef GetDLLSuffix();
167
168 /// GetMainExecutable - Return the path to the main executable, given the
169 /// value of argv[0] from program startup and the address of main itself.
170 /// In extremis, this function may fail and return an empty path.
171 static Path GetMainExecutable(const char *argv0, void *MainAddr);
172
173 /// This is one of the very few ways in which a path can be constructed
174 /// with a syntactically invalid name. The only *legal* invalid name is an
175 /// empty one. Other invalid names are not permitted. Empty paths are
176 /// provided so that they can be used to indicate null or error results in
177 /// other lib/System functionality.
178 /// @brief Construct an empty (and invalid) path.
179 Path() : path() {}
180 Path(const Path &that) : path(that.path) {}
181
182 /// This constructor will accept a char* or std::string as a path. No
183 /// checking is done on this path to determine if it is valid. To
184 /// determine validity of the path, use the isValid method.
185 /// @param p The path to assign.
186 /// @brief Construct a Path from a string.
187 explicit Path(StringRef p);
188
189 /// This constructor will accept a character range as a path. No checking
190 /// is done on this path to determine if it is valid. To determine
191 /// validity of the path, use the isValid method.
192 /// @param StrStart A pointer to the first character of the path name
193 /// @param StrLen The length of the path name at StrStart
194 /// @brief Construct a Path from a string.
195 Path(const char *StrStart, unsigned StrLen);
196
197 /// @}
198 /// @name Operators
199 /// @{
200 public:
201 /// Makes a copy of \p that to \p this.
202 /// @returns \p this
203 /// @brief Assignment Operator
204 Path &operator=(const Path &that) {
205 path = that.path;
206 return *this;
207 }
208
209 /// Makes a copy of \p that to \p this.
210 /// @param that A StringRef denoting the path
211 /// @returns \p this
212 /// @brief Assignment Operator
213 Path &operator=(StringRef that);
214
215 /// Compares \p this Path with \p that Path for equality.
216 /// @returns true if \p this and \p that refer to the same thing.
217 /// @brief Equality Operator
218 bool operator==(const Path &that) const;
219
220 /// Compares \p this Path with \p that Path for inequality.
221 /// @returns true if \p this and \p that refer to different things.
222 /// @brief Inequality Operator
223 bool operator!=(const Path &that) const { return !(*this == that); }
224
225 /// Determines if \p this Path is less than \p that Path. This is required
226 /// so that Path objects can be placed into ordered collections (e.g.
227 /// std::map). The comparison is done lexicographically as defined by
228 /// the std::string::compare method.
229 /// @returns true if \p this path is lexicographically less than \p that.
230 /// @brief Less Than Operator
231 bool operator<(const Path& that) const;
232
233 /// @}
234 /// @name Path Accessors
235 /// @{
236 public:
237 /// This function will use an operating system specific algorithm to
238 /// determine if the current value of \p this is a syntactically valid
239 /// path name for the operating system. The path name does not need to
240 /// exist, validity is simply syntactical. Empty paths are always invalid.
241 /// @returns true iff the path name is syntactically legal for the
242 /// host operating system.
243 /// @brief Determine if a path is syntactically valid or not.
244 bool isValid() const;
245
246 /// This function determines if the contents of the path name are empty.
247 /// That is, the path name has a zero length. This does NOT determine if
248 /// if the file is empty. To get the length of the file itself, Use the
249 /// PathWithStatus::getFileStatus() method and then the getSize() method
250 /// on the returned FileStatus object.
251 /// @returns true iff the path is empty.
252 /// @brief Determines if the path name is empty (invalid).
253 bool isEmpty() const { return path.empty(); }
254
255 /// This function returns the last component of the path name. The last
256 /// component is the file or directory name occuring after the last
257 /// directory separator. If no directory separator is present, the entire
258 /// path name is returned (i.e. same as toString).
259 /// @returns StringRef containing the last component of the path name.
260 /// @brief Returns the last component of the path name.
261 StringRef getLast() const;
262
263 /// This function strips off the path and suffix of the file or directory
264 /// name and returns just the basename. For example /a/foo.bar would cause
265 /// this function to return "foo".
266 /// @returns StringRef containing the basename of the path
267 /// @brief Get the base name of the path
268 StringRef getBasename() const;
269
270 /// This function strips off the suffix of the path beginning with the
271 /// path separator ('/' on Unix, '\' on Windows) and returns the result.
272 StringRef getDirname() const;
273
274 /// This function strips off the path and basename(up to and
275 /// including the last dot) of the file or directory name and
276 /// returns just the suffix. For example /a/foo.bar would cause
277 /// this function to return "bar".
278 /// @returns StringRef containing the suffix of the path
279 /// @brief Get the suffix of the path
280 StringRef getSuffix() const;
281
282 /// Obtain a 'C' string for the path name.
283 /// @returns a 'C' string containing the path name.
284 /// @brief Returns the path as a C string.
285 const char *c_str() const { return path.c_str(); }
286 const std::string &str() const { return path; }
287
288
289 /// size - Return the length in bytes of this path name.
290 size_t size() const { return path.size(); }
291
292 /// empty - Returns true if the path is empty.
293 unsigned empty() const { return path.empty(); }
294
295 /// @}
296 /// @name Disk Accessors
297 /// @{
298 public:
299 /// This function determines if the path name is absolute, as opposed to
300 /// relative.
301 /// @brief Determine if the path is absolute.
302 bool isAbsolute() const;
303
304 /// This function determines if the path name is absolute, as opposed to
305 /// relative.
306 /// @brief Determine if the path is absolute.
307 static bool isAbsolute(const char *NameStart, unsigned NameLen);
308
309 /// This function opens the file associated with the path name provided by
310 /// the Path object and reads its magic number. If the magic number at the
311 /// start of the file matches \p magic, true is returned. In all other
312 /// cases (file not found, file not accessible, etc.) it returns false.
313 /// @returns true if the magic number of the file matches \p magic.
314 /// @brief Determine if file has a specific magic number
315 bool hasMagicNumber(StringRef magic) const;
316
317 /// This function retrieves the first \p len bytes of the file associated
318 /// with \p this. These bytes are returned as the "magic number" in the
319 /// \p Magic parameter.
320 /// @returns true if the Path is a file and the magic number is retrieved,
321 /// false otherwise.
322 /// @brief Get the file's magic number.
323 bool getMagicNumber(std::string& Magic, unsigned len) const;
324
325 /// This function determines if the path name in the object references an
326 /// archive file by looking at its magic number.
327 /// @returns true if the file starts with the magic number for an archive
328 /// file.
329 /// @brief Determine if the path references an archive file.
330 bool isArchive() const;
331
332 /// This function determines if the path name in the object references an
333 /// LLVM Bitcode file by looking at its magic number.
334 /// @returns true if the file starts with the magic number for LLVM
335 /// bitcode files.
336 /// @brief Determine if the path references a bitcode file.
337 bool isBitcodeFile() const;
338
339 /// This function determines if the path name in the object references a
340 /// native Dynamic Library (shared library, shared object) by looking at
341 /// the file's magic number. The Path object must reference a file, not a
342 /// directory.
343 /// @returns true if the file starts with the magic number for a native
344 /// shared library.
345 /// @brief Determine if the path references a dynamic library.
346 bool isDynamicLibrary() const;
347
348 /// This function determines if the path name in the object references a
349 /// native object file by looking at it's magic number. The term object
350 /// file is defined as "an organized collection of separate, named
351 /// sequences of binary data." This covers the obvious file formats such
352 /// as COFF and ELF, but it also includes llvm ir bitcode, archives,
353 /// libraries, etc...
354 /// @returns true if the file starts with the magic number for an object
355 /// file.
356 /// @brief Determine if the path references an object file.
357 bool isObjectFile() const;
358
359 /// This function determines if the path name references an existing file
360 /// or directory in the file system.
361 /// @returns true if the pathname references an existing file or
362 /// directory.
363 /// @brief Determines if the path is a file or directory in
364 /// the file system.
365 bool exists() const;
366
367 /// This function determines if the path name references an
368 /// existing directory.
369 /// @returns true if the pathname references an existing directory.
370 /// @brief Determines if the path is a directory in the file system.
371 bool isDirectory() const;
372
373 /// This function determines if the path name references an
374 /// existing symbolic link.
375 /// @returns true if the pathname references an existing symlink.
376 /// @brief Determines if the path is a symlink in the file system.
377 bool isSymLink() const;
378
379 /// This function determines if the path name references a readable file
380 /// or directory in the file system. This function checks for
381 /// the existence and readability (by the current program) of the file
382 /// or directory.
383 /// @returns true if the pathname references a readable file.
384 /// @brief Determines if the path is a readable file or directory
385 /// in the file system.
386 bool canRead() const;
387
388 /// This function determines if the path name references a writable file
389 /// or directory in the file system. This function checks for the
390 /// existence and writability (by the current program) of the file or
391 /// directory.
392 /// @returns true if the pathname references a writable file.
393 /// @brief Determines if the path is a writable file or directory
394 /// in the file system.
395 bool canWrite() const;
396
397 /// This function checks that what we're trying to work only on a regular
398 /// file. Check for things like /dev/null, any block special file, or
399 /// other things that aren't "regular" regular files.
400 /// @returns true if the file is S_ISREG.
401 /// @brief Determines if the file is a regular file
402 bool isRegularFile() const;
403
404 /// This function determines if the path name references an executable
405 /// file in the file system. This function checks for the existence and
406 /// executability (by the current program) of the file.
407 /// @returns true if the pathname references an executable file.
408 /// @brief Determines if the path is an executable file in the file
409 /// system.
410 bool canExecute() const;
411
412 /// This function builds a list of paths that are the names of the
413 /// files and directories in a directory.
414 /// @returns true if an error occurs, true otherwise
415 /// @brief Build a list of directory's contents.
416 bool getDirectoryContents(
417 std::set &paths, ///< The resulting list of file & directory names
418 std::string* ErrMsg ///< Optional place to return an error message.
419 ) const;
420
421 /// @}
422 /// @name Path Mutators
423 /// @{
424 public:
425 /// The path name is cleared and becomes empty. This is an invalid
426 /// path name but is the *only* invalid path name. This is provided
427 /// so that path objects can be used to indicate the lack of a
428 /// valid path being found.
429 /// @brief Make the path empty.
430 void clear() { path.clear(); }
431
432 /// This method sets the Path object to \p unverified_path. This can fail
433 /// if the \p unverified_path does not pass the syntactic checks of the
434 /// isValid() method. If verification fails, the Path object remains
435 /// unchanged and false is returned. Otherwise true is returned and the
436 /// Path object takes on the path value of \p unverified_path
437 /// @returns true if the path was set, false otherwise.
438 /// @param unverified_path The path to be set in Path object.
439 /// @brief Set a full path from a StringRef
440 bool set(StringRef unverified_path);
441
442 /// One path component is removed from the Path. If only one component is
443 /// present in the path, the Path object becomes empty. If the Path object
444 /// is empty, no change is made.
445 /// @returns false if the path component could not be removed.
446 /// @brief Removes the last directory component of the Path.
447 bool eraseComponent();
448
449 /// The \p component is added to the end of the Path if it is a legal
450 /// name for the operating system. A directory separator will be added if
451 /// needed.
452 /// @returns false if the path component could not be added.
453 /// @brief Appends one path component to the Path.
454 bool appendComponent(StringRef component);
455
456 /// A period and the \p suffix are appended to the end of the pathname.
457 /// The precondition for this function is that the Path reference a file
458 /// name (i.e. isFile() returns true). If the Path is not a file, no
459 /// action is taken and the function returns false. If the path would
460 /// become invalid for the host operating system, false is returned. When
461 /// the \p suffix is empty, no action is performed.
462 /// @returns false if the suffix could not be added, true if it was.
463 /// @brief Adds a period and the \p suffix to the end of the pathname.
464 bool appendSuffix(StringRef suffix);
465
466 /// The suffix of the filename is erased. The suffix begins with and
467 /// includes the last . character in the filename after the last directory
468 /// separator and extends until the end of the name. If no . character is
469 /// after the last directory separator, then the file name is left
470 /// unchanged (i.e. it was already without a suffix) but the function
471 /// returns false.
472 /// @returns false if there was no suffix to remove, true otherwise.
473 /// @brief Remove the suffix from a path name.
474 bool eraseSuffix();
475
476 /// The current Path name is made unique in the file system. Upon return,
477 /// the Path will have been changed to make a unique file in the file
478 /// system or it will not have been changed if the current path name is
479 /// already unique.
480 /// @throws std::string if an unrecoverable error occurs.
481 /// @brief Make the current path name unique in the file system.
482 bool makeUnique( bool reuse_current /*= true*/, std::string* ErrMsg );
483
484 /// The current Path name is made absolute by prepending the
485 /// current working directory if necessary.
486 void makeAbsolute();
487
488 /// @}
489 /// @name Disk Mutators
490 /// @{
491 public:
492 /// This method attempts to make the file referenced by the Path object
493 /// available for reading so that the canRead() method will return true.
494 /// @brief Make the file readable;
495 bool makeReadableOnDisk(std::string* ErrMsg = 0);
496
497 /// This method attempts to make the file referenced by the Path object
498 /// available for writing so that the canWrite() method will return true.
499 /// @brief Make the file writable;
500 bool makeWriteableOnDisk(std::string* ErrMsg = 0);
501
502 /// This method attempts to make the file referenced by the Path object
503 /// available for execution so that the canExecute() method will return
504 /// true.
505 /// @brief Make the file readable;
506 bool makeExecutableOnDisk(std::string* ErrMsg = 0);
507
508 /// This method allows the last modified time stamp and permission bits
509 /// to be set on the disk object referenced by the Path.
510 /// @throws std::string if an error occurs.
511 /// @returns true on error.
512 /// @brief Set the status information.
513 bool setStatusInfoOnDisk(const FileStatus &SI,
514 std::string *ErrStr = 0) const;
515
516 /// This method attempts to create a directory in the file system with the
517 /// same name as the Path object. The \p create_parents parameter controls
518 /// whether intermediate directories are created or not. if \p
519 /// create_parents is true, then an attempt will be made to create all
520 /// intermediate directories, as needed. If \p create_parents is false,
521 /// then only the final directory component of the Path name will be
522 /// created. The created directory will have no entries.
523 /// @returns true if the directory could not be created, false otherwise
524 /// @brief Create the directory this Path refers to.
525 bool createDirectoryOnDisk(
526 bool create_parents = false, ///< Determines whether non-existent
527 ///< directory components other than the last one (the "parents")
528 ///< are created or not.
529 std::string* ErrMsg = 0 ///< Optional place to put error messages.
530 );
531
532 /// This method attempts to create a file in the file system with the same
533 /// name as the Path object. The intermediate directories must all exist
534 /// at the time this method is called. Use createDirectoriesOnDisk to
535 /// accomplish that. The created file will be empty upon return from this
536 /// function.
537 /// @returns true if the file could not be created, false otherwise.
538 /// @brief Create the file this Path refers to.
539 bool createFileOnDisk(
540 std::string* ErrMsg = 0 ///< Optional place to put error messages.
541 );
542
543 /// This is like createFile except that it creates a temporary file. A
544 /// unique temporary file name is generated based on the contents of
545 /// \p this before the call. The new name is assigned to \p this and the
546 /// file is created. Note that this will both change the Path object
547 /// *and* create the corresponding file. This function will ensure that
548 /// the newly generated temporary file name is unique in the file system.
549 /// @returns true if the file couldn't be created, false otherwise.
550 /// @brief Create a unique temporary file
551 bool createTemporaryFileOnDisk(
552 bool reuse_current = false, ///< When set to true, this parameter
553 ///< indicates that if the current file name does not exist then
554 ///< it will be used without modification.
555 std::string* ErrMsg = 0 ///< Optional place to put error messages
556 );
557
558 /// This method renames the file referenced by \p this as \p newName. The
559 /// file referenced by \p this must exist. The file referenced by
560 /// \p newName does not need to exist.
561 /// @returns true on error, false otherwise
562 /// @brief Rename one file as another.
563 bool renamePathOnDisk(const Path& newName, std::string* ErrMsg);
564
565 /// This method attempts to destroy the file or directory named by the
566 /// last component of the Path. If the Path refers to a directory and the
567 /// \p destroy_contents is false, an attempt will be made to remove just
568 /// the directory (the final Path component). If \p destroy_contents is
569 /// true, an attempt will be made to remove the entire contents of the
570 /// directory, recursively. If the Path refers to a file, the
571 /// \p destroy_contents parameter is ignored.
572 /// @param destroy_contents Indicates whether the contents of a destroyed
573 /// @param Err An optional string to receive an error message.
574 /// directory should also be destroyed (recursively).
575 /// @returns false if the file/directory was destroyed, true on error.
576 /// @brief Removes the file or directory from the filesystem.
577 bool eraseFromDisk(bool destroy_contents = false,
578 std::string *Err = 0) const;
579
580
581 /// MapInFilePages - This is a low level system API to map in the file
582 /// that is currently opened as FD into the current processes' address
583 /// space for read only access. This function may return null on failure
584 /// or if the system cannot provide the following constraints:
585 /// 1) The pages must be valid after the FD is closed, until
586 /// UnMapFilePages is called.
587 /// 2) Any padding after the end of the file must be zero filled, if
588 /// present.
589 /// 3) The pages must be contiguous.
590 ///
591 /// This API is not intended for general use, clients should use
592 /// MemoryBuffer::getFile instead.
593 static const char *MapInFilePages(int FD, uint64_t FileSize);
594
595 /// UnMapFilePages - Free pages mapped into the current process by
596 /// MapInFilePages.
597 ///
598 /// This API is not intended for general use, clients should use
599 /// MemoryBuffer::getFile instead.
600 static void UnMapFilePages(const char *Base, uint64_t FileSize);
601
602 /// @}
603 /// @name Data
604 /// @{
605 protected:
606 // Our win32 implementation relies on this string being mutable.
607 mutable std::string path; ///< Storage for the path name.
608
609
610 /// @}
611 };
612
613 /// This class is identical to Path class except it allows you to obtain the
614 /// file status of the Path as well. The reason for the distinction is one of
615 /// efficiency. First, the file status requires additional space and the space
616 /// is incorporated directly into PathWithStatus without an additional malloc.
617 /// Second, obtaining status information is an expensive operation on most
618 /// operating systems so we want to be careful and explicity about where we
619 /// allow this operation in LLVM.
620 /// @brief Path with file status class.
621 class PathWithStatus : public Path {
622 /// @name Constructors
623 /// @{
624 public:
625 /// @brief Default constructor
626 PathWithStatus() : Path(), status(), fsIsValid(false) {}
627
628 /// @brief Copy constructor
629 PathWithStatus(const PathWithStatus &that)
630 : Path(static_cast(that)), status(that.status),
631 fsIsValid(that.fsIsValid) {}
632
633 /// This constructor allows construction from a Path object
634 /// @brief Path constructor
635 PathWithStatus(const Path &other)
636 : Path(other), status(), fsIsValid(false) {}
637
638 /// This constructor will accept a char* or std::string as a path. No
639 /// checking is done on this path to determine if it is valid. To
640 /// determine validity of the path, use the isValid method.
641 /// @brief Construct a Path from a string.
642 explicit PathWithStatus(
643 StringRef p ///< The path to assign.
644 ) : Path(p), status(), fsIsValid(false) {}
645
646 /// This constructor will accept a character range as a path. No checking
647 /// is done on this path to determine if it is valid. To determine
648 /// validity of the path, use the isValid method.
649 /// @brief Construct a Path from a string.
650 explicit PathWithStatus(
651 const char *StrStart, ///< Pointer to the first character of the path
652 unsigned StrLen ///< Length of the path.
653 ) : Path(StrStart, StrLen), status(), fsIsValid(false) {}
654
655 /// Makes a copy of \p that to \p this.
656 /// @returns \p this
657 /// @brief Assignment Operator
658 PathWithStatus &operator=(const PathWithStatus &that) {
659 static_cast(*this) = static_cast(that);
660 status = that.status;
661 fsIsValid = that.fsIsValid;
662 return *this;
663 }
664
665 /// Makes a copy of \p that to \p this.
666 /// @returns \p this
667 /// @brief Assignment Operator
668 PathWithStatus &operator=(const Path &that) {
669 static_cast(*this) = static_cast(that);
670 fsIsValid = false;
671 return *this;
672 }
673
674 /// @}
675 /// @name Methods
676 /// @{
677 public:
678 /// This function returns status information about the file. The type of
679 /// path (file or directory) is updated to reflect the actual contents
680 /// of the file system.
681 /// @returns 0 on failure, with Error explaining why (if non-zero)
682 /// @returns a pointer to a FileStatus structure on success.
683 /// @brief Get file status.
684 const FileStatus *getFileStatus(
685 bool forceUpdate = false, ///< Force an update from the file system
686 std::string *Error = 0 ///< Optional place to return an error msg.
687 ) const;
688
689 /// @}
690 /// @name Data
691 /// @{
692 private:
693 mutable FileStatus status; ///< Status information.
694 mutable bool fsIsValid; ///< Whether we've obtained it or not
695
696 /// @}
697 };
698
699 /// This enumeration delineates the kinds of files that LLVM knows about.
700 enum LLVMFileType {
701 Unknown_FileType = 0, ///< Unrecognized file
702 Bitcode_FileType, ///< Bitcode file
703 Archive_FileType, ///< ar style archive file
704 ELF_Relocatable_FileType, ///< ELF Relocatable object file
705 ELF_Executable_FileType, ///< ELF Executable image
706 ELF_SharedObject_FileType, ///< ELF dynamically linked shared lib
707 ELF_Core_FileType, ///< ELF core image
708 Mach_O_Object_FileType, ///< Mach-O Object file
709 Mach_O_Executable_FileType, ///< Mach-O Executable
710 Mach_O_FixedVirtualMemorySharedLib_FileType, ///< Mach-O Shared Lib, FVM
711 Mach_O_Core_FileType, ///< Mach-O Core File
712 Mach_O_PreloadExecutable_FileType, ///< Mach-O Preloaded Executable
713 Mach_O_DynamicallyLinkedSharedLib_FileType, ///< Mach-O dynlinked shared lib
714 Mach_O_DynamicLinker_FileType, ///< The Mach-O dynamic linker
715 Mach_O_Bundle_FileType, ///< Mach-O Bundle file
716 Mach_O_DynamicallyLinkedSharedLibStub_FileType, ///< Mach-O Shared lib stub
717 COFF_FileType ///< COFF object file or lib
718 };
719
720 /// This utility function allows any memory block to be examined in order
721 /// to determine its file type.
722 LLVMFileType IdentifyFileType(const char*magic, unsigned length);
723
724 /// This function can be used to copy the file specified by Src to the
725 /// file specified by Dest. If an error occurs, Dest is removed.
726 /// @returns true if an error occurs, false otherwise
727 /// @brief Copy one file to another.
728 bool CopyFile(const Path& Dest, const Path& Src, std::string* ErrMsg);
729
730 /// This is the OS-specific path separator: a colon on Unix or a semicolon
731 /// on Windows.
732 extern const char PathSeparator;
733 }
734
735 }
736
737 #endif
0 //===- llvm/System/PathV2.h - Path Operating System Concept -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the llvm::sys::path namespace. It is designed after
10 // TR2/boost filesystem (v3), but modified to remove exception handling and the
11 // path class.
12 //
13 // All functions return an error_code and their actual work via the last out
14 // argument. The out argument is defined if and only if errc::success is
15 // returned. A function may return any error code in the generic or system
16 // category. However, they shall be equivalent to any error conditions listed
17 // in each functions respective documentation if the condition applies. [ note:
18 // this does not guarantee that error_code will be in the set of explicitly
19 // listed codes, but it does guarantee that if any of the explicitly listed
20 // errors occur, the correct error_code will be used ]. All functions may
21 // return errc::not_enough_memory if there is not enough memory to complete the
22 // operation.
23 //
24 //===----------------------------------------------------------------------===//
25
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/Support/DataTypes.h"
28 #include "llvm/Support/system_error.h"
29 #include
30 #include
31 #include
32
33 namespace llvm {
34
35 // Forward decls.
36 class StringRef;
37 class Twine;
38
39 namespace sys {
40 namespace path {
41
42 /// @name Lexical Component Iterator
43 /// @{
44
45 /// @brief Path iterator.
46 ///
47 /// This is a bidirectional iterator that iterates over the individual
48 /// components in \a path. The forward traversal order is as follows:
49 /// * The root-name element, if present.
50 /// * The root-directory element, if present.
51 /// * Each successive filename element, if present.
52 /// * Dot, if one or more trailing non-root slash characters are present.
53 /// The backwards traversal order is the reverse of forward traversal.
54 ///
55 /// Iteration examples. Each component is separated by ',':
56 /// / => /
57 /// /foo => /,foo
58 /// foo/ => foo,.
59 /// /foo/bar => /,foo,bar
60 /// ../ => ..,.
61 /// C:\foo\bar => C:,/,foo,bar
62 ///
63 class const_iterator {
64 StringRef Path; //< The entire path.
65 StringRef Component; //< The current component.
66
67 public:
68 typedef const StringRef value_type;
69 typedef value_type &reference;
70 typedef value_type *pointer;
71 typedef std::bidirectional_iterator_tag iterator_category;
72 reference operator*() const;
73 pointer operator->() const;
74 const_iterator &operator++(); // preincrement
75 const_iterator &operator++(int); // postincrement
76 const_iterator &operator--(); // predecrement
77 const_iterator &operator--(int); // postdecrement
78 bool operator==(const const_iterator &RHS) const;
79 bool operator!=(const const_iterator &RHS) const;
80
81 const_iterator(); //< Default construct end iterator.
82 const_iterator(const StringRef &path);
83 };
84
85 /// @}
86 /// @name Lexical Modifiers
87 /// @{
88
89 /// @brief Make \a path an absolute path.
90 ///
91 /// Makes \a path absolute using the current directory if it is not already. An
92 /// empty \a path will result in the current directory.
93 ///
94 /// /absolute/path => /absolute/path
95 /// relative/../path => /path
96 ///
97 /// @param path A path that is modified to be an absolute path.
98 /// @returns errc::success if \a path has been made absolute, otherwise a
99 /// platform specific error_code.
100 error_code make_absolute(SmallVectorImpl &path);
101
102 /// @brief Remove the last component from \a path if it exists.
103 ///
104 /// directory/filename.cpp => directory/
105 /// directory/ => directory/
106 ///
107 /// @param path A path that is modified to not have a file component.
108 /// @returns errc::success if \a path's file name has been removed (or there was
109 /// not one to begin with), otherwise a platform specific error_code.
110 error_code remove_filename(SmallVectorImpl &path);
111
112 /// @brief Replace the file extension of \a path with \a extension.
113 ///
114 /// ./filename.cpp => ./filename.extension
115 /// ./filename => ./filename.extension
116 /// ./ => ? TODO: decide what semantics this has.
117 ///
118 /// @param path A path that has its extension replaced with \a extension.
119 /// @param extension The extension to be added. It may be empty. It may also
120 /// optionally start with a '.', if it does not, one will be
121 /// prepended.
122 /// @returns errc::success if \a path's extension has been replaced, otherwise a
123 /// platform specific error_code.
124 error_code replace_extension(SmallVectorImpl &path,
125 const Twine &extension);
126
127 /// @brief Append to path.
128 ///
129 /// /foo + bar/f => /foo/bar/f
130 /// /foo/ + bar/f => /foo/bar/f
131 /// foo + bar/f => foo/bar/f
132 ///
133 /// @param path Set to \a path + \a component.
134 /// @param component The component to be appended to \a path.
135 /// @returns errc::success if \a component has been appended to \a path,
136 /// otherwise a platform specific error_code.
137 error_code append(SmallVectorImpl &path, const Twine &component);
138
139 /// @brief Append to path.
140 ///
141 /// /foo + [bar,f] => /foo/bar/f
142 /// /foo/ + [bar,f] => /foo/bar/f
143 /// foo + [bar,f] => foo/bar/f
144 ///
145 /// @param path Set to \a path + [\a begin, \a end).
146 /// @param begin Start of components to append.
147 /// @param end One past the end of components to append.
148 /// @returns errc::success if [\a begin, \a end) has been appended to \a path,
149 /// otherwise a platform specific error_code.
150 error_code append(SmallVectorImpl &path,
151 const_iterator begin, const_iterator end);
152
153 /// @}
154 /// @name Transforms (or some other better name)
155 /// @{
156
157 /// Convert path to the native form. This is used to give paths to users and
158 /// operating system calls in the platform's normal way. For example, on Windows
159 /// all '/' are converted to '\'.
160 ///
161 /// @param path A path that is transformed to native format.
162 /// @param result Holds the result of the transformation.
163 /// @returns errc::success if \a path has been transformed and stored in result,
164 /// otherwise a platform specific error_code.
165 error_code native(const Twine &path, SmallVectorImpl &result);
166
167 /// @}
168 /// @name Lexical Observers
169 /// @{
170
171 /// @brief Get the current path.
172 ///
173 /// @param result Holds the current path on return.
174 /// @results errc::success if the current path has been stored in result,
175 /// otherwise a platform specific error_code.
176 error_code current_path(SmallVectorImpl &result);
177
178 // The following are purely lexical.
179
180 /// @brief Is the current path valid?
181 ///
182 /// @param path Input path.
183 /// @param result Set to true if the path is valid, false if it is not.
184 /// @results errc::success if result has been successfully set, otherwise a
185 /// platform specific error_code.
186 error_code is_valid(const Twine &path, bool &result);
187
188 /// @brief Get root name.
189 ///
190 /// //net/hello => //net
191 /// c:/hello => c: (on Windows, on other platforms nothing)
192 /// /hello =>
193 ///
194 /// @param path Input path.
195 /// @param result Set to the root name of \a path if it has one, otherwise "".
196 /// @results errc::success if result has been successfully set, otherwise a
197 /// platform specific error_code.
198 error_code root_name(const StringRef &path, StringRef &result);
199
200 /// @brief Get root directory.
201 ///
202 /// /goo/hello => /
203 /// c:/hello => /
204 /// d/file.txt =>
205 ///
206 /// @param path Input path.
207 /// @param result Set to the root directory of \a path if it has one, otherwise
208 /// "".
209 /// @results errc::success if result has been successfully set, otherwise a
210 /// platform specific error_code.
211 error_code root_directory(const StringRef &path, StringRef &result);
212
213 /// @brief Get root path.
214 ///
215 /// Equivalent to root_name + root_directory.
216 ///
217 /// @param path Input path.
218 /// @param result Set to the root path of \a path if it has one, otherwise "".
219 /// @results errc::success if result has been successfully set, otherwise a
220 /// platform specific error_code.
221 error_code root_path(const StringRef &path, StringRef &result);
222
223 /// @brief Get relative path.
224 ///
225 /// C:\hello\world => hello\world
226 /// foo/bar => foo/bar
227 /// /foo/bar => foo/bar
228 ///
229 /// @param path Input path.
230 /// @param result Set to the path starting after root_path if one exists,
231 /// otherwise "".
232 /// @results errc::success if result has been successfully set, otherwise a
233 /// platform specific error_code.
234 error_code relative_path(const StringRef &path, StringRef &result);
235
236 /// @brief Get parent path.
237 ///
238 /// / =>
239 /// /foo => /
240 /// foo/../bar => foo/..
241 ///
242 /// @param path Input path.
243 /// @param result Set to the parent path of \a path if one exists, otherwise "".
244 /// @results errc::success if result has been successfully set, otherwise a
245 /// platform specific error_code.
246 error_code parent_path(const StringRef &path, StringRef &result);
247
248 /// @brief Get filename.
249 ///
250 /// /foo.txt => foo.txt
251 /// . => .
252 /// .. => ..
253 /// / => /
254 ///
255 /// @param path Input path.
256 /// @param result Set to the filename part of \a path. This is defined as the
257 /// last component of \a path.
258 /// @results errc::success if result has been successfully set, otherwise a
259 /// platform specific error_code.
260 error_code filename(const StringRef &path, StringRef &result);
261
262 /// @brief Get stem.
263 ///
264 /// If filename contains a dot but not solely one or two dots, result is the
265 /// substring of filename ending at (but not including) the last dot. Otherwise
266 /// it is filename.
267 ///
268 /// /foo/bar.txt => bar
269 /// /foo/bar => bar
270 /// /foo/.txt =>
271 /// /foo/. => .
272 /// /foo/.. => ..
273 ///
274 /// @param path Input path.
275 /// @param result Set to the stem of \a path.
276 /// @results errc::success if result has been successfully set, otherwise a
277 /// platform specific error_code.
278 error_code stem(const StringRef &path, StringRef &result);
279
280 /// @brief Get extension.
281 ///
282 /// If filename contains a dot but not solely one or two dots, result is the
283 /// substring of filename starting at (and including) the last dot, and ending
284 /// at the end of \a path. Otherwise "".
285 ///
286 /// /foo/bar.txt => .txt
287 /// /foo/bar =>
288 /// /foo/.txt => .txt
289 ///
290 /// @param path Input path.
291 /// @param result Set to the extension of \a path.
292 /// @results errc::success if result has been successfully set, otherwise a
293 /// platform specific error_code.
294 error_code extension(const StringRef &path, StringRef &result);
295
296 /// @brief Has root name?
297 ///
298 /// root_name != ""
299 ///
300 /// @param path Input path.
301 /// @param result Set to true if the path has a root name, false otherwise.
302 /// @results errc::success if result has been successfully set, otherwise a
303 /// platform specific error_code.
304 error_code has_root_name(const Twine &path, bool &result);
305
306 /// @brief Has root directory?
307 ///
308 /// root_directory != ""
309 ///
310 /// @param path Input path.
311 /// @param result Set to true if the path has a root directory, false otherwise.
312 /// @results errc::success if result has been successfully set, otherwise a
313 /// platform specific error_code.
314 error_code has_root_directory(const Twine &path, bool &result);
315
316 /// @brief Has root path?
317 ///
318 /// root_path != ""
319 ///
320 /// @param path Input path.
321 /// @param result Set to true if the path has a root path, false otherwise.
322 /// @results errc::success if result has been successfully set, otherwise a
323 /// platform specific error_code.
324 error_code has_root_path(const Twine &path, bool &result);
325
326 /// @brief Has relative path?
327 ///
328 /// relative_path != ""
329 ///
330 /// @param path Input path.
331 /// @param result Set to true if the path has a relative path, false otherwise.
332 /// @results errc::success if result has been successfully set, otherwise a
333 /// platform specific error_code.
334 error_code has_relative_path(const Twine &path, bool &result);
335
336 /// @brief Has parent path?
337 ///
338 /// parent_path != ""
339 ///
340 /// @param path Input path.
341 /// @param result Set to true if the path has a parent path, false otherwise.
342 /// @results errc::success if result has been successfully set, otherwise a
343 /// platform specific error_code.
344 error_code has_parent_path(const Twine &path, bool &result);
345
346 /// @brief Has filename?
347 ///
348 /// filename != ""
349 ///
350 /// @param path Input path.
351 /// @param result Set to true if the path has a filename, false otherwise.
352 /// @results errc::success if result has been successfully set, otherwise a
353 /// platform specific error_code.
354 error_code has_filename(const Twine &path, bool &result);
355
356 /// @brief Has stem?
357 ///
358 /// stem != ""
359 ///
360 /// @param path Input path.
361 /// @param result Set to true if the path has a stem, false otherwise.
362 /// @results errc::success if result has been successfully set, otherwise a
363 /// platform specific error_code.
364 error_code has_stem(const Twine &path, bool &result);
365
366 /// @brief Has extension?
367 ///
368 /// extension != ""
369 ///
370 /// @param path Input path.
371 /// @param result Set to true if the path has a extension, false otherwise.
372 /// @results errc::success if result has been successfully set, otherwise a
373 /// platform specific error_code.
374 error_code has_extension(const Twine &path, bool &result);
375
376 /// @brief Is path absolute?
377 ///
378 /// @param path Input path.
379 /// @param result Set to true if the path is absolute, false if it is not.
380 /// @results errc::success if result has been successfully set, otherwise a
381 /// platform specific error_code.
382 error_code is_absolute(const Twine &path, bool &result);
383
384 /// @brief Is path relative?
385 ///
386 /// @param path Input path.
387 /// @param result Set to true if the path is relative, false if it is not.
388 /// @results errc::success if result has been successfully set, otherwise a
389 /// platform specific error_code.
390 error_code is_relative(const Twine &path, bool &result);
391 // end purely lexical.
392
393 } // end namespace path
394
395 namespace fs {
396
397 /// file_type - An "enum class" enumeration for the file system's view of the
398 /// type.
399 struct file_type {
400 enum _ {
401 status_error,
402 file_not_found,
403 regular_file,
404 directory_file,
405 symlink_file,
406 block_file,
407 character_file,
408 fifo_file,
409 socket_file,
410 type_unknown
411 };
412
413 file_type(_ v) : v_(v) {}
414 explicit file_type(int v) : v_(_(v)) {}
415 operator int() const {return v_;}
416
417 private:
418 int v_;
419 };
420
421 /// copy_option - An "enum class" enumeration of copy semantics for copy
422 /// operations.
423 struct copy_option {
424 enum _ {
425 fail_if_exists,
426 overwrite_if_exists
427 };
428
429 copy_option(_ v) : v_(v) {}
430 explicit copy_option(int v) : v_(_(v)) {}
431 operator int() const {return v_;}
432
433 private:
434 int v_;
435 };
436
437 /// space_info - Self explanatory.
438 struct space_info {
439 uint64_t capacity;
440 uint64_t free;
441 uint64_t available;
442 };
443
444 /// file_status - Represents the result of a call to stat and friends. It has
445 /// a platform specific member to store the result.
446 class file_status
447 {
448 // implementation defined status field.
449 public:
450 explicit file_status(file_type v=file_type::status_error);
451
452 file_type type() const;
453 void type(file_type v);
454 };
455
456 /// @}
457 /// @name Physical Operators
458 /// @{
459
460 /// @brief Copy the file at \a from to the path \a to.
461 ///
462 /// @param from The path to copy the file from.
463 /// @param to The path to copy the file to.
464 /// @param copt Behavior if \a to already exists.
465 /// @returns errc::success if the file has been successfully copied.
466 /// errc::file_exists if \a to already exists and \a copt ==
467 /// copy_option::fail_if_exists. Otherwise a platform specific
468 /// error_code.
469 error_code copy_file(const Twine &from, const Twine &to,
470 copy_option copt = copy_option::fail_if_exists);
471
472 /// @brief Create all the non-existent directories in path.
473 ///
474 /// @param path Directories to create.
475 /// @param existed Set to true if \a path already existed, false otherwise.
476 /// @returns errc::success if is_directory(path) and existed have been set,
477 /// otherwise a platform specific error_code.
478 error_code create_directories(const Twine &path, bool &existed);
479
480 /// @brief Create the directory in path.
481 ///
482 /// @param path Directory to create.
483 /// @param existed Set to true if \a path already existed, false otherwise.
484 /// @returns errc::success if is_directory(path) and existed have been set,
485 /// otherwise a platform specific error_code.
486 error_code create_directory(const Twine &path, bool &existed);
487
488 /// @brief Create a hard link from \a from to \a to.
489 ///
490 /// @param to The path to hard link to.
491 /// @param from The path to hard link from. This is created.
492 /// @returns errc::success if exists(to) && exists(from) && equivalent(to, from)
493 /// , otherwise a platform specific error_code.
494 error_code create_hard_link(const Twine &to, const Twine &from);
495
496 /// @brief Create a symbolic link from \a from to \a to.
497 ///
498 /// @param to The path to symbolically link to.
499 /// @param from The path to symbolically link from. This is created.
500 /// @returns errc::success if exists(to) && exists(from) && is_symlink(from),
501 /// otherwise a platform specific error_code.
502 error_code create_symlink(const Twine &to, const Twine &from);
503
504 /// @brief Remove path. Equivalent to POSIX remove().
505 ///
506 /// @param path Input path.
507 /// @param existed Set to true if \a path existed, false if it did not.
508 /// undefined otherwise.
509 /// @results errc::success if path has been removed and existed has been
510 /// successfully set, otherwise a platform specific error_code.
511 error_code remove(const Twine &path, bool &existed);
512
513 /// @brief Recursively remove all files below \a path, then \a path. Files are
514 /// removed as if by POSIX remove().
515 ///
516 /// @param path Input path.
517 /// @param num_removed Number of files removed.
518 /// @results errc::success if path has been removed and num_removed has been
519 /// successfully set, otherwise a platform specific error_code.
520 error_code remove_all(const Twine &path, uint32_t &num_removed);
521
522 /// @brief Rename \a from to \a to. Files are renamed as if by POSIX rename().
523 ///
524 /// @param from The path to rename from.
525 /// @param to The path to rename to. This is created.
526 error_code rename(const Twine &from, const Twine &to);
527
528 /// @brief Resize path to size. File is resized as if by POSIX truncate().
529 ///
530 /// @param path Input path.
531 /// @param size Size to resize to.
532 /// @returns errc::success if \a path has been resized to \a size, otherwise a
533 /// platform specific error_code.
534 error_code resize_file(const Twine &path, uint64_t size);
535
536 /// @brief Make file readable.
537 ///
538 /// @param path Input path.
539 /// @param value If true, make readable, else, make unreadable.
540 /// @results errc::success if readability has been successfully set, otherwise a
541 /// platform specific error_code.
542 error_code set_read(const Twine &path, bool value);
543
544 /// @brief Make file writeable.
545 ///
546 /// @param path Input path.
547 /// @param value If true, make writeable, else, make unwriteable.
548 /// @results errc::success if writeability has been successfully set, otherwise
549 /// a platform specific error_code.
550 error_code set_write(const Twine &path, bool value);
551
552 /// @brief Make file executable.
553 ///
554 /// @param path Input path.
555 /// @param value If true, make executable, else, make unexecutable.
556 /// @results errc::success if executability has been successfully set, otherwise
557 /// a platform specific error_code.
558 error_code set_execute(const Twine &path, bool value);
559
560 /// @}
561 /// @name Physical Observers
562 /// @{
563
564 /// @brief Does file exist?
565 ///
566 /// @param status A file_status previously returned from stat.
567 /// @param result Set to true if the file represented by status exists, false if
568 /// it does not. Undefined otherwise.
569 /// @results errc::success if result has been successfully set, otherwise a
570 /// platform specific error_code.
571 error_code exists(file_status status, bool &result);
572
573 /// @brief Does file exist?
574 ///
575 /// @param path Input path.
576 /// @param result Set to true if the file represented by status exists, false if
577 /// it does not. Undefined otherwise.
578 /// @results errc::success if result has been successfully set, otherwise a
579 /// platform specific error_code.
580 error_code exists(const Twine &path, bool &result);
581
582 /// @brief Do paths represent the same thing?
583 ///
584 /// @param A Input path A.
585 /// @param B Input path B.
586 /// @param result Set to true if stat(A) and stat(B) have the same device and
587 /// inode (or equivalent).
588 /// @results errc::success if result has been successfully set, otherwise a
589 /// platform specific error_code.
590 error_code equivalent(const Twine &A, const Twine &B, bool &result);
591
592 /// @brief Get file size.