2021-09-27 14:02:44 -04:00
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
2021-10-10 19:41:52 -04:00
|
|
|
#include "codon/util/fmt/format.h"
|
2021-09-27 14:02:44 -04:00
|
|
|
|
2021-10-04 12:10:59 -05:00
|
|
|
using namespace codon::ir;
|
2021-09-27 14:02:44 -04:00
|
|
|
|
|
|
|
TEST_F(SIRCoreTest, ConstTypeQueryAndReplace) {
|
|
|
|
auto *node = module->Nr<IntConst>(1, module->getIntType());
|
|
|
|
ASSERT_EQ(module->getIntType(), node->getType());
|
|
|
|
|
|
|
|
auto usedTypes = node->getUsedTypes();
|
|
|
|
ASSERT_EQ(1, usedTypes.size());
|
|
|
|
ASSERT_EQ(module->getIntType(), usedTypes[0]);
|
|
|
|
ASSERT_EQ(1, node->replaceUsedType(module->getIntType(), module->getIntType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SIRCoreTest, ConstCloning) {
|
|
|
|
auto VALUE = 1;
|
|
|
|
auto *node = module->Nr<IntConst>(VALUE, module->getIntType());
|
|
|
|
auto *clone = cast<IntConst>(cv->clone(node));
|
|
|
|
|
|
|
|
ASSERT_TRUE(clone);
|
|
|
|
ASSERT_EQ(VALUE, clone->getVal());
|
|
|
|
ASSERT_EQ(module->getIntType(), clone->getType());
|
|
|
|
}
|