All --

This patch to assemble.pl and disassemble.pl makes the assembler
output constant #0 as the hex string representation of the MD5 sum
of opcode_table. It also makes disassemble.pl check that the
fingerprint matches before disassembling, and warns if there is no
constant pool at all.

The next issue would be making the interpreter do something with the
fingerprint...


Regards,

-- Gregor
 _____________________________________________________________________ 
/     perl -e 'srand(-2091643526); print chr rand 90 for (0..4)'      \

   Gregor N. Purdy                          [EMAIL PROTECTED]
   Focus Research, Inc.                http://www.focusresearch.com/
   8080 Beckett Center Drive #203                   513-860-3570 vox
   West Chester, OH 45069                           513-860-3579 fax
\_____________________________________________________________________/

? assemble.pl.diff
? fingerprint.diff
Index: assemble.pl
===================================================================
RCS file: /home/perlcvs/parrot/assemble.pl,v
retrieving revision 1.12
diff -u -r1.12 assemble.pl
--- assemble.pl 2001/09/13 14:38:31     1.12
+++ assemble.pl 2001/09/13 15:05:37
@@ -5,6 +5,7 @@
 # Brian Wheeler ([EMAIL PROTECTED])
 
 use strict;
+use Digest::MD5 qw(&md5_hex);
 
 my $opt_c;
 if (@ARGV and $ARGV[0] eq "-c") {
@@ -37,8 +38,10 @@
 close GUTS;
 
 # get opcodes and their arg lists
+my $opcode_table;
 open OPCODES, "<opcode_table" or die "Can't get opcode table, $!/$^E";
 while (<OPCODES>) {
+    $opcode_table .= $_;
     next if /^\s*#/;
     chomp;
     s/^\s+//;
@@ -51,7 +54,8 @@
     $opcodes{$name}{RTYPES}=[@rtypes];
 }
 close OPCODES;
-
+my $opcode_fingerprint = md5_hex($opcode_table);
+constantize($opcode_fingerprint); # Make it constant zero.
 
 # read source and assemble
 my $pc=0; my $op_pc=0;
Index: disassemble.pl
===================================================================
RCS file: /home/perlcvs/parrot/disassemble.pl,v
retrieving revision 1.5
diff -u -r1.5 disassemble.pl
--- disassemble.pl      2001/09/13 07:21:37     1.5
+++ disassemble.pl      2001/09/13 15:05:37
@@ -5,6 +5,7 @@
 # Turn a parrot bytecode file into text
 
 use strict;
+use Digest::MD5 qw(&md5_hex);
 
 my(%opcodes, @opcodes);
 
@@ -32,8 +33,10 @@
     $opcodes{$2}{CODE} = $1;
 }
 
+my $opcode_table;
 open OPCODES, "<opcode_table" or die "Can't get opcode table, $!/$^E";
 while (<OPCODES>) {
+    $opcode_table .= $_;
     next if /^\s*#/;
     s/^\s+//;
     chomp;
@@ -48,6 +51,7 @@
                       TYPES => [@types]
                       }
 }
+my $opcode_fingerprint = md5_hex($opcode_table);
 
 $/ = \4;
 
@@ -62,6 +66,7 @@
     my $count=unpack('l', <>);
     print "# Constants: $count entries ($constants bytes)\n";
     print "# ID  Flags    Encoding Type     Size     Data\n"; 
+    my $constant_num = 0;
     foreach (1..$count) {
        my $flags=unpack('l',<>);
        my $encoding=unpack('l',<>);
@@ -74,7 +79,12 @@
        # strip off any padding nulls
        $data=substr($data,0,$size);
        printf("%04x: %08x %08x %08x %08x 
%s\n",$_-1,$flags,$encoding,$type,$size,$data);
+
+       die "Cannot disassemble (differing opcode table)!" if $constant_num == 0 and 
+$data ne $opcode_fingerprint;
+       $constant_num++;
     }
+} else {
+    warn "Disassembling without opcode table fingerprint!";
 }
 print "# Code Section\n";
 my $offset=0;

Reply via email to