XCode中的LLVM-GCC ASM到LLVM [英] LLVM-GCC ASM to LLVM in XCode

查看:118
本文介绍了XCode中的LLVM-GCC ASM到LLVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用XCode LLVM-GCC编译器,我得到了以下两个可以正常编译(和工作)的定义:

I got the 2 following definition that compile (and work) just fine using XCode LLVM-GCC compiler:

#define SAVE_STACK(v)__asm { mov v, ESP }
#define RESTORE_STACK __asm {sub ESP, s }

但是,当我将编译器更改为Apple LLVM时,出现以下错误:

However when I change the compiler to Apple LLVM I got the following error:

Expected '(' after 'asm'

我将{}替换为(),但不能解决问题,我用Google搜索该错误找不到有用的东西……有人吗?

I replace the {} with () but that doesn't do the trick, I google on that error couldn't find anything useful... anyone?

推荐答案

内联汇编的 __ asm {...} 样式是非标准的,并且不受clang支持.相反,C ++将内联汇编语法指定为 asm("..."),请注意引号.此外,clang使用AT& T汇编语法,因此需要重写宏以确保安全.

The __asm {...} style of inline assembly is non-standard and not supported by clang. Instead C++ specifies inline assembly syntax as asm("..."), note the quotes. Also clang uses AT&T assembly syntax so the macros would need to be rewritten to be safe.

但是,正在进行一些工作来改善对Microsoft非标准汇编语法以及Intel样式汇编的支持.有一个选项 -fenable-experimental-ms-inline-asm 可以启用到目前为止已完成的操作,尽管我不确定何时引入该功能或您对clang版本的支持情况如何正在使用.对您显示的代码进行一次简单的尝试似乎可以处理来自SVN干线的最新版本的clang.

However, some work has been going on to improve support for Microsoft's non-standard assembly syntax, and Intel style assembly along with it. There's an option -fenable-experimental-ms-inline-asm that enables what's been done so far, although I'm not sure when it was introduced or how good the support is in the version of clang you're using. A simple attempt with the code you show seems to work with a recent version of clang from the SVN trunk.

#define SAVE_STACK(v)__asm { mov v, ESP }
#define RESTORE_STACK __asm {sub ESP, s }

int main() {
    int i;
    int s;
    SAVE_STACK(i);
    RESTORE_STACK;
}

clang ++ tmp.cpp -fms-extensions -fenable-experimental-ms-inline-asm -S -o-

        .def     main;
        .scl    2;
        .type   32;
        .endef
        .text
        .globl  main
        .align  16, 0x90
main:                                   # @main
# BB#0:                                 # %entry
        pushq   %rax
        #APP
        .intel_syntax
        mov dword ptr [rsp + 4], ESP
        .att_syntax
        #NO_APP
        #APP
        .intel_syntax
        sub ESP, dword ptr [rsp]
        .att_syntax
        #NO_APP
        xorl    %eax, %eax
        popq    %rdx
        ret

命令 clang ++ tmp.cpp -fms-extensions -fenable-experimental-ms-inline-asm 会生成一个运行的可执行文件.

And the command clang++ tmp.cpp -fms-extensions -fenable-experimental-ms-inline-asm produces an executable that runs.

尽管如此,它仍然会发出如下警告.

It does still produce warnings like the following though.

警告:不支持MS样式的内联汇编[-Wmicrosoft]

warning: MS-style inline assembly is not supported [-Wmicrosoft]

这篇关于XCode中的LLVM-GCC ASM到LLVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆