Class: Fisk
- Inherits:
-
Object
show all
- Defined in:
- lib/fisk/machine/generated.rb,
lib/fisk.rb,
lib/fisk/helpers.rb,
lib/fisk/machine.rb,
lib/fisk/machine/encoding.rb
Overview
Opcodes Database license (2-clause BSD)
Copyright © 2017 Facebook Inc.
Copyright © 2014-2017, Georgia Institute of Technology All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Defined Under Namespace
Modules: Helpers, Registers
Classes: Imm32, Imm64, Imm8, Instruction, Label, Lit, M64, MOffs64, Machine, Operand, Rel32, Rel8, UnknownLabel
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Fisk
Returns a new instance of Fisk.
99
100
101
102
103
|
# File 'lib/fisk.rb', line 99
def initialize
@instructions = []
@labels = {}
@position = 0
end
|
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position.
97
98
99
|
# File 'lib/fisk.rb', line 97
def position
@position
end
|
Instance Method Details
#asm(buf = StringIO.new(''.b), &block) ⇒ Object
222
223
224
225
226
227
|
# File 'lib/fisk.rb', line 222
def asm buf = StringIO.new(''.b), &block
@position = 0
instance_eval(&block)
write_to_buffer buf
buf
end
|
#gen(name, params) ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/fisk.rb', line 161
def gen name, params
insns = Machine.instruction_with_name(name)
forms = insns.forms.find_all do |insn|
if insn.operands.length == params.length
params.zip(insn.operands).all? { |want_op, have_op|
want_op.works?(have_op.type)
}
else
false
end
end
raise NotImplementedError, "couldn't find instruction #{name}" if forms.length == 0
insn = nil
insn = forms.first
insn = Instruction.new(insn, params, position)
@position += insn.bytesize
@instructions << insn
params.each { |param| param.insn = insn if param.unknown_label? }
self
end
|
#imm32(val) ⇒ Object
201
202
203
|
# File 'lib/fisk.rb', line 201
def imm32 val
Imm32.new val
end
|
#imm64(val) ⇒ Object
205
206
207
|
# File 'lib/fisk.rb', line 205
def imm64 val
Imm64.new val
end
|
#imm8(val) ⇒ Object
197
198
199
|
# File 'lib/fisk.rb', line 197
def imm8 val
Imm8.new val
end
|
#label(name) ⇒ Object
125
126
127
|
# File 'lib/fisk.rb', line 125
def label name
UnknownLabel.new(name, self)
end
|
#label_for(name) ⇒ Object
121
122
123
|
# File 'lib/fisk.rb', line 121
def label_for name
@labels.fetch name
end
|
#lit(val) ⇒ Object
217
218
219
220
|
# File 'lib/fisk.rb', line 217
def lit val
Lit.new val
end
|
#m64(x) ⇒ Object
51
52
53
|
# File 'lib/fisk.rb', line 51
def m64 x
M64.new x
end
|
#make_label(name) ⇒ Object
129
130
131
|
# File 'lib/fisk.rb', line 129
def make_label name
@labels[name] = Label.new(name, position)
end
|
#moffs64(val) ⇒ Object
193
194
195
|
# File 'lib/fisk.rb', line 193
def moffs64 val
MOffs64.new val
end
|
#rel32(val) ⇒ Object
213
214
215
|
# File 'lib/fisk.rb', line 213
def rel32 val
Rel32.new val
end
|
#rel8(val) ⇒ Object
209
210
211
|
# File 'lib/fisk.rb', line 209
def rel8 val
Rel8.new val
end
|
#to_binary ⇒ Object
229
230
231
232
233
|
# File 'lib/fisk.rb', line 229
def to_binary
io = StringIO.new ''.b
write_to_buffer io
io.string
end
|