compiler/opcode.rb
sjs 3f070cd0db [NEW] Emit x86 code for the mov instruction. Barely works 1/2 the time.
The supporting infrastructure includes a C program for reading a
binary blob of x86 code and wrapping it in an ELF executable for Linux
x86.  Unsure about getting the data for other sections of the binary
besides .text.
2009-05-19 17:01:14 -07:00

25 lines
451 B
Ruby

class OpCode
Attrs = [:prefix, :op, :modrm, :sib, :extra]
attr_accessor *Attrs
def initialize(attrs)
Attrs.each do |attr|
send("#{attr}=", attrs[attr])
end
end
def size
Attrs.inject(0) {|sum, attr|
iv = instance_variable_get("@#{attr}")
if iv.is_a?(Enumerable)
sum + iv.size
else
sum + 1
end
}
end
def binary
Attrs.map {|attr| send(attr)}.flatten.pack('c*')
end
end