Skip to content

Commit daf0c3e

Browse files
janvranyshingarov
authored andcommitted
DSL: rename AcDSLCodeBuffer to AcDSLCodeObject
The latter - `AcDSLCodeObject` - seems to be a better name of what this really is (or will become in subsequent commit) as it's more like an "object file" (or "object code") than mere memory buffer containing instructions. It has base address, (will) contains relocations, debug info and what not so...
1 parent 2db9613 commit daf0c3e

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

src/ArchC-DSL/AcDSLAssembler.class.st

+24-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Class {
22
#name : #AcDSLAssembler,
33
#superclass : #Object,
44
#instVars : [
5-
'memory',
5+
'object',
66
'cursor',
77
'annotations'
88
],
@@ -59,7 +59,7 @@ AcDSLAssembler >> annotations: aCollection [
5959
{ #category : #'emitting-private' }
6060
AcDSLAssembler >> append: insn [
6161
insn annotations: annotations.
62-
memory instructions add: insn afterIndex: cursor.
62+
object instructions add: insn afterIndex: cursor.
6363
cursor := cursor + 1.
6464
^ insn
6565
]
@@ -95,34 +95,32 @@ AcDSLAssembler >> byte: bytes [
9595
{ #category : #accessing }
9696
AcDSLAssembler >> cursor: anInteger [
9797
self assert: anInteger isInteger.
98-
self assert:(anInteger between: 0 and: memory instructions size).
98+
self assert:(anInteger between: 0 and: object instructions size).
9999

100100
cursor := anInteger
101101
]
102102

103103
{ #category : #inspecting }
104104
AcDSLAssembler >> gtInspectorInstructionsIn: composite [
105105
<gtInspectorPresentationOrder: 60>
106-
^memory gtInspectorInstructionsIn: composite
107-
106+
^object gtInspectorInstructionsIn: composite
108107
]
109108

110109
{ #category : #initialization }
111110
AcDSLAssembler >> initialize [
112111
super initialize.
113-
114-
"Lazy-generate DSL methods here upon first instantiation.
115-
This solves three problems:
116-
(i) spares users to think of it and doing it manually
117-
(ii) avoids generating assemblers which will never be used.
118-
(iii) makes it debuggable if there's an error since this will
119-
be called once all the code is loaded (as opposed to 'at some
120-
undefined time during package loading').
112+
"Lazy-generate DSL methods here upon first instantiation.
113+
This solves three problems:
114+
(i) spares users to think of it and doing it manually
115+
(ii) avoids generating assemblers which will never be used.
116+
(iii) makes it debuggable if there's an error since this will
117+
be called once all the code is loaded (as opposed to 'at some
118+
undefined time during package loading').
121119
"
122-
self class generated ifFalse: [
120+
self class generated ifFalse: [
123121
AcDSLAssemblerGenerator generate: self class.
124122
].
125-
memory := AcDSLCodeBuffer new.
123+
object := AcDSLCodeObject new.
126124
cursor := 0.
127125
]
128126

@@ -157,5 +155,15 @@ AcDSLAssembler >> label: anObject [
157155

158156
{ #category : #accessing }
159157
AcDSLAssembler >> memory [
160-
^ memory
158+
<resource: #obsolete>
159+
160+
^self object
161+
]
162+
163+
{ #category : #accessing }
164+
AcDSLAssembler >> object [
165+
"Return the code object containing the code generated
166+
by this assembler."
167+
168+
^ object
161169
]

src/ArchC-DSL/AcDSLCodeBuffer.class.st src/ArchC-DSL/AcDSLCodeObject.class.st

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Class {
2-
#name : #AcDSLCodeBuffer,
2+
#name : #AcDSLCodeObject,
33
#superclass : #Object,
44
#instVars : [
55
'address',
@@ -9,25 +9,25 @@ Class {
99
}
1010

1111
{ #category : #'instance creation' }
12-
AcDSLCodeBuffer class >> new [
12+
AcDSLCodeObject class >> new [
1313
"return an initialized instance"
1414

1515
^ self basicNew initialize.
1616

1717
]
1818

1919
{ #category : #accessing }
20-
AcDSLCodeBuffer >> address [
20+
AcDSLCodeObject >> address [
2121
^ address
2222
]
2323

2424
{ #category : #accessing }
25-
AcDSLCodeBuffer >> bytes [
25+
AcDSLCodeObject >> bytes [
2626
^ ByteArray streamContents: [ :s | instructions do: [:i | i emitOn: s ] ]
2727
]
2828

2929
{ #category : #utilities }
30-
AcDSLCodeBuffer >> disassembleOn: aStream [
30+
AcDSLCodeObject >> disassembleOn: aStream [
3131
| pc |
3232

3333
pc := address.
@@ -45,12 +45,12 @@ AcDSLCodeBuffer >> disassembleOn: aStream [
4545
]
4646

4747
{ #category : #utilities }
48-
AcDSLCodeBuffer >> disassembled [
48+
AcDSLCodeObject >> disassembled [
4949
^ String streamContents: [ :s | self disassembleOn: s. ].
5050
]
5151

5252
{ #category : #relocation }
53-
AcDSLCodeBuffer >> fixupBranchTargets [
53+
AcDSLCodeObject >> fixupBranchTargets [
5454
| locations insnAddr |
5555

5656
"Pass 1 - collect all labels and their (relative) addresses:"
@@ -69,7 +69,7 @@ AcDSLCodeBuffer >> fixupBranchTargets [
6969
]
7070

7171
{ #category : #relocation }
72-
AcDSLCodeBuffer >> fixupBranchTargetsUsing: locations [
72+
AcDSLCodeObject >> fixupBranchTargetsUsing: locations [
7373
| insnAddr |
7474

7575
insnAddr := address.
@@ -92,7 +92,7 @@ AcDSLCodeBuffer >> fixupBranchTargetsUsing: locations [
9292
]
9393

9494
{ #category : #inspecting }
95-
AcDSLCodeBuffer >> gtInspectorInstructionsIn: composite [
95+
AcDSLCodeObject >> gtInspectorInstructionsIn: composite [
9696
<gtInspectorPresentationOrder: 60>
9797

9898
^ composite fastTable
@@ -128,23 +128,23 @@ AcDSLCodeBuffer >> gtInspectorInstructionsIn: composite [
128128
]
129129

130130
{ #category : #initialization }
131-
AcDSLCodeBuffer >> initialize [
131+
AcDSLCodeObject >> initialize [
132132
address := 0.
133133
instructions := OrderedCollection new.
134134
]
135135

136136
{ #category : #accessing }
137-
AcDSLCodeBuffer >> instructions [
137+
AcDSLCodeObject >> instructions [
138138
^ instructions
139139
]
140140

141141
{ #category : #relocation }
142-
AcDSLCodeBuffer >> relocateTo: newAddress with: ignored [
142+
AcDSLCodeObject >> relocateTo: newAddress with: ignored [
143143
address := newAddress.
144144
]
145145

146146
{ #category : #accessing }
147-
AcDSLCodeBuffer >> relocations [
147+
AcDSLCodeObject >> relocations [
148148
| addr relocs |
149149

150150
addr := address.
@@ -158,3 +158,10 @@ AcDSLCodeBuffer >> relocations [
158158
].
159159
^ relocs
160160
]
161+
162+
{ #category : #accessing }
163+
AcDSLCodeObject >> size [
164+
"Return the size of code in bytes"
165+
166+
^ instructions inject: 0 into: [:size :insn | size + (insn bitWidth // 8) ]
167+
]

0 commit comments

Comments
 (0)