add reversing

This commit is contained in:
2024-11-13 14:50:22 +01:00
parent 6fcc51f2ca
commit f14d05a28a
3 changed files with 76 additions and 18 deletions

View File

@@ -8,9 +8,7 @@ int main(int argc, char** argv) {
argparse::ArgumentParser program("Assembleur");
std::string inputFileName;
program.add_argument("file")
.help("The assembly file to compile")
.store_into(inputFileName);
program.add_argument("file").help("The assembly file to compile").store_into(inputFileName);
std::string outputFileName;
program.add_argument("-o", "--output")
@@ -21,12 +19,25 @@ int main(int argc, char** argv) {
std::string formatType;
program.add_argument("-f", "--format")
.help("Type of the output. [bin|int|binint]")
.help("Type of the output. [logisim|bin|int|binint]")
.metavar("type")
.default_value(std::string("binint"))
.choices("bin", "int", "binint")
.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) {
@@ -38,12 +49,14 @@ int main(int argc, char** argv) {
try {
auto output = ParseFile(inputFileName);
if (formatType == "bin") {
OutputFileBinary(output, outputFileName);
if (formatType == "logisim") {
OutputFileLogisim(output, outputFileName, header, reverse);
} else if (formatType == "bin") {
OutputFileBinary(output, outputFileName, reverse);
} else if (formatType == "int") {
OutputFileIntegers(output, outputFileName);
OutputFileIntegers(output, outputFileName, reverse);
} else {
OutputFileBinIntegers(output, outputFileName);
OutputFileBinIntegers(output, outputFileName, reverse);
}
} catch (std::runtime_error& e) {