aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-01-21 17:16:50 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-01-21 17:16:50 -0800
commit61e4b6b9d40c966ead0198e9a9a32d1067273ef7 (patch)
tree1670bd41f00d7075add1be97e4e08b479e81774e
parentf8525825f5bc91dbe631d4d9afb1b18c3a0e5f75 (diff)
do not generate annotations when disassembling bitcode
-rwxr-xr-xemcc5
-rwxr-xr-xemscripten.py88
-rw-r--r--src/intertyper.js5
-rwxr-xr-xtests/runner.py20
-rw-r--r--tools/shared.py3
5 files changed, 15 insertions, 106 deletions
diff --git a/emcc b/emcc
index 5ddf560e..b1feeb59 100755
--- a/emcc
+++ b/emcc
@@ -414,6 +414,8 @@ try:
shutil.copyfile(input_file, in_temp(unsuffixed_basename(input_file) + '.o'))
else: #.ll
if not LEAVE_INPUTS_RAW:
+ # Note that by assembling the .ll file, then disassembling it later, we will
+ # remove annotations which is a good thing for compilation time
if DEBUG: print >> sys.stderr, 'emcc: assembling assembly file: ', input_file
shared.Building.llvm_as(input_file, in_temp(unsuffixed_basename(input_file) + '.o'))
@@ -549,11 +551,12 @@ try:
final = in_temp(target_basename + '.bc')
if DEBUG: save_intermediate('bc', 'bc')
final = shared.Building.llvm_dis(final, final + '.ll')
- if DEBUG: save_intermediate('ll', 'll')
else:
assert len(input_files) == 1
final = input_files[0]
+ if DEBUG: save_intermediate('ll', 'll')
+ if DEBUG: print >> sys.stderr, 'emcc: LLVM => JS'
final = shared.Building.emscripten(final, append_ext=False)
if DEBUG: save_intermediate('original')
diff --git a/emscripten.py b/emscripten.py
index 4fc6d9bc..93df8823 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -1,17 +1,12 @@
#!/usr/bin/python
'''
-Run with -h to see usage options.
+You should normally never use this! Use emcc instead.
-Notes:
-
- * Emscripten expects the .ll input to be formatted and annotated the way
-
- llvm-dis -show-annotations
-
- does. So if you get .ll from something else, you should run it through
- llvm-as (to generate LLVM bitcode) and then llvm-dis -show-annotations
- (to get properly formatted and annotated .ll).
+This is a small wrapper script around the core JS compiler. This calls that
+compiler with the settings given to it. It can also read data from C/C++
+header files (so that the JS compiler can see the constants in those
+headers, for the libc implementation in JS).
'''
import json
@@ -32,68 +27,6 @@ def path_from_root(*pathelems):
temp_files = shared.TempFiles()
-def assemble(filepath):
- """Converts human-readable LLVM assembly to binary LLVM bitcode.
-
- Args:
- filepath: The path to the file to assemble. If the name ends with ".bc", the
- file is assumed to be in bitcode format already.
-
- Returns:
- The path to the assembled file.
- """
- if not filepath.endswith('.bc'):
- command = [shared.LLVM_AS, '-o=-', filepath]
- with temp_files.get('.bc') as out: ret = subprocess.call(command, stdout=out)
- if ret != 0: raise RuntimeError('Could not assemble %s.' % filepath)
- filepath = out.name
- return filepath
-
-
-def disassemble(filepath):
- """Converts binary LLVM bitcode to human-readable LLVM assembly.
-
- Args:
- filepath: The path to the file to disassemble. If the name ends with ".ll",
- the file is assumed to be in human-readable assembly format already.
-
- Returns:
- The path to the disassembled file.
- """
- if not filepath.endswith('.ll'):
- command = [shared.LLVM_DIS, '-o=-', filepath] + shared.LLVM_DIS_OPTS
- with temp_files.get('.ll') as out: ret = subprocess.call(command, stdout=out)
- if ret != 0: raise RuntimeError('Could not disassemble %s.' % filepath)
- filepath = out.name
- return filepath
-
-
-def link(*objects):
- """Links multiple LLVM bitcode files into a single file.
-
- Args:
- objects: The bitcode files to link.
-
- Returns:
- The path to the linked file.
- """
- command = [shared.LLVM_LINK] + list(objects)
- with temp_files.get('.bc') as out: ret = subprocess.call(command, stdout=out)
- if ret != 0: raise RuntimeError('Could not link %s.' % objects)
- return out.name
-
-
-def has_annotations(filepath):
- """Tests whether an assembly file contains annotations.
-
- Args:
- filepath: The .ll file containing the assembly to check.
-
- Returns:
- Whether the provided file is valid assembly and has annotations.
- """
- return filepath.endswith('.ll') and '[#uses=' in open(filepath).read()
-
def emscript(infile, settings, outfile):
"""Runs the emscripten LLVM-to-JS compiler.
@@ -114,11 +47,6 @@ def emscript(infile, settings, outfile):
def main(args):
- # Construct a final linked and disassembled file.
- if not has_annotations(args.infile):
- args.infile = assemble(args.infile)
- args.infile = disassemble(args.infile)
-
# Prepare settings for serialization to JSON.
settings = {}
for setting in args.settings:
@@ -194,9 +122,9 @@ def main(args):
if __name__ == '__main__':
parser = optparse.OptionParser(
usage='usage: %prog [-h] [-O] [-m] [-H HEADERS] [-o OUTFILE] [-s FOO=BAR]* infile',
- description=('Compile an LLVM assembly file to Javascript. Accepts both '
- 'human-readable (*.ll) and bitcode (*.bc) formats.'),
- epilog='You should have an ~/.emscripten file set up; see settings.py.')
+ description=('You should normally never use this! Use emcc instead. '
+ 'This is a wrapper around the JS compiler, converting .ll to .js.'),
+ epilog='')
parser.add_option('-H', '--headers',
default=[],
action='append',
diff --git a/src/intertyper.js b/src/intertyper.js
index 6b46cdbb..d295a872 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -521,13 +521,12 @@ function intertyper(data, sidePass, baseLineNums) {
ret.ctors.push(segment[1].tokens.slice(-1)[0].text);
});
}
- } else {
- if (!item.tokens[3]) throw 'Did you run llvm-dis with -show-annotations? (b)'; // XXX: do we still need annotations?
+ } else if (!external) {
if (item.tokens[3].text == 'c')
item.tokens.splice(3, 1);
if (item.tokens[3].text in PARSABLE_LLVM_FUNCTIONS) {
ret.value = parseLLVMFunctionCall(item.tokens.slice(2));
- } else if (!external) {
+ } else {
ret.value = scanConst(item.tokens[3], ret.type);
}
}
diff --git a/tests/runner.py b/tests/runner.py
index 56b96256..502b1fb5 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -5000,26 +5000,6 @@ def process(filename):
# This test *should* fail
assert 'Assertion failed' in str(e), str(e)
- def test_autoassemble(self):
- src = r'''
- #include <stdio.h>
-
- int main() {
- puts("test\n");
- return 0;
- }
- '''
- dirname = self.get_dir()
- filename = os.path.join(dirname, 'src.cpp')
- self.build(src, dirname, filename)
-
- new_filename = os.path.join(dirname, 'new.bc')
- shutil.copy(filename + '.o', new_filename)
- Building.emscripten(new_filename, append_ext=False)
-
- shutil.copy(filename + '.o.js', os.path.join(self.get_dir(), 'new.cpp.o.js'))
- self.do_run(None, 'test\n', basename='new.cpp', no_build=True)
-
def test_linespecific(self):
Settings.CHECK_SIGNS = 0
Settings.CHECK_OVERFLOWS = 0
diff --git a/tools/shared.py b/tools/shared.py
index 4c6ddc23..f20fc75c 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -90,7 +90,6 @@ LLVM_OPT=os.path.expanduser(os.path.join(LLVM_ROOT, 'opt'))
LLVM_AS=os.path.expanduser(os.path.join(LLVM_ROOT, 'llvm-as'))
LLVM_DIS=os.path.expanduser(os.path.join(LLVM_ROOT, 'llvm-dis'))
LLVM_NM=os.path.expanduser(os.path.join(LLVM_ROOT, 'llvm-nm'))
-LLVM_DIS_OPTS = ['-show-annotations'] # For LLVM 2.8+. For 2.7, you may need to do just []
LLVM_INTERPRETER=os.path.expanduser(os.path.join(LLVM_ROOT, 'lli'))
LLVM_COMPILER=os.path.expanduser(os.path.join(LLVM_ROOT, 'llc'))
COFFEESCRIPT = path_from_root('tools', 'eliminator', 'node_modules', 'coffee-script', 'bin', 'coffee')
@@ -469,7 +468,7 @@ class Building:
output_filename = input_filename + '.o.ll'
input_filename = input_filename + '.o'
try_delete(output_filename)
- output = Popen([LLVM_DIS, input_filename ] + LLVM_DIS_OPTS + ['-o=' + output_filename], stdout=PIPE).communicate()[0]
+ output = Popen([LLVM_DIS, input_filename, '-o=' + output_filename], stdout=PIPE).communicate()[0]
assert os.path.exists(output_filename), 'Could not create .ll file: ' + output
return output_filename