LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
AttrCAPITestGen.cpp
Go to the documentation of this file.
1//===- AttrCAPITestGen.cpp - C API test generator for attributes ----------===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9//
10// AttrCAPITestGen generates unit tests for the C API attributes generated by
11// AttrCAPIGen. These are link-time tests that ensure all generated functions
12// compile and link properly.
13//
14// Test Strategy:
15// - Each test creates a dummy attribute (IntegerAttr)
16// - Tests then call the generated C API functions inside an if statement that
17// checks if the dummy attribute is of the target type (always false)
18// - This ensures compile-time type checking and link-time symbol resolution
19// without actually executing the code at runtime
20//
21//===----------------------------------------------------------------------===//
22
23#include <mlir/TableGen/AttrOrTypeDef.h>
24#include <mlir/TableGen/Dialect.h>
25#include <mlir/TableGen/GenInfo.h>
26
27#include <llvm/ADT/StringExtras.h>
28#include <llvm/Support/CommandLine.h>
29#include <llvm/Support/FormatVariadic.h>
30#include <llvm/TableGen/Record.h>
31#include <llvm/TableGen/TableGenBackend.h>
32
34#include "CommonCAPIGen.h"
35
36using namespace mlir;
37using namespace mlir::tblgen;
38
40static bool emitAttrCAPITests(const llvm::RecordKeeper &records, raw_ostream &os) {
41 // Generate file header
42 emitSourceFileHeader("Attr C API Tests", os, records);
43
44 // Create generator with test object creation expression
45 AttrOrTypeTestGenerator generator("Attribute", os);
46
47 // Generate test class prologue
48 generator.genTestClassPrologue();
49
50 // Generate tests for each attribute
51 for (const auto *def : records.getAllDerivedDefinitions("AttrDef")) {
52 const AttrOrTypeDef attr(def);
53 generator.genCompleteRecord(attr, false);
54 }
55
56 return false;
57}
58
59static mlir::GenRegistration genAttrCAPITests(
60 "gen-attr-capi-tests", "Generate attribute C API unit tests", &emitAttrCAPITests
61);
This file provides common utilities for generating C API link tests for attributes and types.
Base class for attribute and type test generators.