develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35780 - trunk/compilers/pirc/src

From:
kjs
Date:
January 19, 2009 15:26
Subject:
[svn:parrot] r35780 - trunk/compilers/pirc/src
Message ID:
20090119232555.072AACB9AE@x12.develooper.com
Author: kjs
Date: Mon Jan 19 15:25:54 2009
New Revision: 35780

Modified:
   trunk/compilers/pirc/src/bcgen.c
   trunk/compilers/pirc/src/bcgen.h
   trunk/compilers/pirc/src/piremit.c

Log:
[pirc] add debug segment and debug info. Not finished yet, but at least pbc_disassemble does now print it.

Modified: trunk/compilers/pirc/src/bcgen.c
==============================================================================
--- trunk/compilers/pirc/src/bcgen.c	(original)
+++ trunk/compilers/pirc/src/bcgen.c	Mon Jan 19 15:25:54 2009
@@ -75,9 +75,10 @@
 
 
 struct bytecode {
-    PackFile    *packfile;       /* the actual packfile */
-    opcode_t    *opcursor;       /* for writing ops into the code segment */
-    Interp      *interp;         /* parrot interpreter */
+    PackFile        *packfile;       /* the actual packfile */
+    opcode_t        *opcursor;       /* for writing ops into the code segment */
+    Interp          *interp;         /* parrot interpreter */
+    PackFile_Debug  *debug_seg;      /* debug segment */
 };
 
 
@@ -420,6 +421,46 @@
     bc->opcursor = (opcode_t *)bc->interp->code->base.data;
 }
 
+/*
+
+=item C<void
+create_debugsegment(bytecode * const bc, size_t size)>
+
+Create a debug segment of size C<size>
+
+=cut
+
+*/
+void
+create_debugsegment(bytecode * const bc, size_t size, int sourceline, char const * const sourcefile)
+{
+    bc->debug_seg = Parrot_new_debug_seg(bc->interp, bc->interp->code, size);
+
+    /* XXX why is the +1 needed? FIX! */
+    Parrot_debug_add_mapping(bc->interp, bc->debug_seg, sourceline + 1, sourcefile);
+}
+
+/*
+
+=item C<void
+emit_debug_info(bytecode * const bc, int sourceline)>
+
+Emit debug information.
+XXX
+
+=cut
+
+*/
+void
+emit_debug_info(bytecode * const bc, int sourceline) {
+    /*
+if (IMCC_INFO(interp)->debug_seg)
+            IMCC_INFO(interp)->debug_seg->base.data[IMCC_INFO(interp)->ins_line++] =
+                (opcode_t)ins->line;
+                */
+    bc->debug_seg->base.data[sourceline] = sourceline;
+}
+
 
 /*
 
@@ -986,6 +1027,7 @@
 }
 
 
+
 /*
 
 =item C<void

Modified: trunk/compilers/pirc/src/bcgen.h
==============================================================================
--- trunk/compilers/pirc/src/bcgen.h	(original)
+++ trunk/compilers/pirc/src/bcgen.h	Mon Jan 19 15:25:54 2009
@@ -82,6 +82,8 @@
 void destroy_bytecode(bytecode * bc);
 
 void create_codesegment(bytecode * const bc, int codesize);
+void create_debugsegment(bytecode * const bc, size_t size, int sourceline, char const * const file);
+void emit_debug_info(bytecode * const bc, int sourceline);
 
 void create_annotations_segment(bytecode * const bc, char const * const name);
 

Modified: trunk/compilers/pirc/src/piremit.c
==============================================================================
--- trunk/compilers/pirc/src/piremit.c	(original)
+++ trunk/compilers/pirc/src/piremit.c	Mon Jan 19 15:25:54 2009
@@ -814,6 +814,9 @@
      */
     optimize_instr(lexer, instr);
 
+    /* XXX check whether there's a debug segment, or that debug info must be emitted */
+    emit_debug_info(lexer->bc, instr->sourceline);
+
     /* emit the opcode */
     offset = emit_opcode(lexer->bc, instr->opcode);
 
@@ -871,6 +874,10 @@
     /* initialize iter to first instruction */
     iter = sub->statements->next;
 
+    /* create debug segment */
+    /* XXX is this the right size? */
+    create_debugsegment(lexer->bc, lexer->codesize, iter->sourceline, lexer->filename);
+
     do {
         emit_pbc_instr(lexer, iter);
         iter = iter->next;



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About