On Fri, Feb 15, 2002 at 12:13:57PM -0800, Steve Fink wrote:
> Looks like the commits since last night have re-broken pbc2c.pl, so
> it'll be a little while before I can generate a patch.

My mistake, it was just that 'make clean' deleted my .pbc file and
pbc2c.pl wasn't very good about reporting the error. Fixed now.

There needs to be an easier way to maintain local .ops files and
associated .c and .h files without constantly generating conflicts and
muddying patches. (Actually, Configure.pl handles the .ops file quite
well; it's the rest that's a pain.) I would make one, but I don't want
to put time into a Makefile.in that might be abandoned.

Alternatively, I suppose I could commit my alternative regexp
implementation, but it just seems too similar to Brent Dax's to
clutter up the tree with it.

Anyway, here's a patch to repair pbc2c.pl, combined with removing
typecasts in various places throughout the code. It probably won't
work for Windows yet. The libparrot.a target might need to be modified
to at least prevent it from confusing make on Windows; I don't know.

Preliminary instructions for using pbc2c.pl are in docs/running.pod.
I'll try to do better later.

Silly mops timings:
 standard:  25.8 Mops/sec
     goto:  69.0 Mops/sec
      jit: 361.6 Mops/sec

Index: Makefile.in
===================================================================
RCS file: /home/perlcvs/parrot/Makefile.in,v
retrieving revision 1.131
diff -p -u -b -r1.131 Makefile.in
--- Makefile.in 15 Feb 2002 02:30:02 -0000      1.131
+++ Makefile.in 15 Feb 2002 20:28:44 -0000
@@ -147,6 +152,9 @@ all : $(TEST_PROG) $(PDUMP) docs
 
 mops: examples/assembly/mops${exe} examples/mops/mops${exe}
 
+libparrot$(A) : $(O_FILES)
+       $(AR_CRS) $@ $^
+
 $(TEST_PROG): test_main$(O) $(GEN_HEADERS) $(O_FILES) lib/Parrot/OpLib/core.pm 
lib/Parrot/PMC.pm
        $(LD) ${ld_out}$(TEST_PROG) $(LDFLAGS) $(O_FILES) test_main$(O) $(C_LIBS)
 
Index: core.ops
===================================================================
RCS file: /home/perlcvs/parrot/core.ops,v
retrieving revision 1.94
diff -p -u -b -r1.94 core.ops
--- core.ops    15 Feb 2002 02:30:02 -0000      1.94
+++ core.ops    15 Feb 2002 20:28:47 -0000
@@ -2443,7 +2443,7 @@ op runinterp(inout PMC, in INT) {
 }
 
 op enternative() {
-  goto ADDRESS(( run_native(interpreter, CUR_OPCODE, (opcode_t 
*)interpreter->code->byte_code) ));
+  goto ADDRESS(( run_native(interpreter, CUR_OPCODE, interpreter->code->byte_code) ));
 }
 
 ########################################
Index: interpreter.c
===================================================================
RCS file: /home/perlcvs/parrot/interpreter.c,v
retrieving revision 1.69
diff -p -u -b -r1.69 interpreter.c
--- interpreter.c       14 Feb 2002 05:53:58 -0000      1.69
+++ interpreter.c       15 Feb 2002 20:28:49 -0000
@@ -61,14 +61,14 @@ static void
 runops_generic (opcode_t * (*core)(struct Parrot_Interp *, opcode_t *), 
                 struct Parrot_Interp *interpreter, opcode_t * pc) {
     opcode_t * code_start;
-    UINTVAL    code_size;
+    UINTVAL    code_size; /* in opcodes */
     opcode_t * code_end;
 
     check_fingerprint(interpreter);
 
-    code_start = (opcode_t *)interpreter->code->byte_code;
-    code_size  = interpreter->code->byte_code_size;
-    code_end   = (opcode_t *)((char *)interpreter->code->byte_code + code_size);
+    code_start = interpreter->code->byte_code;
+    code_size  = interpreter->code->byte_code_size / sizeof(opcode_t);
+    code_end   = interpreter->code->byte_code + code_size;
 
     pc = core(interpreter, pc);
 
@@ -286,15 +286,15 @@ static void
 runops_jit (struct Parrot_Interp *interpreter, opcode_t * pc) {
 #ifdef HAS_JIT
     opcode_t * code_start;
-    UINTVAL    code_size;
+    UINTVAL    code_size; /* in opcodes */
     opcode_t * code_end;
     jit_f      jit_code;
 
     check_fingerprint(interpreter);
 
-    code_start = (opcode_t *)interpreter->code->byte_code;
-    code_size  = interpreter->code->byte_code_size;
-    code_end   = (opcode_t *)((char *)interpreter->code->byte_code + code_size);
+    code_start = interpreter->code->byte_code;
+    code_size  = interpreter->code->byte_code_size / sizeof(opcode_t);
+    code_end   = interpreter->code->byte_code + code_size;
 
     jit_code = build_asm(interpreter, pc, code_start, code_end);
 #ifdef ALPHA
@@ -337,15 +337,15 @@ static void
 runops_prederef (struct Parrot_Interp *interpreter, opcode_t * pc, 
                  void ** pc_prederef) {
     opcode_t * code_start;
-    UINTVAL    code_size;
+    UINTVAL    code_size; /* in opcodes */
     opcode_t * code_end;
     void **    code_start_prederef;
 
     check_fingerprint(interpreter);
 
-    code_start = (opcode_t *)interpreter->code->byte_code;
-    code_size  = interpreter->code->byte_code_size;
-    code_end   = (opcode_t *)((char *)interpreter->code->byte_code + code_size);
+    code_start = interpreter->code->byte_code;
+    code_size  = interpreter->code->byte_code_size / sizeof(opcode_t);
+    code_end   = interpreter->code->byte_code + code_size;
 
     code_start_prederef = pc_prederef;
 
Index: pbc2c.pl
===================================================================
RCS file: /home/perlcvs/parrot/pbc2c.pl,v
retrieving revision 1.17
diff -p -u -b -r1.17 pbc2c.pl
--- pbc2c.pl    30 Jan 2002 18:02:15 -0000      1.17
+++ pbc2c.pl    15 Feb 2002 20:28:50 -0000
@@ -238,7 +238,7 @@ main(int argc, char **argv) {
 static opcode_t* run_compiled(struct Parrot_Interp *interpreter, opcode_t 
*cur_opcode, opcode_t *start_code){
 
 switch_label:
-    switch(((ptrcast_t)cur_opcode - (ptrcast_t)start_code) / sizeof(opcode_t)) {
+    switch(cur_opcode - start_code) {
 
 END_C
 
@@ -285,7 +285,8 @@ sub compile_file {
     my ($file_name) = @_;
 
     my $pf = Parrot::PackFile->new;
-    $pf->unpack_file($file_name);
+    $pf->unpack_file($file_name)
+      or die "Unable to unpack file $file_name: $!";
 
 #    dump_const_table($pf);
     compile_byte_code($pf, $file_name);
Index: pdump.c
===================================================================
RCS file: /home/perlcvs/parrot/pdump.c,v
retrieving revision 1.8
diff -p -u -b -r1.8 pdump.c
--- pdump.c     1 Jan 2002 19:49:11 -0000       1.8
+++ pdump.c     15 Feb 2002 20:28:50 -0000
@@ -16,7 +16,7 @@ int
 main(int argc, char **argv) {
     struct stat       file_stat;
     int               fd;
-    char *            packed;
+    opcode_t *        packed;
     size_t            packed_size;
     struct PackFile * pf;
     struct Parrot_Interp *interpreter = make_interpreter(0);
@@ -43,7 +43,7 @@ main(int argc, char **argv) {
     packed_size = file_stat.st_size;
 
 #ifndef HAS_HEADER_SYSMMAN
-    packed = mem_sys_allocate(packed_size);
+    packed = (opcode_t *) mem_sys_allocate(packed_size);
 
     if (!packed) {
         printf("Can't allocate, code %i\n", errno);
@@ -52,7 +52,7 @@ main(int argc, char **argv) {
 
     read(fd, (void*)packed, packed_size);
 #else
-    packed = mmap(0, packed_size, PROT_READ, MAP_SHARED, fd, (off_t)0);
+    packed = (opcode_t *) mmap(0, packed_size, PROT_READ, MAP_SHARED, fd, (off_t)0);
 
     if (!packed) {
         printf("Can't mmap, code %i\n", errno);
Index: runops_cores.c
===================================================================
RCS file: /home/perlcvs/parrot/runops_cores.c,v
retrieving revision 1.12
diff -p -u -b -r1.12 runops_cores.c
--- runops_cores.c      14 Feb 2002 05:53:58 -0000      1.12
+++ runops_cores.c      15 Feb 2002 20:28:50 -0000
@@ -42,14 +42,14 @@ void trace_op(struct Parrot_Interp *inte
 opcode_t *
 runops_slow_core (struct Parrot_Interp *interpreter, opcode_t * pc) {
     opcode_t * code_start;
-    INTVAL     code_size;
+    INTVAL     code_size; /* in opcodes */
     opcode_t * code_end;
     opcode_t * lastpc = NULL;
     FLOATVAL starttime = 0;
 
-    code_start = (opcode_t *)interpreter->code->byte_code;
-    code_size  = interpreter->code->byte_code_size;
-    code_end   = (opcode_t *)((char *)interpreter->code->byte_code + code_size);
+    code_start = interpreter->code->byte_code;
+    code_size  = interpreter->code->byte_code_size / sizeof(opcode_t);
+    code_end   = interpreter->code->byte_code + code_size;
 
     if (interpreter->flags & PARROT_TRACE_FLAG) {
       trace_op(interpreter, code_start, code_end, pc);
Index: docs/running.pod
===================================================================
RCS file: /home/perlcvs/parrot/docs/running.pod,v
retrieving revision 1.3
diff -p -u -b -r1.3 running.pod
--- docs/running.pod    30 Jan 2002 20:54:17 -0000      1.3
+++ docs/running.pod    15 Feb 2002 20:28:54 -0000
@@ -67,12 +67,12 @@ Converts a bytecode file to a native .c 
 
 Usage information (and malformed pod error message): C<perldoc -F pbc2c.pl>
 
-No documentation is available for compiling the .c file to a binary.
-This works, but produces a binary that crashes:
+To convert the generated foo.c file to a binary, do (on Unix only):
 
-  ./assemble.pl examples/assembly/life.pasm > life.pbc
-  perl pbc2c.pl life.pbc > life.c
-  ls **/*.o | egrep -v 'pdump|test_main' | xargs gcc -Iinclude -o life life.c -lm -ldl
+  make libparrot.a
+  gcc -O3 -g -Iinclude -c foo.c -o foo.o
+  gcc -g -o foo foo.o -L. -lparrot -ldl
+  ./foo # Runs it
 
 =item B<tests>
 
@@ -83,7 +83,7 @@ appropriate test file in the t/ director
   perl -Ilib t/op/basic.t
 
 To keep a copy of all of the test C<.pasm> and C<.pbc> files
-generated, set the environment variable POST_MORTEM to 1:
+generated, set the environment variable POSTMORTEM to 1:
 
   POSTMORTEM=1 perl -Ilib t/op/basic.t 
   ls t/op/basic*
Index: lib/Parrot/OpTrans/C.pm
===================================================================
RCS file: /home/perlcvs/parrot/lib/Parrot/OpTrans/C.pm,v
retrieving revision 1.4
diff -p -u -b -r1.4 C.pm
--- lib/Parrot/OpTrans/C.pm     28 Jan 2002 06:03:20 -0000      1.4
+++ lib/Parrot/OpTrans/C.pm     15 Feb 2002 20:28:57 -0000
@@ -21,7 +21,7 @@ use vars qw(@ISA);
 sub defines
 {
   return <<END;
-#define REL_PC     ((size_t)(cur_opcode - (opcode_t *)interpreter->code->byte_code))
+#define REL_PC     ((size_t)(cur_opcode - interpreter->code->byte_code))
 #define CUR_OPCODE cur_opcode
 END
 }
Index: lib/Parrot/OpTrans/CGoto.pm
===================================================================
RCS file: /home/perlcvs/parrot/lib/Parrot/OpTrans/CGoto.pm,v
retrieving revision 1.5
diff -p -u -b -r1.5 CGoto.pm
--- lib/Parrot/OpTrans/CGoto.pm 28 Jan 2002 06:03:20 -0000      1.5
+++ lib/Parrot/OpTrans/CGoto.pm 15 Feb 2002 20:28:57 -0000
@@ -91,8 +91,12 @@ sub expr_offset {
 sub goto_offset
 {
   my ($self, $offset) = @_;
-#print STDERR "pbcc: map_ret_rel($offset)\n";
+  if ($offset =~ /^-?\d+$/) {
   return sprintf("goto PC_%d", $self->pc + $offset);
+  } else {
+      return sprintf("cur_opcode = &&PC_%d; cur_opcode += %s; goto switch_label", 
+$self->pc, $offset);
+  }
+#print STDERR "pbcc: map_ret_rel($offset)\n";
 }
 
 
@@ -103,7 +107,7 @@ sub goto_offset
 sub goto_pop
 {
   my ($self) = @_;
-  return sprintf("cur_opcode = pop_dest(interpreter);\ngoto switch_label");
+  return "goto *pop_dest(interpreter)";
 }
 
 #
Index: lib/Parrot/OpTrans/CPrederef.pm
===================================================================
RCS file: /home/perlcvs/parrot/lib/Parrot/OpTrans/CPrederef.pm,v
retrieving revision 1.6
diff -p -u -b -r1.6 CPrederef.pm
--- lib/Parrot/OpTrans/CPrederef.pm     15 Feb 2002 03:25:00 -0000      1.6
+++ lib/Parrot/OpTrans/CPrederef.pm     15 Feb 2002 20:28:57 -0000
@@ -23,7 +23,7 @@ sub defines
 {
   return <<END;
 #define REL_PC ((size_t)(cur_opcode - interpreter->prederef_code))
-#define CUR_OPCODE (((opcode_t *)interpreter->code->byte_code) + REL_PC)
+#define CUR_OPCODE (interpreter->code->byte_code + REL_PC)
 
 static inline opcode_t* prederef_to_opcode(struct Parrot_Interp* interpreter,
                                            void** prederef_addr)
@@ -69,6 +69,11 @@ sub expr_pop
   my ($self) = @_;
   return "opcode_to_prederef(interpreter, pop_dest(interpreter))";
 }
+
+# expr_address
+#
+# Same logic as expr_pop
+#
 
 sub expr_address
 {

Reply via email to