LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
CommonAttrOrTypeCAPITestGen.h File Reference

This file provides common utilities for generating C API link tests for attributes and types. More...

#include <mlir/TableGen/AttrOrTypeDef.h>
#include <mlir/TableGen/Dialect.h>
#include <llvm/ADT/StringExtras.h>
#include <llvm/Support/FormatVariadic.h>
#include <llvm/Support/raw_ostream.h>
#include "CommonCAPIGen.h"
Include dependency graph for CommonAttrOrTypeCAPITestGen.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  AttrOrTypeTestGenerator
 Base class for attribute and type test generators. More...

Functions

std::string generateDummyParamsForAttrOrTypeGet (const mlir::tblgen::AttrOrTypeDef &def, bool isType)
 Generate dummy parameters for Get builder (used by both Attr and Type)
std::string generateParamListForAttrOrTypeGet (const mlir::tblgen::AttrOrTypeDef &def)
 Generate parameter list for Get builder call (used by both Attr and Type)

Detailed Description

This file provides common utilities for generating C API link tests for attributes and types.

The test generation strategy is:

Test Philosophy: These are link-time verification tests, not functional tests. They ensure that all generated C API functions compile correctly and link properly, catching issues like:

  • Missing function definitions (link errors)
  • Signature mismatches between header and implementation
  • Missing symbols in the build system
  • ABI compatibility problems
  • Breaking changes from refactoring

Test Pattern: Each test creates a dummy object (IndexType or IntegerAttr from MLIR builtins) and wraps the C API function call inside a conditional that checks if the dummy object is of the target dialect type. Since the dummy is from a different dialect, the condition is always false at runtime, but the compiler still verifies type correctness and the linker ensures symbol resolution.

Limitations: These tests do NOT verify:

  • Runtime correctness of the generated code
  • Semantic behavior of the operations
  • Error handling paths
  • Generator logic bugs (if generator is wrong, tests will be wrong too)

For functional testing, separate integration tests are needed.

Definition in file CommonAttrOrTypeCAPITestGen.h.

Function Documentation

◆ generateDummyParamsForAttrOrTypeGet()

std::string generateDummyParamsForAttrOrTypeGet ( const mlir::tblgen::AttrOrTypeDef & def,
bool isType )

Generate dummy parameters for Get builder (used by both Attr and Type)

Parameters
defThe attribute or type definition
isTypetrue if generating for a type, false for an attribute
Returns
String containing dummy parameter declarations

This function generates C code that declares dummy variables for all parameters of an attribute or type Get builder. For ArrayRef parameters, it generates both a count variable and an array variable. For MlirType/MlirAttribute parameters, it calls helper functions to create test instances.

◆ generateParamListForAttrOrTypeGet()

std::string generateParamListForAttrOrTypeGet ( const mlir::tblgen::AttrOrTypeDef & def)

Generate parameter list for Get builder call (used by both Attr and Type)

Parameters
defThe attribute or type definition
Returns
String containing the parameter list

This function generates a comma-separated list of parameter names to pass to a Get builder function. For ArrayRef parameters, it includes both the count and array pointer. For regular parameters, it includes just the parameter name.