diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-12-11 20:43:08 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-12-11 20:43:08 -0800 |
commit | ae02feec361db8a69d51a69d51b02ea742212a94 (patch) | |
tree | 8b7937ea259e3e570112b8e562feca5dcc0f87ae | |
parent | b1ee96ba0dd86ca8e1f8a14bfd0c48bdd67e58b6 (diff) |
more emcc functionality and tests
-rwxr-xr-x | emcc | 32 | ||||
-rw-r--r-- | tests/runner.py | 18 |
2 files changed, 33 insertions, 17 deletions
@@ -33,7 +33,7 @@ Example uses: emconfiguren.py is a tiny script that just sets some environment vars as a convenience. The command just shown is equivalent to - EMMAKEN_JUST_CONFIGURE=1 RANLIB=PATH/emcc.py AR=PATH/emcc.py CXX=PATH/em++.py CC=PATH/emcc.py ./configure [options] + EMMAKEN_JUST_CONFIGURE=1 RANLIB=PATH/emcc AR=PATH/emcc CXX=PATH/em++ CC=PATH/emcc ./configure [options] where PATH is the path to this file. @@ -44,14 +44,14 @@ Example uses: * With CMake, the same command will work (with cmake instead of ./configure). You may also be able to do the following in your CMakeLists.txt: - SET(CMAKE_C_COMPILER "PATH/emcc.py") - SET(CMAKE_CXX_COMPILER "PATH/em++.py") - SET(CMAKE_LINKER "PATH/emcc.py") - SET(CMAKE_CXX_LINKER "PATH/emcc.py") - SET(CMAKE_C_LINK_EXECUTABLE "PATH/emcc.py") - SET(CMAKE_CXX_LINK_EXECUTABLE "PATH/emcc.py") - SET(CMAKE_AR "PATH/emcc.py") - SET(CMAKE_RANLIB "PATH/emcc.py") + SET(CMAKE_C_COMPILER "PATH/emcc") + SET(CMAKE_CXX_COMPILER "PATH/em++") + SET(CMAKE_LINKER "PATH/emcc") + SET(CMAKE_CXX_LINKER "PATH/emcc") + SET(CMAKE_C_LINK_EXECUTABLE "PATH/emcc") + SET(CMAKE_CXX_LINK_EXECUTABLE "PATH/emcc") + SET(CMAKE_AR "PATH/emcc") + SET(CMAKE_RANLIB "PATH/emcc") * For SCons the shared.py can be imported like so: __file__ = str(Dir('#/project_path_to_emscripten/dummy/dummy')) @@ -74,7 +74,7 @@ give to Emscripten. Note that this tool doesn't run Emscripten itself. Note also that you may need to do some manual fiddling later, for example to link files that weren't linked, and them llvm-dis them. -Note the appearance of em++.py instead of emcc.py +Note the appearance of em++ instead of emcc for the C++ compiler. This is needed for cases where we get a C++ file with a C extension, in which case CMake can be told to run g++ on it despite the .c extension, see @@ -103,7 +103,7 @@ print >> sys.stderr, '\n***This is a WORK IN PROGRESS***' print >> sys.stderr, '***[%s]***\n' % str(sys.argv) ################### XXX -if DEBUG: print >> sys.stderr, 'emcc.py: ', ' '.join(sys.argv) +if DEBUG: print >> sys.stderr, 'emcc: ', ' '.join(sys.argv) # Handle some global flags @@ -160,7 +160,7 @@ CMAKE_CONFIG = 'CMakeFiles/cmTryCompileExec.dir' in ' '.join(sys.argv)# or 'CMak if CONFIGURE_CONFIG or CMAKE_CONFIG: compiler = 'g++' if 'CXXCompiler' in ' '.join(sys.argv) or os.environ.get('EMMAKEN_CXX') else 'gcc' cmd = [compiler] + EMSDK_OPTS + sys.argv[1:] - if DEBUG: print >> sys.stderr, 'emcc.py, just configuring: ', cmd + if DEBUG: print >> sys.stderr, 'emcc, just configuring: ', cmd exit(os.execvp(compiler, cmd)) if os.environ.get('EMMAKEN_COMPILER'): @@ -186,7 +186,7 @@ if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += EMMAKEN_CFLAGS.split(' ') if len(sys.argv) == 1 or sys.argv[1] in ['x', 't']: # noop ar - if DEBUG: print >> sys.stderr, 'emcc.py, just ar' + if DEBUG: print >> sys.stderr, 'emcc, just ar' sys.exit(0) use_cxx = True @@ -256,7 +256,7 @@ elif use_compiler: newargs = sys.argv[1:] for i in range(len(newargs)): if newargs[i].startswith('-O'): - if DEBUG: print >> sys.stderr, 'emcc.py: WARNING: Optimization flags (-Ox) are ignored in emcc. Tell emscripten.py to do that, or run LLVM opt.' + if DEBUG: print >> sys.stderr, 'emcc: WARNING: Optimization flags (-Ox) are ignored in emcc. Tell emscripten.py to do that, or run LLVM opt.' newargs[i] = '' newargs = [ arg for arg in newargs if arg is not '' ] + CC_ADDITIONAL_ARGS @@ -265,6 +265,10 @@ elif use_compiler: target = 'a.out.js' target_basename = '.'.join(target.split('.')[:-1]) + + if '-c' in newargs: # -c means do not link in gcc, and for us, the parallel is to not go all the way to JS, but stop at bitcode + target = target_basename + '.bc' + final_suffix = target.split('.')[-1] # First, generate LLVM bitcode TODO: handle |emcc a.cpp b.cpp -c| which generate *two* bitcode files diff --git a/tests/runner.py b/tests/runner.py index 97adf2f0..e8564585 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -4869,6 +4869,10 @@ TT = %s class other(RunnerCore): def test_emcc(self): + def clear(): + for name in os.listdir(self.get_dir()): + try_delete(name) + for compiler in [EMCC, EMXX]: shortcompiler = os.path.basename(compiler) suffix = '.c' if compiler == EMCC else '.cpp' @@ -4916,7 +4920,7 @@ JavaScript in the final linking stage of building. ''' % (shortcompiler, shortcompiler, shortcompiler), output[0], output[1]) # emcc src.cpp ==> writes to a.out.js, much like gcc - try_delete('a.out.js') + clear() output = Popen([compiler, path_from_root('tests', 'hello_world' + suffix)], stdout=PIPE, stderr=PIPE).communicate(input) assert len(output[0]) == 0, output[0] #assert len(output[1]) == 0, output[1] # we have some debug warnings there now, FIXME @@ -4924,15 +4928,23 @@ JavaScript in the final linking stage of building. self.assertContained('hello, world!', run_js('a.out.js')) # emcc src.cpp -o something.js - try_delete('something.js') + clear() output = Popen([compiler, path_from_root('tests', 'hello_world' + suffix), '-o', 'something.js'], stdout=PIPE, stderr=PIPE).communicate(input) assert len(output[0]) == 0, output[0] assert os.path.exists('something.js'), output self.assertContained('hello, world!', run_js('something.js')) + # emcc src.cpp -c and emcc src.cpp -o src.[o|bc] ==> should give a .bc file + for args in [['-c'], ['-o', 'src.o'], ['-o', 'src.bc']]: + target = args[1] if len(args) == 2 else 'a.out.bc' + clear() + output = Popen([compiler, path_from_root('tests', 'hello_world' + suffix)] + args, stdout=PIPE, stderr=PIPE).communicate(input) + assert len(output[0]) == 0, output[0] + assert os.path.exists(target), output + self.assertContained('hello, world!', self.run_llvm_interpreter([target])) + # TODO: make sure all of these match gcc # TODO: when this is done, more test runner to test these (i.e., test all -Ox thoroughly) - # emcc src.cpp -c and emcc src.cpp -o src.[o|bc] ==> should give a .bc file # emcc src.cpp -o src.html ==> should embed the js in an html file for immediate running on the web. only tricky part is sdl. TODO: update library_sdl # emcc -O0 src.cpp ==> same as without -O0: assertions, etc., and greatest chance of code working: i64 1, ta2, etc., micro-opts # emcc -O1 src.cpp ==> no assertions, plus eliminator, plus js optimizer |