<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 4 Feb 2020 at 09:20, George Rimar <<a href="mailto:grimar@accesssoftek.com">grimar@accesssoftek.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">




<div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif">
<p>The idea itself is indeed good.<br>
</p>
<p><br>
</p>
<p>Regarding to <span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">escaping: I think we should have it.</span></p></div></blockquote><div>I think you may be misinterpreting what I mean by escaping. I mean needing to use something like '\' to allow '[[' to be used in the YAML without having a special meaning. I agree we need some sort of indicator to identify a macro, but also think the approach of simply ignoring things if not defined is fine.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif"><p><br>
</p>
<p><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">Imagine the following example (I've took it from D73828).</span></p>
<p><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><br>
</span></p>
<div>--- !ELF<br>
</div>
<div>FileHeader:</div>
<div>  Class:   ELFCLASS[[BITS]]</div>
<div>  Data:    ELFDATA2LSB</div>
<div>  Type:    ET_EXEC</div>
<div>  Machine: EM_386<br>
</div>
<p><span style="color:rgb(33,33,33);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)"><br>
</span></p>
<div># RUN: yaml2obj %s --docnum=4 -D BITS=32 -o %t-32bit.o</div>
<div># RUN: yaml2obj %s --docnum=4 -D BITS=64 -o %t-64bit.o<br>
</div>
<div><br>
</div>
<div>Without escaping it would be:<br>
</div>
<div></div>
<div><span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">Class:   ELFCLASSBITS</span><br>
</div>
<p><br>
</p>
<p>What does not look so clear as a version with escaping IMO.<br>
</p>
<p><br>
</p>
<div id="gmail-m_2592923076165893766Signature">
<div name="divtagdefaultwrapper">
<div><font size="2">
<div>Best regards,<br>
George | Developer | <span style="background-color:rgb(255,255,255);color:rgb(33,33,33);font-family:Calibri,sans-serif;font-size:13.3333px">Access Softek, Inc</span></div>
</font></div>
</div>
</div>
<div style="color:rgb(33,33,33)">
<hr style="display:inline-block;width:98%">
<div id="gmail-m_2592923076165893766divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>От:</b> James Henderson <<a href="mailto:jh7370.2008@my.bristol.ac.uk" target="_blank">jh7370.2008@my.bristol.ac.uk</a>><br>
<b>Отправлено:</b> 4 февраля 2020 г. 12:09<br>
<b>Кому:</b> Fangrui Song<br>
<b>Копия:</b> llvm-dev; George Rimar<br>
<b>Тема:</b> Re: RFC: Add a preprocessor to yaml2obj (and other YAML tools)</font>
<div> </div>
</div>
<div>
<div style="font-size:9pt;font-family:"Calibri",sans-serif">
<h3 style="background-color:rgb(255,255,255);font-size:10pt;border:1px dotted rgb(0,51,51);padding:0.8em">
<span style="color:rgb(255,102,0)">CAUTION:<b> </b></span>This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.  If you suspect potential phishing or spam
 email, report it to <a href="mailto:ReportSpam@accesssoftek.com" target="_blank">ReportSpam@accesssoftek.com</a></h3>
</div>
<div>
<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" target="_blank">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>
</div>
</div>
</div>
</div>

</blockquote></div></div>