parse arguments
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -5,5 +5,6 @@ build/
|
||||
# MacOS Cache
|
||||
.DS_Store
|
||||
|
||||
test.bin
|
||||
.vscode
|
||||
.vscode
|
||||
|
||||
a.out
|
||||
44
src/main.cpp
44
src/main.cpp
@@ -1,13 +1,51 @@
|
||||
#include <argparse/argparse.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "IO.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
try {
|
||||
auto output = ParseFile("test.asm");
|
||||
argparse::ArgumentParser program("Assembleur");
|
||||
|
||||
std::string inputFileName;
|
||||
program.add_argument("file")
|
||||
.help("The assembly file to compile")
|
||||
.store_into(inputFileName);
|
||||
|
||||
std::string outputFileName;
|
||||
program.add_argument("-o", "--output")
|
||||
.help("Specify the output file.")
|
||||
.metavar("file")
|
||||
.default_value(std::string("a.out"))
|
||||
.store_into(outputFileName);
|
||||
|
||||
std::string formatType;
|
||||
program.add_argument("-f", "--format")
|
||||
.help("Type of the output. [bin|int|binint]")
|
||||
.metavar("type")
|
||||
.default_value(std::string("binint"))
|
||||
.choices("bin", "int", "binint")
|
||||
.store_into(formatType);
|
||||
|
||||
try {
|
||||
program.parse_args(argc, argv);
|
||||
} catch (const std::exception& err) {
|
||||
std::cerr << err.what() << std::endl;
|
||||
std::cerr << program;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
auto output = ParseFile(inputFileName);
|
||||
|
||||
if (formatType == "bin") {
|
||||
OutputFileBinary(output, outputFileName);
|
||||
} else if (formatType == "int") {
|
||||
OutputFileIntegers(output, outputFileName);
|
||||
} else {
|
||||
OutputFileBinIntegers(output, outputFileName);
|
||||
}
|
||||
|
||||
OutputFileBinary(output, "test.bin");
|
||||
} catch (std::runtime_error& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user