LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
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 "CAPIGenRegistration.h"
25#include "CommonCAPIGen.h"
26
27#include <mlir/TableGen/AttrOrTypeDef.h>
28#include <mlir/TableGen/Dialect.h>
29#include <mlir/TableGen/GenInfo.h>
30
31#include <llvm/ADT/StringExtras.h>
32#include <llvm/Support/CommandLine.h>
33#include <llvm/Support/FormatVariadic.h>
34#include <llvm/TableGen/Record.h>
35#include <llvm/TableGen/TableGenBackend.h>
36
37using namespace mlir;
38using namespace mlir::tblgen;
39
41static bool emitTypeCAPITests(const llvm::RecordKeeper &records, raw_ostream &os) {
42 // Generate file header
43 emitSourceFileHeader("Type C API Tests", os, records);
44
45 // Create generator with test object creation expression
46 AttrOrTypeTestGenerator generator("Type", os);
47
48 // Generate test class prologue
49 generator.genTestClassPrologue();
50
51 // Generate tests for each type
52 for (const auto *def : records.getAllDerivedDefinitions("TypeDef")) {
53 const AttrOrTypeDef type(def);
54 generator.genCompleteRecord(type, true);
55 }
56
57 return false;
58}
59
61 static mlir::GenRegistration genTypeCAPITests(
62 "gen-type-capi-tests", "Generate type C API unit tests", &emitTypeCAPITests
63 );
64}
This file provides common utilities for generating C API link tests for attributes and types.
void registerTypeCAPITestGenerator()
Register the type C API test generator before command-line parsing.
Base class for attribute and type test generators.