Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Unified Diff: runtime/wasm-runtime.cpp

Issue 1900213002: Subzero - WASM: Codegen fixes, better test infrastructure (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Merge wasm-runtime.c and wasm-runtime.cpp Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/wasm-runtime.cpp
diff --git a/runtime/wasm-runtime.c b/runtime/wasm-runtime.cpp
similarity index 80%
rename from runtime/wasm-runtime.c
rename to runtime/wasm-runtime.cpp
index 2e1bd37d79734753ccbba1a801591da5e1099a66..9628d3a6f30a62b3e598c1f110e82374550c404b 100644
--- a/runtime/wasm-runtime.c
+++ b/runtime/wasm-runtime.cpp
@@ -1,4 +1,4 @@
-//===- subzero/runtime/wasm-runtime.c - Subzero WASM runtime source -------===//
+//===- subzero/runtime/wasm-runtime.cpp - Subzero WASM runtime source -----===//
//
// The Subzero Code Generator
//
@@ -12,8 +12,19 @@
//
//===----------------------------------------------------------------------===//
+#include <cmath>
+
+namespace env {
+double floor(double X) { return std::floor(X); }
+
+float floor(float X) { return std::floor(X); }
+}
+
+// TODO (eholk): move the C parts outside and use C++ name mangling.
+extern "C" {
#include <errno.h>
#include <fcntl.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -44,12 +55,13 @@ UNIMPLEMENTED(setjmp)
UNIMPLEMENTED(longjmp)
UNIMPLEMENTED(__assert_fail)
UNIMPLEMENTED(__builtin_malloc)
+UNIMPLEMENTED(__builtin_isinff)
+UNIMPLEMENTED(__builtin_isinfl)
UNIMPLEMENTED(__builtin_apply)
UNIMPLEMENTED(__builtin_apply_args)
UNIMPLEMENTED(pthread_cleanup_push)
UNIMPLEMENTED(pthread_cleanup_pop)
UNIMPLEMENTED(pthread_self)
-UNIMPLEMENTED(abs)
UNIMPLEMENTED(__floatditf)
UNIMPLEMENTED(__floatsitf)
UNIMPLEMENTED(__fixtfdi)
@@ -66,14 +78,17 @@ UNIMPLEMENTED(__multf3)
UNIMPLEMENTED(__multi3)
UNIMPLEMENTED(__lock)
UNIMPLEMENTED(__unlock)
-UNIMPLEMENTED(__syscall6)
-UNIMPLEMENTED(__syscall20)
-UNIMPLEMENTED(__syscall140)
-UNIMPLEMENTED(__syscall192)
+UNIMPLEMENTED(__syscall6) // sys_close
+UNIMPLEMENTED(__syscall140) // sys_llseek
+UNIMPLEMENTED(__syscall192) // sys_mmap?
+UNIMPLEMENTED(__unordtf2)
+UNIMPLEMENTED(__fixunstfsi)
+UNIMPLEMENTED(__floatunsitf)
+UNIMPLEMENTED(__extenddftf2)
void *wasmPtr(int Index) {
// TODO (eholk): get the mask from the WASM file.
- const int MASK = 0x3fffff;
+ const int MASK = 0xffffff;
Index &= MASK;
return WASM_MEMORY + Index;
@@ -86,6 +101,10 @@ extern int __szwasm_main(int, const char **);
int main(int argc, const char **argv) { return __szwasm_main(argc, argv); }
+int env$$abs(int a) { return abs(a); }
+
+double env$$pow(double x, double y) { return pow(x, y); }
+
/// sys_write
int env$$__syscall4(int Which, int VarArgs) {
int Fd = WASM_DEREF(int, VarArgs + 0 * sizeof(int));
@@ -107,6 +126,14 @@ int env$$__syscall5(int Which, int VarArgs) {
return open(Path, Flags, Mode);
}
+/// sys_getpid
+int env$$__syscall20(int Which, int VarArgs) {
+ (void)Which;
+ (void)VarArgs;
+
+ return getpid();
+}
+
/// sys_ioctl
int env$$__syscall54(int A, int B) {
int Fd = WASM_DEREF(int, B + 0 * sizeof(int));
@@ -116,32 +143,26 @@ int env$$__syscall54(int A, int B) {
return -ENOTTY;
}
+/// sys_write
int env$$__syscall146(int Which, int VarArgs) {
- fprintf(stderr, "syscall146\n");
int Fd = WASM_DEREF(int, VarArgs);
int Iov = WASM_DEREF(int, VarArgs + sizeof(int));
int Iovcnt = WASM_DEREF(int, VarArgs + 2 * sizeof(int));
- fprintf(stderr, " Fd=%d, Iov=%d (%p), Iovcnt=%d\n", Fd, Iov, wasmPtr(Iov),
- Iovcnt);
-
int Count = 0;
for (int I = 0; I < Iovcnt; ++I) {
void *Ptr = WASM_REF(void, WASM_DEREF(int, Iov + I * 8));
int Length = WASM_DEREF(int, Iov + I * 8 + 4);
- fprintf(stderr, " [%d] write(%d, %p, %d) = ", I, Fd, Ptr, Length);
int Curr = write(Fd, Ptr, Length);
- fprintf(stderr, "%d\n", Curr);
-
if (Curr < 0) {
return -1;
}
Count += Curr;
}
- fprintf(stderr, " Count = %d\n", Count);
return Count;
}
+}
John 2016/04/20 20:04:59 maybe } // end of extern "C" Check with Jim.
Eric Holk 2016/04/20 20:25:35 Done.
« no previous file with comments | « runtime/wasm-runtime.c ('k') | src/WasmTranslator.cpp » ('j') | src/WasmTranslator.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698