diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-01-27 10:26:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 10:26:31 -0800 |
commit | 8265388adc8341d52aa075b937ea3f0b10c05a9f (patch) | |
tree | 8b7a87da842e1d23156ad913eba58952f58a0172 /test | |
parent | dd6f63524c35b8b9fa0cb8745f305d5dac56d545 (diff) | |
download | binaryen-8265388adc8341d52aa075b937ea3f0b10c05a9f.tar.gz binaryen-8265388adc8341d52aa075b937ea3f0b10c05a9f.tar.bz2 binaryen-8265388adc8341d52aa075b937ea3f0b10c05a9f.zip |
Add a HeapType method for getting the rec group index (#4480)
Storing the rec group index on the HeapTypeInfo avoids having to do a linear
scan through the rec group to find the index for a particular type. This will
be important for isorecursive canonicalization, which uses rec group indices.
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest/type-builder.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index 78c8037a4..9cbd04298 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -242,3 +242,30 @@ TEST_F(IsorecursiveTest, ForwardReferencedChild) { EXPECT_EQ(error->reason, TypeBuilder::ErrorReason::ForwardChildReference); EXPECT_EQ(error->index, 1u); } + +TEST_F(IsorecursiveTest, RecGroupIndices) { + TypeBuilder builder(5); + + builder.createRecGroup(0, 2); + builder[0] = Struct{}; + builder[1] = Struct{}; + + builder.createRecGroup(2, 3); + builder[2] = Struct{}; + builder[3] = Struct{}; + builder[4] = Struct{}; + + auto result = builder.build(); + ASSERT_TRUE(result); + auto built = *result; + + EXPECT_EQ(built[0].getRecGroup(), built[1].getRecGroup()); + EXPECT_EQ(built[0].getRecGroupIndex(), 0u); + EXPECT_EQ(built[1].getRecGroupIndex(), 1u); + + EXPECT_EQ(built[2].getRecGroup(), built[3].getRecGroup()); + EXPECT_EQ(built[3].getRecGroup(), built[4].getRecGroup()); + EXPECT_EQ(built[2].getRecGroupIndex(), 0u); + EXPECT_EQ(built[3].getRecGroupIndex(), 1u); + EXPECT_EQ(built[4].getRecGroupIndex(), 2u); +} |