repeat until no more exception
move class to where it is used
This commit is contained in:
parent
5eee79719d
commit
ce58de2671
@ -1,6 +1,4 @@
|
||||
module Risc
|
||||
class LinkException < Exception
|
||||
end
|
||||
# Assemble the object machine into a binary.
|
||||
# Assemble first to get positions, then write
|
||||
|
||||
|
@ -12,14 +12,25 @@ module Risc
|
||||
end
|
||||
|
||||
# write into the given BinaryCode instance
|
||||
# LinkException may be thrown, possibly several times
|
||||
# So repeat until it works
|
||||
def assemble( instruction )
|
||||
ok = false
|
||||
until(ok)
|
||||
begin
|
||||
assemble_all(instruction)
|
||||
ok = true
|
||||
rescue LinkException
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Go through and assemble all instructions.
|
||||
# Assembly may cause LinkException, which is caught by caller
|
||||
def assemble_all( instruction )
|
||||
@index = 1
|
||||
while(instruction)
|
||||
begin
|
||||
instruction.assemble(self)
|
||||
rescue LinkException
|
||||
instruction.assemble(self)
|
||||
end
|
||||
instruction = instruction.next
|
||||
end
|
||||
end
|
||||
@ -30,4 +41,19 @@ module Risc
|
||||
end
|
||||
end
|
||||
|
||||
# A LinkException is raised when the arm code can't fit a constant into _one_
|
||||
# instruction. This is kind of unavoidable with arm.
|
||||
#
|
||||
# Off course the problem could be fixed without the exception, but the exception
|
||||
# means all subsequent Instructions, including labels/jump targets move.
|
||||
# Thus changing jump instructions to those labels.
|
||||
# So the whole method has to be reassembled and (at least) the instructions beyond
|
||||
# repositioned. Ie a non-local problem, and so the Exception.
|
||||
#
|
||||
# Note: In the future i hope to have a more flexible system, possibly with position
|
||||
# listeners and change events. Because positions chaning is normal, not exceptional.
|
||||
#
|
||||
class LinkException < Exception
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user