MCPcopy
hub / github.com/google/gvisor / CreateInputFile

Method CreateInputFile

tools/nvidia_driver_differ/parser/runner.go:60–110  ·  view source on GitHub ↗

CreateInputFile saves a list of structs for the runner to parse.

(info *nvproxy.DriverABIInfo)

Source from the content-addressed store, hash-verified

58
59// CreateInputFile saves a list of structs for the runner to parse.
60func (r *Runner) CreateInputFile(info *nvproxy.DriverABIInfo) error {
61 numNonUvm := len(info.FrontendInfos) + len(info.ControlInfos) + len(info.AllocationInfos)
62 numUvm := len(info.UvmInfos)
63 r.nonUVMIoctls = make([]nvproxy.IoctlName, 0, numNonUvm)
64 r.uvmIoctls = make([]nvproxy.IoctlName, 0, numUvm)
65 inputJSON := InputJSON{
66 Structs: make([]nvproxy.DriverStructName, 0, numNonUvm+numUvm),
67 Constants: make([]nvproxy.IoctlName, 0, numNonUvm+numUvm),
68 }
69
70 handleIoctlInfo := func(info nvproxy.IoctlInfo, isUVM bool) {
71 if info.Name == "" {
72 return
73 }
74 if isUVM {
75 r.uvmIoctls = append(r.uvmIoctls, info.Name)
76 } else {
77 r.nonUVMIoctls = append(r.nonUVMIoctls, info.Name)
78 }
79 // Add "GVISOR_" prefix to all constants; see WriteIncludeFile().
80 inputJSON.Constants = append(inputJSON.Constants, "GVISOR_"+info.Name)
81 for _, structDef := range info.Structs {
82 inputJSON.Structs = append(inputJSON.Structs, structDef.Name)
83 }
84 }
85 for _, info := range info.FrontendInfos {
86 handleIoctlInfo(info, false)
87 }
88 for _, info := range info.ControlInfos {
89 handleIoctlInfo(info, false)
90 }
91 for _, info := range info.AllocationInfos {
92 handleIoctlInfo(info, false)
93 }
94 for _, info := range info.UvmInfos {
95 handleIoctlInfo(info, true)
96 }
97
98 f, err := os.CreateTemp(r.dir, "input_*.json")
99 if err != nil {
100 return fmt.Errorf("failed to create temporary structs list: %w", err)
101 }
102 defer f.Close()
103
104 if err := json.NewEncoder(f).Encode(inputJSON); err != nil {
105 return fmt.Errorf("failed to write structs list to file: %w", err)
106 }
107
108 r.inputPath = f.Name()
109 return nil
110}
111
112// parseSourceFile runs driver_ast_parser on sourceFile for the structs listed in structsFile,
113// and returns the parsed JSON output.

Callers 2

MainFunction · 0.95
getDriverDefsFunction · 0.80

Calls 4

ErrorfMethod · 0.65
CloseMethod · 0.65
NameMethod · 0.65
EncodeMethod · 0.45

Tested by 1

getDriverDefsFunction · 0.64