NAME ^

Parrot::OpsFile - Ops To C Code Generation

SYNOPSIS ^

  use Parrot::OpsFile;

DESCRIPTION ^

Parrot::OpsFile takes one or more files of op functions and creates real C code for them.

This class is used by build_tools/ops2c.pl, build_tools/ops2pm.pl and build_tools/pbc2c.pl.

Op Functions ^

For ops that have trivial bodies (such as just a call to some other function and a return statement), opcode functions are in the format:

    inline op opname (args) :class,flags {
        ... body of function ...
    }

Note that currently the inline op type is ignored.

Alternately, for opcode functions that have more internal complexity the format is:

    op opname (args) :class,flags {
        ... body of function ...
    }

There may be more than one return.

In both cases the closing brace must be on its own line.

Op Arguments ^

Op arguments are a comma-separated list of direction and type pairs.

Argument direction is one of:

    in            the argument passes a value into the op
    out           the argument passes a value out of the op
    inout         the argument passes a value into and out of the op
    inconst       the argument passes a constant value into the op
    invar         the argument passes a variable value into the op
    label         an in argument containing a branch offset or address
    labelconst    an invar argument containing a branch offset or address
    labelvar      an inconst argument containing a branch offset or address

Argument direction is used to determine the life times of symbols and their related register allocations. When an argument is passed into an op a register is read from, when it's passed out of an op a register is written to.

Argument type is one of:

    INT       the argument is an integer
    NUM       the argument is an numeric
    STR       the argument is an string
    PMC       the argument is an PMC
    KEY       the argument is an aggregate PMC key
    INTKEY    the argument is an aggregate PMC integer key

The size of the return offset is determined from the op function's signature.

Op Classification and Flags ^

The op classification and flags are optional hints which provide information about the op.

The classification of ops is intended to facilitate the selection of suitable ops for a Parrot safe mode, or for inclusion in miniparrot.

Op Body (Macro Substitutions) ^

In the following macro descriptions, PC and PC' are the current and next position within the Parrot code.

goto OFFSET(X)

Transforms to PC' = PC + X. This is used for branches.

goto NEXT()

Transforms to PC' = PC + S, where S is the size of an op.

goto ADDRESS(X)

Transforms to PC' = X. This is used for absolute jumps.

goto POP()

Transforms to PC' = <pop>. Pops the address off control stack.

expr OFFSET(X)

Transforms to PC + X. This is used to give a relative address.

expr NEXT()

Transforms to PC + S, the position of the next op.

expr ADDRESS(X)

Transforms to X, an absolute address.

OP_SIZE

Transforms to S, the size of an op.

HALT()

Transforms to PC' = 0. Halts run loop, and resets the current position to the start of the Parrot code, without resuming.

restart OFFSET(X)

Transforms to PC' = 0 and restarts at PC + X.

restart NEXT()

Transforms to PC' = 0 and restarts at PC + S.

$n

Transforms to the op function's nth argument. $0 is the opcode itself.

Note that, for ease of parsing, if the argument to one of the above notations in a ops file contains parentheses, then double the enclosing parentheses and add a space around the argument, like so:

    goto OFFSET(( (void*)interpreter->happy_place ))

Class Methods ^

new(@files)

Returns a new instance initialized by calling read_ops() on each of the specified op files.

Instance Methods ^

read_ops($file)

Reads in the specified .ops file, gathering information about the ops.

make_op($code, $type, $short_name, $body, $args, $argdirs, $line, $file, $labels, $flags)

Returns a new Parrot::Op instance for the specified arguments.

expand_args(@args)

Given an argument list, returns a list of all the possible argument combinations.

ops()

Returns the Parrot::Op instances found in the file(s).

op($index)

Returns the op at $index.

preamble()

preamble($trans)

Returns any lines found prior to first op definition.

If $trans (an Parrot::OpTrans subclass) is supplied then substitutions are made.

version($major, $minor, $patch)

version($version)

version()

Sets/gets the version number.

major_version()

Returns the major version number.

minor_version()

Returns the minor version number.

patch_version()

Returns the patch version number.

push_op($op)

Adds $op to the end of the op list.

SEE ALSO ^

Parrot::Op

Parrot::OpTrans

build_tools/ops2c.pl

build_tools/ops2pm.pl

build_tools/pbc2c.pl


parrot