#include "Arguments.h" #include "Error.h" #include "tclap/CmdLine.h" #include "llvm/Support/Host.h" std::string Arguments::input_fname; std::string Arguments::output_fname; bool Arguments::wimport; 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"); TCLAP::UnlabeledValueArg input_fname_arg("file", "Input file.", true, "test.sp", "string"); TCLAP::ValueArg output_fname_arg("o", "output", "Output file.", false, "sp-output", "string"); TCLAP::ValueArg march_arg("", "march", "Architecture to compile for.", false, "native", "string"); TCLAP::ValueArg mcpu_arg("", "mcpu", "CPU to compile for.", false, "generic", "string"); TCLAP::ValueArg 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); 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(); cpu = mcpu_arg.getValue(); setTriple(march_arg.getValue(), msystem_arg.getValue()); } catch (TCLAP::ArgException& e) { Error::throw_error_without_location(e.error()); } } void Arguments::setTriple(const std::string& arch, const std::string& system) { std::string triple = llvm::sys::getDefaultTargetTriple(); llvm::Triple targetTriple(triple); if (arch != "native") { targetTriple.setArchName(arch); } if (system != "native") { targetTriple.setOSAndEnvironmentName(system); } targetTriple.setVendor(llvm::Triple::VendorType::UnknownVendor); // let's leave it like that TargetTriple = targetTriple; }