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

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

Issue 1677373002: Adding support for asm.js foreign globals. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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/wasm/asm-wasm-builder.cc
diff --git a/src/wasm/asm-wasm-builder.cc b/src/wasm/asm-wasm-builder.cc
index 691cc374694e0773ac4791b7c0b145698c0d9fc7..6c4550107f7baf8f2a2dd92f5f6f3fa76d0d9be8 100644
--- a/src/wasm/asm-wasm-builder.cc
+++ b/src/wasm/asm-wasm-builder.cc
@@ -27,7 +27,8 @@ namespace wasm {
class AsmWasmBuilderImpl : public AstVisitor {
public:
- AsmWasmBuilderImpl(Isolate* isolate, Zone* zone, FunctionLiteral* literal)
+ AsmWasmBuilderImpl(Isolate* isolate, Zone* zone, FunctionLiteral* literal,
+ Handle<Object> foreign)
: local_variables_(HashMap::PointersMatch,
ZoneHashMap::kDefaultHashMapCapacity,
ZoneAllocationPolicy(zone)),
@@ -44,6 +45,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
literal_(literal),
isolate_(isolate),
zone_(zone),
+ foreign_(foreign),
cache_(TypeCache::Get()),
breakable_blocks_(zone),
block_size_(0),
@@ -559,6 +561,24 @@ class AsmWasmBuilderImpl : public AstVisitor {
void VisitAssignment(Assignment* expr) {
bool in_init = false;
if (!in_function_) {
+ BinaryOperation* binop = expr->value()->AsBinaryOperation();
+ if (binop != nullptr) {
+ Property* prop = binop->left()->AsProperty();
+ DCHECK(prop != nullptr);
+ LoadInitFunction();
+ is_set_op_ = true;
+ RECURSE(Visit(expr->target()));
+ DCHECK(!is_set_op_);
+ if (binop->op() == Token::MUL) {
+ VisitForeignVariable(true, prop);
+ } else if (binop->op() == Token::BIT_OR) {
+ VisitForeignVariable(false, prop);
+ } else {
+ UNREACHABLE();
+ }
+ UnLoadInitFunction();
+ return;
+ }
// TODO(bradnelson): Get rid of this.
if (TypeOf(expr->value()) == kAstStmt) {
Property* prop = expr->value()->AsProperty();
@@ -610,6 +630,34 @@ class AsmWasmBuilderImpl : public AstVisitor {
void VisitThrow(Throw* expr) { UNREACHABLE(); }
+ void VisitForeignVariable(bool is_float, Property* expr) {
+ VariableProxy* var_proxy = expr->obj()->AsVariableProxy();
+ DCHECK(var_proxy != nullptr);
+ Variable* var = var_proxy->var();
+ DCHECK(var->location() == VariableLocation::PARAMETER && var->index() == 1);
+ Literal* key_literal = expr->key()->AsLiteral();
+ DCHECK(key_literal != nullptr);
+ double val = 0.0;
+ if (!key_literal->value().is_null() && !foreign_.is_null()) {
aseemgarg 2016/02/09 02:38:55 Not sure of these constructs. @Ben, can you review
bradnelson 2016/02/09 04:55:23 Yes please!
+ Handle<Name> name =
+ i::Object::ToName(isolate_, key_literal->value()).ToHandleChecked();
+ MaybeHandle<Object> maybe_value = i::Object::GetProperty(foreign_, name);
+ if (!maybe_value.is_null()) {
+ Handle<Object> value = maybe_value.ToHandleChecked();
+ if (!value.is_null() && value->IsNumber()) {
+ val = static_cast<double>(value->Number());
+ }
+ }
+ }
+ if (is_float) {
+ byte code[] = {WASM_F64(val)};
+ current_function_builder_->EmitCode(code, sizeof(code));
+ } else {
+ byte code[] = {WASM_I32(static_cast<int32_t>(val))};
+ current_function_builder_->EmitCode(code, sizeof(code));
+ }
+ }
+
void VisitProperty(Property* expr) {
Expression* obj = expr->obj();
DCHECK(obj->bounds().lower == obj->bounds().upper);
@@ -1173,6 +1221,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
FunctionLiteral* literal_;
Isolate* isolate_;
Zone* zone_;
+ Handle<Object> foreign_;
TypeCache const& cache_;
ZoneVector<std::pair<BreakableStatement*, bool>> breakable_blocks_;
int block_size_;
@@ -1188,13 +1237,13 @@ class AsmWasmBuilderImpl : public AstVisitor {
};
AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone,
- FunctionLiteral* literal)
- : isolate_(isolate), zone_(zone), literal_(literal) {}
+ FunctionLiteral* literal, Handle<Object> foreign)
+ : isolate_(isolate), zone_(zone), literal_(literal), foreign_(foreign) {}
// TODO(aseemgarg): probably should take zone (to write wasm to) as input so
// that zone in constructor may be thrown away once wasm module is written.
WasmModuleIndex* AsmWasmBuilder::Run() {
- AsmWasmBuilderImpl impl(isolate_, zone_, literal_);
+ AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_);
impl.Compile();
WasmModuleWriter* writer = impl.builder_->Build(zone_);
return writer->WriteTo(zone_);
« no previous file with comments | « src/wasm/asm-wasm-builder.h ('k') | src/wasm/wasm-js.cc » ('j') | test/mjsunit/wasm/asm-wasm.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698