summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/ObjectYAML/MachOYAML.cpp2
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp23
-rw-r--r--llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml6
3 files changed, 27 insertions, 4 deletions
diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp
index 0a303a6e739..d819e80836c 100644
--- a/llvm/lib/ObjectYAML/MachOYAML.cpp
+++ b/llvm/lib/ObjectYAML/MachOYAML.cpp
@@ -91,8 +91,8 @@ void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
// For Fat files there will be a different tag so they can be differentiated.
if (!IO.getContext()) {
IO.setContext(&Object);
- IO.mapTag("!mach-o", true);
}
+ IO.mapTag("!mach-o", true);
IO.mapRequired("FileHeader", Object.Header);
IO.mapOptional("LoadCommands", Object.LoadCommands);
IO.mapOptional("LinkEditData", Object.LinkEdit);
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 2aa6e9b7468..75fac20a8ed 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -423,8 +423,29 @@ void Output::beginMapping() {
bool Output::mapTag(StringRef Tag, bool Use) {
if (Use) {
- this->output(" ");
+ // If this tag is being written inside a sequence we should write the start
+ // of the sequence before writing the tag, otherwise the tag won't be
+ // attached to the element in the sequence, but rather the sequence itself.
+ bool SequenceElement =
+ StateStack.size() > 1 && (StateStack[StateStack.size() - 2] == inSeq ||
+ StateStack[StateStack.size() - 2] == inFlowSeq);
+ if (SequenceElement && StateStack.back() == inMapFirstKey) {
+ this->newLineCheck();
+ } else {
+ this->output(" ");
+ }
this->output(Tag);
+ if (SequenceElement) {
+ // If we're writing the tag during the first element of a map, the tag
+ // takes the place of the first element in the sequence.
+ if (StateStack.back() == inMapFirstKey) {
+ StateStack.pop_back();
+ StateStack.push_back(inMapOtherKey);
+ }
+ // Tags inside maps in sequences should act as keys in the map from a
+ // formatting perspective, so we always want a newline in a sequence.
+ NeedsNewLine = true;
+ }
}
return Use;
}
diff --git a/llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml b/llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml
index 75043a9de74..a3d566b920d 100644
--- a/llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml
+++ b/llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml
@@ -52,7 +52,8 @@ Slices:
#CHECK: size: 15380
#CHECK: align: 12
#CHECK: Slices:
-#CHECK: - FileHeader:
+#CHECK: - !mach-o
+#CHECK FileHeader:
#CHECK: magic: 0xFEEDFACE
#CHECK: cputype: 0x00000007
#CHECK: cpusubtype: 0x00000003
@@ -60,7 +61,8 @@ Slices:
#CHECK: ncmds: 0
#CHECK: sizeofcmds: 0
#CHECK: flags: 0x01218085
-#CHECK: - FileHeader:
+#CHECK: - !mach-o
+#CHECK FileHeader:
#CHECK: magic: 0xFEEDFACF
#CHECK: cputype: 0x01000007
#CHECK: cpusubtype: 0x80000003
OpenPOWER on IntegriCloud