From 7047a43d9f0742e11af3c198d3fb7c20bee33581 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Sun, 19 Dec 2021 10:58:23 +0000 Subject: Define a minimal interface for working with Arm pseudocode. --- src/Helium/Data/Pseudocode.agda | 167 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 src/Helium/Data/Pseudocode.agda (limited to 'src/Helium') diff --git a/src/Helium/Data/Pseudocode.agda b/src/Helium/Data/Pseudocode.agda new file mode 100644 index 0000000..2a31055 --- /dev/null +++ b/src/Helium/Data/Pseudocode.agda @@ -0,0 +1,167 @@ +{-# OPTIONS --safe --without-K #-} + +module Helium.Data.Pseudocode where + +open import Algebra.Core +open import Data.Bool using (if_then_else_) +open import Data.Fin hiding (_+_; cast) +import Data.Fin.Properties as Finₚ +open import Data.Nat using (ℕ; zero; suc; _+_; _^_) +open import Level using (_⊔_) renaming (suc to ℓsuc) +open import Relation.Binary using (REL; Rel; Symmetric; Transitive; Decidable) +open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym) +open import Relation.Nullary using (Dec; does) +open import Relation.Nullary.Decidable + +private + map-False : ∀ {p q} {P : Set p} {Q : Set q} {P? : Dec P} {Q? : Dec Q} → (P → Q) → False Q? → False P? + map-False ⇒ f = fromWitnessFalse (λ x → toWitnessFalse f (⇒ x)) + +record RawPseudocode b₁ b₂ i₁ i₂ i₃ r₁ r₂ r₃ : Set (ℓsuc (b₁ ⊔ b₂ ⊔ i₁ ⊔ i₂ ⊔ i₃ ⊔ r₁ ⊔ r₂ ⊔ r₃)) where + infix 9 _^ᶻ_ _^ʳ_ + infix 8 _⁻¹ + infix 7 _*ᶻ_ _*ʳ_ + infix 6 -ᶻ_ -ʳ_ + infix 5 _+ᶻ_ _+ʳ_ + infix 4 _≈ᵇ_ _≟ᵇ_ _≈ᶻ_ _≟ᶻ_ _<ᶻ_ _>_ : ℤ → ℕ → ℤ + x >> n = (x div (2ℤ ^ᶻ n)) {2^n≢0 n} + + getᶻ : ℕ → ℤ → Bits 1 + getᶻ i x = if (does ((x mod (2ℤ ^ᶻ suc i)) {2^n≢0 (suc i)}