Remove unneeded LLVM Hello World
This commit is contained in:
parent
bdcd8838ee
commit
df8ca04274
45
src/main.cpp
45
src/main.cpp
@ -100,52 +100,7 @@ int main() {
|
|||||||
|
|
||||||
std::cout << ir_output << std::endl;
|
std::cout << ir_output << std::endl;
|
||||||
|
|
||||||
// LLVM Hello World
|
|
||||||
// llvm_hello_world();
|
|
||||||
|
|
||||||
std::cout << "hello" << std::endl;
|
std::cout << "hello" << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void llvm_hello_world() {
|
|
||||||
|
|
||||||
auto Context = std::make_unique<llvm::LLVMContext>();
|
|
||||||
auto Module = std::make_unique<llvm::Module>("my cool module", *Context);
|
|
||||||
|
|
||||||
auto Builder = std::make_unique<llvm::IRBuilder<>>(*Context);
|
|
||||||
|
|
||||||
llvm::FunctionType* FunType = llvm::FunctionType::get(llvm::Type::getInt32Ty(*Context), false);
|
|
||||||
llvm::Function* Function = llvm::Function::Create(
|
|
||||||
FunType, llvm::GlobalValue::LinkageTypes::ExternalLinkage, "main", *Module);
|
|
||||||
|
|
||||||
llvm::BasicBlock* BB = llvm::BasicBlock::Create(*Context, "entry", Function, nullptr);
|
|
||||||
|
|
||||||
Builder->SetInsertPoint(BB);
|
|
||||||
llvm::Value* value = llvm::ConstantInt::get(llvm::Type::getInt32Ty(*Context), 5);
|
|
||||||
Builder->CreateRet(value);
|
|
||||||
|
|
||||||
llvm::verifyFunction(*Function);
|
|
||||||
|
|
||||||
llvm::InitializeAllTargetInfos();
|
|
||||||
llvm::InitializeAllTargets();
|
|
||||||
llvm::InitializeAllTargetMCs();
|
|
||||||
llvm::InitializeAllAsmParsers();
|
|
||||||
llvm::InitializeAllAsmPrinters();
|
|
||||||
|
|
||||||
auto TargetTriple = llvm::sys::getDefaultTargetTriple();
|
|
||||||
std::string Error;
|
|
||||||
auto Target = llvm::TargetRegistry::lookupTarget(TargetTriple, Error);
|
|
||||||
|
|
||||||
llvm::TargetOptions opt;
|
|
||||||
auto TargetMachine = Target->createTargetMachine(TargetTriple, "generic", "", opt, llvm::Reloc::PIC_);
|
|
||||||
Module->setDataLayout(TargetMachine->createDataLayout());
|
|
||||||
|
|
||||||
std::string out;
|
|
||||||
llvm::raw_string_ostream dest{ out };
|
|
||||||
|
|
||||||
Module->print(dest, nullptr);
|
|
||||||
dest.flush();
|
|
||||||
|
|
||||||
std::cout << out << std::endl;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user