From 6e533589bb7390380ca05943f9fc641be913645d Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Tue, 13 Sep 2016 10:55:26 +1000 Subject: [PATCH] rose: move END instruction to start of enum Stop overloading END as the last Rose interpreter instruction, use new sentinel LAST_ROSE_INSTRUCTION for that. This change will also make it easier to add new instructions without renumbering END and thus changing all generated bytecodes. --- src/rose/program_runtime.h | 14 +++++++------- src/rose/rose_dump.cpp | 8 ++++---- src/rose/rose_program.h | 11 ++++++----- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/rose/program_runtime.h b/src/rose/program_runtime.h index 735f8cdb..198b8e13 100644 --- a/src/rose/program_runtime.h +++ b/src/rose/program_runtime.h @@ -1389,9 +1389,15 @@ hwlmcb_rv_t roseRunProgram_i(const struct RoseEngine *t, assert(pc >= pc_base); assert((size_t)(pc - pc_base) < t->size); const u8 code = *(const u8 *)pc; - assert(code <= ROSE_INSTR_END); + assert(code <= LAST_ROSE_INSTRUCTION); switch ((enum RoseInstructionCode)code) { + PROGRAM_CASE(END) { + DEBUG_PRINTF("finished\n"); + return HWLM_CONTINUE_MATCHING; + } + PROGRAM_NEXT_INSTRUCTION + PROGRAM_CASE(ANCHORED_DELAY) { if (in_anchored && end > t->floatingMinLiteralMatchOffset) { DEBUG_PRINTF("delay until playback\n"); @@ -1971,12 +1977,6 @@ hwlmcb_rv_t roseRunProgram_i(const struct RoseEngine *t, } } PROGRAM_NEXT_INSTRUCTION - - PROGRAM_CASE(END) { - DEBUG_PRINTF("finished\n"); - return HWLM_CONTINUE_MATCHING; - } - PROGRAM_NEXT_INSTRUCTION } } diff --git a/src/rose/rose_dump.cpp b/src/rose/rose_dump.cpp index f0bec701..4a0d297e 100644 --- a/src/rose/rose_dump.cpp +++ b/src/rose/rose_dump.cpp @@ -234,9 +234,12 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { const char *pc_base = pc; for (;;) { u8 code = *(const u8 *)pc; - assert(code <= ROSE_INSTR_END); + assert(code <= LAST_ROSE_INSTRUCTION); const size_t offset = pc - pc_base; switch (code) { + PROGRAM_CASE(END) { return; } + PROGRAM_NEXT_INSTRUCTION + PROGRAM_CASE(ANCHORED_DELAY) { os << " groups 0x" << std::hex << ri->groups << std::dec << endl; @@ -607,9 +610,6 @@ void dumpProgram(ofstream &os, const RoseEngine *t, const char *pc) { PROGRAM_CASE(MATCHER_EOD) {} PROGRAM_NEXT_INSTRUCTION - PROGRAM_CASE(END) { return; } - PROGRAM_NEXT_INSTRUCTION - default: os << " UNKNOWN (code " << int{code} << ")" << endl; os << " " << endl; diff --git a/src/rose/rose_program.h b/src/rose/rose_program.h index 370fc826..4714960c 100644 --- a/src/rose/rose_program.h +++ b/src/rose/rose_program.h @@ -42,6 +42,7 @@ /** \brief Role program instruction opcodes. */ enum RoseInstructionCode { + ROSE_INSTR_END, //!< End of program. ROSE_INSTR_ANCHORED_DELAY, //!< Delay until after anchored matcher. ROSE_INSTR_CHECK_LIT_EARLY, //!< Skip matches before floating min offset. ROSE_INSTR_CHECK_GROUPS, //!< Check that literal groups are on. @@ -116,7 +117,11 @@ enum RoseInstructionCode { /** \brief Run the EOD-anchored HWLM literal matcher. */ ROSE_INSTR_MATCHER_EOD, - ROSE_INSTR_END //!< End of program. + LAST_ROSE_INSTRUCTION = ROSE_INSTR_MATCHER_EOD //!< Sentinel. +}; + +struct ROSE_STRUCT_END { + u8 code; //!< From enum RoseInstructionCode. }; struct ROSE_STRUCT_ANCHORED_DELAY { @@ -460,8 +465,4 @@ struct ROSE_STRUCT_MATCHER_EOD { u8 code; //!< From enum RoseInstructionCode. }; -struct ROSE_STRUCT_END { - u8 code; //!< From enum RoseInstructionCode. -}; - #endif // ROSE_ROSE_PROGRAM_H