LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
TypeCAPITestGen.cpp
Go to the documentation of this file.
1//===- TypeCAPITestGen.cpp - C API test generator for types ---------------===//
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// TypeCAPITestGen generates unit tests for the C API types generated by
11// TypeCAPIGen. 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 type (IndexType)
16// - Tests then call the generated C API functions inside an if statement that
17// checks if the dummy type 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 emitTypeCAPITests(const llvm::RecordKeeper &records, raw_ostream &os) {
41 // Generate file header
42 emitSourceFileHeader("Type C API Tests", os, records);
43
44 // Create generator with test object creation expression
45 AttrOrTypeTestGenerator generator("Type", os);
46
47 // Generate test class prologue
48 generator.genTestClassPrologue();
49
50 // Generate tests for each type
51 for (const auto *def : records.getAllDerivedDefinitions("TypeDef")) {
52 const AttrOrTypeDef type(def);
53 generator.genCompleteRecord(type, true);
54 }
55
56 return false;
57}
58
59static mlir::GenRegistration
60 genTypeCAPITests("gen-type-capi-tests", "Generate type C API unit tests", &emitTypeCAPITests);
This file provides common utilities for generating C API link tests for attributes and types.
Base class for attribute and type test generators.