diff options
Diffstat (limited to 'include/llvm/Support')
-rw-r--r-- | include/llvm/Support/IRBuilder.h | 87 | ||||
-rw-r--r-- | include/llvm/Support/JSONParser.h | 448 | ||||
-rw-r--r-- | include/llvm/Support/Locale.h | 17 | ||||
-rw-r--r-- | include/llvm/Support/MDBuilder.h | 118 | ||||
-rw-r--r-- | include/llvm/Support/Process.h | 4 | ||||
-rw-r--r-- | include/llvm/Support/SourceMgr.h | 7 | ||||
-rw-r--r-- | include/llvm/Support/YAMLParser.h | 5 | ||||
-rw-r--r-- | include/llvm/Support/raw_ostream.h | 5 |
8 files changed, 213 insertions, 478 deletions
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/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/YAMLParser.h b/include/llvm/Support/YAMLParser.h index b24cacd..47206b3 100644 --- a/include/llvm/Support/YAMLParser.h +++ b/include/llvm/Support/YAMLParser.h @@ -516,8 +516,11 @@ 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 Doc != Other.Doc; + return !(*this == Other); } document_iterator operator ++() { 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 |