A new IRLine pseudoinstruction added to include debugging info into the bytecode.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 02 Dec 2008 08:14:54 +0000
changeset 6 49a61123c743
parent 5 b94aea1d3710
child 7 0de2eaa86456
A new IRLine pseudoinstruction added to include debugging info into the bytecode. See IRBuilderTests for examples.
IRBuilder.st
IRBuilderTest.st
IRBytecodeGenerator.st
IRInstruction.st
IRInterpreter.st
IRLine.st
IRPrinter.st
IRTranslator.st
stx_goodies_newcompiler.st
--- a/IRBuilder.st	Mon Dec 01 19:01:08 2008 +0000
+++ b/IRBuilder.st	Tue Dec 02 08:14:54 2008 +0000
@@ -168,6 +168,13 @@
 	self startNewSequence.
 !
 
+line: line
+
+        self add: (IRInstruction line: line)
+
+    "Created: / 02-12-2008 / 09:00:15 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
 popTop
 
 	self add: IRInstruction popTop
--- a/IRBuilderTest.st	Mon Dec 01 19:01:08 2008 +0000
+++ b/IRBuilderTest.st	Tue Dec 02 08:14:54 2008 +0000
@@ -25,7 +25,7 @@
 
     ^arg1 + arg2
 
-    "Created: / 01-12-2008 / 19:59:11 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Created: / 02-12-2008 / 09:11:46 / Jan Vrany <vranyj1@fel.cvut.cz>"
 ! !
 
 !IRBuilderTest methodsFor:'testing'!
@@ -156,6 +156,48 @@
 	
 !
 
+testLine1
+
+        | iRMethod aCompiledMethod |
+        iRMethod := IRBuilder new
+                numRargs: 1;
+                addTemps: #(self); "receiver and args declarations"
+
+                line: 5;
+                pushLiteral: true;
+                returnTop;
+                ir.
+
+        aCompiledMethod := iRMethod compiledMethod.
+
+        self assert: (aCompiledMethod isKindOf: CompiledMethod).
+     self assert: ((aCompiledMethod valueWithReceiver: nil arguments: #() ) = true).
+
+    "Created: / 02-12-2008 / 09:11:06 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+testLine2
+
+        | iRMethod aCompiledMethod |
+        iRMethod := IRBuilder new
+                numRargs: 1;
+                addTemps: #(self); "receiver and args declarations"
+
+                line: 5;
+                pushLiteral: true;
+                pushLiteral: false;
+                send: #&;
+                returnTop;
+                ir.
+
+        aCompiledMethod := iRMethod compiledMethod.
+
+        self assert: (aCompiledMethod isKindOf: CompiledMethod).
+     self assert: ((aCompiledMethod valueWithReceiver: nil arguments: #() ) = false).
+
+    "Created: / 02-12-2008 / 09:11:42 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
 testLiteralArray
 
 	| iRMethod aCompiledMethod |
--- a/IRBytecodeGenerator.st	Mon Dec 01 19:01:08 2008 +0000
+++ b/IRBytecodeGenerator.st	Tue Dec 02 08:14:54 2008 +0000
@@ -3,7 +3,7 @@
 Object subclass:#IRBytecodeGenerator
 	instanceVariableNames:'seqOrder orderSeq jumps literals lastLiteral currentSeqId
 		currentSeqNum lastSpecialReturn instrMaps instrMap maxTemp stacks
-		stack primNum numArgs properties code seqCode'
+		stack primNum numArgs properties code seqCode lastLine'
 	classVariableNames:'BytecodeTable Bytecodes SpecialConstants SpecialSelectors'
 	poolDictionaries:''
 	category:'NewCompiler-Bytecode'
@@ -55,11 +55,12 @@
         numArgs := 0.
         currentSeqNum := 0.
         orderSeq := OrderedDictionary new.  "reverse map of seqOrder"
+        lastLine := 0.
 
         "starting label in case one is not provided by client"
         self label: self newDummySeqId.
 
-    "Modified: / 05-11-2008 / 10:33:30 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 02-12-2008 / 09:08:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
 !
 
 numArgs: n
@@ -136,6 +137,23 @@
     "Modified: / 11-06-2008 / 13:58:56 / Jan Vrany <vranyj1@fel.cvut.cz>"
 !
 
+line: line
+
+    lastLine := line.
+
+    (line < 256) 
+        ifTrue:
+            [self 
+                nextPut: #lineno;
+                nextPut: line]
+        ifFalse:
+            [self 
+                nextPut: #lineno16;
+                nextPut: line]
+
+    "Created: / 02-12-2008 / 09:02:30 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
 popTop
 
         stack pop.
@@ -289,11 +307,12 @@
 
         self 
             nextPut: #send;
-            nextPut: 0; "lineno"
+            nextPut: lastLine;
             nextPut: (self addLiteral: selector);
             nextPut: sendNumArgs.
 
     "Created: / 01-12-2008 / 19:47:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 02-12-2008 / 09:10:31 / Jan Vrany <vranyj1@fel.cvut.cz>"
 !
 
 send: selector numArgs: sendNumArgs toSuperOf: behavior
@@ -303,12 +322,13 @@
 
         self 
             nextPut: #superSend;
-            nextPut: 0; "lineno"
+            nextPut: lastLine;
             nextPut: (self addLiteral: selector);
             nextPut: sendNumArgs;
             nextPut: (self addLiteral: behavior superclass)
 
     "Created: / 01-12-2008 / 19:48:14 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 02-12-2008 / 09:10:37 / Jan Vrany <vranyj1@fel.cvut.cz>"
 !
 
 storeInstVar: index
--- a/IRInstruction.st	Mon Dec 01 19:01:08 2008 +0000
+++ b/IRInstruction.st	Tue Dec 02 08:14:54 2008 +0000
@@ -27,6 +27,14 @@
 		otherwise: seq2
 !
 
+line: line
+
+        ^ IRLine new
+                line: line
+
+    "Created: / 02-12-2008 / 08:59:56 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
 new
 	^super basicNew.
 !
--- a/IRInterpreter.st	Mon Dec 01 19:01:08 2008 +0000
+++ b/IRInterpreter.st	Tue Dec 02 08:14:54 2008 +0000
@@ -28,6 +28,11 @@
 label: seqNum
 !
 
+line: line
+
+    "Created: / 02-12-2008 / 09:00:27 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
 popTop
 !
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IRLine.st	Tue Dec 02 08:14:54 2008 +0000
@@ -0,0 +1,38 @@
+"{ Package: 'stx:goodies/newcompiler' }"
+
+IRInstruction subclass:#IRLine
+	instanceVariableNames:'line'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'NewCompiler-IR'
+!
+
+
+!IRLine methodsFor:'accessing'!
+
+line
+    ^ line
+
+    "Created: / 02-12-2008 / 08:58:59 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+line:anInteger
+    line := anInteger.
+
+    "Created: / 02-12-2008 / 08:58:59 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!IRLine methodsFor:'interpret'!
+
+executeOn: interpreter
+
+        ^ interpreter line: line
+
+    "Created: / 02-12-2008 / 08:59:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!IRLine class methodsFor:'documentation'!
+
+version
+    ^'$Id$'
+! !
--- a/IRPrinter.st	Mon Dec 01 19:01:08 2008 +0000
+++ b/IRPrinter.st	Tue Dec 02 08:14:54 2008 +0000
@@ -65,6 +65,14 @@
 	stream cr.
 !
 
+line: line
+
+    stream nextPutAll: 'line: '.
+    line printOn: stream
+
+    "Created: / 02-12-2008 / 09:00:40 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
 popTop
 
 	stream nextPutAll: 'popTop'
--- a/IRTranslator.st	Mon Dec 01 19:01:08 2008 +0000
+++ b/IRTranslator.st	Tue Dec 02 08:14:54 2008 +0000
@@ -73,6 +73,14 @@
     "Modified: / 11-06-2008 / 10:13:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
 !
 
+line: line
+
+        self doPending.
+        gen line: line
+
+    "Created: / 02-12-2008 / 09:01:47 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
 popTop
 
 	"if last was storeTemp,  storeInstVar storeIntoLiteralVariable then convert to storePopTemp, storePopInstVar storePopIntoLiteralVariable"
--- a/stx_goodies_newcompiler.st	Mon Dec 01 19:01:08 2008 +0000
+++ b/stx_goodies_newcompiler.st	Tue Dec 02 08:14:54 2008 +0000
@@ -15,14 +15,14 @@
         #'stx:goodies/libtool3'    "Tools::Inspector2Tab - referenced by IRMethod>>inspector2TabIRCode "
         #'stx:goodies/refactoryBrowser/parser'    "RBIdentifierToken - referenced by IRDecompiler>>newVar: "
         #'stx:goodies/sunit'    "TestCase - superclass of IRTransformTest "
-        #'stx:libbasic'    "Object - superclass of IRTransformTest "
+        #'stx:libbasic'    "Link - superclass of IRLine "
         #'stx:libbasic2'    "OrderedDictionary - referenced by IRBytecodeGenerator>>initialize "
         #'stx:libcomp'    "PrimitiveNode - referenced by IRMethod>>initialize "
         #'stx:libcompat'    "Preferences - referenced by IRDecompiler>>removeClosureCreation: "
         #'stx:libwidg'    "ScrollableView - referenced by IRMethod>>inspector2TabIRCode "
     )
 
-    "Modified: / 01-12-2008 / 19:59:45 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 02-12-2008 / 09:13:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
 ! !
 
 !stx_goodies_newcompiler class methodsFor:'description - contents'!
@@ -45,6 +45,7 @@
         IRDecompiler
         IRDup
         IRJump
+        IRLine
         IRPop
         IRPrinter
         IRReturn
@@ -64,7 +65,7 @@
         IRTempStore
     )
 
-    "Modified: / 01-12-2008 / 19:59:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 02-12-2008 / 09:13:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
 !
 
 extensionMethodNames
@@ -74,7 +75,7 @@
         Class bindingOf:
     )
 
-    "Modified: / 01-12-2008 / 19:59:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
+    "Modified: / 02-12-2008 / 09:13:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
 ! !
 
 !stx_goodies_newcompiler class methodsFor:'description - project information'!