diff options
author | Yuyang Huang <yuyanghuang@google.com> | 2023-10-16 17:45:35 +0900 |
---|---|---|
committer | Yuyang Huang <yuyanghuang@google.com> | 2023-10-17 14:41:55 +0900 |
commit | 9aece5c618714b8ca02531ba8144f1b057254102 (patch) | |
tree | c8a39bb0dc6043db6c0b4d564c8f8df9ad7ebae1 | |
parent | a57fefba56ff96ae0295b2285c9e553b02818ef9 (diff) | |
download | apf-9aece5c618714b8ca02531ba8144f1b057254102.tar.gz |
Add support for ALLOC and TRANS opcodes to apf_disassemble()
Support ALLOC and TRANS opcodes in apf_disassemble() and export it in
libapfdisassembler for JNI use.
Bug: 293811969
Test: TH
Change-Id: Ie077ab9f4eefbfac15e0da1ccb101fc39df33ec5
-rw-r--r-- | Android.bp | 9 | ||||
-rw-r--r-- | disassembler.c | 24 | ||||
-rw-r--r-- | disassembler.h | 20 |
3 files changed, 52 insertions, 1 deletions
@@ -40,6 +40,15 @@ cc_library_static { sdk_version: "24", } +cc_library_static { + name: "libapfdisassembler", + defaults: ["apf_defaults"], + srcs: [ + "disassembler.c", + ], + sdk_version: "24", +} + cc_binary_host { name: "apf_disassembler", defaults: ["apf_defaults"], diff --git a/disassembler.c b/disassembler.c index 830e621..091ff9e 100644 --- a/disassembler.c +++ b/disassembler.c @@ -17,7 +17,7 @@ #include <stdint.h> #include <stdio.h> -#include "apf.h" +#include "v5/apf.h" // If "c" is of a signed type, generate a compile warning that gets promoted to an error. // This makes bounds checking simpler because ">= 0" can be avoided. Otherwise adding @@ -344,6 +344,28 @@ uint32_t apf_disassemble(const uint8_t* program, uint32_t program_len, ASSERT_RET_INBOUND(ret); offset += ret; break; + case ALLOC_EXT_OPCODE: + ret = print_opcode("alloc", output_buffer, + output_buffer_len, offset); + ASSERT_RET_INBOUND(ret); + offset += ret; + ret = + snprintf(output_buffer + offset, + output_buffer_len - offset, "r%d", reg_num); + ASSERT_RET_INBOUND(ret); + offset += ret; + break; + case TRANS_EXT_OPCODE: + ret = print_opcode("trans", output_buffer, + output_buffer_len, offset); + ASSERT_RET_INBOUND(ret); + offset += ret; + ret = + snprintf(output_buffer + offset, + output_buffer_len - offset, "r%d", reg_num); + ASSERT_RET_INBOUND(ret); + offset += ret; + break; default: ret = snprintf(output_buffer + offset, output_buffer_len - offset, "unknown_ext %u", diff --git a/disassembler.h b/disassembler.h index f4c36f6..cf10166 100644 --- a/disassembler.h +++ b/disassembler.h @@ -18,6 +18,26 @@ #include <stdint.h> +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Disassembles a APF program into a human-readable format. + * + * @param program the program bytecode. + * @param program_len the length of the program bytecode. + * @param pc The program counter which point to the current instruction. + * @param output_buffer A pointer to a buffer where the disassembled + * instruction will be stored. + * @param output_buffer_len the length of the output buffer. + * + * @return the program counter which point to the next instruction. + */ uint32_t apf_disassemble(const uint8_t* program, uint32_t program_len, uint32_t pc, char* output_buffer, int output_buffer_len); + +#ifdef __cplusplus +} +#endif |