Browse Source

Add sort for global types and procedures

gingerBill 1 year ago
parent
commit
0f664893dd
2 changed files with 25 additions and 1 deletions
  1. 1 1
      src/checker.cpp
  2. 24 0
      src/llvm_backend.cpp

+ 1 - 1
src/checker.cpp

@@ -519,7 +519,7 @@ gb_internal Entity *scope_insert_no_mutex(Scope *s, Entity *entity) {
 }
 }
 
 
 
 
-GB_COMPARE_PROC(entity_variable_pos_cmp) {
+gb_internal GB_COMPARE_PROC(entity_variable_pos_cmp) {
 	Entity *x = *cast(Entity **)a;
 	Entity *x = *cast(Entity **)a;
 	Entity *y = *cast(Entity **)b;
 	Entity *y = *cast(Entity **)b;
 
 

+ 24 - 0
src/llvm_backend.cpp

@@ -1321,6 +1321,24 @@ gb_internal WORKER_TASK_PROC(lb_generate_procedures_and_types_per_module) {
 	return 0;
 	return 0;
 }
 }
 
 
+gb_internal GB_COMPARE_PROC(llvm_global_entity_cmp) {
+	Entity *x = *cast(Entity **)a;
+	Entity *y = *cast(Entity **)b;
+	if (x == y) {
+		return 0;
+	}
+	if (x->kind != y->kind) {
+		return cast(i32)(x->kind - y->kind);
+	}
+
+	i32 cmp = 0;
+	cmp = token_pos_cmp(x->token.pos, y->token.pos);
+	if (!cmp) {
+		return cmp;
+	}
+	return cmp;
+}
+
 gb_internal void lb_create_global_procedures_and_types(lbGenerator *gen, CheckerInfo *info, bool do_threading) {
 gb_internal void lb_create_global_procedures_and_types(lbGenerator *gen, CheckerInfo *info, bool do_threading) {
 	auto *min_dep_set = &info->minimum_dependency_set;
 	auto *min_dep_set = &info->minimum_dependency_set;
 
 
@@ -1377,6 +1395,12 @@ gb_internal void lb_create_global_procedures_and_types(lbGenerator *gen, Checker
 		}
 		}
 	}
 	}
 
 
+	for (auto const &entry : gen->modules) {
+		lbModule *m = entry.value;
+		gb_sort_array(m->global_types_to_create.data, m->global_types_to_create.count, llvm_global_entity_cmp);
+		gb_sort_array(m->global_procedures_to_create.data, m->global_procedures_to_create.count, llvm_global_entity_cmp);
+	}
+
 	if (do_threading) {
 	if (do_threading) {
 		for (auto const &entry : gen->modules) {
 		for (auto const &entry : gen->modules) {
 			lbModule *m = entry.value;
 			lbModule *m = entry.value;