Module: RMasm::ObjectExtension

Included in:
Object
Defined in:
lib/rmasm/struct.rb,
lib/rmasm/align.rb,
lib/rmasm/label.rb,
lib/rmasm/extern.rb,
lib/rmasm/section.rb,
lib/rmasm/assembler.rb,
lib/rmasm/data_core.rb,
lib/rmasm/data_primitive.rb

Overview




Instance Method Summary collapse

Instance Method Details

#__(*args) ⇒ Object



24
25
26
# File 'lib/rmasm/label.rb', line 24

def __(*args)
  Label.define(*args)
end

#asmObject



48
49
50
# File 'lib/rmasm/assembler.rb', line 48

def asm()
  $rmasm
end

#data(*args) ⇒ Object



46
47
48
49
50
# File 'lib/rmasm/data_core.rb', line 46

def data(*args)
  return Data if args.empty?
  # report an error if any arguments are passed to the data directive
  return Report.error(:ARGS, args.length, "none", "data")
end

#db(*args) ⇒ Object Also known as: uint8, int8, byte

Declare a byte data



45
46
47
48
# File 'lib/rmasm/data_primitive.rb', line 45

def db(*args)
  return Byte if args.empty?
  Data.fetch(Byte, *args)
end

#dd(*args) ⇒ Object Also known as: uint32, int32, dword

Declare a dword data



65
66
67
68
# File 'lib/rmasm/data_primitive.rb', line 65

def dd(*args)
  return DWord if args.empty?
  Data.fetch(DWord, *args)
end

#double(*args) ⇒ Object

Declare a float data



91
92
93
94
# File 'lib/rmasm/data_primitive.rb', line 91

def double(*args)
  return Double if args.empty?
  Data.fetch(Double, *args)
end

#dq(*args) ⇒ Object Also known as: uint64, int64, qword

Declare a qword data



75
76
77
78
# File 'lib/rmasm/data_primitive.rb', line 75

def dq(*args)
  return QWord if args.empty?
  Data.fetch(QWord, *args)
end

#dw(*args) ⇒ Object Also known as: uint16, int16, word

Declare a word data



55
56
57
58
# File 'lib/rmasm/data_primitive.rb', line 55

def dw(*args)
  return Word if args.empty?
  Data.fetch(Word, *args)
end

#externObject



38
39
40
41
42
# File 'lib/rmasm/extern.rb', line 38

def extern()
  instr = Extern.new
  instr.fetch
  instr
end

#float(*args) ⇒ Object

Declare a float data



85
86
87
88
# File 'lib/rmasm/data_primitive.rb', line 85

def float(*args)
  return Float if args.empty?
  Data.fetch(Float, *args)
end

#float2(*args) ⇒ Object

Declare a float2 data



97
98
99
100
# File 'lib/rmasm/data_primitive.rb', line 97

def float2(*args)
  return Float2 if args.empty?
  Data.fetch(Float2, *args)
end

#float3(*args) ⇒ Object

Declare a float3 data



103
104
105
106
# File 'lib/rmasm/data_primitive.rb', line 103

def float3(*args)
  return Float3 if args.empty?
  Data.fetch(Float3, *args)
end

#float4(*args) ⇒ Object

Declare a float4 data



109
110
111
112
# File 'lib/rmasm/data_primitive.rb', line 109

def float4(*args)
  return Float4 if args.empty?
  Data.fetch(Float4, *args)
end

#label(*args) ⇒ Object



28
29
30
# File 'lib/rmasm/label.rb', line 28

def label(*args)
  Label.define(*args)
end

#section(*sym, &block) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/rmasm/section.rb', line 135

def section(*sym, &block)
  if sym.empty?
    Section
  else
    Section.define(*sym, &block)
  end
end

#struct(*args, &block) ⇒ Object

Declare a struct

  • struct :Name (=> InheritedStruct) do … end

Global alignment for struct can be changed with :

  • struct.align = xx , this will set the align to xx for all following struct declared

  • struct.align.push xx, this will set the current alignment to xx, keeping the last alignment in a stack

  • struct.align.pop, this will restore the last alignment in the stack before the last push



77
78
79
80
81
# File 'lib/rmasm/struct.rb', line 77

def struct(*args, &block)
  # if no arg, then return the Struct class
  return Struct if args.empty?
  Struct.rmasm_define_struct(self, *args, &block)
end

#union(*args, &block) ⇒ Object

an union is a struct declared with en enclosing union



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rmasm/struct.rb', line 84

def union(*args, &block)
  # Check that the block is not nil
  if ( block.nil?)
    return Report.error(:BLOCK_BODY, "union #{args.join(',')}")
  end

  # Return the union
  struct *args do
    union do
      instance_eval &block
    end
  end
end

#use(arch) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rmasm/assembler.rb', line 26

def use(arch)
  $rmasm_list ||= {}
  $rmasm ||= nil
  # if current assembler is in the same architecture, return it
  return true if ($rmasm && $rmasm.arch == :arch)
  # if the assembler arch was already loaded, return the instance
  return true if $rmasm_list.key?(arch)

  # printf "use %p\n", self
  $rmasm_list[arch] = $rmasm = RMasm::Assembler.new(arch)

  # puts "require #{arch.to_s}_Assembler"
  arch_name = arch.to_s
  require "rmasm/#{arch_name}/#{arch_name}_assembler"

  # printf "use %p\n", self
  Object.class_eval "include(#{arch_name.capitalize}Assembler)"

  __init__()
  true
end