Add IsSigned() to opt::Analysis::Integer.

This commit is contained in:
qining 2016-09-08 18:00:12 -04:00
parent 1773b95737
commit 049f80f3b9
2 changed files with 12 additions and 0 deletions

View File

@ -125,6 +125,7 @@ class Integer : public Type {
Integer* AsInteger() override { return this; } Integer* AsInteger() override { return this; }
const Integer* AsInteger() const override { return this; } const Integer* AsInteger() const override { return this; }
uint32_t width() const { return width_; } uint32_t width() const { return width_; }
bool IsSigned() const { return signed_; }
private: private:
uint32_t width_; // bit width uint32_t width_; // bit width

View File

@ -208,6 +208,17 @@ TEST(Types, AllTypes) {
} }
} }
TEST(Types, IntSignedness) {
std::vector<bool> signednesses = {true, false, false, true};
std::vector<std::unique_ptr<Integer>> types;
for (bool s : signednesses) {
types.emplace_back(new Integer(32, s));
}
for (size_t i = 0; i < signednesses.size(); i++) {
EXPECT_EQ(signednesses[i], types[i]->IsSigned());
}
}
TEST(Types, IntWidth) { TEST(Types, IntWidth) {
std::vector<uint32_t> widths = {1, 2, 4, 8, 16, 32, 48, 64, 128}; std::vector<uint32_t> widths = {1, 2, 4, 8, 16, 32, 48, 64, 128};
std::vector<std::unique_ptr<Integer>> types; std::vector<std::unique_ptr<Integer>> types;