tvm
doc.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  */
19 #ifndef TVM_SCRIPT_PRINTER_DOC_H_
20 #define TVM_SCRIPT_PRINTER_DOC_H_
21 
22 #include <tvm/ir/expr.h>
23 #include <tvm/node/node.h>
24 #include <tvm/runtime/data_type.h>
25 
26 #include <string>
27 
28 namespace tvm {
29 namespace script {
30 namespace printer {
31 
32 // Forward declaration
33 class Doc;
34 
41 
53 class DocNode : public Object {
54  public:
63 
64  void VisitAttrs(AttrVisitor* v) { v->Visit("source_paths", &source_paths); }
65 
66  static constexpr const char* _type_key = "script.printer.Doc";
68 
69  public:
70  virtual ~DocNode() = default;
71 };
72 
78 class Doc : public ObjectRef {
79  protected:
80  Doc() = default;
81 
82  public:
83  virtual ~Doc() = default;
85 };
86 
87 class ExprDoc;
88 
94 class ExprDocNode : public DocNode {
95  public:
100  ExprDoc Attr(String attr) const;
101 
106  ExprDoc operator[](Array<Doc> indices) const;
107 
113 
121  Array<String> kwargs_keys, //
122  Array<ExprDoc, void> kwargs_values) const;
123 
125 
126  static constexpr const char* _type_key = "script.printer.ExprDoc";
128 };
129 
135 class ExprDoc : public Doc {
136  protected:
137  ExprDoc() = default;
138 
139  public:
144  ExprDoc operator[](Array<Doc> indices) const;
145 
147 };
148 
154 class StmtDocNode : public DocNode {
155  public:
165 
168  v->Visit("comment", &comment);
169  }
170 
171  static constexpr const char* _type_key = "script.printer.StmtDoc";
173 };
174 
180 class StmtDoc : public Doc {
181  protected:
182  StmtDoc() = default;
183 
184  public:
186 };
187 
194 class StmtBlockDocNode : public DocNode {
195  public:
198 
201  v->Visit("stmts", &stmts);
202  }
203 
204  static constexpr const char* _type_key = "script.printer.StmtBlockDoc";
206 };
207 
212 class StmtBlockDoc : public Doc {
213  public:
218  explicit StmtBlockDoc(Array<StmtDoc> stmts);
220 };
221 
227 class LiteralDocNode : public ExprDocNode {
228  public:
239 
242  v->Visit("value", &value);
243  }
244 
245  static constexpr const char* _type_key = "script.printer.LiteralDoc";
247 };
248 
254 class LiteralDoc : public ExprDoc {
255  protected:
256  explicit LiteralDoc(ObjectRef value, const Optional<ObjectPath>& object_path);
257 
258  public:
264  return LiteralDoc(ObjectRef(nullptr), p);
265  }
271  static LiteralDoc Int(int64_t v, const Optional<ObjectPath>& p) {
272  return LiteralDoc(IntImm(DataType::Int(64), v), p);
273  }
279  static LiteralDoc Boolean(bool v, const Optional<ObjectPath>& p) {
280  return LiteralDoc(IntImm(DataType::Bool(), v), p);
281  }
287  static LiteralDoc Float(double v, const Optional<ObjectPath>& p) {
288  return LiteralDoc(FloatImm(DataType::Float(64), v), p);
289  }
295  static LiteralDoc Str(const String& v, const Optional<ObjectPath>& p) { return LiteralDoc(v, p); }
302  std::string dtype = v.is_void() ? "void" : runtime::DLDataType2String(v);
303  return LiteralDoc::Str(dtype, p);
304  }
305 
307 };
308 
314 class IdDocNode : public ExprDocNode {
315  public:
318 
321  v->Visit("name", &name);
322  }
323 
324  static constexpr const char* _type_key = "script.printer.IdDoc";
326 };
327 
333 class IdDoc : public ExprDoc {
334  public:
339  explicit IdDoc(String name);
340  explicit IdDoc(std::nullptr_t) : ExprDoc(nullptr) {}
342 };
343 
350  public:
352  ExprDoc value{nullptr};
355 
358  v->Visit("value", &value);
359  v->Visit("name", &name);
360  }
361 
362  static constexpr const char* _type_key = "script.printer.AttrAccessDoc";
364 };
365 
371 class AttrAccessDoc : public ExprDoc {
372  public:
378  explicit AttrAccessDoc(ExprDoc value, String name);
380 };
381 
387 class IndexDocNode : public ExprDocNode {
388  public:
390  ExprDoc value{nullptr};
398  Array<Doc> indices; // Each element is union of: Slice / ExprDoc
399 
402  v->Visit("value", &value);
403  v->Visit("indices", &indices);
404  }
405 
406  static constexpr const char* _type_key = "script.printer.IndexDoc";
408 };
409 
415 class IndexDoc : public ExprDoc {
416  public:
422  explicit IndexDoc(ExprDoc value, Array<Doc> indices);
424 };
425 
431 class CallDocNode : public ExprDocNode {
432  public:
434  ExprDoc callee{nullptr};
446 
449  v->Visit("callee", &callee);
450  v->Visit("args", &args);
451  v->Visit("kwargs_keys", &kwargs_keys);
452  v->Visit("kwargs_values", &kwargs_values);
453  }
454 
455  static constexpr const char* _type_key = "script.printer.CallDoc";
457 };
458 
464 class CallDoc : public ExprDoc {
465  public:
473  CallDoc(ExprDoc callee, Array<ExprDoc> args, Array<String> kwargs_keys,
474  Array<ExprDoc> kwargs_values);
476 };
477 
487  public:
488  enum class Kind : int32_t {
489  // Unary operators
490  kUnaryStart = 0,
491  kUSub = 1, // -x
492  kInvert = 2, // ~x
493  kNot = 3, // not x
494  kUnaryEnd = 4,
495 
496  // Binary operators
497  kBinaryStart = 5,
498  kAdd = 6, // +
499  kSub = 7, // -
500  kMult = 8, // *
501  kDiv = 9, // /
502  kFloorDiv = 10, // // in Python
503  kMod = 11, // % in Python
504  kPow = 12, // ** in Python
505  kLShift = 13, // <<
506  kRShift = 14, // >>
507  kBitAnd = 15, // &
508  kBitOr = 16, // |
509  kBitXor = 17, // ^
510  kLt = 18, // <
511  kLtE = 19, // <=
512  kEq = 20, // ==
513  kNotEq = 21, // !=
514  kGt = 22, // >
515  kGtE = 23, // >=
516  kAnd = 24, // and
517  kOr = 25, // or
518  kBinaryEnd = 26,
519 
520  // Special
521  kSpecialStart = 27,
522  kIfThenElse = 28, // <operands[1]> if <operands[0]> else <operands[2]>
523  kSpecialEnd = 29
524  };
525 
530 
533  v->Visit("kind", &kind);
534  v->Visit("operands", &operands);
535  }
536 
537  static constexpr const char* _type_key = "script.printer.OperationDoc";
539 };
540 
546 class OperationDoc : public ExprDoc {
547  public:
555 };
556 
565 class LambdaDocNode : public ExprDocNode {
566  public:
570  ExprDoc body{nullptr};
571 
574  v->Visit("args", &args);
575  v->Visit("body", &body);
576  }
577 
578  static constexpr const char* _type_key = "script.printer.LambdaDoc";
580 };
581 
587 class LambdaDoc : public ExprDoc {
588  public:
594  explicit LambdaDoc(Array<IdDoc> args, ExprDoc body);
596 };
597 
603 class TupleDocNode : public ExprDocNode {
604  public:
607 
610  v->Visit("elements", &elements);
611  }
612 
613  static constexpr const char* _type_key = "script.printer.TupleDoc";
615 };
616 
622 class TupleDoc : public ExprDoc {
623  public:
632  explicit TupleDoc(Array<ExprDoc> elements);
634 };
635 
641 class ListDocNode : public ExprDocNode {
642  public:
645 
648  v->Visit("elements", &elements);
649  }
650 
651  static constexpr const char* _type_key = "script.printer.ListDoc";
653 };
654 
660 class ListDoc : public ExprDoc {
661  public:
670  explicit ListDoc(Array<ExprDoc> elements);
672 };
673 
679 class DictDocNode : public ExprDocNode {
680  public:
690 
693  v->Visit("keys", &keys);
694  v->Visit("values", &values);
695  }
696 
697  static constexpr const char* _type_key = "script.printer.DictDoc";
699 };
700 
706 class DictDoc : public ExprDoc {
707  public:
717  explicit DictDoc(Array<ExprDoc> keys, Array<ExprDoc> values);
719 };
720 
728 class SliceDocNode : public DocNode {
729  public:
736 
739  v->Visit("start", &start);
740  v->Visit("stop", &stop);
741  v->Visit("step", &step);
742  }
743 
744  static constexpr const char* _type_key = "script.printer.SliceDoc";
746 };
747 
753 class SliceDoc : public Doc {
754  public:
763 };
764 
770 class AssignDocNode : public StmtDocNode {
771  public:
773  ExprDoc lhs{nullptr};
782 
785  v->Visit("lhs", &lhs);
786  v->Visit("rhs", &rhs);
787  v->Visit("annotation", &annotation);
788  }
789 
790  static constexpr const char* _type_key = "script.printer.AssignDoc";
792 };
793 
799 class AssignDoc : public StmtDoc {
800  public:
807  explicit AssignDoc(ExprDoc lhs, Optional<ExprDoc> rhs, Optional<ExprDoc> annotation);
809 };
810 
816 class IfDocNode : public StmtDocNode {
817  public:
819  ExprDoc predicate{nullptr};
824 
827  v->Visit("predicate", &predicate);
828  v->Visit("then_branch", &then_branch);
829  v->Visit("else_branch", &else_branch);
830  }
831 
832  static constexpr const char* _type_key = "script.printer.IfDoc";
834 };
835 
841 class IfDoc : public StmtDoc {
842  public:
849  explicit IfDoc(ExprDoc predicate, Array<StmtDoc> then_branch, Array<StmtDoc> else_branch);
851 };
852 
858 class WhileDocNode : public StmtDocNode {
859  public:
861  ExprDoc predicate{nullptr};
864 
867  v->Visit("predicate", &predicate);
868  v->Visit("body", &body);
869  }
870 
871  static constexpr const char* _type_key = "script.printer.WhileDoc";
873 };
874 
880 class WhileDoc : public StmtDoc {
881  public:
887  explicit WhileDoc(ExprDoc predicate, Array<StmtDoc> body);
889 };
890 
900 class ForDocNode : public StmtDocNode {
901  public:
903  ExprDoc lhs{nullptr};
905  ExprDoc rhs{nullptr};
908 
911  v->Visit("lhs", &lhs);
912  v->Visit("rhs", &rhs);
913  v->Visit("body", &body);
914  }
915 
916  static constexpr const char* _type_key = "script.printer.ForDoc";
918 };
919 
925 class ForDoc : public StmtDoc {
926  public:
933  explicit ForDoc(ExprDoc lhs, ExprDoc rhs, Array<StmtDoc> body);
935 };
936 
947 class ScopeDocNode : public StmtDocNode {
948  public:
952  ExprDoc rhs{nullptr};
955 
958  v->Visit("lhs", &lhs);
959  v->Visit("rhs", &rhs);
960  v->Visit("body", &body);
961  }
962 
963  static constexpr const char* _type_key = "script.printer.ScopeDoc";
965 };
966 
972 class ScopeDoc : public StmtDoc {
973  public:
981 
987  explicit ScopeDoc(ExprDoc rhs, Array<StmtDoc> body);
988 
990 };
991 
997 class ExprStmtDocNode : public StmtDocNode {
998  public:
1000  ExprDoc expr{nullptr};
1001 
1004  v->Visit("expr", &expr);
1005  }
1006 
1007  static constexpr const char* _type_key = "script.printer.ExprStmtDoc";
1009 };
1010 
1016 class ExprStmtDoc : public StmtDoc {
1017  public:
1022  explicit ExprStmtDoc(ExprDoc expr);
1024 };
1025 
1031 class AssertDocNode : public StmtDocNode {
1032  public:
1034  ExprDoc test{nullptr};
1037 
1040  v->Visit("test", &test);
1041  v->Visit("msg", &msg);
1042  }
1043 
1044  static constexpr const char* _type_key = "script.printer.AssertDoc";
1046 };
1047 
1053 class AssertDoc : public StmtDoc {
1054  public:
1062 };
1063 
1069 class ReturnDocNode : public StmtDocNode {
1070  public:
1072  ExprDoc value{nullptr};
1073 
1076  v->Visit("value", &value);
1077  }
1078 
1079  static constexpr const char* _type_key = "script.printer.ReturnDoc";
1081 };
1082 
1088 class ReturnDoc : public StmtDoc {
1089  public:
1094  explicit ReturnDoc(ExprDoc value);
1096 };
1097 
1104  public:
1106  IdDoc name{nullptr};
1121 
1124  v->Visit("name", &name);
1125  v->Visit("args", &args);
1126  v->Visit("decorators", &decorators);
1127  v->Visit("return_type", &return_type);
1128  v->Visit("body", &body);
1129  }
1130 
1131  static constexpr const char* _type_key = "script.printer.FunctionDoc";
1133 };
1134 
1140 class FunctionDoc : public StmtDoc {
1141  public:
1150  explicit FunctionDoc(IdDoc name, Array<AssignDoc> args, Array<ExprDoc> decorators,
1151  Optional<ExprDoc> return_type, Array<StmtDoc> body);
1153 };
1154 
1160 class ClassDocNode : public StmtDocNode {
1161  public:
1163  IdDoc name{nullptr};
1168 
1171  v->Visit("name", &name);
1172  v->Visit("decorators", &decorators);
1173  v->Visit("body", &body);
1174  }
1175 
1176  static constexpr const char* _type_key = "script.printer.ClassDoc";
1178 };
1179 
1185 class ClassDoc : public StmtDoc {
1186  public:
1193  explicit ClassDoc(IdDoc name, Array<ExprDoc> decorators, Array<StmtDoc> body);
1195 };
1196 
1202 class CommentDocNode : public StmtDocNode {
1203  public:
1204  static constexpr const char* _type_key = "script.printer.CommentDoc";
1206 };
1207 
1213 class CommentDoc : public StmtDoc {
1214  public:
1215  explicit CommentDoc(String comment);
1217 };
1218 
1225  public:
1226  static constexpr const char* _type_key = "script.printer.DocStringDoc";
1228 };
1229 
1235 class DocStringDoc : public StmtDoc {
1236  public:
1237  explicit DocStringDoc(String docs);
1239 };
1240 
1241 } // namespace printer
1242 } // namespace script
1243 } // namespace tvm
1244 
1245 #endif // TVM_SCRIPT_PRINTER_DOC_H_
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Managed reference class to FloatImmNode.
Definition: expr.h:577
Managed reference class to IntImmNode.
Definition: expr.h:530
Definition: script_printer.h:149
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Runtime primitive data type.
Definition: data_type.h:43
static DataType Float(int bits, int lanes=1)
Construct an float type.
Definition: data_type.h:236
static DataType Bool(int lanes=1, bool is_scalable=false)
Construct a bool type.
Definition: data_type.h:262
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:219
bool is_void() const
Definition: data_type.h:156
Base class of all object reference.
Definition: object.h:519
ObjectRef()=default
default constructor
base class of all object containers.
Definition: object.h:171
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to string objects.
Definition: string.h:98
Doc that represents assert statement.
Definition: doc.h:1031
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:1038
ExprDoc test
The expression to test.
Definition: doc.h:1034
TVM_DECLARE_FINAL_OBJECT_INFO(AssertDocNode, StmtDocNode)
static constexpr const char * _type_key
Definition: doc.h:1044
Optional< ExprDoc > msg
The optional error message when assertion failed.
Definition: doc.h:1036
Reference type of AssertDocNode.
Definition: doc.h:1053
AssertDoc(ExprDoc test, Optional< ExprDoc > msg=NullOpt)
Constructor of AssertDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(AssertDoc, StmtDoc, AssertDocNode)
Doc that represents assign statement.
Definition: doc.h:770
Optional< ExprDoc > annotation
The type annotation of this assignment.
Definition: doc.h:781
Optional< ExprDoc > rhs
The right hand side of the assignment.
Definition: doc.h:779
ExprDoc lhs
The left hand side of the assignment.
Definition: doc.h:773
static constexpr const char * _type_key
Definition: doc.h:790
TVM_DECLARE_FINAL_OBJECT_INFO(AssignDocNode, StmtDocNode)
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:783
Reference type of AssignDocNode.
Definition: doc.h:799
AssignDoc(ExprDoc lhs, Optional< ExprDoc > rhs, Optional< ExprDoc > annotation)
Constructor of AssignDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(AssignDoc, StmtDoc, AssignDocNode)
Doc that represents attribute access on another expression.
Definition: doc.h:349
static constexpr const char * _type_key
Definition: doc.h:362
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:356
String name
The attribute to be accessed.
Definition: doc.h:354
ExprDoc value
The target expression to be accessed.
Definition: doc.h:352
TVM_DECLARE_FINAL_OBJECT_INFO(AttrAccessDocNode, ExprDocNode)
Reference type of AttrAccessDocNode.
Definition: doc.h:371
AttrAccessDoc(ExprDoc value, String name)
Constructor of AttrAccessDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(AttrAccessDoc, ExprDoc, AttrAccessDocNode)
Doc that represents function call.
Definition: doc.h:431
Array< ExprDoc > kwargs_values
The values of keyword arguments.
Definition: doc.h:445
Array< ExprDoc > args
The positional arguments.
Definition: doc.h:436
TVM_DECLARE_FINAL_OBJECT_INFO(CallDocNode, ExprDocNode)
static constexpr const char * _type_key
Definition: doc.h:455
Array< String > kwargs_keys
The keys of keyword arguments.
Definition: doc.h:438
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:447
ExprDoc callee
The callee of this function call.
Definition: doc.h:434
Reference type of CallDocNode.
Definition: doc.h:464
CallDoc(ExprDoc callee, Array< ExprDoc > args, Array< String > kwargs_keys, Array< ExprDoc > kwargs_values)
Constructor of CallDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(CallDoc, ExprDoc, CallDocNode)
Doc that represents class definition.
Definition: doc.h:1160
static constexpr const char * _type_key
Definition: doc.h:1176
Array< ExprDoc > decorators
Decorators of class.
Definition: doc.h:1165
TVM_DECLARE_FINAL_OBJECT_INFO(ClassDocNode, StmtDocNode)
Array< StmtDoc > body
The body of class.
Definition: doc.h:1167
IdDoc name
The name of class.
Definition: doc.h:1163
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:1169
Reference type of ClassDocNode.
Definition: doc.h:1185
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ClassDoc, StmtDoc, ClassDocNode)
ClassDoc(IdDoc name, Array< ExprDoc > decorators, Array< StmtDoc > body)
Constructor of ClassDoc.
Doc that represents comment.
Definition: doc.h:1202
TVM_DECLARE_FINAL_OBJECT_INFO(CommentDocNode, StmtDocNode)
static constexpr const char * _type_key
Definition: doc.h:1204
Reference type of CommentDocNode.
Definition: doc.h:1213
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(CommentDoc, StmtDoc, CommentDocNode)
Doc that represents dictionary literal.
Definition: doc.h:679
Array< ExprDoc > values
Values of dictionary.
Definition: doc.h:689
Array< ExprDoc > keys
keys of dictionary
Definition: doc.h:682
static constexpr const char * _type_key
Definition: doc.h:697
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:691
TVM_DECLARE_FINAL_OBJECT_INFO(DictDocNode, ExprDocNode)
Reference type of DictDocNode.
Definition: doc.h:706
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(DictDoc, ExprDoc, DictDocNode)
DictDoc(Array< ExprDoc > keys, Array< ExprDoc > values)
Constructor of DictDoc.
DictDoc()
Create an empty dictionary.
Definition: doc.h:711
The base class of all Doc.
Definition: doc.h:53
Array< ObjectPath > source_paths
The list of object paths of the source IR node.
Definition: doc.h:62
virtual ~DocNode()=default
TVM_DECLARE_BASE_OBJECT_INFO(DocNode, Object)
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:64
static constexpr const char * _type_key
Definition: doc.h:66
Doc that represents docstring.
Definition: doc.h:1224
static constexpr const char * _type_key
Definition: doc.h:1226
TVM_DECLARE_FINAL_OBJECT_INFO(DocStringDocNode, StmtDocNode)
Reference type of DocStringDocNode.
Definition: doc.h:1235
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(DocStringDoc, StmtDoc, DocStringDocNode)
Reference type of DocNode.
Definition: doc.h:78
virtual ~Doc()=default
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Doc, ObjectRef, DocNode)
The base class of expression doc.
Definition: doc.h:94
static constexpr const char * _type_key
Definition: doc.h:126
TVM_DECLARE_BASE_OBJECT_INFO(ExprDocNode, DocNode)
ExprDoc Attr(String attr) const
Create a doc representing attribute access on the current ExprDoc.
ExprDoc Call(Array< ExprDoc, void > args) const
Create a doc representing calling the current ExprDoc.
ExprDoc operator[](Array< Doc > indices) const
Create a doc representing index access on the current ExprDoc.
ExprDoc Call(Array< ExprDoc, void > args, Array< String > kwargs_keys, Array< ExprDoc, void > kwargs_values) const
Create a doc representing attribute access on the current ExprDoc.
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:124
Reference type of ExprDocNode.
Definition: doc.h:135
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ExprDoc, Doc, ExprDocNode)
ExprDoc operator[](Array< Doc > indices) const
Create a doc representing index access on the current ExprDoc.
Doc that represents an expression as statement.
Definition: doc.h:997
static constexpr const char * _type_key
Definition: doc.h:1007
TVM_DECLARE_FINAL_OBJECT_INFO(ExprStmtDocNode, StmtDocNode)
ExprDoc expr
The expression represented by this doc.
Definition: doc.h:1000
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:1002
Reference type of ExprStmtDocNode.
Definition: doc.h:1016
ExprStmtDoc(ExprDoc expr)
Constructor of ExprStmtDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ExprStmtDoc, StmtDoc, ExprStmtDocNode)
Doc that represents for statement.
Definition: doc.h:900
ExprDoc lhs
The left hand side of the assignment of iterating variable.
Definition: doc.h:903
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:909
static constexpr const char * _type_key
Definition: doc.h:916
ExprDoc rhs
The right hand side of the assignment of iterating variable.
Definition: doc.h:905
Array< StmtDoc > body
The body of the for statement.
Definition: doc.h:907
TVM_DECLARE_FINAL_OBJECT_INFO(ForDocNode, StmtDocNode)
Reference type of ForDocNode.
Definition: doc.h:925
ForDoc(ExprDoc lhs, ExprDoc rhs, Array< StmtDoc > body)
Constructor of ForDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ForDoc, StmtDoc, ForDocNode)
Doc that represents function definition.
Definition: doc.h:1103
TVM_DECLARE_FINAL_OBJECT_INFO(FunctionDocNode, StmtDocNode)
Optional< ExprDoc > return_type
The return type of function.
Definition: doc.h:1118
Array< ExprDoc > decorators
Decorators of function.
Definition: doc.h:1116
Array< StmtDoc > body
The body of function.
Definition: doc.h:1120
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:1122
Array< AssignDoc > args
The arguments of function.
Definition: doc.h:1114
IdDoc name
The name of function.
Definition: doc.h:1106
static constexpr const char * _type_key
Definition: doc.h:1131
Reference type of FunctionDocNode.
Definition: doc.h:1140
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(FunctionDoc, StmtDoc, FunctionDocNode)
FunctionDoc(IdDoc name, Array< AssignDoc > args, Array< ExprDoc > decorators, Optional< ExprDoc > return_type, Array< StmtDoc > body)
Constructor of FunctionDoc.
Doc that represents identifier.
Definition: doc.h:314
TVM_DECLARE_FINAL_OBJECT_INFO(IdDocNode, ExprDocNode)
String name
The name of the identifier.
Definition: doc.h:317
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:319
static constexpr const char * _type_key
Definition: doc.h:324
Reference type of IdDocNode.
Definition: doc.h:333
IdDoc(std::nullptr_t)
Definition: doc.h:340
IdDoc(String name)
Constructor of IdDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(IdDoc, ExprDoc, IdDocNode)
Doc that represent if-then-else statement.
Definition: doc.h:816
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:825
TVM_DECLARE_FINAL_OBJECT_INFO(IfDocNode, StmtDocNode)
Array< StmtDoc > else_branch
The else branch of the if-then-else statement.
Definition: doc.h:823
static constexpr const char * _type_key
Definition: doc.h:832
Array< StmtDoc > then_branch
The then branch of the if-then-else statement.
Definition: doc.h:821
ExprDoc predicate
The predicate of the if-then-else statement.
Definition: doc.h:819
Reference type of IfDocNode.
Definition: doc.h:841
IfDoc(ExprDoc predicate, Array< StmtDoc > then_branch, Array< StmtDoc > else_branch)
Constructor of IfDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(IfDoc, StmtDoc, IfDocNode)
Doc that represents index access on another expression.
Definition: doc.h:387
static constexpr const char * _type_key
Definition: doc.h:406
TVM_DECLARE_FINAL_OBJECT_INFO(IndexDocNode, ExprDocNode)
ExprDoc value
The container value to be accessed.
Definition: doc.h:390
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:400
Array< Doc > indices
The indices to access.
Definition: doc.h:398
Reference type of IndexDocNode.
Definition: doc.h:415
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(IndexDoc, ExprDoc, IndexDocNode)
IndexDoc(ExprDoc value, Array< Doc > indices)
Constructor of IndexDoc.
Doc that represents anonymous function.
Definition: doc.h:565
Array< IdDoc > args
The arguments of this anonymous function.
Definition: doc.h:568
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:572
ExprDoc body
The body of this anonymous function.
Definition: doc.h:570
static constexpr const char * _type_key
Definition: doc.h:578
TVM_DECLARE_FINAL_OBJECT_INFO(LambdaDocNode, ExprDocNode)
Reference type of LambdaDocNode.
Definition: doc.h:587
LambdaDoc(Array< IdDoc > args, ExprDoc body)
Constructor of LambdaDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(LambdaDoc, ExprDoc, LambdaDocNode)
Doc that represents list literal.
Definition: doc.h:641
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:646
Array< ExprDoc > elements
Elements of list.
Definition: doc.h:644
TVM_DECLARE_FINAL_OBJECT_INFO(ListDocNode, ExprDocNode)
static constexpr const char * _type_key
Definition: doc.h:651
Reference type of ListDocNode.
Definition: doc.h:660
ListDoc()
Create an empty ListDoc.
Definition: doc.h:665
ListDoc(Array< ExprDoc > elements)
Constructor of ListDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ListDoc, ExprDoc, ListDocNode)
Doc that represents literal value.
Definition: doc.h:227
static constexpr const char * _type_key
Definition: doc.h:245
ObjectRef value
the internal representation of the literal value.
Definition: doc.h:238
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:240
TVM_DECLARE_FINAL_OBJECT_INFO(LiteralDocNode, ExprDocNode)
Reference type of LiteralDocNode.
Definition: doc.h:254
static LiteralDoc Float(double v, const Optional< ObjectPath > &p)
Create a LiteralDoc to represent float.
Definition: doc.h:287
static LiteralDoc Int(int64_t v, const Optional< ObjectPath > &p)
Create a LiteralDoc to represent integer.
Definition: doc.h:271
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(LiteralDoc, ExprDoc, LiteralDocNode)
static LiteralDoc Str(const String &v, const Optional< ObjectPath > &p)
Create a LiteralDoc to represent string.
Definition: doc.h:295
LiteralDoc(ObjectRef value, const Optional< ObjectPath > &object_path)
static LiteralDoc Boolean(bool v, const Optional< ObjectPath > &p)
Create a LiteralDoc to represent boolean.
Definition: doc.h:279
static LiteralDoc DataType(const runtime::DataType &v, const Optional< ObjectPath > &p)
Create a LiteralDoc to represent string.
Definition: doc.h:301
static LiteralDoc None(const Optional< ObjectPath > &p)
Create a LiteralDoc to represent None/null/empty value.
Definition: doc.h:263
Doc that represents operation.
Definition: doc.h:486
TVM_DECLARE_FINAL_OBJECT_INFO(OperationDocNode, ExprDocNode)
Array< ExprDoc > operands
Operands of this expression.
Definition: doc.h:529
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:531
static constexpr const char * _type_key
Definition: doc.h:537
Kind kind
The kind of operation (operator)
Definition: doc.h:527
Reference type of OperationDocNode.
Definition: doc.h:546
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(OperationDoc, ExprDoc, OperationDocNode)
OperationDoc(OperationDocNode::Kind kind, Array< ExprDoc > operands)
Constructor of OperationDoc.
Doc that represents return statement.
Definition: doc.h:1069
ExprDoc value
The value to return.
Definition: doc.h:1072
TVM_DECLARE_FINAL_OBJECT_INFO(ReturnDocNode, StmtDocNode)
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:1074
static constexpr const char * _type_key
Definition: doc.h:1079
Reference type of ReturnDocNode.
Definition: doc.h:1088
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ReturnDoc, StmtDoc, ReturnDocNode)
ReturnDoc(ExprDoc value)
Constructor of ReturnDoc.
Doc that represents special scopes.
Definition: doc.h:947
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:956
TVM_DECLARE_FINAL_OBJECT_INFO(ScopeDocNode, StmtDocNode)
Optional< ExprDoc > lhs
The name of the scoped variable.
Definition: doc.h:950
static constexpr const char * _type_key
Definition: doc.h:963
ExprDoc rhs
The value of the scoped variable.
Definition: doc.h:952
Array< StmtDoc > body
The body of the scope doc.
Definition: doc.h:954
Reference type of ScopeDocNode.
Definition: doc.h:972
ScopeDoc(ExprDoc rhs, Array< StmtDoc > body)
Constructor of ScopeDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ScopeDoc, StmtDoc, ScopeDocNode)
ScopeDoc(Optional< ExprDoc > lhs, ExprDoc rhs, Array< StmtDoc > body)
Constructor of ScopeDoc.
Doc that represents slice in Index expression.
Definition: doc.h:728
Optional< ExprDoc > start
The start of slice.
Definition: doc.h:731
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:737
static constexpr const char * _type_key
Definition: doc.h:744
Optional< ExprDoc > step
The step of slice.
Definition: doc.h:735
Optional< ExprDoc > stop
The exclusive end of slice.
Definition: doc.h:733
TVM_DECLARE_FINAL_OBJECT_INFO(SliceDocNode, DocNode)
Reference type of SliceDocNode.
Definition: doc.h:753
SliceDoc(Optional< ExprDoc > start, Optional< ExprDoc > stop, Optional< ExprDoc > step)
Constructor of SliceDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(SliceDoc, Doc, SliceDocNode)
The container doc that holds a list of StmtDoc.
Definition: doc.h:194
TVM_DECLARE_FINAL_OBJECT_INFO(StmtBlockDocNode, DocNode)
Array< StmtDoc > stmts
The list of statements.
Definition: doc.h:197
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:199
static constexpr const char * _type_key
Definition: doc.h:204
Reference type of StmtBlockDocNode.
Definition: doc.h:212
StmtBlockDoc(Array< StmtDoc > stmts)
Constructor of StmtBlockDoc.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(StmtBlockDoc, Doc, StmtBlockDocNode)
The base class of statement doc.
Definition: doc.h:154
TVM_DECLARE_BASE_OBJECT_INFO(StmtDocNode, DocNode)
static constexpr const char * _type_key
Definition: doc.h:171
Optional< String > comment
The comment of this doc.
Definition: doc.h:164
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:166
Reference type of StmtDocNode.
Definition: doc.h:180
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(StmtDoc, Doc, StmtDocNode)
Doc that represents tuple literal.
Definition: doc.h:603
Array< ExprDoc > elements
Elements of tuple.
Definition: doc.h:606
static constexpr const char * _type_key
Definition: doc.h:613
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:608
TVM_DECLARE_FINAL_OBJECT_INFO(TupleDocNode, ExprDocNode)
Reference type of TupleDocNode.
Definition: doc.h:622
TupleDoc(Array< ExprDoc > elements)
Constructor of TupleDoc.
TupleDoc()
Create an empty TupleDoc.
Definition: doc.h:627
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TupleDoc, ExprDoc, TupleDocNode)
Doc that represents while statement.
Definition: doc.h:858
void VisitAttrs(AttrVisitor *v)
Definition: doc.h:865
static constexpr const char * _type_key
Definition: doc.h:871
Array< StmtDoc > body
The body of the while statement.
Definition: doc.h:863
TVM_DECLARE_FINAL_OBJECT_INFO(WhileDocNode, StmtDocNode)
ExprDoc predicate
The predicate of the while statement.
Definition: doc.h:861
Reference type of WhileDocNode.
Definition: doc.h:880
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(WhileDoc, StmtDoc, WhileDocNode)
WhileDoc(ExprDoc predicate, Array< StmtDoc > body)
Constructor of WhileDoc.
Base expr nodes in TVM.
ObjectPtr< ArrayNode > make_object()
Definition: array.h:908
std::string DLDataType2String(DLDataType t)
convert a TVM type to string.
Definition: data_type.h:422
String DocToPythonScript(Doc doc, const PrinterConfig &cfg)
Convert Doc into Python script.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
constexpr runtime::NullOptType NullOpt
Definition: optional.h:169
Definitions and helper macros for IR/AST nodes.