mirror of
https://github.com/samsonjs/compiler.git
synced 2026-04-27 14:57:45 +00:00
[CHANGED] updated comments, removed some unnecessary code
This commit is contained in:
parent
a7a30b329a
commit
1877d7e4d7
1 changed files with 27 additions and 17 deletions
|
|
@ -18,11 +18,6 @@ module Assembler
|
||||||
@data = [] # Blobs of data that appear at the end of the file.
|
@data = [] # Blobs of data that appear at the end of the file.
|
||||||
# (text, data, symtab, ...)
|
# (text, data, symtab, ...)
|
||||||
@current_segment = nil # An alias for the last defined segment.
|
@current_segment = nil # An alias for the last defined segment.
|
||||||
|
|
||||||
# Leave room for __PAGEZERO, a single 0x1000 (4kb) page at 0x0. The
|
|
||||||
# __TEXT segment starts at 0x1000 and contains mach headers and load
|
|
||||||
# commands.
|
|
||||||
@text_offset = 0x1000
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -231,12 +226,15 @@ module Assembler
|
||||||
# TODO sanity checks, e.g. assert(@header[:ncmds] == @load_command.size)
|
# TODO sanity checks, e.g. assert(@header[:ncmds] == @load_command.size)
|
||||||
# ... perhaps an option to recalculate such data as well.
|
# ... perhaps an option to recalculate such data as well.
|
||||||
|
|
||||||
|
# Now that we have all the pieces of the file defined we can calculate
|
||||||
|
# the file offsets of segments and sections.
|
||||||
recalculate_offsets
|
recalculate_offsets
|
||||||
|
|
||||||
|
|
||||||
# |------------------|
|
# |------------------|
|
||||||
# | Mach Header |
|
# | Mach Header | Part 1
|
||||||
# |------------------|
|
# |------------------|
|
||||||
# | Segment 1 |
|
# | Segment 1 | Part 2
|
||||||
# | Section 1 | ---
|
# | Section 1 | ---
|
||||||
# | Section 2 | --|--
|
# | Section 2 | --|--
|
||||||
# | ... | | |
|
# | ... | | |
|
||||||
|
|
@ -247,16 +245,23 @@ module Assembler
|
||||||
# | ... | | |
|
# | ... | | |
|
||||||
# | [Symtab cmd] | | |
|
# | [Symtab cmd] | | |
|
||||||
# |------------------| | |
|
# |------------------| | |
|
||||||
# | Section data 1 | <-- |
|
# | Section data 1 | <-- | Part 3
|
||||||
# | Section data 2 | <----
|
# | Section data 2 | <----
|
||||||
# | ... |
|
# | ... |
|
||||||
# | [Symtab data] |
|
# | [Symtab data] |
|
||||||
# |------------------|
|
# |------------------|
|
||||||
|
|
||||||
|
###################################
|
||||||
|
# Mach-O file Part 1: Mach Header #
|
||||||
|
###################################
|
||||||
|
|
||||||
# dump the mach header
|
|
||||||
obj = @header.serialize
|
obj = @header.serialize
|
||||||
|
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
# Mach-O file Part 2: Load Commands #
|
||||||
|
#####################################
|
||||||
|
|
||||||
# dump each load command (which include the section headers under them)
|
# dump each load command (which include the section headers under them)
|
||||||
obj += @load_commands.map do |cmd|
|
obj += @load_commands.map do |cmd|
|
||||||
sects = @sections[cmd[:segname]] rescue []
|
sects = @sections[cmd[:segname]] rescue []
|
||||||
|
|
@ -265,19 +270,24 @@ module Assembler
|
||||||
end
|
end
|
||||||
end.join
|
end.join
|
||||||
|
|
||||||
# and finally dump the blobs at the end
|
|
||||||
|
###################################
|
||||||
|
# Mach-O file Part 3: Binary data #
|
||||||
|
###################################
|
||||||
|
|
||||||
obj += @data.join
|
obj += @data.join
|
||||||
|
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Update the file offsets in SegmentCommand, SymtabCommand, and Section structs.
|
# Update the file offsets in segments and sections.
|
||||||
|
|
||||||
def recalculate_offsets
|
def recalculate_offsets
|
||||||
|
|
||||||
# Maintain the offset into the the file. This is used to update
|
# Maintain the offset into the the file on disk. This is used
|
||||||
# the various structures.
|
# to update the various structures.
|
||||||
offset = @header.bytesize
|
offset = @header.bytesize
|
||||||
|
|
||||||
# First pass over load commands. Most sizes are filled in here.
|
# First pass over load commands. Most sizes are filled in here.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue