Skip to content

Commit

Permalink
DSL: rename instvar address to base in AcDSLCodeObject
Browse files Browse the repository at this point in the history
  • Loading branch information
janvrany authored and shingarov committed Sep 4, 2024
1 parent daf0c3e commit 69e88ab
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/ArchC-DSL/AcDSLCodeObject.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Class {
#name : #AcDSLCodeObject,
#superclass : #Object,
#instVars : [
'address',
'base',
'instructions'
],
#category : #'ArchC-DSL'
Expand All @@ -18,19 +18,35 @@ AcDSLCodeObject class >> new [

{ #category : #accessing }
AcDSLCodeObject >> address [
^ address
"Obsolete, use #base"
<resource: #obsolete>

^ self base
]

{ #category : #accessing }
AcDSLCodeObject >> base [
"Return the base address of this object file.
Defaults to 0 (zero), unless it is relocated to a different address.
see #relocateTo:with:
"
^ base
]

{ #category : #accessing }
AcDSLCodeObject >> bytes [
"Return a bytearray with binary code. All instructions mys be fully
grounded."

^ ByteArray streamContents: [ :s | instructions do: [:i | i emitOn: s ] ]
]

{ #category : #utilities }
AcDSLCodeObject >> disassembleOn: aStream [
| pc |

pc := address.
pc := base.
instructions do: [:insn |
| addr |

Expand All @@ -56,7 +72,7 @@ AcDSLCodeObject >> fixupBranchTargets [
"Pass 1 - collect all labels and their (relative) addresses:"
locations := Dictionary new.

insnAddr := address.
insnAddr := base.
instructions do: [:insn |
insn isLabelInstruction ifTrue: [
locations at: insn symbol put: insnAddr.
Expand All @@ -72,7 +88,7 @@ AcDSLCodeObject >> fixupBranchTargets [
AcDSLCodeObject >> fixupBranchTargetsUsing: locations [
| insnAddr |

insnAddr := address.
insnAddr := base.
1 to: instructions size do: [:i |
| insn |

Expand Down Expand Up @@ -100,7 +116,7 @@ AcDSLCodeObject >> gtInspectorInstructionsIn: composite [
display: [
| pc insnsWithAddrs |

pc := address.
pc := base.
insnsWithAddrs := OrderedCollection new: instructions size.
instructions collect:[:insn |
insnsWithAddrs add: { insn . pc }.
Expand Down Expand Up @@ -129,25 +145,29 @@ AcDSLCodeObject >> gtInspectorInstructionsIn: composite [

{ #category : #initialization }
AcDSLCodeObject >> initialize [
address := 0.
base := 0.
instructions := OrderedCollection new.
]

{ #category : #accessing }
AcDSLCodeObject >> instructions [
"Return code as a sequence of AcInstructions. Users are
allowed to modify this sequence in place to add/remove/replace
instructions."

^ instructions
]

{ #category : #relocation }
AcDSLCodeObject >> relocateTo: newAddress with: ignored [
address := newAddress.
AcDSLCodeObject >> relocateTo: address with: ignored [
base := address.
]

{ #category : #accessing }
AcDSLCodeObject >> relocations [
| addr relocs |

addr := address.
addr := base.
relocs := OrderedCollection new.
instructions do: [:insn |
insn relocation notNil ifTrue: [
Expand Down

0 comments on commit 69e88ab

Please sign in to comment.