Verified Commit 23e09611 authored by Camil Staps's avatar Camil Staps 🚀

WIP on bytecode stripping

parent aa514a74
......@@ -50,14 +50,14 @@ serialize_for_interpretation graph bcfile w
| isError bytecode = abort "Failed to read the bytecode file\n"
# bytecode = fromOk bytecode
#! bytecodep = strip_bytecode bytecode {#symbol_name di mods \\ di <-: descs}
#! bytecode = derefString bytecodep
#! (len,bytecodep) = strip_bytecode bytecode {#symbol_name di mods \\ di <-: descs}
#! bytecode = derefCharArray bytecodep len
| free_to_false bytecodep = abort "cannot happen\n"
# rec =
{ graph = graph
, descinfo = descs
, modules = mods
, descinfo = {}//descs // TODO
, modules = {}//mods
, bytecode = bytecode
}
= (rec, w)
......@@ -71,7 +71,7 @@ where
where
PREFIX_D = 4
strip_bytecode :: !String !{#String} -> Pointer
strip_bytecode :: !String !{#String} -> (!Int, !Pointer)
strip_bytecode bytecode descriptors = code {
ccall strip_bytecode "sA:VIp"
}
......
......@@ -126,7 +126,7 @@ parseLine`{|CONS of d|} fx = \0 line -> case d.gcd_name of
first_char = case instr.[0] of
'I' -> '\t' // Instruction
'A' -> '.' // Annotation
parseLine`{|OBJECT|} fx = \i s -> appFst OBJECT <$> fx i s
parseLine`{|OBJECT|} fx = \i s -> appFst (\x->OBJECT x) <$> fx i s
parseLine`{|EITHER|} fl fr = \i s -> case fl i s of
Just (l,i) -> Just (LEFT l,i)
Nothing -> case fr i s of
......
......@@ -3830,7 +3830,7 @@ struct label *code_descriptor
int n;
/* Resolve descriptor address */
store_data_l(-1); /* TODO check that this is correct in all cases */
store_data_l(-1);
if (list_code) {
printf("\t.data\n");
......
......@@ -26,7 +26,7 @@ void init_parser(struct parser *state
, int host_symbols_n, int host_symbols_string_length, char *host_symbols
#endif
) {
state->state = PS_init_code;
state->state = PS_init;
state->program = safe_calloc(1, sizeof(struct program));
state->ptr = 0;
......@@ -112,25 +112,7 @@ void next_state(struct parser *state) {
state->symbols_ptr = 0;
switch (state->state) {
case PS_init_code:
state->state = PS_init_words_in_strings;
return;
case PS_init_words_in_strings:
state->state = PS_init_strings;
return;
case PS_init_strings:
state->state = PS_init_data;
return;
case PS_init_data:
state->state = PS_init_symbol_table;
return;
case PS_init_symbol_table:
state->state = PS_init_code_reloc;
return;
case PS_init_code_reloc:
state->state = PS_init_data_reloc;
return;
case PS_init_data_reloc:
case PS_init:
state->state = PS_code;
#ifdef LINKER
if (state->code_size > 0)
......@@ -209,7 +191,7 @@ int parse_program(struct parser *state, struct char_provider *cp) {
while (state->state != PS_end) {
switch (state->state) {
case PS_init_code:
case PS_init:
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
return 1;
#ifdef LINKER
......@@ -218,9 +200,7 @@ int parse_program(struct parser *state, struct char_provider *cp) {
state->program->code_size = elem32;
#endif
state->program->code = safe_malloc(sizeof(BC_WORD) * elem32);
next_state(state);
break;
case PS_init_words_in_strings:
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
return 1;
#ifdef LINKER
......@@ -230,9 +210,7 @@ int parse_program(struct parser *state, struct char_provider *cp) {
state->words_in_strings = elem32;
# endif
#endif
next_state(state);
break;
case PS_init_strings:
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
return 1;
state->strings_size = elem32;
......@@ -241,9 +219,7 @@ int parse_program(struct parser *state, struct char_provider *cp) {
state->strings = safe_malloc(sizeof(uint32_t*) * (elem32+1));
state->strings[elem32] = 0;
#endif
next_state(state);
break;
case PS_init_data:
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
return 1;
#ifdef LINKER
......@@ -258,9 +234,7 @@ int parse_program(struct parser *state, struct char_provider *cp) {
# endif
state->program->data = safe_malloc(sizeof(BC_WORD) * state->program->data_size);
#endif
next_state(state);
break;
case PS_init_symbol_table:
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
return 1;
state->program->symbol_table_size = elem32;
......@@ -268,18 +242,15 @@ int parse_program(struct parser *state, struct char_provider *cp) {
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
return 1;
state->program->symbols = safe_malloc(elem32 + state->program->symbol_table_size);
next_state(state);
break;
case PS_init_code_reloc:
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
return 1;
state->code_reloc_size = elem32;
next_state(state);
break;
case PS_init_data_reloc:
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
return 1;
state->data_reloc_size = elem32;
next_state(state);
break;
case PS_code: {
......@@ -348,7 +319,6 @@ int parse_program(struct parser *state, struct char_provider *cp) {
state->program->code[state->ptr++] = (BC_WORD) elem16 << IF_INT_64_OR_32(48, 16);
#endif
break;
case 'd': /* Descriptor */
case 'l': /* Label */
case 'S': /* String label */
case 's': /* String label */
......@@ -574,6 +544,8 @@ int parse_program(struct parser *state, struct char_provider *cp) {
return 1;
struct symbol *sym = &state->program->symbol_table[sym_i];
EPRINTF("code reloc %d %d %ld\n",code_i,sym_i,sym->offset);
#ifdef LINKER
struct label *label;
if (sym->name[0] == '\0')
......
......@@ -5,13 +5,7 @@
#include "util.h"
enum parse_state {
PS_init_code,
PS_init_words_in_strings,
PS_init_strings,
PS_init_data,
PS_init_symbol_table,
PS_init_code_reloc,
PS_init_data_reloc,
PS_init,
PS_code,
PS_strings,
PS_data,
......
This diff is collapsed.
......@@ -5,8 +5,8 @@
struct clean_string {
void *cs_desc;
BC_WORD cs_size;
char cs_characters[0];
const char cs_characters[0];
};
void strip_bytecode(uint32_t *bytecode, struct clean_string **descriptors,
uint32_t *result_size, uint32_t **result);
uint32_t *result_size, char **result);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment