Relocation and linking #
Instr.relocate offshifts every jump/branch target byoff;Program.relocatemaps it over a program. Straight-line instructions are unchanged (Instr.relocate_of_isStraight).SubAt p q base: the programpsits verbatim at addressbaseinsideq(∀ i ins, p[i]? = some ins → q[base + i]? = some ins). Lemmas for[],::,++, transitivity, and the two halves of a concatenation.shiftPc off c: the configurationcwith its program counter shifted byoff.- The relocation theorem
run_relocate: ifp.relocate offsits atoffinsideqand ak-step run ofpfromcnever leavesp's code (the program counter of every configuration before a step is< p.length), thenrun q P k (shiftPc off c) = (run p P k c).map (shiftPc off). Faults (halt, division by zero) are reproduced exactly.RunsTo.relocatetransfers bounded runs, andAtHalt.relocatetransfers the finalhalt.
Shift every jump/branch target by off; other instructions are unchanged.
Equations
- WordRAM.Instr.relocate off (WordRAM.Instr.jump l) = WordRAM.Instr.jump (l + off)
- WordRAM.Instr.relocate off (WordRAM.Instr.brLtN a b l) = WordRAM.Instr.brLtN a b (l + off)
- WordRAM.Instr.relocate off (WordRAM.Instr.brLtR a b l) = WordRAM.Instr.brLtR a b (l + off)
- WordRAM.Instr.relocate off x✝ = x✝
Instances For
Relocation does not touch straight-line instructions.
Relocate every instruction of a program.
Equations
- WordRAM.Program.relocate off p = List.map (WordRAM.Instr.relocate off) p
Instances For
Placement of a program inside a larger one #
A nonempty placed program fits inside the host.
The first half of a concatenation sits at address 0.
The second half of a concatenation sits at address p₁.length.
Placement inside a longer program obtained by prepending on the left.
Shifting the program counter #
The relocation theorem #
One step of p at c is simulated by one step of q at shiftPc off c, provided the
relocated instruction sits at the shifted address. Faults are reproduced.
Relocation. If p.relocate off sits at off inside q and the k-step run of p
from c never leaves p's code (the program counter of every configuration at which a step
is taken is < p.length), then the run of q from the shifted configuration is the shifted
run of p, faults included.
A halt of p at c is a halt of q at the shifted configuration.
A program placed at 0 with no relocation.