Commit 6e2653e0 authored by Camil Staps's avatar Camil Staps 🍃

Labels can be stored as 2 bytes instead of 4, since we only store the offset

parent 8c2d131c
......@@ -338,7 +338,7 @@ struct relocation *add_data_relocation(struct label *label, uint32_t offset) {
#ifndef LINK_CLEAN_RUNTIME
void store_code_internal_label_value(struct label *label,uint32_t offset) {
add_code_relocation(label, pgrm.code_size);
store_code_elem(4, offset);
store_code_elem(2, offset);
}
void store_code_label_value(char *label_name,int32_t offset) {
......@@ -348,7 +348,7 @@ void store_code_label_value(char *label_name,int32_t offset) {
add_code_relocation(label, pgrm.code_size);
store_code_elem(4, offset);
store_code_elem(2, offset);
}
static void store_data_label_value_of_label(struct label *label,uint32_t offset) {
......
......@@ -365,12 +365,12 @@ int parse_program(struct parser *state, struct char_provider *cp) {
case 'C': /* CAF label */
case 'S': /* String label */
case 's': /* String label */
if (provide_chars(&elem32, sizeof(elem32), 1, cp) < 0)
if (provide_chars(&elem16, sizeof(elem16), 1, cp) < 0)
return 1;
#ifdef LINKER
store_code_elem(4, elem32);
store_code_elem(2, elem16);
#else
state->program->code[state->ptr++] = elem32;
state->program->code[state->ptr++] = elem16;
#endif
break;
case 'r': /* Real */
......
......@@ -27,4 +27,4 @@ typedef int64_t CleanInt;
#define BCGEN_INSTRUCTION_TABLE_SIZE 512
#define ABC_MAGIC_NUMBER 0x2a434241
#define ABC_VERSION 9
#define ABC_VERSION 10
......@@ -417,16 +417,16 @@ static void activate_label(struct s_label *label) {
add_label_to_queue(&labels[reloc->relocation_label]);
add_code_relocation(labels[reloc->relocation_label].bcgen_label, pgrm->code_size);
}
store_code_elem(4, *(uint32_t*)code_block);
code_block+=4;
store_code_elem(2, *(uint32_t*)code_block);
code_block+=2;
break;
case 'C': /* CAF label */
reloc=find_relocation_by_offset(code_relocations, code_reloc_size, ci);
add_label_to_queue(&labels[reloc->relocation_label]);
labels[reloc->relocation_label].label_type=DLT_CAF;
add_code_relocation(labels[reloc->relocation_label].bcgen_label, pgrm->code_size);
store_code_elem(4, *(uint32_t*)code_block);
code_block+=4;
store_code_elem(2, *(uint32_t*)code_block);
code_block+=2;
break;
case 'S': /* String with __STRING__ label */
case 's': /* Plain string label */
......@@ -434,8 +434,8 @@ static void activate_label(struct s_label *label) {
add_label_to_queue(&labels[reloc->relocation_label]);
labels[reloc->relocation_label].label_type=*type=='S' ? DLT_STRING_WITH_DESCRIPTOR : DLT_STRING;
add_code_relocation(labels[reloc->relocation_label].bcgen_label, pgrm->code_size);
store_code_elem(4, *(uint32_t*)code_block);
code_block+=4;
store_code_elem(2, *(uint32_t*)code_block);
code_block+=2;
break;
case 'r': /* Real */
case 'i': /* Int */
......@@ -522,13 +522,11 @@ void prepare_strip_bytecode(uint32_t *bytecode,
case 'n': /* Stack index */
case 'N': /* Stack index, optimised to byte width */
case 'a': /* Arity */
i+=2;
break;
case 'l': /* Label */
case 'C': /* CAF label */
case 'S': /* String label */
case 's': /* String label */
i+=4;
i+=2;
break;
case 'r': /* Real */
case 'i': /* Int */
......
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