add multiple outputs
This commit is contained in:
18
src/IO.cpp
18
src/IO.cpp
@@ -1,6 +1,7 @@
|
||||
#include "IO.h"
|
||||
|
||||
#include "Assembleur.h"
|
||||
#include <bitset>
|
||||
#include <fstream>
|
||||
|
||||
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<const char*>(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";
|
||||
}
|
||||
}
|
||||
4
src/IO.h
4
src/IO.h
@@ -7,4 +7,6 @@ using BinaryData = std::vector<std::uint32_t>;
|
||||
|
||||
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);
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user