Basic text reading completed.
This commit is contained in:
1 parent
1bde438a57
commit
8390a0253e
5 files changed
+69
-5
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 20)
|
||||
include_directories(include)
|
||||
|
||||
add_library(r8asm_core src/r8asm_core.cc src/r8asm_asm.cc
|
||||
src/r8asm_macro.cc)
|
||||
src/r8asm_macro.cc src/r8asm_parse.cc)
|
||||
|
||||
add_executable(r8asm_test tests/r8_test.cc)
|
||||
target_link_libraries(r8asm_test r8asm_core)
|
||||
@@ -2,6 +2,7 @@
|
||||
#define R8ASM
|
||||
|
||||
#include "r8asm/r8asm_asm.hh" // IWYU pragma: export
|
||||
#include "r8asm_macro.hh" // IWYU pragma: export
|
||||
#include "r8asm_macro.hh" // IWYU pragma: export
|
||||
#include "r8asm_parse.hh" // IWYU pragma: export
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef R8ASM_PARSE
|
||||
#define R8ASM_PARSE
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define EMPTY_CHARS (" \t\n\r\f\v")
|
||||
|
||||
struct r8asm_src {
|
||||
std::vector<std::vector<std::string>> raw_src;
|
||||
};
|
||||
|
||||
r8asm_src read_src(std::string filename);
|
||||
|
||||
void include_src(r8asm_src);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "r8asm/r8asm_parse.hh"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
void r8asm_trim(std::string &str) {
|
||||
auto start = str.find_first_not_of(EMPTY_CHARS);
|
||||
|
||||
if (!(start ==
|
||||
std::string::npos)) { // The string isn't filled with empty chars.
|
||||
auto tmp_end = str.find_last_not_of(EMPTY_CHARS);
|
||||
str = str.substr(start, tmp_end - start + 1);
|
||||
} else
|
||||
str = "";
|
||||
}
|
||||
|
||||
std::string r8asm_peel(std::string &str) {
|
||||
r8asm_trim(str);
|
||||
auto end = str.find_first_of(EMPTY_CHARS);
|
||||
|
||||
if (end != std::string::npos) {
|
||||
std::string tmp_str = str.substr(0, end);
|
||||
str = str.substr(end);
|
||||
r8asm_trim(str);
|
||||
return (tmp_str);
|
||||
} else {
|
||||
std::string tmp_str = str;
|
||||
str = "";
|
||||
return (tmp_str);
|
||||
}
|
||||
}
|
||||
|
||||
r8asm_src read_src(std::string filename) {
|
||||
r8asm_src out_src;
|
||||
|
||||
std::ifstream ifile;
|
||||
std::string line_buffer;
|
||||
ifile.open(filename, std::ios::in);
|
||||
while (std::getline(ifile, line_buffer)) {
|
||||
auto comment = line_buffer.find_first_of(';');
|
||||
if (comment != std::string::npos)
|
||||
line_buffer = line_buffer.substr(0, comment);
|
||||
std::vector<std::string> ins_buffer;
|
||||
while (!line_buffer.empty())
|
||||
ins_buffer.push_back(r8asm_peel(line_buffer));
|
||||
out_src.raw_src.push_back(ins_buffer);
|
||||
}
|
||||
ifile.close();
|
||||
return (out_src);
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "r8asm/r8asm.hh"
|
||||
#include "r8asm/r8asm_asm.hh"
|
||||
#include "r8asm/r8asm_core.hh"
|
||||
#include "r8asm/r8asm_macro.hh"
|
||||
|
||||
int main() {
|
||||
std::vector<R8Instruction> ins = {
|
||||
|
||||
Reference in new issue
Block a user