Check for entry point before code generation
This commit is contained in:
parent
cb5f41a7c8
commit
5a0b183198
@ -33,8 +33,10 @@ void Arguments::parse(int argc, char** argv)
|
||||
CreateValueArgument(march, "", "march", "Architecture to compile for.", "native");
|
||||
CreateValueArgument(mcpu, "", "mcpu", "CPU to compile for.", "generic");
|
||||
CreateValueArgument(msystem, "", "msystem", "Operating System to compile for.", "native");
|
||||
CreateValueArgument(entry, "e", "entry", "Name of entry function.", "main");
|
||||
|
||||
CreateFlagArgument(emit_llvm, "", "emit-llvm", "Emit LLVM IR instead of an object file.");
|
||||
CreateFlagArgument(omit_entry, "", "omit-entry", "Do not check for an entry point.");
|
||||
|
||||
#ifndef NO_BENCHMARKING
|
||||
CreateFlagArgument(mprofile, "", "mprofile", "Show execution times for functions.");
|
||||
@ -46,7 +48,9 @@ void Arguments::parse(int argc, char** argv)
|
||||
SaveValueArgument(march);
|
||||
SaveValueArgument(msystem);
|
||||
SaveValueArgument(mcpu);
|
||||
SaveValueArgument(entry);
|
||||
SaveFlagArgument(emit_llvm);
|
||||
SaveFlagArgument(omit_entry);
|
||||
|
||||
setTriple(values["march"], values["msystem"]);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "IRBuilder.h"
|
||||
#include "Arguments.h"
|
||||
#include "Error.h"
|
||||
#include "FormatString/FormatString.hpp"
|
||||
#include "GlobalContext.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/LegacyPassManager.h"
|
||||
@ -29,6 +30,14 @@ llvm::IRBuilder<>* IRBuilder::getBuilder()
|
||||
void IRBuilder::create_program(std::shared_ptr<ProgramNode> program)
|
||||
{
|
||||
program->walk([&](std::shared_ptr<TopLevelNode> node) { node->codegen(this, module.get()); });
|
||||
|
||||
if (!Arguments::flags["omit_entry"])
|
||||
{
|
||||
if (!module->getFunction(Arguments::values["entry"]))
|
||||
{
|
||||
Error::throw_error_without_location(format_string("Missing entry point: %s", Arguments::values["entry"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IRBuilder::resolveToLLVMIR(std::string_view path)
|
||||
@ -38,7 +47,8 @@ void IRBuilder::resolveToLLVMIR(std::string_view path)
|
||||
|
||||
if (EC)
|
||||
{
|
||||
Error::throw_error_without_location("Could not open file " + Arguments::values["output"] + " :" + EC.message());
|
||||
Error::throw_error_without_location(
|
||||
format_string("Could not open file %s: %s", Arguments::values["output"], EC.message()));
|
||||
}
|
||||
|
||||
module->print(dest, nullptr);
|
||||
|
Loading…
Reference in New Issue
Block a user