class Daedalus::InstructionSourceFile

Public Instance Methods

build(ctx) click to toggle source
    # File lib/daedalus.rb
518 def build(ctx)
519   ctx.log.inc!
520 
521   @data[:sha1] = sha1(ctx)
522 
523   fname = File.basename path, "cpp"
524   ll_path = "#{File.dirname(path)}/artifacts/#{fname}ll"
525 
526   ll_compile ctx, path, ll_path
527   cxx_compile ctx, ll_path, object_path
528 
529   save!
530 end
cxx_compile(ctx, source, object) click to toggle source
    # File lib/daedalus.rb
507 def cxx_compile(ctx, source, object)
508   ctx.log.show "CXX", source
509 
510   flags = (ctx.cflags + ctx.cxxflags).join(" ").
511     gsub(/-I\s?[^ ]*/, "").
512     gsub(/-O.?/, "")
513   flags << " -Oz"
514 
515   ctx.log.command "#{ctx.cxx} #{flags} -c -o #{object} #{source}"
516 end
ll_compile(ctx, source, object) click to toggle source
    # File lib/daedalus.rb
476 def ll_compile(ctx, source, object)
477   ctx.log.show "LL", source
478 
479   flags = (ctx.cflags + ctx.cxxflags).join(" ").
480     gsub(/-O.?/, "")
481   flags << " -Oz"
482 
483   ctx.log.command "#{ctx.cxx} -S -emit-llvm #{flags} -c -o #{object} #{source}"
484 
485   re = %r[tail call i64 %\d+\(%"class.rubinius::State"\*( nonnull)? %state, %"struct.rubinius::CallFrame"\*( nonnull)? %call_frame, i64\*( nonnull)? %opcodes\)]
486 
487   lines = File.readlines object
488 
489   i = 0
490   t = lines.size
491 
492   while i < t
493     line = lines[i]
494     if re =~ line
495       if next_line = lines[i+1] and next_line =~ /^\s+ret\s/
496         line.sub!(/tail call/, "musttail call")
497       end
498     end
499     i += 1
500   end
501 
502   File.open object, "wb" do |insn_file|
503     lines.each { |l| insn_file.print l }
504   end
505 end