tvm_tirx.script.ir_builder.parser_protocol

tvm_tirx.script.ir_builder.parser_protocol#

Shared structural contract for source-to-builder rewriting.

The source namespace selects language variant X; shared module support uses I. For example, target()[index()] = value() lowers to X.setitem_(value=value(), target=target(), key=index()). Python evaluates the keywords in that order, preserving the assignment’s RHS-first semantics.

Native frames own construction state. Language variant implementations live in builder.parser_protocol; shared defaults cover module operations and metadata, while language-specific contract stubs raise NotImplementedError. Special syntax markers are documented in the special protocol section below.

Functions and Modules#

ir_module()

Start a ir_module frame.

decl_function(func_name, func_signature)

Register a function signature or a completed function in the active module.

function_(*[, decl, loc])

Create the native function frame used for signature and body construction.

arg_(name, annotation, *[, loc])

Add a parameter to the active native function signature.

func_name_(name)

Set the active native function's source name.

func_ret_type_(annotation, *[, loc])

Set the active native function's return annotation.

Bindings and Statements#

resolve_global_info_(content)

Resolve a named global-info selector in the current module context.

call_global_var_(function, args)

Construct a call to a declared module function.

module_member_(name, value)

Register a concrete function member or retain ordinary class setup.

bind_([value, ty, name, loc, value_loc, ...])

Apply the language variant's ordinary assignment policy.

decl_mutable_cell_([value, ty, name, loc, ...])

Introduce explicitly declared mutable storage.

set_mutable_cell_(target, value, *[, loc])

Emit an update through an existing mutable handle without rebinding it.

unpack_(value)

Expose elements for ordinary Python target unpacking.

emit_(value, *[, loc])

Consume a source expression statement.

setitem_(target, key, value, *[, loc])

Apply an indexed assignment using already-evaluated operands.

setattr_(target, name, value, *[, loc])

Apply an attribute assignment using already-evaluated operands.

Control Flow#

if_(condition, *[, loc])

Create the native conditional frame for a source if statement.

then_(*[, loc])

Create the true branch of the active conditional.

else_(*[, loc])

Create the false branch of the active conditional.

for_(iterable, *[, names, loc])

Configure and return the native iteration frame for a source for loop.

while_(condition, *[, loc])

Create a native while-loop frame.

range_(*args[, annotations])

Normalize builtin range syntax to a native serial loop frame.

break_(*[, loc])

Emit break for the enclosing language variant loop.

continue_(*[, loc])

Emit continue for the enclosing language variant loop.

return_([value, loc])

Record a language variant function return while continuing Python construction.

assert_(condition[, message, loc])

Emit a runtime assertion.

Operators#

if_then_else_(condition, true_value, false_value)

Construct conditional evaluation from eagerly constructed operands.

and_(*values)

Construct a conjunction from ordinary boolean or comparison operands.

or_(*values)

Construct a disjunction from already-evaluated operands.

not_(value)

Negate a host or language variant boolean without coercing IR truth in Python.

lt_(lhs, rhs, *[, loc])

Construct the < comparison in written operand order.

le_(lhs, rhs, *[, loc])

Construct the <= comparison in written operand order.

gt_(lhs, rhs, *[, loc])

Construct the > comparison in written operand order.

ge_(lhs, rhs, *[, loc])

Construct the >= comparison in written operand order.

eq_(lhs, rhs, *[, loc])

Construct the == comparison in written operand order.

ne_(lhs, rhs, *[, loc])

Construct the != comparison in written operand order.