[PATCH] D130981: [yaml2obj] Add a `-E` flag to preprocess only.
Simon Tatham via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 2 05:58:42 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07e6eb6e75b8: [yaml2obj] Add a `-E` flag to preprocess only. (authored by simon_tatham).
Changed prior to commit:
https://reviews.llvm.org/D130981?vs=449256&id=449272#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130981/new/
https://reviews.llvm.org/D130981
Files:
llvm/test/tools/yaml2obj/preprocess-only.test
llvm/tools/yaml2obj/yaml2obj.cpp
Index: llvm/tools/yaml2obj/yaml2obj.cpp
===================================================================
--- llvm/tools/yaml2obj/yaml2obj.cpp
+++ llvm/tools/yaml2obj/yaml2obj.cpp
@@ -40,6 +40,9 @@
"definition. The syntax is <macro>=<definition>"),
cl::cat(Cat));
+cl::opt<bool> PreprocessOnly("E", cl::desc("Just print the preprocessed file"),
+ cl::cat(Cat));
+
cl::opt<unsigned>
DocNum("docnum", cl::init(1),
cl::desc("Read specified document from input (default = 1)"),
@@ -133,11 +136,16 @@
Optional<std::string> Buffer = preprocess(Buf.get()->getBuffer(), ErrHandler);
if (!Buffer)
return 1;
- yaml::Input YIn(*Buffer);
- if (!convertYAML(YIn, Out->os(), ErrHandler, DocNum,
- MaxSize == 0 ? UINT64_MAX : MaxSize))
- return 1;
+ if (PreprocessOnly) {
+ Out->os() << Buffer;
+ } else {
+ yaml::Input YIn(*Buffer);
+
+ if (!convertYAML(YIn, Out->os(), ErrHandler, DocNum,
+ MaxSize == 0 ? UINT64_MAX : MaxSize))
+ return 1;
+ }
Out->keep();
Out->os().flush();
Index: llvm/test/tools/yaml2obj/preprocess-only.test
===================================================================
--- /dev/null
+++ llvm/test/tools/yaml2obj/preprocess-only.test
@@ -0,0 +1,16 @@
+# RUN: yaml2obj -E -Dfoo=wibble %s | FileCheck %s
+
+This is a test of yaml2obj's pure preprocessing mode, so it doesn't
+have to contain valid YAML, or any YAML at all. But we do have to be
+careful with the FileCheck CHECK directives, because they'll be
+emitted into the preprocessed output, and risk matching themselves!
+For that reason, each one matches only at the start of a line.
+
+Expand a macro:
+[[foo]] # CHECK: {{^wibble}}
+
+Expand an undefined macro:
+[[bar]] # CHECK: {{^\[\[bar\]\]}}
+
+Expand an undefined macro where we provided a default value:
+[[baz=123]] # CHECK: {{^123}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130981.449272.patch
Type: text/x-patch
Size: 1948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220802/9269e2db/attachment.bin>
More information about the llvm-commits
mailing list