SYNOPSIS
pbc_merge -o all.pbc a.pbc, b.pbc [, ...]
ABSTRACT
Read all given pbc files and repack the bytecode into one result pbc.
DESCRIPTION
Since r8676 parrot can (again) create a string representation of evaled
code.
compiled = compiler(code)
print io, compiled
is all to create a packfile, suitable for later loading with
C<load_bytecode>.
But as some language compilers like forth create a lot of evaled code,
there should be a way to combine these packfiles into one.
The utility should roughly work like this:
- create all default segments
- for all pbcs
append each segment to the combined one and
- fold constants
- relocate subroutine offsets to the new offset
Folding constants is a bit tricky, as it needs also to walk trough the
code and replace changed constant table entries.
see also imcc/pbc.c, src/packfile.c, and
src/interpreter.c:prederef_args() or src/debug.c /disassemble for
reading opcodes and arguments.
leo
I'll be brave and have a crack at this one. :-)
Leo and I have had some discussions about moving some packfile related
code into PMCs, which sould neaten things up and, importantly, make
packfile manipulation accessible to Parrot programs. While I know I'll
need to re-work pbc_merge to use those later on, I think I'd like to try
pbc_merge first using the current code we have so I can get more
familiar with how things are now, before doing something significant
inside Parrot itself. Then, provided my supply of Parrot hackery time
goes on (it should) I can look at the moving stuff into PMCs task.
Jonathan
To build it, after an svn up and re-configuring, do:-
make pbc_merge # pbc_merge.exe on Win32
Or it is also built when you do:-
make parrot_utils
Feedback (bugs, issues with the code, feature requests) welcome.
> Folding constants is a bit tricky, as it needs also to walk trough the
> code and replace changed constant table entries.
>
This sounded harder than it actually turned out to be - the ops side of
Parrot is well put together.
Have fun,
Jonathan
$ cat in1.imc
.sub _main @MAIN
.local string ft
ft = _FortyTwo()
print "Got "
print ft
print "\n"
.end
$ cat in2.imc
.sub _FortyTwo
.return("42")
.end
$ parrot -o in1.pbc in1.imc
$ parrot -o in2.pbc in2.imc
$ pbc_merge -o out.pbc in1.pbc in2.pbc
$ parrot out.pbc
Got 42
$ pbc_merge -o out.pbc in2.pbc in1.pbc
$ parrot out.pbc
Got 42
Since my last post about pbc_merge, I've also checked in some tests plus
hunted down and fixed a problem that prevented the tool from working in the
leo-ctx5 branch. I think this ticket can now be closed (I don't have RT
privs to do stuff like this).
Thanks,
Jonathan