API Overview
pyxls exposes four main modules. All primary classes and functions are re-exported from the top-level xls package for convenience.
xls.c_api: Core Types and Functions
The c_api module provides the core abstractions that mirror the XLS C API:
Package: a container for IR functions and types. Created viaPackage.create()orPackage.parse_ir().Function/FunctionBase: an XLS function. Supports interpretation (interpret), JIT compilation (to_jit), and SMT encoding (to_z3_smtlib).FunctionJit: a JIT-compiled function. Callrun(args)for fast repeated execution.FunctionType: describes a function’s parameter and return types.Type: represents an XLS type (bits[N], tuple, array, token). Query withget_kind(),get_flat_bit_count().Value: a concrete XLS value. Construct withValue.make_ubits(),Value.make_sbits(),Value.make_tuple(), etc.Bits: raw bit-vector data. Supports arithmetic operators (+,-,&,|,^,<<,>>) and conversion to/from Python integers and bytes.BitsRope: for concatenateBitsvalues.ScheduleAndCodegenResult: the output ofPackage.schedule_and_codegen(), providingget_verilog_text().
Likely useful functions:
Function |
Description |
|---|---|
|
Compile DSLX source to XLS IR text |
|
Run IR optimisation passes |
|
Produce the mangled IR name for a DSLX function |
|
Parse IR text into a |
|
Parse a typed value from its string representation |
|
Run a JIT function with numpy inputs, loop inside C++ |
xls.ir_builder: Functional IR Builder API
The ir_builder module lets you build XLS IR functions in Python without writing textual IR:
FunctionBuilder: entry point for building a new function. CallFunctionBuilder.create(name, package)thenadd_parameter()to add typed inputs, and finallybuild_with_return_value(bval)to finalise.BuilderBase: holds all the arithmetic, logical, bitwise, and structural operations. Obtain viafb.as_builder_base(). Operations include:Arithmetic:
add_add,add_sub,add_umul,add_smul,add_udiv,add_sdiv, …Bitwise/logical:
add_and,add_or,add_xor,add_not,add_negate, …Comparisons:
add_ult,add_slt,add_eq,add_ne, …Reductions:
add_and_reduce,add_or_reduce,add_xor_reduceBit manipulation:
add_bit_slice,add_sign_extend,add_zero_extend,add_concat, …Collections:
add_tuple,add_tuple_index,add_array,add_array_index, …Multiplexing:
add_select,add_one_hot,add_one_hot_select,add_priority_select
BValue: a reference to a node in the IR graph (symbolic value).
xls.dslx: DSLX Language Support
The dslx module exposes the DSLX parser and typechecker. DSLX is XLS’s statically typed, hardware-oriented functional language.
Key entry point:
from xls.dslx import parse_and_typecheck, ImportData
import_data = ImportData.create(dslx_stdlib_path='', additional_search_paths=[])
result = parse_and_typecheck(dslx_text, 'module.x', 'module_name', import_data)
The returned TypecheckedModule exposes the parsed AST and type information. The module also provides types for introspecting DSLX programs: DslxModule, DslxFunction, StructDef, EnumDef, TypeInfo, ParametricEnv, InterpValue, and more.
xls.vast: Verilog AST
The vast module provides a structured API for constructing Verilog and SystemVerilog files:
VerilogFile: top-level file object. Create withVerilogFile.create(FileType.SYSTEM_VERILOG)orFileType.VERILOG. Callemit()to produce Verilog text.VerilogModule: a Verilog module. Add viavf.add_module(name). Then useadd_input(),add_output(),add_logic(),add_wire(),add_reg()to declare ports and signals.LogicRef: a reference to a declared signal. Useas_expression()in expressions.Expression: a Verilog expression node. Callemit()for the text form.DataType: a Verilog data type (scalar or bit-vector).
The VerilogFile object also provides factory methods for all expression and statement types: make_literal(), make_unary(), make_binary(), make_scalar_type(), make_bit_vector_type(), etc.