llvm.org GIT mirror llvm / 31512fe
MIR Parser: Use source locations for MBB naming errors. This commit changes the type of the field 'Name' in the struct 'yaml::MachineBasicBlock' from 'std::string' to 'yaml::StringValue'. This change allows the MIR parser to report errors related to the MBB name with the proper source locations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241718 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Lorenz 5 years ago
4 changed file(s) with 23 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
8282
8383 struct MachineBasicBlock {
8484 unsigned ID;
85 std::string Name;
85 StringValue Name;
8686 unsigned Alignment = 0;
8787 bool IsLandingPad = false;
8888 bool AddressTaken = false;
9696 static void mapping(IO &YamlIO, MachineBasicBlock &MBB) {
9797 YamlIO.mapRequired("id", MBB.ID);
9898 YamlIO.mapOptional("name", MBB.Name,
99 std::string()); // Don't print out an empty name.
99 StringValue()); // Don't print out an empty name.
100100 YamlIO.mapOptional("alignment", MBB.Alignment);
101101 YamlIO.mapOptional("isLandingPad", MBB.IsLandingPad);
102102 YamlIO.mapOptional("addressTaken", MBB.AddressTaken);
5959 /// Always returns true.
6060 bool error(const Twine &Message);
6161
62 /// Report an error with the given message at the given location.
63 ///
64 /// Always returns true.
65 bool error(SMLoc Loc, const Twine &Message);
66
6267 /// Report a given error with the location translated from the location in an
6368 /// embedded string literal to a location in the MIR file.
6469 ///
120125 bool MIRParserImpl::error(const Twine &Message) {
121126 Context.diagnose(DiagnosticInfoMIRParser(
122127 DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
128 return true;
129 }
130
131 bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
132 Context.diagnose(DiagnosticInfoMIRParser(
133 DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
123134 return true;
124135 }
125136
238249 const auto &F = *MF.getFunction();
239250 for (const auto &YamlMBB : YamlMF.BasicBlocks) {
240251 const BasicBlock *BB = nullptr;
241 if (!YamlMBB.Name.empty()) {
252 const yaml::StringValue &Name = YamlMBB.Name;
253 if (!Name.Value.empty()) {
242254 BB = dyn_cast_or_null(
243 F.getValueSymbolTable().lookup(YamlMBB.Name));
255 F.getValueSymbolTable().lookup(Name.Value));
244256 if (!BB)
245 return error(Twine("basic block '") + YamlMBB.Name +
246 "' is not defined in the function '" + MF.getName() + "'");
257 return error(Name.SourceRange.Start,
258 Twine("basic block '") + Name.Value +
259 "' is not defined in the function '" + MF.getName() +
260 "'");
247261 }
248262 auto *MBB = MF.CreateMachineBasicBlock(BB);
249263 MF.insert(MF.end(), MBB);
126126 YamlMBB.ID = (unsigned)MBB.getNumber();
127127 // TODO: Serialize unnamed BB references.
128128 if (const auto *BB = MBB.getBasicBlock())
129 YamlMBB.Name = BB->hasName() ? BB->getName() : "";
129 YamlMBB.Name.Value = BB->hasName() ? BB->getName() : "";
130130 else
131 YamlMBB.Name = "";
131 YamlMBB.Name.Value = "";
132132 YamlMBB.Alignment = MBB.getAlignment();
133133 YamlMBB.AddressTaken = MBB.hasAddressTaken();
134134 YamlMBB.IsLandingPad = MBB.isLandingPad();
1212 ---
1313 name: foo
1414 body:
15 # CHECK: basic block 'entrie' is not defined in the function 'foo'
15 # CHECK: [[@LINE+2]]:18: basic block 'entrie' is not defined in the function 'foo'
1616 - id: 0
1717 name: entrie
1818 ...