diff --git a/src/IO.cpp b/src/IO.cpp index 9619e53..83ff2dc 100644 --- a/src/IO.cpp +++ b/src/IO.cpp @@ -1,6 +1,7 @@ #include "IO.h" #include "Assembleur.h" +#include #include BinaryData ParseFile(const std::string& fileName) { @@ -44,7 +45,22 @@ BinaryData ParseFile(const std::string& fileName) { return output; } -void OutputFile(const BinaryData& a_Data, const std::string& fileName) { +void OutputFileBinary(const BinaryData& a_Data, const std::string& fileName) { std::ofstream file{fileName}; file.write(reinterpret_cast(a_Data.data()), a_Data.size() * sizeof(a_Data.at(0))); } + +void OutputFileIntegers(const BinaryData& a_Data, const std::string& fileName) { + std::ofstream file{fileName}; + for (std::uint32_t number : a_Data) { + file << number << "\n"; + } +} + +void OutputFileBinIntegers(const BinaryData& a_Data, const std::string& fileName) { + std::ofstream file{fileName}; + for (std::uint32_t number : a_Data) { + file << std::bitset<8>(number >> 24) << " " << std::bitset<8>(number >> 16) << " " << std::bitset<8>(number >> 8) << + " " << std::bitset<8>(number) << "\n"; + } +} \ No newline at end of file diff --git a/src/IO.h b/src/IO.h index a62c236..dddbde7 100644 --- a/src/IO.h +++ b/src/IO.h @@ -7,4 +7,6 @@ using BinaryData = std::vector; BinaryData ParseFile(const std::string& fileName); -void OutputFile(const BinaryData& a_Data, const std::string& fileName); +void OutputFileBinary(const BinaryData& a_Data, const std::string& fileName); +void OutputFileIntegers(const BinaryData& a_Data, const std::string& fileName); +void OutputFileBinIntegers(const BinaryData& a_Data, const std::string& fileName); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5b6c886..d12f32f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,7 @@ int main(int argc, char** argv) { try { auto output = ParseFile("test.asm"); - OutputFile(output, "test.bin"); + OutputFileBinary(output, "test.bin"); } catch (std::runtime_error& e) { std::cerr << e.what() << std::endl; return 1;