Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array compound generation first pass #57

Open
wants to merge 11 commits into
base: rewrite
Choose a base branch
from
Open

Conversation

BrettRToomey
Copy link
Contributor

@BrettRToomey BrettRToomey commented Aug 13, 2019

I did a first pass but still would like to clean up a little. Please feel free to nitpick this

src/checker.c Outdated Show resolved Hide resolved
src/llvm.cpp Outdated
@@ -1732,16 +1749,26 @@ void emit_decl_var(IRContext *self, Decl *decl) {
return;
}
}
Type *type = llvm_type(self, sym->type);

Type *type = llvm_type(self, sym->type, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like I need the true here for global variables but I'm not exactly sure if I need it for all cases. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense for array's, a Global Variable needs the raw type so it know's how much space to reserve, this actually will cause an error for functions though, llvm_type will return a FunctionType for functions, this will cause an assert in LLVM when it attempts to work out a size for the global.
I guess maybe we need llvm_type's hide behind pointer to be a mask maybe? Something like llvm_type(self, sym->type, ARRAY | STRUCT) and in emit_expr_func we would have llvm_type(self, type, FUNCTION)

@BrettRToomey
Copy link
Contributor Author

I'm so sorry about the whitespace... Looks like Xcode is mixing tabs and spaces... Will fix later

@@ -1856,7 +1885,7 @@ void emit_decl_val(IRContext *self, Decl *decl) {
arrpush(self->symbols, sym);
Value *value = emit_expr(self, decl->dval.val).val;
arrpop(self->symbols);
if (isa<Function>(value)) {
if (isa<Function>(value) || isa<StructType>((Type *)value)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is bad

src/llvm.cpp Outdated
@@ -1732,16 +1749,26 @@ void emit_decl_var(IRContext *self, Decl *decl) {
return;
}
}
Type *type = llvm_type(self, sym->type);

Type *type = llvm_type(self, sym->type, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense for array's, a Global Variable needs the raw type so it know's how much space to reserve, this actually will cause an error for functions though, llvm_type will return a FunctionType for functions, this will cause an assert in LLVM when it attempts to work out a size for the global.
I guess maybe we need llvm_type's hide behind pointer to be a mask maybe? Something like llvm_type(self, sym->type, ARRAY | STRUCT) and in emit_expr_func we would have llvm_type(self, type, FUNCTION)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants