# Copyright (C) 2002-2007, The Perl Foundation. # $Id: OpTrans.pm 18563 2007-05-16 00:53:55Z chromatic $ =head1 NAME Parrot::OpTrans - Transform Ops to C Code =head1 DESCRIPTION C is the abstract superclass for the Parrot op to C transforms. Each transform contains various bits of information needed to generate the C code, and creates a different type of run loop. The methods defined here supply various default values and behaviour common to all transforms. The subclass hierarchy is as follows: OpTrans |_________________________ | | | C CGoto Compiled | | CPrederef | | | | | |_________| | | CSwitch CGP =head2 Class Methods =over 4 =cut package Parrot::OpTrans; use strict; use warnings; =item C Returns a new instance. =cut sub new { return bless {}, shift; } =back =head2 Instance Methods =over 4 =item C Returns the default 'C' prefix. Used by C's C to individuate op function names. =cut sub prefix { return 'Parrot_'; } =item C Implemented in subclasses to return a suffix with which to individuate variable names. This default implementation returns an empty string. =cut sub suffix { return ''; } =item C Implemented in subclasses to return the C C<#define> macros required. =item C Returns the type for the array of opcodes. By default here it's an array C, but the prederef runops core uses an array of C to do its clever tricks. =cut sub opsarraytype { return 'opcode_t'; } =item C Implemented in subclasses to return the type of core created by the transform. This default implementation raises an exception indicating that the core type is missing. See the C C in F for a list of the core types. =cut sub core_type { my $self = shift; die ref($self) . " doesn't have core_type()"; } =item C Implemented in subclasses to return a short prefix indicating the core type used to individuate core function names. =item C Optionally implemented in subclasses to return the C code for the run core function declaration. C<$base> is the name of the main ops file minus the .ops extension. =item C Optionally implemented in subclasses to return the C code for the ops address declaration. C<$base_suffix> is the name of the main ops file minus the .ops extension with C and an underscore appended. =item C Optionally implemented in subclasses to return the C code for the run core function declaration. C<$base> is the same as for C. =item C Implemented in subclasses, if C is implemented, to return the C code prior to the run core function. =item C Optionally implemented in subclasses to return the run core C code for section after the address table. C<$base_suffix> is the same as for C. =item C Implemented in subclasses to return the C code following the run core function. C<$base> is the same as for C. =item C Optionally implemented in subclasses to return the C code for the core's init function. C<$base> is the same as for C. =item C Optionally implemented in subclasses to return the C code for initializing the dispatch mechanism within the core's init function. C<$base_suffix> is the same as for C. =back B The following methods are called by C to perform ops file macro substitutions. =over =item C Implemented in subclasses to return the C code for the specified op argument type and value. C<$op> is an instance of C. =item C The various C> methods below call this method with the return value of an C> method (implemented in subclass). =cut sub gen_goto { my ( $self, $where_str ) = @_; return "return $where_str"; } =item C Implemented in subclasses to return the C code for C. =item C Implemented in subclasses to return the C code for C. =item C Transforms the C macro in an ops file into the relevant C code. =cut sub goto_address { my $self = shift; return $self->gen_goto( $self->expr_address(@_) ); } =item C Transforms the C macro in an ops file into the relevant C code. =cut sub goto_offset { my $self = shift; return $self->gen_goto( $self->expr_offset(@_) ); } =item C Transforms the C macro in an ops file into the relevant C code. =cut sub goto_pop { my ($self) = @_; return $self->gen_goto( $self->expr_pop(@_) ); } =item C Implemented in subclasses to return the C code for C. Called by C. =item C Implemented in subclasses to return the C code for C. Called by C. =back =head1 SEE ALSO =over 4 =item C =item C =item C =item C =item C =item C =back =cut 1; # Local Variables: # mode: cperl # cperl-indent-level: 4 # fill-column: 100 # End: # vim: expandtab shiftwidth=4: