Skip to content

Commit 67d6bb8

Browse files
committed
syn: Add slot check to parse
Assisted-by: Claude (various models) Signed-off-by: Martin Povišer <povik@cutebit.org>
1 parent 4e7267d commit 67d6bb8

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/syn/src/ir/Parse.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,13 @@ class Parser
539539
error("unknown cell keyword: " + keyword);
540540
}
541541

542-
(void) id;
542+
const uint32_t expected_slots = std::max(width, 1u);
543+
if (g->tableSize() != id + expected_slots) {
544+
error("'" + keyword + "' declared output width " + std::to_string(width)
545+
+ " but produced " + std::to_string(g->tableSize() - id) + " slot"
546+
+ (g->tableSize() - id == 1 ? "" : "s"));
547+
}
548+
543549
expectNewline();
544550
}
545551

src/syn/test/parse_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) 2026, The OpenROAD Authors
33

44
#include <sstream>
5+
#include <stdexcept>
56

67
#include "gtest/gtest.h"
78
#include "syn/ir/Graph.h"
@@ -189,4 +190,13 @@ TEST(ParseTest, NonConsecutiveIds)
189190
}
190191
}
191192

193+
TEST(ParseTest, RejectsDeclaredWidthMismatch)
194+
{
195+
std::istringstream is(
196+
"%3:8 = input \"a\"\n"
197+
"%11:8 = input \"b\"\n"
198+
"%19:16 = mul %3:8 %11:8\n");
199+
EXPECT_THROW({ (void) Graph::parse(is); }, std::runtime_error);
200+
}
201+
192202
} // namespace syn

0 commit comments

Comments
 (0)