-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
52 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
class Vaporware::Compiler::Assembler::ELF::Section::Shstrtab | ||
include Vaporware::Compiler::Assembler::ELF::Utils | ||
def initialize = @strtab = [] | ||
def initialize = @name = [] | ||
def build = bytes.flatten.pack("C*") | ||
def set!(name:) = @strtab << name | ||
def set!(name:) | ||
@name << set(name) | ||
self | ||
end | ||
|
||
def set(name:) = name!(name) | ||
|
||
private | ||
def bytes = [@strtab] | ||
def bytes = [@name] | ||
def name!(name) | ||
case name | ||
when String | ||
(name.match(/\A\0.+\0\z/) ? name : "\0#{name}\0").bytes | ||
when Array | ||
raise Vaporware::Compiler::Assembler::ELF::Error, "unaccepted type in Array" unless name.all? { |elem| elem.is_a?(Integer) } | ||
n = name | ||
n.unshift(0) && n.push(0) unless n.first == 0 && n.last == 0 | ||
n | ||
else | ||
raise Vaporware::Compiler::Assembler::ELF::Error, "unsupported type" unless name.then { |elem| [Integer, Array].map.all? { |c| elem.is_a?(c) } } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
class Vaporware::Compiler::Assembler::ELF | ||
class Error | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/vaporware/compiler/assembler/elf/section/test_shstrtab.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "vaporware" | ||
require "test/unit" | ||
|
||
class Vaporware::Compiler::Assembler::ELF::Section::TestShstrtab < Test::Unit::TestCase | ||
def setup = @shstrtab = Vaporware::Compiler::Assembler::ELF::Section::Shstrtab.new | ||
def test_set_values | ||
assert_equal(@shstrtab.set(name: "main"), [0, 109, 97, 105, 110, 0]) | ||
assert_equal(@shstrtab.set(name: [0, 109, 97, 105, 110, 0]), [0, 109, 97, 105, 110, 0]) | ||
end | ||
def test_alert_values | ||
assert_raise(Vaporware::Compiler::Assembler::ELF::Error) { @shstrtab.set(name: :main) } | ||
assert_raise(Vaporware::Compiler::Assembler::ELF::Error) { @shstrtab.set(name: 123) } | ||
end | ||
end |