Skip to content

Commit

Permalink
Remove unused dataio "field location" stuff
Browse files Browse the repository at this point in the history
Simplifies generate_packets as well
  • Loading branch information
lmoureaux committed Dec 10, 2023
1 parent 2040a92 commit 9ceffc9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 120 deletions.
66 changes: 33 additions & 33 deletions common/generate_packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,40 +349,40 @@ def get_put(self, deltafragment):
"""

if self.dataio_type == "bitvector":
return f"DIO_BV_PUT(&dout, &field_addr, packet->{self.name});"
return f"DIO_BV_PUT(&dout, packet->{self.name});"

if self.struct_type == "float" and not self.is_array:
return f" DIO_PUT({self.dataio_type}, &dout, &field_addr, real_packet->{self.name}, {self.float_factor});"
return f" DIO_PUT({self.dataio_type}, &dout, real_packet->{self.name}, {self.float_factor});"

if self.dataio_type in ["worklist", "cm_parameter"]:
return f" DIO_PUT({self.dataio_type}, &dout, &field_addr, &real_packet->{self.name});"
return f" DIO_PUT({self.dataio_type}, &dout, &real_packet->{self.name});"

if self.dataio_type == "memory":
return f" DIO_PUT({self.dataio_type}, &dout, &field_addr, &real_packet->{self.name}, {self.array_size_u});"
return f" DIO_PUT({self.dataio_type}, &dout, &real_packet->{self.name}, {self.array_size_u});"

arr_types = ["string", "city_map"]
if (self.dataio_type in arr_types and self.is_array == 1) or (
self.dataio_type not in arr_types and self.is_array == 0
):
return f" DIO_PUT({self.dataio_type}, &dout, &field_addr, real_packet->{self.name});"
return f" DIO_PUT({self.dataio_type}, &dout, real_packet->{self.name});"
if self.is_struct:
if self.is_array == 2:
c = f"DIO_PUT({self.dataio_type}, &dout, &field_addr, &real_packet->{self.name}[i][j]);"
c = f"DIO_PUT({self.dataio_type}, &dout, &real_packet->{self.name}[i][j]);"
else:
c = f"DIO_PUT({self.dataio_type}, &dout, &field_addr, &real_packet->{self.name}[i]);"
c = f"DIO_PUT({self.dataio_type}, &dout, &real_packet->{self.name}[i]);"
elif self.dataio_type == "string":
c = f"DIO_PUT({self.dataio_type}, &dout, &field_addr, real_packet->{self.name}[i]);"
c = f"DIO_PUT({self.dataio_type}, &dout, real_packet->{self.name}[i]);"

elif self.struct_type == "float":
if self.is_array == 2:
c = f" DIO_PUT({self.dataio_type}, &dout, &field_addr, real_packet->{self.name}[i][j], {self.float_factor});"
c = f" DIO_PUT({self.dataio_type}, &dout, real_packet->{self.name}[i][j], {self.float_factor});"
else:
c = f" DIO_PUT({self.dataio_type}, &dout, &field_addr, real_packet->{self.name}[i], {self.float_factor});"
c = f" DIO_PUT({self.dataio_type}, &dout, real_packet->{self.name}[i], {self.float_factor});"
else:
if self.is_array == 2:
c = f"DIO_PUT({self.dataio_type}, &dout, &field_addr, real_packet->{self.name}[i][j]);"
c = f"DIO_PUT({self.dataio_type}, &dout, real_packet->{self.name}[i][j]);"
else:
c = f"DIO_PUT({self.dataio_type}, &dout, &field_addr, real_packet->{self.name}[i]);"
c = f"DIO_PUT({self.dataio_type}, &dout, real_packet->{self.name}[i]);"

array_size_u = self.array_size1_u if self.is_array == 2 else self.array_size_u

Expand All @@ -395,12 +395,12 @@ def get_put(self, deltafragment):
for (i = 0; i < {array_size_u}; i++) {{
if (old->{self.name}[i] != real_packet->{self.name}[i]) {{
DIO_PUT(uint8, &dout, &field_addr, i);
DIO_PUT(uint8, &dout, i);
{c}
}}
}}
DIO_PUT(uint8, &dout, &field_addr, 255);
DIO_PUT(uint8, &dout, 255);
}}"""
if self.is_array == 2 and self.dataio_type != "string":
Expand Down Expand Up @@ -450,81 +450,81 @@ def get_get(self, deltafragment):
"""

if self.struct_type == "float" and not self.is_array:
return f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name}, {self.float_factor})) {{
return f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name}, {self.float_factor})) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
if self.dataio_type == "bitvector":
return f"""if (!DIO_BV_GET(&din, &field_addr, real_packet->{self.name})) {{
return f"""if (!DIO_BV_GET(&din, real_packet->{self.name})) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
if self.dataio_type in ["string", "city_map"] and self.is_array != 2:
return f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, real_packet->{self.name}, sizeof(real_packet->{self.name}))) {{
return f"""if (!DIO_GET({self.dataio_type}, &din, real_packet->{self.name}, sizeof(real_packet->{self.name}))) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
if self.is_struct and self.is_array == 0:
return f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name})) {{
return f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name})) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
if not self.is_array:
if self.struct_type in ["int", "bool"]:
return f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name})) {{
return f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name})) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""

return f"""{{
int readin;
if (!DIO_GET({self.dataio_type}, &din, &field_addr, &readin)) {{
if (!DIO_GET({self.dataio_type}, &din, &readin)) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}
real_packet->{self.name} = static_cast<decltype(real_packet->{self.name})>(readin);
}}"""

if self.is_struct:
if self.is_array == 2:
c = f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name}[i][j])) {{
c = f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name}[i][j])) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
else:
c = f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name}[i])) {{
c = f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name}[i])) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
elif self.dataio_type == "string":
c = f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, real_packet->{self.name}[i], sizeof(real_packet->{self.name}[i]))) {{
c = f"""if (!DIO_GET({self.dataio_type}, &din, real_packet->{self.name}[i], sizeof(real_packet->{self.name}[i]))) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
elif self.struct_type == "float":
if self.is_array == 2:
c = f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name}[i][j], {self.float_factor})) {{
c = f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name}[i][j], {self.float_factor})) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
else:
c = f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name}[i], {self.float_factor})) {{
c = f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name}[i], {self.float_factor})) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
elif self.is_array == 2:
if self.struct_type in ["int", "bool"]:
c = f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name}[i][j])) {{
c = f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name}[i][j])) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
else:
c = f"""{{
int readin;
if (!DIO_GET({self.dataio_type}, &din, &field_addr, &readin)) {{
if (!DIO_GET({self.dataio_type}, &din, &readin)) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}
real_packet->{self.name}[i][j] = readin;
}}"""
elif self.struct_type in ["int", "bool"]:
c = f"""if (!DIO_GET({self.dataio_type}, &din, &field_addr, &real_packet->{self.name}[i])) {{
c = f"""if (!DIO_GET({self.dataio_type}, &din, &real_packet->{self.name}[i])) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
else:
c = f"""{{
int readin;
if (!DIO_GET({self.dataio_type}, &din, &field_addr, &readin)) {{
if (!DIO_GET({self.dataio_type}, &din, &readin)) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}
real_packet->{self.name}[i] = readin;
Expand All @@ -547,7 +547,7 @@ def get_get(self, deltafragment):
extra = ""
if self.dataio_type == "memory":
return f"""{extra}
if (!DIO_GET({self.dataio_type}, &din, &field_addr, real_packet->{self.name}, {array_size_u})) {{
if (!DIO_GET({self.dataio_type}, &din, real_packet->{self.name}, {array_size_u})) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}"""
if self.is_array == 2 and self.dataio_type != "string":
Expand Down Expand Up @@ -580,7 +580,7 @@ def get_get(self, deltafragment):
for (count = 0;; count++) {{
int i;
if (!DIO_GET(uint8, &din, &field_addr, &i)) {{
if (!DIO_GET(uint8, &din, &i)) {{
RECEIVE_PACKET_FIELD_ERROR({self.name});
}}
if (i == 255) {{
Expand Down Expand Up @@ -930,7 +930,7 @@ def get_delta_send_body(self, pre2):
"""

body += """
DIO_BV_PUT(&dout, &field_addr, fields);
DIO_BV_PUT(&dout, fields);
"""

for field in self.key_fields:
Expand Down Expand Up @@ -969,7 +969,7 @@ def get_receive(self):
genhash **hash = pc->phs.received + {self.type};
"""
delta_body1 = """
DIO_BV_GET(&din, &field_addr, fields);
DIO_BV_GET(&din, fields);
"""
body1 = ""
for field in self.key_fields:
Expand Down
52 changes: 0 additions & 52 deletions common/networking/dataio_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,55 +927,3 @@ void dio_put_requirement_raw(struct raw_data_out *dout,
dio_put_bool8_raw(dout, present);
dio_put_bool8_raw(dout, quiet);
}

/**
Create a new address of the location of a field inside a packet.
*/
struct plocation *plocation_field_new(char *name)
{
auto *out = new plocation;

out->kind = PADR_FIELD;
out->name = name;
out->sub_location = nullptr;

return out;
}

/**
Create a new address of the location of an array element inside a packet.
*/
struct plocation *plocation_elem_new(int number)
{
auto *out = new plocation;

out->kind = PADR_ELEMENT;
out->number = number;
out->sub_location = nullptr;

return out;
}

/**
Give textual description of the location. This might return address of
a static buffer next call reuses, so don't expect result to be valid
over another call to this.
*/
const char *plocation_name(const struct plocation *loc)
{
static char locname[10];

if (loc == nullptr) {
return "No location";
}

switch (loc->kind) {
case PADR_FIELD:
return loc->name;
case PADR_ELEMENT:
fc_snprintf(locname, sizeof(locname), "%d", loc->number);
return locname;
}

return "Illegal location";
}
39 changes: 4 additions & 35 deletions common/networking/dataio_raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,6 @@ enum data_type {
DIOT_LAST
};

// What a location inside a packet is.
enum plocation_kind {
// A field. Addressed by its name.
PADR_FIELD,
// An array element. Addressed by its number.
PADR_ELEMENT
};

// Address of a location inside a packet.
struct plocation {
// The location kind.
enum plocation_kind kind;

union {
// Used if this is an array element
int number;

// Used if this is a field.
char *name;
};

/* If the full address is to a location inside this this field should
* point to it. If this location is the final location this field should
* be nullptr. */
struct plocation *sub_location;
};

struct plocation *plocation_field_new(char *name);
struct plocation *plocation_elem_new(int number);
const char *plocation_name(const struct plocation *loc);

// network string conversion
typedef char *(*DIO_PUT_CONV_FUN)(const char *src, size_t *length);
void dio_set_put_conv_callback(DIO_PUT_CONV_FUN fun);
Expand Down Expand Up @@ -144,10 +113,10 @@ bool dio_get_action_probability_raw(struct data_in *din,
fc__attribute((nonnull(2)));

// Should be a function but we need some macro magic.
#define DIO_BV_GET(pdin, location, bv) \
#define DIO_BV_GET(pdin, bv) \
dio_get_memory_raw((pdin), (bv).vec, sizeof((bv).vec))

#define DIO_GET(f, d, l, ...) dio_get_##f##_raw(d, ##__VA_ARGS__)
#define DIO_GET(f, d, ...) dio_get_##f##_raw(d, ##__VA_ARGS__)

// puts
void dio_put_type_raw(struct raw_data_out *dout, enum data_type type,
Expand Down Expand Up @@ -184,7 +153,7 @@ void dio_put_action_probability_raw(struct raw_data_out *dout,
const struct act_prob *aprob);

// Should be a function but we need some macro magic.
#define DIO_BV_PUT(pdout, location, bv) \
#define DIO_BV_PUT(pdout, bv) \
dio_put_memory_raw((pdout), (bv).vec, sizeof((bv).vec))

#define DIO_PUT(f, d, l, ...) dio_put_##f##_raw(d, ##__VA_ARGS__)
#define DIO_PUT(f, d, ...) dio_put_##f##_raw(d, ##__VA_ARGS__)

0 comments on commit 9ceffc9

Please sign in to comment.