diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2023-06-02 09:59:53 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2023-06-02 09:59:53 -0400 |
commit | 114b825c355cc522f9c7c57176fb27e2ced8165f (patch) | |
tree | 7e18839035a1a545cc0802c8e6ba4e8c1fd8fb6b | |
parent | d36bb13f52b3899fd0f57e38f00d97e2c3a0f627 (diff) |
wip: dictionary disassemblyllvm
-rw-r--r-- | alee.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -19,11 +19,15 @@ #include "alee.hpp" #include "memdict.hpp" +#include <algorithm> #include <charconv> +#include <cstdio> #include <fstream> #include <iostream> #include <vector> +static void compile(State&); + static bool okay = false; static void readchar(State&); @@ -107,6 +111,9 @@ void user_sys(State& state) case 4: // load load(state); break; + case 5: // compile + compile(state); + break; default: break; } @@ -158,3 +165,37 @@ void parseFile(State& state, std::istream& file) } } +// Prints all compiled words, their start addresses, and their "disassembly". +// Hopefully, it won't be too difficult to translate these into LLVM IR. +void compile(State& state) +{ + auto& dict = state.dict; + + Addr latest = dict.latest(); + Addr attr = 0; + do { + Addr oldlen = attr >> 6; + latest -= oldlen; + + attr = dict.read(latest); + auto lw = Word::fromLength(latest + sizeof(Cell), attr & 0x1F); + + if (!(attr & Dictionary::Immediate)) { + Addr start = dict.getexec(latest); + Addr len = oldlen; + len -= start; + len += latest; + + std::for_each(lw.begin(&dict), lw.end(&dict), putchar); + std::cout << " @ " << start << std::endl; + + for (Addr i = 0; i < len; i += sizeof(Cell)) { + Addr addr = start; + addr += i; + std::cout << '\t' << (Addr)dict.read(addr) << ' '; + } + std::cout << std::endl; + } + } while (latest != Dictionary::Begin); +} + |