<div dir="ltr">We should probably rewrite enums in the frontend into integer constants. I guess the fix would live in buildMSAsmString.</div><div class="gmail_extra"><br><div class="gmail_quote">2016-12-05 7:38 GMT-08:00 Haroush, Matan via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_-915247507686494WordSection1">
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Hey <u></u><u></u></p>
<p class="MsoNormal">I’m working on adding support for inline asm to LLVM.org.<u></u><u></u></p>
<p class="MsoNormal">I am trying to determine what is the best place to insert code to enable use of enumerated constants<u></u><u></u></p>
<p class="MsoNormal">when using Microsoft style inline asm in a similar fashion to the way macros are used.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">EXAMPLE:<u></u><u></u></p>
<p class="MsoNormal">##############################<wbr>##############################<wbr>##############################<wbr>##############<u></u><u></u></p>
<p class="MsoNormal">C code:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">int test_inline_asm_enum() {<u></u><u></u></p>
<p class="MsoNormal"> enum { A = 12, B}; // can also be declared globally<u></u><u></u></p>
<p class="MsoNormal"> __asm mov ax, A<u></u><u></u></p>
<p class="MsoNormal"> return B;<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Generated LLVM IR:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">define i32 @test_inline_asm_enum() #0 {<u></u><u></u></p>
<p class="MsoNormal">entry: <u></u><u></u></p>
<p class="MsoNormal">call void asm sideeffect inteldialect <wbr> \<u></u><u></u></p>
<p class="MsoNormal">"mov ax, <b>qword ptr </b>A", "~{dirflag},~{fpsr},~{<wbr>flags}"() #1, !srcloc !1
<u></u><u></u></p>
<p class="MsoNormal">ret i32 13<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">COMPILE LINE:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Clang -cc1 -fasm-blocks -O0 -emit-llvm <codefile.c> -o -<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">* without –emit-llvm flag the compiler will crash as it tries to handles A like a variable.<u></u><u></u></p>
<p class="MsoNormal">** note the absence of an allocation of A before the function call, this is because enums are
<u></u><u></u></p>
<p class="MsoNormal">not emitted to IR but treated as integer constants.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">##############################<wbr>##############################<wbr>##############################<wbr>##############<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">After some investigation I narrowed the scope to two locations in clang which are reasonable candidates:<u></u><u></u></p>
<p class="m_-915247507686494MsoListParagraph"><u></u><span>1.<span style="font:7.0pt "Times New Roman"">
</span></span><u></u><span dir="LTR"></span>buildMsAsmString – where macros are handled<u></u><u></u></p>
<p class="m_-915247507686494MsoListParagraph"><u></u><span>2.<span style="font:7.0pt "Times New Roman"">
</span></span><u></u><span dir="LTR"></span>asmParser/X86 AsmParser which handles the assembly semantics and emits the IR.<u></u><u></u></p>
<p class="m_-915247507686494MsoListParagraph"><u></u> <u></u></p>
<p class="MsoNormal">My main issue though is to determine if the token/identifier belongs to an EnumConstDecl/Expr.<u></u><u></u></p>
<p class="MsoNormal">I’ve noticed the code in this area uses a lookup method which is called via parser->semaCallback.<u></u><u></u></p>
<p class="MsoNormal">However I don’t really understand yet how to create an instance of such a handler in order to lookup<u></u><u></u></p>
<p class="MsoNormal">previously declared labels(particularly EnumConstantDecls).<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I was hoping that someone may have some insight to share regarding the problem or on lookup usage in general.<u></u><u></u></p>
<p class="MsoNormal">Please let me know if you need any clarifications and feel free to contact me via mail.<u></u><u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Matan Haroush<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p>------------------------------<wbr>------------------------------<wbr>---------<br>
Intel Israel (74) Limited</p>
<p>This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</p></div>
<br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>