asm/AJOperand.st
changeset 3 483729eb4432
child 23 d2d9a2d4d6bf
equal deleted inserted replaced
2:88445baa732f 3:483729eb4432
       
     1 "{ Package: 'jv:dragonfly/asm' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 Object subclass:#AJOperand
       
     6 	instanceVariableNames:'data compilerData operandId x64padding annotation'
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:'AJConstants'
       
     9 	category:'AsmJit-Operands'
       
    10 !
       
    11 
       
    12 AJOperand comment:'I am a generic operand used in the ASMJit assembler.
       
    13 I define the interface for setting the final instruction code and annotations.'
       
    14 !
       
    15 
       
    16 !AJOperand methodsFor:'accessing'!
       
    17 
       
    18 annotation
       
    19     ^ annotation
       
    20 !
       
    21 
       
    22 annotation: anObject
       
    23     annotation := anObject
       
    24 !
       
    25 
       
    26 clearId
       
    27     operandId := 0.
       
    28 !
       
    29 
       
    30 compilerData
       
    31     ^ compilerData
       
    32 !
       
    33 
       
    34 operandId
       
    35     ^ operandId
       
    36 !
       
    37 
       
    38 size
       
    39     "Return size of operand in bytes."
       
    40     
       
    41     self shouldBeImplemented 
       
    42 !
       
    43 
       
    44 size16
       
    45     ^ self size: 2
       
    46 !
       
    47 
       
    48 size32
       
    49     ^ self size: 4
       
    50 !
       
    51 
       
    52 size64
       
    53     ^ self size: 8
       
    54 !
       
    55 
       
    56 size8
       
    57     ^ self size: 1
       
    58 !
       
    59 
       
    60 stackSize
       
    61     ^ self size
       
    62 ! !
       
    63 
       
    64 !AJOperand methodsFor:'code generation'!
       
    65 
       
    66 emitPushOnStack: asm
       
    67     asm push: self
       
    68 ! !
       
    69 
       
    70 !AJOperand methodsFor:'converting'!
       
    71 
       
    72 asAJOperand
       
    73     "receiver is already an operand. no nothing"
       
    74 !
       
    75 
       
    76 ptr
       
    77 
       
    78     "turn receiver into a memory operand "
       
    79     
       
    80     self subclassResponsibility 
       
    81 !
       
    82 
       
    83 ptr16
       
    84 
       
    85     "turn receiver into a memory operand with receiver as base,
       
    86     with 2 bytes size"
       
    87     
       
    88     ^ self ptr size: 2
       
    89 !
       
    90 
       
    91 ptr32
       
    92 
       
    93     "turn receiver into a memory operand with receiver as base,
       
    94     with 4 bytes size"
       
    95     
       
    96     ^ self ptr size: 4
       
    97 !
       
    98 
       
    99 ptr64
       
   100 
       
   101     "turn receiver into a memory operand with receiver as base,
       
   102     with 8 bytes size"
       
   103     
       
   104     ^ self ptr size: 8
       
   105 !
       
   106 
       
   107 ptr8
       
   108 
       
   109     "turn receiver into a memory operand with receiver as base,
       
   110     with 1 byte size"
       
   111     
       
   112     ^ self ptr size: 1
       
   113 ! !
       
   114 
       
   115 !AJOperand methodsFor:'labels'!
       
   116 
       
   117 extractLabels: aBlockClosure
       
   118     " do nothing"
       
   119 ! !
       
   120 
       
   121 !AJOperand methodsFor:'printing'!
       
   122 
       
   123 printAnnotationOn: aStream
       
   124     annotation ifNil: [ ^ self ].
       
   125     aStream 
       
   126         nextPut: $" ; 
       
   127         nextPutAll: annotation asString; 
       
   128         nextPut: $";  space.
       
   129 !
       
   130 
       
   131 printAsOperandOn: aStream
       
   132     self printAnnotationOn: aStream.
       
   133     ^ self printOn: aStream 
       
   134 ! !
       
   135 
       
   136 !AJOperand methodsFor:'testing'!
       
   137 
       
   138 hasUpperBankIndex
       
   139     "True iff I have an index register, and it is one of r8-r15"
       
   140 
       
   141     ^ false	"Only can be true for memory references."
       
   142 !
       
   143 
       
   144 is16
       
   145     ^ self size == 2
       
   146 !
       
   147 
       
   148 is32
       
   149     ^ self size == 4
       
   150 !
       
   151 
       
   152 is64
       
   153     ^ self size == 8
       
   154 !
       
   155 
       
   156 is8
       
   157     ^ self size == 1
       
   158 !
       
   159 
       
   160 isImm
       
   161 
       
   162     ^ false 
       
   163 !
       
   164 
       
   165 isLabel
       
   166 
       
   167     ^ false
       
   168 !
       
   169 
       
   170 isMem
       
   171 
       
   172     ^ false
       
   173 !
       
   174 
       
   175 isNone
       
   176     "Return true if operand is none (OP_NONE)."
       
   177     self shouldBeImplemented 
       
   178 !
       
   179 
       
   180 isReg
       
   181 
       
   182     ^ false
       
   183 !
       
   184 
       
   185 isRegCode: aRegCode
       
   186 
       
   187     self shouldBeImplemented 
       
   188 !
       
   189 
       
   190 isRegIndex: aRegIndex
       
   191 
       
   192     ^ self isReg and: [ self index == (aRegIndex bitAnd: RegCodeMask ) ]
       
   193 !
       
   194 
       
   195 isRegMem
       
   196 
       
   197     ^ self isReg or: [ self isMem ]
       
   198 !
       
   199 
       
   200 isRegMem: aRegType
       
   201 
       
   202     self shouldBeImplemented 
       
   203 !
       
   204 
       
   205 isRegType: aRegType
       
   206 
       
   207     ^ self isReg and: [self type == aRegType]
       
   208 !
       
   209 
       
   210 isRegTypeGPB
       
   211     ^ self isRegType: RegGPB
       
   212 !
       
   213 
       
   214 isRegTypeGPD
       
   215     ^ self isRegType: RegGPD
       
   216 !
       
   217 
       
   218 isRegTypeGPQ
       
   219     ^ self isRegType: RegGPQ
       
   220 !
       
   221 
       
   222 isRegTypeGPW
       
   223     ^ self isRegType: RegGPW
       
   224 !
       
   225 
       
   226 isRegTypeMM
       
   227     ^ false
       
   228 !
       
   229 
       
   230 isRegTypeX87
       
   231     ^ false
       
   232 !
       
   233 
       
   234 isRegTypeXMM
       
   235     ^ false
       
   236 !
       
   237 
       
   238 isRip
       
   239     ^ false
       
   240 !
       
   241 
       
   242 prohibitsRex
       
   243     "Answer true if use of this operand requires that the instruction *not* have a REX prefix."
       
   244 
       
   245     self subclassResponsibility
       
   246 !
       
   247 
       
   248 requiresRex
       
   249     "Answer true if use of this operand requires that the instruction have a REX prefix."
       
   250 
       
   251     self subclassResponsibility
       
   252 ! !
       
   253