Verified Commit 671d5580 authored by Camil Staps's avatar Camil Staps 🚀

Revert 1a355d38 to restore new_label(_at_offset), because it helps to reduce...

Revert 1a355d38 to restore new_label(_at_offset), because it helps to reduce the number of unnamed labels
parent 0185ae4d
Pipeline #21893 passed with stages
in 16 minutes and 41 seconds
......@@ -176,10 +176,19 @@ struct label *enter_label(char *label_name) {
return new_label_p;
}
struct label *new_label_at_offset(uint32_t offset) {
char name[16];
snprintf(name, 16, "i%x", offset);
name[15] = '\0';
struct label *label = enter_label(name);
label->label_offset = offset;
return label;
}
int internal_label_id = 0;
struct label *new_internal_label(void) {
char label_name[14];
sprintf(label_name,"_internal%d",internal_label_id++);
sprintf(label_name,"_i_%d%c",internal_label_id++,'\0');
struct label *label = enter_label(label_name);
return label;
}
......
......@@ -29,7 +29,7 @@ void add_code_and_data_offsets(void);
struct label *enter_label(char *label_name);
struct label *new_internal_label(void);
struct label *new_label(uint32_t offset);
struct label *new_label_at_offset(uint32_t offset);
void make_label_global(struct label *label);
struct relocation *add_code_relocation(struct label *label, uint32_t offset);
struct relocation *add_data_relocation(struct label *label, uint32_t offset);
......
......@@ -633,10 +633,9 @@ int parse_program(struct parser *state, struct char_provider *cp) {
#ifdef LINKER
struct label *label;
if (sym->name[0] == '\0') {
label = new_internal_label();
label->label_offset = sym->offset;
} else
if (sym->name[0] == '\0')
label = new_label_at_offset(sym->offset);
else
label = enter_label(sym->name);
add_code_relocation(label, code_i + state->code_offset);
#else
......@@ -662,10 +661,9 @@ int parse_program(struct parser *state, struct char_provider *cp) {
#ifdef LINKER
struct label *label;
if (sym->name[0] == '\0') {
label = new_internal_label();
label->label_offset = sym->offset;
} else
if (sym->name[0] == '\0')
label = new_label_at_offset(sym->offset);
else
label = enter_label(sym->name);
add_data_relocation(label, data_i + state->data_offset);
#else
......
......@@ -379,7 +379,7 @@ static void activate_label(struct s_label *label) {
if (export_label(lab->name))
make_label_global(lab->bcgen_label);
} else
lab->bcgen_label=new_internal_label();
lab->bcgen_label=new_label_at_offset(pgrm->code_size<<2);
} else if (lab->bcgen_label->label_offset!=-1 && lab->bcgen_label->label_offset!=(pgrm->code_size<<2)) {
EPRINTF("Error: overwriting label '%s'\n",lab->bcgen_label->label_name);
EXIT(NULL,1);
......
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