diff --git a/frontends/p4/fromv1.0/programStructure.cpp b/frontends/p4/fromv1.0/programStructure.cpp index c998016e8d0..0fc8a4bbf68 100644 --- a/frontends/p4/fromv1.0/programStructure.cpp +++ b/frontends/p4/fromv1.0/programStructure.cpp @@ -2063,7 +2063,7 @@ ProgramStructure::convert(const IR::Register* reg, cstring newName, regElementType = new IR::Type_Name(new IR::Path(str->name)); // use provided type } else if (reg->width > 0) { - regElementType = IR::Type_Bits::get(reg->width); + regElementType = IR::Type_Bits::get(reg->width, reg->signed_); } else if (reg->layout) { cstring newName = ::get(registerLayoutType, reg->layout); if (newName.isNullOrEmpty()) diff --git a/testdata/p4_14_samples/register_signed.p4 b/testdata/p4_14_samples/register_signed.p4 new file mode 100644 index 00000000000..07bffd6025e --- /dev/null +++ b/testdata/p4_14_samples/register_signed.p4 @@ -0,0 +1,72 @@ +header_type ethernet_t { + fields { + dstAddr : 48; + srcAddr : 48; + etherType : 16; + } +} + +header_type intrinsic_metadata_t { + fields { + mcast_grp : 4; + egress_rid : 4; + } +} + +header_type meta_t { + fields { + register_tmp : 32 (signed); + } +} + +metadata meta_t meta; + +parser start { + return parse_ethernet; +} + +header ethernet_t ethernet; +metadata intrinsic_metadata_t intrinsic_metadata; + +parser parse_ethernet { + extract(ethernet); + return ingress; +} + +action _drop() { + drop(); +} + +action _nop() { +} + +register my_register { + width: 32; + static: m_table; + instance_count: 16384; + attributes: signed; +} + +action m_action(register_idx) { + // modify_field_rng_uniform(meta.register_tmp, 100, 200); + // register_write(my_register, register_idx, meta.register_tmp); + register_read(meta.register_tmp, my_register, register_idx); + // TODO +} + +table m_table { + reads { + ethernet.srcAddr : exact; + } + actions { + m_action; _nop; + } + size : 16384; +} + +control ingress { + apply(m_table); +} + +control egress { +} diff --git a/testdata/p4_14_samples_outputs/register_signed-first.p4 b/testdata/p4_14_samples_outputs/register_signed-first.p4 new file mode 100644 index 00000000000..00da695a43c --- /dev/null +++ b/testdata/p4_14_samples_outputs/register_signed-first.p4 @@ -0,0 +1,87 @@ +#include +#define V1MODEL_VERSION 20200408 +#include + +struct intrinsic_metadata_t { + bit<4> mcast_grp; + bit<4> egress_rid; +} + +struct meta_t { + int<32> register_tmp; +} + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +struct metadata { + @name(".meta") + meta_t meta; +} + +struct headers { + @name(".ethernet") + ethernet_t ethernet; +} + +parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".parse_ethernet") state parse_ethernet { + packet.extract(hdr.ethernet); + transition accept; + } + @name(".start") state start { + transition parse_ethernet; + } +} + +control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +@name(".my_register") register, bit<14>>(32w16384) my_register; + +control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".m_action") action m_action(bit<14> register_idx) { + my_register.read(meta.meta.register_tmp, register_idx); + } + @name("._nop") action _nop() { + } + @name(".m_table") table m_table { + actions = { + m_action(); + _nop(); + @defaultonly NoAction(); + } + key = { + hdr.ethernet.srcAddr: exact @name("ethernet.srcAddr") ; + } + size = 16384; + default_action = NoAction(); + } + apply { + m_table.apply(); + } +} + +control DeparserImpl(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + } +} + +control verifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control computeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; + diff --git a/testdata/p4_14_samples_outputs/register_signed-frontend.p4 b/testdata/p4_14_samples_outputs/register_signed-frontend.p4 new file mode 100644 index 00000000000..97337b17797 --- /dev/null +++ b/testdata/p4_14_samples_outputs/register_signed-frontend.p4 @@ -0,0 +1,89 @@ +#include +#define V1MODEL_VERSION 20200408 +#include + +struct intrinsic_metadata_t { + bit<4> mcast_grp; + bit<4> egress_rid; +} + +struct meta_t { + int<32> register_tmp; +} + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +struct metadata { + @name(".meta") + meta_t meta; +} + +struct headers { + @name(".ethernet") + ethernet_t ethernet; +} + +parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".parse_ethernet") state parse_ethernet { + packet.extract(hdr.ethernet); + transition accept; + } + @name(".start") state start { + transition parse_ethernet; + } +} + +control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +@name(".my_register") register, bit<14>>(32w16384) my_register; + +control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @noWarn("unused") @name(".NoAction") action NoAction_1() { + } + @name(".m_action") action m_action(@name("register_idx") bit<14> register_idx) { + my_register.read(meta.meta.register_tmp, register_idx); + } + @name("._nop") action _nop() { + } + @name(".m_table") table m_table_0 { + actions = { + m_action(); + _nop(); + @defaultonly NoAction_1(); + } + key = { + hdr.ethernet.srcAddr: exact @name("ethernet.srcAddr") ; + } + size = 16384; + default_action = NoAction_1(); + } + apply { + m_table_0.apply(); + } +} + +control DeparserImpl(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + } +} + +control verifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control computeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; + diff --git a/testdata/p4_14_samples_outputs/register_signed-midend.p4 b/testdata/p4_14_samples_outputs/register_signed-midend.p4 new file mode 100644 index 00000000000..6b57c9023b3 --- /dev/null +++ b/testdata/p4_14_samples_outputs/register_signed-midend.p4 @@ -0,0 +1,88 @@ +#include +#define V1MODEL_VERSION 20200408 +#include + +struct intrinsic_metadata_t { + bit<4> mcast_grp; + bit<4> egress_rid; +} + +struct meta_t { + int<32> register_tmp; +} + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +struct metadata { + int<32> _meta_register_tmp0; +} + +struct headers { + @name(".ethernet") + ethernet_t ethernet; +} + +parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".parse_ethernet") state parse_ethernet { + packet.extract(hdr.ethernet); + transition accept; + } + @name(".start") state start { + transition parse_ethernet; + } +} + +control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +@name(".my_register") register, bit<14>>(32w16384) my_register; + +control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @noWarn("unused") @name(".NoAction") action NoAction_1() { + } + @name(".m_action") action m_action(@name("register_idx") bit<14> register_idx) { + my_register.read(meta._meta_register_tmp0, register_idx); + } + @name("._nop") action _nop() { + } + @name(".m_table") table m_table_0 { + actions = { + m_action(); + _nop(); + @defaultonly NoAction_1(); + } + key = { + hdr.ethernet.srcAddr: exact @name("ethernet.srcAddr") ; + } + size = 16384; + default_action = NoAction_1(); + } + apply { + m_table_0.apply(); + } +} + +control DeparserImpl(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + } +} + +control verifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control computeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; + diff --git a/testdata/p4_14_samples_outputs/register_signed.p4 b/testdata/p4_14_samples_outputs/register_signed.p4 new file mode 100644 index 00000000000..f0a230e225d --- /dev/null +++ b/testdata/p4_14_samples_outputs/register_signed.p4 @@ -0,0 +1,85 @@ +#include +#define V1MODEL_VERSION 20200408 +#include + +struct intrinsic_metadata_t { + bit<4> mcast_grp; + bit<4> egress_rid; +} + +struct meta_t { + int<32> register_tmp; +} + +header ethernet_t { + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; +} + +struct metadata { + @name(".meta") + meta_t meta; +} + +struct headers { + @name(".ethernet") + ethernet_t ethernet; +} + +parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".parse_ethernet") state parse_ethernet { + packet.extract(hdr.ethernet); + transition accept; + } + @name(".start") state start { + transition parse_ethernet; + } +} + +control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + apply { + } +} + +@name(".my_register") register, bit<14>>(32w16384) my_register; + +control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) { + @name(".m_action") action m_action(bit<14> register_idx) { + my_register.read(meta.meta.register_tmp, (bit<14>)register_idx); + } + @name("._nop") action _nop() { + } + @name(".m_table") table m_table { + actions = { + m_action; + _nop; + } + key = { + hdr.ethernet.srcAddr: exact; + } + size = 16384; + } + apply { + m_table.apply(); + } +} + +control DeparserImpl(packet_out packet, in headers hdr) { + apply { + packet.emit(hdr.ethernet); + } +} + +control verifyChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +control computeChecksum(inout headers hdr, inout metadata meta) { + apply { + } +} + +V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main; + diff --git a/testdata/p4_14_samples_outputs/register_signed.p4-stderr b/testdata/p4_14_samples_outputs/register_signed.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d