Compare commits
2 Commits
48e149b29f
...
d3cb3d82de
| Author | SHA1 | Date | |
|---|---|---|---|
| d3cb3d82de | |||
| 40041b0f12 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,4 +5,5 @@ build/
|
|||||||
# MacOS Cache
|
# MacOS Cache
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
test.bin
|
||||||
|
.vscode
|
||||||
5
.vscode/c_cpp_properties.json
vendored
5
.vscode/c_cpp_properties.json
vendored
@@ -1,11 +1,8 @@
|
|||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Blitz",
|
"name": "Assembleur",
|
||||||
"cppStandard": "c++17",
|
"cppStandard": "c++17",
|
||||||
"includePath": [
|
|
||||||
"include"
|
|
||||||
],
|
|
||||||
"compileCommands": ".vscode/compile_commands.json"
|
"compileCommands": ".vscode/compile_commands.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"stdexcept": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
34
src/IO.cpp
Normal file
34
src/IO.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "IO.h"
|
||||||
|
|
||||||
|
#include "Assembleur.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
BinaryData ParseFile(const std::string& fileName) {
|
||||||
|
std::ifstream file{fileName};
|
||||||
|
std::uint32_t lineNumber = 0, realLineNumber = 0;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
Assembleur assembleur;
|
||||||
|
|
||||||
|
BinaryData output;
|
||||||
|
|
||||||
|
while (getline(file, line)) {
|
||||||
|
lineNumber++;
|
||||||
|
realLineNumber++;
|
||||||
|
|
||||||
|
if (line.find(":") != std::string::npos) {
|
||||||
|
std::string label = line.substr(0, line.size() - 1);
|
||||||
|
assembleur.AddLabel(label, lineNumber);
|
||||||
|
lineNumber--;
|
||||||
|
} else {
|
||||||
|
output.push_back(assembleur.ParseInstruction(line, lineNumber, realLineNumber));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputFile(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)));
|
||||||
|
}
|
||||||
10
src/IO.h
Normal file
10
src/IO.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using BinaryData = std::vector<std::uint32_t>;
|
||||||
|
|
||||||
|
BinaryData ParseFile(const std::string& fileName);
|
||||||
|
|
||||||
|
void OutputFile(const BinaryData& a_Data, const std::string& fileName);
|
||||||
38
src/main.cpp
38
src/main.cpp
@@ -1,42 +1,6 @@
|
|||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "Assembleur.h"
|
|
||||||
|
|
||||||
using BinaryData = std::vector<std::uint32_t>;
|
|
||||||
|
|
||||||
|
|
||||||
static BinaryData ParseFile(const std::string& fileName) {
|
|
||||||
std::ifstream file{fileName};
|
|
||||||
std::uint32_t lineNumber = 0, realLineNumber = 0;
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
Assembleur assembleur;
|
|
||||||
|
|
||||||
BinaryData output;
|
|
||||||
|
|
||||||
while (getline(file, line)) {
|
|
||||||
lineNumber++;
|
|
||||||
realLineNumber++;
|
|
||||||
|
|
||||||
if (line.find(":") != std::string::npos) {
|
|
||||||
std::string label = line.substr(0, line.size() - 1);
|
|
||||||
assembleur.AddLabel(label, lineNumber);
|
|
||||||
lineNumber--;
|
|
||||||
} else {
|
|
||||||
output.push_back(assembleur.ParseInstruction(line, lineNumber, realLineNumber));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OutputFile(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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#include "IO.h"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user