cl: fix package patching

This commit is contained in:
Li Jie
2024-11-25 11:17:06 +08:00
parent 2f5c033f09
commit e732e5158e
3 changed files with 35 additions and 18 deletions

View File

@@ -105,6 +105,8 @@ type aProgram struct {
sizes types.Sizes // provided by Go compiler
gocvt goTypes
patchType func(types.Type) types.Type
rt *types.Package
rtget func() *types.Package
@@ -233,6 +235,17 @@ func NewProgram(target *Target) Program {
}
}
func (p Program) SetPatch(patchType func(types.Type) types.Type) {
p.patchType = patchType
}
func (p Program) patch(typ types.Type) types.Type {
if p.patchType != nil {
return p.patchType(typ)
}
return typ
}
// SetRuntime sets the runtime.
// Its type can be *types.Package or func() *types.Package.
func (p Program) SetRuntime(runtime any) {

View File

@@ -429,7 +429,7 @@ func (p Program) toLLVMFields(raw *types.Struct) (fields []llvm.Type) {
if n > 0 {
fields = make([]llvm.Type, n)
for i := 0; i < n; i++ {
fields[i] = p.rawType(raw.Field(i).Type()).ll
fields[i] = p.rawType(p.patch(raw.Field(i).Type())).ll
}
}
return
@@ -443,7 +443,7 @@ func (p Program) toLLVMTypes(t *types.Tuple, n int) (ret []llvm.Type) {
if n > 0 {
ret = make([]llvm.Type, n)
for i := 0; i < n; i++ {
ret[i] = p.rawType(t.At(i).Type()).ll
ret[i] = p.rawType(p.patch(t.At(i).Type())).ll
}
}
return