[perl #36639] [TODO] pbc_merge utility

0 views
Skip to first unread message

Leopold Toetsch

unread,
Jul 23, 2005, 10:06:58 AM7/23/05
to bugs-bi...@rt.perl.org
# New Ticket Created by Leopold Toetsch
# Please include the string: [perl #36639]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=36639 >


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

Jonathan Worthington via RT

unread,
Sep 7, 2005, 6:54:10 PM9/7/05
to perl6-i...@perl.org
Hi,

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

Jonathan Worthington

unread,
Sep 18, 2005, 1:10:52 PM9/18/05
to perl6-i...@perl.org, bugs-bi...@rt.perl.org
"Leopold Toetsch (via RT)" <parrotbug...@parrotcode.org> wrote:
>
> 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
>
Done, checked in as revision r9207. Example of it at work is at the end of
the email, which tests both sub offset relocation and constant table pointer
corrections.

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

Jonathan Worthington

unread,
Sep 21, 2005, 6:52:01 AM9/21/05
to perl6-i...@perl.org, bugs-bi...@rt.perl.org
Hi,

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

Matt Diephouse via RT

unread,
Sep 21, 2005, 1:55:03 PM9/21/05
to perl6-i...@perl.org
I've just closed the ticket. Thanks.
Reply all
Reply to author
Forward
0 new messages