OSDN Git Service

[opt-viewer] Use Python 3-compatible `intern()`
authorBrian Gesiak <modocache@gmail.com>
Fri, 11 Aug 2017 17:56:57 +0000 (17:56 +0000)
committerBrian Gesiak <modocache@gmail.com>
Fri, 11 Aug 2017 17:56:57 +0000 (17:56 +0000)
Summary:
In Python 2, `intern()` is a builtin function available to all programs.
In Python 3, it was moved into the `sys` module, available as
`sys.intern`. Import it such that, within `optrecord.py`, `intern()` is
available whether run using Python 2 or 3.

Test Plan:
Run `opt-viewer.py` using Python 3, confirm it no longer
encounters a runtime error when `intern()` is called.

Reviewers: anemet

Reviewed By: anemet

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D36622

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310739 91177308-0d34-0410-b5e6-96231b3b80d8

tools/opt-viewer/optrecord.py

index 3744c68..2bf0f35 100644 (file)
@@ -17,6 +17,12 @@ import functools
 from multiprocessing import Lock
 import os, os.path
 import subprocess
+try:
+    # The previously builtin function `intern()` was moved
+    # to the `sys` module in Python 3.
+    from sys import intern
+except:
+    pass
 
 import optpmap