Arg spec
arg_spec
¶
When passing command-line arguments to xdsl-opt, it may be useful to parametrize them.
The parametrized argument model object ArgSpec holds the name of the argument, and a
mapping from a key to a tuple of parameters, described below.
This is used when building pass pipelines.
ParameterType = str | int | bool | float
module-attribute
¶
The only types that can be used as ArgSpec parameters.
ParameterListType = tuple[ParameterType, ...]
module-attribute
¶
The ArgSpec holds a dictionary from strings to lists of parameters.
SpecToken: TypeAlias = Token[SpecTokenKind, str]
module-attribute
¶
ArgSpec
dataclass
¶
A specification for a command-line argument name and its parameters.
Source code in xdsl/utils/arg_spec.py
name: str
instance-attribute
¶
The name of the argument.
parameters: dict[str, ParameterListType]
instance-attribute
¶
The parameters of this argument.
__init__(name: str, parameters: dict[str, ParameterListType]) -> None
¶
normalize_parameter_names() -> ArgSpec
¶
This normalized all arg names by replacing - with _
Source code in xdsl/utils/arg_spec.py
__str__() -> str
¶
This function returns a string containing the PipelineSpec name, its arguments and respective values for use on the commandline.
Source code in xdsl/utils/arg_spec.py
ArgSpecConvertible
dataclass
¶
Bases: ABC
A base class for frozen dataclasses with a name: ClassVar[str] that can
be instantiated from an ArgSpec and serialized back to one.
Subclasses must be decorated with @dataclass(frozen=True).
Only the following types are supported as argument types:
Base types: int | float | bool | string N-tuples of base types: tuple[int, ...], tuple[int|float, ...], tuple[int, ...] | tuple[float, ...] Top-level optional: ... | None
Arguments are formatted as follows::
Spec arg Mapped to class field
------------------------- ------------------------------
my-thing{arg-1=1} arg_1: int = 1
my-thing{arg-1} arg_1: int | None = None
my-thing{arg-1=1,2,3} arg_1: tuple[int, ...] = (1, 2, 3)
my-thing{arg-1=true} arg_1: bool | None = True
Source code in xdsl/utils/arg_spec.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
name: str
class-attribute
¶
__init__() -> None
¶
from_spec(spec: ArgSpec) -> Self
classmethod
¶
Takes an ArgSpec, does type checking on the arguments, and instantiates an instance of this class from the spec.
Source code in xdsl/utils/arg_spec.py
required_fields() -> set[str]
classmethod
¶
Inspects the definition for fields that do not have default values.
spec(*, include_default: bool = False) -> ArgSpec
¶
Returns an ArgSpec representation of this instance.
If include_default is True, then optional arguments with default
values are also included in the spec.
Source code in xdsl/utils/arg_spec.py
SpecTokenKind
¶
Bases: Enum
Source code in xdsl/utils/arg_spec.py
EOF = object()
class-attribute
instance-attribute
¶
IDENT = object()
class-attribute
instance-attribute
¶
L_BRACE = '{'
class-attribute
instance-attribute
¶
R_BRACE = '}'
class-attribute
instance-attribute
¶
EQUALS = '='
class-attribute
instance-attribute
¶
NUMBER = object()
class-attribute
instance-attribute
¶
SPACE = object()
class-attribute
instance-attribute
¶
STRING_LIT = object()
class-attribute
instance-attribute
¶
MLIR_PIPELINE = object()
class-attribute
instance-attribute
¶
COMMA = ','
class-attribute
instance-attribute
¶
PipelineLexer
¶
This tokenizes a pass declaration string:
pipeline ::= pipeline-element (, pipeline-element)*
pipeline-element ::= MLIR_PIPELINE
| pass-name options?
options ::= { options-element ( options-element)* }
options-element ::= key (= value (, value)* )?
key ::= IDENT pass-name ::= IDENT value ::= NUMBER | BOOL | IDENT | STRING_LITERAL
Source code in xdsl/utils/arg_spec.py
parse_pipeline(pipeline_spec: str) -> Iterator[ArgSpec]
¶
This takes a pipeline string and gives a representation of the specification.
Each pass is represented by a tuple of
- name: the name of the pass as string
- args: a dictionary, where each value is zero or more of (str | bool | float | int)
Source code in xdsl/utils/arg_spec.py
parse_spec(spec: str) -> ArgSpec
¶
Parses a spec, with optional arguments, or raises a ArgSpecParseError if one
cannot be parsed.