lib/haxor/linker.rb in haxor-0.3.0 vs lib/haxor/linker.rb in haxor-0.4.0
- old
+ new
@@ -6,11 +6,11 @@
def initialize
@cpu = Vm::Cpu::Core.new
@units = []
@tokens = []
- @labels = @cpu.labels.clone
+ @labels = {}
@stack = 4096
end
def load_unit(filename)
@units << Haxor::Compiler::Unit.load(filename)
@@ -54,12 +54,20 @@
@labels[token.label] = token
end
end
def unwind_pointers
- walk_tokens(Token::Pointer) do |token|
- fail "Label not found: #{token.label}." unless @labels.key? token.label
- token.data = @labels[token.label].absolute_addr
+ walk_tokens(Token::Cmd) do |token|
+ next unless token.imm.is_a? String
+ fail "Label not found: #{token.imm}." unless @labels.key? token.imm
+
+ token.imm = @labels[token.imm].absolute_addr
+
+ if token.opts.include? :rel_imm
+ token.imm -= token.absolute_addr + Consts::WORD_SIZE
+ end
+
+ token.imm /= Consts::WORD_SIZE if token.opts.include? :x8
end
end
def build_header
bss_size = 0