-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(structs): generate type ir for structs
- Loading branch information
1 parent
74bbd31
commit c5df772
Showing
21 changed files
with
271 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//use crate::ir::module::Types; | ||
use crate::ir::try_convert_any_to_basic; | ||
use crate::IrDatabase; | ||
use inkwell::types::{AnyTypeEnum, BasicTypeEnum}; | ||
|
||
pub(super) fn gen_struct_decl(db: &impl IrDatabase, s: hir::Struct) { | ||
if let AnyTypeEnum::StructType(struct_type) = db.type_ir(s.ty(db)) { | ||
if struct_type.is_opaque() { | ||
let field_types: Vec<BasicTypeEnum> = s | ||
.fields(db) | ||
.iter() | ||
.map(|field| { | ||
let field_type = field.ty(db); | ||
try_convert_any_to_basic(db.type_ir(field_type)) | ||
.expect("could not convert field type") | ||
}) | ||
.collect(); | ||
|
||
struct_type.set_body(&field_types, false); | ||
} | ||
} else { | ||
unreachable!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
source: crates/mun_codegen/src/test.rs | ||
expression: "struct Bar(float, int, bool, Foo);\nstruct Foo { a: int };\nstruct Baz;\nfn foo() {\n let a: Foo;\n let b: Bar;\n let c: Baz;\n}" | ||
--- | ||
; ModuleID = 'main.mun' | ||
source_filename = "main.mun" | ||
|
||
%Baz = type {} | ||
%Bar = type { double, i64, i1, %Foo } | ||
%Foo = type { i64 } | ||
|
||
define void @foo() { | ||
body: | ||
%c = alloca %Baz | ||
%b = alloca %Bar | ||
%a = alloca %Foo | ||
ret void | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.