
inc = ARGV.shift || '../cygwin/vm.inc'
asm = ARGV.shift || '../cygwin/vm.asm.txt'

inc = File.readlines(inc)
asm = File.readlines(asm)

in_inc    = false
asm_store = Array.new(inc.size){|i| ''}
asm_lines = ''
asm_label = nil
line_no   = 0

asm.each_with_index{|line, idx|
  if /\.stabs	"(.+)"/ =~ line
    if $1 == 'vm.inc'
      in_inc = true
    else
      in_inc = false
    end
  elsif /^(LM|LBE|LBB)\d+/ =~ line
    # skip
  elsif in_inc == true
    if /^\.stabn 68,(\d+),(\d+),/ =~ line
      
      if line_no
        asm_store[line_no] << asm_lines
        asm_lines = ''
      end
      
      line_no = $2.to_i
      
    elsif /^(L\d+)/ =~ line
      l = line
      if /\.stabn/ =~ asm[idx+2]
        # commit
        asm_store[line_no] << asm_lines
        asm_lines = l
        asm_label = l
        line_no = nil
      else
        asm_lines << line
      end
    else
      asm_lines << line
    end
  end
}

inc.each_with_index{|line, i|
  i+=1
  puts line
  if asm_store[i] && asm_store[i].size > 0
    puts "-- #{'%04d' % i} ------------------------------------"
    asm_store[i].map{|ls|
      puts ls
    }.join("--* \n")
    puts '--------------------------------------------'
  end
}





