[erlang-questions] Re: how hard is it to rewrite code in a .beam file?
Matthias Lang
matthias@REDACTED
Sat Aug 28 09:58:16 CEST 2010
Kostis wrote:
> The {f,L} args denote labels -- possibly where to go upon failure.
> The {u,N} args denote unsigned integers N.
Ah, ok. I had a working transform yesterday, and that gets me closer
to understanding why it works:
case beam_opcodes:opname(Opcode) of
{m_plus, Arity = 4} ->
io:fwrite("rewriting mplus instruction\n"),
{[Function, S1, S2, Dest], Leftover} = decode_n_args(Arity, [], Rest),
New_opcode = beam_opcodes:opcode(gc_bif2, 6),
Live = {{u,1}, 16},
Bif = {{u,0}, 0},
New_args = [Function, Live, Bif, S1, S2, Dest],
New_bytes = lists:flatten([New_opcode|args_to_ops(New_args)]),
io:fwrite("rewritten mplus assembles to ~p\n", [New_bytes]),
[{New_bytes, gc_bif2, args_to_syms(New_args)}|disasm(Leftover)];
There's another avenue I should take a look at: R11 (and, probably, R12) can
load those R10 files, I should check what those releases do with the m_plus
instructions.
Thanks for the tips.
Matt
More information about the erlang-questions
mailing list