-
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
16 changed files
with
104 additions
and
60 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
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,6 +1,8 @@ | ||
class Vaporware::Compiler::Assembler::ELF::Section::Data | ||
|
||
include Vaporware::Compiler::Assembler::ELF::Utils | ||
def initialize = nil | ||
def build = bytes.flatten.pack("C*") | ||
def set! = self | ||
private | ||
def bytes = [] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Vaporware::Compiler::Assembler::ELF::Section::Null | ||
include Vaporware::Compiler::Assembler::ELF::Utils | ||
def initialize = nil | ||
def build = bytes.flatten.pack("C*") | ||
def set! = self | ||
private def bytes = [] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
class Vaporware::Compiler::Assembler::ELF::Section::Strtab | ||
|
||
class Vaporware::Compiler::Assembler::ELF::Section::Shstrtab | ||
include Vaporware::Compiler::Assembler::ELF::Utils | ||
def initialize = @strtab = [] | ||
def build = bytes.flatten.pack("C*") | ||
def set!(name:) = @strtab << name | ||
private | ||
def bytes = [] | ||
def bytes = [@strtab] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class Vaporware::Compiler::Assembler::ELF::Section::Strtab | ||
include Vaporware::Compiler::Assembler::ELF::Utils | ||
def initialize(names = "\0main\0") = @names = names | ||
def build = @names.bytes.pack("C*") | ||
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
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,22 @@ | ||
require_relative "section" | ||
|
||
class Vaporware::Compiler::Assembler::ELF::Sections | ||
attr_reader %i|null text data bss note symtab strtab shsymtab| | ||
ATTRIBUTES = %i|null text data bss note symtab strtab shstrtab| | ||
attr_reader *ATTRIBUTES | ||
def initialize | ||
@null, @text, @data, @bss, @note, @symtab, @strtab, @shsymtab = %i|null text data bss note symtab strtab shsymtab|.map { |cn| Section.new(type: cn) } | ||
@null = Section.new(type: :null) | ||
@text = Section.new(type: :text) | ||
@data = Section.new(type: :data) | ||
@bss = Section.new(type: :bss) | ||
@note = Section.new(type: :note) | ||
@symtab = Section.new(type: :symtab) | ||
@strtab = Section.new(type: :strtab) | ||
@shstrtab = Section.new(type: :shstrtab) | ||
end | ||
|
||
def each(&block) | ||
ATTRIBUTES.each do |t| | ||
yield t | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Vaporware::Compiler::Assembler::ELF::Utils | ||
def build = bytes.flatten.pack("C*") | ||
def size = build.bytesize | ||
|
||
private | ||
|
||
def align(val, bytes) = (val << 0 until val.size % bytes == 0) | ||
def bytes = (raise Vaporware::Error, "should be implement this class") | ||
def num2bytes(val, bytes) = ("%0#{bytes}x" % val).scan(/.{1,2}/).map { |v| v.to_i(16) }.reverse | ||
def check(val, bytes) = (val.is_a?(Array) && val.all? { |v| v.is_a?(Integer) } && val.size == bytes) || val.is_a?(Integer) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Vaporware::Compiler::Assembler::ELF::Section::Null | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Vaporware::Utils | ||
def build: () -> String | ||
private def align: (Array[Integer], Integer) -> void | ||
private def check: (Array[Integer]?, Integer) -> bool | ||
private def num2bytes: (Integer?, Integer) -> Array[Integer] | ||
private def bytes: () -> Array[Array[Integer]?] | ||
end |