MCPcopy Create free account
hub / github.com/google/gapid / buildModule

Method buildModule

gapil/compiler/module.go:29–128  ·  view source on GitHub ↗

buildModule builds the output module definition.

()

Source from the content-addressed store, hash-verified

27
28// buildModule builds the output module definition.
29func (c *C) buildModule() {
30 apiModuleTy := c.T.Struct("module_api",
31 codegen.Field{Name: "globals_offset", Type: c.T.Uint64},
32 codegen.Field{Name: "globals_size", Type: c.T.Uint64},
33 codegen.Field{Name: "num_cmds", Type: c.T.Uint32},
34 codegen.Field{Name: "cmds", Type: c.T.VoidPtrPtr},
35 )
36 symbolTy := c.T.Struct("symbol",
37 codegen.Field{Name: "name", Type: c.T.Pointer(c.T.Uint8)},
38 codegen.Field{Name: "addr", Type: c.T.VoidPtr},
39 )
40 moduleTy := c.T.Struct("module",
41 codegen.Field{Name: "create_context", Type: c.T.Pointer(c.ctx.create.Type)},
42 codegen.Field{Name: "destroy_context", Type: c.T.Pointer(c.ctx.destroy.Type)},
43 codegen.Field{Name: "globals_size", Type: c.T.Uint64},
44 codegen.Field{Name: "num_apis", Type: c.T.Uint32},
45 codegen.Field{Name: "apis", Type: c.T.Pointer(apiModuleTy)},
46 codegen.Field{Name: "num_symbols", Type: c.T.Uint32},
47 codegen.Field{Name: "symbols", Type: c.T.Pointer(symbolTy)},
48 )
49
50 apiMaxIndex := 0
51 for _, api := range c.APIs {
52 if apiMaxIndex < int(api.Index) {
53 apiMaxIndex = int(api.Index)
54 }
55 }
56
57 apis := make([]codegen.Const, apiMaxIndex+1)
58 for i := range apis {
59 apis[i] = c.M.Zero(apiModuleTy)
60 }
61
62 for _, api := range c.APIs {
63 commands := make([]*codegen.Function, len(api.Functions))
64
65 for i, f := range api.Functions {
66 commands[i] = c.commands[f]
67 }
68
69 cmdTbl := c.M.
70 Global(api.Name()+"-cmd-tbl", c.M.Array(commands, c.T.VoidPtr)).
71 SetConstant(true).
72 Cast(c.T.VoidPtr)
73
74 apis[api.Index] = c.M.ConstStruct(
75 apiModuleTy, map[string]interface{}{
76 "globals_offset": c.M.OffsetOf(c.T.Globals, api.Name()),
77 "globals_size": c.M.SizeOf(c.T.Globals.Field(api.Name()).Type),
78 "num_cmds": len(commands),
79 "cmds": cmdTbl.Cast(c.T.VoidPtrPtr),
80 },
81 )
82 }
83
84 apiTbl := c.M.
85 Global("api-tbl", c.M.Array(apis, apiModuleTy)).
86 SetConstant(true)

Callers 1

compileMethod · 0.95

Calls 15

StructMethod · 0.80
SetConstantMethod · 0.80
ConstStructMethod · 0.80
OffsetOfMethod · 0.80
LinkPublicMethod · 0.80
NameMethod · 0.65
SliceMethod · 0.65
PointerMethod · 0.45
ZeroMethod · 0.45
CastMethod · 0.45
GlobalMethod · 0.45
ArrayMethod · 0.45

Tested by

no test coverage detected