wip: dictionary disassembly

llvm
Clyne 1 year ago
parent d36bb13f52
commit 114b825c35
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -19,11 +19,15 @@
#include "alee.hpp" #include "alee.hpp"
#include "memdict.hpp" #include "memdict.hpp"
#include <algorithm>
#include <charconv> #include <charconv>
#include <cstdio>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
static void compile(State&);
static bool okay = false; static bool okay = false;
static void readchar(State&); static void readchar(State&);
@ -107,6 +111,9 @@ void user_sys(State& state)
case 4: // load case 4: // load
load(state); load(state);
break; break;
case 5: // compile
compile(state);
break;
default: default:
break; 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);
}

Loading…
Cancel
Save