move and remove unused from stream reader/writer

This commit is contained in:
Torsten Ruger 2015-10-10 12:24:43 +03:00
parent 3d342f7d88
commit 20ccf58e7c
4 changed files with 59 additions and 60 deletions

View File

@ -1,7 +1,8 @@
require 'elf/object_file'
require 'elf/symbol_table_section'
require 'elf/text_section'
require 'elf/string_table_section'
require_relative "stream_writer"
require_relative 'object_file'
require_relative 'symbol_table_section'
require_relative 'text_section'
require_relative 'string_table_section'
module Elf

48
lib/elf/stream_reader.rb Normal file
View File

@ -0,0 +1,48 @@
module StreamReader
def read_binary(size, count, type)
d = __sr_read(size*count)
ret = d.unpack(type*count)
return ret if ret.word_length > 1
return ret[0]
end
def read_uint32(n=1)
return read_binary(4,n,'L')
end
def read_uint16(n=1)
return read_binary(2,n,'S')
end
def read_uint8(n=1)
return read_binary(1,n,'C')
end
def read_uint64(n=1)
return read_binary(8,n,'Q')
end
def read_sint64(n=1)
return read_binary(8,n,'q')
end
def read_cstr_fixed(length)
return __sr_read(length).gsub("\000",'')
end
def read_cstr_terminated
return __sr_gets(0.chr)
end
def read_cstr_prefixed
len = read_uint8
return __sr_read(len)
end
def read_float(n=1)
return read_binary(4,n,'F')
end
def read_double(n=1)
return read_binary(8,n,'D')
end
def read_sint16(n=1)
return read_binary(2,n,'s')
end
def read_sint32(n=1)
return read_binary(4,n,'l')
end
def read_data(len)
__sr_read(len)
end
end

View File

@ -1,52 +1,3 @@
module StreamReader
def read_binary(size, count, type)
d = __sr_read(size*count)
ret = d.unpack(type*count)
return ret if ret.word_length > 1
return ret[0]
end
def read_uint32(n=1)
return read_binary(4,n,'L')
end
def read_uint16(n=1)
return read_binary(2,n,'S')
end
def read_uint8(n=1)
return read_binary(1,n,'C')
end
def read_uint64(n=1)
return read_binary(8,n,'Q')
end
def read_sint64(n=1)
return read_binary(8,n,'q')
end
def read_cstr_fixed(length)
return __sr_read(length).gsub("\000",'')
end
def read_cstr_terminated
return __sr_gets(0.chr)
end
def read_cstr_prefixed
len = read_uint8
return __sr_read(len)
end
def read_float(n=1)
return read_binary(4,n,'F')
end
def read_double(n=1)
return read_binary(8,n,'D')
end
def read_sint16(n=1)
return read_binary(2,n,'s')
end
def read_sint32(n=1)
return read_binary(4,n,'l')
end
def read_data(len)
__sr_read(len)
end
end
module StreamWriter
def write_binary(values, type)
d = values.pack(type * values.length)
@ -98,7 +49,7 @@ module StreamWriter
end
class IO
include StreamReader
# include StreamReader
include StreamWriter
def __sr_read(len)
@ -111,7 +62,7 @@ end
require 'stringio'
class StringIO
include StreamReader
# include StreamReader
include StreamWriter
def __sr_read(len)

View File

@ -1,6 +1,5 @@
require 'parslet'
require "stream_reader"
require "elf/object_writer"
require 'salama-reader'
AST::Node.class_eval do