mirror of
https://github.com/mlaux/gb6.git
synced 2025-04-27 20:42:35 +00:00
no idea how to write a JIT compiler but this seems like an ok start
This commit is contained in:
parent
5ed288eaa9
commit
a3efa63361
66
src/compiler68k.c
Normal file
66
src/compiler68k.c
Normal file
@ -0,0 +1,66 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
uint8_t out_code[1024];
|
||||
uint8_t memory[1024]; // ???
|
||||
uint32_t out_ptr;
|
||||
|
||||
struct basic_block {
|
||||
// in 68k space?
|
||||
void *start_address;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
// need some kind of map from gb address to struct basic_block?
|
||||
|
||||
uint8_t test_code[] = {
|
||||
0
|
||||
};
|
||||
|
||||
struct basic_block *compile_block(uint16_t src_address, uint8_t *gb_code)
|
||||
{
|
||||
uint32_t start = out_ptr;
|
||||
struct basic_block *bblock;
|
||||
|
||||
bblock = malloc(sizeof *bblock);
|
||||
bblock->start_address = out_code + start;
|
||||
|
||||
return bblock;
|
||||
}
|
||||
|
||||
void run_block(struct basic_block *bblock)
|
||||
{
|
||||
// calling convention? do i need to do this from asm?
|
||||
uint16_t jump_target = ((uint16_t (*)()) bblock->start_address)();
|
||||
}
|
||||
|
||||
// TODO
|
||||
void block_cache_add(uint16_t src_address, struct basic_block *bblock);
|
||||
struct basic_block *block_cache_get(uint16_t src_address);
|
||||
|
||||
// 1. compile each block ending in a jump
|
||||
// 2. turn the jump into a return
|
||||
// 3. add the compiled code to some kind of cache
|
||||
// 3. return back to check the cache and maybe compile the next block
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct basic_block *bblock;
|
||||
|
||||
bblock = compile_block(0, test_code);
|
||||
block_cache_add(0, bblock);
|
||||
|
||||
while (1) {
|
||||
uint16_t jump_target;
|
||||
|
||||
jump_target = ((uint16_t (*)()) bblock->start_address)();
|
||||
|
||||
bblock = block_cache_get(jump_target);
|
||||
if (!bblock) {
|
||||
bblock = compile_block(jump_target, test_code + jump_target);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user