LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
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 "
CommonAttrOrTypeCAPITestGen.h
"
24
#include "
CommonCAPIGen.h
"
25
26
#include <mlir/TableGen/AttrOrTypeDef.h>
27
#include <mlir/TableGen/Dialect.h>
28
#include <mlir/TableGen/GenInfo.h>
29
30
#include <llvm/ADT/StringExtras.h>
31
#include <llvm/Support/CommandLine.h>
32
#include <llvm/Support/FormatVariadic.h>
33
#include <llvm/TableGen/Record.h>
34
#include <llvm/TableGen/TableGenBackend.h>
35
36
using namespace
mlir
;
37
using namespace
mlir::tblgen;
38
40
static
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
59
static
mlir::GenRegistration
60
genTypeCAPITests(
"gen-type-capi-tests"
,
"Generate type C API unit tests"
, &emitTypeCAPITests);
CommonAttrOrTypeCAPITestGen.h
This file provides common utilities for generating C API link tests for attributes and types.
CommonCAPIGen.h
mlir
Definition
ValueModel.h:30
AttrOrTypeTestGenerator
Base class for attribute and type test generators.
Definition
CommonAttrOrTypeCAPITestGen.h:78
tools
llzk-tblgen
TypeCAPITestGen.cpp
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.