It is impossible to implement general cast<T> helper under open Instr
class hierarchy.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
/**
* @brief Cast as a derived instruction
*
- * @note "ins" cannot be a null pointer
- * @note The behavior is undefined when "isa<T>(ins)" does not hold.
- */
-template <typename T> T *cast(Instr *ins);
-
-/**
- * @brief Cast as a derived instruction
- *
* @note "safe_cast<T>(ins)" returns a null pointer if "ins" is not of T type
* @note "safe_cast<T>(ins)" returns a null pointer if "ins" is a null pointer
*/
#undef INSTR
//
-// cast<T>
-//
-#define INSTR(Name) \
- template <> Name *cast<Name>(Instr * ins) \
- { \
- assert(ins != nullptr); \
- auto casted = ins->as##Name(); \
- assert(casted != nullptr); \
- return casted; \
- }
-#include "coco/IR/Instr.lst"
-#undef INSTR
-
-//
// safe_cast<T>
//
#define INSTR(Name) \
auto ins = entity->instr()->create<Name>(); \
ASSERT_EQ(ins->module(), m.get()); \
ASSERT_TRUE(coco::isa<Name>(ins)); \
- ASSERT_NE(coco::cast<Name>(ins), nullptr); \
ASSERT_NE(coco::safe_cast<Name>(ins), nullptr); \
}
#include "coco/IR/Instr.lst"