Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6339e596 authored by Henri Chataing's avatar Henri Chataing
Browse files

packetgen: Delete the rust generator

The rust generation is now assumed by the rewritten pdl compiler
tools, using the 'pdl_rust_generator_defaults' genrule configuration

Bug: 284980692
Test: NA
Change-Id: Id6a2b4a25872383ae88886b4d7c345c73a2f4242
parent 330b6df7
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -132,10 +132,3 @@ packetgen_headers("BluetoothGeneratedPackets_h") {
  include = "system/gd"
  source_root = "../.."
}

packetgen_rust("BluetoothGeneratedPackets_rust") {
  sources = [ "hci/hci_packets.pdl" ]

  include = "system/gd"
  source_root = "../.."
}
+0 −1
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ cc_binary_host {
        "fields/variable_length_struct_field.cc",
        "fields/vector_field.cc",
        "gen_cpp.cc",
        "gen_rust.cc",
        "language_l.ll",
        "language_y.yy",
        "main.cc",
+0 −1
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ executable("bluetooth_packetgen") {
    "fields/variable_length_struct_field.cc",
    "fields/vector_field.cc",
    "gen_cpp.cc",
    "gen_rust.cc",
    "main.cc",
    "packet_def.cc",
    "packet_dependency.cc",
+0 −41
Original line number Diff line number Diff line
@@ -59,44 +59,3 @@ void EnumGen::GenLogging(std::ostream& stream) {
  stream << "  return os << " << e_.name_ << "Text(param);";
  stream << "}\n";
}

void EnumGen::GenRustDef(std::ostream& stream) {
  stream << "#[derive(FromPrimitive, ToPrimitive, Debug, Hash, Eq, PartialEq, Clone, Copy)]\n";
  stream << "#[repr(u64)]\n";
  stream << "pub enum " << e_.name_ << " {";
  for (const auto& pair : e_.constants_) {
    stream << util::ConstantCaseToCamelCase(pair.second) << " = 0x" << std::hex << pair.first << std::dec << ",";
  }
  stream << "}";

  stream << "impl fmt::Display for " << e_.name_ << " {";
  stream << "fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {";
  stream << "match self {";
  for (const auto& pair : e_.constants_) {
    stream << e_.name_ << "::" << util::ConstantCaseToCamelCase(pair.second) << " => "
           << "write!(f, \"{:#0" << (util::RoundSizeUp(e_.size_) / 4) + 2 << "X} (" << pair.second << ")\", "
           << "self.to_" << util::GetRustTypeForSize(e_.size_) << "().unwrap()),";
  }
  stream << "}}}\n";

  if (e_.try_from_enum_ != nullptr) {
    std::vector<std::string> other_items;
    for (const auto& pair : e_.try_from_enum_->constants_) {
      other_items.push_back(pair.second);
    }
    stream << "impl TryFrom<" << e_.try_from_enum_->name_ << "> for " << e_.name_ << " {";
    stream << "type Error = &'static str;";
    stream << "fn try_from(value: " << e_.try_from_enum_->name_ << ") -> std::result::Result<Self, Self::Error> {";
    stream << "match value {";
    for (const auto& pair : e_.constants_) {
      if (std::find(other_items.begin(), other_items.end(), pair.second) == other_items.end()) {
        continue;
      }
      auto constant_name = util::ConstantCaseToCamelCase(pair.second);
      stream << e_.try_from_enum_->name_ << "::" << constant_name << " => Ok(" << e_.name_ << "::" << constant_name
             << "),";
    }
    stream << "_ => Err(\"No mapping for provided key\"),";
    stream << "}}}";
  }
}
+0 −2
Original line number Diff line number Diff line
@@ -31,7 +31,5 @@ class EnumGen {

  void GenLogging(std::ostream& stream);

  void GenRustDef(std::ostream& stream);

  EnumDef e_;
};
Loading