|
1 "{ Package: 'jv:dragonfly/asm' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 AJInstruction subclass:#AJData |
|
6 instanceVariableNames:'data alignment' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'AJConstants' |
|
9 category:'AsmJit-Instructions' |
|
10 ! |
|
11 |
|
12 AJData comment:'I represent a pure data section in an assembly instruction stream. |
|
13 |
|
14 Example: |
|
15 asm := AJx64Assembler noStackFrame. |
|
16 |
|
17 "add a raw byte" |
|
18 asm db: 16rFF. |
|
19 |
|
20 "add a raw word" |
|
21 asm dw: #[16r34 16r12]. |
|
22 |
|
23 "add a raw double" |
|
24 asm dw: #[16r78 16r56 16r34 16r12]. |
|
25 |
|
26 "add a arbitrary sized data section with a byteArray" |
|
27 asm data: #[1 2 3 4 5 6 7 8 9 10 11 12 ].' |
|
28 ! |
|
29 |
|
30 !AJData class methodsFor:'instance creation'! |
|
31 |
|
32 byte: aByteValue |
|
33 ^ self data: (ByteArray with: aByteValue) |
|
34 ! |
|
35 |
|
36 data: aDataByteArray |
|
37 ^ self new |
|
38 data: aDataByteArray; |
|
39 yourself |
|
40 ! |
|
41 |
|
42 label: aLabel data: aDataByteArray |
|
43 ^ self new |
|
44 label: aLabel; |
|
45 data: aDataByteArray; |
|
46 yourself |
|
47 ! ! |
|
48 |
|
49 !AJData methodsFor:'accessing'! |
|
50 |
|
51 data |
|
52 ^ machineCode |
|
53 ! |
|
54 |
|
55 data: aByteArray |
|
56 "the will be put in the executable." |
|
57 machineCode := aByteArray |
|
58 ! |
|
59 |
|
60 name |
|
61 name ifNotNil: [ ^ name ]. |
|
62 |
|
63 "standard data sections" |
|
64 self is8 ifTrue: [ ^ 'db' ]. |
|
65 self is16 ifTrue: [ ^ 'dw' ]. |
|
66 self is32 ifTrue: [ ^ 'dd' ]. |
|
67 ! |
|
68 |
|
69 size |
|
70 ^ self data size |
|
71 ! ! |
|
72 |
|
73 !AJData methodsFor:'emitting code'! |
|
74 |
|
75 emitCode: asm |
|
76 machineCode ifNil: [ machineCode := #[] ] |
|
77 ! ! |
|
78 |
|
79 !AJData methodsFor:'testing'! |
|
80 |
|
81 is16 |
|
82 ^ self size = 2 |
|
83 ! |
|
84 |
|
85 is32 |
|
86 ^ self size = 4 |
|
87 ! |
|
88 |
|
89 is64 |
|
90 ^ self size = 8 |
|
91 ! |
|
92 |
|
93 is8 |
|
94 ^ self size = 1 |
|
95 ! ! |
|
96 |
|
97 !AJData methodsFor:'visitor'! |
|
98 |
|
99 accept: anObject |
|
100 anObject instructionData: self |
|
101 ! ! |
|
102 |