rust_converter

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package rust_converter is Godzilla's Rust frontend. It compiles each .rs file to rustc's textual MIR (Mid-level IR) and lowers that to gIR.

MIR — not LLVM IR — is the right substrate for Rust taint analysis. rustc's LLVM IR routes returned values through `sret` out-pointers and stack memory, and exposes only internal monomorphized symbols (`std::env::__var`, `std::sys::process::unix::common::Command::arg`) that are unstable across compiler versions. MIR instead names the source-level public API (`std::env::var`, `Command::arg`) and assigns call results directly to locals, so a straight-line value-forwarding pass (mir.go) recovers clean SSA with no cgo, no libLLVM, and no memory modeling. Emitting MIR also skips codegen, so it is fast.

Scope: std-based flows compile standalone (env / fs / process / io). Sources or sinks that live in third-party crates (web frameworks, DB drivers) need those crates available at scan time, like Godzilla's other compiled-language frontends; single .rs files are compiled directly here. A directory containing a Cargo.toml is built with `cargo rustc -- --emit=mir` (convertCargo) so its dependency crates resolve and calls are named by their real crate paths — opt-in via buildpolicy, since cargo runs the repo's build scripts and proc-macros.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRustFile

func IsRustFile(path string) bool

IsRustFile reports whether path is a Rust source file this frontend lowers. Exported so internal/scan's language detection and this frontend's own file selection share ONE predicate.

Types

type Converter

type Converter struct {
	frontend.Driver[rsFileResult]
}

Converter lowers Rust source files/directories into gIR: the shared frontend.Driver surface (ConvertFile/ConvertInventory/Skipped) over Rust's batch hooks (see batch), with a cargo pre-step wrapped around both entry points for Cargo projects.

func NewConverter

func NewConverter() *Converter

func (*Converter) ConvertFile

func (c *Converter) ConvertFile(path string) (*ir.Program, error)

ConvertFile lowers a single .rs file, a directory of standalone .rs files, or a Cargo project. A directory with a Cargo.toml at its root is built with cargo (so its dependency crates — a web framework, etc. — resolve); otherwise each .rs file is compiled standalone with rustc via the shared batch driver.

func (*Converter) ConvertInventory

func (c *Converter) ConvertInventory(inv *walkignore.Inventory) (*ir.Program, error)

ConvertInventory lowers the Rust files of a pre-walked scan-root inventory (see walkignore.Inventory), skipping the directory walk ConvertFile's directory mode would repeat. A Cargo project at the inventory root still takes the cargo path (which builds by target, not by walked file), exactly as in ConvertFile.

Jump to

Keyboard shortcuts

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