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 |
|
51 properties: aDictionary |
40 properties: aDictionary |
52 |
41 |
53 properties := aDictionary. |
42 properties := aDictionary. |
54 |
43 |
55 "Created: / 17-09-2008 / 12:17:49 / Jan Vrany <vranyj1@fel.cvut.cz>" |
44 "Created: / 17-09-2008 / 12:17:49 / Jan Vrany <vranyj1@fel.cvut.cz>" |
222 instr == #makeBlock ifTrue: |
211 instr == #makeBlock ifTrue: |
223 [closureCode |
212 [closureCode |
224 at: index + 1 |
213 at: index + 1 |
225 put: (closureCode at: index + 1) + pos + 4]]. |
214 put: (closureCode at: index + 1) + pos + 4]]. |
226 |
215 |
227 |
|
228 code addAll: closureCode. |
216 code addAll: closureCode. |
229 |
217 |
230 "Patch number of closure bytecodes" |
218 "Patch number of closure bytecodes" |
231 code at: pos + 2 put: code size + 1. |
219 code at: pos + 2 put: code size + 1. |
232 |
220 |
233 "Created: / 30-03-2009 / 18:16:10 / Jan Vrany <vranyj1@fel.cvut.cz>" |
221 "Created: / 30-03-2009 / 18:16:10 / Jan Vrany <vranyj1@fel.cvut.cz>" |
234 "Modified: / 12-05-2009 / 08:58:11 / Jan Vrany <vranyj1@fel.cvut.cz>" |
222 "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>" |
235 ! |
224 ! |
236 |
225 |
237 popTop |
226 popTop |
238 |
227 |
239 stack pop. |
228 stack pop. |
724 |
713 |
725 "Created: / 11-06-2008 / 14:02:03 / Jan Vrany <vranyj1@fel.cvut.cz>" |
714 "Created: / 11-06-2008 / 14:02:03 / Jan Vrany <vranyj1@fel.cvut.cz>" |
726 "Modified: / 13-05-2009 / 10:42:16 / Jan Vrany <vranyj1@fel.cvut.cz>" |
715 "Modified: / 13-05-2009 / 10:42:16 / Jan Vrany <vranyj1@fel.cvut.cz>" |
727 ! |
716 ! |
728 |
717 |
729 literals |
718 getCode |
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 |
|
778 |
719 |
779 | stream basicBlockStartOffset | |
720 | stream basicBlockStartOffset | |
780 [ orderSeq |
721 [ orderSeq |
781 inject: false |
722 inject: false |
782 into: [:changed :seqId | (self updateJump: seqId) | changed] |
723 into: [:changed :seqId | (self updateJump: seqId) | changed] |
797 put: ((seqCode at: seqId) at: index + 1) + basicBlockStartOffset]]. |
738 put: ((seqCode at: seqId) at: index + 1) + basicBlockStartOffset]]. |
798 |
739 |
799 stream nextPutAll: (seqCode at: seqId). |
740 stream nextPutAll: (seqCode at: seqId). |
800 basicBlockStartOffset := basicBlockStartOffset + (seqCode at: seqId) size. |
741 basicBlockStartOffset := basicBlockStartOffset + (seqCode at: seqId) size. |
801 ]. |
742 ]. |
802 ^self relativeJumpsToAbsoluteIn:stream contents |
743 ^stream contents |
803 |
744 |
804 "Created: / 11-06-2008 / 14:00:43 / Jan Vrany <vranyj1@fel.cvut.cz>" |
745 "Created: / 11-06-2008 / 14:00:43 / Jan Vrany <vranyj1@fel.cvut.cz>" |
805 "Modified: / 13-05-2009 / 11:15:41 / Jan Vrany <vranyj1@fel.cvut.cz>" |
746 "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>" |
806 ! ! |
827 ! ! |
807 |
828 |
808 !IRBytecodeGenerator class methodsFor:'documentation'! |
829 !IRBytecodeGenerator class methodsFor:'documentation'! |
809 |
830 |
810 version |
831 version |