From 6154309f0cd3ed5071996951465808f2503e2eb1 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 29 Mar 2020 18:30:04 +0200 Subject: mcc produces first dummy executable --- mcc.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'mcc.cpp') diff --git a/mcc.cpp b/mcc.cpp index da2a981..fa9b0b8 100644 --- a/mcc.cpp +++ b/mcc.cpp @@ -1,6 +1,50 @@ +// // CLI +// + +#include "cpp.h" +#include "elf.h" +#include "file.h" + +#include + +using namespace std::string_literals; + +namespace { + +void usage() { + std::cout << "Usage: mcc " << std::endl; +} + +} int main(int argc, char* argv[]) { + try { + CPP cpp; + + if (argc != 2) { + usage(); + return 1; + } + + fs::path in_filename{argv[1]}; + fs::path out_filename{in_filename.parent_path() / in_filename.stem()}; + + if (in_filename == out_filename) + throw std::runtime_error("Bad output filename: "s + out_filename.generic_string()); + + auto unit {File::getFile(in_filename)}; + + std::string unit_string(reinterpret_cast(unit.data()), unit.size()); + + cpp.translate(unit_string); + + Elf::Write(out_filename, cpp.getCode(), cpp.getData()); + } catch (const std::exception& ex) { + std::cout << "Error: " << ex.what() << std::endl; + return 1; + } + return 0; } -- cgit v1.2.3