[llvm] r310739 - [opt-viewer] Use Python 3-compatible `intern()`

Brian Gesiak via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 10:56:57 PDT 2017


Author: modocache
Date: Fri Aug 11 10:56:57 2017
New Revision: 310739

URL: http://llvm.org/viewvc/llvm-project?rev=310739&view=rev
Log:
[opt-viewer] Use Python 3-compatible `intern()`

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

Modified:
    llvm/trunk/tools/opt-viewer/optrecord.py

Modified: llvm/trunk/tools/opt-viewer/optrecord.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt-viewer/optrecord.py?rev=310739&r1=310738&r2=310739&view=diff
==============================================================================
--- llvm/trunk/tools/opt-viewer/optrecord.py (original)
+++ llvm/trunk/tools/opt-viewer/optrecord.py Fri Aug 11 10:56:57 2017
@@ -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
 




More information about the llvm-commits mailing list