aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/runtime.js8
-rw-r--r--system/include/emscripten/emscripten.h5
-rw-r--r--tests/cases/fixablebadcasts_fastcomp.ll27
-rw-r--r--tests/cases/fixablebadcasts_fastcomp.txt1
-rw-r--r--tests/core/test_inlinejs3.in1
-rw-r--r--tests/core/test_inlinejs3.out1
-rw-r--r--tests/fs/test_idbfs_sync.c26
7 files changed, 54 insertions, 15 deletions
diff --git a/src/runtime.js b/src/runtime.js
index edcbf637..63610d3b 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -409,7 +409,13 @@ var Runtime = {
abort('invalid EM_ASM input |' + source + '|. Please use EM_ASM(..code..) (no quotes) or EM_ASM({ ..code($0).. }, input) (to input values)');
}
}
- return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + source + ' })'); // new Function does not allow upvars in node
+ try {
+ var evalled = eval('(function(' + args.join(',') + '){ ' + source + ' })'); // new Function does not allow upvars in node
+ } catch(e) {
+ Module.printErr('error in executing inline EM_ASM code: ' + e + ' on: \n\n' + source + '\n\nwith args |' + args + '| (make sure to use the right one out of EM_ASM, EM_ASM_ARGS, etc.)');
+ throw e;
+ }
+ return Runtime.asmConstCache[code] = evalled;
},
warnOnce: function(text) {
diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h
index 2b883f93..73836018 100644
--- a/system/include/emscripten/emscripten.h
+++ b/system/include/emscripten/emscripten.h
@@ -42,8 +42,8 @@ extern "C" {
/*
* Input-output versions of EM_ASM.
*
- * EM_ASM_ (an extra _ is added) allows sending values (ints
- * or doubles) into the code. If you also want a return value,
+ * EM_ASM_ (an extra _ is added) or EM_ASM_ARGS allow sending values
+ * (ints or doubles) into the code. If you also want a return value,
* EM_ASM_INT receives arguments (of int or double type)
* and returns an int; EM_ASM_DOUBLE does the same and returns
* a double.
@@ -60,6 +60,7 @@ extern "C" {
* EM_ASM_INT_V and EM_ASM_DOUBLE_V respectively.
*/
#define EM_ASM_(code, ...) emscripten_asm_const_int(#code, __VA_ARGS__)
+#define EM_ASM_ARGS(code, ...) emscripten_asm_const_int(#code, __VA_ARGS__)
#define EM_ASM_INT(code, ...) emscripten_asm_const_int(#code, __VA_ARGS__)
#define EM_ASM_DOUBLE(code, ...) emscripten_asm_const_double(#code, __VA_ARGS__)
#define EM_ASM_INT_V(code) emscripten_asm_const_int(#code)
diff --git a/tests/cases/fixablebadcasts_fastcomp.ll b/tests/cases/fixablebadcasts_fastcomp.ll
new file mode 100644
index 00000000..3870e0e0
--- /dev/null
+++ b/tests/cases/fixablebadcasts_fastcomp.ll
@@ -0,0 +1,27 @@
+; ModuleID = 'tests/hello_world.bc'
+target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:128-n32-S128"
+target triple = "asmjs-unknown-emscripten"
+
+@.str = private unnamed_addr constant [18 x i8] c"hello, world %d!\0A\00", align 1
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4 ; [#uses=1 type=i32*]
+ store i32 0, i32* %retval
+ %a = call i32 bitcast (i32 (i32)* @twoparam to i32 (i32, i32)*)(i32 5, i32 6)
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 x i8]* @.str, i32 0, i32 0), i32 %a) ; [#uses=0 type=i32]
+ call void bitcast (void (i32, i32*, i32*)* @_ZN7WebCore33signedPublicKeyAndChallengeStringEjRKN3WTF6StringERKNS_3URLE to void (i32*, i32, i32*, i32*)*)(i32* sret null, i32 0, i32* null, i32* null)
+ ret i32 1
+}
+
+define i32 @twoparam(i32 %x) {
+ ret i32 %x
+}
+
+define void @_ZN7WebCore33signedPublicKeyAndChallengeStringEjRKN3WTF6StringERKNS_3URLE(i32, i32* nocapture, i32* nocapture) {
+ ret void
+}
+
+; [#uses=1]
+declare i32 @printf(i8*, ...)
diff --git a/tests/cases/fixablebadcasts_fastcomp.txt b/tests/cases/fixablebadcasts_fastcomp.txt
new file mode 100644
index 00000000..47abd748
--- /dev/null
+++ b/tests/cases/fixablebadcasts_fastcomp.txt
@@ -0,0 +1 @@
+hello, world 5!
diff --git a/tests/core/test_inlinejs3.in b/tests/core/test_inlinejs3.in
index b45abe95..c3b9b769 100644
--- a/tests/core/test_inlinejs3.in
+++ b/tests/core/test_inlinejs3.in
@@ -13,6 +13,7 @@ int main(int argc, char **argv) {
EM_ASM(Module.print('hello dere3'); Module.print('hello dere' + 4););
}
EM_ASM_({ Module.print('hello input ' + $0) }, 123);
+ EM_ASM_ARGS({ Module.print('hello input ' + $0) }, 456);
int sum = 0;
for (int i = 0; i < argc * 3; i++) {
sum += EM_ASM_INT({
diff --git a/tests/core/test_inlinejs3.out b/tests/core/test_inlinejs3.out
index 5d185adc..c48cc3c8 100644
--- a/tests/core/test_inlinejs3.out
+++ b/tests/core/test_inlinejs3.out
@@ -7,6 +7,7 @@ hello dere4
hello dere3
hello dere4
hello input 123
+hello input 456
i: 0,0.00
i: 1,0.08
i: 2,0.17
diff --git a/tests/fs/test_idbfs_sync.c b/tests/fs/test_idbfs_sync.c
index ff356416..0d8f4d71 100644
--- a/tests/fs/test_idbfs_sync.c
+++ b/tests/fs/test_idbfs_sync.c
@@ -1,8 +1,6 @@
#include <stdio.h>
#include <emscripten.h>
-#define EM_ASM_REEXPAND(x) EM_ASM(x)
-
void success() {
int result = 1;
REPORT_RESULT();
@@ -15,31 +13,35 @@ int main() {
);
#if FIRST
- // store local files to backing IDB
- EM_ASM_REEXPAND(
+ // store local files to backing IDB. Note that we use the JS FS API for everything here, but we
+ // could use normal libc fwrite etc. to do the writing. All we need the JS FS API for is to
+ // mount the filesystem and do syncfs.
+ EM_ASM_ARGS({
FS.writeFile('/working/waka.txt', 'az');
- FS.writeFile('/working/moar.txt', SECRET);
+ FS.writeFile('/working/moar.txt', $0);
FS.syncfs(function (err) {
assert(!err);
- ccall('success', 'v', '', []);
+ ccall('success', 'v');
});
- );
+ }, SECRET);
#else
// load files from backing IDB
- EM_ASM_REEXPAND(
+ EM_ASM_ARGS({
FS.syncfs(true, function (err) {
assert(!err);
var contents = FS.readFile('/working/waka.txt', { encoding: 'utf8' });
- assert(contents === 'az');
+ assert(contents === 'az', 'bad contents ' + contents);
- var secret = FS.readFile('/working/moar.txt', { encoding: 'utf8' });
- assert(secret === SECRET);
+ // note we convert to a number here (using +), since we used writeFile, which writes a
+ // JS string.
+ var secret = +FS.readFile('/working/moar.txt', { encoding: 'utf8' });
+ assert(secret === $0, 'bad secret ' + [secret, $0, typeof secret, typeof $0]);
ccall('success', 'v', '', []);
});
- );
+ }, SECRET);
#endif
emscripten_exit_with_live_runtime();