| 123456789101112131415161718192021222324252627282930313233343536 |
- //
- // Created by 李晓明 on 2023/8/16.
- //
- #include "debug.h"
- #include <stdio.h>
- /**
- * @brief 打印指令
- * @param name 名称
- * @param offset 偏移
- * @return
- */
- static int simpleInstruction(const char *name, int offset) {
- printf("%s\n", name);
- return offset + 1;
- }
- void disassembleChunk(Chunk *chunk, const char *name) {
- printf("== %s ==\n", name);
- for (int offset = 0; offset < chunk->count;) {
- offset = disassembleInstruction(chunk, offset);
- }
- }
- int disassembleInstruction(Chunk *chunk, int offset) {
- printf("%04d ", offset);
- uint8_t instruction = chunk->code[offset];
- switch (instruction) {
- case OP_RETURN:return simpleInstruction("OP_RETURN", offset);
- default:printf("Unknown opcode %d\n", instruction);
- return offset + 1;
- }
- }
|