[PATCH] D82455: [yaml2obj] - Add a way to set default values for macros used in a YAML.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 30 02:41:06 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG657c4ab39dc8: [yaml2obj] - Add a way to set default values for macros used in a YAML. (authored by grimar).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D82455/new/
https://reviews.llvm.org/D82455
Files:
llvm/test/tools/yaml2obj/macro.yaml
llvm/tools/yaml2obj/yaml2obj.cpp
Index: llvm/tools/yaml2obj/yaml2obj.cpp
===================================================================
--- llvm/tools/yaml2obj/yaml2obj.cpp
+++ llvm/tools/yaml2obj/yaml2obj.cpp
@@ -75,10 +75,22 @@
if (Buf.startswith("[[")) {
size_t I = Buf.find_first_of("[]", 2);
if (Buf.substr(I).startswith("]]")) {
- StringRef Macro = Buf.substr(2, I - 2);
+ StringRef MacroExpr = Buf.substr(2, I - 2);
+ StringRef Macro;
+ StringRef Default;
+ std::tie(Macro, Default) = MacroExpr.split('=');
+
+ // When the -D option is requested, we use the provided value.
+ // Otherwise we use a default macro value if present.
auto It = Defines.find(Macro);
- if (It != Defines.end()) {
- Preprocessed += It->second;
+ Optional<StringRef> Value;
+ if (It != Defines.end())
+ Value = It->second;
+ else if (!Default.empty() || MacroExpr.endswith("="))
+ Value = Default;
+
+ if (Value) {
+ Preprocessed += *Value;
Buf = Buf.substr(I + 2);
continue;
}
Index: llvm/test/tools/yaml2obj/macro.yaml
===================================================================
--- llvm/test/tools/yaml2obj/macro.yaml
+++ llvm/test/tools/yaml2obj/macro.yaml
@@ -58,3 +58,34 @@
- Name: "[[a]"
- Name: "[[a[[a]]"
- Name: "[[a][[a]][[b]]"
+
+## Check that it is possible to set a default value for a macro in the YAML description.
+## Check that we are able to provide an empty default value for a macro.
+# RUN: yaml2obj --docnum=4 %s -o %t4.1
+# RUN: llvm-nm --no-sort %t4.1 | FileCheck %s --check-prefix=DEFAULT
+
+# DEFAULT: U _foo_
+# DEFAULT-NEXT: U __
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Symbols:
+ - Name: _[[FOO=foo]]_
+ - Name: _[[BAR=]]_
+
+## Check that it is possible to override a default macro value.
+# RUN: yaml2obj --docnum=4 %s -o %t4.2 -DFOO=bar -DBAR=foo
+# RUN: llvm-nm --no-sort %t4.2 | FileCheck %s --check-prefix=OVERRIDE-DEFAULT1
+
+# OVERRIDE-DEFAULT1: U _bar_
+# OVERRIDE-DEFAULT1-NEXT: U _foo_
+
+# RUN: yaml2obj --docnum=4 %s -o %t4.3 -DFOO=bar=foo -DBAR=foo=bar
+# RUN: llvm-nm --no-sort %t4.3 | FileCheck %s --check-prefix=OVERRIDE-DEFAULT2
+
+# OVERRIDE-DEFAULT2: U _bar=foo_
+# OVERRIDE-DEFAULT2-NEXT: U _foo=bar_
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82455.274378.patch
Type: text/x-patch
Size: 2393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200630/30755b4a/attachment.bin>
More information about the llvm-commits
mailing list