MIR 对象

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)[源代码]

基类:object

Bit width declaration of an unsigned integer index parameter, for the inputs mapping.

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.

变量:

width (int) -- Unsigned bit width, in the range 1..64.

width
class oracq.infrastructure.mathfunc.graph.Parameter(name, kind='real', width=0)[源代码]

基类:object

Name and math kind of an MIR function formal parameter.

变量:
  • 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=())[源代码]

基类:object

One value node of the MIR sequential SSA graph.

The node index is its position in the function's nodes sequence; args may only reference nodes with smaller indices.

变量:
  • op (str) -- Operation name, such as input, const, an arithmetic operation or call.

  • 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)[源代码]

基类:object

One pure math function in MIR: a formal parameter table and a sequential SSA node sequence.

变量:
  • 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')[源代码]

基类:object

MIR 0.1 top-level object: the entry function symbol and the full function table.

变量:
  • entry (str) -- The entry function's symbol name, which must appear in functions.

  • functions (tuple[oracq.infrastructure.mathfunc.graph.MathFunction, ...]) -- Immutable tuple of all MathFunction objects.

  • 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()[源代码]

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.

返回:

Self, once validation has passed.

返回类型:

MathProgram

抛出:

ValidationError -- Any structural or type constraint is violated.

dumps()[源代码]

Validate first, then serialize the program into canonical JSON text.

返回:

JSON text with sorted keys, two-space indentation and a trailing newline; non-ASCII characters are kept verbatim.

返回类型:

str

抛出:

ValidationError -- The program failed validation.

classmethod loads(text)[源代码]

Deserialize and validate an MIR program from JSON text.

参数:

text -- JSON text produced by MathProgram.dumps.

返回:

The validated program object.

返回类型:

MathProgram

抛出:

ValidationError -- The text is not valid MIR JSON, or failed validation.