# New Ticket Created by Steve Peters
# Please include the string: [perl #43089]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=43089 >
Function prototypes in C work much better when they are living in a header
file rather than in .c files. The attached patch below moves the prototypes
generated in the src/ops/*.c files to the header files created from the
*.ops files.
This change does cause a single new warning to appear, but I'm working
on completing that fix now (that fix will probably mean that g++ will be
compiling Parrot).
Steve Peters
[EMAIL PROTECTED]
Index: lib/Parrot/Ops2c/Utils.pm
===================================================================
--- lib/Parrot/Ops2c/Utils.pm (revision 18699)
+++ lib/Parrot/Ops2c/Utils.pm (working copy)
@@ -201,7 +201,9 @@
$argsref->{defines} = $argsref->{trans}->defines();
$argsref->{flag} = $flagref;
- return bless $argsref, $class;
+ my $self = bless $argsref, $class;
+ $self->_iterate_over_ops();
+ return $self;
}
sub _prepare_core {
@@ -293,6 +295,11 @@
$self->_print_preamble_header($HEADER);
+ my @op_protos = @{ $self->{op_protos} };
+ foreach my $proto (@op_protos) {
+ print $HEADER "$proto;\n";
+ }
+
$self->_print_run_core_func_decl_header($HEADER);
$self->_print_guard_suffix($HEADER);
@@ -436,9 +443,6 @@
$self->_print_run_core_func_decl_source($SOURCE);
- # Iterate over the ops, appending HEADER and SOURCE fragments:
- $self->_iterate_over_ops();
-
$self->_print_cg_jump_table($SOURCE);
$self->_print_goto_opcode($SOURCE);
@@ -494,6 +498,7 @@
sub _iterate_over_ops {
my $self = shift;
my @op_funcs;
+ my @op_protos;
my @op_func_table;
my @cg_jump_table;
my $index = 0;
@@ -518,7 +523,7 @@
$comment = "/* " . $op->full_name() . " */";
}
else {
- $definition = "$prototype;\n$self->{opsarraytype} *\n$func_name
($args)";
+ $definition = "$self->{opsarraytype} *\n$func_name ($args)";
}
my $src = $op->source( $self->{trans} );
@@ -542,6 +547,7 @@
else {
$one_op .= "$definition $comment {\n$src}\n\n";
push @op_funcs, $one_op;
+ push @op_protos, $prototype;
$prev_src = $src if ( $self->{suffix} eq '_cgp' || $self->{suffix}
eq '_switch' );
$prev_index = $index;
}
@@ -549,6 +555,7 @@
}
$self->{index} = $index;
$self->{op_funcs} = [EMAIL PROTECTED];
+ $self->{op_protos} = [EMAIL PROTECTED];
$self->{op_func_table} = [EMAIL PROTECTED];
$self->{cg_jump_table} = [EMAIL PROTECTED];
}
@@ -577,7 +584,7 @@
#ifdef __GNUC__
# ifdef I386
else if (cur_opcode == (void **) 1)
- asm ("jmp *4(%ebp)"); /* jump to ret addr, used by JIT */
+ __asm__ ("jmp *4(%ebp)"); /* jump to ret addr, used by JIT */
# endif
#endif
_reg_base = (char*)interp->ctx.bp.regs_i;
Index: lib/Parrot/OpTrans/CSwitch.pm
===================================================================
--- lib/Parrot/OpTrans/CSwitch.pm (revision 18699)
+++ lib/Parrot/OpTrans/CSwitch.pm (working copy)
@@ -153,8 +153,8 @@
return <<END_C;
/* run_core_func_start - $0 -> $type */
#if defined(__GNUC__) && defined(I386) && defined(PARROT_SWITCH_REGS)
- register void ** cur_opcode asm ("esi") = cur_op;
- register char * _reg_base asm ("edi");
+ register void ** cur_opcode __asm__ ("esi") = cur_op;
+ register char * _reg_base __asm__ ("edi");
#else
void ** cur_opcode = cur_op;
char * _reg_base;
Index: lib/Parrot/OpTrans/CGP.pm
===================================================================
--- lib/Parrot/OpTrans/CGP.pm (revision 18699)
+++ lib/Parrot/OpTrans/CGP.pm (working copy)
@@ -132,8 +132,8 @@
* (gdb) disas l_ops_addr[1191] l_ops_addr[1192]
*/
#if defined(__GNUC__) && defined(I386) && defined(PARROT_CGP_REGS)
- register void ** cur_opcode asm ("esi") = cur_op;
- register char * _reg_base asm ("edi");
+ register void ** cur_opcode __asm__ ("esi") = cur_op;
+ register char * _reg_base __asm__ ("edi");
#else
void **cur_opcode = cur_op;
char * _reg_base;
Index: lib/Parrot/OpTrans/CGoto.pm
===================================================================
--- lib/Parrot/OpTrans/CGoto.pm (revision 18699)
+++ lib/Parrot/OpTrans/CGoto.pm (working copy)
@@ -278,7 +278,7 @@
sub run_core_func_start {
return <<END_C;
#if defined(__GNUC__) && defined(I386) /* && defined(NO_DYNOPS) */
- register opcode_t *cur_opcode asm ("esi") = cur_op;
+ register opcode_t *cur_opcode __asm__ ("esi") = cur_op;
#else
opcode_t *cur_opcode = cur_op;
#endif
Index: lib/Parrot/OpTrans/CPrederef.pm
===================================================================
--- lib/Parrot/OpTrans/CPrederef.pm (revision 18699)
+++ lib/Parrot/OpTrans/CPrederef.pm (working copy)
@@ -44,16 +44,6 @@
END
}
-=item C<opsarraytype()>
-
-The ops array type is C<void *>.
-
-=cut
-
-sub opsarraytype {
- return 'void *';
-}
-
=item expr_address($addr)
=item expr_address($offset)