Class: RMasm::Assembler

Inherits:
Object show all
Includes:
Enumerable, DirectiveContainer
Defined in:
lib/rmasm/assembler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DirectiveContainer

#<<, #add_directive_core, #container_block_begin, #container_block_end, #init_container, #parent, #parent=

Constructor Details

#initialize(arch) ⇒ Assembler

Returns a new instance of Assembler.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rmasm/assembler.rb', line 70

def initialize(arch)
  @arch = arch;
  @registers = Registers.new
  @structures = StructManager.instance
  @errors = []
  @sections = SectionManager.new

  # Object.const_set(:RMasmScope, Class.new)

  @directive_list = []

  @@file_includes ||= []

  init_container
  @context = self
end

Instance Attribute Details

#archObject (readonly)

Returns the value of attribute arch.



57
58
59
# File 'lib/rmasm/assembler.rb', line 57

def arch
  @arch
end

#contextObject

Returns the value of attribute context.



63
64
65
# File 'lib/rmasm/assembler.rb', line 63

def context
  @context
end

#directive_listObject (readonly)

Returns the value of attribute directive_list.



62
63
64
# File 'lib/rmasm/assembler.rb', line 62

def directive_list
  @directive_list
end

#errorsObject (readonly)

Returns the value of attribute errors.



60
61
62
# File 'lib/rmasm/assembler.rb', line 60

def errors
  @errors
end

#inside_struct_defObject

Returns the value of attribute inside_struct_def.



64
65
66
# File 'lib/rmasm/assembler.rb', line 64

def inside_struct_def
  @inside_struct_def
end

#registersObject (readonly)

Returns the value of attribute registers.



58
59
60
# File 'lib/rmasm/assembler.rb', line 58

def registers
  @registers
end

#sectionsObject (readonly)

Returns the value of attribute sections.



61
62
63
# File 'lib/rmasm/assembler.rb', line 61

def sections
  @sections
end

#structuresObject (readonly)

Returns the value of attribute structures.



59
60
61
# File 'lib/rmasm/assembler.rb', line 59

def structures
  @structures
end

Class Method Details

.file_includesObject



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

def self.file_includes()
  @@file_includes ||= []
end

Instance Method Details

#accept(directive) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/rmasm/assembler.rb', line 114

def accept(directive)
  case directive.id
    when :struct, :section
      :process
    else
      :reject
  end
end

#add_directive(arg) ⇒ Object

def include_rasm_file(file)

  begin
    filename = "./" + file
    Assembler.file_includes << filename

    scope_binding = RMasmScope.class_eval "binding"
    eval(File.read(filename), scope_binding, filename)
    # owner.instance_eval(File.read(filename), filename)
    Assembler.file_includes.pop
  rescue Exception => exp
    is_include_ok = false
    RMasm::Report.error(exp)
    raise exp
  end
end


139
140
141
# File 'lib/rmasm/assembler.rb', line 139

def add_directive(arg)
  directive_list << arg
end

#eachObject



87
88
89
# File 'lib/rmasm/assembler.rb', line 87

def each
  directive_list.each {|item| yield item }
end

#reportObject



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

def report()
  Report
end

#ruby(&block) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rmasm/assembler.rb', line 95

def ruby(&block)
  if block.nil?
    return Report.error(:BLOCK_BODY, "asm.ruby")
  end
  result = nil
  begin
    Symbol.remove_modifier_hook
    result = block.call
  rescue Exception => exp
    Symbol.install_modifier_hook
    if @@file_includes.empty?
      Report.error(exp)
    end
    raise exp
  end
  Symbol.install_modifier_hook
  result
end