Skip to content

Commit

Permalink
Added AddressTuple conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
9Tempest committed Dec 6, 2023
1 parent c7dfbc4 commit 0d0e79b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions gematria/basic_block/basic_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ InstructionOperand InstructionOperand::Address(std::string base_register,
result.address_.displacement = displacement;
result.address_.scaling = scaling;
result.address_.segment_register = segment_register;
result.address_.base_register_size = 64;
result.address_.index_register_size = 64;
result.address_.segment_register_size = 64;
result.address_.base_register_intefered_register = {};
result.address_.index_register_intefered_register = {};
result.address_.segment_register_intefered_register = {};
return result;
}

Expand Down
33 changes: 32 additions & 1 deletion gematria/basic_block/basic_block_protos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,25 @@ namespace {

AddressTuple AddressTupleFromProto(
const CanonicalizedOperandProto::AddressTuple& proto) {
return AddressTuple(
auto result = AddressTuple(
/* base_register = */ proto.base_register(),
/* displacement = */ proto.displacement(),
/* index_register = */ proto.index_register(),
/* scaling = */ proto.scaling(),
/* segment_register = */ proto.segment());
if (proto.base_register()[0] == '%'){
result.base_register_size = proto.base_register_size();
result.base_register_intefered_register = ToVector(proto.base_register_intefered_register());
}
if (proto.index_register()[0] == '%'){
result.index_register_size = proto.index_register_size();
result.index_register_intefered_register = ToVector(proto.index_register_intefered_register());
}
if (proto.segment()[0] == '%'){
result.segment_register_size = proto.segment_size();
result.segment_register_intefered_register = ToVector(proto.segment_intefered_register());
}
return result;
}

CanonicalizedOperandProto::AddressTuple ProtoFromAddressTuple(
Expand All @@ -50,6 +63,24 @@ CanonicalizedOperandProto::AddressTuple ProtoFromAddressTuple(
proto.set_index_register(address_tuple.index_register);
proto.set_scaling(address_tuple.scaling);
proto.set_segment(address_tuple.segment_register);
if (!address_tuple.base_register.empty() && address_tuple.base_register[0] == '%') {
proto.set_base_register_size(address_tuple.base_register_size);
for (auto interfered_register : address_tuple.base_register_intefered_register){
proto.add_base_register_intefered_register(std::move(interfered_register));
}
}
if (!address_tuple.index_register.empty() && address_tuple.index_register[0] == '%') {
proto.set_index_register_size(address_tuple.index_register_size);
for (auto interfered_register : address_tuple.index_register_intefered_register){
proto.add_index_register_intefered_register(std::move(interfered_register));
}
}
if (!address_tuple.segment_register.empty() && address_tuple.segment_register[0] == '%') {
proto.set_segment_size(address_tuple.segment_register_size);
for (auto interfered_register : address_tuple.segment_register_intefered_register){
proto.add_segment_intefered_register(std::move(interfered_register));
}
}
return proto;
}

Expand Down

0 comments on commit 0d0e79b

Please sign in to comment.