x86jit: Use templates to avoid some void * casts.

Makes it a bit cleaner and potentially safer.
Avoid an infinite loop on bad stack walk.

If the address is wrong, it'll re-trigger debug mode, which will re-walk
the stack, which will continue ad infinitum.
Merge pull request #5128 from unknownbrackets/jit-minor

Cut down on void * casts within jit