NAME

Parrot::PackFile

SYNOPSIS

use Parrot::PackFile;

DESCRIPTION

This package contains all the functions required to process a Parrot bytecode file. It is not intended to understand the contents of the bytecode file's segments, but merely to dissect and reconstruct data from the various segments. See parrotbyte for information about the structure of the frozen bycode.

byte_code =head2 byte_code CODE

Get or set the byte code.

const_table

Get the constant table, and instance of the Parrot::PackFile::ConstTable class.

fixup_table

Get the fixup table, and instance of the Parrot::PackFile::FixupTable class.

magic

Get the magic number.

new

Make a new instance.

pack

Pack the contents to a string.

pack_file FILENAME

Pack the contents to a string and write it to the named file.

pack_filehandle FILEHANDLE

Pack the contents to a string and write it to the filehandle.

unpack STRING

Unpack the contents from the string.

unpack_file FILENAME

Unpack the contents from the named file.

unpack_filehandle FILEHANDLE

Unpack the contents from the filehandle.

FORMAT

0
+----------+----------+----------+----------+
|         Parrot Magic = 0x 13155a1         |
+----------+----------+----------+----------+

For each segment:

4, 4 + (4 + S0), 4 + (4 + S0) + (4 + S1)
+----------+----------+----------+----------+
|       Segment length in bytes (S)         |
+----------+----------+----------+----------+
|                                           |
:        S bytes of segment content         :
|                                           |
+----------+----------+----------+----------+

Currently there are three segment types defined, and they must occur in precisely the order: FIXUP, CONSTANT TABLE, BYTE CODE. Every segment must be present, even if empty.

FIXUP SEGMENT

<< The format for the FIXUP segment is not yet defined. >>

CONSTANT TABLE SEGMENT

0 (relative)
+----------+----------+----------+----------+
|            Constant Count (N)             |
+----------+----------+----------+----------+

For each constant:

+----------+----------+----------+----------+
|             Constant Type (T)             |
+----------+----------+----------+----------+
|             Constant Size (S)             |
+----------+----------+----------+----------+
|                                           |
|        S bytes of constant content        |
:       appropriate for representing        :
|              a value of type T            |
|                                           |
+----------+----------+----------+----------+

CONSTANTS

For integer constants:

<< integer constants are represented as manifest constants in
   the byte code stream currently, limiting them to 32 bit values. >>

For number constants (S is constant, and is equal to sizeof(FLOATVAL)):

+----------+----------+----------+----------+
|                                           |
|             S' bytes of Data              |
|                                           |
+----------+----------+----------+----------+

where

S' = S + (S % 4) ? (4 - (S % 4)) : 0

If S' > S, then the extra bytes are filled with zeros.

For string constants (S varies, and is the size of the particular string):

4, 4 + (16 + S'0), 4 + (16 + S'0) + (16 + S'1)
+----------+----------+----------+----------+
|                   Flags                   |
+----------+----------+----------+----------+
|                  Encoding                 |
+----------+----------+----------+----------+
|                   Type                    |
+----------+----------+----------+----------+
|                  Size (S)                 |
+----------+----------+----------+----------+
|                                           |
:             S' bytes of Data              :
|                                           |
+----------+----------+----------+----------+

where

S' = S + (S % 4) ? (4 - (S % 4)) : 0

If S' > S, then the extra bytes are filled with zeros.

BYTE CODE SEGMENT

The pieces that can be found in the byte code segment are as follows:

+----------+----------+----------+----------+
|              Operation Code               |
+----------+----------+----------+----------+

+----------+----------+----------+----------+
|             Register Argument             |
+----------+----------+----------+----------+

+----------+----------+----------+----------+
|    Integer Argument (Manifest Constant)   |
+----------+----------+----------+----------+

+----------+----------+----------+----------+
|   String Argument (Constant Table Index)  |
+----------+----------+----------+----------+

+----------+----------+----------+----------+
|   Number Argument (Constant Table Index)  |
+----------+----------+----------+----------+

The number and types for each argument can be determined by consulting Parrot::Opcode.

SOURCE CODE SEGMENT

Currently there are no utilities that use this segment, even though it is mentioned in some of the early Parrot documents.

Eventually there will be a more complete and useful PackFile specification, but this simple format works well enough for now (c. Parrot 0.0.2).

AUTHOR

Gregor N. Purdy <gregor@focusresearch.com>

COPYRIGHT

Copyright (C) 2001 Gregor N. Purdy. All rights reserved.

LICENSE

This program is free software. It is subject to the same license as Perl itself.