Skip to content

Commit 2d4d448

Browse files
committed
[feature] basic interpreting
1 parent 97a0776 commit 2d4d448

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/execute_engine/cvm_execute.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ void CVM::execute(const Classfile& cf, const std::string& methodName) {
3838

3939
const uint8_t* bytecode = getByteCode(cf, methodInfo);
4040
validateByteCode(bytecode);
41+
42+
spdlog::info("Size of bytecode: {}", sizeof(bytecode));
43+
44+
interprete(bytecode, cf);
4145
}
4246

4347
std::string CVM::getUtf8FromConstantPool(const Classfile& cf, uint16_t index) {
@@ -71,3 +75,18 @@ const uint8_t* CVM::getByteCode(const Classfile& cf,
7175
}
7276
return nullptr;
7377
}
78+
79+
void CVM::interprete(const uint8_t* byteCode, const Classfile& cf) {
80+
size_t pc = 0;
81+
std::stack<int> operandStack;
82+
size_t codeLength = sizeof(byteCode);
83+
84+
while (pc < 100) {
85+
uint8_t opcode = byteCode[pc++];
86+
switch (opcode) {
87+
default:
88+
spdlog::error("Unknown Opcode: {:#04x} at PC: {}", opcode, pc);
89+
break;
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)