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

Unified Diff: src/interpreter/interpreter.cc

Issue 2471033004: [ignition,modules] Introduce bytecodes for loading/storing module variables. (Closed)
Patch Set: More comments. 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..bfac7610b655c7e37f85ed26695ae62b0ef723b9 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) {
+ 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));
rmcilroy 2016/11/03 13:58:06 nit - would IntPtrSub(0, raw_index) be more effici
neis 2016/11/04 10:37:23 Good question. Benedikt, can you comment on this?
Benedikt Meurer (Google) 2016/11/04 13:12:55 I agree with Ross.
+ 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 (possibly never).
+ __ DebugBreak();
rmcilroy 2016/11/03 13:58:06 Could we do a real abort here with a bailoutid des
neis 2016/11/04 10:37:23 Done.
+ __ 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