Adjust 'Program' to have a graph and basic blocks
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
ba1c9b3ec8
commit
4fe0d147fa
|
@ -5,10 +5,11 @@ open import Data.Nat.Properties using (m≤n⇒m≤n+o; ≤-reflexive; +-assoc;
|
||||||
open import Data.Integer using (ℤ; +_) renaming (_+_ to _+ᶻ_; _-_ to _-ᶻ_)
|
open import Data.Integer using (ℤ; +_) renaming (_+_ to _+ᶻ_; _-_ to _-ᶻ_)
|
||||||
open import Data.String using (String) renaming (_≟_ to _≟ˢ_)
|
open import Data.String using (String) renaming (_≟_ to _≟ˢ_)
|
||||||
open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂)
|
open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂)
|
||||||
|
open import Data.Product.Properties using (≡-dec)
|
||||||
open import Data.Vec using (Vec; foldr; lookup; _∷_; []; _++_; cast)
|
open import Data.Vec using (Vec; foldr; lookup; _∷_; []; _++_; cast)
|
||||||
open import Data.Vec.Properties using (++-assoc; ++-identityʳ; lookup-++ˡ; lookup-cast₁; cast-sym)
|
open import Data.Vec.Properties using (++-assoc; ++-identityʳ; lookup-++ˡ; lookup-cast₁; cast-sym)
|
||||||
open import Data.Vec.Relation.Binary.Equality.Cast using (cast-is-id)
|
open import Data.Vec.Relation.Binary.Equality.Cast using (cast-is-id)
|
||||||
open import Data.List using ([]; _∷_; List) renaming (foldr to foldrˡ; map to mapˡ; _++_ to _++ˡ_)
|
open import Data.List using ([]; _∷_; List) renaming (foldr to foldrˡ; map to mapˡ; filter to filterᶠ; _++_ to _++ˡ_)
|
||||||
open import Data.List.Properties using () renaming (++-assoc to ++ˡ-assoc; map-++ to mapˡ-++ˡ; ++-identityʳ to ++ˡ-identityʳ)
|
open import Data.List.Properties using () renaming (++-assoc to ++ˡ-assoc; map-++ to mapˡ-++ˡ; ++-identityʳ to ++ˡ-identityʳ)
|
||||||
open import Data.List.Membership.Propositional as MemProp using () renaming (_∈_ to _∈ˡ_)
|
open import Data.List.Membership.Propositional as MemProp using () renaming (_∈_ to _∈ˡ_)
|
||||||
open import Data.List.Membership.Propositional.Properties using () renaming (∈-++⁺ʳ to ∈ˡ-++⁺ʳ)
|
open import Data.List.Membership.Propositional.Properties using () renaming (∈-++⁺ʳ to ∈ˡ-++⁺ʳ)
|
||||||
|
@ -19,11 +20,12 @@ open import Data.Fin using (Fin; suc; zero; fromℕ; inject₁; inject≤; _↑
|
||||||
open import Data.Fin.Properties using (suc-injective) renaming (cast-is-id to castᶠ-is-id)
|
open import Data.Fin.Properties using (suc-injective) renaming (cast-is-id to castᶠ-is-id)
|
||||||
open import Relation.Binary.PropositionalEquality as Eq using (subst; cong; _≡_; sym; trans; refl)
|
open import Relation.Binary.PropositionalEquality as Eq using (subst; cong; _≡_; sym; trans; refl)
|
||||||
open import Relation.Nullary using (¬_)
|
open import Relation.Nullary using (¬_)
|
||||||
|
open import Relation.Nullary.Decidable.Core using (does)
|
||||||
open import Function using (_∘_)
|
open import Function using (_∘_)
|
||||||
open Eq.≡-Reasoning
|
open Eq.≡-Reasoning
|
||||||
|
|
||||||
open import Lattice
|
open import Lattice
|
||||||
open import Utils using (Unique; Unique-map; empty; push; x∈xs⇒fx∈fxs; _⊗_; _,_)
|
open import Utils using (Unique; Unique-map; push; x∈xs⇒fx∈fxs; _⊗_; _,_) renaming (empty to emptyᵘ; proj₁ to proj₁'; proj₂ to proj₂')
|
||||||
|
|
||||||
data Expr : Set where
|
data Expr : Set where
|
||||||
_+_ : Expr → Expr → Expr
|
_+_ : Expr → Expr → Expr
|
||||||
|
@ -104,6 +106,13 @@ module Graphs where
|
||||||
nodes : Vec (List BasicStmt) size
|
nodes : Vec (List BasicStmt) size
|
||||||
edges : List Edge
|
edges : List Edge
|
||||||
|
|
||||||
|
empty : Graph
|
||||||
|
empty = record
|
||||||
|
{ size = 0
|
||||||
|
; nodes = []
|
||||||
|
; edges = []
|
||||||
|
}
|
||||||
|
|
||||||
↑ˡ-Edge : ∀ {n} → (Fin n × Fin n) → ∀ m → (Fin (n +ⁿ m) × Fin (n +ⁿ m))
|
↑ˡ-Edge : ∀ {n} → (Fin n × Fin n) → ∀ m → (Fin (n +ⁿ m) × Fin (n +ⁿ m))
|
||||||
↑ˡ-Edge (idx₁ , idx₂) m = (idx₁ ↑ˡ m , idx₂ ↑ˡ m)
|
↑ˡ-Edge (idx₁ , idx₂) m = (idx₁ ↑ˡ m , idx₂ ↑ˡ m)
|
||||||
|
|
||||||
|
@ -471,7 +480,7 @@ private
|
||||||
z≢mapsfs (f ∷ fs') = z≢sf f ∷ z≢mapsfs fs'
|
z≢mapsfs (f ∷ fs') = z≢sf f ∷ z≢mapsfs fs'
|
||||||
|
|
||||||
indices : ∀ (n : ℕ) → Σ (List (Fin n)) Unique
|
indices : ∀ (n : ℕ) → Σ (List (Fin n)) Unique
|
||||||
indices 0 = ([] , empty)
|
indices 0 = ([] , emptyᵘ)
|
||||||
indices (suc n') =
|
indices (suc n') =
|
||||||
let
|
let
|
||||||
(inds' , unids') = indices n'
|
(inds' , unids') = indices n'
|
||||||
|
@ -487,13 +496,29 @@ private
|
||||||
|
|
||||||
-- For now, just represent the program and CFG as one type, without branching.
|
-- For now, just represent the program and CFG as one type, without branching.
|
||||||
record Program : Set where
|
record Program : Set where
|
||||||
|
open Graphs
|
||||||
|
|
||||||
field
|
field
|
||||||
length : ℕ
|
prog : Stmt
|
||||||
stmts : Vec Stmt length
|
|
||||||
|
private
|
||||||
|
buildResult = Construction.buildCfg prog empty
|
||||||
|
|
||||||
|
graph : Graph
|
||||||
|
graph = proj₁ buildResult
|
||||||
|
|
||||||
|
State : Set
|
||||||
|
State = Graph.Index graph
|
||||||
|
|
||||||
|
initialState : State
|
||||||
|
initialState = proj₁' (proj₁ (proj₂ buildResult))
|
||||||
|
|
||||||
|
finalState : State
|
||||||
|
finalState = proj₂' (proj₁ (proj₂ buildResult))
|
||||||
|
|
||||||
private
|
private
|
||||||
vars-Set : StringSet
|
vars-Set : StringSet
|
||||||
vars-Set = Stmts-vars stmts
|
vars-Set = Stmt-vars prog
|
||||||
|
|
||||||
vars : List String
|
vars : List String
|
||||||
vars = to-Listˢ vars-Set
|
vars = to-Listˢ vars-Set
|
||||||
|
@ -501,20 +526,17 @@ record Program : Set where
|
||||||
vars-Unique : Unique vars
|
vars-Unique : Unique vars
|
||||||
vars-Unique = proj₂ vars-Set
|
vars-Unique = proj₂ vars-Set
|
||||||
|
|
||||||
State : Set
|
|
||||||
State = Fin length
|
|
||||||
|
|
||||||
states : List State
|
states : List State
|
||||||
states = proj₁ (indices length)
|
states = proj₁ (indices (Graph.size graph))
|
||||||
|
|
||||||
states-complete : ∀ (s : State) → s ∈ˡ states
|
states-complete : ∀ (s : State) → s ∈ˡ states
|
||||||
states-complete = indices-complete length
|
states-complete = indices-complete (Graph.size graph)
|
||||||
|
|
||||||
states-Unique : Unique states
|
states-Unique : Unique states
|
||||||
states-Unique = proj₂ (indices length)
|
states-Unique = proj₂ (indices (Graph.size graph))
|
||||||
|
|
||||||
code : State → Stmt
|
code : State → List BasicStmt
|
||||||
code = lookup stmts
|
code st = graph [ st ]
|
||||||
|
|
||||||
-- vars-complete : ∀ {k : String} (s : State) → k ∈ᵇ (code s) → k ∈ˡ vars
|
-- vars-complete : ∀ {k : String} (s : State) → k ∈ᵇ (code s) → k ∈ˡ vars
|
||||||
-- vars-complete {k} s = ∈⇒∈-Stmts-vars {length} {k} {stmts} {s}
|
-- vars-complete {k} s = ∈⇒∈-Stmts-vars {length} {k} {stmts} {s}
|
||||||
|
@ -522,14 +544,10 @@ record Program : Set where
|
||||||
_≟_ : IsDecidable (_≡_ {_} {State})
|
_≟_ : IsDecidable (_≡_ {_} {State})
|
||||||
_≟_ = _≟ᶠ_
|
_≟_ = _≟ᶠ_
|
||||||
|
|
||||||
-- Computations for incoming and outgoing edges will have to change too
|
_≟ᵉ_ : IsDecidable (_≡_ {_} {Graph.Edge graph})
|
||||||
-- when we support branching etc.
|
_≟ᵉ_ = ≡-dec _≟_ _≟_
|
||||||
|
|
||||||
|
open import Data.List.Membership.DecPropositional _≟ᵉ_ using () renaming (_∈?_ to _∈ˡ?_)
|
||||||
|
|
||||||
incoming : State → List State
|
incoming : State → List State
|
||||||
incoming
|
incoming idx = filterᶠ (λ idx' → (idx' , idx) ∈ˡ? (Graph.edges graph)) states
|
||||||
with length
|
|
||||||
... | 0 = (λ ())
|
|
||||||
... | suc n' = (λ
|
|
||||||
{ zero → []
|
|
||||||
; (suc f') → (inject₁ f') ∷ []
|
|
||||||
})
|
|
||||||
|
|
|
@ -72,3 +72,9 @@ data Pairwise {a} {b} {c} {A : Set a} {B : Set b} (P : A → B → Set c) : List
|
||||||
infixr 2 _⊗_
|
infixr 2 _⊗_
|
||||||
data _⊗_ {a p q} {A : Set a} (P : A → Set p) (Q : A → Set q) : A → Set (a ⊔ℓ p ⊔ℓ q) where
|
data _⊗_ {a p q} {A : Set a} (P : A → Set p) (Q : A → Set q) : A → Set (a ⊔ℓ p ⊔ℓ q) where
|
||||||
_,_ : ∀ {val : A} → P val → Q val → (P ⊗ Q) val
|
_,_ : ∀ {val : A} → P val → Q val → (P ⊗ Q) val
|
||||||
|
|
||||||
|
proj₁ : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} {a : A} → (P ⊗ Q) a → P a
|
||||||
|
proj₁ (v , _) = v
|
||||||
|
|
||||||
|
proj₂ : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} {a : A} → (P ⊗ Q) a → Q a
|
||||||
|
proj₂ (_ , v) = v
|
||||||
|
|
Loading…
Reference in New Issue
Block a user