diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-03-29 18:30:04 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-03-29 18:30:04 +0200 |
commit | 6154309f0cd3ed5071996951465808f2503e2eb1 (patch) | |
tree | b1666eea410e859f814ae47ca47b8b2d7d333c50 /mcc.cpp | |
parent | b0cac4997b5767526b29187fecf2a87aa1b0ebef (diff) |
mcc produces first dummy executable
Diffstat (limited to 'mcc.cpp')
-rw-r--r-- | mcc.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -1,6 +1,50 @@ +// // CLI +// + +#include "cpp.h" +#include "elf.h" +#include "file.h" + +#include <iostream> + +using namespace std::string_literals; + +namespace { + +void usage() { + std::cout << "Usage: mcc <translation_unit>" << 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<char*>(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; } |