-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 50432c4
Showing
15 changed files
with
5,379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required (VERSION 3.8) | ||
|
||
project ("dwarbf") | ||
|
||
add_subdirectory("dwarfas") | ||
add_subdirectory("dwarfter") | ||
add_subdirectory("dwarbf") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# dwarbf - A Brainfuck interpreter written in DWARF debug information | ||
|
||
Run the BF program with: | ||
|
||
```shell | ||
$ gdb --eval-command=starti --eval-command="p (int)&dwarbf_program" fib --batch | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add_executable (dwarbf "dwarbf.cpp") | ||
target_link_libraries(dwarbf PRIVATE dwarfas dwarfter) | ||
|
||
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/dwarbf.dw INTERPRETER_TEXT) | ||
file(TOUCH ${CMAKE_CURRENT_SOURCE_DIR}/dwarbf_interpreter.hpp.in) | ||
configure_file( | ||
${CMAKE_CURRENT_SOURCE_DIR}/dwarbf_interpreter.hpp.in | ||
${CMAKE_CURRENT_BINARY_DIR}/dwarbf_interpreter.gen.hpp | ||
@ONLY | ||
) | ||
|
||
target_include_directories(dwarbf PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <string> | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <dwarfas.hpp> | ||
#include <dwarfter.hpp> | ||
#include "dwarbf_interpreter.gen.hpp" | ||
|
||
void print_usage() { | ||
std::cerr << "Usage: dwarbf <input_file> [--run/--debug]\n"; | ||
} | ||
int main(int argc, const char** argv) { | ||
if (argc < 2 or !std::filesystem::exists(argv[1])) { | ||
print_usage(); | ||
return -1; | ||
} | ||
std::filesystem::path program_path = argv[1]; | ||
std::ifstream program_file(program_path); | ||
std::ostringstream program_text; | ||
program_text << program_file.rdbuf(); | ||
|
||
auto dwarf_program = dwas::assemble_dwarf_program(dwarbf::interpreter_text); | ||
auto load_segment = dwas::create_elf( | ||
dwarf_program, "dwarbf", | ||
program_text.str(), "dwarbf_program", | ||
program_path.replace_extension()); | ||
|
||
if (argc > 3) { | ||
print_usage(); | ||
return -1; | ||
} | ||
if (argc == 3) { | ||
if (std::string(argv[2]) == "--run" or std::string(argv[2]) == "--debug") { | ||
auto debug = std::string(argv[2]) == "--debug"; | ||
dwter::eval(load_segment, 0x08048000, 0x08048025, dwarf_program, debug); | ||
} | ||
else { | ||
print_usage(); | ||
return -1; | ||
} | ||
} | ||
} |
Oops, something went wrong.