summaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/APInt.cpp6
-rw-r--r--lib/Support/Annotation.cpp2
-rw-r--r--lib/Support/SourceMgr.cpp86
-rw-r--r--lib/Support/SystemUtils.cpp16
-rw-r--r--lib/Support/Triple.cpp3
5 files changed, 88 insertions, 25 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index 73bf774..30dc352 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -2178,6 +2178,12 @@ void APInt::print(raw_ostream &OS, bool isSigned) const {
OS << S.c_str();
}
+std::ostream &llvm::operator<<(std::ostream &o, const APInt &I) {
+ raw_os_ostream OS(o);
+ OS << I;
+ return o;
+}
+
// This implements a variety of operations on a representation of
// arbitrary precision, two's-complement, bignum integer values.
diff --git a/lib/Support/Annotation.cpp b/lib/Support/Annotation.cpp
index b778043..4b5b97e 100644
--- a/lib/Support/Annotation.cpp
+++ b/lib/Support/Annotation.cpp
@@ -39,7 +39,7 @@ namespace {
}
typedef std::map<const char*, unsigned, StrCmp> IDMapType;
-static unsigned IDCounter = 0; // Unique ID counter
+static volatile sys::cas_flag IDCounter = 0; // Unique ID counter
// Static member to ensure initialiation on demand.
static ManagedStatic<IDMapType> IDMap;
diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp
index d789f10..6b0d55c1 100644
--- a/lib/Support/SourceMgr.cpp
+++ b/lib/Support/SourceMgr.cpp
@@ -76,38 +76,36 @@ unsigned SourceMgr::FindLineNumber(SMLoc Loc, int BufferID) const {
return LineNo;
}
-void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc) const {
+void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
if (IncludeLoc == SMLoc()) return; // Top of stack.
int CurBuf = FindBufferContainingLoc(IncludeLoc);
assert(CurBuf != -1 && "Invalid or unspecified location!");
- PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc);
+ PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
- errs() << "Included from "
- << getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
- << ":" << FindLineNumber(IncludeLoc, CurBuf) << ":\n";
+ OS << "Included from "
+ << getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
+ << ":" << FindLineNumber(IncludeLoc, CurBuf) << ":\n";
}
-void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg) const {
- raw_ostream &OS = errs();
+/// GetMessage - Return an SMDiagnostic at the specified location with the
+/// specified string.
+///
+/// @param Type - If non-null, the kind of message (e.g., "error") which is
+/// prefixed to the message.
+SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const std::string &Msg,
+ const char *Type) const {
// First thing to do: find the current buffer containing the specified
// location.
int CurBuf = FindBufferContainingLoc(Loc);
assert(CurBuf != -1 && "Invalid or unspecified location!");
- PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc);
-
MemoryBuffer *CurMB = getBufferInfo(CurBuf).Buffer;
- OS << "Parsing " << CurMB->getBufferIdentifier() << ":"
- << FindLineNumber(Loc, CurBuf) << ": ";
-
- OS << Msg << "\n";
-
// Scan backward to find the start of the line.
const char *LineStart = Loc.getPointer();
while (LineStart != CurMB->getBufferStart() &&
@@ -118,10 +116,60 @@ void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg) const {
while (LineEnd != CurMB->getBufferEnd() &&
LineEnd[0] != '\n' && LineEnd[0] != '\r')
++LineEnd;
+
+ std::string PrintedMsg;
+ if (Type) {
+ PrintedMsg = Type;
+ PrintedMsg += ": ";
+ }
+ PrintedMsg += Msg;
+
// Print out the line.
- OS << std::string(LineStart, LineEnd) << "\n";
- // Print out spaces before the caret.
- for (const char *Pos = LineStart; Pos != Loc.getPointer(); ++Pos)
- OS << (*Pos == '\t' ? '\t' : ' ');
- OS << "^\n";
+ return SMDiagnostic(CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
+ Loc.getPointer()-LineStart, PrintedMsg,
+ std::string(LineStart, LineEnd));
+}
+
+void SourceMgr::PrintMessage(SMLoc Loc, const std::string &Msg,
+ const char *Type) const {
+ raw_ostream &OS = errs();
+
+ int CurBuf = FindBufferContainingLoc(Loc);
+ assert(CurBuf != -1 && "Invalid or unspecified location!");
+ PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
+
+ GetMessage(Loc, Msg, Type).Print(0, OS);
}
+
+//===----------------------------------------------------------------------===//
+// SMDiagnostic Implementation
+//===----------------------------------------------------------------------===//
+
+void SMDiagnostic::Print(const char *ProgName, raw_ostream &S) {
+ if (ProgName && ProgName[0])
+ S << ProgName << ": ";
+
+ if (Filename == "-")
+ S << "<stdin>";
+ else
+ S << Filename;
+
+ if (LineNo != -1) {
+ S << ':' << LineNo;
+ if (ColumnNo != -1)
+ S << ':' << (ColumnNo+1);
+ }
+
+ S << ": " << Message << '\n';
+
+ if (LineNo != -1 && ColumnNo != -1) {
+ S << LineContents << '\n';
+
+ // Print out spaces/tabs before the caret.
+ for (unsigned i = 0; i != unsigned(ColumnNo); ++i)
+ S << (LineContents[i] == '\t' ? '\t' : ' ');
+ S << "^\n";
+ }
+}
+
+
diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp
index 80d6e4c..c8c3238 100644
--- a/lib/Support/SystemUtils.cpp
+++ b/lib/Support/SystemUtils.cpp
@@ -38,15 +38,21 @@ bool llvm::CheckBitcodeOutputToConsole(std::ostream* stream_to_check,
/// being executed. This allows us to find another LLVM tool if it is built
/// into the same directory, but that directory is neither the current
/// directory, nor in the PATH. If the executable cannot be found, return an
-/// empty string.
+/// empty string. Return the input string if given a full path to an executable.
///
#undef FindExecutable // needed on windows :(
sys::Path llvm::FindExecutable(const std::string &ExeName,
const std::string &ProgramPath) {
- // First check the directory that the calling program is in. We can do this
- // if ProgramPath contains at least one / character, indicating that it is a
- // relative path to bugpoint itself.
- sys::Path Result ( ProgramPath );
+ // First check if the given name is already a valid path to an executable.
+ sys::Path Result(ExeName);
+ Result.makeAbsolute();
+ if (Result.canExecute())
+ return Result;
+
+ // Otherwise check the directory that the calling program is in. We can do
+ // this if ProgramPath contains at least one / character, indicating that it
+ // is a relative path to bugpoint itself.
+ Result = ProgramPath;
Result.eraseComponent();
if (!Result.isEmpty()) {
Result.appendComponent(ExeName);
diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp
index dd5c3d6..279bd43 100644
--- a/lib/Support/Triple.cpp
+++ b/lib/Support/Triple.cpp
@@ -48,6 +48,7 @@ const char *Triple::getOSTypeName(OSType Kind) {
case DragonFly: return "dragonfly";
case FreeBSD: return "freebsd";
case Linux: return "linux";
+ case OpenBSD: return "openbsd";
}
return "<invalid>";
@@ -90,6 +91,8 @@ void Triple::Parse() const {
OS = FreeBSD;
else if (memcmp(&OSName[0], "linux", 5) == 0)
OS = Linux;
+ else if (memcmp(&OSName[0], "openbsd", 7) == 0)
+ OS = OpenBSD;
else
OS = UnknownOS;
OpenPOWER on IntegriCloud