]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
rose: move END instruction to start of enum
authorJustin Viiret <justin.viiret@intel.com>
Tue, 13 Sep 2016 00:55:26 +0000 (10:55 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Fri, 28 Oct 2016 03:47:07 +0000 (14:47 +1100)
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
src/rose/rose_dump.cpp
src/rose/rose_program.h

index 735f8cdb7fd080a7991a04b4b53885be39530290..198b8e1371d3b8b2f42ed1421a53e34bf5ed6a73 100644 (file)
@@ -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
         }
     }
 
index f0bec701fee908a3be91f537324458a0fcf3ecef..4a0d297e60f3daf4b1e5ae58109fe40385c37f2a 100644 (file)
@@ -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 << "  <stopping>" << endl;
index 370fc826c70cacd69713597160943dadf1ec5d26..4714960ca8fb4dd9bb86ebf61e119dc0aeec010d 100644 (file)
@@ -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