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

Unified Diff: src/interpreter/bytecodes.cc

Issue 1325983002: [Intepreter] Extend and move Register class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bug in test. Created 5 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/interpreter/bytecodes.cc
diff --git a/src/interpreter/bytecodes.cc b/src/interpreter/bytecodes.cc
index 5f334d1ff82ae844af75cfc528731fa89917e704..0ed7ae185016bf76a5aff4d22ef4cf5d513788c3 100644
--- a/src/interpreter/bytecodes.cc
+++ b/src/interpreter/bytecodes.cc
@@ -4,7 +4,7 @@
#include "src/interpreter/bytecodes.h"
-#include "src/interpreter/bytecode-array-builder.h"
+#include "src/frames.h"
namespace v8 {
namespace internal {
@@ -103,8 +103,51 @@ int Bytecodes::MaximumSize() { return 1 + kMaxOperands; }
// static
-std::ostream& Bytecodes::Decode(std::ostream& os,
- const uint8_t* bytecode_start) {
+uint8_t Bytecodes::RegisterIndexToOperand(int index) {
+ return static_cast<uint8_t>(-index);
+}
+
+
+// static
+int Bytecodes::RegisterIndexFromOperand(uint8_t operand) {
+ int8_t index = -static_cast<int8_t>(operand);
+ return index;
+}
+
+
+static const int kLastParamRegisterIndex =
+ -InterpreterFrameConstants::kLastParamFromRegisterPointer / kPointerSize;
+
+
+// static
+uint8_t Bytecodes::ParameterIndexToOperand(int index, int parameter_count) {
rmcilroy 2015/09/02 11:42:42 Could we make this a Register::FromParameterIndex(
oth 2015/09/02 14:02:20 Done.
+ // Parameters share the same space as registers
+ DCHECK_LE(parameter_count, MaximumNumberOfParameters());
+ DCHECK_GE(index, 0);
rmcilroy 2015/09/02 11:42:41 nit - DCHECK_LT(index, parameter_count)
oth 2015/09/02 14:02:20 Done.
+ int register_index = kLastParamRegisterIndex - parameter_count + index + 1;
+ DCHECK_LT(register_index, 0);
+ return RegisterIndexToOperand(register_index);
+}
+
+
+// static
+int Bytecodes::ParameterIndexFromOperand(uint8_t operand, int parameter_count) {
+ // Parameters share the same space as registers
+ DCHECK_LE(parameter_count, MaximumNumberOfParameters());
+ int register_index = RegisterIndexFromOperand(operand);
+ return register_index - kLastParamRegisterIndex + parameter_count - 1;
+}
+
+
+// static
+int Bytecodes::MaximumNumberOfParameters() {
+ return 128 + kLastParamRegisterIndex;
rmcilroy 2015/09/02 11:42:41 This is a bit confusing. Could you use kMinRegiste
oth 2015/09/02 14:02:20 Comment added.
+}
+
+
+// static
+std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
+ int parameter_count) {
Vector<char> buf = Vector<char>::New(50);
Bytecode bytecode = Bytecodes::FromByte(bytecode_start[0]);
@@ -132,9 +175,21 @@ std::ostream& Bytecodes::Decode(std::ostream& os,
case interpreter::OperandType::kImm8:
os << "#" << static_cast<int>(operand);
break;
- case interpreter::OperandType::kReg:
- os << "r" << Register::FromOperand(operand).index();
+ case interpreter::OperandType::kReg: {
+ int register_index = RegisterIndexFromOperand(operand);
+ if (register_index >= 0) {
+ os << "r" << register_index;
+ } else {
+ int parameter_index =
+ ParameterIndexFromOperand(operand, parameter_count);
+ if (parameter_index == 0) {
+ os << "this";
rmcilroy 2015/09/02 11:42:42 nit - could we make it "<this>" or "|this|" or som
oth 2015/09/02 14:02:20 Done <this>. Prefer current consistency of r0, r1
+ } else {
+ os << "a" << parameter_index - 1;
+ }
+ }
break;
+ }
case interpreter::OperandType::kNone:
UNREACHABLE();
break;

Powered by Google App Engine
This is Rietveld 408576698