Skip to content

Conversation

smeenai
Copy link
Collaborator

@smeenai smeenai commented Aug 9, 2024

The idea is that the output of hmaptool dump --json can be fed
directly back to hmaptool write for easy round-tripping.

The idea is that the output of `hmaptool dump --json` can be fed
directly back to `hmaptool write` for easy round-tripping.
@smeenai smeenai requested a review from bcardosolopes August 9, 2024 17:19
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Aug 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 9, 2024

@llvm/pr-subscribers-clang

Author: Shoaib Meenai (smeenai)

Changes

The idea is that the output of hmaptool dump --json can be fed
directly back to hmaptool write for easy round-tripping.


Full diff: https://github.com/llvm/llvm-project/pull/102648.diff

1 Files Affected:

  • (modified) clang/utils/hmaptool/hmaptool (+6-1)
diff --git a/clang/utils/hmaptool/hmaptool b/clang/utils/hmaptool/hmaptool
index d7754632b162bf..ccbb9f7d8a1450 100755
--- a/clang/utils/hmaptool/hmaptool
+++ b/clang/utils/hmaptool/hmaptool
@@ -120,6 +120,9 @@ def action_dump(name, args):
     parser.add_option("-v", "--verbose", dest="verbose",
                       help="show more verbose output [%default]",
                       action="store_true", default=False)
+    parser.add_option("--json", dest="json",
+                      help="output as JSON [%default]",
+                      action="store_true", default=False)
     (opts, args) = parser.parse_args(args)
 
     if len(args) != 1:
@@ -130,7 +133,6 @@ def action_dump(name, args):
     hmap = HeaderMap.frompath(path)
 
     # Dump all of the buckets.
-    print ('Header Map: %s' % (path,))
     if opts.verbose:
         print ('headermap: %r' % (path,))
         print ('  num entries: %d' % (hmap.num_entries,))
@@ -149,7 +151,10 @@ def action_dump(name, args):
 
             print ("  bucket[%d]: %r -> (%r, %r) -- %d" % (
                 i, key, prefix, suffix, (hmap_hash(key) & (len(hmap.buckets) - 1))))
+    elif opts.json:
+        print(json.dumps({"mappings": dict(hmap.mappings)}, indent=4))
     else:
+        print ('Header Map: %s' % (path,))
         mappings = sorted(hmap.mappings)
         for key,value in mappings:
             print ("%s -> %s" % (key, value))

facebook-github-bot pushed a commit to facebook/buck2-prelude that referenced this pull request Aug 12, 2024
Summary:
The idea is to allow easy round-tripping from `hmaptool dump --json` to
`hmaptool write`. Upstreamed as llvm/llvm-project#102648.

Reviewed By: yozhu

Differential Revision: D61043994

fbshipit-source-id: 5a1620ab880413485fdbf8fbc33fadb2e6d75d88
facebook-github-bot pushed a commit to facebook/buck2 that referenced this pull request Aug 12, 2024
Summary:
The idea is to allow easy round-tripping from `hmaptool dump --json` to
`hmaptool write`. Upstreamed as llvm/llvm-project#102648.

Reviewed By: yozhu

Differential Revision: D61043994

fbshipit-source-id: 5a1620ab880413485fdbf8fbc33fadb2e6d75d88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants