From c09c7cdd875eeebb75db5c6f4c52c4c7b1332fa1 Mon Sep 17 00:00:00 2001 From: gabrielbosio Date: Thu, 27 Jul 2023 19:06:58 -0300 Subject: [PATCH] Start implementing relocation Start with nested for loops that iterate over segments and cells. --- src/cairo_runner.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/cairo_runner.c b/src/cairo_runner.c index 8264c4f..f3dcb79 100644 --- a/src/cairo_runner.c +++ b/src/cairo_runner.c @@ -1,8 +1,11 @@ #include "cairo_runner.h" #include "clist.h" +#include "memory.h" #include "program.h" #include "relocatable.h" #include "vm.h" +#include +#include cairo_runner runner_new(struct program program) { virtual_machine vm = vm_new(); @@ -84,4 +87,18 @@ relocatable runner_initialize(cairo_runner *runner) { return end; } -void runner_relocate_memory(cairo_runner *runner) { (void)runner; } +void runner_relocate_memory(cairo_runner *runner) { + assert(runner->relocated_memory->count(runner->relocated_memory) == 0); + relocated_memory_cell first_cell = {.memory_value = {.none = 0}, .is_some = false}; + runner->relocated_memory->add(runner->relocated_memory, &first_cell); + + int num_segments = runner->vm.memory.num_segments; + for (int i = 0; i < num_segments; i++) { + CList *segment = runner->vm.memory.data->at(runner->vm.memory.data, i); + int segment_size = segment->count(segment); + for (int j = 0; j < segment_size; j++) { + memory_cell *cell = segment->at(segment, j); + (void)cell; + } + } +}