IRBytecodeGenerator.st
changeset 37 be8c2dd09dff
parent 30 1b7ff9c8c40b
child 41 f3898a3b378d
equal deleted inserted replaced
36:1bfd09c6b3d8 37:be8c2dd09dff
    35     "Created: / 11-06-2008 / 13:53:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
    35     "Created: / 11-06-2008 / 13:53:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
    36 ! !
    36 ! !
    37 
    37 
    38 !IRBytecodeGenerator methodsFor:'accessing'!
    38 !IRBytecodeGenerator methodsFor:'accessing'!
    39 
    39 
       
    40 getCode
       
    41 
       
    42     "
       
    43         Private entry for IRBytecodeGenerator>>makeBlock:
       
    44     "
       
    45 
       
    46     ^code
       
    47 
       
    48     "Created: / 30-03-2009 / 19:00:07 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
    49 !
       
    50 
    40 properties: aDictionary
    51 properties: aDictionary
    41 
    52 
    42     properties := aDictionary.
    53     properties := aDictionary.
    43 
    54 
    44     "Created: / 17-09-2008 / 12:17:49 / Jan Vrany <vranyj1@fel.cvut.cz>"
    55     "Created: / 17-09-2008 / 12:17:49 / Jan Vrany <vranyj1@fel.cvut.cz>"
   211         instr == #makeBlock ifTrue:
   222         instr == #makeBlock ifTrue:
   212             [closureCode 
   223             [closureCode 
   213                 at: index + 1 
   224                 at: index + 1 
   214                 put: (closureCode at: index + 1) + pos + 4]].
   225                 put: (closureCode at: index + 1) + pos + 4]].
   215 
   226 
       
   227 
   216     code addAll: closureCode.
   228     code addAll: closureCode.
   217 
   229 
   218     "Patch number of closure bytecodes"
   230     "Patch number of closure bytecodes"
   219     code at: pos + 2 put: code size + 1.
   231     code at: pos + 2 put: code size + 1.
   220 
   232 
   221     "Created: / 30-03-2009 / 18:16:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
   233     "Created: / 30-03-2009 / 18:16:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
   222     "Modified: / 12-05-2009 / 08:58:11 / Jan Vrany <vranyj1@fel.cvut.cz>"
   234     "Modified: / 12-05-2009 / 08:58:11 / Jan Vrany <vranyj1@fel.cvut.cz>"
   223     "Modified: / 23-03-2010 / 22:34:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   224 !
   235 !
   225 
   236 
   226 popTop
   237 popTop
   227 
   238 
   228         stack pop.
   239         stack pop.
   713 
   724 
   714     "Created: / 11-06-2008 / 14:02:03 / Jan Vrany <vranyj1@fel.cvut.cz>"
   725     "Created: / 11-06-2008 / 14:02:03 / Jan Vrany <vranyj1@fel.cvut.cz>"
   715     "Modified: / 13-05-2009 / 10:42:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
   726     "Modified: / 13-05-2009 / 10:42:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
   716 !
   727 !
   717 
   728 
   718 getCode
   729 literals
       
   730 
       
   731     ^literals asArray
       
   732 
       
   733 
       
   734     " old "
       
   735     "    literals := literals asArray copyWith: MethodProperties new.
       
   736 
       
   737         ^ lastLiteral 
       
   738                 ifNil: [literals copyWith: nil ] 
       
   739                 ifNotNil: [literals copyWith: lastLiteral]"
       
   740 
       
   741     "Modified: / 03-11-2008 / 13:41:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
   742 !
       
   743 
       
   744 numArgs
       
   745 
       
   746 	^ numArgs
       
   747 !
       
   748 
       
   749 numTemps
       
   750 
       
   751         ^ numArgs + numVars
       
   752 
       
   753     "Modified: / 30-03-2009 / 13:53:32 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
   754 !
       
   755 
       
   756 relativeJumpsToAbsoluteIn: symbolicCode
       
   757 
       
   758     symbolicCode withIndexDo:
       
   759         [:instr :index|
       
   760         (instr isSymbol and:[#(jump trueJump falseJump) includes: instr]) ifTrue:
       
   761             [|offset|
       
   762             offset := symbolicCode at: index + 1.
       
   763             (offset > 0)
       
   764                 ifTrue:[symbolicCode at: index + 1 put: (index + offset + 2)]
       
   765                 ifFalse:[symbolicCode at: index + 1 put: (index + offset)]]].
       
   766 
       
   767     ^symbolicCode.
       
   768 
       
   769     "Created: / 11-06-2008 / 15:56:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
   770 !
       
   771 
       
   772 stackSize
       
   773 
       
   774 	^ (stacks collect: [:s | s length]) max
       
   775 !
       
   776 
       
   777 symboliccodes
   719 
   778 
   720         | stream basicBlockStartOffset |
   779         | stream basicBlockStartOffset |
   721         [ orderSeq
   780         [ orderSeq
   722                 inject: false
   781                 inject: false
   723                 into: [:changed :seqId | (self updateJump: seqId) | changed]
   782                 into: [:changed :seqId | (self updateJump: seqId) | changed]
   738                             put: ((seqCode at: seqId) at: index + 1) + basicBlockStartOffset]].
   797                             put: ((seqCode at: seqId) at: index + 1) + basicBlockStartOffset]].
   739 
   798 
   740                 stream nextPutAll: (seqCode at: seqId).
   799                 stream nextPutAll: (seqCode at: seqId).
   741                 basicBlockStartOffset := basicBlockStartOffset + (seqCode at: seqId) size.
   800                 basicBlockStartOffset := basicBlockStartOffset + (seqCode at: seqId) size.
   742         ].
   801         ].
   743         ^stream contents
   802         ^self relativeJumpsToAbsoluteIn:stream contents
   744 
   803 
   745     "Created: / 11-06-2008 / 14:00:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
   804     "Created: / 11-06-2008 / 14:00:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
   746     "Modified: / 13-05-2009 / 11:15:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
   805     "Modified: / 13-05-2009 / 11:15:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
   747     "Modified: / 24-03-2010 / 08:42:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   748 !
       
   749 
       
   750 literals
       
   751 
       
   752     ^literals asArray
       
   753 
       
   754 
       
   755     " old "
       
   756     "    literals := literals asArray copyWith: MethodProperties new.
       
   757 
       
   758         ^ lastLiteral 
       
   759                 ifNil: [literals copyWith: nil ] 
       
   760                 ifNotNil: [literals copyWith: lastLiteral]"
       
   761 
       
   762     "Modified: / 03-11-2008 / 13:41:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
   763 !
       
   764 
       
   765 numArgs
       
   766 
       
   767 	^ numArgs
       
   768 !
       
   769 
       
   770 numTemps
       
   771 
       
   772         ^ numArgs + numVars
       
   773 
       
   774     "Modified: / 30-03-2009 / 13:53:32 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
   775 !
       
   776 
       
   777 relativeJumpsToAbsoluteIn: symbolicCode
       
   778 
       
   779     symbolicCode withIndexDo:
       
   780         [:instr :index|
       
   781         (instr isSymbol and:[#(jump trueJump falseJump) includes: instr]) ifTrue:
       
   782             [|offset|
       
   783             offset := symbolicCode at: index + 1.
       
   784             (offset > 0)
       
   785                 ifTrue:[symbolicCode at: index + 1 put: (index + offset + 2)]
       
   786                 ifFalse:[symbolicCode at: index + 1 put: (index + offset)]]].
       
   787 
       
   788     ^symbolicCode.
       
   789 
       
   790     "Created: / 11-06-2008 / 15:56:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
   791 !
       
   792 
       
   793 stackSize
       
   794 
       
   795 	^ (stacks collect: [:s | s length]) max
       
   796 !
       
   797 
       
   798 symboliccodes
       
   799 
       
   800         | stream basicBlockStartOffset |
       
   801         [ orderSeq
       
   802                 inject: false
       
   803                 into: [:changed :seqId | (self updateJump: seqId) | changed]
       
   804         ] whileTrue.
       
   805 
       
   806         stream := (OrderedCollection new: 200) writeStream.
       
   807         basicBlockStartOffset := 0. 
       
   808         orderSeq do: [:seqId |
       
   809                 (instrMaps at: seqId) do: [:assoc |
       
   810                         assoc key "instr" bytecodeIndex: stream position + assoc value.
       
   811                 ].
       
   812                 "Patch makeBlock offsets"
       
   813                 (seqCode at: seqId) withIndexDo:
       
   814                     [:instr :index|
       
   815                     instr == #makeBlock ifTrue:
       
   816                         [(seqCode at: seqId) 
       
   817                             at: index + 1
       
   818                             put: ((seqCode at: seqId) at: index + 1) + basicBlockStartOffset]].
       
   819 
       
   820                 stream nextPutAll: (seqCode at: seqId).
       
   821                 basicBlockStartOffset := basicBlockStartOffset + (seqCode at: seqId) size.
       
   822         ].
       
   823         ^self relativeJumpsToAbsoluteIn:stream contents
       
   824 
       
   825     "Created: / 11-06-2008 / 14:00:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
   826     "Modified: / 13-05-2009 / 11:15:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
       
   827 ! !
   806 ! !
   828 
   807 
   829 !IRBytecodeGenerator class methodsFor:'documentation'!
   808 !IRBytecodeGenerator class methodsFor:'documentation'!
   830 
   809 
   831 version
   810 version
   832     ^ '$Header: /cvs/stx/cvut/stx/goodies/newcompiler/IRBytecodeGenerator.st,v 1.3 2009/10/08 12:04:39 fm Exp $'
   811     ^ '$Id$'
   833 !
   812 !
   834 
   813 
   835 version_CVS
   814 version_CVS
   836     ^ '$Header: /cvs/stx/cvut/stx/goodies/newcompiler/IRBytecodeGenerator.st,v 1.3 2009/10/08 12:04:39 fm Exp $'
   815     ^ '§Header: /cvs/stx/cvut/stx/goodies/newcompiler/IRBytecodeGenerator.st,v 1.3 2009/10/08 12:04:39 fm Exp §'
   837 !
   816 !
   838 
   817 
   839 version_SVN
   818 version_SVN
   840     ^ '$Id$'
   819     ^ '$Id::                                                                                                                        $'
   841 ! !
   820 ! !