Skip to content

Commit

Permalink
Lean: improve handwritten support
Browse files Browse the repository at this point in the history
Adds a few miscellaneous definitions needed by the Sail model in the
Lean support file, and sets up a measure for the type of extensions so
that Lean can prove termination of `extensionEnabled`.
  • Loading branch information
ineol committed Feb 27, 2025
1 parent 8387b14 commit ba5a0b1
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions handwritten_support/RiscvExtras.lean
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

import THE_MODULE_NAME.Sail.Sail
import THE_MODULE_NAME.Defs

open Sail

def print (_ : String) : Unit := ()
def print_endline (_ : String) : Unit := ()
def print_bits (_ : String) (_ : BitVec n) : Unit := ()
def print_string (_ : String) (_ : String) : Unit := ()
def print_int (_ : String) (_ : Int) : Unit := ()
def prerr_endline (_: String) : Unit := ()
def prerr_string (_: String) : Unit := ()
def putchar {T} (_: T ) : Unit := ()
Expand Down Expand Up @@ -53,6 +55,7 @@ axiom plat_htif_tohost : Unit → Arch.pa
axiom plat_clint_base : Unit → Arch.pa
axiom plat_clint_size : Unit → Arch.pa
axiom plat_insns_per_tick : Unit → Int
axiom plat_cache_block_size_exp : Unit → Int

section Effectful

Expand All @@ -63,8 +66,8 @@ axiom plat_term_read : Unit → PreSailM RegisterType c ue String

-- Reservations
axiom load_reservation : Arch.pa → PreSailM RegisterType c ue Unit
axiom match_reservation : Arch.pa → PreSailM RegisterType c ue Bool
axiom cancel_reservation : Unit → PreSailM RegisterType c ue Bool
axiom match_reservation : Arch.pa → Bool
axiom cancel_reservation : Unit → PreSailM RegisterType c ue Unit

axiom get_16_random_bits : Unit → PreSailM RegisterType c ue (BitVec 16)

Expand Down Expand Up @@ -139,3 +142,20 @@ axiom extern_f64Eq : BitVec 64 → BitVec 64 → Unit
axiom extern_f16roundToInt : BitVec 3 → BitVec 16 → Bool → Unit
axiom extern_f32roundToInt : BitVec 3 → BitVec 32 → Bool → Unit
axiom extern_f64roundToInt : BitVec 3 → BitVec 64 → Bool → Unit

-- Termination of extensionEnabled


instance : SizeOf extension where
sizeOf x :=
match x with
| .Ext_Zihpm => 0
| .Ext_B => 0
| .Ext_C => 0
| .Ext_D => 0
| .Ext_F => 0
| .Ext_Zfh => 0
| .Ext_Zca => 1
| _ => 2

macro_rules | `(tactic| decreasing_trivial) => `(tactic| simp [sizeOf])

0 comments on commit ba5a0b1

Please sign in to comment.