1 require 'voodoo/config'
2 require 'voodoo/generators/command_postprocessor'
5 # Class that generates ELF object files by invoking nasm on
6 # the output of a code generator that generates NASM assembly.
8 def initialize nasmgenerator, nasm_extra_args
9 @nasmgenerator = nasmgenerator
10 @nasm_extra_args = nasm_extra_args
11 @output_file_suffix = '.o'
14 include CommandPostProcessor
16 def output_file_name input_name
17 input_name.sub(/\.voo$/, '') + @output_file_suffix
20 def output_file_suffix
24 # Writes the generated code to the given IO handle
26 # Create temporary file to write NASM code to
27 if io.respond_to? :path
28 base = File.basename(io.path).sub(/([^.]*).*/, "\\1")
30 base = self.class.name
33 Tempfile.open(base + '.asm') do |nasmfile|
35 Tempfile.open(base + '.o') do |elffile|
38 # Write NASM code to nasmfile
39 @nasmgenerator.write nasmfile
41 # Find out the name of the nasm executable
42 if ENV.has_key? 'NASM'
44 elsif ENV.has_key? 'YASM'
47 nasm = Voodoo::Config.nasm_command
49 # Invoke nasm on nasmfile
50 command = "#{nasm} #{@nasm_extra_args}" +
51 " -o #{shell_encode elffile.path}" +
52 " #{shell_encode nasmfile.path}"
54 write_file_to_io elffile.path, io
56 raise "Command (#{command}) failed " +
57 " with status #{$?.exitstatus}"