diff options
author | Thomas Lively <tlively@google.com> | 2023-01-18 13:31:26 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-18 11:31:26 -0800 |
commit | 82bd2c4e5717cbe19a1a6c34cfdd5116b13a68dc (patch) | |
tree | c801db56ab7288144c0fd288cb57dec0023a9569 /test/gtest | |
parent | ab5b3e455770fec0e9ac78e566b48ec5a873a7ca (diff) | |
download | binaryen-82bd2c4e5717cbe19a1a6c34cfdd5116b13a68dc.tar.gz binaryen-82bd2c4e5717cbe19a1a6c34cfdd5116b13a68dc.tar.bz2 binaryen-82bd2c4e5717cbe19a1a6c34cfdd5116b13a68dc.zip |
Add a TypeNameGenerator that uses names from a Module (#5437)
If the module does not have a name for a particular type, the new utility falls
back to use a different user-configurable type name generator, just like the
existing IndexedTypeNameGenerator does.
Also change how heap types are printed by this printing machinery (which is
currently only used for debugging) so that their names are printed in addition
to their contents. This makes the printer much more useful for debugging.
Diffstat (limited to 'test/gtest')
-rw-r--r-- | test/gtest/type-builder.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index d26b8bb97..af6613bd2 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -103,19 +103,57 @@ TEST_F(TypeTest, IndexedTypePrinter) { std::stringstream stream; stream << print(built[0]); - EXPECT_EQ(stream.str(), "(struct (field (ref null $array1)))"); + EXPECT_EQ(stream.str(), + "(type $struct0 (struct (field (ref null $array1))))"); stream.str(""); stream << print(built[1]); - EXPECT_EQ(stream.str(), "(struct (field (ref null $struct0)))"); + EXPECT_EQ(stream.str(), + "(type $struct1 (struct (field (ref null $struct0))))"); stream.str(""); stream << print(built[2]); - EXPECT_EQ(stream.str(), "(array (ref null $struct1))"); + EXPECT_EQ(stream.str(), "(type $array0 (array (ref null $struct1)))"); stream.str(""); stream << print(built[3]); - EXPECT_EQ(stream.str(), "(array (ref null $array0))"); + EXPECT_EQ(stream.str(), "(type $array1 (array (ref null $array0)))"); +} + +TEST_F(TypeTest, ModuleTypePrinter) { + TypeBuilder builder(2); + builder.createRecGroup(0, 2); + builder[0] = Struct({Field(Type::i32, Immutable)}); + builder[1] = Struct({Field(Type::i32, Immutable)}); + + auto result = builder.build(); + ASSERT_TRUE(result); + auto built = *result; + + Module module; + module.typeNames[built[0]] = {"A", {}}; + + ModuleTypeNameGenerator printDefault(module); + + std::stringstream stream; + stream << printDefault(built[0]); + EXPECT_EQ(stream.str(), "(type $A (struct (field i32)))"); + + stream.str(""); + stream << printDefault(built[1]); + EXPECT_EQ(stream.str(), "(type $struct.0 (struct (field i32)))"); + + using IndexedFallback = IndexedTypeNameGenerator<DefaultTypeNameGenerator>; + IndexedTypeNameGenerator fallback(built); + ModuleTypeNameGenerator<IndexedFallback> printIndexed(module, fallback); + + stream.str(""); + stream << printIndexed(built[0]); + EXPECT_EQ(stream.str(), "(type $A (struct (field i32)))"); + + stream.str(""); + stream << printIndexed(built[1]); + EXPECT_EQ(stream.str(), "(type $1 (struct (field i32)))"); } TEST_F(IsorecursiveTest, Basics) { |