Skip to content

Commit

Permalink
use ostream
Browse files Browse the repository at this point in the history
  • Loading branch information
TennyZhuang committed Oct 18, 2021
1 parent 7c996a5 commit c6cb005
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion taichi/ir/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

TLANG_NAMESPACE_BEGIN

void Expr::serialize(std::stringstream &ss) const {
void Expr::serialize(std::ostream &ss) const {
TI_ASSERT(expr);
expr->serialize(ss);
}
Expand Down
2 changes: 1 addition & 1 deletion taichi/ir/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Expr {
Expr operator[](const ExprGroup &indices) const;

std::string serialize() const;
void serialize(std::stringstream &ss) const;
void serialize(std::ostream &ss) const;

void operator+=(const Expr &o);
void operator-=(const Expr &o);
Expand Down
2 changes: 1 addition & 1 deletion taichi/ir/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ExprGroup ExprGroup::loaded() const {
return indices_loaded;
}

void ExprGroup::serialize(std::stringstream &ss) const {
void ExprGroup::serialize(std::ostream &ss) const {
for (int i = 0; i < (int)exprs.size(); i++) {
exprs[i].serialize(ss);
if (i + 1 < (int)exprs.size()) {
Expand Down
4 changes: 2 additions & 2 deletions taichi/ir/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Expression {
stmt = nullptr;
}

virtual void serialize(std::stringstream &ss) = 0;
virtual void serialize(std::ostream &ss) = 0;

virtual void flatten(FlattenContext *ctx) {
TI_NOT_IMPLEMENTED;
Expand Down Expand Up @@ -99,7 +99,7 @@ class ExprGroup {
return exprs[i];
}

void serialize(std::stringstream &ss) const;
void serialize(std::ostream &ss) const;

std::string serialize() const;

Expand Down
12 changes: 6 additions & 6 deletions taichi/ir/frontend_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void RandExpression::flatten(FlattenContext *ctx) {
stmt = ctx->back_stmt();
}

void UnaryOpExpression::serialize(std::stringstream &ss) {
void UnaryOpExpression::serialize(std::ostream &ss) {
ss << '(';
if (is_cast()) {
ss << (type == UnaryOpType::cast_value ? "" : "reinterpret_");
Expand Down Expand Up @@ -187,7 +187,7 @@ void GlobalVariableExpression::flatten(FlattenContext *ctx) {
ctx->push_back(std::move(ptr));
}

void GlobalPtrExpression::serialize(std::stringstream &ss) {
void GlobalPtrExpression::serialize(std::ostream &ss) {
if (snode) {
ss << snode->get_node_type_name_hinted();
} else {
Expand Down Expand Up @@ -304,7 +304,7 @@ void RangeAssumptionExpression::flatten(FlattenContext *ctx) {
stmt = ctx->back_stmt();
}

void LoopUniqueExpression::serialize(std::stringstream &ss) {
void LoopUniqueExpression::serialize(std::ostream &ss) {
ss << "loop_unique(";
input.serialize(ss);
for (int i = 0; i < covers.size(); i++) {
Expand Down Expand Up @@ -344,7 +344,7 @@ void IdExpression::flatten(FlattenContext *ctx) {
}
}

void AtomicOpExpression::serialize(std::stringstream &ss) {
void AtomicOpExpression::serialize(std::ostream &ss) {
if (op_type == AtomicOpType::add) {
ss << "atomic_add(";
} else if (op_type == AtomicOpType::sub) {
Expand Down Expand Up @@ -395,7 +395,7 @@ void AtomicOpExpression::flatten(FlattenContext *ctx) {
stmt = ctx->back_stmt();
}

void SNodeOpExpression::serialize(std::stringstream &ss) {
void SNodeOpExpression::serialize(std::ostream &ss) {
ss << snode_op_type_name(op_type);
ss << '(';
ss << snode->get_node_type_name_hinted() << ", [";
Expand Down Expand Up @@ -477,7 +477,7 @@ void FuncCallExpression::flatten(FlattenContext *ctx) {
stmt = ctx->back_stmt();
}

void FuncCallExpression::serialize(std::stringstream &ss) {
void FuncCallExpression::serialize(std::ostream &ss) {
ss << "func_call(\"" << func->func_key.get_full_name() << "\", ";
args.serialize(ss);
ss << ')';
Expand Down
44 changes: 22 additions & 22 deletions taichi/ir/frontend_ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class ArgLoadExpression : public Expression {
ArgLoadExpression(int arg_id, DataType dt) : arg_id(arg_id), dt(dt) {
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << fmt::format("arg[{}] (dt={})", arg_id, data_type_name(dt));
}

Expand All @@ -256,7 +256,7 @@ class RandExpression : public Expression {
RandExpression(DataType dt) : dt(dt) {
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << fmt::format("rand<{}>()", data_type_name(dt));
}

Expand All @@ -276,7 +276,7 @@ class UnaryOpExpression : public Expression {

bool is_cast() const;

void serialize(std::stringstream &ss) override;
void serialize(std::ostream &ss) override;

void flatten(FlattenContext *ctx) override;
};
Expand All @@ -292,7 +292,7 @@ class BinaryOpExpression : public Expression {
this->rhs.set(smart_load(rhs));
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << '(';
lhs->serialize(ss);
ss << ' ';
Expand Down Expand Up @@ -320,7 +320,7 @@ class TernaryOpExpression : public Expression {
this->op3.set(load_if_ptr(op3));
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << ternary_type_name(type) << '(';
op1->serialize(ss);
ss << ' ';
Expand All @@ -346,7 +346,7 @@ class InternalFuncCallExpression : public Expression {
}
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << "internal call " << func_name << '(';
std::string args_str;
for (int i = 0; i < args.size(); i++) {
Expand Down Expand Up @@ -375,7 +375,7 @@ class ExternalFuncCallExpression : public Expression {
: func(func), source(source), args(args), outputs(outputs) {
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
if (func) {
ss << fmt::format("call {:x} (", (uint64)func);
} else {
Expand Down Expand Up @@ -416,7 +416,7 @@ class ExternalTensorExpression : public Expression {
set_attribute("dim", std::to_string(dim));
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << fmt::format("{}d_ext_arr", dim);
}

Expand Down Expand Up @@ -452,7 +452,7 @@ class GlobalVariableExpression : public Expression {
set_attribute("dim", std::to_string(snode->num_active_indices));
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << "#" << ident.name();
}

Expand All @@ -473,7 +473,7 @@ class GlobalPtrExpression : public Expression {
: snode(snode), indices(indices) {
}

void serialize(std::stringstream &ss) override;
void serialize(std::ostream &ss) override;

void flatten(FlattenContext *ctx) override;

Expand All @@ -500,7 +500,7 @@ class TensorElementExpression : public Expression {

bool is_global_tensor() const;

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
var.serialize(ss);
ss << '[';
for (int i = 0; i < (int)indices.size(); i++) {
Expand Down Expand Up @@ -533,7 +533,7 @@ class EvalExpression : public Expression {
// cache stmt->id since it may be released later
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << '%' << stmt_id;
}

Expand All @@ -554,7 +554,7 @@ class RangeAssumptionExpression : public Expression {
: input(input), base(base), low(low), high(high) {
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << "assume_in_range({";
base.serialize(ss);
ss << fmt::format("{:+d}", low);
Expand All @@ -577,7 +577,7 @@ class LoopUniqueExpression : public Expression {
: input(input), covers(covers) {
}

void serialize(std::stringstream &ss) override;
void serialize(std::ostream &ss) override;

void flatten(FlattenContext *ctx) override;
};
Expand All @@ -590,7 +590,7 @@ class IdExpression : public Expression {
IdExpression(const Identifier &id) : id(id) {
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << id.name();
}

Expand All @@ -615,7 +615,7 @@ class AtomicOpExpression : public Expression {
: op_type(op_type), dest(dest), val(val) {
}

void serialize(std::stringstream &ss) override;
void serialize(std::ostream &ss) override;

void flatten(FlattenContext *ctx) override;
};
Expand All @@ -638,7 +638,7 @@ class SNodeOpExpression : public Expression {
: snode(snode), op_type(op_type), indices(indices), value(value) {
}

void serialize(std::stringstream &ss) override;
void serialize(std::ostream &ss) override;

void flatten(FlattenContext *ctx) override;
};
Expand All @@ -649,7 +649,7 @@ class LocalLoadExpression : public Expression {
LocalLoadExpression(const Expr &ptr) : ptr(ptr) {
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << "lcl load ";
ptr.serialize(ss);
}
Expand All @@ -663,7 +663,7 @@ class GlobalLoadExpression : public Expression {
GlobalLoadExpression(const Expr &ptr) : ptr(ptr) {
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << "gbl load ";
ptr.serialize(ss);
}
Expand All @@ -679,7 +679,7 @@ class ConstExpression : public Expression {
ConstExpression(const T &x) : val(x) {
}

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << val.stringify();
}

Expand All @@ -691,7 +691,7 @@ class ExternalTensorShapeAlongAxisExpression : public Expression {
Expr ptr;
int axis;

void serialize(std::stringstream &ss) override {
void serialize(std::ostream &ss) override {
ss << "external_tensor_shape_along_axis(";
ptr->serialize(ss);
ss << ", " << axis << ')';
Expand All @@ -709,7 +709,7 @@ class FuncCallExpression : public Expression {
Function *func;
ExprGroup args;

void serialize(std::stringstream &ss) override;
void serialize(std::ostream &ss) override;

FuncCallExpression(Function *func, const ExprGroup &args)
: func(func), args(args) {
Expand Down
8 changes: 4 additions & 4 deletions taichi/util/action_recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

TI_NAMESPACE_BEGIN

void ActionArg::serialize(std::stringstream &ss) const {
void ActionArg::serialize(std::ostream &ss) const {
ss << key << ": ";
if (type == argument_type::str) {
ss << lang::c_quoted(val_str);
Expand Down Expand Up @@ -46,9 +46,9 @@ void ActionRecorder::record(const std::string &content,
return;
ofs << "- action: \"" << content << "\"" << std::endl;
for (auto &arg : arguments) {
std::stringstream ss;
arg.serialize(ss);
ofs << " " << ss.str() << std::endl;
ofs << " ";
arg.serialize(ofs);
ofs << std::endl;
}
ofs.flush();
}
Expand Down
2 changes: 1 addition & 1 deletion taichi/util/action_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ActionArg {
: key(key), val_float64(val), type(argument_type::float64) {
}

void serialize(std::stringstream &ss) const;
void serialize(std::ostream &ss) const;

std::string key;

Expand Down

0 comments on commit c6cb005

Please sign in to comment.