随笔分类 -  编译器 / llvm

摘要:见下文代码,方式一样的 ```c++ #include #include "llvm/IR/Module.h" #include "llvm/IR/LLVMContext.h" #include "llvm/Support/raw_ostream.h" #include "llvm/IR/Funct 阅读全文
posted @ 2023-08-09 19:53 00lab 阅读(88) 评论(0) 推荐(0) 编辑
摘要:llvm::raw_ostream llvm::raw_ostream是一个抽象class,有两个重要的纯虚函数由子类实现,write_impl()保存将数据写入基础流的逻辑,current_pos()返回流中当前正在写入的位置。 llvm提供了以下输出流实现: - `outs()` for wri 阅读全文
posted @ 2023-08-02 21:19 00lab 阅读(548) 评论(0) 推荐(0) 编辑
摘要:**编译生成可执行文件** ```shell clang hello.c -o hello ``` ### 编译生成bc文件(不可读) 得到 LLVM 字节码文件.bc(不可读字节码文件) ```shell clang -O3 -emit-llvm hello.c -c -o hello.bc `` 阅读全文
posted @ 2023-08-02 21:14 00lab 阅读(467) 评论(0) 推荐(0) 编辑
摘要:## 一个ifelse源码编译 先看如下代码: ```c++ int func(int a) { int b; if (a > 5) b = 6; else b = 5; return b; } ``` 编译命令 ../output/bin/clang++ -emit-llvm llvm_if_el 阅读全文
posted @ 2023-08-02 21:10 00lab 阅读(100) 评论(0) 推荐(0) 编辑
摘要:## 四则运算指令 介绍如下: ```c++ #include #include "llvm/IR/Module.h" #include "llvm/IR/LLVMContext.h" #include "llvm/Support/raw_ostream.h" #include "llvm/IR/F 阅读全文
posted @ 2023-08-02 20:07 00lab 阅读(17) 评论(0) 推荐(0) 编辑
摘要:主要分全局变量、函数参数、局部变量(常量)与返回值 ## 测试全局变量 介绍说明、代码、编译与结果如下: ```c++ #include "llvm/IR/Module.h" #include "llvm/IR/LLVMContext.h" #include "llvm/Support/raw_os 阅读全文
posted @ 2023-08-02 19:59 00lab 阅读(79) 评论(0) 推荐(0) 编辑
摘要:如果要使用LLVM的能力,则需熟悉如何根据自己的代码生成出llvm的IR,以便提供给llvm使用。 ### 测试创建function 测试代码如下02_test_function.cpp ```c++ #include "llvm/IR/Module.h" #include "llvm/IR/LLV 阅读全文
posted @ 2023-07-31 21:35 00lab 阅读(97) 评论(0) 推荐(0) 编辑
摘要:## LLVM源码编译 准备好匹配的环境后,我的环境如下: ```shell $ cat /proc/version Linux version 5.4.0-150-generic (buildd@bos03-amd64-012) (gcc version 7.5.0 (Ubuntu 7.5.0-3 阅读全文
posted @ 2023-07-29 14:49 00lab 阅读(80) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示