#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::Type或者LLVM::Value的值
最新推荐文章于 2023-02-28 09:26:28 发布