使用 C++ 后端查看这些事情的最简单方法 - 它生成为您构建模块的 C++ API 调用。你可以在网上看到这个。
“编译”这段代码:
const char* foo() {
const char* s = "hello world";
return s;
}
以下是相关的 C++ API 调用:
GlobalVariable* gvar_array__str = new GlobalVariable(/*Module=*/*mod,
/*Type=*/ArrayTy_0,
/*isConstant=*/true,
/*Linkage=*/GlobalValue::PrivateLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/".str");
gvar_array__str->setAlignment(1);
// Constant Definitions
Constant *const_array_4 = ConstantDataArray::getString(mod->getContext(), "hello world", true);
std::vector<Constant*> const_ptr_5_indices;
ConstantInt* const_int64_6 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("0"), 10));
const_ptr_5_indices.push_back(const_int64_6);
const_ptr_5_indices.push_back(const_int64_6);
Constant* const_ptr_5 = ConstantExpr::getGetElementPtr(gvar_array__str, const_ptr_5_indices);
// Global Variable Definitions
gvar_array__str->setInitializer(const_array_4);
// Function Definitions
// Function: foo (func_foo)
{
BasicBlock* label_entry = BasicBlock::Create(mod->getContext(), "entry",func_foo,0);
// Block entry (label_entry)
ReturnInst::Create(mod->getContext(), const_ptr_5, label_entry);
}