class Integer : public Type {
public:
- Integer(uint32_t width, bool is_signed) : width_(width), signed_(is_signed) {}
+ Integer(uint32_t w, bool is_signed) : width_(w), signed_(is_signed) {}
Integer(const Integer&) = default;
bool IsSame(Type* that) const override;
Integer* AsInteger() override { return this; }
const Integer* AsInteger() const override { return this; }
+ uint32_t width() const { return width_; }
private:
uint32_t width_; // bit width
class Float : public Type {
public:
- Float(uint32_t width) : width_(width) {}
+ Float(uint32_t w) : width_(w) {}
Float(const Float&) = default;
bool IsSame(Type* that) const override;
Float* AsFloat() override { return this; }
const Float* AsFloat() const override { return this; }
+ uint32_t width() const { return width_; }
private:
uint32_t width_; // bit width
}
}
+TEST(Types, IntWidth) {
+ std::vector<uint32_t> widths = {1, 2, 4, 8, 16, 32, 48, 64, 128};
+ std::vector<std::unique_ptr<Integer>> types;
+ for (uint32_t w : widths) {
+ types.emplace_back(new Integer(w, true));
+ }
+ for (size_t i = 0; i < widths.size(); i++) {
+ EXPECT_EQ(widths[i], types[i]->width());
+ }
+}
+
+TEST(Types, FloatWidth) {
+ std::vector<uint32_t> widths = {1, 2, 4, 8, 16, 32, 48, 64, 128};
+ std::vector<std::unique_ptr<Float>> types;
+ for (uint32_t w : widths) {
+ types.emplace_back(new Float(w));
+ }
+ for (size_t i = 0; i < widths.size(); i++) {
+ EXPECT_EQ(widths[i], types[i]->width());
+ }
+}
+
} // anonymous namespace