Files
mdemory/src/transpiler/main.cpp
jorenchik 6359d97ba5 paramerized show time and debug in global config
Also some additional time measurements in the qt app.
2024-10-27 12:12:00 +02:00

77 lines
1.5 KiB
C++

#include <exception>
#include <iostream>
#include <fstream>
#include <string>
#include <chrono>
#include "config.h"
#include "api.h"
std::string readFile(const std::string& filePath) {
std::ifstream file(filePath);
if (!file.is_open()) {
throw std::runtime_error("Cannot open file: " + filePath);
}
std::string content;
std::string line;
while (std::getline(file, line)) {
content += line + '\n';
}
file.close();
return content;
}
int main(int argc, char* argv[]) {
std::string filePath;
if (argc == 3) {
auto option = std::string(argv[1]);
if (option == "--debug") {
debug = true;
showTimes = true;
} else {
std::cout << std::format("Unrecognized option: {}", option) << std::endl;
return 1;
}
filePath = argv[2];
} else if (argc == 2) {
filePath = argv[1];
} else {
std::cerr << "Usage: " << argv[0] << " <file-path>\n";
return 1;
}
try {
std::string fileContent = readFile(filePath);
end = std::chrono::high_resolution_clock::now();
if (showTimes) {
std::cout << showTime("I/O time") << std::endl;
}
auto res = transpile(fileContent);
auto questions = res.value.questions;
if (res.error.length() > 0) {
std::cout << std::format(
"{} ({}:{})\n",
res.error,
res.row,
res.column
);
return 1;
}
for (Question* question: questions) {
delete question;
}
} catch (std::exception &e) {
std::cout << e.what() << std::endl;
return 1;
}
return 0;
}