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

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

Issue 1832603002: Properly handle unsigned literals, fix typing issue with unary +. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: drop print Created 4 years, 9 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
« no previous file with comments | « src/typing-asm.cc ('k') | test/cctest/test-asm-validator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/asm-wasm-builder.cc
diff --git a/src/wasm/asm-wasm-builder.cc b/src/wasm/asm-wasm-builder.cc
index 4c7410d7e004c612e809db7f3ccc06da5da3188e..359035994dd4a01808e5fba5074dc7084779020a 100644
--- a/src/wasm/asm-wasm-builder.cc
+++ b/src/wasm/asm-wasm-builder.cc
@@ -461,33 +461,32 @@ class AsmWasmBuilderImpl : public AstVisitor {
}
void VisitLiteral(Literal* expr) {
- if (in_function_) {
- if (expr->raw_value()->IsNumber()) {
- LocalType type = TypeOf(expr);
- switch (type) {
- case kAstI32: {
- int val = static_cast<int>(expr->raw_value()->AsNumber());
- // TODO(bradnelson): variable size
- byte code[] = {WASM_I32V(val)};
- current_function_builder_->EmitCode(code, sizeof(code));
- break;
- }
- case kAstF32: {
- float val = static_cast<float>(expr->raw_value()->AsNumber());
- byte code[] = {WASM_F32(val)};
- current_function_builder_->EmitCode(code, sizeof(code));
- break;
- }
- case kAstF64: {
- double val = static_cast<double>(expr->raw_value()->AsNumber());
- byte code[] = {WASM_F64(val)};
- current_function_builder_->EmitCode(code, sizeof(code));
- break;
- }
- default:
- UNREACHABLE();
- }
+ Handle<Object> value = expr->value();
+ if (!in_function_ || !value->IsNumber()) {
+ return;
+ }
+ Type* type = expr->bounds().upper;
+ if (type->Is(cache_.kAsmSigned)) {
+ int32_t i;
+ if (!value->ToInt32(&i)) {
+ UNREACHABLE();
+ }
+ byte code[] = {WASM_I32V(i)};
+ current_function_builder_->EmitCode(code, sizeof(code));
+ } else if (type->Is(cache_.kAsmUnsigned) || type->Is(cache_.kAsmFixnum)) {
+ uint32_t u;
+ if (!value->ToUint32(&u)) {
+ UNREACHABLE();
}
+ int32_t i = static_cast<int32_t>(u);
+ byte code[] = {WASM_I32V(i)};
+ current_function_builder_->EmitCode(code, sizeof(code));
+ } else if (type->Is(cache_.kAsmDouble)) {
+ double val = expr->raw_value()->AsNumber();
+ byte code[] = {WASM_F64(val)};
+ current_function_builder_->EmitCode(code, sizeof(code));
+ } else {
+ UNREACHABLE();
}
}
« no previous file with comments | « src/typing-asm.cc ('k') | test/cctest/test-asm-validator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698