MIR objects¶
oracq.infrastructure.mathfunc.graph
MIR 0.1: a typed SSA graph of pure math functions; it holds no Python callables.
- class oracq.infrastructure.mathfunc.graph.Index(width)[source]¶
Bases:
objectBit width declaration of an unsigned integer index parameter, for the
inputsmapping.Provides a shorter public register for unsigned integers such as row and column indices; it is converted to the current fixed-point representation when entering math computation, and the format must hold its full range.
- Variables:
width (int) – Unsigned bit width, in the range 1..64.
- width¶
- class oracq.infrastructure.mathfunc.graph.Parameter(name, kind='real', width=0)[source]¶
Bases:
objectName and math kind of an MIR function formal parameter.
- Variables:
name (str) – Parameter name, unique within its function.
kind (str) – Parameter kind: real, complex, bool or index.
width (int) – Unsigned bit width used only by index parameters; must be 0 for other kinds.
- name¶
- kind = 'real'¶
- width = 0¶
- class oracq.infrastructure.mathfunc.graph.MathNode(op, kind, args=(), data=())[source]¶
Bases:
objectOne value node of the MIR sequential SSA graph.
The node index is its position in the function’s
nodessequence;argsmay only reference nodes with smaller indices.- Variables:
op (str) – Operation name, such as
input,const, an arithmetic operation orcall.kind (str) – Result value kind: real, complex or bool.
args (tuple[int, ...]) – Tuple of operand node indices.
data (tuple) – Attached data: input stores the parameter name, const stores the constant encoding, intrinsic stores the math function name, call stores the callee symbol and return index.
- op¶
- kind¶
- args = ()¶
- data = ()¶
- class oracq.infrastructure.mathfunc.graph.MathFunction(name, label, parameters, nodes, returns)[source]¶
Bases:
objectOne pure math function in MIR: a formal parameter table and a sequential SSA node sequence.
- Variables:
name (str) – Function symbol name, unique within the program.
label (str) – The function name in the source, used for display and module attributes.
parameters (tuple[oracq.infrastructure.mathfunc.graph.Parameter, ...]) – The parameter table in formal parameter order.
nodes (tuple[oracq.infrastructure.mathfunc.graph.MathNode, ...]) – The sequential SSA node sequence.
returns (tuple[int, ...]) – Non-empty tuple of return node indices; multiple indices mean multiple independent results.
- name¶
- label¶
- parameters¶
- nodes¶
- returns¶
- class oracq.infrastructure.mathfunc.graph.MathProgram(entry, functions, version='0.1')[source]¶
Bases:
objectMIR 0.1 top-level object: the entry function symbol and the full function table.
- Variables:
entry (str) – The entry function’s symbol name, which must appear in
functions.functions (tuple[oracq.infrastructure.mathfunc.graph.MathFunction, ...]) – Immutable tuple of all
MathFunctionobjects.version (str) – The MIR version number, currently 0.1.
- entry¶
- functions¶
- version = '0.1'¶
- property function_map¶
Mapping from function symbol names to
MathFunction.
- validate()[source]¶
Check the program’s structural and type constraints and return self.
Covers the version number, function table immutability and entry validity, parameter uniqueness and kinds, sequential SSA references, operation arities and type promotion, constant finiteness, call interface consistency, and acyclicity of the function graph.
- Returns:
Self, once validation has passed.
- Return type:
- Raises:
ValidationError – Any structural or type constraint is violated.
- dumps()[source]¶
Validate first, then serialize the program into canonical JSON text.
- Returns:
JSON text with sorted keys, two-space indentation and a trailing newline; non-ASCII characters are kept verbatim.
- Return type:
str
- Raises:
ValidationError – The program failed validation.
- classmethod loads(text)[source]¶
Deserialize and validate an MIR program from JSON text.
- Parameters:
text – JSON text produced by
MathProgram.dumps.- Returns:
The validated program object.
- Return type:
- Raises:
ValidationError – The text is not valid MIR JSON, or failed validation.