-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a lattice with two elements: `false` is bottom and `true` is top. Add a new gtest file for testing lattices.
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2023 WebAssembly Community Group participants | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef wasm_analysis_lattices_bool_h | ||
#define wasm_analysis_lattices_bool_h | ||
|
||
#include "../lattice.h" | ||
|
||
namespace wasm::analysis { | ||
|
||
struct Bool { | ||
using Element = bool; | ||
Element getBottom() const noexcept { return false; } | ||
LatticeComparison compare(Element a, Element b) const noexcept { | ||
return a > b ? GREATER : a == b ? EQUAL : LESS; | ||
} | ||
bool join(Element& self, Element other) const noexcept { | ||
if (!self && other) { | ||
self = other; | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
|
||
#if __cplusplus >= 202002L | ||
static_assert(Lattice<Bool>); | ||
#endif // __cplusplus >= 202002L | ||
|
||
} // namespace wasm::analysis | ||
|
||
#endif // wasm_analysis_lattices_bool_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2023 WebAssembly Community Group participants | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "analysis/lattices/bool.h" | ||
#include "gtest/gtest.h" | ||
|
||
using namespace wasm; | ||
|
||
TEST(BoolLattice, GetBottom) { | ||
analysis::Bool lattice; | ||
EXPECT_FALSE(lattice.getBottom()); | ||
} | ||
|
||
TEST(BoolLattice, Compare) { | ||
analysis::Bool lattice; | ||
EXPECT_EQ(lattice.compare(false, false), analysis::EQUAL); | ||
EXPECT_EQ(lattice.compare(false, true), analysis::LESS); | ||
EXPECT_EQ(lattice.compare(true, false), analysis::GREATER); | ||
EXPECT_EQ(lattice.compare(true, true), analysis::EQUAL); | ||
} | ||
|
||
TEST(BoolLattice, Join) { | ||
analysis::Bool lattice; | ||
bool elem = false; | ||
|
||
EXPECT_FALSE(lattice.join(elem, false)); | ||
ASSERT_FALSE(elem); | ||
|
||
EXPECT_TRUE(lattice.join(elem, true)); | ||
ASSERT_TRUE(elem); | ||
|
||
EXPECT_FALSE(lattice.join(elem, false)); | ||
ASSERT_TRUE(elem); | ||
|
||
EXPECT_FALSE(lattice.join(elem, true)); | ||
ASSERT_TRUE(elem); | ||
} |