您的位置:首页 > 产品设计 > UI/UE

打印LLVM::Type或者LLVM::Value的值

2017-01-09 10:34 1216 查看
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
#include "iostream"

using namespace llvm;
/// Returns the string representation of a llvm::Value* or llvm::Type*
template <typename T> static std::string Print(T* value_or_type) {
std::string str;
llvm::raw_string_ostream stream(str);
value_or_type->print(stream);
return str;
}

int main() {

LLVMContext Context;

// Create some module to put our function into it.
std::unique_ptr<Module> Owner = make_unique<Module>("test", Context);
Module *mod = Owner.get();

/*
//param numBits the bit width of the constructed APInt
//param str the string to be interpreted
//param radix the radix to use for the conversion
APInt(unsigned numBits, StringRef str, uint8_t radix);

//ConstantInt int type constant
*/
ConstantInt* const_int32_one = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));

std::string result = Print(const_int32_one);
std::cout << result << std::endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  llvm
相关文章推荐