tvm
printer.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  */
28 #ifndef TVM_SCRIPT_PRINTER_PRINTER_H_
29 #define TVM_SCRIPT_PRINTER_PRINTER_H_
30 
31 #include <tvm/ir/node_functor.h>
33 
34 namespace tvm {
35 
40 TVM_DLL std::string Script(const ffi::ObjectRef& node,
41  const ffi::Optional<PrinterConfig>& config = std::nullopt);
42 
48  public:
49  using FType = NodeFunctor<std::string(const ffi::ObjectRef&, const PrinterConfig&)>;
50  TVM_DLL static FType& vtable();
51 };
52 
60 #define TVM_REGISTER_SCRIPT_AS_REPR(ObjectType, Method) \
61  TVM_FFI_STATIC_INIT_BLOCK() { \
62  namespace refl = tvm::ffi::reflection; \
63  refl::TypeAttrDef<ObjectType>().def(refl::type_attr::kRepr, \
64  [](ffi::ObjectRef obj, ffi::Function) -> ffi::String { \
65  return RedirectedReprPrinterMethod(obj); \
66  }); \
67  } \
68  TVM_STATIC_IR_FUNCTOR(TVMScriptPrinter, vtable).set_dispatch<ObjectType>(Method)
69 
70 } // namespace tvm
71 #endif // TVM_SCRIPT_PRINTER_PRINTER_H_
A dynamically dispatched functor on the type of the first argument.
Definition: node_functor.h:62
Definition: config.h:146
Dispatch vtable used by per-dialect printers to register their object-type printing functions....
Definition: printer.h:47
static FType & vtable()
Configuration object for the TVMScript printer.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
std::string Script(const ffi::ObjectRef &node, const ffi::Optional< PrinterConfig > &config=std::nullopt)
Print node as TVMScript with the given config.
Defines the Functor data structures.