aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Support
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Support')
-rw-r--r--include/llvm/Support/CodeGen.h10
-rw-r--r--include/llvm/Support/Debug.h6
-rw-r--r--include/llvm/Support/Dwarf.h2
-rw-r--r--include/llvm/Support/ELF.h4
-rw-r--r--include/llvm/Support/IRBuilder.h87
-rw-r--r--include/llvm/Support/InstVisitor.h25
-rw-r--r--include/llvm/Support/JSONParser.h448
-rw-r--r--include/llvm/Support/Locale.h17
-rw-r--r--include/llvm/Support/MDBuilder.h118
-rw-r--r--include/llvm/Support/Process.h4
-rw-r--r--include/llvm/Support/SourceMgr.h7
-rw-r--r--include/llvm/Support/TargetRegistry.h4
-rw-r--r--include/llvm/Support/TargetSelect.h12
-rw-r--r--include/llvm/Support/ValueHandle.h43
-rw-r--r--include/llvm/Support/YAMLParser.h552
-rw-r--r--include/llvm/Support/raw_ostream.h5
-rw-r--r--include/llvm/Support/type_traits.h2
17 files changed, 843 insertions, 503 deletions
diff --git a/include/llvm/Support/CodeGen.h b/include/llvm/Support/CodeGen.h
index 3a76cc7..1b66c94 100644
--- a/include/llvm/Support/CodeGen.h
+++ b/include/llvm/Support/CodeGen.h
@@ -27,6 +27,16 @@ namespace llvm {
enum Model { Default, JITDefault, Small, Kernel, Medium, Large };
}
+ // TLS models.
+ namespace TLSModel {
+ enum Model {
+ GeneralDynamic,
+ LocalDynamic,
+ InitialExec,
+ LocalExec
+ };
+ }
+
// Code generation optimization level.
namespace CodeGenOpt {
enum Level {
diff --git a/include/llvm/Support/Debug.h b/include/llvm/Support/Debug.h
index 8651fc1..e723272 100644
--- a/include/llvm/Support/Debug.h
+++ b/include/llvm/Support/Debug.h
@@ -35,14 +35,14 @@ class raw_ostream;
#ifndef DEBUG_TYPE
#define DEBUG_TYPE ""
#endif
-
+
#ifndef NDEBUG
/// DebugFlag - This boolean is set to true if the '-debug' command line option
/// is specified. This should probably not be referenced directly, instead, use
/// the DEBUG macro below.
///
extern bool DebugFlag;
-
+
/// isCurrentDebugType - Return true if the specified string is the debug type
/// specified on the command line, or if none was specified on the command line
/// with the -debug-only=X option.
@@ -54,7 +54,7 @@ bool isCurrentDebugType(const char *Type);
/// debug output to be produced.
///
void SetCurrentDebugType(const char *Type);
-
+
/// DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug
/// information. In the '-debug' option is specified on the commandline, and if
/// this is a debug build, then the code specified as the option to the macro
diff --git a/include/llvm/Support/Dwarf.h b/include/llvm/Support/Dwarf.h
index e57fbf7..8f18a99 100644
--- a/include/llvm/Support/Dwarf.h
+++ b/include/llvm/Support/Dwarf.h
@@ -131,7 +131,7 @@ enum dwarf_constants {
DW_TAG_GNU_template_parameter_pack = 0x4107,
DW_TAG_GNU_formal_parameter_pack = 0x4108,
DW_TAG_lo_user = 0x4080,
- DW_TAG_APPLE_Property = 0x4200,
+ DW_TAG_APPLE_property = 0x4200,
DW_TAG_hi_user = 0xffff,
// Children flag
diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h
index 5c5e4a1..fdd889b 100644
--- a/include/llvm/Support/ELF.h
+++ b/include/llvm/Support/ELF.h
@@ -609,8 +609,10 @@ enum {
EF_MIPS_ARCH_3 = 0x20000000, // MIPS3 instruction set
EF_MIPS_ARCH_4 = 0x30000000, // MIPS4 instruction set
EF_MIPS_ARCH_5 = 0x40000000, // MIPS5 instruction set
- EF_MIPS_ARCH_32 = 0x60000000, // MIPS32 instruction set
+ EF_MIPS_ARCH_32 = 0x50000000, // MIPS32 instruction set per linux not elf.h
+ EF_MIPS_ARCH_64 = 0x60000000, // MIPS64 instruction set per linux not elf.h
EF_MIPS_ARCH_32R2 = 0x70000000, // mips32r2
+ EF_MIPS_ARCH_64R2 = 0x80000000, // mips64r2
EF_MIPS_ARCH = 0xf0000000 // Mask for applying EF_MIPS_ARCH_ variant
};
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index 7828001..ef00e8e 100644
--- a/include/llvm/Support/IRBuilder.h
+++ b/include/llvm/Support/IRBuilder.h
@@ -17,6 +17,7 @@
#include "llvm/Instructions.h"
#include "llvm/BasicBlock.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
@@ -331,49 +332,63 @@ template<bool preserveNames = true, typename T = ConstantFolder,
typename Inserter = IRBuilderDefaultInserter<preserveNames> >
class IRBuilder : public IRBuilderBase, public Inserter {
T Folder;
+ MDNode *DefaultFPMathTag;
public:
- IRBuilder(LLVMContext &C, const T &F, const Inserter &I = Inserter())
- : IRBuilderBase(C), Inserter(I), Folder(F) {
+ IRBuilder(LLVMContext &C, const T &F, const Inserter &I = Inserter(),
+ MDNode *FPMathTag = 0)
+ : IRBuilderBase(C), Inserter(I), Folder(F), DefaultFPMathTag(FPMathTag) {
}
- explicit IRBuilder(LLVMContext &C) : IRBuilderBase(C), Folder() {
+ explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = 0) : IRBuilderBase(C),
+ Folder(), DefaultFPMathTag(FPMathTag) {
}
- explicit IRBuilder(BasicBlock *TheBB, const T &F)
- : IRBuilderBase(TheBB->getContext()), Folder(F) {
+ explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = 0)
+ : IRBuilderBase(TheBB->getContext()), Folder(F),
+ DefaultFPMathTag(FPMathTag) {
SetInsertPoint(TheBB);
}
- explicit IRBuilder(BasicBlock *TheBB)
- : IRBuilderBase(TheBB->getContext()), Folder() {
+ explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = 0)
+ : IRBuilderBase(TheBB->getContext()), Folder(),
+ DefaultFPMathTag(FPMathTag) {
SetInsertPoint(TheBB);
}
- explicit IRBuilder(Instruction *IP)
- : IRBuilderBase(IP->getContext()), Folder() {
+ explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = 0)
+ : IRBuilderBase(IP->getContext()), Folder(), DefaultFPMathTag(FPMathTag) {
SetInsertPoint(IP);
SetCurrentDebugLocation(IP->getDebugLoc());
}
- explicit IRBuilder(Use &U)
- : IRBuilderBase(U->getContext()), Folder() {
+ explicit IRBuilder(Use &U, MDNode *FPMathTag = 0)
+ : IRBuilderBase(U->getContext()), Folder(), DefaultFPMathTag(FPMathTag) {
SetInsertPoint(U);
SetCurrentDebugLocation(cast<Instruction>(U.getUser())->getDebugLoc());
}
- IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F)
- : IRBuilderBase(TheBB->getContext()), Folder(F) {
+ IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F,
+ MDNode *FPMathTag = 0)
+ : IRBuilderBase(TheBB->getContext()), Folder(F),
+ DefaultFPMathTag(FPMathTag) {
SetInsertPoint(TheBB, IP);
}
- IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP)
- : IRBuilderBase(TheBB->getContext()), Folder() {
+ IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, MDNode *FPMathTag = 0)
+ : IRBuilderBase(TheBB->getContext()), Folder(),
+ DefaultFPMathTag(FPMathTag) {
SetInsertPoint(TheBB, IP);
}
/// getFolder - Get the constant folder being used.
const T &getFolder() { return Folder; }
+ /// getDefaultFPMathTag - Get the floating point math metadata being used.
+ MDNode *getDefaultFPMathTag() const { return DefaultFPMathTag; }
+
+ /// SetDefaultFPMathTag - Set the floating point math metadata to be used.
+ void SetDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
+
/// isNamePreserving - Return true if this builder is configured to actually
/// add the requested names to IR created through it.
bool isNamePreserving() const { return preserveNames; }
@@ -496,6 +511,14 @@ private:
if (HasNSW) BO->setHasNoSignedWrap();
return BO;
}
+
+ Instruction *AddFPMathTag(Instruction *I, MDNode *FPMathTag) const {
+ if (!FPMathTag)
+ FPMathTag = DefaultFPMathTag;
+ if (FPMathTag)
+ I->setMetadata(LLVMContext::MD_fpmath, FPMathTag);
+ return I;
+ }
public:
Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
bool HasNUW = false, bool HasNSW = false) {
@@ -511,11 +534,13 @@ public:
Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
return CreateAdd(LHS, RHS, Name, true, false);
}
- Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
+ Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "",
+ MDNode *FPMathTag = 0) {
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
return Insert(Folder.CreateFAdd(LC, RC), Name);
- return Insert(BinaryOperator::CreateFAdd(LHS, RHS), Name);
+ return Insert(AddFPMathTag(BinaryOperator::CreateFAdd(LHS, RHS),
+ FPMathTag), Name);
}
Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
bool HasNUW = false, bool HasNSW = false) {
@@ -531,11 +556,13 @@ public:
Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
return CreateSub(LHS, RHS, Name, true, false);
}
- Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "") {
+ Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "",
+ MDNode *FPMathTag = 0) {
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
return Insert(Folder.CreateFSub(LC, RC), Name);
- return Insert(BinaryOperator::CreateFSub(LHS, RHS), Name);
+ return Insert(AddFPMathTag(BinaryOperator::CreateFSub(LHS, RHS),
+ FPMathTag), Name);
}
Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
bool HasNUW = false, bool HasNSW = false) {
@@ -551,11 +578,13 @@ public:
Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
return CreateMul(LHS, RHS, Name, true, false);
}
- Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "") {
+ Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "",
+ MDNode *FPMathTag = 0) {
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
return Insert(Folder.CreateFMul(LC, RC), Name);
- return Insert(BinaryOperator::CreateFMul(LHS, RHS), Name);
+ return Insert(AddFPMathTag(BinaryOperator::CreateFMul(LHS, RHS),
+ FPMathTag), Name);
}
Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
bool isExact = false) {
@@ -581,11 +610,13 @@ public:
Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
return CreateSDiv(LHS, RHS, Name, true);
}
- Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
+ Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "",
+ MDNode *FPMathTag = 0) {
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
return Insert(Folder.CreateFDiv(LC, RC), Name);
- return Insert(BinaryOperator::CreateFDiv(LHS, RHS), Name);
+ return Insert(AddFPMathTag(BinaryOperator::CreateFDiv(LHS, RHS),
+ FPMathTag), Name);
}
Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
if (Constant *LC = dyn_cast<Constant>(LHS))
@@ -599,11 +630,13 @@ public:
return Insert(Folder.CreateSRem(LC, RC), Name);
return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
}
- Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "") {
+ Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "",
+ MDNode *FPMathTag = 0) {
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
return Insert(Folder.CreateFRem(LC, RC), Name);
- return Insert(BinaryOperator::CreateFRem(LHS, RHS), Name);
+ return Insert(AddFPMathTag(BinaryOperator::CreateFRem(LHS, RHS),
+ FPMathTag), Name);
}
Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
@@ -729,10 +762,10 @@ public:
Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
return CreateNeg(V, Name, true, false);
}
- Value *CreateFNeg(Value *V, const Twine &Name = "") {
+ Value *CreateFNeg(Value *V, const Twine &Name = "", MDNode *FPMathTag = 0) {
if (Constant *VC = dyn_cast<Constant>(V))
return Insert(Folder.CreateFNeg(VC), Name);
- return Insert(BinaryOperator::CreateFNeg(V), Name);
+ return Insert(AddFPMathTag(BinaryOperator::CreateFNeg(V), FPMathTag), Name);
}
Value *CreateNot(Value *V, const Twine &Name = "") {
if (Constant *VC = dyn_cast<Constant>(V))
diff --git a/include/llvm/Support/InstVisitor.h b/include/llvm/Support/InstVisitor.h
index 2001456..52de8f6 100644
--- a/include/llvm/Support/InstVisitor.h
+++ b/include/llvm/Support/InstVisitor.h
@@ -14,6 +14,7 @@
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
+#include "llvm/Support/CallSite.h"
#include "llvm/Support/ErrorHandling.h"
namespace llvm {
@@ -161,7 +162,6 @@ public:
RetTy visitBranchInst(BranchInst &I) { DELEGATE(TerminatorInst);}
RetTy visitSwitchInst(SwitchInst &I) { DELEGATE(TerminatorInst);}
RetTy visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);}
- RetTy visitInvokeInst(InvokeInst &I) { DELEGATE(TerminatorInst);}
RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
@@ -187,7 +187,6 @@ public:
RetTy visitIntToPtrInst(IntToPtrInst &I) { DELEGATE(CastInst);}
RetTy visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst);}
RetTy visitSelectInst(SelectInst &I) { DELEGATE(Instruction);}
- RetTy visitCallInst(CallInst &I) { DELEGATE(Instruction);}
RetTy visitVAArgInst(VAArgInst &I) { DELEGATE(UnaryInstruction);}
RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
RetTy visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction);}
@@ -196,6 +195,15 @@ public:
RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
+ // Call and Invoke are slightly different as they delegate first through
+ // a generic CallSite visitor.
+ RetTy visitCallInst(CallInst &I) {
+ return static_cast<SubClass*>(this)->visitCallSite(&I);
+ }
+ RetTy visitInvokeInst(InvokeInst &I) {
+ return static_cast<SubClass*>(this)->visitCallSite(&I);
+ }
+
// Next level propagators: If the user does not overload a specific
// instruction type, they can overload one of these to get the whole class
// of instructions...
@@ -206,6 +214,19 @@ public:
RetTy visitTerminatorInst(TerminatorInst &I) { DELEGATE(Instruction);}
RetTy visitUnaryInstruction(UnaryInstruction &I){ DELEGATE(Instruction);}
+ // Provide a special visitor for a 'callsite' that visits both calls and
+ // invokes. When unimplemented, properly delegates to either the terminator or
+ // regular instruction visitor.
+ RetTy visitCallSite(CallSite CS) {
+ assert(CS);
+ Instruction &I = *CS.getInstruction();
+ if (CS.isCall())
+ DELEGATE(Instruction);
+
+ assert(CS.isInvoke());
+ DELEGATE(TerminatorInst);
+ }
+
// If the user wants a 'default' case, they can choose to override this
// function. If this function is not overloaded in the user's subclass, then
// this instruction just gets ignored.
diff --git a/include/llvm/Support/JSONParser.h b/include/llvm/Support/JSONParser.h
deleted file mode 100644
index 11149f1..0000000
--- a/include/llvm/Support/JSONParser.h
+++ /dev/null
@@ -1,448 +0,0 @@
-//===--- JSONParser.h - Simple JSON parser ----------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements a JSON parser.
-//
-// See http://www.json.org/ for an overview.
-// See http://www.ietf.org/rfc/rfc4627.txt for the full standard.
-//
-// FIXME: Currently this supports a subset of JSON. Specifically, support
-// for numbers, booleans and null for values is missing.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_JSON_PARSER_H
-#define LLVM_SUPPORT_JSON_PARSER_H
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Allocator.h"
-#include "llvm/Support/Casting.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/SourceMgr.h"
-
-namespace llvm {
-
-class JSONContainer;
-class JSONString;
-class JSONValue;
-class JSONKeyValuePair;
-
-/// \brief Base class for a parsable JSON atom.
-///
-/// This class has no semantics other than being a unit of JSON data which can
-/// be parsed out of a JSON document.
-class JSONAtom {
-public:
- /// \brief Possible types of JSON objects.
- enum Kind { JK_KeyValuePair, JK_Array, JK_Object, JK_String };
-
- /// \brief Returns the type of this value.
- Kind getKind() const { return MyKind; }
-
- static bool classof(const JSONAtom *Atom) { return true; }
-
-protected:
- JSONAtom(Kind MyKind) : MyKind(MyKind) {}
-
-private:
- Kind MyKind;
-};
-
-/// \brief A parser for JSON text.
-///
-/// Use an object of JSONParser to iterate over the values of a JSON text.
-/// All objects are parsed during the iteration, so you can only iterate once
-/// over the JSON text, but the cost of partial iteration is minimized.
-/// Create a new JSONParser if you want to iterate multiple times.
-class JSONParser {
-public:
- /// \brief Create a JSONParser for the given input.
- ///
- /// Parsing is started via parseRoot(). Access to the object returned from
- /// parseRoot() will parse the input lazily.
- JSONParser(StringRef Input, SourceMgr *SM);
-
- /// \brief Returns the outermost JSON value (either an array or an object).
- ///
- /// Can return NULL if the input does not start with an array or an object.
- /// The object is not parsed yet - the caller must iterate over the
- /// returned object to trigger parsing.
- ///
- /// A JSONValue can be either a JSONString, JSONObject or JSONArray.
- JSONValue *parseRoot();
-
- /// \brief Parses the JSON text and returns whether it is valid JSON.
- ///
- /// In case validate() return false, failed() will return true and
- /// getErrorMessage() will return the parsing error.
- bool validate();
-
- /// \brief Returns true if an error occurs during parsing.
- ///
- /// If there was an error while parsing an object that was created by
- /// iterating over the result of 'parseRoot', 'failed' will return true.
- bool failed() const;
-
-private:
- /// \brief These methods manage the implementation details of parsing new JSON
- /// atoms.
- /// @{
- JSONString *parseString();
- JSONValue *parseValue();
- JSONKeyValuePair *parseKeyValuePair();
- /// @}
-
- /// \brief Helpers to parse the elements out of both forms of containers.
- /// @{
- const JSONAtom *parseElement(JSONAtom::Kind ContainerKind);
- StringRef::iterator parseFirstElement(JSONAtom::Kind ContainerKind,
- char StartChar, char EndChar,
- const JSONAtom *&Element);
- StringRef::iterator parseNextElement(JSONAtom::Kind ContainerKind,
- char EndChar,
- const JSONAtom *&Element);
- /// @}
-
- /// \brief Whitespace parsing.
- /// @{
- void nextNonWhitespace();
- bool isWhitespace();
- /// @}
-
- /// \brief These methods are used for error handling.
- /// {
- void setExpectedError(StringRef Expected, StringRef Found);
- void setExpectedError(StringRef Expected, char Found);
- bool errorIfAtEndOfFile(StringRef Message);
- bool errorIfNotAt(char C, StringRef Message);
- /// }
-
- /// \brief Skips all elements in the given container.
- bool skipContainer(const JSONContainer &Container);
-
- /// \brief Skips to the next position behind the given JSON atom.
- bool skip(const JSONAtom &Atom);
-
- /// All nodes are allocated by the parser and will be deallocated when the
- /// parser is destroyed.
- BumpPtrAllocator ValueAllocator;
-
- /// \brief The original input to the parser.
- MemoryBuffer *InputBuffer;
-
- /// \brief The source manager used for diagnostics and buffer management.
- SourceMgr *SM;
-
- /// \brief The current position in the parse stream.
- StringRef::iterator Position;
-
- /// \brief The end position for fast EOF checks without introducing
- /// unnecessary dereferences.
- StringRef::iterator End;
-
- /// \brief If true, an error has occurred.
- bool Failed;
-
- friend class JSONContainer;
-};
-
-
-/// \brief Base class for JSON value objects.
-///
-/// This object represents an abstract JSON value. It is the root node behind
-/// the group of JSON entities that can represent top-level values in a JSON
-/// document. It has no API, and is just a placeholder in the type hierarchy of
-/// nodes.
-class JSONValue : public JSONAtom {
-protected:
- JSONValue(Kind MyKind) : JSONAtom(MyKind) {}
-
-public:
- /// \brief dyn_cast helpers
- ///@{
- static bool classof(const JSONAtom *Atom) {
- switch (Atom->getKind()) {
- case JK_Array:
- case JK_Object:
- case JK_String:
- return true;
- case JK_KeyValuePair:
- return false;
- }
- llvm_unreachable("Invalid JSONAtom kind");
- }
- static bool classof(const JSONValue *Value) { return true; }
- ///@}
-};
-
-/// \brief Gives access to the text of a JSON string.
-///
-/// FIXME: Implement a method to return the unescaped text.
-class JSONString : public JSONValue {
-public:
- /// \brief Returns the underlying parsed text of the string.
- ///
- /// This is the unescaped content of the JSON text.
- /// See http://www.ietf.org/rfc/rfc4627.txt for details.
- StringRef getRawText() const { return RawText; }
-
-private:
- JSONString(StringRef RawText) : JSONValue(JK_String), RawText(RawText) {}
-
- StringRef RawText;
-
- friend class JSONParser;
-
-public:
- /// \brief dyn_cast helpers
- ///@{
- static bool classof(const JSONAtom *Atom) {
- return Atom->getKind() == JK_String;
- }
- static bool classof(const JSONString *String) { return true; }
- ///@}
-};
-
-/// \brief A (key, value) tuple of type (JSONString *, JSONValue *).
-///
-/// Note that JSONKeyValuePair is not a JSONValue, it is a bare JSONAtom.
-/// JSONKeyValuePairs can be elements of a JSONObject, but not of a JSONArray.
-/// They are not viable as top-level values either.
-class JSONKeyValuePair : public JSONAtom {
-public:
- const JSONString * const Key;
- const JSONValue * const Value;
-
-private:
- JSONKeyValuePair(const JSONString *Key, const JSONValue *Value)
- : JSONAtom(JK_KeyValuePair), Key(Key), Value(Value) {}
-
- friend class JSONParser;
-
-public:
- /// \brief dyn_cast helpers
- ///@{
- static bool classof(const JSONAtom *Atom) {
- return Atom->getKind() == JK_KeyValuePair;
- }
- static bool classof(const JSONKeyValuePair *KeyValuePair) { return true; }
- ///@}
-};
-
-/// \brief Implementation of JSON containers (arrays and objects).
-///
-/// JSONContainers drive the lazy parsing of JSON arrays and objects via
-/// forward iterators.
-class JSONContainer : public JSONValue {
-private:
- /// \brief An iterator that parses the underlying container during iteration.
- ///
- /// Iterators on the same collection use shared state, so when multiple copies
- /// of an iterator exist, only one is allowed to be used for iteration;
- /// iterating multiple copies of an iterator of the same collection will lead
- /// to undefined behavior.
- class AtomIterator {
- public:
- AtomIterator(const AtomIterator &I) : Container(I.Container) {}
-
- /// \brief Iterator interface.
- ///@{
- bool operator==(const AtomIterator &I) const {
- if (isEnd() || I.isEnd())
- return isEnd() == I.isEnd();
- return Container->Position == I.Container->Position;
- }
- bool operator!=(const AtomIterator &I) const {
- return !(*this == I);
- }
- AtomIterator &operator++() {
- Container->parseNextElement();
- return *this;
- }
- const JSONAtom *operator*() {
- return Container->Current;
- }
- ///@}
-
- private:
- /// \brief Create an iterator for which 'isEnd' returns true.
- AtomIterator() : Container(0) {}
-
- /// \brief Create an iterator for the given container.
- AtomIterator(const JSONContainer *Container) : Container(Container) {}
-
- bool isEnd() const {
- return Container == 0 || Container->Position == StringRef::iterator();
- }
-
- const JSONContainer * const Container;
-
- friend class JSONContainer;
- };
-
-protected:
- /// \brief An iterator for the specified AtomT.
- ///
- /// Used for the implementation of iterators for JSONArray and JSONObject.
- template <typename AtomT>
- class IteratorTemplate : public std::iterator<std::forward_iterator_tag,
- const AtomT*> {
- public:
- explicit IteratorTemplate(const AtomIterator& AtomI)
- : AtomI(AtomI) {}
-
- bool operator==(const IteratorTemplate &I) const {
- return AtomI == I.AtomI;
- }
- bool operator!=(const IteratorTemplate &I) const { return !(*this == I); }
-
- IteratorTemplate &operator++() {
- ++AtomI;
- return *this;
- }
-
- const AtomT *operator*() { return dyn_cast<AtomT>(*AtomI); }
-
- private:
- AtomIterator AtomI;
- };
-
- JSONContainer(JSONParser *Parser, char StartChar, char EndChar,
- JSONAtom::Kind ContainerKind)
- : JSONValue(ContainerKind), Parser(Parser),
- Position(), Current(0), Started(false),
- StartChar(StartChar), EndChar(EndChar) {}
-
- /// \brief Returns a lazy parsing iterator over the container.
- ///
- /// As the iterator drives the parse stream, begin() must only be called
- /// once per container.
- AtomIterator atom_begin() const {
- if (Started)
- report_fatal_error("Cannot parse container twice.");
- Started = true;
- // Set up the position and current element when we begin iterating over the
- // container.
- Position = Parser->parseFirstElement(getKind(), StartChar, EndChar, Current);
- return AtomIterator(this);
- }
- AtomIterator atom_end() const {
- return AtomIterator();
- }
-
-private:
- AtomIterator atom_current() const {
- if (!Started)
- return atom_begin();
-
- return AtomIterator(this);
- }
-
- /// \brief Parse the next element in the container into the Current element.
- ///
- /// This routine is called as an iterator into this container walks through
- /// its elements. It mutates the container's internal current node to point to
- /// the next atom of the container.
- void parseNextElement() const {
- Parser->skip(*Current);
- Position = Parser->parseNextElement(getKind(), EndChar, Current);
- }
-
- // For parsing, JSONContainers call back into the JSONParser.
- JSONParser * const Parser;
-
- // 'Position', 'Current' and 'Started' store the state of the parse stream
- // for iterators on the container, they don't change the container's elements
- // and are thus marked as mutable.
- mutable StringRef::iterator Position;
- mutable const JSONAtom *Current;
- mutable bool Started;
-
- const char StartChar;
- const char EndChar;
-
- friend class JSONParser;
-
-public:
- /// \brief dyn_cast helpers
- ///@{
- static bool classof(const JSONAtom *Atom) {
- switch (Atom->getKind()) {
- case JK_Array:
- case JK_Object:
- return true;
- case JK_KeyValuePair:
- case JK_String:
- return false;
- }
- llvm_unreachable("Invalid JSONAtom kind");
- }
- static bool classof(const JSONContainer *Container) { return true; }
- ///@}
-};
-
-/// \brief A simple JSON array.
-class JSONArray : public JSONContainer {
-public:
- typedef IteratorTemplate<JSONValue> const_iterator;
-
- /// \brief Returns a lazy parsing iterator over the container.
- ///
- /// As the iterator drives the parse stream, begin() must only be called
- /// once per container.
- const_iterator begin() const { return const_iterator(atom_begin()); }
- const_iterator end() const { return const_iterator(atom_end()); }
-
-private:
- JSONArray(JSONParser *Parser)
- : JSONContainer(Parser, '[', ']', JSONAtom::JK_Array) {}
-
-public:
- /// \brief dyn_cast helpers
- ///@{
- static bool classof(const JSONAtom *Atom) {
- return Atom->getKind() == JSONAtom::JK_Array;
- }
- static bool classof(const JSONArray *Array) { return true; }
- ///@}
-
- friend class JSONParser;
-};
-
-/// \brief A JSON object: an iterable list of JSON key-value pairs.
-class JSONObject : public JSONContainer {
-public:
- typedef IteratorTemplate<JSONKeyValuePair> const_iterator;
-
- /// \brief Returns a lazy parsing iterator over the container.
- ///
- /// As the iterator drives the parse stream, begin() must only be called
- /// once per container.
- const_iterator begin() const { return const_iterator(atom_begin()); }
- const_iterator end() const { return const_iterator(atom_end()); }
-
-private:
- JSONObject(JSONParser *Parser)
- : JSONContainer(Parser, '{', '}', JSONAtom::JK_Object) {}
-
-public:
- /// \brief dyn_cast helpers
- ///@{
- static bool classof(const JSONAtom *Atom) {
- return Atom->getKind() == JSONAtom::JK_Object;
- }
- static bool classof(const JSONObject *Object) { return true; }
- ///@}
-
- friend class JSONParser;
-};
-
-} // end namespace llvm
-
-#endif // LLVM_SUPPORT_JSON_PARSER_H
diff --git a/include/llvm/Support/Locale.h b/include/llvm/Support/Locale.h
new file mode 100644
index 0000000..b0f1295
--- /dev/null
+++ b/include/llvm/Support/Locale.h
@@ -0,0 +1,17 @@
+#ifndef LLVM_SUPPORT_LOCALE
+#define LLVM_SUPPORT_LOCALE
+
+#include "llvm/ADT/StringRef.h"
+
+namespace llvm {
+namespace sys {
+namespace locale {
+
+int columnWidth(StringRef s);
+bool isPrint(int c);
+
+}
+}
+}
+
+#endif // LLVM_SUPPORT_LOCALE
diff --git a/include/llvm/Support/MDBuilder.h b/include/llvm/Support/MDBuilder.h
new file mode 100644
index 0000000..40f028a
--- /dev/null
+++ b/include/llvm/Support/MDBuilder.h
@@ -0,0 +1,118 @@
+//===---- llvm/Support/MDBuilder.h - Builder for LLVM metadata --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the MDBuilder class, which is used as a convenient way to
+// create LLVM metadata with a consistent and simplified interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_MDBUILDER_H
+#define LLVM_SUPPORT_MDBUILDER_H
+
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
+#include "llvm/Metadata.h"
+#include "llvm/ADT/APInt.h"
+
+namespace llvm {
+
+ class MDBuilder {
+ LLVMContext &Context;
+
+ public:
+ MDBuilder(LLVMContext &context) : Context(context) {}
+
+ /// \brief Return the given string as metadata.
+ MDString *createString(StringRef Str) {
+ return MDString::get(Context, Str);
+ }
+
+ //===------------------------------------------------------------------===//
+ // FPMath metadata.
+ //===------------------------------------------------------------------===//
+
+ /// \brief Return metadata with the given settings. The special value 0.0
+ /// for the Accuracy parameter indicates the default (maximal precision)
+ /// setting.
+ MDNode *createFPMath(float Accuracy) {
+ if (Accuracy == 0.0)
+ return 0;
+ assert(Accuracy > 0.0 && "Invalid fpmath accuracy!");
+ Value *Op = ConstantFP::get(Type::getFloatTy(Context), Accuracy);
+ return MDNode::get(Context, Op);
+ }
+
+
+ //===------------------------------------------------------------------===//
+ // Range metadata.
+ //===------------------------------------------------------------------===//
+
+ /// \brief Return metadata describing the range [Lo, Hi).
+ MDNode *createRange(const APInt &Lo, const APInt &Hi) {
+ assert(Lo.getBitWidth() == Hi.getBitWidth() && "Mismatched bitwidths!");
+ // If the range is everything then it is useless.
+ if (Hi == Lo)
+ return 0;
+
+ // Return the range [Lo, Hi).
+ Type *Ty = IntegerType::get(Context, Lo.getBitWidth());
+ Value *Range[2] = { ConstantInt::get(Ty, Lo), ConstantInt::get(Ty, Hi) };
+ return MDNode::get(Context, Range);
+ }
+
+
+ //===------------------------------------------------------------------===//
+ // TBAA metadata.
+ //===------------------------------------------------------------------===//
+
+ /// \brief Return metadata appropriate for a TBAA root node. Each returned
+ /// node is distinct from all other metadata and will never be identified
+ /// (uniqued) with anything else.
+ MDNode *createAnonymousTBAARoot() {
+ // To ensure uniqueness the root node is self-referential.
+ MDNode *Dummy = MDNode::getTemporary(Context, ArrayRef<Value*>());
+ MDNode *Root = MDNode::get(Context, Dummy);
+ // At this point we have
+ // !0 = metadata !{} <- dummy
+ // !1 = metadata !{metadata !0} <- root
+ // Replace the dummy operand with the root node itself and delete the dummy.
+ Root->replaceOperandWith(0, Root);
+ MDNode::deleteTemporary(Dummy);
+ // We now have
+ // !1 = metadata !{metadata !1} <- self-referential root
+ return Root;
+ }
+
+ /// \brief Return metadata appropriate for a TBAA root node with the given
+ /// name. This may be identified (uniqued) with other roots with the same
+ /// name.
+ MDNode *createTBAARoot(StringRef Name) {
+ return MDNode::get(Context, createString(Name));
+ }
+
+ /// \brief Return metadata for a non-root TBAA node with the given name,
+ /// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
+ MDNode *createTBAANode(StringRef Name, MDNode *Parent,
+ bool isConstant = false) {
+ if (isConstant) {
+ Constant *Flags = ConstantInt::get(Type::getInt64Ty(Context), 1);
+ Value *Ops[3] = { createString(Name), Parent, Flags };
+ return MDNode::get(Context, Ops);
+ } else {
+ Value *Ops[2] = { createString(Name), Parent };
+ return MDNode::get(Context, Ops);
+ }
+ }
+
+ };
+
+} // end namespace llvm
+
+#endif
diff --git a/include/llvm/Support/Process.h b/include/llvm/Support/Process.h
index 3379922..d796b79 100644
--- a/include/llvm/Support/Process.h
+++ b/include/llvm/Support/Process.h
@@ -136,6 +136,10 @@ namespace sys {
/// Same as OutputColor, but only enables the bold attribute.
static const char *OutputBold(bool bg);
+ /// This function returns the escape sequence to reverse forground and
+ /// background colors.
+ static const char *OutputReverse();
+
/// Resets the terminals colors, or returns an escape sequence to do so.
static const char *ResetColor();
/// @}
diff --git a/include/llvm/Support/SourceMgr.h b/include/llvm/Support/SourceMgr.h
index 58b8fab..76967db 100644
--- a/include/llvm/Support/SourceMgr.h
+++ b/include/llvm/Support/SourceMgr.h
@@ -128,8 +128,11 @@ public:
/// PrintMessage - Emit a message about the specified location with the
/// specified string.
///
+ /// @param ShowColors - Display colored messages if output is a terminal and
+ /// the default error handler is used.
void PrintMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg,
- ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) const;
+ ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
+ bool ShowColors = true) const;
/// GetMessage - Return an SMDiagnostic at the specified location with the
@@ -188,7 +191,7 @@ public:
const std::vector<std::pair<unsigned, unsigned> > &getRanges() const {
return Ranges;
}
- void print(const char *ProgName, raw_ostream &S) const;
+ void print(const char *ProgName, raw_ostream &S, bool ShowColors = true) const;
};
} // end llvm namespace
diff --git a/include/llvm/Support/TargetRegistry.h b/include/llvm/Support/TargetRegistry.h
index 93bdbca..8808130 100644
--- a/include/llvm/Support/TargetRegistry.h
+++ b/include/llvm/Support/TargetRegistry.h
@@ -104,6 +104,7 @@ namespace llvm {
typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
unsigned SyntaxVariant,
const MCAsmInfo &MAI,
+ const MCInstrInfo &MII,
const MCRegisterInfo &MRI,
const MCSubtargetInfo &STI);
typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
@@ -393,11 +394,12 @@ namespace llvm {
MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
const MCAsmInfo &MAI,
+ const MCInstrInfo &MII,
const MCRegisterInfo &MRI,
const MCSubtargetInfo &STI) const {
if (!MCInstPrinterCtorFn)
return 0;
- return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MRI, STI);
+ return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
}
diff --git a/include/llvm/Support/TargetSelect.h b/include/llvm/Support/TargetSelect.h
index 83ff68c..a86e953 100644
--- a/include/llvm/Support/TargetSelect.h
+++ b/include/llvm/Support/TargetSelect.h
@@ -149,6 +149,18 @@ namespace llvm {
#endif
}
+ /// InitializeNativeTargetDisassembler - The main program should call
+ /// this function to initialize the native target disassembler.
+ inline bool InitializeNativeTargetDisassembler() {
+ // If we have a native target, initialize the corresponding disassembler.
+#ifdef LLVM_NATIVE_DISASSEMBLER
+ LLVM_NATIVE_DISASSEMBLER();
+ return false;
+#else
+ return true;
+#endif
+ }
+
}
#endif
diff --git a/include/llvm/Support/ValueHandle.h b/include/llvm/Support/ValueHandle.h
index c0cdc35..b7210b2 100644
--- a/include/llvm/Support/ValueHandle.h
+++ b/include/llvm/Support/ValueHandle.h
@@ -49,52 +49,61 @@ protected:
Tracking,
Weak
};
-private:
+private:
PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
ValueHandleBase *Next;
- Value *VP;
+
+ // A subclass may want to store some information along with the value
+ // pointer. Allow them to do this by making the value pointer a pointer-int
+ // pair. The 'setValPtrInt' and 'getValPtrInt' methods below give them this
+ // access.
+ PointerIntPair<Value*, 2> VP;
explicit ValueHandleBase(const ValueHandleBase&); // DO NOT IMPLEMENT.
public:
explicit ValueHandleBase(HandleBaseKind Kind)
- : PrevPair(0, Kind), Next(0), VP(0) {}
+ : PrevPair(0, Kind), Next(0), VP(0, 0) {}
ValueHandleBase(HandleBaseKind Kind, Value *V)
- : PrevPair(0, Kind), Next(0), VP(V) {
- if (isValid(VP))
+ : PrevPair(0, Kind), Next(0), VP(V, 0) {
+ if (isValid(VP.getPointer()))
AddToUseList();
}
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
: PrevPair(0, Kind), Next(0), VP(RHS.VP) {
- if (isValid(VP))
+ if (isValid(VP.getPointer()))
AddToExistingUseList(RHS.getPrevPtr());
}
~ValueHandleBase() {
- if (isValid(VP))
+ if (isValid(VP.getPointer()))
RemoveFromUseList();
}
Value *operator=(Value *RHS) {
- if (VP == RHS) return RHS;
- if (isValid(VP)) RemoveFromUseList();
- VP = RHS;
- if (isValid(VP)) AddToUseList();
+ if (VP.getPointer() == RHS) return RHS;
+ if (isValid(VP.getPointer())) RemoveFromUseList();
+ VP.setPointer(RHS);
+ if (isValid(VP.getPointer())) AddToUseList();
return RHS;
}
Value *operator=(const ValueHandleBase &RHS) {
- if (VP == RHS.VP) return RHS.VP;
- if (isValid(VP)) RemoveFromUseList();
- VP = RHS.VP;
- if (isValid(VP)) AddToExistingUseList(RHS.getPrevPtr());
- return VP;
+ if (VP.getPointer() == RHS.VP.getPointer()) return RHS.VP.getPointer();
+ if (isValid(VP.getPointer())) RemoveFromUseList();
+ VP.setPointer(RHS.VP.getPointer());
+ if (isValid(VP.getPointer())) AddToExistingUseList(RHS.getPrevPtr());
+ return VP.getPointer();
}
Value *operator->() const { return getValPtr(); }
Value &operator*() const { return *getValPtr(); }
protected:
- Value *getValPtr() const { return VP; }
+ Value *getValPtr() const { return VP.getPointer(); }
+
+ void setValPtrInt(unsigned K) { VP.setInt(K); }
+ unsigned getValPtrInt() const { return VP.getInt(); }
+
static bool isValid(Value *V) {
return V &&
V != DenseMapInfo<Value *>::getEmptyKey() &&
diff --git a/include/llvm/Support/YAMLParser.h b/include/llvm/Support/YAMLParser.h
new file mode 100644
index 0000000..47206b3
--- /dev/null
+++ b/include/llvm/Support/YAMLParser.h
@@ -0,0 +1,552 @@
+//===--- YAMLParser.h - Simple YAML parser --------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a YAML 1.2 parser.
+//
+// See http://www.yaml.org/spec/1.2/spec.html for the full standard.
+//
+// This currently does not implement the following:
+// * Multi-line literal folding.
+// * Tag resolution.
+// * UTF-16.
+// * BOMs anywhere other than the first Unicode scalar value in the file.
+//
+// The most important class here is Stream. This represents a YAML stream with
+// 0, 1, or many documents.
+//
+// SourceMgr sm;
+// StringRef input = getInput();
+// yaml::Stream stream(input, sm);
+//
+// for (yaml::document_iterator di = stream.begin(), de = stream.end();
+// di != de; ++di) {
+// yaml::Node *n = di->getRoot();
+// if (n) {
+// // Do something with n...
+// } else
+// break;
+// }
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_YAML_PARSER_H
+#define LLVM_SUPPORT_YAML_PARSER_H
+
+#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/SMLoc.h"
+
+#include <limits>
+#include <utility>
+
+namespace llvm {
+class MemoryBuffer;
+class SourceMgr;
+class raw_ostream;
+class Twine;
+
+namespace yaml {
+
+class document_iterator;
+class Document;
+class Node;
+class Scanner;
+struct Token;
+
+/// @brief Dump all the tokens in this stream to OS.
+/// @returns true if there was an error, false otherwise.
+bool dumpTokens(StringRef Input, raw_ostream &);
+
+/// @brief Scans all tokens in input without outputting anything. This is used
+/// for benchmarking the tokenizer.
+/// @returns true if there was an error, false otherwise.
+bool scanTokens(StringRef Input);
+
+/// @brief Escape \a Input for a double quoted scalar.
+std::string escape(StringRef Input);
+
+/// @brief This class represents a YAML stream potentially containing multiple
+/// documents.
+class Stream {
+public:
+ Stream(StringRef Input, SourceMgr &);
+ ~Stream();
+
+ document_iterator begin();
+ document_iterator end();
+ void skip();
+ bool failed();
+ bool validate() {
+ skip();
+ return !failed();
+ }
+
+ void printError(Node *N, const Twine &Msg);
+
+private:
+ OwningPtr<Scanner> scanner;
+ OwningPtr<Document> CurrentDoc;
+
+ friend class Document;
+
+ /// @brief Validate a %YAML x.x directive.
+ void handleYAMLDirective(const Token &);
+};
+
+/// @brief Abstract base class for all Nodes.
+class Node {
+public:
+ enum NodeKind {
+ NK_Null,
+ NK_Scalar,
+ NK_KeyValue,
+ NK_Mapping,
+ NK_Sequence,
+ NK_Alias
+ };
+
+ Node(unsigned int Type, OwningPtr<Document>&, StringRef Anchor);
+
+ /// @brief Get the value of the anchor attached to this node. If it does not
+ /// have one, getAnchor().size() will be 0.
+ StringRef getAnchor() const { return Anchor; }
+
+ SMRange getSourceRange() const { return SourceRange; }
+ void setSourceRange(SMRange SR) { SourceRange = SR; }
+
+ // These functions forward to Document and Scanner.
+ Token &peekNext();
+ Token getNext();
+ Node *parseBlockNode();
+ BumpPtrAllocator &getAllocator();
+ void setError(const Twine &Message, Token &Location) const;
+ bool failed() const;
+
+ virtual void skip() {};
+
+ unsigned int getType() const { return TypeID; }
+ static inline bool classof(const Node *) { return true; }
+
+ void *operator new ( size_t Size
+ , BumpPtrAllocator &Alloc
+ , size_t Alignment = 16) throw() {
+ return Alloc.Allocate(Size, Alignment);
+ }
+
+ void operator delete(void *Ptr, BumpPtrAllocator &Alloc, size_t) throw() {
+ Alloc.Deallocate(Ptr);
+ }
+
+protected:
+ OwningPtr<Document> &Doc;
+ SMRange SourceRange;
+
+ void operator delete(void *) throw() {}
+
+ virtual ~Node() {}
+
+private:
+ unsigned int TypeID;
+ StringRef Anchor;
+};
+
+/// @brief A null value.
+///
+/// Example:
+/// !!null null
+class NullNode : public Node {
+public:
+ NullNode(OwningPtr<Document> &D) : Node(NK_Null, D, StringRef()) {}
+
+ static inline bool classof(const NullNode *) { return true; }
+ static inline bool classof(const Node *N) {
+ return N->getType() == NK_Null;
+ }
+};
+
+/// @brief A scalar node is an opaque datum that can be presented as a
+/// series of zero or more Unicode scalar values.
+///
+/// Example:
+/// Adena
+class ScalarNode : public Node {
+public:
+ ScalarNode(OwningPtr<Document> &D, StringRef Anchor, StringRef Val)
+ : Node(NK_Scalar, D, Anchor)
+ , Value(Val) {
+ SMLoc Start = SMLoc::getFromPointer(Val.begin());
+ SMLoc End = SMLoc::getFromPointer(Val.end() - 1);
+ SourceRange = SMRange(Start, End);
+ }
+
+ // Return Value without any escaping or folding or other fun YAML stuff. This
+ // is the exact bytes that are contained in the file (after conversion to
+ // utf8).
+ StringRef getRawValue() const { return Value; }
+
+ /// @brief Gets the value of this node as a StringRef.
+ ///
+ /// @param Storage is used to store the content of the returned StringRef iff
+ /// it requires any modification from how it appeared in the source.
+ /// This happens with escaped characters and multi-line literals.
+ StringRef getValue(SmallVectorImpl<char> &Storage) const;
+
+ static inline bool classof(const ScalarNode *) { return true; }
+ static inline bool classof(const Node *N) {
+ return N->getType() == NK_Scalar;
+ }
+
+private:
+ StringRef Value;
+
+ StringRef unescapeDoubleQuoted( StringRef UnquotedValue
+ , StringRef::size_type Start
+ , SmallVectorImpl<char> &Storage) const;
+};
+
+/// @brief A key and value pair. While not technically a Node under the YAML
+/// representation graph, it is easier to treat them this way.
+///
+/// TODO: Consider making this not a child of Node.
+///
+/// Example:
+/// Section: .text
+class KeyValueNode : public Node {
+public:
+ KeyValueNode(OwningPtr<Document> &D)
+ : Node(NK_KeyValue, D, StringRef())
+ , Key(0)
+ , Value(0)
+ {}
+
+ /// @brief Parse and return the key.
+ ///
+ /// This may be called multiple times.
+ ///
+ /// @returns The key, or nullptr if failed() == true.
+ Node *getKey();
+
+ /// @brief Parse and return the value.
+ ///
+ /// This may be called multiple times.
+ ///
+ /// @returns The value, or nullptr if failed() == true.
+ Node *getValue();
+
+ virtual void skip() {
+ getKey()->skip();
+ getValue()->skip();
+ }
+
+ static inline bool classof(const KeyValueNode *) { return true; }
+ static inline bool classof(const Node *N) {
+ return N->getType() == NK_KeyValue;
+ }
+
+private:
+ Node *Key;
+ Node *Value;
+};
+
+/// @brief This is an iterator abstraction over YAML collections shared by both
+/// sequences and maps.
+///
+/// BaseT must have a ValueT* member named CurrentEntry and a member function
+/// increment() which must set CurrentEntry to 0 to create an end iterator.
+template <class BaseT, class ValueT>
+class basic_collection_iterator
+ : public std::iterator<std::forward_iterator_tag, ValueT> {
+public:
+ basic_collection_iterator() : Base(0) {}
+ basic_collection_iterator(BaseT *B) : Base(B) {}
+
+ ValueT *operator ->() const {
+ assert(Base && Base->CurrentEntry && "Attempted to access end iterator!");
+ return Base->CurrentEntry;
+ }
+
+ ValueT &operator *() const {
+ assert(Base && Base->CurrentEntry &&
+ "Attempted to dereference end iterator!");
+ return *Base->CurrentEntry;
+ }
+
+ operator ValueT*() const {
+ assert(Base && Base->CurrentEntry && "Attempted to access end iterator!");
+ return Base->CurrentEntry;
+ }
+
+ bool operator !=(const basic_collection_iterator &Other) const {
+ if(Base != Other.Base)
+ return true;
+ return (Base && Other.Base) && Base->CurrentEntry
+ != Other.Base->CurrentEntry;
+ }
+
+ basic_collection_iterator &operator++() {
+ assert(Base && "Attempted to advance iterator past end!");
+ Base->increment();
+ // Create an end iterator.
+ if (Base->CurrentEntry == 0)
+ Base = 0;
+ return *this;
+ }
+
+private:
+ BaseT *Base;
+};
+
+// The following two templates are used for both MappingNode and Sequence Node.
+template <class CollectionType>
+typename CollectionType::iterator begin(CollectionType &C) {
+ assert(C.IsAtBeginning && "You may only iterate over a collection once!");
+ C.IsAtBeginning = false;
+ typename CollectionType::iterator ret(&C);
+ ++ret;
+ return ret;
+}
+
+template <class CollectionType>
+void skip(CollectionType &C) {
+ // TODO: support skipping from the middle of a parsed collection ;/
+ assert((C.IsAtBeginning || C.IsAtEnd) && "Cannot skip mid parse!");
+ if (C.IsAtBeginning)
+ for (typename CollectionType::iterator i = begin(C), e = C.end();
+ i != e; ++i)
+ i->skip();
+}
+
+/// @brief Represents a YAML map created from either a block map for a flow map.
+///
+/// This parses the YAML stream as increment() is called.
+///
+/// Example:
+/// Name: _main
+/// Scope: Global
+class MappingNode : public Node {
+public:
+ enum MappingType {
+ MT_Block,
+ MT_Flow,
+ MT_Inline //< An inline mapping node is used for "[key: value]".
+ };
+
+ MappingNode(OwningPtr<Document> &D, StringRef Anchor, MappingType MT)
+ : Node(NK_Mapping, D, Anchor)
+ , Type(MT)
+ , IsAtBeginning(true)
+ , IsAtEnd(false)
+ , CurrentEntry(0)
+ {}
+
+ friend class basic_collection_iterator<MappingNode, KeyValueNode>;
+ typedef basic_collection_iterator<MappingNode, KeyValueNode> iterator;
+ template <class T> friend typename T::iterator yaml::begin(T &);
+ template <class T> friend void yaml::skip(T &);
+
+ iterator begin() {
+ return yaml::begin(*this);
+ }
+
+ iterator end() { return iterator(); }
+
+ virtual void skip() {
+ yaml::skip(*this);
+ }
+
+ static inline bool classof(const MappingNode *) { return true; }
+ static inline bool classof(const Node *N) {
+ return N->getType() == NK_Mapping;
+ }
+
+private:
+ MappingType Type;
+ bool IsAtBeginning;
+ bool IsAtEnd;
+ KeyValueNode *CurrentEntry;
+
+ void increment();
+};
+
+/// @brief Represents a YAML sequence created from either a block sequence for a
+/// flow sequence.
+///
+/// This parses the YAML stream as increment() is called.
+///
+/// Example:
+/// - Hello
+/// - World
+class SequenceNode : public Node {
+public:
+ enum SequenceType {
+ ST_Block,
+ ST_Flow,
+ // Use for:
+ //
+ // key:
+ // - val1
+ // - val2
+ //
+ // As a BlockMappingEntry and BlockEnd are not created in this case.
+ ST_Indentless
+ };
+
+ SequenceNode(OwningPtr<Document> &D, StringRef Anchor, SequenceType ST)
+ : Node(NK_Sequence, D, Anchor)
+ , SeqType(ST)
+ , IsAtBeginning(true)
+ , IsAtEnd(false)
+ , WasPreviousTokenFlowEntry(true) // Start with an imaginary ','.
+ , CurrentEntry(0)
+ {}
+
+ friend class basic_collection_iterator<SequenceNode, Node>;
+ typedef basic_collection_iterator<SequenceNode, Node> iterator;
+ template <class T> friend typename T::iterator yaml::begin(T &);
+ template <class T> friend void yaml::skip(T &);
+
+ void increment();
+
+ iterator begin() {
+ return yaml::begin(*this);
+ }
+
+ iterator end() { return iterator(); }
+
+ virtual void skip() {
+ yaml::skip(*this);
+ }
+
+ static inline bool classof(const SequenceNode *) { return true; }
+ static inline bool classof(const Node *N) {
+ return N->getType() == NK_Sequence;
+ }
+
+private:
+ SequenceType SeqType;
+ bool IsAtBeginning;
+ bool IsAtEnd;
+ bool WasPreviousTokenFlowEntry;
+ Node *CurrentEntry;
+};
+
+/// @brief Represents an alias to a Node with an anchor.
+///
+/// Example:
+/// *AnchorName
+class AliasNode : public Node {
+public:
+ AliasNode(OwningPtr<Document> &D, StringRef Val)
+ : Node(NK_Alias, D, StringRef()), Name(Val) {}
+
+ StringRef getName() const { return Name; }
+ Node *getTarget();
+
+ static inline bool classof(const ScalarNode *) { return true; }
+ static inline bool classof(const Node *N) {
+ return N->getType() == NK_Alias;
+ }
+
+private:
+ StringRef Name;
+};
+
+/// @brief A YAML Stream is a sequence of Documents. A document contains a root
+/// node.
+class Document {
+public:
+ /// @brief Root for parsing a node. Returns a single node.
+ Node *parseBlockNode();
+
+ Document(Stream &ParentStream);
+
+ /// @brief Finish parsing the current document and return true if there are
+ /// more. Return false otherwise.
+ bool skip();
+
+ /// @brief Parse and return the root level node.
+ Node *getRoot() {
+ if (Root)
+ return Root;
+ return Root = parseBlockNode();
+ }
+
+private:
+ friend class Node;
+ friend class document_iterator;
+
+ /// @brief Stream to read tokens from.
+ Stream &stream;
+
+ /// @brief Used to allocate nodes to. All are destroyed without calling their
+ /// destructor when the document is destroyed.
+ BumpPtrAllocator NodeAllocator;
+
+ /// @brief The root node. Used to support skipping a partially parsed
+ /// document.
+ Node *Root;
+
+ Token &peekNext();
+ Token getNext();
+ void setError(const Twine &Message, Token &Location) const;
+ bool failed() const;
+
+ void handleTagDirective(const Token &Tag) {
+ // TODO: Track tags.
+ }
+
+ /// @brief Parse %BLAH directives and return true if any were encountered.
+ bool parseDirectives();
+
+ /// @brief Consume the next token and error if it is not \a TK.
+ bool expectToken(int TK);
+};
+
+/// @brief Iterator abstraction for Documents over a Stream.
+class document_iterator {
+public:
+ document_iterator() : Doc(NullDoc) {}
+ document_iterator(OwningPtr<Document> &D) : Doc(D) {}
+
+ bool operator ==(const document_iterator &Other) {
+ return Doc == Other.Doc;
+ }
+ bool operator !=(const document_iterator &Other) {
+ return !(*this == Other);
+ }
+
+ document_iterator operator ++() {
+ if (!Doc->skip()) {
+ Doc.reset(0);
+ } else {
+ Stream &S = Doc->stream;
+ Doc.reset(new Document(S));
+ }
+ return *this;
+ }
+
+ Document &operator *() {
+ return *Doc;
+ }
+
+ OwningPtr<Document> &operator ->() {
+ return Doc;
+ }
+
+private:
+ static OwningPtr<Document> NullDoc;
+ OwningPtr<Document> &Doc;
+};
+
+}
+}
+
+#endif
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h
index 6bfae5e..6c5d478 100644
--- a/include/llvm/Support/raw_ostream.h
+++ b/include/llvm/Support/raw_ostream.h
@@ -222,6 +222,9 @@ public:
/// outputting colored text, or before program exit.
virtual raw_ostream &resetColor() { return *this; }
+ /// Reverses the forground and background colors.
+ virtual raw_ostream &reverseColor() { return *this; }
+
/// This function determines if this stream is connected to a "tty" or
/// "console" window. That is, the output would be displayed to the user
/// rather than being put on a pipe or stored in a file.
@@ -379,6 +382,8 @@ public:
bool bg=false);
virtual raw_ostream &resetColor();
+ virtual raw_ostream &reverseColor();
+
virtual bool is_displayed() const;
/// has_error - Return the value of the flag in this raw_fd_ostream indicating
diff --git a/include/llvm/Support/type_traits.h b/include/llvm/Support/type_traits.h
index 0cb8e97..a3a551f 100644
--- a/include/llvm/Support/type_traits.h
+++ b/include/llvm/Support/type_traits.h
@@ -66,7 +66,7 @@ struct isPodLike {
// std::pair's are pod-like if their elements are.
template<typename T, typename U>
struct isPodLike<std::pair<T, U> > {
- static const bool value = isPodLike<T>::value & isPodLike<U>::value;
+ static const bool value = isPodLike<T>::value && isPodLike<U>::value;
};