1 require 'voodoo/config'
2 require 'voodoo/generators/command_postprocessor'
5 # Class that generates ELF object files by invoking the GNU assembler on
6 # the output of a code generator that generates GNU assembly.
8 def initialize asmgenerator, extra_args
9 @asmgenerator = asmgenerator
10 @extra_args = 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 assembly 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 + '.s') do |asmfile|
34 Tempfile.open(base + '.o') do |elffile|
36 # Write assembly code to nsamfile
37 @asmgenerator.write asmfile
39 # Find out the name of the GNU assembler
40 gas = Voodoo::Config.gas_command
41 # Invoke gas on asmfile
42 command = "#{gas} #{@extra_args}" +
43 " -o #{shell_encode elffile.path}" +
44 " #{shell_encode asmfile.path}"
46 write_file_to_io elffile.path, io