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

Unified Diff: src/asmjs/asm-wasm-builder.cc

Issue 2377903002: [wasm] [asm.js] Fix various asm.js issues. (Closed)
Patch Set: Created 4 years, 3 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: src/asmjs/asm-wasm-builder.cc
diff --git a/src/asmjs/asm-wasm-builder.cc b/src/asmjs/asm-wasm-builder.cc
index 301f7f45cf2783f3aae319c059f77dde3e34cc22..213db14cf66e8ab2cf212eae5dcd00dddc241aeb 100644
--- a/src/asmjs/asm-wasm-builder.cc
+++ b/src/asmjs/asm-wasm-builder.cc
@@ -621,13 +621,31 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
} else if (expr->raw_value()->IsFalse()) {
byte code[] = {WASM_I32V(0)};
current_function_builder_->EmitCode(code, sizeof(code));
+ } else if (expr->raw_value()->IsNumber()) {
+ // This can happen when -x becomes x * -1 (due to the parser).
+ int32_t i = 0;
+ if (!value->ToInt32(&i) || i != -1) {
+ UNREACHABLE();
+ }
+ byte code[] = {WASM_I32V(i)};
+ current_function_builder_->EmitCode(code, sizeof(code));
} else {
UNREACHABLE();
}
} else if (type->IsA(AsmType::Double())) {
+ // TODO(bradnelson): Pattern match the case where negation occurs and
+ // emit f64.neg instead.
double val = expr->raw_value()->AsNumber();
byte code[] = {WASM_F64(val)};
current_function_builder_->EmitCode(code, sizeof(code));
+ } else if (type->IsA(AsmType::Float())) {
+ // This can happen when -fround(x) becomes fround(x) * 1.0[float]
+ // (due to the parser).
+ // TODO(bradnelson): Pattern match this and emit f32.neg instead.
+ double val = expr->raw_value()->AsNumber();
+ DCHECK_EQ(-1.0, val);
+ byte code[] = {WASM_F32(val)};
+ current_function_builder_->EmitCode(code, sizeof(code));
} else {
UNREACHABLE();
}

Powered by Google App Engine
This is Rietveld 408576698