<div dir="ltr">As someone who suggested this kind of functionality in a review earlier, this will certainly be useful, I think. I think the syntax makes sense to me, if we allow for unrecognised macros to just be treated as part of the input string. This means we don't have to worry about complexities like escaping "[[" etc. In the (unlikely) event that somebody's YAML needs to include the literal "[[FOO]]", they simply should not also use -DFOO - use a different name instead, e.g. -DBAR.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 3 Feb 2020 at 22:04, Fangrui Song <<a href="mailto:maskray@google.com">maskray@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I am adding -D k=v to yaml2obj, similar to clang -D. This makes it easy<br>
to generate {32-bit,64-bit} x {big-endian,little-endian} tests.<br>
<br>
   --- !ELF<br>
   FileHeader:<br>
     Class:   ELFCLASS[[BITS]]<br>
     Data:    ELFDATA2[[ENCODE]]<br>
     Type:    ET_DYN<br>
     Machine: EM_X86_64<br>
<br>
# RUN: yaml2obj -D BITS=32 -D ENCODE=LSB %s -o %t.32le<br>
# RUN: yaml2obj -D BITS=32 -D ENCODE=MSB %s -o %t.32le<br>
# RUN: yaml2obj -D BITS=64 -D ENCODE=LSB %s -o %t.64le<br>
# RUN: yaml2obj -D BITS=64 -D ENCODE=MSB %s -o %t.64be<br>
<br>
See <a href="https://reviews.llvm.org/D73828" rel="noreferrer" target="_blank">https://reviews.llvm.org/D73828</a> for examples how -D simplifies tests.<br>
<br>
Do people think it may be useful in other YAML tools? If yes, I'll move<br>
the yaml2obj implementation (<a href="https://reviews.llvm.org/D73821" rel="noreferrer" target="_blank">https://reviews.llvm.org/D73821</a> ) to<br>
include/llvm/Support/YAMLTraits.h llvm::yaml::Input so that other YAML<br>
tools can use the feature.<br>
<br>
Do people prefer a different syntax? I think [[PATTERN]] is nice because<br>
it is what FileCheck -DFILE=... uses:<br>
<br>
   # CHECK: ... [[FILE]]<br>
<br>
   FileCheck only preprocesses patterns in CHECK lines.<br>
   D73821 preprocesses both comment lines (which include CHECK lines) and non-comment lines (which include YAML).<br>
   It is not a problem that the YAML preprocessor also processes CHECK lines, because tokens on a comment line will be ignored.<br>
<br>
If -D UNDEF= is not specified, should [[UNDEF]] in the source be considered an error?<br>
I think it is fine not to treat it as an error because there can be<br>
legitimate use cases of unterminated [[, for example, [[ in a string literal.<br>
YAML parsing is complex. I don't expect the preprocessor to be smart<br>
enough to recognize string literals. (llvm/lib/Support/YAMLParser.cpp does not seem to provide raw strings of<br>
spaces and comments. Hooking a preprocessor into the scanner does not seem to be simple.)<br>
<br>
Do people know other preprocessing features which may be useful?<br>
</blockquote></div>