In modding a closed-source game I'm modifying the machine code at runtime to jmp into my own code. To do this in a generic manner I'm using pattern matching to find the code locations I want to modify. (The patterns consist only of characters/bytes and wildcards where bytes can vary.) By building a deterministic finite automaton from all my patterns I can search in linear time.
However I've found that building the DFA takes more time than actually running it, especially in debug builds (which I certainly want during development), and that's only going to get worse as I add more patterns. But that could easily be done offline. I'm currently thinking about the how; can the compiler do it?
As far as I know it's impossible with constexpr
functions since I can't allocate static memory with them. But I have a vague feeling that it should be doable in a type-safe manner with template meta-programming. Or am I likely to run into recursion limits when creating automatons with hundreds or thousands of states?
And regardless of technical possibility, is it reasonable? Or should I rather, say, calculate a source file in a separate build step?