diff --git a/emscripten.py b/emscripten.py index 0b9244c270a2c..08ae85c5e2cc8 100755 --- a/emscripten.py +++ b/emscripten.py @@ -41,7 +41,8 @@ def process_funcs((i, funcs, meta, settings_file, compiler, forwarded_file, libr compiler, engine=compiler_engine, args=[settings_file, funcs_file, 'funcs', forwarded_file] + libraries, - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, + cwd=path_from_root('src')) tempfiles.try_delete(funcs_file) return out @@ -153,7 +154,8 @@ def save_settings(): if out and DEBUG: print >> sys.stderr, ' loading pre from jcache' if not out: open(pre_file, 'w').write(pre_input) - out = jsrun.run_js(compiler, compiler_engine, [settings_file, pre_file, 'pre'] + libraries, stdout=subprocess.PIPE) + out = jsrun.run_js(compiler, compiler_engine, [settings_file, pre_file, 'pre'] + libraries, stdout=subprocess.PIPE, + cwd=path_from_root('src')) if jcache: if DEBUG: print >> sys.stderr, ' saving pre to jcache' jcache.set(shortkey, keys, out) @@ -236,7 +238,7 @@ def load_from_cache(chunk): outputs = [output.split('//FORWARDED_DATA:') for output in outputs] for output in outputs: - assert len(output) == 2, 'Did not receive forwarded data in an output - process failed? We only got: ' + output[0] + assert len(output) == 2, 'Did not receive forwarded data in an output - process failed? We only got: ' + output[0][-300:] if DEBUG: print >> sys.stderr, ' emscript: phase 2 took %s seconds' % (time.time() - t) if DEBUG: t = time.time() @@ -304,7 +306,8 @@ def blockaddrsize(js): if DEBUG: t = time.time() post_file = temp_files.get('.post.ll').name open(post_file, 'w').write('\n') # no input, just processing of forwarded data - out = jsrun.run_js(compiler, compiler_engine, [settings_file, post_file, 'post', forwarded_file] + libraries, stdout=subprocess.PIPE) + out = jsrun.run_js(compiler, compiler_engine, [settings_file, post_file, 'post', forwarded_file] + libraries, stdout=subprocess.PIPE, + cwd=path_from_root('src')) post, last_forwarded_data = out.split('//FORWARDED_DATA:') # if this fails, perhaps the process failed prior to printing forwarded data? last_forwarded_json = json.loads(last_forwarded_data) diff --git a/src/analyzer.js b/src/analyzer.js index ecb5ea6b03d52..dbbb267d79be0 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -1380,7 +1380,7 @@ function analyzer(data, sidePass) { var label = func.labels[i]; for (var j = 0; j < label.lines.length; j++) { var line = label.lines[j]; - if (line.intertype == 'call' && line.ident == setjmp) { + if ((line.intertype == 'call' || line.intertype == 'invoke') && line.ident == setjmp) { // Add a new label var oldIdent = label.ident; var newIdent = func.labelIdCounter++; diff --git a/src/intertyper.js b/src/intertyper.js index 6c88e765caedb..2103ecfab35e2 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -677,7 +677,7 @@ function intertyper(data, sidePass, baseLineNums) { item.type = item.tokens[1].text; Types.needAnalysis[item.type] = 0; while (['@', '%'].indexOf(item.tokens[2].text[0]) == -1 && !(item.tokens[2].text in PARSABLE_LLVM_FUNCTIONS) && - item.tokens[2].text != 'null' && item.tokens[2].text != 'asm') { + item.tokens[2].text != 'null' && item.tokens[2].text != 'asm' && item.tokens[2].text != 'undef') { assert(item.tokens[2].text != 'asm', 'Inline assembly cannot be compiled to JavaScript!'); item.tokens.splice(2, 1); } diff --git a/src/library.js b/src/library.js index 1cd7e3f5833d7..a5166c72cdc29 100644 --- a/src/library.js +++ b/src/library.js @@ -2403,6 +2403,7 @@ LibraryManager.library = { case {{{ cDefine('_SC_STREAM_MAX') }}}: return 16; case {{{ cDefine('_SC_TZNAME_MAX') }}}: return 6; case {{{ cDefine('_SC_THREAD_DESTRUCTOR_ITERATIONS') }}}: return 4; + case {{{ cDefine('_SC_NPROCESSORS_ONLN') }}}: return 1; } ___setErrNo(ERRNO_CODES.EINVAL); return -1; @@ -5506,6 +5507,14 @@ LibraryManager.library = { return -a; }, copysignf: 'copysign', + __signbit__deps: ['copysign'], + __signbit: function(x) { + // We implement using copysign so that we get support + // for negative zero (once copysign supports that). + return _copysign(1.0, x) < 0; + }, + __signbitf: '__signbit', + __signbitd: '__signbit', hypot: function(a, b) { return Math.sqrt(a*a + b*b); }, @@ -6064,6 +6073,15 @@ LibraryManager.library = { __timespec_struct_layout: Runtime.generateStructInfo([ ['i32', 'tv_sec'], ['i32', 'tv_nsec']]), + nanosleep__deps: ['usleep', '__timespec_struct_layout'], + nanosleep: function(rqtp, rmtp) { + // int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); + var seconds = {{{ makeGetValue('rqtp', '___timespec_struct_layout.tv_sec', 'i32') }}}; + var nanoseconds = {{{ makeGetValue('rqtp', '___timespec_struct_layout.tv_nsec', 'i32') }}}; + {{{ makeSetValue('rmtp', '___timespec_struct_layout.tv_sec', '0', 'i32') }}} + {{{ makeSetValue('rmtp', '___timespec_struct_layout.tv_nsec', '0', 'i32') }}} + return _usleep((seconds * 1e6) + (nanoseconds / 1000)); + }, // TODO: Implement these for real. clock_gettime__deps: ['__timespec_struct_layout'], clock_gettime: function(clk_id, tp) { @@ -6692,6 +6710,13 @@ LibraryManager.library = { return 0; }, + // ========================================================================== + // sched.h (stubs only - no thread support yet!) + // ========================================================================== + sched_yield: function() { + return 0; + }, + // ========================================================================== // pthread.h (stubs for mutexes only - no thread support yet!) // ========================================================================== @@ -6708,8 +6733,15 @@ LibraryManager.library = { }, pthread_cond_init: function() {}, pthread_cond_destroy: function() {}, - pthread_cond_broadcast: function() {}, - pthread_cond_wait: function() {}, + pthread_cond_broadcast: function() { + return 0; + }, + pthread_cond_wait: function() { + return 0; + }, + pthread_cond_timedwait: function() { + return 0; + }, pthread_self: function() { //FIXME: assumes only a single thread return 0; diff --git a/src/library_sdl.js b/src/library_sdl.js index 96ae6fa2da149..d707a8bfbf983 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1463,10 +1463,70 @@ var LibrarySDL = { return (SDL.music.audio && !SDL.music.audio.paused) ? 1 : 0; }, + // http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_38.html#SEC38 + // "Note: Does not check if the channel has been paused." + Mix_Playing: function(id) { + if (id === -1) { + var count = 0; + for (var i = 0; i < SDL.audios.length; i++) { + count += SDL.Mix_Playing(i); + } + return count; + } + var info = SDL.audios[id]; + if (info && info.audio && !info.audio.paused) { + return 1; + } + return 0; + }, + + Mix_Pause: function(id) { + if (id === -1) { + for (var i = 0; i BlockList; + void Relooper::Calculate(Block *Entry) { // Scan and optimize the input struct PreOptimizer : public RelooperRecursor { PreOptimizer(Relooper *Parent) : RelooperRecursor(Parent) {} BlockSet Live; - void FindLive(Block *Curr) { - if (Live.find(Curr) != Live.end()) return; - Live.insert(Curr); - for (BlockBranchMap::iterator iter = Curr->BranchesOut.begin(); iter != Curr->BranchesOut.end(); iter++) { - FindLive(iter->first); + void FindLive(Block *Root) { + BlockList ToInvestigate; + ToInvestigate.push_back(Root); + while (ToInvestigate.size() > 0) { + Block *Curr = ToInvestigate.front(); + ToInvestigate.pop_front(); + if (Live.find(Curr) != Live.end()) continue; + Live.insert(Curr); + for (BlockBranchMap::iterator iter = Curr->BranchesOut.begin(); iter != Curr->BranchesOut.end(); iter++) { + ToInvestigate.push_back(iter->first); + } } } @@ -529,7 +537,6 @@ void Relooper::Calculate(Block *Entry) { // ignore directly reaching the entry itself by another entry. void FindIndependentGroups(BlockSet &Blocks, BlockSet &Entries, BlockBlockSetMap& IndependentGroups) { typedef std::map BlockBlockMap; - typedef std::list BlockList; struct HelperClass { BlockBlockSetMap& IndependentGroups; diff --git a/src/relooper/fuzzer.py b/src/relooper/fuzzer.py index 887eab3b4d1c1..96929028523a7 100644 --- a/src/relooper/fuzzer.py +++ b/src/relooper/fuzzer.py @@ -98,14 +98,14 @@ open('fuzz.slow.js', 'w').write(slow) open('fuzz.cpp', 'w').write(fast) print '_' - slow_out = subprocess.Popen(['/home/alon/Dev/mozilla-central/js/src/fast/js', '-m', '-n', 'fuzz.slow.js'], stdout=subprocess.PIPE).communicate()[0] + slow_out = subprocess.Popen(['/home/alon/Dev/odinmonkey/js/src/fast/js', '-m', '-n', 'fuzz.slow.js'], stdout=subprocess.PIPE).communicate()[0] print '.' subprocess.call(['g++', 'fuzz.cpp', 'Relooper.o', '-o', 'fuzz', '-g']) print '*' subprocess.call(['./fuzz'], stdout=open('fuzz.fast.js', 'w')) print '-' - fast_out = subprocess.Popen(['/home/alon/Dev/mozilla-central/js/src/fast/js', '-m', '-n', 'fuzz.fast.js'], stdout=subprocess.PIPE).communicate()[0] + fast_out = subprocess.Popen(['/home/alon/Dev/odinmonkey/js/src/fast/js', '-m', '-n', 'fuzz.fast.js'], stdout=subprocess.PIPE).communicate()[0] print if slow_out != fast_out: diff --git a/src/relooper/test.txt b/src/relooper/test.txt index b7c8794d06c5b..12d0ef39b06ad 100644 --- a/src/relooper/test.txt +++ b/src/relooper/test.txt @@ -54,7 +54,7 @@ while(1) { // code 2 if (!($2)) { var $x_1 = $x_0; - label = 19; + label = 18; break; } // code 3 @@ -64,7 +64,7 @@ while(1) { var $i_0 = $7;var $x_0 = $5; } } -if (label == 19) { +if (label == 18) { // code 7 } // code 4 diff --git a/src/runtime.js b/src/runtime.js index 7f97da351eb45..dc604a8d23375 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -365,6 +365,11 @@ var Runtime = { return ret; }, + removeFunction: function(index) { + var table = FUNCTION_TABLE; // TODO: support asm + table[index] = null; + }, + warnOnce: function(text) { if (!Runtime.warnOnce.shown) Runtime.warnOnce.shown = {}; if (!Runtime.warnOnce.shown[text]) { diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h index 427dda0cc5592..61634b0e4a6eb 100644 --- a/system/include/emscripten/emscripten.h +++ b/system/include/emscripten/emscripten.h @@ -60,7 +60,7 @@ extern void emscripten_async_run_script(const char *script, int millis); * that execution continues normally. Note that in both cases * we do not run global destructors, atexit, etc., since we * know the main loop will still be running, but if we do - * not simulate an infinite loop then the stack will be unwinded. + * not simulate an infinite loop then the stack will be unwound. * That means that if simulate_infinite_loop is false, and * you created an object on the stack, it will be cleaned up * before the main loop will be called the first time. @@ -215,7 +215,7 @@ void emscripten_async_wget_data(const char* url, void *arg, void (*onload)(void* * More feature-complete version of emscripten_async_wget. Note: * this version is experimental. * - * The requestype is 'GET' or 'POST', + * The requesttype is 'GET' or 'POST', * If is post request, param is the post parameter * like key=value&key2=value2. * The param 'arg' is a pointer will be pass to the callback diff --git a/system/include/stdbool.h b/system/include/stdbool.h index f970ade88ba91..561eed3f2db88 100644 --- a/system/include/stdbool.h +++ b/system/include/stdbool.h @@ -2,12 +2,13 @@ #ifndef __stdbool_h__ #define __stdbool_h__ +#define __bool_true_false_are_defined 1 + #ifndef __cplusplus #define bool _Bool #define true 1 #define false 0 -#define __bool_true_false_are_defined 1 #endif diff --git a/tests/cases/invokeundef.ll b/tests/cases/invokeundef.ll new file mode 100644 index 0000000000000..9dc1f93dcc30a --- /dev/null +++ b/tests/cases/invokeundef.ll @@ -0,0 +1,41 @@ +; ModuleID = '/dev/shm/tmp/src.cpp.o' +; Just test for compilation here +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-f128:128:128-n8:16:32" +target triple = "i386-pc-linux-gnu" + +%struct.CPU_Regs = type { [8 x %union.GenReg32] } +%union.GenReg32 = type { [1 x i32] } + +@cpu_regs = unnamed_addr global %struct.CPU_Regs zeroinitializer, align 32 ; [#uses=2] +@.str = private unnamed_addr constant [14 x i8] c"hello, world!\00", align 1 ; [#uses=1] + +; [#uses=0] +define i32 @main() { +entry: + %retval = alloca i32 ; [#uses=2] + %0 = alloca i32 ; [#uses=2] + %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] + %1 = load i32* bitcast (i32* getelementptr inbounds (%struct.CPU_Regs* @cpu_regs, i32 0, i32 0, i32 1, i32 0, i32 0) to i32*), align 2 ; [#uses=1] + store i16 %1, i16* bitcast (%struct.CPU_Regs* @cpu_regs to i16*), align 2 + %2 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + store i32 0, i32* %0, align 4 + %3 = load i32* %0, align 4 ; [#uses=1] + store i32 %3, i32* %retval, align 4 + br label %return + + invoke void undef(%struct.CPU_Regs* noalias @cpu_regs, i32 %99) + to label %invcont33 unwind label %lpad106 + +invcont33: + ret i32 %retval1 + +lpad106: + ret i32 %retval1 + +return: ; preds = %entry + %retval1 = load i32* %retval ; [#uses=1] + ret i32 %retval1 +} + +; [#uses=1] +declare i32 @puts(i8*) diff --git a/tests/cases/longjmp_tiny_noasm_invoke.ll b/tests/cases/longjmp_tiny_noasm_invoke.ll new file mode 100644 index 0000000000000..e1a72e001c95c --- /dev/null +++ b/tests/cases/longjmp_tiny_noasm_invoke.ll @@ -0,0 +1,71 @@ +; ModuleID = '/tmp/emscripten_temp/src.cpp.o' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" +target triple = "i386-pc-linux-gnu" + +@_ZL3buf = internal global [20 x i16] zeroinitializer, align 2 +@.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00", align 1 +@.str1 = private unnamed_addr constant [6 x i8] c"more\0A\00", align 1 + +define i32 @main() { + %retval = alloca i32, align 4 + store i32 0, i32* %retval + %call = invoke i32 @setjmp(i16* getelementptr inbounds ([20 x i16]* @_ZL3buf, i32 0, i32 0)) returns_twice, !dbg !20 + to label %allgood unwind label %awful + +allgood: + %tobool = icmp ne i32 %call, 0, !dbg !20 + br i1 %tobool, label %if.else, label %if.then, !dbg !20 + +if.then: ; preds = %entry + %call1 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0)), !dbg !22 + call void @longjmp(i16* getelementptr inbounds ([20 x i16]* @_ZL3buf, i32 0, i32 0), i32 10), !dbg !24 + br label %if.end, !dbg !25 + +if.else: ; preds = %entry + %call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str1, i32 0, i32 0)), !dbg !26 + br label %if.end + +if.end: ; preds = %if.else, %if.then + ret i32 0, !dbg !28 + +awful: + ret i32 1 +} + +declare i32 @setjmp(i16*) returns_twice + +declare i32 @printf(i8*, ...) + +declare void @longjmp(i16*, i32) + +!llvm.dbg.cu = !{!0} + +!0 = metadata !{i32 786449, i32 0, i32 4, metadata !"/tmp/emscripten_temp/src.cpp", metadata !"/home/alon/Dev/emscripten", metadata !"clang version 3.1 (trunk 150936)", i1 true, i1 false, metadata !"", i32 0, metadata !1, metadata !1, metadata !3, metadata !12} ; [ DW_TAG_compile_unit ] +!1 = metadata !{metadata !2} +!2 = metadata !{i32 0} +!3 = metadata !{metadata !4} +!4 = metadata !{metadata !5} +!5 = metadata !{i32 786478, i32 0, metadata !6, metadata !"main", metadata !"main", metadata !"", metadata !6, i32 7, metadata !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, metadata !10} ; [ DW_TAG_subprogram ] +!6 = metadata !{i32 786473, metadata !"/tmp/emscripten_temp/src.cpp", metadata !"/home/alon/Dev/emscripten", null} ; [ DW_TAG_file_type ] +!7 = metadata !{i32 786453, i32 0, metadata !"", i32 0, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !8, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] +!8 = metadata !{metadata !9} +!9 = metadata !{i32 786468, null, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] +!10 = metadata !{metadata !11} +!11 = metadata !{i32 786468} ; [ DW_TAG_base_type ] +!12 = metadata !{metadata !13} +!13 = metadata !{metadata !14} +!14 = metadata !{i32 786484, i32 0, null, metadata !"buf", metadata !"buf", metadata !"_ZL3buf", metadata !6, i32 5, metadata !15, i32 1, i32 1, [20 x i16]* @_ZL3buf} ; [ DW_TAG_variable ] +!15 = metadata !{i32 786454, null, metadata !"jmp_buf", metadata !6, i32 279, i64 0, i64 0, i64 0, i32 0, metadata !16} ; [ DW_TAG_typedef ] +!16 = metadata !{i32 786433, null, metadata !"", null, i32 0, i64 320, i64 16, i32 0, i32 0, metadata !17, metadata !18, i32 0, i32 0} ; [ DW_TAG_array_type ] +!17 = metadata !{i32 786468, null, metadata !"unsigned short", null, i32 0, i64 16, i64 16, i64 0, i32 0, i32 7} ; [ DW_TAG_base_type ] +!18 = metadata !{metadata !19} +!19 = metadata !{i32 786465, i64 0, i64 19} ; [ DW_TAG_subrange_type ] +!20 = metadata !{i32 8, i32 18, metadata !21, null} +!21 = metadata !{i32 786443, metadata !5, i32 7, i32 22, metadata !6, i32 0} ; [ DW_TAG_lexical_block ] +!22 = metadata !{i32 9, i32 15, metadata !23, null} +!23 = metadata !{i32 786443, metadata !21, i32 8, i32 31, metadata !6, i32 1} ; [ DW_TAG_lexical_block ] +!24 = metadata !{i32 10, i32 15, metadata !23, null} +!25 = metadata !{i32 11, i32 13, metadata !23, null} +!26 = metadata !{i32 12, i32 15, metadata !27, null} +!27 = metadata !{i32 786443, metadata !21, i32 11, i32 20, metadata !6, i32 2} ; [ DW_TAG_lexical_block ] +!28 = metadata !{i32 14, i32 13, metadata !21, null} diff --git a/tests/cases/longjmp_tiny_noasm_invoke.txt b/tests/cases/longjmp_tiny_noasm_invoke.txt new file mode 100644 index 0000000000000..8a0aa3869352d --- /dev/null +++ b/tests/cases/longjmp_tiny_noasm_invoke.txt @@ -0,0 +1,2 @@ +hello world +more diff --git a/tests/runner.py b/tests/runner.py index e631b02529d9b..e4c7a1e1521c0 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -11282,7 +11282,7 @@ def do_benchmark(self, name, src, args=[], expected_output='FAIL', emcc_args=[], try_delete(final_filename) output = Popen([PYTHON, EMCC, filename, #'-O3', '-O2', '-s', 'INLINING_LIMIT=0', '-s', 'DOUBLE_MODE=0', '-s', 'PRECISE_I64_MATH=0',# '-s', 'EXPLICIT_ZEXT=1', - '-s', 'ASM_JS=1', '-s', 'USE_MATH_IMUL=1', + '-s', 'ASM_JS=1', '-s', 'USE_MATH_IMUL=1', '--llvm-lto', '1', '-s', 'TOTAL_MEMORY=128*1024*1024', '-s', 'FAST_MEMORY=10*1024*1024', '-o', final_filename] + shared_args + emcc_args, stdout=PIPE, stderr=self.stderr_redirect).communicate() assert os.path.exists(final_filename), 'Failed to compile file: ' + output[0] diff --git a/tests/sdl_audio.c b/tests/sdl_audio.c index 938df3c4eb144..ce3bf5a9a46fe 100644 --- a/tests/sdl_audio.c +++ b/tests/sdl_audio.c @@ -6,13 +6,14 @@ Mix_Chunk *sound, *sound2; -void play2(); +int play2(); -void play() { +int play() { int channel = Mix_PlayChannel(-1, sound, 1); assert(channel == 0); emscripten_run_script("setTimeout(Module['_play2'], 500)"); + return channel; } void done(int channel) { @@ -22,11 +23,12 @@ void done(int channel) { REPORT_RESULT(); } -void play2() { +int play2() { Mix_ChannelFinished(done); int channel2 = Mix_PlayChannel(-1, sound2, 1); assert(channel2 == 1); + return channel2; } int main(int argc, char **argv) { @@ -40,7 +42,17 @@ int main(int argc, char **argv) { sound2 = Mix_LoadWAV("sound2.wav"); assert(sound); - play(); + int channel = play(); + printf( "Pausing Channel %d", channel ); + Mix_Pause(channel); + int paused = Mix_Paused(channel); + printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" ); + assert(paused); + Mix_Resume(channel); + paused = Mix_Paused(channel); + printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" ); + assert(paused == 0); + if (argc == 12121) play2(); // keep it alive emscripten_run_script("element = document.createElement('input');" diff --git a/tools/shared.py b/tools/shared.py index 09f6aef46e575..46faddb6d3537 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -181,7 +181,7 @@ def check_node_version(): # we re-check sanity when the settings are changed) # We also re-check sanity and clear the cache when the version changes -EMSCRIPTEN_VERSION = '1.2.6' +EMSCRIPTEN_VERSION = '1.2.7' def check_sanity(force=False): try: