make elf symbols optional
and default to false. Smaller executables by at least half also add option for compiler cli
This commit is contained in:
@ -7,7 +7,9 @@ require_relative 'string_table_section'
|
||||
module Elf
|
||||
|
||||
class ObjectWriter
|
||||
def initialize( linker )
|
||||
attr_reader :text
|
||||
|
||||
def initialize( linker , options = {} )
|
||||
@linker = linker
|
||||
target = Elf::Constants::TARGET_ARM
|
||||
@object = Elf::ObjectFile.new(target)
|
||||
@ -22,7 +24,15 @@ module Elf
|
||||
assembler = Risc::TextWriter.new(@linker)
|
||||
set_text assembler.write_as_string
|
||||
|
||||
# for debug add labels for labels
|
||||
add_debug_symbols(options)
|
||||
|
||||
end
|
||||
|
||||
# for debug add labels for labels
|
||||
def add_debug_symbols(options)
|
||||
debug = options[:debug]
|
||||
return unless debug
|
||||
|
||||
@linker.assemblers.each do |asm|
|
||||
meth = asm.callable
|
||||
asm.instructions.each do |label|
|
||||
@ -34,7 +44,6 @@ module Elf
|
||||
add_symbol label , Risc::Position.get(code).at
|
||||
end
|
||||
end
|
||||
|
||||
@linker.object_positions.each do |slot , position|
|
||||
next if slot.is_a?(Parfait::BinaryCode)
|
||||
next if slot.class.name.include?("Arm")
|
||||
@ -48,8 +57,6 @@ module Elf
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :text
|
||||
|
||||
def set_text(text)
|
||||
@text.text = text
|
||||
add_symbol "_start", 0
|
||||
|
@ -5,6 +5,7 @@ require "risc/interpreter"
|
||||
class RubyXC < Thor
|
||||
class_option :integers , type: :numeric
|
||||
class_option :mesages , type: :numeric
|
||||
class_option :elf , type: :boolean
|
||||
|
||||
|
||||
desc "compile FILE" , "Compile given FILE to binary"
|
||||
@ -27,11 +28,13 @@ class RubyXC < Thor
|
||||
puts "compiling #{file}"
|
||||
|
||||
linker = ::RubyX::RubyXCompiler.new(extract_options).ruby_to_binary( ruby , :arm )
|
||||
writer = Elf::ObjectWriter.new(linker)
|
||||
elf = { debug: options[:elf] || false }
|
||||
writer = Elf::ObjectWriter.new(linker , elf)
|
||||
|
||||
outfile = file.split("/").last.gsub(".rb" , ".o")
|
||||
writer.save outfile
|
||||
|
||||
system "arm-linux-gnu-ld -N #{outfile}"
|
||||
File.delete outfile
|
||||
return outfile
|
||||
end
|
||||
|
||||
@ -92,16 +95,15 @@ class RubyXC < Thor
|
||||
|
||||
def execute(file)
|
||||
outfile = compile(file)
|
||||
system "arm-linux-gnu-ld -N #{outfile}"
|
||||
puts "Linked ok, now running #{outfile}"
|
||||
system "qemu-arm ./a.out ; echo $?"
|
||||
puts "Running #{outfile}\n\n"
|
||||
system "qemu-arm ./a.out ;echo $?"
|
||||
end
|
||||
|
||||
private
|
||||
def extract_options
|
||||
opt = { Integer: options[:integers] || 1024 ,
|
||||
Message: options[:messages] || 1024}
|
||||
return {parfait: opt}
|
||||
return {parfait: opt }
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user