aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-17 11:48:34 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-17 11:48:34 -0800
commit6017afb6a1ef999dec20beb836901a8b5b0ed4bf (patch)
tree59deb9dfaf8003b8a3cfd5bc821b91821a6a7882
parent082bfd3366b30bde75b7ed5f7c59f1987c62e2a8 (diff)
bitcode checking function
-rw-r--r--tools/shared.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/tools/shared.py b/tools/shared.py
index a480faa9..faf26816 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -77,6 +77,8 @@ if USE_EMSDK:
'-U__APPLE__'
]
COMPILER_OPTS += EMSDK_OPTS
+else:
+ EMSDK_OPTS = []
# Engine tweaks
@@ -345,9 +347,9 @@ class Building:
assert os.path.exists(output_filename), 'Could not create bc file: ' + output
@staticmethod
- def llvm_nm(filename):
+ def llvm_nm(filename, stdout=PIPE, stderr=None):
# LLVM binary ==> list of symbols
- output = Popen([LLVM_NM, filename], stdout=PIPE).communicate()[0]
+ output = Popen([LLVM_NM, filename], stdout=stdout, stderr=stderr).communicate()[0]
class ret:
defs = []
undefs = []
@@ -534,3 +536,16 @@ class Building:
return filename + '.cc.js'
+ @staticmethod
+ def is_bitcode(filename):
+ # checks if a file contains LLVM bitcode
+ # if the file doesn't exist or doesn't have valid symbols, it isn't bitcode
+ try:
+ defs = Building.llvm_nm(filename, stderr=PIPE)
+ assert len(defs.defs + defs.undefs) > 0
+ except:
+ return False
+ # look for magic signature
+ b = open(filename, 'r').read(4)
+ return b[0] == 'B' and b[1] == 'C'
+