From add95b14f74e6dbe04a6efe98ff0f20424930b73 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Tue, 3 Feb 2026 14:59:53 -0500 Subject: [willow]: initial frontend work, unit tests (#8) --- willow/unittest/ir/BUILD.bazel | 16 ++++++++++++ willow/unittest/ir/VerifierTest.cpp | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 willow/unittest/ir/BUILD.bazel create mode 100644 willow/unittest/ir/VerifierTest.cpp (limited to 'willow/unittest/ir') diff --git a/willow/unittest/ir/BUILD.bazel b/willow/unittest/ir/BUILD.bazel new file mode 100644 index 0000000..b41dfcd --- /dev/null +++ b/willow/unittest/ir/BUILD.bazel @@ -0,0 +1,16 @@ +cc_test( + name = "verifier", + srcs = ["VerifierTest.cpp"], + deps = [ + "//willow", + "@catch2//:catch2_main" + ], + tags = ["ir"] +) + +test_suite( + name = "ir_tests", + tests = [ + ":verifier" + ], +) diff --git a/willow/unittest/ir/VerifierTest.cpp b/willow/unittest/ir/VerifierTest.cpp new file mode 100644 index 0000000..959d72a --- /dev/null +++ b/willow/unittest/ir/VerifierTest.cpp @@ -0,0 +1,51 @@ +#include + +#include +#include +#include +#include +#include +#include + +using namespace willow; + +TEST_CASE("valid modules", "[verifier]") { + WillowContext ctx; + std::vector diags; + DiagnosticEngine eng( + [&](Diagnostic d) { diags.push_back(std::move(d)); }); + + auto &m = *ctx.addModule("test"); + SECTION("empty module") { + REQUIRE(succeeded(verifyModule(ctx, m, eng))); + REQUIRE(diags.empty()); + } +} + +TEST_CASE("valid function", "[verifier]") { + WillowContext ctx; + std::vector diags; + DiagnosticEngine eng( + [&](Diagnostic d) { diags.push_back(std::move(d)); }); + + auto &m = *ctx.addModule("test"); + + Type fty = ctx.types().FunctionType(ctx.types().VoidType(), {}); + auto &fn = *m.emplaceFunction("fn", &m, fty); + + REQUIRE(succeeded(verifyFunction(ctx, fn, eng))); + REQUIRE(diags.empty()); +} + +TEST_CASE("invalid basic block", "[verifier]") { + WillowContext ctx; + std::vector diags; + DiagnosticEngine eng( + [&](Diagnostic d) { diags.push_back(std::move(d)); }); + + auto &m = *ctx.addModule("test"); + + Type fty = ctx.types().FunctionType(ctx.types().VoidType(), {}); + auto &fn = *m.emplaceFunction("fn", &m, fty); + // TODO +} -- cgit v1.2.3