diff --git a/src/backends/regex.h b/src/backends/regex.h index a0bc5b85bd70a9f98a5110413b6ff5a8a24d9866..605ff77a6dae25ea5a3e9ac419e4f2f3caf7472f 100644 --- a/src/backends/regex.h +++ b/src/backends/regex.h @@ -27,7 +27,7 @@ typedef struct HRVMInsn_{ uint16_t arg; } HRVMInsn; -const HTokenType TT_MARK = TT_RESERVED_1; +#define TT_MARK TT_RESERVED_1 typedef struct HSVMContext_ { HParsedToken **stack; @@ -49,7 +49,21 @@ typedef struct HRVMProg_ { HSVMAction *actions; } HRVMProg; +// Returns true IFF the provided parser could be compiled. +bool h_compile_regex(HRVMProg *prog, const HParser* parser); +// These functions are used by the compile_to_rvm method of HParser +uint16_t h_rvm_create_action(HRVMProg *prog, HSVMAction *action); +// returns the address of the instruction just created +uint16_t h_rvm_insert_insn(HRVMProg *prog, HRVMOp op, uint16_t arg); + +// returns the address of the next insn to be created. +uint16_t h_rvm_get_ip(HRVMProg *prog); + +// Used to insert forward references; the idea is to generate a JUMP +// or FORK instruction with a target of 0, then update it once the +// correct target is known. +void h_rvm_patch_arg(HRVMProg *prog, uint16_t ip, uint16_t new_val); #endif diff --git a/src/parsers/parser_internal.h b/src/parsers/parser_internal.h index d8b36514ce76a0f3ce6f464c2bdfff5df8713cf4..938dd23c3c7119dbac63c251dd07bb273809ae9f 100644 --- a/src/parsers/parser_internal.h +++ b/src/parsers/parser_internal.h @@ -2,6 +2,7 @@ #define HAMMER_PARSE_INTERNAL__H #include "../hammer.h" #include "../internal.h" +#include "../backends/regex.h" #define a_new_(arena, typ, count) ((typ*)h_arena_malloc((arena), sizeof(typ)*(count))) #define a_new(typ, count) a_new_(state->arena, typ, count)