Files
revng-revng/include/revng/mlir/Dialect/Clift/IR/CliftAttributes.td
2025-03-24 09:26:43 +02:00

203 lines
6.5 KiB
TableGen

//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#ifndef MLIR_CLIFT_ATTRIBUTE
#define MLIR_CLIFT_ATTRIBUTE
include "mlir/IR/EnumAttr.td"
include "mlir/IR/SubElementInterfaces.td"
include "Clift.td"
include "CliftEnums.td"
include "CliftInterfaces.td"
class Clift_Attr<string name, string attrMnemonic, list<Trait> traits = []>
: AttrDef<Clift_Dialect, name, traits> {
let mnemonic = attrMnemonic;
}
def Clift_FieldAttr
: AttrDef<Clift_Dialect,
"Field",
[DeclareAttrInterfaceMethods<SubElementAttrInterface>]> {
let summary = "A attribute representing a field of a struct or a union";
let description = [{
A attribute representing a field of a struct or a union
}];
let parameters = (ins "uint64_t":$offset,
"mlir::clift::ValueType":$type,
StringRefParameter<>:$name);
let builders = [
AttrBuilderWithInferredContext<(ins "uint64_t":$Offset,
"mlir::clift::ValueType":$Type,
CArg<"llvm::StringRef", "\"\"">:$Name), [{
return $_get(Type.getContext(), Offset, Type, Name);
}]>,
AttrBuilderWithInferredContext<(ins "mlir::clift::ValueType":$Type,
CArg<"llvm::StringRef", "\"\"">:$Name), [{
return $_get(Type.getContext(), 0, Type, Name);
}]>
];
let genVerifyDecl = 1;
}
def Clift_EnumFieldAttr
: AttrDef<Clift_Dialect,
"EnumField",
[DeclareAttrInterfaceMethods<SubElementAttrInterface>]> {
let summary = "A attribute representing a field of enum";
let description = [{
A attribute representing a field of a struct or a union
}];
let parameters = (ins "uint64_t":$raw_value,
StringRefParameter<>:$name);
let genVerifyDecl = 1;
}
def Clift_EnumTypeAttr
: Clift_Attr<"EnumType",
"enum",
[DeclareAttrInterfaceMethods<Clift_AliasableAttr>,
DeclareAttrInterfaceMethods<Clift_TypeDefinitionAttr,
["getByteSize"]>,
SubElementAttrInterface]> {
let summary = "Clift enum type";
let parameters = (ins StringRefParameter<>:$handle,
StringRefParameter<>:$name,
"mlir::clift::ValueType":$underlying_type,
ArrayRefParameter<"mlir::clift::EnumFieldAttr">:$fields);
let builders = [
TypeBuilderWithInferredContext<(ins "llvm::StringRef":$Handle,
"llvm::StringRef":$Name,
"mlir::clift::ValueType":$ElementType,
"llvm::ArrayRef<mlir::clift::EnumFieldAttr>":$Fields), [{
return EnumTypeAttr::get(ElementType.getContext(),
Handle,
Name,
ElementType,
Fields);
}]>,
];
let description = [{
Enum type.
}];
let genVerifyDecl = 1;
let assemblyFormat = [{
`<`
$handle custom<CliftDebugName>($name) `:` $underlying_type
custom<CliftEnumerators>($fields)
`>`
}];
}
def Clift_TypedefTypeAttr
: Clift_Attr<"TypedefType",
"typedef",
[DeclareAttrInterfaceMethods<Clift_AliasableAttr>,
DeclareAttrInterfaceMethods<Clift_TypeDefinitionAttr,
["getByteSize"]>,
SubElementAttrInterface]> {
let summary = "Clift typedef type";
let parameters = (ins StringRefParameter<>:$handle,
StringRefParameter<>:$name,
"mlir::clift::ValueType":$underlying_type);
let builders = [
TypeBuilderWithInferredContext<(ins "llvm::StringRef":$Handle,
"llvm::StringRef":$Name,
"mlir::clift::ValueType":$ElementType), [{
return TypedefTypeAttr::get(ElementType.getContext(),
Handle,
Name,
ElementType);
}]>,
];
let description = [{
Typedef type.
}];
let genVerifyDecl = 1;
let assemblyFormat = [{
`<` $handle custom<CliftDebugName>($name) `:` $underlying_type `>`
}];
}
def Clift_FunctionTypeAttr
: Clift_Attr<"FunctionType",
"func",
[DeclareAttrInterfaceMethods<Clift_AliasableAttr>,
DeclareAttrInterfaceMethods<Clift_TypeDefinitionAttr,
["getByteSize"]>,
SubElementAttrInterface]> {
let summary = "Clift function type";
let parameters = (ins StringRefParameter<>:$handle,
StringRefParameter<>:$name,
"mlir::Type":$return_type,
OptionalArrayRefParameter<"mlir::Type">:$argument_types);
let builders = [
TypeBuilder<(ins "llvm::StringRef":$Handle,
"llvm::StringRef":$Name,
"mlir::clift::ValueType":$ReturnType,
"llvm::ArrayRef<mlir::clift::ValueType>":$ArgumentTypes), [{
return $_get($_ctxt,
Handle,
Name,
ReturnType,
llvm::SmallVector<mlir::Type, 16>(ArgumentTypes));
}]>,
TypeBuilderWithInferredContext<(ins "llvm::StringRef":$Handle,
"llvm::StringRef":$Name,
"mlir::clift::ValueType":$ReturnType,
"llvm::ArrayRef<mlir::clift::ValueType>":$ArgumentTypes), [{
return $_get(ReturnType.getContext(),
Handle,
Name,
ReturnType,
llvm::SmallVector<mlir::Type, 16>(ArgumentTypes));
}]>,
];
let extraClassDeclaration = [{
llvm::ArrayRef<mlir::Type> getResultTypes();
mlir::LogicalResult verify(llvm::function_ref<mlir::InFlightDiagnostic()> EmitError,
llvm::StringRef Handle,
llvm::StringRef Name,
clift::ValueType ReturnType,
llvm::ArrayRef<clift::ValueType> ArgumentTypes);
}];
let description = [{
TypeDef type.
}];
let genVerifyDecl = 1;
let assemblyFormat = [{
`<`
$handle custom<CliftDebugName>($name)
`:` $return_type `(` (`)`) : ($argument_types^ `)`)?
`>`
}];
}
#endif