23 #ifndef BM_BM_SIM_FIELDS_H_
24 #define BM_BM_SIM_FIELDS_H_
26 #include <bm/config.h>
53 explicit Field(
int nbits,
Header *parent_hdr,
bool arith_flag =
true,
54 bool is_signed =
false,
bool hidden =
false,
bool VL =
false,
55 bool is_saturating =
false);
59 void reserve_VL(
size_t max_bytes);
63 void set_bytes(
const char *src_bytes,
int len) {
64 assert(len == nbytes);
65 std::copy(src_bytes, src_bytes + len, bytes.
begin());
66 if (arith) sync_value();
70 bignum::import_bytes(&value, bytes.
data(), nbytes);
71 if (is_signed && bignum::test_bit(value, nbits - 1)) {
72 bignum::clear_bit(&value, nbits - 1);
77 DEBUGGER_NOTIFY_UPDATE(*packet_id, my_id, bytes.
data(), nbits);
99 void set_arith(
bool arith_flag) { arith = arith_flag; }
101 bool get_arith_flag()
const {
return arith; }
103 void export_bytes()
override {
104 std::fill(bytes.
begin(), bytes.
end(), 0);
107 if (value < min) value = min;
108 else if (value > max) value = max;
114 bignum::export_bytes(bytes.
data(), nbytes, value);
116 if (value < min || value > mask) {
118 if (value > max) value -= (mask + 1);
121 bignum::export_bytes(bytes.
data(), nbytes, value);
126 bignum::export_bytes(bytes.
data(), nbytes, value - min - min);
130 DEBUGGER_NOTIFY_UPDATE(*packet_id, my_id, bytes.
data(), nbits);
134 void swap_values(Field *other);
137 int extract(
const char *data,
int hdr_offset);
139 int extract_VL(
const char *data,
int hdr_offset,
int computed_nbits);
142 int deparse(
char *data,
int hdr_offset)
const;
144 void assign_VL(
const Field &src);
149 void set_id(uint64_t
id) { my_id = id; }
150 void set_packet_id(
const Debugger::PacketId *
id) { packet_id = id; }
152 void set_id(uint64_t) { }
153 void set_packet_id(
const Debugger::PacketId *) { }
158 void copy_value(
const Field &src);
160 bool is_hidden()
const {
186 bool is_signed{
false};
189 bool is_saturating{
false};
190 bool written_to{
false};
196 const Debugger::PacketId *packet_id{&Debugger::dummy_PacketId};
202 #endif // BM_BM_SIM_FIELDS_H_