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 tools/build/ops2c.pl, tools/build/ops2pm.pl and tools/build/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) :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) :flags { ... body of function ... }
There may be more than one return
.
In both cases the closing brace must be on its own line.
When specifying multiple flags, each flag gets its own prefixing colon.
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
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 LABEL the argument is an integer branch offset or address
The size of the return offset is determined from the op function's signature.
Op Flags
The flags are of two types:
- 1 class The classification of ops is intended to facilitate the selection of suitable ops for a Parrot safe mode.
- 2 behavior The presence (or absence) of certain flags will change how the op behaviors. For example, the lack of the
flow
flag will cause the op to be implicitly terminated with goto NEXT()
. (See next section).The :deprecated flag will generate a diagnostic to standard error at runtime when a deprecated opcode is invoked and PARROT_WARNINGS_DEPRECATED_FLAG
has been set.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 goto NEXT()
Transforms to goto ADDRESS(X)
Transforms to goto POP()
Transforms to expr OFFSET(X)
Transforms to expr NEXT()
Transforms to expr ADDRESS(X)
Transforms to OP_SIZE
Transforms to HALT()
Transforms to restart OFFSET(X)
Transforms to restart NEXT()
Transforms to $n
Transforms to the op function's nth argument.
PC' = PC + X
. This is used for branches.
PC' = PC + S
, where S
is the size of an op.
PC' = X
. This is used for absolute jumps.
PC' = <pop>
. Pops the address off control stack.
PC + X
. This is used to give a relative address.
PC + S
, the position of the next op.
X
, an absolute address.
S
, the size of an op.
PC' = 0
. Halts run loop, and resets the current position to the start of the Parrot code, without resuming.
PC' = 0
and restarts at PC + X
.
PC' = 0
and restarts at PC + S
.
$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*)interp->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,$nolines)
Reads in the specified .ops file, gathering information about the ops.
make_op($code, $type, $short_name, $body, $args, $argdirs, $line, $file, $labels, $flags, $nolines)
Returns a new expand_args(@args)
Given an argument list, returns a list of all the possible argument combinations.
ops()
Returns the op($index)
Returns the op at preamble()
preamble($trans)
Returns any lines found prior to first op definition.If 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
Parrot::Op
instance for the specified arguments.
Parrot::Op
instances found in the file(s).
$index
.
$trans
(an Parrot::OpTrans
subclass) is supplied then substitutions are made.
$op
to the end of the op list.