Verified Commit 81f446dc authored by Camil Staps's avatar Camil Staps 🙂

Cleanup bcgen_instructions.c global label handling

parent fce45e72
......@@ -17,7 +17,6 @@ uint32_t last_d, last_jsr_with_d;
struct label_node *labels;
uint32_t label_id;
uint32_t global_label_count;
uint32_t global_label_string_count;
struct label *start_label=NULL;
......@@ -98,7 +97,6 @@ struct program *initialize_code(void) {
labels = NULL;
label_id = 0;
global_label_count = 0;
global_label_string_count = 0;
module_n = 0;
......@@ -172,6 +170,8 @@ struct label *enter_label(char *label_name) {
if (r==0) {
if (label_node_p->label_node_label_p->label_module_n>=0 && label_node_p->label_node_label_p->label_module_n!=module_n) {
if (label_node_p->label_node_label_p->label_offset<0) {
make_label_global (label_node_p->label_node_label_p);
return label_node_p->label_node_label_p;
} else {
struct label *new_label_p;
......@@ -359,9 +359,8 @@ struct label *new_internal_label(void) {
}
void make_label_global(struct label *label) {
if (label->label_module_n != -1) {
label->label_module_n = -1;
global_label_count++;
if (label->label_module_n>=0){
label->label_module_n=-1;
global_label_string_count+=strlen(label->label_name);
}
}
......@@ -1024,7 +1023,7 @@ struct word *add_add_arg_labels(void) {
char label_name[11];
sprintf(label_name,"_add_arg%d",i);
struct label *label = enter_label(label_name);
if (label->label_module_n != -1) {
if (label->label_module_n>=0){
make_label_global(label);
label->label_offset = pgrm.code_size<<2;
}
......@@ -1035,7 +1034,7 @@ struct word *add_add_arg_labels(void) {
fprintf(stderr,"Warning: currying of functions with more than 32 arguments is not implemented.\n");
struct label *label=enter_label("_add_arg");
if (label->label_module_n!=-1) {
if (label->label_module_n>=0){
make_label_global(label);
label->label_offset=pgrm.code_size<<2;
}
......@@ -4908,9 +4907,9 @@ static void count_and_renumber_labels(struct label_node *node, int *start, int *
if (label->label_offset < 0 || label->label_module_n < 0) {
label->label_id=*start;
*start=*start+1;
if (label->label_offset < 0) {
global_label_count++;
global_label_string_count+=strlen(label->label_name);
if (label->label_offset<0){
make_label_global (label);
fprintf (stderr,"Warning: undefined label %s\n",label->label_name);
}
} else {
label->label_id=*end;
......@@ -4993,7 +4992,7 @@ static void print_global_labels(struct label_node *node, FILE *program_file) {
print_global_labels(node->label_node_left, program_file);
struct label *label = node->label_node_label_p;
if (label->label_module_n == -1 || label->label_offset < 0) {
if (label->label_offset<0 || label->label_module_n<0){
fwrite(&label->label_offset, sizeof(label->label_offset), 1, program_file);
fprintf(program_file, "%s", label->label_name);
fputc('\0', program_file);
......@@ -5009,7 +5008,7 @@ static void print_local_labels(struct label_node *node, FILE *program_file) {
print_local_labels(node->label_node_right, program_file);
struct label *label = node->label_node_label_p;
if (!(label->label_module_n == - 1 || label->label_offset < 0)) {
if (!(label->label_offset<0 || label->label_module_n<0)){
fwrite(&label->label_offset, sizeof(label->label_offset), 1, program_file);
fputc('\0', program_file);
}
......
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