Documentation

CslibFrontier.Computability.Program.Blocks

Indexed assembly of finite instruction blocks #

The assembler is independent of the source and target instruction types. Fixed block lengths provide exact prefix offsets; forward and reverse machine compilers share this construction.

def Cslib.Program.compileBlocks {α : Type u_1} {β : Type u_2} (block : ℕ → α → List β) :
ℕ → List α → List β

Concatenate compiled blocks, numbering source instructions from start.

theorem Cslib.Program.length_compileBlocks {α : Type u_1} {β : Type u_2} {block : ℕ → α → List β} {k : ℕ} {code : List α} (hblock : ∀ (pc : ℕ), ∀ i ∈ code, (block pc i).length = k) (start : ℕ) :
(compileBlocks block start code).length = k * code.length

Fixed-size blocks give a target program of length k * code.length.

theorem Cslib.Program.compileBlocks_decompose {α : Type u_1} {β : Type u_2} {block : ℕ → α → List β} {k start j : ℕ} {code : List α} {i : α} (hblock : ∀ (pc : ℕ), ∀ a ∈ code, (block pc a).length = k) (hi : code[j]? = some i) :
∃ (pre : List β) (post : List β), pre.length = k * j ∧ compileBlocks block start code = pre ++ (block (start + j) i ++ post)

An indexed block occurs after a prefix of exactly k * j target instructions.

theorem Cslib.Program.getElem?_compileBlocks {α : Type u_1} {β : Type u_2} {block : ℕ → α → List β} {k start j n : ℕ} {code : List α} {i : α} {instruction : β} (hblock : ∀ (pc : ℕ), ∀ a ∈ code, (block pc a).length = k) (hi : code[j]? = some i) (localGet : (block (start + j) i)[n]? = some instruction) :
(compileBlocks block start code)[k * j + n]? = some instruction

Fetch within a fixed-size compiled block agrees with fetching inside that block.