-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit add "data instructions", a kind instruction that is not an ISA instruction but merely byte value. These allows users to build data (structures) and code in an uniform way and also simplify embedding data into instruction stream (when generating trampolines / PLTs, compiled code headers and so on - all this is common in JIT compilers)
- Loading branch information
Showing
8 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Class { | ||
#name : #AcByte, | ||
#superclass : #AcInt, | ||
#category : #'ArchC-Core-Core' | ||
} | ||
|
||
{ #category : #accessing } | ||
AcByte >> bitWidth [ | ||
^ 8 | ||
] | ||
|
||
{ #category : #accessing } | ||
AcByte >> name [ | ||
^ '.byte' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Class { | ||
#name : #AcDataInstruction, | ||
#superclass : #AcInstruction, | ||
#instVars : [ | ||
'isa', | ||
'binaryEncoding', | ||
'relocation' | ||
], | ||
#category : #'ArchC-Core-Core' | ||
} | ||
|
||
{ #category : #queries } | ||
AcDataInstruction class >> isAbstract [ | ||
^ self == AcDataInstruction. | ||
] | ||
|
||
{ #category : #'instance creation' } | ||
AcDataInstruction class >> value: value [ | ||
self assert: self isAbstract not description: 'Cannot instantiate abstract class'. | ||
|
||
^ self basicNew | ||
value: value; | ||
yourself. | ||
] | ||
|
||
{ #category : #accessing } | ||
AcDataInstruction >> binaryEncoding [ | ||
^ binaryEncoding | ||
] | ||
|
||
{ #category : #accessing } | ||
AcDataInstruction >> isa [ | ||
^ isa | ||
] | ||
|
||
{ #category : #accessing } | ||
AcDataInstruction >> isa: anAcProcessorDefinition [ | ||
self assert:(isa isNil or: [ anAcProcessorDefinition == isa ]). | ||
|
||
isa := anAcProcessorDefinition. | ||
] | ||
|
||
{ #category : #accessing } | ||
AcDataInstruction >> relocation [ | ||
^ relocation | ||
] | ||
|
||
{ #category : #accessing } | ||
AcDataInstruction >> relocation: anAcRelocationOrNil [ | ||
"Set or clear relocation entry associated with this instruction." | ||
|
||
self assert: (anAcRelocationOrNil isNil or: [ anAcRelocationOrNil isAcRelocation ]). | ||
self assert: (anAcRelocationOrNil isNil or: [ anAcRelocationOrNil isValidForInstruction: self]) | ||
description: 'Invalid data relocation'. | ||
self assert: (relocation isNil or: [ anAcRelocationOrNil isNil ]) | ||
description: 'A relocation already associated'. | ||
|
||
relocation := anAcRelocationOrNil | ||
] | ||
|
||
{ #category : #accessing } | ||
AcDataInstruction >> value [ | ||
^ self subclassResponsibility | ||
] | ||
|
||
{ #category : #accessing } | ||
AcDataInstruction >> value: value [ | ||
^ self subclassResponsibility | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Class { | ||
#name : #AcInt, | ||
#superclass : #AcDataInstruction, | ||
#category : #'ArchC-Core-Core' | ||
} | ||
|
||
{ #category : #queries } | ||
AcInt class >> isAbstract [ | ||
"Return if this class is an abstract class. | ||
True is returned here for myself only; false for subclasses. | ||
Abstract subclasses must redefine this again." | ||
|
||
^ self == AcInt. | ||
] | ||
|
||
{ #category : #'instance creation' } | ||
AcInt class >> new [ | ||
^ self value: 0 | ||
] | ||
|
||
{ #category : #'encoding / decoding' } | ||
AcInt >> assembler [ | ||
^ (self name asParser trim, | ||
( "hex literal"('0x' asParser, #hex asParser plus flatten ==> [ :prefAndnumeral | Integer readFrom: prefAndnumeral second base: 16 ]) | ||
/ "dec literal"(#digit asParser plus flatten ==> [ :numeralString | numeralString asInteger ]) | ||
/ "{varname}" (${ asParser, (PPPredicateObjectParser anyExceptAnyOf: #($})) star flatten, $} asParser ==> [ :expr | expr second]))) | ||
==> [ :nameAndValue | self class value: nameAndValue second ]. | ||
|
||
" | ||
AcByte basicNew assembler parse: '.byte 0x1' | ||
AcByte basicNew assembler parse: '.byte 255' | ||
AcByte basicNew assembler parse: '.byte {byteval}' | ||
" | ||
] | ||
|
||
{ #category : #'encoding / decoding' } | ||
AcInt >> disassemble [ | ||
^ self name , ' 0x' , (self value printStringRadix: 16) | ||
] | ||
|
||
{ #category : #'encoding / decoding' } | ||
AcInt >> emitOn: aStream [ | ||
self binaryEncoding toByteArrayEndian: self isa endian on: aStream | ||
] | ||
|
||
{ #category : #accessing } | ||
AcInt >> value [ | ||
^ self binaryEncoding unsignedValue | ||
] | ||
|
||
{ #category : #accessing } | ||
AcInt >> value: value [ | ||
binaryEncoding := value toBitVector: self bitWidth | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Class { | ||
#name : #AcInt16, | ||
#superclass : #AcInt, | ||
#category : #'ArchC-Core-Core' | ||
} | ||
|
||
{ #category : #accessing } | ||
AcInt16 >> bitWidth [ | ||
^ 16 | ||
] | ||
|
||
{ #category : #accessing } | ||
AcInt16 >> name [ | ||
^ '.2byte' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Class { | ||
#name : #AcInt32, | ||
#superclass : #AcInt, | ||
#category : #'ArchC-Core-Core' | ||
} | ||
|
||
{ #category : #accessing } | ||
AcInt32 >> bitWidth [ | ||
^ 32 | ||
] | ||
|
||
{ #category : #accessing } | ||
AcInt32 >> name [ | ||
^ '.4byte' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Class { | ||
#name : #AcInt64, | ||
#superclass : #AcInt, | ||
#category : #'ArchC-Core-Core' | ||
} | ||
|
||
{ #category : #accessing } | ||
AcInt64 >> bitWidth [ | ||
^ 64 | ||
] | ||
|
||
{ #category : #accessing } | ||
AcInt64 >> name [ | ||
^ '.8byte' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters