[svn:parrot] r37970 - in trunk/compilers/pct/src: PCT POST

pmichaud at svn.parrot.org pmichaud at svn.parrot.org
Wed Apr 8 00:09:17 UTC 2009


Author: pmichaud
Date: Wed Apr  8 00:09:15 2009
New Revision: 37970
URL: https://trac.parrot.org/parrot/changeset/37970

Log:
[pct]:  Add HLL source line bytecode annotations to PCT.

Modified:
   trunk/compilers/pct/src/PCT/Node.pir
   trunk/compilers/pct/src/POST/Compiler.pir

Modified: trunk/compilers/pct/src/PCT/Node.pir
==============================================================================
--- trunk/compilers/pct/src/PCT/Node.pir	Tue Apr  7 23:57:16 2009	(r37969)
+++ trunk/compilers/pct/src/PCT/Node.pir	Wed Apr  8 00:09:15 2009	(r37970)
@@ -197,10 +197,27 @@
 
 .sub 'node' :method
     .param pmc node
-     ## Do nothing for now.  When we're in a better position to
-     ## handle source line information (RT #43269 and others)
-     ## we'll figure out what to do here.
-    .return ()
+
+    if null node goto done
+    $I0 = isa node, ['PGE';'Match']
+    if $I0 goto node_match
+    $I0 = isa node, ['PCT';'Node']
+    if $I0 goto node_pct
+    $S0 = typeof node
+    $S0 = concat "Don't know how to save info from node of type ", $S0
+    die $S0
+  node_match:
+    .local pmc source, pos
+    source = getattribute node, '$.target'
+    pos    = node.'from'()
+    goto node_done
+  node_pct:
+    source = node['source']
+    pos    = node['pos']
+  node_done:
+    self['source'] = source
+    self['pos']    = pos
+  done:
 .end
 
 

Modified: trunk/compilers/pct/src/POST/Compiler.pir
==============================================================================
--- trunk/compilers/pct/src/POST/Compiler.pir	Tue Apr  7 23:57:16 2009	(r37969)
+++ trunk/compilers/pct/src/POST/Compiler.pir	Wed Apr  8 00:09:15 2009	(r37970)
@@ -41,9 +41,11 @@
     .local pmc newself
     newself = new ['POST';'Compiler']
 
-    .local pmc innerpir
+    .local pmc innerpir, line
     innerpir = new 'CodeString'
     .lex '$CODE', innerpir
+    line = box 0
+    .lex '$LINE', line
 
     ##  if the root node isn't a Sub, wrap it
     $I0 = isa post, ['POST';'Sub']
@@ -68,12 +70,22 @@
 
 .sub 'pir_children' :method
     .param pmc node
+    .local pmc line
+    line = find_caller_lex '$LINE'
+    .lex '$LINE', line
+
     .local pmc iter
     iter = node.'iterator'()
   iter_loop:
     unless iter goto iter_end
-    .local pmc cpost
+    .local pmc cpost, pos, source
     cpost = shift iter
+    pos = cpost['pos']
+    if null pos goto done_subline
+    source = cpost['source']
+    line = source.'lineof'(pos)
+    inc line
+  done_subline:
     $P0 = self.'pir'(cpost)
     goto iter_loop
   iter_end:
@@ -156,8 +168,14 @@
     goto pirop_emit
 
   pirop_emit:
-    .local pmc subpir
-    subpir = find_caller_lex '$SUBPIR'
+    .local pmc subpir, subline, line
+    subpir  = find_caller_lex '$SUBPIR'
+    subline = find_caller_lex '$SUBLINE'
+    line    = find_caller_lex '$LINE'
+    if subline == line goto done_line
+    subpir.'emit'('.annotate "line", %0', line)
+    assign subline, line
+  done_line:
     subpir.'emit'(fmt, arglist :flat, 'r'=>result, 'n'=>name, 'i'=>invocant, 't'=>result)
 .end
 
@@ -188,9 +206,11 @@
 .sub 'pir' :method :multi(_, ['POST';'Sub'])
     .param pmc node
 
-    .local pmc innerpir, subpir
+    .local pmc subpir, subline, innerpir
     subpir = new 'CodeString'
     .lex '$SUBPIR', subpir
+    subline = box -1
+    .lex '$SUBLINE', subline
     innerpir = new 'CodeString'
     .lex '$CODE', innerpir
 


More information about the parrot-commits mailing list