Add IsSigned() to opt::Analysis::Integer.
diff --git a/source/opt/types.h b/source/opt/types.h
index fd652d7..a7d9e7c 100644
--- a/source/opt/types.h
+++ b/source/opt/types.h
@@ -125,6 +125,7 @@
Integer* AsInteger() override { return this; }
const Integer* AsInteger() const override { return this; }
uint32_t width() const { return width_; }
+ bool IsSigned() const { return signed_; }
private:
uint32_t width_; // bit width
diff --git a/test/opt/test_types.cpp b/test/opt/test_types.cpp
index dbb3a01..adbc870 100644
--- a/test/opt/test_types.cpp
+++ b/test/opt/test_types.cpp
@@ -208,6 +208,17 @@
}
}
+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) {
std::vector<uint32_t> widths = {1, 2, 4, 8, 16, 32, 48, 64, 128};
std::vector<std::unique_ptr<Integer>> types;