parse arguments
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -5,5 +5,6 @@ build/
|
|||||||
# MacOS Cache
|
# MacOS Cache
|
||||||
.DS_Store
|
.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 <iostream>
|
||||||
|
|
||||||
#include "IO.h"
|
#include "IO.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
try {
|
argparse::ArgumentParser program("Assembleur");
|
||||||
auto output = ParseFile("test.asm");
|
|
||||||
|
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) {
|
} catch (std::runtime_error& e) {
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
add_rules("mode.debug", "mode.release")
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
|
add_requires("argparse")
|
||||||
|
|
||||||
target("Assembleur")
|
target("Assembleur")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_files("src/*.cpp")
|
add_files("src/*.cpp")
|
||||||
set_rundir(".")
|
set_rundir(".")
|
||||||
|
add_packages("argparse")
|
||||||
|
|
||||||
--
|
--
|
||||||
-- If you want to known more usage about xmake, please see https://xmake.io
|
-- If you want to known more usage about xmake, please see https://xmake.io
|
||||||
|
|||||||
Reference in New Issue
Block a user