diff --git a/lib/Utilities/export_to_p4.cpp b/lib/Utilities/export_to_p4.cpp index 3b9b0c14..c70c6003 100644 --- a/lib/Utilities/export_to_p4.cpp +++ b/lib/Utilities/export_to_p4.cpp @@ -4436,26 +4436,67 @@ class P4HirToP4Exporter { /// ```p4 /// in bit<32> data /// ``` + // mlir::LogicalResult exportArgument(mlir::FunctionOpInterface functionInterface, + // ExtendedFormattedOStream &ss, int index) { + // if (auto argAttrs = functionInterface.getArgAttrsAttr()) { + // if (index < static_cast(argAttrs.size())) { + // if (auto dict = + // mlir::dyn_cast_if_present(argAttrs[index])) { + // auto annots = + // mlir::dyn_cast_if_present(dict.get("annotations")); + // if (!annots) { + // annots = mlir::dyn_cast_if_present( + // dict.get("p4hir.annotations")); + // } + // if (annots) { + // if (failed(exportAnnotations(annots, ss))) { + // return mlir::failure(); + // } + // } + // } + // } + // } + + + + mlir::LogicalResult exportArgument(mlir::FunctionOpInterface functionInterface, - ExtendedFormattedOStream &ss, int index) { - if (auto argAttrs = functionInterface.getArgAttrsAttr()) { - if (index < static_cast(argAttrs.size())) { - if (auto dict = - mlir::dyn_cast_if_present(argAttrs[index])) { - auto annots = - mlir::dyn_cast_if_present(dict.get("annotations")); - if (!annots) { - annots = mlir::dyn_cast_if_present( - dict.get("p4hir.annotations")); - } - if (annots) { - if (failed(exportAnnotations(annots, ss))) { - return mlir::failure(); - } + ExtendedFormattedOStream &ss, int index) { + // 🔹 Handle annotations + if (auto argAttrs = functionInterface.getArgAttrsAttr()) { + if (index < static_cast(argAttrs.size())) { + if (auto dict = + mlir::dyn_cast_if_present(argAttrs[index])) { + auto annots = + mlir::dyn_cast_if_present(dict.get("annotations")); + if (!annots) { + annots = mlir::dyn_cast_if_present( + dict.get("p4hir.annotations")); + } + if (annots) { + if (failed(exportAnnotations(annots, ss))) { + return mlir::failure(); } } } } + } + + ss << "in "; + + auto type = functionInterface.getArgumentTypes()[index]; + if (failed(exportP4Type(type, ss))) { + return mlir::failure(); + } + + ss << " arg" << index; + + return mlir::success(); +} + + + + // Export direction (in, out, inout). auto directionAttr = functionInterface.getArgAttr(index, P4HIR::FuncOp::getDirectionAttrName());