parser

package
v0.0.0-...-75bfadc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 15 Imported by: 0

Documentation

Overview

Package parser contains functions for interfacing with driver_ast_parser.

Index

Constants

View Source
const GitRepoURL = "https://github.com/NVIDIA/open-gpu-kernel-modules.git"

GitRepoURL is the URL for the NVIDIA open-gpu-kernel-modules repo.

Variables

This section is empty.

Functions

func CreateCompileCommandsFile

func CreateCompileCommandsFile(dir string, config []ClangASTConfig) error

CreateCompileCommandsFile creates a new compile_commands.json file in the given directory, and writes config to it.

func GetRecordDiff

func GetRecordDiff(name string, a, b RecordDef) string

GetRecordDiff prints a diff between two records.

func WriteIncludeFile

func WriteIncludeFile(sources []string, w io.Writer, ioctls []nvproxy.IoctlName) error

WriteIncludeFile writes an cc file at file that includes all the given sources.

Types

type ClangASTConfig

type ClangASTConfig struct {
	Directory string   `json:"directory"`
	Arguments []string `json:"arguments"`
	Filename  string   `json:"file"`
}

ClangASTConfig is the format for compilation_commands.json.

func CreateIncludeFiles

func CreateIncludeFiles(dir string, driverSource DriverSourceDir, nonUVMIoctls, uvmIoctls []nvproxy.IoctlName) ([]ClangASTConfig, error)

CreateIncludeFiles creates the necessary include files for the given driver version, and returns the config options for the files.

func NewParserConfig

func NewParserConfig(directory, filename string, includes []string) ClangASTConfig

NewParserConfig creates a ClangASTConfig for the given file using the list of includes.

type DriverSourceDir

type DriverSourceDir struct {
	ParentDirectory string
	Version         nvconf.DriverVersion
}

DriverSourceDir represents a directory containing the source code for a given driver version.

func CloneDriverSource

func CloneDriverSource(dir string, version nvconf.DriverVersion) (*DriverSourceDir, error)

CloneDriverSource clones the given driver version into the given directory.

func (*DriverSourceDir) GetNonUVMIncludePaths

func (d *DriverSourceDir) GetNonUVMIncludePaths() []string

GetNonUVMIncludePaths returns the list of paths for non-uvm include files.

func (*DriverSourceDir) GetNonUVMSourcePaths

func (d *DriverSourceDir) GetNonUVMSourcePaths() ([]string, error)

GetNonUVMSourcePaths returns the list of paths for non-uvm source files.

func (*DriverSourceDir) GetUVMIncludePaths

func (d *DriverSourceDir) GetUVMIncludePaths() []string

GetUVMIncludePaths returns the list of paths for uvm include files.

func (*DriverSourceDir) GetUVMSourcePaths

func (d *DriverSourceDir) GetUVMSourcePaths() []string

GetUVMSourcePaths returns the list of paths for uvm source files.

func (*DriverSourceDir) GlobDriverFiles

func (d *DriverSourceDir) GlobDriverFiles(pattern string) ([]string, error)

GlobDriverFiles returns all files in the given driver directory that match the given pattern.

func (DriverSourceDir) Name

func (d DriverSourceDir) Name() string

Name returns the name of the driver source directory.

type InputJSON

type InputJSON struct {
	Structs   []string `json:"structs"`
	Constants []string `json:"constants"`
}

InputJSON is the format for the input.json file that driver_ast_parser takes as input.

type OutputJSON

type OutputJSON struct {
	Records   RecordDefs
	Aliases   TypeAliases
	Constants map[string]uint64
}

OutputJSON is the format for the output of driver_ast_parser.

func (*OutputJSON) Merge

func (a *OutputJSON) Merge(b OutputJSON)

Merge merges the struct definitions from b into this OutputJSON.

type RecordDef

type RecordDef struct {
	Fields  []RecordField
	Size    uint64
	IsUnion bool `json:"is_union"`
	Source  string
}

RecordDef represents the definition of a record (struct or union).

func (RecordDef) Equals

func (s RecordDef) Equals(other RecordDef) bool

Equals returns true if the two record definitions are equal. We ignore the source of the records.

type RecordDefs

type RecordDefs map[string]RecordDef

RecordDefs is a map of type names to definitions.

type RecordField

type RecordField struct {
	Name   string
	Type   string
	Offset uint64
}

RecordField represents a field in a record (struct or union).

func (RecordField) String

func (s RecordField) String() string

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner is a helper for running the driver_ast_parser on a given set of structs.

func NewRunner

func NewRunner(parserPath string) (*Runner, error)

NewRunner creates a new Runner around a given parser file and a temporary working directory.

func (*Runner) Cleanup

func (r *Runner) Cleanup() error

Cleanup removes the working directory for the runner.

func (*Runner) CreateInputFile

func (r *Runner) CreateInputFile(info *nvproxy.DriverABIInfo) error

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

func (*Runner) ParseDriver

func (r *Runner) ParseDriver(version nvconf.DriverVersion) (*OutputJSON, error)

ParseDriver checks out the git repo for the given version, and runs the driver_ast_parser on the source code.

type TypeAliases

type TypeAliases map[string]TypeDef

TypeAliases is a map of type aliases to their underlying type.

type TypeDef

type TypeDef struct {
	Type string
	Size uint64
}

TypeDef represents the definition of a type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL