|
7 | 7 | #include <llvm/Support/MemoryBuffer.h> |
8 | 8 |
|
9 | 9 | #include <algorithm> |
| 10 | +#include <format> |
10 | 11 | #include <string> |
11 | 12 | #include <vector> |
12 | 13 |
|
@@ -299,6 +300,26 @@ void ExprRule::dump() const { |
299 | 300 | } |
300 | 301 | } |
301 | 302 |
|
| 303 | +void ExprRule::validate(const std::string &name) const { |
| 304 | + if (src.empty()) { |
| 305 | + llvm::errs() << name << '\n'; |
| 306 | + dump(); |
| 307 | + assert(0 && "Expr rule loaded from IR but has no src"); |
| 308 | + } |
| 309 | + |
| 310 | + // Check that both source and target use the same generics. |
| 311 | + for (unsigned i = 0; i < generics.size(); ++i) { |
| 312 | + auto placeholder = std::format("T{}", i + 1); |
| 313 | + if (src.find(placeholder) == std::string::npos) { |
| 314 | + llvm::errs() << name << '\n'; |
| 315 | + dump(); |
| 316 | + llvm::errs() << "generic " << placeholder |
| 317 | + << " declared but missing from src: " << src << '\n'; |
| 318 | + assert(0 && "Expr rule declares a generic absent from its src"); |
| 319 | + } |
| 320 | + } |
| 321 | +} |
| 322 | + |
302 | 323 | void GenericFragment::dump() const { log() << " generic: " << n << '\n'; } |
303 | 324 |
|
304 | 325 | void TypeInfo::dump() const { |
@@ -335,11 +356,7 @@ std::pair<ExprRules, TypeRules> Load(const std::filesystem::path &path, |
335 | 356 | LoadIrSrc(exprs, types, dir / "ir_src.json"); |
336 | 357 |
|
337 | 358 | for (auto &[name, rule] : exprs) { |
338 | | - if (rule.src.empty()) { |
339 | | - llvm::errs() << name << '\n'; |
340 | | - rule.dump(); |
341 | | - assert(0 && "Expr rule loaded from IR but has no src"); |
342 | | - } |
| 359 | + rule.validate(name); |
343 | 360 | } |
344 | 361 | for (auto &[name, rule] : types) { |
345 | 362 | if (rule.src.empty()) { |
|
0 commit comments