-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some basic boilerplate and support for bit / int and bool P4 types
Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
- Loading branch information
Showing
18 changed files
with
432 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_H | ||
#define P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_H | ||
|
||
#include "mlir/IR/BuiltinAttributes.h" | ||
#include "p4mlir/Dialect/P4HIR/P4HIR_Types.h" | ||
|
||
#define GET_ATTRDEF_CLASSES | ||
#include "p4mlir/Dialect/P4HIR/P4HIR_Attrs.h.inc" | ||
|
||
#endif // P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifndef P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_TD | ||
#define P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_TD | ||
|
||
include "mlir/IR/BuiltinAttributeInterfaces.td" | ||
include "mlir/IR/EnumAttr.td" | ||
|
||
include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.td" | ||
|
||
class P4HIR_Attr<string name, string attrMnemonic, list<Trait> traits = []> | ||
: AttrDef<P4HIR_Dialect, name, traits> { | ||
let mnemonic = attrMnemonic; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// BoolAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def P4_BoolAttr : P4HIR_Attr<"Bool", "bool", [TypedAttrInterface]> { | ||
let summary = "Represent true/false for !p4hir.bool types"; | ||
let description = [{ | ||
The BoolAttr represents a 'true' or 'false' value. | ||
}]; | ||
|
||
let parameters = (ins AttributeSelfTypeParameter<"", "BoolType">:$type, | ||
"bool":$value); | ||
|
||
let assemblyFormat = [{ | ||
`<` $value `>` | ||
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// IntegerAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def IntAttr : P4HIR_Attr<"Int", "int", [TypedAttrInterface]> { | ||
let summary = "An Attribute containing a integer value"; | ||
let description = [{ | ||
An integer attribute is a literal attribute that represents an integral | ||
value of the specified integer type. | ||
}]; | ||
let parameters = (ins AttributeSelfTypeParameter<"">:$type, "llvm::APInt":$value); | ||
let builders = [ | ||
AttrBuilderWithInferredContext<(ins "mlir::Type":$type, "const llvm::APInt &":$value), [{ | ||
return $_get(type.getContext(), type, value); | ||
}]>, | ||
AttrBuilderWithInferredContext<(ins "mlir::Type":$type, "int64_t":$value), [{ | ||
BitsType intType = mlir::cast<BitsType>(type); | ||
mlir::APInt apValue(intType.getWidth(), value, intType.isSigned()); | ||
return $_get(intType.getContext(), intType, apValue); | ||
}]>, | ||
]; | ||
let extraClassDeclaration = [{ | ||
int64_t getSInt() const { return getValue().getSExtValue(); } | ||
uint64_t getUInt() const { return getValue().getZExtValue(); } | ||
bool isNullValue() const { return getValue() == 0; } | ||
}]; | ||
let genVerifyDecl = 1; | ||
let hasCustomAssemblyFormat = 1; | ||
} | ||
|
||
#endif // P4MLIR_DIALECT_P4HIR_P4HIR_ATTRS_TD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
#ifndef P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_H | ||
#define P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_H | ||
|
||
// We explicitly do not use push / pop for diagnostic in | ||
// order to propagate pragma further on | ||
#pragma GCC diagnostic ignored "-Wunused-parameter" | ||
|
||
#include "mlir/Bytecode/BytecodeOpInterface.h" | ||
#include "mlir/IR/Dialect.h" | ||
|
||
#include "p4mlir/Dialect/P4HIR/P4HIR_Dialect.h.inc" | ||
|
||
#endif // P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_H | ||
#endif // P4MLIR_DIALECT_P4HIR_P4HIR_DIALECT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.