1#ifndef FREE_TENSOR_PRINT_AST_H
2#define FREE_TENSOR_PRINT_AST_H
6#include <unordered_set>
14 bool printAllId_ =
false, pretty_ =
false, dtypeInLoad_ =
false,
15 hexFloat_ =
false, parenDespitePriority_ =
false,
16 printSourceLocation_ =
false;
17 const std::unordered_set<std::string> keywords = {
18 "if",
"else",
"for",
"from",
"until",
"step",
19 "length",
"assert",
"assume",
"func",
"true",
"false",
29 enum class Precedence {
50 Precedence precedence_ = Precedence::ANY;
60 void precedence_enclose(Precedence new_priority,
auto inner,
61 bool parentheses =
true) {
62 auto old_priority = precedence_;
63 precedence_ = new_priority;
65 (parenDespitePriority_ || old_priority > precedence_))
69 (parenDespitePriority_ || old_priority > precedence_))
71 precedence_ = old_priority;
80 void precedence_new(
auto inner) {
81 precedence_enclose(Precedence::ANY, inner,
false);
86 bool dtypeInLoad =
false,
bool hexFloat =
false,
87 bool compact =
false,
bool parenDespitePriority =
false,
88 bool printSourceLocation =
false)
89 :
CodeGen(compact), printAllId_(printAllId), pretty_(pretty),
90 dtypeInLoad_(dtypeInLoad), hexFloat_(hexFloat),
91 parenDespitePriority_(parenDespitePriority),
92 printSourceLocation_(printSourceLocation) {
99 void recur(
const Expr &op);
100 void recur(
const Stmt &op);
101 void printMetadataAndId(
const Stmt &op);
103 std::string escape(
const std::string &name);
104 std::string prettyIterName(
const std::string &name);
105 std::string prettyVarDefName(
const std::string &name);
106 std::string prettyFuncName(
const std::string &name);
107 std::function<std::ostream &(std::ostream &)> prettyId(
const ID &
id);
108 std::string prettyLiteral(
const std::string &lit);
109 std::string prettyKeyword(
const std::string &kw);
110 std::string prettyDType(
const DataType &dtype);
140 void visit(
const LT &op)
override;
141 void visit(
const LE &op)
override;
142 void visit(
const GT &op)
override;
143 void visit(
const GE &op)
override;
144 void visit(
const EQ &op)
override;
145 void visit(
const NE &op)
override;
151 void visit(
const Ln &op)
override;
165 void visit(
const If &op)
override;
182std::string
toString(
const AST &op,
bool pretty,
bool printAllId);
183std::string
toString(
const AST &op,
bool pretty,
bool printAllId,
184 bool dtypeInLoad,
bool hexFloat =
false,
185 bool compact =
false,
bool parenDespitePriority =
false);
186std::string
toString(
const AST &op,
bool pretty,
bool printAllId,
187 bool dtypeInLoad,
bool hexFloat,
bool compact,
188 bool parenDespitePriority,
bool printSourceLocation);
194inline std::string
dumpAST(
const AST &op,
bool dtypeInLoad =
false,
195 bool hexFloat =
true) {
196 return toString(op,
false,
true, dtypeInLoad, hexFloat,
true,
false,
false);
Definition: code_gen.h:28
std::ostream & os()
Definition: code_gen.h:87
Definition: data_type.h:106
Definition: print_ast.h:13
void visitStmt(const Stmt &op) override
Definition: print_ast.cc:134
void visit(const Func &op) override
Definition: print_ast.cc:141
PrintVisitor(bool printAllId=false, bool pretty=false, bool dtypeInLoad=false, bool hexFloat=false, bool compact=false, bool parenDespitePriority=false, bool printSourceLocation=false)
Definition: print_ast.h:85
Definition: allocator.h:9
std::function< std::ostream &(std::ostream &)> manipNoIdSign(bool flag)
Definition: id.cc:8
std::function< std::ostream &(std::ostream &)> manipNoPrettyAST(bool flag)
Definition: print_ast.cc:814
std::ostream & manipMetadataSkipLocation(std::ostream &)
Definition: metadata.cc:33
std::string toString(const AST &op)
Definition: print_ast.cc:784
Ref< ASTNode > AST
Definition: ast.h:149
std::string dumpAST(const AST &op, bool dtypeInLoad=false, bool hexFloat=true)
Definition: print_ast.h:194
std::ostream & manipMetadataWithLocation(std::ostream &)
Definition: metadata.cc:37
int OSTREAM_NO_PRETTY
Definition: print_ast.cc:813
std::ostream & operator<<(std::ostream &os, const Dependence &dep)
Definition: deps.cc:1404