Llvm 如何编译和运行llc-3.4生成的C++;使用本机编译器(g+;+;)编写代码? 注:

Llvm 如何编译和运行llc-3.4生成的C++;使用本机编译器(g+;+;)编写代码? 注:,llvm,llvm-clang,llvm-gcc,Llvm,Llvm Clang,Llvm Gcc,这项工作的目标是在非c++11编译器中使用一些c++11特性 完成以下步骤: 生成llvm位代码 clang++ -emit-llvm -c test.cc -o test.o < L> > P>将LLVM位代码转换为C++代码, llc-3.4 test.o -o test.cpp -march=cpp 编译时的误差小于 arunprasadr@geekvm:~/works/myex/llvm$g++test.cpp test.cpp:3:23:致命错误:llvm/Pass.h:没有这

这项工作的目标是在非c++11编译器中使用一些c++11特性

完成以下步骤:

  • 生成llvm位代码

    clang++ -emit-llvm -c test.cc -o test.o
    
  • < L> > P>将LLVM位代码转换为C++代码,

    llc-3.4 test.o -o test.cpp -march=cpp
    
    <0:LIVM生成的C++代码使用GNU+G++/P>编译时的误差小于 arunprasadr@geekvm:~/works/myex/llvm$g++test.cpp test.cpp:3:23:致命错误:llvm/Pass.h:没有这样的文件或目录 编译终止

    我甚至尝试添加llvm dev include path,但仍然失败

    arunprasadr@geekvm:~/works/myex/llvm$ g++ test.cpp -I/usr/include/llvm-3.4 -I /usr/include/llvm-c-3.4
    In file included from /usr/include/llvm-3.4/llvm/Support/type_traits.h:20:0,
                     from /usr/include/llvm-3.4/llvm/ADT/StringRef.h:13,
                     from /usr/include/llvm-3.4/llvm/PassRegistry.h:20,
                     from /usr/include/llvm-3.4/llvm/PassSupport.h:26,
                     from /usr/include/llvm-3.4/llvm/Pass.h:366,
                     from test.cpp:3:
    /usr/include/llvm-3.4/llvm/Support/DataTypes.h:48:3: error: #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h"
    /usr/include/llvm-3.4/llvm/Support/DataTypes.h:52:3: error: #error "Must #define __STDC_CONSTANT_MACROS before " "#including Support/DataTypes.h"
    In file included from /usr/include/llvm-3.4/llvm/ADT/SmallVector.h:19:0,
                     from /usr/include/llvm-3.4/llvm/PassAnalysisSupport.h:22,
                     from /usr/include/llvm-3.4/llvm/Pass.h:367,
                     from test.cpp:3:
    /usr/include/llvm-3.4/llvm/Support/MathExtras.h: In function ‘bool llvm::isInt(int64_t)’:
    /usr/include/llvm-3.4/llvm/Support/MathExtras.h:264:33: error: there are no arguments to ‘INT64_C’ that depend on a template parameter, so a declaration of ‘INT64_C’ must be available [-fpermissive]
    /usr/include/llvm-3.4/llvm/Support/MathExtras.h:264:33: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
    /usr/include/llvm-3.4/llvm/Support/MathExtras.h:264:65: error: there are no arguments to ‘INT64_C’ that depend on a template parameter, so a declaration of ‘INT64_C’ must be available [-fpermissive]
    /usr/include/llvm-3.4/llvm/Support/MathExtras.h: In function ‘bool llvm::isUInt(uint64_t)’:
    /usr/include/llvm-3.4/llvm/Support/MathExtras.h:290:36: error: there are no arguments to ‘UINT64_C’ that depend on a template parameter, so a declaration of ‘UINT64_C’ must be available [-fpermissive]
    /usr/include/llvm-3.4/llvm/Support/MathExtras.h: In function ‘bool llvm::isIntN(unsigned int, int64_t)’:
    /usr/include/llvm-3.4/llvm/Support/MathExtras.h:322:33: error: ‘INT64_C’ was not declared in this scope
    

    您需要根据
    llvm config
    提供的标志进行编译。如下所示:

    input.cc 为了提供帮助,下面是我机器上llvm配置行的输出:
    谢谢你的回答@sharth。它现在正在生成可执行文件,但它没有按预期运行,请参阅。我不知道
    llc
    应该生产什么。这简单地解决了你所看到的编译器错误的问题。<代码> CPP < /COD>后端生成一个C++代码,它将构造你的LLVM IR模块。显然,你想要一些不同的东西——就像旧的C后端所做的那样,但它很久以前就从LLVM中删除了,而且从来没有真正工作过。谢谢@SK logic,听到这个消息我有点失望。有没有其他从LLVM IR生成C代码的替代方案?
    #include <iostream>
    
    int main() {
        std::cout << "hello" << std::endl;
    }
    
    [3:21pm][wlynch@apple /tmp] /opt/llvm/3.4/bin/clang++ -emit-llvm -c input.cc -o input.o
    [3:22pm][wlynch@apple /tmp] /opt/llvm/3.4/bin/llc input.o -o llvm.cc -march=cpp
    [3:22pm][wlynch@apple /tmp] /opt/llvm/3.4/bin/clang++ -gcc-toolchain /opt/gcc/4.8.2/ llvm.cc `/opt/llvm/3.4/bin/llvm-config --cxxflags --ldflags --libs`
    
    -I/opt/llvm/3.4/include -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
    -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -fomit-frame-pointer
    -std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fPIC
    -Woverloaded-virtual -Wcast-qual -L/opt/llvm/3.4/lib -lz -lpthread -ltinfo -lrt
    -ldl -lm -lLLVMInstrumentation -lLLVMIRReader -lLLVMAsmParser -lLLVMDebugInfo
    -lLLVMOption -lLLVMLTO -lLLVMLinker -lLLVMipo -lLLVMVectorize -lLLVMBitWriter
    -lLLVMBitReader -lLLVMTableGen -lLLVMR600CodeGen -lLLVMR600Desc -lLLVMR600Info
    -lLLVMR600AsmPrinter -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen
    -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo
    -lLLVMSystemZAsmPrinter -lLLVMHexagonCodeGen -lLLVMHexagonAsmPrinter
    -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc
    -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMCppBackendCodeGen
    -lLLVMCppBackendInfo -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info
    -lLLVMMSP430AsmPrinter -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen
    -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMMipsDisassembler
    -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo
    -lLLVMMipsAsmPrinter -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser
    -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAArch64Disassembler
    -lLLVMAArch64CodeGen -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info
    -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMPowerPCCodeGen
    -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo
    -lLLVMPowerPCAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo
    -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG
    -lLLVMAsmPrinter -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils
    -lLLVMMCDisassembler -lLLVMMCParser -lLLVMInterpreter -lLLVMMCJIT -lLLVMJIT
    -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine
    -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMRuntimeDyld
    -lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore
    -lLLVMSupport