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|
34 Tempfile.open(base + '.o') do |elffile|
36 # Write NASM code to nsamfile
37 @nasmgenerator.write nasmfile
39 # Find out the name of the nasm executable
40 if ENV.has_key? 'NASM'
42 elsif ENV.has_key? 'YASM'
45 nasm = Voodoo::Config.nasm_command
47 # Invoke nasm on nasmfile
48 command = "#{nasm} #{@nasm_extra_args}" +
49 " -o #{shell_encode elffile.path}" +
50 " #{shell_encode nasmfile.path}"
52 write_file_to_io elffile.path, io