return result.second;
}
-ReturnStmt::ReturnStmt(Statement *exp) : returnValue_{GetApplyExpr(exp)} {
- CHECK(returnValue_);
+ReturnStmt::ReturnStmt(Statement *exp) : value_{GetApplyExpr(exp)} {
+ CHECK(value_);
}
SwitchStmt::SwitchStmt(const Value &cond, BasicBlock *defaultBlock,
return SuccBlocks<SwitchRankStmt>(valueSuccPairs_);
}
-template<typename T> bool PointerNotNull(const T &variant) {
- return std::visit(
+// check LoadInsn constraints
+static void CheckLoadInsn(const Value &v) {
+ std::visit(
common::visitors{
- [](const Addressable_impl *p) { return p != nullptr; },
- [](const Value &value) { return !IsNothing(value); },
+ [](DataObject *) { /* ok */ },
+ [](Statement *s) { CHECK(GetAddressable(s)); },
+ [](auto) { CHECK(!"invalid load input"); },
},
- variant);
+ v.u);
}
-
-LoadInsn::LoadInsn(Statement *addr) : address_{GetAddressable(addr)} {
- CHECK(PointerNotNull(address_));
+LoadInsn::LoadInsn(const Value &addr) : address_{addr} {
+ CheckLoadInsn(address_);
+}
+LoadInsn::LoadInsn(Value &&addr) : address_{std::move(addr)} {
+ CheckLoadInsn(address_);
+}
+LoadInsn::LoadInsn(Statement *addr) : address_{addr} {
+ CHECK(GetAddressable(addr));
}
StoreInsn::StoreInsn(Statement *addr, Statement *val)
value_ = expr;
}
}
-
StoreInsn::StoreInsn(Statement *addr, BasicBlock *val)
: address_{GetAddressable(addr)}, value_{val} {
CHECK(address_);
[](const BranchStmt &branch) {
if (branch.hasCondition()) {
std::string cond{"???"};
-#if 0
- if (auto expr{GetApplyExpr(branch.getCond())}) {
- cond = FIR::dump(expr->expression());
- }
-#endif
return "branch (" + cond + ") " +
std::to_string(
reinterpret_cast<std::intptr_t>(branch.getTrueSucc())) +
class ReturnStmt : public TerminatorStmt_impl {
public:
static ReturnStmt Create(Statement *stmt) { return ReturnStmt{stmt}; }
+ static ReturnStmt Create() { return ReturnStmt{nullptr}; }
std::list<BasicBlock *> succ_blocks() const override { return {}; }
- Statement *returnValue() const;
+ bool has_value() const { return value_ != nullptr; }
+ Statement *value() const;
private:
- ApplyExprStmt *returnValue_;
+ ApplyExprStmt *value_;
explicit ReturnStmt(Statement *exp);
};
// Load value(s) from a location
class LoadInsn : public MemoryStmt_impl {
public:
- static LoadInsn Create(Value addr) { return LoadInsn{addr}; }
+ static LoadInsn Create(const Value &addr) { return LoadInsn{addr}; }
+ static LoadInsn Create(Value &&addr) { return LoadInsn{addr}; }
static LoadInsn Create(Statement *addr) { return LoadInsn{addr}; }
private:
- explicit LoadInsn(Value addr) : address_{addr} {}
+ explicit LoadInsn(const Value &addr);
+ explicit LoadInsn(Value &&addr);
explicit LoadInsn(Statement *addr);
- std::variant<Addressable_impl *, Value> address_;
+ Value address_;
};
// Store value(s) from an applied expression to a location
return reinterpret_cast<std::size_t>(&static_cast<Statement *>(nullptr)->u);
}
static Statement *From(Stmt_impl *stmt) {
- return reinterpret_cast<Statement *>(
- reinterpret_cast<char *>(stmt) - Statement::offsetof_impl());
+ char *cp{reinterpret_cast<char *>(stmt)};
+ auto adjust{Statement::offsetof_impl()};
+ CHECK(adjust == 0);
+ return reinterpret_cast<Statement *>(cp - adjust);
}
};
return {};
}
-inline Statement *ReturnStmt::returnValue() const {
- return Statement::From(returnValue_);
+inline Statement *ReturnStmt::value() const {
+ return Statement::From(value_);
}
inline ApplyExprStmt *GetApplyExpr(Statement *stmt) {