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

Unified Diff: src/interpreter/interpreter.cc

Issue 2471033004: [ignition,modules] Introduce bytecodes for loading/storing module variables. (Closed)
Patch Set: Address other feedback. Created 4 years, 1 month 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/interpreter/interpreter.cc
diff --git a/src/interpreter/interpreter.cc b/src/interpreter/interpreter.cc
index d36480769b0d296ec5891ce895805854c78b8b03..593ee79032cab177e522b5b49fbcee8f847b691e 100644
--- a/src/interpreter/interpreter.cc
+++ b/src/interpreter/interpreter.cc
@@ -928,6 +928,82 @@ void Interpreter::DoStaKeyedPropertyStrict(InterpreterAssembler* assembler) {
DoKeyedStoreIC(ic, assembler);
}
+// LdaModuleVariable <imm>
+//
+// Load the contents of a module variable into the accumulator. The variable is
+// identified by its index <imm>.
+void Interpreter::DoLdaModuleVariable(InterpreterAssembler* assembler) {
Benedikt Meurer 2016/11/04 16:45:59 Cool! I like this!
+ Node* raw_index = __ BytecodeOperandImm(0);
+
+ Node* module_context = __ LoadModuleContext(__ GetContext());
+ Node* module = __ LoadContextSlot(module_context, Context::EXTENSION_INDEX);
+
+ Label if_export(assembler), if_import(assembler), end(assembler);
+ __ Branch(__ IntPtrGreaterThan(raw_index, __ IntPtrConstant(0)), &if_export,
+ &if_import);
+
+ __ Bind(&if_export);
+ {
+ Node* regular_exports =
+ __ LoadObjectField(module, Module::kRegularExportsOffset);
+ // The actual array index is (raw_index - 1).
+ Node* export_index = __ IntPtrSub(raw_index, __ IntPtrConstant(1));
+ Node* cell = __ LoadFixedArrayElement(regular_exports, export_index);
+ __ SetAccumulator(__ LoadObjectField(cell, Cell::kValueOffset));
+ __ Goto(&end);
+ }
+
+ __ Bind(&if_import);
+ {
+ Node* regular_imports =
+ __ LoadObjectField(module, Module::kRegularImportsOffset);
+ // The actual array index is (-raw_index - 1).
+ Node* import_index = __ IntPtrSub(
+ __ IntPtrMul(raw_index, __ IntPtrConstant(-1)), __ IntPtrConstant(1));
+ Node* cell = __ LoadFixedArrayElement(regular_imports, import_index);
+ __ SetAccumulator(__ LoadObjectField(cell, Cell::kValueOffset));
+ __ Goto(&end);
+ }
+
+ __ Bind(&end);
+ __ Dispatch();
+}
+
+// StaModuleVariable <imm>
+//
+// Store accumulator to the module variable identified by its index <imm>.
+void Interpreter::DoStaModuleVariable(InterpreterAssembler* assembler) {
+ Node* value = __ GetAccumulator();
+ Node* raw_index = __ BytecodeOperandImm(0);
+
+ Node* module_context = __ LoadModuleContext(__ GetContext());
+ Node* module = __ LoadContextSlot(module_context, Context::EXTENSION_INDEX);
+
+ Label if_export(assembler), if_import(assembler), end(assembler);
+ __ Branch(__ IntPtrGreaterThan(raw_index, __ IntPtrConstant(0)), &if_export,
+ &if_import);
+
+ __ Bind(&if_export);
+ {
+ Node* regular_exports =
+ __ LoadObjectField(module, Module::kRegularExportsOffset);
+ Node* export_index = __ IntPtrSub(raw_index, __ IntPtrConstant(1));
+ Node* cell = __ LoadFixedArrayElement(regular_exports, export_index);
+ __ StoreObjectField(cell, Cell::kValueOffset, value);
+ __ Goto(&end);
+ }
+
+ __ Bind(&if_import);
+ {
+ // Not supported (probably never).
+ __ Abort(kUnsupportedModuleOperation);
+ __ Goto(&end);
+ }
+
+ __ Bind(&end);
+ __ Dispatch();
+}
+
// PushContext <context>
//
// Saves the current context in <context>, and pushes the accumulator as the

Powered by Google App Engine
This is Rietveld 408576698