diff options
author | Yuyang Huang <yuyanghuang@google.com> | 2023-10-13 08:02:42 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-10-13 08:02:42 +0000 |
commit | 65b02cde06d6456f77bcf806617800e31aa5ccd9 (patch) | |
tree | e5d5893146a87b32f768cf6dfe6f6d750c96b77f | |
parent | 3432300e07bd54b0c53b0d4655d79494cf0ebed6 (diff) | |
parent | 178ebe0278d3b20e8993a17e3e7962c553a62ed3 (diff) | |
download | apf-65b02cde06d6456f77bcf806617800e31aa5ccd9.tar.gz |
Merge "Support ALLOC opcode" into main
-rw-r--r-- | v5/apf.h | 1 | ||||
-rw-r--r-- | v5/apf_interpreter.c | 11 |
2 files changed, 12 insertions, 0 deletions
@@ -165,6 +165,7 @@ #define NEG_EXT_OPCODE 33 // Negate, e.g. "neg R0" #define SWAP_EXT_OPCODE 34 // Swap, e.g. "swap R0,R1" #define MOV_EXT_OPCODE 35 // Move, e.g. "move R0,R1" +#define ALLOC_EXT_OPCODE 36 // Allocate buffer, "e.g. ALLOC R0" #define EXTRACT_OPCODE(i) (((i) >> 3) & 31) #define EXTRACT_REGISTER(i) ((i) & 1) diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c index f2662ed..cfb69e2 100644 --- a/v5/apf_interpreter.c +++ b/v5/apf_interpreter.c @@ -16,6 +16,7 @@ #include "apf_interpreter.h" +// TODO: Remove the dependency of the standard library and make the interpreter self-contained. #include <string.h> // For memcmp #include "apf.h" @@ -86,6 +87,11 @@ int apf_run(uint8_t* program, uint32_t program_len, uint32_t ram_len, // upper bound on the number of instructions in the program. uint32_t instructions_remaining = program_len; + // The output buffer pointer + uint8_t* allocated_buffer = NULL; + // The length of the output buffer + uint32_t allocate_buffer_len = 0; + do { APF_TRACE_HOOK(pc, registers, program, program_len, packet, packet_len, memory, ram_len); if (pc == program_len) { @@ -273,6 +279,11 @@ int apf_run(uint8_t* program, uint32_t program_len, uint32_t ram_len, case MOV_EXT_OPCODE: REG = OTHER_REG; break; + case ALLOC_EXT_OPCODE: + allocate_buffer_len = REG; + allocated_buffer = apf_allocate_buffer(allocate_buffer_len); + ASSERT_RETURN(allocated_buffer != NULL); + break; // Unknown extended opcode default: // Bail out |