-
Notifications
You must be signed in to change notification settings - Fork 79
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
How to generate ir for embedded struct? #232
Comments
From my understanding, embedded struct is a field that got an implicit name, so you insert reference to A and give a generated name. |
yes, I understand, but how to write the code there, it is a type of types.Var, so what if I have a types.Struct? |
I believe you can use the "variable" in Go as instance of "type" |
in fact, not that easy. the variable in Go has type *types.Struct but the input needs to be a *types.Var, types.Var includes types.object and types.object include golang "Type", but not a types.Struct, so I have no idea about how to input the parameters. Or if you can write down the code. |
m := ir.NewModule()
foo := m.NewTypeDef("foo", types.NewStruct(types.I32))
_ = m.NewTypeDef("bar", types.NewStruct(foo))
main := m.NewFunc("main", types.I32)
{
entry := main.NewBlock("")
entry.NewRet(constant.NewInt(types.I32, 0))
}
fmt.Println(m) output %foo = type { i32 }
%bar = type { %foo }
define i32 @main() {
0:
ret i32 0
} |
You can also use %foo = type { i32 }
%bar = type { %foo* }
define i32 @main() {
0:
ret i32 0
} |
I didn't find about anything to process embedded struct, such as
type A struct{
value int
}
type B struct{
a A
}
what should I fill in " b := types.NewStruct(/what to fill here?/) "
The text was updated successfully, but these errors were encountered: