diff options
author | Sid Nayyar <sidnayyar@google.com> | 2024-02-19 19:20:15 +0000 |
---|---|---|
committer | Giuliano Procida <gprocida@google.com> | 2024-03-08 14:23:07 +0000 |
commit | ba07021fadad855a1f3959d7677203c93be327a8 (patch) | |
tree | 500ef87beca9e8e57c7a5940eab6c81e695a400f | |
parent | df42034b3ac4f7c86a9db668b5720bdfed601b8e (diff) | |
download | stg-ba07021fadad855a1f3959d7677203c93be327a8.tar.gz |
proto writer: add method returning a mapping from external to internal IDs
This mapping in the STG proto transformer will be used to describe STG
graph nodes, using their external IDs for edge annotation.
Also rename external ID map for better code clarity.
PiperOrigin-RevId: 608373212
Change-Id: I5da4cd3f1dcd2932a73787df76ca1b99af7923ea
-rw-r--r-- | proto_writer.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/proto_writer.cc b/proto_writer.cc index 3ed8624..8935485 100644 --- a/proto_writer.cc +++ b/proto_writer.cc @@ -89,9 +89,17 @@ struct Transform { ElfSymbol::Binding operator()(stg::ElfSymbol::Binding); ElfSymbol::Visibility operator()(stg::ElfSymbol::Visibility); + std::unordered_map<uint32_t, Id> GetInternalIdByExternalIdMap() { + std::unordered_map<uint32_t, Id> internal_id_map; + for (const auto [id, ext_id] : external_id_by_internal_id) { + internal_id_map.emplace(ext_id, id); + } + return internal_id_map; + } + const Graph& graph; proto::STG& stg; - std::unordered_map<Id, uint32_t> external_id; + std::unordered_map<Id, uint32_t> external_id_by_internal_id; std::unordered_set<uint32_t> used_ids; // Function object: Id -> uint32_t @@ -100,7 +108,7 @@ struct Transform { template <typename MapId> uint32_t Transform<MapId>::operator()(Id id) { - auto [it, inserted] = external_id.emplace(id, 0); + auto [it, inserted] = external_id_by_internal_id.emplace(id, 0); if (inserted) { uint32_t mapped_id = map_id(id); |