[cfe-dev] [CLANG][X86][inline-asm]Clang support for inline assembly MS style

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Wed Dec 7 09:03:09 PST 2016


We should probably rewrite enums in the frontend into integer constants. I
guess the fix would live in buildMSAsmString.

2016-12-05 7:38 GMT-08:00 Haroush, Matan via cfe-dev <cfe-dev at lists.llvm.org
>:

>
>
> Hey
>
> I’m working on adding support for inline asm to LLVM.org.
>
> I am trying to determine what is the best place to insert code to enable
> use of enumerated constants
>
> when using Microsoft style inline asm in a similar fashion to the way
> macros are used.
>
>
>
> EXAMPLE:
>
> ############################################################
> ############################################
>
> C code:
>
>
>
> int test_inline_asm_enum() {
>
>     enum { A = 12, B};                        // can also be declared
> globally
>
>                 __asm mov ax, A
>
>     return B;
>
> }
>
>
>
> Generated LLVM IR:
>
>
>
> define i32 @test_inline_asm_enum() #0 {
>
> entry:
>
> call void asm sideeffect inteldialect
>                                                 \
>
> "mov ax, *qword ptr *A",   "~{dirflag},~{fpsr},~{flags}"() #1, !srcloc
> !1
>
> ret i32 13
>
> }
>
>
>
> COMPILE LINE:
>
>
>
> Clang -cc1 -fasm-blocks -O0 -emit-llvm <codefile.c> -o -
>
>
>
> * without –emit-llvm flag the compiler will crash as it tries to handles A
> like a variable.
>
> ** note the absence of an allocation of A before the function call, this
> is because enums are
>
> not emitted to IR but treated as integer constants.
>
>
>
> ############################################################
> ############################################
>
>
>
> After some investigation I narrowed the scope to two locations in clang
> which are reasonable candidates:
>
> 1.       buildMsAsmString – where macros are handled
>
> 2.       asmParser/X86 AsmParser which handles the assembly semantics and
> emits the IR.
>
>
>
> My main issue though is to determine if the token/identifier belongs to an
> EnumConstDecl/Expr.
>
> I’ve noticed the code in this area uses a lookup method which is called
> via parser->semaCallback.
>
> However I don’t really understand yet how to create an instance of such a
> handler in order to lookup
>
> previously declared labels(particularly EnumConstantDecls).
>
>
>
> I was hoping that someone may have some insight to share regarding the
> problem or on lookup usage in general.
>
> Please let me know if you need any clarifications and feel free to contact
> me via mail.
>
> Thanks,
>
>
>
> Matan Haroush
>
>
>
> ---------------------------------------------------------------------
> Intel Israel (74) Limited
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161207/4b1bae34/attachment.html>


More information about the cfe-dev mailing list