Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements (01) #43

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ArchC-Core-Tests/AcAssemblerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ AcAssemblerTest >> test_byte [

result := AcProcessorDescriptions powerpc assembler parse: '.byte 0x7F'.
self assert: result binaryEncoding equals: 16r7F.
self assert: result disassemble equals: '.byte 0x' , (16r7F printStringRadix: 16).
self assert: result disassemble equals: '.byte 0x7F'.
]

{ #category : #data }
Expand All @@ -329,7 +329,7 @@ AcAssemblerTest >> test_u16 [

result := AcProcessorDescriptions powerpc assembler parse: '.2byte 0x7FE0'.
self assert: result binaryEncoding equals: 16r7FE0.
self assert: result disassemble equals: '.2byte 0x' , (16r7FE0 printStringRadix:16).
self assert: result disassemble equals: '.2byte 0x7FE0'.
]

{ #category : #data }
Expand All @@ -338,7 +338,7 @@ AcAssemblerTest >> test_u32 [

result := AcProcessorDescriptions powerpc assembler parse: '.4byte 0x7FE00008'.
self assert: result binaryEncoding equals: 16r7FE00008.
self assert: result disassemble equals: '.4byte 0x' , (16r7FE00008 printStringRadix:16).
self assert: result disassemble equals: '.4byte 0x7FE00008'.
]

{ #category : #data }
Expand All @@ -347,5 +347,5 @@ AcAssemblerTest >> test_u64 [

result := AcProcessorDescriptions powerpc assembler parse: '.8byte 0x7FE00008CAFEAFFE'.
self assert: result binaryEncoding equals: 16r7FE00008CAFEAFFE.
self assert: result disassemble equals: '.8byte 0x' , (16r7FE00008CAFEAFFE printStringRadix:16).
self assert: result disassemble equals: '.8byte 0x7FE00008CAFEAFFE'.
]
5 changes: 5 additions & 0 deletions src/ArchC-Core/AcAsmOperandModifier.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ AcAsmOperandModifier >> encodeInFields: fs accordingTo: format [
self subclassResponsibility
]

{ #category : #testing }
AcAsmOperandModifier >> isAcAsmOperandModifier [
^ true
]

{ #category : #queries }
AcAsmOperandModifier >> isPRREL [
^ self class isPCREL
Expand Down
4 changes: 2 additions & 2 deletions src/ArchC-Core/AcAsmSyntax.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ AcAsmSyntax >> assembler [
allOperands := actualOperands copy addAll: constraints; yourself.
fieldValues := Dictionary new.
allOperands keysAndValuesDo: [ :opDef :v |
fieldValues addAll: (opDef asOperandInstantiation encodeValue: v accoringTo: instruction format) ].
fieldValues addAll: (opDef asOperandInstantiation encodeValue: v
accordingTo: instruction format) ].
self instruction inEnvironment: fieldValues ]

]

{ #category : #accessing }
Expand Down
15 changes: 14 additions & 1 deletion src/ArchC-Core/AcInt.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ AcInt >> assembler [

{ #category : #'encoding / decoding' }
AcInt >> disassemble [
^ self name , ' 0x' , (self value printStringRadix: 16)
binaryEncoding isSymbolic ifTrue: [
| variables |

variables := binaryEncoding variableNames.
variables size == 1 ifTrue: [
"Simple function of one variable"
^ self name , ' {' , variables anyOne , '}'
] ifFalse: [
"Function of multiple variables, print the whole AST"
^ self name , ' {' , binaryEncoding astToString , '}'
].
] ifFalse: [
^ self name , ' 0x', (self value printPaddedWith:$0 to: self bitWidth // 8 base:16)
].
]

{ #category : #'encoding / decoding' }
Expand Down
14 changes: 10 additions & 4 deletions src/ArchC-Core/AcProcessorDescription.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,16 @@ AcProcessorDescription >> decodeBits: aBitVector [
AcProcessorDescription >> decodeableFormFor: code [
self hasConstantInstructionWidth ifTrue: [
(code isKindOf: ByteArray)"Sigh, Pharo has no #isByteArray"
ifTrue: [
code size == (self constantInstructionWidth // 8)
ifFalse: [ self error: 'Invalid bytes (too few or too much)' ].
^code toBitVectorEndian: self endian ].
ifTrue: [
| bitsPerInsn bytesPerInsn bvs |

bitsPerInsn := self constantInstructionWidth.
bytesPerInsn := bitsPerInsn // 8.
code size == bytesPerInsn
ifTrue: [ ^ code toBitVectorEndian: self endian ].
(code size \\ bytesPerInsn) ~~ 0
ifTrue: [ self error: 'Invalid bytes (too few or too much)' ].
^ (1 to: code size // bytesPerInsn) collect: [ :i | code toBitVector: bitsPerInsn endian: self endian startingAt: (i - 1) * bytesPerInsn + 1 ]].
(code isCollection and:[code isSequenceable])
ifTrue:[ ^code ].
^code toBitVector: self constantInstructionWidth
Expand Down
10 changes: 6 additions & 4 deletions src/ArchC-Core/AsmOperandInstantiation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ AsmOperandInstantiation >> encodeSimpleValue: value [
]

{ #category : #private }
AsmOperandInstantiation >> encodeValue: value accoringTo: format [
(value isKindOf: AcAsmOperandModifier) ifTrue: [ ^value encodeInFields: self accordingTo: format ].
^self encodeSimpleValue: value

AsmOperandInstantiation >> encodeValue: value accordingTo: format [
value isAcAsmOperandModifier ifTrue: [
^ value encodeInFields: self accordingTo: format
] ifFalse: [
^ self encodeSimpleValue: value
]
]

{ #category : #rewriting }
Expand Down
22 changes: 18 additions & 4 deletions src/ArchC-Core/ByteArray.extension.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
Extension { #name : #ByteArray }

{ #category : #'*ArchC-Core' }
ByteArray >> toBitVectorEndian: endian [
self assert: self size isPowerOfTwo.
ByteArray >> toBitVector: xlen endian: endian startingAt: startIndex [
self assert: (xlen \\ 8) == 0.
self assert: (xlen // 8) isPowerOfTwo.

endian ifBig: [
^ (BitVector concatAll: (self collect: [ :aByte | aByte toBitVector: 8] as: Array)) simplify
^ (BitVector concatAll: ((startIndex to: startIndex + (xlen // 8) - 1 by: 1) collect: [ :i | (self at:i) toBitVector: 8] as: Array)) simplify
] ifLittle: [
^ (BitVector concatAll: (self reverse collect: [ :aByte | aByte toBitVector: 8] as: Array)) simplify
^ (BitVector concatAll: ((startIndex + (xlen // 8) - 1 to: startIndex by: -1) collect: [ :i | (self at:i) toBitVector: 8] as: Array)) simplify
].

"
#[ 16r0A 16r0B 16r0C 16r0D ] toBitVector: 32 endian: Endian little startingAt: 1
#[ 16r0A 16r0B 16r0C 16r0D ] toBitVector: 32 endian: Endian big startingAt: 1
"

"Created: / 18-06-2024 / 22:32:07 / Jan Vrany <[email protected]>"
]

{ #category : #'*ArchC-Core' }
ByteArray >> toBitVectorEndian: endian [
^ self toBitVector: self size * 8 endian: endian startingAt: 1

"
#[ 16r0A 16r0B 16r0C 16r0D ] toBitVectorEndian: Endian little.
#[ 16r0A 16r0B 16r0C 16r0D ] toBitVectorEndian: Endian big.
Expand Down
5 changes: 5 additions & 0 deletions src/ArchC-Core/Object.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ Extension { #name : #Object }
Object >> decodeFor: anISA [
^(anISA decodeableFormFor: self) decodeFor: anISA
]

{ #category : #'*ArchC-Core' }
Object >> isAcAsmOperandModifier [
^ false
]
8 changes: 6 additions & 2 deletions src/ArchC-Core/ProcessorInstructionDeclaration.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Class {
'format',
'internalBindings',
'syntax',
'isa'
'isa',
'binaryEncoding'
],
#classVars : [
'EmptyBindings'
Expand Down Expand Up @@ -132,7 +133,10 @@ ProcessorInstructionDeclaration >> assertInvariants [

{ #category : #accessing }
ProcessorInstructionDeclaration >> binaryEncoding [
^format binaryEncoding inEnvironment: internalBindings
binaryEncoding isNil ifTrue: [
binaryEncoding := format binaryEncoding inEnvironment: internalBindings.
].
^ binaryEncoding
]

{ #category : #accessing }
Expand Down
11 changes: 6 additions & 5 deletions src/ArchC-DSL/AcAsmSyntax.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ AcAsmSyntax >> assembleDSL: mnemonic operands: operandList [
| operandDef |

operandDef := self operands at: operandIdx.
environment addAll: (operandDef asOperandInstantiation encodeValue: operandValue accoringTo: instruction format).
environment addAll: (operandDef asOperandInstantiation encodeValue: operandValue
accordingTo: instruction format).
operandIdx := operandIdx + 1.
].
].
Expand All @@ -36,9 +37,9 @@ AcAsmSyntax >> assembleDSL: mnemonic operands: operandList [
baseMod := operandFormat base modifier.

environment addAll: (offsetDef asOperandInstantiation encodeValue: (offsetMod new x: operandValue offset)
accoringTo: instruction format).
accordingTo: instruction format).
environment addAll: (baseDef asOperandInstantiation encodeValue: (baseMod new x: operandValue base)
accoringTo: instruction format).
accordingTo: instruction format).

operandIdx := operandIdx + 2.
] ifFalse: [
Expand All @@ -48,7 +49,7 @@ AcAsmSyntax >> assembleDSL: mnemonic operands: operandList [
operandModifier := operandFormat modifier.

environment addAll: (operandDef asOperandInstantiation encodeValue: (operandModifier new x: operandValue)
accoringTo: instruction format).
accordingTo: instruction format).

operandIdx := operandIdx + 1.
].
Expand All @@ -57,7 +58,7 @@ AcAsmSyntax >> assembleDSL: mnemonic operands: operandList [

self constraints keysAndValuesDo: [:operandDef :operand |
environment addAll: (operandDef asOperandInstantiation encodeValue: operand
accoringTo: instruction format)
accordingTo: instruction format)
].
^self instruction inEnvironment: environment
]
Loading