asm/AJAlignmentInstruction.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 17 Jun 2016 17:25:15 +0100
changeset 26 8eb6716029aa
parent 23 d2d9a2d4d6bf
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     1
"
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     2
    Copyright (c) 2012-2016 Igor Stasenko
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     3
                            Martin McClure
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     4
                            Damien Pollet
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     5
                            Camillo Bruni
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     6
                            Guido Chari
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     7
                   2016-now Jan Vrany <jan.vrany [at] fit . cvut . cz>
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     8
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
     9
    Permission is hereby granted, free of charge, to any person obtaining a copy
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    10
    of this software and associated documentation files (the 'Software'), to deal
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    11
    in the Software without restriction, including without limitation the rights
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    12
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    13
    copies of the Software, and to permit persons to whom the Software is
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    14
    furnished to do so, subject to the following conditions:
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    15
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    16
    The above copyright notice and this permission notice shall be included in all
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    17
    copies or substantial portions of the Software.
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    18
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    19
    THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    20
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    21
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    22
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    23
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    24
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    25
    SOFTWARE.
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    26
"
3
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
"{ Package: 'jv:dragonfly/asm' }"
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
"{ NameSpace: Smalltalk }"
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
AJInstruction subclass:#AJAlignmentInstruction
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
	instanceVariableNames:'alignTo'
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
	classVariableNames:''
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
	poolDictionaries:'AJConstants'
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
	category:'AsmJit-Instructions'
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
AJAlignmentInstruction comment:'I am a pseudo instruction used to align the following instruction to a multiple of a given byte number.

Example:
	asm := AJx64Assembler noStackFrame.
	
	"align the following instruction to a word (2bytes)"
	asm alignWord.
	asm inc: asm RAX.
	
	"align the following instruction to a double (4bytes)"
	asm alignDouble.
	asm inc: asm RAX.
	
	"align the following instruction to a QuadWord (8bytes)"
	asm alignQuad.
	asm inc: asm RAX.
	
	"align the following instruction to a multiple of an arbirary count"
	asm align: 64.
	asm inc: asm RAX.'
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
23
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    41
!AJAlignmentInstruction class methodsFor:'documentation'!
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    42
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    43
copyright
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    44
"
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    45
    Copyright (c) 2012-2016 Igor Stasenko
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    46
                            Martin McClure
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    47
                            Damien Pollet
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    48
                            Camillo Bruni
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    49
                            Guido Chari
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    50
                   2016-now Jan Vrany <jan.vrany [at] fit . cvut . cz>
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    51
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    52
    Permission is hereby granted, free of charge, to any person obtaining a copy
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    53
    of this software and associated documentation files (the 'Software'), to deal
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    54
    in the Software without restriction, including without limitation the rights
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    55
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    56
    copies of the Software, and to permit persons to whom the Software is
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    57
    furnished to do so, subject to the following conditions:
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    58
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    59
    The above copyright notice and this permission notice shall be included in all
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    60
    copies or substantial portions of the Software.
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    61
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    62
    THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    63
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    64
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    65
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    66
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    67
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    68
    SOFTWARE.
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    69
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    70
"
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    71
! !
d2d9a2d4d6bf Added README, licenses and copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3
diff changeset
    72
3
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
!AJAlignmentInstruction class methodsFor:'instance creation'!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
align: byteSize
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
    ^ self new align: byteSize
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
alignDouble
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
    ^ self new alignDouble
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
alignQuad
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
    ^ self new alignQuad
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    86
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
alignWord
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
    ^ self new alignWord
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
! !
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
!AJAlignmentInstruction methodsFor:'accessing'!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    92
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    93
align
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    94
    ^ alignTo
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    96
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    97
align: bytesSize
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    98
    "align the data to the given byte count"
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    99
    alignTo := bytesSize
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   100
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   101
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   102
name
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   103
    ^ String streamContents: [ :s|
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   104
        self printSelfOn: s]
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   105
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   106
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   107
printSelfOn: aStream  
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   108
    self align <= 1 ifTrue: [ ^ self ].
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   109
    
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   110
    aStream nextPut: $|.
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   111
    self align <= 8 
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   112
        ifTrue: [
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   113
            self align timesRepeat: [
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   114
                aStream nextPutAll: '----|']]
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   115
        ifFalse: [
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   116
            aStream 
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   117
                nextPutAll: (self align asString padded: #left to: 4 with: $ );
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   118
                nextPut: $|]
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   119
! !
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   120
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   121
!AJAlignmentInstruction methodsFor:'alignment'!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   122
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   123
alignByte
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   124
    self align: 1
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   125
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   126
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   127
alignDouble
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   128
    self align: 4
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   129
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   130
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   131
alignQuad
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   132
    self align: 8
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   133
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   134
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   135
alignWord
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   136
    self align: 2
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   137
! !
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   138
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   139
!AJAlignmentInstruction methodsFor:'emitting code'!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   140
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   141
emitCode: asm
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   142
    | padding |
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   143
    
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   144
    padding := self paddingForPosition: position.
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   145
    
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   146
    "new machine code: | padding |"
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   147
    machineCode := ByteArray new: padding .
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   148
!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   149
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   150
paddingForPosition: aPositionNumber
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   151
    | padding |
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   152
    
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   153
    padding := aPositionNumber \\ self align.
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   154
    padding = 0 
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   155
        ifFalse: [ padding := self align - padding ].
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   156
        
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   157
    ^ padding
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   158
! !
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   159
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   160
!AJAlignmentInstruction methodsFor:'initialize-release'!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   161
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   162
initialize 
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   163
    super initialize.
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   164
    self alignByte.
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   165
! !
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   166
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   167
!AJAlignmentInstruction methodsFor:'visitor'!
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   168
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   169
accept: anObject
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   170
    self shouldBeImplemented 
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   171
! !
483729eb4432 Initial port ot Igor Stasenko's AsmJit
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   172