parser

package
v0.0.0-...-2b55090 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0, MIT Imports: 13 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 nvproxy.DriverStructName, a, b RecordDef) string

GetRecordDiff prints a diff between two records.

func WriteIncludeFile

func WriteIncludeFile(sources []string, w io.Writer) 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) ([]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         nvproxy.DriverVersion
}

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

func CloneDriverSource

func CloneDriverSource(dir string, version nvproxy.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"`
}

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

type OutputJSON

type OutputJSON struct {
	Records RecordDefs
	Aliases TypeAliases
}

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 ParserFile

type ParserFile os.File

ParserFile is a wrapper around the driver_ast_parser binary.

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(parserFile *ParserFile) (*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) CreateStructsFile

func (r *Runner) CreateStructsFile(structs []nvproxy.DriverStructName) error

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

func (*Runner) ParseDriver

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

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

type StructsFile

type StructsFile os.File

StructsFile is a wrapper around the structs list file.

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