sapphire/src/Arguments.cpp

68 lines
2.1 KiB
C++
Raw Normal View History

#include "Arguments.h"
#include "Error.h"
#include "tclap/CmdLine.h"
2022-06-07 16:12:43 +00:00
#include "llvm/Support/Host.h"
std::string Arguments::input_fname;
std::string Arguments::output_fname;
bool Arguments::wimport;
2022-06-07 16:12:43 +00:00
llvm::Triple Arguments::TargetTriple;
std::string Arguments::cpu;
void Arguments::parse(int argc, char **argv)
{
try {
TCLAP::CmdLine command_line("The Sapphire compiler.",' ',"0.1");
2022-06-07 16:12:43 +00:00
TCLAP::UnlabeledValueArg<std::string> input_fname_arg("file","Input file.",true,"test.sp","string");
2022-06-07 16:12:43 +00:00
TCLAP::ValueArg<std::string> output_fname_arg("o","output","Output file.",false,"sp-output","string");
TCLAP::ValueArg<std::string> march_arg("","march","Architecture to compile for.",false,"native","string");
TCLAP::ValueArg<std::string> mcpu_arg("","mcpu","CPU to compile for.",false,"generic","string");
TCLAP::ValueArg<std::string> msystem_arg("","msystem","Operating System to compile for.",false,"native","string");
TCLAP::SwitchArg wimport_arg("","wimport","Show a warning when trying to import an already imported file.");
command_line.add(wimport_arg);
command_line.add(input_fname_arg);
command_line.add(output_fname_arg);
2022-06-07 16:12:43 +00:00
command_line.add(march_arg);
command_line.add(mcpu_arg);
command_line.add(msystem_arg);
command_line.parse(argc,argv);
input_fname = input_fname_arg.getValue();
output_fname = output_fname_arg.getValue();
wimport = wimport_arg.getValue();
2022-06-07 16:12:43 +00:00
cpu = mcpu_arg.getValue();
setTriple(march_arg.getValue(),msystem_arg.getValue());
} catch (TCLAP::ArgException &e) {
Error::throw_error_without_location(e.error());
}
}
2022-06-07 16:12:43 +00:00
void Arguments::setTriple(const std::string& arch, const std::string& system)
{
std::string triple = llvm::sys::getDefaultTargetTriple();
llvm::Triple tgTriple(triple);
if(arch != "native")
{
tgTriple.setArchName(arch);
}
if(system != "native")
{
tgTriple.setOSAndEnvironmentName(system);
}
tgTriple.setVendor(llvm::Triple::VendorType::UnknownVendor); // let's leave it like that
TargetTriple = tgTriple;
}