llvm

Method to create LLVM IR

只愿长相守 提交于 2019-12-11 11:42:36
问题 I am creating clang tool and I want to generate LLVM IR from clang AST. I am aware of -emit-llvm option that I can use to get *.ll file, but is there way to generate IR inside code? Some method that I can call that takes clang AST or AST context and returns llvm::Module ? I cannot find any example that shows this. Edited: So I tried using CodeGenAction for this, but I can't get it to work. I end up with unresolved external symbol error. Am I missing something? #include <clang/CodeGen

How to print fully qualified Expr in clang?

允我心安 提交于 2019-12-11 11:33:21
问题 I'm working on my reflection tool with clang 8.0.1. And right now I need to print Expr with all names fully qualified. I already tried builtin prettyPrint function with FullyQualifiedName bit set to true. But it still gives incorrect result. For this piece of code: namespace math { struct Transform { float val; [[custom_attr(&Transform::public_val)]] void foo(); }; } It gives me &Transform::public_val instead of &math::Transform::public_val And for static_cast<float (*)(const Transform&)>

Buliding llvm examples, /llvm/lib/Support/Mutex.cpp:53: undefined reference to `pthread_mutexattr_init'

江枫思渺然 提交于 2019-12-11 11:08:33
问题 I'm attempting to follow the steps on http://llvm.org/docs/tutorial/LangImpl3.html to build the example. based on Building llvm examples #error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h" Why am I getting "undefined reference to `dladdr'" even with -ldl for this simple program? I've ended up with the command clang++ -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -std=c++11 -g -O3 toy.cpp `llvm-config --libs core --cppflags --ldflags` -o toy which is giving /usr

In LLVM IR, how can I print the name of a unnamed value which is represented as an unsigned numeric value with their prefix such as %2?

☆樱花仙子☆ 提交于 2019-12-11 10:37:57
问题 I want to print out the instructions written in LLVM IR( for practice ) and I have a BitCastInst like this: %0 = bitcast [32xi32]* %reg to i8* How can I print its name of left value which is a unnamed value %0 in this case? 回答1: Those names don't really exist in the in-memory representation of the IR -- there, values just refer to other values using pointers. The names are computed and added to the textual form as it's being written out. This makes sense since transforms are constantly

Qt高级——QtCreator代码格式化

早过忘川 提交于 2019-12-11 10:35:25
Qt高级——QtCreator代码格式化 一、QtCreator代码格式化简介 QtCreator提供了一个Beautifier插件,用于加载外部工具(Artistic Style、ClangFormat、Uncrustify)对代码进行格式化。 Beautifier会将源代码解析为结构模块,如赋值语句、IF语句块、循环体等等,并用Beautifier指定的选项对模块进行格式化。 Beautifier可以使用预定义和自定义风格对代码进行格式化。 二、Clang-format 1、Clang-format简介 Clang-format是一个基于LLVM的C++代码格式化工具。 LLVM下载地址: http://ftp.math.utah.edu/pub/llvm/ 2、Clang-format安装 根据GCC版本下载相应的LLVM,本人操作系统为RHEL7.3,GCC版本为4.8.5,选择Fedora 20 x86-64的LLVM版本。如果选择Red Hat 6 x86-64、Red Hat 7 x86-64版本则GLIBC版本要求GLIBCXX_3.4.20,RHEL7.3不能满足。 解压llvm-20140716.tar.gz文件 tar -zxvf llvm-20140716.tar.gz 进入llvm-20140716/bin目录 将clang-format拷贝到/usr

Cannot execute function JITed by LLVM

那年仲夏 提交于 2019-12-11 09:41:29
问题 Using LLVM-5.0 I implemented a minimal testcase that creates assembly for a function returning the 32bit integer "42" at runtime and executes it. Using llvm::ExecutionEngine I was able to generate the following code at runtime (displayed with gdb): 0x7ffff7ff5000 mov $0x2a,%eax 0x7ffff7ff5005 retq Calling the function yields Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7ff5000 in ?? () My working theory is that the memory page LLVM wrote the code on is not executable. Is

Extracting LLVM::Module from LLVM::ModuleRef

别说谁变了你拦得住时间么 提交于 2019-12-11 08:32:28
问题 I'm trying to build a simple bitcode reader (rather than a dedicated pass, in order to be able to debug more easily) and I have some problems extracting the module. Here's what I have inside main: LLVMModuleRef module; char *message = nullptr; LLVMMemoryBufferRef memoryBuffer; LLVMCreateMemoryBufferWithContentsOfFile( argv[1], &memoryBuffer, &message); LLVMParseBitcode2(memoryBuffer,&module); // for (auto func:module->getFunctionList()) { /* ... */ } How can I extract Module from

Failed to link obj files generated by LLVM compiler using MS Linker

亡梦爱人 提交于 2019-12-11 08:23:26
问题 I used llvm online compiler to compile my sample C code, int main() { return 0; } the generated LLVM assembly, ; ModuleID = '/tmp/webcompile/_31588_0.bc' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" define i32 @main() nounwind uwtable { %1 = alloca i32, align 4 store i32 0, i32* %1 ret i32 0 } then I compiled LLVM assembly to obj