Skip to content

Commit

Permalink
Compilers: clean up pointer handling in codegen (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Jan 15, 2025
1 parent 8a7df41 commit 0f631b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
10 changes: 2 additions & 8 deletions bootstrap_compiler/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,8 @@ static LLVMTypeRef codegen_type(const Type *type)
int n = type->data.classdata.fields.len;

LLVMTypeRef *flat_elems = malloc(sizeof(flat_elems[0]) * n); // NOLINT
for (int i = 0; i < n; i++) {
// Treat all pointers inside structs as if they were void*.
// This allows structs to contain pointers to themselves.
if (type->data.classdata.fields.ptr[i].type->kind == TYPE_POINTER)
flat_elems[i] = codegen_type(voidPtrType);
else
flat_elems[i] = codegen_type(type->data.classdata.fields.ptr[i].type);
}
for (int i = 0; i < n; i++)
flat_elems[i] = codegen_type(type->data.classdata.fields.ptr[i].type);

// Combine together fields of the same union.
LLVMTypeRef *combined = malloc(sizeof(combined[0]) * n); // NOLINT
Expand Down
7 changes: 1 addition & 6 deletions compiler/codegen.jou
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ def codegen_class_type(type: Type*) -> LLVMType*:

flat_elems: LLVMType** = malloc(sizeof(flat_elems[0]) * n)
for i = 0; i < n; i++:
# Treat all pointers inside classes as if they were void*.
# This allows classes to contain pointers to themselves.
if type->classdata.fields[i].type->kind == TypeKind.Pointer:
flat_elems[i] = codegen_type(voidPtrType)
else:
flat_elems[i] = codegen_type(type->classdata.fields[i].type)
flat_elems[i] = codegen_type(type->classdata.fields[i].type)

# Combine together fields of the same union.
combined: LLVMType** = malloc(sizeof(combined[0]) * n)
Expand Down

0 comments on commit 0f631b2

Please sign in to comment.