Class: Daedalus::InstructionSourceFile

Inherits:
SourceFile show all
Defined in:
lib/daedalus.rb

Instance Attribute Summary

Attributes inherited from Path

#data, #path

Instance Method Summary collapse

Methods inherited from SourceFile

#autogenerate, #clean, #consider, #dependencies, #depends_on, #describe, #info, #initialize, #newer_dependencies, #object_path, #out_of_date?, #recalc_depedencies, #sha1

Methods inherited from Path

#artifacts_path, #basename, #data_path, #initialize, #save!

Constructor Details

This class inherits a constructor from Daedalus::SourceFile

Instance Method Details

#build(ctx) ⇒ Object



519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/daedalus.rb', line 519

def build(ctx)
  ctx.log.inc!

  @data[:sha1] = sha1(ctx)

  fname = File.basename path, "cpp"
  ll_path = "#{File.dirname(path)}/artifacts/#{fname}ll"

  ll_compile ctx, path, ll_path
  cxx_compile ctx, ll_path, object_path

  save!
end

#cxx_compile(ctx, source, object) ⇒ Object



508
509
510
511
512
513
514
515
516
517
# File 'lib/daedalus.rb', line 508

def cxx_compile(ctx, source, object)
  ctx.log.show "CXX", source

  flags = (ctx.cflags + ctx.cxxflags).join(" ").
    gsub(/-I\s?[^ ]*/, "").
    gsub(/-O.?/, "")
  flags << " -Oz"

  ctx.log.command "#{ctx.cxx} #{flags} -c -o #{object} #{source}"
end

#ll_compile(ctx, source, object) ⇒ Object



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/daedalus.rb', line 477

def ll_compile(ctx, source, object)
  ctx.log.show "LL", source

  flags = (ctx.cflags + ctx.cxxflags).join(" ").
    gsub(/-O.?/, "")
  flags << " -Oz"

  ctx.log.command "#{ctx.cxx} -S -emit-llvm #{flags} -c -o #{object} #{source}"

  re = %r[tail call i64 %\d+\(%"class.rubinius::State"\*( nonnull)? %state, %"struct.rubinius::CallFrame"\*( nonnull)? %call_frame, i64\*( nonnull)? %opcodes\)]

  lines = File.readlines object

  i = 0
  t = lines.size

  while i < t
    line = lines[i]
    if re =~ line
      if next_line = lines[i+1] and next_line =~ /^\s+ret\s/
        line.sub!(/tail call/, "musttail call")
      end
    end
    i += 1
  end

  File.open object, "wb" do |insn_file|
    lines.each { |l| insn_file.print l }
  end
end