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

Unified Diff: src/interpreter/bytecodes.cc

Issue 1257543003: [Interpreter] Add more bytecode definitions and add operand types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. Created 5 years, 5 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/interpreter/bytecodes.h ('k') | src/interpreter/interpreter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecodes.cc
diff --git a/src/interpreter/bytecodes.cc b/src/interpreter/bytecodes.cc
index 89fcaf60e8e2339eb716ea9db5a900e134b94752..0787b66c317d1fa818cce77fae09287ae3a59e62 100644
--- a/src/interpreter/bytecodes.cc
+++ b/src/interpreter/bytecodes.cc
@@ -8,12 +8,27 @@ namespace v8 {
namespace internal {
namespace interpreter {
+// Maximum number of operands a bytecode may have.
+static const int kMaxOperands = 3;
+
+// kBytecodeTable relies on kNone being the same as zero to detect length.
+STATIC_ASSERT(static_cast<int>(OperandType::kNone) == 0);
+
+static const OperandType kBytecodeTable[][kMaxOperands] = {
+#define DECLARE_OPERAND(_, ...) \
+ { __VA_ARGS__ } \
+ ,
+ BYTECODE_LIST(DECLARE_OPERAND)
+#undef DECLARE_OPERAND
+};
+
+
// static
const char* Bytecodes::ToString(Bytecode bytecode) {
switch (bytecode) {
-#define CASE(Name, _) \
- case Bytecode::k##Name: \
- return #Name;
+#define CASE(Name, ...) \
+ case Bytecode::k##Name: \
+ return #Name;
BYTECODE_LIST(CASE)
#undef CASE
}
@@ -23,29 +38,52 @@ const char* Bytecodes::ToString(Bytecode bytecode) {
// static
-const int Bytecodes::NumberOfArguments(Bytecode bytecode) {
- switch (bytecode) {
-#define CASE(Name, arg_count) \
- case Bytecode::k##Name: \
- return arg_count;
- BYTECODE_LIST(CASE)
-#undef CASE
+uint8_t Bytecodes::ToByte(Bytecode bytecode) {
+ return static_cast<uint8_t>(bytecode);
+}
+
+
+// static
+Bytecode Bytecodes::FromByte(uint8_t value) {
+ Bytecode bytecode = static_cast<Bytecode>(value);
+ DCHECK(bytecode <= Bytecode::kLast);
+ return bytecode;
+}
+
+
+// static
+const int Bytecodes::NumberOfOperands(Bytecode bytecode) {
+ DCHECK(bytecode <= Bytecode::kLast);
+ int count;
+ uint8_t row = ToByte(bytecode);
+ for (count = 0; count < kMaxOperands; count++) {
+ if (kBytecodeTable[row][count] == OperandType::kNone) {
+ break;
+ }
}
- UNREACHABLE();
- return 0;
+ return count;
+}
+
+
+// static
+const OperandType Bytecodes::GetOperandType(Bytecode bytecode, int i) {
+ DCHECK(bytecode <= Bytecode::kLast && i < NumberOfOperands(bytecode));
+ return kBytecodeTable[ToByte(bytecode)][i];
}
// static
const int Bytecodes::Size(Bytecode bytecode) {
- return NumberOfArguments(bytecode) + 1;
+ return 1 + NumberOfOperands(bytecode);
}
-#define CHECK_SIZE(Name, arg_count) \
- STATIC_ASSERT(arg_count <= Bytecodes::kMaximumNumberOfArguments);
- BYTECODE_LIST(CHECK_SIZE)
-#undef CHECK_SIZE
+// static
+const int Bytecodes::MaximumNumberOfOperands() { return kMaxOperands; }
+
+
+// static
+const int Bytecodes::MaximumSize() { return 1 + kMaxOperands; }
std::ostream& operator<<(std::ostream& os, const Bytecode& bytecode) {
« no previous file with comments | « src/interpreter/bytecodes.h ('k') | src/interpreter/interpreter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698