MIR Parser: Use correct source locations for machine instruction diagnostics.

This commit translates the source locations for MIParser diagnostics from
the locations in the machine instruction string to the locations in the
MIR file.

Reviewers: Duncan P. N. Exon Smith

Differential Revision: http://reviews.llvm.org/D10574


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240474 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz
2015-06-23 22:39:23 +00:00
parent d621812aac
commit 926d65d4f7
8 changed files with 67 additions and 10 deletions

View File

@@ -22,7 +22,43 @@
#include "llvm/Support/YAMLTraits.h"
#include <vector>
LLVM_YAML_IS_SEQUENCE_VECTOR(std::string)
namespace llvm {
namespace yaml {
/// A wrapper around std::string which contains a source range that's being
/// set during parsing.
struct StringValue {
std::string Value;
SMRange SourceRange;
StringValue() {}
StringValue(std::string Value) : Value(std::move(Value)) {}
bool operator==(const StringValue &Other) const {
return Value == Other.Value;
}
};
template <> struct ScalarTraits<StringValue> {
static void output(const StringValue &S, void *, llvm::raw_ostream &OS) {
OS << S.Value;
}
static StringRef input(StringRef Scalar, void *Ctx, StringValue &S) {
S.Value = Scalar.str();
if (const auto *Node =
reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
S.SourceRange = Node->getSourceRange();
return "";
}
static bool mustQuote(StringRef Scalar) { return needsQuotes(Scalar); }
};
} // end namespace yaml
} // end namespace llvm
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::StringValue)
namespace llvm {
namespace yaml {
@@ -34,7 +70,7 @@ struct MachineBasicBlock {
bool AddressTaken = false;
// TODO: Serialize the successors and liveins.
std::vector<std::string> Instructions;
std::vector<StringValue> Instructions;
};
template <> struct MappingTraits<MachineBasicBlock> {