# OpenVAF Compiler Wrapper

`OpenvafCompiler` (`openvafcomp.h`/`openvafcomp.cpp`) implements `SourceCompiler`, the single-method (`compile()`) pluggable interface a `load` directive naming a `.va` (Verilog-A source) file instead of a prebuilt `.osdi` file uses to compile it on the fly, via the OpenVAF-reloaded compiler.

## When it acts

`compile()` only does anything for a `.va`/`.VA` extension; any other extension is a no-op success, leaving the caller free to treat it as an already-compiled `.osdi` file to load directly via [`OsdiFile::open()`](osdifile.md).

## Staleness check

The target `.osdi` file's path is derived from the `.va` file's own name, written to the current working directory. Recompilation happens only if that `.osdi` doesn't exist yet or its modification time is older than the `.va` source's - the same mtime-based staleness idea as [`ParserTables::writeEmbedded()`](parsertables.md)'s origin-file tracking, simpler here since there's no ambiguity about what produced a given `.osdi` (its name is derived directly from the `.va` file, rather than being an arbitrary caller-chosen name).

## Compiling

Before invoking the compiler, `compile()` temporarily changes the process's working directory to the `.va` file's own directory (so any `` `include``-style relative references inside the Verilog-A source resolve against it), and always restores the original directory afterward - including on a compilation failure. The compiler itself is invoked via [`runProcess()`](processutils.md), using either an explicitly configured compiler path/arguments (passed to `OpenvafCompiler`'s constructor) or the platform default (`defaultOpenVafBinaryName()`, [Platform Specifics](libplatform.md)), with `-o <osdi path> <va file>` appended to whatever arguments were configured. A nonzero exit or failure to launch is reported through [`Status`](status.md), including the compiler's captured stderr output.
