tvm
Loading...
Searching...
No Matches
support.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
23#ifndef TVM_SCRIPT_PRINTER_SUPPORT_H_
24#define TVM_SCRIPT_PRINTER_SUPPORT_H_
25
26#include <tvm/ffi/extra/dataclass.h>
27#include <tvm/ffi/extra/visit_error_context.h>
28#include <tvm/ffi/reflection/registry.h>
29#include <tvm/ir/expr.h>
32
33namespace tvm {
34namespace script {
35namespace printer {
36
44TVM_TIRX_DLL ffi::String RedirectReprPrinterMethod(const ffi::ObjectRef& obj);
45
52TVM_TIRX_DLL ffi::Error RedirectVisitErrorEnrichMethod(const ffi::Error& error,
53 const ffi::ObjectRef& root);
54
56template <typename ObjectType>
58 namespace refl = ffi::reflection;
59 refl::TypeAttrDef<ObjectType>()
60 .def(ffi::type_attr::kRepr.name,
61 [](ffi::ObjectRef obj, ffi::Function) -> ffi::String {
62 return RedirectReprPrinterMethod(obj);
63 })
64 .def(ffi::type_attr::kEnrichVisitError.name, [](ffi::Error error, ffi::ObjectRef root) {
65 return RedirectVisitErrorEnrichMethod(error, root);
66 });
67}
68
77TVM_TIRX_DLL IdDoc VarDoc(DocTranslatorObj* d, const Var& var, bool explicit_def = true);
78
88TVM_TIRX_DLL ffi::Optional<ExprDoc> VarDocTranslate(DocTranslatorObj* d, ffi::AnyView input,
89 const ffi::Object* destination);
90
98
108 ffi::Optional<ffi::Array<ExprDoc>> translated_args = std::nullopt);
109
117 const CallObj* call);
118
119} // namespace printer
120} // namespace script
121} // namespace tvm
122#endif // TVM_SCRIPT_PRINTER_SUPPORT_H_
Base expr nodes in TVM.
#define TVM_TIRX_DLL
Definition base.h:55
Call corresponds to callable invocation.
Definition expr.h:788
Managed reference to VarObj.
Definition expr.h:571
Eager translation context shared by registered hooks. Hooks construct Docs, use explicit lexical scop...
Definition doc_translator.h:124
Reference type of ExprDocObj.
Definition doc.h:135
Reference type of IdDocObj.
Definition doc.h:387
Configuration object for the TVMScript printer.
Translator from IR values to printer docs.
TVM_TIRX_DLL IdDoc VarDoc(DocTranslatorObj *d, const Var &var, bool explicit_def=true)
Allocate or retrieve a variable identifier and record its origin.
TVM_TIRX_DLL ffi::Optional< ExprDoc > StandardCallDocTranslate(DocTranslatorObj *d, const CallObj *call)
Translate named Op-call syntax, falling back to an explicit call as needed.
TVM_TIRX_DLL ffi::Optional< ExprDoc > VarDocTranslate(DocTranslatorObj *d, ffi::AnyView input, const ffi::Object *destination)
Translate a Var using the normal translation-hook signature.
void RegisterScriptRepr()
Register TVMScript repr and visit-error rendering for ObjectType.
Definition support.h:57
TVM_TIRX_DLL ExprDoc AddMetadata(DocTranslatorObj *d, ffi::Any value)
Store a non-null value in the initialized metadata table.
TVM_TIRX_DLL ffi::String RedirectReprPrinterMethod(const ffi::ObjectRef &obj)
Render an IR object for its registered repr callback.
TVM_TIRX_DLL ffi::Error RedirectVisitErrorEnrichMethod(const ffi::Error &error, const ffi::ObjectRef &root)
Render visit-error context through the shared IR error renderer.
TVM_TIRX_DLL ExprDoc RawCallDocTranslate(DocTranslatorObj *d, const CallObj *call, ffi::Optional< ffi::Array< ExprDoc > > translated_args=std::nullopt)
Emit an explicit Call constructor preserving all call fields.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41