composeStruct unpacks registers into struct fields.
(structType *types.Struct, input *ssa.Parameter, i int, offset int)
| 8 | |
| 9 | // composeStruct unpacks registers into struct fields. |
| 10 | func (f *Function) composeStruct(structType *types.Struct, input *ssa.Parameter, i int, offset int) (*ssa.Struct, int) { |
| 11 | fields := make([]ssa.Value, 0, len(structType.Fields)) |
| 12 | |
| 13 | if structType.Size() > 16 { |
| 14 | for _, field := range structType.Fields { |
| 15 | param := &ssa.Parameter{ |
| 16 | Index: uint8(offset + i), |
| 17 | Name: input.Name + "." + field.Name, |
| 18 | Typ: field.Type, |
| 19 | Tokens: input.Tokens, |
| 20 | Source: input.Source, |
| 21 | } |
| 22 | |
| 23 | f.Append(param) |
| 24 | f.Block().Identify(param.Name, param) |
| 25 | fields = append(fields, param) |
| 26 | offset++ |
| 27 | } |
| 28 | |
| 29 | structure := f.makeStruct(structType, fields, input.Source) |
| 30 | return structure, offset - 1 |
| 31 | } |
| 32 | |
| 33 | var ( |
| 34 | param *ssa.Parameter |
| 35 | size = 8 |
| 36 | ) |
| 37 | |
| 38 | for _, field := range structType.Fields { |
| 39 | fieldSize := field.Type.Size() |
| 40 | |
| 41 | if size+fieldSize > 8 { |
| 42 | param = &ssa.Parameter{ |
| 43 | Index: uint8(offset + i), |
| 44 | Typ: field.Type, |
| 45 | Tokens: input.Tokens, |
| 46 | Source: input.Source, |
| 47 | } |
| 48 | |
| 49 | f.Append(param) |
| 50 | offset++ |
| 51 | size = 0 |
| 52 | } |
| 53 | |
| 54 | var fieldValue ssa.Value |
| 55 | |
| 56 | if size == 0 && fieldSize == 8 { |
| 57 | fieldValue = param |
| 58 | } else { |
| 59 | var shifted ssa.Value |
| 60 | |
| 61 | if size > 0 { |
| 62 | param.Typ = types.UInt |
| 63 | sizeValue := f.Append(&ssa.Int{Int: size * 8}) |
| 64 | shifted = f.Append(&ssa.BinaryOp{Op: token.Shr, Left: param, Right: sizeValue}) |
| 65 | } else { |
| 66 | shifted = param |
| 67 | } |
no test coverage detected