Eager translation context shared by registered hooks. Hooks construct Docs, use explicit lexical scopes, and attach origins when emitting.
More...
#include <doc_translator.h>
|
| ffi::Optional< ExprDoc > | Translate (ffi::AnyView value, const ffi::Optional< Var > bind_var=std::nullopt) |
| | Translate a value with an optional pre-mapped binding variable.
|
| |
| void | Emit (const Doc &doc, ffi::Optional< ffi::ObjectRef > origin=std::nullopt) |
| | Append a completed Doc and record its optional origin.
|
| |
| IdDoc | VarGetOrAllocId (const Var &var, bool explicit_def) |
| | Reuse or allocate a variable's stable identifier.
|
| |
| IdDoc | AllocId (const ffi::String &hint) |
| | Reserve a fresh identifier without mapping a variable.
|
| |
| ffi::Dict< Var, IdDoc > | GetImplicitDefs () |
| | Get the current variable scope's pending definitions.
|
| |
| template<typename T > |
| T | GetExtraConfig (const ffi::String &name, T fallback) const |
| | Read a typed extension option.
|
| |
| template<typename T > |
| T | GetOrCreateExtraState (const ffi::String &name) |
| | Get or initialize typed extension state.
|
| |
| void | SetExtraState (const ffi::String &name, std::optional< ffi::Any > value) |
| | Replace or remove extension state.
|
| |
| void | BeginVarScope () |
| | Begin a lexical variable scope independent of Doc collection.
|
| |
| void | EndVarScope () |
| | End the latest naming region, retaining the root region. Explicit local bindings expire. Unresolved implicit references and their identifiers remain pending in the enclosing region, preserving captures shared by sibling functions.
|
| |
| void | BeginDocScope () |
| | Push an empty Doc collection.
|
| |
| ffi::List< Doc > | EndDocScope () |
| | Pop the latest Doc collection.
|
| |
| ffi::List< Doc > | CurrentScopeDocs () const |
| | Get the current Doc collection without popping it.
|
| |
| template<typename Callback > |
| ffi::List< Doc > | WithDocScope (Callback &&callback) |
| | Run a callback in a balanced Doc collection scope.
|
| |
| ffi::Dict< Doc, ffi::ObjectRef > | GetDocOrigins () const |
| | Get the owned Doc-to-original-object associations.
|
| |
| void | RecordOrigin (const Doc &doc, const ffi::ObjectRef &origin) |
| | Set a Doc's original IR object, replacing any previous association.
|
| |
| ffi::Optional< ExprDoc > | DefaultTranslate (ffi::AnyView value, const ffi::Object *destination=nullptr) |
| | Dispatch directly to the registered native or packed hook.
|
| |
| | TVM_FFI_DECLARE_OBJECT_INFO ("script.printer.DocTranslator", DocTranslatorObj, ffi::Object) |
| |
|
| ffi::List< ffi::List< Doc > > | doc_scopes_ |
| | Active Doc collections, independent of lexical variable scopes.
|
| |
Eager translation context shared by registered hooks. Hooks construct Docs, use explicit lexical scopes, and attach origins when emitting.
const ffi::Object* destination) {
if (!destination) return rhs;
auto var = ffi::GetRef<Var>(
static_cast<const VarNode*
>(destination));
return std::nullopt;
}
A local variable in the IR.
Definition expr.h:694
Reference type of AssignDocNode.
Definition doc.h:842
Eager translation context shared by registered hooks. Hooks construct Docs, use explicit lexical scop...
Definition doc_translator.h:120
void Emit(const Doc &doc, ffi::Optional< ffi::ObjectRef > origin=std::nullopt)
Append a completed Doc and record its optional origin.
Definition doc_translator.h:148
IdDoc VarGetOrAllocId(const Var &var, bool explicit_def)
Reuse or allocate a variable's stable identifier.
Definition doc_translator.h:159
Reference type of ExprDocNode.
Definition doc.h:134
Reference type of IdDocNode.
Definition doc.h:386
static LiteralDoc Str(const ffi::String &v, const ffi::Optional< AccessPath > &p)
Create a LiteralDoc to represent string.
Definition doc.h:303
◆ DocTranslatorObj()
| tvm::script::printer::DocTranslatorObj::DocTranslatorObj |
( |
const DocTranslatorVTable * |
vtable, |
|
|
ffi::Map< ffi::String, ffi::Any > |
extra_config = {} |
|
) |
| |
|
inlineexplicitprotected |
Initialize an engine's translation context.
- Parameters
-
| vtable | The engine callbacks, valid for this object's lifetime. |
| extra_config | The owned configuration snapshot. |
◆ AllocId()
| IdDoc tvm::script::printer::DocTranslatorObj::AllocId |
( |
const ffi::String & |
hint | ) |
|
|
inline |
Reserve a fresh identifier without mapping a variable.
- Parameters
-
- Returns
- The allocated identifier.
◆ BeginDocScope()
| void tvm::script::printer::DocTranslatorObj::BeginDocScope |
( |
| ) |
|
|
inline |
Push an empty Doc collection.
◆ BeginVarScope()
| void tvm::script::printer::DocTranslatorObj::BeginVarScope |
( |
| ) |
|
|
inline |
Begin a lexical variable scope independent of Doc collection.
◆ CurrentScopeDocs()
| ffi::List< Doc > tvm::script::printer::DocTranslatorObj::CurrentScopeDocs |
( |
| ) |
const |
|
inline |
Get the current Doc collection without popping it.
- Returns
- A mutable handle sharing the active collection's storage.
◆ DefaultTranslate()
| ffi::Optional< ExprDoc > tvm::script::printer::DocTranslatorObj::DefaultTranslate |
( |
ffi::AnyView |
value, |
|
|
const ffi::Object * |
destination = nullptr |
|
) |
| |
|
inline |
Dispatch directly to the registered native or packed hook.
- Parameters
-
| value | The input value. |
| destination | A borrowed Var, or nullptr when no binding is requested. |
- Returns
- An expression for the caller, or None after completed emission.
◆ Emit()
| void tvm::script::printer::DocTranslatorObj::Emit |
( |
const Doc & |
doc, |
|
|
ffi::Optional< ffi::ObjectRef > |
origin = std::nullopt |
|
) |
| |
|
inline |
Append a completed Doc and record its optional origin.
- Parameters
-
| doc | The emitted Doc. |
| origin | The original IR object represented by this emission. |
◆ EndDocScope()
| ffi::List< Doc > tvm::script::printer::DocTranslatorObj::EndDocScope |
( |
| ) |
|
|
inline |
Pop the latest Doc collection.
- Returns
- The collected Docs.
◆ EndVarScope()
| void tvm::script::printer::DocTranslatorObj::EndVarScope |
( |
| ) |
|
|
inline |
End the latest naming region, retaining the root region. Explicit local bindings expire. Unresolved implicit references and their identifiers remain pending in the enclosing region, preserving captures shared by sibling functions.
◆ GetDocOrigins()
| ffi::Dict< Doc, ffi::ObjectRef > tvm::script::printer::DocTranslatorObj::GetDocOrigins |
( |
| ) |
const |
|
inline |
Get the owned Doc-to-original-object associations.
- Returns
- A mutable handle sharing the origin dictionary's storage.
◆ GetExtraConfig()
template<typename T >
| T tvm::script::printer::DocTranslatorObj::GetExtraConfig |
( |
const ffi::String & |
name, |
|
|
T |
fallback |
|
) |
| const |
|
inline |
Read a typed extension option.
- Template Parameters
-
- Parameters
-
| name | The option name. |
| fallback | The value to use when absent. |
- Returns
- The typed option or fallback, rejecting an existing wrong type.
◆ GetImplicitDefs()
| ffi::Dict< Var, IdDoc > tvm::script::printer::DocTranslatorObj::GetImplicitDefs |
( |
| ) |
|
|
inline |
Get the current variable scope's pending definitions.
- Returns
- The live mutable dictionary of variables and their identifiers.
◆ GetOrCreateExtraState()
template<typename T >
| T tvm::script::printer::DocTranslatorObj::GetOrCreateExtraState |
( |
const ffi::String & |
name | ) |
|
|
inline |
Get or initialize typed extension state.
- Template Parameters
-
| T | The state type, default constructed when absent. |
- Parameters
-
- Returns
- The stored value, rejecting an existing wrong type; mutable handles share storage.
◆ RecordOrigin()
| void tvm::script::printer::DocTranslatorObj::RecordOrigin |
( |
const Doc & |
doc, |
|
|
const ffi::ObjectRef & |
origin |
|
) |
| |
|
inline |
Set a Doc's original IR object, replacing any previous association.
- Parameters
-
| doc | The constructed Doc. |
| origin | The original IR object. |
◆ SetExtraState()
| void tvm::script::printer::DocTranslatorObj::SetExtraState |
( |
const ffi::String & |
name, |
|
|
std::optional< ffi::Any > |
value |
|
) |
| |
|
inline |
Replace or remove extension state.
- Parameters
-
| name | The state name. |
| value | The replacement value, or nullopt to remove the entry. |
◆ Translate()
| ffi::Optional< ExprDoc > tvm::script::printer::DocTranslatorObj::Translate |
( |
ffi::AnyView |
value, |
|
|
const ffi::Optional< Var > |
bind_var = std::nullopt |
|
) |
| |
|
inline |
Translate a value with an optional pre-mapped binding variable.
- Parameters
-
| value | The input value. |
| bind_var | The binding variable, or None when no binding is requested. |
- Returns
- An expression for the caller, or None when emission completed the request. Callers requiring an expression use value(); for a specific Doc subtype, use value().as_or_throw<T>().
◆ TVM_FFI_DECLARE_OBJECT_INFO()
| tvm::script::printer::DocTranslatorObj::TVM_FFI_DECLARE_OBJECT_INFO |
( |
"script.printer.DocTranslator" |
, |
|
|
DocTranslatorObj |
, |
|
|
ffi::Object |
|
|
) |
| |
◆ VarGetOrAllocId()
| IdDoc tvm::script::printer::DocTranslatorObj::VarGetOrAllocId |
( |
const Var & |
var, |
|
|
bool |
explicit_def |
|
) |
| |
|
inline |
Reuse or allocate a variable's stable identifier.
- Parameters
-
| var | The variable to name. |
| explicit_def | Whether this occurrence defines the variable. |
- Returns
- The binding's IdDoc, with explicit definitions removed from pending entries.
◆ WithDocScope()
template<typename Callback >
| ffi::List< Doc > tvm::script::printer::DocTranslatorObj::WithDocScope |
( |
Callback && |
callback | ) |
|
|
inline |
Run a callback in a balanced Doc collection scope.
- Template Parameters
-
| Callback | The callable type. |
- Parameters
-
| callback | The callback that emits Docs. |
- Returns
- The collected Docs.
◆ _type_mutable
| constexpr bool tvm::script::printer::DocTranslatorObj::_type_mutable = true |
|
staticconstexpr |
◆ doc_scopes_
| ffi::List<ffi::List<Doc> > tvm::script::printer::DocTranslatorObj::doc_scopes_ |
|
protected |
Active Doc collections, independent of lexical variable scopes.
The documentation for this class was generated from the following file: