Add IsSigned() to opt::Analysis::Integer.
authorqining <qining@google.com>
Thu, 8 Sep 2016 22:00:12 +0000 (18:00 -0400)
committerqining <qining@google.com>
Thu, 8 Sep 2016 23:32:20 +0000 (19:32 -0400)
source/opt/types.h
test/opt/test_types.cpp

index fd652d7..a7d9e7c 100644 (file)
@@ -125,6 +125,7 @@ class Integer : public Type {
   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
index dbb3a01..adbc870 100644 (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) {
   std::vector<uint32_t> widths = {1, 2, 4, 8, 16, 32, 48, 64, 128};
   std::vector<std::unique_ptr<Integer>> types;