junrushao1994 commented on code in PR #12048:
URL: https://github.com/apache/tvm/pull/12048#discussion_r922704537


##########
src/script/printer/python_doc_printer.cc:
##########
@@ -57,6 +82,179 @@ void PythonDocPrinter::PrintTypedDoc(const LiteralDoc& doc) 
{
   }
 }
 
+void PythonDocPrinter::PrintTypedDoc(const IdDoc& doc) { output_ << doc->name; 
}
+
+void PythonDocPrinter::PrintTypedDoc(const AttrAccessDoc& doc) {
+  PrintDoc(doc->value);
+  output_ << "." << doc->attr;
+}
+
+void PythonDocPrinter::PrintTypedDoc(const IndexDoc& doc) {
+  PrintDoc(doc->value);
+  if (doc->indices.size() == 0) {
+    output_ << "[()]";
+  } else {
+    output_ << "[";
+    PrintJoinedDocs(doc->indices, ", ");
+    output_ << "]";
+  }
+}
+
+const std::string OperatorToString(OperationDocNode::Kind operation_kind) {
+  static const std::vector<std::string> OP_STR_TABLE = []() {
+    using OpKind = OperationDocNode::Kind;
+    std::map<OpKind, std::string> raw_table = {
+        {OpKind::kUSub, "-"},       //
+        {OpKind::kInvert, "~"},     //
+        {OpKind::kAdd, "+"},        //
+        {OpKind::kSub, "-"},        //
+        {OpKind::kMult, "*"},       //
+        {OpKind::kDiv, "/"},        //
+        {OpKind::kFloorDiv, "//"},  //
+        {OpKind::kMod, "%"},        //
+        {OpKind::kPow, "**"},       //
+        {OpKind::kLShift, "<<"},    //
+        {OpKind::kRShift, ">>"},    //
+        {OpKind::kBitAnd, "&"},     //
+        {OpKind::kBitOr, "|"},      //
+        {OpKind::kBitXor, "^"},     //
+        {OpKind::kLt, "<"},         //
+        {OpKind::kLtE, "<="},       //
+        {OpKind::kEq, "=="},        //
+        {OpKind::kNotEq, "!="},     //
+        {OpKind::kGt, ">"},         //
+        {OpKind::kGtE, ">="},       //
+    };
+
+    std::vector<std::string> table;
+    table.resize(static_cast<int>(OperationDocNode::Kind::kSpecialEnd) + 1);
+
+    for (const auto& kv : raw_table) {
+      table[static_cast<int>(kv.first)] = kv.second;
+    }
+
+    return table;
+  }();
+
+  auto op_index = static_cast<int>(operation_kind);
+  ICHECK_LT(op_index, OP_STR_TABLE.size());
+  const std::string str = OP_STR_TABLE[op_index];
+  if (str.empty()) {
+    LOG(FATAL) << "OperationDocNode::Kind " << static_cast<int>(operation_kind)
+               << " cannot be converted to operator token in Python directly.";
+    throw;
+  }

Review Comment:
   you may use ICHECK directly
   
   ```suggestion
     ICHECK(!str.empty()) << "OperationDocNode::Kind " << 
static_cast<int>(operation_kind)
                  << " cannot be converted to operator token in Python 
directly.";
     }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to