70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
#include <argparse/argparse.hpp>
|
|
#include <iostream>
|
|
|
|
#include "IO.h"
|
|
|
|
#define ASSEMBLEUR_VERSION "1.4"
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
argparse::ArgumentParser program("Assembleur", ASSEMBLEUR_VERSION);
|
|
|
|
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. [logisim|bin|int|binint]")
|
|
.metavar("type")
|
|
.default_value(std::string("logisim"))
|
|
.choices("logisim", "bin", "int", "binint")
|
|
.store_into(formatType);
|
|
|
|
std::string header;
|
|
program.add_argument("-h", "--header")
|
|
.help("Header of the file")
|
|
.metavar("header")
|
|
.default_value(std::string("v3.0 hex words addressed"))
|
|
.store_into(header);
|
|
|
|
bool reverse;
|
|
program.add_argument("-r", "--reversed").help("inverse bit orders").flag().store_into(reverse);
|
|
|
|
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 == "logisim") {
|
|
OutputFileLogisim(output, outputFileName, header, reverse);
|
|
} else if (formatType == "bin") {
|
|
OutputFileBinary(output, outputFileName, reverse);
|
|
} else if (formatType == "int") {
|
|
OutputFileIntegers(output, outputFileName, reverse);
|
|
} else {
|
|
OutputFileBinIntegers(output, outputFileName, reverse);
|
|
}
|
|
|
|
} catch (std::runtime_error& e) {
|
|
std::cerr << e.what() << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|