MCPcopy Create free account
hub / github.com/decomp/decomp / goTypeDef

Method goTypeDef

cmd/ll2go/type.go:22–117  ·  view source on GitHub ↗

goTypeDef returns the definitions of the given LLVM IR type as a corresponding Go type.

(t irtypes.Type)

Source from the content-addressed store, hash-verified

20// goTypeDef returns the definitions of the given LLVM IR type as a
21// corresponding Go type.
22func (d *decompiler) goTypeDef(t irtypes.Type) ast.Expr {
23 switch t := t.(type) {
24 case *irtypes.VoidType:
25 // The void type is only valid as a function return type in LLVM IR, or as
26 // part of a call instruction to a void function, or a ret instruction
27 // from a void function.
28 //
29 // Each of these cases will be handled specifically to take consideration
30 // to void types.
31 panic("unexpected void type")
32 case *irtypes.FuncType:
33 params := &ast.FieldList{}
34 for _, p := range t.Params {
35 param := &ast.Field{
36 Type: d.goType(p.Typ),
37 }
38 if len(p.Name) > 0 {
39 param.Names = append(param.Names, d.localIdent(p.Name))
40 }
41 params.List = append(params.List, param)
42 }
43 var results *ast.FieldList
44 if !irtypes.Equal(t.Ret, irtypes.Void) {
45 result := &ast.Field{
46 Type: d.goType(t.Ret),
47 }
48 results = &ast.FieldList{
49 List: []*ast.Field{result},
50 }
51 }
52 // TODO: Handle t.Variadic.
53 return &ast.FuncType{
54 Params: params,
55 Results: results,
56 }
57 case *irtypes.IntType:
58 d.intSizes[t.Size] = true
59 return &ast.Ident{
60 Name: fmt.Sprintf("int%d", t.Size),
61 }
62 case *irtypes.FloatType:
63 switch t.Kind {
64 case irtypes.FloatKindIEEE_32:
65 return ast.NewIdent("float32")
66 case irtypes.FloatKindIEEE_64:
67 return ast.NewIdent("float64")
68 case irtypes.FloatKindIEEE_16, irtypes.FloatKindIEEE_128, irtypes.FloatKindDoubleExtended_80, irtypes.FloatKindDoubleDouble_128:
69 // TODO: Add proper support for non-builtin float types.
70 return ast.NewIdent("float64")
71 default:
72 panic(fmt.Sprintf("support for floating-point kind %v not yet implemented", t.Kind))
73 }
74 case *irtypes.PointerType:
75 return &ast.StarExpr{
76 X: d.goType(t.Elem),
77 }
78 case *irtypes.VectorType:
79 return &ast.ArrayType{

Callers 2

goTypeMethod · 0.95
typeDefMethod · 0.95

Calls 2

goTypeMethod · 0.95
localIdentMethod · 0.95

Tested by

no test coverage detected