parrotcode: Ops To C Code Generation | |
Contents | Perl Modules |
Parrot::OpsFile - Ops To C Code Generation
use Parrot::OpsFile;
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.
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 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.
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.
In the following macro descriptions, PC
and PC'
are the current and next position within the Parrot code.
goto OFFSET(X)
PC' = PC + X
. This is used for branches.goto NEXT()
PC' = PC + S
, where S
is the size of an op.goto ADDRESS(X)
PC' = X
. This is used for absolute jumps.goto POP()
PC' = <pop>
. Pops the address off control stack.expr OFFSET(X)
PC + X
. This is used to give a relative address.expr NEXT()
PC + S
, the position of the next op.expr ADDRESS(X)
X
, an absolute address.OP_SIZE
S
, the size of an op.HALT()
PC' = 0
. Halts run loop, and resets the current position to the start of the Parrot code, without resuming.restart OFFSET(X)
PC' = 0
and restarts at PC + X
.restart NEXT()
PC' = 0
and restarts at PC + S
.$n
$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 ))
new(@files)
read_ops()
on each of the specified op files.read_ops($file,$nolines)
make_op($code, $type, $short_name, $body, $args, $argdirs, $line, $file, $labels, $flags, $nolines)
Parrot::Op
instance for the specified arguments.expand_args(@args)
ops()
Parrot::Op
instances found in the file(s).op($index)
$index
.preamble()
preamble($trans)
$trans
(an Parrot::OpTrans
subclass) is supplied then substitutions are made.version($major, $minor, $patch)
version($version)
version()
major_version()
minor_version()
patch_version()
push_op($op)
$op
to the end of the op list.
|