LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
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 "
CAPIGenRegistration.h
"
24
#include "
CommonAttrOrTypeCAPITestGen.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
37
using namespace
mlir
;
38
using namespace
mlir::tblgen
;
39
41
static
bool
emitAttrCAPITests(
const
llvm::RecordKeeper &records, raw_ostream &os) {
42
// Generate file header
43
emitSourceFileHeader(
"Attr C API Tests"
, os, records);
44
45
// Create generator with test object creation expression
46
AttrOrTypeTestGenerator
generator(
"Attribute"
, os);
47
48
// Generate test class prologue
49
generator.genTestClassPrologue();
50
51
// Generate tests for each attribute
52
for
(
const
auto
*def : records.getAllDerivedDefinitions(
"AttrDef"
)) {
53
const
AttrOrTypeDef attr(def);
54
generator.genCompleteRecord(attr,
false
);
55
}
56
57
return
false
;
58
}
59
60
void
llzk::registerAttrCAPITestGenerator
() {
61
static
mlir::GenRegistration genAttrCAPITests(
62
"gen-attr-capi-tests"
,
"Generate attribute C API unit tests"
, &emitAttrCAPITests
63
);
64
}
CAPIGenRegistration.h
CommonAttrOrTypeCAPITestGen.h
This file provides common utilities for generating C API link tests for attributes and types.
CommonCAPIGen.h
llzk::registerAttrCAPITestGenerator
void registerAttrCAPITestGenerator()
Register the attribute C API test generator before command-line parsing.
Definition
AttrCAPITestGen.cpp:60
mlir::tblgen
Definition
CommonCAPIGen.h:50
mlir
Definition
CommonCAPIGen.h:50
AttrOrTypeTestGenerator
Base class for attribute and type test generators.
Definition
CommonAttrOrTypeCAPITestGen.h:78
tools
llzk-tblgen
AttrCAPITestGen.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.