API Reference
This reference documents the main Python classes and functions in Axion-HDL.
Core Classes
AxionHDL
The main entry point for programmatic usage.
from axion_hdl import AxionHDL
# Create instance
axion = AxionHDL()
# Add source files or directories
axion.add_source("./rtl") # Auto-detect by extension
axion.add_source("registers.yaml")
# Analyze all sources
modules = axion.analyze()
# Generate outputs
axion.set_output_dir("./output")
axion.generate_all()
Constructor
AxionHDL(output_dir="./axion_output")
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Output directory for generated files |
Source Management Methods
Method |
Description |
|---|---|
|
Add source file/directory (auto-detects type by extension) |
|
Add VHDL source file or directory |
|
Add YAML source file or directory |
|
Add JSON source file or directory |
|
Add XML source file or directory |
|
List all added source files and directories |
Example:
axion = AxionHDL()
# Unified method (recommended)
axion.add_source("./rtl") # Directory with VHDL files
axion.add_source("config.yaml") # YAML file
axion.add_source("extra.json") # JSON file
# Type-specific methods
axion.add_src("spi_master.vhd") # VHDL only
axion.add_yaml_src("registers.yaml") # YAML only
# List sources
sources = axion.list_src()
print(sources)
Exclusion Methods
Method |
Description |
|---|---|
|
Exclude files/directories matching glob patterns |
|
Remove patterns from exclusion list |
|
Clear all exclusion patterns |
|
List current exclusion patterns |
Example:
axion = AxionHDL()
axion.add_source("./rtl")
# Exclude testbenches and deprecated files
axion.exclude("*_tb.vhd", "test_*.vhd")
axion.exclude("deprecated")
# Check what's excluded
print(axion.list_excludes())
# Output: {'*_tb.vhd', 'test_*.vhd', 'deprecated'}
# Re-include something
axion.include("test_*.vhd")
Analysis Methods
Method |
Description |
|---|---|
|
Parse all sources and return list of modules |
|
Get list of analyzed modules |
|
Property: True if analyze() has been called |
Example:
axion = AxionHDL()
axion.add_source("./rtl")
axion.exclude("*_tb.vhd")
# Analyze
modules = axion.analyze()
print(f"Found {len(modules)} modules")
# Access later
if axion.is_analyzed:
modules = axion.get_modules()
for m in modules:
print(f" {m['name']}: {len(m['registers'])} registers")
Generation Methods
Method |
Description |
|---|---|
|
Set output directory for generated files |
|
Generate all output formats |
|
Generate VHDL register modules |
|
Generate SystemVerilog register modules |
|
Generate C header files |
|
Generate documentation (md, html, pdf) |
|
Generate XML register maps |
|
Generate YAML register maps |
|
Generate JSON register maps |
Example:
axion = AxionHDL()
axion.add_source("registers.yaml")
axion.analyze()
# Set output directory
axion.set_output_dir("./generated")
# Generate everything
axion.generate_all()
# Or generate specific formats
axion.generate_vhdl()
axion.generate_c_header()
axion.generate_documentation(format="html")
Validation Methods
Method |
Description |
|---|---|
|
Run validation rules and print report |
|
Check for address overlaps between modules |
Example:
axion = AxionHDL()
axion.add_source("./rtl")
axion.analyze()
# Run rule checks
axion.run_rules()
# Or save to file
axion.run_rules(report_file="validation_report.txt")
# Check address overlaps
try:
errors = axion.check_address_overlaps()
except AddressConflictError as e:
print(f"Overlap: {e}")
RuleChecker
Validates register definitions against design rules.
from axion_hdl.rule_checker import RuleChecker
from axion_hdl import AxionHDL
# Analyze sources
axion = AxionHDL()
axion.add_source("./rtl")
modules = axion.analyze()
# Run rule checks
checker = RuleChecker()
results = checker.run_all_checks(modules)
# Get report
print(checker.generate_report())
# Check status
if results["errors"]:
print(f"Found {len(results['errors'])} errors")
Methods
Method |
Description |
|---|---|
|
Run all validation checks |
|
Generate text report |
|
Generate JSON report |
|
Check for address overlaps |
|
Check 4-byte alignment |
|
Validate default values fit width |
|
Validate VHDL identifiers |
|
Check for duplicate register names |
|
Check for duplicate module names |
|
Check for missing descriptions |
|
Check module/register structure |
|
Check source file syntax |
Return Value
run_all_checks() returns a dictionary:
{
"errors": [
{
"rule": "address_overlap",
"module": "spi_master",
"message": "Registers control and status overlap at 0x00"
}
],
"warnings": [
{
"rule": "documentation",
"module": "gpio",
"message": "Register 'direction' missing description"
}
]
}
Check Categories
Category |
Rule ID |
Description |
|---|---|---|
Address |
|
Registers share same address |
Address |
|
Not 4-byte aligned |
Values |
|
Default exceeds width |
Naming |
|
Invalid VHDL identifier |
Naming |
|
Duplicate register name |
Naming |
|
Duplicate module name |
Documentation |
|
No description field |
Structure |
|
Module has no registers |
Parsers
Individual parsers for each input format. Usually you don’t need these directly - use AxionHDL.add_source() instead.
VHDLParser
Parses VHDL files with @axion annotations.
from axion_hdl.parser import VHDLParser
parser = VHDLParser()
modules = parser.parse_file("module.vhd")
SystemVerilogParser
Parses SystemVerilog files with @axion annotations.
from axion_hdl.systemverilog_parser import SystemVerilogParser
parser = SystemVerilogParser()
modules = parser.parse_file("module.sv")
YAMLInputParser
Parses YAML register definition files.
from axion_hdl.yaml_input_parser import YAMLInputParser
parser = YAMLInputParser()
module = parser.parse_file("registers.yaml")
JSONInputParser
Parses JSON register definition files.
from axion_hdl.json_input_parser import JSONInputParser
parser = JSONInputParser()
module = parser.parse_file("registers.json")
XMLInputParser
Parses XML register definition files.
from axion_hdl.xml_input_parser import XMLInputParser
parser = XMLInputParser()
module = parser.parse_file("registers.xml")
TOMLInputParser
Parses TOML register definition files.
from axion_hdl.toml_input_parser import TOMLInputParser
parser = TOMLInputParser()
module = parser.parse_file("registers.toml")
Generators
Individual generators for each output format. Usually accessed via AxionHDL.generate_*() methods.
VHDLGenerator
Generates AXI4-Lite slave VHDL modules.
from axion_hdl.generator import VHDLGenerator
generator = VHDLGenerator(output_dir="./output")
output_path = generator.generate(module)
SystemVerilogGenerator
Generates SystemVerilog register interface modules.
from axion_hdl.systemverilog_generator import SystemVerilogGenerator
generator = SystemVerilogGenerator(output_dir="./output")
output_path = generator.generate(module)
DocGenerator
Generates documentation (Markdown, HTML, PDF).
from axion_hdl.doc_generators import DocGenerator
generator = DocGenerator(output_dir="./output")
output_path = generator.generate_markdown(modules)
output_path = generator.generate_html(modules)
output_path = generator.generate_pdf(modules)
CHeaderGenerator
Generates C header files.
from axion_hdl.doc_generators import CHeaderGenerator
generator = CHeaderGenerator(output_dir="./output")
output_path = generator.generate_header(module)
XMLGenerator
Generates XML register maps.
from axion_hdl.doc_generators import XMLGenerator
generator = XMLGenerator(output_dir="./output")
output_path = generator.generate_xml(module)
YAMLGenerator
Generates YAML register maps.
from axion_hdl.doc_generators import YAMLGenerator
generator = YAMLGenerator(output_dir="./output")
output_path = generator.generate_yaml(module)
JSONGenerator
Generates JSON register maps.
from axion_hdl.doc_generators import JSONGenerator
generator = JSONGenerator(output_dir="./output")
output_path = generator.generate_json(module)
TOMLGenerator
Generates TOML register maps.
from axion_hdl.doc_generators import TOMLGenerator
generator = TOMLGenerator(output_dir="./output")
output_path = generator.generate_toml(module)
Data Structures
Module Dictionary
Returned by analyze() and get_modules():
module = {
"name": "spi_master",
"entity_name": "spi_master",
"source_file": "/path/to/spi_master.vhd",
"base_address": 4096, # Integer (0x1000)
"base_addr": "0x1000", # String representation
"cdc_enabled": True,
"cdc_stages": 2,
"registers": [
# List of Register dictionaries
]
}
Register Dictionary
Each register in a module:
register = {
"name": "control",
"addr": "0x00",
"offset": 0,
"access": "RW", # "RO", "WO", or "RW"
"width": 32,
"default": 0,
"description": "Control register",
"r_strobe": False,
"w_strobe": True,
"fields": [] # Optional subregisters
}
Register Fields
Field |
Type |
Required |
Description |
|---|---|---|---|
|
str |
✓ |
Register/signal name |
|
str |
✓ |
Hex address (e.g., “0x04”) |
|
int |
Integer offset from base |
|
|
str |
✓ |
“RO”, “WO”, or “RW” |
|
int |
Bit width (default: 32) |
|
|
int/str |
Reset value (default: 0) |
|
|
str |
Documentation |
|
|
bool |
Generate read strobe (default: False) |
|
|
bool |
Generate write strobe (default: False) |
|
|
list |
Subregister bit fields |
Exceptions
AddressConflictError
Raised when address conflicts are detected.
from axion_hdl.address_manager import AddressConflictError
try:
axion.check_address_overlaps()
except AddressConflictError as e:
print(f"Conflict at address {e.address}")
print(f"Between: {e.existing_signal} and {e.new_signal}")
See Also
Python API Usage - Practical examples and workflows
CLI Usage - Command-line interface
Interactive GUI - Web-based interface