max_stars_repo_path stringlengths 4 261 | max_stars_repo_name stringlengths 6 106 | max_stars_count int64 0 38.8k | id stringlengths 1 6 | text stringlengths 7 1.05M |
|---|---|---|---|---|
sim/asm/fn11.asm | nanamake/avr_cpu | 2 | 24964 | <reponame>nanamake/avr_cpu
;-------------------
; test for ld/st
;-------------------
.def xl = r26
.def xh = r27
.def yl = r28
.def yh = r29
.def zl = r30
.def zh = r31
;-------------------
ldi r16,0xff
ldi r24,0x10
mov r7 ,r16
mov r8 ,r24
ldi r16,0x20
ldi r24,0x30
ldi xh,0x01
ldi xl,0x00
st x ,r7
ldi xl,0x01
st x ,r8
ldi xl,0x02
st x ,r16
ldi xl,0x03
st x ,r24
;-------------------
ldi xh,0x01
ldi xl,0x00
ld r6 ,x+
ld r9 ,x+
ld r17,x+
ld r25,x+
dec r6
inc r9
inc r17
inc r25
st x+,r6
st x+,r9
st x+,r17
st x+,r25
;-------------------
ldi yh,0x01
ldi yl,0x04
ld r5 ,y+
ld r10,y+
ld r18,y+
ld r24,y+
dec r5
inc r10
inc r18
inc r24
st y+,r5
st y+,r10
st y+,r18
st y+,r24
;-------------------
ldi zh,0x01
ldi zl,0x08
ld r4 ,z+
ld r11,z+
ld r19,z+
ld r25,z+
dec r4
inc r11
inc r19
inc r25
st z+,r4
st z+,r11
st z+,r19
st z+,r25
;-------------------
ldi xh,0x01
ldi xl,0x10
ld r24,-x
ld r20,-x
ld r12,-x
ld r3 ,-x
inc r24
inc r20
inc r12
dec r3
ldi xh,0x01
ldi xl,0x20
st -x,r24
st -x,r20
st -x,r12
st -x,r3
;-------------------
ldi yh,0x01
ldi yl,0x20
ld r25,-y
ld r21,-y
ld r13,-y
ld r2 ,-y
inc r25
inc r21
inc r13
dec r2
st -y,r25
st -y,r21
st -y,r13
st -y,r2
;-------------------
ldi zh,0x01
ldi zl,0x1c
ld r24,-z
ld r22,-z
ld r14,-z
ld r1 ,-z
inc r24
inc r22
inc r14
dec r1
st -z,r24
st -z,r22
st -z,r14
st -z,r1
;-------------------
ldi xh ,0x01
ldi xl ,0x17
ld r25,x
ldi xl ,0x16
ld r23,x
ldi xl ,0x15
ld r15,x
ldi xl ,0x14
ld r0 ,x
inc r25
inc r23
inc r15
dec r0
st -x,r25
st -x,r23
st -x,r15
st -x,r0
;-------------------
ldi zh,0x01
ldi zl,0x20
st z+,r0
st z+,r1
st z+,r2
st z+,r3
st z+,r4
st z+,r5
st z+,r6
st z+,r7
st z+,r8
st z+,r9
st z+,r10
st z+,r11
st z+,r12
st z+,r13
st z+,r14
st z+,r15
st z+,r16
st z+,r17
st z+,r18
st z+,r19
st z+,r20
st z+,r21
st z+,r22
st z+,r23
st z+,r24
st z+,r25
st z+,r26
st z+,r27
st z+,r28
st z+,r29
st z ,r30
ldi zl,0x3f
st z ,r31
;-------------------
ldi r16,0xff
sts 0xffff,r16
halt:
rjmp halt
|
src/openapi-streams.ads | mgrojo/swagger-ada | 0 | 14092 | -----------------------------------------------------------------------
-- openapi-streams -- Stream operations
-- Copyright (C) 2017, 2020 <NAME>
-- Written by <NAME> (<EMAIL>)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Serialize.IO;
-- == Streams ==
-- The <tt>Swagger.Streams</tt> package provides operations to manage data streams
-- in order to serialize and deserialize the data either in JSON or in XML.
package OpenAPI.Streams is
subtype Output_Stream is Util.Serialize.IO.Output_Stream;
type Output_Stream_Access is access all Output_Stream'Class;
-- Serialize a list of strings in the stream.
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in OpenAPI.UString_Vectors.Vector);
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in OpenAPI.Nullable_UString_Vectors.Vector);
-- Serialize a long value.
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in OpenAPI.Long);
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in OpenAPI.Nullable_Long);
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in OpenAPI.UString);
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in OpenAPI.Nullable_UString);
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in Integer_Map);
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in Nullable_Integer_Map);
procedure Serialize (Stream : in out Output_Stream'Class;
Name : in String;
Value : in Object_Map);
-- Extract an integer value stored under the given name.
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Boolean);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Nullable_Boolean);
-- Extract an integer value stored under the given name.
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Integer);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Nullable_Integer);
-- Extract an integer value stored under the given name.
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Long);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Nullable_Long);
-- Extract an integer value stored under the given name.
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out UString);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Nullable_UString);
-- Extract an integer value stored under the given name.
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Value_Type);
-- Extract an integer value stored under the given name.
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Value_Array_Type);
-- Extract an integer value stored under the given name.
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Ada.Calendar.Time);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Nullable_Date);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out UString_Vectors.Vector);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Nullable_UString_Vectors.Vector);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Integer_Map);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Nullable_Integer_Map);
procedure Deserialize (From : in OpenAPI.Value_Type;
Name : in String;
Value : out Object_Map);
end OpenAPI.Streams;
|
.config/alfred/Alfred.alfredpreferences/workflows/user.workflow.D27B6AD4-C1F8-4105-8C0B-0E52489E70FE/app_Webkit.applescript | kuanger/dotfiles | 1 | 3619 | <filename>.config/alfred/Alfred.alfredpreferences/workflows/user.workflow.D27B6AD4-C1F8-4105-8C0B-0E52489E70FE/app_Webkit.applescript<gh_stars>1-10
on getTitle()
tell application id "org.webkit.nightly.WebKit"
using terms from application "Safari"
set theTab to front document
return name of theTab
end using terms from
end tell
end getTitle
on getBody()
tell application id "org.webkit.nightly.WebKit"
using terms from application "Safari"
set theTab to front document
return URL of theTab
end using terms from
end tell
end getBody |
programs/oeis/020/A020330.asm | neoneye/loda | 22 | 177787 | <reponame>neoneye/loda
; A020330: Numbers whose base-2 representation is the juxtaposition of two identical strings.
; 3,10,15,36,45,54,63,136,153,170,187,204,221,238,255,528,561,594,627,660,693,726,759,792,825,858,891,924,957,990,1023,2080,2145,2210,2275,2340,2405,2470,2535,2600,2665,2730,2795,2860,2925,2990,3055,3120,3185,3250,3315,3380,3445,3510,3575,3640,3705,3770,3835,3900,3965,4030,4095,8256,8385,8514,8643,8772,8901,9030,9159,9288,9417,9546,9675,9804,9933,10062,10191,10320,10449,10578,10707,10836,10965,11094,11223,11352,11481,11610,11739,11868,11997,12126,12255,12384,12513,12642,12771,12900
add $0,1
mov $2,$0
mov $3,$0
lpb $0
div $0,2
mul $2,2
lpe
add $1,$2
add $1,$3
mov $0,$1
|
Cubical/ZCohomology/Groups/Torus.agda | kl-i/cubical-0.3 | 0 | 781 | {-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.Torus where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Groups.Connected
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.Groups.Prelims
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.Data.Int renaming (_+_ to _+ℤ_; +Comm to +ℤ-comm ; +Assoc to +ℤ-assoc)
open import Cubical.Data.Nat
open import Cubical.Data.Unit
open import Cubical.Algebra.Group renaming (ℤ to ℤGroup ; Bool to BoolGroup ; Unit to UnitGroup)
open import Cubical.HITs.Pushout
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2) hiding (map)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim2 to pElim2 ; ∣_∣ to ∣_∣₁) hiding (map)
open import Cubical.HITs.Nullification
open import Cubical.HITs.Truncation renaming (elim to trElim ; elim2 to trElim2 ; map to trMap ; rec to trRec)
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.Loopspace
open IsGroupHom
open Iso
-- The following section contains stengthened induction principles for cohomology groups of T². They are particularly useful for showing that
-- that some Isos are morphisms. They make things type-check faster, but should probably not be used for computations.
-- We first need some functions
elimFunT² : (n : ℕ) (p q : typ (Ω (coHomK-ptd (suc n))))
→ Square q q p p
→ S¹ × S¹ → coHomK (suc n)
elimFunT² n p q P (base , base) = ∣ ptSn (suc n) ∣
elimFunT² n p q P (base , loop i) = q i
elimFunT² n p q P (loop i , base) = p i
elimFunT² n p q P (loop i , loop j) = P i j
elimFunT²' : (n : ℕ) → Square (refl {ℓ-zero} {coHomK (suc n)} {∣ ptSn (suc n) ∣}) refl refl refl
→ S¹ × S¹ → coHomK (suc n)
elimFunT²' n P (x , base) = ∣ ptSn (suc n) ∣
elimFunT²' n P (base , loop j) = ∣ ptSn (suc n) ∣
elimFunT²' n P (loop i , loop j) = P i j
elimFunT²'≡elimFunT² : (n : ℕ) → (P : _) → elimFunT²' n P ≡ elimFunT² n refl refl P
elimFunT²'≡elimFunT² n P i (base , base) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (base , loop k) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (loop j , base) = ∣ ptSn (suc n) ∣
elimFunT²'≡elimFunT² n P i (loop j , loop k) = P j k
{-
The first induction principle says that when proving a proposition for some x : Hⁿ(T²), n ≥ 1, it suffices to show that it holds for
(elimFunT² p q P) for any paths p q : ΩKₙ, and square P : Square q q p p. This is useful because elimFunT² p q P (base , base) recudes to 0
-}
coHomPointedElimT² : ∀ {ℓ} (n : ℕ) {B : coHom (suc n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (suc n) (S¹ × S¹)) → isProp (B x))
→ ((p q : _) (P : _) → B ∣ elimFunT² n p q P ∣₂)
→ (x : coHom (suc n) (S¹ × S¹)) → B x
coHomPointedElimT² n {B = B} isprop indp =
coHomPointedElim _ (base , base) isprop
λ f fId → subst B (cong ∣_∣₂ (funExt (λ { (base , base) → sym fId
; (base , loop i) j → helper f fId i1 i (~ j)
; (loop i , base) j → helper f fId i i1 (~ j)
; (loop i , loop j) k → helper f fId i j (~ k)})))
(indp (λ i → helper f fId i i1 i1)
(λ i → helper f fId i1 i i1)
λ i j → helper f fId i j i1)
where
helper : (f : S¹ × S¹ → coHomK (suc n)) → f (base , base) ≡ ∣ ptSn (suc n) ∣
→ I → I → I → coHomK (suc n)
helper f fId i j k =
hfill (λ k → λ {(i = i0) → doubleCompPath-filler (sym fId) (cong f (λ i → (base , loop i))) fId k j
; (i = i1) → doubleCompPath-filler (sym fId) (cong f (λ i → (base , loop i))) fId k j
; (j = i0) → doubleCompPath-filler (sym fId) (cong f (λ i → (loop i , base))) fId k i
; (j = i1) → doubleCompPath-filler (sym fId) (cong f (λ i → (loop i , base))) fId k i})
(inS (f ((loop i) , (loop j))))
k
private
lem : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((P : _) → B ∣ elimFunT² (suc n) refl refl P ∣₂)
→ (p : _) → (refl ≡ p)
→ (q : _) → (refl ≡ q)
→ (P : _)
→ B ∣ elimFunT² (suc n) p q P ∣₂
lem n {B = B} elimP p =
J (λ p _ → (q : _) → (refl ≡ q)
→ (P : _)
→ B ∣ elimFunT² (suc n) p q P ∣₂)
λ q →
J (λ q _ → (P : _) → B ∣ elimFunT² (suc n) refl q P ∣₂)
elimP
{- When working with Hⁿ(T²) , n ≥ 2, we are, in the case described above, allowed to assume that any f : Hⁿ(T²) is
elimFunT² n refl refl P -}
coHomPointedElimT²' : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (2 + n) (S¹ × S¹)) → isProp (B x))
→ ((P : _) → B ∣ elimFunT² (suc n) refl refl P ∣₂)
→ (x : coHom (2 + n) (S¹ × S¹)) → B x
coHomPointedElimT²' n {B = B} prop ind =
coHomPointedElimT² (suc n) prop
λ p q P → trRec (isProp→isOfHLevelSuc n (prop _))
(λ p-refl → trRec (isProp→isOfHLevelSuc n (prop _))
(λ q-refl → lem n {B = B} ind p (sym p-refl) q (sym q-refl) P)
(isConnectedPath _ (isConnectedPathKn (suc n) _ _) q refl .fst))
(isConnectedPath _ (isConnectedPathKn (suc n) _ _) p refl .fst)
{- A slight variation of the above which gives definitional equalities for all points (x , base) -}
private
coHomPointedElimT²'' : ∀ {ℓ} (n : ℕ) {B : coHom (2 + n) (S¹ × S¹) → Type ℓ}
→ ((x : coHom (2 + n) (S¹ × S¹)) → isProp (B x))
→ ((P : _) → B ∣ elimFunT²' (suc n) P ∣₂)
→ (x : coHom (2 + n) (S¹ × S¹)) → B x
coHomPointedElimT²'' n {B = B} prop ind =
coHomPointedElimT²' n prop λ P → subst (λ x → B ∣ x ∣₂)
(elimFunT²'≡elimFunT² (suc n) P) (ind P)
--------- H⁰(T²) ------------
H⁰-T²≅ℤ : GroupIso (coHomGr 0 (S₊ 1 × S₊ 1)) ℤGroup
H⁰-T²≅ℤ =
H⁰-connected (base , base)
λ (a , b) → pRec isPropPropTrunc
(λ id1 → pRec isPropPropTrunc
(λ id2 → ∣ ΣPathP (id1 , id2) ∣₁)
(Sn-connected 0 b) )
(Sn-connected 0 a)
--------- H¹(T²) -------------------------------
H¹-T²≅ℤ×ℤ : GroupIso (coHomGr 1 ((S₊ 1) × (S₊ 1))) (DirProd ℤGroup ℤGroup)
H¹-T²≅ℤ×ℤ = theIso □ GroupIsoDirProd (Hⁿ-Sⁿ≅ℤ 0) (H⁰-Sⁿ≅ℤ 0)
where
typIso : Iso _ _
typIso = setTruncIso (curryIso ⋄ codomainIso S1→K₁≡S1×ℤ ⋄ toProdIso)
⋄ setTruncOfProdIso
theIso : GroupIso _ _
fst theIso = typIso
snd theIso =
makeIsGroupHom
(coHomPointedElimT² _ (λ _ → isPropΠ λ _ → isSet× isSetSetTrunc isSetSetTrunc _ _)
λ pf qf Pf →
coHomPointedElimT² _ (λ _ → isSet× isSetSetTrunc isSetSetTrunc _ _)
λ pg qg Pg i → ∣ funExt (helperFst pf qf pg qg Pg Pf) i ∣₂
, ∣ funExt (helperSnd pf qf pg qg Pg Pf) i ∣₂)
where
module _ (pf qf pg qg : 0ₖ 1 ≡ 0ₖ 1) (Pg : Square qg qg pg pg) (Pf : Square qf qf pf pf) where
helperFst : (x : S¹)
→ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .fst
≡ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y)) .fst
+ₖ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pg qg Pg (x , y)) .fst
helperFst base = refl
helperFst (loop i) j = loopLem j i
where
loopLem : cong (λ x → fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .fst) loop
≡ cong (λ x → fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y)) .fst
+ₖ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pg qg Pg (x , y)) .fst) loop
loopLem = (λ i j → S¹map-id (pf j +ₖ pg j) i)
∙ (λ i j → S¹map-id (pf j) (~ i) +ₖ S¹map-id (pg j) (~ i))
helperSnd : (x : S¹)
→ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y) +ₖ elimFunT² 0 pg qg Pg (x , y)) .snd
≡ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pf qf Pf (x , y)) .snd +ℤ fun S1→K₁≡S1×ℤ (λ y → elimFunT² 0 pg qg Pg (x , y)) .snd
helperSnd =
toPropElim (λ _ → isSetℤ _ _)
((λ i → winding (basechange2⁻ base λ j → S¹map (∙≡+₁ qf qg (~ i) j)))
∙∙ cong (winding ∘ basechange2⁻ base) (congFunct S¹map qf qg)
∙∙ (cong winding (basechange2⁻-morph base (cong S¹map qf) (cong S¹map qg))
∙ winding-hom (basechange2⁻ base (cong S¹map qf)) (basechange2⁻ base (cong S¹map qg))))
----------------------- H²(T²) ------------------------------
H²-T²≅ℤ : GroupIso (coHomGr 2 (S₊ 1 × S₊ 1)) ℤGroup
H²-T²≅ℤ = compGroupIso helper2 (Hⁿ-Sⁿ≅ℤ 0)
where
helper : Iso (∥ ((a : S¹) → coHomK 2) ∥₂ × ∥ ((a : S¹) → coHomK 1) ∥₂) (coHom 1 S¹)
inv helper s = 0ₕ _ , s
fun helper = snd
leftInv helper _ =
ΣPathP (isOfHLevelSuc 0 (isOfHLevelRetractFromIso 0 (fst (Hⁿ-S¹≅0 0)) (isContrUnit)) _ _
, refl)
rightInv helper _ = refl
theIso : Iso (coHom 2 (S¹ × S¹)) (coHom 1 S¹)
theIso = setTruncIso (curryIso ⋄ codomainIso S1→K2≡K2×K1 ⋄ toProdIso)
⋄ setTruncOfProdIso
⋄ helper
helper2 : GroupIso (coHomGr 2 (S¹ × S¹)) (coHomGr 1 S¹)
helper2 .fst = theIso
helper2 .snd = makeIsGroupHom (
coHomPointedElimT²'' 0 (λ _ → isPropΠ λ _ → isSetSetTrunc _ _)
λ P → coHomPointedElimT²'' 0 (λ _ → isSetSetTrunc _ _)
λ Q → ((λ i → ∣ (λ a → ΩKn+1→Kn 1 (sym (rCancel≡refl 0 i)
∙∙ cong (λ x → (elimFunT²' 1 P (a , x) +ₖ elimFunT²' 1 Q (a , x)) -ₖ ∣ north ∣) loop
∙∙ rCancel≡refl 0 i)) ∣₂))
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 P (a , x) +ₖ elimFunT²' 1 Q (a , x)) i) loop) (~ i))) ∣₂)
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn 1 (∙≡+₂ 0 (cong (λ x → elimFunT²' 1 P (a , x)) loop) (cong (λ x → elimFunT²' 1 Q (a , x)) loop) (~ i))) ∣₂)
∙∙ (λ i → ∣ (λ a → ΩKn+1→Kn-hom 1 (cong (λ x → elimFunT²' 1 P (a , x)) loop) (cong (λ x → elimFunT²' 1 Q (a , x)) loop) i) ∣₂)
∙∙ (λ i → ∣ ((λ a → ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 P (a , x)) (~ i)) loop) i)
+ₖ ΩKn+1→Kn 1 (rUnit (cong (λ x → rUnitₖ 2 (elimFunT²' 1 Q (a , x)) (~ i)) loop) i))) ∣₂)
∙ (λ i → ∣ ((λ a → ΩKn+1→Kn 1 (sym (rCancel≡refl 0 (~ i))
∙∙ cong (λ x → elimFunT²' 1 P (a , x) +ₖ ∣ north ∣) loop
∙∙ rCancel≡refl 0 (~ i))
+ₖ ΩKn+1→Kn 1 (sym (rCancel≡refl 0 (~ i))
∙∙ cong (λ x → elimFunT²' 1 Q (a , x) +ₖ ∣ north ∣) loop
∙∙ rCancel≡refl 0 (~ i)))) ∣₂))
-- >>>>>>> master
private
to₂ : coHom 2 (S₊ 1 × S₊ 1) → ℤ
to₂ = fun (fst H²-T²≅ℤ)
from₂ : ℤ → coHom 2 (S₊ 1 × S₊ 1)
from₂ = inv (fst H²-T²≅ℤ)
to₁ : coHom 1 (S₊ 1 × S₊ 1) → ℤ × ℤ
to₁ = fun (fst H¹-T²≅ℤ×ℤ)
from₁ : ℤ × ℤ → coHom 1 (S₊ 1 × S₊ 1)
from₁ = inv (fst H¹-T²≅ℤ×ℤ)
to₀ : coHom 0 (S₊ 1 × S₊ 1) → ℤ
to₀ = fun (fst H⁰-T²≅ℤ)
from₀ : ℤ → coHom 0 (S₊ 1 × S₊ 1)
from₀ = inv (fst H⁰-T²≅ℤ)
{-
-- Compute fast:
test : to₁ (from₁ (0 , 1) +ₕ from₁ (1 , 0)) ≡ (1 , 1)
test = refl
test2 : to₁ (from₁ (5 , 1) +ₕ from₁ (-2 , 3)) ≡ (3 , 4)
test2 = refl
-- Compute pretty fast
test3 : to₂ (from₂ 1) ≡ 1
test3 = refl
test4 : to₂ (from₂ 2) ≡ 2
test4 = refl
test5 : to₂ (from₂ 3) ≡ 3
test5 = refl
-- Compute, but slower
test6 : to₂ (from₂ 0 +ₕ from₂ 0) ≡ 0
test6 = refl
test6 : to₂ (from₂ 0 +ₕ from₂ 1) ≡ 1
test6 = refl
-- Does not compute
test7 : to₂ (from₂ 1 +ₕ from₂ 0) ≡ 1
test7 = refl
-}
|
programs/fibonacci.asm | blurpy/8-bit-computer-emulator | 12 | 91490 | LDI 0 ; Put the value 0 in the A-register
STA 13 ; Store the value from the A-register in memory location 13
OUT ; Output the value of the A-register
LDI 1 ; Put the value 1 in the A-register
STA 14 ; Store the value from the A-register in memory location 14
OUT ; Output the value of the A-register
ADD 13 ; Put the value from memory location 13 in the B-register, and store A+B in the A-register
JC 0 ; Jump to instruction 0 if the A-register is past 255
STA 15 ; Store the value from the A-register in memory location 15
LDA 14 ; Put the value from memory location 14 in the A-register
STA 13 ; Store the value from the A-register in memory location 13
LDA 15 ; Put the value from memory location 15 in the A-register
JMP 4 ; Jump to instruction 4
DB 0 ; Define a byte with the value 0 at memory location 13
DB 0 ; Define a byte with the value 0 at memory location 14
DB 0 ; Define a byte with the value 0 at memory location 15
|
notes/FOT/FOTC/Data/List/Examples.agda | asr/fotc | 11 | 4768 | <filename>notes/FOT/FOTC/Data/List/Examples.agda
------------------------------------------------------------------------------
-- Lists examples
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Data.List.Examples where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Data.List.Type
------------------------------------------------------------------------------
l₁ : List (true ∷ false ∷ [])
l₁ = lcons true (lcons false lnil)
l₂ : List (zero ∷ 1' ∷ 2' ∷ [])
l₂ = lcons zero (lcons 1' (lcons 2' lnil))
|
src/play_sound.asm | Gegel85/SpaceShooterGB | 3 | 29423 | <reponame>Gegel85/SpaceShooterGB
;laser sound sfxOpera
;Channel1
laser::
db $1F, $CF, $85, $D0, $87
;Channel4
destruction::
db $00, $D5, $70, $80
;channel4
bam::
db $00, $95, $7D, $80
;channel4
destructionOn::
db $00, $4F, $7B, $80
;channel4
meteorDestruction::
db $00, $D3, $65, $80
;GO SFX Channel2
gameOverSFX::
db $80, $00, $0C, $86, QUAVER * 4; NO SOUND
db $80, $80, $0C, $86, QUAVER * 4; DO 1
db $80, $80, $EF, $85, QUAVER * 4; SI 0
db $80, $80, $CD, $85, QUAVER * 4; LA# 0
db $80, $80, $AC, $85, QUAVER * 8; LA 0
db $80, $00, $AC, $85, $00; LA 0
wpRamWave::
db $FF, $88, $00, $88, $FF, $88, $00, $88, $FF, $88, $00, $88, $FF, $88, $00, $88
initWPRAM::
ld hl, wpRamWave
ld de, WPRAM
ld bc, 16
call copyMemory
playChannel1Sound::
ld de, CHANNEL1_SWEEP
ld c, 5
.loop:
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
ret
playChannel2Sound::
ld de, CHANNEL2_LENGTH
ld c, 4
.loop:
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
ret
playChannelWave::
ld de, CHANNEL3_ON_OFF
ld c, 5
.loop:
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
ret
playNoiseSound::
ld de, CHANNEL4_LENGTH
ld c, 4
.loop:
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
ret
updateSound::
xor a
ld hl, MUSIC_TIMER
or [hl]
jr z, .skip
dec [hl]
jr nz, .skip
ld a, [MUSIC_PTR_H]
ld h, a
ld a, [MUSIC_PTR_L]
ld l, a
call playChannel2Sound
ld a, [hli]
cp a, $FF
jr z, .reset
ld [MUSIC_TIMER], a
ld a, h
ld [MUSIC_PTR_H], a
ld a, l
ld [MUSIC_PTR_L], a
ret
.reset:
reg MUSIC_PTR_H, [MUSIC_START_PTR_H]
reg MUSIC_PTR_L, [MUSIC_START_PTR_L]
reg MUSIC_TIMER, QUAVER
.skip:
ret
playSound::
ld a, h
ld [MUSIC_PTR_H], a
ld [MUSIC_START_PTR_H], a
ld a, l
ld [MUSIC_PTR_L], a
ld [MUSIC_START_PTR_L], a
ld a, 1
ld [MUSIC_TIMER], a
ret
updateSound2::
xor a
ld hl, MUSIC_2_TIMER
or [hl]
jr z, .skip
dec [hl]
jr nz, .skip
ld a, [MUSIC_2_PTR_H]
ld h, a
ld a, [MUSIC_2_PTR_L]
ld l, a
call playChannelWave
ld a, [hli]
cp a, $FF
jr z, .reset
ld [MUSIC_2_TIMER], a
ld a, h
ld [MUSIC_2_PTR_H], a
ld a, l
ld [MUSIC_2_PTR_L], a
ret
.reset:
reg MUSIC_2_PTR_H, [MUSIC_2_START_PTR_H]
reg MUSIC_2_PTR_L, [MUSIC_2_START_PTR_L]
reg MUSIC_2_TIMER, QUAVER
.skip:
ret
playSound2::
ld a, h
ld [MUSIC_2_PTR_H], a
ld [MUSIC_2_START_PTR_H], a
ld a, l
ld [MUSIC_2_PTR_L], a
ld [MUSIC_2_START_PTR_L], a
ld a, 1
ld [MUSIC_2_TIMER], a
ret |
platform/osal/winx64_src/mutex.asm | AarhusCrypto/PASTA | 0 | 7975 | <gh_stars>0
; Hand written assembly for Windows x64
.CODE
Mutex_lock PROC
; RCX has the argument
begin:
mov rax, 0
mov rbx, 1
lock cmpxchg [rcx],rbx
or rax,rax
jnz begin
ret
Mutex_lock ENDP
end |
Examples/qt/qtwidgetnasm/asm/qchar.asm | agguro/linux-nasm | 6 | 24635 | ;name: qchar.asm
;
;description:
;
bits 64
global getunicode
global setunicode
section .text
getunicode:
xor rax,rax ; rax = 0
mov ax,word[rdi] ; get unicode in ax
ret
setunicode:
mov ax,0x0047
ret
|
asgn3/prob1.asm | debargham14/Microprocessors-8085- | 0 | 922 | <reponame>debargham14/Microprocessors-8085-
LXI H,2600
XCHG
LXI H,2500
MOV B,M
LOOP: INX H
MOV A,M
RRC
JNC COND2
RLC
XCHG
MOV M,A
INX H
XCHG
JMP SKIP
COND2: RLC
RLC
JNC SKIP
RRC
XCHG
MOV M,A
INX H
XCHG
SKIP: DCR B
JNZ LOOP
HLT
|
Code_0.asm | vishnuajith/PIC-18-Example-Codes | 0 | 166617 | <reponame>vishnuajith/PIC-18-Example-Codes
;*******************************************************************
;* Description : Copy literal to WREG and performing Addition
;* [MY FIRST PIC 18 CODE]
;********************************************************************
#include<p18f452.inc>
ORG 0
MOVLW 10
ADDLW 20
MOVLW 30
END |
Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0xca_notsx.log_12_1422.asm | ljhsiun2/medusa | 9 | 166440 | .global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_normal_ht+0x1d617, %rsi
lea addresses_normal_ht+0xb417, %rdi
clflush (%rdi)
nop
nop
nop
nop
nop
xor %r13, %r13
mov $14, %rcx
rep movsw
nop
nop
nop
nop
nop
add $56969, %rbp
lea addresses_D_ht+0x90b3, %r11
nop
nop
nop
nop
nop
and %rbx, %rbx
mov (%r11), %rdi
nop
nop
nop
nop
nop
xor %rdi, %rdi
lea addresses_D_ht+0x1bb9f, %rsi
dec %rbp
mov (%rsi), %r13d
nop
nop
nop
xor %rbp, %rbp
lea addresses_WT_ht+0x1c897, %rcx
nop
nop
nop
nop
add %r13, %r13
mov $0x6162636465666768, %r11
movq %r11, (%rcx)
cmp $49962, %rbp
lea addresses_UC_ht+0x167b7, %r13
nop
add %rcx, %rcx
mov (%r13), %rsi
nop
nop
nop
nop
inc %rsi
lea addresses_normal_ht+0x17d33, %rbp
nop
nop
nop
and %rdi, %rdi
mov $0x6162636465666768, %r11
movq %r11, (%rbp)
nop
nop
and $2927, %rcx
lea addresses_A_ht+0xc19a, %r13
nop
nop
xor $17311, %rdi
mov (%r13), %bx
nop
nop
dec %rbp
lea addresses_WT_ht+0x1b54d, %r13
clflush (%r13)
nop
nop
nop
nop
sub $40089, %r11
mov $0x6162636465666768, %rsi
movq %rsi, %xmm4
vmovups %ymm4, (%r13)
mfence
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r14
push %r9
push %rdi
push %rdx
// Store
lea addresses_D+0x12117, %rdx
nop
nop
and %rdi, %rdi
mov $0x5152535455565758, %r14
movq %r14, %xmm3
vmovaps %ymm3, (%rdx)
// Exception!!!
nop
nop
nop
mov (0), %rdi
nop
nop
xor %r14, %r14
// Faulty Load
lea addresses_PSE+0x3c17, %r13
nop
nop
and $9468, %r11
vmovups (%r13), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $0, %xmm1, %r9
lea oracles, %rdx
and $0xff, %r9
shlq $12, %r9
mov (%rdx,%r9,1), %r9
pop %rdx
pop %rdi
pop %r9
pop %r14
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': True, 'size': 32, 'congruent': 0, 'same': False, 'type': 'addresses_PSE'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': True, 'size': 32, 'congruent': 8, 'same': False, 'type': 'addresses_D'}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0, 'same': True, 'type': 'addresses_PSE'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 4, 'same': False, 'type': 'addresses_normal_ht'}, 'dst': {'congruent': 10, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM'}
{'src': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 2, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 3, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 6, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'STOR'}
{'src': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 4, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 2, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'STOR'}
{'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 1, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'STOR'}
{'33': 12}
33 33 33 33 33 33 33 33 33 33 33 33
*/
|
sound/musicasm/Emerald.asm | NatsumiFox/Sonic-3-93-Nov-03 | 7 | 102756 | Emerald_Header:
sHeaderInit ; Z80 offset is $C96A
sHeaderPatch Emerald_Patches
sHeaderCh $07, $03
sHeaderTempo $01, $35
sHeaderDAC Emerald_DAC
sHeaderFM Emerald_FM1, $F4, $08
sHeaderFM Emerald_FM2, $F4, $08
sHeaderFM Emerald_FM3, $F4, $07
sHeaderFM Emerald_FM4, $F4, $16
sHeaderFM Emerald_FM5, $F4, $16
sHeaderFM Emerald_FM6, $F4, $16
sHeaderPSG Emerald_PSG1, $F4, $02, $00, v04
sHeaderPSG Emerald_PSG2, $F4, $02, $00, v05
sHeaderPSG Emerald_DAC, $F4, $00, $00, v04
Emerald_FM3:
ssDetune $02
Emerald_FM1:
sPatFM $00
dc.b nE5, $06, nG5, nC6, nE6, $0C, nC6, nG6
dc.b $2A
sStop
Emerald_FM2:
sPatFM $00
dc.b nC5, $06, nE5, nG5, nC6, $0C, nA5, nD6
dc.b $2A
sStop
Emerald_FM4:
sPatFM $01
dc.b nE5, $0C, nE5, $06, nG5, $06, nRst, nG5
dc.b nRst, nC6, $2A
sStop
Emerald_FM5:
sPatFM $01
dc.b nC6, $0C, nC6, $06, nE6, $06, nRst, nE6
dc.b nRst, nG6, $2A
sStop
Emerald_FM6:
sPatFM $01
dc.b nG5, $0C, nG5, $06, nC6, $06, nRst, nC6
dc.b nRst, nE6, $2A
sStop
Emerald_PSG2:
dc.b nRst, $2D
Emerald_Loop2:
dc.b nG5, $06, nF5, nE5, nD5
saVolPSG $03
sLoop $00, $04, Emerald_Loop2
sStop
Emerald_PSG1:
sFade $01
dc.b nRst, $02, nRst, $2D
Emerald_Loop1:
dc.b nG5, $06, nF5, nE5, nD5
saVolPSG $03
sLoop $00, $04, Emerald_Loop1
Emerald_DAC:
sFade $01
sStop
Emerald_Patches:
; Patch $00
; $04
; $35, $72, $54, $46, $1F, $1F, $1F, $1F
; $07, $0A, $07, $0D, $00, $0B, $00, $0B
; $1F, $0F, $1F, $0F, $23, $14, $1D, $80
spAlgorithm $04
spFeedback $00
spDetune $03, $05, $07, $04
spMultiple $05, $04, $02, $06
spRateScale $00, $00, $00, $00
spAttackRt $1F, $1F, $1F, $1F
spAmpMod $00, $00, $00, $00
spSustainRt $07, $07, $0A, $0D
spSustainLv $01, $01, $00, $00
spDecayRt $00, $00, $0B, $0B
spReleaseRt $0F, $0F, $0F, $0F
spTotalLv $23, $1D, $14, $00
; Patch $01
; $3C
; $31, $52, $50, $30, $52, $53, $52, $53
; $08, $00, $08, $00, $04, $00, $04, $00
; $10, $07, $10, $07, $1A, $80, $16, $80
spAlgorithm $04
spFeedback $07
spDetune $03, $05, $05, $03
spMultiple $01, $00, $02, $00
spRateScale $01, $01, $01, $01
spAttackRt $12, $12, $13, $13
spAmpMod $00, $00, $00, $00
spSustainRt $08, $08, $00, $00
spSustainLv $01, $01, $00, $00
spDecayRt $04, $04, $00, $00
spReleaseRt $00, $00, $07, $07
spTotalLv $1A, $16, $00, $00
|
programs/oeis/154/A154612.asm | neoneye/loda | 22 | 89334 | ; A154612: 17n + 7.
; 7,24,41,58,75,92,109,126,143,160,177,194,211,228,245,262,279,296,313,330,347,364,381,398,415,432,449,466,483,500,517,534,551,568,585,602,619,636,653,670,687,704,721,738,755,772,789,806,823,840,857,874,891,908,925,942,959,976,993,1010,1027,1044,1061,1078,1095,1112,1129,1146,1163,1180,1197,1214,1231,1248,1265,1282,1299,1316,1333,1350,1367,1384,1401,1418,1435,1452,1469,1486,1503,1520,1537,1554,1571,1588,1605,1622,1639,1656,1673,1690
mul $0,17
add $0,7
|
programs/oeis/056/A056051.asm | karttu/loda | 0 | 96209 | ; A056051: a(n) = (n-2)! - 1 (mod n).
; 0,0,1,0,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,-1,0,-1,0,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,0
add $0,1
mov $2,-3
div $2,$0
cal $0,10051 ; Characteristic function of primes: 1 if n is prime, else 0.
sub $0,1
mov $3,$2
cmp $3,0
mov $4,$2
add $4,$3
div $0,$4
mov $1,$0
|
oeis/130/A130716.asm | neoneye/loda-programs | 11 | 175891 | <gh_stars>10-100
; A130716: a(0)=a(1)=a(2)=1, a(n)=0 for n>2.
; Submitted by <NAME>
; 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
div $0,3
cmp $0,0
|
test/Fail/NoPatternMatching.agda | cruhland/agda | 1,989 | 12254 | {-# OPTIONS --no-pattern-matching #-}
id : {A : Set} (x : A) → A
id x = x
data Unit : Set where
unit : Unit
fail : Unit → Set
fail unit = Unit
-- Expected error: Pattern matching is disabled
|
Transynther/x86/_processed/AVXALIGN/_st_/i7-7700_9_0xca.log_21829_1568.asm | ljhsiun2/medusa | 9 | 103421 | .global s_prepare_buffers
s_prepare_buffers:
push %r8
push %r9
push %rax
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x3ec4, %rsi
lea addresses_D_ht+0xcc94, %rdi
clflush (%rsi)
nop
dec %rbx
mov $78, %rcx
rep movsb
nop
nop
nop
nop
nop
add $31890, %r8
lea addresses_UC_ht+0x1a714, %rsi
lea addresses_UC_ht+0x27d8, %rdi
nop
nop
nop
and %rbp, %rbp
mov $54, %rcx
rep movsw
nop
nop
nop
nop
nop
inc %rdi
lea addresses_WT_ht+0xa66a, %rsi
lea addresses_UC_ht+0x10194, %rdi
nop
inc %r9
mov $76, %rcx
rep movsl
nop
nop
nop
nop
nop
sub $10922, %r9
lea addresses_D_ht+0xfe34, %rdi
nop
sub $31239, %r8
mov (%rdi), %ebp
nop
nop
nop
nop
nop
and $34235, %rsi
lea addresses_A_ht+0x1c894, %rsi
lea addresses_normal_ht+0xdc54, %rdi
nop
nop
nop
inc %rax
mov $67, %rcx
rep movsq
sub $8805, %rdi
lea addresses_normal_ht+0x4620, %rcx
add %rax, %rax
movb (%rcx), %bl
nop
dec %rax
lea addresses_WC_ht+0x9114, %rsi
lea addresses_normal_ht+0x2f34, %rdi
nop
cmp $4970, %rbx
mov $22, %rcx
rep movsw
nop
add $42520, %rbx
lea addresses_WC_ht+0x2b3c, %rbp
add $22324, %rbx
movw $0x6162, (%rbp)
sub %r8, %r8
lea addresses_D_ht+0x6c94, %rsi
lea addresses_UC_ht+0xf14, %rdi
dec %r8
mov $24, %rcx
rep movsb
nop
nop
dec %r8
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %rax
pop %r9
pop %r8
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r13
push %r14
push %r15
push %rax
push %rbp
push %rcx
// Store
lea addresses_RW+0xc694, %r15
nop
nop
add $28369, %rbp
mov $0x5152535455565758, %rcx
movq %rcx, %xmm5
movups %xmm5, (%r15)
nop
and %r10, %r10
// Load
mov $0xe94, %r14
nop
nop
nop
dec %r15
movb (%r14), %r13b
sub %r10, %r10
// Faulty Load
lea addresses_PSE+0x11894, %r14
sub $1025, %rax
mov (%r14), %cx
lea oracles, %r10
and $0xff, %rcx
shlq $12, %rcx
mov (%r10,%rcx,1), %rcx
pop %rcx
pop %rbp
pop %rax
pop %r15
pop %r14
pop %r13
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_PSE'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 6, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_RW'}}
{'src': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_P'}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 2, 'NT': True, 'type': 'addresses_PSE'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 3, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 10, 'same': False, 'type': 'addresses_D_ht'}}
{'src': {'congruent': 4, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 1, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'congruent': 8, 'same': False, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 11, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_normal_ht'}}
{'src': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 7, 'same': True, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 3, 'AVXalign': False, 'same': True, 'size': 2, 'NT': False, 'type': 'addresses_WC_ht'}}
{'src': {'congruent': 9, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_UC_ht'}}
{'33': 21829}
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
*/
|
Task/Rot-13/AppleScript/rot-13-4.applescript | LaudateCorpus1/RosettaCodeData | 1 | 2749 | <reponame>LaudateCorpus1/RosettaCodeData<filename>Task/Rot-13/AppleScript/rot-13-4.applescript<gh_stars>1-10
-- ROT 13 --------------------------------------------------------------------
-- rot13 :: String -> String
on rot13(str)
script rt13
on |λ|(x)
if (x ≥ "a" and x ≤ "m") or (x ≥ "A" and x ≤ "M") then
character id ((id of x) + 13)
else if (x ≥ "n" and x ≤ "z") or (x ≥ "N" and x ≤ "Z") then
character id ((id of x) - 13)
else
x
end if
end |λ|
end script
intercalate("", map(rt13, characters of str))
end rot13
-- TEST ----------------------------------------------------------------------
on run
rot13("nowhere ABJURER")
--> "abjurer NOWHERE"
end run
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to |λ|(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn
|
Cubical/Homotopy/Whitehead.agda | thomas-lamiaux/cubical | 1 | 17250 | {-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Whitehead where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.Unit
open import Cubical.HITs.Susp renaming (toSusp to σ)
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.Join
open import Cubical.HITs.Wedge
open import Cubical.HITs.SetTruncation
open import Cubical.Homotopy.Group.Base
open Iso
open 3x3-span
joinTo⋁ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'}
→ join (typ A) (typ B)
→ (Susp (typ A) , north) ⋁ (Susp (typ B) , north)
joinTo⋁ (inl x) = inr north
joinTo⋁ (inr x) = inl north
joinTo⋁ {A = A} {B = B} (push a b i) =
((λ i → inr (σ B b i))
∙∙ sym (push tt)
∙∙ λ i → inl (σ A a i)) i
-- Whitehead product (main definition)
[_∣_] : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ (S₊∙ (suc n) →∙ X)
→ (S₊∙ (suc m) →∙ X)
→ S₊∙ (suc (n + m)) →∙ X
fst ([_∣_] {X = X} {n = n} {m = m} f g) x =
_∨→_ (f ∘∙ (inv (IsoSucSphereSusp n) , IsoSucSphereSusp∙ n))
(g ∘∙ (inv (IsoSucSphereSusp m) , IsoSucSphereSusp∙ m))
(joinTo⋁ {A = S₊∙ n} {B = S₊∙ m}
(inv (IsoSphereJoin n m) x))
snd ([_∣_] {n = n} {m = m} f g) =
cong (_∨→_ (f ∘∙ (inv (IsoSucSphereSusp n) , IsoSucSphereSusp∙ n))
(g ∘∙ (inv (IsoSucSphereSusp m) , IsoSucSphereSusp∙ m)))
(cong (joinTo⋁ {A = S₊∙ n} {B = S₊∙ m}) (IsoSphereJoin⁻Pres∙ n m))
∙ cong (fst g) (IsoSucSphereSusp∙ m)
∙ snd g
-- For Sⁿ, Sᵐ with n, m ≥ 2, we can avoid some bureaucracy. We make
-- a separate definition and prove it equivalent.
[_∣_]-pre : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ (S₊∙ (suc (suc n)) →∙ X)
→ (S₊∙ (suc (suc m)) →∙ X)
→ join (typ (S₊∙ (suc n))) (typ (S₊∙ (suc m))) → fst X
[_∣_]-pre {n = n} {m = m} f g x =
_∨→_ f g
(joinTo⋁ {A = S₊∙ (suc n)} {B = S₊∙ (suc m)}
x)
[_∣_]₂ : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ (S₊∙ (suc (suc n)) →∙ X)
→ (S₊∙ (suc (suc m)) →∙ X)
→ S₊∙ (suc ((suc n) + (suc m))) →∙ X
fst ([_∣_]₂ {n = n} {m = m} f g) x =
[ f ∣ g ]-pre (inv (IsoSphereJoin (suc n) (suc m)) x)
snd ([_∣_]₂ {n = n} {m = m} f g) =
cong ([ f ∣ g ]-pre) (IsoSphereJoin⁻Pres∙ (suc n) (suc m))
∙ snd g
[]≡[]₂ : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ (f : (S₊∙ (suc (suc n)) →∙ X))
→ (g : (S₊∙ (suc (suc m)) →∙ X))
→ [ f ∣ g ] ≡ [ f ∣ g ]₂
[]≡[]₂ {n = n} {m = m} f g =
ΣPathP (
(λ i x → _∨→_ (∘∙-idˡ f i)
(∘∙-idˡ g i)
(joinTo⋁ {A = S₊∙ (suc n)} {B = S₊∙ (suc m)}
(inv (IsoSphereJoin (suc n) (suc m)) x)))
, (cong (cong (_∨→_ (f ∘∙ idfun∙ _)
(g ∘∙ idfun∙ _))
(cong (joinTo⋁ {A = S₊∙ (suc n)} {B = S₊∙ (suc m)})
(IsoSphereJoin⁻Pres∙ (suc n) (suc m))) ∙_)
(sym (lUnit (snd g)))
◁ λ j → (λ i → _∨→_ (∘∙-idˡ f j)
(∘∙-idˡ g j)
( joinTo⋁ {A = S₊∙ (suc n)} {B = S₊∙ (suc m)}
((IsoSphereJoin⁻Pres∙ (suc n) (suc m)) i))) ∙ snd g))
-- Homotopy group version
[_∣_]π' : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ π' (suc n) X → π' (suc m) X
→ π' (suc (n + m)) X
[_∣_]π' = elim2 (λ _ _ → squash₂) λ f g → ∣ [ f ∣ g ] ∣₂
-- We prove that the function joinTo⋁ used in the definition of the whitehead
-- product gives an equivalence between (Susp A × Susp B) and the
-- appropriate cofibre of joinTo⋁ (last two theorems in the following
-- module).
module _ (A B : Type) (a₀ : A) (b₀ : B) where
private
W = joinTo⋁ {A = (A , a₀)} {B = (B , b₀)}
A∨B = (Susp A , north) ⋁ (Susp B , north)
σB = σ (B , b₀)
σA = σ (A , a₀)
cofibW = Pushout W λ _ → tt
whitehead3x3 : 3x3-span
A00 whitehead3x3 = Susp A
A02 whitehead3x3 = B
A04 whitehead3x3 = Unit
A20 whitehead3x3 = B
A22 whitehead3x3 = A × B
A24 whitehead3x3 = A
A40 whitehead3x3 = B
A42 whitehead3x3 = B
A44 whitehead3x3 = Unit
f10 whitehead3x3 _ = south
f12 whitehead3x3 = snd
f14 whitehead3x3 _ = tt
f30 whitehead3x3 = idfun B
f32 whitehead3x3 = snd
f34 whitehead3x3 _ = tt
f01 whitehead3x3 _ = north
f21 whitehead3x3 = snd
f41 whitehead3x3 = idfun B
f03 whitehead3x3 _ = tt
f23 whitehead3x3 = fst
f43 whitehead3x3 _ = tt
H11 whitehead3x3 x = merid (fst x)
H13 whitehead3x3 _ = refl
H31 whitehead3x3 _ = refl
H33 whitehead3x3 _ = refl
A0□→A∨B : A0□ whitehead3x3 → A∨B
A0□→A∨B (inl x) = inl x
A0□→A∨B (inr x) = inr north
A0□→A∨B (push a i) = (push tt ∙ λ i → inr (σB a (~ i))) i
A∨B→A0□ : A∨B → A0□ whitehead3x3
A∨B→A0□ (inl x) = inl x
A∨B→A0□ (inr north) = inl north
A∨B→A0□ (inr south) = inl north
A∨B→A0□ (inr (merid b i)) = (push b₀ ∙ sym (push b)) i
A∨B→A0□ (push a i) = inl north
Iso-A0□-⋁ : Iso (A0□ whitehead3x3) A∨B
fun Iso-A0□-⋁ = A0□→A∨B
inv Iso-A0□-⋁ = A∨B→A0□
rightInv Iso-A0□-⋁ (inl x) = refl
rightInv Iso-A0□-⋁ (inr north) = push tt
rightInv Iso-A0□-⋁ (inr south) = push tt ∙ λ i → inr (merid b₀ i)
rightInv Iso-A0□-⋁ (inr (merid a i)) j = lem j i
where
lem : PathP (λ i → push tt i ≡ (push tt ∙ (λ i → inr (merid b₀ i))) i)
(cong A0□→A∨B (cong A∨B→A0□ λ i → inr (merid a i)))
(λ i → inr (merid a i))
lem = (cong-∙ A0□→A∨B (push b₀) (sym (push a))
∙ cong₂ _∙_ (cong (push tt ∙_)
(λ j i → inr (rCancel (merid b₀) j (~ i)))
∙ sym (rUnit (push tt)))
(symDistr (push tt) (λ i → inr (σB a (~ i)))))
◁ λ i j → hcomp (λ k →
λ { (i = i0) → compPath-filler' (push tt)
(compPath-filler (λ i → inr (σB a i))
(sym (push tt)) k) k j
; (i = i1) → inr (merid a j)
; (j = i0) → push tt (i ∨ ~ k)
; (j = i1) → compPath-filler' (push tt)
(λ i → inr (merid b₀ i)) k i})
(inr (compPath-filler (merid a)
(sym (merid b₀)) (~ i) j))
rightInv Iso-A0□-⋁ (push a i) j = push tt (i ∧ j)
leftInv Iso-A0□-⋁ (inl x) = refl
leftInv Iso-A0□-⋁ (inr tt) = push b₀
leftInv Iso-A0□-⋁ (push b i) j = help j i
where
help : PathP (λ i → inl north ≡ push b₀ i)
(cong A∨B→A0□ (cong A0□→A∨B (push b)))
(push b)
help = (cong-∙ A∨B→A0□ (push tt) (λ i → inr (σB b (~ i)))
∙ (λ i → lUnit (sym (cong-∙ (A∨B→A0□ ∘ inr)
(merid b) (sym (merid b₀)) i)) (~ i))
∙ cong sym (cong ((push b₀ ∙ sym (push b)) ∙_)
(cong sym (rCancel (push b₀))))
∙ cong sym (sym (rUnit (push b₀ ∙ sym (push b)))))
◁ λ i j → compPath-filler' (push b₀) (sym (push b)) (~ i) (~ j)
Iso-A2□-join : Iso (A2□ whitehead3x3) (join A B)
fun Iso-A2□-join (inl x) = inr x
fun Iso-A2□-join (inr x) = inl x
fun Iso-A2□-join (push (a , b) i) = push a b (~ i)
inv Iso-A2□-join (inl x) = inr x
inv Iso-A2□-join (inr x) = inl x
inv Iso-A2□-join (push a b i) = push (a , b) (~ i)
rightInv Iso-A2□-join (inl x) = refl
rightInv Iso-A2□-join (inr x) = refl
rightInv Iso-A2□-join (push a b i) = refl
leftInv Iso-A2□-join (inl x) = refl
leftInv Iso-A2□-join (inr x) = refl
leftInv Iso-A2□-join (push a i) = refl
isContrA4□ : isContr (A4□ whitehead3x3)
fst isContrA4□ = inr tt
snd isContrA4□ (inl x) = sym (push x)
snd isContrA4□ (inr x) = refl
snd isContrA4□ (push a i) j = push a (i ∨ ~ j)
A4□≃Unit : A4□ whitehead3x3 ≃ Unit
A4□≃Unit = isContr→≃Unit isContrA4□
Iso-A□0-Susp : Iso (A□0 whitehead3x3) (Susp A)
fun Iso-A□0-Susp (inl x) = x
fun Iso-A□0-Susp (inr x) = north
fun Iso-A□0-Susp (push a i) = merid a₀ (~ i)
inv Iso-A□0-Susp x = inl x
rightInv Iso-A□0-Susp x = refl
leftInv Iso-A□0-Susp (inl x) = refl
leftInv Iso-A□0-Susp (inr x) = (λ i → inl (merid a₀ i)) ∙ push x
leftInv Iso-A□0-Susp (push a i) j =
hcomp (λ k → λ { (i = i0) → inl (merid a₀ (k ∨ j))
; (i = i1) → compPath-filler
(λ i₁ → inl (merid a₀ i₁))
(push (idfun B a)) k j
; (j = i0) → inl (merid a₀ (~ i ∧ k))
; (j = i1) → push a (i ∧ k)})
(inl (merid a₀ j))
Iso-A□2-Susp× : Iso (A□2 whitehead3x3) (Susp A × B)
fun Iso-A□2-Susp× (inl x) = north , x
fun Iso-A□2-Susp× (inr x) = south , x
fun Iso-A□2-Susp× (push a i) = merid (fst a) i , (snd a)
inv Iso-A□2-Susp× (north , y) = inl y
inv Iso-A□2-Susp× (south , y) = inr y
inv Iso-A□2-Susp× (merid a i , y) = push (a , y) i
rightInv Iso-A□2-Susp× (north , snd₁) = refl
rightInv Iso-A□2-Susp× (south , snd₁) = refl
rightInv Iso-A□2-Susp× (merid a i , snd₁) = refl
leftInv Iso-A□2-Susp× (inl x) = refl
leftInv Iso-A□2-Susp× (inr x) = refl
leftInv Iso-A□2-Susp× (push a i) = refl
Iso-A□4-Susp : Iso (A□4 whitehead3x3) (Susp A)
fun Iso-A□4-Susp (inl x) = north
fun Iso-A□4-Susp (inr x) = south
fun Iso-A□4-Susp (push a i) = merid a i
inv Iso-A□4-Susp north = inl tt
inv Iso-A□4-Susp south = inr tt
inv Iso-A□4-Susp (merid a i) = push a i
rightInv Iso-A□4-Susp north = refl
rightInv Iso-A□4-Susp south = refl
rightInv Iso-A□4-Susp (merid a i) = refl
leftInv Iso-A□4-Susp (inl x) = refl
leftInv Iso-A□4-Susp (inr x) = refl
leftInv Iso-A□4-Susp (push a i) = refl
Iso-PushSusp×-Susp×Susp :
Iso (Pushout {A = Susp A × B} fst fst) (Susp A × Susp B)
Iso-PushSusp×-Susp×Susp = theIso
where
F : Pushout {A = Susp A × B} fst fst
→ Susp A × Susp B
F (inl x) = x , north
F (inr x) = x , north
F (push (x , b) i) = x , σB b i
G : Susp A × Susp B → Pushout {A = Susp A × B} fst fst
G (a , north) = inl a
G (a , south) = inr a
G (a , merid b i) = push (a , b) i
retr : retract F G
retr (inl x) = refl
retr (inr x) = push (x , b₀)
retr (push (a , b) i) j = help j i
where
help : PathP (λ i → Path (Pushout fst fst) (inl a) (push (a , b₀) i))
(cong G (λ i → a , σB b i))
(push (a , b))
help = cong-∙ (λ x → G (a , x)) (merid b) (sym (merid b₀))
◁ λ i j → compPath-filler
(push (a , b))
(sym (push (a , b₀)))
(~ i) j
theIso : Iso (Pushout fst fst) (Susp A × Susp B)
fun theIso = F
inv theIso = G
rightInv theIso (a , north) = refl
rightInv theIso (a , south) = ΣPathP (refl , merid b₀)
rightInv theIso (a , merid b i) j =
a , compPath-filler (merid b) (sym (merid b₀)) (~ j) i
leftInv theIso = retr
Iso-A□○-PushSusp× :
Iso (A□○ whitehead3x3) (Pushout {A = Susp A × B} fst fst)
Iso-A□○-PushSusp× =
pushoutIso _ _ fst fst
(isoToEquiv Iso-A□2-Susp×)
(isoToEquiv Iso-A□0-Susp)
(isoToEquiv Iso-A□4-Susp)
(funExt (λ { (inl x) → refl
; (inr x) → merid a₀
; (push a i) j → help₁ a j i}))
(funExt λ { (inl x) → refl
; (inr x) → refl
; (push a i) j
→ fun Iso-A□4-Susp (rUnit (push (fst a)) (~ j) i)})
where
help₁ : (a : A × B)
→ PathP (λ i → north ≡ merid a₀ i)
(cong (fun Iso-A□0-Susp)
(cong (f□1 whitehead3x3) (push a)))
(merid (fst a))
help₁ a =
(cong-∙∙ (fun Iso-A□0-Susp)
(λ i → inl (merid (fst a) i))
(push (snd a))
refl)
◁ (λ i j → hcomp (λ k → λ {(i = i1) → merid (fst a) (j ∨ ~ k)
; (j = i0) → merid (fst a) (~ k)
; (j = i1) → merid a₀ i})
(merid a₀ (i ∨ ~ j)))
Iso-A□○-Susp×Susp : Iso (A□○ whitehead3x3) (Susp A × Susp B)
Iso-A□○-Susp×Susp = compIso Iso-A□○-PushSusp× Iso-PushSusp×-Susp×Susp
Iso-A○□-cofibW : Iso (A○□ whitehead3x3) cofibW
Iso-A○□-cofibW =
pushoutIso _ _
W (λ _ → tt)
(isoToEquiv Iso-A2□-join) (isoToEquiv Iso-A0□-⋁)
A4□≃Unit
(funExt lem)
λ _ _ → tt
where
lem : (x : A2□ whitehead3x3)
→ A0□→A∨B (f1□ whitehead3x3 x) ≡ W (fun Iso-A2□-join x)
lem (inl x) = (λ i → inl (merid a₀ (~ i)))
lem (inr x) = refl
lem (push (a , b) i) j = help j i
where
help : PathP (λ i → Path (Pushout (λ _ → north) (λ _ → north))
((inl (merid a₀ (~ i))))
(inr north))
(cong A0□→A∨B (cong (f1□ whitehead3x3) (push (a , b))))
(cong W (cong (fun Iso-A2□-join) (push (a , b))))
help = (cong-∙∙ A0□→A∨B (λ i → inl (merid a (~ i))) (push b) refl
∙ λ j → (λ i₂ → inl (merid a (~ i₂)))
∙∙ compPath-filler (push tt) (λ i → inr (σB b (~ i))) (~ j)
∙∙ λ i → inr (σB b (~ i ∧ j)))
◁ (λ j → (λ i → inl (sym (compPath-filler
(merid a) (sym (merid a₀)) j) i))
∙∙ push tt
∙∙ λ i → inr (σB b (~ i)))
Iso₁-Susp×Susp-cofibW : Iso (Susp A × Susp B) cofibW
Iso₁-Susp×Susp-cofibW =
compIso (invIso Iso-A□○-Susp×Susp)
(compIso (3x3-Iso whitehead3x3) Iso-A○□-cofibW)
-- Main iso
Iso-Susp×Susp-cofibJoinTo⋁ : Iso (Susp A × Susp B) cofibW
Iso-Susp×Susp-cofibJoinTo⋁ =
compIso (Σ-cong-iso-snd (λ _ → invSuspIso))
Iso₁-Susp×Susp-cofibW
-- The induced function A ∨ B → Susp A × Susp B satisfies
-- the following identity
Susp×Susp→cofibW≡ : Path (A∨B → Susp A × Susp B)
(Iso.inv Iso-Susp×Susp-cofibJoinTo⋁ ∘ inl)
⋁↪
Susp×Susp→cofibW≡ =
funExt λ { (inl x) → ΣPathP (refl , (sym (merid b₀)))
; (inr north) → ΣPathP (refl , (sym (merid b₀)))
; (inr south) → refl
; (inr (merid a i)) j → lem₂ a j i
; (push a i) j → north , (merid b₀ (~ j))}
where
f₁ = fun Iso-PushSusp×-Susp×Susp
f₂ = fun Iso-A□○-PushSusp×
f₃ = backward-l whitehead3x3
f₄ = fun (Σ-cong-iso-snd (λ _ → invSuspIso))
lem : (b : B)
→ cong (f₁ ∘ f₂ ∘ f₃) (push b)
≡ (λ i → north , σB b i)
lem b = cong (cong f₁) (sym (rUnit (push (north , b))))
lem₂ : (a : B)
→ PathP (λ i → (north , merid b₀ (~ i)) ≡ (north , south))
(cong (f₄ ∘ f₁ ∘ f₂ ∘ f₃ ∘ A∨B→A0□ ∘ inr) (merid a))
λ i → north , merid a i
lem₂ a =
cong (cong f₄) (cong-∙ (f₁ ∘ f₂ ∘ f₃) (push b₀) (sym (push a))
∙∙ cong₂ _∙_ (lem b₀ ∙ (λ j i → north , rCancel (merid b₀) j i))
(cong sym (lem a))
∙∙ sym (lUnit (λ i₁ → north , σB a (~ i₁))))
∙ (λ i j → north , cong-∙ invSusp (merid a) (sym (merid b₀)) i (~ j) )
◁ λ i j → north , compPath-filler (sym (merid a)) (merid b₀) (~ i) (~ j)
|
oeis/033/A033906.asm | neoneye/loda-programs | 11 | 177346 | <filename>oeis/033/A033906.asm<gh_stars>10-100
; A033906: Sort then Add!.
; Submitted by <NAME>
; 20,22,44,88,176,343,677,1354,2699,5398,8987,16876,33554,67009,67688,134476,268943,503632,526988,783877,1161665,2277331,3500708,3504286,3738854,7084642,7329320,7552699,10109498,10224397,11447876,22894654
mov $1,20
lpb $0
sub $0,1
seq $1,70196 ; a(n)=n plus the sorted version of the base-10 digits of n.
lpe
mov $0,$1
|
1A/S5/PIM/tps/tp1/min_max_serie.adb | MOUDDENEHamza/ENSEEIHT | 4 | 5682 | <filename>1A/S5/PIM/tps/tp1/min_max_serie.adb
with Text_IO;
use Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
-- Afficher le plus petit et le plus grand élément d'une série d'entiers
-- naturels lus au clavier. La saisie de la série se termine par 0
-- (qui n'appartient pas à la série).
-- Exemple : 2, 9, 3, 6, 3, 0 -> min = 2 et max = 9
procedure Min_Max_Serie is
Entier: Integer; -- un entier lu au clavier
Min, Max: Integer; -- le plus petit et le plus grand élément de la série
begin
-- Afficher la consigne
Put("Saisir les valeurs de la série (-1 pour terminer) : ");
-- Saisir un premier entier
Put("Saisir les valeurs de la série (-1 pour terminer) : ");
Get(Entier);
if Entier = 0 then --{ entier n'est pas une valeur de la série }
Put_Line("Pas de valeurs dans la série");
else -- Entier est le premier élément de la série
-- initialiser Min et Max avec le premier entier
Min := Entier;
Max := Entier;
-- traiter les autres éléments de la série
Get(Entier); -- saisir un nouvel entier
while Entier /= 0 loop -- Entier est une valeur de la série
-- mettre à jour le Min et le Max
if Entier > Max then -- nouveau max
-- mettre à jour le max avec Entier
Max := Entier;
elsif Entier < Min then -- nouveau Min
-- mettre à jour le min avec Entier
Min := Entier;
else
null;
end if;
-- saisir un nouvel entier
Get(Entier);
end loop;
-- afficher le min et le max de la série
Put("Min = ");
Put(Min, 1);
New_Line;
Put_Line("Max =" & Integer'Image(Max));
end if;
end Min_Max_Serie;
|
Validation/pyFrame3DD-master/gcc-master/gcc/ada/sem_elab.adb | djamal2727/Main-Bearing-Analytical-Model | 0 | 27551 | <gh_stars>0
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ E L A B --
-- --
-- B o d y --
-- --
-- Copyright (C) 1997-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with ALI; use ALI;
with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
with Exp_Ch11; use Exp_Ch11;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Expander; use Expander;
with Lib; use Lib;
with Lib.Load; use Lib.Load;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Cat; use Sem_Cat;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Disp; use Sem_Disp;
with Sem_Prag; use Sem_Prag;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Snames; use Snames;
with Stand; use Stand;
with Table;
with Tbuild; use Tbuild;
with Uintp; use Uintp;
with Uname; use Uname;
with GNAT; use GNAT;
with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
with GNAT.Lists; use GNAT.Lists;
with GNAT.Sets; use GNAT.Sets;
package body Sem_Elab is
-----------------------------------------
-- Access-before-elaboration mechanism --
-----------------------------------------
-- The access-before-elaboration (ABE) mechanism implemented in this unit
-- has the following objectives:
--
-- * Diagnose at compile time or install run-time checks to prevent ABE
-- access to data and behavior.
--
-- The high-level idea is to accurately diagnose ABE issues within a
-- single unit because the ABE mechanism can inspect the whole unit.
-- As soon as the elaboration graph extends to an external unit, the
-- diagnostics stop because the body of the unit may not be available.
-- Due to control and data flow, the ABE mechanism cannot accurately
-- determine whether a particular scenario will be elaborated or not.
-- Conditional ABE checks are therefore used to verify the elaboration
-- status of local and external targets at run time.
--
-- * Supply implicit elaboration dependencies for a unit to binde
--
-- The ABE mechanism creates implicit dependencies in the form of with
-- clauses subject to pragma Elaborate[_All] when the elaboration graph
-- reaches into an external unit. The implicit dependencies are encoded
-- in the ALI file of the main unit. GNATbind and binde then use these
-- dependencies to augment the library item graph and determine the
-- elaboration order of all units in the compilation.
--
-- * Supply pieces of the invocation graph for a unit to bindo
--
-- The ABE mechanism captures paths starting from elaboration code or
-- top level constructs that reach into an external unit. The paths are
-- encoded in the ALI file of the main unit in the form of declarations
-- which represent nodes, and relations which represent edges. GNATbind
-- and bindo then build the full invocation graph in order to augment
-- the library item graph and determine the elaboration order of all
-- units in the compilation.
--
-- The ABE mechanism supports three models of elaboration:
--
-- * Dynamic model - This is the most permissive of the three models.
-- When the dynamic model is in effect, the mechanism diagnoses and
-- installs run-time checks to detect ABE issues in the main unit.
-- The behavior of this model is identical to that specified by the
-- Ada RM. This model is enabled with switch -gnatE.
--
-- Static model - This is the middle ground of the three models. When
-- the static model is in effect, the mechanism diagnoses and installs
-- run-time checks to detect ABE issues in the main unit. In addition,
-- the mechanism generates implicit dependencies between units in the
-- form of with clauses subject to pragma Elaborate[_All] to ensure
-- the prior elaboration of withed units. This is the default model.
--
-- * SPARK model - This is the most conservative of the three models and
-- implements the semantics defined in SPARK RM 7.7. The SPARK model
-- is in effect only when a context resides in a SPARK_Mode On region,
-- otherwise the mechanism falls back to one of the previous models.
--
-- The ABE mechanism consists of a "recording" phase and a "processing"
-- phase.
-----------------
-- Terminology --
-----------------
-- * ABE - An attempt to invoke a scenario which has not been elaborated
-- yet.
--
-- * Bridge target - A type of target. A bridge target is a link between
-- scenarios. It is usually a byproduct of expansion and does not have
-- any direct ABE ramifications.
--
-- * Call marker - A special node used to indicate the presence of a call
-- in the tree in case expansion transforms or eliminates the original
-- call. N_Call_Marker nodes do not have static and run-time semantics.
--
-- * Conditional ABE - A type of ABE. A conditional ABE occurs when the
-- invocation of a target by a scenario within the main unit causes an
-- ABE, but does not cause an ABE for another scenarios within the main
-- unit.
--
-- * Declaration level - A type of enclosing level. A scenario or target is
-- at the declaration level when it appears within the declarations of a
-- block statement, entry body, subprogram body, or task body, ignoring
-- enclosing packages.
--
-- * Early call region - A section of code which ends at a subprogram body
-- and starts from the nearest non-preelaborable construct which precedes
-- the subprogram body. The early call region extends from a package body
-- to a package spec when the spec carries pragma Elaborate_Body.
--
-- * Generic library level - A type of enclosing level. A scenario or
-- target is at the generic library level if it appears in a generic
-- package library unit, ignoring enclosing packages.
--
-- * Guaranteed ABE - A type of ABE. A guaranteed ABE occurs when the
-- invocation of a target by all scenarios within the main unit causes
-- an ABE.
--
-- * Instantiation library level - A type of enclosing level. A scenario
-- or target is at the instantiation library level if it appears in an
-- instantiation library unit, ignoring enclosing packages.
--
-- * Invocation - The act of activating a task, calling a subprogram, or
-- instantiating a generic.
--
-- * Invocation construct - An entry declaration, [single] protected type,
-- subprogram declaration, subprogram instantiation, or a [single] task
-- type declared in the visible, private, or body declarations of the
-- main unit.
--
-- * Invocation relation - A flow link between two invocation constructs
--
-- * Invocation signature - A set of attributes that uniquely identify an
-- invocation construct within the namespace of all ALI files.
--
-- * Library level - A type of enclosing level. A scenario or target is at
-- the library level if it appears in a package library unit, ignoring
-- enclosing packages.
--
-- * Non-library-level encapsulator - A construct that cannot be elaborated
-- on its own and requires elaboration by a top-level scenario.
--
-- * Scenario - A construct or context which is invoked by elaboration code
-- or invocation construct. The scenarios recognized by the ABE mechanism
-- are as follows:
--
-- - '[Unrestricted_]Access of entries, operators, and subprograms
--
-- - Assignments to variables
--
-- - Calls to entries, operators, and subprograms
--
-- - Derived type declarations
--
-- - Instantiations
--
-- - Pragma Refined_State
--
-- - Reads of variables
--
-- - Task activation
--
-- * Target - A construct invoked by a scenario. The targets recognized by
-- the ABE mechanism are as follows:
--
-- - For '[Unrestricted_]Access of entries, operators, and subprograms,
-- the target is the entry, operator, or subprogram.
--
-- - For assignments to variables, the target is the variable
--
-- - For calls, the target is the entry, operator, or subprogram
--
-- - For derived type declarations, the target is the derived type
--
-- - For instantiations, the target is the generic template
--
-- - For pragma Refined_State, the targets are the constituents
--
-- - For reads of variables, the target is the variable
--
-- - For task activation, the target is the task body
------------------
-- Architecture --
------------------
-- Analysis/Resolution
-- |
-- +- Build_Call_Marker
-- |
-- +- Build_Variable_Reference_Marker
-- |
-- +- | -------------------- Recording phase ---------------------------+
-- | v |
-- | Record_Elaboration_Scenario |
-- | | |
-- | +--> Check_Preelaborated_Call |
-- | | |
-- | +--> Process_Guaranteed_ABE |
-- | | | |
-- | | +--> Process_Guaranteed_ABE_Activation |
-- | | +--> Process_Guaranteed_ABE_Call |
-- | | +--> Process_Guaranteed_ABE_Instantiation |
-- | | |
-- +- | ----------------------------------------------------------------+
-- |
-- |
-- +--> Internal_Representation
-- |
-- +--> Scenario_Storage
-- |
-- End of Compilation
-- |
-- +- | --------------------- Processing phase -------------------------+
-- | v |
-- | Check_Elaboration_Scenarios |
-- | | |
-- | +--> Check_Conditional_ABE_Scenarios |
-- | | | |
-- | | +--> Process_Conditional_ABE <----------------------+ |
-- | | | | |
-- | | +--> Process_Conditional_ABE_Activation | |
-- | | | | | |
-- | | | +-----------------------------+ | |
-- | | | | | |
-- | | +--> Process_Conditional_ABE_Call +---> Traverse_Body |
-- | | | | | |
-- | | | +-----------------------------+ |
-- | | | |
-- | | +--> Process_Conditional_ABE_Access_Taken |
-- | | +--> Process_Conditional_ABE_Instantiation |
-- | | +--> Process_Conditional_ABE_Variable_Assignment |
-- | | +--> Process_Conditional_ABE_Variable_Reference |
-- | | |
-- | +--> Check_SPARK_Scenario |
-- | | | |
-- | | +--> Process_SPARK_Scenario |
-- | | | |
-- | | +--> Process_SPARK_Derived_Type |
-- | | +--> Process_SPARK_Instantiation |
-- | | +--> Process_SPARK_Refined_State_Pragma |
-- | | |
-- | +--> Record_Invocation_Graph |
-- | | |
-- | +--> Process_Invocation_Body_Scenarios |
-- | +--> Process_Invocation_Spec_Scenarios |
-- | +--> Process_Main_Unit |
-- | | |
-- | +--> Process_Invocation_Scenario <-------------+ |
-- | | | |
-- | +--> Process_Invocation_Activation | |
-- | | | | |
-- | | +------------------------+ | |
-- | | | | |
-- | +--> Process_Invocation_Call +---> Traverse_Body |
-- | | | |
-- | +------------------------+ |
-- | |
-- +--------------------------------------------------------------------+
---------------------
-- Recording phase --
---------------------
-- The Recording phase coincides with the analysis/resolution phase of the
-- compiler. It has the following objectives:
--
-- * Record all suitable scenarios for examination by the Processing
-- phase.
--
-- Saving only a certain number of nodes improves the performance of
-- the ABE mechanism. This eliminates the need to examine the whole
-- tree in a separate pass.
--
-- * Record certain SPARK scenarios which are not necessarily invoked
-- during elaboration, but still require elaboration-related checks.
--
-- Saving only a certain number of nodes improves the performance of
-- the ABE mechanism. This eliminates the need to examine the whole
-- tree in a separate pass.
--
-- * Detect and diagnose calls in preelaborable or pure units, including
-- generic bodies.
--
-- This diagnostic is carried out during the Recording phase because it
-- does not need the heavy recursive traversal done by the Processing
-- phase.
--
-- * Detect and diagnose guaranteed ABEs caused by instantiations, calls,
-- and task activation.
--
-- The issues detected by the ABE mechanism are reported as warnings
-- because they do not violate Ada semantics. Forward instantiations
-- may thus reach gigi, however gigi cannot handle certain kinds of
-- premature instantiations and may crash. To avoid this limitation,
-- the ABE mechanism must identify forward instantiations as early as
-- possible and suppress their bodies. Calls and task activations are
-- included in this category for completeness.
----------------------
-- Processing phase --
----------------------
-- The Processing phase is a separate pass which starts after instantiating
-- and/or inlining of bodies, but before the removal of Ghost code. It has
-- the following objectives:
--
-- * Examine all scenarios saved during the Recording phase, and perform
-- the following actions:
--
-- - Dynamic model
--
-- Diagnose conditional ABEs, and install run-time conditional ABE
-- checks for all scenarios.
--
-- - SPARK model
--
-- Enforce the SPARK elaboration rules
--
-- - Static model
--
-- Diagnose conditional ABEs, install run-time conditional ABE
-- checks only for scenarios are reachable from elaboration code,
-- and guarantee the elaboration of external units by creating
-- implicit with clauses subject to pragma Elaborate[_All].
--
-- * Examine library-level scenarios and invocation constructs, and
-- perform the following actions:
--
-- - Determine whether the flow of execution reaches into an external
-- unit. If this is the case, encode the path in the ALI file of
-- the main unit.
--
-- - Create declarations for invocation constructs in the ALI file of
-- the main unit.
----------------------
-- Important points --
----------------------
-- The Processing phase starts after the analysis, resolution, expansion
-- phase has completed. As a result, no current semantic information is
-- available. The scope stack is empty, global flags such as In_Instance
-- or Inside_A_Generic become useless. To remedy this, the ABE mechanism
-- must either save or recompute semantic information.
--
-- Expansion heavily transforms calls and to some extent instantiations. To
-- remedy this, the ABE mechanism generates N_Call_Marker nodes in order to
-- capture the target and relevant attributes of the original call.
--
-- The diagnostics of the ABE mechanism depend on accurate source locations
-- to determine the spatial relation of nodes.
-----------------------------------------
-- Suppression of elaboration warnings --
-----------------------------------------
-- Elaboration warnings along multiple traversal paths rooted at a scenario
-- are suppressed when the scenario has elaboration warnings suppressed.
--
-- Root scenario
-- |
-- +-- Child scenario 1
-- | |
-- | +-- Grandchild scenario 1
-- | |
-- | +-- Grandchild scenario N
-- |
-- +-- Child scenario N
--
-- If the root scenario has elaboration warnings suppressed, then all its
-- child, grandchild, etc. scenarios will have their elaboration warnings
-- suppressed.
--
-- In addition to switch -gnatwL, pragma Warnings may be used to suppress
-- elaboration-related warnings when used in the following manner:
--
-- pragma Warnings ("L");
-- <scenario-or-target>
--
-- <target>
-- pragma Warnings (Off, target);
--
-- pragma Warnings (Off);
-- <scenario-or-target>
--
-- * To suppress elaboration warnings for '[Unrestricted_]Access of
-- entries, operators, and subprograms, either:
--
-- - Suppress the entry, operator, or subprogram, or
-- - Suppress the attribute, or
-- - Use switch -gnatw.f
--
-- * To suppress elaboration warnings for calls to entries, operators,
-- and subprograms, either:
--
-- - Suppress the entry, operator, or subprogram, or
-- - Suppress the call
--
-- * To suppress elaboration warnings for instantiations, suppress the
-- instantiation.
--
-- * To suppress elaboration warnings for task activations, either:
--
-- - Suppress the task object, or
-- - Suppress the task type, or
-- - Suppress the activation call
--------------
-- Switches --
--------------
-- The following switches may be used to control the behavior of the ABE
-- mechanism.
--
-- -gnatd_a stop elaboration checks on accept or select statement
--
-- The ABE mechanism stops the traversal of a task body when it
-- encounters an accept or a select statement. This behavior is
-- equivalent to restriction No_Entry_Calls_In_Elaboration_Code,
-- but without penalizing actual entry calls during elaboration.
--
-- -gnatd_e ignore entry calls and requeue statements for elaboration
--
-- The ABE mechanism does not generate N_Call_Marker nodes for
-- protected or task entry calls as well as requeue statements.
-- As a result, the calls and requeues are not recorded or
-- processed.
--
-- -gnatdE elaboration checks on predefined units
--
-- The ABE mechanism considers scenarios which appear in internal
-- units (Ada, GNAT, Interfaces, System).
--
-- -gnatd_F encode full invocation paths in ALI files
--
-- The ABE mechanism encodes the full path from an elaboration
-- procedure or invocable construct to an external target. The
-- path contains all intermediate activations, instantiations,
-- and calls.
--
-- -gnatd.G ignore calls through generic formal parameters for elaboration
--
-- The ABE mechanism does not generate N_Call_Marker nodes for
-- calls which occur in expanded instances, and invoke generic
-- actual subprograms through generic formal subprograms. As a
-- result, the calls are not recorded or processed.
--
-- -gnatd_i ignore activations and calls to instances for elaboration
--
-- The ABE mechanism ignores calls and task activations when they
-- target a subprogram or task type defined an external instance.
-- As a result, the calls and task activations are not processed.
--
-- -gnatdL ignore external calls from instances for elaboration
--
-- The ABE mechanism does not generate N_Call_Marker nodes for
-- calls which occur in expanded instances, do not invoke generic
-- actual subprograms through formal subprograms, and the target
-- is external to the instance. As a result, the calls are not
-- recorded or processed.
--
-- -gnatd.o conservative elaboration order for indirect calls
--
-- The ABE mechanism treats '[Unrestricted_]Access of an entry,
-- operator, or subprogram as an immediate invocation of the
-- target. As a result, it performs ABE checks and diagnostics on
-- the immediate call.
--
-- -gnatd_p ignore assertion pragmas for elaboration
--
-- The ABE mechanism does not generate N_Call_Marker nodes for
-- calls to subprograms which verify the run-time semantics of
-- the following assertion pragmas:
--
-- Default_Initial_Condition
-- Initial_Condition
-- Invariant
-- Invariant'Class
-- Post
-- Post'Class
-- Postcondition
-- Type_Invariant
-- Type_Invariant_Class
--
-- As a result, the assertion expressions of the pragmas are not
-- processed.
--
-- -gnatd_s stop elaboration checks on synchronous suspension
--
-- The ABE mechanism stops the traversal of a task body when it
-- encounters a call to one of the following routines:
--
-- Ada.Synchronous_Barriers.Wait_For_Release
-- Ada.Synchronous_Task_Control.Suspend_Until_True
--
-- -gnatd_T output trace information on invocation relation construction
--
-- The ABE mechanism outputs text information concerning relation
-- construction to standard output.
--
-- -gnatd.U ignore indirect calls for static elaboration
--
-- The ABE mechanism does not consider '[Unrestricted_]Access of
-- entries, operators, and subprograms. As a result, the scenarios
-- are not recorder or processed.
--
-- -gnatd.v enforce SPARK elaboration rules in SPARK code
--
-- The ABE mechanism applies some of the SPARK elaboration rules
-- defined in the SPARK reference manual, chapter 7.7. Note that
-- certain rules are always enforced, regardless of whether the
-- switch is active.
--
-- -gnatd.y disable implicit pragma Elaborate_All on task bodies
--
-- The ABE mechanism does not generate implicit Elaborate_All when
-- the need for the pragma came from a task body.
--
-- -gnatE dynamic elaboration checking mode enabled
--
-- The ABE mechanism assumes that any scenario is elaborated or
-- invoked by elaboration code. The ABE mechanism performs very
-- little diagnostics and generates condintional ABE checks to
-- detect ABE issues at run-time.
--
-- -gnatel turn on info messages on generated Elaborate[_All] pragmas
--
-- The ABE mechanism produces information messages on generated
-- implicit Elabote[_All] pragmas along with traceback showing
-- why the pragma was generated. In addition, the ABE mechanism
-- produces information messages for each scenario elaborated or
-- invoked by elaboration code.
--
-- -gnateL turn off info messages on generated Elaborate[_All] pragmas
--
-- The complementary switch for -gnatel.
--
-- -gnatH legacy elaboration checking mode enabled
--
-- When this switch is in effect, the pre-18.x ABE model becomes
-- the de facto ABE model. This amounts to cutting off all entry
-- points into the new ABE mechanism, and giving full control to
-- the old ABE mechanism.
--
-- -gnatJ permissive elaboration checking mode enabled
--
-- This switch activates the following switches:
--
-- -gnatd_a
-- -gnatd_e
-- -gnatd.G
-- -gnatd_i
-- -gnatdL
-- -gnatd_p
-- -gnatd_s
-- -gnatd.U
-- -gnatd.y
--
-- IMPORTANT: The behavior of the ABE mechanism becomes more
-- permissive at the cost of accurate diagnostics and runtime
-- ABE checks.
--
-- -gnatw.f turn on warnings for suspicious Subp'Access
--
-- The ABE mechanism treats '[Unrestricted_]Access of an entry,
-- operator, or subprogram as a pseudo invocation of the target.
-- As a result, it performs ABE diagnostics on the pseudo call.
--
-- -gnatw.F turn off warnings for suspicious Subp'Access
--
-- The complementary switch for -gnatw.f.
--
-- -gnatwl turn on warnings for elaboration problems
--
-- The ABE mechanism produces warnings on detected ABEs along with
-- a traceback showing the graph of the ABE.
--
-- -gnatwL turn off warnings for elaboration problems
--
-- The complementary switch for -gnatwl.
--------------------------
-- Debugging ABE issues --
--------------------------
-- * If the issue involves a call, ensure that the call is eligible for ABE
-- processing and receives a corresponding call marker. The routines of
-- interest are
--
-- Build_Call_Marker
-- Record_Elaboration_Scenario
--
-- * If the issue involves an arbitrary scenario, ensure that the scenario
-- is either recorded, or is successfully recognized while traversing a
-- body. The routines of interest are
--
-- Record_Elaboration_Scenario
-- Process_Conditional_ABE
-- Process_Guaranteed_ABE
-- Traverse_Body
--
-- * If the issue involves a circularity in the elaboration order, examine
-- the ALI files and look for the following encodings next to units:
--
-- E indicates a source Elaborate
--
-- EA indicates a source Elaborate_All
--
-- AD indicates an implicit Elaborate_All
--
-- ED indicates an implicit Elaborate
--
-- If possible, compare these encodings with those generated by the old
-- ABE mechanism. The routines of interest are
--
-- Ensure_Prior_Elaboration
-----------
-- Kinds --
-----------
-- The following type enumerates all possible elaboration phase statutes
type Elaboration_Phase_Status is
(Inactive,
-- The elaboration phase of the compiler has not started yet
Active,
-- The elaboration phase of the compiler is currently in progress
Completed);
-- The elaboration phase of the compiler has finished
Elaboration_Phase : Elaboration_Phase_Status := Inactive;
-- The status of the elaboration phase. Use routine Set_Elaboration_Phase
-- to alter its value.
-- The following type enumerates all subprogram body traversal modes
type Body_Traversal_Kind is
(Deep_Traversal,
-- The traversal examines the internals of a subprogram
No_Traversal);
-- The following type enumerates all operation modes
type Processing_Kind is
(Conditional_ABE_Processing,
-- The ABE mechanism detects and diagnoses conditional ABEs for library
-- and declaration-level scenarios.
Dynamic_Model_Processing,
-- The ABE mechanism installs conditional ABE checks for all eligible
-- scenarios when the dynamic model is in effect.
Guaranteed_ABE_Processing,
-- The ABE mechanism detects and diagnoses guaranteed ABEs caused by
-- calls, instantiations, and task activations.
Invocation_Construct_Processing,
-- The ABE mechanism locates all invocation constructs within the main
-- unit and utilizes them as roots of miltiple DFS traversals aimed at
-- detecting transitions from the main unit to an external unit.
Invocation_Body_Processing,
-- The ABE mechanism utilizes all library-level body scenarios as roots
-- of miltiple DFS traversals aimed at detecting transitions from the
-- main unit to an external unit.
Invocation_Spec_Processing,
-- The ABE mechanism utilizes all library-level spec scenarios as roots
-- of miltiple DFS traversals aimed at detecting transitions from the
-- main unit to an external unit.
SPARK_Processing,
-- The ABE mechanism detects and diagnoses violations of the SPARK
-- elaboration rules for SPARK-specific scenarios.
No_Processing);
-- The following type enumerates all possible scenario kinds
type Scenario_Kind is
(Access_Taken_Scenario,
-- An attribute reference which takes 'Access or 'Unrestricted_Access of
-- an entry, operator, or subprogram.
Call_Scenario,
-- A call which invokes an entry, operator, or subprogram
Derived_Type_Scenario,
-- A declaration of a derived type. This is a SPARK-specific scenario.
Instantiation_Scenario,
-- An instantiation which instantiates a generic package or subprogram.
-- This scenario is also subject to SPARK-specific rules.
Refined_State_Pragma_Scenario,
-- A Refined_State pragma. This is a SPARK-specific scenario.
Task_Activation_Scenario,
-- A call which activates objects of various task types
Variable_Assignment_Scenario,
-- An assignment statement which modifies the value of some variable
Variable_Reference_Scenario,
-- A reference to a variable. This is a SPARK-specific scenario.
No_Scenario);
-- The following type enumerates all possible consistency models of target
-- and scenario representations.
type Representation_Kind is
(Inconsistent_Representation,
-- A representation is said to be "inconsistent" when it is created from
-- a partially analyzed tree. In such an environment, certain attributes
-- such as a completing body may not be available yet.
Consistent_Representation,
-- A representation is said to be "consistent" when it is created from a
-- fully analyzed tree, where all attributes are available.
No_Representation);
-- The following type enumerates all possible target kinds
type Target_Kind is
(Generic_Target,
-- A generic unit being instantiated
Package_Target,
-- The package form of an instantiation
Subprogram_Target,
-- An entry, operator, or subprogram being invoked, or aliased through
-- 'Access or 'Unrestricted_Access.
Task_Target,
-- A task being activated by an activation call
Variable_Target,
-- A variable being updated through an assignment statement, or read
-- through a variable reference.
No_Target);
-----------
-- Types --
-----------
procedure Destroy (NE : in out Node_Or_Entity_Id);
pragma Inline (Destroy);
-- Destroy node or entity NE
function Hash (NE : Node_Or_Entity_Id) return Bucket_Range_Type;
pragma Inline (Hash);
-- Obtain the hash value of key NE
-- The following is a general purpose list for nodes and entities
package NE_List is new Doubly_Linked_Lists
(Element_Type => Node_Or_Entity_Id,
"=" => "=",
Destroy_Element => Destroy);
-- The following is a general purpose map which relates nodes and entities
-- to lists of nodes and entities.
package NE_List_Map is new Dynamic_Hash_Tables
(Key_Type => Node_Or_Entity_Id,
Value_Type => NE_List.Doubly_Linked_List,
No_Value => NE_List.Nil,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => NE_List.Destroy,
Hash => Hash);
-- The following is a general purpose membership set for nodes and entities
package NE_Set is new Membership_Sets
(Element_Type => Node_Or_Entity_Id,
"=" => "=",
Hash => Hash);
-- The following type captures relevant attributes which pertain to the
-- in state of the Processing phase.
type Processing_In_State is record
Processing : Processing_Kind := No_Processing;
-- Operation mode of the Processing phase. Once set, this value should
-- not be changed.
Representation : Representation_Kind := No_Representation;
-- Required level of scenario and target representation. Once set, this
-- value should not be changed.
Suppress_Checks : Boolean := False;
-- This flag is set when the Processing phase must not generate any ABE
-- checks.
Suppress_Implicit_Pragmas : Boolean := False;
-- This flag is set when the Processing phase must not generate any
-- implicit Elaborate[_All] pragmas.
Suppress_Info_Messages : Boolean := False;
-- This flag is set when the Processing phase must not emit any info
-- messages.
Suppress_Up_Level_Targets : Boolean := False;
-- This flag is set when the Processing phase must ignore up-level
-- targets.
Suppress_Warnings : Boolean := False;
-- This flag is set when the Processing phase must not emit any warnings
-- on elaboration problems.
Traversal : Body_Traversal_Kind := No_Traversal;
-- The subprogram body traversal mode. Once set, this value should not
-- be changed.
Within_Generic : Boolean := False;
-- This flag is set when the Processing phase is currently within a
-- generic unit.
Within_Initial_Condition : Boolean := False;
-- This flag is set when the Processing phase is currently examining a
-- scenario which was reached from an initial condition procedure.
Within_Partial_Finalization : Boolean := False;
-- This flag is set when the Processing phase is currently examining a
-- scenario which was reached from a partial finalization procedure.
Within_Task_Body : Boolean := False;
-- This flag is set when the Processing phase is currently examining a
-- scenario which was reached from a task body.
end record;
-- The following constants define the various operational states of the
-- Processing phase.
-- The conditional ABE state is used when processing scenarios that appear
-- at the declaration, instantiation, and library levels to detect errors
-- and install conditional ABE checks.
Conditional_ABE_State : constant Processing_In_State :=
(Processing => Conditional_ABE_Processing,
Representation => Consistent_Representation,
Traversal => Deep_Traversal,
others => False);
-- The dynamic model state is used to install conditional ABE checks when
-- switch -gnatE (dynamic elaboration checking mode enabled) is in effect.
Dynamic_Model_State : constant Processing_In_State :=
(Processing => Dynamic_Model_Processing,
Representation => Consistent_Representation,
Suppress_Implicit_Pragmas => True,
Suppress_Info_Messages => True,
Suppress_Up_Level_Targets => True,
Suppress_Warnings => True,
Traversal => No_Traversal,
others => False);
-- The guaranteed ABE state is used when processing scenarios that appear
-- at the declaration, instantiation, and library levels to detect errors
-- and install guarateed ABE failures.
Guaranteed_ABE_State : constant Processing_In_State :=
(Processing => Guaranteed_ABE_Processing,
Representation => Inconsistent_Representation,
Suppress_Implicit_Pragmas => True,
Traversal => No_Traversal,
others => False);
-- The invocation body state is used when processing scenarios that appear
-- at the body library level to encode paths that start from elaboration
-- code and ultimately reach into external units.
Invocation_Body_State : constant Processing_In_State :=
(Processing => Invocation_Body_Processing,
Representation => Consistent_Representation,
Suppress_Checks => True,
Suppress_Implicit_Pragmas => True,
Suppress_Info_Messages => True,
Suppress_Up_Level_Targets => True,
Suppress_Warnings => True,
Traversal => Deep_Traversal,
others => False);
-- The invocation construct state is used when processing constructs that
-- appear within the spec and body of the main unit and eventually reach
-- into external units.
Invocation_Construct_State : constant Processing_In_State :=
(Processing => Invocation_Construct_Processing,
Representation => Consistent_Representation,
Suppress_Checks => True,
Suppress_Implicit_Pragmas => True,
Suppress_Info_Messages => True,
Suppress_Up_Level_Targets => True,
Suppress_Warnings => True,
Traversal => Deep_Traversal,
others => False);
-- The invocation spec state is used when processing scenarios that appear
-- at the spec library level to encode paths that start from elaboration
-- code and ultimately reach into external units.
Invocation_Spec_State : constant Processing_In_State :=
(Processing => Invocation_Spec_Processing,
Representation => Consistent_Representation,
Suppress_Checks => True,
Suppress_Implicit_Pragmas => True,
Suppress_Info_Messages => True,
Suppress_Up_Level_Targets => True,
Suppress_Warnings => True,
Traversal => Deep_Traversal,
others => False);
-- The SPARK state is used when verying SPARK-specific semantics of certain
-- scenarios.
SPARK_State : constant Processing_In_State :=
(Processing => SPARK_Processing,
Representation => Consistent_Representation,
Traversal => No_Traversal,
others => False);
-- The following type identifies a scenario representation
type Scenario_Rep_Id is new Natural;
No_Scenario_Rep : constant Scenario_Rep_Id := Scenario_Rep_Id'First;
First_Scenario_Rep : constant Scenario_Rep_Id := No_Scenario_Rep + 1;
-- The following type identifies a target representation
type Target_Rep_Id is new Natural;
No_Target_Rep : constant Target_Rep_Id := Target_Rep_Id'First;
First_Target_Rep : constant Target_Rep_Id := No_Target_Rep + 1;
--------------
-- Services --
--------------
-- The following package keeps track of all active scenarios during a DFS
-- traversal.
package Active_Scenarios is
-----------
-- Types --
-----------
-- The following type defines the position within the active scenario
-- stack.
type Active_Scenario_Pos is new Natural;
---------------------
-- Data structures --
---------------------
-- The following table stores all active scenarios in a DFS traversal.
-- This table must be maintained in a FIFO fashion.
package Active_Scenario_Stack is new Table.Table
(Table_Index_Type => Active_Scenario_Pos,
Table_Component_Type => Node_Id,
Table_Low_Bound => 1,
Table_Initial => 50,
Table_Increment => 200,
Table_Name => "Active_Scenario_Stack");
---------
-- API --
---------
procedure Output_Active_Scenarios
(Error_Nod : Node_Id;
In_State : Processing_In_State);
pragma Inline (Output_Active_Scenarios);
-- Output the contents of the active scenario stack from earliest to
-- latest to supplement an earlier error emitted for node Error_Nod.
-- In_State denotes the current state of the Processing phase.
procedure Pop_Active_Scenario (N : Node_Id);
pragma Inline (Pop_Active_Scenario);
-- Pop the top of the scenario stack. A check is made to ensure that the
-- scenario being removed is the same as N.
procedure Push_Active_Scenario (N : Node_Id);
pragma Inline (Push_Active_Scenario);
-- Push scenario N on top of the scenario stack
function Root_Scenario return Node_Id;
pragma Inline (Root_Scenario);
-- Return the scenario which started a DFS traversal
end Active_Scenarios;
use Active_Scenarios;
-- The following package provides the main entry point for task activation
-- processing.
package Activation_Processor is
-----------
-- Types --
-----------
type Activation_Processor_Ptr is access procedure
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State);
-- Reference to a procedure that takes all attributes of an activation
-- and performs a desired action. Call is the activation call. Call_Rep
-- is the representation of the call. Obj_Id is the task object being
-- activated. Obj_Rep is the representation of the object. Task_Typ is
-- the task type whose body is being activated. Task_Rep denotes the
-- representation of the task type. In_State is the current state of
-- the Processing phase.
---------
-- API --
---------
procedure Process_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Processor : Activation_Processor_Ptr;
In_State : Processing_In_State);
-- Find all task objects activated by activation call Call and invoke
-- Processor on them. Call_Rep denotes the representation of the call.
-- In_State is the current state of the Processing phase.
end Activation_Processor;
use Activation_Processor;
-- The following package profides functionality for traversing subprogram
-- bodies in DFS manner and processing of eligible scenarios within.
package Body_Processor is
-----------
-- Types --
-----------
type Scenario_Predicate_Ptr is access function
(N : Node_Id) return Boolean;
-- Reference to a function which determines whether arbitrary node N
-- denotes a suitable scenario for processing.
type Scenario_Processor_Ptr is access procedure
(N : Node_Id; In_State : Processing_In_State);
-- Reference to a procedure which processes scenario N. In_State is the
-- current state of the Processing phase.
---------
-- API --
---------
procedure Traverse_Body
(N : Node_Id;
Requires_Processing : Scenario_Predicate_Ptr;
Processor : Scenario_Processor_Ptr;
In_State : Processing_In_State);
pragma Inline (Traverse_Body);
-- Traverse the declarations and handled statements of subprogram body
-- N, looking for scenarios that satisfy predicate Requires_Processing.
-- Routine Processor is invoked for each such scenario.
procedure Reset_Traversed_Bodies;
pragma Inline (Reset_Traversed_Bodies);
-- Reset the visited status of all subprogram bodies that have already
-- been processed by routine Traverse_Body.
-----------------
-- Maintenance --
-----------------
procedure Finalize_Body_Processor;
pragma Inline (Finalize_Body_Processor);
-- Finalize all internal data structures
procedure Initialize_Body_Processor;
pragma Inline (Initialize_Body_Processor);
-- Initialize all internal data structures
end Body_Processor;
use Body_Processor;
-- The following package provides functionality for installing ABE-related
-- checks and failures.
package Check_Installer is
---------
-- API --
---------
function Check_Or_Failure_Generation_OK return Boolean;
pragma Inline (Check_Or_Failure_Generation_OK);
-- Determine whether a conditional ABE check or guaranteed ABE failure
-- can be generated.
procedure Install_Dynamic_ABE_Checks;
pragma Inline (Install_Dynamic_ABE_Checks);
-- Install conditional ABE checks for all saved scenarios when the
-- dynamic model is in effect.
procedure Install_Scenario_ABE_Check
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Scenario_Rep_Id);
pragma Inline (Install_Scenario_ABE_Check);
-- Install a conditional ABE check for scenario N to ensure that target
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the
-- target. If the check is installed, disable the elaboration checks of
-- scenario Disable.
procedure Install_Scenario_ABE_Check
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Target_Rep_Id);
pragma Inline (Install_Scenario_ABE_Check);
-- Install a conditional ABE check for scenario N to ensure that target
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the
-- target. If the check is installed, disable the elaboration checks of
-- target Disable.
procedure Install_Scenario_ABE_Failure
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Scenario_Rep_Id);
pragma Inline (Install_Scenario_ABE_Failure);
-- Install a guaranteed ABE failure for scenario N with target Targ_Id.
-- Targ_Rep denotes the representation of the target. If the failure is
-- installed, disable the elaboration checks of scenario Disable.
procedure Install_Scenario_ABE_Failure
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Target_Rep_Id);
pragma Inline (Install_Scenario_ABE_Failure);
-- Install a guaranteed ABE failure for scenario N with target Targ_Id.
-- Targ_Rep denotes the representation of the target. If the failure is
-- installed, disable the elaboration checks of target Disable.
procedure Install_Unit_ABE_Check
(N : Node_Id;
Unit_Id : Entity_Id;
Disable : Scenario_Rep_Id);
pragma Inline (Install_Unit_ABE_Check);
-- Install a conditional ABE check for scenario N to ensure that unit
-- Unit_Id is properly elaborated. If the check is installed, disable
-- the elaboration checks of scenario Disable.
procedure Install_Unit_ABE_Check
(N : Node_Id;
Unit_Id : Entity_Id;
Disable : Target_Rep_Id);
pragma Inline (Install_Unit_ABE_Check);
-- Install a conditional ABE check for scenario N to ensure that unit
-- Unit_Id is properly elaborated. If the check is installed, disable
-- the elaboration checks of target Disable.
end Check_Installer;
use Check_Installer;
-- The following package provides the main entry point for conditional ABE
-- checks and diagnostics.
package Conditional_ABE_Processor is
---------
-- API --
---------
procedure Check_Conditional_ABE_Scenarios
(Iter : in out NE_Set.Iterator);
pragma Inline (Check_Conditional_ABE_Scenarios);
-- Perform conditional ABE checks and diagnostics for all scenarios
-- available through iterator Iter.
procedure Process_Conditional_ABE
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE);
-- Perform conditional ABE checks and diagnostics for scenario N.
-- In_State denotes the current state of the Processing phase.
end Conditional_ABE_Processor;
use Conditional_ABE_Processor;
-- The following package provides functionality to emit errors, information
-- messages, and warnings.
package Diagnostics is
---------
-- API --
---------
procedure Elab_Msg_NE
(Msg : String;
N : Node_Id;
Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean);
pragma Inline (Elab_Msg_NE);
-- Wrapper around Error_Msg_NE. Emit message Msg concerning arbitrary
-- node N and entity. If flag Info_Msg is set, the routine emits an
-- information message, otherwise it emits an error. If flag In_SPARK
-- is set, then string " in SPARK" is added to the end of the message.
procedure Info_Call
(Call : Node_Id;
Subp_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean);
pragma Inline (Info_Call);
-- Output information concerning call Call that invokes subprogram
-- Subp_Id. When flag Info_Msg is set, the routine emits an information
-- message, otherwise it emits an error. When flag In_SPARK is set, " in
-- SPARK" is added to the end of the message.
procedure Info_Instantiation
(Inst : Node_Id;
Gen_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean);
pragma Inline (Info_Instantiation);
-- Output information concerning instantiation Inst which instantiates
-- generic unit Gen_Id. If flag Info_Msg is set, the routine emits an
-- information message, otherwise it emits an error. If flag In_SPARK
-- is set, then string " in SPARK" is added to the end of the message.
procedure Info_Variable_Reference
(Ref : Node_Id;
Var_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean);
pragma Inline (Info_Variable_Reference);
-- Output information concerning reference Ref which mentions variable
-- Var_Id. If flag Info_Msg is set, the routine emits an information
-- message, otherwise it emits an error. If flag In_SPARK is set, then
-- string " in SPARK" is added to the end of the message.
end Diagnostics;
use Diagnostics;
-- The following package provides functionality to locate the early call
-- region of a subprogram body.
package Early_Call_Region_Processor is
---------
-- API --
---------
function Find_Early_Call_Region
(Body_Decl : Node_Id;
Assume_Elab_Body : Boolean := False;
Skip_Memoization : Boolean := False) return Node_Id;
pragma Inline (Find_Early_Call_Region);
-- Find the start of the early call region that belongs to subprogram
-- body Body_Decl as defined in SPARK RM 7.7. This routine finds the
-- early call region, memoizes it, and returns it, but this behavior
-- can be altered. Flag Assume_Elab_Body should be set when a package
-- spec may lack pragma Elaborate_Body, but the routine must still
-- examine that spec. Flag Skip_Memoization should be set when the
-- routine must avoid memoizing the region.
-----------------
-- Maintenance --
-----------------
procedure Finalize_Early_Call_Region_Processor;
pragma Inline (Finalize_Early_Call_Region_Processor);
-- Finalize all internal data structures
procedure Initialize_Early_Call_Region_Processor;
pragma Inline (Initialize_Early_Call_Region_Processor);
-- Initialize all internal data structures
end Early_Call_Region_Processor;
use Early_Call_Region_Processor;
-- The following package provides access to the elaboration statuses of all
-- units withed by the main unit.
package Elaborated_Units is
---------
-- API --
---------
procedure Collect_Elaborated_Units;
pragma Inline (Collect_Elaborated_Units);
-- Save the elaboration statuses of all units withed by the main unit
procedure Ensure_Prior_Elaboration
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State);
pragma Inline (Ensure_Prior_Elaboration);
-- Guarantee the elaboration of unit Unit_Id with respect to the main
-- unit by either suggesting or installing an Elaborate[_All] pragma
-- denoted by Prag_Nam. N denotes the related scenario. In_State is the
-- current state of the Processing phase.
function Has_Prior_Elaboration
(Unit_Id : Entity_Id;
Context_OK : Boolean := False;
Elab_Body_OK : Boolean := False;
Same_Unit_OK : Boolean := False) return Boolean;
pragma Inline (Has_Prior_Elaboration);
-- Determine whether unit Unit_Id is elaborated prior to the main unit.
-- If flag Context_OK is set, the routine considers the following case
-- as valid prior elaboration:
--
-- * Unit_Id is in the elaboration context of the main unit
--
-- If flag Elab_Body_OK is set, the routine considers the following case
-- as valid prior elaboration:
--
-- * Unit_Id has pragma Elaborate_Body and is not the main unit
--
-- If flag Same_Unit_OK is set, the routine considers the following
-- cases as valid prior elaboration:
--
-- * Unit_Id is the main unit
--
-- * Unit_Id denotes the spec of the main unit body
procedure Meet_Elaboration_Requirement
(N : Node_Id;
Targ_Id : Entity_Id;
Req_Nam : Name_Id;
In_State : Processing_In_State);
pragma Inline (Meet_Elaboration_Requirement);
-- Determine whether elaboration requirement Req_Nam for scenario N with
-- target Targ_Id is met by the context of the main unit using the SPARK
-- rules. Req_Nam must denote either Elaborate or Elaborate_All. Emit an
-- error if this is not the case. In_State denotes the current state of
-- the Processing phase.
-----------------
-- Maintenance --
-----------------
procedure Finalize_Elaborated_Units;
pragma Inline (Finalize_Elaborated_Units);
-- Finalize all internal data structures
procedure Initialize_Elaborated_Units;
pragma Inline (Initialize_Elaborated_Units);
-- Initialize all internal data structures
end Elaborated_Units;
use Elaborated_Units;
-- The following package provides the main entry point for guaranteed ABE
-- checks and diagnostics.
package Guaranteed_ABE_Processor is
---------
-- API --
---------
procedure Process_Guaranteed_ABE
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Guaranteed_ABE);
-- Perform guaranteed ABE checks and diagnostics for scenario N.
-- In_State is the current state of the Processing phase.
end Guaranteed_ABE_Processor;
use Guaranteed_ABE_Processor;
-- The following package provides access to the internal representation of
-- scenarios and targets.
package Internal_Representation is
-----------
-- Types --
-----------
-- The following type enumerates all possible Ghost mode kinds
type Extended_Ghost_Mode is
(Is_Ignored,
Is_Checked_Or_Not_Specified);
-- The following type enumerates all possible SPARK mode kinds
type Extended_SPARK_Mode is
(Is_On,
Is_Off_Or_Not_Specified);
--------------
-- Builders --
--------------
function Scenario_Representation_Of
(N : Node_Id;
In_State : Processing_In_State) return Scenario_Rep_Id;
pragma Inline (Scenario_Representation_Of);
-- Obtain the id of elaboration scenario N's representation. The routine
-- constructs the representation if it is not available. In_State is the
-- current state of the Processing phase.
function Target_Representation_Of
(Id : Entity_Id;
In_State : Processing_In_State) return Target_Rep_Id;
pragma Inline (Target_Representation_Of);
-- Obtain the id of elaboration target Id's representation. The routine
-- constructs the representation if it is not available. In_State is the
-- current state of the Processing phase.
-------------------------
-- Scenario attributes --
-------------------------
function Activated_Task_Objects
(S_Id : Scenario_Rep_Id) return NE_List.Doubly_Linked_List;
pragma Inline (Activated_Task_Objects);
-- For Task_Activation_Scenario S_Id, obtain the list of task objects
-- the scenario is activating.
function Activated_Task_Type (S_Id : Scenario_Rep_Id) return Entity_Id;
pragma Inline (Activated_Task_Type);
-- For Task_Activation_Scenario S_Id, obtain the currently activated
-- task type.
procedure Disable_Elaboration_Checks (S_Id : Scenario_Rep_Id);
pragma Inline (Disable_Elaboration_Checks);
-- Disable elaboration checks of scenario S_Id
function Elaboration_Checks_OK (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Elaboration_Checks_OK);
-- Determine whether scenario S_Id may be subjected to elaboration
-- checks.
function Elaboration_Warnings_OK (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Elaboration_Warnings_OK);
-- Determine whether scenario S_Id may be subjected to elaboration
-- warnings.
function Ghost_Mode_Of
(S_Id : Scenario_Rep_Id) return Extended_Ghost_Mode;
pragma Inline (Ghost_Mode_Of);
-- Obtain the Ghost mode of scenario S_Id
function Is_Dispatching_Call (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Is_Dispatching_Call);
-- For Call_Scenario S_Id, determine whether the call is dispatching
function Is_Read_Reference (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Is_Read_Reference);
-- For Variable_Reference_Scenario S_Id, determine whether the reference
-- is a read.
function Kind (S_Id : Scenario_Rep_Id) return Scenario_Kind;
pragma Inline (Kind);
-- Obtain the nature of scenario S_Id
function Level (S_Id : Scenario_Rep_Id) return Enclosing_Level_Kind;
pragma Inline (Level);
-- Obtain the enclosing level of scenario S_Id
procedure Set_Activated_Task_Objects
(S_Id : Scenario_Rep_Id;
Task_Objs : NE_List.Doubly_Linked_List);
pragma Inline (Set_Activated_Task_Objects);
-- For Task_Activation_Scenario S_Id, set the list of task objects
-- activated by the scenario to Task_Objs.
procedure Set_Activated_Task_Type
(S_Id : Scenario_Rep_Id;
Task_Typ : Entity_Id);
pragma Inline (Set_Activated_Task_Type);
-- For Task_Activation_Scenario S_Id, set the currently activated task
-- type to Task_Typ.
function SPARK_Mode_Of
(S_Id : Scenario_Rep_Id) return Extended_SPARK_Mode;
pragma Inline (SPARK_Mode_Of);
-- Obtain the SPARK mode of scenario S_Id
function Target (S_Id : Scenario_Rep_Id) return Entity_Id;
pragma Inline (Target);
-- Obtain the target of scenario S_Id
-----------------------
-- Target attributes --
-----------------------
function Barrier_Body_Declaration (T_Id : Target_Rep_Id) return Node_Id;
pragma Inline (Barrier_Body_Declaration);
-- For Subprogram_Target T_Id, obtain the declaration of the barrier
-- function's body.
function Body_Declaration (T_Id : Target_Rep_Id) return Node_Id;
pragma Inline (Body_Declaration);
-- Obtain the declaration of the body which belongs to target T_Id
procedure Disable_Elaboration_Checks (T_Id : Target_Rep_Id);
pragma Inline (Disable_Elaboration_Checks);
-- Disable elaboration checks of target T_Id
function Elaboration_Checks_OK (T_Id : Target_Rep_Id) return Boolean;
pragma Inline (Elaboration_Checks_OK);
-- Determine whether target T_Id may be subjected to elaboration checks
function Elaboration_Warnings_OK (T_Id : Target_Rep_Id) return Boolean;
pragma Inline (Elaboration_Warnings_OK);
-- Determine whether target T_Id may be subjected to elaboration
-- warnings.
function Ghost_Mode_Of (T_Id : Target_Rep_Id) return Extended_Ghost_Mode;
pragma Inline (Ghost_Mode_Of);
-- Obtain the Ghost mode of target T_Id
function Kind (T_Id : Target_Rep_Id) return Target_Kind;
pragma Inline (Kind);
-- Obtain the nature of target T_Id
function SPARK_Mode_Of (T_Id : Target_Rep_Id) return Extended_SPARK_Mode;
pragma Inline (SPARK_Mode_Of);
-- Obtain the SPARK mode of target T_Id
function Spec_Declaration (T_Id : Target_Rep_Id) return Node_Id;
pragma Inline (Spec_Declaration);
-- Obtain the declaration of the spec which belongs to target T_Id
function Unit (T_Id : Target_Rep_Id) return Entity_Id;
pragma Inline (Unit);
-- Obtain the unit where the target is defined
function Variable_Declaration (T_Id : Target_Rep_Id) return Node_Id;
pragma Inline (Variable_Declaration);
-- For Variable_Target T_Id, obtain the declaration of the variable
-----------------
-- Maintenance --
-----------------
procedure Finalize_Internal_Representation;
pragma Inline (Finalize_Internal_Representation);
-- Finalize all internal data structures
procedure Initialize_Internal_Representation;
pragma Inline (Initialize_Internal_Representation);
-- Initialize all internal data structures
end Internal_Representation;
use Internal_Representation;
-- The following package provides functionality for recording pieces of the
-- invocation graph in the ALI file of the main unit.
package Invocation_Graph is
---------
-- API --
---------
procedure Record_Invocation_Graph;
pragma Inline (Record_Invocation_Graph);
-- Process all declaration, instantiation, and library level scenarios,
-- along with invocation construct within the spec and body of the main
-- unit to determine whether any of these reach into an external unit.
-- If such a path exists, encode in the ALI file of the main unit.
-----------------
-- Maintenance --
-----------------
procedure Finalize_Invocation_Graph;
pragma Inline (Finalize_Invocation_Graph);
-- Finalize all internal data structures
procedure Initialize_Invocation_Graph;
pragma Inline (Initialize_Invocation_Graph);
-- Initialize all internal data structures
end Invocation_Graph;
use Invocation_Graph;
-- The following package stores scenarios
package Scenario_Storage is
---------
-- API --
---------
procedure Add_Declaration_Scenario (N : Node_Id);
pragma Inline (Add_Declaration_Scenario);
-- Save declaration level scenario N
procedure Add_Dynamic_ABE_Check_Scenario (N : Node_Id);
pragma Inline (Add_Dynamic_ABE_Check_Scenario);
-- Save scenario N for conditional ABE check installation purposes when
-- the dynamic model is in effect.
procedure Add_Library_Body_Scenario (N : Node_Id);
pragma Inline (Add_Library_Body_Scenario);
-- Save library-level body scenario N
procedure Add_Library_Spec_Scenario (N : Node_Id);
pragma Inline (Add_Library_Spec_Scenario);
-- Save library-level spec scenario N
procedure Add_SPARK_Scenario (N : Node_Id);
pragma Inline (Add_SPARK_Scenario);
-- Save SPARK scenario N
procedure Delete_Scenario (N : Node_Id);
pragma Inline (Delete_Scenario);
-- Delete arbitrary scenario N
function Iterate_Declaration_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_Declaration_Scenarios);
-- Obtain an iterator over all declaration level scenarios
function Iterate_Dynamic_ABE_Check_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_Dynamic_ABE_Check_Scenarios);
-- Obtain an iterator over all scenarios that require a conditional ABE
-- check when the dynamic model is in effect.
function Iterate_Library_Body_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_Library_Body_Scenarios);
-- Obtain an iterator over all library level body scenarios
function Iterate_Library_Spec_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_Library_Spec_Scenarios);
-- Obtain an iterator over all library level spec scenarios
function Iterate_SPARK_Scenarios return NE_Set.Iterator;
pragma Inline (Iterate_SPARK_Scenarios);
-- Obtain an iterator over all SPARK scenarios
procedure Replace_Scenario (Old_N : Node_Id; New_N : Node_Id);
pragma Inline (Replace_Scenario);
-- Replace scenario Old_N with scenario New_N
-----------------
-- Maintenance --
-----------------
procedure Finalize_Scenario_Storage;
pragma Inline (Finalize_Scenario_Storage);
-- Finalize all internal data structures
procedure Initialize_Scenario_Storage;
pragma Inline (Initialize_Scenario_Storage);
-- Initialize all internal data structures
end Scenario_Storage;
use Scenario_Storage;
-- The following package provides various semantic predicates
package Semantics is
---------
-- API --
---------
function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Accept_Alternative_Proc);
-- Determine whether arbitrary entity Id denotes an internally generated
-- procedure which encapsulates the statements of an accept alternative.
function Is_Activation_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Activation_Proc);
-- Determine whether arbitrary entity Id denotes a runtime procedure in
-- charge with activating tasks.
function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_Ada_Semantic_Target);
-- Determine whether arbitrary entity Id denodes a source or internally
-- generated subprogram which emulates Ada semantics.
function Is_Assertion_Pragma_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_Assertion_Pragma_Target);
-- Determine whether arbitrary entity Id denotes a procedure which
-- varifies the run-time semantics of an assertion pragma.
function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean;
pragma Inline (Is_Bodiless_Subprogram);
-- Determine whether subprogram Subp_Id will never have a body
function Is_Bridge_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_Bridge_Target);
-- Determine whether arbitrary entity Id denotes a bridge target
function Is_Controlled_Proc
(Subp_Id : Entity_Id;
Subp_Nam : Name_Id) return Boolean;
pragma Inline (Is_Controlled_Proc);
-- Determine whether subprogram Subp_Id denotes controlled type
-- primitives Adjust, Finalize, or Initialize as denoted by name
-- Subp_Nam.
function Is_Default_Initial_Condition_Proc
(Id : Entity_Id) return Boolean;
pragma Inline (Is_Default_Initial_Condition_Proc);
-- Determine whether arbitrary entity Id denotes internally generated
-- routine Default_Initial_Condition.
function Is_Finalizer_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Finalizer_Proc);
-- Determine whether arbitrary entity Id denotes internally generated
-- routine _Finalizer.
function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Initial_Condition_Proc);
-- Determine whether arbitrary entity Id denotes internally generated
-- routine Initial_Condition.
function Is_Initialized (Obj_Decl : Node_Id) return Boolean;
pragma Inline (Is_Initialized);
-- Determine whether object declaration Obj_Decl is initialized
function Is_Invariant_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Invariant_Proc);
-- Determine whether arbitrary entity Id denotes an invariant procedure
function Is_Non_Library_Level_Encapsulator (N : Node_Id) return Boolean;
pragma Inline (Is_Non_Library_Level_Encapsulator);
-- Determine whether arbitrary node N is a non-library encapsulator
function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Partial_Invariant_Proc);
-- Determine whether arbitrary entity Id denotes a partial invariant
-- procedure.
function Is_Postconditions_Proc (Id : Entity_Id) return Boolean;
pragma Inline (Is_Postconditions_Proc);
-- Determine whether arbitrary entity Id denotes internally generated
-- routine _Postconditions.
function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean;
pragma Inline (Is_Preelaborated_Unit);
-- Determine whether arbitrary entity Id denotes a unit which is subject
-- to one of the following pragmas:
--
-- * Preelaborable
-- * Pure
-- * Remote_Call_Interface
-- * Remote_Types
-- * Shared_Passive
function Is_Protected_Entry (Id : Entity_Id) return Boolean;
pragma Inline (Is_Protected_Entry);
-- Determine whether arbitrary entity Id denotes a protected entry
function Is_Protected_Subp (Id : Entity_Id) return Boolean;
pragma Inline (Is_Protected_Subp);
-- Determine whether entity Id denotes a protected subprogram
function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean;
pragma Inline (Is_Protected_Body_Subp);
-- Determine whether entity Id denotes the protected or unprotected
-- version of a protected subprogram.
function Is_Scenario (N : Node_Id) return Boolean;
pragma Inline (Is_Scenario);
-- Determine whether attribute node N denotes a scenario. The scenario
-- may not necessarily be eligible for ABE processing.
function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_SPARK_Semantic_Target);
-- Determine whether arbitrary entity Id nodes a source or internally
-- generated subprogram which emulates SPARK semantics.
function Is_Subprogram_Inst (Id : Entity_Id) return Boolean;
pragma Inline (Is_Subprogram_Inst);
-- Determine whether arbitrary entity Id denotes a subprogram instance
function Is_Suitable_Access_Taken (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Access_Taken);
-- Determine whether arbitrary node N denotes a suitable attribute for
-- ABE processing.
function Is_Suitable_Call (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Call);
-- Determine whether arbitrary node N denotes a suitable call for ABE
-- processing.
function Is_Suitable_Instantiation (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Instantiation);
-- Determine whether arbitrary node N is a suitable instantiation for
-- ABE processing.
function Is_Suitable_SPARK_Derived_Type (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_SPARK_Derived_Type);
-- Determine whether arbitrary node N denotes a suitable derived type
-- declaration for ABE processing using the SPARK rules.
function Is_Suitable_SPARK_Instantiation (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_SPARK_Instantiation);
-- Determine whether arbitrary node N denotes a suitable instantiation
-- for ABE processing using the SPARK rules.
function Is_Suitable_SPARK_Refined_State_Pragma
(N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_SPARK_Refined_State_Pragma);
-- Determine whether arbitrary node N denotes a suitable Refined_State
-- pragma for ABE processing using the SPARK rules.
function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Variable_Assignment);
-- Determine whether arbitrary node N denotes a suitable assignment for
-- ABE processing.
function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Variable_Reference);
-- Determine whether arbitrary node N is a suitable variable reference
-- for ABE processing.
function Is_Task_Entry (Id : Entity_Id) return Boolean;
pragma Inline (Is_Task_Entry);
-- Determine whether arbitrary entity Id denotes a task entry
function Is_Up_Level_Target
(Targ_Decl : Node_Id;
In_State : Processing_In_State) return Boolean;
pragma Inline (Is_Up_Level_Target);
-- Determine whether the current root resides at the declaration level.
-- If this is the case, determine whether a target with by declaration
-- Target_Decl is within a context which encloses the current root or is
-- in a different unit. In_State is the current state of the Processing
-- phase.
end Semantics;
use Semantics;
-- The following package provides the main entry point for SPARK-related
-- checks and diagnostics.
package SPARK_Processor is
---------
-- API --
---------
procedure Check_SPARK_Model_In_Effect;
pragma Inline (Check_SPARK_Model_In_Effect);
-- Determine whether a suitable elaboration model is currently in effect
-- for verifying SPARK rules. Emit a warning if this is not the case.
procedure Check_SPARK_Scenarios;
pragma Inline (Check_SPARK_Scenarios);
-- Examine SPARK scenarios which are not necessarily executable during
-- elaboration, but still requires elaboration-related checks.
end SPARK_Processor;
use SPARK_Processor;
-----------------------
-- Local subprograms --
-----------------------
function Assignment_Target (Asmt : Node_Id) return Node_Id;
pragma Inline (Assignment_Target);
-- Obtain the target of assignment statement Asmt
function Call_Name (Call : Node_Id) return Node_Id;
pragma Inline (Call_Name);
-- Obtain the name of an entry, operator, or subprogram call Call
function Canonical_Subprogram (Subp_Id : Entity_Id) return Entity_Id;
pragma Inline (Canonical_Subprogram);
-- Obtain the uniform canonical entity of subprogram Subp_Id
function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id;
pragma Inline (Compilation_Unit);
-- Return the N_Compilation_Unit node of unit Unit_Id
function Elaboration_Phase_Active return Boolean;
pragma Inline (Elaboration_Phase_Active);
-- Determine whether the elaboration phase of the compilation has started
procedure Error_Preelaborated_Call (N : Node_Id);
-- Give an error or warning for a non-static/non-preelaborable call in a
-- preelaborated unit.
procedure Finalize_All_Data_Structures;
pragma Inline (Finalize_All_Data_Structures);
-- Destroy all internal data structures
function Find_Enclosing_Instance (N : Node_Id) return Node_Id;
pragma Inline (Find_Enclosing_Instance);
-- Find the declaration or body of the nearest expanded instance which
-- encloses arbitrary node N. Return Empty if no such instance exists.
function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id;
pragma Inline (Find_Top_Unit);
-- Return the top unit which contains arbitrary node or entity N. The unit
-- is obtained by logically unwinding instantiations and subunits when N
-- resides within one.
function Find_Unit_Entity (N : Node_Id) return Entity_Id;
pragma Inline (Find_Unit_Entity);
-- Return the entity of unit N
function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id;
pragma Inline (First_Formal_Type);
-- Return the type of subprogram Subp_Id's first formal parameter. If the
-- subprogram lacks formal parameters, return Empty.
function Has_Body (Pack_Decl : Node_Id) return Boolean;
pragma Inline (Has_Body);
-- Determine whether package declaration Pack_Decl has a corresponding body
-- or would eventually have one.
function In_External_Instance
(N : Node_Id;
Target_Decl : Node_Id) return Boolean;
pragma Inline (In_External_Instance);
-- Determine whether a target desctibed by its declaration Target_Decl
-- resides in a package instance which is external to scenario N.
function In_Main_Context (N : Node_Id) return Boolean;
pragma Inline (In_Main_Context);
-- Determine whether arbitrary node N appears within the main compilation
-- unit.
function In_Same_Context
(N1 : Node_Id;
N2 : Node_Id;
Nested_OK : Boolean := False) return Boolean;
pragma Inline (In_Same_Context);
-- Determine whether two arbitrary nodes N1 and N2 appear within the same
-- context ignoring enclosing library levels. Nested_OK should be set when
-- the context of N1 can enclose that of N2.
procedure Initialize_All_Data_Structures;
pragma Inline (Initialize_All_Data_Structures);
-- Create all internal data structures
function Instantiated_Generic (Inst : Node_Id) return Entity_Id;
pragma Inline (Instantiated_Generic);
-- Obtain the generic instantiated by instance Inst
function Is_Safe_Activation
(Call : Node_Id;
Task_Rep : Target_Rep_Id) return Boolean;
pragma Inline (Is_Safe_Activation);
-- Determine whether activation call Call which activates an object of a
-- task type described by representation Task_Rep is always ABE-safe.
function Is_Safe_Call
(Call : Node_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id) return Boolean;
pragma Inline (Is_Safe_Call);
-- Determine whether call Call which invokes entry, operator, or subprogram
-- Subp_Id is always ABE-safe. Subp_Rep is the representation of the entry,
-- operator, or subprogram.
function Is_Safe_Instantiation
(Inst : Node_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id) return Boolean;
pragma Inline (Is_Safe_Instantiation);
-- Determine whether instantiation Inst which instantiates generic Gen_Id
-- is always ABE-safe. Gen_Rep is the representation of the generic.
function Is_Same_Unit
(Unit_1 : Entity_Id;
Unit_2 : Entity_Id) return Boolean;
pragma Inline (Is_Same_Unit);
-- Determine whether entities Unit_1 and Unit_2 denote the same unit
function Main_Unit_Entity return Entity_Id;
pragma Inline (Main_Unit_Entity);
-- Return the entity of the main unit
function Non_Private_View (Typ : Entity_Id) return Entity_Id;
pragma Inline (Non_Private_View);
-- Return the full view of private type Typ if available, otherwise return
-- type Typ.
function Scenario (N : Node_Id) return Node_Id;
pragma Inline (Scenario);
-- Return the appropriate scenario node for scenario N
procedure Set_Elaboration_Phase (Status : Elaboration_Phase_Status);
pragma Inline (Set_Elaboration_Phase);
-- Change the status of the elaboration phase of the compiler to Status
procedure Spec_And_Body_From_Entity
(Id : Node_Id;
Spec_Decl : out Node_Id;
Body_Decl : out Node_Id);
pragma Inline (Spec_And_Body_From_Entity);
-- Given arbitrary entity Id representing a construct with a spec and body,
-- retrieve declaration of the spec in Spec_Decl and the declaration of the
-- body in Body_Decl.
procedure Spec_And_Body_From_Node
(N : Node_Id;
Spec_Decl : out Node_Id;
Body_Decl : out Node_Id);
pragma Inline (Spec_And_Body_From_Node);
-- Given arbitrary node N representing a construct with a spec and body,
-- retrieve declaration of the spec in Spec_Decl and the declaration of
-- the body in Body_Decl.
function Static_Elaboration_Checks return Boolean;
pragma Inline (Static_Elaboration_Checks);
-- Determine whether the static model is in effect
function Unit_Entity (Unit_Id : Entity_Id) return Entity_Id;
pragma Inline (Unit_Entity);
-- Return the entity of the initial declaration for unit Unit_Id
procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id);
pragma Inline (Update_Elaboration_Scenario);
-- Update all relevant internal data structures when scenario Old_N is
-- transformed into scenario New_N by Atree.Rewrite.
----------------------
-- Active_Scenarios --
----------------------
package body Active_Scenarios is
-----------------------
-- Local subprograms --
-----------------------
procedure Output_Access_Taken
(Attr : Node_Id;
Attr_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Access_Taken);
-- Emit a specific diagnostic message for 'Access attribute reference
-- Attr with representation Attr_Rep. The message is associated with
-- node Error_Nod.
procedure Output_Active_Scenario
(N : Node_Id;
Error_Nod : Node_Id;
In_State : Processing_In_State);
pragma Inline (Output_Active_Scenario);
-- Top level dispatcher for outputting a scenario. Emit a specific
-- diagnostic message for scenario N. The message is associated with
-- node Error_Nod. In_State is the current state of the Processing
-- phase.
procedure Output_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Call);
-- Emit a diagnostic message for call Call with representation Call_Rep.
-- The message is associated with node Error_Nod.
procedure Output_Header (Error_Nod : Node_Id);
pragma Inline (Output_Header);
-- Emit a specific diagnostic message for the unit of the root scenario.
-- The message is associated with node Error_Nod.
procedure Output_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Instantiation);
-- Emit a specific diagnostic message for instantiation Inst with
-- representation Inst_Rep. The message is associated with node
-- Error_Nod.
procedure Output_Refined_State_Pragma
(Prag : Node_Id;
Prag_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Refined_State_Pragma);
-- Emit a specific diagnostic message for Refined_State pragma Prag
-- with representation Prag_Rep. The message is associated with node
-- Error_Nod.
procedure Output_Task_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Task_Activation);
-- Emit a specific diagnostic message for activation call Call
-- with representation Call_Rep. The message is associated with
-- node Error_Nod.
procedure Output_Variable_Assignment
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Variable_Assignment);
-- Emit a specific diagnostic message for assignment statement Asmt
-- with representation Asmt_Rep. The message is associated with node
-- Error_Nod.
procedure Output_Variable_Reference
(Ref : Node_Id;
Ref_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id);
pragma Inline (Output_Variable_Reference);
-- Emit a specific diagnostic message for read reference Ref with
-- representation Ref_Rep. The message is associated with node
-- Error_Nod.
-------------------
-- Output_Access --
-------------------
procedure Output_Access_Taken
(Attr : Node_Id;
Attr_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
Subp_Id : constant Entity_Id := Target (Attr_Rep);
begin
Error_Msg_Name_1 := Attribute_Name (Attr);
Error_Msg_Sloc := Sloc (Attr);
Error_Msg_NE ("\\ % of & taken #", Error_Nod, Subp_Id);
end Output_Access_Taken;
----------------------------
-- Output_Active_Scenario --
----------------------------
procedure Output_Active_Scenario
(N : Node_Id;
Error_Nod : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
Scen_Rep : Scenario_Rep_Id;
begin
-- 'Access
if Is_Suitable_Access_Taken (Scen) then
Output_Access_Taken
(Attr => Scen,
Attr_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
-- Call or task activation
elsif Is_Suitable_Call (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
if Kind (Scen_Rep) = Call_Scenario then
Output_Call
(Call => Scen,
Call_Rep => Scen_Rep,
Error_Nod => Error_Nod);
else
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario);
Output_Task_Activation
(Call => Scen,
Call_Rep => Scen_Rep,
Error_Nod => Error_Nod);
end if;
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Output_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
-- Pragma Refined_State
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then
Output_Refined_State_Pragma
(Prag => Scen,
Prag_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
-- Variable assignment
elsif Is_Suitable_Variable_Assignment (Scen) then
Output_Variable_Assignment
(Asmt => Scen,
Asmt_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
-- Variable reference
elsif Is_Suitable_Variable_Reference (Scen) then
Output_Variable_Reference
(Ref => Scen,
Ref_Rep => Scenario_Representation_Of (Scen, In_State),
Error_Nod => Error_Nod);
end if;
end Output_Active_Scenario;
-----------------------------
-- Output_Active_Scenarios --
-----------------------------
procedure Output_Active_Scenarios
(Error_Nod : Node_Id;
In_State : Processing_In_State)
is
package Scenarios renames Active_Scenario_Stack;
Header_Posted : Boolean := False;
begin
-- Output the contents of the active scenario stack starting from the
-- bottom, or the least recent scenario.
for Index in Scenarios.First .. Scenarios.Last loop
if not Header_Posted then
Output_Header (Error_Nod);
Header_Posted := True;
end if;
Output_Active_Scenario
(N => Scenarios.Table (Index),
Error_Nod => Error_Nod,
In_State => In_State);
end loop;
end Output_Active_Scenarios;
-----------------
-- Output_Call --
-----------------
procedure Output_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
procedure Output_Accept_Alternative (Alt_Id : Entity_Id);
pragma Inline (Output_Accept_Alternative);
-- Emit a specific diagnostic message concerning accept alternative
-- with entity Alt_Id.
procedure Output_Call (Subp_Id : Entity_Id; Kind : String);
pragma Inline (Output_Call);
-- Emit a specific diagnostic message concerning a call of kind Kind
-- which invokes subprogram Subp_Id.
procedure Output_Type_Actions (Subp_Id : Entity_Id; Action : String);
pragma Inline (Output_Type_Actions);
-- Emit a specific diagnostic message concerning action Action of a
-- type performed by subprogram Subp_Id.
procedure Output_Verification_Call
(Pred : String;
Id : Entity_Id;
Id_Kind : String);
pragma Inline (Output_Verification_Call);
-- Emit a specific diagnostic message concerning the verification of
-- predicate Pred applied to related entity Id with kind Id_Kind.
-------------------------------
-- Output_Accept_Alternative --
-------------------------------
procedure Output_Accept_Alternative (Alt_Id : Entity_Id) is
Entry_Id : constant Entity_Id := Receiving_Entry (Alt_Id);
begin
pragma Assert (Present (Entry_Id));
Error_Msg_NE ("\\ entry & selected #", Error_Nod, Entry_Id);
end Output_Accept_Alternative;
-----------------
-- Output_Call --
-----------------
procedure Output_Call (Subp_Id : Entity_Id; Kind : String) is
begin
Error_Msg_NE ("\\ " & Kind & " & called #", Error_Nod, Subp_Id);
end Output_Call;
-------------------------
-- Output_Type_Actions --
-------------------------
procedure Output_Type_Actions
(Subp_Id : Entity_Id;
Action : String)
is
Typ : constant Entity_Id := First_Formal_Type (Subp_Id);
begin
pragma Assert (Present (Typ));
Error_Msg_NE
("\\ " & Action & " actions for type & #", Error_Nod, Typ);
end Output_Type_Actions;
------------------------------
-- Output_Verification_Call --
------------------------------
procedure Output_Verification_Call
(Pred : String;
Id : Entity_Id;
Id_Kind : String)
is
begin
pragma Assert (Present (Id));
Error_Msg_NE
("\\ " & Pred & " of " & Id_Kind & " & verified #",
Error_Nod, Id);
end Output_Verification_Call;
-- Local variables
Subp_Id : constant Entity_Id := Target (Call_Rep);
-- Start of processing for Output_Call
begin
Error_Msg_Sloc := Sloc (Call);
-- Accept alternative
if Is_Accept_Alternative_Proc (Subp_Id) then
Output_Accept_Alternative (Subp_Id);
-- Adjustment
elsif Is_TSS (Subp_Id, TSS_Deep_Adjust) then
Output_Type_Actions (Subp_Id, "adjustment");
-- Default_Initial_Condition
elsif Is_Default_Initial_Condition_Proc (Subp_Id) then
Output_Verification_Call
(Pred => "Default_Initial_Condition",
Id => First_Formal_Type (Subp_Id),
Id_Kind => "type");
-- Entries
elsif Is_Protected_Entry (Subp_Id) then
Output_Call (Subp_Id, "entry");
-- Task entry calls are never processed because the entry being
-- invoked does not have a corresponding "body", it has a select. A
-- task entry call appears in the stack of active scenarios for the
-- sole purpose of checking No_Entry_Calls_In_Elaboration_Code and
-- nothing more.
elsif Is_Task_Entry (Subp_Id) then
null;
-- Finalization
elsif Is_TSS (Subp_Id, TSS_Deep_Finalize) then
Output_Type_Actions (Subp_Id, "finalization");
-- Calls to _Finalizer procedures must not appear in the output
-- because this creates confusing noise.
elsif Is_Finalizer_Proc (Subp_Id) then
null;
-- Initial_Condition
elsif Is_Initial_Condition_Proc (Subp_Id) then
Output_Verification_Call
(Pred => "Initial_Condition",
Id => Find_Enclosing_Scope (Call),
Id_Kind => "package");
-- Initialization
elsif Is_Init_Proc (Subp_Id)
or else Is_TSS (Subp_Id, TSS_Deep_Initialize)
then
Output_Type_Actions (Subp_Id, "initialization");
-- Invariant
elsif Is_Invariant_Proc (Subp_Id) then
Output_Verification_Call
(Pred => "invariants",
Id => First_Formal_Type (Subp_Id),
Id_Kind => "type");
-- Partial invariant calls must not appear in the output because this
-- creates confusing noise. Note that a partial invariant is always
-- invoked by the "full" invariant which is already placed on the
-- stack.
elsif Is_Partial_Invariant_Proc (Subp_Id) then
null;
-- _Postconditions
elsif Is_Postconditions_Proc (Subp_Id) then
Output_Verification_Call
(Pred => "postconditions",
Id => Find_Enclosing_Scope (Call),
Id_Kind => "subprogram");
-- Subprograms must come last because some of the previous cases fall
-- under this category.
elsif Ekind (Subp_Id) = E_Function then
Output_Call (Subp_Id, "function");
elsif Ekind (Subp_Id) = E_Procedure then
Output_Call (Subp_Id, "procedure");
else
pragma Assert (False);
return;
end if;
end Output_Call;
-------------------
-- Output_Header --
-------------------
procedure Output_Header (Error_Nod : Node_Id) is
Unit_Id : constant Entity_Id := Find_Top_Unit (Root_Scenario);
begin
if Ekind (Unit_Id) = E_Package then
Error_Msg_NE ("\\ spec of unit & elaborated", Error_Nod, Unit_Id);
elsif Ekind (Unit_Id) = E_Package_Body then
Error_Msg_NE ("\\ body of unit & elaborated", Error_Nod, Unit_Id);
else
Error_Msg_NE ("\\ in body of unit &", Error_Nod, Unit_Id);
end if;
end Output_Header;
--------------------------
-- Output_Instantiation --
--------------------------
procedure Output_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String);
pragma Inline (Output_Instantiation);
-- Emit a specific diagnostic message concerning an instantiation of
-- generic unit Gen_Id. Kind denotes the kind of the instantiation.
--------------------------
-- Output_Instantiation --
--------------------------
procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String) is
begin
Error_Msg_NE
("\\ " & Kind & " & instantiated as & #", Error_Nod, Gen_Id);
end Output_Instantiation;
-- Local variables
Gen_Id : constant Entity_Id := Target (Inst_Rep);
-- Start of processing for Output_Instantiation
begin
Error_Msg_Node_2 := Defining_Entity (Inst);
Error_Msg_Sloc := Sloc (Inst);
if Nkind (Inst) = N_Function_Instantiation then
Output_Instantiation (Gen_Id, "function");
elsif Nkind (Inst) = N_Package_Instantiation then
Output_Instantiation (Gen_Id, "package");
elsif Nkind (Inst) = N_Procedure_Instantiation then
Output_Instantiation (Gen_Id, "procedure");
else
pragma Assert (False);
return;
end if;
end Output_Instantiation;
---------------------------------
-- Output_Refined_State_Pragma --
---------------------------------
procedure Output_Refined_State_Pragma
(Prag : Node_Id;
Prag_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
pragma Unreferenced (Prag_Rep);
begin
Error_Msg_Sloc := Sloc (Prag);
Error_Msg_N ("\\ refinement constituents read #", Error_Nod);
end Output_Refined_State_Pragma;
----------------------------
-- Output_Task_Activation --
----------------------------
procedure Output_Task_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
pragma Unreferenced (Call_Rep);
function Find_Activator return Entity_Id;
-- Find the nearest enclosing construct which houses call Call
--------------------
-- Find_Activator --
--------------------
function Find_Activator return Entity_Id is
Par : Node_Id;
begin
-- Climb the parent chain looking for a package [body] or a
-- construct with a statement sequence.
Par := Parent (Call);
while Present (Par) loop
if Nkind (Par) in N_Package_Body | N_Package_Declaration then
return Defining_Entity (Par);
elsif Nkind (Par) = N_Handled_Sequence_Of_Statements then
return Defining_Entity (Parent (Par));
end if;
Par := Parent (Par);
end loop;
return Empty;
end Find_Activator;
-- Local variables
Activator : constant Entity_Id := Find_Activator;
-- Start of processing for Output_Task_Activation
begin
pragma Assert (Present (Activator));
Error_Msg_NE ("\\ local tasks of & activated", Error_Nod, Activator);
end Output_Task_Activation;
--------------------------------
-- Output_Variable_Assignment --
--------------------------------
procedure Output_Variable_Assignment
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
Var_Id : constant Entity_Id := Target (Asmt_Rep);
begin
Error_Msg_Sloc := Sloc (Asmt);
Error_Msg_NE ("\\ variable & assigned #", Error_Nod, Var_Id);
end Output_Variable_Assignment;
-------------------------------
-- Output_Variable_Reference --
-------------------------------
procedure Output_Variable_Reference
(Ref : Node_Id;
Ref_Rep : Scenario_Rep_Id;
Error_Nod : Node_Id)
is
Var_Id : constant Entity_Id := Target (Ref_Rep);
begin
Error_Msg_Sloc := Sloc (Ref);
Error_Msg_NE ("\\ variable & read #", Error_Nod, Var_Id);
end Output_Variable_Reference;
-------------------------
-- Pop_Active_Scenario --
-------------------------
procedure Pop_Active_Scenario (N : Node_Id) is
package Scenarios renames Active_Scenario_Stack;
Top : Node_Id renames Scenarios.Table (Scenarios.Last);
begin
pragma Assert (Top = N);
Scenarios.Decrement_Last;
end Pop_Active_Scenario;
--------------------------
-- Push_Active_Scenario --
--------------------------
procedure Push_Active_Scenario (N : Node_Id) is
begin
Active_Scenario_Stack.Append (N);
end Push_Active_Scenario;
-------------------
-- Root_Scenario --
-------------------
function Root_Scenario return Node_Id is
package Scenarios renames Active_Scenario_Stack;
begin
-- Ensure that the scenario stack has at least one active scenario in
-- it. The one at the bottom (index First) is the root scenario.
pragma Assert (Scenarios.Last >= Scenarios.First);
return Scenarios.Table (Scenarios.First);
end Root_Scenario;
end Active_Scenarios;
--------------------------
-- Activation_Processor --
--------------------------
package body Activation_Processor is
------------------------
-- Process_Activation --
------------------------
procedure Process_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Processor : Activation_Processor_Ptr;
In_State : Processing_In_State)
is
procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id);
pragma Inline (Process_Task_Object);
-- Invoke Processor for task object Obj_Id of type Typ
procedure Process_Task_Objects
(Task_Objs : NE_List.Doubly_Linked_List);
pragma Inline (Process_Task_Objects);
-- Invoke Processor for all task objects found in list Task_Objs
procedure Traverse_List
(List : List_Id;
Task_Objs : NE_List.Doubly_Linked_List);
pragma Inline (Traverse_List);
-- Traverse declarative or statement list List while searching for
-- objects of a task type, or containing task components. If such an
-- object is found, first save it in list Task_Objs and then invoke
-- Processor on it.
-------------------------
-- Process_Task_Object --
-------------------------
procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id) is
Root_Typ : constant Entity_Id :=
Non_Private_View (Root_Type (Typ));
Comp_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Root_Rep : Target_Rep_Id;
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
if Is_Task_Type (Typ) then
Obj_Rep := Target_Representation_Of (Obj_Id, New_In_State);
Root_Rep := Target_Representation_Of (Root_Typ, New_In_State);
-- Warnings are suppressed when a prior scenario is already in
-- that mode, or when the object, activation call, or task type
-- have warnings suppressed. Update the state of the Processing
-- phase to reflect this.
New_In_State.Suppress_Warnings :=
New_In_State.Suppress_Warnings
or else not Elaboration_Warnings_OK (Call_Rep)
or else not Elaboration_Warnings_OK (Obj_Rep)
or else not Elaboration_Warnings_OK (Root_Rep);
-- Update the state of the Processing phase to indicate that
-- any further traversal is now within a task body.
New_In_State.Within_Task_Body := True;
-- Associate the current task type with the activation call
Set_Activated_Task_Type (Call_Rep, Root_Typ);
-- Process the activation of the current task object by calling
-- the supplied processor.
Processor.all
(Call => Call,
Call_Rep => Call_Rep,
Obj_Id => Obj_Id,
Obj_Rep => Obj_Rep,
Task_Typ => Root_Typ,
Task_Rep => Root_Rep,
In_State => New_In_State);
-- Reset the association between the current task and the
-- activtion call.
Set_Activated_Task_Type (Call_Rep, Empty);
-- Examine the component type when the object is an array
elsif Is_Array_Type (Typ) and then Has_Task (Root_Typ) then
Process_Task_Object
(Obj_Id => Obj_Id,
Typ => Component_Type (Typ));
-- Examine individual component types when the object is a record
elsif Is_Record_Type (Typ) and then Has_Task (Root_Typ) then
Comp_Id := First_Component (Typ);
while Present (Comp_Id) loop
Process_Task_Object
(Obj_Id => Obj_Id,
Typ => Etype (Comp_Id));
Next_Component (Comp_Id);
end loop;
end if;
end Process_Task_Object;
--------------------------
-- Process_Task_Objects --
--------------------------
procedure Process_Task_Objects
(Task_Objs : NE_List.Doubly_Linked_List)
is
Iter : NE_List.Iterator;
Obj_Id : Entity_Id;
begin
Iter := NE_List.Iterate (Task_Objs);
while NE_List.Has_Next (Iter) loop
NE_List.Next (Iter, Obj_Id);
Process_Task_Object
(Obj_Id => Obj_Id,
Typ => Etype (Obj_Id));
end loop;
end Process_Task_Objects;
-------------------
-- Traverse_List --
-------------------
procedure Traverse_List
(List : List_Id;
Task_Objs : NE_List.Doubly_Linked_List)
is
Item : Node_Id;
Item_Id : Entity_Id;
Item_Typ : Entity_Id;
begin
-- Examine the contents of the list looking for an object
-- declaration of a task type or one that contains a task
-- within.
Item := First (List);
while Present (Item) loop
if Nkind (Item) = N_Object_Declaration then
Item_Id := Defining_Entity (Item);
Item_Typ := Etype (Item_Id);
if Has_Task (Item_Typ) then
-- The object is either of a task type, or contains a
-- task component. Save it in the list of task objects
-- associated with the activation call.
NE_List.Append (Task_Objs, Item_Id);
Process_Task_Object
(Obj_Id => Item_Id,
Typ => Item_Typ);
end if;
end if;
Next (Item);
end loop;
end Traverse_List;
-- Local variables
Context : Node_Id;
Spec : Node_Id;
Task_Objs : NE_List.Doubly_Linked_List;
-- Start of processing for Process_Activation
begin
-- Nothing to do when the activation is a guaranteed ABE
if Is_Known_Guaranteed_ABE (Call) then
return;
end if;
Task_Objs := Activated_Task_Objects (Call_Rep);
-- The activation call has been processed at least once, and all
-- task objects have already been collected. Directly process the
-- objects without having to reexamine the context of the call.
if NE_List.Present (Task_Objs) then
Process_Task_Objects (Task_Objs);
-- Otherwise the activation call is being processed for the first
-- time. Collect all task objects in case the call is reprocessed
-- multiple times.
else
Task_Objs := NE_List.Create;
Set_Activated_Task_Objects (Call_Rep, Task_Objs);
-- Find the context of the activation call where all task objects
-- being activated are declared. This is usually the parent of the
-- call.
Context := Parent (Call);
-- Handle the case where the activation call appears within the
-- handled statements of a block or a body.
if Nkind (Context) = N_Handled_Sequence_Of_Statements then
Context := Parent (Context);
end if;
-- Process all task objects in both the spec and body when the
-- activation call appears in a package body.
if Nkind (Context) = N_Package_Body then
Spec :=
Specification
(Unit_Declaration_Node (Corresponding_Spec (Context)));
Traverse_List
(List => Visible_Declarations (Spec),
Task_Objs => Task_Objs);
Traverse_List
(List => Private_Declarations (Spec),
Task_Objs => Task_Objs);
Traverse_List
(List => Declarations (Context),
Task_Objs => Task_Objs);
-- Process all task objects in the spec when the activation call
-- appears in a package spec.
elsif Nkind (Context) = N_Package_Specification then
Traverse_List
(List => Visible_Declarations (Context),
Task_Objs => Task_Objs);
Traverse_List
(List => Private_Declarations (Context),
Task_Objs => Task_Objs);
-- Otherwise the context must be a block or a body. Process all
-- task objects found in the declarations.
else
pragma Assert
(Nkind (Context) in
N_Block_Statement | N_Entry_Body | N_Protected_Body |
N_Subprogram_Body | N_Task_Body);
Traverse_List
(List => Declarations (Context),
Task_Objs => Task_Objs);
end if;
end if;
end Process_Activation;
end Activation_Processor;
-----------------------
-- Assignment_Target --
-----------------------
function Assignment_Target (Asmt : Node_Id) return Node_Id is
Nam : Node_Id;
begin
Nam := Name (Asmt);
-- When the name denotes an array or record component, find the whole
-- object.
while Nkind (Nam) in
N_Explicit_Dereference | N_Indexed_Component |
N_Selected_Component | N_Slice
loop
Nam := Prefix (Nam);
end loop;
return Nam;
end Assignment_Target;
--------------------
-- Body_Processor --
--------------------
package body Body_Processor is
---------------------
-- Data structures --
---------------------
-- The following map relates scenario lists to subprogram bodies
Nested_Scenarios_Map : NE_List_Map.Dynamic_Hash_Table := NE_List_Map.Nil;
-- The following set contains all subprogram bodies that have been
-- processed by routine Traverse_Body.
Traversed_Bodies_Set : NE_Set.Membership_Set := NE_Set.Nil;
-----------------------
-- Local subprograms --
-----------------------
function Is_Traversed_Body (N : Node_Id) return Boolean;
pragma Inline (Is_Traversed_Body);
-- Determine whether subprogram body N has already been traversed
function Nested_Scenarios
(N : Node_Id) return NE_List.Doubly_Linked_List;
pragma Inline (Nested_Scenarios);
-- Obtain the list of scenarios associated with subprogram body N
procedure Set_Is_Traversed_Body
(N : Node_Id;
Val : Boolean := True);
pragma Inline (Set_Is_Traversed_Body);
-- Mark subprogram body N as traversed depending on value Val
procedure Set_Nested_Scenarios
(N : Node_Id;
Scenarios : NE_List.Doubly_Linked_List);
pragma Inline (Set_Nested_Scenarios);
-- Associate scenario list Scenarios with subprogram body N
-----------------------------
-- Finalize_Body_Processor --
-----------------------------
procedure Finalize_Body_Processor is
begin
NE_List_Map.Destroy (Nested_Scenarios_Map);
NE_Set.Destroy (Traversed_Bodies_Set);
end Finalize_Body_Processor;
-------------------------------
-- Initialize_Body_Processor --
-------------------------------
procedure Initialize_Body_Processor is
begin
Nested_Scenarios_Map := NE_List_Map.Create (250);
Traversed_Bodies_Set := NE_Set.Create (250);
end Initialize_Body_Processor;
-----------------------
-- Is_Traversed_Body --
-----------------------
function Is_Traversed_Body (N : Node_Id) return Boolean is
pragma Assert (Present (N));
begin
return NE_Set.Contains (Traversed_Bodies_Set, N);
end Is_Traversed_Body;
----------------------
-- Nested_Scenarios --
----------------------
function Nested_Scenarios
(N : Node_Id) return NE_List.Doubly_Linked_List
is
pragma Assert (Present (N));
pragma Assert (Nkind (N) = N_Subprogram_Body);
begin
return NE_List_Map.Get (Nested_Scenarios_Map, N);
end Nested_Scenarios;
----------------------------
-- Reset_Traversed_Bodies --
----------------------------
procedure Reset_Traversed_Bodies is
begin
NE_Set.Reset (Traversed_Bodies_Set);
end Reset_Traversed_Bodies;
---------------------------
-- Set_Is_Traversed_Body --
---------------------------
procedure Set_Is_Traversed_Body
(N : Node_Id;
Val : Boolean := True)
is
pragma Assert (Present (N));
begin
if Val then
NE_Set.Insert (Traversed_Bodies_Set, N);
else
NE_Set.Delete (Traversed_Bodies_Set, N);
end if;
end Set_Is_Traversed_Body;
--------------------------
-- Set_Nested_Scenarios --
--------------------------
procedure Set_Nested_Scenarios
(N : Node_Id;
Scenarios : NE_List.Doubly_Linked_List)
is
pragma Assert (Present (N));
begin
NE_List_Map.Put (Nested_Scenarios_Map, N, Scenarios);
end Set_Nested_Scenarios;
-------------------
-- Traverse_Body --
-------------------
procedure Traverse_Body
(N : Node_Id;
Requires_Processing : Scenario_Predicate_Ptr;
Processor : Scenario_Processor_Ptr;
In_State : Processing_In_State)
is
Scenarios : NE_List.Doubly_Linked_List := NE_List.Nil;
-- The list of scenarios that appear within the declarations and
-- statement of subprogram body N. The variable is intentionally
-- global because Is_Potential_Scenario needs to populate it.
function In_Task_Body (Nod : Node_Id) return Boolean;
pragma Inline (In_Task_Body);
-- Determine whether arbitrary node Nod appears within a task body
function Is_Synchronous_Suspension_Call
(Nod : Node_Id) return Boolean;
pragma Inline (Is_Synchronous_Suspension_Call);
-- Determine whether arbitrary node Nod denotes a call to one of
-- these routines:
--
-- Ada.Synchronous_Barriers.Wait_For_Release
-- Ada.Synchronous_Task_Control.Suspend_Until_True
procedure Traverse_Collected_Scenarios;
pragma Inline (Traverse_Collected_Scenarios);
-- Traverse the already collected scenarios in list Scenarios by
-- invoking Processor on each individual one.
procedure Traverse_List (List : List_Id);
pragma Inline (Traverse_List);
-- Invoke Traverse_Potential_Scenarios on each node in list List
function Traverse_Potential_Scenario
(Scen : Node_Id) return Traverse_Result;
pragma Inline (Traverse_Potential_Scenario);
-- Determine whether arbitrary node Scen is a suitable scenario using
-- predicate Is_Scenario and traverse it by invoking Processor on it.
procedure Traverse_Potential_Scenarios is
new Traverse_Proc (Traverse_Potential_Scenario);
------------------
-- In_Task_Body --
------------------
function In_Task_Body (Nod : Node_Id) return Boolean is
Par : Node_Id;
begin
-- Climb the parent chain looking for a task body [procedure]
Par := Nod;
while Present (Par) loop
if Nkind (Par) = N_Task_Body then
return True;
elsif Nkind (Par) = N_Subprogram_Body
and then Is_Task_Body_Procedure (Par)
then
return True;
-- Prevent the search from going too far. Note that this test
-- shares nodes with the two cases above, and must come last.
elsif Is_Body_Or_Package_Declaration (Par) then
return False;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Task_Body;
------------------------------------
-- Is_Synchronous_Suspension_Call --
------------------------------------
function Is_Synchronous_Suspension_Call
(Nod : Node_Id) return Boolean
is
Subp_Id : Entity_Id;
begin
-- To qualify, the call must invoke one of the runtime routines
-- which perform synchronous suspension.
if Is_Suitable_Call (Nod) then
Subp_Id := Target (Nod);
return
Is_RTE (Subp_Id, RE_Suspend_Until_True)
or else
Is_RTE (Subp_Id, RE_Wait_For_Release);
end if;
return False;
end Is_Synchronous_Suspension_Call;
----------------------------------
-- Traverse_Collected_Scenarios --
----------------------------------
procedure Traverse_Collected_Scenarios is
Iter : NE_List.Iterator;
Scen : Node_Id;
begin
Iter := NE_List.Iterate (Scenarios);
while NE_List.Has_Next (Iter) loop
NE_List.Next (Iter, Scen);
-- The current scenario satisfies the input predicate, process
-- it.
if Requires_Processing.all (Scen) then
Processor.all (Scen, In_State);
end if;
end loop;
end Traverse_Collected_Scenarios;
-------------------
-- Traverse_List --
-------------------
procedure Traverse_List (List : List_Id) is
Scen : Node_Id;
begin
Scen := First (List);
while Present (Scen) loop
Traverse_Potential_Scenarios (Scen);
Next (Scen);
end loop;
end Traverse_List;
---------------------------------
-- Traverse_Potential_Scenario --
---------------------------------
function Traverse_Potential_Scenario
(Scen : Node_Id) return Traverse_Result
is
begin
-- Special cases
-- Skip constructs which do not have elaboration of their own and
-- need to be elaborated by other means such as invocation, task
-- activation, etc.
if Is_Non_Library_Level_Encapsulator (Scen) then
return Skip;
-- Terminate the traversal of a task body when encountering an
-- accept or select statement, and
--
-- * Entry calls during elaboration are not allowed. In this
-- case the accept or select statement will cause the task
-- to block at elaboration time because there are no entry
-- calls to unblock it.
--
-- or
--
-- * Switch -gnatd_a (stop elaboration checks on accept or
-- select statement) is in effect.
elsif (Debug_Flag_Underscore_A
or else Restriction_Active
(No_Entry_Calls_In_Elaboration_Code))
and then Nkind (Original_Node (Scen)) in
N_Accept_Statement | N_Selective_Accept
then
return Abandon;
-- Terminate the traversal of a task body when encountering a
-- suspension call, and
--
-- * Entry calls during elaboration are not allowed. In this
-- case the suspension call emulates an entry call and will
-- cause the task to block at elaboration time.
--
-- or
--
-- * Switch -gnatd_s (stop elaboration checks on synchronous
-- suspension) is in effect.
--
-- Note that the guard should not be checking the state of flag
-- Within_Task_Body because only suspension calls which appear
-- immediately within the statements of the task are supported.
-- Flag Within_Task_Body carries over to deeper levels of the
-- traversal.
elsif (Debug_Flag_Underscore_S
or else Restriction_Active
(No_Entry_Calls_In_Elaboration_Code))
and then Is_Synchronous_Suspension_Call (Scen)
and then In_Task_Body (Scen)
then
return Abandon;
-- Certain nodes carry semantic lists which act as repositories
-- until expansion transforms the node and relocates the contents.
-- Examine these lists in case expansion is disabled.
elsif Nkind (Scen) in N_And_Then | N_Or_Else then
Traverse_List (Actions (Scen));
elsif Nkind (Scen) in N_Elsif_Part | N_Iteration_Scheme then
Traverse_List (Condition_Actions (Scen));
elsif Nkind (Scen) = N_If_Expression then
Traverse_List (Then_Actions (Scen));
Traverse_List (Else_Actions (Scen));
elsif Nkind (Scen) in
N_Component_Association | N_Iterated_Component_Association
then
Traverse_List (Loop_Actions (Scen));
-- General case
-- The current node satisfies the input predicate, process it
elsif Requires_Processing.all (Scen) then
Processor.all (Scen, In_State);
end if;
-- Save a general scenario regardless of whether it satisfies the
-- input predicate. This allows for quick subsequent traversals of
-- general scenarios, even with different predicates.
if Is_Suitable_Access_Taken (Scen)
or else Is_Suitable_Call (Scen)
or else Is_Suitable_Instantiation (Scen)
or else Is_Suitable_Variable_Assignment (Scen)
or else Is_Suitable_Variable_Reference (Scen)
then
NE_List.Append (Scenarios, Scen);
end if;
return OK;
end Traverse_Potential_Scenario;
-- Start of processing for Traverse_Body
begin
-- Nothing to do when the traversal is suppressed
if In_State.Traversal = No_Traversal then
return;
-- Nothing to do when there is no input
elsif No (N) then
return;
-- Nothing to do when the input is not a subprogram body
elsif Nkind (N) /= N_Subprogram_Body then
return;
-- Nothing to do if the subprogram body was already traversed
elsif Is_Traversed_Body (N) then
return;
end if;
-- Mark the subprogram body as traversed
Set_Is_Traversed_Body (N);
Scenarios := Nested_Scenarios (N);
-- The subprogram body has been traversed at least once, and all
-- scenarios that appear within its declarations and statements
-- have already been collected. Directly retraverse the scenarios
-- without having to retraverse the subprogram body subtree.
if NE_List.Present (Scenarios) then
Traverse_Collected_Scenarios;
-- Otherwise the subprogram body is being traversed for the first
-- time. Collect all scenarios that appear within its declarations
-- and statements in case the subprogram body has to be retraversed
-- multiple times.
else
Scenarios := NE_List.Create;
Set_Nested_Scenarios (N, Scenarios);
Traverse_List (Declarations (N));
Traverse_Potential_Scenarios (Handled_Statement_Sequence (N));
end if;
end Traverse_Body;
end Body_Processor;
-----------------------
-- Build_Call_Marker --
-----------------------
procedure Build_Call_Marker (N : Node_Id) is
function In_External_Context
(Call : Node_Id;
Subp_Id : Entity_Id) return Boolean;
pragma Inline (In_External_Context);
-- Determine whether entry, operator, or subprogram Subp_Id is external
-- to call Call which must reside within an instance.
function In_Premature_Context (Call : Node_Id) return Boolean;
pragma Inline (In_Premature_Context);
-- Determine whether call Call appears within a premature context
function Is_Default_Expression (Call : Node_Id) return Boolean;
pragma Inline (Is_Default_Expression);
-- Determine whether call Call acts as the expression of a defaulted
-- parameter within a source call.
function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean;
pragma Inline (Is_Generic_Formal_Subp);
-- Determine whether subprogram Subp_Id denotes a generic formal
-- subprogram which appears in the "prologue" of an instantiation.
-------------------------
-- In_External_Context --
-------------------------
function In_External_Context
(Call : Node_Id;
Subp_Id : Entity_Id) return Boolean
is
Spec_Decl : constant Entity_Id := Unit_Declaration_Node (Subp_Id);
Inst : Node_Id;
Inst_Body : Node_Id;
Inst_Spec : Node_Id;
begin
Inst := Find_Enclosing_Instance (Call);
-- The call appears within an instance
if Present (Inst) then
-- The call comes from the main unit and the target does not
if In_Extended_Main_Code_Unit (Call)
and then not In_Extended_Main_Code_Unit (Spec_Decl)
then
return True;
-- Otherwise the target declaration must not appear within the
-- instance spec or body.
else
Spec_And_Body_From_Node
(N => Inst,
Spec_Decl => Inst_Spec,
Body_Decl => Inst_Body);
return not In_Subtree
(N => Spec_Decl,
Root1 => Inst_Spec,
Root2 => Inst_Body);
end if;
end if;
return False;
end In_External_Context;
--------------------------
-- In_Premature_Context --
--------------------------
function In_Premature_Context (Call : Node_Id) return Boolean is
Par : Node_Id;
begin
-- Climb the parent chain looking for premature contexts
Par := Parent (Call);
while Present (Par) loop
-- Aspect specifications and generic associations are premature
-- contexts because nested calls has not been relocated to their
-- final context.
if Nkind (Par) in N_Aspect_Specification | N_Generic_Association
then
return True;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Premature_Context;
---------------------------
-- Is_Default_Expression --
---------------------------
function Is_Default_Expression (Call : Node_Id) return Boolean is
Outer_Call : constant Node_Id := Parent (Call);
Outer_Nam : Node_Id;
begin
-- To qualify, the node must appear immediately within a source call
-- which invokes a source target.
if Nkind (Outer_Call) in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement
and then Comes_From_Source (Outer_Call)
then
Outer_Nam := Call_Name (Outer_Call);
return
Is_Entity_Name (Outer_Nam)
and then Present (Entity (Outer_Nam))
and then Is_Subprogram_Or_Entry (Entity (Outer_Nam))
and then Comes_From_Source (Entity (Outer_Nam));
end if;
return False;
end Is_Default_Expression;
----------------------------
-- Is_Generic_Formal_Subp --
----------------------------
function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean is
Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
Context : constant Node_Id := Parent (Subp_Decl);
begin
-- To qualify, the subprogram must rename a generic actual subprogram
-- where the enclosing context is an instantiation.
return
Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
and then not Comes_From_Source (Subp_Decl)
and then Nkind (Context) in N_Function_Specification
| N_Package_Specification
| N_Procedure_Specification
and then Present (Generic_Parent (Context));
end Is_Generic_Formal_Subp;
-- Local variables
Call_Nam : Node_Id;
Marker : Node_Id;
Subp_Id : Entity_Id;
-- Start of processing for Build_Call_Marker
begin
-- Nothing to do when switch -gnatH (legacy elaboration checking mode
-- enabled) is in effect because the legacy ABE mechanism does not need
-- to carry out this action.
if Legacy_Elaboration_Checks then
return;
-- Nothing to do when the call is being preanalyzed as the marker will
-- be inserted in the wrong place.
elsif Preanalysis_Active then
return;
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
elsif not Elaboration_Phase_Active then
return;
-- Nothing to do when the input does not denote a call or a requeue
elsif Nkind (N) not in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement
| N_Requeue_Statement
then
return;
-- Nothing to do when the input denotes entry call or requeue statement,
-- and switch -gnatd_e (ignore entry calls and requeue statements for
-- elaboration) is in effect.
elsif Debug_Flag_Underscore_E
and then Nkind (N) in N_Entry_Call_Statement | N_Requeue_Statement
then
return;
-- Nothing to do when the call is analyzed/resolved too early within an
-- intermediate context. This check is saved for last because it incurs
-- a performance penalty.
elsif In_Premature_Context (N) then
return;
end if;
Call_Nam := Call_Name (N);
-- Nothing to do when the call is erroneous or left in a bad state
if not (Is_Entity_Name (Call_Nam)
and then Present (Entity (Call_Nam))
and then Is_Subprogram_Or_Entry (Entity (Call_Nam)))
then
return;
end if;
Subp_Id := Canonical_Subprogram (Entity (Call_Nam));
-- Nothing to do when the call invokes a generic formal subprogram and
-- switch -gnatd.G (ignore calls through generic formal parameters for
-- elaboration) is in effect. This check must be performed with the
-- direct target of the call to avoid the side effects of mapping
-- actuals to formals using renamings.
if Debug_Flag_Dot_GG
and then Is_Generic_Formal_Subp (Entity (Call_Nam))
then
return;
-- Nothing to do when the call appears within the expanded spec or
-- body of an instantiated generic, the call does not invoke a generic
-- formal subprogram, the target is external to the instance, and switch
-- -gnatdL (ignore external calls from instances for elaboration) is in
-- effect. This check must be performed with the direct target of the
-- call to avoid the side effects of mapping actuals to formals using
-- renamings.
elsif Debug_Flag_LL
and then not Is_Generic_Formal_Subp (Entity (Call_Nam))
and then In_External_Context
(Call => N,
Subp_Id => Subp_Id)
then
return;
-- Nothing to do when the call invokes an assertion pragma procedure
-- and switch -gnatd_p (ignore assertion pragmas for elaboration) is
-- in effect.
elsif Debug_Flag_Underscore_P
and then Is_Assertion_Pragma_Target (Subp_Id)
then
return;
-- Static expression functions require no ABE processing
elsif Is_Static_Function (Subp_Id) then
return;
-- Source calls to source targets are always considered because they
-- reflect the original call graph.
elsif Comes_From_Source (N) and then Comes_From_Source (Subp_Id) then
null;
-- A call to a source function which acts as the default expression in
-- another call requires special detection.
elsif Comes_From_Source (Subp_Id)
and then Nkind (N) = N_Function_Call
and then Is_Default_Expression (N)
then
null;
-- The target emulates Ada semantics
elsif Is_Ada_Semantic_Target (Subp_Id) then
null;
-- The target acts as a link between scenarios
elsif Is_Bridge_Target (Subp_Id) then
null;
-- The target emulates SPARK semantics
elsif Is_SPARK_Semantic_Target (Subp_Id) then
null;
-- Otherwise the call is not suitable for ABE processing. This prevents
-- the generation of call markers which will never play a role in ABE
-- diagnostics.
else
return;
end if;
-- At this point it is known that the call will play some role in ABE
-- checks and diagnostics. Create a corresponding call marker in case
-- the original call is heavily transformed by expansion later on.
Marker := Make_Call_Marker (Sloc (N));
-- Inherit the attributes of the original call
Set_Is_Declaration_Level_Node
(Marker, Find_Enclosing_Level (N) = Declaration_Level);
Set_Is_Dispatching_Call
(Marker,
Nkind (N) in N_Function_Call | N_Procedure_Call_Statement
and then Present (Controlling_Argument (N)));
Set_Is_Elaboration_Checks_OK_Node
(Marker, Is_Elaboration_Checks_OK_Node (N));
Set_Is_Elaboration_Warnings_OK_Node
(Marker, Is_Elaboration_Warnings_OK_Node (N));
Set_Is_Ignored_Ghost_Node (Marker, Is_Ignored_Ghost_Node (N));
Set_Is_Source_Call (Marker, Comes_From_Source (N));
Set_Is_SPARK_Mode_On_Node (Marker, Is_SPARK_Mode_On_Node (N));
Set_Target (Marker, Subp_Id);
-- Ada 2020 (AI12-0175): Calls to certain functions that are essentially
-- unchecked conversions are preelaborable.
if Ada_Version >= Ada_2020 then
Set_Is_Preelaborable_Call (Marker, Is_Preelaborable_Construct (N));
else
Set_Is_Preelaborable_Call (Marker, False);
end if;
-- The marker is inserted prior to the original call. This placement has
-- several desirable effects:
-- 1) The marker appears in the same context, in close proximity to
-- the call.
-- <marker>
-- <call>
-- 2) Inserting the marker prior to the call ensures that an ABE check
-- will take effect prior to the call.
-- <ABE check>
-- <marker>
-- <call>
-- 3) The above two properties are preserved even when the call is a
-- function which is subsequently relocated in order to capture its
-- result. Note that if the call is relocated to a new context, the
-- relocated call will receive a marker of its own.
-- <ABE check>
-- <maker>
-- Temp : ... := Func_Call ...;
-- ... Temp ...
-- The insertion must take place even when the call does not occur in
-- the main unit to keep the tree symmetric. This ensures that internal
-- name serialization is consistent in case the call marker causes the
-- tree to transform in some way.
Insert_Action (N, Marker);
-- The marker becomes the "corresponding" scenario for the call. Save
-- the marker for later processing by the ABE phase.
Record_Elaboration_Scenario (Marker);
end Build_Call_Marker;
-------------------------------------
-- Build_Variable_Reference_Marker --
-------------------------------------
procedure Build_Variable_Reference_Marker
(N : Node_Id;
Read : Boolean;
Write : Boolean)
is
function Ultimate_Variable (Var_Id : Entity_Id) return Entity_Id;
pragma Inline (Ultimate_Variable);
-- Obtain the ultimate renamed variable of variable Var_Id
-----------------------
-- Ultimate_Variable --
-----------------------
function Ultimate_Variable (Var_Id : Entity_Id) return Entity_Id is
Ren_Id : Entity_Id;
begin
Ren_Id := Var_Id;
while Present (Renamed_Entity (Ren_Id))
and then Nkind (Renamed_Entity (Ren_Id)) in N_Entity
loop
Ren_Id := Renamed_Entity (Ren_Id);
end loop;
return Ren_Id;
end Ultimate_Variable;
-- Local variables
Var_Id : constant Entity_Id := Ultimate_Variable (Entity (N));
Marker : Node_Id;
-- Start of processing for Build_Variable_Reference_Marker
begin
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
if not Elaboration_Phase_Active then
return;
end if;
Marker := Make_Variable_Reference_Marker (Sloc (N));
-- Inherit the attributes of the original variable reference
Set_Is_Elaboration_Checks_OK_Node
(Marker, Is_Elaboration_Checks_OK_Node (N));
Set_Is_Elaboration_Warnings_OK_Node
(Marker, Is_Elaboration_Warnings_OK_Node (N));
Set_Is_Read (Marker, Read);
Set_Is_SPARK_Mode_On_Node (Marker, Is_SPARK_Mode_On_Node (N));
Set_Is_Write (Marker, Write);
Set_Target (Marker, Var_Id);
-- The marker is inserted prior to the original variable reference. The
-- insertion must take place even when the reference does not occur in
-- the main unit to keep the tree symmetric. This ensures that internal
-- name serialization is consistent in case the variable marker causes
-- the tree to transform in some way.
Insert_Action (N, Marker);
-- The marker becomes the "corresponding" scenario for the reference.
-- Save the marker for later processing for the ABE phase.
Record_Elaboration_Scenario (Marker);
end Build_Variable_Reference_Marker;
---------------
-- Call_Name --
---------------
function Call_Name (Call : Node_Id) return Node_Id is
Nam : Node_Id;
begin
Nam := Name (Call);
-- When the call invokes an entry family, the name appears as an indexed
-- component.
if Nkind (Nam) = N_Indexed_Component then
Nam := Prefix (Nam);
end if;
-- When the call employs the object.operation form, the name appears as
-- a selected component.
if Nkind (Nam) = N_Selected_Component then
Nam := Selector_Name (Nam);
end if;
return Nam;
end Call_Name;
--------------------------
-- Canonical_Subprogram --
--------------------------
function Canonical_Subprogram (Subp_Id : Entity_Id) return Entity_Id is
Canon_Id : Entity_Id;
begin
Canon_Id := Subp_Id;
-- Use the original protected subprogram when dealing with one of the
-- specialized lock-manipulating versions.
if Is_Protected_Body_Subp (Canon_Id) then
Canon_Id := Protected_Subprogram (Canon_Id);
end if;
-- Obtain the original subprogram except when the subprogram is also
-- an instantiation. In this case the alias is the internally generated
-- subprogram which appears within the anonymous package created for the
-- instantiation, making it unuitable.
if not Is_Generic_Instance (Canon_Id) then
Canon_Id := Get_Renamed_Entity (Canon_Id);
end if;
return Canon_Id;
end Canonical_Subprogram;
---------------------------------
-- Check_Elaboration_Scenarios --
---------------------------------
procedure Check_Elaboration_Scenarios is
Iter : NE_Set.Iterator;
begin
-- Nothing to do when switch -gnatH (legacy elaboration checking mode
-- enabled) is in effect because the legacy ABE mechanism does not need
-- to carry out this action.
if Legacy_Elaboration_Checks then
Finalize_All_Data_Structures;
return;
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
elsif not Elaboration_Phase_Active then
Finalize_All_Data_Structures;
return;
end if;
-- Restore the original elaboration model which was in effect when the
-- scenarios were first recorded. The model may be specified by pragma
-- Elaboration_Checks which appears on the initial declaration of the
-- main unit.
Install_Elaboration_Model (Unit_Entity (Main_Unit_Entity));
-- Examine the context of the main unit and record all units with prior
-- elaboration with respect to it.
Collect_Elaborated_Units;
-- Examine all scenarios saved during the Recording phase applying the
-- Ada or SPARK elaboration rules in order to detect and diagnose ABE
-- issues, install conditional ABE checks, and ensure the elaboration
-- of units.
Iter := Iterate_Declaration_Scenarios;
Check_Conditional_ABE_Scenarios (Iter);
Iter := Iterate_Library_Body_Scenarios;
Check_Conditional_ABE_Scenarios (Iter);
Iter := Iterate_Library_Spec_Scenarios;
Check_Conditional_ABE_Scenarios (Iter);
-- Examine each SPARK scenario saved during the Recording phase which
-- is not necessarily executable during elaboration, but still requires
-- elaboration-related checks.
Check_SPARK_Scenarios;
-- Add conditional ABE checks for all scenarios that require one when
-- the dynamic model is in effect.
Install_Dynamic_ABE_Checks;
-- Examine all scenarios saved during the Recording phase along with
-- invocation constructs within the spec and body of the main unit.
-- Record the declarations and paths that reach into an external unit
-- in the ALI file of the main unit.
Record_Invocation_Graph;
-- Destroy all internal data structures and complete the elaboration
-- phase of the compiler.
Finalize_All_Data_Structures;
Set_Elaboration_Phase (Completed);
end Check_Elaboration_Scenarios;
---------------------
-- Check_Installer --
---------------------
package body Check_Installer is
-----------------------
-- Local subprograms --
-----------------------
function ABE_Check_Or_Failure_OK
(N : Node_Id;
Targ_Id : Entity_Id;
Unit_Id : Entity_Id) return Boolean;
pragma Inline (ABE_Check_Or_Failure_OK);
-- Determine whether a conditional ABE check or guaranteed ABE failure
-- can be installed for scenario N with target Targ_Id which resides in
-- unit Unit_Id.
function Insertion_Node (N : Node_Id) return Node_Id;
pragma Inline (Insertion_Node);
-- Obtain the proper insertion node of an ABE check or failure for
-- scenario N.
procedure Insert_ABE_Check_Or_Failure (N : Node_Id; Check : Node_Id);
pragma Inline (Insert_ABE_Check_Or_Failure);
-- Insert conditional ABE check or guaranteed ABE failure Check prior to
-- scenario N.
procedure Install_Scenario_ABE_Check_Common
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id);
pragma Inline (Install_Scenario_ABE_Check_Common);
-- Install a conditional ABE check for scenario N to ensure that target
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the
-- target.
procedure Install_Scenario_ABE_Failure_Common (N : Node_Id);
pragma Inline (Install_Scenario_ABE_Failure_Common);
-- Install a guaranteed ABE failure for scenario N
procedure Install_Unit_ABE_Check_Common
(N : Node_Id;
Unit_Id : Entity_Id);
pragma Inline (Install_Unit_ABE_Check_Common);
-- Install a conditional ABE check for scenario N to ensure that unit
-- Unit_Id is properly elaborated.
-----------------------------
-- ABE_Check_Or_Failure_OK --
-----------------------------
function ABE_Check_Or_Failure_OK
(N : Node_Id;
Targ_Id : Entity_Id;
Unit_Id : Entity_Id) return Boolean
is
pragma Unreferenced (Targ_Id);
Ins_Node : constant Node_Id := Insertion_Node (N);
begin
if not Check_Or_Failure_Generation_OK then
return False;
-- Nothing to do when the scenario denots a compilation unit because
-- there is no executable environment at that level.
elsif Nkind (Parent (Ins_Node)) = N_Compilation_Unit then
return False;
-- An ABE check or failure is not needed when the target is defined
-- in a unit which is elaborated prior to the main unit. This check
-- must also consider the following cases:
--
-- * The unit of the target appears in the context of the main unit
--
-- * The unit of the target is subject to pragma Elaborate_Body. An
-- ABE check MUST NOT be generated because the unit is always
-- elaborated prior to the main unit.
--
-- * The unit of the target is the main unit. An ABE check MUST be
-- added in this case because a conditional ABE may be raised
-- depending on the flow of execution within the main unit (flag
-- Same_Unit_OK is False).
elsif Has_Prior_Elaboration
(Unit_Id => Unit_Id,
Context_OK => True,
Elab_Body_OK => True)
then
return False;
end if;
return True;
end ABE_Check_Or_Failure_OK;
------------------------------------
-- Check_Or_Failure_Generation_OK --
------------------------------------
function Check_Or_Failure_Generation_OK return Boolean is
begin
-- An ABE check or failure is not needed when the compilation will
-- not produce an executable.
if Serious_Errors_Detected > 0 then
return False;
-- An ABE check or failure must not be installed when compiling for
-- GNATprove because raise statements are not supported.
elsif GNATprove_Mode then
return False;
end if;
return True;
end Check_Or_Failure_Generation_OK;
--------------------
-- Insertion_Node --
--------------------
function Insertion_Node (N : Node_Id) return Node_Id is
begin
-- When the scenario denotes an instantiation, the proper insertion
-- node is the instance spec. This ensures that the generic actuals
-- will not be evaluated prior to a potential ABE.
if Nkind (N) in N_Generic_Instantiation
and then Present (Instance_Spec (N))
then
return Instance_Spec (N);
-- Otherwise the proper insertion node is the scenario itself
else
return N;
end if;
end Insertion_Node;
---------------------------------
-- Insert_ABE_Check_Or_Failure --
---------------------------------
procedure Insert_ABE_Check_Or_Failure (N : Node_Id; Check : Node_Id) is
Ins_Nod : constant Node_Id := Insertion_Node (N);
Scop_Id : constant Entity_Id := Find_Enclosing_Scope (Ins_Nod);
begin
-- Install the nearest enclosing scope of the scenario as there must
-- be something on the scope stack.
Push_Scope (Scop_Id);
Insert_Action (Ins_Nod, Check);
Pop_Scope;
end Insert_ABE_Check_Or_Failure;
--------------------------------
-- Install_Dynamic_ABE_Checks --
--------------------------------
procedure Install_Dynamic_ABE_Checks is
Iter : NE_Set.Iterator;
N : Node_Id;
begin
if not Check_Or_Failure_Generation_OK then
return;
-- Nothing to do if the dynamic model is not in effect
elsif not Dynamic_Elaboration_Checks then
return;
end if;
-- Install a conditional ABE check for each saved scenario
Iter := Iterate_Dynamic_ABE_Check_Scenarios;
while NE_Set.Has_Next (Iter) loop
NE_Set.Next (Iter, N);
Process_Conditional_ABE
(N => N,
In_State => Dynamic_Model_State);
end loop;
end Install_Dynamic_ABE_Checks;
--------------------------------
-- Install_Scenario_ABE_Check --
--------------------------------
procedure Install_Scenario_ABE_Check
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Scenario_Rep_Id)
is
begin
-- Nothing to do when the scenario does not need an ABE check
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Targ_Id,
Unit_Id => Unit (Targ_Rep))
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Scenario_ABE_Check_Common
(N => N,
Targ_Id => Targ_Id,
Targ_Rep => Targ_Rep);
end Install_Scenario_ABE_Check;
--------------------------------
-- Install_Scenario_ABE_Check --
--------------------------------
procedure Install_Scenario_ABE_Check
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Target_Rep_Id)
is
begin
-- Nothing to do when the scenario does not need an ABE check
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Targ_Id,
Unit_Id => Unit (Targ_Rep))
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Scenario_ABE_Check_Common
(N => N,
Targ_Id => Targ_Id,
Targ_Rep => Targ_Rep);
end Install_Scenario_ABE_Check;
---------------------------------------
-- Install_Scenario_ABE_Check_Common --
---------------------------------------
procedure Install_Scenario_ABE_Check_Common
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id)
is
Targ_Body : constant Node_Id := Body_Declaration (Targ_Rep);
Targ_Decl : constant Node_Id := Spec_Declaration (Targ_Rep);
pragma Assert (Present (Targ_Body));
pragma Assert (Present (Targ_Decl));
procedure Build_Elaboration_Entity;
pragma Inline (Build_Elaboration_Entity);
-- Create a new elaboration flag for Targ_Id, insert it prior to
-- Targ_Decl, and set it after Targ_Body.
------------------------------
-- Build_Elaboration_Entity --
------------------------------
procedure Build_Elaboration_Entity is
Loc : constant Source_Ptr := Sloc (Targ_Id);
Flag_Id : Entity_Id;
begin
-- Nothing to do if the target has an elaboration flag
if Present (Elaboration_Entity (Targ_Id)) then
return;
end if;
-- Create the declaration of the elaboration flag. The name
-- carries a unique counter in case the name is overloaded.
Flag_Id :=
Make_Defining_Identifier (Loc,
Chars => New_External_Name (Chars (Targ_Id), 'E', -1));
Set_Elaboration_Entity (Targ_Id, Flag_Id);
Set_Elaboration_Entity_Required (Targ_Id);
Push_Scope (Scope (Targ_Id));
-- Generate:
-- Enn : Short_Integer := 0;
Insert_Action (Targ_Decl,
Make_Object_Declaration (Loc,
Defining_Identifier => Flag_Id,
Object_Definition =>
New_Occurrence_Of (Standard_Short_Integer, Loc),
Expression => Make_Integer_Literal (Loc, Uint_0)));
-- Generate:
-- Enn := 1;
Set_Elaboration_Flag (Targ_Body, Targ_Id);
Pop_Scope;
end Build_Elaboration_Entity;
-- Local variables
Loc : constant Source_Ptr := Sloc (N);
-- Start for processing for Install_Scenario_ABE_Check_Common
begin
-- Create an elaboration flag for the target when it does not have
-- one.
Build_Elaboration_Entity;
-- Generate:
-- if not Targ_Id'Elaborated then
-- raise Program_Error with "access before elaboration";
-- end if;
Insert_ABE_Check_Or_Failure
(N => N,
Check =>
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Not (Loc,
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Targ_Id, Loc),
Attribute_Name => Name_Elaborated)),
Reason => PE_Access_Before_Elaboration));
end Install_Scenario_ABE_Check_Common;
----------------------------------
-- Install_Scenario_ABE_Failure --
----------------------------------
procedure Install_Scenario_ABE_Failure
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Scenario_Rep_Id)
is
begin
-- Nothing to do when the scenario does not require an ABE failure
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Targ_Id,
Unit_Id => Unit (Targ_Rep))
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Scenario_ABE_Failure_Common (N);
end Install_Scenario_ABE_Failure;
----------------------------------
-- Install_Scenario_ABE_Failure --
----------------------------------
procedure Install_Scenario_ABE_Failure
(N : Node_Id;
Targ_Id : Entity_Id;
Targ_Rep : Target_Rep_Id;
Disable : Target_Rep_Id)
is
begin
-- Nothing to do when the scenario does not require an ABE failure
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Targ_Id,
Unit_Id => Unit (Targ_Rep))
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Scenario_ABE_Failure_Common (N);
end Install_Scenario_ABE_Failure;
-----------------------------------------
-- Install_Scenario_ABE_Failure_Common --
-----------------------------------------
procedure Install_Scenario_ABE_Failure_Common (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
begin
-- Generate:
-- raise Program_Error with "access before elaboration";
Insert_ABE_Check_Or_Failure
(N => N,
Check =>
Make_Raise_Program_Error (Loc,
Reason => PE_Access_Before_Elaboration));
end Install_Scenario_ABE_Failure_Common;
----------------------------
-- Install_Unit_ABE_Check --
----------------------------
procedure Install_Unit_ABE_Check
(N : Node_Id;
Unit_Id : Entity_Id;
Disable : Scenario_Rep_Id)
is
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id);
begin
-- Nothing to do when the scenario does not require an ABE check
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Empty,
Unit_Id => Spec_Id)
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Unit_ABE_Check_Common
(N => N,
Unit_Id => Unit_Id);
end Install_Unit_ABE_Check;
----------------------------
-- Install_Unit_ABE_Check --
----------------------------
procedure Install_Unit_ABE_Check
(N : Node_Id;
Unit_Id : Entity_Id;
Disable : Target_Rep_Id)
is
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id);
begin
-- Nothing to do when the scenario does not require an ABE check
if not ABE_Check_Or_Failure_OK
(N => N,
Targ_Id => Empty,
Unit_Id => Spec_Id)
then
return;
end if;
-- Prevent multiple attempts to install the same ABE check
Disable_Elaboration_Checks (Disable);
Install_Unit_ABE_Check_Common
(N => N,
Unit_Id => Unit_Id);
end Install_Unit_ABE_Check;
-----------------------------------
-- Install_Unit_ABE_Check_Common --
-----------------------------------
procedure Install_Unit_ABE_Check_Common
(N : Node_Id;
Unit_Id : Entity_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id);
begin
-- Generate:
-- if not Spec_Id'Elaborated then
-- raise Program_Error with "access before elaboration";
-- end if;
Insert_ABE_Check_Or_Failure
(N => N,
Check =>
Make_Raise_Program_Error (Loc,
Condition =>
Make_Op_Not (Loc,
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Spec_Id, Loc),
Attribute_Name => Name_Elaborated)),
Reason => PE_Access_Before_Elaboration));
end Install_Unit_ABE_Check_Common;
end Check_Installer;
----------------------
-- Compilation_Unit --
----------------------
function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id is
Comp_Unit : Node_Id;
begin
Comp_Unit := Parent (Unit_Id);
-- Handle the case where a concurrent subunit is rewritten as a null
-- statement due to expansion activities.
if Nkind (Comp_Unit) = N_Null_Statement
and then Nkind (Original_Node (Comp_Unit)) in
N_Protected_Body | N_Task_Body
then
Comp_Unit := Parent (Comp_Unit);
pragma Assert (Nkind (Comp_Unit) = N_Subunit);
-- Otherwise use the declaration node of the unit
else
Comp_Unit := Parent (Unit_Declaration_Node (Unit_Id));
end if;
-- Handle the case where a subprogram instantiation which acts as a
-- compilation unit is expanded into an anonymous package that wraps
-- the instantiated subprogram.
if Nkind (Comp_Unit) = N_Package_Specification
and then Nkind (Original_Node (Parent (Comp_Unit))) in
N_Function_Instantiation | N_Procedure_Instantiation
then
Comp_Unit := Parent (Parent (Comp_Unit));
-- Handle the case where the compilation unit is a subunit
elsif Nkind (Comp_Unit) = N_Subunit then
Comp_Unit := Parent (Comp_Unit);
end if;
pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit);
return Comp_Unit;
end Compilation_Unit;
-------------------------------
-- Conditional_ABE_Processor --
-------------------------------
package body Conditional_ABE_Processor is
-----------------------
-- Local subprograms --
-----------------------
function Is_Conditional_ABE_Scenario (N : Node_Id) return Boolean;
pragma Inline (Is_Conditional_ABE_Scenario);
-- Determine whether node N is a suitable scenario for conditional ABE
-- checks and diagnostics.
procedure Process_Conditional_ABE_Access_Taken
(Attr : Node_Id;
Attr_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Access_Taken);
-- Perform ABE checks and diagnostics for attribute reference Attr with
-- representation Attr_Rep which takes 'Access of an entry, operator, or
-- subprogram. In_State is the current state of the Processing phase.
procedure Process_Conditional_ABE_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Activation);
-- Perform common conditional ABE checks and diagnostics for activation
-- call Call which activates object Obj_Id of task type Task_Typ. Formal
-- Call_Rep denotes the representation of the call. Obj_Rep denotes the
-- representation of the object. Task_Rep denotes the representation of
-- the task type. In_State is the current state of the Processing phase.
procedure Process_Conditional_ABE_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Call);
-- Top-level dispatcher for processing of calls. Perform ABE checks and
-- diagnostics for call Call with representation Call_Rep. In_State is
-- the current state of the Processing phase.
procedure Process_Conditional_ABE_Call_Ada
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Call_Ada);
-- Perform ABE checks and diagnostics for call Call which invokes entry,
-- operator, or subprogram Subp_Id using the Ada rules. Call_Rep denotes
-- the representation of the call. Subp_Rep denotes the representation
-- of the subprogram. In_State is the current state of the Processing
-- phase.
procedure Process_Conditional_ABE_Call_SPARK
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Call_SPARK);
-- Perform ABE checks and diagnostics for call Call which invokes entry,
-- operator, or subprogram Subp_Id using the SPARK rules. Call_Rep is
-- the representation of the call. Subp_Rep denotes the representation
-- of the subprogram. In_State is the current state of the Processing
-- phase.
procedure Process_Conditional_ABE_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Instantiation);
-- Top-level dispatcher for processing of instantiations. Perform ABE
-- checks and diagnostics for instantiation Inst with representation
-- Inst_Rep. In_State is the current state of the Processing phase.
procedure Process_Conditional_ABE_Instantiation_Ada
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Instantiation_Ada);
-- Perform ABE checks and diagnostics for instantiation Inst of generic
-- Gen_Id using the Ada rules. Inst_Rep denotes the representation of
-- the instnace. Gen_Rep is the representation of the generic. In_State
-- is the current state of the Processing phase.
procedure Process_Conditional_ABE_Instantiation_SPARK
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Instantiation_SPARK);
-- Perform ABE checks and diagnostics for instantiation Inst of generic
-- Gen_Id using the SPARK rules. Inst_Rep denotes the representation of
-- the instnace. Gen_Rep is the representation of the generic. In_State
-- is the current state of the Processing phase.
procedure Process_Conditional_ABE_Variable_Assignment
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Variable_Assignment);
-- Top-level dispatcher for processing of variable assignments. Perform
-- ABE checks and diagnostics for assignment Asmt with representation
-- Asmt_Rep. In_State denotes the current state of the Processing phase.
procedure Process_Conditional_ABE_Variable_Assignment_Ada
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Var_Id : Entity_Id;
Var_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Variable_Assignment_Ada);
-- Perform ABE checks and diagnostics for assignment statement Asmt that
-- modifies the value of variable Var_Id using the Ada rules. Asmt_Rep
-- denotes the representation of the assignment. Var_Rep denotes the
-- representation of the variable. In_State is the current state of the
-- Processing phase.
procedure Process_Conditional_ABE_Variable_Assignment_SPARK
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Var_Id : Entity_Id;
Var_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Variable_Assignment_SPARK);
-- Perform ABE checks and diagnostics for assignment statement Asmt that
-- modifies the value of variable Var_Id using the SPARK rules. Asmt_Rep
-- denotes the representation of the assignment. Var_Rep denotes the
-- representation of the variable. In_State is the current state of the
-- Processing phase.
procedure Process_Conditional_ABE_Variable_Reference
(Ref : Node_Id;
Ref_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Conditional_ABE_Variable_Reference);
-- Perform ABE checks and diagnostics for variable reference Ref with
-- representation Ref_Rep. In_State denotes the current state of the
-- Processing phase.
procedure Traverse_Conditional_ABE_Body
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Traverse_Conditional_ABE_Body);
-- Traverse subprogram body N looking for suitable scenarios that need
-- to be processed for conditional ABE checks and diagnostics. In_State
-- is the current state of the Processing phase.
-------------------------------------
-- Check_Conditional_ABE_Scenarios --
-------------------------------------
procedure Check_Conditional_ABE_Scenarios
(Iter : in out NE_Set.Iterator)
is
N : Node_Id;
begin
while NE_Set.Has_Next (Iter) loop
NE_Set.Next (Iter, N);
-- Reset the traversed status of all subprogram bodies because the
-- current conditional scenario acts as a new DFS traversal root.
Reset_Traversed_Bodies;
Process_Conditional_ABE
(N => N,
In_State => Conditional_ABE_State);
end loop;
end Check_Conditional_ABE_Scenarios;
---------------------------------
-- Is_Conditional_ABE_Scenario --
---------------------------------
function Is_Conditional_ABE_Scenario (N : Node_Id) return Boolean is
begin
return
Is_Suitable_Access_Taken (N)
or else Is_Suitable_Call (N)
or else Is_Suitable_Instantiation (N)
or else Is_Suitable_Variable_Assignment (N)
or else Is_Suitable_Variable_Reference (N);
end Is_Conditional_ABE_Scenario;
-----------------------------
-- Process_Conditional_ABE --
-----------------------------
procedure Process_Conditional_ABE
(N : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
Scen_Rep : Scenario_Rep_Id;
begin
-- Add the current scenario to the stack of active scenarios
Push_Active_Scenario (Scen);
-- 'Access
if Is_Suitable_Access_Taken (Scen) then
Process_Conditional_ABE_Access_Taken
(Attr => Scen,
Attr_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Call or task activation
elsif Is_Suitable_Call (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
-- Routine Build_Call_Marker creates call markers regardless of
-- whether the call occurs within the main unit or not. This way
-- the serialization of internal names is kept consistent. Only
-- call markers found within the main unit must be processed.
if In_Main_Context (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
if Kind (Scen_Rep) = Call_Scenario then
Process_Conditional_ABE_Call
(Call => Scen,
Call_Rep => Scen_Rep,
In_State => In_State);
else
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario);
Process_Activation
(Call => Scen,
Call_Rep => Scen_Rep,
Processor => Process_Conditional_ABE_Activation'Access,
In_State => In_State);
end if;
end if;
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Process_Conditional_ABE_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Variable assignments
elsif Is_Suitable_Variable_Assignment (Scen) then
Process_Conditional_ABE_Variable_Assignment
(Asmt => Scen,
Asmt_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Variable references
elsif Is_Suitable_Variable_Reference (Scen) then
-- Routine Build_Variable_Reference_Marker makes variable markers
-- regardless of whether the reference occurs within the main unit
-- or not. This way the serialization of internal names is kept
-- consistent. Only variable markers within the main unit must be
-- processed.
if In_Main_Context (Scen) then
Process_Conditional_ABE_Variable_Reference
(Ref => Scen,
Ref_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
end if;
end if;
-- Remove the current scenario from the stack of active scenarios
-- once all ABE diagnostics and checks have been performed.
Pop_Active_Scenario (Scen);
end Process_Conditional_ABE;
------------------------------------------
-- Process_Conditional_ABE_Access_Taken --
------------------------------------------
procedure Process_Conditional_ABE_Access_Taken
(Attr : Node_Id;
Attr_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
function Build_Access_Marker (Subp_Id : Entity_Id) return Node_Id;
pragma Inline (Build_Access_Marker);
-- Create a suitable call marker which invokes subprogram Subp_Id
-------------------------
-- Build_Access_Marker --
-------------------------
function Build_Access_Marker (Subp_Id : Entity_Id) return Node_Id is
Marker : Node_Id;
begin
Marker := Make_Call_Marker (Sloc (Attr));
-- Inherit relevant attributes from the attribute
Set_Target (Marker, Subp_Id);
Set_Is_Declaration_Level_Node
(Marker, Level (Attr_Rep) = Declaration_Level);
Set_Is_Dispatching_Call
(Marker, False);
Set_Is_Elaboration_Checks_OK_Node
(Marker, Elaboration_Checks_OK (Attr_Rep));
Set_Is_Elaboration_Warnings_OK_Node
(Marker, Elaboration_Warnings_OK (Attr_Rep));
Set_Is_Preelaborable_Call
(Marker, False);
Set_Is_Source_Call
(Marker, Comes_From_Source (Attr));
Set_Is_SPARK_Mode_On_Node
(Marker, SPARK_Mode_Of (Attr_Rep) = Is_On);
-- Partially insert the call marker into the tree by setting its
-- parent pointer.
Set_Parent (Marker, Attr);
return Marker;
end Build_Access_Marker;
-- Local variables
Root : constant Node_Id := Root_Scenario;
Subp_Id : constant Entity_Id := Target (Attr_Rep);
Subp_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Subp_Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
-- Start of processing for Process_Conditional_ABE_Access
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not New_In_State.Suppress_Info_Messages
then
Error_Msg_NE
("info: access to & during elaboration", Attr, Subp_Id);
end if;
-- Warnings are suppressed when a prior scenario is already in that
-- mode or when the attribute or the target have warnings suppressed.
-- Update the state of the Processing phase to reflect this.
New_In_State.Suppress_Warnings :=
New_In_State.Suppress_Warnings
or else not Elaboration_Warnings_OK (Attr_Rep)
or else not Elaboration_Warnings_OK (Subp_Rep);
-- Do not emit any ABE diagnostics when the current or previous
-- scenario in this traversal has suppressed elaboration warnings.
if New_In_State.Suppress_Warnings then
null;
-- Both the attribute and the corresponding subprogram body are in
-- the same unit. The body must appear prior to the root scenario
-- which started the recursive search. If this is not the case, then
-- there is a potential ABE if the access value is used to call the
-- subprogram. Emit a warning only when switch -gnatw.f (warnings on
-- suspucious 'Access) is in effect.
elsif Warn_On_Elab_Access
and then Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
and then Earlier_In_Extended_Unit (Root, Body_Decl)
then
Error_Msg_Name_1 := Attribute_Name (Attr);
Error_Msg_NE
("??% attribute of & before body seen", Attr, Subp_Id);
Error_Msg_N ("\possible Program_Error on later references", Attr);
Output_Active_Scenarios (Attr, New_In_State);
end if;
-- Treat the attribute an immediate invocation of the target when
-- switch -gnatd.o (conservative elaboration order for indirect
-- calls) is in effect. This has the following desirable effects:
--
-- * Ensure that the unit with the corresponding body is elaborated
-- prior to the main unit.
--
-- * Perform conditional ABE checks and diagnostics
--
-- * Traverse the body of the target (if available)
if Debug_Flag_Dot_O then
Process_Conditional_ABE
(N => Build_Access_Marker (Subp_Id),
In_State => New_In_State);
-- Otherwise ensure that the unit with the corresponding body is
-- elaborated prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Attr,
Unit_Id => Unit (Subp_Rep),
Prag_Nam => Name_Elaborate_All,
In_State => New_In_State);
end if;
end Process_Conditional_ABE_Access_Taken;
----------------------------------------
-- Process_Conditional_ABE_Activation --
----------------------------------------
procedure Process_Conditional_ABE_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Task_Typ);
Body_Decl : constant Node_Id := Body_Declaration (Task_Rep);
Spec_Decl : constant Node_Id := Spec_Declaration (Task_Rep);
Root : constant Node_Id := Root_Scenario;
Unit_Id : constant Node_Id := Unit (Task_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Obj_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Task_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Obj_Rep)
and then Elaboration_Checks_OK (Task_Rep);
-- A run-time ABE check may be installed only when the object and the
-- task type have active elaboration checks, and both are not ignored
-- Ghost constructs.
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not New_In_State.Suppress_Info_Messages
then
Error_Msg_NE
("info: activation of & during elaboration", Call, Obj_Id);
end if;
-- Nothing to do when the call activates a task whose type is defined
-- within an instance and switch -gnatd_i (ignore activations and
-- calls to instances for elaboration) is in effect.
if Debug_Flag_Underscore_I
and then In_External_Instance
(N => Call,
Target_Decl => Spec_Decl)
then
return;
-- Nothing to do when the activation is a guaranteed ABE
elsif Is_Known_Guaranteed_ABE (Call) then
return;
-- Nothing to do when the root scenario appears at the declaration
-- level and the task is in the same unit, but outside this context.
--
-- task type Task_Typ; -- task declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- T : Task_Typ;
-- begin
-- <activation call> -- activation site
-- end;
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- task body Task_Typ is
-- ...
-- end Task_Typ;
--
-- In the example above, the context of X is the declarative list of
-- Proc. The "elaboration" of X may reach the activation of T whose
-- body is defined outside of X's context. The task body is relevant
-- only when Proc is invoked, but this happens only during "normal"
-- elaboration, therefore the task body must not be considered if
-- this is not the case.
elsif Is_Up_Level_Target
(Targ_Decl => Spec_Decl,
In_State => New_In_State)
then
return;
-- Nothing to do when the activation is ABE-safe
--
-- generic
-- package Gen is
-- task type Task_Typ;
-- end Gen;
--
-- package body Gen is
-- task body Task_Typ is
-- begin
-- ...
-- end Task_Typ;
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- package Nested is
-- package Inst is new Gen;
-- T : Inst.Task_Typ;
-- <activation call> -- safe activation
-- end Nested;
-- ...
elsif Is_Safe_Activation (Call, Task_Rep) then
-- Note that the task body must still be examined for any nested
-- scenarios.
null;
-- The activation call and the task body are both in the main unit
--
-- If the root scenario appears prior to the task body, then this is
-- a possible ABE with respect to the root scenario.
--
-- task type Task_Typ;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- package Pack is
-- T : Task_Typ;
-- end Pack; -- activation of T
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
--
-- task body Task_Typ is -- task body
-- ...
-- end Task_Typ;
--
-- Y : ... := A; -- root scenario
--
-- IMPORTANT: The activation of T is a possible ABE for X, but
-- not for Y. Intalling an unconditional ABE raise prior to the
-- activation call would be wrong as it will fail for Y as well
-- but in Y's case the activation of T is never an ABE.
elsif Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
then
if Earlier_In_Extended_Unit (Root, Body_Decl) then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if New_In_State.Suppress_Warnings then
null;
-- Do not emit any ABE diagnostics when the activation occurs
-- in a partial finalization context because this action leads
-- to confusing noise.
elsif New_In_State.Within_Partial_Finalization then
null;
-- Otherwise emit the ABE disgnostic
else
Error_Msg_Sloc := Sloc (Call);
Error_Msg_N
("??task & will be activated # before elaboration of its "
& "body", Obj_Id);
Error_Msg_N
("\Program_Error may be raised at run time", Obj_Id);
Output_Active_Scenarios (Obj_Id, New_In_State);
end if;
-- Install a conditional run-time ABE check to verify that the
-- task body has been elaborated prior to the activation call.
if Check_OK then
Install_Scenario_ABE_Check
(N => Call,
Targ_Id => Defining_Entity (Spec_Decl),
Targ_Rep => Task_Rep,
Disable => Obj_Rep);
-- Update the state of the Processing phase to indicate that
-- no implicit Elaborate[_All] pragma must be generated from
-- this point on.
--
-- task type Task_Typ;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- package Pack is
-- <ABE check>
-- T : Task_Typ;
-- end Pack; -- activation of T
-- ...
-- end A;
--
-- X : ... := A;
--
-- task body Task_Typ is
-- begin
-- External.Subp; -- imparts Elaborate_All
-- end Task_Typ;
--
-- If Some_Condition is True, then the ABE check will fail
-- at runtime and the call to External.Subp will never take
-- place, rendering the implicit Elaborate_All useless.
--
-- If the value of Some_Condition is False, then the call
-- to External.Subp will never take place, rendering the
-- implicit Elaborate_All useless.
New_In_State.Suppress_Implicit_Pragmas := True;
end if;
end if;
-- Otherwise the task body is not available in this compilation or
-- it resides in an external unit. Install a run-time ABE check to
-- verify that the task body has been elaborated prior to the
-- activation call when the dynamic model is in effect.
elsif Check_OK
and then New_In_State.Processing = Dynamic_Model_Processing
then
Install_Unit_ABE_Check
(N => Call,
Unit_Id => Unit_Id,
Disable => Obj_Rep);
end if;
-- Both the activation call and task type are subject to SPARK_Mode
-- On, this triggers the SPARK rules for task activation. Compared
-- to calls and instantiations, task activation in SPARK does not
-- require the presence of Elaborate[_All] pragmas in case the task
-- type is defined outside the main unit. This is because SPARK uses
-- a special policy which activates all tasks after the main unit has
-- finished its elaboration.
if SPARK_Mode_Of (Call_Rep) = Is_On
and then SPARK_Mode_Of (Task_Rep) = Is_On
then
null;
-- Otherwise the Ada rules are in effect. Ensure that the unit with
-- the task body is elaborated prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Call,
Unit_Id => Unit_Id,
Prag_Nam => Name_Elaborate_All,
In_State => New_In_State);
end if;
Traverse_Conditional_ABE_Body
(N => Body_Decl,
In_State => New_In_State);
end Process_Conditional_ABE_Activation;
----------------------------------
-- Process_Conditional_ABE_Call --
----------------------------------
procedure Process_Conditional_ABE_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
function In_Initialization_Context (N : Node_Id) return Boolean;
pragma Inline (In_Initialization_Context);
-- Determine whether arbitrary node N appears within a type init
-- proc, primitive [Deep_]Initialize, or a block created for
-- initialization purposes.
function Is_Partial_Finalization_Proc
(Subp_Id : Entity_Id) return Boolean;
pragma Inline (Is_Partial_Finalization_Proc);
-- Determine whether subprogram Subp_Id is a partial finalization
-- procedure.
-------------------------------
-- In_Initialization_Context --
-------------------------------
function In_Initialization_Context (N : Node_Id) return Boolean is
Par : Node_Id;
Spec_Id : Entity_Id;
begin
-- Climb the parent chain looking for initialization actions
Par := Parent (N);
while Present (Par) loop
-- A block may be part of the initialization actions of a
-- default initialized object.
if Nkind (Par) = N_Block_Statement
and then Is_Initialization_Block (Par)
then
return True;
-- A subprogram body may denote an initialization routine
elsif Nkind (Par) = N_Subprogram_Body then
Spec_Id := Unique_Defining_Entity (Par);
-- The current subprogram body denotes a type init proc or
-- primitive [Deep_]Initialize.
if Is_Init_Proc (Spec_Id)
or else Is_Controlled_Proc (Spec_Id, Name_Initialize)
or else Is_TSS (Spec_Id, TSS_Deep_Initialize)
then
return True;
end if;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Initialization_Context;
----------------------------------
-- Is_Partial_Finalization_Proc --
----------------------------------
function Is_Partial_Finalization_Proc
(Subp_Id : Entity_Id) return Boolean
is
begin
-- To qualify, the subprogram must denote a finalizer procedure
-- or primitive [Deep_]Finalize, and the call must appear within
-- an initialization context.
return
(Is_Controlled_Proc (Subp_Id, Name_Finalize)
or else Is_Finalizer_Proc (Subp_Id)
or else Is_TSS (Subp_Id, TSS_Deep_Finalize))
and then In_Initialization_Context (Call);
end Is_Partial_Finalization_Proc;
-- Local variables
Subp_Id : constant Entity_Id := Target (Call_Rep);
Subp_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Subp_Id, In_State);
Subp_Decl : constant Node_Id := Spec_Declaration (Subp_Rep);
SPARK_Rules_On : constant Boolean :=
SPARK_Mode_Of (Call_Rep) = Is_On
and then SPARK_Mode_Of (Subp_Rep) = Is_On;
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
-- Start of processing for Process_Conditional_ABE_Call
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not New_In_State.Suppress_Info_Messages
then
Info_Call
(Call => Call,
Subp_Id => Subp_Id,
Info_Msg => True,
In_SPARK => SPARK_Rules_On);
end if;
-- Check whether the invocation of an entry clashes with an existing
-- restriction. This check is relevant only when the processing was
-- started from some library-level scenario.
if Is_Protected_Entry (Subp_Id) then
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call);
elsif Is_Task_Entry (Subp_Id) then
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call);
-- Task entry calls are never processed because the entry being
-- invoked does not have a corresponding "body", it has a select.
return;
end if;
-- Nothing to do when the call invokes a target defined within an
-- instance and switch -gnatd_i (ignore activations and calls to
-- instances for elaboration) is in effect.
if Debug_Flag_Underscore_I
and then In_External_Instance
(N => Call,
Target_Decl => Subp_Decl)
then
return;
-- Nothing to do when the call is a guaranteed ABE
elsif Is_Known_Guaranteed_ABE (Call) then
return;
-- Nothing to do when the root scenario appears at the declaration
-- level and the target is in the same unit but outside this context.
--
-- function B ...; -- target declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- return B; -- call site
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- function B ... is
-- ...
-- end B;
--
-- In the example above, the context of X is the declarative region
-- of Proc. The "elaboration" of X may eventually reach B which is
-- defined outside of X's context. B is relevant only when Proc is
-- invoked, but this happens only by means of "normal" elaboration,
-- therefore B must not be considered if this is not the case.
elsif Is_Up_Level_Target
(Targ_Decl => Subp_Decl,
In_State => New_In_State)
then
return;
end if;
-- Warnings are suppressed when a prior scenario is already in that
-- mode, or the call or target have warnings suppressed. Update the
-- state of the Processing phase to reflect this.
New_In_State.Suppress_Warnings :=
New_In_State.Suppress_Warnings
or else not Elaboration_Warnings_OK (Call_Rep)
or else not Elaboration_Warnings_OK (Subp_Rep);
-- The call occurs in an initial condition context when a prior
-- scenario is already in that mode, or when the target is an
-- Initial_Condition procedure. Update the state of the Processing
-- phase to reflect this.
New_In_State.Within_Initial_Condition :=
New_In_State.Within_Initial_Condition
or else Is_Initial_Condition_Proc (Subp_Id);
-- The call occurs in a partial finalization context when a prior
-- scenario is already in that mode, or when the target denotes a
-- [Deep_]Finalize primitive or a finalizer within an initialization
-- context. Update the state of the Processing phase to reflect this.
New_In_State.Within_Partial_Finalization :=
New_In_State.Within_Partial_Finalization
or else Is_Partial_Finalization_Proc (Subp_Id);
-- The SPARK rules are in effect. Note that -gnatd.v (enforce SPARK
-- elaboration rules in SPARK code) is intentionally not taken into
-- account here because Process_Conditional_ABE_Call_SPARK has two
-- separate modes of operation.
if SPARK_Rules_On then
Process_Conditional_ABE_Call_SPARK
(Call => Call,
Call_Rep => Call_Rep,
Subp_Id => Subp_Id,
Subp_Rep => Subp_Rep,
In_State => New_In_State);
-- Otherwise the Ada rules are in effect
else
Process_Conditional_ABE_Call_Ada
(Call => Call,
Call_Rep => Call_Rep,
Subp_Id => Subp_Id,
Subp_Rep => Subp_Rep,
In_State => New_In_State);
end if;
-- Inspect the target body (and barried function) for other suitable
-- elaboration scenarios.
Traverse_Conditional_ABE_Body
(N => Barrier_Body_Declaration (Subp_Rep),
In_State => New_In_State);
Traverse_Conditional_ABE_Body
(N => Body_Declaration (Subp_Rep),
In_State => New_In_State);
end Process_Conditional_ABE_Call;
--------------------------------------
-- Process_Conditional_ABE_Call_Ada --
--------------------------------------
procedure Process_Conditional_ABE_Call_Ada
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
Root : constant Node_Id := Root_Scenario;
Unit_Id : constant Node_Id := Unit (Subp_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Call_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Subp_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Call_Rep)
and then Elaboration_Checks_OK (Subp_Rep);
-- A run-time ABE check may be installed only when both the call
-- and the target have active elaboration checks, and both are not
-- ignored Ghost constructs.
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
-- Nothing to do for an Ada dispatching call because there are no
-- ABE diagnostics for either models. ABE checks for the dynamic
-- model are handled by Install_Primitive_Elaboration_Check.
if Is_Dispatching_Call (Call_Rep) then
return;
-- Nothing to do when the call is ABE-safe
--
-- generic
-- function Gen ...;
--
-- function Gen ... is
-- begin
-- ...
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- function Inst is new Gen;
-- X : ... := Inst; -- safe call
-- ...
elsif Is_Safe_Call (Call, Subp_Id, Subp_Rep) then
return;
-- The call and the target body are both in the main unit
--
-- If the root scenario appears prior to the target body, then this
-- is a possible ABE with respect to the root scenario.
--
-- function B ...;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- return B; -- call site
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
--
-- function B ... is -- target body
-- ...
-- end B;
--
-- Y : ... := A; -- root scenario
--
-- IMPORTANT: The call to B from A is a possible ABE for X, but
-- not for Y. Installing an unconditional ABE raise prior to the
-- call to B would be wrong as it will fail for Y as well, but in
-- Y's case the call to B is never an ABE.
elsif Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
then
if Earlier_In_Extended_Unit (Root, Body_Decl) then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if New_In_State.Suppress_Warnings then
null;
-- Do not emit any ABE diagnostics when the call occurs in a
-- partial finalization context because this leads to confusing
-- noise.
elsif New_In_State.Within_Partial_Finalization then
null;
-- Otherwise emit the ABE diagnostic
else
Error_Msg_NE
("??cannot call & before body seen", Call, Subp_Id);
Error_Msg_N
("\Program_Error may be raised at run time", Call);
Output_Active_Scenarios (Call, New_In_State);
end if;
-- Install a conditional run-time ABE check to verify that the
-- target body has been elaborated prior to the call.
if Check_OK then
Install_Scenario_ABE_Check
(N => Call,
Targ_Id => Subp_Id,
Targ_Rep => Subp_Rep,
Disable => Call_Rep);
-- Update the state of the Processing phase to indicate that
-- no implicit Elaborate[_All] pragma must be generated from
-- this point on.
--
-- function B ...;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- <ABE check>
-- return B;
-- ...
-- end A;
--
-- X : ... := A;
--
-- function B ... is
-- External.Subp; -- imparts Elaborate_All
-- end B;
--
-- If Some_Condition is True, then the ABE check will fail
-- at runtime and the call to External.Subp will never take
-- place, rendering the implicit Elaborate_All useless.
--
-- If the value of Some_Condition is False, then the call
-- to External.Subp will never take place, rendering the
-- implicit Elaborate_All useless.
New_In_State.Suppress_Implicit_Pragmas := True;
end if;
end if;
-- Otherwise the target body is not available in this compilation or
-- it resides in an external unit. Install a run-time ABE check to
-- verify that the target body has been elaborated prior to the call
-- site when the dynamic model is in effect.
elsif Check_OK
and then New_In_State.Processing = Dynamic_Model_Processing
then
Install_Unit_ABE_Check
(N => Call,
Unit_Id => Unit_Id,
Disable => Call_Rep);
end if;
-- Ensure that the unit with the target body is elaborated prior to
-- the main unit. The implicit Elaborate[_All] is generated only when
-- the call has elaboration checks enabled. This behavior parallels
-- that of the old ABE mechanism.
if Elaboration_Checks_OK (Call_Rep) then
Ensure_Prior_Elaboration
(N => Call,
Unit_Id => Unit_Id,
Prag_Nam => Name_Elaborate_All,
In_State => New_In_State);
end if;
end Process_Conditional_ABE_Call_Ada;
----------------------------------------
-- Process_Conditional_ABE_Call_SPARK --
----------------------------------------
procedure Process_Conditional_ABE_Call_SPARK
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Call_Rep);
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
Region : Node_Id;
begin
-- Ensure that a suitable elaboration model is in effect for SPARK
-- rule verification.
Check_SPARK_Model_In_Effect;
-- The call and the target body are both in the main unit
if Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
and then Earlier_In_Extended_Unit (Call, Body_Decl)
then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if In_State.Suppress_Warnings then
null;
-- Do not emit any ABE diagnostics when the call occurs in an
-- initial condition context because this leads to incorrect
-- diagnostics.
elsif In_State.Within_Initial_Condition then
null;
-- Do not emit any ABE diagnostics when the call occurs in a
-- partial finalization context because this leads to confusing
-- noise.
elsif In_State.Within_Partial_Finalization then
null;
-- Ensure that a call that textually precedes the subprogram body
-- it invokes appears within the early call region of the body.
--
-- IMPORTANT: This check must always be performed even when switch
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not
-- specified because the static model cannot guarantee the absence
-- of elaboration issues when dispatching calls are involved.
else
Region := Find_Early_Call_Region (Body_Decl);
if Earlier_In_Extended_Unit (Call, Region) then
Error_Msg_NE
("call must appear within early call region of subprogram "
& "body & (SPARK RM 7.7(3))",
Call, Subp_Id);
Error_Msg_Sloc := Sloc (Region);
Error_Msg_N ("\region starts #", Call);
Error_Msg_Sloc := Sloc (Body_Decl);
Error_Msg_N ("\region ends #", Call);
Output_Active_Scenarios (Call, In_State);
end if;
end if;
end if;
-- A call to a source target or to a target which emulates Ada
-- or SPARK semantics imposes an Elaborate_All requirement on the
-- context of the main unit. Determine whether the context has a
-- pragma strong enough to meet the requirement.
--
-- IMPORTANT: This check must be performed only when switch -gnatd.v
-- (enforce SPARK elaboration rules in SPARK code) is active because
-- the static model can ensure the prior elaboration of the unit
-- which contains a body by installing an implicit Elaborate[_All]
-- pragma.
if Debug_Flag_Dot_V then
if Comes_From_Source (Subp_Id)
or else Is_Ada_Semantic_Target (Subp_Id)
or else Is_SPARK_Semantic_Target (Subp_Id)
then
Meet_Elaboration_Requirement
(N => Call,
Targ_Id => Subp_Id,
Req_Nam => Name_Elaborate_All,
In_State => In_State);
end if;
-- Otherwise ensure that the unit with the target body is elaborated
-- prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Call,
Unit_Id => Unit (Subp_Rep),
Prag_Nam => Name_Elaborate_All,
In_State => In_State);
end if;
end Process_Conditional_ABE_Call_SPARK;
-------------------------------------------
-- Process_Conditional_ABE_Instantiation --
-------------------------------------------
procedure Process_Conditional_ABE_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Gen_Id : constant Entity_Id := Target (Inst_Rep);
Gen_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Gen_Id, In_State);
SPARK_Rules_On : constant Boolean :=
SPARK_Mode_Of (Inst_Rep) = Is_On
and then SPARK_Mode_Of (Gen_Rep) = Is_On;
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not New_In_State.Suppress_Info_Messages
then
Info_Instantiation
(Inst => Inst,
Gen_Id => Gen_Id,
Info_Msg => True,
In_SPARK => SPARK_Rules_On);
end if;
-- Nothing to do when the instantiation is a guaranteed ABE
if Is_Known_Guaranteed_ABE (Inst) then
return;
-- Nothing to do when the root scenario appears at the declaration
-- level and the generic is in the same unit, but outside this
-- context.
--
-- generic
-- procedure Gen is ...; -- generic declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- procedure I is new Gen; -- instantiation site
-- ...
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- procedure Gen is
-- ...
-- end Gen;
--
-- In the example above, the context of X is the declarative region
-- of Proc. The "elaboration" of X may eventually reach Gen which
-- appears outside of X's context. Gen is relevant only when Proc is
-- invoked, but this happens only by means of "normal" elaboration,
-- therefore Gen must not be considered if this is not the case.
elsif Is_Up_Level_Target
(Targ_Decl => Spec_Declaration (Gen_Rep),
In_State => New_In_State)
then
return;
end if;
-- Warnings are suppressed when a prior scenario is already in that
-- mode, or when the instantiation has warnings suppressed. Update
-- the state of the processing phase to reflect this.
New_In_State.Suppress_Warnings :=
New_In_State.Suppress_Warnings
or else not Elaboration_Warnings_OK (Inst_Rep);
-- The SPARK rules are in effect
if SPARK_Rules_On then
Process_Conditional_ABE_Instantiation_SPARK
(Inst => Inst,
Inst_Rep => Inst_Rep,
Gen_Id => Gen_Id,
Gen_Rep => Gen_Rep,
In_State => New_In_State);
-- Otherwise the Ada rules are in effect, or SPARK code is allowed to
-- violate the SPARK rules.
else
Process_Conditional_ABE_Instantiation_Ada
(Inst => Inst,
Inst_Rep => Inst_Rep,
Gen_Id => Gen_Id,
Gen_Rep => Gen_Rep,
In_State => New_In_State);
end if;
end Process_Conditional_ABE_Instantiation;
-----------------------------------------------
-- Process_Conditional_ABE_Instantiation_Ada --
-----------------------------------------------
procedure Process_Conditional_ABE_Instantiation_Ada
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
Body_Decl : constant Node_Id := Body_Declaration (Gen_Rep);
Root : constant Node_Id := Root_Scenario;
Unit_Id : constant Entity_Id := Unit (Gen_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Inst_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Gen_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Inst_Rep)
and then Elaboration_Checks_OK (Gen_Rep);
-- A run-time ABE check may be installed only when both the instance
-- and the generic have active elaboration checks and both are not
-- ignored Ghost constructs.
New_In_State : Processing_In_State := In_State;
-- Each step of the Processing phase constitutes a new state
begin
-- Nothing to do when the instantiation is ABE-safe
--
-- generic
-- package Gen is
-- ...
-- end Gen;
--
-- package body Gen is
-- ...
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- package Inst is new Gen (ABE); -- safe instantiation
-- ...
if Is_Safe_Instantiation (Inst, Gen_Id, Gen_Rep) then
return;
-- The instantiation and the generic body are both in the main unit
--
-- If the root scenario appears prior to the generic body, then this
-- is a possible ABE with respect to the root scenario.
--
-- generic
-- package Gen is
-- ...
-- end Gen;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- package Inst is new Gen; -- instantiation site
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
--
-- package body Gen is -- generic body
-- ...
-- end Gen;
--
-- Y : ... := A; -- root scenario
--
-- IMPORTANT: The instantiation of Gen is a possible ABE for X,
-- but not for Y. Installing an unconditional ABE raise prior to
-- the instance site would be wrong as it will fail for Y as well,
-- but in Y's case the instantiation of Gen is never an ABE.
elsif Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
then
if Earlier_In_Extended_Unit (Root, Body_Decl) then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if New_In_State.Suppress_Warnings then
null;
-- Do not emit any ABE diagnostics when the instantiation
-- occurs in partial finalization context because this leads
-- to unwanted noise.
elsif New_In_State.Within_Partial_Finalization then
null;
-- Otherwise output the diagnostic
else
Error_Msg_NE
("??cannot instantiate & before body seen", Inst, Gen_Id);
Error_Msg_N
("\Program_Error may be raised at run time", Inst);
Output_Active_Scenarios (Inst, New_In_State);
end if;
-- Install a conditional run-time ABE check to verify that the
-- generic body has been elaborated prior to the instantiation.
if Check_OK then
Install_Scenario_ABE_Check
(N => Inst,
Targ_Id => Gen_Id,
Targ_Rep => Gen_Rep,
Disable => Inst_Rep);
-- Update the state of the Processing phase to indicate that
-- no implicit Elaborate[_All] pragma must be generated from
-- this point on.
--
-- generic
-- package Gen is
-- ...
-- end Gen;
--
-- function A ... is
-- begin
-- if Some_Condition then
-- <ABE check>
-- declare Inst is new Gen;
-- ...
-- end A;
--
-- X : ... := A;
--
-- package body Gen is
-- begin
-- External.Subp; -- imparts Elaborate_All
-- end Gen;
--
-- If Some_Condition is True, then the ABE check will fail
-- at runtime and the call to External.Subp will never take
-- place, rendering the implicit Elaborate_All useless.
--
-- If the value of Some_Condition is False, then the call
-- to External.Subp will never take place, rendering the
-- implicit Elaborate_All useless.
New_In_State.Suppress_Implicit_Pragmas := True;
end if;
end if;
-- Otherwise the generic body is not available in this compilation
-- or it resides in an external unit. Install a run-time ABE check
-- to verify that the generic body has been elaborated prior to the
-- instantiation when the dynamic model is in effect.
elsif Check_OK
and then New_In_State.Processing = Dynamic_Model_Processing
then
Install_Unit_ABE_Check
(N => Inst,
Unit_Id => Unit_Id,
Disable => Inst_Rep);
end if;
-- Ensure that the unit with the generic body is elaborated prior
-- to the main unit. No implicit pragma has to be generated if the
-- instantiation has elaboration checks suppressed. This behavior
-- parallels that of the old ABE mechanism.
if Elaboration_Checks_OK (Inst_Rep) then
Ensure_Prior_Elaboration
(N => Inst,
Unit_Id => Unit_Id,
Prag_Nam => Name_Elaborate,
In_State => New_In_State);
end if;
end Process_Conditional_ABE_Instantiation_Ada;
-------------------------------------------------
-- Process_Conditional_ABE_Instantiation_SPARK --
-------------------------------------------------
procedure Process_Conditional_ABE_Instantiation_SPARK
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Inst_Rep);
Req_Nam : Name_Id;
begin
-- Ensure that a suitable elaboration model is in effect for SPARK
-- rule verification.
Check_SPARK_Model_In_Effect;
-- A source instantiation imposes an Elaborate[_All] requirement
-- on the context of the main unit. Determine whether the context
-- has a pragma strong enough to meet the requirement. The check
-- is orthogonal to the ABE ramifications of the instantiation.
--
-- IMPORTANT: This check must be performed only when switch -gnatd.v
-- (enforce SPARK elaboration rules in SPARK code) is active because
-- the static model can ensure the prior elaboration of the unit
-- which contains a body by installing an implicit Elaborate[_All]
-- pragma.
if Debug_Flag_Dot_V then
if Nkind (Inst) = N_Package_Instantiation then
Req_Nam := Name_Elaborate_All;
else
Req_Nam := Name_Elaborate;
end if;
Meet_Elaboration_Requirement
(N => Inst,
Targ_Id => Gen_Id,
Req_Nam => Req_Nam,
In_State => In_State);
-- Otherwise ensure that the unit with the target body is elaborated
-- prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Inst,
Unit_Id => Unit (Gen_Rep),
Prag_Nam => Name_Elaborate,
In_State => In_State);
end if;
end Process_Conditional_ABE_Instantiation_SPARK;
-------------------------------------------------
-- Process_Conditional_ABE_Variable_Assignment --
-------------------------------------------------
procedure Process_Conditional_ABE_Variable_Assignment
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Var_Id : constant Entity_Id := Target (Asmt_Rep);
Var_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Var_Id, In_State);
SPARK_Rules_On : constant Boolean :=
SPARK_Mode_Of (Asmt_Rep) = Is_On
and then SPARK_Mode_Of (Var_Rep) = Is_On;
begin
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
Elab_Msg_NE
(Msg => "assignment to & during elaboration",
N => Asmt,
Id => Var_Id,
Info_Msg => True,
In_SPARK => SPARK_Rules_On);
end if;
-- The SPARK rules are in effect. These rules are applied regardless
-- of whether switch -gnatd.v (enforce SPARK elaboration rules in
-- SPARK code) is in effect because the static model cannot ensure
-- safe assignment of variables.
if SPARK_Rules_On then
Process_Conditional_ABE_Variable_Assignment_SPARK
(Asmt => Asmt,
Asmt_Rep => Asmt_Rep,
Var_Id => Var_Id,
Var_Rep => Var_Rep,
In_State => In_State);
-- Otherwise the Ada rules are in effect
else
Process_Conditional_ABE_Variable_Assignment_Ada
(Asmt => Asmt,
Asmt_Rep => Asmt_Rep,
Var_Id => Var_Id,
Var_Rep => Var_Rep,
In_State => In_State);
end if;
end Process_Conditional_ABE_Variable_Assignment;
-----------------------------------------------------
-- Process_Conditional_ABE_Variable_Assignment_Ada --
-----------------------------------------------------
procedure Process_Conditional_ABE_Variable_Assignment_Ada
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Var_Id : Entity_Id;
Var_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Asmt_Rep);
Var_Decl : constant Node_Id := Variable_Declaration (Var_Rep);
Unit_Id : constant Entity_Id := Unit (Var_Rep);
begin
-- Emit a warning when an uninitialized variable declared in a
-- package spec without a pragma Elaborate_Body is initialized
-- by elaboration code within the corresponding body.
if Is_Elaboration_Warnings_OK_Id (Var_Id)
and then not Is_Initialized (Var_Decl)
and then not Has_Pragma_Elaborate_Body (Unit_Id)
then
-- Do not emit any ABE diagnostics when a previous scenario in
-- this traversal has suppressed elaboration warnings.
if not In_State.Suppress_Warnings then
Error_Msg_NE
("??variable & can be accessed by clients before this "
& "initialization", Asmt, Var_Id);
Error_Msg_NE
("\add pragma ""Elaborate_Body"" to spec & to ensure proper "
& "initialization", Asmt, Unit_Id);
Output_Active_Scenarios (Asmt, In_State);
end if;
-- Generate an implicit Elaborate_Body in the spec
Set_Elaborate_Body_Desirable (Unit_Id);
end if;
end Process_Conditional_ABE_Variable_Assignment_Ada;
-------------------------------------------------------
-- Process_Conditional_ABE_Variable_Assignment_SPARK --
-------------------------------------------------------
procedure Process_Conditional_ABE_Variable_Assignment_SPARK
(Asmt : Node_Id;
Asmt_Rep : Scenario_Rep_Id;
Var_Id : Entity_Id;
Var_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Asmt_Rep);
Var_Decl : constant Node_Id := Variable_Declaration (Var_Rep);
Unit_Id : constant Entity_Id := Unit (Var_Rep);
begin
-- Ensure that a suitable elaboration model is in effect for SPARK
-- rule verification.
Check_SPARK_Model_In_Effect;
-- Do not emit any ABE diagnostics when a previous scenario in this
-- traversal has suppressed elaboration warnings.
if In_State.Suppress_Warnings then
null;
-- Emit an error when an initialized variable declared in a package
-- spec that is missing pragma Elaborate_Body is further modified by
-- elaboration code within the corresponding body.
elsif Is_Elaboration_Warnings_OK_Id (Var_Id)
and then Is_Initialized (Var_Decl)
and then not Has_Pragma_Elaborate_Body (Unit_Id)
then
Error_Msg_NE
("variable & modified by elaboration code in package body",
Asmt, Var_Id);
Error_Msg_NE
("\add pragma ""Elaborate_Body"" to spec & to ensure full "
& "initialization", Asmt, Unit_Id);
Output_Active_Scenarios (Asmt, In_State);
end if;
end Process_Conditional_ABE_Variable_Assignment_SPARK;
------------------------------------------------
-- Process_Conditional_ABE_Variable_Reference --
------------------------------------------------
procedure Process_Conditional_ABE_Variable_Reference
(Ref : Node_Id;
Ref_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Var_Id : constant Entity_Id := Target (Ref);
Var_Rep : Target_Rep_Id;
Unit_Id : Entity_Id;
begin
-- Nothing to do when the variable reference is not a read
if not Is_Read_Reference (Ref_Rep) then
return;
end if;
Var_Rep := Target_Representation_Of (Var_Id, In_State);
Unit_Id := Unit (Var_Rep);
-- Output relevant information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas) is in effect.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
Elab_Msg_NE
(Msg => "read of variable & during elaboration",
N => Ref,
Id => Var_Id,
Info_Msg => True,
In_SPARK => True);
end if;
-- Nothing to do when the variable appears within the main unit
-- because diagnostics on reads are relevant only for external
-- variables.
if Is_Same_Unit (Unit_Id, Main_Unit_Entity) then
null;
-- Nothing to do when the variable is already initialized. Note that
-- the variable may be further modified by the external unit.
elsif Is_Initialized (Variable_Declaration (Var_Rep)) then
null;
-- Nothing to do when the external unit guarantees the initialization
-- of the variable by means of pragma Elaborate_Body.
elsif Has_Pragma_Elaborate_Body (Unit_Id) then
null;
-- A variable read imposes an Elaborate requirement on the context of
-- the main unit. Determine whether the context has a pragma strong
-- enough to meet the requirement.
else
Meet_Elaboration_Requirement
(N => Ref,
Targ_Id => Var_Id,
Req_Nam => Name_Elaborate,
In_State => In_State);
end if;
end Process_Conditional_ABE_Variable_Reference;
-----------------------------------
-- Traverse_Conditional_ABE_Body --
-----------------------------------
procedure Traverse_Conditional_ABE_Body
(N : Node_Id;
In_State : Processing_In_State)
is
begin
Traverse_Body
(N => N,
Requires_Processing => Is_Conditional_ABE_Scenario'Access,
Processor => Process_Conditional_ABE'Access,
In_State => In_State);
end Traverse_Conditional_ABE_Body;
end Conditional_ABE_Processor;
-------------
-- Destroy --
-------------
procedure Destroy (NE : in out Node_Or_Entity_Id) is
pragma Unreferenced (NE);
begin
null;
end Destroy;
-----------------
-- Diagnostics --
-----------------
package body Diagnostics is
-----------------
-- Elab_Msg_NE --
-----------------
procedure Elab_Msg_NE
(Msg : String;
N : Node_Id;
Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean)
is
function Prefix return String;
pragma Inline (Prefix);
-- Obtain the prefix of the message
function Suffix return String;
pragma Inline (Suffix);
-- Obtain the suffix of the message
------------
-- Prefix --
------------
function Prefix return String is
begin
if Info_Msg then
return "info: ";
else
return "";
end if;
end Prefix;
------------
-- Suffix --
------------
function Suffix return String is
begin
if In_SPARK then
return " in SPARK";
else
return "";
end if;
end Suffix;
-- Start of processing for Elab_Msg_NE
begin
Error_Msg_NE (Prefix & Msg & Suffix, N, Id);
end Elab_Msg_NE;
---------------
-- Info_Call --
---------------
procedure Info_Call
(Call : Node_Id;
Subp_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean)
is
procedure Info_Accept_Alternative;
pragma Inline (Info_Accept_Alternative);
-- Output information concerning an accept alternative
procedure Info_Simple_Call;
pragma Inline (Info_Simple_Call);
-- Output information concerning the call
procedure Info_Type_Actions (Action : String);
pragma Inline (Info_Type_Actions);
-- Output information concerning action Action of a type
procedure Info_Verification_Call
(Pred : String;
Id : Entity_Id;
Id_Kind : String);
pragma Inline (Info_Verification_Call);
-- Output information concerning the verification of predicate Pred
-- applied to related entity Id with kind Id_Kind.
-----------------------------
-- Info_Accept_Alternative --
-----------------------------
procedure Info_Accept_Alternative is
Entry_Id : constant Entity_Id := Receiving_Entry (Subp_Id);
pragma Assert (Present (Entry_Id));
begin
Elab_Msg_NE
(Msg => "accept for entry & during elaboration",
N => Call,
Id => Entry_Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Accept_Alternative;
----------------------
-- Info_Simple_Call --
----------------------
procedure Info_Simple_Call is
begin
Elab_Msg_NE
(Msg => "call to & during elaboration",
N => Call,
Id => Subp_Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Simple_Call;
-----------------------
-- Info_Type_Actions --
-----------------------
procedure Info_Type_Actions (Action : String) is
Typ : constant Entity_Id := First_Formal_Type (Subp_Id);
pragma Assert (Present (Typ));
begin
Elab_Msg_NE
(Msg => Action & " actions for type & during elaboration",
N => Call,
Id => Typ,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Type_Actions;
----------------------------
-- Info_Verification_Call --
----------------------------
procedure Info_Verification_Call
(Pred : String;
Id : Entity_Id;
Id_Kind : String)
is
pragma Assert (Present (Id));
begin
Elab_Msg_NE
(Msg =>
"verification of " & Pred & " of " & Id_Kind & " & during "
& "elaboration",
N => Call,
Id => Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Verification_Call;
-- Start of processing for Info_Call
begin
-- Do not output anything for targets defined in internal units
-- because this creates noise.
if not In_Internal_Unit (Subp_Id) then
-- Accept alternative
if Is_Accept_Alternative_Proc (Subp_Id) then
Info_Accept_Alternative;
-- Adjustment
elsif Is_TSS (Subp_Id, TSS_Deep_Adjust) then
Info_Type_Actions ("adjustment");
-- Default_Initial_Condition
elsif Is_Default_Initial_Condition_Proc (Subp_Id) then
Info_Verification_Call
(Pred => "Default_Initial_Condition",
Id => First_Formal_Type (Subp_Id),
Id_Kind => "type");
-- Entries
elsif Is_Protected_Entry (Subp_Id) then
Info_Simple_Call;
-- Task entry calls are never processed because the entry being
-- invoked does not have a corresponding "body", it has a select.
elsif Is_Task_Entry (Subp_Id) then
null;
-- Finalization
elsif Is_TSS (Subp_Id, TSS_Deep_Finalize) then
Info_Type_Actions ("finalization");
-- Calls to _Finalizer procedures must not appear in the output
-- because this creates confusing noise.
elsif Is_Finalizer_Proc (Subp_Id) then
null;
-- Initial_Condition
elsif Is_Initial_Condition_Proc (Subp_Id) then
Info_Verification_Call
(Pred => "Initial_Condition",
Id => Find_Enclosing_Scope (Call),
Id_Kind => "package");
-- Initialization
elsif Is_Init_Proc (Subp_Id)
or else Is_TSS (Subp_Id, TSS_Deep_Initialize)
then
Info_Type_Actions ("initialization");
-- Invariant
elsif Is_Invariant_Proc (Subp_Id) then
Info_Verification_Call
(Pred => "invariants",
Id => First_Formal_Type (Subp_Id),
Id_Kind => "type");
-- Partial invariant calls must not appear in the output because
-- this creates confusing noise.
elsif Is_Partial_Invariant_Proc (Subp_Id) then
null;
-- _Postconditions
elsif Is_Postconditions_Proc (Subp_Id) then
Info_Verification_Call
(Pred => "postconditions",
Id => Find_Enclosing_Scope (Call),
Id_Kind => "subprogram");
-- Subprograms must come last because some of the previous cases
-- fall under this category.
elsif Ekind (Subp_Id) = E_Function then
Info_Simple_Call;
elsif Ekind (Subp_Id) = E_Procedure then
Info_Simple_Call;
else
pragma Assert (False);
return;
end if;
end if;
end Info_Call;
------------------------
-- Info_Instantiation --
------------------------
procedure Info_Instantiation
(Inst : Node_Id;
Gen_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean)
is
begin
Elab_Msg_NE
(Msg => "instantiation of & during elaboration",
N => Inst,
Id => Gen_Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end Info_Instantiation;
-----------------------------
-- Info_Variable_Reference --
-----------------------------
procedure Info_Variable_Reference
(Ref : Node_Id;
Var_Id : Entity_Id;
Info_Msg : Boolean;
In_SPARK : Boolean)
is
begin
if Is_Read (Ref) then
Elab_Msg_NE
(Msg => "read of variable & during elaboration",
N => Ref,
Id => Var_Id,
Info_Msg => Info_Msg,
In_SPARK => In_SPARK);
end if;
end Info_Variable_Reference;
end Diagnostics;
---------------------------------
-- Early_Call_Region_Processor --
---------------------------------
package body Early_Call_Region_Processor is
---------------------
-- Data structures --
---------------------
-- The following map relates early call regions to subprogram bodies
procedure Destroy (N : in out Node_Id);
-- Destroy node N
package ECR_Map is new Dynamic_Hash_Tables
(Key_Type => Entity_Id,
Value_Type => Node_Id,
No_Value => Empty,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => Destroy,
Hash => Hash);
Early_Call_Regions_Map : ECR_Map.Dynamic_Hash_Table := ECR_Map.Nil;
-----------------------
-- Local subprograms --
-----------------------
function Early_Call_Region (Body_Id : Entity_Id) return Node_Id;
pragma Inline (Early_Call_Region);
-- Obtain the early call region associated with entry or subprogram body
-- Body_Id.
procedure Set_Early_Call_Region (Body_Id : Entity_Id; Start : Node_Id);
pragma Inline (Set_Early_Call_Region);
-- Associate an early call region with begins at construct Start with
-- entry or subprogram body Body_Id.
-------------
-- Destroy --
-------------
procedure Destroy (N : in out Node_Id) is
pragma Unreferenced (N);
begin
null;
end Destroy;
-----------------------
-- Early_Call_Region --
-----------------------
function Early_Call_Region (Body_Id : Entity_Id) return Node_Id is
pragma Assert (Present (Body_Id));
begin
return ECR_Map.Get (Early_Call_Regions_Map, Body_Id);
end Early_Call_Region;
------------------------------------------
-- Finalize_Early_Call_Region_Processor --
------------------------------------------
procedure Finalize_Early_Call_Region_Processor is
begin
ECR_Map.Destroy (Early_Call_Regions_Map);
end Finalize_Early_Call_Region_Processor;
----------------------------
-- Find_Early_Call_Region --
----------------------------
function Find_Early_Call_Region
(Body_Decl : Node_Id;
Assume_Elab_Body : Boolean := False;
Skip_Memoization : Boolean := False) return Node_Id
is
-- NOTE: The routines within Find_Early_Call_Region are intentionally
-- unnested to avoid deep indentation of code.
ECR_Found : exception;
-- This exception is raised when the early call region has been found
Start : Node_Id := Empty;
-- The start of the early call region. This variable is updated by
-- the various nested routines. Due to the use of exceptions, the
-- variable must be global to the nested routines.
-- The algorithm implemented in this routine attempts to find the
-- early call region of a subprogram body by inspecting constructs
-- in reverse declarative order, while navigating the tree. The
-- algorithm consists of an Inspection phase and Advancement phase.
-- The pseudocode is as follows:
--
-- loop
-- inspection phase
-- advancement phase
-- end loop
--
-- The infinite loop is terminated by raising exception ECR_Found.
-- The algorithm utilizes two pointers, Curr and Start, to represent
-- the current construct to inspect and the start of the early call
-- region.
--
-- IMPORTANT: The algorithm must maintain the following invariant at
-- all time for it to function properly:
--
-- A nested construct is entered only when it contains suitable
-- constructs.
--
-- This guarantees that leaving a nested or encapsulating construct
-- functions properly.
--
-- The Inspection phase determines whether the current construct is
-- non-preelaborable, and if it is, the algorithm terminates.
--
-- The Advancement phase walks the tree in reverse declarative order,
-- while entering and leaving nested and encapsulating constructs. It
-- may also terminate the elaborithm. There are several special cases
-- of advancement.
--
-- 1) General case:
--
-- <construct 1>
-- ...
-- <construct N-1> <- Curr
-- <construct N> <- Start
-- <subprogram body>
--
-- In the general case, a declarative or statement list is traversed
-- in reverse order where Curr is the lead pointer, and Start is the
-- last preelaborable construct.
--
-- 2) Entering handled bodies
--
-- package body Nested is <- Curr (2.3)
-- <declarations> <- Curr (2.2)
-- begin
-- <statements> <- Curr (2.1)
-- end Nested;
-- <construct> <- Start
--
-- In this case, the algorithm enters a handled body by starting from
-- the last statement (2.1), or the last declaration (2.2), or the
-- body is consumed (2.3) because it is empty and thus preelaborable.
--
-- 3) Entering package declarations
--
-- package Nested is <- Curr (2.3)
-- <visible declarations> <- Curr (2.2)
-- private
-- <private declarations> <- Curr (2.1)
-- end Nested;
-- <construct> <- Start
--
-- In this case, the algorithm enters a package declaration by
-- starting from the last private declaration (2.1), the last visible
-- declaration (2.2), or the package is consumed (2.3) because it is
-- empty and thus preelaborable.
--
-- 4) Transitioning from list to list of the same construct
--
-- Certain constructs have two eligible lists. The algorithm must
-- thus transition from the second to the first list when the second
-- list is exhausted.
--
-- declare <- Curr (4.2)
-- <declarations> <- Curr (4.1)
-- begin
-- <statements> <- Start
-- end;
--
-- In this case, the algorithm has exhausted the second list (the
-- statements in the example above), and continues with the last
-- declaration (4.1) or the construct is consumed (4.2) because it
-- contains only preelaborable code.
--
-- 5) Transitioning from list to construct
--
-- tack body Task is <- Curr (5.1)
-- <- Curr (Empty)
-- <construct 1> <- Start
--
-- In this case, the algorithm has exhausted a list, Curr is Empty,
-- and the owner of the list is consumed (5.1).
--
-- 6) Transitioning from unit to unit
--
-- A package body with a spec subject to pragma Elaborate_Body
-- extends the possible range of the early call region to the package
-- spec.
--
-- package Pack is <- Curr (6.3)
-- pragma Elaborate_Body; <- Curr (6.2)
-- <visible declarations> <- Curr (6.2)
-- private
-- <private declarations> <- Curr (6.1)
-- end Pack;
--
-- package body Pack is <- Curr, Start
--
-- In this case, the algorithm has reached a package body compilation
-- unit whose spec is subject to pragma Elaborate_Body, or the caller
-- of the algorithm has specified this behavior. This transition is
-- equivalent to 3).
--
-- 7) Transitioning from unit to termination
--
-- Reaching a compilation unit always terminates the algorithm as
-- there are no more lists to examine. This must take case 6) into
-- account.
--
-- 8) Transitioning from subunit to stub
--
-- package body Pack is separate; <- Curr (8.1)
--
-- separate (...)
-- package body Pack is <- Curr, Start
--
-- Reaching a subunit continues the search from the corresponding
-- stub (8.1).
procedure Advance (Curr : in out Node_Id);
pragma Inline (Advance);
-- Update the Curr and Start pointers depending on their location
-- in the tree to the next eligible construct. This routine raises
-- ECR_Found.
procedure Enter_Handled_Body (Curr : in out Node_Id);
pragma Inline (Enter_Handled_Body);
-- Update the Curr and Start pointers to enter a nested handled body
-- if applicable. This routine raises ECR_Found.
procedure Enter_Package_Declaration (Curr : in out Node_Id);
pragma Inline (Enter_Package_Declaration);
-- Update the Curr and Start pointers to enter a nested package spec
-- if applicable. This routine raises ECR_Found.
function Find_ECR (N : Node_Id) return Node_Id;
pragma Inline (Find_ECR);
-- Find an early call region starting from arbitrary node N
function Has_Suitable_Construct (List : List_Id) return Boolean;
pragma Inline (Has_Suitable_Construct);
-- Determine whether list List contains a suitable construct for
-- inclusion into an early call region.
procedure Include (N : Node_Id; Curr : out Node_Id);
pragma Inline (Include);
-- Update the Curr and Start pointers to include arbitrary construct
-- N in the early call region. This routine raises ECR_Found.
function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean;
pragma Inline (Is_OK_Preelaborable_Construct);
-- Determine whether arbitrary node N denotes a preelaboration-safe
-- construct.
function Is_Suitable_Construct (N : Node_Id) return Boolean;
pragma Inline (Is_Suitable_Construct);
-- Determine whether arbitrary node N denotes a suitable construct
-- for inclusion into the early call region.
procedure Transition_Body_Declarations
(Bod : Node_Id;
Curr : out Node_Id);
pragma Inline (Transition_Body_Declarations);
-- Update the Curr and Start pointers when construct Bod denotes a
-- block statement or a suitable body. This routine raises ECR_Found.
procedure Transition_Handled_Statements
(HSS : Node_Id;
Curr : out Node_Id);
pragma Inline (Transition_Handled_Statements);
-- Update the Curr and Start pointers when node HSS denotes a handled
-- sequence of statements. This routine raises ECR_Found.
procedure Transition_Spec_Declarations
(Spec : Node_Id;
Curr : out Node_Id);
pragma Inline (Transition_Spec_Declarations);
-- Update the Curr and Start pointers when construct Spec denotes
-- a concurrent definition or a package spec. This routine raises
-- ECR_Found.
procedure Transition_Unit (Unit : Node_Id; Curr : out Node_Id);
pragma Inline (Transition_Unit);
-- Update the Curr and Start pointers when node Unit denotes a
-- potential compilation unit. This routine raises ECR_Found.
-------------
-- Advance --
-------------
procedure Advance (Curr : in out Node_Id) is
Context : Node_Id;
begin
-- Curr denotes one of the following cases upon entry into this
-- routine:
--
-- * Empty - There is no current construct when a declarative or
-- a statement list has been exhausted. This does not indicate
-- that the early call region has been computed as it is still
-- possible to transition to another list.
--
-- * Encapsulator - The current construct wraps declarations
-- and/or statements. This indicates that the early call
-- region may extend within the nested construct.
--
-- * Preelaborable - The current construct is preelaborable
-- because Find_ECR would not invoke Advance if this was not
-- the case.
-- The current construct is an encapsulator or is preelaborable
if Present (Curr) then
-- Enter encapsulators by inspecting their declarations and/or
-- statements.
if Nkind (Curr) in N_Block_Statement | N_Package_Body then
Enter_Handled_Body (Curr);
elsif Nkind (Curr) = N_Package_Declaration then
Enter_Package_Declaration (Curr);
-- Early call regions have a property which can be exploited to
-- optimize the algorithm.
--
-- <preceding subprogram body>
-- <preelaborable construct 1>
-- ...
-- <preelaborable construct N>
-- <initiating subprogram body>
--
-- If a traversal initiated from a subprogram body reaches a
-- preceding subprogram body, then both bodies share the same
-- early call region.
--
-- The property results in the following desirable effects:
--
-- * If the preceding body already has an early call region,
-- then the initiating body can reuse it. This minimizes the
-- amount of processing performed by the algorithm.
--
-- * If the preceding body lack an early call region, then the
-- algorithm can compute the early call region, and reuse it
-- for the initiating body. This processing performs the same
-- amount of work, but has the beneficial effect of computing
-- the early call regions of all preceding bodies.
elsif Nkind (Curr) in N_Entry_Body | N_Subprogram_Body then
Start :=
Find_Early_Call_Region
(Body_Decl => Curr,
Assume_Elab_Body => Assume_Elab_Body,
Skip_Memoization => Skip_Memoization);
raise ECR_Found;
-- Otherwise current construct is preelaborable. Unpdate the
-- early call region to include it.
else
Include (Curr, Curr);
end if;
-- Otherwise the current construct is missing, indicating that the
-- current list has been exhausted. Depending on the context of
-- the list, several transitions are possible.
else
-- The invariant of the algorithm ensures that Curr and Start
-- are at the same level of nesting at the point of transition.
-- The algorithm can determine which list the traversal came
-- from by examining Start.
Context := Parent (Start);
-- Attempt the following transitions:
--
-- private declarations -> visible declarations
-- private declarations -> upper level
-- private declarations -> terminate
-- visible declarations -> upper level
-- visible declarations -> terminate
if Nkind (Context) in N_Package_Specification
| N_Protected_Definition
| N_Task_Definition
then
Transition_Spec_Declarations (Context, Curr);
-- Attempt the following transitions:
--
-- statements -> declarations
-- statements -> upper level
-- statements -> corresponding package spec (Elab_Body)
-- statements -> terminate
elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
Transition_Handled_Statements (Context, Curr);
-- Attempt the following transitions:
--
-- declarations -> upper level
-- declarations -> corresponding package spec (Elab_Body)
-- declarations -> terminate
elsif Nkind (Context) in N_Block_Statement
| N_Entry_Body
| N_Package_Body
| N_Protected_Body
| N_Subprogram_Body
| N_Task_Body
then
Transition_Body_Declarations (Context, Curr);
-- Otherwise it is not possible to transition. Stop the search
-- because there are no more declarations or statements to
-- check.
else
raise ECR_Found;
end if;
end if;
end Advance;
--------------------------
-- Enter_Handled_Body --
--------------------------
procedure Enter_Handled_Body (Curr : in out Node_Id) is
Decls : constant List_Id := Declarations (Curr);
HSS : constant Node_Id := Handled_Statement_Sequence (Curr);
Stmts : List_Id := No_List;
begin
if Present (HSS) then
Stmts := Statements (HSS);
end if;
-- The handled body has a non-empty statement sequence. The
-- construct to inspect is the last statement.
if Has_Suitable_Construct (Stmts) then
Curr := Last (Stmts);
-- The handled body lacks statements, but has non-empty
-- declarations. The construct to inspect is the last declaration.
elsif Has_Suitable_Construct (Decls) then
Curr := Last (Decls);
-- Otherwise the handled body lacks both declarations and
-- statements. The construct to inspect is the node which precedes
-- the handled body. Update the early call region to include the
-- handled body.
else
Include (Curr, Curr);
end if;
end Enter_Handled_Body;
-------------------------------
-- Enter_Package_Declaration --
-------------------------------
procedure Enter_Package_Declaration (Curr : in out Node_Id) is
Pack_Spec : constant Node_Id := Specification (Curr);
Prv_Decls : constant List_Id := Private_Declarations (Pack_Spec);
Vis_Decls : constant List_Id := Visible_Declarations (Pack_Spec);
begin
-- The package has a non-empty private declarations. The construct
-- to inspect is the last private declaration.
if Has_Suitable_Construct (Prv_Decls) then
Curr := Last (Prv_Decls);
-- The package lacks private declarations, but has non-empty
-- visible declarations. In this case the construct to inspect
-- is the last visible declaration.
elsif Has_Suitable_Construct (Vis_Decls) then
Curr := Last (Vis_Decls);
-- Otherwise the package lacks any declarations. The construct
-- to inspect is the node which precedes the package. Update the
-- early call region to include the package declaration.
else
Include (Curr, Curr);
end if;
end Enter_Package_Declaration;
--------------
-- Find_ECR --
--------------
function Find_ECR (N : Node_Id) return Node_Id is
Curr : Node_Id;
begin
-- The early call region starts at N
Curr := Prev (N);
Start := N;
-- Inspect each node in reverse declarative order while going in
-- and out of nested and enclosing constructs. Note that the only
-- way to terminate this infinite loop is to raise ECR_Found.
loop
-- The current construct is not preelaboration-safe. Terminate
-- the traversal.
if Present (Curr)
and then not Is_OK_Preelaborable_Construct (Curr)
then
raise ECR_Found;
end if;
-- Advance to the next suitable construct. This may terminate
-- the traversal by raising ECR_Found.
Advance (Curr);
end loop;
exception
when ECR_Found =>
return Start;
end Find_ECR;
----------------------------
-- Has_Suitable_Construct --
----------------------------
function Has_Suitable_Construct (List : List_Id) return Boolean is
Item : Node_Id;
begin
-- Examine the list in reverse declarative order, looking for a
-- suitable construct.
if Present (List) then
Item := Last (List);
while Present (Item) loop
if Is_Suitable_Construct (Item) then
return True;
end if;
Prev (Item);
end loop;
end if;
return False;
end Has_Suitable_Construct;
-------------
-- Include --
-------------
procedure Include (N : Node_Id; Curr : out Node_Id) is
begin
Start := N;
-- The input node is a compilation unit. This terminates the
-- search because there are no more lists to inspect and there are
-- no more enclosing constructs to climb up to. The transitions
-- are:
--
-- private declarations -> terminate
-- visible declarations -> terminate
-- statements -> terminate
-- declarations -> terminate
if Nkind (Parent (Start)) = N_Compilation_Unit then
raise ECR_Found;
-- Otherwise the input node is still within some list
else
Curr := Prev (Start);
end if;
end Include;
-----------------------------------
-- Is_OK_Preelaborable_Construct --
-----------------------------------
function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean is
begin
-- Assignment statements are acceptable as long as they were
-- produced by the ABE mechanism to update elaboration flags.
if Nkind (N) = N_Assignment_Statement then
return Is_Elaboration_Code (N);
-- Block statements are acceptable even though they directly
-- violate preelaborability. The intention is not to penalize
-- the early call region when a block contains only preelaborable
-- constructs.
--
-- declare
-- Val : constant Integer := 1;
-- begin
-- pragma Assert (Val = 1);
-- null;
-- end;
--
-- Note that the Advancement phase does enter blocks, and will
-- detect any non-preelaborable declarations or statements within.
elsif Nkind (N) = N_Block_Statement then
return True;
end if;
-- Otherwise the construct must be preelaborable. The check must
-- take the syntactic and semantic structure of the construct. DO
-- NOT use Is_Preelaborable_Construct here.
return not Is_Non_Preelaborable_Construct (N);
end Is_OK_Preelaborable_Construct;
---------------------------
-- Is_Suitable_Construct --
---------------------------
function Is_Suitable_Construct (N : Node_Id) return Boolean is
Context : constant Node_Id := Parent (N);
begin
-- An internally-generated statement sequence which contains only
-- a single null statement is not a suitable construct because it
-- is a byproduct of the parser. Such a null statement should be
-- excluded from the early call region because it carries the
-- source location of the "end" keyword, and may lead to confusing
-- diagnistics.
if Nkind (N) = N_Null_Statement
and then not Comes_From_Source (N)
and then Present (Context)
and then Nkind (Context) = N_Handled_Sequence_Of_Statements
then
return False;
end if;
-- Otherwise only constructs which correspond to pure Ada
-- constructs are considered suitable.
case Nkind (N) is
when N_Call_Marker
| N_Freeze_Entity
| N_Freeze_Generic_Entity
| N_Implicit_Label_Declaration
| N_Itype_Reference
| N_Pop_Constraint_Error_Label
| N_Pop_Program_Error_Label
| N_Pop_Storage_Error_Label
| N_Push_Constraint_Error_Label
| N_Push_Program_Error_Label
| N_Push_Storage_Error_Label
| N_SCIL_Dispatch_Table_Tag_Init
| N_SCIL_Dispatching_Call
| N_SCIL_Membership_Test
| N_Variable_Reference_Marker
=>
return False;
when others =>
return True;
end case;
end Is_Suitable_Construct;
----------------------------------
-- Transition_Body_Declarations --
----------------------------------
procedure Transition_Body_Declarations
(Bod : Node_Id;
Curr : out Node_Id)
is
Decls : constant List_Id := Declarations (Bod);
begin
-- The search must come from the declarations of the body
pragma Assert
(Is_Non_Empty_List (Decls)
and then List_Containing (Start) = Decls);
-- The search finished inspecting the declarations. The construct
-- to inspect is the node which precedes the handled body, unless
-- the body is a compilation unit. The transitions are:
--
-- declarations -> upper level
-- declarations -> corresponding package spec (Elab_Body)
-- declarations -> terminate
Transition_Unit (Bod, Curr);
end Transition_Body_Declarations;
-----------------------------------
-- Transition_Handled_Statements --
-----------------------------------
procedure Transition_Handled_Statements
(HSS : Node_Id;
Curr : out Node_Id)
is
Bod : constant Node_Id := Parent (HSS);
Decls : constant List_Id := Declarations (Bod);
Stmts : constant List_Id := Statements (HSS);
begin
-- The search must come from the statements of certain bodies or
-- statements.
pragma Assert
(Nkind (Bod) in
N_Block_Statement |
N_Entry_Body |
N_Package_Body |
N_Protected_Body |
N_Subprogram_Body |
N_Task_Body);
-- The search must come from the statements of the handled
-- sequence.
pragma Assert
(Is_Non_Empty_List (Stmts)
and then List_Containing (Start) = Stmts);
-- The search finished inspecting the statements. The handled body
-- has non-empty declarations. The construct to inspect is the
-- last declaration. The transitions are:
--
-- statements -> declarations
if Has_Suitable_Construct (Decls) then
Curr := Last (Decls);
-- Otherwise the handled body lacks declarations. The construct to
-- inspect is the node which precedes the handled body, unless the
-- body is a compilation unit. The transitions are:
--
-- statements -> upper level
-- statements -> corresponding package spec (Elab_Body)
-- statements -> terminate
else
Transition_Unit (Bod, Curr);
end if;
end Transition_Handled_Statements;
----------------------------------
-- Transition_Spec_Declarations --
----------------------------------
procedure Transition_Spec_Declarations
(Spec : Node_Id;
Curr : out Node_Id)
is
Prv_Decls : constant List_Id := Private_Declarations (Spec);
Vis_Decls : constant List_Id := Visible_Declarations (Spec);
begin
pragma Assert (Present (Start) and then Is_List_Member (Start));
-- The search came from the private declarations and finished
-- their inspection.
if Has_Suitable_Construct (Prv_Decls)
and then List_Containing (Start) = Prv_Decls
then
-- The context has non-empty visible declarations. The node to
-- inspect is the last visible declaration. The transitions
-- are:
--
-- private declarations -> visible declarations
if Has_Suitable_Construct (Vis_Decls) then
Curr := Last (Vis_Decls);
-- Otherwise the context lacks visible declarations. The
-- construct to inspect is the node which precedes the context
-- unless the context is a compilation unit. The transitions
-- are:
--
-- private declarations -> upper level
-- private declarations -> terminate
else
Transition_Unit (Parent (Spec), Curr);
end if;
-- The search came from the visible declarations and finished
-- their inspections. The construct to inspect is the node which
-- precedes the context, unless the context is a compilaton unit.
-- The transitions are:
--
-- visible declarations -> upper level
-- visible declarations -> terminate
elsif Has_Suitable_Construct (Vis_Decls)
and then List_Containing (Start) = Vis_Decls
then
Transition_Unit (Parent (Spec), Curr);
-- At this point both declarative lists are empty, but the
-- traversal still came from within the spec. This indicates
-- that the invariant of the algorithm has been violated.
else
pragma Assert (False);
raise ECR_Found;
end if;
end Transition_Spec_Declarations;
---------------------
-- Transition_Unit --
---------------------
procedure Transition_Unit
(Unit : Node_Id;
Curr : out Node_Id)
is
Context : constant Node_Id := Parent (Unit);
begin
-- The unit is a compilation unit. This terminates the search
-- because there are no more lists to inspect and there are no
-- more enclosing constructs to climb up to.
if Nkind (Context) = N_Compilation_Unit then
-- A package body with a corresponding spec subject to pragma
-- Elaborate_Body is an exception to the above. The annotation
-- allows the search to continue into the package declaration.
-- The transitions are:
--
-- statements -> corresponding package spec (Elab_Body)
-- declarations -> corresponding package spec (Elab_Body)
if Nkind (Unit) = N_Package_Body
and then (Assume_Elab_Body
or else Has_Pragma_Elaborate_Body
(Corresponding_Spec (Unit)))
then
Curr := Unit_Declaration_Node (Corresponding_Spec (Unit));
Enter_Package_Declaration (Curr);
-- Otherwise terminate the search. The transitions are:
--
-- private declarations -> terminate
-- visible declarations -> terminate
-- statements -> terminate
-- declarations -> terminate
else
raise ECR_Found;
end if;
-- The unit is a subunit. The construct to inspect is the node
-- which precedes the corresponding stub. Update the early call
-- region to include the unit.
elsif Nkind (Context) = N_Subunit then
Start := Unit;
Curr := Corresponding_Stub (Context);
-- Otherwise the unit is nested. The construct to inspect is the
-- node which precedes the unit. Update the early call region to
-- include the unit.
else
Include (Unit, Curr);
end if;
end Transition_Unit;
-- Local variables
Body_Id : constant Entity_Id := Unique_Defining_Entity (Body_Decl);
Region : Node_Id;
-- Start of processing for Find_Early_Call_Region
begin
-- The caller demands the start of the early call region without
-- saving or retrieving it to/from internal data structures.
if Skip_Memoization then
Region := Find_ECR (Body_Decl);
-- Default behavior
else
-- Check whether the early call region of the subprogram body is
-- available.
Region := Early_Call_Region (Body_Id);
if No (Region) then
Region := Find_ECR (Body_Decl);
-- Associate the early call region with the subprogram body in
-- case other scenarios need it.
Set_Early_Call_Region (Body_Id, Region);
end if;
end if;
-- A subprogram body must always have an early call region
pragma Assert (Present (Region));
return Region;
end Find_Early_Call_Region;
--------------------------------------------
-- Initialize_Early_Call_Region_Processor --
--------------------------------------------
procedure Initialize_Early_Call_Region_Processor is
begin
Early_Call_Regions_Map := ECR_Map.Create (100);
end Initialize_Early_Call_Region_Processor;
---------------------------
-- Set_Early_Call_Region --
---------------------------
procedure Set_Early_Call_Region (Body_Id : Entity_Id; Start : Node_Id) is
pragma Assert (Present (Body_Id));
pragma Assert (Present (Start));
begin
ECR_Map.Put (Early_Call_Regions_Map, Body_Id, Start);
end Set_Early_Call_Region;
end Early_Call_Region_Processor;
----------------------
-- Elaborated_Units --
----------------------
package body Elaborated_Units is
-----------
-- Types --
-----------
-- The following type idenfities the elaboration attributes of a unit
type Elaboration_Attributes_Id is new Natural;
No_Elaboration_Attributes : constant Elaboration_Attributes_Id :=
Elaboration_Attributes_Id'First;
First_Elaboration_Attributes : constant Elaboration_Attributes_Id :=
No_Elaboration_Attributes + 1;
-- The following type represents the elaboration attributes of a unit
type Elaboration_Attributes_Record is record
Elab_Pragma : Node_Id := Empty;
-- This attribute denotes a source Elaborate or Elaborate_All pragma
-- which guarantees the prior elaboration of some unit with respect
-- to the main unit. The pragma may come from the following contexts:
--
-- * The main unit
-- * The spec of the main unit (if applicable)
-- * Any parent spec of the main unit (if applicable)
-- * Any parent subunit of the main unit (if applicable)
--
-- The attribute remains Empty if no such pragma is available. Source
-- pragmas play a role in satisfying SPARK elaboration requirements.
With_Clause : Node_Id := Empty;
-- This attribute denotes an internally-generated or a source with
-- clause for some unit withed by the main unit. With clauses carry
-- flags which represent implicit Elaborate or Elaborate_All pragmas.
-- These clauses play a role in supplying elaboration dependencies to
-- binde.
end record;
---------------------
-- Data structures --
---------------------
-- The following table stores all elaboration attributes
package Elaboration_Attributes is new Table.Table
(Table_Index_Type => Elaboration_Attributes_Id,
Table_Component_Type => Elaboration_Attributes_Record,
Table_Low_Bound => First_Elaboration_Attributes,
Table_Initial => 250,
Table_Increment => 200,
Table_Name => "Elaboration_Attributes");
procedure Destroy (EA_Id : in out Elaboration_Attributes_Id);
-- Destroy elaboration attributes EA_Id
package UA_Map is new Dynamic_Hash_Tables
(Key_Type => Entity_Id,
Value_Type => Elaboration_Attributes_Id,
No_Value => No_Elaboration_Attributes,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => Destroy,
Hash => Hash);
-- The following map relates an elaboration attributes of a unit to the
-- unit.
Unit_To_Attributes_Map : UA_Map.Dynamic_Hash_Table := UA_Map.Nil;
------------------
-- Constructors --
------------------
function Elaboration_Attributes_Of
(Unit_Id : Entity_Id) return Elaboration_Attributes_Id;
pragma Inline (Elaboration_Attributes_Of);
-- Obtain the elaboration attributes of unit Unit_Id
-----------------------
-- Local subprograms --
-----------------------
function Elab_Pragma (EA_Id : Elaboration_Attributes_Id) return Node_Id;
pragma Inline (Elab_Pragma);
-- Obtain the Elaborate[_All] pragma of elaboration attributes EA_Id
procedure Ensure_Prior_Elaboration_Dynamic
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State);
pragma Inline (Ensure_Prior_Elaboration_Dynamic);
-- Guarantee the elaboration of unit Unit_Id with respect to the main
-- unit by suggesting the use of Elaborate[_All] with name Prag_Nam. N
-- denotes the related scenario. In_State is the current state of the
-- Processing phase.
procedure Ensure_Prior_Elaboration_Static
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State);
pragma Inline (Ensure_Prior_Elaboration_Static);
-- Guarantee the elaboration of unit Unit_Id with respect to the main
-- unit by installing an implicit Elaborate[_All] pragma with name
-- Prag_Nam. N denotes the related scenario. In_State is the current
-- state of the Processing phase.
function Present (EA_Id : Elaboration_Attributes_Id) return Boolean;
pragma Inline (Present);
-- Determine whether elaboration attributes UA_Id exist
procedure Set_Elab_Pragma
(EA_Id : Elaboration_Attributes_Id;
Prag : Node_Id);
pragma Inline (Set_Elab_Pragma);
-- Set the Elaborate[_All] pragma of elaboration attributes EA_Id to
-- Prag.
procedure Set_With_Clause
(EA_Id : Elaboration_Attributes_Id;
Clause : Node_Id);
pragma Inline (Set_With_Clause);
-- Set the with clause of elaboration attributes EA_Id to Clause
function With_Clause (EA_Id : Elaboration_Attributes_Id) return Node_Id;
pragma Inline (With_Clause);
-- Obtain the implicit or source with clause of elaboration attributes
-- EA_Id.
------------------------------
-- Collect_Elaborated_Units --
------------------------------
procedure Collect_Elaborated_Units is
procedure Add_Pragma (Prag : Node_Id);
pragma Inline (Add_Pragma);
-- Determine whether pragma Prag denotes a legal Elaborate[_All]
-- pragma. If this is the case, add the related unit to the context.
-- For pragma Elaborate_All, include recursively all units withed by
-- the related unit.
procedure Add_Unit
(Unit_Id : Entity_Id;
Prag : Node_Id;
Full_Context : Boolean);
pragma Inline (Add_Unit);
-- Add unit Unit_Id to the elaboration context. Prag denotes the
-- pragma which prompted the inclusion of the unit to the context.
-- If flag Full_Context is set, examine the nonlimited clauses of
-- unit Unit_Id and add each withed unit to the context.
procedure Find_Elaboration_Context (Comp_Unit : Node_Id);
pragma Inline (Find_Elaboration_Context);
-- Examine the context items of compilation unit Comp_Unit for
-- suitable elaboration-related pragmas and add all related units
-- to the context.
----------------
-- Add_Pragma --
----------------
procedure Add_Pragma (Prag : Node_Id) is
Prag_Args : constant List_Id :=
Pragma_Argument_Associations (Prag);
Prag_Nam : constant Name_Id := Pragma_Name (Prag);
Unit_Arg : Node_Id;
begin
-- Nothing to do if the pragma is not related to elaboration
if Prag_Nam not in Name_Elaborate | Name_Elaborate_All then
return;
-- Nothing to do when the pragma is illegal
elsif Error_Posted (Prag) then
return;
end if;
Unit_Arg := Get_Pragma_Arg (First (Prag_Args));
-- The argument of the pragma may appear in package.package form
if Nkind (Unit_Arg) = N_Selected_Component then
Unit_Arg := Selector_Name (Unit_Arg);
end if;
Add_Unit
(Unit_Id => Entity (Unit_Arg),
Prag => Prag,
Full_Context => Prag_Nam = Name_Elaborate_All);
end Add_Pragma;
--------------
-- Add_Unit --
--------------
procedure Add_Unit
(Unit_Id : Entity_Id;
Prag : Node_Id;
Full_Context : Boolean)
is
Clause : Node_Id;
EA_Id : Elaboration_Attributes_Id;
Unit_Prag : Node_Id;
begin
-- Nothing to do when some previous error left a with clause or a
-- pragma in a bad state.
if No (Unit_Id) then
return;
end if;
EA_Id := Elaboration_Attributes_Of (Unit_Id);
Unit_Prag := Elab_Pragma (EA_Id);
-- The unit is already included in the context by means of pragma
-- Elaborate[_All].
if Present (Unit_Prag) then
-- Upgrade an existing pragma Elaborate when the unit is
-- subject to Elaborate_All because the new pragma covers a
-- larger set of units.
if Pragma_Name (Unit_Prag) = Name_Elaborate
and then Pragma_Name (Prag) = Name_Elaborate_All
then
Set_Elab_Pragma (EA_Id, Prag);
-- Otherwise the unit retains its existing pragma and does not
-- need to be included in the context again.
else
return;
end if;
-- Otherwise the current unit is not included in the context
else
Set_Elab_Pragma (EA_Id, Prag);
end if;
-- Includes all units withed by the current one when computing the
-- full context.
if Full_Context then
-- Process all nonlimited with clauses found in the context of
-- the current unit. Note that limited clauses do not impose an
-- elaboration order.
Clause := First (Context_Items (Compilation_Unit (Unit_Id)));
while Present (Clause) loop
if Nkind (Clause) = N_With_Clause
and then not Error_Posted (Clause)
and then not Limited_Present (Clause)
then
Add_Unit
(Unit_Id => Entity (Name (Clause)),
Prag => Prag,
Full_Context => Full_Context);
end if;
Next (Clause);
end loop;
end if;
end Add_Unit;
------------------------------
-- Find_Elaboration_Context --
------------------------------
procedure Find_Elaboration_Context (Comp_Unit : Node_Id) is
pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit);
Prag : Node_Id;
begin
-- Process all elaboration-related pragmas found in the context of
-- the compilation unit.
Prag := First (Context_Items (Comp_Unit));
while Present (Prag) loop
if Nkind (Prag) = N_Pragma then
Add_Pragma (Prag);
end if;
Next (Prag);
end loop;
end Find_Elaboration_Context;
-- Local variables
Par_Id : Entity_Id;
Unit_Id : Node_Id;
-- Start of processing for Collect_Elaborated_Units
begin
-- Perform a traversal to examines the context of the main unit. The
-- traversal performs the following jumps:
--
-- subunit -> parent subunit
-- parent subunit -> body
-- body -> spec
-- spec -> parent spec
-- parent spec -> grandparent spec and so on
--
-- The traversal relies on units rather than scopes because the scope
-- of a subunit is some spec, while this traversal must process the
-- body as well. Given that protected and task bodies can also be
-- subunits, this complicates the scope approach even further.
Unit_Id := Unit (Cunit (Main_Unit));
-- Perform the following traversals when the main unit is a subunit
--
-- subunit -> parent subunit
-- parent subunit -> body
while Present (Unit_Id) and then Nkind (Unit_Id) = N_Subunit loop
Find_Elaboration_Context (Parent (Unit_Id));
-- Continue the traversal by going to the unit which contains the
-- corresponding stub.
if Present (Corresponding_Stub (Unit_Id)) then
Unit_Id :=
Unit (Cunit (Get_Source_Unit (Corresponding_Stub (Unit_Id))));
-- Otherwise the subunit may be erroneous or left in a bad state
else
exit;
end if;
end loop;
-- Perform the following traversal now that subunits have been taken
-- care of, or the main unit is a body.
--
-- body -> spec
if Present (Unit_Id)
and then Nkind (Unit_Id) in N_Package_Body | N_Subprogram_Body
then
Find_Elaboration_Context (Parent (Unit_Id));
-- Continue the traversal by going to the unit which contains the
-- corresponding spec.
if Present (Corresponding_Spec (Unit_Id)) then
Unit_Id :=
Unit (Cunit (Get_Source_Unit (Corresponding_Spec (Unit_Id))));
end if;
end if;
-- Perform the following traversals now that the body has been taken
-- care of, or the main unit is a spec.
--
-- spec -> parent spec
-- parent spec -> grandparent spec and so on
if Present (Unit_Id)
and then Nkind (Unit_Id) in N_Generic_Package_Declaration
| N_Generic_Subprogram_Declaration
| N_Package_Declaration
| N_Subprogram_Declaration
then
Find_Elaboration_Context (Parent (Unit_Id));
-- Process a potential chain of parent units which ends with the
-- main unit spec. The traversal can now safely rely on the scope
-- chain.
Par_Id := Scope (Defining_Entity (Unit_Id));
while Present (Par_Id) and then Par_Id /= Standard_Standard loop
Find_Elaboration_Context (Compilation_Unit (Par_Id));
Par_Id := Scope (Par_Id);
end loop;
end if;
end Collect_Elaborated_Units;
-------------
-- Destroy --
-------------
procedure Destroy (EA_Id : in out Elaboration_Attributes_Id) is
pragma Unreferenced (EA_Id);
begin
null;
end Destroy;
-----------------
-- Elab_Pragma --
-----------------
function Elab_Pragma
(EA_Id : Elaboration_Attributes_Id) return Node_Id
is
pragma Assert (Present (EA_Id));
begin
return Elaboration_Attributes.Table (EA_Id).Elab_Pragma;
end Elab_Pragma;
-------------------------------
-- Elaboration_Attributes_Of --
-------------------------------
function Elaboration_Attributes_Of
(Unit_Id : Entity_Id) return Elaboration_Attributes_Id
is
EA_Id : Elaboration_Attributes_Id;
begin
EA_Id := UA_Map.Get (Unit_To_Attributes_Map, Unit_Id);
-- The unit lacks elaboration attributes. This indicates that the
-- unit is encountered for the first time. Create the elaboration
-- attributes for it.
if not Present (EA_Id) then
Elaboration_Attributes.Append
((Elab_Pragma => Empty,
With_Clause => Empty));
EA_Id := Elaboration_Attributes.Last;
-- Associate the elaboration attributes with the unit
UA_Map.Put (Unit_To_Attributes_Map, Unit_Id, EA_Id);
end if;
pragma Assert (Present (EA_Id));
return EA_Id;
end Elaboration_Attributes_Of;
------------------------------
-- Ensure_Prior_Elaboration --
------------------------------
procedure Ensure_Prior_Elaboration
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State)
is
pragma Assert (Prag_Nam in Name_Elaborate | Name_Elaborate_All);
begin
-- Nothing to do when the need for prior elaboration came from a
-- partial finalization routine which occurs in an initialization
-- context. This behavior parallels that of the old ABE mechanism.
if In_State.Within_Partial_Finalization then
return;
-- Nothing to do when the need for prior elaboration came from a task
-- body and switch -gnatd.y (disable implicit pragma Elaborate_All on
-- task bodies) is in effect.
elsif Debug_Flag_Dot_Y and then In_State.Within_Task_Body then
return;
-- Nothing to do when the unit is elaborated prior to the main unit.
-- This check must also consider the following cases:
--
-- * No check is made against the context of the main unit because
-- this is specific to the elaboration model in effect and requires
-- custom handling (see Ensure_xxx_Prior_Elaboration).
--
-- * Unit_Id is subject to pragma Elaborate_Body. An implicit pragma
-- Elaborate[_All] MUST be generated even though Unit_Id is always
-- elaborated prior to the main unit. This conservative strategy
-- ensures that other units withed by Unit_Id will not lead to an
-- ABE.
--
-- package A is package body A is
-- procedure ABE; procedure ABE is ... end ABE;
-- end A; end A;
--
-- with A;
-- package B is package body B is
-- pragma Elaborate_Body; procedure Proc is
-- begin
-- procedure Proc; A.ABE;
-- package B; end Proc;
-- end B;
--
-- with B;
-- package C is package body C is
-- ... ...
-- end C; begin
-- B.Proc;
-- end C;
--
-- In the example above, the elaboration of C invokes B.Proc. B is
-- subject to pragma Elaborate_Body. If no pragma Elaborate[_All]
-- is gnerated for B in C, then the following elaboratio order will
-- lead to an ABE:
--
-- spec of A elaborated
-- spec of B elaborated
-- body of B elaborated
-- spec of C elaborated
-- body of C elaborated <-- calls B.Proc which calls A.ABE
-- body of A elaborated <-- problem
--
-- The generation of an implicit pragma Elaborate_All (B) ensures
-- that the elaboration-order mechanism will not pick the above
-- order.
--
-- An implicit Elaborate is NOT generated when the unit is subject
-- to Elaborate_Body because both pragmas have the same effect.
--
-- * Unit_Id is the main unit. An implicit pragma Elaborate[_All]
-- MUST NOT be generated in this case because a unit cannot depend
-- on its own elaboration. This case is therefore treated as valid
-- prior elaboration.
elsif Has_Prior_Elaboration
(Unit_Id => Unit_Id,
Same_Unit_OK => True,
Elab_Body_OK => Prag_Nam = Name_Elaborate)
then
return;
end if;
-- Suggest the use of pragma Prag_Nam when the dynamic model is in
-- effect.
if Dynamic_Elaboration_Checks then
Ensure_Prior_Elaboration_Dynamic
(N => N,
Unit_Id => Unit_Id,
Prag_Nam => Prag_Nam,
In_State => In_State);
-- Install an implicit pragma Prag_Nam when the static model is in
-- effect.
else
pragma Assert (Static_Elaboration_Checks);
Ensure_Prior_Elaboration_Static
(N => N,
Unit_Id => Unit_Id,
Prag_Nam => Prag_Nam,
In_State => In_State);
end if;
end Ensure_Prior_Elaboration;
--------------------------------------
-- Ensure_Prior_Elaboration_Dynamic --
--------------------------------------
procedure Ensure_Prior_Elaboration_Dynamic
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State)
is
procedure Info_Missing_Pragma;
pragma Inline (Info_Missing_Pragma);
-- Output information concerning missing Elaborate or Elaborate_All
-- pragma with name Prag_Nam for scenario N, which would ensure the
-- prior elaboration of Unit_Id.
-------------------------
-- Info_Missing_Pragma --
-------------------------
procedure Info_Missing_Pragma is
begin
-- Internal units are ignored as they cause unnecessary noise
if not In_Internal_Unit (Unit_Id) then
-- The name of the unit subjected to the elaboration pragma is
-- fully qualified to improve the clarity of the info message.
Error_Msg_Name_1 := Prag_Nam;
Error_Msg_Qual_Level := Nat'Last;
Error_Msg_NE ("info: missing pragma % for unit &", N, Unit_Id);
Error_Msg_Qual_Level := 0;
end if;
end Info_Missing_Pragma;
-- Local variables
EA_Id : constant Elaboration_Attributes_Id :=
Elaboration_Attributes_Of (Unit_Id);
N_Lvl : Enclosing_Level_Kind;
N_Rep : Scenario_Rep_Id;
-- Start of processing for Ensure_Prior_Elaboration_Dynamic
begin
-- Nothing to do when the unit is guaranteed prior elaboration by
-- means of a source Elaborate[_All] pragma.
if Present (Elab_Pragma (EA_Id)) then
return;
end if;
-- Output extra information on a missing Elaborate[_All] pragma when
-- switch -gnatel (info messages on implicit Elaborate[_All] pragmas
-- is in effect.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
N_Rep := Scenario_Representation_Of (N, In_State);
N_Lvl := Level (N_Rep);
-- Declaration-level scenario
if (Is_Suitable_Call (N) or else Is_Suitable_Instantiation (N))
and then N_Lvl = Declaration_Level
then
null;
-- Library-level scenario
elsif N_Lvl in Library_Level then
null;
-- Instantiation library-level scenario
elsif N_Lvl = Instantiation_Level then
null;
-- Otherwise the scenario does not appear at the proper level
else
return;
end if;
Info_Missing_Pragma;
end if;
end Ensure_Prior_Elaboration_Dynamic;
-------------------------------------
-- Ensure_Prior_Elaboration_Static --
-------------------------------------
procedure Ensure_Prior_Elaboration_Static
(N : Node_Id;
Unit_Id : Entity_Id;
Prag_Nam : Name_Id;
In_State : Processing_In_State)
is
function Find_With_Clause
(Items : List_Id;
Withed_Id : Entity_Id) return Node_Id;
pragma Inline (Find_With_Clause);
-- Find a nonlimited with clause in the list of context items Items
-- that withs unit Withed_Id. Return Empty if no such clause exists.
procedure Info_Implicit_Pragma;
pragma Inline (Info_Implicit_Pragma);
-- Output information concerning an implicitly generated Elaborate
-- or Elaborate_All pragma with name Prag_Nam for scenario N which
-- ensures the prior elaboration of unit Unit_Id.
----------------------
-- Find_With_Clause --
----------------------
function Find_With_Clause
(Items : List_Id;
Withed_Id : Entity_Id) return Node_Id
is
Item : Node_Id;
begin
-- Examine the context clauses looking for a suitable with. Note
-- that limited clauses do not affect the elaboration order.
Item := First (Items);
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Error_Posted (Item)
and then not Limited_Present (Item)
and then Entity (Name (Item)) = Withed_Id
then
return Item;
end if;
Next (Item);
end loop;
return Empty;
end Find_With_Clause;
--------------------------
-- Info_Implicit_Pragma --
--------------------------
procedure Info_Implicit_Pragma is
begin
-- Internal units are ignored as they cause unnecessary noise
if not In_Internal_Unit (Unit_Id) then
-- The name of the unit subjected to the elaboration pragma is
-- fully qualified to improve the clarity of the info message.
Error_Msg_Name_1 := Prag_Nam;
Error_Msg_Qual_Level := Nat'Last;
Error_Msg_NE
("info: implicit pragma % generated for unit &", N, Unit_Id);
Error_Msg_Qual_Level := 0;
Output_Active_Scenarios (N, In_State);
end if;
end Info_Implicit_Pragma;
-- Local variables
EA_Id : constant Elaboration_Attributes_Id :=
Elaboration_Attributes_Of (Unit_Id);
Main_Cunit : constant Node_Id := Cunit (Main_Unit);
Loc : constant Source_Ptr := Sloc (Main_Cunit);
Unit_Cunit : constant Node_Id := Compilation_Unit (Unit_Id);
Unit_Prag : constant Node_Id := Elab_Pragma (EA_Id);
Unit_With : constant Node_Id := With_Clause (EA_Id);
Clause : Node_Id;
Items : List_Id;
-- Start of processing for Ensure_Prior_Elaboration_Static
begin
-- Nothing to do when the caller has suppressed the generation of
-- implicit Elaborate[_All] pragmas.
if In_State.Suppress_Implicit_Pragmas then
return;
-- Nothing to do when the unit is guaranteed prior elaboration by
-- means of a source Elaborate[_All] pragma.
elsif Present (Unit_Prag) then
return;
-- Nothing to do when the unit has an existing implicit Elaborate or
-- Elaborate_All pragma installed by a previous scenario.
elsif Present (Unit_With) then
-- The unit is already guaranteed prior elaboration by means of an
-- implicit Elaborate pragma, however the current scenario imposes
-- a stronger requirement of Elaborate_All. "Upgrade" the existing
-- pragma to match this new requirement.
if Elaborate_Desirable (Unit_With)
and then Prag_Nam = Name_Elaborate_All
then
Set_Elaborate_All_Desirable (Unit_With);
Set_Elaborate_Desirable (Unit_With, False);
end if;
return;
end if;
-- At this point it is known that the unit has no prior elaboration
-- according to pragmas and hierarchical relationships.
Items := Context_Items (Main_Cunit);
if No (Items) then
Items := New_List;
Set_Context_Items (Main_Cunit, Items);
end if;
-- Locate the with clause for the unit. Note that there may not be a
-- clause if the unit is visible through a subunit-body, body-spec,
-- or spec-parent relationship.
Clause :=
Find_With_Clause
(Items => Items,
Withed_Id => Unit_Id);
-- Generate:
-- with Id;
-- Note that adding implicit with clauses is safe because analysis,
-- resolution, and expansion have already taken place and it is not
-- possible to interfere with visibility.
if No (Clause) then
Clause :=
Make_With_Clause (Loc,
Name => New_Occurrence_Of (Unit_Id, Loc));
Set_Implicit_With (Clause);
Set_Library_Unit (Clause, Unit_Cunit);
Append_To (Items, Clause);
end if;
-- Mark the with clause depending on the pragma required
if Prag_Nam = Name_Elaborate then
Set_Elaborate_Desirable (Clause);
else
Set_Elaborate_All_Desirable (Clause);
end if;
-- The implicit Elaborate[_All] ensures the prior elaboration of
-- the unit. Include the unit in the elaboration context of the
-- main unit.
Set_With_Clause (EA_Id, Clause);
-- Output extra information on an implicit Elaborate[_All] pragma
-- when switch -gnatel (info messages on implicit Elaborate[_All]
-- pragmas is in effect.
if Elab_Info_Messages then
Info_Implicit_Pragma;
end if;
end Ensure_Prior_Elaboration_Static;
-------------------------------
-- Finalize_Elaborated_Units --
-------------------------------
procedure Finalize_Elaborated_Units is
begin
UA_Map.Destroy (Unit_To_Attributes_Map);
end Finalize_Elaborated_Units;
---------------------------
-- Has_Prior_Elaboration --
---------------------------
function Has_Prior_Elaboration
(Unit_Id : Entity_Id;
Context_OK : Boolean := False;
Elab_Body_OK : Boolean := False;
Same_Unit_OK : Boolean := False) return Boolean
is
EA_Id : constant Elaboration_Attributes_Id :=
Elaboration_Attributes_Of (Unit_Id);
Main_Id : constant Entity_Id := Main_Unit_Entity;
Unit_Prag : constant Node_Id := Elab_Pragma (EA_Id);
Unit_With : constant Node_Id := With_Clause (EA_Id);
begin
-- A preelaborated unit is always elaborated prior to the main unit
if Is_Preelaborated_Unit (Unit_Id) then
return True;
-- An internal unit is always elaborated prior to a non-internal main
-- unit.
elsif In_Internal_Unit (Unit_Id)
and then not In_Internal_Unit (Main_Id)
then
return True;
-- A unit has prior elaboration if it appears within the context
-- of the main unit. Consider this case only when requested by the
-- caller.
elsif Context_OK
and then (Present (Unit_Prag) or else Present (Unit_With))
then
return True;
-- A unit whose body is elaborated together with its spec has prior
-- elaboration except with respect to itself. Consider this case only
-- when requested by the caller.
elsif Elab_Body_OK
and then Has_Pragma_Elaborate_Body (Unit_Id)
and then not Is_Same_Unit (Unit_Id, Main_Id)
then
return True;
-- A unit has no prior elaboration with respect to itself, but does
-- not require any means of ensuring its own elaboration either.
-- Treat this case as valid prior elaboration only when requested by
-- the caller.
elsif Same_Unit_OK and then Is_Same_Unit (Unit_Id, Main_Id) then
return True;
end if;
return False;
end Has_Prior_Elaboration;
---------------------------------
-- Initialize_Elaborated_Units --
---------------------------------
procedure Initialize_Elaborated_Units is
begin
Unit_To_Attributes_Map := UA_Map.Create (250);
end Initialize_Elaborated_Units;
----------------------------------
-- Meet_Elaboration_Requirement --
----------------------------------
procedure Meet_Elaboration_Requirement
(N : Node_Id;
Targ_Id : Entity_Id;
Req_Nam : Name_Id;
In_State : Processing_In_State)
is
pragma Assert (Req_Nam in Name_Elaborate | Name_Elaborate_All);
Main_Id : constant Entity_Id := Main_Unit_Entity;
Unit_Id : constant Entity_Id := Find_Top_Unit (Targ_Id);
procedure Elaboration_Requirement_Error;
pragma Inline (Elaboration_Requirement_Error);
-- Emit an error concerning scenario N which has failed to meet the
-- elaboration requirement.
function Find_Preelaboration_Pragma
(Prag_Nam : Name_Id) return Node_Id;
pragma Inline (Find_Preelaboration_Pragma);
-- Traverse the visible declarations of unit Unit_Id and locate a
-- source preelaboration-related pragma with name Prag_Nam.
procedure Info_Requirement_Met (Prag : Node_Id);
pragma Inline (Info_Requirement_Met);
-- Output information concerning pragma Prag which meets requirement
-- Req_Nam.
-----------------------------------
-- Elaboration_Requirement_Error --
-----------------------------------
procedure Elaboration_Requirement_Error is
begin
if Is_Suitable_Call (N) then
Info_Call
(Call => N,
Subp_Id => Targ_Id,
Info_Msg => False,
In_SPARK => True);
elsif Is_Suitable_Instantiation (N) then
Info_Instantiation
(Inst => N,
Gen_Id => Targ_Id,
Info_Msg => False,
In_SPARK => True);
elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
Error_Msg_N
("read of refinement constituents during elaboration in "
& "SPARK", N);
elsif Is_Suitable_Variable_Reference (N) then
Info_Variable_Reference
(Ref => N,
Var_Id => Targ_Id,
Info_Msg => False,
In_SPARK => True);
-- No other scenario may impose a requirement on the context of
-- the main unit.
else
pragma Assert (False);
return;
end if;
Error_Msg_Name_1 := Req_Nam;
Error_Msg_Node_2 := Unit_Id;
Error_Msg_NE ("\\unit & requires pragma % for &", N, Main_Id);
Output_Active_Scenarios (N, In_State);
end Elaboration_Requirement_Error;
--------------------------------
-- Find_Preelaboration_Pragma --
--------------------------------
function Find_Preelaboration_Pragma
(Prag_Nam : Name_Id) return Node_Id
is
Spec : constant Node_Id := Parent (Unit_Id);
Decl : Node_Id;
begin
-- A preelaboration-related pragma comes from source and appears
-- at the top of the visible declarations of a package.
if Nkind (Spec) = N_Package_Specification then
Decl := First (Visible_Declarations (Spec));
while Present (Decl) loop
if Comes_From_Source (Decl) then
if Nkind (Decl) = N_Pragma
and then Pragma_Name (Decl) = Prag_Nam
then
return Decl;
-- Otherwise the construct terminates the region where
-- the preelaboration-related pragma may appear.
else
exit;
end if;
end if;
Next (Decl);
end loop;
end if;
return Empty;
end Find_Preelaboration_Pragma;
--------------------------
-- Info_Requirement_Met --
--------------------------
procedure Info_Requirement_Met (Prag : Node_Id) is
pragma Assert (Present (Prag));
begin
Error_Msg_Name_1 := Req_Nam;
Error_Msg_Sloc := Sloc (Prag);
Error_Msg_NE
("\\% requirement for unit & met by pragma #", N, Unit_Id);
end Info_Requirement_Met;
-- Local variables
EA_Id : Elaboration_Attributes_Id;
Elab_Nam : Name_Id;
Req_Met : Boolean;
Unit_Prag : Node_Id;
-- Start of processing for Meet_Elaboration_Requirement
begin
-- Assume that the requirement has not been met
Req_Met := False;
-- If the target is within the main unit, either at the source level
-- or through an instantiation, then there is no real requirement to
-- meet because the main unit cannot force its own elaboration by
-- means of an Elaborate[_All] pragma. Treat this case as valid
-- coverage.
if In_Extended_Main_Code_Unit (Targ_Id) then
Req_Met := True;
-- Otherwise the target resides in an external unit
-- The requirement is met when the target comes from an internal unit
-- because such a unit is elaborated prior to a non-internal unit.
elsif In_Internal_Unit (Unit_Id)
and then not In_Internal_Unit (Main_Id)
then
Req_Met := True;
-- The requirement is met when the target comes from a preelaborated
-- unit. This portion must parallel predicate Is_Preelaborated_Unit.
elsif Is_Preelaborated_Unit (Unit_Id) then
Req_Met := True;
-- Output extra information when switch -gnatel (info messages on
-- implicit Elaborate[_All] pragmas.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
if Is_Preelaborated (Unit_Id) then
Elab_Nam := Name_Preelaborate;
elsif Is_Pure (Unit_Id) then
Elab_Nam := Name_Pure;
elsif Is_Remote_Call_Interface (Unit_Id) then
Elab_Nam := Name_Remote_Call_Interface;
elsif Is_Remote_Types (Unit_Id) then
Elab_Nam := Name_Remote_Types;
else
pragma Assert (Is_Shared_Passive (Unit_Id));
Elab_Nam := Name_Shared_Passive;
end if;
Info_Requirement_Met (Find_Preelaboration_Pragma (Elab_Nam));
end if;
-- Determine whether the context of the main unit has a pragma strong
-- enough to meet the requirement.
else
EA_Id := Elaboration_Attributes_Of (Unit_Id);
Unit_Prag := Elab_Pragma (EA_Id);
-- The pragma must be either Elaborate_All or be as strong as the
-- requirement.
if Present (Unit_Prag)
and then Pragma_Name (Unit_Prag) in Name_Elaborate_All | Req_Nam
then
Req_Met := True;
-- Output extra information when switch -gnatel (info messages
-- on implicit Elaborate[_All] pragmas.
if Elab_Info_Messages
and then not In_State.Suppress_Info_Messages
then
Info_Requirement_Met (Unit_Prag);
end if;
end if;
end if;
-- The requirement was not met by the context of the main unit, issue
-- an error.
if not Req_Met then
Elaboration_Requirement_Error;
end if;
end Meet_Elaboration_Requirement;
-------------
-- Present --
-------------
function Present (EA_Id : Elaboration_Attributes_Id) return Boolean is
begin
return EA_Id /= No_Elaboration_Attributes;
end Present;
---------------------
-- Set_Elab_Pragma --
---------------------
procedure Set_Elab_Pragma
(EA_Id : Elaboration_Attributes_Id;
Prag : Node_Id)
is
pragma Assert (Present (EA_Id));
begin
Elaboration_Attributes.Table (EA_Id).Elab_Pragma := Prag;
end Set_Elab_Pragma;
---------------------
-- Set_With_Clause --
---------------------
procedure Set_With_Clause
(EA_Id : Elaboration_Attributes_Id;
Clause : Node_Id)
is
pragma Assert (Present (EA_Id));
begin
Elaboration_Attributes.Table (EA_Id).With_Clause := Clause;
end Set_With_Clause;
-----------------
-- With_Clause --
-----------------
function With_Clause
(EA_Id : Elaboration_Attributes_Id) return Node_Id
is
pragma Assert (Present (EA_Id));
begin
return Elaboration_Attributes.Table (EA_Id).With_Clause;
end With_Clause;
end Elaborated_Units;
------------------------------
-- Elaboration_Phase_Active --
------------------------------
function Elaboration_Phase_Active return Boolean is
begin
return Elaboration_Phase = Active;
end Elaboration_Phase_Active;
------------------------------
-- Error_Preelaborated_Call --
------------------------------
procedure Error_Preelaborated_Call (N : Node_Id) is
begin
-- This is a warning in GNAT mode allowing such calls to be used in the
-- predefined library units with appropriate care.
Error_Msg_Warn := GNAT_Mode;
-- Ada 2020 (AI12-0175): Calls to certain functions that are essentially
-- unchecked conversions are preelaborable.
if Ada_Version >= Ada_2020 then
Error_Msg_N
("<<non-preelaborable call not allowed in preelaborated unit", N);
else
Error_Msg_N
("<<non-static call not allowed in preelaborated unit", N);
end if;
end Error_Preelaborated_Call;
----------------------------------
-- Finalize_All_Data_Structures --
----------------------------------
procedure Finalize_All_Data_Structures is
begin
Finalize_Body_Processor;
Finalize_Early_Call_Region_Processor;
Finalize_Elaborated_Units;
Finalize_Internal_Representation;
Finalize_Invocation_Graph;
Finalize_Scenario_Storage;
end Finalize_All_Data_Structures;
-----------------------------
-- Find_Enclosing_Instance --
-----------------------------
function Find_Enclosing_Instance (N : Node_Id) return Node_Id is
Par : Node_Id;
begin
-- Climb the parent chain looking for an enclosing instance spec or body
Par := N;
while Present (Par) loop
if Nkind (Par) in N_Package_Body
| N_Package_Declaration
| N_Subprogram_Body
| N_Subprogram_Declaration
and then Is_Generic_Instance (Unique_Defining_Entity (Par))
then
return Par;
end if;
Par := Parent (Par);
end loop;
return Empty;
end Find_Enclosing_Instance;
--------------------------
-- Find_Enclosing_Level --
--------------------------
function Find_Enclosing_Level (N : Node_Id) return Enclosing_Level_Kind is
function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind;
pragma Inline (Level_Of);
-- Obtain the corresponding level of unit Unit
--------------
-- Level_Of --
--------------
function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind is
Spec_Id : Entity_Id;
begin
if Nkind (Unit) in N_Generic_Instantiation then
return Instantiation_Level;
elsif Nkind (Unit) = N_Generic_Package_Declaration then
return Generic_Spec_Level;
elsif Nkind (Unit) = N_Package_Declaration then
return Library_Spec_Level;
elsif Nkind (Unit) = N_Package_Body then
Spec_Id := Corresponding_Spec (Unit);
-- The body belongs to a generic package
if Present (Spec_Id)
and then Ekind (Spec_Id) = E_Generic_Package
then
return Generic_Body_Level;
-- Otherwise the body belongs to a non-generic package. This also
-- treats an illegal package body without a corresponding spec as
-- a non-generic package body.
else
return Library_Body_Level;
end if;
end if;
return No_Level;
end Level_Of;
-- Local variables
Context : Node_Id;
Curr : Node_Id;
Prev : Node_Id;
-- Start of processing for Find_Enclosing_Level
begin
-- Call markers and instantiations which appear at the declaration level
-- but are later relocated in a different context retain their original
-- declaration level.
if Nkind (N) in N_Call_Marker
| N_Function_Instantiation
| N_Package_Instantiation
| N_Procedure_Instantiation
and then Is_Declaration_Level_Node (N)
then
return Declaration_Level;
end if;
-- Climb the parent chain looking at the enclosing levels
Prev := N;
Curr := Parent (Prev);
while Present (Curr) loop
-- A traversal from a subunit continues via the corresponding stub
if Nkind (Curr) = N_Subunit then
Curr := Corresponding_Stub (Curr);
-- The current construct is a package. Packages are ignored because
-- they are always elaborated when the enclosing context is invoked
-- or elaborated.
elsif Nkind (Curr) in N_Package_Body | N_Package_Declaration then
null;
-- The current construct is a block statement
elsif Nkind (Curr) = N_Block_Statement then
-- Ignore internally generated blocks created by the expander for
-- various purposes such as abort defer/undefer.
if not Comes_From_Source (Curr) then
null;
-- If the traversal came from the handled sequence of statments,
-- then the node appears at the level of the enclosing construct.
-- This is a more reliable test because transients scopes within
-- the declarative region of the encapsulator are hard to detect.
elsif Nkind (Prev) = N_Handled_Sequence_Of_Statements
and then Handled_Statement_Sequence (Curr) = Prev
then
return Find_Enclosing_Level (Parent (Curr));
-- Otherwise the traversal came from the declarations, the node is
-- at the declaration level.
else
return Declaration_Level;
end if;
-- The current construct is a declaration-level encapsulator
elsif Nkind (Curr) in
N_Entry_Body | N_Subprogram_Body | N_Task_Body
then
-- If the traversal came from the handled sequence of statments,
-- then the node cannot possibly appear at any level. This is
-- a more reliable test because transients scopes within the
-- declarative region of the encapsulator are hard to detect.
if Nkind (Prev) = N_Handled_Sequence_Of_Statements
and then Handled_Statement_Sequence (Curr) = Prev
then
return No_Level;
-- Otherwise the traversal came from the declarations, the node is
-- at the declaration level.
else
return Declaration_Level;
end if;
-- The current construct is a non-library-level encapsulator which
-- indicates that the node cannot possibly appear at any level. Note
-- that the check must come after the declaration-level check because
-- both predicates share certain nodes.
elsif Is_Non_Library_Level_Encapsulator (Curr) then
Context := Parent (Curr);
-- The sole exception is when the encapsulator is the compilation
-- utit itself because the compilation unit node requires special
-- processing (see below).
if Present (Context)
and then Nkind (Context) = N_Compilation_Unit
then
null;
-- Otherwise the node is not at any level
else
return No_Level;
end if;
-- The current construct is a compilation unit. The node appears at
-- the [generic] library level when the unit is a [generic] package.
elsif Nkind (Curr) = N_Compilation_Unit then
return Level_Of (Unit (Curr));
end if;
Prev := Curr;
Curr := Parent (Prev);
end loop;
return No_Level;
end Find_Enclosing_Level;
-------------------
-- Find_Top_Unit --
-------------------
function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id is
begin
return Find_Unit_Entity (Unit (Cunit (Get_Top_Level_Code_Unit (N))));
end Find_Top_Unit;
----------------------
-- Find_Unit_Entity --
----------------------
function Find_Unit_Entity (N : Node_Id) return Entity_Id is
Context : constant Node_Id := Parent (N);
Orig_N : constant Node_Id := Original_Node (N);
begin
-- The unit denotes a package body of an instantiation which acts as
-- a compilation unit. The proper entity is that of the package spec.
if Nkind (N) = N_Package_Body
and then Nkind (Orig_N) = N_Package_Instantiation
and then Nkind (Context) = N_Compilation_Unit
then
return Corresponding_Spec (N);
-- The unit denotes an anonymous package created to wrap a subprogram
-- instantiation which acts as a compilation unit. The proper entity is
-- that of the "related instance".
elsif Nkind (N) = N_Package_Declaration
and then Nkind (Orig_N) in
N_Function_Instantiation | N_Procedure_Instantiation
and then Nkind (Context) = N_Compilation_Unit
then
return Related_Instance (Defining_Entity (N));
-- The unit denotes a concurrent body acting as a subunit. Such bodies
-- are generally rewritten into null statements. The proper entity is
-- that of the "original node".
elsif Nkind (N) = N_Subunit
and then Nkind (Proper_Body (N)) = N_Null_Statement
and then Nkind (Original_Node (Proper_Body (N))) in
N_Protected_Body | N_Task_Body
then
return Defining_Entity (Original_Node (Proper_Body (N)));
-- Otherwise the proper entity is the defining entity
else
return Defining_Entity (N);
end if;
end Find_Unit_Entity;
-----------------------
-- First_Formal_Type --
-----------------------
function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id is
Formal_Id : constant Entity_Id := First_Formal (Subp_Id);
Typ : Entity_Id;
begin
if Present (Formal_Id) then
Typ := Etype (Formal_Id);
-- Handle various combinations of concurrent and private types
loop
if Ekind (Typ) in E_Protected_Type | E_Task_Type
and then Present (Anonymous_Object (Typ))
then
Typ := Anonymous_Object (Typ);
elsif Is_Concurrent_Record_Type (Typ) then
Typ := Corresponding_Concurrent_Type (Typ);
elsif Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
Typ := Full_View (Typ);
else
exit;
end if;
end loop;
return Typ;
end if;
return Empty;
end First_Formal_Type;
------------------------------
-- Guaranteed_ABE_Processor --
------------------------------
package body Guaranteed_ABE_Processor is
function Is_Guaranteed_ABE
(N : Node_Id;
Target_Decl : Node_Id;
Target_Body : Node_Id) return Boolean;
pragma Inline (Is_Guaranteed_ABE);
-- Determine whether scenario N with a target described by its initial
-- declaration Target_Decl and body Target_Decl results in a guaranteed
-- ABE.
procedure Process_Guaranteed_ABE_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Guaranteed_ABE_Activation);
-- Perform common guaranteed ABE checks and diagnostics for activation
-- call Call which activates object Obj_Id of task type Task_Typ. Formal
-- Call_Rep denotes the representation of the call. Obj_Rep denotes the
-- representation of the object. Task_Rep denotes the representation of
-- the task type. In_State is the current state of the Processing phase.
procedure Process_Guaranteed_ABE_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Guaranteed_ABE_Call);
-- Perform common guaranteed ABE checks and diagnostics for call Call
-- with representation Call_Rep. In_State denotes the current state of
-- the Processing phase.
procedure Process_Guaranteed_ABE_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Guaranteed_ABE_Instantiation);
-- Perform common guaranteed ABE checks and diagnostics for instance
-- Inst with representation Inst_Rep. In_State is the current state of
-- the Processing phase.
-----------------------
-- Is_Guaranteed_ABE --
-----------------------
function Is_Guaranteed_ABE
(N : Node_Id;
Target_Decl : Node_Id;
Target_Body : Node_Id) return Boolean
is
Spec : Node_Id;
begin
-- Avoid cascaded errors if there were previous serious infractions.
-- As a result the scenario will not be treated as a guaranteed ABE.
-- This behavior parallels that of the old ABE mechanism.
if Serious_Errors_Detected > 0 then
return False;
-- The scenario and the target appear in the same context ignoring
-- enclosing library levels.
elsif In_Same_Context (N, Target_Decl) then
-- The target body has already been encountered. The scenario
-- results in a guaranteed ABE if it appears prior to the body.
if Present (Target_Body) then
return Earlier_In_Extended_Unit (N, Target_Body);
-- Otherwise the body has not been encountered yet. The scenario
-- is a guaranteed ABE since the body will appear later, unless
-- this is a null specification, which can occur if expansion is
-- disabled (e.g. -gnatc or GNATprove mode). It is assumed that
-- the caller has already ensured that the scenario is ABE-safe
-- because optional bodies are not considered here.
else
Spec := Specification (Target_Decl);
if Nkind (Spec) /= N_Procedure_Specification
or else not Null_Present (Spec)
then
return True;
end if;
end if;
end if;
return False;
end Is_Guaranteed_ABE;
----------------------------
-- Process_Guaranteed_ABE --
----------------------------
procedure Process_Guaranteed_ABE
(N : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
Scen_Rep : Scenario_Rep_Id;
begin
-- Add the current scenario to the stack of active scenarios
Push_Active_Scenario (Scen);
-- Only calls, instantiations, and task activations may result in a
-- guaranteed ABE.
-- Call or task activation
if Is_Suitable_Call (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
if Kind (Scen_Rep) = Call_Scenario then
Process_Guaranteed_ABE_Call
(Call => Scen,
Call_Rep => Scen_Rep,
In_State => In_State);
else
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario);
Process_Activation
(Call => Scen,
Call_Rep => Scenario_Representation_Of (Scen, In_State),
Processor => Process_Guaranteed_ABE_Activation'Access,
In_State => In_State);
end if;
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Process_Guaranteed_ABE_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
end if;
-- Remove the current scenario from the stack of active scenarios
-- once all ABE diagnostics and checks have been performed.
Pop_Active_Scenario (Scen);
end Process_Guaranteed_ABE;
---------------------------------------
-- Process_Guaranteed_ABE_Activation --
---------------------------------------
procedure Process_Guaranteed_ABE_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
Spec_Decl : constant Node_Id := Spec_Declaration (Task_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Obj_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Task_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Obj_Rep)
and then Elaboration_Checks_OK (Task_Rep);
-- A run-time ABE check may be installed only when the object and the
-- task type have active elaboration checks, and both are not ignored
-- Ghost constructs.
begin
-- Nothing to do when the root scenario appears at the declaration
-- level and the task is in the same unit, but outside this context.
--
-- task type Task_Typ; -- task declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- T : Task_Typ;
-- begin
-- <activation call> -- activation site
-- end;
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- task body Task_Typ is
-- ...
-- end Task_Typ;
--
-- In the example above, the context of X is the declarative list
-- of Proc. The "elaboration" of X may reach the activation of T
-- whose body is defined outside of X's context. The task body is
-- relevant only when Proc is invoked, but this happens only in
-- "normal" elaboration, therefore the task body must not be
-- considered if this is not the case.
if Is_Up_Level_Target
(Targ_Decl => Spec_Decl,
In_State => In_State)
then
return;
-- Nothing to do when the activation is ABE-safe
--
-- generic
-- package Gen is
-- task type Task_Typ;
-- end Gen;
--
-- package body Gen is
-- task body Task_Typ is
-- begin
-- ...
-- end Task_Typ;
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- package Nested is
-- package Inst is new Gen;
-- T : Inst.Task_Typ;
-- end Nested; -- safe activation
-- ...
elsif Is_Safe_Activation (Call, Task_Rep) then
return;
-- An activation call leads to a guaranteed ABE when the activation
-- call and the task appear within the same context ignoring library
-- levels, and the body of the task has not been seen yet or appears
-- after the activation call.
--
-- procedure Guaranteed_ABE is
-- task type Task_Typ;
--
-- package Nested is
-- T : Task_Typ;
-- <activation call> -- guaranteed ABE
-- end Nested;
--
-- task body Task_Typ is
-- ...
-- end Task_Typ;
-- ...
elsif Is_Guaranteed_ABE
(N => Call,
Target_Decl => Spec_Decl,
Target_Body => Body_Declaration (Task_Rep))
then
if Elaboration_Warnings_OK (Call_Rep) then
Error_Msg_Sloc := Sloc (Call);
Error_Msg_N
("??task & will be activated # before elaboration of its "
& "body", Obj_Id);
Error_Msg_N
("\Program_Error will be raised at run time", Obj_Id);
end if;
-- Mark the activation call as a guaranteed ABE
Set_Is_Known_Guaranteed_ABE (Call);
-- Install a run-time ABE failue because this activation call will
-- always result in an ABE.
if Check_OK then
Install_Scenario_ABE_Failure
(N => Call,
Targ_Id => Task_Typ,
Targ_Rep => Task_Rep,
Disable => Obj_Rep);
end if;
end if;
end Process_Guaranteed_ABE_Activation;
---------------------------------
-- Process_Guaranteed_ABE_Call --
---------------------------------
procedure Process_Guaranteed_ABE_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Subp_Id : constant Entity_Id := Target (Call_Rep);
Subp_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Subp_Id, In_State);
Spec_Decl : constant Node_Id := Spec_Declaration (Subp_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Call_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Subp_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Call_Rep)
and then Elaboration_Checks_OK (Subp_Rep);
-- A run-time ABE check may be installed only when both the call
-- and the target have active elaboration checks, and both are not
-- ignored Ghost constructs.
begin
-- Nothing to do when the root scenario appears at the declaration
-- level and the target is in the same unit but outside this context.
--
-- function B ...; -- target declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- return B; -- call site
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- function B ... is
-- ...
-- end B;
--
-- In the example above, the context of X is the declarative region
-- of Proc. The "elaboration" of X may eventually reach B which is
-- defined outside of X's context. B is relevant only when Proc is
-- invoked, but this happens only by means of "normal" elaboration,
-- therefore B must not be considered if this is not the case.
if Is_Up_Level_Target
(Targ_Decl => Spec_Decl,
In_State => In_State)
then
return;
-- Nothing to do when the call is ABE-safe
--
-- generic
-- function Gen ...;
--
-- function Gen ... is
-- begin
-- ...
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- function Inst is new Gen;
-- X : ... := Inst; -- safe call
-- ...
elsif Is_Safe_Call (Call, Subp_Id, Subp_Rep) then
return;
-- A call leads to a guaranteed ABE when the call and the target
-- appear within the same context ignoring library levels, and the
-- body of the target has not been seen yet or appears after the
-- call.
--
-- procedure Guaranteed_ABE is
-- function Func ...;
--
-- package Nested is
-- Obj : ... := Func; -- guaranteed ABE
-- end Nested;
--
-- function Func ... is
-- ...
-- end Func;
-- ...
elsif Is_Guaranteed_ABE
(N => Call,
Target_Decl => Spec_Decl,
Target_Body => Body_Declaration (Subp_Rep))
then
if Elaboration_Warnings_OK (Call_Rep) then
Error_Msg_NE
("??cannot call & before body seen", Call, Subp_Id);
Error_Msg_N ("\Program_Error will be raised at run time", Call);
end if;
-- Mark the call as a guaranteed ABE
Set_Is_Known_Guaranteed_ABE (Call);
-- Install a run-time ABE failure because the call will always
-- result in an ABE.
if Check_OK then
Install_Scenario_ABE_Failure
(N => Call,
Targ_Id => Subp_Id,
Targ_Rep => Subp_Rep,
Disable => Call_Rep);
end if;
end if;
end Process_Guaranteed_ABE_Call;
------------------------------------------
-- Process_Guaranteed_ABE_Instantiation --
------------------------------------------
procedure Process_Guaranteed_ABE_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Gen_Id : constant Entity_Id := Target (Inst_Rep);
Gen_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Gen_Id, In_State);
Spec_Decl : constant Node_Id := Spec_Declaration (Gen_Rep);
Check_OK : constant Boolean :=
not In_State.Suppress_Checks
and then Ghost_Mode_Of (Inst_Rep) /= Is_Ignored
and then Ghost_Mode_Of (Gen_Rep) /= Is_Ignored
and then Elaboration_Checks_OK (Inst_Rep)
and then Elaboration_Checks_OK (Gen_Rep);
-- A run-time ABE check may be installed only when both the instance
-- and the generic have active elaboration checks and both are not
-- ignored Ghost constructs.
begin
-- Nothing to do when the root scenario appears at the declaration
-- level and the generic is in the same unit, but outside this
-- context.
--
-- generic
-- procedure Gen is ...; -- generic declaration
--
-- procedure Proc is
-- function A ... is
-- begin
-- if Some_Condition then
-- declare
-- procedure I is new Gen; -- instantiation site
-- ...
-- ...
-- end A;
--
-- X : ... := A; -- root scenario
-- ...
--
-- procedure Gen is
-- ...
-- end Gen;
--
-- In the example above, the context of X is the declarative region
-- of Proc. The "elaboration" of X may eventually reach Gen which
-- appears outside of X's context. Gen is relevant only when Proc is
-- invoked, but this happens only by means of "normal" elaboration,
-- therefore Gen must not be considered if this is not the case.
if Is_Up_Level_Target
(Targ_Decl => Spec_Decl,
In_State => In_State)
then
return;
-- Nothing to do when the instantiation is ABE-safe
--
-- generic
-- package Gen is
-- ...
-- end Gen;
--
-- package body Gen is
-- ...
-- end Gen;
--
-- with Gen;
-- procedure Main is
-- package Inst is new Gen (ABE); -- safe instantiation
-- ...
elsif Is_Safe_Instantiation (Inst, Gen_Id, Gen_Rep) then
return;
-- An instantiation leads to a guaranteed ABE when the instantiation
-- and the generic appear within the same context ignoring library
-- levels, and the body of the generic has not been seen yet or
-- appears after the instantiation.
--
-- procedure Guaranteed_ABE is
-- generic
-- procedure Gen;
--
-- package Nested is
-- procedure Inst is new Gen; -- guaranteed ABE
-- end Nested;
--
-- procedure Gen is
-- ...
-- end Gen;
-- ...
elsif Is_Guaranteed_ABE
(N => Inst,
Target_Decl => Spec_Decl,
Target_Body => Body_Declaration (Gen_Rep))
then
if Elaboration_Warnings_OK (Inst_Rep) then
Error_Msg_NE
("??cannot instantiate & before body seen", Inst, Gen_Id);
Error_Msg_N ("\Program_Error will be raised at run time", Inst);
end if;
-- Mark the instantiation as a guarantee ABE. This automatically
-- suppresses the instantiation of the generic body.
Set_Is_Known_Guaranteed_ABE (Inst);
-- Install a run-time ABE failure because the instantiation will
-- always result in an ABE.
if Check_OK then
Install_Scenario_ABE_Failure
(N => Inst,
Targ_Id => Gen_Id,
Targ_Rep => Gen_Rep,
Disable => Inst_Rep);
end if;
end if;
end Process_Guaranteed_ABE_Instantiation;
end Guaranteed_ABE_Processor;
--------------
-- Has_Body --
--------------
function Has_Body (Pack_Decl : Node_Id) return Boolean is
function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id;
pragma Inline (Find_Corresponding_Body);
-- Try to locate the corresponding body of spec Spec_Id. If no body is
-- found, return Empty.
function Find_Body
(Spec_Id : Entity_Id;
From : Node_Id) return Node_Id;
pragma Inline (Find_Body);
-- Try to locate the corresponding body of spec Spec_Id in the node list
-- which follows arbitrary node From. If no body is found, return Empty.
function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id;
pragma Inline (Load_Package_Body);
-- Attempt to load the body of unit Unit_Nam. If the load failed, return
-- Empty. If the compilation will not generate code, return Empty.
-----------------------------
-- Find_Corresponding_Body --
-----------------------------
function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id is
Context : constant Entity_Id := Scope (Spec_Id);
Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
Body_Decl : Node_Id;
Body_Id : Entity_Id;
begin
if Is_Compilation_Unit (Spec_Id) then
Body_Id := Corresponding_Body (Spec_Decl);
if Present (Body_Id) then
return Unit_Declaration_Node (Body_Id);
-- The package is at the library and requires a body. Load the
-- corresponding body because the optional body may be declared
-- there.
elsif Unit_Requires_Body (Spec_Id) then
return
Load_Package_Body
(Get_Body_Name (Unit_Name (Get_Source_Unit (Spec_Decl))));
-- Otherwise there is no optional body
else
return Empty;
end if;
-- The immediate context is a package. The optional body may be
-- within the body of that package.
-- procedure Proc is
-- package Nested_1 is
-- package Nested_2 is
-- generic
-- package Pack is
-- end Pack;
-- end Nested_2;
-- end Nested_1;
-- package body Nested_1 is
-- package body Nested_2 is separate;
-- end Nested_1;
-- separate (Proc.Nested_1.Nested_2)
-- package body Nested_2 is
-- package body Pack is -- optional body
-- ...
-- end Pack;
-- end Nested_2;
elsif Is_Package_Or_Generic_Package (Context) then
Body_Decl := Find_Corresponding_Body (Context);
-- The optional body is within the body of the enclosing package
if Present (Body_Decl) then
return
Find_Body
(Spec_Id => Spec_Id,
From => First (Declarations (Body_Decl)));
-- Otherwise the enclosing package does not have a body. This may
-- be the result of an error or a genuine lack of a body.
else
return Empty;
end if;
-- Otherwise the immediate context is a body. The optional body may
-- be within the same list as the spec.
-- procedure Proc is
-- generic
-- package Pack is
-- end Pack;
-- package body Pack is -- optional body
-- ...
-- end Pack;
else
return
Find_Body
(Spec_Id => Spec_Id,
From => Next (Spec_Decl));
end if;
end Find_Corresponding_Body;
---------------
-- Find_Body --
---------------
function Find_Body
(Spec_Id : Entity_Id;
From : Node_Id) return Node_Id
is
Spec_Nam : constant Name_Id := Chars (Spec_Id);
Item : Node_Id;
Lib_Unit : Node_Id;
begin
Item := From;
while Present (Item) loop
-- The current item denotes the optional body
if Nkind (Item) = N_Package_Body
and then Chars (Defining_Entity (Item)) = Spec_Nam
then
return Item;
-- The current item denotes a stub, the optional body may be in
-- the subunit.
elsif Nkind (Item) = N_Package_Body_Stub
and then Chars (Defining_Entity (Item)) = Spec_Nam
then
Lib_Unit := Library_Unit (Item);
-- The corresponding subunit was previously loaded
if Present (Lib_Unit) then
return Lib_Unit;
-- Otherwise attempt to load the corresponding subunit
else
return Load_Package_Body (Get_Unit_Name (Item));
end if;
end if;
Next (Item);
end loop;
return Empty;
end Find_Body;
-----------------------
-- Load_Package_Body --
-----------------------
function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id is
Body_Decl : Node_Id;
Unit_Num : Unit_Number_Type;
begin
-- The load is performed only when the compilation will generate code
if Operating_Mode = Generate_Code then
Unit_Num :=
Load_Unit
(Load_Name => Unit_Nam,
Required => False,
Subunit => False,
Error_Node => Pack_Decl);
-- The load failed most likely because the physical file is
-- missing.
if Unit_Num = No_Unit then
return Empty;
-- Otherwise the load was successful, return the body of the unit
else
Body_Decl := Unit (Cunit (Unit_Num));
-- If the unit is a subunit with an available proper body,
-- return the proper body.
if Nkind (Body_Decl) = N_Subunit
and then Present (Proper_Body (Body_Decl))
then
Body_Decl := Proper_Body (Body_Decl);
end if;
return Body_Decl;
end if;
end if;
return Empty;
end Load_Package_Body;
-- Local variables
Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
-- Start of processing for Has_Body
begin
-- The body is available
if Present (Corresponding_Body (Pack_Decl)) then
return True;
-- The body is required if the package spec contains a construct which
-- requires a completion in a body.
elsif Unit_Requires_Body (Pack_Id) then
return True;
-- The body may be optional
else
return Present (Find_Corresponding_Body (Pack_Id));
end if;
end Has_Body;
----------
-- Hash --
----------
function Hash (NE : Node_Or_Entity_Id) return Bucket_Range_Type is
pragma Assert (Present (NE));
begin
return Bucket_Range_Type (NE);
end Hash;
--------------------------
-- In_External_Instance --
--------------------------
function In_External_Instance
(N : Node_Id;
Target_Decl : Node_Id) return Boolean
is
Inst : Node_Id;
Inst_Body : Node_Id;
Inst_Spec : Node_Id;
begin
Inst := Find_Enclosing_Instance (Target_Decl);
-- The target declaration appears within an instance spec. Visibility is
-- ignored because internally generated primitives for private types may
-- reside in the private declarations and still be invoked from outside.
if Present (Inst) and then Nkind (Inst) = N_Package_Declaration then
-- The scenario comes from the main unit and the instance does not
if In_Extended_Main_Code_Unit (N)
and then not In_Extended_Main_Code_Unit (Inst)
then
return True;
-- Otherwise the scenario must not appear within the instance spec or
-- body.
else
Spec_And_Body_From_Node
(N => Inst,
Spec_Decl => Inst_Spec,
Body_Decl => Inst_Body);
return not In_Subtree
(N => N,
Root1 => Inst_Spec,
Root2 => Inst_Body);
end if;
end if;
return False;
end In_External_Instance;
---------------------
-- In_Main_Context --
---------------------
function In_Main_Context (N : Node_Id) return Boolean is
begin
-- Scenarios outside the main unit are not considered because the ALI
-- information supplied to binde is for the main unit only.
if not In_Extended_Main_Code_Unit (N) then
return False;
-- Scenarios within internal units are not considered unless switch
-- -gnatdE (elaboration checks on predefined units) is in effect.
elsif not Debug_Flag_EE and then In_Internal_Unit (N) then
return False;
end if;
return True;
end In_Main_Context;
---------------------
-- In_Same_Context --
---------------------
function In_Same_Context
(N1 : Node_Id;
N2 : Node_Id;
Nested_OK : Boolean := False) return Boolean
is
function Find_Enclosing_Context (N : Node_Id) return Node_Id;
pragma Inline (Find_Enclosing_Context);
-- Return the nearest enclosing non-library-level or compilation unit
-- node which encapsulates arbitrary node N. Return Empty is no such
-- context is available.
function In_Nested_Context
(Outer : Node_Id;
Inner : Node_Id) return Boolean;
pragma Inline (In_Nested_Context);
-- Determine whether arbitrary node Outer encapsulates arbitrary node
-- Inner.
----------------------------
-- Find_Enclosing_Context --
----------------------------
function Find_Enclosing_Context (N : Node_Id) return Node_Id is
Context : Node_Id;
Par : Node_Id;
begin
Par := Parent (N);
while Present (Par) loop
-- A traversal from a subunit continues via the corresponding stub
if Nkind (Par) = N_Subunit then
Par := Corresponding_Stub (Par);
-- Stop the traversal when the nearest enclosing non-library-level
-- encapsulator has been reached.
elsif Is_Non_Library_Level_Encapsulator (Par) then
Context := Parent (Par);
-- The sole exception is when the encapsulator is the unit of
-- compilation because this case requires special processing
-- (see below).
if Present (Context)
and then Nkind (Context) = N_Compilation_Unit
then
null;
else
return Par;
end if;
-- Reaching a compilation unit node without hitting a non-library-
-- level encapsulator indicates that N is at the library level in
-- which case the compilation unit is the context.
elsif Nkind (Par) = N_Compilation_Unit then
return Par;
end if;
Par := Parent (Par);
end loop;
return Empty;
end Find_Enclosing_Context;
-----------------------
-- In_Nested_Context --
-----------------------
function In_Nested_Context
(Outer : Node_Id;
Inner : Node_Id) return Boolean
is
Par : Node_Id;
begin
Par := Inner;
while Present (Par) loop
-- A traversal from a subunit continues via the corresponding stub
if Nkind (Par) = N_Subunit then
Par := Corresponding_Stub (Par);
elsif Par = Outer then
return True;
end if;
Par := Parent (Par);
end loop;
return False;
end In_Nested_Context;
-- Local variables
Context_1 : constant Node_Id := Find_Enclosing_Context (N1);
Context_2 : constant Node_Id := Find_Enclosing_Context (N2);
-- Start of processing for In_Same_Context
begin
-- Both nodes appear within the same context
if Context_1 = Context_2 then
return True;
-- Both nodes appear in compilation units. Determine whether one unit
-- is the body of the other.
elsif Nkind (Context_1) = N_Compilation_Unit
and then Nkind (Context_2) = N_Compilation_Unit
then
return
Is_Same_Unit
(Unit_1 => Defining_Entity (Unit (Context_1)),
Unit_2 => Defining_Entity (Unit (Context_2)));
-- The context of N1 encloses the context of N2
elsif Nested_OK and then In_Nested_Context (Context_1, Context_2) then
return True;
end if;
return False;
end In_Same_Context;
----------------
-- Initialize --
----------------
procedure Initialize is
begin
-- Set the soft link which enables Atree.Rewrite to update a scenario
-- each time it is transformed into another node.
Set_Rewriting_Proc (Update_Elaboration_Scenario'Access);
-- Create all internal data structures and activate the elaboration
-- phase of the compiler.
Initialize_All_Data_Structures;
Set_Elaboration_Phase (Active);
end Initialize;
------------------------------------
-- Initialize_All_Data_Structures --
------------------------------------
procedure Initialize_All_Data_Structures is
begin
Initialize_Body_Processor;
Initialize_Early_Call_Region_Processor;
Initialize_Elaborated_Units;
Initialize_Internal_Representation;
Initialize_Invocation_Graph;
Initialize_Scenario_Storage;
end Initialize_All_Data_Structures;
--------------------------
-- Instantiated_Generic --
--------------------------
function Instantiated_Generic (Inst : Node_Id) return Entity_Id is
begin
-- Traverse a possible chain of renamings to obtain the original generic
-- being instantiatied.
return Get_Renamed_Entity (Entity (Name (Inst)));
end Instantiated_Generic;
-----------------------------
-- Internal_Representation --
-----------------------------
package body Internal_Representation is
-----------
-- Types --
-----------
-- The following type represents the contents of a scenario
type Scenario_Rep_Record is record
Elab_Checks_OK : Boolean := False;
-- The status of elaboration checks for the scenario
Elab_Warnings_OK : Boolean := False;
-- The status of elaboration warnings for the scenario
GM : Extended_Ghost_Mode := Is_Checked_Or_Not_Specified;
-- The Ghost mode of the scenario
Kind : Scenario_Kind := No_Scenario;
-- The nature of the scenario
Level : Enclosing_Level_Kind := No_Level;
-- The enclosing level where the scenario resides
SM : Extended_SPARK_Mode := Is_Off_Or_Not_Specified;
-- The SPARK mode of the scenario
Target : Entity_Id := Empty;
-- The target of the scenario
-- The following attributes are multiplexed and depend on the Kind of
-- the scenario. They are mapped as follows:
--
-- Call_Scenario
-- Is_Dispatching_Call (Flag_1)
--
-- Task_Activation_Scenario
-- Activated_Task_Objects (List_1)
-- Activated_Task_Type (Field_1)
--
-- Variable_Reference
-- Is_Read_Reference (Flag_1)
Flag_1 : Boolean := False;
Field_1 : Node_Or_Entity_Id := Empty;
List_1 : NE_List.Doubly_Linked_List := NE_List.Nil;
end record;
-- The following type represents the contents of a target
type Target_Rep_Record is record
Body_Decl : Node_Id := Empty;
-- The declaration of the target body
Elab_Checks_OK : Boolean := False;
-- The status of elaboration checks for the target
Elab_Warnings_OK : Boolean := False;
-- The status of elaboration warnings for the target
GM : Extended_Ghost_Mode := Is_Checked_Or_Not_Specified;
-- The Ghost mode of the target
Kind : Target_Kind := No_Target;
-- The nature of the target
SM : Extended_SPARK_Mode := Is_Off_Or_Not_Specified;
-- The SPARK mode of the target
Spec_Decl : Node_Id := Empty;
-- The declaration of the target spec
Unit : Entity_Id := Empty;
-- The top unit where the target is declared
Version : Representation_Kind := No_Representation;
-- The version of the target representation
-- The following attributes are multiplexed and depend on the Kind of
-- the target. They are mapped as follows:
--
-- Subprogram_Target
-- Barrier_Body_Declaration (Field_1)
--
-- Variable_Target
-- Variable_Declaration (Field_1)
Field_1 : Node_Or_Entity_Id := Empty;
end record;
---------------------
-- Data structures --
---------------------
procedure Destroy (T_Id : in out Target_Rep_Id);
-- Destroy a target representation T_Id
package ETT_Map is new Dynamic_Hash_Tables
(Key_Type => Entity_Id,
Value_Type => Target_Rep_Id,
No_Value => No_Target_Rep,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => Destroy,
Hash => Hash);
-- The following map relates target representations to entities
Entity_To_Target_Map : ETT_Map.Dynamic_Hash_Table := ETT_Map.Nil;
procedure Destroy (S_Id : in out Scenario_Rep_Id);
-- Destroy a scenario representation S_Id
package NTS_Map is new Dynamic_Hash_Tables
(Key_Type => Node_Id,
Value_Type => Scenario_Rep_Id,
No_Value => No_Scenario_Rep,
Expansion_Threshold => 1.5,
Expansion_Factor => 2,
Compression_Threshold => 0.3,
Compression_Factor => 2,
"=" => "=",
Destroy_Value => Destroy,
Hash => Hash);
-- The following map relates scenario representations to nodes
Node_To_Scenario_Map : NTS_Map.Dynamic_Hash_Table := NTS_Map.Nil;
-- The following table stores all scenario representations
package Scenario_Reps is new Table.Table
(Table_Index_Type => Scenario_Rep_Id,
Table_Component_Type => Scenario_Rep_Record,
Table_Low_Bound => First_Scenario_Rep,
Table_Initial => 1000,
Table_Increment => 200,
Table_Name => "Scenario_Reps");
-- The following table stores all target representations
package Target_Reps is new Table.Table
(Table_Index_Type => Target_Rep_Id,
Table_Component_Type => Target_Rep_Record,
Table_Low_Bound => First_Target_Rep,
Table_Initial => 1000,
Table_Increment => 200,
Table_Name => "Target_Reps");
--------------
-- Builders --
--------------
function Create_Access_Taken_Rep
(Attr : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Access_Taken_Rep);
-- Create the representation of 'Access attribute Attr
function Create_Call_Or_Task_Activation_Rep
(Call : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Call_Or_Task_Activation_Rep);
-- Create the representation of call or task activation Call
function Create_Derived_Type_Rep
(Typ_Decl : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Derived_Type_Rep);
-- Create the representation of a derived type described by declaration
-- Typ_Decl.
function Create_Generic_Rep
(Gen_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Generic_Rep);
-- Create the representation of generic Gen_Id
function Create_Instantiation_Rep
(Inst : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Instantiation_Rep);
-- Create the representation of instantiation Inst
function Create_Package_Rep
(Pack_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Package_Rep);
-- Create the representation of package Pack_Id
function Create_Protected_Entry_Rep
(PE_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Protected_Entry_Rep);
-- Create the representation of protected entry PE_Id
function Create_Protected_Subprogram_Rep
(PS_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Protected_Subprogram_Rep);
-- Create the representation of protected subprogram PS_Id
function Create_Refined_State_Pragma_Rep
(Prag : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Refined_State_Pragma_Rep);
-- Create the representation of Refined_State pragma Prag
function Create_Scenario_Rep
(N : Node_Id;
In_State : Processing_In_State) return Scenario_Rep_Record;
pragma Inline (Create_Scenario_Rep);
-- Top level dispatcher. Create the representation of elaboration
-- scenario N. In_State is the current state of the Processing phase.
function Create_Subprogram_Rep
(Subp_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Subprogram_Rep);
-- Create the representation of entry, operator, or subprogram Subp_Id
function Create_Target_Rep
(Id : Entity_Id;
In_State : Processing_In_State) return Target_Rep_Record;
pragma Inline (Create_Target_Rep);
-- Top level dispatcher. Create the representation of elaboration target
-- Id. In_State is the current state of the Processing phase.
function Create_Task_Entry_Rep
(TE_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Task_Entry_Rep);
-- Create the representation of task entry TE_Id
function Create_Task_Rep (Task_Typ : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Task_Rep);
-- Create the representation of task type Typ
function Create_Variable_Assignment_Rep
(Asmt : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Variable_Assignment_Rep);
-- Create the representation of variable assignment Asmt
function Create_Variable_Reference_Rep
(Ref : Node_Id) return Scenario_Rep_Record;
pragma Inline (Create_Variable_Reference_Rep);
-- Create the representation of variable reference Ref
function Create_Variable_Rep
(Var_Id : Entity_Id) return Target_Rep_Record;
pragma Inline (Create_Variable_Rep);
-- Create the representation of variable Var_Id
-----------------------
-- Local subprograms --
-----------------------
function Ghost_Mode_Of_Entity
(Id : Entity_Id) return Extended_Ghost_Mode;
pragma Inline (Ghost_Mode_Of_Entity);
-- Obtain the extended Ghost mode of arbitrary entity Id
function Ghost_Mode_Of_Node (N : Node_Id) return Extended_Ghost_Mode;
pragma Inline (Ghost_Mode_Of_Node);
-- Obtain the extended Ghost mode of arbitrary node N
function Present (S_Id : Scenario_Rep_Id) return Boolean;
pragma Inline (Present);
-- Determine whether scenario representation S_Id exists
function Present (T_Id : Target_Rep_Id) return Boolean;
pragma Inline (Present);
-- Determine whether target representation T_Id exists
function SPARK_Mode_Of_Entity
(Id : Entity_Id) return Extended_SPARK_Mode;
pragma Inline (SPARK_Mode_Of_Entity);
-- Obtain the extended SPARK mode of arbitrary entity Id
function SPARK_Mode_Of_Node (N : Node_Id) return Extended_SPARK_Mode;
pragma Inline (SPARK_Mode_Of_Node);
-- Obtain the extended SPARK mode of arbitrary node N
function To_Ghost_Mode
(Ignored_Status : Boolean) return Extended_Ghost_Mode;
pragma Inline (To_Ghost_Mode);
-- Convert a Ghost mode indicated by Ignored_Status into its extended
-- equivalent.
function To_SPARK_Mode (On_Status : Boolean) return Extended_SPARK_Mode;
pragma Inline (To_SPARK_Mode);
-- Convert a SPARK mode indicated by On_Status into its extended
-- equivalent.
function Version (T_Id : Target_Rep_Id) return Representation_Kind;
pragma Inline (Version);
-- Obtain the version of target representation T_Id
----------------------------
-- Activated_Task_Objects --
----------------------------
function Activated_Task_Objects
(S_Id : Scenario_Rep_Id) return NE_List.Doubly_Linked_List
is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Task_Activation_Scenario);
begin
return Scenario_Reps.Table (S_Id).List_1;
end Activated_Task_Objects;
-------------------------
-- Activated_Task_Type --
-------------------------
function Activated_Task_Type
(S_Id : Scenario_Rep_Id) return Entity_Id
is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Task_Activation_Scenario);
begin
return Scenario_Reps.Table (S_Id).Field_1;
end Activated_Task_Type;
------------------------------
-- Barrier_Body_Declaration --
------------------------------
function Barrier_Body_Declaration
(T_Id : Target_Rep_Id) return Node_Id
is
pragma Assert (Present (T_Id));
pragma Assert (Kind (T_Id) = Subprogram_Target);
begin
return Target_Reps.Table (T_Id).Field_1;
end Barrier_Body_Declaration;
----------------------
-- Body_Declaration --
----------------------
function Body_Declaration (T_Id : Target_Rep_Id) return Node_Id is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Body_Decl;
end Body_Declaration;
-----------------------------
-- Create_Access_Taken_Rep --
-----------------------------
function Create_Access_Taken_Rep
(Attr : Node_Id) return Scenario_Rep_Record
is
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Attr);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Attr);
Rec.GM := Is_Checked_Or_Not_Specified;
Rec.SM := SPARK_Mode_Of_Node (Attr);
Rec.Kind := Access_Taken_Scenario;
Rec.Target := Canonical_Subprogram (Entity (Prefix (Attr)));
return Rec;
end Create_Access_Taken_Rep;
----------------------------------------
-- Create_Call_Or_Task_Activation_Rep --
----------------------------------------
function Create_Call_Or_Task_Activation_Rep
(Call : Node_Id) return Scenario_Rep_Record
is
Subp_Id : constant Entity_Id := Canonical_Subprogram (Target (Call));
Kind : Scenario_Kind;
Rec : Scenario_Rep_Record;
begin
if Is_Activation_Proc (Subp_Id) then
Kind := Task_Activation_Scenario;
else
Kind := Call_Scenario;
end if;
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Call);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Call);
Rec.GM := Ghost_Mode_Of_Node (Call);
Rec.SM := SPARK_Mode_Of_Node (Call);
Rec.Kind := Kind;
Rec.Target := Subp_Id;
-- Scenario-specific attributes
Rec.Flag_1 := Is_Dispatching_Call (Call); -- Dispatching_Call
return Rec;
end Create_Call_Or_Task_Activation_Rep;
-----------------------------
-- Create_Derived_Type_Rep --
-----------------------------
function Create_Derived_Type_Rep
(Typ_Decl : Node_Id) return Scenario_Rep_Record
is
Typ : constant Entity_Id := Defining_Entity (Typ_Decl);
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := False; -- not relevant
Rec.Elab_Warnings_OK := False; -- not relevant
Rec.GM := Ghost_Mode_Of_Entity (Typ);
Rec.SM := SPARK_Mode_Of_Entity (Typ);
Rec.Kind := Derived_Type_Scenario;
Rec.Target := Typ;
return Rec;
end Create_Derived_Type_Rep;
------------------------
-- Create_Generic_Rep --
------------------------
function Create_Generic_Rep
(Gen_Id : Entity_Id) return Target_Rep_Record
is
Rec : Target_Rep_Record;
begin
Rec.Kind := Generic_Target;
Spec_And_Body_From_Entity
(Id => Gen_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Generic_Rep;
------------------------------
-- Create_Instantiation_Rep --
------------------------------
function Create_Instantiation_Rep
(Inst : Node_Id) return Scenario_Rep_Record
is
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Inst);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Inst);
Rec.GM := Ghost_Mode_Of_Node (Inst);
Rec.SM := SPARK_Mode_Of_Node (Inst);
Rec.Kind := Instantiation_Scenario;
Rec.Target := Instantiated_Generic (Inst);
return Rec;
end Create_Instantiation_Rep;
------------------------
-- Create_Package_Rep --
------------------------
function Create_Package_Rep
(Pack_Id : Entity_Id) return Target_Rep_Record
is
Rec : Target_Rep_Record;
begin
Rec.Kind := Package_Target;
Spec_And_Body_From_Entity
(Id => Pack_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Package_Rep;
--------------------------------
-- Create_Protected_Entry_Rep --
--------------------------------
function Create_Protected_Entry_Rep
(PE_Id : Entity_Id) return Target_Rep_Record
is
Prot_Id : constant Entity_Id := Protected_Body_Subprogram (PE_Id);
Barf_Id : Entity_Id;
Dummy : Node_Id;
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
-- When the entry [family] has already been expanded, it carries both
-- the procedure which emulates the behavior of the entry [family] as
-- well as the barrier function.
if Present (Prot_Id) then
Barf_Id := Barrier_Function (PE_Id);
Spec_Id := Prot_Id;
-- Otherwise no expansion took place
else
Barf_Id := Empty;
Spec_Id := PE_Id;
end if;
Rec.Kind := Subprogram_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
-- Target-specific attributes
if Present (Barf_Id) then
Spec_And_Body_From_Entity
(Id => Barf_Id,
Body_Decl => Rec.Field_1, -- Barrier_Body_Declaration
Spec_Decl => Dummy);
end if;
return Rec;
end Create_Protected_Entry_Rep;
-------------------------------------
-- Create_Protected_Subprogram_Rep --
-------------------------------------
function Create_Protected_Subprogram_Rep
(PS_Id : Entity_Id) return Target_Rep_Record
is
Prot_Id : constant Entity_Id := Protected_Body_Subprogram (PS_Id);
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
-- When the protected subprogram has already been expanded, it
-- carries the subprogram which seizes the lock and invokes the
-- original statements.
if Present (Prot_Id) then
Spec_Id := Prot_Id;
-- Otherwise no expansion took place
else
Spec_Id := PS_Id;
end if;
Rec.Kind := Subprogram_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Protected_Subprogram_Rep;
-------------------------------------
-- Create_Refined_State_Pragma_Rep --
-------------------------------------
function Create_Refined_State_Pragma_Rep
(Prag : Node_Id) return Scenario_Rep_Record
is
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := False; -- not relevant
Rec.Elab_Warnings_OK := False; -- not relevant
Rec.GM :=
To_Ghost_Mode (Is_Ignored_Ghost_Pragma (Prag));
Rec.SM := Is_Off_Or_Not_Specified;
Rec.Kind := Refined_State_Pragma_Scenario;
Rec.Target := Empty;
return Rec;
end Create_Refined_State_Pragma_Rep;
-------------------------
-- Create_Scenario_Rep --
-------------------------
function Create_Scenario_Rep
(N : Node_Id;
In_State : Processing_In_State) return Scenario_Rep_Record
is
pragma Unreferenced (In_State);
Rec : Scenario_Rep_Record;
begin
if Is_Suitable_Access_Taken (N) then
Rec := Create_Access_Taken_Rep (N);
elsif Is_Suitable_Call (N) then
Rec := Create_Call_Or_Task_Activation_Rep (N);
elsif Is_Suitable_Instantiation (N) then
Rec := Create_Instantiation_Rep (N);
elsif Is_Suitable_SPARK_Derived_Type (N) then
Rec := Create_Derived_Type_Rep (N);
elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
Rec := Create_Refined_State_Pragma_Rep (N);
elsif Is_Suitable_Variable_Assignment (N) then
Rec := Create_Variable_Assignment_Rep (N);
elsif Is_Suitable_Variable_Reference (N) then
Rec := Create_Variable_Reference_Rep (N);
else
pragma Assert (False);
return Rec;
end if;
-- Common scenario attributes
Rec.Level := Find_Enclosing_Level (N);
return Rec;
end Create_Scenario_Rep;
---------------------------
-- Create_Subprogram_Rep --
---------------------------
function Create_Subprogram_Rep
(Subp_Id : Entity_Id) return Target_Rep_Record
is
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
Spec_Id := Subp_Id;
-- The elaboration target denotes an internal function that returns a
-- constrained array type in a SPARK-to-C compilation. In this case
-- the function receives a corresponding procedure which has an out
-- parameter. The proper body for ABE checks and diagnostics is that
-- of the procedure.
if Ekind (Spec_Id) = E_Function
and then Rewritten_For_C (Spec_Id)
then
Spec_Id := Corresponding_Procedure (Spec_Id);
end if;
Rec.Kind := Subprogram_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Subprogram_Rep;
-----------------------
-- Create_Target_Rep --
-----------------------
function Create_Target_Rep
(Id : Entity_Id;
In_State : Processing_In_State) return Target_Rep_Record
is
Rec : Target_Rep_Record;
begin
if Is_Generic_Unit (Id) then
Rec := Create_Generic_Rep (Id);
elsif Is_Protected_Entry (Id) then
Rec := Create_Protected_Entry_Rep (Id);
elsif Is_Protected_Subp (Id) then
Rec := Create_Protected_Subprogram_Rep (Id);
elsif Is_Task_Entry (Id) then
Rec := Create_Task_Entry_Rep (Id);
elsif Is_Task_Type (Id) then
Rec := Create_Task_Rep (Id);
elsif Ekind (Id) in E_Constant | E_Variable then
Rec := Create_Variable_Rep (Id);
elsif Ekind (Id) in E_Entry | E_Function | E_Operator | E_Procedure
then
Rec := Create_Subprogram_Rep (Id);
elsif Ekind (Id) = E_Package then
Rec := Create_Package_Rep (Id);
else
pragma Assert (False);
return Rec;
end if;
-- Common target attributes
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Id);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Id (Id);
Rec.GM := Ghost_Mode_Of_Entity (Id);
Rec.SM := SPARK_Mode_Of_Entity (Id);
Rec.Unit := Find_Top_Unit (Id);
Rec.Version := In_State.Representation;
return Rec;
end Create_Target_Rep;
---------------------------
-- Create_Task_Entry_Rep --
---------------------------
function Create_Task_Entry_Rep
(TE_Id : Entity_Id) return Target_Rep_Record
is
Task_Typ : constant Entity_Id := Non_Private_View (Scope (TE_Id));
Task_Body_Id : constant Entity_Id := Task_Body_Procedure (Task_Typ);
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
-- The task type has already been expanded, it carries the procedure
-- which emulates the behavior of the task body.
if Present (Task_Body_Id) then
Spec_Id := Task_Body_Id;
-- Otherwise no expansion took place
else
Spec_Id := TE_Id;
end if;
Rec.Kind := Subprogram_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Task_Entry_Rep;
---------------------
-- Create_Task_Rep --
---------------------
function Create_Task_Rep
(Task_Typ : Entity_Id) return Target_Rep_Record
is
Task_Body_Id : constant Entity_Id := Task_Body_Procedure (Task_Typ);
Rec : Target_Rep_Record;
Spec_Id : Entity_Id;
begin
-- The task type has already been expanded, it carries the procedure
-- which emulates the behavior of the task body.
if Present (Task_Body_Id) then
Spec_Id := Task_Body_Id;
-- Otherwise no expansion took place
else
Spec_Id := Task_Typ;
end if;
Rec.Kind := Task_Target;
Spec_And_Body_From_Entity
(Id => Spec_Id,
Body_Decl => Rec.Body_Decl,
Spec_Decl => Rec.Spec_Decl);
return Rec;
end Create_Task_Rep;
------------------------------------
-- Create_Variable_Assignment_Rep --
------------------------------------
function Create_Variable_Assignment_Rep
(Asmt : Node_Id) return Scenario_Rep_Record
is
Var_Id : constant Entity_Id := Entity (Assignment_Target (Asmt));
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Asmt);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Id (Var_Id);
Rec.GM := Ghost_Mode_Of_Node (Asmt);
Rec.SM := SPARK_Mode_Of_Node (Asmt);
Rec.Kind := Variable_Assignment_Scenario;
Rec.Target := Var_Id;
return Rec;
end Create_Variable_Assignment_Rep;
-----------------------------------
-- Create_Variable_Reference_Rep --
-----------------------------------
function Create_Variable_Reference_Rep
(Ref : Node_Id) return Scenario_Rep_Record
is
Rec : Scenario_Rep_Record;
begin
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Ref);
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Ref);
Rec.GM := Ghost_Mode_Of_Node (Ref);
Rec.SM := SPARK_Mode_Of_Node (Ref);
Rec.Kind := Variable_Reference_Scenario;
Rec.Target := Target (Ref);
-- Scenario-specific attributes
Rec.Flag_1 := Is_Read (Ref); -- Is_Read_Reference
return Rec;
end Create_Variable_Reference_Rep;
-------------------------
-- Create_Variable_Rep --
-------------------------
function Create_Variable_Rep
(Var_Id : Entity_Id) return Target_Rep_Record
is
Rec : Target_Rep_Record;
begin
Rec.Kind := Variable_Target;
-- Target-specific attributes
Rec.Field_1 := Declaration_Node (Var_Id); -- Variable_Declaration
return Rec;
end Create_Variable_Rep;
-------------
-- Destroy --
-------------
procedure Destroy (S_Id : in out Scenario_Rep_Id) is
pragma Unreferenced (S_Id);
begin
null;
end Destroy;
-------------
-- Destroy --
-------------
procedure Destroy (T_Id : in out Target_Rep_Id) is
pragma Unreferenced (T_Id);
begin
null;
end Destroy;
--------------------------------
-- Disable_Elaboration_Checks --
--------------------------------
procedure Disable_Elaboration_Checks (S_Id : Scenario_Rep_Id) is
pragma Assert (Present (S_Id));
begin
Scenario_Reps.Table (S_Id).Elab_Checks_OK := False;
end Disable_Elaboration_Checks;
--------------------------------
-- Disable_Elaboration_Checks --
--------------------------------
procedure Disable_Elaboration_Checks (T_Id : Target_Rep_Id) is
pragma Assert (Present (T_Id));
begin
Target_Reps.Table (T_Id).Elab_Checks_OK := False;
end Disable_Elaboration_Checks;
---------------------------
-- Elaboration_Checks_OK --
---------------------------
function Elaboration_Checks_OK (S_Id : Scenario_Rep_Id) return Boolean is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Elab_Checks_OK;
end Elaboration_Checks_OK;
---------------------------
-- Elaboration_Checks_OK --
---------------------------
function Elaboration_Checks_OK (T_Id : Target_Rep_Id) return Boolean is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Elab_Checks_OK;
end Elaboration_Checks_OK;
-----------------------------
-- Elaboration_Warnings_OK --
-----------------------------
function Elaboration_Warnings_OK
(S_Id : Scenario_Rep_Id) return Boolean
is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Elab_Warnings_OK;
end Elaboration_Warnings_OK;
-----------------------------
-- Elaboration_Warnings_OK --
-----------------------------
function Elaboration_Warnings_OK (T_Id : Target_Rep_Id) return Boolean is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Elab_Warnings_OK;
end Elaboration_Warnings_OK;
--------------------------------------
-- Finalize_Internal_Representation --
--------------------------------------
procedure Finalize_Internal_Representation is
begin
ETT_Map.Destroy (Entity_To_Target_Map);
NTS_Map.Destroy (Node_To_Scenario_Map);
end Finalize_Internal_Representation;
-------------------
-- Ghost_Mode_Of --
-------------------
function Ghost_Mode_Of
(S_Id : Scenario_Rep_Id) return Extended_Ghost_Mode
is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).GM;
end Ghost_Mode_Of;
-------------------
-- Ghost_Mode_Of --
-------------------
function Ghost_Mode_Of
(T_Id : Target_Rep_Id) return Extended_Ghost_Mode
is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).GM;
end Ghost_Mode_Of;
--------------------------
-- Ghost_Mode_Of_Entity --
--------------------------
function Ghost_Mode_Of_Entity
(Id : Entity_Id) return Extended_Ghost_Mode
is
begin
return To_Ghost_Mode (Is_Ignored_Ghost_Entity (Id));
end Ghost_Mode_Of_Entity;
------------------------
-- Ghost_Mode_Of_Node --
------------------------
function Ghost_Mode_Of_Node (N : Node_Id) return Extended_Ghost_Mode is
begin
return To_Ghost_Mode (Is_Ignored_Ghost_Node (N));
end Ghost_Mode_Of_Node;
----------------------------------------
-- Initialize_Internal_Representation --
----------------------------------------
procedure Initialize_Internal_Representation is
begin
Entity_To_Target_Map := ETT_Map.Create (500);
Node_To_Scenario_Map := NTS_Map.Create (500);
end Initialize_Internal_Representation;
-------------------------
-- Is_Dispatching_Call --
-------------------------
function Is_Dispatching_Call (S_Id : Scenario_Rep_Id) return Boolean is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Call_Scenario);
begin
return Scenario_Reps.Table (S_Id).Flag_1;
end Is_Dispatching_Call;
-----------------------
-- Is_Read_Reference --
-----------------------
function Is_Read_Reference (S_Id : Scenario_Rep_Id) return Boolean is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Variable_Reference_Scenario);
begin
return Scenario_Reps.Table (S_Id).Flag_1;
end Is_Read_Reference;
----------
-- Kind --
----------
function Kind (S_Id : Scenario_Rep_Id) return Scenario_Kind is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Kind;
end Kind;
----------
-- Kind --
----------
function Kind (T_Id : Target_Rep_Id) return Target_Kind is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Kind;
end Kind;
-----------
-- Level --
-----------
function Level (S_Id : Scenario_Rep_Id) return Enclosing_Level_Kind is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Level;
end Level;
-------------
-- Present --
-------------
function Present (S_Id : Scenario_Rep_Id) return Boolean is
begin
return S_Id /= No_Scenario_Rep;
end Present;
-------------
-- Present --
-------------
function Present (T_Id : Target_Rep_Id) return Boolean is
begin
return T_Id /= No_Target_Rep;
end Present;
--------------------------------
-- Scenario_Representation_Of --
--------------------------------
function Scenario_Representation_Of
(N : Node_Id;
In_State : Processing_In_State) return Scenario_Rep_Id
is
S_Id : Scenario_Rep_Id;
begin
S_Id := NTS_Map.Get (Node_To_Scenario_Map, N);
-- The elaboration scenario lacks a representation. This indicates
-- that the scenario is encountered for the first time. Create the
-- representation of it.
if not Present (S_Id) then
Scenario_Reps.Append (Create_Scenario_Rep (N, In_State));
S_Id := Scenario_Reps.Last;
-- Associate the internal representation with the elaboration
-- scenario.
NTS_Map.Put (Node_To_Scenario_Map, N, S_Id);
end if;
pragma Assert (Present (S_Id));
return S_Id;
end Scenario_Representation_Of;
--------------------------------
-- Set_Activated_Task_Objects --
--------------------------------
procedure Set_Activated_Task_Objects
(S_Id : Scenario_Rep_Id;
Task_Objs : NE_List.Doubly_Linked_List)
is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Task_Activation_Scenario);
begin
Scenario_Reps.Table (S_Id).List_1 := Task_Objs;
end Set_Activated_Task_Objects;
-----------------------------
-- Set_Activated_Task_Type --
-----------------------------
procedure Set_Activated_Task_Type
(S_Id : Scenario_Rep_Id;
Task_Typ : Entity_Id)
is
pragma Assert (Present (S_Id));
pragma Assert (Kind (S_Id) = Task_Activation_Scenario);
begin
Scenario_Reps.Table (S_Id).Field_1 := Task_Typ;
end Set_Activated_Task_Type;
-------------------
-- SPARK_Mode_Of --
-------------------
function SPARK_Mode_Of
(S_Id : Scenario_Rep_Id) return Extended_SPARK_Mode
is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).SM;
end SPARK_Mode_Of;
-------------------
-- SPARK_Mode_Of --
-------------------
function SPARK_Mode_Of
(T_Id : Target_Rep_Id) return Extended_SPARK_Mode
is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).SM;
end SPARK_Mode_Of;
--------------------------
-- SPARK_Mode_Of_Entity --
--------------------------
function SPARK_Mode_Of_Entity
(Id : Entity_Id) return Extended_SPARK_Mode
is
Prag : constant Node_Id := SPARK_Pragma (Id);
begin
return
To_SPARK_Mode
(Present (Prag)
and then Get_SPARK_Mode_From_Annotation (Prag) = On);
end SPARK_Mode_Of_Entity;
------------------------
-- SPARK_Mode_Of_Node --
------------------------
function SPARK_Mode_Of_Node (N : Node_Id) return Extended_SPARK_Mode is
begin
return To_SPARK_Mode (Is_SPARK_Mode_On_Node (N));
end SPARK_Mode_Of_Node;
----------------------
-- Spec_Declaration --
----------------------
function Spec_Declaration (T_Id : Target_Rep_Id) return Node_Id is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Spec_Decl;
end Spec_Declaration;
------------
-- Target --
------------
function Target (S_Id : Scenario_Rep_Id) return Entity_Id is
pragma Assert (Present (S_Id));
begin
return Scenario_Reps.Table (S_Id).Target;
end Target;
------------------------------
-- Target_Representation_Of --
------------------------------
function Target_Representation_Of
(Id : Entity_Id;
In_State : Processing_In_State) return Target_Rep_Id
is
T_Id : Target_Rep_Id;
begin
T_Id := ETT_Map.Get (Entity_To_Target_Map, Id);
-- The elaboration target lacks an internal representation. This
-- indicates that the target is encountered for the first time.
-- Create the internal representation of it.
if not Present (T_Id) then
Target_Reps.Append (Create_Target_Rep (Id, In_State));
T_Id := Target_Reps.Last;
-- Associate the internal representation with the elaboration
-- target.
ETT_Map.Put (Entity_To_Target_Map, Id, T_Id);
-- The Processing phase is working with a partially analyzed tree,
-- where various attributes become available as analysis continues.
-- This case arrises in the context of guaranteed ABE processing.
-- Update the existing representation by including new attributes.
elsif In_State.Representation = Inconsistent_Representation then
Target_Reps.Table (T_Id) := Create_Target_Rep (Id, In_State);
-- Otherwise the Processing phase imposes a particular representation
-- version which is not satisfied by the target. This case arrises
-- when the Processing phase switches from guaranteed ABE checks and
-- diagnostics to some other mode of operation. Update the existing
-- representation to include all attributes.
elsif In_State.Representation /= Version (T_Id) then
Target_Reps.Table (T_Id) := Create_Target_Rep (Id, In_State);
end if;
pragma Assert (Present (T_Id));
return T_Id;
end Target_Representation_Of;
-------------------
-- To_Ghost_Mode --
-------------------
function To_Ghost_Mode
(Ignored_Status : Boolean) return Extended_Ghost_Mode
is
begin
if Ignored_Status then
return Is_Ignored;
else
return Is_Checked_Or_Not_Specified;
end if;
end To_Ghost_Mode;
-------------------
-- To_SPARK_Mode --
-------------------
function To_SPARK_Mode
(On_Status : Boolean) return Extended_SPARK_Mode
is
begin
if On_Status then
return Is_On;
else
return Is_Off_Or_Not_Specified;
end if;
end To_SPARK_Mode;
----------
-- Unit --
----------
function Unit (T_Id : Target_Rep_Id) return Entity_Id is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Unit;
end Unit;
--------------------------
-- Variable_Declaration --
--------------------------
function Variable_Declaration (T_Id : Target_Rep_Id) return Node_Id is
pragma Assert (Present (T_Id));
pragma Assert (Kind (T_Id) = Variable_Target);
begin
return Target_Reps.Table (T_Id).Field_1;
end Variable_Declaration;
-------------
-- Version --
-------------
function Version (T_Id : Target_Rep_Id) return Representation_Kind is
pragma Assert (Present (T_Id));
begin
return Target_Reps.Table (T_Id).Version;
end Version;
end Internal_Representation;
----------------------
-- Invocation_Graph --
----------------------
package body Invocation_Graph is
-----------
-- Types --
-----------
-- The following type represents simplified version of an invocation
-- relation.
type Invoker_Target_Relation is record
Invoker : Entity_Id := Empty;
Target : Entity_Id := Empty;
end record;
-- The following variables define the entities of the dummy elaboration
-- procedures used as origins of library level paths.
Elab_Body_Id : Entity_Id := Empty;
Elab_Spec_Id : Entity_Id := Empty;
---------------------
-- Data structures --
---------------------
-- The following set contains all declared invocation constructs. It
-- ensures that the same construct is not declared multiple times in
-- the ALI file of the main unit.
Saved_Constructs_Set : NE_Set.Membership_Set := NE_Set.Nil;
function Hash (Key : Invoker_Target_Relation) return Bucket_Range_Type;
-- Obtain the hash value of pair Key
package IR_Set is new Membership_Sets
(Element_Type => Invoker_Target_Relation,
"=" => "=",
Hash => Hash);
-- The following set contains all recorded simple invocation relations.
-- It ensures that multiple relations involving the same invoker and
-- target do not appear in the ALI file of the main unit.
Saved_Relations_Set : IR_Set.Membership_Set := IR_Set.Nil;
--------------
-- Builders --
--------------
function Signature_Of (Id : Entity_Id) return Invocation_Signature_Id;
pragma Inline (Signature_Of);
-- Obtain the invication signature id of arbitrary entity Id
-----------------------
-- Local subprograms --
-----------------------
procedure Build_Elaborate_Body_Procedure;
pragma Inline (Build_Elaborate_Body_Procedure);
-- Create a dummy elaborate body procedure and store its entity in
-- Elab_Body_Id.
procedure Build_Elaborate_Procedure
(Proc_Id : out Entity_Id;
Proc_Nam : Name_Id;
Loc : Source_Ptr);
pragma Inline (Build_Elaborate_Procedure);
-- Create a dummy elaborate procedure with name Proc_Nam and source
-- location Loc. The entity is returned in Proc_Id.
procedure Build_Elaborate_Spec_Procedure;
pragma Inline (Build_Elaborate_Spec_Procedure);
-- Create a dummy elaborate spec procedure and store its entity in
-- Elab_Spec_Id.
function Build_Subprogram_Invocation
(Subp_Id : Entity_Id) return Node_Id;
pragma Inline (Build_Subprogram_Invocation);
-- Create a dummy call marker that invokes subprogram Subp_Id
function Build_Task_Activation
(Task_Typ : Entity_Id;
In_State : Processing_In_State) return Node_Id;
pragma Inline (Build_Task_Activation);
-- Create a dummy call marker that activates an anonymous task object of
-- type Task_Typ.
procedure Declare_Invocation_Construct
(Constr_Id : Entity_Id;
In_State : Processing_In_State);
pragma Inline (Declare_Invocation_Construct);
-- Declare invocation construct Constr_Id by creating a declaration for
-- it in the ALI file of the main unit. In_State is the current state of
-- the Processing phase.
function Invocation_Graph_Recording_OK return Boolean;
pragma Inline (Invocation_Graph_Recording_OK);
-- Determine whether the invocation graph can be recorded
function Is_Invocation_Scenario (N : Node_Id) return Boolean;
pragma Inline (Is_Invocation_Scenario);
-- Determine whether node N is a suitable scenario for invocation graph
-- recording purposes.
function Is_Invocation_Target (Id : Entity_Id) return Boolean;
pragma Inline (Is_Invocation_Target);
-- Determine whether arbitrary entity Id denotes an invocation target
function Is_Saved_Construct (Constr : Entity_Id) return Boolean;
pragma Inline (Is_Saved_Construct);
-- Determine whether invocation construct Constr has already been
-- declared in the ALI file of the main unit.
function Is_Saved_Relation
(Rel : Invoker_Target_Relation) return Boolean;
pragma Inline (Is_Saved_Relation);
-- Determine whether simple invocation relation Rel has already been
-- recorded in the ALI file of the main unit.
procedure Process_Declarations
(Decls : List_Id;
In_State : Processing_In_State);
pragma Inline (Process_Declarations);
-- Process declaration list Decls by processing all invocation scenarios
-- within it.
procedure Process_Freeze_Node
(Fnode : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Freeze_Node);
-- Process freeze node Fnode by processing all invocation scenarios in
-- its Actions list.
procedure Process_Invocation_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Activation);
-- Process activation call Call which activates object Obj_Id of task
-- type Task_Typ by processing all invocation scenarios within the task
-- body. Call_Rep is the representation of the call. Obj_Rep denotes the
-- representation of the object. Task_Rep is the representation of the
-- task type. In_State is the current state of the Processing phase.
procedure Process_Invocation_Body_Scenarios;
pragma Inline (Process_Invocation_Body_Scenarios);
-- Process all library level body scenarios
procedure Process_Invocation_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Call);
-- Process invocation call scenario Call with representation Call_Rep.
-- In_State is the current state of the Processing phase.
procedure Process_Invocation_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Instantiation);
-- Process invocation instantiation scenario Inst with representation
-- Inst_Rep. In_State is the current state of the Processing phase.
procedure Process_Invocation_Scenario
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Scenario);
-- Process single invocation scenario N. In_State is the current state
-- of the Processing phase.
procedure Process_Invocation_Scenarios
(Iter : in out NE_Set.Iterator;
In_State : Processing_In_State);
pragma Inline (Process_Invocation_Scenarios);
-- Process all invocation scenarios obtained via iterator Iter. In_State
-- is the current state of the Processing phase.
procedure Process_Invocation_Spec_Scenarios;
pragma Inline (Process_Invocation_Spec_Scenarios);
-- Process all library level spec scenarios
procedure Process_Main_Unit;
pragma Inline (Process_Main_Unit);
-- Process all invocation scenarios within the main unit
procedure Process_Package_Declaration
(Pack_Decl : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Package_Declaration);
-- Process package declaration Pack_Decl by processing all invocation
-- scenarios in its visible and private declarations. If the main unit
-- contains a generic, the declarations of the body are also examined.
-- In_State is the current state of the Processing phase.
procedure Process_Protected_Type_Declaration
(Prot_Decl : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Protected_Type_Declaration);
-- Process the declarations of protected type Prot_Decl. In_State is the
-- current state of the Processing phase.
procedure Process_Subprogram_Declaration
(Subp_Decl : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Subprogram_Declaration);
-- Process subprogram declaration Subp_Decl by processing all invocation
-- scenarios within its body. In_State denotes the current state of the
-- Processing phase.
procedure Process_Subprogram_Instantiation
(Inst : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Subprogram_Instantiation);
-- Process subprogram instantiation Inst. In_State is the current state
-- of the Processing phase.
procedure Process_Task_Type_Declaration
(Task_Decl : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_Task_Type_Declaration);
-- Process task declaration Task_Decl by processing all invocation
-- scenarios within its body. In_State is the current state of the
-- Processing phase.
procedure Record_Full_Invocation_Path (In_State : Processing_In_State);
pragma Inline (Record_Full_Invocation_Path);
-- Record all relations between scenario pairs found in the stack of
-- active scenarios. In_State is the current state of the Processing
-- phase.
procedure Record_Invocation_Graph_Encoding;
pragma Inline (Record_Invocation_Graph_Encoding);
-- Record the encoding format used to capture information related to
-- invocation constructs and relations.
procedure Record_Invocation_Path (In_State : Processing_In_State);
pragma Inline (Record_Invocation_Path);
-- Record the invocation relations found within the path represented in
-- the active scenario stack. In_State denotes the current state of the
-- Processing phase.
procedure Record_Simple_Invocation_Path (In_State : Processing_In_State);
pragma Inline (Record_Simple_Invocation_Path);
-- Record a single relation from the start to the end of the stack of
-- active scenarios. In_State is the current state of the Processing
-- phase.
procedure Record_Invocation_Relation
(Invk_Id : Entity_Id;
Targ_Id : Entity_Id;
In_State : Processing_In_State);
pragma Inline (Record_Invocation_Relation);
-- Record an invocation relation with invoker Invk_Id and target Targ_Id
-- by creating an entry for it in the ALI file of the main unit. Formal
-- In_State denotes the current state of the Processing phase.
procedure Set_Is_Saved_Construct
(Constr : Entity_Id;
Val : Boolean := True);
pragma Inline (Set_Is_Saved_Construct);
-- Mark invocation construct Constr as declared in the ALI file of the
-- main unit depending on value Val.
procedure Set_Is_Saved_Relation
(Rel : Invoker_Target_Relation;
Val : Boolean := True);
pragma Inline (Set_Is_Saved_Relation);
-- Mark simple invocation relation Rel as recorded in the ALI file of
-- the main unit depending on value Val.
function Target_Of
(Pos : Active_Scenario_Pos;
In_State : Processing_In_State) return Entity_Id;
pragma Inline (Target_Of);
-- Given position within the active scenario stack Pos, obtain the
-- target of the indicated scenario. In_State is the current state
-- of the Processing phase.
procedure Traverse_Invocation_Body
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Traverse_Invocation_Body);
-- Traverse subprogram body N looking for suitable invocation scenarios
-- that need to be processed for invocation graph recording purposes.
-- In_State is the current state of the Processing phase.
procedure Write_Invocation_Path (In_State : Processing_In_State);
pragma Inline (Write_Invocation_Path);
-- Write out a path represented by the active scenario on the stack to
-- standard output. In_State denotes the current state of the Processing
-- phase.
------------------------------------
-- Build_Elaborate_Body_Procedure --
------------------------------------
procedure Build_Elaborate_Body_Procedure is
Body_Decl : Node_Id;
Spec_Decl : Node_Id;
begin
-- Nothing to do when a previous call already created the procedure
if Present (Elab_Body_Id) then
return;
end if;
Spec_And_Body_From_Entity
(Id => Main_Unit_Entity,
Body_Decl => Body_Decl,
Spec_Decl => Spec_Decl);
pragma Assert (Present (Body_Decl));
Build_Elaborate_Procedure
(Proc_Id => Elab_Body_Id,
Proc_Nam => Name_B,
Loc => Sloc (Body_Decl));
end Build_Elaborate_Body_Procedure;
-------------------------------
-- Build_Elaborate_Procedure --
-------------------------------
procedure Build_Elaborate_Procedure
(Proc_Id : out Entity_Id;
Proc_Nam : Name_Id;
Loc : Source_Ptr)
is
Proc_Decl : Node_Id;
pragma Unreferenced (Proc_Decl);
begin
Proc_Id := Make_Defining_Identifier (Loc, Proc_Nam);
-- Partially decorate the elaboration procedure because it will not
-- be insertred into the tree and analyzed.
Set_Ekind (Proc_Id, E_Procedure);
Set_Etype (Proc_Id, Standard_Void_Type);
Set_Scope (Proc_Id, Unique_Entity (Main_Unit_Entity));
-- Create a dummy declaration for the elaboration procedure. The
-- declaration does not need to be syntactically legal, but must
-- carry an accurate source location.
Proc_Decl :=
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Proc_Id),
Declarations => No_List,
Handled_Statement_Sequence => Empty);
end Build_Elaborate_Procedure;
------------------------------------
-- Build_Elaborate_Spec_Procedure --
------------------------------------
procedure Build_Elaborate_Spec_Procedure is
Body_Decl : Node_Id;
Spec_Decl : Node_Id;
begin
-- Nothing to do when a previous call already created the procedure
if Present (Elab_Spec_Id) then
return;
end if;
Spec_And_Body_From_Entity
(Id => Main_Unit_Entity,
Body_Decl => Body_Decl,
Spec_Decl => Spec_Decl);
pragma Assert (Present (Spec_Decl));
Build_Elaborate_Procedure
(Proc_Id => Elab_Spec_Id,
Proc_Nam => Name_S,
Loc => Sloc (Spec_Decl));
end Build_Elaborate_Spec_Procedure;
---------------------------------
-- Build_Subprogram_Invocation --
---------------------------------
function Build_Subprogram_Invocation
(Subp_Id : Entity_Id) return Node_Id
is
Marker : constant Node_Id := Make_Call_Marker (Sloc (Subp_Id));
Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
begin
-- Create a dummy call marker which invokes the subprogram
Set_Is_Declaration_Level_Node (Marker, False);
Set_Is_Dispatching_Call (Marker, False);
Set_Is_Elaboration_Checks_OK_Node (Marker, False);
Set_Is_Elaboration_Warnings_OK_Node (Marker, False);
Set_Is_Ignored_Ghost_Node (Marker, False);
Set_Is_Preelaborable_Call (Marker, False);
Set_Is_Source_Call (Marker, False);
Set_Is_SPARK_Mode_On_Node (Marker, False);
-- Invoke the uniform canonical entity of the subprogram
Set_Target (Marker, Canonical_Subprogram (Subp_Id));
-- Partially insert the marker into the tree
Set_Parent (Marker, Parent (Subp_Decl));
return Marker;
end Build_Subprogram_Invocation;
---------------------------
-- Build_Task_Activation --
---------------------------
function Build_Task_Activation
(Task_Typ : Entity_Id;
In_State : Processing_In_State) return Node_Id
is
Loc : constant Source_Ptr := Sloc (Task_Typ);
Marker : constant Node_Id := Make_Call_Marker (Loc);
Task_Decl : constant Node_Id := Unit_Declaration_Node (Task_Typ);
Activ_Id : Entity_Id;
Marker_Rep_Id : Scenario_Rep_Id;
Task_Obj : Entity_Id;
Task_Objs : NE_List.Doubly_Linked_List;
begin
-- Create a dummy call marker which activates some tasks
Set_Is_Declaration_Level_Node (Marker, False);
Set_Is_Dispatching_Call (Marker, False);
Set_Is_Elaboration_Checks_OK_Node (Marker, False);
Set_Is_Elaboration_Warnings_OK_Node (Marker, False);
Set_Is_Ignored_Ghost_Node (Marker, False);
Set_Is_Preelaborable_Call (Marker, False);
Set_Is_Source_Call (Marker, False);
Set_Is_SPARK_Mode_On_Node (Marker, False);
-- Invoke the appropriate version of Activate_Tasks
if Restricted_Profile then
Activ_Id := RTE (RE_Activate_Restricted_Tasks);
else
Activ_Id := RTE (RE_Activate_Tasks);
end if;
Set_Target (Marker, Activ_Id);
-- Partially insert the marker into the tree
Set_Parent (Marker, Parent (Task_Decl));
-- Create a dummy task object. Partially decorate the object because
-- it will not be inserted into the tree and analyzed.
Task_Obj := Make_Temporary (Loc, 'T');
Set_Ekind (Task_Obj, E_Variable);
Set_Etype (Task_Obj, Task_Typ);
-- Associate the dummy task object with the activation call
Task_Objs := NE_List.Create;
NE_List.Append (Task_Objs, Task_Obj);
Marker_Rep_Id := Scenario_Representation_Of (Marker, In_State);
Set_Activated_Task_Objects (Marker_Rep_Id, Task_Objs);
Set_Activated_Task_Type (Marker_Rep_Id, Task_Typ);
return Marker;
end Build_Task_Activation;
----------------------------------
-- Declare_Invocation_Construct --
----------------------------------
procedure Declare_Invocation_Construct
(Constr_Id : Entity_Id;
In_State : Processing_In_State)
is
function Body_Placement_Of
(Id : Entity_Id) return Declaration_Placement_Kind;
pragma Inline (Body_Placement_Of);
-- Obtain the placement of arbitrary entity Id's body
function Declaration_Placement_Of_Node
(N : Node_Id) return Declaration_Placement_Kind;
pragma Inline (Declaration_Placement_Of_Node);
-- Obtain the placement of arbitrary node N
function Kind_Of (Id : Entity_Id) return Invocation_Construct_Kind;
pragma Inline (Kind_Of);
-- Obtain the invocation construct kind of arbitrary entity Id
function Spec_Placement_Of
(Id : Entity_Id) return Declaration_Placement_Kind;
pragma Inline (Spec_Placement_Of);
-- Obtain the placement of arbitrary entity Id's spec
-----------------------
-- Body_Placement_Of --
-----------------------
function Body_Placement_Of
(Id : Entity_Id) return Declaration_Placement_Kind
is
Id_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Id_Rep);
Spec_Decl : constant Node_Id := Spec_Declaration (Id_Rep);
begin
-- The entity has a body
if Present (Body_Decl) then
return Declaration_Placement_Of_Node (Body_Decl);
-- Otherwise the entity must have a spec
else
pragma Assert (Present (Spec_Decl));
return Declaration_Placement_Of_Node (Spec_Decl);
end if;
end Body_Placement_Of;
-----------------------------------
-- Declaration_Placement_Of_Node --
-----------------------------------
function Declaration_Placement_Of_Node
(N : Node_Id) return Declaration_Placement_Kind
is
Main_Unit_Id : constant Entity_Id := Main_Unit_Entity;
N_Unit_Id : constant Entity_Id := Find_Top_Unit (N);
begin
-- The node is in the main unit, its placement depends on the main
-- unit kind.
if N_Unit_Id = Main_Unit_Id then
-- The main unit is a body
if Ekind (Main_Unit_Id) in E_Package_Body | E_Subprogram_Body
then
return In_Body;
-- The main unit is a stand-alone subprogram body
elsif Ekind (Main_Unit_Id) in E_Function | E_Procedure
and then Nkind (Unit_Declaration_Node (Main_Unit_Id)) =
N_Subprogram_Body
then
return In_Body;
-- Otherwise the main unit is a spec
else
return In_Spec;
end if;
-- Otherwise the node is in the complementary unit of the main
-- unit. The main unit is a body, the node is in the spec.
elsif Ekind (Main_Unit_Id) in E_Package_Body | E_Subprogram_Body
then
return In_Spec;
-- The main unit is a spec, the node is in the body
else
return In_Body;
end if;
end Declaration_Placement_Of_Node;
-------------
-- Kind_Of --
-------------
function Kind_Of (Id : Entity_Id) return Invocation_Construct_Kind is
begin
if Id = Elab_Body_Id then
return Elaborate_Body_Procedure;
elsif Id = Elab_Spec_Id then
return Elaborate_Spec_Procedure;
else
return Regular_Construct;
end if;
end Kind_Of;
-----------------------
-- Spec_Placement_Of --
-----------------------
function Spec_Placement_Of
(Id : Entity_Id) return Declaration_Placement_Kind
is
Id_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Id_Rep);
Spec_Decl : constant Node_Id := Spec_Declaration (Id_Rep);
begin
-- The entity has a spec
if Present (Spec_Decl) then
return Declaration_Placement_Of_Node (Spec_Decl);
-- Otherwise the entity must have a body
else
pragma Assert (Present (Body_Decl));
return Declaration_Placement_Of_Node (Body_Decl);
end if;
end Spec_Placement_Of;
-- Start of processing for Declare_Invocation_Construct
begin
-- Nothing to do when the construct has already been declared in the
-- ALI file.
if Is_Saved_Construct (Constr_Id) then
return;
end if;
-- Mark the construct as declared in the ALI file
Set_Is_Saved_Construct (Constr_Id);
-- Add the construct in the ALI file
Add_Invocation_Construct
(Body_Placement => Body_Placement_Of (Constr_Id),
Kind => Kind_Of (Constr_Id),
Signature => Signature_Of (Constr_Id),
Spec_Placement => Spec_Placement_Of (Constr_Id),
Update_Units => False);
end Declare_Invocation_Construct;
-------------------------------
-- Finalize_Invocation_Graph --
-------------------------------
procedure Finalize_Invocation_Graph is
begin
NE_Set.Destroy (Saved_Constructs_Set);
IR_Set.Destroy (Saved_Relations_Set);
end Finalize_Invocation_Graph;
----------
-- Hash --
----------
function Hash (Key : Invoker_Target_Relation) return Bucket_Range_Type is
pragma Assert (Present (Key.Invoker));
pragma Assert (Present (Key.Target));
begin
return
Hash_Two_Keys
(Bucket_Range_Type (Key.Invoker),
Bucket_Range_Type (Key.Target));
end Hash;
---------------------------------
-- Initialize_Invocation_Graph --
---------------------------------
procedure Initialize_Invocation_Graph is
begin
Saved_Constructs_Set := NE_Set.Create (100);
Saved_Relations_Set := IR_Set.Create (200);
end Initialize_Invocation_Graph;
-----------------------------------
-- Invocation_Graph_Recording_OK --
-----------------------------------
function Invocation_Graph_Recording_OK return Boolean is
Main_Cunit : constant Node_Id := Cunit (Main_Unit);
begin
-- Nothing to do when compiling for GNATprove because the invocation
-- graph is not needed.
if GNATprove_Mode then
return False;
-- Nothing to do when the compilation will not produce an ALI file
elsif Serious_Errors_Detected > 0 then
return False;
-- Nothing to do when the main unit requires a body. Processing the
-- completing body will create the ALI file for the unit and record
-- the invocation graph.
elsif Body_Required (Main_Cunit) then
return False;
end if;
return True;
end Invocation_Graph_Recording_OK;
----------------------------
-- Is_Invocation_Scenario --
----------------------------
function Is_Invocation_Scenario (N : Node_Id) return Boolean is
begin
return
Is_Suitable_Access_Taken (N)
or else Is_Suitable_Call (N)
or else Is_Suitable_Instantiation (N);
end Is_Invocation_Scenario;
--------------------------
-- Is_Invocation_Target --
--------------------------
function Is_Invocation_Target (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must either come from source, or denote an
-- Ada, bridge, or SPARK target.
return
Comes_From_Source (Id)
or else Is_Ada_Semantic_Target (Id)
or else Is_Bridge_Target (Id)
or else Is_SPARK_Semantic_Target (Id);
end Is_Invocation_Target;
------------------------
-- Is_Saved_Construct --
------------------------
function Is_Saved_Construct (Constr : Entity_Id) return Boolean is
pragma Assert (Present (Constr));
begin
return NE_Set.Contains (Saved_Constructs_Set, Constr);
end Is_Saved_Construct;
-----------------------
-- Is_Saved_Relation --
-----------------------
function Is_Saved_Relation
(Rel : Invoker_Target_Relation) return Boolean
is
pragma Assert (Present (Rel.Invoker));
pragma Assert (Present (Rel.Target));
begin
return IR_Set.Contains (Saved_Relations_Set, Rel);
end Is_Saved_Relation;
--------------------------
-- Process_Declarations --
--------------------------
procedure Process_Declarations
(Decls : List_Id;
In_State : Processing_In_State)
is
Decl : Node_Id;
begin
Decl := First (Decls);
while Present (Decl) loop
-- Freeze node
if Nkind (Decl) = N_Freeze_Entity then
Process_Freeze_Node
(Fnode => Decl,
In_State => In_State);
-- Package (nested)
elsif Nkind (Decl) = N_Package_Declaration then
Process_Package_Declaration
(Pack_Decl => Decl,
In_State => In_State);
-- Protected type
elsif Nkind (Decl) in N_Protected_Type_Declaration
| N_Single_Protected_Declaration
then
Process_Protected_Type_Declaration
(Prot_Decl => Decl,
In_State => In_State);
-- Subprogram or entry
elsif Nkind (Decl) in N_Entry_Declaration
| N_Subprogram_Declaration
then
Process_Subprogram_Declaration
(Subp_Decl => Decl,
In_State => In_State);
-- Subprogram body (stand alone)
elsif Nkind (Decl) = N_Subprogram_Body
and then No (Corresponding_Spec (Decl))
then
Process_Subprogram_Declaration
(Subp_Decl => Decl,
In_State => In_State);
-- Subprogram instantiation
elsif Nkind (Decl) in N_Subprogram_Instantiation then
Process_Subprogram_Instantiation
(Inst => Decl,
In_State => In_State);
-- Task type
elsif Nkind (Decl) in N_Single_Task_Declaration
| N_Task_Type_Declaration
then
Process_Task_Type_Declaration
(Task_Decl => Decl,
In_State => In_State);
-- Task type (derived)
elsif Nkind (Decl) = N_Full_Type_Declaration
and then Is_Task_Type (Defining_Entity (Decl))
then
Process_Task_Type_Declaration
(Task_Decl => Decl,
In_State => In_State);
end if;
Next (Decl);
end loop;
end Process_Declarations;
-------------------------
-- Process_Freeze_Node --
-------------------------
procedure Process_Freeze_Node
(Fnode : Node_Id;
In_State : Processing_In_State)
is
begin
Process_Declarations
(Decls => Actions (Fnode),
In_State => In_State);
end Process_Freeze_Node;
-----------------------------------
-- Process_Invocation_Activation --
-----------------------------------
procedure Process_Invocation_Activation
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
Obj_Id : Entity_Id;
Obj_Rep : Target_Rep_Id;
Task_Typ : Entity_Id;
Task_Rep : Target_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Call);
pragma Unreferenced (Call_Rep);
pragma Unreferenced (Obj_Id);
pragma Unreferenced (Obj_Rep);
begin
-- Nothing to do when the task type appears within an internal unit
if In_Internal_Unit (Task_Typ) then
return;
end if;
-- The task type being activated is within the main unit. Extend the
-- DFS traversal into its body.
if In_Extended_Main_Code_Unit (Task_Typ) then
Traverse_Invocation_Body
(N => Body_Declaration (Task_Rep),
In_State => In_State);
-- The task type being activated resides within an external unit
--
-- Main unit External unit
-- +-----------+ +-------------+
-- | | | |
-- | Start ------------> Task_Typ |
-- | | | |
-- +-----------+ +-------------+
--
-- Record the invocation path which originates from Start and reaches
-- the task type.
else
Record_Invocation_Path (In_State);
end if;
end Process_Invocation_Activation;
---------------------------------------
-- Process_Invocation_Body_Scenarios --
---------------------------------------
procedure Process_Invocation_Body_Scenarios is
Iter : NE_Set.Iterator := Iterate_Library_Body_Scenarios;
begin
Process_Invocation_Scenarios
(Iter => Iter,
In_State => Invocation_Body_State);
end Process_Invocation_Body_Scenarios;
-----------------------------
-- Process_Invocation_Call --
-----------------------------
procedure Process_Invocation_Call
(Call : Node_Id;
Call_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Call);
Subp_Id : constant Entity_Id := Target (Call_Rep);
Subp_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Subp_Id, In_State);
begin
-- Nothing to do when the subprogram appears within an internal unit
if In_Internal_Unit (Subp_Id) then
return;
-- Nothing to do for an abstract subprogram because it has no body to
-- examine.
elsif Ekind (Subp_Id) in E_Function | E_Procedure
and then Is_Abstract_Subprogram (Subp_Id)
then
return;
-- Nothin to do for a formal subprogram because it has no body to
-- examine.
elsif Is_Formal_Subprogram (Subp_Id) then
return;
end if;
-- The subprogram being called is within the main unit. Extend the
-- DFS traversal into its barrier function and body.
if In_Extended_Main_Code_Unit (Subp_Id) then
if Ekind (Subp_Id) in E_Entry | E_Entry_Family | E_Procedure then
Traverse_Invocation_Body
(N => Barrier_Body_Declaration (Subp_Rep),
In_State => In_State);
end if;
Traverse_Invocation_Body
(N => Body_Declaration (Subp_Rep),
In_State => In_State);
-- The subprogram being called resides within an external unit
--
-- Main unit External unit
-- +-----------+ +-------------+
-- | | | |
-- | Start ------------> Subp_Id |
-- | | | |
-- +-----------+ +-------------+
--
-- Record the invocation path which originates from Start and reaches
-- the subprogram.
else
Record_Invocation_Path (In_State);
end if;
end Process_Invocation_Call;
--------------------------------------
-- Process_Invocation_Instantiation --
--------------------------------------
procedure Process_Invocation_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Inst);
Gen_Id : constant Entity_Id := Target (Inst_Rep);
begin
-- Nothing to do when the generic appears within an internal unit
if In_Internal_Unit (Gen_Id) then
return;
end if;
-- The generic being instantiated resides within an external unit
--
-- Main unit External unit
-- +-----------+ +-------------+
-- | | | |
-- | Start ------------> Generic |
-- | | | |
-- +-----------+ +-------------+
--
-- Record the invocation path which originates from Start and reaches
-- the generic.
if not In_Extended_Main_Code_Unit (Gen_Id) then
Record_Invocation_Path (In_State);
end if;
end Process_Invocation_Instantiation;
---------------------------------
-- Process_Invocation_Scenario --
---------------------------------
procedure Process_Invocation_Scenario
(N : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
Scen_Rep : Scenario_Rep_Id;
begin
-- Add the current scenario to the stack of active scenarios
Push_Active_Scenario (Scen);
-- Call or task activation
if Is_Suitable_Call (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
-- Routine Build_Call_Marker creates call markers regardless of
-- whether the call occurs within the main unit or not. This way
-- the serialization of internal names is kept consistent. Only
-- call markers found within the main unit must be processed.
if In_Main_Context (Scen) then
Scen_Rep := Scenario_Representation_Of (Scen, In_State);
if Kind (Scen_Rep) = Call_Scenario then
Process_Invocation_Call
(Call => Scen,
Call_Rep => Scen_Rep,
In_State => In_State);
else
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario);
Process_Activation
(Call => Scen,
Call_Rep => Scen_Rep,
Processor => Process_Invocation_Activation'Access,
In_State => In_State);
end if;
end if;
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Process_Invocation_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
end if;
-- Remove the current scenario from the stack of active scenarios
-- once all invocation constructs and paths have been saved.
Pop_Active_Scenario (Scen);
end Process_Invocation_Scenario;
----------------------------------
-- Process_Invocation_Scenarios --
----------------------------------
procedure Process_Invocation_Scenarios
(Iter : in out NE_Set.Iterator;
In_State : Processing_In_State)
is
N : Node_Id;
begin
while NE_Set.Has_Next (Iter) loop
NE_Set.Next (Iter, N);
-- Reset the traversed status of all subprogram bodies because the
-- current invocation scenario acts as a new DFS traversal root.
Reset_Traversed_Bodies;
Process_Invocation_Scenario (N, In_State);
end loop;
end Process_Invocation_Scenarios;
---------------------------------------
-- Process_Invocation_Spec_Scenarios --
---------------------------------------
procedure Process_Invocation_Spec_Scenarios is
Iter : NE_Set.Iterator := Iterate_Library_Spec_Scenarios;
begin
Process_Invocation_Scenarios
(Iter => Iter,
In_State => Invocation_Spec_State);
end Process_Invocation_Spec_Scenarios;
-----------------------
-- Process_Main_Unit --
-----------------------
procedure Process_Main_Unit is
Unit_Decl : constant Node_Id := Unit (Cunit (Main_Unit));
Spec_Id : Entity_Id;
begin
-- The main unit is a [generic] package body
if Nkind (Unit_Decl) = N_Package_Body then
Spec_Id := Corresponding_Spec (Unit_Decl);
pragma Assert (Present (Spec_Id));
Process_Package_Declaration
(Pack_Decl => Unit_Declaration_Node (Spec_Id),
In_State => Invocation_Construct_State);
-- The main unit is a [generic] package declaration
elsif Nkind (Unit_Decl) = N_Package_Declaration then
Process_Package_Declaration
(Pack_Decl => Unit_Decl,
In_State => Invocation_Construct_State);
-- The main unit is a [generic] subprogram body
elsif Nkind (Unit_Decl) = N_Subprogram_Body then
Spec_Id := Corresponding_Spec (Unit_Decl);
-- The body completes a previous declaration
if Present (Spec_Id) then
Process_Subprogram_Declaration
(Subp_Decl => Unit_Declaration_Node (Spec_Id),
In_State => Invocation_Construct_State);
-- Otherwise the body is stand-alone
else
Process_Subprogram_Declaration
(Subp_Decl => Unit_Decl,
In_State => Invocation_Construct_State);
end if;
-- The main unit is a subprogram instantiation
elsif Nkind (Unit_Decl) in N_Subprogram_Instantiation then
Process_Subprogram_Instantiation
(Inst => Unit_Decl,
In_State => Invocation_Construct_State);
-- The main unit is an imported subprogram declaration
elsif Nkind (Unit_Decl) = N_Subprogram_Declaration then
Process_Subprogram_Declaration
(Subp_Decl => Unit_Decl,
In_State => Invocation_Construct_State);
end if;
end Process_Main_Unit;
---------------------------------
-- Process_Package_Declaration --
---------------------------------
procedure Process_Package_Declaration
(Pack_Decl : Node_Id;
In_State : Processing_In_State)
is
Body_Id : constant Entity_Id := Corresponding_Body (Pack_Decl);
Spec : constant Node_Id := Specification (Pack_Decl);
Spec_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
begin
-- Add a declaration for the generic package in the ALI of the main
-- unit in case a client unit instantiates it.
if Ekind (Spec_Id) = E_Generic_Package then
Declare_Invocation_Construct
(Constr_Id => Spec_Id,
In_State => In_State);
-- Otherwise inspect the visible and private declarations of the
-- package for invocation constructs.
else
Process_Declarations
(Decls => Visible_Declarations (Spec),
In_State => In_State);
Process_Declarations
(Decls => Private_Declarations (Spec),
In_State => In_State);
-- The package body containst at least one generic unit or an
-- inlinable subprogram. Such constructs may grant clients of
-- the main unit access to the private enclosing contexts of
-- the constructs. Process the main unit body to discover and
-- encode relevant invocation constructs and relations that
-- may ultimately reach an external unit.
if Present (Body_Id)
and then Save_Invocation_Graph_Of_Body (Cunit (Main_Unit))
then
Process_Declarations
(Decls => Declarations (Unit_Declaration_Node (Body_Id)),
In_State => In_State);
end if;
end if;
end Process_Package_Declaration;
----------------------------------------
-- Process_Protected_Type_Declaration --
----------------------------------------
procedure Process_Protected_Type_Declaration
(Prot_Decl : Node_Id;
In_State : Processing_In_State)
is
Prot_Def : constant Node_Id := Protected_Definition (Prot_Decl);
begin
if Present (Prot_Def) then
Process_Declarations
(Decls => Visible_Declarations (Prot_Def),
In_State => In_State);
end if;
end Process_Protected_Type_Declaration;
------------------------------------
-- Process_Subprogram_Declaration --
------------------------------------
procedure Process_Subprogram_Declaration
(Subp_Decl : Node_Id;
In_State : Processing_In_State)
is
Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl);
begin
-- Nothing to do when the subprogram is not an invocation target
if not Is_Invocation_Target (Subp_Id) then
return;
end if;
-- Add a declaration for the subprogram in the ALI file of the main
-- unit in case a client unit calls or instantiates it.
Declare_Invocation_Construct
(Constr_Id => Subp_Id,
In_State => In_State);
-- Do not process subprograms without a body because they do not
-- contain any invocation scenarios.
if Is_Bodiless_Subprogram (Subp_Id) then
null;
-- Do not process generic subprograms because generics must not be
-- examined.
elsif Is_Generic_Subprogram (Subp_Id) then
null;
-- Otherwise create a dummy scenario which calls the subprogram to
-- act as a root for a DFS traversal.
else
-- Reset the traversed status of all subprogram bodies because the
-- subprogram acts as a new DFS traversal root.
Reset_Traversed_Bodies;
Process_Invocation_Scenario
(N => Build_Subprogram_Invocation (Subp_Id),
In_State => In_State);
end if;
end Process_Subprogram_Declaration;
--------------------------------------
-- Process_Subprogram_Instantiation --
--------------------------------------
procedure Process_Subprogram_Instantiation
(Inst : Node_Id;
In_State : Processing_In_State)
is
begin
-- Add a declaration for the instantiation in the ALI file of the
-- main unit in case a client unit calls it.
Declare_Invocation_Construct
(Constr_Id => Defining_Entity (Inst),
In_State => In_State);
end Process_Subprogram_Instantiation;
-----------------------------------
-- Process_Task_Type_Declaration --
-----------------------------------
procedure Process_Task_Type_Declaration
(Task_Decl : Node_Id;
In_State : Processing_In_State)
is
Task_Typ : constant Entity_Id := Defining_Entity (Task_Decl);
Task_Def : Node_Id;
begin
-- Add a declaration for the task type the ALI file of the main unit
-- in case a client unit creates a task object and activates it.
Declare_Invocation_Construct
(Constr_Id => Task_Typ,
In_State => In_State);
-- Process the entries of the task type because they represent valid
-- entry points into the task body.
if Nkind (Task_Decl) in N_Single_Task_Declaration
| N_Task_Type_Declaration
then
Task_Def := Task_Definition (Task_Decl);
if Present (Task_Def) then
Process_Declarations
(Decls => Visible_Declarations (Task_Def),
In_State => In_State);
end if;
end if;
-- Reset the traversed status of all subprogram bodies because the
-- task type acts as a new DFS traversal root.
Reset_Traversed_Bodies;
-- Create a dummy scenario which activates an anonymous object of the
-- task type to acts as a root of a DFS traversal.
Process_Invocation_Scenario
(N => Build_Task_Activation (Task_Typ, In_State),
In_State => In_State);
end Process_Task_Type_Declaration;
---------------------------------
-- Record_Full_Invocation_Path --
---------------------------------
procedure Record_Full_Invocation_Path (In_State : Processing_In_State) is
package Scenarios renames Active_Scenario_Stack;
begin
-- The path originates from the elaboration of the body. Add an extra
-- relation from the elaboration body procedure to the first active
-- scenario.
if In_State.Processing = Invocation_Body_Processing then
Build_Elaborate_Body_Procedure;
Record_Invocation_Relation
(Invk_Id => Elab_Body_Id,
Targ_Id => Target_Of (Scenarios.First, In_State),
In_State => In_State);
-- The path originates from the elaboration of the spec. Add an extra
-- relation from the elaboration spec procedure to the first active
-- scenario.
elsif In_State.Processing = Invocation_Spec_Processing then
Build_Elaborate_Spec_Procedure;
Record_Invocation_Relation
(Invk_Id => Elab_Spec_Id,
Targ_Id => Target_Of (Scenarios.First, In_State),
In_State => In_State);
end if;
-- Record individual relations formed by pairs of scenarios
for Index in Scenarios.First .. Scenarios.Last - 1 loop
Record_Invocation_Relation
(Invk_Id => Target_Of (Index, In_State),
Targ_Id => Target_Of (Index + 1, In_State),
In_State => In_State);
end loop;
end Record_Full_Invocation_Path;
-----------------------------
-- Record_Invocation_Graph --
-----------------------------
procedure Record_Invocation_Graph is
begin
-- Nothing to do when the invocation graph is not recorded
if not Invocation_Graph_Recording_OK then
return;
end if;
-- Save the encoding format used to capture information about the
-- invocation constructs and relations in the ALI file of the main
-- unit.
Record_Invocation_Graph_Encoding;
-- Examine all library level invocation scenarios and perform DFS
-- traversals from each one. Encode a path in the ALI file of the
-- main unit if it reaches into an external unit.
Process_Invocation_Body_Scenarios;
Process_Invocation_Spec_Scenarios;
-- Examine all invocation constructs within the spec and body of the
-- main unit and perform DFS traversals from each one. Encode a path
-- in the ALI file of the main unit if it reaches into an external
-- unit.
Process_Main_Unit;
end Record_Invocation_Graph;
--------------------------------------
-- Record_Invocation_Graph_Encoding --
--------------------------------------
procedure Record_Invocation_Graph_Encoding is
Kind : Invocation_Graph_Encoding_Kind := No_Encoding;
begin
-- Switch -gnatd_F (encode full invocation paths in ALI files) is in
-- effect.
if Debug_Flag_Underscore_FF then
Kind := Full_Path_Encoding;
else
Kind := Endpoints_Encoding;
end if;
-- Save the encoding format in the ALI file of the main unit
Set_Invocation_Graph_Encoding
(Kind => Kind,
Update_Units => False);
end Record_Invocation_Graph_Encoding;
----------------------------
-- Record_Invocation_Path --
----------------------------
procedure Record_Invocation_Path (In_State : Processing_In_State) is
package Scenarios renames Active_Scenario_Stack;
begin
-- Save a path when the active scenario stack contains at least one
-- invocation scenario.
if Scenarios.Last - Scenarios.First < 0 then
return;
end if;
-- Register all relations in the path when switch -gnatd_F (encode
-- full invocation paths in ALI files) is in effect.
if Debug_Flag_Underscore_FF then
Record_Full_Invocation_Path (In_State);
-- Otherwise register a single relation
else
Record_Simple_Invocation_Path (In_State);
end if;
Write_Invocation_Path (In_State);
end Record_Invocation_Path;
--------------------------------
-- Record_Invocation_Relation --
--------------------------------
procedure Record_Invocation_Relation
(Invk_Id : Entity_Id;
Targ_Id : Entity_Id;
In_State : Processing_In_State)
is
pragma Assert (Present (Invk_Id));
pragma Assert (Present (Targ_Id));
procedure Get_Invocation_Attributes
(Extra : out Entity_Id;
Kind : out Invocation_Kind);
pragma Inline (Get_Invocation_Attributes);
-- Return the additional entity used in error diagnostics in Extra
-- and the invocation kind in Kind which pertain to the invocation
-- relation with invoker Invk_Id and target Targ_Id.
-------------------------------
-- Get_Invocation_Attributes --
-------------------------------
procedure Get_Invocation_Attributes
(Extra : out Entity_Id;
Kind : out Invocation_Kind)
is
Targ_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Targ_Id, In_State);
Spec_Decl : constant Node_Id := Spec_Declaration (Targ_Rep);
begin
-- Accept within a task body
if Is_Accept_Alternative_Proc (Targ_Id) then
Extra := Receiving_Entry (Targ_Id);
Kind := Accept_Alternative;
-- Activation of a task object
elsif Is_Activation_Proc (Targ_Id)
or else Is_Task_Type (Targ_Id)
then
Extra := Empty;
Kind := Task_Activation;
-- Controlled adjustment actions
elsif Is_Controlled_Proc (Targ_Id, Name_Adjust) then
Extra := First_Formal_Type (Targ_Id);
Kind := Controlled_Adjustment;
-- Controlled finalization actions
elsif Is_Controlled_Proc (Targ_Id, Name_Finalize)
or else Is_Finalizer_Proc (Targ_Id)
then
Extra := First_Formal_Type (Targ_Id);
Kind := Controlled_Finalization;
-- Controlled initialization actions
elsif Is_Controlled_Proc (Targ_Id, Name_Initialize) then
Extra := First_Formal_Type (Targ_Id);
Kind := Controlled_Initialization;
-- Default_Initial_Condition verification
elsif Is_Default_Initial_Condition_Proc (Targ_Id) then
Extra := First_Formal_Type (Targ_Id);
Kind := Default_Initial_Condition_Verification;
-- Initialization of object
elsif Is_Init_Proc (Targ_Id) then
Extra := First_Formal_Type (Targ_Id);
Kind := Type_Initialization;
-- Initial_Condition verification
elsif Is_Initial_Condition_Proc (Targ_Id) then
Extra := First_Formal_Type (Targ_Id);
Kind := Initial_Condition_Verification;
-- Instantiation
elsif Is_Generic_Unit (Targ_Id) then
Extra := Empty;
Kind := Instantiation;
-- Internal controlled adjustment actions
elsif Is_TSS (Targ_Id, TSS_Deep_Adjust) then
Extra := First_Formal_Type (Targ_Id);
Kind := Internal_Controlled_Adjustment;
-- Internal controlled finalization actions
elsif Is_TSS (Targ_Id, TSS_Deep_Finalize) then
Extra := First_Formal_Type (Targ_Id);
Kind := Internal_Controlled_Finalization;
-- Internal controlled initialization actions
elsif Is_TSS (Targ_Id, TSS_Deep_Initialize) then
Extra := First_Formal_Type (Targ_Id);
Kind := Internal_Controlled_Initialization;
-- Invariant verification
elsif Is_Invariant_Proc (Targ_Id)
or else Is_Partial_Invariant_Proc (Targ_Id)
then
Extra := First_Formal_Type (Targ_Id);
Kind := Invariant_Verification;
-- Postcondition verification
elsif Is_Postconditions_Proc (Targ_Id) then
Extra := Find_Enclosing_Scope (Spec_Decl);
Kind := Postcondition_Verification;
-- Protected entry call
elsif Is_Protected_Entry (Targ_Id) then
Extra := Empty;
Kind := Protected_Entry_Call;
-- Protected subprogram call
elsif Is_Protected_Subp (Targ_Id) then
Extra := Empty;
Kind := Protected_Subprogram_Call;
-- Task entry call
elsif Is_Task_Entry (Targ_Id) then
Extra := Empty;
Kind := Task_Entry_Call;
-- Entry, operator, or subprogram call. This case must come last
-- because most invocations above are variations of this case.
elsif Ekind (Targ_Id) in
E_Entry | E_Function | E_Operator | E_Procedure
then
Extra := Empty;
Kind := Call;
else
pragma Assert (False);
Extra := Empty;
Kind := No_Invocation;
end if;
end Get_Invocation_Attributes;
-- Local variables
Extra : Entity_Id;
Extra_Nam : Name_Id;
Kind : Invocation_Kind;
Rel : Invoker_Target_Relation;
-- Start of processing for Record_Invocation_Relation
begin
Rel.Invoker := Invk_Id;
Rel.Target := Targ_Id;
-- Nothing to do when the invocation relation has already been
-- recorded in ALI file of the main unit.
if Is_Saved_Relation (Rel) then
return;
end if;
-- Mark the relation as recorded in the ALI file
Set_Is_Saved_Relation (Rel);
-- Declare the invoker in the ALI file
Declare_Invocation_Construct
(Constr_Id => Invk_Id,
In_State => In_State);
-- Obtain the invocation-specific attributes of the relation
Get_Invocation_Attributes (Extra, Kind);
-- Certain invocations lack an extra entity used in error diagnostics
if Present (Extra) then
Extra_Nam := Chars (Extra);
else
Extra_Nam := No_Name;
end if;
-- Add the relation in the ALI file
Add_Invocation_Relation
(Extra => Extra_Nam,
Invoker => Signature_Of (Invk_Id),
Kind => Kind,
Target => Signature_Of (Targ_Id),
Update_Units => False);
end Record_Invocation_Relation;
-----------------------------------
-- Record_Simple_Invocation_Path --
-----------------------------------
procedure Record_Simple_Invocation_Path
(In_State : Processing_In_State)
is
package Scenarios renames Active_Scenario_Stack;
Last_Targ : constant Entity_Id :=
Target_Of (Scenarios.Last, In_State);
First_Targ : Entity_Id;
begin
-- The path originates from the elaboration of the body. Add an extra
-- relation from the elaboration body procedure to the first active
-- scenario.
if In_State.Processing = Invocation_Body_Processing then
Build_Elaborate_Body_Procedure;
First_Targ := Elab_Body_Id;
-- The path originates from the elaboration of the spec. Add an extra
-- relation from the elaboration spec procedure to the first active
-- scenario.
elsif In_State.Processing = Invocation_Spec_Processing then
Build_Elaborate_Spec_Procedure;
First_Targ := Elab_Spec_Id;
else
First_Targ := Target_Of (Scenarios.First, In_State);
end if;
-- Record a single relation from the first to the last scenario
if First_Targ /= Last_Targ then
Record_Invocation_Relation
(Invk_Id => First_Targ,
Targ_Id => Last_Targ,
In_State => In_State);
end if;
end Record_Simple_Invocation_Path;
----------------------------
-- Set_Is_Saved_Construct --
----------------------------
procedure Set_Is_Saved_Construct
(Constr : Entity_Id;
Val : Boolean := True)
is
pragma Assert (Present (Constr));
begin
if Val then
NE_Set.Insert (Saved_Constructs_Set, Constr);
else
NE_Set.Delete (Saved_Constructs_Set, Constr);
end if;
end Set_Is_Saved_Construct;
---------------------------
-- Set_Is_Saved_Relation --
---------------------------
procedure Set_Is_Saved_Relation
(Rel : Invoker_Target_Relation;
Val : Boolean := True)
is
begin
if Val then
IR_Set.Insert (Saved_Relations_Set, Rel);
else
IR_Set.Delete (Saved_Relations_Set, Rel);
end if;
end Set_Is_Saved_Relation;
------------------
-- Signature_Of --
------------------
function Signature_Of (Id : Entity_Id) return Invocation_Signature_Id is
Loc : constant Source_Ptr := Sloc (Id);
function Instantiation_Locations return Name_Id;
pragma Inline (Instantiation_Locations);
-- Create a concatenation of all lines and colums of each instance
-- where source location Loc appears. Return No_Name if no instances
-- exist.
function Qualified_Scope return Name_Id;
pragma Inline (Qualified_Scope);
-- Obtain the qualified name of Id's scope
-----------------------------
-- Instantiation_Locations --
-----------------------------
function Instantiation_Locations return Name_Id is
Buffer : Bounded_String (2052);
Inst : Source_Ptr;
Loc_Nam : Name_Id;
SFI : Source_File_Index;
begin
SFI := Get_Source_File_Index (Loc);
Inst := Instantiation (SFI);
-- The location is within an instance. Construct a concatenation
-- of all lines and colums of each individual instance using the
-- following format:
--
-- line1_column1_line2_column2_ ... _lineN_columnN
if Inst /= No_Location then
loop
Append (Buffer, Nat (Get_Logical_Line_Number (Inst)));
Append (Buffer, '_');
Append (Buffer, Nat (Get_Column_Number (Inst)));
SFI := Get_Source_File_Index (Inst);
Inst := Instantiation (SFI);
exit when Inst = No_Location;
Append (Buffer, '_');
end loop;
Loc_Nam := Name_Find (Buffer);
return Loc_Nam;
-- Otherwise there no instances are involved
else
return No_Name;
end if;
end Instantiation_Locations;
---------------------
-- Qualified_Scope --
---------------------
function Qualified_Scope return Name_Id is
Scop : Entity_Id;
begin
Scop := Scope (Id);
-- The entity appears within an anonymous concurrent type created
-- for a single protected or task type declaration. Use the entity
-- of the anonymous object as it represents the original scope.
if Is_Concurrent_Type (Scop)
and then Present (Anonymous_Object (Scop))
then
Scop := Anonymous_Object (Scop);
end if;
return Get_Qualified_Name (Scop);
end Qualified_Scope;
-- Start of processing for Signature_Of
begin
return
Invocation_Signature_Of
(Column => Nat (Get_Column_Number (Loc)),
Line => Nat (Get_Logical_Line_Number (Loc)),
Locations => Instantiation_Locations,
Name => Chars (Id),
Scope => Qualified_Scope);
end Signature_Of;
---------------
-- Target_Of --
---------------
function Target_Of
(Pos : Active_Scenario_Pos;
In_State : Processing_In_State) return Entity_Id
is
package Scenarios renames Active_Scenario_Stack;
-- Ensure that the position is within the bounds of the active
-- scenario stack.
pragma Assert (Scenarios.First <= Pos);
pragma Assert (Pos <= Scenarios.Last);
Scen_Rep : constant Scenario_Rep_Id :=
Scenario_Representation_Of
(Scenarios.Table (Pos), In_State);
begin
-- The true target of an activation call is the current task type
-- rather than routine Activate_Tasks.
if Kind (Scen_Rep) = Task_Activation_Scenario then
return Activated_Task_Type (Scen_Rep);
else
return Target (Scen_Rep);
end if;
end Target_Of;
------------------------------
-- Traverse_Invocation_Body --
------------------------------
procedure Traverse_Invocation_Body
(N : Node_Id;
In_State : Processing_In_State)
is
begin
Traverse_Body
(N => N,
Requires_Processing => Is_Invocation_Scenario'Access,
Processor => Process_Invocation_Scenario'Access,
In_State => In_State);
end Traverse_Invocation_Body;
---------------------------
-- Write_Invocation_Path --
---------------------------
procedure Write_Invocation_Path (In_State : Processing_In_State) is
procedure Write_Target (Targ_Id : Entity_Id; Is_First : Boolean);
pragma Inline (Write_Target);
-- Write out invocation target Targ_Id to standard output. Flag
-- Is_First should be set when the target is first in a path.
-------------
-- Targ_Id --
-------------
procedure Write_Target (Targ_Id : Entity_Id; Is_First : Boolean) is
begin
if not Is_First then
Write_Str (" --> ");
end if;
Write_Name (Get_Qualified_Name (Targ_Id));
Write_Eol;
end Write_Target;
-- Local variables
package Scenarios renames Active_Scenario_Stack;
First_Seen : Boolean := False;
-- Start of processing for Write_Invocation_Path
begin
-- Nothing to do when flag -gnatd_T (output trace information on
-- invocation path recording) is not in effect.
if not Debug_Flag_Underscore_TT then
return;
end if;
-- The path originates from the elaboration of the body. Write the
-- elaboration body procedure.
if In_State.Processing = Invocation_Body_Processing then
Write_Target (Elab_Body_Id, True);
First_Seen := True;
-- The path originates from the elaboration of the spec. Write the
-- elaboration spec procedure.
elsif In_State.Processing = Invocation_Spec_Processing then
Write_Target (Elab_Spec_Id, True);
First_Seen := True;
end if;
-- Write each individual target invoked by its corresponding scenario
-- on the active scenario stack.
for Index in Scenarios.First .. Scenarios.Last loop
Write_Target
(Targ_Id => Target_Of (Index, In_State),
Is_First => Index = Scenarios.First and then not First_Seen);
end loop;
Write_Eol;
end Write_Invocation_Path;
end Invocation_Graph;
------------------------
-- Is_Safe_Activation --
------------------------
function Is_Safe_Activation
(Call : Node_Id;
Task_Rep : Target_Rep_Id) return Boolean
is
begin
-- The activation of a task coming from an external instance cannot
-- cause an ABE because the generic was already instantiated. Note
-- that the instantiation itself may lead to an ABE.
return
In_External_Instance
(N => Call,
Target_Decl => Spec_Declaration (Task_Rep));
end Is_Safe_Activation;
------------------
-- Is_Safe_Call --
------------------
function Is_Safe_Call
(Call : Node_Id;
Subp_Id : Entity_Id;
Subp_Rep : Target_Rep_Id) return Boolean
is
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep);
Spec_Decl : constant Node_Id := Spec_Declaration (Subp_Rep);
begin
-- The target is either an abstract subprogram, formal subprogram, or
-- imported, in which case it does not have a body at compile or bind
-- time. Assume that the call is ABE-safe.
if Is_Bodiless_Subprogram (Subp_Id) then
return True;
-- The target is an instantiation of a generic subprogram. The call
-- cannot cause an ABE because the generic was already instantiated.
-- Note that the instantiation itself may lead to an ABE.
elsif Is_Generic_Instance (Subp_Id) then
return True;
-- The invocation of a target coming from an external instance cannot
-- cause an ABE because the generic was already instantiated. Note that
-- the instantiation itself may lead to an ABE.
elsif In_External_Instance
(N => Call,
Target_Decl => Spec_Decl)
then
return True;
-- The target is a subprogram body without a previous declaration. The
-- call cannot cause an ABE because the body has already been seen.
elsif Nkind (Spec_Decl) = N_Subprogram_Body
and then No (Corresponding_Spec (Spec_Decl))
then
return True;
-- The target is a subprogram body stub without a prior declaration.
-- The call cannot cause an ABE because the proper body substitutes
-- the stub.
elsif Nkind (Spec_Decl) = N_Subprogram_Body_Stub
and then No (Corresponding_Spec_Of_Stub (Spec_Decl))
then
return True;
-- Subprogram bodies which wrap attribute references used as actuals
-- in instantiations are always ABE-safe. These bodies are artifacts
-- of expansion.
elsif Present (Body_Decl)
and then Nkind (Body_Decl) = N_Subprogram_Body
and then Was_Attribute_Reference (Body_Decl)
then
return True;
end if;
return False;
end Is_Safe_Call;
---------------------------
-- Is_Safe_Instantiation --
---------------------------
function Is_Safe_Instantiation
(Inst : Node_Id;
Gen_Id : Entity_Id;
Gen_Rep : Target_Rep_Id) return Boolean
is
Spec_Decl : constant Node_Id := Spec_Declaration (Gen_Rep);
begin
-- The generic is an intrinsic subprogram in which case it does not
-- have a body at compile or bind time. Assume that the instantiation
-- is ABE-safe.
if Is_Bodiless_Subprogram (Gen_Id) then
return True;
-- The instantiation of an external nested generic cannot cause an ABE
-- if the outer generic was already instantiated. Note that the instance
-- of the outer generic may lead to an ABE.
elsif In_External_Instance
(N => Inst,
Target_Decl => Spec_Decl)
then
return True;
-- The generic is a package. The instantiation cannot cause an ABE when
-- the package has no body.
elsif Ekind (Gen_Id) = E_Generic_Package
and then not Has_Body (Spec_Decl)
then
return True;
end if;
return False;
end Is_Safe_Instantiation;
------------------
-- Is_Same_Unit --
------------------
function Is_Same_Unit
(Unit_1 : Entity_Id;
Unit_2 : Entity_Id) return Boolean
is
begin
return Unit_Entity (Unit_1) = Unit_Entity (Unit_2);
end Is_Same_Unit;
-------------------------------
-- Kill_Elaboration_Scenario --
-------------------------------
procedure Kill_Elaboration_Scenario (N : Node_Id) is
begin
-- Nothing to do when switch -gnatH (legacy elaboration checking mode
-- enabled) is in effect because the legacy ABE lechanism does not need
-- to carry out this action.
if Legacy_Elaboration_Checks then
return;
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
elsif not Elaboration_Phase_Active then
return;
end if;
-- Eliminate a recorded scenario when it appears within dead code
-- because it will not be executed at elaboration time.
if Is_Scenario (N) then
Delete_Scenario (N);
end if;
end Kill_Elaboration_Scenario;
----------------------
-- Main_Unit_Entity --
----------------------
function Main_Unit_Entity return Entity_Id is
begin
-- Note that Cunit_Entity (Main_Unit) is not reliable in the presence of
-- generic bodies and may return an outdated entity.
return Defining_Entity (Unit (Cunit (Main_Unit)));
end Main_Unit_Entity;
----------------------
-- Non_Private_View --
----------------------
function Non_Private_View (Typ : Entity_Id) return Entity_Id is
begin
if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
return Full_View (Typ);
else
return Typ;
end if;
end Non_Private_View;
---------------------------------
-- Record_Elaboration_Scenario --
---------------------------------
procedure Record_Elaboration_Scenario (N : Node_Id) is
procedure Check_Preelaborated_Call
(Call : Node_Id;
Call_Lvl : Enclosing_Level_Kind);
pragma Inline (Check_Preelaborated_Call);
-- Verify that entry, operator, or subprogram call Call with enclosing
-- level Call_Lvl does not appear at the library level of preelaborated
-- unit.
function Find_Code_Unit (Nod : Node_Or_Entity_Id) return Entity_Id;
pragma Inline (Find_Code_Unit);
-- Return the code unit which contains arbitrary node or entity Nod.
-- This is the unit of the file which physically contains the related
-- construct denoted by Nod except when Nod is within an instantiation.
-- In that case the unit is that of the top-level instantiation.
function In_Preelaborated_Context (Nod : Node_Id) return Boolean;
pragma Inline (In_Preelaborated_Context);
-- Determine whether arbitrary node Nod appears within a preelaborated
-- context.
procedure Record_Access_Taken
(Attr : Node_Id;
Attr_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Access_Taken);
-- Record 'Access scenario Attr with enclosing level Attr_Lvl
procedure Record_Call_Or_Task_Activation
(Call : Node_Id;
Call_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Call_Or_Task_Activation);
-- Record call scenario Call with enclosing level Call_Lvl
procedure Record_Instantiation
(Inst : Node_Id;
Inst_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Instantiation);
-- Record instantiation scenario Inst with enclosing level Inst_Lvl
procedure Record_Variable_Assignment
(Asmt : Node_Id;
Asmt_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Variable_Assignment);
-- Record variable assignment scenario Asmt with enclosing level
-- Asmt_Lvl.
procedure Record_Variable_Reference
(Ref : Node_Id;
Ref_Lvl : Enclosing_Level_Kind);
pragma Inline (Record_Variable_Reference);
-- Record variable reference scenario Ref with enclosing level Ref_Lvl
------------------------------
-- Check_Preelaborated_Call --
------------------------------
procedure Check_Preelaborated_Call
(Call : Node_Id;
Call_Lvl : Enclosing_Level_Kind)
is
begin
-- Nothing to do when the call is internally generated because it is
-- assumed that it will never violate preelaboration.
if not Is_Source_Call (Call) then
return;
-- Nothing to do when the call is preelaborable by definition
elsif Is_Preelaborable_Call (Call) then
return;
-- Library-level calls are always considered because they are part of
-- the associated unit's elaboration actions.
elsif Call_Lvl in Library_Level then
null;
-- Calls at the library level of a generic package body have to be
-- checked because they would render an instantiation illegal if the
-- template is marked as preelaborated. Note that this does not apply
-- to calls at the library level of a generic package spec.
elsif Call_Lvl = Generic_Body_Level then
null;
-- Otherwise the call does not appear at the proper level and must
-- not be considered for this check.
else
return;
end if;
-- If the call appears within a preelaborated unit, give an error
if In_Preelaborated_Context (Call) then
Error_Preelaborated_Call (Call);
end if;
end Check_Preelaborated_Call;
--------------------
-- Find_Code_Unit --
--------------------
function Find_Code_Unit (Nod : Node_Or_Entity_Id) return Entity_Id is
begin
return Find_Unit_Entity (Unit (Cunit (Get_Code_Unit (Nod))));
end Find_Code_Unit;
------------------------------
-- In_Preelaborated_Context --
------------------------------
function In_Preelaborated_Context (Nod : Node_Id) return Boolean is
Body_Id : constant Entity_Id := Find_Code_Unit (Nod);
Spec_Id : constant Entity_Id := Unique_Entity (Body_Id);
begin
-- The node appears within a package body whose corresponding spec is
-- subject to pragma Remote_Call_Interface or Remote_Types. This does
-- not result in a preelaborated context because the package body may
-- be on another machine.
if Ekind (Body_Id) = E_Package_Body
and then Is_Package_Or_Generic_Package (Spec_Id)
and then (Is_Remote_Call_Interface (Spec_Id)
or else Is_Remote_Types (Spec_Id))
then
return False;
-- Otherwise the node appears within a preelaborated context when the
-- associated unit is preelaborated.
else
return Is_Preelaborated_Unit (Spec_Id);
end if;
end In_Preelaborated_Context;
-------------------------
-- Record_Access_Taken --
-------------------------
procedure Record_Access_Taken
(Attr : Node_Id;
Attr_Lvl : Enclosing_Level_Kind)
is
begin
-- Signal any enclosing local exception handlers that the 'Access may
-- raise Program_Error due to a failed ABE check when switch -gnatd.o
-- (conservative elaboration order for indirect calls) is in effect.
-- Marking the exception handlers ensures proper expansion by both
-- the front and back end restriction when No_Exception_Propagation
-- is in effect.
if Debug_Flag_Dot_O then
Possible_Local_Raise (Attr, Standard_Program_Error);
end if;
-- Add 'Access to the appropriate set
if Attr_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Attr);
elsif Attr_Lvl = Library_Spec_Level
or else Attr_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Attr);
end if;
-- 'Access requires a conditional ABE check when the dynamic model is
-- in effect.
Add_Dynamic_ABE_Check_Scenario (Attr);
end Record_Access_Taken;
------------------------------------
-- Record_Call_Or_Task_Activation --
------------------------------------
procedure Record_Call_Or_Task_Activation
(Call : Node_Id;
Call_Lvl : Enclosing_Level_Kind)
is
begin
-- Signal any enclosing local exception handlers that the call may
-- raise Program_Error due to failed ABE check. Marking the exception
-- handlers ensures proper expansion by both the front and back end
-- restriction when No_Exception_Propagation is in effect.
Possible_Local_Raise (Call, Standard_Program_Error);
-- Perform early detection of guaranteed ABEs in order to suppress
-- the instantiation of generic bodies because gigi cannot handle
-- certain types of premature instantiations.
Process_Guaranteed_ABE
(N => Call,
In_State => Guaranteed_ABE_State);
-- Add the call or task activation to the appropriate set
if Call_Lvl = Declaration_Level then
Add_Declaration_Scenario (Call);
elsif Call_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Call);
elsif Call_Lvl = Library_Spec_Level
or else Call_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Call);
end if;
-- A call or a task activation requires a conditional ABE check when
-- the dynamic model is in effect.
Add_Dynamic_ABE_Check_Scenario (Call);
end Record_Call_Or_Task_Activation;
--------------------------
-- Record_Instantiation --
--------------------------
procedure Record_Instantiation
(Inst : Node_Id;
Inst_Lvl : Enclosing_Level_Kind)
is
begin
-- Signal enclosing local exception handlers that instantiation may
-- raise Program_Error due to failed ABE check. Marking the exception
-- handlers ensures proper expansion by both the front and back end
-- restriction when No_Exception_Propagation is in effect.
Possible_Local_Raise (Inst, Standard_Program_Error);
-- Perform early detection of guaranteed ABEs in order to suppress
-- the instantiation of generic bodies because gigi cannot handle
-- certain types of premature instantiations.
Process_Guaranteed_ABE
(N => Inst,
In_State => Guaranteed_ABE_State);
-- Add the instantiation to the appropriate set
if Inst_Lvl = Declaration_Level then
Add_Declaration_Scenario (Inst);
elsif Inst_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Inst);
elsif Inst_Lvl = Library_Spec_Level
or else Inst_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Inst);
end if;
-- Instantiations of generics subject to SPARK_Mode On require
-- elaboration-related checks even though the instantiations may
-- not appear within elaboration code.
if Is_Suitable_SPARK_Instantiation (Inst) then
Add_SPARK_Scenario (Inst);
end if;
-- An instantiation requires a conditional ABE check when the dynamic
-- model is in effect.
Add_Dynamic_ABE_Check_Scenario (Inst);
end Record_Instantiation;
--------------------------------
-- Record_Variable_Assignment --
--------------------------------
procedure Record_Variable_Assignment
(Asmt : Node_Id;
Asmt_Lvl : Enclosing_Level_Kind)
is
begin
-- Add the variable assignment to the appropriate set
if Asmt_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Asmt);
elsif Asmt_Lvl = Library_Spec_Level
or else Asmt_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Asmt);
end if;
end Record_Variable_Assignment;
-------------------------------
-- Record_Variable_Reference --
-------------------------------
procedure Record_Variable_Reference
(Ref : Node_Id;
Ref_Lvl : Enclosing_Level_Kind)
is
begin
-- Add the variable reference to the appropriate set
if Ref_Lvl = Library_Body_Level then
Add_Library_Body_Scenario (Ref);
elsif Ref_Lvl = Library_Spec_Level
or else Ref_Lvl = Instantiation_Level
then
Add_Library_Spec_Scenario (Ref);
end if;
end Record_Variable_Reference;
-- Local variables
Scen : constant Node_Id := Scenario (N);
Scen_Lvl : Enclosing_Level_Kind;
-- Start of processing for Record_Elaboration_Scenario
begin
-- Nothing to do when switch -gnatH (legacy elaboration checking mode
-- enabled) is in effect because the legacy ABE mechanism does not need
-- to carry out this action.
if Legacy_Elaboration_Checks then
return;
-- Nothing to do when the scenario is being preanalyzed
elsif Preanalysis_Active then
return;
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
elsif not Elaboration_Phase_Active then
return;
end if;
Scen_Lvl := Find_Enclosing_Level (Scen);
-- Ensure that a library-level call does not appear in a preelaborated
-- unit. The check must come before ignoring scenarios within external
-- units or inside generics because calls in those context must also be
-- verified.
if Is_Suitable_Call (Scen) then
Check_Preelaborated_Call (Scen, Scen_Lvl);
end if;
-- Nothing to do when the scenario does not appear within the main unit
if not In_Main_Context (Scen) then
return;
-- Nothing to do when the scenario appears within a generic
elsif Inside_A_Generic then
return;
-- 'Access
elsif Is_Suitable_Access_Taken (Scen) then
Record_Access_Taken
(Attr => Scen,
Attr_Lvl => Scen_Lvl);
-- Call or task activation
elsif Is_Suitable_Call (Scen) then
Record_Call_Or_Task_Activation
(Call => Scen,
Call_Lvl => Scen_Lvl);
-- Derived type declaration
elsif Is_Suitable_SPARK_Derived_Type (Scen) then
Add_SPARK_Scenario (Scen);
-- Instantiation
elsif Is_Suitable_Instantiation (Scen) then
Record_Instantiation
(Inst => Scen,
Inst_Lvl => Scen_Lvl);
-- Refined_State pragma
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then
Add_SPARK_Scenario (Scen);
-- Variable assignment
elsif Is_Suitable_Variable_Assignment (Scen) then
Record_Variable_Assignment
(Asmt => Scen,
Asmt_Lvl => Scen_Lvl);
-- Variable reference
elsif Is_Suitable_Variable_Reference (Scen) then
Record_Variable_Reference
(Ref => Scen,
Ref_Lvl => Scen_Lvl);
end if;
end Record_Elaboration_Scenario;
--------------
-- Scenario --
--------------
function Scenario (N : Node_Id) return Node_Id is
Orig_N : constant Node_Id := Original_Node (N);
begin
-- An expanded instantiation is rewritten into a spec-body pair where
-- N denotes the spec. In this case the original instantiation is the
-- proper elaboration scenario.
if Nkind (Orig_N) in N_Generic_Instantiation then
return Orig_N;
-- Otherwise the scenario is already in its proper form
else
return N;
end if;
end Scenario;
----------------------
-- Scenario_Storage --
----------------------
package body Scenario_Storage is
---------------------
-- Data structures --
---------------------
-- The following sets store all scenarios
Declaration_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
Dynamic_ABE_Check_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
Library_Body_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
Library_Spec_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
SPARK_Scenarios : NE_Set.Membership_Set := NE_Set.Nil;
-------------------------------
-- Finalize_Scenario_Storage --
-------------------------------
procedure Finalize_Scenario_Storage is
begin
NE_Set.Destroy (Declaration_Scenarios);
NE_Set.Destroy (Dynamic_ABE_Check_Scenarios);
NE_Set.Destroy (Library_Body_Scenarios);
NE_Set.Destroy (Library_Spec_Scenarios);
NE_Set.Destroy (SPARK_Scenarios);
end Finalize_Scenario_Storage;
---------------------------------
-- Initialize_Scenario_Storage --
---------------------------------
procedure Initialize_Scenario_Storage is
begin
Declaration_Scenarios := NE_Set.Create (1000);
Dynamic_ABE_Check_Scenarios := NE_Set.Create (500);
Library_Body_Scenarios := NE_Set.Create (1000);
Library_Spec_Scenarios := NE_Set.Create (1000);
SPARK_Scenarios := NE_Set.Create (100);
end Initialize_Scenario_Storage;
------------------------------
-- Add_Declaration_Scenario --
------------------------------
procedure Add_Declaration_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (Declaration_Scenarios, N);
end Add_Declaration_Scenario;
------------------------------------
-- Add_Dynamic_ABE_Check_Scenario --
------------------------------------
procedure Add_Dynamic_ABE_Check_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
if not Check_Or_Failure_Generation_OK then
return;
-- Nothing to do if the dynamic model is not in effect
elsif not Dynamic_Elaboration_Checks then
return;
end if;
NE_Set.Insert (Dynamic_ABE_Check_Scenarios, N);
end Add_Dynamic_ABE_Check_Scenario;
-------------------------------
-- Add_Library_Body_Scenario --
-------------------------------
procedure Add_Library_Body_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (Library_Body_Scenarios, N);
end Add_Library_Body_Scenario;
-------------------------------
-- Add_Library_Spec_Scenario --
-------------------------------
procedure Add_Library_Spec_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (Library_Spec_Scenarios, N);
end Add_Library_Spec_Scenario;
------------------------
-- Add_SPARK_Scenario --
------------------------
procedure Add_SPARK_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
NE_Set.Insert (SPARK_Scenarios, N);
end Add_SPARK_Scenario;
---------------------
-- Delete_Scenario --
---------------------
procedure Delete_Scenario (N : Node_Id) is
pragma Assert (Present (N));
begin
-- Delete the scenario from whichever set it belongs to
NE_Set.Delete (Declaration_Scenarios, N);
NE_Set.Delete (Dynamic_ABE_Check_Scenarios, N);
NE_Set.Delete (Library_Body_Scenarios, N);
NE_Set.Delete (Library_Spec_Scenarios, N);
NE_Set.Delete (SPARK_Scenarios, N);
end Delete_Scenario;
-----------------------------------
-- Iterate_Declaration_Scenarios --
-----------------------------------
function Iterate_Declaration_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (Declaration_Scenarios);
end Iterate_Declaration_Scenarios;
-----------------------------------------
-- Iterate_Dynamic_ABE_Check_Scenarios --
-----------------------------------------
function Iterate_Dynamic_ABE_Check_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (Dynamic_ABE_Check_Scenarios);
end Iterate_Dynamic_ABE_Check_Scenarios;
------------------------------------
-- Iterate_Library_Body_Scenarios --
------------------------------------
function Iterate_Library_Body_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (Library_Body_Scenarios);
end Iterate_Library_Body_Scenarios;
------------------------------------
-- Iterate_Library_Spec_Scenarios --
------------------------------------
function Iterate_Library_Spec_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (Library_Spec_Scenarios);
end Iterate_Library_Spec_Scenarios;
-----------------------------
-- Iterate_SPARK_Scenarios --
-----------------------------
function Iterate_SPARK_Scenarios return NE_Set.Iterator is
begin
return NE_Set.Iterate (SPARK_Scenarios);
end Iterate_SPARK_Scenarios;
----------------------
-- Replace_Scenario --
----------------------
procedure Replace_Scenario (Old_N : Node_Id; New_N : Node_Id) is
procedure Replace_Scenario_In (Scenarios : NE_Set.Membership_Set);
-- Determine whether scenario Old_N is present in set Scenarios, and
-- if this is the case it, replace it with New_N.
-------------------------
-- Replace_Scenario_In --
-------------------------
procedure Replace_Scenario_In (Scenarios : NE_Set.Membership_Set) is
begin
-- The set is intentionally checked for existance because node
-- rewriting may occur after Sem_Elab has verified all scenarios
-- and data structures have been destroyed.
if NE_Set.Present (Scenarios)
and then NE_Set.Contains (Scenarios, Old_N)
then
NE_Set.Delete (Scenarios, Old_N);
NE_Set.Insert (Scenarios, New_N);
end if;
end Replace_Scenario_In;
-- Start of processing for Replace_Scenario
begin
Replace_Scenario_In (Declaration_Scenarios);
Replace_Scenario_In (Dynamic_ABE_Check_Scenarios);
Replace_Scenario_In (Library_Body_Scenarios);
Replace_Scenario_In (Library_Spec_Scenarios);
Replace_Scenario_In (SPARK_Scenarios);
end Replace_Scenario;
end Scenario_Storage;
---------------
-- Semantics --
---------------
package body Semantics is
--------------------------------
-- Is_Accept_Alternative_Proc --
--------------------------------
function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a procedure with a receiving
-- entry.
return
Ekind (Id) = E_Procedure and then Present (Receiving_Entry (Id));
end Is_Accept_Alternative_Proc;
------------------------
-- Is_Activation_Proc --
------------------------
function Is_Activation_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote one of the runtime procedures
-- in charge of task activation.
if Ekind (Id) = E_Procedure then
if Restricted_Profile then
return Is_RTE (Id, RE_Activate_Restricted_Tasks);
else
return Is_RTE (Id, RE_Activate_Tasks);
end if;
end if;
return False;
end Is_Activation_Proc;
----------------------------
-- Is_Ada_Semantic_Target --
----------------------------
function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean is
begin
return
Is_Activation_Proc (Id)
or else Is_Controlled_Proc (Id, Name_Adjust)
or else Is_Controlled_Proc (Id, Name_Finalize)
or else Is_Controlled_Proc (Id, Name_Initialize)
or else Is_Init_Proc (Id)
or else Is_Invariant_Proc (Id)
or else Is_Protected_Entry (Id)
or else Is_Protected_Subp (Id)
or else Is_Protected_Body_Subp (Id)
or else Is_Subprogram_Inst (Id)
or else Is_Task_Entry (Id);
end Is_Ada_Semantic_Target;
--------------------------------
-- Is_Assertion_Pragma_Target --
--------------------------------
function Is_Assertion_Pragma_Target (Id : Entity_Id) return Boolean is
begin
return
Is_Default_Initial_Condition_Proc (Id)
or else Is_Initial_Condition_Proc (Id)
or else Is_Invariant_Proc (Id)
or else Is_Partial_Invariant_Proc (Id)
or else Is_Postconditions_Proc (Id);
end Is_Assertion_Pragma_Target;
----------------------------
-- Is_Bodiless_Subprogram --
----------------------------
function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean is
begin
-- An abstract subprogram does not have a body
if Ekind (Subp_Id) in E_Function | E_Operator | E_Procedure
and then Is_Abstract_Subprogram (Subp_Id)
then
return True;
-- A formal subprogram does not have a body
elsif Is_Formal_Subprogram (Subp_Id) then
return True;
-- An imported subprogram may have a body, however it is not known at
-- compile or bind time where the body resides and whether it will be
-- elaborated on time.
elsif Is_Imported (Subp_Id) then
return True;
end if;
return False;
end Is_Bodiless_Subprogram;
----------------------
-- Is_Bridge_Target --
----------------------
function Is_Bridge_Target (Id : Entity_Id) return Boolean is
begin
return
Is_Accept_Alternative_Proc (Id)
or else Is_Finalizer_Proc (Id)
or else Is_Partial_Invariant_Proc (Id)
or else Is_Postconditions_Proc (Id)
or else Is_TSS (Id, TSS_Deep_Adjust)
or else Is_TSS (Id, TSS_Deep_Finalize)
or else Is_TSS (Id, TSS_Deep_Initialize);
end Is_Bridge_Target;
------------------------
-- Is_Controlled_Proc --
------------------------
function Is_Controlled_Proc
(Subp_Id : Entity_Id;
Subp_Nam : Name_Id) return Boolean
is
Formal_Id : Entity_Id;
begin
pragma Assert
(Subp_Nam in Name_Adjust | Name_Finalize | Name_Initialize);
-- To qualify, the subprogram must denote a source procedure with
-- name Adjust, Finalize, or Initialize where the sole formal is
-- controlled.
if Comes_From_Source (Subp_Id)
and then Ekind (Subp_Id) = E_Procedure
and then Chars (Subp_Id) = Subp_Nam
then
Formal_Id := First_Formal (Subp_Id);
return
Present (Formal_Id)
and then Is_Controlled (Etype (Formal_Id))
and then No (Next_Formal (Formal_Id));
end if;
return False;
end Is_Controlled_Proc;
---------------------------------------
-- Is_Default_Initial_Condition_Proc --
---------------------------------------
function Is_Default_Initial_Condition_Proc
(Id : Entity_Id) return Boolean
is
begin
-- To qualify, the entity must denote a Default_Initial_Condition
-- procedure.
return Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id);
end Is_Default_Initial_Condition_Proc;
-----------------------
-- Is_Finalizer_Proc --
-----------------------
function Is_Finalizer_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a _Finalizer procedure
return Ekind (Id) = E_Procedure and then Chars (Id) = Name_uFinalizer;
end Is_Finalizer_Proc;
-------------------------------
-- Is_Initial_Condition_Proc --
-------------------------------
function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote an Initial_Condition procedure
return
Ekind (Id) = E_Procedure
and then Is_Initial_Condition_Procedure (Id);
end Is_Initial_Condition_Proc;
--------------------
-- Is_Initialized --
--------------------
function Is_Initialized (Obj_Decl : Node_Id) return Boolean is
begin
-- To qualify, the object declaration must have an expression
return
Present (Expression (Obj_Decl))
or else Has_Init_Expression (Obj_Decl);
end Is_Initialized;
-----------------------
-- Is_Invariant_Proc --
-----------------------
function Is_Invariant_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote the "full" invariant procedure
return Ekind (Id) = E_Procedure and then Is_Invariant_Procedure (Id);
end Is_Invariant_Proc;
---------------------------------------
-- Is_Non_Library_Level_Encapsulator --
---------------------------------------
function Is_Non_Library_Level_Encapsulator
(N : Node_Id) return Boolean
is
begin
case Nkind (N) is
when N_Abstract_Subprogram_Declaration
| N_Aspect_Specification
| N_Component_Declaration
| N_Entry_Body
| N_Entry_Declaration
| N_Expression_Function
| N_Formal_Abstract_Subprogram_Declaration
| N_Formal_Concrete_Subprogram_Declaration
| N_Formal_Object_Declaration
| N_Formal_Package_Declaration
| N_Formal_Type_Declaration
| N_Generic_Association
| N_Implicit_Label_Declaration
| N_Incomplete_Type_Declaration
| N_Private_Extension_Declaration
| N_Private_Type_Declaration
| N_Protected_Body
| N_Protected_Type_Declaration
| N_Single_Protected_Declaration
| N_Single_Task_Declaration
| N_Subprogram_Body
| N_Subprogram_Declaration
| N_Task_Body
| N_Task_Type_Declaration
=>
return True;
when others =>
return Is_Generic_Declaration_Or_Body (N);
end case;
end Is_Non_Library_Level_Encapsulator;
-------------------------------
-- Is_Partial_Invariant_Proc --
-------------------------------
function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote the "partial" invariant
-- procedure.
return
Ekind (Id) = E_Procedure
and then Is_Partial_Invariant_Procedure (Id);
end Is_Partial_Invariant_Proc;
----------------------------
-- Is_Postconditions_Proc --
----------------------------
function Is_Postconditions_Proc (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a _Postconditions procedure
return
Ekind (Id) = E_Procedure and then Chars (Id) = Name_uPostconditions;
end Is_Postconditions_Proc;
---------------------------
-- Is_Preelaborated_Unit --
---------------------------
function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean is
begin
return
Is_Preelaborated (Id)
or else Is_Pure (Id)
or else Is_Remote_Call_Interface (Id)
or else Is_Remote_Types (Id)
or else Is_Shared_Passive (Id);
end Is_Preelaborated_Unit;
------------------------
-- Is_Protected_Entry --
------------------------
function Is_Protected_Entry (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote an entry defined in a protected
-- type.
return
Is_Entry (Id)
and then Is_Protected_Type (Non_Private_View (Scope (Id)));
end Is_Protected_Entry;
-----------------------
-- Is_Protected_Subp --
-----------------------
function Is_Protected_Subp (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a subprogram defined within a
-- protected type.
return
Ekind (Id) in E_Function | E_Procedure
and then Is_Protected_Type (Non_Private_View (Scope (Id)));
end Is_Protected_Subp;
----------------------------
-- Is_Protected_Body_Subp --
----------------------------
function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a subprogram with attribute
-- Protected_Subprogram set.
return
Ekind (Id) in E_Function | E_Procedure
and then Present (Protected_Subprogram (Id));
end Is_Protected_Body_Subp;
-----------------
-- Is_Scenario --
-----------------
function Is_Scenario (N : Node_Id) return Boolean is
begin
case Nkind (N) is
when N_Assignment_Statement
| N_Attribute_Reference
| N_Call_Marker
| N_Entry_Call_Statement
| N_Expanded_Name
| N_Function_Call
| N_Function_Instantiation
| N_Identifier
| N_Package_Instantiation
| N_Procedure_Call_Statement
| N_Procedure_Instantiation
| N_Requeue_Statement
=>
return True;
when others =>
return False;
end case;
end Is_Scenario;
------------------------------
-- Is_SPARK_Semantic_Target --
------------------------------
function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean is
begin
return
Is_Default_Initial_Condition_Proc (Id)
or else Is_Initial_Condition_Proc (Id);
end Is_SPARK_Semantic_Target;
------------------------
-- Is_Subprogram_Inst --
------------------------
function Is_Subprogram_Inst (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote a function or a procedure which
-- is hidden within an anonymous package, and is a generic instance.
return
Ekind (Id) in E_Function | E_Procedure
and then Is_Hidden (Id)
and then Is_Generic_Instance (Id);
end Is_Subprogram_Inst;
------------------------------
-- Is_Suitable_Access_Taken --
------------------------------
function Is_Suitable_Access_Taken (N : Node_Id) return Boolean is
Nam : Name_Id;
Pref : Node_Id;
Subp_Id : Entity_Id;
begin
-- Nothing to do when switch -gnatd.U (ignore 'Access) is in effect
if Debug_Flag_Dot_UU then
return False;
-- Nothing to do when the scenario is not an attribute reference
elsif Nkind (N) /= N_Attribute_Reference then
return False;
-- Nothing to do for internally-generated attributes because they are
-- assumed to be ABE safe.
elsif not Comes_From_Source (N) then
return False;
end if;
Nam := Attribute_Name (N);
Pref := Prefix (N);
-- Sanitize the prefix of the attribute
if not Is_Entity_Name (Pref) then
return False;
elsif No (Entity (Pref)) then
return False;
end if;
Subp_Id := Entity (Pref);
if not Is_Subprogram_Or_Entry (Subp_Id) then
return False;
end if;
-- Traverse a possible chain of renamings to obtain the original
-- entry or subprogram which the prefix may rename.
Subp_Id := Get_Renamed_Entity (Subp_Id);
-- To qualify, the attribute must meet the following prerequisites:
return
-- The prefix must denote a source entry, operator, or subprogram
-- which is not imported.
Comes_From_Source (Subp_Id)
and then Is_Subprogram_Or_Entry (Subp_Id)
and then not Is_Bodiless_Subprogram (Subp_Id)
-- The attribute name must be one of the 'Access forms. Note that
-- 'Unchecked_Access cannot apply to a subprogram.
and then Nam in Name_Access | Name_Unrestricted_Access;
end Is_Suitable_Access_Taken;
----------------------
-- Is_Suitable_Call --
----------------------
function Is_Suitable_Call (N : Node_Id) return Boolean is
begin
-- Entry and subprogram calls are intentionally ignored because they
-- may undergo expansion depending on the compilation mode, previous
-- errors, generic context, etc. Call markers play the role of calls
-- and provide a uniform foundation for ABE processing.
return Nkind (N) = N_Call_Marker;
end Is_Suitable_Call;
-------------------------------
-- Is_Suitable_Instantiation --
-------------------------------
function Is_Suitable_Instantiation (N : Node_Id) return Boolean is
Inst : constant Node_Id := Scenario (N);
begin
-- To qualify, the instantiation must come from source
return
Comes_From_Source (Inst)
and then Nkind (Inst) in N_Generic_Instantiation;
end Is_Suitable_Instantiation;
------------------------------------
-- Is_Suitable_SPARK_Derived_Type --
------------------------------------
function Is_Suitable_SPARK_Derived_Type (N : Node_Id) return Boolean is
Prag : Node_Id;
Typ : Entity_Id;
begin
-- To qualify, the type declaration must denote a derived tagged type
-- with primitive operations, subject to pragma SPARK_Mode On.
if Nkind (N) = N_Full_Type_Declaration
and then Nkind (Type_Definition (N)) = N_Derived_Type_Definition
then
Typ := Defining_Entity (N);
Prag := SPARK_Pragma (Typ);
return
Is_Tagged_Type (Typ)
and then Has_Primitive_Operations (Typ)
and then Present (Prag)
and then Get_SPARK_Mode_From_Annotation (Prag) = On;
end if;
return False;
end Is_Suitable_SPARK_Derived_Type;
-------------------------------------
-- Is_Suitable_SPARK_Instantiation --
-------------------------------------
function Is_Suitable_SPARK_Instantiation (N : Node_Id) return Boolean is
Inst : constant Node_Id := Scenario (N);
Gen_Id : Entity_Id;
Prag : Node_Id;
begin
-- To qualify, both the instantiation and the generic must be subject
-- to SPARK_Mode On.
if Is_Suitable_Instantiation (N) then
Gen_Id := Instantiated_Generic (Inst);
Prag := SPARK_Pragma (Gen_Id);
return
Is_SPARK_Mode_On_Node (Inst)
and then Present (Prag)
and then Get_SPARK_Mode_From_Annotation (Prag) = On;
end if;
return False;
end Is_Suitable_SPARK_Instantiation;
--------------------------------------------
-- Is_Suitable_SPARK_Refined_State_Pragma --
--------------------------------------------
function Is_Suitable_SPARK_Refined_State_Pragma
(N : Node_Id) return Boolean
is
begin
-- To qualfy, the pragma must denote Refined_State
return
Nkind (N) = N_Pragma
and then Pragma_Name (N) = Name_Refined_State;
end Is_Suitable_SPARK_Refined_State_Pragma;
-------------------------------------
-- Is_Suitable_Variable_Assignment --
-------------------------------------
function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean is
N_Unit : Node_Id;
N_Unit_Id : Entity_Id;
Nam : Node_Id;
Var_Decl : Node_Id;
Var_Id : Entity_Id;
Var_Unit : Node_Id;
Var_Unit_Id : Entity_Id;
begin
-- Nothing to do when the scenario is not an assignment
if Nkind (N) /= N_Assignment_Statement then
return False;
-- Nothing to do for internally-generated assignments because they
-- are assumed to be ABE safe.
elsif not Comes_From_Source (N) then
return False;
-- Assignments are ignored in GNAT mode on the assumption that
-- they are ABE-safe. This behavior parallels that of the old
-- ABE mechanism.
elsif GNAT_Mode then
return False;
end if;
Nam := Assignment_Target (N);
-- Sanitize the left hand side of the assignment
if not Is_Entity_Name (Nam) then
return False;
elsif No (Entity (Nam)) then
return False;
end if;
Var_Id := Entity (Nam);
-- Sanitize the variable
if Var_Id = Any_Id then
return False;
elsif Ekind (Var_Id) /= E_Variable then
return False;
end if;
Var_Decl := Declaration_Node (Var_Id);
if Nkind (Var_Decl) /= N_Object_Declaration then
return False;
end if;
N_Unit_Id := Find_Top_Unit (N);
N_Unit := Unit_Declaration_Node (N_Unit_Id);
Var_Unit_Id := Find_Top_Unit (Var_Decl);
Var_Unit := Unit_Declaration_Node (Var_Unit_Id);
-- To qualify, the assignment must meet the following prerequisites:
return
Comes_From_Source (Var_Id)
-- The variable must be declared in the spec of compilation unit
-- U.
and then Nkind (Var_Unit) = N_Package_Declaration
and then Find_Enclosing_Level (Var_Decl) = Library_Spec_Level
-- The assignment must occur in the body of compilation unit U
and then Nkind (N_Unit) = N_Package_Body
and then Present (Corresponding_Body (Var_Unit))
and then Corresponding_Body (Var_Unit) = N_Unit_Id;
end Is_Suitable_Variable_Assignment;
------------------------------------
-- Is_Suitable_Variable_Reference --
------------------------------------
function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean is
begin
-- Expanded names and identifiers are intentionally ignored because
-- they be folded, optimized away, etc. Variable references markers
-- play the role of variable references and provide a uniform
-- foundation for ABE processing.
return Nkind (N) = N_Variable_Reference_Marker;
end Is_Suitable_Variable_Reference;
-------------------
-- Is_Task_Entry --
-------------------
function Is_Task_Entry (Id : Entity_Id) return Boolean is
begin
-- To qualify, the entity must denote an entry defined in a task type
return
Is_Entry (Id) and then Is_Task_Type (Non_Private_View (Scope (Id)));
end Is_Task_Entry;
------------------------
-- Is_Up_Level_Target --
------------------------
function Is_Up_Level_Target
(Targ_Decl : Node_Id;
In_State : Processing_In_State) return Boolean
is
Root : constant Node_Id := Root_Scenario;
Root_Rep : constant Scenario_Rep_Id :=
Scenario_Representation_Of (Root, In_State);
begin
-- The root appears within the declaratons of a block statement,
-- entry body, subprogram body, or task body ignoring enclosing
-- packages. The root is always within the main unit.
if not In_State.Suppress_Up_Level_Targets
and then Level (Root_Rep) = Declaration_Level
then
-- The target is within the main unit. It acts as an up-level
-- target when it appears within a context which encloses the
-- root.
--
-- package body Main_Unit is
-- function Func ...; -- target
--
-- procedure Proc is
-- X : ... := Func; -- root scenario
if In_Extended_Main_Code_Unit (Targ_Decl) then
return not In_Same_Context (Root, Targ_Decl, Nested_OK => True);
-- Otherwise the target is external to the main unit which makes
-- it an up-level target.
else
return True;
end if;
end if;
return False;
end Is_Up_Level_Target;
end Semantics;
---------------------------
-- Set_Elaboration_Phase --
---------------------------
procedure Set_Elaboration_Phase (Status : Elaboration_Phase_Status) is
begin
Elaboration_Phase := Status;
end Set_Elaboration_Phase;
---------------------
-- SPARK_Processor --
---------------------
package body SPARK_Processor is
-----------------------
-- Local subprograms --
-----------------------
procedure Process_SPARK_Derived_Type
(Typ_Decl : Node_Id;
Typ_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_SPARK_Derived_Type);
-- Verify that the freeze node of a derived type denoted by declaration
-- Typ_Decl is within the early call region of each overriding primitive
-- body that belongs to the derived type (SPARK RM 7.7(8)). Typ_Rep is
-- the representation of the type. In_State denotes the current state of
-- the Processing phase.
procedure Process_SPARK_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_SPARK_Instantiation);
-- Verify that instanciation Inst does not precede the generic body it
-- instantiates (SPARK RM 7.7(6)). Inst_Rep is the representation of the
-- instantiation. In_State is the current state of the Processing phase.
procedure Process_SPARK_Refined_State_Pragma
(Prag : Node_Id;
Prag_Rep : Scenario_Rep_Id;
In_State : Processing_In_State);
pragma Inline (Process_SPARK_Refined_State_Pragma);
-- Verify that each constituent of Refined_State pragma Prag which
-- belongs to abstract state mentioned in pragma Initializes has prior
-- elaboration with respect to the main unit (SPARK RM 7.7.1(7)).
-- Prag_Rep is the representation of the pragma. In_State denotes the
-- current state of the Processing phase.
procedure Process_SPARK_Scenario
(N : Node_Id;
In_State : Processing_In_State);
pragma Inline (Process_SPARK_Scenario);
-- Top-level dispatcher for verifying SPARK scenarios which are not
-- always executable during elaboration but still need elaboration-
-- related checks. In_State is the current state of the Processing
-- phase.
---------------------------------
-- Check_SPARK_Model_In_Effect --
---------------------------------
SPARK_Model_Warning_Posted : Boolean := False;
-- This flag prevents the same SPARK model-related warning from being
-- emitted multiple times.
procedure Check_SPARK_Model_In_Effect is
Spec_Id : constant Entity_Id := Unique_Entity (Main_Unit_Entity);
begin
-- Do not emit the warning multiple times as this creates useless
-- noise.
if SPARK_Model_Warning_Posted then
null;
-- SPARK rule verification requires the "strict" static model
elsif Static_Elaboration_Checks
and not Relaxed_Elaboration_Checks
then
null;
-- Any other combination of models does not guarantee the absence of
-- ABE problems for SPARK rule verification purposes. Note that there
-- is no need to check for the presence of the legacy ABE mechanism
-- because the legacy code has its own dedicated processing for SPARK
-- rules.
else
SPARK_Model_Warning_Posted := True;
Error_Msg_N
("??SPARK elaboration checks require static elaboration model",
Spec_Id);
if Dynamic_Elaboration_Checks then
Error_Msg_N
("\dynamic elaboration model is in effect", Spec_Id);
else
pragma Assert (Relaxed_Elaboration_Checks);
Error_Msg_N
("\relaxed elaboration model is in effect", Spec_Id);
end if;
end if;
end Check_SPARK_Model_In_Effect;
---------------------------
-- Check_SPARK_Scenarios --
---------------------------
procedure Check_SPARK_Scenarios is
Iter : NE_Set.Iterator;
N : Node_Id;
begin
Iter := Iterate_SPARK_Scenarios;
while NE_Set.Has_Next (Iter) loop
NE_Set.Next (Iter, N);
Process_SPARK_Scenario
(N => N,
In_State => SPARK_State);
end loop;
end Check_SPARK_Scenarios;
--------------------------------
-- Process_SPARK_Derived_Type --
--------------------------------
procedure Process_SPARK_Derived_Type
(Typ_Decl : Node_Id;
Typ_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (In_State);
Typ : constant Entity_Id := Target (Typ_Rep);
Stop_Check : exception;
-- This exception is raised when the freeze node violates the
-- placement rules.
procedure Check_Overriding_Primitive
(Prim : Entity_Id;
FNode : Node_Id);
pragma Inline (Check_Overriding_Primitive);
-- Verify that freeze node FNode is within the early call region of
-- overriding primitive Prim's body.
function Freeze_Node_Location (FNode : Node_Id) return Source_Ptr;
pragma Inline (Freeze_Node_Location);
-- Return a more accurate source location associated with freeze node
-- FNode.
function Precedes_Source_Construct (N : Node_Id) return Boolean;
pragma Inline (Precedes_Source_Construct);
-- Determine whether arbitrary node N appears prior to some source
-- construct.
procedure Suggest_Elaborate_Body
(N : Node_Id;
Body_Decl : Node_Id;
Error_Nod : Node_Id);
pragma Inline (Suggest_Elaborate_Body);
-- Suggest the use of pragma Elaborate_Body when the pragma will
-- allow for node N to appear within the early call region of
-- subprogram body Body_Decl. The suggestion is attached to
-- Error_Nod as a continuation error.
--------------------------------
-- Check_Overriding_Primitive --
--------------------------------
procedure Check_Overriding_Primitive
(Prim : Entity_Id;
FNode : Node_Id)
is
Prim_Decl : constant Node_Id := Unit_Declaration_Node (Prim);
Body_Decl : Node_Id;
Body_Id : Entity_Id;
Region : Node_Id;
begin
-- Nothing to do for predefined primitives because they are
-- artifacts of tagged type expansion and cannot override source
-- primitives. Nothing to do as well for inherited primitives, as
-- the check concerns overriding ones.
if Is_Predefined_Dispatching_Operation (Prim)
or else not Is_Overriding_Subprogram (Prim)
then
return;
end if;
Body_Id := Corresponding_Body (Prim_Decl);
-- Nothing to do when the primitive does not have a corresponding
-- body. This can happen when the unit with the bodies is not the
-- main unit subjected to ABE checks.
if No (Body_Id) then
return;
-- The primitive overrides a parent or progenitor primitive
elsif Present (Overridden_Operation (Prim)) then
-- Nothing to do when overriding an interface primitive happens
-- by inheriting a non-interface primitive as the check would
-- be done on the parent primitive.
if Present (Alias (Prim)) then
return;
end if;
-- Nothing to do when the primitive is not overriding. The body of
-- such a primitive cannot be targeted by a dispatching call which
-- is executable during elaboration, and cannot cause an ABE.
else
return;
end if;
Body_Decl := Unit_Declaration_Node (Body_Id);
Region := Find_Early_Call_Region (Body_Decl);
-- The freeze node appears prior to the early call region of the
-- primitive body.
-- IMPORTANT: This check must always be performed even when
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not
-- specified because the static model cannot guarantee the absence
-- of ABEs in the presence of dispatching calls.
if Earlier_In_Extended_Unit (FNode, Region) then
Error_Msg_Node_2 := Prim;
Error_Msg_NE
("first freezing point of type & must appear within early "
& "call region of primitive body & (SPARK RM 7.7(8))",
Typ_Decl, Typ);
Error_Msg_Sloc := Sloc (Region);
Error_Msg_N ("\region starts #", Typ_Decl);
Error_Msg_Sloc := Sloc (Body_Decl);
Error_Msg_N ("\region ends #", Typ_Decl);
Error_Msg_Sloc := Freeze_Node_Location (FNode);
Error_Msg_N ("\first freezing point #", Typ_Decl);
-- If applicable, suggest the use of pragma Elaborate_Body in
-- the associated package spec.
Suggest_Elaborate_Body
(N => FNode,
Body_Decl => Body_Decl,
Error_Nod => Typ_Decl);
raise Stop_Check;
end if;
end Check_Overriding_Primitive;
--------------------------
-- Freeze_Node_Location --
--------------------------
function Freeze_Node_Location (FNode : Node_Id) return Source_Ptr is
Context : constant Node_Id := Parent (FNode);
Loc : constant Source_Ptr := Sloc (FNode);
Prv_Decls : List_Id;
Vis_Decls : List_Id;
begin
-- In general, the source location of the freeze node is as close
-- as possible to the real freeze point, except when the freeze
-- node is at the "bottom" of a package spec.
if Nkind (Context) = N_Package_Specification then
Prv_Decls := Private_Declarations (Context);
Vis_Decls := Visible_Declarations (Context);
-- The freeze node appears in the private declarations of the
-- package.
if Present (Prv_Decls)
and then List_Containing (FNode) = Prv_Decls
then
null;
-- The freeze node appears in the visible declarations of the
-- package and there are no private declarations.
elsif Present (Vis_Decls)
and then List_Containing (FNode) = Vis_Decls
and then (No (Prv_Decls) or else Is_Empty_List (Prv_Decls))
then
null;
-- Otherwise the freeze node is not in the "last" declarative
-- list of the package. Use the existing source location of the
-- freeze node.
else
return Loc;
end if;
-- The freeze node appears at the "bottom" of the package when
-- it is in the "last" declarative list and is either the last
-- in the list or is followed by internal constructs only. In
-- that case the more appropriate source location is that of
-- the package end label.
if not Precedes_Source_Construct (FNode) then
return Sloc (End_Label (Context));
end if;
end if;
return Loc;
end Freeze_Node_Location;
-------------------------------
-- Precedes_Source_Construct --
-------------------------------
function Precedes_Source_Construct (N : Node_Id) return Boolean is
Decl : Node_Id;
begin
Decl := Next (N);
while Present (Decl) loop
if Comes_From_Source (Decl) then
return True;
-- A generated body for a source expression function is treated
-- as a source construct.
elsif Nkind (Decl) = N_Subprogram_Body
and then Was_Expression_Function (Decl)
and then Comes_From_Source (Original_Node (Decl))
then
return True;
end if;
Next (Decl);
end loop;
return False;
end Precedes_Source_Construct;
----------------------------
-- Suggest_Elaborate_Body --
----------------------------
procedure Suggest_Elaborate_Body
(N : Node_Id;
Body_Decl : Node_Id;
Error_Nod : Node_Id)
is
Unit_Id : constant Node_Id := Unit (Cunit (Main_Unit));
Region : Node_Id;
begin
-- The suggestion applies only when the subprogram body resides in
-- a compilation package body, and a pragma Elaborate_Body would
-- allow for the node to appear in the early call region of the
-- subprogram body. This implies that all code from the subprogram
-- body up to the node is preelaborable.
if Nkind (Unit_Id) = N_Package_Body then
-- Find the start of the early call region again assuming that
-- the package spec has pragma Elaborate_Body. Note that the
-- internal data structures are intentionally not updated
-- because this is a speculative search.
Region :=
Find_Early_Call_Region
(Body_Decl => Body_Decl,
Assume_Elab_Body => True,
Skip_Memoization => True);
-- If the node appears within the early call region, assuming
-- that the package spec carries pragma Elaborate_Body, then it
-- is safe to suggest the pragma.
if Earlier_In_Extended_Unit (Region, N) then
Error_Msg_Name_1 := Name_Elaborate_Body;
Error_Msg_NE
("\consider adding pragma % in spec of unit &",
Error_Nod, Defining_Entity (Unit_Id));
end if;
end if;
end Suggest_Elaborate_Body;
-- Local variables
FNode : constant Node_Id := Freeze_Node (Typ);
Prims : constant Elist_Id := Direct_Primitive_Operations (Typ);
Prim_Elmt : Elmt_Id;
-- Start of processing for Process_SPARK_Derived_Type
begin
-- A type should have its freeze node set by the time SPARK scenarios
-- are being verified.
pragma Assert (Present (FNode));
-- Verify that the freeze node of the derived type is within the
-- early call region of each overriding primitive body
-- (SPARK RM 7.7(8)).
if Present (Prims) then
Prim_Elmt := First_Elmt (Prims);
while Present (Prim_Elmt) loop
Check_Overriding_Primitive
(Prim => Node (Prim_Elmt),
FNode => FNode);
Next_Elmt (Prim_Elmt);
end loop;
end if;
exception
when Stop_Check =>
null;
end Process_SPARK_Derived_Type;
---------------------------------
-- Process_SPARK_Instantiation --
---------------------------------
procedure Process_SPARK_Instantiation
(Inst : Node_Id;
Inst_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
Gen_Id : constant Entity_Id := Target (Inst_Rep);
Gen_Rep : constant Target_Rep_Id :=
Target_Representation_Of (Gen_Id, In_State);
Body_Decl : constant Node_Id := Body_Declaration (Gen_Rep);
begin
-- The instantiation and the generic body are both in the main unit
if Present (Body_Decl)
and then In_Extended_Main_Code_Unit (Body_Decl)
-- If the instantiation appears prior to the generic body, then the
-- instantiation is illegal (SPARK RM 7.7(6)).
-- IMPORTANT: This check must always be performed even when
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not
-- specified because the rule prevents use-before-declaration of
-- objects that may precede the generic body.
and then Earlier_In_Extended_Unit (Inst, Body_Decl)
then
Error_Msg_NE
("cannot instantiate & before body seen", Inst, Gen_Id);
end if;
end Process_SPARK_Instantiation;
----------------------------
-- Process_SPARK_Scenario --
----------------------------
procedure Process_SPARK_Scenario
(N : Node_Id;
In_State : Processing_In_State)
is
Scen : constant Node_Id := Scenario (N);
begin
-- Ensure that a suitable elaboration model is in effect for SPARK
-- rule verification.
Check_SPARK_Model_In_Effect;
-- Add the current scenario to the stack of active scenarios
Push_Active_Scenario (Scen);
-- Derived type
if Is_Suitable_SPARK_Derived_Type (Scen) then
Process_SPARK_Derived_Type
(Typ_Decl => Scen,
Typ_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Instantiation
elsif Is_Suitable_SPARK_Instantiation (Scen) then
Process_SPARK_Instantiation
(Inst => Scen,
Inst_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
-- Refined_State pragma
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then
Process_SPARK_Refined_State_Pragma
(Prag => Scen,
Prag_Rep => Scenario_Representation_Of (Scen, In_State),
In_State => In_State);
end if;
-- Remove the current scenario from the stack of active scenarios
-- once all ABE diagnostics and checks have been performed.
Pop_Active_Scenario (Scen);
end Process_SPARK_Scenario;
----------------------------------------
-- Process_SPARK_Refined_State_Pragma --
----------------------------------------
procedure Process_SPARK_Refined_State_Pragma
(Prag : Node_Id;
Prag_Rep : Scenario_Rep_Id;
In_State : Processing_In_State)
is
pragma Unreferenced (Prag_Rep);
procedure Check_SPARK_Constituent (Constit_Id : Entity_Id);
pragma Inline (Check_SPARK_Constituent);
-- Ensure that a single constituent Constit_Id is elaborated prior to
-- the main unit.
procedure Check_SPARK_Constituents (Constits : Elist_Id);
pragma Inline (Check_SPARK_Constituents);
-- Ensure that all constituents found in list Constits are elaborated
-- prior to the main unit.
procedure Check_SPARK_Initialized_State (State : Node_Id);
pragma Inline (Check_SPARK_Initialized_State);
-- Ensure that the constituents of single abstract state State are
-- elaborated prior to the main unit.
procedure Check_SPARK_Initialized_States (Pack_Id : Entity_Id);
pragma Inline (Check_SPARK_Initialized_States);
-- Ensure that the constituents of all abstract states which appear
-- in the Initializes pragma of package Pack_Id are elaborated prior
-- to the main unit.
-----------------------------
-- Check_SPARK_Constituent --
-----------------------------
procedure Check_SPARK_Constituent (Constit_Id : Entity_Id) is
SM_Prag : Node_Id;
begin
-- Nothing to do for "null" constituents
if Nkind (Constit_Id) = N_Null then
return;
-- Nothing to do for illegal constituents
elsif Error_Posted (Constit_Id) then
return;
end if;
SM_Prag := SPARK_Pragma (Constit_Id);
-- The check applies only when the constituent is subject to
-- pragma SPARK_Mode On.
if Present (SM_Prag)
and then Get_SPARK_Mode_From_Annotation (SM_Prag) = On
then
-- An external constituent of an abstract state which appears
-- in the Initializes pragma of a package spec imposes an
-- Elaborate requirement on the context of the main unit.
-- Determine whether the context has a pragma strong enough to
-- meet the requirement.
-- IMPORTANT: This check is performed only when -gnatd.v
-- (enforce SPARK elaboration rules in SPARK code) is in effect
-- because the static model can ensure the prior elaboration of
-- the unit which contains a constituent by installing implicit
-- Elaborate pragma.
if Debug_Flag_Dot_V then
Meet_Elaboration_Requirement
(N => Prag,
Targ_Id => Constit_Id,
Req_Nam => Name_Elaborate,
In_State => In_State);
-- Otherwise ensure that the unit with the external constituent
-- is elaborated prior to the main unit.
else
Ensure_Prior_Elaboration
(N => Prag,
Unit_Id => Find_Top_Unit (Constit_Id),
Prag_Nam => Name_Elaborate,
In_State => In_State);
end if;
end if;
end Check_SPARK_Constituent;
------------------------------
-- Check_SPARK_Constituents --
------------------------------
procedure Check_SPARK_Constituents (Constits : Elist_Id) is
Constit_Elmt : Elmt_Id;
begin
if Present (Constits) then
Constit_Elmt := First_Elmt (Constits);
while Present (Constit_Elmt) loop
Check_SPARK_Constituent (Node (Constit_Elmt));
Next_Elmt (Constit_Elmt);
end loop;
end if;
end Check_SPARK_Constituents;
-----------------------------------
-- Check_SPARK_Initialized_State --
-----------------------------------
procedure Check_SPARK_Initialized_State (State : Node_Id) is
SM_Prag : Node_Id;
State_Id : Entity_Id;
begin
-- Nothing to do for "null" initialization items
if Nkind (State) = N_Null then
return;
-- Nothing to do for illegal states
elsif Error_Posted (State) then
return;
end if;
State_Id := Entity_Of (State);
-- Sanitize the state
if No (State_Id) then
return;
elsif Error_Posted (State_Id) then
return;
elsif Ekind (State_Id) /= E_Abstract_State then
return;
end if;
-- The check is performed only when the abstract state is subject
-- to SPARK_Mode On.
SM_Prag := SPARK_Pragma (State_Id);
if Present (SM_Prag)
and then Get_SPARK_Mode_From_Annotation (SM_Prag) = On
then
Check_SPARK_Constituents (Refinement_Constituents (State_Id));
end if;
end Check_SPARK_Initialized_State;
------------------------------------
-- Check_SPARK_Initialized_States --
------------------------------------
procedure Check_SPARK_Initialized_States (Pack_Id : Entity_Id) is
Init_Prag : constant Node_Id :=
Get_Pragma (Pack_Id, Pragma_Initializes);
Init : Node_Id;
Inits : Node_Id;
begin
if Present (Init_Prag) then
Inits := Expression (Get_Argument (Init_Prag, Pack_Id));
-- Avoid processing a "null" initialization list. The only
-- other alternative is an aggregate.
if Nkind (Inits) = N_Aggregate then
-- The initialization items appear in list form:
--
-- (state1, state2)
if Present (Expressions (Inits)) then
Init := First (Expressions (Inits));
while Present (Init) loop
Check_SPARK_Initialized_State (Init);
Next (Init);
end loop;
end if;
-- The initialization items appear in associated form:
--
-- (state1 => item1,
-- state2 => (item2, item3))
if Present (Component_Associations (Inits)) then
Init := First (Component_Associations (Inits));
while Present (Init) loop
Check_SPARK_Initialized_State (Init);
Next (Init);
end loop;
end if;
end if;
end if;
end Check_SPARK_Initialized_States;
-- Local variables
Pack_Body : constant Node_Id := Find_Related_Package_Or_Body (Prag);
-- Start of processing for Process_SPARK_Refined_State_Pragma
begin
-- Pragma Refined_State must be associated with a package body
pragma Assert
(Present (Pack_Body) and then Nkind (Pack_Body) = N_Package_Body);
-- Verify that each external contitunent of an abstract state
-- mentioned in pragma Initializes is properly elaborated.
Check_SPARK_Initialized_States (Unique_Defining_Entity (Pack_Body));
end Process_SPARK_Refined_State_Pragma;
end SPARK_Processor;
-------------------------------
-- Spec_And_Body_From_Entity --
-------------------------------
procedure Spec_And_Body_From_Entity
(Id : Node_Id;
Spec_Decl : out Node_Id;
Body_Decl : out Node_Id)
is
begin
Spec_And_Body_From_Node
(N => Unit_Declaration_Node (Id),
Spec_Decl => Spec_Decl,
Body_Decl => Body_Decl);
end Spec_And_Body_From_Entity;
-----------------------------
-- Spec_And_Body_From_Node --
-----------------------------
procedure Spec_And_Body_From_Node
(N : Node_Id;
Spec_Decl : out Node_Id;
Body_Decl : out Node_Id)
is
Body_Id : Entity_Id;
Spec_Id : Entity_Id;
begin
-- Assume that the construct lacks spec and body
Body_Decl := Empty;
Spec_Decl := Empty;
-- Bodies
if Nkind (N) in N_Package_Body
| N_Protected_Body
| N_Subprogram_Body
| N_Task_Body
then
Spec_Id := Corresponding_Spec (N);
-- The body completes a previous declaration
if Present (Spec_Id) then
Spec_Decl := Unit_Declaration_Node (Spec_Id);
-- Otherwise the body acts as the initial declaration, and is both a
-- spec and body. There is no need to look for an optional body.
else
Body_Decl := N;
Spec_Decl := N;
return;
end if;
-- Declarations
elsif Nkind (N) in N_Entry_Declaration
| N_Generic_Package_Declaration
| N_Generic_Subprogram_Declaration
| N_Package_Declaration
| N_Protected_Type_Declaration
| N_Subprogram_Declaration
| N_Task_Type_Declaration
then
Spec_Decl := N;
-- Expression function
elsif Nkind (N) = N_Expression_Function then
Spec_Id := Corresponding_Spec (N);
pragma Assert (Present (Spec_Id));
Spec_Decl := Unit_Declaration_Node (Spec_Id);
-- Instantiations
elsif Nkind (N) in N_Generic_Instantiation then
Spec_Decl := Instance_Spec (N);
pragma Assert (Present (Spec_Decl));
-- Stubs
elsif Nkind (N) in N_Body_Stub then
Spec_Id := Corresponding_Spec_Of_Stub (N);
-- The stub completes a previous declaration
if Present (Spec_Id) then
Spec_Decl := Unit_Declaration_Node (Spec_Id);
-- Otherwise the stub acts as a spec
else
Spec_Decl := N;
end if;
end if;
-- Obtain an optional or mandatory body
if Present (Spec_Decl) then
Body_Id := Corresponding_Body (Spec_Decl);
if Present (Body_Id) then
Body_Decl := Unit_Declaration_Node (Body_Id);
end if;
end if;
end Spec_And_Body_From_Node;
-------------------------------
-- Static_Elaboration_Checks --
-------------------------------
function Static_Elaboration_Checks return Boolean is
begin
return not Dynamic_Elaboration_Checks;
end Static_Elaboration_Checks;
-----------------
-- Unit_Entity --
-----------------
function Unit_Entity (Unit_Id : Entity_Id) return Entity_Id is
function Is_Subunit (Id : Entity_Id) return Boolean;
pragma Inline (Is_Subunit);
-- Determine whether the entity of an initial declaration denotes a
-- subunit.
----------------
-- Is_Subunit --
----------------
function Is_Subunit (Id : Entity_Id) return Boolean is
Decl : constant Node_Id := Unit_Declaration_Node (Id);
begin
return
Nkind (Decl) in N_Generic_Package_Declaration
| N_Generic_Subprogram_Declaration
| N_Package_Declaration
| N_Protected_Type_Declaration
| N_Subprogram_Declaration
| N_Task_Type_Declaration
and then Present (Corresponding_Body (Decl))
and then Nkind (Parent (Unit_Declaration_Node
(Corresponding_Body (Decl)))) = N_Subunit;
end Is_Subunit;
-- Local variables
Id : Entity_Id;
-- Start of processing for Unit_Entity
begin
Id := Unique_Entity (Unit_Id);
-- Skip all subunits found in the scope chain which ends at the input
-- unit.
while Is_Subunit (Id) loop
Id := Scope (Id);
end loop;
return Id;
end Unit_Entity;
---------------------------------
-- Update_Elaboration_Scenario --
---------------------------------
procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id) is
begin
-- Nothing to do when the elaboration phase of the compiler is not
-- active.
if not Elaboration_Phase_Active then
return;
-- Nothing to do when the old and new scenarios are one and the same
elsif Old_N = New_N then
return;
end if;
-- A scenario is being transformed by Atree.Rewrite. Update all relevant
-- internal data structures to reflect this change. This ensures that a
-- potential run-time conditional ABE check or a guaranteed ABE failure
-- is inserted at the proper place in the tree.
if Is_Scenario (Old_N) then
Replace_Scenario (Old_N, New_N);
end if;
end Update_Elaboration_Scenario;
---------------------------------------------------------------------------
-- --
-- L E G A C Y A C C E S S B E F O R E E L A B O R A T I O N --
-- --
-- M E C H A N I S M --
-- --
---------------------------------------------------------------------------
-- This section contains the implementation of the pre-18.x legacy ABE
-- mechanism. The mechanism can be activated using switch -gnatH (legacy
-- elaboration checking mode enabled).
-----------------------------
-- Description of Approach --
-----------------------------
-- Every non-static call that is encountered by Sem_Res results in a call
-- to Check_Elab_Call, with N being the call node, and Outer set to its
-- default value of True. In addition X'Access is treated like a call
-- for the access-to-procedure case, and in SPARK mode only we also
-- check variable references.
-- The goal of Check_Elab_Call is to determine whether or not the reference
-- in question can generate an access before elaboration error (raising
-- Program_Error) either by directly calling a subprogram whose body
-- has not yet been elaborated, or indirectly, by calling a subprogram
-- whose body has been elaborated, but which contains a call to such a
-- subprogram.
-- In addition, in SPARK mode, we are checking for a variable reference in
-- another package, which requires an explicit Elaborate_All pragma.
-- The only references that we need to look at the outer level are
-- references that occur in elaboration code. There are two cases. The
-- reference can be at the outer level of elaboration code, or it can
-- be within another unit, e.g. the elaboration code of a subprogram.
-- In the case of an elaboration call at the outer level, we must trace
-- all calls to outer level routines either within the current unit or to
-- other units that are with'ed. For calls within the current unit, we can
-- determine if the body has been elaborated or not, and if it has not,
-- then a warning is generated.
-- Note that there are two subcases. If the original call directly calls a
-- subprogram whose body has not been elaborated, then we know that an ABE
-- will take place, and we replace the call by a raise of Program_Error.
-- If the call is indirect, then we don't know that the PE will be raised,
-- since the call might be guarded by a conditional. In this case we set
-- Do_Elab_Check on the call so that a dynamic check is generated, and
-- output a warning.
-- For calls to a subprogram in a with'ed unit or a 'Access or variable
-- reference (SPARK mode case), we require that a pragma Elaborate_All
-- or pragma Elaborate be present, or that the referenced unit have a
-- pragma Preelaborate, pragma Pure, or pragma Elaborate_Body. If none
-- of these conditions is met, then a warning is generated that a pragma
-- Elaborate_All may be needed (error in the SPARK case), or an implicit
-- pragma is generated.
-- For the case of an elaboration call at some inner level, we are
-- interested in tracing only calls to subprograms at the same level, i.e.
-- those that can be called during elaboration. Any calls to outer level
-- routines cannot cause ABE's as a result of the original call (there
-- might be an outer level call to the subprogram from outside that causes
-- the ABE, but that gets analyzed separately).
-- Note that we never trace calls to inner level subprograms, since these
-- cannot result in ABE's unless there is an elaboration problem at a lower
-- level, which will be separately detected.
-- Note on pragma Elaborate. The checking here assumes that a pragma
-- Elaborate on a with'ed unit guarantees that subprograms within the unit
-- can be called without causing an ABE. This is not in fact the case since
-- pragma Elaborate does not guarantee the transitive coverage guaranteed
-- by Elaborate_All. However, we decide to trust the user in this case.
--------------------------------------
-- Instantiation Elaboration Errors --
--------------------------------------
-- A special case arises when an instantiation appears in a context that is
-- known to be before the body is elaborated, e.g.
-- generic package x is ...
-- ...
-- package xx is new x;
-- ...
-- package body x is ...
-- In this situation it is certain that an elaboration error will occur,
-- and an unconditional raise Program_Error statement is inserted before
-- the instantiation, and a warning generated.
-- The problem is that in this case we have no place to put the body of
-- the instantiation. We can't put it in the normal place, because it is
-- too early, and will cause errors to occur as a result of referencing
-- entities before they are declared.
-- Our approach in this case is simply to avoid creating the body of the
-- instantiation in such a case. The instantiation spec is modified to
-- include dummy bodies for all subprograms, so that the resulting code
-- does not contain subprogram specs with no corresponding bodies.
-- The following table records the recursive call chain for output in the
-- Output routine. Each entry records the call node and the entity of the
-- called routine. The number of entries in the table (i.e. the value of
-- Elab_Call.Last) indicates the current depth of recursion and is used to
-- identify the outer level.
type Elab_Call_Element is record
Cloc : Source_Ptr;
Ent : Entity_Id;
end record;
package Elab_Call is new Table.Table
(Table_Component_Type => Elab_Call_Element,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 50,
Table_Increment => 100,
Table_Name => "Elab_Call");
-- The following table records all calls that have been processed starting
-- from an outer level call. The table prevents both infinite recursion and
-- useless reanalysis of calls within the same context. The use of context
-- is important because it allows for proper checks in more complex code:
-- if ... then
-- Call; -- requires a check
-- Call; -- does not need a check thanks to the table
-- elsif ... then
-- Call; -- requires a check, different context
-- end if;
-- Call; -- requires a check, different context
type Visited_Element is record
Subp_Id : Entity_Id;
-- The entity of the subprogram being called
Context : Node_Id;
-- The context where the call to the subprogram occurs
end record;
package Elab_Visited is new Table.Table
(Table_Component_Type => Visited_Element,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 200,
Table_Increment => 100,
Table_Name => "Elab_Visited");
-- The following table records delayed calls which must be examined after
-- all generic bodies have been instantiated.
type Delay_Element is record
N : Node_Id;
-- The parameter N from the call to Check_Internal_Call. Note that this
-- node may get rewritten over the delay period by expansion in the call
-- case (but not in the instantiation case).
E : Entity_Id;
-- The parameter E from the call to Check_Internal_Call
Orig_Ent : Entity_Id;
-- The parameter Orig_Ent from the call to Check_Internal_Call
Curscop : Entity_Id;
-- The current scope of the call. This is restored when we complete the
-- delayed call, so that we do this in the right scope.
Outer_Scope : Entity_Id;
-- Save scope of outer level call
From_Elab_Code : Boolean;
-- Save indication of whether this call is from elaboration code
In_Task_Activation : Boolean;
-- Save indication of whether this call is from a task body. Tasks are
-- activated at the "begin", which is after all local procedure bodies,
-- so calls to those procedures can't fail, even if they occur after the
-- task body.
From_SPARK_Code : Boolean;
-- Save indication of whether this call is under SPARK_Mode => On
end record;
package Delay_Check is new Table.Table
(Table_Component_Type => Delay_Element,
Table_Index_Type => Int,
Table_Low_Bound => 1,
Table_Initial => 1000,
Table_Increment => 100,
Table_Name => "Delay_Check");
C_Scope : Entity_Id;
-- Top-level scope of current scope. Compute this only once at the outer
-- level, i.e. for a call to Check_Elab_Call from outside this unit.
Outer_Level_Sloc : Source_Ptr;
-- Save Sloc value for outer level call node for comparisons of source
-- locations. A body is too late if it appears after the *outer* level
-- call, not the particular call that is being analyzed.
From_Elab_Code : Boolean;
-- This flag shows whether the outer level call currently being examined
-- is or is not in elaboration code. We are only interested in calls to
-- routines in other units if this flag is True.
In_Task_Activation : Boolean := False;
-- This flag indicates whether we are performing elaboration checks on task
-- bodies, at the point of activation. If true, we do not raise
-- Program_Error for calls to local procedures, because all local bodies
-- are known to be elaborated. However, we still need to trace such calls,
-- because a local procedure could call a procedure in another package,
-- so we might need an implicit Elaborate_All.
Delaying_Elab_Checks : Boolean := True;
-- This is set True till the compilation is complete, including the
-- insertion of all instance bodies. Then when Check_Elab_Calls is called,
-- the delay table is used to make the delayed calls and this flag is reset
-- to False, so that the calls are processed.
-----------------------
-- Local Subprograms --
-----------------------
-- Note: Outer_Scope in all following specs represents the scope of
-- interest of the outer level call. If it is set to Standard_Standard,
-- then it means the outer level call was at elaboration level, and that
-- thus all calls are of interest. If it was set to some other scope,
-- then the original call was an inner call, and we are not interested
-- in calls that go outside this scope.
procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id);
-- Analysis of construct N shows that we should set Elaborate_All_Desirable
-- for the WITH clause for unit U (which will always be present). A special
-- case is when N is a function or procedure instantiation, in which case
-- it is sufficient to set Elaborate_Desirable, since in this case there is
-- no possibility of transitive elaboration issues.
procedure Check_A_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Inter_Unit_Only : Boolean;
Generate_Warnings : Boolean := True;
In_Init_Proc : Boolean := False);
-- This is the internal recursive routine that is called to check for
-- possible elaboration error. The argument N is a subprogram call or
-- generic instantiation, or 'Access attribute reference to be checked, and
-- E is the entity of the called subprogram, or instantiated generic unit,
-- or subprogram referenced by 'Access.
--
-- In SPARK mode, N can also be a variable reference, since in SPARK this
-- also triggers a requirement for Elaborate_All, and in this case E is the
-- entity being referenced.
--
-- Outer_Scope is the outer level scope for the original reference.
-- Inter_Unit_Only is set if the call is only to be checked in the
-- case where it is to another unit (and skipped if within a unit).
-- Generate_Warnings is set to False to suppress warning messages about
-- missing pragma Elaborate_All's. These messages are not wanted for
-- inner calls in the dynamic model. Note that an instance of the Access
-- attribute applied to a subprogram also generates a call to this
-- procedure (since the referenced subprogram may be called later
-- indirectly). Flag In_Init_Proc should be set whenever the current
-- context is a type init proc.
--
-- Note: this might better be called Check_A_Reference to recognize the
-- variable case for SPARK, but we prefer to retain the historical name
-- since in practice this is mostly about checking calls for the possible
-- occurrence of an access-before-elaboration exception.
procedure Check_Bad_Instantiation (N : Node_Id);
-- N is a node for an instantiation (if called with any other node kind,
-- Check_Bad_Instantiation ignores the call). This subprogram checks for
-- the special case of a generic instantiation of a generic spec in the
-- same declarative part as the instantiation where a body is present and
-- has not yet been seen. This is an obvious error, but needs to be checked
-- specially at the time of the instantiation, since it is a case where we
-- cannot insert the body anywhere. If this case is detected, warnings are
-- generated, and a raise of Program_Error is inserted. In addition any
-- subprograms in the generic spec are stubbed, and the Bad_Instantiation
-- flag is set on the instantiation node. The caller in Sem_Ch12 uses this
-- flag as an indication that no attempt should be made to insert an
-- instance body.
procedure Check_Internal_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id);
-- N is a function call or procedure statement call node and E is the
-- entity of the called function, which is within the current compilation
-- unit (where subunits count as part of the parent). This call checks if
-- this call, or any call within any accessed body could cause an ABE, and
-- if so, outputs a warning. Orig_Ent differs from E only in the case of
-- renamings, and points to the original name of the entity. This is used
-- for error messages. Outer_Scope is the outer level scope for the
-- original call.
procedure Check_Internal_Call_Continue
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id);
-- The processing for Check_Internal_Call is divided up into two phases,
-- and this represents the second phase. The second phase is delayed if
-- Delaying_Elab_Checks is set to True. In this delayed case, the first
-- phase makes an entry in the Delay_Check table, which is processed when
-- Check_Elab_Calls is called. N, E and Orig_Ent are as for the call to
-- Check_Internal_Call. Outer_Scope is the outer level scope for the
-- original call.
function Get_Referenced_Ent (N : Node_Id) return Entity_Id;
-- N is either a function or procedure call or an access attribute that
-- references a subprogram. This call retrieves the relevant entity. If
-- this is a call to a protected subprogram, the entity is a selected
-- component. The callable entity may be absent, in which case Empty is
-- returned. This happens with non-analyzed calls in nested generics.
--
-- If SPARK_Mode is On, then N can also be a reference to an E_Variable
-- entity, in which case, the value returned is simply this entity.
function Has_Generic_Body (N : Node_Id) return Boolean;
-- N is a generic package instantiation node, and this routine determines
-- if this package spec does in fact have a generic body. If so, then
-- True is returned, otherwise False. Note that this is not at all the
-- same as checking if the unit requires a body, since it deals with
-- the case of optional bodies accurately (i.e. if a body is optional,
-- then it looks to see if a body is actually present). Note: this
-- function can only do a fully correct job if in generating code mode
-- where all bodies have to be present. If we are operating in semantics
-- check only mode, then in some cases of optional bodies, a result of
-- False may incorrectly be given. In practice this simply means that
-- some cases of warnings for incorrect order of elaboration will only
-- be given when generating code, which is not a big problem (and is
-- inevitable, given the optional body semantics of Ada).
procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty);
-- Given code for an elaboration check (or unconditional raise if the check
-- is not needed), inserts the code in the appropriate place. N is the call
-- or instantiation node for which the check code is required. C is the
-- test whose failure triggers the raise.
function Is_Call_Of_Generic_Formal (N : Node_Id) return Boolean;
-- Returns True if node N is a call to a generic formal subprogram
function Is_Finalization_Procedure (Id : Entity_Id) return Boolean;
-- Determine whether entity Id denotes a [Deep_]Finalize procedure
procedure Output_Calls
(N : Node_Id;
Check_Elab_Flag : Boolean);
-- Outputs chain of calls stored in the Elab_Call table. The caller has
-- already generated the main warning message, so the warnings generated
-- are all continuation messages. The argument is the call node at which
-- the messages are to be placed. When Check_Elab_Flag is set, calls are
-- enumerated only when flag Elab_Warning is set for the dynamic case or
-- when flag Elab_Info_Messages is set for the static case.
function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean;
-- Given two scopes, determine whether they are the same scope from an
-- elaboration point of view, i.e. packages and blocks are ignored.
procedure Set_C_Scope;
-- On entry C_Scope is set to some scope. On return, C_Scope is reset
-- to be the enclosing compilation unit of this scope.
procedure Set_Elaboration_Constraint
(Call : Node_Id;
Subp : Entity_Id;
Scop : Entity_Id);
-- The current unit U may depend semantically on some unit P that is not
-- in the current context. If there is an elaboration call that reaches P,
-- we need to indicate that P requires an Elaborate_All, but this is not
-- effective in U's ali file, if there is no with_clause for P. In this
-- case we add the Elaborate_All on the unit Q that directly or indirectly
-- makes P available. This can happen in two cases:
--
-- a) Q declares a subtype of a type declared in P, and the call is an
-- initialization call for an object of that subtype.
--
-- b) Q declares an object of some tagged type whose root type is
-- declared in P, and the initialization call uses object notation on
-- that object to reach a primitive operation or a classwide operation
-- declared in P.
--
-- If P appears in the context of U, the current processing is correct.
-- Otherwise we must identify these two cases to retrieve Q and place the
-- Elaborate_All_Desirable on it.
function Spec_Entity (E : Entity_Id) return Entity_Id;
-- Given a compilation unit entity, if it is a spec entity, it is returned
-- unchanged. If it is a body entity, then the spec for the corresponding
-- spec is returned
function Within (E1, E2 : Entity_Id) return Boolean;
-- Given two scopes E1 and E2, returns True if E1 is equal to E2, or is one
-- of its contained scopes, False otherwise.
function Within_Elaborate_All
(Unit : Unit_Number_Type;
E : Entity_Id) return Boolean;
-- Return True if we are within the scope of an Elaborate_All for E, or if
-- we are within the scope of an Elaborate_All for some other unit U, and U
-- with's E. This prevents spurious warnings when the called entity is
-- renamed within U, or in case of generic instances.
--------------------------------------
-- Activate_Elaborate_All_Desirable --
--------------------------------------
procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id) is
UN : constant Unit_Number_Type := Get_Code_Unit (N);
CU : constant Node_Id := Cunit (UN);
UE : constant Entity_Id := Cunit_Entity (UN);
Unm : constant Unit_Name_Type := Unit_Name (UN);
CI : constant List_Id := Context_Items (CU);
Itm : Node_Id;
Ent : Entity_Id;
procedure Add_To_Context_And_Mark (Itm : Node_Id);
-- This procedure is called when the elaborate indication must be
-- applied to a unit not in the context of the referencing unit. The
-- unit gets added to the context as an implicit with.
function In_Withs_Of (UEs : Entity_Id) return Boolean;
-- UEs is the spec entity of a unit. If the unit to be marked is
-- in the context item list of this unit spec, then the call returns
-- True and Itm is left set to point to the relevant N_With_Clause node.
procedure Set_Elab_Flag (Itm : Node_Id);
-- Sets Elaborate_[All_]Desirable as appropriate on Itm
-----------------------------
-- Add_To_Context_And_Mark --
-----------------------------
procedure Add_To_Context_And_Mark (Itm : Node_Id) is
CW : constant Node_Id :=
Make_With_Clause (Sloc (Itm),
Name => Name (Itm));
begin
Set_Library_Unit (CW, Library_Unit (Itm));
Set_Implicit_With (CW);
-- Set elaborate all desirable on copy and then append the copy to
-- the list of body with's and we are done.
Set_Elab_Flag (CW);
Append_To (CI, CW);
end Add_To_Context_And_Mark;
-----------------
-- In_Withs_Of --
-----------------
function In_Withs_Of (UEs : Entity_Id) return Boolean is
UNs : constant Unit_Number_Type := Get_Source_Unit (UEs);
CUs : constant Node_Id := Cunit (UNs);
CIs : constant List_Id := Context_Items (CUs);
begin
Itm := First (CIs);
while Present (Itm) loop
if Nkind (Itm) = N_With_Clause then
Ent :=
Cunit_Entity (Get_Cunit_Unit_Number (Library_Unit (Itm)));
if U = Ent then
return True;
end if;
end if;
Next (Itm);
end loop;
return False;
end In_Withs_Of;
-------------------
-- Set_Elab_Flag --
-------------------
procedure Set_Elab_Flag (Itm : Node_Id) is
begin
if Nkind (N) in N_Subprogram_Instantiation then
Set_Elaborate_Desirable (Itm);
else
Set_Elaborate_All_Desirable (Itm);
end if;
end Set_Elab_Flag;
-- Start of processing for Activate_Elaborate_All_Desirable
begin
-- Do not set binder indication if expansion is disabled, as when
-- compiling a generic unit.
if not Expander_Active then
return;
end if;
-- If an instance of a generic package contains a controlled object (so
-- we're calling Initialize at elaboration time), and the instance is in
-- a package body P that says "with P;", then we need to return without
-- adding "pragma Elaborate_All (P);" to P.
if U = Main_Unit_Entity then
return;
end if;
Itm := First (CI);
while Present (Itm) loop
if Nkind (Itm) = N_With_Clause then
Ent := Cunit_Entity (Get_Cunit_Unit_Number (Library_Unit (Itm)));
-- If we find it, then mark elaborate all desirable and return
if U = Ent then
Set_Elab_Flag (Itm);
return;
end if;
end if;
Next (Itm);
end loop;
-- If we fall through then the with clause is not present in the
-- current unit. One legitimate possibility is that the with clause
-- is present in the spec when we are a body.
if Is_Body_Name (Unm)
and then In_Withs_Of (Spec_Entity (UE))
then
Add_To_Context_And_Mark (Itm);
return;
end if;
-- Similarly, we may be in the spec or body of a child unit, where
-- the unit in question is with'ed by some ancestor of the child unit.
if Is_Child_Name (Unm) then
declare
Pkg : Entity_Id;
begin
Pkg := UE;
loop
Pkg := Scope (Pkg);
exit when Pkg = Standard_Standard;
if In_Withs_Of (Pkg) then
Add_To_Context_And_Mark (Itm);
return;
end if;
end loop;
end;
end if;
-- Here if we do not find with clause on spec or body. We just ignore
-- this case; it means that the elaboration involves some other unit
-- than the unit being compiled, and will be caught elsewhere.
end Activate_Elaborate_All_Desirable;
------------------
-- Check_A_Call --
------------------
procedure Check_A_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Inter_Unit_Only : Boolean;
Generate_Warnings : Boolean := True;
In_Init_Proc : Boolean := False)
is
Access_Case : constant Boolean := Nkind (N) = N_Attribute_Reference;
-- Indicates if we have Access attribute case
function Call_To_Instance_From_Outside (Id : Entity_Id) return Boolean;
-- True if we're calling an instance of a generic subprogram, or a
-- subprogram in an instance of a generic package, and the call is
-- outside that instance.
procedure Elab_Warning
(Msg_D : String;
Msg_S : String;
Ent : Node_Or_Entity_Id);
-- Generate a call to Error_Msg_NE with parameters Msg_D or Msg_S (for
-- dynamic or static elaboration model), N and Ent. Msg_D is a real
-- warning (output if Msg_D is non-null and Elab_Warnings is set),
-- Msg_S is an info message (output if Elab_Info_Messages is set).
function Find_W_Scope return Entity_Id;
-- Find top-level scope for called entity (not following renamings
-- or derivations). This is where the Elaborate_All will go if it is
-- needed. We start with the called entity, except in the case of an
-- initialization procedure outside the current package, where the init
-- proc is in the root package, and we start from the entity of the name
-- in the call.
-----------------------------------
-- Call_To_Instance_From_Outside --
-----------------------------------
function Call_To_Instance_From_Outside (Id : Entity_Id) return Boolean is
Scop : Entity_Id := Id;
begin
loop
if Scop = Standard_Standard then
return False;
end if;
if Is_Generic_Instance (Scop) then
return not In_Open_Scopes (Scop);
end if;
Scop := Scope (Scop);
end loop;
end Call_To_Instance_From_Outside;
------------------
-- Elab_Warning --
------------------
procedure Elab_Warning
(Msg_D : String;
Msg_S : String;
Ent : Node_Or_Entity_Id)
is
begin
-- Dynamic elaboration checks, real warning
if Dynamic_Elaboration_Checks then
if not Access_Case then
if Msg_D /= "" and then Elab_Warnings then
Error_Msg_NE (Msg_D, N, Ent);
end if;
-- In the access case emit first warning message as well,
-- otherwise list of calls will appear as errors.
elsif Elab_Warnings then
Error_Msg_NE (Msg_S, N, Ent);
end if;
-- Static elaboration checks, info message
else
if Elab_Info_Messages then
Error_Msg_NE (Msg_S, N, Ent);
end if;
end if;
end Elab_Warning;
------------------
-- Find_W_Scope --
------------------
function Find_W_Scope return Entity_Id is
Refed_Ent : constant Entity_Id := Get_Referenced_Ent (N);
W_Scope : Entity_Id;
begin
if Is_Init_Proc (Refed_Ent)
and then not In_Same_Extended_Unit (N, Refed_Ent)
then
W_Scope := Scope (Refed_Ent);
else
W_Scope := E;
end if;
-- Now loop through scopes to get to the enclosing compilation unit
while not Is_Compilation_Unit (W_Scope) loop
W_Scope := Scope (W_Scope);
end loop;
return W_Scope;
end Find_W_Scope;
-- Local variables
Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
-- Indicates if we have instantiation case
Loc : constant Source_Ptr := Sloc (N);
Variable_Case : constant Boolean :=
Nkind (N) in N_Has_Entity
and then Present (Entity (N))
and then Ekind (Entity (N)) = E_Variable;
-- Indicates if we have variable reference case
W_Scope : constant Entity_Id := Find_W_Scope;
-- Top-level scope of directly called entity for subprogram. This
-- differs from E_Scope in the case where renamings or derivations
-- are involved, since it does not follow these links. W_Scope is
-- generally in a visible unit, and it is this scope that may require
-- an Elaborate_All. However, there are some cases (initialization
-- calls and calls involving object notation) where W_Scope might not
-- be in the context of the current unit, and there is an intermediate
-- package that is, in which case the Elaborate_All has to be placed
-- on this intermediate package. These special cases are handled in
-- Set_Elaboration_Constraint.
Ent : Entity_Id;
Callee_Unit_Internal : Boolean;
Caller_Unit_Internal : Boolean;
Decl : Node_Id;
Inst_Callee : Source_Ptr;
Inst_Caller : Source_Ptr;
Unit_Callee : Unit_Number_Type;
Unit_Caller : Unit_Number_Type;
Body_Acts_As_Spec : Boolean;
-- Set to true if call is to body acting as spec (no separate spec)
Cunit_SC : Boolean := False;
-- Set to suppress dynamic elaboration checks where one of the
-- enclosing scopes has Elaboration_Checks_Suppressed set, or else
-- if a pragma Elaborate[_All] applies to that scope, in which case
-- warnings on the scope are also suppressed. For the internal case,
-- we ignore this flag.
E_Scope : Entity_Id;
-- Top-level scope of entity for called subprogram. This value includes
-- following renamings and derivations, so this scope can be in a
-- non-visible unit. This is the scope that is to be investigated to
-- see whether an elaboration check is required.
Is_DIC : Boolean;
-- Flag set when the subprogram being invoked is the procedure generated
-- for pragma Default_Initial_Condition.
SPARK_Elab_Errors : Boolean;
-- Flag set when an entity is called or a variable is read during SPARK
-- dynamic elaboration.
-- Start of processing for Check_A_Call
begin
-- If the call is known to be within a local Suppress Elaboration
-- pragma, nothing to check. This can happen in task bodies. But
-- we ignore this for a call to a generic formal.
if Nkind (N) in N_Subprogram_Call
and then No_Elaboration_Check (N)
and then not Is_Call_Of_Generic_Formal (N)
then
return;
-- If this is a rewrite of a Valid_Scalars attribute, then nothing to
-- check, we don't mind in this case if the call occurs before the body
-- since this is all generated code.
elsif Nkind (Original_Node (N)) = N_Attribute_Reference
and then Attribute_Name (Original_Node (N)) = Name_Valid_Scalars
then
return;
-- Intrinsics such as instances of Unchecked_Deallocation do not have
-- any body, so elaboration checking is not needed, and would be wrong.
elsif Is_Intrinsic_Subprogram (E) then
return;
-- Do not consider references to internal variables for SPARK semantics
elsif Variable_Case and then not Comes_From_Source (E) then
return;
end if;
-- Proceed with check
Ent := E;
-- For a variable reference, just set Body_Acts_As_Spec to False
if Variable_Case then
Body_Acts_As_Spec := False;
-- Additional checks for all other cases
else
-- Go to parent for derived subprogram, or to original subprogram in
-- the case of a renaming (Alias covers both these cases).
loop
if (Suppress_Elaboration_Warnings (Ent)
or else Elaboration_Checks_Suppressed (Ent))
and then (Inst_Case or else No (Alias (Ent)))
then
return;
end if;
-- Nothing to do for imported entities
if Is_Imported (Ent) then
return;
end if;
exit when Inst_Case or else No (Alias (Ent));
Ent := Alias (Ent);
end loop;
Decl := Unit_Declaration_Node (Ent);
if Nkind (Decl) = N_Subprogram_Body then
Body_Acts_As_Spec := True;
elsif Nkind (Decl) in
N_Subprogram_Declaration | N_Subprogram_Body_Stub
or else Inst_Case
then
Body_Acts_As_Spec := False;
-- If we have none of an instantiation, subprogram body or subprogram
-- declaration, or in the SPARK case, a variable reference, then
-- it is not a case that we want to check. (One case is a call to a
-- generic formal subprogram, where we do not want the check in the
-- template).
else
return;
end if;
end if;
E_Scope := Ent;
loop
if Elaboration_Checks_Suppressed (E_Scope)
or else Suppress_Elaboration_Warnings (E_Scope)
then
Cunit_SC := True;
end if;
-- Exit when we get to compilation unit, not counting subunits
exit when Is_Compilation_Unit (E_Scope)
and then (Is_Child_Unit (E_Scope)
or else Scope (E_Scope) = Standard_Standard);
pragma Assert (E_Scope /= Standard_Standard);
-- Move up a scope looking for compilation unit
E_Scope := Scope (E_Scope);
end loop;
-- No checks needed for pure or preelaborated compilation units
if Is_Pure (E_Scope) or else Is_Preelaborated (E_Scope) then
return;
end if;
-- If the generic entity is within a deeper instance than we are, then
-- either the instantiation to which we refer itself caused an ABE, in
-- which case that will be handled separately, or else we know that the
-- body we need appears as needed at the point of the instantiation.
-- However, this assumption is only valid if we are in static mode.
if not Dynamic_Elaboration_Checks
and then
Instantiation_Depth (Sloc (Ent)) > Instantiation_Depth (Sloc (N))
then
return;
end if;
-- Do not give a warning for a package with no body
if Ekind (Ent) = E_Generic_Package and then not Has_Generic_Body (N) then
return;
end if;
-- Case of entity is in same unit as call or instantiation. In the
-- instantiation case, W_Scope may be different from E_Scope; we want
-- the unit in which the instantiation occurs, since we're analyzing
-- based on the expansion.
if W_Scope = C_Scope then
if not Inter_Unit_Only then
Check_Internal_Call (N, Ent, Outer_Scope, E);
end if;
return;
end if;
-- Case of entity is not in current unit (i.e. with'ed unit case)
-- We are only interested in such calls if the outer call was from
-- elaboration code, or if we are in Dynamic_Elaboration_Checks mode.
if not From_Elab_Code and then not Dynamic_Elaboration_Checks then
return;
end if;
-- Nothing to do if some scope said that no checks were required
if Cunit_SC then
return;
end if;
-- Nothing to do for a generic instance, because a call to an instance
-- cannot fail the elaboration check, because the body of the instance
-- is always elaborated immediately after the spec.
if Call_To_Instance_From_Outside (Ent) then
return;
end if;
-- Nothing to do if subprogram with no separate spec. However, a call
-- to Deep_Initialize may result in a call to a user-defined Initialize
-- procedure, which imposes a body dependency. This happens only if the
-- type is controlled and the Initialize procedure is not inherited.
if Body_Acts_As_Spec then
if Is_TSS (Ent, TSS_Deep_Initialize) then
declare
Typ : constant Entity_Id := Etype (First_Formal (Ent));
Init : Entity_Id;
begin
if not Is_Controlled (Typ) then
return;
else
Init := Find_Prim_Op (Typ, Name_Initialize);
if Comes_From_Source (Init) then
Ent := Init;
else
return;
end if;
end if;
end;
else
return;
end if;
end if;
-- Check cases of internal units
Callee_Unit_Internal := In_Internal_Unit (E_Scope);
-- Do not give a warning if the with'ed unit is internal and this is
-- the generic instantiation case (this saves a lot of hassle dealing
-- with the Text_IO special child units)
if Callee_Unit_Internal and Inst_Case then
return;
end if;
if C_Scope = Standard_Standard then
Caller_Unit_Internal := False;
else
Caller_Unit_Internal := In_Internal_Unit (C_Scope);
end if;
-- Do not give a warning if the with'ed unit is internal and the caller
-- is not internal (since the binder always elaborates internal units
-- first).
if Callee_Unit_Internal and not Caller_Unit_Internal then
return;
end if;
-- For now, if debug flag -gnatdE is not set, do no checking for one
-- internal unit withing another. This fixes the problem with the sgi
-- build and storage errors. To be resolved later ???
if (Callee_Unit_Internal and Caller_Unit_Internal)
and not Debug_Flag_EE
then
return;
end if;
if Is_TSS (E, TSS_Deep_Initialize) then
Ent := E;
end if;
-- If the call is in an instance, and the called entity is not
-- defined in the same instance, then the elaboration issue focuses
-- around the unit containing the template, it is this unit that
-- requires an Elaborate_All.
-- However, if we are doing dynamic elaboration, we need to chase the
-- call in the usual manner.
-- We also need to chase the call in the usual manner if it is a call
-- to a generic formal parameter, since that case was not handled as
-- part of the processing of the template.
Inst_Caller := Instantiation (Get_Source_File_Index (Sloc (N)));
Inst_Callee := Instantiation (Get_Source_File_Index (Sloc (Ent)));
if Inst_Caller = No_Location then
Unit_Caller := No_Unit;
else
Unit_Caller := Get_Source_Unit (N);
end if;
if Inst_Callee = No_Location then
Unit_Callee := No_Unit;
else
Unit_Callee := Get_Source_Unit (Ent);
end if;
if Unit_Caller /= No_Unit
and then Unit_Callee /= Unit_Caller
and then not Dynamic_Elaboration_Checks
and then not Is_Call_Of_Generic_Formal (N)
then
E_Scope := Spec_Entity (Cunit_Entity (Unit_Caller));
-- If we don't get a spec entity, just ignore call. Not quite
-- clear why this check is necessary. ???
if No (E_Scope) then
return;
end if;
-- Otherwise step to enclosing compilation unit
while not Is_Compilation_Unit (E_Scope) loop
E_Scope := Scope (E_Scope);
end loop;
-- For the case where N is not an instance, and is not a call within
-- instance to other than a generic formal, we recompute E_Scope
-- for the error message, since we do NOT want to go to the unit
-- that has the ultimate declaration in the case of renaming and
-- derivation and we also want to go to the generic unit in the
-- case of an instance, and no further.
else
-- Loop to carefully follow renamings and derivations one step
-- outside the current unit, but not further.
if not (Inst_Case or Variable_Case)
and then Present (Alias (Ent))
then
E_Scope := Alias (Ent);
else
E_Scope := Ent;
end if;
loop
while not Is_Compilation_Unit (E_Scope) loop
E_Scope := Scope (E_Scope);
end loop;
-- If E_Scope is the same as C_Scope, it means that there
-- definitely was a local renaming or derivation, and we
-- are not yet out of the current unit.
exit when E_Scope /= C_Scope;
Ent := Alias (Ent);
E_Scope := Ent;
-- If no alias, there could be a previous error, but not if we've
-- already reached the outermost level (Standard).
if No (Ent) then
return;
end if;
end loop;
end if;
if Within_Elaborate_All (Current_Sem_Unit, E_Scope) then
return;
end if;
-- Determine whether the Default_Initial_Condition procedure of some
-- type is being invoked.
Is_DIC := Ekind (Ent) = E_Procedure and then Is_DIC_Procedure (Ent);
-- Checks related to Default_Initial_Condition fall under the SPARK
-- umbrella because this is a SPARK-specific annotation.
SPARK_Elab_Errors :=
SPARK_Mode = On and (Is_DIC or Dynamic_Elaboration_Checks);
-- Now check if an Elaborate_All (or dynamic check) is needed
if (Elab_Info_Messages or Elab_Warnings or SPARK_Elab_Errors)
and then Generate_Warnings
and then not Suppress_Elaboration_Warnings (Ent)
and then not Elaboration_Checks_Suppressed (Ent)
and then not Suppress_Elaboration_Warnings (E_Scope)
and then not Elaboration_Checks_Suppressed (E_Scope)
then
-- Instantiation case
if Inst_Case then
if Comes_From_Source (Ent) and then SPARK_Elab_Errors then
Error_Msg_NE
("instantiation of & during elaboration in SPARK", N, Ent);
else
Elab_Warning
("instantiation of & may raise Program_Error?l?",
"info: instantiation of & during elaboration?$?", Ent);
end if;
-- Indirect call case, info message only in static elaboration
-- case, because the attribute reference itself cannot raise an
-- exception. Note that SPARK does not permit indirect calls.
elsif Access_Case then
Elab_Warning ("", "info: access to & during elaboration?$?", Ent);
-- Variable reference in SPARK mode
elsif Variable_Case then
if Comes_From_Source (Ent) and then SPARK_Elab_Errors then
Error_Msg_NE
("reference to & during elaboration in SPARK", N, Ent);
end if;
-- Subprogram call case
else
if Nkind (Name (N)) in N_Has_Entity
and then Is_Init_Proc (Entity (Name (N)))
and then Comes_From_Source (Ent)
then
Elab_Warning
("implicit call to & may raise Program_Error?l?",
"info: implicit call to & during elaboration?$?",
Ent);
elsif SPARK_Elab_Errors then
-- Emit a specialized error message when the elaboration of an
-- object of a private type evaluates the expression of pragma
-- Default_Initial_Condition. This prevents the internal name
-- of the procedure from appearing in the error message.
if Is_DIC then
Error_Msg_N
("call to Default_Initial_Condition during elaboration in "
& "SPARK", N);
else
Error_Msg_NE
("call to & during elaboration in SPARK", N, Ent);
end if;
else
Elab_Warning
("call to & may raise Program_Error?l?",
"info: call to & during elaboration?$?",
Ent);
end if;
end if;
Error_Msg_Qual_Level := Nat'Last;
-- Case of Elaborate_All not present and required, for SPARK this
-- is an error, so give an error message.
if SPARK_Elab_Errors then
Error_Msg_NE -- CODEFIX
("\Elaborate_All pragma required for&", N, W_Scope);
-- Otherwise we generate an implicit pragma. For a subprogram
-- instantiation, Elaborate is good enough, since no transitive
-- call is possible at elaboration time in this case.
elsif Nkind (N) in N_Subprogram_Instantiation then
Elab_Warning
("\missing pragma Elaborate for&?l?",
"\implicit pragma Elaborate for& generated?$?",
W_Scope);
-- For all other cases, we need an implicit Elaborate_All
else
Elab_Warning
("\missing pragma Elaborate_All for&?l?",
"\implicit pragma Elaborate_All for & generated?$?",
W_Scope);
end if;
Error_Msg_Qual_Level := 0;
-- Take into account the flags related to elaboration warning
-- messages when enumerating the various calls involved. This
-- ensures the proper pairing of the main warning and the
-- clarification messages generated by Output_Calls.
Output_Calls (N, Check_Elab_Flag => True);
-- Set flag to prevent further warnings for same unit unless in
-- All_Errors_Mode.
if not All_Errors_Mode and not Dynamic_Elaboration_Checks then
Set_Suppress_Elaboration_Warnings (W_Scope);
end if;
end if;
-- Check for runtime elaboration check required
if Dynamic_Elaboration_Checks then
if not Elaboration_Checks_Suppressed (Ent)
and then not Elaboration_Checks_Suppressed (W_Scope)
and then not Elaboration_Checks_Suppressed (E_Scope)
and then not Cunit_SC
then
-- Runtime elaboration check required. Generate check of the
-- elaboration Boolean for the unit containing the entity.
-- Note that for this case, we do check the real unit (the one
-- from following renamings, since that is the issue).
-- Could this possibly miss a useless but required PE???
Insert_Elab_Check (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Elaborated,
Prefix =>
New_Occurrence_Of (Spec_Entity (E_Scope), Loc)));
-- Prevent duplicate elaboration checks on the same call, which
-- can happen if the body enclosing the call appears itself in a
-- call whose elaboration check is delayed.
if Nkind (N) in N_Subprogram_Call then
Set_No_Elaboration_Check (N);
end if;
end if;
-- Case of static elaboration model
else
-- Do not do anything if elaboration checks suppressed. Note that
-- we check Ent here, not E, since we want the real entity for the
-- body to see if checks are suppressed for it, not the dummy
-- entry for renamings or derivations.
if Elaboration_Checks_Suppressed (Ent)
or else Elaboration_Checks_Suppressed (E_Scope)
or else Elaboration_Checks_Suppressed (W_Scope)
then
null;
-- Do not generate an Elaborate_All for finalization routines
-- that perform partial clean up as part of initialization.
elsif In_Init_Proc and then Is_Finalization_Procedure (Ent) then
null;
-- Here we need to generate an implicit elaborate all
else
-- Generate Elaborate_All warning unless suppressed
if (Elab_Info_Messages and Generate_Warnings and not Inst_Case)
and then not Suppress_Elaboration_Warnings (Ent)
and then not Suppress_Elaboration_Warnings (E_Scope)
and then not Suppress_Elaboration_Warnings (W_Scope)
then
Error_Msg_Node_2 := W_Scope;
Error_Msg_NE
("info: call to& in elaboration code requires pragma "
& "Elaborate_All on&?$?", N, E);
end if;
-- Set indication for binder to generate Elaborate_All
Set_Elaboration_Constraint (N, E, W_Scope);
end if;
end if;
end Check_A_Call;
-----------------------------
-- Check_Bad_Instantiation --
-----------------------------
procedure Check_Bad_Instantiation (N : Node_Id) is
Ent : Entity_Id;
begin
-- Nothing to do if we do not have an instantiation (happens in some
-- error cases, and also in the formal package declaration case)
if Nkind (N) not in N_Generic_Instantiation then
return;
-- Nothing to do if serious errors detected (avoid cascaded errors)
elsif Serious_Errors_Detected /= 0 then
return;
-- Nothing to do if not in full analysis mode
elsif not Full_Analysis then
return;
-- Nothing to do if inside a generic template
elsif Inside_A_Generic then
return;
-- Nothing to do if a library level instantiation
elsif Nkind (Parent (N)) = N_Compilation_Unit then
return;
-- Nothing to do if we are compiling a proper body for semantic
-- purposes only. The generic body may be in another proper body.
elsif
Nkind (Parent (Unit_Declaration_Node (Main_Unit_Entity))) = N_Subunit
then
return;
end if;
Ent := Get_Generic_Entity (N);
-- The case we are interested in is when the generic spec is in the
-- current declarative part
if not Same_Elaboration_Scope (Current_Scope, Scope (Ent))
or else not In_Same_Extended_Unit (N, Ent)
then
return;
end if;
-- If the generic entity is within a deeper instance than we are, then
-- either the instantiation to which we refer itself caused an ABE, in
-- which case that will be handled separately. Otherwise, we know that
-- the body we need appears as needed at the point of the instantiation.
-- If they are both at the same level but not within the same instance
-- then the body of the generic will be in the earlier instance.
declare
D1 : constant Nat := Instantiation_Depth (Sloc (Ent));
D2 : constant Nat := Instantiation_Depth (Sloc (N));
begin
if D1 > D2 then
return;
elsif D1 = D2
and then Is_Generic_Instance (Scope (Ent))
and then not In_Open_Scopes (Scope (Ent))
then
return;
end if;
end;
-- Now we can proceed, if the entity being called has a completion,
-- then we are definitely OK, since we have already seen the body.
if Has_Completion (Ent) then
return;
end if;
-- If there is no body, then nothing to do
if not Has_Generic_Body (N) then
return;
end if;
-- Here we definitely have a bad instantiation
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_NE ("cannot instantiate& before body seen<<", N, Ent);
Error_Msg_N ("\Program_Error [<<", N);
Insert_Elab_Check (N);
Set_Is_Known_Guaranteed_ABE (N);
end Check_Bad_Instantiation;
---------------------
-- Check_Elab_Call --
---------------------
procedure Check_Elab_Call
(N : Node_Id;
Outer_Scope : Entity_Id := Empty;
In_Init_Proc : Boolean := False)
is
Ent : Entity_Id;
P : Node_Id;
begin
pragma Assert (Legacy_Elaboration_Checks);
-- If the reference is not in the main unit, there is nothing to check.
-- Elaboration call from units in the context of the main unit will lead
-- to semantic dependencies when those units are compiled.
if not In_Extended_Main_Code_Unit (N) then
return;
end if;
-- For an entry call, check relevant restriction
if Nkind (N) = N_Entry_Call_Statement
and then not In_Subprogram_Or_Concurrent_Unit
then
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, N);
-- Nothing to do if this is not an expected type of reference (happens
-- in some error conditions, and in some cases where rewriting occurs).
elsif Nkind (N) not in N_Subprogram_Call
and then Nkind (N) /= N_Attribute_Reference
and then (SPARK_Mode /= On
or else Nkind (N) not in N_Has_Entity
or else No (Entity (N))
or else Ekind (Entity (N)) /= E_Variable)
then
return;
-- Nothing to do if this is a call already rewritten for elab checking.
-- Such calls appear as the targets of If_Expressions.
-- This check MUST be wrong, it catches far too much
elsif Nkind (Parent (N)) = N_If_Expression then
return;
-- Nothing to do if inside a generic template
elsif Inside_A_Generic
and then No (Enclosing_Generic_Body (N))
then
return;
-- Nothing to do if call is being preanalyzed, as when within a
-- pre/postcondition, a predicate, or an invariant.
elsif In_Spec_Expression then
return;
end if;
-- Nothing to do if this is a call to a postcondition, which is always
-- within a subprogram body, even though the current scope may be the
-- enclosing scope of the subprogram.
if Nkind (N) = N_Procedure_Call_Statement
and then Is_Entity_Name (Name (N))
and then Chars (Entity (Name (N))) = Name_uPostconditions
then
return;
end if;
-- Here we have a reference at elaboration time that must be checked
if Debug_Flag_Underscore_LL then
Write_Str (" Check_Elab_Ref: ");
if Nkind (N) = N_Attribute_Reference then
if not Is_Entity_Name (Prefix (N)) then
Write_Str ("<<not entity name>>");
else
Write_Name (Chars (Entity (Prefix (N))));
end if;
Write_Str ("'Access");
elsif No (Name (N)) or else not Is_Entity_Name (Name (N)) then
Write_Str ("<<not entity name>> ");
else
Write_Name (Chars (Entity (Name (N))));
end if;
Write_Str (" reference at ");
Write_Location (Sloc (N));
Write_Eol;
end if;
-- Climb up the tree to make sure we are not inside default expression
-- of a parameter specification or a record component, since in both
-- these cases, we will be doing the actual reference later, not now,
-- and it is at the time of the actual reference (statically speaking)
-- that we must do our static check, not at the time of its initial
-- analysis).
-- However, we have to check references within component definitions
-- (e.g. a function call that determines an array component bound),
-- so we terminate the loop in that case.
P := Parent (N);
while Present (P) loop
if Nkind (P) in N_Parameter_Specification | N_Component_Declaration
then
return;
-- The reference occurs within the constraint of a component,
-- so it must be checked.
elsif Nkind (P) = N_Component_Definition then
exit;
else
P := Parent (P);
end if;
end loop;
-- Stuff that happens only at the outer level
if No (Outer_Scope) then
Elab_Visited.Set_Last (0);
-- Nothing to do if current scope is Standard (this is a bit odd, but
-- it happens in the case of generic instantiations).
C_Scope := Current_Scope;
if C_Scope = Standard_Standard then
return;
end if;
-- First case, we are in elaboration code
From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
if From_Elab_Code then
-- Complain if ref that comes from source in preelaborated unit
-- and we are not inside a subprogram (i.e. we are in elab code).
-- Ada 2020 (AI12-0175): Calls to certain functions that are
-- essentially unchecked conversions are preelaborable.
if Comes_From_Source (N)
and then In_Preelaborated_Unit
and then not In_Inlined_Body
and then Nkind (N) /= N_Attribute_Reference
and then not (Ada_Version >= Ada_2020
and then Is_Preelaborable_Construct (N))
then
Error_Preelaborated_Call (N);
return;
end if;
-- Second case, we are inside a subprogram or concurrent unit, which
-- means we are not in elaboration code.
else
-- In this case, the issue is whether we are inside the
-- declarative part of the unit in which we live, or inside its
-- statements. In the latter case, there is no issue of ABE calls
-- at this level (a call from outside to the unit in which we live
-- might cause an ABE, but that will be detected when we analyze
-- that outer level call, as it recurses into the called unit).
-- Climb up the tree, doing this test, and also testing for being
-- inside a default expression, which, as discussed above, is not
-- checked at this stage.
declare
P : Node_Id;
L : List_Id;
begin
P := N;
loop
-- If we find a parentless subtree, it seems safe to assume
-- that we are not in a declarative part and that no
-- checking is required.
if No (P) then
return;
end if;
if Is_List_Member (P) then
L := List_Containing (P);
P := Parent (L);
else
L := No_List;
P := Parent (P);
end if;
exit when Nkind (P) = N_Subunit;
-- Filter out case of default expressions, where we do not
-- do the check at this stage.
if Nkind (P) in
N_Parameter_Specification | N_Component_Declaration
then
return;
end if;
-- A protected body has no elaboration code and contains
-- only other bodies.
if Nkind (P) = N_Protected_Body then
return;
elsif Nkind (P) in N_Subprogram_Body
| N_Task_Body
| N_Block_Statement
| N_Entry_Body
then
if L = Declarations (P) then
exit;
-- We are not in elaboration code, but we are doing
-- dynamic elaboration checks, in this case, we still
-- need to do the reference, since the subprogram we are
-- in could be called from another unit, also in dynamic
-- elaboration check mode, at elaboration time.
elsif Dynamic_Elaboration_Checks then
-- We provide a debug flag to disable this check. That
-- way we have an easy work around for regressions
-- that are caused by this new check. This debug flag
-- can be removed later.
if Debug_Flag_DD then
return;
end if;
-- Do the check in this case
exit;
elsif Nkind (P) = N_Task_Body then
-- The check is deferred until Check_Task_Activation
-- but we need to capture local suppress pragmas
-- that may inhibit checks on this call.
Ent := Get_Referenced_Ent (N);
if No (Ent) then
return;
elsif Elaboration_Checks_Suppressed (Current_Scope)
or else Elaboration_Checks_Suppressed (Ent)
or else Elaboration_Checks_Suppressed (Scope (Ent))
then
if Nkind (N) in N_Subprogram_Call then
Set_No_Elaboration_Check (N);
end if;
end if;
return;
-- Static model, call is not in elaboration code, we
-- never need to worry, because in the static model the
-- top-level caller always takes care of things.
else
return;
end if;
end if;
end loop;
end;
end if;
end if;
Ent := Get_Referenced_Ent (N);
if No (Ent) then
return;
end if;
-- Determine whether a prior call to the same subprogram was already
-- examined within the same context. If this is the case, then there is
-- no need to proceed with the various warnings and checks because the
-- work was already done for the previous call.
declare
Self : constant Visited_Element :=
(Subp_Id => Ent, Context => Parent (N));
begin
for Index in 1 .. Elab_Visited.Last loop
if Self = Elab_Visited.Table (Index) then
return;
end if;
end loop;
end;
-- See if we need to analyze this reference. We analyze it if either of
-- the following conditions is met:
-- It is an inner level call (since in this case it was triggered
-- by an outer level call from elaboration code), but only if the
-- call is within the scope of the original outer level call.
-- It is an outer level reference from elaboration code, or a call to
-- an entity is in the same elaboration scope.
-- And in these cases, we will check both inter-unit calls and
-- intra-unit (within a single unit) calls.
C_Scope := Current_Scope;
-- If not outer level reference, then we follow it if it is within the
-- original scope of the outer reference.
if Present (Outer_Scope)
and then Within (Scope (Ent), Outer_Scope)
then
Set_C_Scope;
Check_A_Call
(N => N,
E => Ent,
Outer_Scope => Outer_Scope,
Inter_Unit_Only => False,
In_Init_Proc => In_Init_Proc);
-- Nothing to do if elaboration checks suppressed for this scope.
-- However, an interesting exception, the fact that elaboration checks
-- are suppressed within an instance (because we can trace the body when
-- we process the template) does not extend to calls to generic formal
-- subprograms.
elsif Elaboration_Checks_Suppressed (Current_Scope)
and then not Is_Call_Of_Generic_Formal (N)
then
null;
elsif From_Elab_Code then
Set_C_Scope;
Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
Set_C_Scope;
Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
-- If none of those cases holds, but Dynamic_Elaboration_Checks mode
-- is set, then we will do the check, but only in the inter-unit case
-- (this is to accommodate unguarded elaboration calls from other units
-- in which this same mode is set). We don't want warnings in this case,
-- it would generate warnings having nothing to do with elaboration.
elsif Dynamic_Elaboration_Checks then
Set_C_Scope;
Check_A_Call
(N,
Ent,
Standard_Standard,
Inter_Unit_Only => True,
Generate_Warnings => False);
-- Otherwise nothing to do
else
return;
end if;
-- A call to an Init_Proc in elaboration code may bring additional
-- dependencies, if some of the record components thereof have
-- initializations that are function calls that come from source. We
-- treat the current node as a call to each of these functions, to check
-- their elaboration impact.
if Is_Init_Proc (Ent) and then From_Elab_Code then
Process_Init_Proc : declare
Unit_Decl : constant Node_Id := Unit_Declaration_Node (Ent);
function Check_Init_Call (Nod : Node_Id) return Traverse_Result;
-- Find subprogram calls within body of Init_Proc for Traverse
-- instantiation below.
procedure Traverse_Body is new Traverse_Proc (Check_Init_Call);
-- Traversal procedure to find all calls with body of Init_Proc
---------------------
-- Check_Init_Call --
---------------------
function Check_Init_Call (Nod : Node_Id) return Traverse_Result is
Func : Entity_Id;
begin
if Nkind (Nod) in N_Subprogram_Call
and then Is_Entity_Name (Name (Nod))
then
Func := Entity (Name (Nod));
if Comes_From_Source (Func) then
Check_A_Call
(N, Func, Standard_Standard, Inter_Unit_Only => True);
end if;
return OK;
else
return OK;
end if;
end Check_Init_Call;
-- Start of processing for Process_Init_Proc
begin
if Nkind (Unit_Decl) = N_Subprogram_Body then
Traverse_Body (Handled_Statement_Sequence (Unit_Decl));
end if;
end Process_Init_Proc;
end if;
end Check_Elab_Call;
-----------------------
-- Check_Elab_Assign --
-----------------------
procedure Check_Elab_Assign (N : Node_Id) is
Ent : Entity_Id;
Scop : Entity_Id;
Pkg_Spec : Entity_Id;
Pkg_Body : Entity_Id;
begin
pragma Assert (Legacy_Elaboration_Checks);
-- For record or array component, check prefix. If it is an access type,
-- then there is nothing to do (we do not know what is being assigned),
-- but otherwise this is an assignment to the prefix.
if Nkind (N) in N_Indexed_Component | N_Selected_Component | N_Slice then
if not Is_Access_Type (Etype (Prefix (N))) then
Check_Elab_Assign (Prefix (N));
end if;
return;
end if;
-- For type conversion, check expression
if Nkind (N) = N_Type_Conversion then
Check_Elab_Assign (Expression (N));
return;
end if;
-- Nothing to do if this is not an entity reference otherwise get entity
if Is_Entity_Name (N) then
Ent := Entity (N);
else
return;
end if;
-- What we are looking for is a reference in the body of a package that
-- modifies a variable declared in the visible part of the package spec.
if Present (Ent)
and then Comes_From_Source (N)
and then not Suppress_Elaboration_Warnings (Ent)
and then Ekind (Ent) = E_Variable
and then not In_Private_Part (Ent)
and then Is_Library_Level_Entity (Ent)
then
Scop := Current_Scope;
loop
if No (Scop) or else Scop = Standard_Standard then
return;
elsif Ekind (Scop) = E_Package
and then Is_Compilation_Unit (Scop)
then
exit;
else
Scop := Scope (Scop);
end if;
end loop;
-- Here Scop points to the containing library package
Pkg_Spec := Scop;
Pkg_Body := Body_Entity (Pkg_Spec);
-- All OK if the package has an Elaborate_Body pragma
if Has_Pragma_Elaborate_Body (Scop) then
return;
end if;
-- OK if entity being modified is not in containing package spec
if not In_Same_Source_Unit (Scop, Ent) then
return;
end if;
-- All OK if entity appears in generic package or generic instance.
-- We just get too messed up trying to give proper warnings in the
-- presence of generics. Better no message than a junk one.
Scop := Scope (Ent);
while Present (Scop) and then Scop /= Pkg_Spec loop
if Ekind (Scop) = E_Generic_Package then
return;
elsif Ekind (Scop) = E_Package
and then Is_Generic_Instance (Scop)
then
return;
end if;
Scop := Scope (Scop);
end loop;
-- All OK if in task, don't issue warnings there
if In_Task_Activation then
return;
end if;
-- OK if no package body
if No (Pkg_Body) then
return;
end if;
-- OK if reference is not in package body
if not In_Same_Source_Unit (Pkg_Body, N) then
return;
end if;
-- OK if package body has no handled statement sequence
declare
HSS : constant Node_Id :=
Handled_Statement_Sequence (Declaration_Node (Pkg_Body));
begin
if No (HSS) or else not Comes_From_Source (HSS) then
return;
end if;
end;
-- We definitely have a case of a modification of an entity in
-- the package spec from the elaboration code of the package body.
-- We may not give the warning (because there are some additional
-- checks to avoid too many false positives), but it would be a good
-- idea for the binder to try to keep the body elaboration close to
-- the spec elaboration.
Set_Elaborate_Body_Desirable (Pkg_Spec);
-- All OK in gnat mode (we know what we are doing)
if GNAT_Mode then
return;
end if;
-- All OK if all warnings suppressed
if Warning_Mode = Suppress then
return;
end if;
-- All OK if elaboration checks suppressed for entity
if Checks_May_Be_Suppressed (Ent)
and then Is_Check_Suppressed (Ent, Elaboration_Check)
then
return;
end if;
-- OK if the entity is initialized. Note that the No_Initialization
-- flag usually means that the initialization has been rewritten into
-- assignments, but that still counts for us.
declare
Decl : constant Node_Id := Declaration_Node (Ent);
begin
if Nkind (Decl) = N_Object_Declaration
and then (Present (Expression (Decl))
or else No_Initialization (Decl))
then
return;
end if;
end;
-- Here is where we give the warning
-- All OK if warnings suppressed on the entity
if not Has_Warnings_Off (Ent) then
Error_Msg_Sloc := Sloc (Ent);
Error_Msg_NE
("??& can be accessed by clients before this initialization",
N, Ent);
Error_Msg_NE
("\??add Elaborate_Body to spec to ensure & is initialized",
N, Ent);
end if;
if not All_Errors_Mode then
Set_Suppress_Elaboration_Warnings (Ent);
end if;
end if;
end Check_Elab_Assign;
----------------------
-- Check_Elab_Calls --
----------------------
-- WARNING: This routine manages SPARK regions
procedure Check_Elab_Calls is
Saved_SM : SPARK_Mode_Type;
Saved_SMP : Node_Id;
begin
pragma Assert (Legacy_Elaboration_Checks);
-- If expansion is disabled, do not generate any checks, unless we
-- are in GNATprove mode, so that errors are issued in GNATprove for
-- violations of static elaboration rules in SPARK code. Also skip
-- checks if any subunits are missing because in either case we lack the
-- full information that we need, and no object file will be created in
-- any case.
if (not Expander_Active and not GNATprove_Mode)
or else Is_Generic_Unit (Cunit_Entity (Main_Unit))
or else Subunits_Missing
then
return;
end if;
-- Skip delayed calls if we had any errors
if Serious_Errors_Detected = 0 then
Delaying_Elab_Checks := False;
Expander_Mode_Save_And_Set (True);
for J in Delay_Check.First .. Delay_Check.Last loop
Push_Scope (Delay_Check.Table (J).Curscop);
From_Elab_Code := Delay_Check.Table (J).From_Elab_Code;
In_Task_Activation := Delay_Check.Table (J).In_Task_Activation;
Saved_SM := SPARK_Mode;
Saved_SMP := SPARK_Mode_Pragma;
-- Set appropriate value of SPARK_Mode
if Delay_Check.Table (J).From_SPARK_Code then
SPARK_Mode := On;
end if;
Check_Internal_Call_Continue
(N => Delay_Check.Table (J).N,
E => Delay_Check.Table (J).E,
Outer_Scope => Delay_Check.Table (J).Outer_Scope,
Orig_Ent => Delay_Check.Table (J).Orig_Ent);
Restore_SPARK_Mode (Saved_SM, Saved_SMP);
Pop_Scope;
end loop;
-- Set Delaying_Elab_Checks back on for next main compilation
Expander_Mode_Restore;
Delaying_Elab_Checks := True;
end if;
end Check_Elab_Calls;
------------------------------
-- Check_Elab_Instantiation --
------------------------------
procedure Check_Elab_Instantiation
(N : Node_Id;
Outer_Scope : Entity_Id := Empty)
is
Ent : Entity_Id;
begin
pragma Assert (Legacy_Elaboration_Checks);
-- Check for and deal with bad instantiation case. There is some
-- duplicated code here, but we will worry about this later ???
Check_Bad_Instantiation (N);
if Is_Known_Guaranteed_ABE (N) then
return;
end if;
-- Nothing to do if we do not have an instantiation (happens in some
-- error cases, and also in the formal package declaration case)
if Nkind (N) not in N_Generic_Instantiation then
return;
end if;
-- Nothing to do if inside a generic template
if Inside_A_Generic then
return;
end if;
-- Nothing to do if the instantiation is not in the main unit
if not In_Extended_Main_Code_Unit (N) then
return;
end if;
Ent := Get_Generic_Entity (N);
From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
-- See if we need to analyze this instantiation. We analyze it if
-- either of the following conditions is met:
-- It is an inner level instantiation (since in this case it was
-- triggered by an outer level call from elaboration code), but
-- only if the instantiation is within the scope of the original
-- outer level call.
-- It is an outer level instantiation from elaboration code, or the
-- instantiated entity is in the same elaboration scope.
-- And in these cases, we will check both the inter-unit case and
-- the intra-unit (within a single unit) case.
C_Scope := Current_Scope;
if Present (Outer_Scope) and then Within (Scope (Ent), Outer_Scope) then
Set_C_Scope;
Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
elsif From_Elab_Code then
Set_C_Scope;
Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
Set_C_Scope;
Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
-- If none of those cases holds, but Dynamic_Elaboration_Checks mode is
-- set, then we will do the check, but only in the inter-unit case (this
-- is to accommodate unguarded elaboration calls from other units in
-- which this same mode is set). We inhibit warnings in this case, since
-- this instantiation is not occurring in elaboration code.
elsif Dynamic_Elaboration_Checks then
Set_C_Scope;
Check_A_Call
(N,
Ent,
Standard_Standard,
Inter_Unit_Only => True,
Generate_Warnings => False);
else
return;
end if;
end Check_Elab_Instantiation;
-------------------------
-- Check_Internal_Call --
-------------------------
procedure Check_Internal_Call
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id)
is
function Within_Initial_Condition (Call : Node_Id) return Boolean;
-- Determine whether call Call occurs within pragma Initial_Condition or
-- pragma Check with check_kind set to Initial_Condition.
------------------------------
-- Within_Initial_Condition --
------------------------------
function Within_Initial_Condition (Call : Node_Id) return Boolean is
Args : List_Id;
Nam : Name_Id;
Par : Node_Id;
begin
-- Traverse the parent chain looking for an enclosing pragma
Par := Call;
while Present (Par) loop
if Nkind (Par) = N_Pragma then
Nam := Pragma_Name (Par);
-- Pragma Initial_Condition appears in its alternative from as
-- Check (Initial_Condition, ...).
if Nam = Name_Check then
Args := Pragma_Argument_Associations (Par);
-- Pragma Check should have at least two arguments
pragma Assert (Present (Args));
return
Chars (Expression (First (Args))) = Name_Initial_Condition;
-- Direct match
elsif Nam = Name_Initial_Condition then
return True;
-- Since pragmas are never nested within other pragmas, stop
-- the traversal.
else
return False;
end if;
-- Prevent the search from going too far
elsif Is_Body_Or_Package_Declaration (Par) then
exit;
end if;
Par := Parent (Par);
-- If assertions are not enabled, the check pragma is rewritten
-- as an if_statement in sem_prag, to generate various warnings
-- on boolean expressions. Retrieve the original pragma.
if Nkind (Original_Node (Par)) = N_Pragma then
Par := Original_Node (Par);
end if;
end loop;
return False;
end Within_Initial_Condition;
-- Local variables
Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
-- Start of processing for Check_Internal_Call
begin
-- For P'Access, we want to warn if the -gnatw.f switch is set, and the
-- node comes from source.
if Nkind (N) = N_Attribute_Reference
and then ((not Warn_On_Elab_Access and then not Debug_Flag_Dot_O)
or else not Comes_From_Source (N))
then
return;
-- If not function or procedure call, instantiation, or 'Access, then
-- ignore call (this happens in some error cases and rewriting cases).
elsif Nkind (N) not in N_Attribute_Reference
| N_Function_Call
| N_Procedure_Call_Statement
and then not Inst_Case
then
return;
-- Nothing to do if this is a call or instantiation that has already
-- been found to be a sure ABE.
elsif Nkind (N) /= N_Attribute_Reference
and then Is_Known_Guaranteed_ABE (N)
then
return;
-- Nothing to do if errors already detected (avoid cascaded errors)
elsif Serious_Errors_Detected /= 0 then
return;
-- Nothing to do if not in full analysis mode
elsif not Full_Analysis then
return;
-- Nothing to do if analyzing in special spec-expression mode, since the
-- call is not actually being made at this time.
elsif In_Spec_Expression then
return;
-- Nothing to do for call to intrinsic subprogram
elsif Is_Intrinsic_Subprogram (E) then
return;
-- Nothing to do if call is within a generic unit
elsif Inside_A_Generic then
return;
-- Nothing to do when the call appears within pragma Initial_Condition.
-- The pragma is part of the elaboration statements of a package body
-- and may only call external subprograms or subprograms whose body is
-- already available.
elsif Within_Initial_Condition (N) then
return;
end if;
-- Delay this call if we are still delaying calls
if Delaying_Elab_Checks then
Delay_Check.Append
((N => N,
E => E,
Orig_Ent => Orig_Ent,
Curscop => Current_Scope,
Outer_Scope => Outer_Scope,
From_Elab_Code => From_Elab_Code,
In_Task_Activation => In_Task_Activation,
From_SPARK_Code => SPARK_Mode = On));
return;
-- Otherwise, call phase 2 continuation right now
else
Check_Internal_Call_Continue (N, E, Outer_Scope, Orig_Ent);
end if;
end Check_Internal_Call;
----------------------------------
-- Check_Internal_Call_Continue --
----------------------------------
procedure Check_Internal_Call_Continue
(N : Node_Id;
E : Entity_Id;
Outer_Scope : Entity_Id;
Orig_Ent : Entity_Id)
is
function Find_Elab_Reference (N : Node_Id) return Traverse_Result;
-- Function applied to each node as we traverse the body. Checks for
-- call or entity reference that needs checking, and if so checks it.
-- Always returns OK, so entire tree is traversed, except that as
-- described below subprogram bodies are skipped for now.
procedure Traverse is new Atree.Traverse_Proc (Find_Elab_Reference);
-- Traverse procedure using above Find_Elab_Reference function
-------------------------
-- Find_Elab_Reference --
-------------------------
function Find_Elab_Reference (N : Node_Id) return Traverse_Result is
Actual : Node_Id;
begin
-- If user has specified that there are no entry calls in elaboration
-- code, do not trace past an accept statement, because the rendez-
-- vous will happen after elaboration.
if Nkind (Original_Node (N)) in
N_Accept_Statement | N_Selective_Accept
and then Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
then
return Abandon;
-- If we have a function call, check it
elsif Nkind (N) = N_Function_Call then
Check_Elab_Call (N, Outer_Scope);
return OK;
-- If we have a procedure call, check the call, and also check
-- arguments that are assignments (OUT or IN OUT mode formals).
elsif Nkind (N) = N_Procedure_Call_Statement then
Check_Elab_Call (N, Outer_Scope, In_Init_Proc => Is_Init_Proc (E));
Actual := First_Actual (N);
while Present (Actual) loop
if Known_To_Be_Assigned (Actual) then
Check_Elab_Assign (Actual);
end if;
Next_Actual (Actual);
end loop;
return OK;
-- If we have an access attribute for a subprogram, check it.
-- Suppress this behavior under debug flag.
elsif not Debug_Flag_Dot_UU
and then Nkind (N) = N_Attribute_Reference
and then
Attribute_Name (N) in Name_Access | Name_Unrestricted_Access
and then Is_Entity_Name (Prefix (N))
and then Is_Subprogram (Entity (Prefix (N)))
then
Check_Elab_Call (N, Outer_Scope);
return OK;
-- In SPARK mode, if we have an entity reference to a variable, then
-- check it. For now we consider any reference.
elsif SPARK_Mode = On
and then Nkind (N) in N_Has_Entity
and then Present (Entity (N))
and then Ekind (Entity (N)) = E_Variable
then
Check_Elab_Call (N, Outer_Scope);
return OK;
-- If we have a generic instantiation, check it
elsif Nkind (N) in N_Generic_Instantiation then
Check_Elab_Instantiation (N, Outer_Scope);
return OK;
-- Skip subprogram bodies that come from source (wait for call to
-- analyze these). The reason for the come from source test is to
-- avoid catching task bodies.
-- For task bodies, we should really avoid these too, waiting for the
-- task activation, but that's too much trouble to catch for now, so
-- we go in unconditionally. This is not so terrible, it means the
-- error backtrace is not quite complete, and we are too eager to
-- scan bodies of tasks that are unused, but this is hardly very
-- significant.
elsif Nkind (N) = N_Subprogram_Body
and then Comes_From_Source (N)
then
return Skip;
elsif Nkind (N) = N_Assignment_Statement
and then Comes_From_Source (N)
then
Check_Elab_Assign (Name (N));
return OK;
else
return OK;
end if;
end Find_Elab_Reference;
Inst_Case : constant Boolean := Is_Generic_Unit (E);
Loc : constant Source_Ptr := Sloc (N);
Ebody : Entity_Id;
Sbody : Node_Id;
-- Start of processing for Check_Internal_Call_Continue
begin
-- Save outer level call if at outer level
if Elab_Call.Last = 0 then
Outer_Level_Sloc := Loc;
end if;
-- If the call is to a function that renames a literal, no check needed
if Ekind (E) = E_Enumeration_Literal then
return;
end if;
-- Register the subprogram as examined within this particular context.
-- This ensures that calls to the same subprogram but in different
-- contexts receive warnings and checks of their own since the calls
-- may be reached through different flow paths.
Elab_Visited.Append ((Subp_Id => E, Context => Parent (N)));
Sbody := Unit_Declaration_Node (E);
if Nkind (Sbody) not in N_Subprogram_Body | N_Package_Body then
Ebody := Corresponding_Body (Sbody);
if No (Ebody) then
return;
else
Sbody := Unit_Declaration_Node (Ebody);
end if;
end if;
-- If the body appears after the outer level call or instantiation then
-- we have an error case handled below.
if Earlier_In_Extended_Unit (Outer_Level_Sloc, Sloc (Sbody))
and then not In_Task_Activation
then
null;
-- If we have the instantiation case we are done, since we now know that
-- the body of the generic appeared earlier.
elsif Inst_Case then
return;
-- Otherwise we have a call, so we trace through the called body to see
-- if it has any problems.
else
pragma Assert (Nkind (Sbody) = N_Subprogram_Body);
Elab_Call.Append ((Cloc => Loc, Ent => E));
if Debug_Flag_Underscore_LL then
Write_Str ("Elab_Call.Last = ");
Write_Int (Int (Elab_Call.Last));
Write_Str (" Ent = ");
Write_Name (Chars (E));
Write_Str (" at ");
Write_Location (Sloc (N));
Write_Eol;
end if;
-- Now traverse declarations and statements of subprogram body. Note
-- that we cannot simply Traverse (Sbody), since traverse does not
-- normally visit subprogram bodies.
declare
Decl : Node_Id;
begin
Decl := First (Declarations (Sbody));
while Present (Decl) loop
Traverse (Decl);
Next (Decl);
end loop;
end;
Traverse (Handled_Statement_Sequence (Sbody));
Elab_Call.Decrement_Last;
return;
end if;
-- Here is the case of calling a subprogram where the body has not yet
-- been encountered. A warning message is needed, except if this is the
-- case of appearing within an aspect specification that results in
-- a check call, we do not really have such a situation, so no warning
-- is needed (e.g. the case of a precondition, where the call appears
-- textually before the body, but in actual fact is moved to the
-- appropriate subprogram body and so does not need a check).
declare
P : Node_Id;
O : Node_Id;
begin
P := Parent (N);
loop
-- Keep looking at parents if we are still in the subexpression
if Nkind (P) in N_Subexpr then
P := Parent (P);
-- Here P is the parent of the expression, check for special case
else
O := Original_Node (P);
-- Definitely not the special case if orig node is not a pragma
exit when Nkind (O) /= N_Pragma;
-- Check we have an If statement or a null statement (happens
-- when the If has been expanded to be True).
exit when Nkind (P) not in N_If_Statement | N_Null_Statement;
-- Our special case will be indicated either by the pragma
-- coming from an aspect ...
if Present (Corresponding_Aspect (O)) then
return;
-- Or, in the case of an initial condition, specifically by a
-- Check pragma specifying an Initial_Condition check.
elsif Pragma_Name (O) = Name_Check
and then
Chars
(Expression (First (Pragma_Argument_Associations (O)))) =
Name_Initial_Condition
then
return;
-- For anything else, we have an error
else
exit;
end if;
end if;
end loop;
end;
-- Not that special case, warning and dynamic check is required
-- If we have nothing in the call stack, then this is at the outer
-- level, and the ABE is bound to occur, unless it's a 'Access, or
-- it's a renaming.
if Elab_Call.Last = 0 then
Error_Msg_Warn := SPARK_Mode /= On;
declare
Insert_Check : Boolean := True;
-- This flag is set to True if an elaboration check should be
-- inserted.
begin
if In_Task_Activation then
Insert_Check := False;
elsif Inst_Case then
Error_Msg_NE
("cannot instantiate& before body seen<<", N, Orig_Ent);
elsif Nkind (N) = N_Attribute_Reference then
Error_Msg_NE
("Access attribute of & before body seen<<", N, Orig_Ent);
Error_Msg_N
("\possible Program_Error on later references<<", N);
Insert_Check := False;
elsif Nkind (Unit_Declaration_Node (Orig_Ent)) /=
N_Subprogram_Renaming_Declaration
or else Is_Generic_Actual_Subprogram (Orig_Ent)
then
Error_Msg_NE
("cannot call& before body seen<<", N, Orig_Ent);
else
Insert_Check := False;
end if;
if Insert_Check then
Error_Msg_N ("\Program_Error [<<", N);
Insert_Elab_Check (N);
end if;
end;
-- Call is not at outer level
else
-- Do not generate elaboration checks in GNATprove mode because the
-- elaboration counter and the check are both forms of expansion.
if GNATprove_Mode then
null;
-- Generate an elaboration check
elsif not Elaboration_Checks_Suppressed (E) then
Set_Elaboration_Entity_Required (E);
-- Create a declaration of the elaboration entity, and insert it
-- prior to the subprogram or the generic unit, within the same
-- scope. Since the subprogram may be overloaded, create a unique
-- entity.
if No (Elaboration_Entity (E)) then
declare
Loce : constant Source_Ptr := Sloc (E);
Ent : constant Entity_Id :=
Make_Defining_Identifier (Loc,
New_External_Name (Chars (E), 'E', -1));
begin
Set_Elaboration_Entity (E, Ent);
Push_Scope (Scope (E));
Insert_Action (Declaration_Node (E),
Make_Object_Declaration (Loce,
Defining_Identifier => Ent,
Object_Definition =>
New_Occurrence_Of (Standard_Short_Integer, Loce),
Expression =>
Make_Integer_Literal (Loc, Uint_0)));
-- Set elaboration flag at the point of the body
Set_Elaboration_Flag (Sbody, E);
-- Kill current value indication. This is necessary because
-- the tests of this flag are inserted out of sequence and
-- must not pick up bogus indications of the wrong constant
-- value. Also, this is never a true constant, since one way
-- or another, it gets reset.
Set_Current_Value (Ent, Empty);
Set_Last_Assignment (Ent, Empty);
Set_Is_True_Constant (Ent, False);
Pop_Scope;
end;
end if;
-- Generate:
-- if Enn = 0 then
-- raise Program_Error with "access before elaboration";
-- end if;
Insert_Elab_Check (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Elaborated,
Prefix => New_Occurrence_Of (E, Loc)));
end if;
-- Generate the warning
if not Suppress_Elaboration_Warnings (E)
and then not Elaboration_Checks_Suppressed (E)
-- Suppress this warning if we have a function call that occurred
-- within an assertion expression, since we can get false warnings
-- in this case, due to the out of order handling in this case.
and then
(Nkind (Original_Node (N)) /= N_Function_Call
or else not In_Assertion_Expression_Pragma (Original_Node (N)))
then
Error_Msg_Warn := SPARK_Mode /= On;
if Inst_Case then
Error_Msg_NE
("instantiation of& may occur before body is seen<l<",
N, Orig_Ent);
else
-- A rather specific check. For Finalize/Adjust/Initialize, if
-- the type has Warnings_Off set, suppress the warning.
if Chars (E) in Name_Adjust
| Name_Finalize
| Name_Initialize
and then Present (First_Formal (E))
then
declare
T : constant Entity_Id := Etype (First_Formal (E));
begin
if Is_Controlled (T) then
if Warnings_Off (T)
or else (Ekind (T) = E_Private_Type
and then Warnings_Off (Full_View (T)))
then
goto Output;
end if;
end if;
end;
end if;
-- Go ahead and give warning if not this special case
Error_Msg_NE
("call to& may occur before body is seen<l<", N, Orig_Ent);
end if;
Error_Msg_N ("\Program_Error ]<l<", N);
-- There is no need to query the elaboration warning message flags
-- because the main message is an error, not a warning, therefore
-- all the clarification messages produces by Output_Calls must be
-- emitted unconditionally.
<<Output>>
Output_Calls (N, Check_Elab_Flag => False);
end if;
end if;
end Check_Internal_Call_Continue;
---------------------------
-- Check_Task_Activation --
---------------------------
procedure Check_Task_Activation (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Inter_Procs : constant Elist_Id := New_Elmt_List;
Intra_Procs : constant Elist_Id := New_Elmt_List;
Ent : Entity_Id;
P : Entity_Id;
Task_Scope : Entity_Id;
Cunit_SC : Boolean := False;
Decl : Node_Id;
Elmt : Elmt_Id;
Enclosing : Entity_Id;
procedure Add_Task_Proc (Typ : Entity_Id);
-- Add to Task_Procs the task body procedure(s) of task types in Typ.
-- For record types, this procedure recurses over component types.
procedure Collect_Tasks (Decls : List_Id);
-- Collect the types of the tasks that are to be activated in the given
-- list of declarations, in order to perform elaboration checks on the
-- corresponding task procedures that are called implicitly here.
function Outer_Unit (E : Entity_Id) return Entity_Id;
-- find enclosing compilation unit of Entity, ignoring subunits, or
-- else enclosing subprogram. If E is not a package, there is no need
-- for inter-unit elaboration checks.
-------------------
-- Add_Task_Proc --
-------------------
procedure Add_Task_Proc (Typ : Entity_Id) is
Comp : Entity_Id;
Proc : Entity_Id := Empty;
begin
if Is_Task_Type (Typ) then
Proc := Get_Task_Body_Procedure (Typ);
elsif Is_Array_Type (Typ)
and then Has_Task (Base_Type (Typ))
then
Add_Task_Proc (Component_Type (Typ));
elsif Is_Record_Type (Typ)
and then Has_Task (Base_Type (Typ))
then
Comp := First_Component (Typ);
while Present (Comp) loop
Add_Task_Proc (Etype (Comp));
Next_Component (Comp);
end loop;
end if;
-- If the task type is another unit, we will perform the usual
-- elaboration check on its enclosing unit. If the type is in the
-- same unit, we can trace the task body as for an internal call,
-- but we only need to examine other external calls, because at
-- the point the task is activated, internal subprogram bodies
-- will have been elaborated already. We keep separate lists for
-- each kind of task.
-- Skip this test if errors have occurred, since in this case
-- we can get false indications.
if Serious_Errors_Detected /= 0 then
return;
end if;
if Present (Proc) then
if Outer_Unit (Scope (Proc)) = Enclosing then
if No (Corresponding_Body (Unit_Declaration_Node (Proc)))
and then
(not Is_Generic_Instance (Scope (Proc))
or else Scope (Proc) = Scope (Defining_Identifier (Decl)))
then
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_N
("task will be activated before elaboration of its body<<",
Decl);
Error_Msg_N ("\Program_Error [<<", Decl);
elsif Present
(Corresponding_Body (Unit_Declaration_Node (Proc)))
then
Append_Elmt (Proc, Intra_Procs);
end if;
else
-- No need for multiple entries of the same type
Elmt := First_Elmt (Inter_Procs);
while Present (Elmt) loop
if Node (Elmt) = Proc then
return;
end if;
Next_Elmt (Elmt);
end loop;
Append_Elmt (Proc, Inter_Procs);
end if;
end if;
end Add_Task_Proc;
-------------------
-- Collect_Tasks --
-------------------
procedure Collect_Tasks (Decls : List_Id) is
begin
if Present (Decls) then
Decl := First (Decls);
while Present (Decl) loop
if Nkind (Decl) = N_Object_Declaration
and then Has_Task (Etype (Defining_Identifier (Decl)))
then
Add_Task_Proc (Etype (Defining_Identifier (Decl)));
end if;
Next (Decl);
end loop;
end if;
end Collect_Tasks;
----------------
-- Outer_Unit --
----------------
function Outer_Unit (E : Entity_Id) return Entity_Id is
Outer : Entity_Id;
begin
Outer := E;
while Present (Outer) loop
if Elaboration_Checks_Suppressed (Outer) then
Cunit_SC := True;
end if;
exit when Is_Child_Unit (Outer)
or else Scope (Outer) = Standard_Standard
or else Ekind (Outer) /= E_Package;
Outer := Scope (Outer);
end loop;
return Outer;
end Outer_Unit;
-- Start of processing for Check_Task_Activation
begin
pragma Assert (Legacy_Elaboration_Checks);
Enclosing := Outer_Unit (Current_Scope);
-- Find all tasks declared in the current unit
if Nkind (N) = N_Package_Body then
P := Unit_Declaration_Node (Corresponding_Spec (N));
Collect_Tasks (Declarations (N));
Collect_Tasks (Visible_Declarations (Specification (P)));
Collect_Tasks (Private_Declarations (Specification (P)));
elsif Nkind (N) = N_Package_Declaration then
Collect_Tasks (Visible_Declarations (Specification (N)));
Collect_Tasks (Private_Declarations (Specification (N)));
else
Collect_Tasks (Declarations (N));
end if;
-- We only perform detailed checks in all tasks that are library level
-- entities. If the master is a subprogram or task, activation will
-- depend on the activation of the master itself.
-- Should dynamic checks be added in the more general case???
if Ekind (Enclosing) /= E_Package then
return;
end if;
-- For task types defined in other units, we want the unit containing
-- the task body to be elaborated before the current one.
Elmt := First_Elmt (Inter_Procs);
while Present (Elmt) loop
Ent := Node (Elmt);
Task_Scope := Outer_Unit (Scope (Ent));
if not Is_Compilation_Unit (Task_Scope) then
null;
elsif Suppress_Elaboration_Warnings (Task_Scope)
or else Elaboration_Checks_Suppressed (Task_Scope)
then
null;
elsif Dynamic_Elaboration_Checks then
if not Elaboration_Checks_Suppressed (Ent)
and then not Cunit_SC
and then not Restriction_Active
(No_Entry_Calls_In_Elaboration_Code)
then
-- Runtime elaboration check required. Generate check of the
-- elaboration counter for the unit containing the entity.
Insert_Elab_Check (N,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Spec_Entity (Task_Scope), Loc),
Attribute_Name => Name_Elaborated));
end if;
else
-- Force the binder to elaborate other unit first
if Elab_Info_Messages
and then not Suppress_Elaboration_Warnings (Ent)
and then not Elaboration_Checks_Suppressed (Ent)
and then not Suppress_Elaboration_Warnings (Task_Scope)
and then not Elaboration_Checks_Suppressed (Task_Scope)
then
Error_Msg_Node_2 := Task_Scope;
Error_Msg_NE
("info: activation of an instance of task type & requires "
& "pragma Elaborate_All on &?$?", N, Ent);
end if;
Activate_Elaborate_All_Desirable (N, Task_Scope);
Set_Suppress_Elaboration_Warnings (Task_Scope);
end if;
Next_Elmt (Elmt);
end loop;
-- For tasks declared in the current unit, trace other calls within the
-- task procedure bodies, which are available.
if not Debug_Flag_Dot_Y then
In_Task_Activation := True;
Elmt := First_Elmt (Intra_Procs);
while Present (Elmt) loop
Ent := Node (Elmt);
Check_Internal_Call_Continue (N, Ent, Enclosing, Ent);
Next_Elmt (Elmt);
end loop;
In_Task_Activation := False;
end if;
end Check_Task_Activation;
------------------------
-- Get_Referenced_Ent --
------------------------
function Get_Referenced_Ent (N : Node_Id) return Entity_Id is
Nam : Node_Id;
begin
if Nkind (N) in N_Has_Entity
and then Present (Entity (N))
and then Ekind (Entity (N)) = E_Variable
then
return Entity (N);
end if;
if Nkind (N) = N_Attribute_Reference then
Nam := Prefix (N);
else
Nam := Name (N);
end if;
if No (Nam) then
return Empty;
elsif Nkind (Nam) = N_Selected_Component then
return Entity (Selector_Name (Nam));
elsif not Is_Entity_Name (Nam) then
return Empty;
else
return Entity (Nam);
end if;
end Get_Referenced_Ent;
----------------------
-- Has_Generic_Body --
----------------------
function Has_Generic_Body (N : Node_Id) return Boolean is
Ent : constant Entity_Id := Get_Generic_Entity (N);
Decl : constant Node_Id := Unit_Declaration_Node (Ent);
Scop : Entity_Id;
function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id;
-- Determine if the list of nodes headed by N and linked by Next
-- contains a package body for the package spec entity E, and if so
-- return the package body. If not, then returns Empty.
function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id;
-- This procedure is called load the unit whose name is given by Nam.
-- This unit is being loaded to see whether it contains an optional
-- generic body. The returned value is the loaded unit, which is always
-- a package body (only package bodies can contain other entities in the
-- sense in which Has_Generic_Body is interested). We only attempt to
-- load bodies if we are generating code. If we are in semantics check
-- only mode, then it would be wrong to load bodies that are not
-- required from a semantic point of view, so in this case we return
-- Empty. The result is that the caller may incorrectly decide that a
-- generic spec does not have a body when in fact it does, but the only
-- harm in this is that some warnings on elaboration problems may be
-- lost in semantic checks only mode, which is not big loss. We also
-- return Empty if we go for a body and it is not there.
function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id;
-- PE is the entity for a package spec. This function locates the
-- corresponding package body, returning Empty if none is found. The
-- package body returned is fully parsed but may not yet be analyzed,
-- so only syntactic fields should be referenced.
------------------
-- Find_Body_In --
------------------
function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id is
Nod : Node_Id;
begin
Nod := N;
while Present (Nod) loop
-- If we found the package body we are looking for, return it
if Nkind (Nod) = N_Package_Body
and then Chars (Defining_Unit_Name (Nod)) = Chars (E)
then
return Nod;
-- If we found the stub for the body, go after the subunit,
-- loading it if necessary.
elsif Nkind (Nod) = N_Package_Body_Stub
and then Chars (Defining_Identifier (Nod)) = Chars (E)
then
if Present (Library_Unit (Nod)) then
return Unit (Library_Unit (Nod));
else
return Load_Package_Body (Get_Unit_Name (Nod));
end if;
-- If neither package body nor stub, keep looking on chain
else
Next (Nod);
end if;
end loop;
return Empty;
end Find_Body_In;
-----------------------
-- Load_Package_Body --
-----------------------
function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id is
U : Unit_Number_Type;
begin
if Operating_Mode /= Generate_Code then
return Empty;
else
U :=
Load_Unit
(Load_Name => Nam,
Required => False,
Subunit => False,
Error_Node => N);
if U = No_Unit then
return Empty;
else
return Unit (Cunit (U));
end if;
end if;
end Load_Package_Body;
-------------------------------
-- Locate_Corresponding_Body --
-------------------------------
function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id is
Spec : constant Node_Id := Declaration_Node (PE);
Decl : constant Node_Id := Parent (Spec);
Scop : constant Entity_Id := Scope (PE);
PBody : Node_Id;
begin
if Is_Library_Level_Entity (PE) then
-- If package is a library unit that requires a body, we have no
-- choice but to go after that body because it might contain an
-- optional body for the original generic package.
if Unit_Requires_Body (PE) then
-- Load the body. Note that we are a little careful here to use
-- Spec to get the unit number, rather than PE or Decl, since
-- in the case where the package is itself a library level
-- instantiation, Spec will properly reference the generic
-- template, which is what we really want.
return
Load_Package_Body
(Get_Body_Name (Unit_Name (Get_Source_Unit (Spec))));
-- But if the package is a library unit that does NOT require
-- a body, then no body is permitted, so we are sure that there
-- is no body for the original generic package.
else
return Empty;
end if;
-- Otherwise look and see if we are embedded in a further package
elsif Is_Package_Or_Generic_Package (Scop) then
-- If so, get the body of the enclosing package, and look in
-- its package body for the package body we are looking for.
PBody := Locate_Corresponding_Body (Scop);
if No (PBody) then
return Empty;
else
return Find_Body_In (PE, First (Declarations (PBody)));
end if;
-- If we are not embedded in a further package, then the body
-- must be in the same declarative part as we are.
else
return Find_Body_In (PE, Next (Decl));
end if;
end Locate_Corresponding_Body;
-- Start of processing for Has_Generic_Body
begin
if Present (Corresponding_Body (Decl)) then
return True;
elsif Unit_Requires_Body (Ent) then
return True;
-- Compilation units cannot have optional bodies
elsif Is_Compilation_Unit (Ent) then
return False;
-- Otherwise look at what scope we are in
else
Scop := Scope (Ent);
-- Case of entity is in other than a package spec, in this case
-- the body, if present, must be in the same declarative part.
if not Is_Package_Or_Generic_Package (Scop) then
declare
P : Node_Id;
begin
-- Declaration node may get us a spec, so if so, go to
-- the parent declaration.
P := Declaration_Node (Ent);
while not Is_List_Member (P) loop
P := Parent (P);
end loop;
return Present (Find_Body_In (Ent, Next (P)));
end;
-- If the entity is in a package spec, then we have to locate
-- the corresponding package body, and look there.
else
declare
PBody : constant Node_Id := Locate_Corresponding_Body (Scop);
begin
if No (PBody) then
return False;
else
return
Present
(Find_Body_In (Ent, (First (Declarations (PBody)))));
end if;
end;
end if;
end if;
end Has_Generic_Body;
-----------------------
-- Insert_Elab_Check --
-----------------------
procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty) is
Nod : Node_Id;
Loc : constant Source_Ptr := Sloc (N);
Chk : Node_Id;
-- The check (N_Raise_Program_Error) node to be inserted
begin
-- If expansion is disabled, do not generate any checks. Also
-- skip checks if any subunits are missing because in either
-- case we lack the full information that we need, and no object
-- file will be created in any case.
if not Expander_Active or else Subunits_Missing then
return;
end if;
-- If we have a generic instantiation, where Instance_Spec is set,
-- then this field points to a generic instance spec that has
-- been inserted before the instantiation node itself, so that
-- is where we want to insert a check.
if Nkind (N) in N_Generic_Instantiation
and then Present (Instance_Spec (N))
then
Nod := Instance_Spec (N);
else
Nod := N;
end if;
-- Build check node, possibly with condition
Chk :=
Make_Raise_Program_Error (Loc, Reason => PE_Access_Before_Elaboration);
if Present (C) then
Set_Condition (Chk, Make_Op_Not (Loc, Right_Opnd => C));
end if;
-- If we are inserting at the top level, insert in Aux_Decls
if Nkind (Parent (Nod)) = N_Compilation_Unit then
declare
ADN : constant Node_Id := Aux_Decls_Node (Parent (Nod));
begin
if No (Declarations (ADN)) then
Set_Declarations (ADN, New_List (Chk));
else
Append_To (Declarations (ADN), Chk);
end if;
Analyze (Chk);
end;
-- Otherwise just insert as an action on the node in question
else
Insert_Action (Nod, Chk);
end if;
end Insert_Elab_Check;
-------------------------------
-- Is_Call_Of_Generic_Formal --
-------------------------------
function Is_Call_Of_Generic_Formal (N : Node_Id) return Boolean is
begin
return Nkind (N) in N_Function_Call | N_Procedure_Call_Statement
-- Always return False if debug flag -gnatd.G is set
and then not Debug_Flag_Dot_GG
-- For now, we detect this by looking for the strange identifier
-- node, whose Chars reflect the name of the generic formal, but
-- the Chars of the Entity references the generic actual.
and then Nkind (Name (N)) = N_Identifier
and then Chars (Name (N)) /= Chars (Entity (Name (N)));
end Is_Call_Of_Generic_Formal;
-------------------------------
-- Is_Finalization_Procedure --
-------------------------------
function Is_Finalization_Procedure (Id : Entity_Id) return Boolean is
begin
-- Check whether Id is a procedure with at least one parameter
if Ekind (Id) = E_Procedure and then Present (First_Formal (Id)) then
declare
Typ : constant Entity_Id := Etype (First_Formal (Id));
Deep_Fin : Entity_Id := Empty;
Fin : Entity_Id := Empty;
begin
-- If the type of the first formal does not require finalization
-- actions, then this is definitely not [Deep_]Finalize.
if not Needs_Finalization (Typ) then
return False;
end if;
-- At this point we have the following scenario:
-- procedure Name (Param1 : [in] [out] Ctrl[; Param2 : ...]);
-- Recover the two possible versions of [Deep_]Finalize using the
-- type of the first parameter and compare with the input.
Deep_Fin := TSS (Typ, TSS_Deep_Finalize);
if Is_Controlled (Typ) then
Fin := Find_Prim_Op (Typ, Name_Finalize);
end if;
return (Present (Deep_Fin) and then Id = Deep_Fin)
or else (Present (Fin) and then Id = Fin);
end;
end if;
return False;
end Is_Finalization_Procedure;
------------------
-- Output_Calls --
------------------
procedure Output_Calls
(N : Node_Id;
Check_Elab_Flag : Boolean)
is
function Emit (Flag : Boolean) return Boolean;
-- Determine whether to emit an error message based on the combination
-- of flags Check_Elab_Flag and Flag.
function Is_Printable_Error_Name return Boolean;
-- An internal function, used to determine if a name, stored in the
-- Name_Buffer, is either a non-internal name, or is an internal name
-- that is printable by the error message circuits (i.e. it has a single
-- upper case letter at the end).
----------
-- Emit --
----------
function Emit (Flag : Boolean) return Boolean is
begin
if Check_Elab_Flag then
return Flag;
else
return True;
end if;
end Emit;
-----------------------------
-- Is_Printable_Error_Name --
-----------------------------
function Is_Printable_Error_Name return Boolean is
begin
if not Is_Internal_Name then
return True;
elsif Name_Len = 1 then
return False;
else
Name_Len := Name_Len - 1;
return not Is_Internal_Name;
end if;
end Is_Printable_Error_Name;
-- Local variables
Ent : Entity_Id;
-- Start of processing for Output_Calls
begin
for J in reverse 1 .. Elab_Call.Last loop
Error_Msg_Sloc := Elab_Call.Table (J).Cloc;
Ent := Elab_Call.Table (J).Ent;
Get_Name_String (Chars (Ent));
-- Dynamic elaboration model, warnings controlled by -gnatwl
if Dynamic_Elaboration_Checks then
if Emit (Elab_Warnings) then
if Is_Generic_Unit (Ent) then
Error_Msg_NE ("\\?l?& instantiated #", N, Ent);
elsif Is_Init_Proc (Ent) then
Error_Msg_N ("\\?l?initialization procedure called #", N);
elsif Is_Printable_Error_Name then
Error_Msg_NE ("\\?l?& called #", N, Ent);
else
Error_Msg_N ("\\?l?called #", N);
end if;
end if;
-- Static elaboration model, info messages controlled by -gnatel
else
if Emit (Elab_Info_Messages) then
if Is_Generic_Unit (Ent) then
Error_Msg_NE ("\\?$?& instantiated #", N, Ent);
elsif Is_Init_Proc (Ent) then
Error_Msg_N ("\\?$?initialization procedure called #", N);
elsif Is_Printable_Error_Name then
Error_Msg_NE ("\\?$?& called #", N, Ent);
else
Error_Msg_N ("\\?$?called #", N);
end if;
end if;
end if;
end loop;
end Output_Calls;
----------------------------
-- Same_Elaboration_Scope --
----------------------------
function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean is
S1 : Entity_Id;
S2 : Entity_Id;
begin
-- Find elaboration scope for Scop1
-- This is either a subprogram or a compilation unit.
S1 := Scop1;
while S1 /= Standard_Standard
and then not Is_Compilation_Unit (S1)
and then Ekind (S1) in E_Package | E_Protected_Type | E_Block
loop
S1 := Scope (S1);
end loop;
-- Find elaboration scope for Scop2
S2 := Scop2;
while S2 /= Standard_Standard
and then not Is_Compilation_Unit (S2)
and then Ekind (S2) in E_Package | E_Protected_Type | E_Block
loop
S2 := Scope (S2);
end loop;
return S1 = S2;
end Same_Elaboration_Scope;
-----------------
-- Set_C_Scope --
-----------------
procedure Set_C_Scope is
begin
while not Is_Compilation_Unit (C_Scope) loop
C_Scope := Scope (C_Scope);
end loop;
end Set_C_Scope;
--------------------------------
-- Set_Elaboration_Constraint --
--------------------------------
procedure Set_Elaboration_Constraint
(Call : Node_Id;
Subp : Entity_Id;
Scop : Entity_Id)
is
Elab_Unit : Entity_Id;
-- Check whether this is a call to an Initialize subprogram for a
-- controlled type. Note that Call can also be a 'Access attribute
-- reference, which now generates an elaboration check.
Init_Call : constant Boolean :=
Nkind (Call) = N_Procedure_Call_Statement
and then Chars (Subp) = Name_Initialize
and then Comes_From_Source (Subp)
and then Present (Parameter_Associations (Call))
and then Is_Controlled (Etype (First_Actual (Call)));
begin
-- If the unit is mentioned in a with_clause of the current unit, it is
-- visible, and we can set the elaboration flag.
if Is_Immediately_Visible (Scop)
or else (Is_Child_Unit (Scop) and then Is_Visible_Lib_Unit (Scop))
then
Activate_Elaborate_All_Desirable (Call, Scop);
Set_Suppress_Elaboration_Warnings (Scop);
return;
end if;
-- If this is not an initialization call or a call using object notation
-- we know that the unit of the called entity is in the context, and we
-- can set the flag as well. The unit need not be visible if the call
-- occurs within an instantiation.
if Is_Init_Proc (Subp)
or else Init_Call
or else Nkind (Original_Node (Call)) = N_Selected_Component
then
null; -- detailed processing follows.
else
Activate_Elaborate_All_Desirable (Call, Scop);
Set_Suppress_Elaboration_Warnings (Scop);
return;
end if;
-- If the unit is not in the context, there must be an intermediate unit
-- that is, on which we need to place to elaboration flag. This happens
-- with init proc calls.
if Is_Init_Proc (Subp) or else Init_Call then
-- The initialization call is on an object whose type is not declared
-- in the same scope as the subprogram. The type of the object must
-- be a subtype of the type of operation. This object is the first
-- actual in the call.
declare
Typ : constant Entity_Id :=
Etype (First (Parameter_Associations (Call)));
begin
Elab_Unit := Scope (Typ);
while (Present (Elab_Unit))
and then not Is_Compilation_Unit (Elab_Unit)
loop
Elab_Unit := Scope (Elab_Unit);
end loop;
end;
-- If original node uses selected component notation, the prefix is
-- visible and determines the scope that must be elaborated. After
-- rewriting, the prefix is the first actual in the call.
elsif Nkind (Original_Node (Call)) = N_Selected_Component then
Elab_Unit := Scope (Etype (First (Parameter_Associations (Call))));
-- Not one of special cases above
else
-- Using previously computed scope. If the elaboration check is
-- done after analysis, the scope is not visible any longer, but
-- must still be in the context.
Elab_Unit := Scop;
end if;
Activate_Elaborate_All_Desirable (Call, Elab_Unit);
Set_Suppress_Elaboration_Warnings (Elab_Unit);
end Set_Elaboration_Constraint;
-----------------
-- Spec_Entity --
-----------------
function Spec_Entity (E : Entity_Id) return Entity_Id is
Decl : Node_Id;
begin
-- Check for case of body entity
-- Why is the check for E_Void needed???
if Ekind (E) in E_Void | E_Subprogram_Body | E_Package_Body then
Decl := E;
loop
Decl := Parent (Decl);
exit when Nkind (Decl) in N_Proper_Body;
end loop;
return Corresponding_Spec (Decl);
else
return E;
end if;
end Spec_Entity;
------------
-- Within --
------------
function Within (E1, E2 : Entity_Id) return Boolean is
Scop : Entity_Id;
begin
Scop := E1;
loop
if Scop = E2 then
return True;
elsif Scop = Standard_Standard then
return False;
else
Scop := Scope (Scop);
end if;
end loop;
end Within;
--------------------------
-- Within_Elaborate_All --
--------------------------
function Within_Elaborate_All
(Unit : Unit_Number_Type;
E : Entity_Id) return Boolean
is
type Unit_Number_Set is array (Main_Unit .. Last_Unit) of Boolean;
pragma Pack (Unit_Number_Set);
Seen : Unit_Number_Set := (others => False);
-- Seen (X) is True after we have seen unit X in the walk. This is used
-- to prevent processing the same unit more than once.
Result : Boolean := False;
procedure Helper (Unit : Unit_Number_Type);
-- This helper procedure does all the work for Within_Elaborate_All. It
-- walks the dependency graph, and sets Result to True if it finds an
-- appropriate Elaborate_All.
------------
-- Helper --
------------
procedure Helper (Unit : Unit_Number_Type) is
CU : constant Node_Id := Cunit (Unit);
Item : Node_Id;
Item2 : Node_Id;
Elab_Id : Entity_Id;
Par : Node_Id;
begin
if Seen (Unit) then
return;
else
Seen (Unit) := True;
end if;
-- First, check for Elaborate_Alls on this unit
Item := First (Context_Items (CU));
while Present (Item) loop
if Nkind (Item) = N_Pragma
and then Pragma_Name (Item) = Name_Elaborate_All
then
-- Return if some previous error on the pragma itself. The
-- pragma may be unanalyzed, because of a previous error, or
-- if it is the context of a subunit, inherited by its parent.
if Error_Posted (Item) or else not Analyzed (Item) then
return;
end if;
Elab_Id :=
Entity
(Expression (First (Pragma_Argument_Associations (Item))));
if E = Elab_Id then
Result := True;
return;
end if;
Par := Parent (Unit_Declaration_Node (Elab_Id));
Item2 := First (Context_Items (Par));
while Present (Item2) loop
if Nkind (Item2) = N_With_Clause
and then Entity (Name (Item2)) = E
and then not Limited_Present (Item2)
then
Result := True;
return;
end if;
Next (Item2);
end loop;
end if;
Next (Item);
end loop;
-- Second, recurse on with's. We could do this as part of the above
-- loop, but it's probably more efficient to have two loops, because
-- the relevant Elaborate_All is likely to be on the initial unit. In
-- other words, we're walking the with's breadth-first. This part is
-- only necessary in the dynamic elaboration model.
if Dynamic_Elaboration_Checks then
Item := First (Context_Items (CU));
while Present (Item) loop
if Nkind (Item) = N_With_Clause
and then not Limited_Present (Item)
then
-- Note: the following call to Get_Cunit_Unit_Number does a
-- linear search, which could be slow, but it's OK because
-- we're about to give a warning anyway. Also, there might
-- be hundreds of units, but not millions. If it turns out
-- to be a problem, we could store the Get_Cunit_Unit_Number
-- in each N_Compilation_Unit node, but that would involve
-- rearranging N_Compilation_Unit_Aux to make room.
Helper (Get_Cunit_Unit_Number (Library_Unit (Item)));
if Result then
return;
end if;
end if;
Next (Item);
end loop;
end if;
end Helper;
-- Start of processing for Within_Elaborate_All
begin
Helper (Unit);
return Result;
end Within_Elaborate_All;
end Sem_Elab;
|
archive/agda-3/src/Oscar/Data/ProperlyExtensionNothing.agda | m0davis/oscar | 0 | 9233 |
open import Oscar.Prelude
open import Oscar.Data.𝟘
module Oscar.Data.ProperlyExtensionNothing where
module _
{𝔵} {𝔛 : Ø 𝔵}
{𝔬} {𝔒 : 𝔛 → Ø 𝔬}
{ℓ}
{ℓ̇} {_↦_ : ∀ {x} → 𝔒 x → 𝔒 x → Ø ℓ̇}
where
record ProperlyExtensionNothing (P : ExtensionṖroperty ℓ 𝔒 _↦_) : Ø 𝔵 ∙̂ 𝔬 ∙̂ ℓ where
constructor ∁
field
π₀ : ∀ {n} {f : 𝔒 n} → π₀ (π₀ P) f → 𝟘
open ProperlyExtensionNothing public
|
tests/kat/cshake_runner.adb | damaki/libkeccak | 26 | 632 | <gh_stars>10-100
-------------------------------------------------------------------------------
-- Copyright (c) 2019, <NAME>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
-- * The name of the copyright holder may not be used to endorse or promote
-- Products derived from this software without specific prior written
-- permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO;
with Ada.Unchecked_Deallocation;
with Interfaces; use Interfaces;
with Keccak.Types;
with Test_Vectors; use Test_Vectors;
package body CSHAKE_Runner
is
procedure Free is new Ada.Unchecked_Deallocation
(Object => Keccak.Types.Byte_Array,
Name => Byte_Array_Access);
procedure Run_Tests (File_Name : in String;
Num_Passed : out Natural;
Num_Failed : out Natural)
is
use type Keccak.Types.Byte_Array;
package Integer_IO is new Ada.Text_IO.Integer_IO(Integer);
N_Key : constant Unbounded_String := To_Unbounded_String("N");
S_Key : constant Unbounded_String := To_Unbounded_String("S");
InLen_Key : constant Unbounded_String := To_Unbounded_String("InLen");
In_Key : constant Unbounded_String := To_Unbounded_String("In");
OutLen_Key : constant Unbounded_String := To_Unbounded_String("OutLen");
Out_Key : constant Unbounded_String := To_Unbounded_String("Out");
Schema : Test_Vectors.Schema_Maps.Map;
Tests : Test_Vectors.Lists.List;
Ctx : CSHAKE.Context;
Output : Byte_Array_Access;
OutLen : Natural;
begin
Num_Passed := 0;
Num_Failed := 0;
-- Setup schema
Schema.Insert (Key => N_Key,
New_Item => Schema_Entry'(VType => String_Type,
Required => True,
Is_List => False));
Schema.Insert (Key => S_Key,
New_Item => Schema_Entry'(VType => String_Type,
Required => True,
Is_List => False));
Schema.Insert (Key => InLen_Key,
New_Item => Schema_Entry'(VType => Integer_Type,
Required => True,
Is_List => False));
Schema.Insert (Key => In_Key,
New_Item => Schema_Entry'(VType => Hex_Array_Type,
Required => True,
Is_List => False));
Schema.Insert (Key => OutLen_Key,
New_Item => Schema_Entry'(VType => Integer_Type,
Required => True,
Is_List => False));
Schema.Insert (Key => Out_Key,
New_Item => Schema_Entry'(VType => Hex_Array_Type,
Required => True,
Is_List => False));
-- Load the test file using the file name given on the command line
Ada.Text_IO.Put_Line("Loading file: " & File_Name);
Test_Vectors.Load (File_Name => File_Name,
Schema => Schema,
Vectors_List => Tests);
Ada.Text_IO.Put ("Running ");
Integer_IO.Put (Integer (Tests.Length), Width => 0);
Ada.Text_IO.Put_Line (" tests ...");
-- Run each test.
for C of Tests loop
CSHAKE.Init (Ctx => Ctx,
Customization => To_String (C.Element (S_Key).First_Element.Str),
Function_Name => To_String (C.Element (N_Key).First_Element.Str));
CSHAKE.Update(Ctx => Ctx,
Message => C.Element (In_Key).First_Element.Hex.all,
Bit_Length => C.Element (InLen_Key).First_Element.Int);
Output := new Keccak.Types.Byte_Array (C.Element (Out_Key).First_Element.Hex.all'Range);
CSHAKE.Extract (Ctx, Output.all);
-- Mask any unused bits from the output.
OutLen := C.Element (OutLen_Key).First_Element.Int;
if OutLen mod 8 /= 0 then
Output.all(Output.all'Last) := Output.all(Output.all'Last) and Keccak.Types.Byte((2**(OutLen mod 8)) - 1);
end if;
-- Check output
if Output.all = C.Element(Out_Key).First_Element.Hex.all then
Num_Passed := Num_Passed + 1;
else
Num_Failed := Num_Failed + 1;
-- Display a message on failure to help with debugging.
Ada.Text_IO.Put("FAILURE (Input bit-len: ");
Integer_IO.Put(C.Element (InLen_Key).First_Element.Int, Width => 0);
Ada.Text_IO.Put_Line(")");
Ada.Text_IO.Put(" Expected MD: ");
Ada.Text_IO.Put(Byte_Array_To_String (C.Element(Out_Key).First_Element.Hex.all));
Ada.Text_IO.New_Line;
Ada.Text_IO.Put(" Actual MD: ");
Ada.Text_IO.Put(Byte_Array_To_String(Output.all));
Ada.Text_IO.New_Line;
end if;
Free (Output);
end loop;
end Run_Tests;
end CSHAKE_Runner;
|
list1/task2/src/poly.adb | luk9400/nsi | 0 | 19026 | package body Poly with SPARK_Mode is
function Horner (X: Integer; A: Vector) return Integer is
Acc: Integer := 0;
Aux: Integer := 0 with Ghost;
begin
for Index in reverse A'First .. A'Last loop
Acc := A (Index) + (Acc * X);
Aux := Aux + A (Index) * (X ** (Index - A'First));
pragma Loop_Invariant (Aux = ((X**(Index - A'First)) * Acc));
end loop;
pragma Assert(Aux = Acc);
return Acc;
end Horner;
end Poly;
|
test/fail/PositivityCheckNeedsLinearityCheck.agda | asr/agda-kanso | 1 | 8746 | <reponame>asr/agda-kanso
-- This is an example emphasizing the important of a linearity check
-- in the positivity check.
--
-- Currently it does not type check since there is no universe subtyping.
module PositivityCheckNeedsLinearityCheck where
data Eq (S : Set2) : Set2 -> Set where
refl : Eq S S
subst' : {S S' : Set2} -> Eq S S' -> S -> S'
subst' refl s = s
-- what happens if Eq is considered covariant in its first argument?
-- then because of subtyping,
p : Eq Set1 Set
p = refl
S : Set
S = subst' p Set
-- now S, which evaluates to Set, is in Set
|
TurtleTools/Examples/test_le.asm | foxostro/TurtleTTL | 1 | 168401 | <reponame>foxostro/TurtleTTL
LI A, 0
LI B, 1
CMP
LXY is_le
JLE
NOP
NOP
LI A, 0xff
LI B, 0xff
LI U, 0xff
LI V, 0xff
LI X, 0xff
LI Y, 0xff
HLT
is_le:
LI A, 0xaa
LI B, 0xaa
LI U, 0xaa
LI V, 0xaa
LI X, 0xaa
LI Y, 0xaa
HLT |
src/agda/FRP/JS/Geolocation/Coords.agda | agda/agda-frp-js | 63 | 12855 | <filename>src/agda/FRP/JS/Geolocation/Coords.agda
open import FRP.JS.Geolocation.Angle using ( Angle ) renaming ( toString to toString° )
open import FRP.JS.String using ( String ; _++_ )
module FRP.JS.Geolocation.Coords where
-- Not including the optional fields yet.
record Coords : Set where
field
latitude : Angle
longitude : Angle
open Coords public
toString : Coords → String
toString c = toString° (latitude c) ++ "," ++ toString° (longitude c)
|
tpantlr2-code/code/reference/foo/Count.g4 | cgonul/antlr-poc | 10 | 2150 | <reponame>cgonul/antlr-poc
grammar Count;
@header {
package foo;
}
@members {
int count = 0;
}
list
@after {System.out.println(count+" ints");}
: INT {count++;} (',' INT {count++;} )*
;
INT : [0-9]+ ;
WS : [ \r\t\n]+ -> skip ;
|
examples/GUIgeneric/GUIModelExample.agda | stephanadls/state-dependent-gui | 2 | 194 | open import Data.Bool
module GUIgeneric.GUIModelExample where
open import GUIgeneric.Prelude renaming (inj₁ to secondButton; inj₂ to firstButton; WxColor to Color) hiding (IOInterfaceˢ)
open import GUIgeneric.GUIDefinitions renaming (add to add'; add' to add; ComponentEls to Frame)
open import GUIgeneric.GUI
open import GUIgeneric.GUIExampleLib
open import StateSizedIO.writingOOsUsingIOVers4ReaderMethods
open import StateSizedIO.Base
open import GUIgeneric.GUIExample using (oneBtnGUI ; propOneBtn ; obj1Btn; twoBtnGUI ; propTwoBtn ; obj2Btn )
open import GUIgeneric.GUIModel
open import Data.Sum
open IOInterfaceˢ public
private postulate btn : FFIButton
private postulate fr : FFIFrame
state1Btn : ModelGuiState
state1Btn = state oneBtnGUI propOneBtn
(obj1Btn {∞}) notStarted
state2Btn : ModelGuiState
state2Btn = state twoBtnGUI propTwoBtn
(obj2Btn {∞}) notStarted
corstate1BtnNext1∀ : (m : ModelGuiState)
→ (state1Btn -gui->¹ m)
→ m ≡ state2Btn
corstate1BtnNext1∀ m (step _) = refl
corstate1BtnNext∃ : state1Btn -gui->¹ state2Btn
corstate1BtnNext∃ = step (btn , fr)
corstate1BtnNext∀ : (m : ModelGuiState)
→ (state2Btn -gui->¹ m)
→ (m ≡ state2Btn ⊎ m ≡ state1Btn )
corstate1BtnNext∀ m (step (inj₁ _)) = inj₁ refl
corstate1BtnNext∀ m (step (inj₂ _)) = inj₂ refl
corstate2BtnNext∃1 : state2Btn -gui->¹ state2Btn
corstate2BtnNext∃1 = step (inj₁ (btn , (btn , fr)) )
corstate2BtnNext∃2 : state2Btn -gui->¹ state1Btn
corstate2BtnNext∃2 = step (inj₂ (btn , (btn , fr)) )
|
libsrc/math/cpcmath/tan.asm | RC2014Z80/z88dk | 8 | 103823 | <filename>libsrc/math/cpcmath/tan.asm
;
; CPC Maths Routines
;
; August 2003 **_|warp6|_** <kbaccam /at/ free.fr>
;
; $Id: tan.asm,v 1.4 2016-06-22 19:50:49 dom Exp $
;
SECTION code_fp
INCLUDE "cpcfirm.def"
INCLUDE "cpcfp.def"
PUBLIC tan
PUBLIC tanc
EXTERN get_para
.tan call get_para
call firmware
.tanc defw CPCFP_FLO_TAN
ret
|
third_party/antlr_grammars_v4/python/python2-js/Python2.g4 | mikhan808/rsyntaxtextarea-antlr4-extension | 4 | 6327 | <reponame>mikhan808/rsyntaxtextarea-antlr4-extension
/*
* Parser grammar taken directly from official Python 2.7.13 grammar
* with only minor syntactical changes (instances of [X] changed to (X)?, and
* semicolons added to ends of rules).:
* https://docs.python.org/2/reference/grammar.html
*
* Added lexer rules, and code to handle INDENT's, DEDENT's,
* line continuations, etc.
*
* Compiles with ANTLR 4.7, generated lexer/parser for Python 2 target.
*/
grammar Python2;
tokens { INDENT, DEDENT, NEWLINE, ENDMARKER }
@lexer::header {
var Python2Parser = require('./Python2Parser').Python2Parser;
var CommonToken = require('antlr4').CommonToken
class IndentStack {
constructor() {
this._s = [];
}
empty() {
return this._s.length === 0;
}
push(wsval) {
this._s.push(wsval);
}
pop() {
this._s.pop();
}
wsval() {
if (this._s.length) return this._s[this._s.length - 1];
else return 0;
}
}
class TokenQueue {
constructor() {
this._q = [];
}
empty() {
return this._q.length === 0;
}
enq(t) {
this._q.push(t);
}
deq() {
return this._q.shift();
}
}
function ord(char) {
return char.charCodeAt();
}
}
@lexer::members {
var old_lexer = Python2Lexer;
Python2Lexer = function() {
old_lexer.apply(this, arguments);
this._openBRCount = 0
this._suppressNewlines = false
this._lineContinuation = false
this._tokens = new TokenQueue();
this._indents = new IndentStack();
antlr4.Lexer.prototype.reset.call(this);
}
Python2Lexer.prototype = Object.create(old_lexer.prototype);
Python2Lexer.prototype.constructor = Python2Lexer;
Python2Lexer.prototype.nextToken = function() {
if (!this._tokens.empty()) {
return this._tokens.deq();
} else {
var t = antlr4.Lexer.prototype.nextToken.call(this);
if (t.type !== Python2Parser.EOF) return t;
else {
if (!this._suppressNewlines) {
this.emitNewline();
}
this.emitFullDedent();
this.emitEndmarker();
this.emitEndToken(t);
return this._tokens.deq();
}
}
}
Python2Lexer.prototype.emitEndToken = function (token) {
this._tokens.enq(token);
}
Python2Lexer.prototype.emitIndent = function (length = 0, text = 'INDENT') {
var t = this.createToken(Python2Parser.INDENT, text, length);
this._tokens.enq(t);
}
Python2Lexer.prototype.emitDedent = function () {
var t = this.createToken(Python2Parser.DEDENT, 'DEDENT');
this._tokens.enq(t);
}
Python2Lexer.prototype.emitFullDedent = function () {
while (!this._indents.empty()) {
this._indents.pop();
this.emitDedent();
}
}
Python2Lexer.prototype.emitEndmarker = function () {
var t = this.createToken(Python2Parser.ENDMARKER, 'ENDMARKER');
this._tokens.enq(t);
}
Python2Lexer.prototype.emitNewline = function () {
var t = this.createToken(Python2Parser.NEWLINE, 'NEWLINE');
this._tokens.enq(t);
}
Python2Lexer.prototype.createToken = function (type_, text="", length=0) {
var start = this._tokenStartCharIndex;
var stop = start + length;
var t = new CommonToken(this._tokenFactorySourcePair,
type_, this.DEFAULT_TOKEN_CHANNEL,
start, stop);
t.text = text;
return t;
}
}
// Header included from Python site:
/*
* Grammar for Python
*
* Note: Changing the grammar specified in this file will most likely
* require corresponding changes in the parser module
* (../Modules/parsermodule.c). If you can't make the changes to
* that module yourself, please co-ordinate the required changes
* with someone who can; ask around on python-dev for help. Fred
* Drake <<EMAIL>> will probably be listening there.
*
* NOTE WELL: You should also follow all the steps listed in PEP 306,
* "How to Change Python's Grammar"
*
* Start symbols for the grammar:
* single_input is a single interactive statement;
* file_input is a module or sequence of commands read from an input file;
* eval_input is the input for the eval() and input() functions.
* NB: compound_stmt in single_input is followed by extra NEWLINE!
*/
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
;
file_input: (NEWLINE | stmt)* ENDMARKER
;
eval_input: testlist NEWLINE* ENDMARKER
;
decorator: '@' dotted_name ( '(' (arglist)? ')' )? NEWLINE
;
decorators: decorator+
;
decorated: decorators (classdef | funcdef)
;
funcdef: 'def' NAME parameters ':' suite
;
parameters: '(' (varargslist)? ')'
;
varargslist: ((fpdef ('=' test)? ',')*
('*' NAME (',' '**' NAME)? | '**' NAME) |
fpdef ('=' test)? (',' fpdef ('=' test)?)* (',')?)
;
fpdef: NAME | '(' fplist ')'
;
fplist: fpdef (',' fpdef)* (',')?
;
stmt: simple_stmt | compound_stmt
;
simple_stmt: small_stmt (';' small_stmt)* (';')? NEWLINE
;
small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | exec_stmt | assert_stmt)
;
expr_stmt: testlist (augassign (yield_expr|testlist) |
('=' (yield_expr|testlist))*)
;
augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
// For normal assignments, additional restrictions enforced by the interpreter
;
//print_stmt: 'print' ( ( test (',' test)* (',')? )? |
// '>>' test ( (',' test)+ (',')? )? )
// ;
print_stmt: {this._input.LT(1).text=='print'}?
// tt: this change allows print to be treated as a NAME
// while preserving the print statement syntax.
NAME ( ( test (',' test)* (',')? )? |
'>>' test ( (',' test)+ (',')? )? )
;
del_stmt: 'del' exprlist
;
pass_stmt: 'pass'
;
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
;
break_stmt: 'break'
;
continue_stmt: 'continue'
;
return_stmt: 'return' (testlist)?
;
yield_stmt: yield_expr
;
raise_stmt: 'raise' (test (',' test (',' test)?)?)?
;
import_stmt: import_name | import_from
;
import_name: 'import' dotted_as_names
;
import_from: ('from' ('.'* dotted_name | '.'+)
'import' ('*' | '(' import_as_names ')' | import_as_names))
;
import_as_name: NAME ('as' NAME)?
;
dotted_as_name: dotted_name ('as' NAME)?
;
import_as_names: import_as_name (',' import_as_name)* (',')?
;
dotted_as_names: dotted_as_name (',' dotted_as_name)*
;
dotted_name: NAME ('.' NAME)*
;
global_stmt: 'global' NAME (',' NAME)*
;
exec_stmt: 'exec' expr ('in' test (',' test)?)?
;
assert_stmt: 'assert' test (',' test)?
;
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
;
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ('else' ':' suite)?
;
while_stmt: 'while' test ':' suite ('else' ':' suite)?
;
for_stmt: 'for' exprlist 'in' testlist ':' suite ('else' ':' suite)?
;
try_stmt: ('try' ':' suite
((except_clause ':' suite)+
('else' ':' suite)?
('finally' ':' suite)? |
'finally' ':' suite))
;
with_stmt: 'with' with_item (',' with_item)* ':' suite
;
with_item: test ('as' expr)?
// NB compile.c makes sure that the default except clause is last
;
except_clause: 'except' (test (('as' | ',') test)?)?
;
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
;
// Backward compatibility cruft to support:
// [ x for x in lambda: True, lambda: False if x() ]
// even while also allowing:
// lambda x: 5 if x else 2
// (But not a mix of the two)
testlist_safe: old_test ((',' old_test)+ (',')?)?
;
old_test: or_test | old_lambdef
;
old_lambdef: 'lambda' (varargslist)? ':' old_test
;
test: or_test ('if' or_test 'else' test)? | lambdef
;
or_test: and_test ('or' and_test)*
;
and_test: not_test ('and' not_test)*
;
not_test: 'not' not_test | comparison
;
comparison: expr (comp_op expr)*
;
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
;
expr: xor_expr ('|' xor_expr)*
;
xor_expr: and_expr ('^' and_expr)*
;
and_expr: shift_expr ('&' shift_expr)*
;
shift_expr: arith_expr (('<<'|'>>') arith_expr)*
;
arith_expr: term (('+'|'-') term)*
;
term: factor (('*'|'/'|'%'|'//') factor)*
;
factor: ('+'|'-'|'~') factor | power
;
power: atom trailer* ('**' factor)?
;
atom: ('(' (yield_expr|testlist_comp)? ')' |
'[' (listmaker)? ']' |
'{' (dictorsetmaker)? '}' |
'`' testlist1 '`' | '.' '.' '.' | // tt: added elipses.
NAME | NUMBER | STRING+)
;
listmaker: test ( list_for | (',' test)* (',')? )
;
testlist_comp: test ( comp_for | (',' test)* (',')? )
;
lambdef: 'lambda' (varargslist)? ':' test
;
trailer: '(' (arglist)? ')' | '[' subscriptlist ']' | '.' NAME
;
subscriptlist: subscript (',' subscript)* (',')?
;
subscript: '.' '.' '.' | test | (test)? ':' (test)? (sliceop)?
;
sliceop: ':' (test)?
;
exprlist: expr (',' expr)* (',')?
;
testlist: test (',' test)* (',')?
;
dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* (',')?)) |
(test (comp_for | (',' test)* (',')?)) )
;
classdef: 'class' NAME ('(' (testlist)? ')')? ':' suite
;
arglist: (argument ',')* (argument (',')?
|'*' test (',' argument)* (',' '**' test)?
|'**' test)
// The reason that keywords are test nodes instead of NAME is that using NAME
// results in an ambiguity. ast.c makes sure it's a NAME.
;
argument: test (comp_for)? | test '=' test
;
list_iter: list_for | list_if
;
list_for: 'for' exprlist 'in' testlist_safe (list_iter)?
;
list_if: 'if' old_test (list_iter)?
;
comp_iter: comp_for | comp_if
;
comp_for: 'for' exprlist 'in' or_test (comp_iter)?
;
comp_if: 'if' old_test (comp_iter)?
;
testlist1: test (',' test)*
;
// not used in grammar, but may appear in "node" passed from Parser to Compiler
encoding_decl: NAME
;
yield_expr: 'yield' 'from'? (testlist)?
;
/*****************************************************************************
* Lexer rules
*****************************************************************************/
NAME: [a-zA-Z_] [a-zA-Z0-9_]*
;
NUMBER
: '0' ([xX] [0-9a-fA-F]+ ([lL] | [eE] [+-]? [0-9]+)?
| [oO] [0-7]+ [lL]?
| [bB] [01]+ [lL]?)
| ([0-9]+ '.' [0-9]* | '.' [0-9]+) ([eE] [+-]? [0-9]+)? [jJ]?
| [0-9]+ ([lL] | [eE] [+-]? [0-9]+ [jJ]? | [jJ])?
;
STRING
: ([uUbB]? [rR]? | [rR]? [uUbB]?)
( '\'' ('\\' (([ \t]+ ('\r'? '\n')?)|.) | ~[\\\r\n'])* '\''
| '"' ('\\' (([ \t]+ ('\r'? '\n')?)|.) | ~[\\\r\n"])* '"'
| '"""' ('\\' . | ~'\\' )*? '"""'
| '\'\'\'' ('\\' . | ~'\\' )*? '\'\'\''
)
;
LINENDING: (('\r'? '\n')+ {this._lineContinuation=false}
| '\\' [ \t]* ('\r'? '\n') {this._lineContinuation=true})
{
if (this._openBRCount == 0 && !this._lineContinuation) {
if (!this._suppressNewlines) {
this.emitNewline()
this._suppressNewlines = true
}
var la = this._input.LA(1)
if ([ord(' '), ord('\t'), ord('#')].indexOf(la) === -1) {
this._suppressNewlines = false
this.emitFullDedent()
}
}
} -> channel(HIDDEN)
;
WHITESPACE: ('\t' | ' ')+
{
if (this._tokenStartColumn == 0 && this._openBRCount == 0
&& !this._lineContinuation) {
var la = this._input.LA(1);
if ([ord('\r'), ord('\n'), ord('#'), -1].indexOf(la)===-1)
this._suppressNewlines = false
var wsCount = 0;
for (var ch in this.text) {
ch = this.text[ch];
if (ch == ' ') wsCount += 1
else if (ch == '\t') wsCount += 8
}
if (wsCount > this._indents.wsval()) {
this.emitIndent(this.text.length)
this._indents.push(wsCount)
}
else {
while (wsCount < this._indents.wsval()) {
this.emitDedent()
this._indents.pop()
}
if (wsCount != this._indents.wsval()) {
// throw new Error('wsCount')
}
}
}
} -> channel(HIDDEN)
;
COMMENT: '#' ~[\r\n]* -> skip;
OPEN_PAREN: '(' {this._openBRCount += 1};
CLOSE_PAREN: ')' {this._openBRCount -= 1};
OPEN_BRACE: '{' {this._openBRCount += 1};
CLOSE_BRACE: '}' {this._openBRCount -= 1};
OPEN_BRACKET: '[' {this._openBRCount += 1};
CLOSE_BRACKET: ']' {this._openBRCount -= 1};
UNKNOWN: . -> skip;
|
theorems/cw/cohomology/cochainequiv/HigherCoboundaryCommSquare.agda | timjb/HoTT-Agda | 0 | 13451 | <reponame>timjb/HoTT-Agda
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cw.CW
open import cw.FinCW
open import cw.FinBoundary
open import cohomology.Theory
module cw.cohomology.cochainequiv.HigherCoboundaryCommSquare (OT : OrdinaryTheory lzero)
{n} (⊙fin-skel : ⊙FinSkeleton (S (S n))) where
open OrdinaryTheory OT
open import cw.cohomology.WedgeOfCells OT
open import cw.cohomology.reconstructed.HigherCoboundary OT ⊙⦉ ⊙fin-skel ⦊
open import cw.cohomology.cochainequiv.DualizedHigherBoundary OT ⊙fin-skel
open import cw.cohomology.cochainequiv.HigherCoboundary OT ⊙fin-skel
private
fin-skel = ⊙FinSkeleton.skel ⊙fin-skel
I = AttachedFinSkeleton.numCells fin-skel
ac = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero
⊙fin-skel₋₁ = ⊙fcw-init ⊙fin-skel
fin-skel₋₁ = ⊙FinSkeleton.skel ⊙fin-skel₋₁
ac₋₁ = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel₋₁ lzero
abstract
rephrase-dualized-higher-boundary-comm-sqr :
CommSquareEquiv
(λ g <I → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (fdegree-last fin-skel <I <I₋₁)))
(_∘ᴳ fboundary-last fin-skel)
(FreeAbGroup-extend (C2-abgroup 0))
(FreeAbGroup-extend (C2-abgroup 0))
rephrase-dualized-higher-boundary-comm-sqr =
comm-sqr (λ g →
equiv-adj'
(GroupIso.f-equiv (FreeAbGroup-extend-iso (C2-abgroup 0)))
(λ= λ <I → ! (rephrase-dualized-higher-boundary-in-degree g <I))) ,
FreeAbGroup-extend-is-equiv (C2-abgroup 0) ,
FreeAbGroup-extend-is-equiv (C2-abgroup 0)
rephrase-cw-co∂-last-comm-sqr :
CommSquareEquiv
(λ g <I → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (fdegree-last fin-skel <I <I₋₁)))
(GroupHom.f cw-co∂-last)
(GroupIso.g (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel₋₁ ⦊ ac₋₁))
(GroupIso.g (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel ⦊ ac))
rephrase-cw-co∂-last-comm-sqr =
comm-sqr (λ g →
equiv-adj'
(GroupIso.g-equiv (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel ⦊ ac))
(λ= λ <I → ! (rephrase-cw-co∂-last-in-degree g <I))) ,
(GroupIso.g-is-equiv (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel₋₁ ⦊ ac₋₁)) ,
(GroupIso.g-is-equiv (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel ⦊ ac))
higher-coboundary-comm-sqr :
CommSquareEquiv
(GroupHom.f cw-co∂-last)
(_∘ᴳ fboundary-last fin-skel)
(FreeAbGroup-extend (C2-abgroup 0) ∘ GroupIso.f (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel₋₁ ⦊ ac₋₁))
(FreeAbGroup-extend (C2-abgroup 0) ∘ GroupIso.f (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel ⦊ ac))
higher-coboundary-comm-sqr =
CommSquareEquiv-∘v
rephrase-dualized-higher-boundary-comm-sqr
(CommSquareEquiv-inverse-v rephrase-cw-co∂-last-comm-sqr)
higher-coboundary-comm-sqrᴳ :
CommSquareEquivᴳ
cw-co∂-last
(pre∘ᴳ-hom (C2-abgroup 0) (fboundary-last fin-skel))
(FreeAbGroup-extend-hom (C2-abgroup 0) ∘ᴳ GroupIso.f-hom (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel₋₁ ⦊ ac₋₁))
(FreeAbGroup-extend-hom (C2-abgroup 0) ∘ᴳ GroupIso.f-hom (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel ⦊ ac))
higher-coboundary-comm-sqrᴳ =
comm-sqrᴳ (fst higher-coboundary-comm-sqr □$_) , snd higher-coboundary-comm-sqr
|
RuntimeIntegrationTests/CPPGrammar/CPPGrammarLib/CPP14.g4 | Agrabski/Antlr_fork | 0 | 3631 | <filename>RuntimeIntegrationTests/CPPGrammar/CPPGrammarLib/CPP14.g4
/*******************************************************************************
* The MIT License (MIT)
Copyright (c) 2015 <NAME> (Camiloasc1)
Permission is hereby
* granted, free of charge, to any person obtaining a copy
of this software and associated
* documentation files (the "Software"), to deal
in the Software without restriction, including
* without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to
* do so, subject to the following conditions:
The above copyright notice and this permission
* notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE
* IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT
* LIMITED
TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN
NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
* ****************************************************************************
*/
grammar CPP14;
/*Basic concepts*/
translationunit: declarationseq? EOF;
/*Expressions*/
primaryexpression:
literal
| This
| '(' expression ')'
| idexpression
| lambdaexpression;
idexpression: unqualifiedid | qualifiedid;
unqualifiedid:
Identifier
| operatorfunctionid
| conversionfunctionid
| literaloperatorid
| '~' classname
| '~' decltypespecifier
| templateid;
qualifiedid: nestednamespecifier Template? unqualifiedid;
nestednamespecifier:
'::'
| thetypename '::'
| namespacename '::'
| decltypespecifier '::'
| nestednamespecifier Identifier '::'
| nestednamespecifier Template? simpletemplateid '::';
lambdaexpression:
lambdaintroducer lambdadeclarator? compoundstatement;
lambdaintroducer: '[' lambdacapture? ']';
lambdacapture:
capturedefault
| capturelist
| capturedefault ',' capturelist;
capturedefault: '&' | '=';
capturelist: capture '...'? | capturelist ',' capture '...'?;
capture: simplecapture | initcapture;
simplecapture: Identifier | '&' Identifier | This;
initcapture:
Identifier initializer
| '&' Identifier initializer;
lambdadeclarator:
'(' parameterdeclarationclause ')' Mutable? exceptionspecification? attributespecifierseq?
trailingreturntype?;
postfixexpression:
primaryexpression
| postfixexpression '[' expression ']'
| postfixexpression '[' bracedinitlist ']'
| postfixexpression '(' expressionlist? ')'
| simpletypespecifier '(' expressionlist? ')'
| typenamespecifier '(' expressionlist? ')'
| simpletypespecifier bracedinitlist
| typenamespecifier bracedinitlist
| postfixexpression '.' Template? idexpression
| postfixexpression '->' Template? idexpression
| postfixexpression '.' pseudodestructorname
| postfixexpression '->' pseudodestructorname
| postfixexpression '++'
| postfixexpression '--'
| Dynamic_cast '<' thetypeid GreaterThan '(' expression ')'
| Static_cast '<' thetypeid GreaterThan '(' expression ')'
| Reinterpret_cast '<' thetypeid GreaterThan '(' expression ')'
| Const_cast '<' thetypeid GreaterThan '(' expression ')'
| typeidofthetypeid '(' expression ')'
| typeidofthetypeid '(' thetypeid ')';
/*
add a middle layer to eliminate duplicated function declarations
*/
typeidofexpr: Typeid_;
typeidofthetypeid: Typeid_;
expressionlist: initializerlist;
pseudodestructorname:
nestednamespecifier? thetypename '::' '~' thetypename
| nestednamespecifier Template simpletemplateid '::' '~' thetypename
| nestednamespecifier? '~' thetypename
| '~' decltypespecifier;
unaryexpression:
postfixexpression
| '++' castexpression
| '--' castexpression
| unaryoperator castexpression
| Sizeof unaryexpression
| Sizeof '(' thetypeid ')'
| Sizeof '...' '(' Identifier ')'
| Alignof '(' thetypeid ')'
| noexceptexpression
| newexpression
| deleteexpression;
unaryoperator: '|' | '*' | '&' | '+' | '!' | '~' | '-' | 'not';
newexpression:
'::'? New newplacement? newtypeid newinitializer?
| '::'? New newplacement? '(' thetypeid ')' newinitializer?;
newplacement: '(' expressionlist ')';
newtypeid: typespecifierseq newdeclarator?;
newdeclarator: ptroperator newdeclarator? | noptrnewdeclarator | abstractdeclarator;
noptrnewdeclarator:
'[' expression ']' attributespecifierseq?
| noptrnewdeclarator '[' constantexpression ']' attributespecifierseq?;
newinitializer: '(' expressionlist? ')' | bracedinitlist;
deleteexpression:
'::'? Delete castexpression
| '::'? Delete '[' ']' castexpression;
noexceptexpression: Noexcept '(' expression ')';
castexpression:
unaryexpression
| '(' thetypeid ')' castexpression;
pmexpression:
castexpression
| pmexpression '.*' castexpression
| pmexpression '->*' castexpression;
multiplicativeexpression:
pmexpression
| multiplicativeexpression '*' pmexpression
| multiplicativeexpression '/' pmexpression
| multiplicativeexpression '%' pmexpression;
additiveexpression:
multiplicativeexpression
| additiveexpression '+' multiplicativeexpression
| additiveexpression '-' multiplicativeexpression;
shiftexpression:
additiveexpression
| shiftexpression shiftoperator additiveexpression;
shiftoperator: rightShift | LeftShift;
relationalexpression:
shiftexpression
| relationalexpression '<' shiftexpression
| relationalexpression GreaterThan shiftexpression
| relationalexpression '<=' shiftexpression
| relationalexpression '>=' shiftexpression;
equalityexpression:
relationalexpression
| equalityexpression '==' relationalexpression
| equalityexpression '!=' relationalexpression;
andexpression:
equalityexpression
| andexpression '&' equalityexpression;
exclusiveorexpression:
andexpression
| exclusiveorexpression '^' andexpression;
inclusiveorexpression:
exclusiveorexpression
| inclusiveorexpression '|' exclusiveorexpression;
logicalandexpression:
inclusiveorexpression
| logicalandexpression '&&' inclusiveorexpression
| logicalandexpression 'and' inclusiveorexpression;
logicalorexpression:
logicalandexpression
| logicalorexpression '||' logicalandexpression
| logicalorexpression 'or' logicalandexpression;
conditionalexpression:
logicalorexpression
| logicalorexpression '?' expression ':' assignmentexpression;
assignmentexpression:
conditionalexpression
| logicalorexpression assignmentoperator initializerclause
| throwexpression;
assignmentoperator:
'='
| '*='
| '/='
| '%='
| '+='
| '-='
| rightShiftAssign
| LeftShiftAssign
| '&='
| '^='
| '|=';
expression:
assignmentexpression
| expression ',' assignmentexpression;
constantexpression: conditionalexpression;
/*Statements*/
statement:
labeledstatement
| attributespecifierseq? expressionstatement
| attributespecifierseq? compoundstatement
| attributespecifierseq? selectionstatement
| attributespecifierseq? iterationstatement
| attributespecifierseq? jumpstatement
| declarationstatement
| attributespecifierseq? tryblock;
labeledstatement:
attributespecifierseq? Identifier ':' statement
| attributespecifierseq? Case constantexpression ':' statement
| attributespecifierseq? Default ':' statement;
expressionstatement: expression? ';';
compoundstatement: '{' statementseq? '}';
statementseq: statement | statementseq statement;
selectionstatement:
If '(' condition ')' statement
| If '(' condition ')' statement Else statement
| Switch '(' condition ')' statement;
condition:
expression
| attributespecifierseq? declspecifierseq declarator '=' initializerclause
| attributespecifierseq? declspecifierseq declarator bracedinitlist;
iterationstatement:
While '(' condition ')' statement
| Do statement While '(' expression ')' ';'
| For '(' forinitstatement condition? ';' expression? ')' statement
| For '(' forrangedeclaration ':' forrangeinitializer ')' statement;
forinitstatement: expressionstatement | simpledeclaration;
forrangedeclaration:
attributespecifierseq? declspecifierseq declarator;
forrangeinitializer: expression | bracedinitlist;
jumpstatement:
Break ';'
| Continue ';'
| Return expression? ';'
| Return bracedinitlist ';'
| Goto Identifier ';';
declarationstatement: blockdeclaration;
/*Declarations*/
declarationseq: declaration*;
declaration:
blockdeclaration
| functiondefinition
| templatedeclaration
| explicitinstantiation
| explicitspecialization
| linkagespecification
| namespacedefinition
| emptydeclaration
| attributedeclaration
| preprocessorDirective;
preprocessorDirective
: MultiLineMacro
| Directive
;
blockdeclaration:
simpledeclaration
| asmdefinition
| namespacealiasdefinition
| usingdeclaration
| usingdirective
| static_assertdeclaration
| aliasdeclaration
| opaqueenumdeclaration;
aliasdeclaration:
Using Identifier attributespecifierseq? '=' thetypeid ';';
simpledeclaration:
declspecifierseq? initdeclaratorlist? ';'
| attributespecifierseq declspecifierseq? initdeclaratorlist ';';
static_assertdeclaration:
Static_assert '(' constantexpression ',' Stringliteral ')' ';';
emptydeclaration: ';';
attributedeclaration: attributespecifierseq ';';
declspecifier:
storageclassspecifier
| typespecifier
| functionspecifier
| Friend
| Typedef
| Constexpr;
declspecifierseq:
declspecifier attributespecifierseq?
| declspecifier declspecifierseq;
storageclassspecifier:
Register
| Static
| Thread_local
| Extern
| Mutable;
functionspecifier: Inline | Virtual | Explicit;
typedefname: Identifier;
typespecifier:
trailingtypespecifier
| classspecifier
| enumspecifier;
trailingtypespecifier:
simpletypespecifier
| elaboratedtypespecifier
| typenamespecifier
| cvqualifier;
typespecifierseq:
typespecifier attributespecifierseq?
| typespecifier typespecifierseq;
trailingtypespecifierseq:
trailingtypespecifier attributespecifierseq?
| trailingtypespecifier trailingtypespecifierseq;
simpletypespecifier:
nestednamespecifier? thetypename
| nestednamespecifier Template simpletemplateid
| Char
| Char16
| Char32
| Wchar
| Bool
| Short
| Int
| Long
| Signed
| Unsigned
| Float
| Double
| Void
| Auto
| decltypespecifier;
thetypename:
classname
| enumname
| typedefname
| simpletemplateid;
decltypespecifier:
Decltype '(' expression ')'
| Decltype '(' Auto ')';
elaboratedtypespecifier:
classkey attributespecifierseq? nestednamespecifier? Identifier
| classkey simpletemplateid
| classkey nestednamespecifier Template? simpletemplateid
| Enum nestednamespecifier? Identifier;
enumname: Identifier;
enumspecifier:
enumhead '{' enumeratorlist? '}'
| enumhead '{' enumeratorlist ',' '}';
enumhead:
enumkey attributespecifierseq? Identifier? enumbase?
| enumkey attributespecifierseq? nestednamespecifier Identifier enumbase?;
opaqueenumdeclaration:
enumkey attributespecifierseq? Identifier enumbase? ';';
enumkey: Enum | Enum Class | Enum Struct;
enumbase: ':' typespecifierseq;
enumeratorlist:
enumeratordefinition
| enumeratorlist ',' enumeratordefinition;
enumeratordefinition:
enumerator
| enumerator '=' constantexpression;
enumerator: Identifier;
namespacename: originalnamespacename | namespacealias;
originalnamespacename: Identifier;
namespacedefinition:
namednamespacedefinition
| unnamednamespacedefinition;
namednamespacedefinition:
originalnamespacedefinition
| extensionnamespacedefinition;
originalnamespacedefinition:
Inline? Namespace Identifier '{' namespacebody '}';
extensionnamespacedefinition:
Inline? Namespace originalnamespacename '{' namespacebody '}';
unnamednamespacedefinition:
Inline? Namespace '{' namespacebody '}';
namespacebody: declarationseq?;
namespacealias: Identifier;
namespacealiasdefinition:
Namespace Identifier '=' qualifiednamespacespecifier ';';
qualifiednamespacespecifier: nestednamespecifier? namespacename;
usingdeclaration:
Using Typename_? nestednamespecifier unqualifiedid ';'
| Using '::' unqualifiedid ';';
usingdirective:
attributespecifierseq? Using Namespace nestednamespecifier? namespacename ';';
asmdefinition: Asm '(' Stringliteral ')' ';';
linkagespecification:
Extern Stringliteral '{' declarationseq? '}'
| Extern Stringliteral declaration;
attributespecifierseq:
attributespecifier
| attributespecifierseq attributespecifier;
attributespecifier:
'[' '[' attributelist ']' ']'
| alignmentspecifier;
alignmentspecifier:
Alignas '(' thetypeid '...'? ')'
| Alignas '(' constantexpression '...'? ')';
attributelist:
attribute?
| attributelist ',' attribute?
| attribute '...'
| attributelist ',' attribute '...';
attribute: attributetoken attributeargumentclause?;
attributetoken: Identifier | attributescopedtoken;
attributescopedtoken: attributenamespace '::' Identifier;
attributenamespace: Identifier;
attributeargumentclause: '(' balancedtokenseq ')';
balancedtokenseq:
balancedtoken?
| balancedtokenseq balancedtoken;
balancedtoken:
'(' balancedtokenseq ')'
| '[' balancedtokenseq ']'
| '{' balancedtokenseq '}'
| ~('(' | ')' | '{' | '}' | '[' | ']')+;
/*Declarators*/
initdeclaratorlist:
initdeclarator
| initdeclaratorlist ',' initdeclarator;
initdeclarator: declarator initializer?;
declarator:
ptrdeclarator
| noptrdeclarator parametersandqualifiers trailingreturntype;
ptrdeclarator: noptrdeclarator | ptroperator ptrdeclarator;
noptrdeclarator:
declaratorid attributespecifierseq?
| noptrdeclarator parametersandqualifiers
| noptrdeclarator '[' constantexpression? ']' attributespecifierseq?
| '(' ptrdeclarator ')';
parametersandqualifiers:
'(' parameterdeclarationclause ')' cvqualifierseq? refqualifier? exceptionspecification?
attributespecifierseq?;
trailingreturntype:
'->' trailingtypespecifierseq abstractdeclarator?;
ptroperator:
'*' attributespecifierseq? cvqualifierseq?
| '&' attributespecifierseq?
| '&&' attributespecifierseq?
| nestednamespecifier '*' attributespecifierseq? cvqualifierseq?;
cvqualifierseq: cvqualifier cvqualifierseq?;
cvqualifier: Const | Volatile;
refqualifier: '&' | '&&';
declaratorid: '...'? idexpression;
thetypeid: typespecifierseq abstractdeclarator?;
abstractdeclarator:
ptrabstractdeclarator
| noptrabstractdeclarator? parametersandqualifiers trailingreturntype
| abstractpackdeclarator;
ptrabstractdeclarator:
noptrabstractdeclarator
| ptroperator ptrabstractdeclarator?;
noptrabstractdeclarator:
noptrabstractdeclarator parametersandqualifiers
| parametersandqualifiers
| noptrabstractdeclarator '[' constantexpression? ']' attributespecifierseq?
| '[' constantexpression? ']' attributespecifierseq?
| '(' ptrabstractdeclarator ')';
abstractpackdeclarator:
noptrabstractpackdeclarator
| ptroperator abstractpackdeclarator;
noptrabstractpackdeclarator:
noptrabstractpackdeclarator parametersandqualifiers
| noptrabstractpackdeclarator '[' constantexpression? ']' attributespecifierseq?
| '...';
parameterdeclarationclause:
parameterdeclarationlist? '...'?
| parameterdeclarationlist ',' '...';
parameterdeclarationlist:
parameterdeclaration
| parameterdeclarationlist ',' parameterdeclaration;
parameterdeclaration:
attributespecifierseq? declspecifierseq declarator unqualifiedid?
| attributespecifierseq? declspecifierseq declarator unqualifiedid? '=' initializerclause
| attributespecifierseq? declspecifierseq abstractdeclarator? unqualifiedid?
| attributespecifierseq? declspecifierseq abstractdeclarator? unqualifiedid? '=' initializerclause;
functiondefinition:
attributespecifierseq? declspecifierseq? declarator virtspecifierseq? functionbody;
functionbody:
ctorinitializer? compoundstatement
| functiontryblock
| '=' Default ';'
| '=' Delete ';';
initializer: braceorequalinitializer | '(' expressionlist ')';
braceorequalinitializer: '=' initializerclause | bracedinitlist;
initializerclause: assignmentexpression | bracedinitlist;
initializerlist:
initializerclause '...'?
| initializerlist ',' initializerclause '...'?;
bracedinitlist: '{' initializerlist ','? '}' | '{' '}';
/*Classes*/
classname: Identifier | simpletemplateid;
classspecifier: classhead '{' memberspecification? '}';
classhead:
classkey attributespecifierseq? classheadname classvirtspecifier? baseclause?
| classkey attributespecifierseq? baseclause?;
classheadname: nestednamespecifier? classname;
classvirtspecifier: Final;
classkey: Class | Struct | Union;
memberspecification:
memberdeclaration memberspecification?
| accessspecifier ':' memberspecification?;
memberdeclaration:
attributespecifierseq? declspecifierseq? memberdeclaratorlist? ';'
| functiondefinition
| usingdeclaration
| static_assertdeclaration
| templatedeclaration
| aliasdeclaration
| emptydeclaration;
memberdeclaratorlist:
memberdeclarator
| memberdeclaratorlist ',' memberdeclarator;
memberdeclarator:
declarator virtspecifierseq? purespecifier?
| declarator braceorequalinitializer?
| Identifier? attributespecifierseq? ':' constantexpression;
virtspecifierseq:
virtspecifier
| virtspecifierseq virtspecifier;
virtspecifier: Override | Final;
/*
purespecifier:
'=' '0'//Conflicts with the lexer
;
*/
purespecifier:
Assign val = Octalliteral;
/*Derived classes*/
baseclause: ':' basespecifierlist;
basespecifierlist:
basespecifier '...'?
| basespecifierlist ',' basespecifier '...'?;
basespecifier:
attributespecifierseq? basetypespecifier
| attributespecifierseq? Virtual accessspecifier? basetypespecifier
| attributespecifierseq? accessspecifier Virtual? basetypespecifier;
classordecltype:
nestednamespecifier? classname
| decltypespecifier;
basetypespecifier: classordecltype;
accessspecifier: Private | Protected | Public;
/*Special member functions*/
conversionfunctionid: Operator conversiontypeid;
conversiontypeid: typespecifierseq conversiondeclarator?;
conversiondeclarator: ptroperator conversiondeclarator?;
ctorinitializer: ':' meminitializerlist;
meminitializerlist:
meminitializer '...'?
| meminitializer '...'? ',' meminitializerlist;
meminitializer:
meminitializerid '(' expressionlist? ')'
| meminitializerid bracedinitlist;
meminitializerid: classordecltype | Identifier;
/*Overloading*/
operatorfunctionid: Operator theoperator;
literaloperatorid:
Operator Stringliteral Identifier
| Operator Userdefinedstringliteral;
/*Templates*/
templatedeclaration:
Template '<' templateparameterlist GreaterThan declaration;
templateparameterlist:
templateparameter
| templateparameterlist ',' templateparameter;
templateparameter: typeparameter | parameterdeclaration;
typeparameter:
Class '...'? Identifier?
| Class Identifier? '=' thetypeid
| Typename_ '...'? Identifier?
| Typename_ Identifier? '=' thetypeid
| Template '<' templateparameterlist GreaterThan Class '...'? Identifier?
| Template '<' templateparameterlist GreaterThan Class Identifier? '=' idexpression;
simpletemplateid: templatename '<' templateargumentlist? GreaterThan;
templateid:
simpletemplateid
| operatorfunctionid '<' templateargumentlist? GreaterThan
| literaloperatorid '<' templateargumentlist? GreaterThan;
templatename: Identifier;
templateargumentlist:
templateargument '...'?
| templateargumentlist ',' templateargument '...'?;
templateargument: simpletemplateid | thetypeid | constantexpression | idexpression;
typenamespecifier:
Typename_ nestednamespecifier Identifier
| Typename_ nestednamespecifier Template? simpletemplateid;
explicitinstantiation: Extern? Template declaration;
explicitspecialization: Template '<' GreaterThan declaration;
/*Exception handling*/
tryblock: Try compoundstatement handlerseq;
functiontryblock:
Try ctorinitializer? compoundstatement handlerseq;
handlerseq: handler handlerseq?;
handler: Catch '(' exceptiondeclaration ')' compoundstatement;
exceptiondeclaration:
attributespecifierseq? typespecifierseq declarator
| attributespecifierseq? typespecifierseq abstractdeclarator?
| '...';
throwexpression: Throw assignmentexpression?;
exceptionspecification:
dynamicexceptionspecification
| noexceptspecification;
dynamicexceptionspecification: Throw '(' typeidlist? ')';
typeidlist: thetypeid '...'? | typeidlist ',' thetypeid '...'?;
noexceptspecification:
Noexcept '(' constantexpression ')'
| Noexcept;
/*Preprocessing directives*/
MultiLineMacro:
'#' (~ [\n]*? '\\' '\r'? '\n')+ ~ [\n]+ -> channel (HIDDEN);
Directive: '#' ~ [\n]* -> channel (HIDDEN);
/*Lexer*/
/*Keywords*/
Alignas: 'alignas';
Alignof: 'alignof';
Asm: 'asm';
Auto: 'auto';
Bool: 'bool';
Break: 'break';
Case: 'case';
Catch: 'catch';
Char: 'char';
Char16: 'char16_t';
Char32: 'char32_t';
Class: 'class';
Const: 'const';
Constexpr: 'constexpr';
Const_cast: 'const_cast';
Continue: 'continue';
Decltype: 'decltype';
Default: 'default';
Delete: 'delete';
Do: 'do';
Double: 'double';
Dynamic_cast: 'dynamic_cast';
Else: 'else';
Enum: 'enum';
Explicit: 'explicit';
Export: 'export';
Extern: 'extern';
False: 'false';
Final: 'final';
Float: 'float';
For: 'for';
Friend: 'friend';
Goto: 'goto';
If: 'if';
Inline: 'inline';
Int: 'int';
Long: 'long';
Mutable: 'mutable';
Namespace: 'namespace';
New: 'new';
Noexcept: 'noexcept';
Nullptr: 'nullptr';
Operator: 'operator';
Override: 'override';
Private: 'private';
Protected: 'protected';
Public: 'public';
Register: 'register';
Reinterpret_cast: 'reinterpret_cast';
Return: 'return';
Short: 'short';
Signed: 'signed';
Sizeof: 'sizeof';
Static: 'static';
Static_assert: 'static_assert';
Static_cast: 'static_cast';
Struct: 'struct';
Switch: 'switch';
Template: 'template';
This: 'this';
Thread_local: 'thread_local';
Throw: 'throw';
True: 'true';
Try: 'try';
Typedef: 'typedef';
Typeid_: 'typeid';
Typename_: 'typename';
Union: 'union';
Unsigned: 'unsigned';
Using: 'using';
Virtual: 'virtual';
Void: 'void';
Volatile: 'volatile';
Wchar: 'wchar_t';
While: 'while';
/*Operators*/
LeftParen: '(';
RightParen: ')';
LeftBracket: '[';
RightBracket: ']';
LeftBrace: '{';
RightBrace: '}';
Plus: '+';
Minus: '-';
Star: '*';
Div: '/';
Mod: '%';
Caret: '^';
And: '&';
Or: '|';
Tilde: '~';
Not: '!' | 'not';
Assign: '=';
Less: '<';
PlusAssign: '+=';
MinusAssign: '-=';
StarAssign: '*=';
DivAssign: '/=';
ModAssign: '%=';
XorAssign: '^=';
AndAssign: '&=';
OrAssign: '|=';
LeftShift: '<<';
rightShift: GreaterThan GreaterThan;
LeftShiftAssign: '<<=';
rightShiftAssign: GreaterThan GreaterThan '=';
Equal: '==';
NotEqual: '!=';
LessEqual: '<=';
GreaterEqual: '>=';
AndAnd: '&&' | 'and';
OrOr: '||' | 'or';
PlusPlus: '++';
MinusMinus: '--';
Comma: ',';
ArrowStar: '->*';
Arrow: '->';
Question: '?';
Colon: ':';
Doublecolon: '::';
Semi: ';';
Dot: '.';
DotStar: '.*';
Ellipsis: '...';
theoperator:
New
| Delete
| New '[' ']'
| Delete '[' ']'
| '+'
| '-'
| '*'
| '/'
| '%'
| '^'
| '&'
| '|'
| '~'
| '!'
| 'not'
| '='
| '<'
| GreaterThan
| '+='
| '-='
| '*='
| '/='
| '%='
| '^='
| '&='
| '|='
| LeftShift
| rightShift
| rightShiftAssign
| LeftShiftAssign
| '=='
| '!='
| '<='
| '>='
| '&&'
| 'and'
| '||'
| 'or'
| '++'
| '--'
| ','
| '->*'
| '->'
| '(' ')'
| '[' ']';
/*Lexer*/
fragment Hexquad:
HEXADECIMALDIGIT HEXADECIMALDIGIT HEXADECIMALDIGIT HEXADECIMALDIGIT;
fragment Universalcharactername:
'\\u' Hexquad
| '\\U' Hexquad Hexquad;
Identifier:
/*
Identifiernondigit
| Identifier Identifiernondigit
| Identifier DIGIT
*/
Identifiernondigit (Identifiernondigit | DIGIT)*;
fragment Identifiernondigit: NONDIGIT | Universalcharactername;
fragment NONDIGIT: [a-zA-Z_];
fragment DIGIT: [0-9];
literal:
Integerliteral
| Characterliteral
| Floatingliteral
| Stringliteral
| booleanliteral
| pointerliteral
| userdefinedliteral;
Integerliteral:
Decimalliteral Integersuffix?
| Octalliteral Integersuffix?
| Hexadecimalliteral Integersuffix?
| Binaryliteral Integersuffix?;
Decimalliteral: NONZERODIGIT ('\''? DIGIT)*;
Octalliteral: '0' ('\''? OCTALDIGIT)*;
Hexadecimalliteral: ('0x' | '0X') HEXADECIMALDIGIT (
'\''? HEXADECIMALDIGIT
)*;
Binaryliteral: ('0b' | '0B') BINARYDIGIT ('\''? BINARYDIGIT)*;
fragment NONZERODIGIT: [1-9];
fragment OCTALDIGIT: [0-7];
fragment HEXADECIMALDIGIT: [0-9a-fA-F];
fragment BINARYDIGIT: [01];
Integersuffix:
Unsignedsuffix Longsuffix?
| Unsignedsuffix Longlongsuffix?
| Longsuffix Unsignedsuffix?
| Longlongsuffix Unsignedsuffix?;
fragment Unsignedsuffix: [uU];
fragment Longsuffix: [lL];
fragment Longlongsuffix: 'll' | 'LL';
Characterliteral:
'\'' Cchar+ '\''
| 'u' '\'' Cchar+ '\''
| 'U' '\'' Cchar+ '\''
| 'L' '\'' Cchar+ '\'';
fragment Cchar:
~ ['\\\r\n]
| Escapesequence
| Universalcharactername;
fragment Escapesequence:
Simpleescapesequence
| Octalescapesequence
| Hexadecimalescapesequence;
fragment Simpleescapesequence:
'\\\''
| '\\"'
| '\\?'
| '\\\\'
| '\\a'
| '\\b'
| '\\f'
| '\\n'
| '\\r'
| '\\t'
| '\\v';
fragment Octalescapesequence:
'\\' OCTALDIGIT
| '\\' OCTALDIGIT OCTALDIGIT
| '\\' OCTALDIGIT OCTALDIGIT OCTALDIGIT;
fragment Hexadecimalescapesequence: '\\x' HEXADECIMALDIGIT+;
Floatingliteral:
Fractionalconstant Exponentpart? Floatingsuffix?
| Digitsequence Exponentpart Floatingsuffix?;
fragment Fractionalconstant:
Digitsequence? '.' Digitsequence
| Digitsequence '.';
fragment Exponentpart:
'e' SIGN? Digitsequence
| 'E' SIGN? Digitsequence;
fragment SIGN: [+-];
fragment Digitsequence: DIGIT ('\''? DIGIT)*;
fragment Floatingsuffix: [flFL];
Stringliteral:
Encodingprefix? '"' Schar* '"'
| Encodingprefix? 'R' Rawstring;
fragment Encodingprefix: 'u8' | 'u' | 'U' | 'L';
fragment Schar:
~ ["\\\r\n]
| Escapesequence
| Universalcharactername;
fragment Rawstring: '"' .*? '(' .*? ')' .*? '"';
booleanliteral: False | True;
pointerliteral: Nullptr;
userdefinedliteral:
Userdefinedintegerliteral
| Userdefinedfloatingliteral
| Userdefinedstringliteral
| Userdefinedcharacterliteral;
Userdefinedintegerliteral:
Decimalliteral Udsuffix
| Octalliteral Udsuffix
| Hexadecimalliteral Udsuffix
| Binaryliteral Udsuffix;
Userdefinedfloatingliteral:
Fractionalconstant Exponentpart? Udsuffix
| Digitsequence Exponentpart Udsuffix;
Userdefinedstringliteral: Stringliteral Udsuffix;
Userdefinedcharacterliteral: Characterliteral Udsuffix;
fragment Udsuffix: Identifier;
Whitespace: [ \t]+ -> skip;
Newline: ('\r' '\n'? | '\n') -> skip;
BlockComment: '/*' .*? '*/' -> skip;
LineComment: '//' ~ [\r\n]* -> skip;
GreaterThan: '>'; |
alloy4fun_models/trashltl/models/17/5GCGTKDEG9PFN9izc.als | Kaixi26/org.alloytools.alloy | 0 | 728 | <reponame>Kaixi26/org.alloytools.alloy
open main
pred id5GCGTKDEG9PFN9izc_prop18 {
always all f: Protected | f in Trash triggered f not in Protected
}
pred __repair { id5GCGTKDEG9PFN9izc_prop18 }
check __repair { id5GCGTKDEG9PFN9izc_prop18 <=> prop18o } |
programs/oeis/083/A083686.asm | neoneye/loda | 22 | 247175 | <filename>programs/oeis/083/A083686.asm<gh_stars>10-100
; A083686: a(0) = 8; for n>0, a(n) = 2*a(n-1) - 1.
; 8,15,29,57,113,225,449,897,1793,3585,7169,14337,28673,57345,114689,229377,458753,917505,1835009,3670017,7340033,14680065,29360129,58720257,117440513,234881025,469762049,939524097,1879048193,3758096385,7516192769,15032385537,30064771073,60129542145,120259084289,240518168577,481036337153,962072674305,1924145348609,3848290697217,7696581394433,15393162788865,30786325577729,61572651155457,123145302310913,246290604621825,492581209243649,985162418487297,1970324836974593,3940649673949185,7881299347898369,15762598695796737,31525197391593473,63050394783186945,126100789566373889,252201579132747777,504403158265495553,1008806316530991105,2017612633061982209,4035225266123964417,8070450532247928833,16140901064495857665,32281802128991715329,64563604257983430657,129127208515966861313,258254417031933722625,516508834063867445249,1033017668127734890497,2066035336255469780993,4132070672510939561985,8264141345021879123969,16528282690043758247937,33056565380087516495873,66113130760175032991745,132226261520350065983489,264452523040700131966977,528905046081400263933953,1057810092162800527867905,2115620184325601055735809,4231240368651202111471617,8462480737302404222943233,16924961474604808445886465,33849922949209616891772929,67699845898419233783545857,135399691796838467567091713,270799383593676935134183425,541598767187353870268366849,1083197534374707740536733697,2166395068749415481073467393,4332790137498830962146934785,8665580274997661924293869569,17331160549995323848587739137,34662321099990647697175478273,69324642199981295394350956545,138649284399962590788701913089,277298568799925181577403826177,554597137599850363154807652353,1109194275199700726309615304705,2218388550399401452619230609409,4436777100798802905238461218817
mov $1,2
pow $1,$0
mul $1,7
add $1,1
mov $0,$1
|
stm32f1/stm32gd-timeout.adb | ekoeppen/STM32_Generic_Ada_Drivers | 1 | 29382 | <reponame>ekoeppen/STM32_Generic_Ada_Drivers<gh_stars>1-10
with STM32GD.RTC;
package body STM32GD.Timeout is
Microseconds_Timeout : Microseconds;
Milliseconds_Timeout : Milliseconds;
Seconds_Timeout : Seconds;
procedure Set (T : Microseconds) is
begin
null;
end Set;
procedure Set (T : Milliseconds) is
begin
null;
end Set;
procedure Set (T : Seconds) is
package RTC is new STM32GD.RTC (Clock => Clock_Tree.RTC_Source, Clock_Tree => Clock_Tree);
Alarm : RTC.Date_Time_Type;
begin
RTC.Read (Alarm);
RTC.Add_Seconds (Alarm, RTC.Second_Delta_Type (T));
RTC.Set_Alarm (Alarm);
end Set;
procedure Await is
begin
while not Expired loop null; end loop;
end Await;
function Expired return Boolean is
begin
return False;
end Expired;
end STM32GD.Timeout;
|
extra/extra/Even.agda | manikdv/plfa.github.io | 1,003 | 16822 | <reponame>manikdv/plfa.github.io
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; trans; cong; cong-app)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Data.Product using (∃; _,_)
+-assoc : ∀ (m n p : ℕ) → m + (n + p) ≡ (m + n) + p
+-assoc zero n p =
begin
zero + (n + p)
≡⟨⟩
n + p
≡⟨⟩
(zero + n) + p
∎
+-assoc (suc m) n p =
begin
suc m + (n + p)
≡⟨⟩
suc (m + (n + p))
≡⟨ cong suc (+-assoc m n p) ⟩
suc ((m + n) + p)
≡⟨⟩
(suc m + n) + p
∎
+-identity : ∀ (m : ℕ) → m + zero ≡ m
+-identity zero =
begin
zero + zero
≡⟨⟩
zero
∎
+-identity (suc m) =
begin
suc m + zero
≡⟨⟩
suc (m + zero)
≡⟨ cong suc (+-identity m) ⟩
suc m
∎
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc zero n =
begin
zero + suc n
≡⟨⟩
suc n
≡⟨⟩
suc (zero + n)
∎
+-suc (suc m) n =
begin
suc m + suc n
≡⟨⟩
suc (m + suc n)
≡⟨ cong suc (+-suc m n) ⟩
suc (suc (m + n))
≡⟨⟩
suc (suc m + n)
∎
+-comm : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm m zero =
begin
m + zero
≡⟨ +-identity m ⟩
m
≡⟨⟩
zero + m
∎
+-comm m (suc n) =
begin
m + suc n
≡⟨ +-suc m n ⟩
suc (m + n)
≡⟨ cong suc (+-comm m n) ⟩
suc (n + m)
≡⟨⟩
suc n + m
∎
*-distrib-+ : ∀ (m n p : ℕ) → (m + n) * p ≡ m * p + n * p
*-distrib-+ zero n p =
begin
(zero + n) * p
≡⟨⟩
n * p
≡⟨⟩
zero * p + n * p
∎
*-distrib-+ (suc m) n p =
begin
(suc m + n) * p
≡⟨⟩
p + (m + n) * p
≡⟨ cong (_+_ p) (*-distrib-+ m n p) ⟩
p + (m * p + n * p)
≡⟨ +-assoc p (m * p) (n * p) ⟩
(p + m * p) + n * p
≡⟨⟩
suc m * p + n * p
∎
data even : ℕ → Set where
ev0 : even zero
ev+2 : ∀ {n : ℕ} → even n → even (suc (suc n))
lemma : ∀ (m : ℕ) → 2 * suc m ≡ suc (suc (2 * m))
lemma m =
begin
2 * suc m
≡⟨⟩
suc m + (suc m + zero)
≡⟨⟩
suc (m + (suc (m + zero)))
≡⟨ cong suc (+-suc m (m + zero)) ⟩
suc (suc (m + (m + zero)))
≡⟨⟩
suc (suc (2 * m))
∎
ev-ex : ∀ {n : ℕ} → even n → ∃(λ (m : ℕ) → 2 * m ≡ n)
ev-ex ev0 = (0 , refl)
ev-ex (ev+2 ev) with ev-ex ev
... | (m , refl) = (suc m , lemma m)
ex-ev : ∀ {n : ℕ} → ∃(λ (m : ℕ) → 2 * m ≡ n) → even n
ex-ev (zero , refl) = ev0
ex-ev (suc m , refl) rewrite lemma m = ev+2 (ex-ev (m , refl))
-- I can't see how to avoid using rewrite in the second proof,
-- or how to use rewrite in the first proof!
|
source/a-excide.ads | ytomino/drake | 33 | 28208 | <filename>source/a-excide.ads
pragma License (Unrestricted);
-- extended unit
private with System.Unwind;
package Ada.Exception_Identification is
-- "Pure" version of Ada.Exceptions.
pragma Pure;
type Exception_Id is private;
pragma Preelaborable_Initialization (Exception_Id);
Null_Id : constant Exception_Id;
function Exception_Name (Id : Exception_Id) return String;
procedure Raise_Exception (E : Exception_Id; Message : String := "")
with Import,
Convention => Ada,
External_Name => "ada__exceptions__raise_exception";
pragma No_Return (Raise_Exception);
-- These functions raise a new occurrence of the identified exception
-- with source location.
procedure Raise_Exception_From_Here (
E : Exception_Id;
File : String := Debug.File;
Line : Integer := Debug.Line)
with Import,
Convention => Ada,
External_Name => "__drake_raise_exception_from_here";
procedure Raise_Exception_From_Here (
E : Exception_Id;
File : String := Debug.File;
Line : Integer := Debug.Line;
Message : String)
with Import,
Convention => Ada,
External_Name => "__drake_raise_exception_from_here_with";
pragma No_Return (Raise_Exception_From_Here);
private
type Exception_Id is new System.Unwind.Exception_Data_Access;
Null_Id : constant Exception_Id := null;
end Ada.Exception_Identification;
|
libsrc/_DEVELOPMENT/adt/p_forward_list/z80/asm_p_forward_list_size.asm | jpoikela/z88dk | 640 | 174887 |
; ===============================================================
; Dec 2013
; ===============================================================
;
; size_t p_forward_list_size(p_forward_list_t *list)
;
; Return number of items in list. O(n).
;
; ===============================================================
SECTION code_clib
SECTION code_adt_p_forward_list
PUBLIC asm_p_forward_list_size
asm_p_forward_list_size:
; enter : hl = p_forward_list_t *list
;
; exit : hl = number of items in list
;
; uses : af, de, hl
ld de,$ffff
loop:
inc de
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
or h
jr nz, loop
ex de,hl
ret
|
Categories/Object/Terminal/Exponentiating.agda | copumpkin/categories | 98 | 6099 | {-# OPTIONS --universe-polymorphism #-}
open import Categories.Category
open import Categories.Object.Products
open import Categories.Object.Terminal
open import Level
module Categories.Object.Terminal.Exponentiating {o ℓ e : Level}
(C : Category o ℓ e)
(P : Products C) where
open Category C
open Products P
open Terminal terminal
open import Categories.Object.Exponentiating
import Categories.Object.Terminal.Exponentials
open Categories.Object.Terminal.Exponentials C terminal
⊤-exponentiating : Exponentiating C binary ⊤
⊤-exponentiating = record
{ exponential = λ {X : Obj} → [⊤↑ X ]-exponential
}
|
tools-src/gnu/gcc/gcc/ada/4vintnam.ads | enfoTek/tomato.linksys.e2000.nvram-mod | 80 | 13785 | ------------------------------------------------------------------------------
-- --
-- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- A D A . I N T E R R U P T S . N A M E S --
-- --
-- S p e c --
-- --
-- $Revision$
-- --
-- Copyright (C) 1991-2000 Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNARL; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This is a OpenVMS/Alpha version of this package.
--
-- This target-dependent package spec contains names of interrupts
-- supported by the local system.
with System.OS_Interface;
package Ada.Interrupts.Names is
package OS renames System.OS_Interface;
Interrupt_ID_0 : constant Interrupt_ID := OS.Interrupt_ID_0;
Interrupt_ID_1 : constant Interrupt_ID := OS.Interrupt_ID_1;
Interrupt_ID_2 : constant Interrupt_ID := OS.Interrupt_ID_2;
Interrupt_ID_3 : constant Interrupt_ID := OS.Interrupt_ID_3;
Interrupt_ID_4 : constant Interrupt_ID := OS.Interrupt_ID_4;
Interrupt_ID_5 : constant Interrupt_ID := OS.Interrupt_ID_5;
Interrupt_ID_6 : constant Interrupt_ID := OS.Interrupt_ID_6;
Interrupt_ID_7 : constant Interrupt_ID := OS.Interrupt_ID_7;
Interrupt_ID_8 : constant Interrupt_ID := OS.Interrupt_ID_8;
Interrupt_ID_9 : constant Interrupt_ID := OS.Interrupt_ID_9;
Interrupt_ID_10 : constant Interrupt_ID := OS.Interrupt_ID_10;
Interrupt_ID_11 : constant Interrupt_ID := OS.Interrupt_ID_11;
Interrupt_ID_12 : constant Interrupt_ID := OS.Interrupt_ID_12;
Interrupt_ID_13 : constant Interrupt_ID := OS.Interrupt_ID_13;
Interrupt_ID_14 : constant Interrupt_ID := OS.Interrupt_ID_14;
Interrupt_ID_15 : constant Interrupt_ID := OS.Interrupt_ID_15;
Interrupt_ID_16 : constant Interrupt_ID := OS.Interrupt_ID_16;
Interrupt_ID_17 : constant Interrupt_ID := OS.Interrupt_ID_17;
Interrupt_ID_18 : constant Interrupt_ID := OS.Interrupt_ID_18;
Interrupt_ID_19 : constant Interrupt_ID := OS.Interrupt_ID_19;
Interrupt_ID_20 : constant Interrupt_ID := OS.Interrupt_ID_20;
Interrupt_ID_21 : constant Interrupt_ID := OS.Interrupt_ID_21;
Interrupt_ID_22 : constant Interrupt_ID := OS.Interrupt_ID_22;
Interrupt_ID_23 : constant Interrupt_ID := OS.Interrupt_ID_23;
Interrupt_ID_24 : constant Interrupt_ID := OS.Interrupt_ID_24;
Interrupt_ID_25 : constant Interrupt_ID := OS.Interrupt_ID_25;
Interrupt_ID_26 : constant Interrupt_ID := OS.Interrupt_ID_26;
Interrupt_ID_27 : constant Interrupt_ID := OS.Interrupt_ID_27;
Interrupt_ID_28 : constant Interrupt_ID := OS.Interrupt_ID_28;
Interrupt_ID_29 : constant Interrupt_ID := OS.Interrupt_ID_29;
Interrupt_ID_30 : constant Interrupt_ID := OS.Interrupt_ID_30;
Interrupt_ID_31 : constant Interrupt_ID := OS.Interrupt_ID_31;
end Ada.Interrupts.Names;
|
source/web/servlet/websocket/web_socket-listeners.ads | svn2github/matreshka | 24 | 22331 | <reponame>svn2github/matreshka<gh_stars>10-100
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2015, <NAME> <<EMAIL>> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Streams;
with League.Strings;
package Web_Socket.Listeners is
pragma Preelaborate;
type Status_Code is
(Normal_Closure, -- 1000
Going_Away, -- 1001
Protocol_Error, -- 1002
Unsupported_Data, -- 1003
No_Status_Received, -- 1005
Abnormal_Closure, -- 1006
Invalid_Frame_Payload_Data, -- 1007
Policy_Violation, -- 1008
Message_Too_Big, -- 1009
Mandatory_Extension, -- 1010
Internal_Server_Error, -- 1011
TLS_Handshake); -- 1012
type Web_Socket_Listener is limited interface;
type Web_Socket_Listener_Access is access all Web_Socket_Listener'Class;
not overriding procedure On_Binary
(Self : in out Web_Socket_Listener;
Data : Ada.Streams.Stream_Element_Array) is abstract;
-- A WebSocket binary frame has been received.
not overriding procedure On_Close
(Self : in out Web_Socket_Listener;
Status : Status_Code;
Reason : League.Strings.Universal_String) is abstract;
-- A Close Event was received.
--
-- The underlying Connection will be considered closed at this point.
not overriding procedure On_Connect
(Self : in out Web_Socket_Listener) is abstract;
-- A WebSocket Session has connected successfully and is ready to be used.
not overriding procedure On_Error
(Self : in out Web_Socket_Listener) is abstract;
-- A WebSocket exception has occurred.
--
-- This is a way for the internal implementation to notify of exceptions
-- occured during the processing of websocket.
--
-- Usually this occurs from bad / malformed incoming packets. (example: bad
-- UTF8 data, frames that are too big, violations of the spec)
--
-- This will result in the Session being closed by the implementing side.
not overriding procedure On_Text
(Self : in out Web_Socket_Listener;
Text : League.Strings.Universal_String) is abstract;
-- A WebSocket Text frame was received.
end Web_Socket.Listeners;
|
test/Fail/Issue308b.agda | cruhland/agda | 1,989 | 9754 | <filename>test/Fail/Issue308b.agda
module Issue308b where
data D : Set where
d : D → D
syntax d x = e x x
g : D → D
g (d x) = e x
|
agda/Cardinality/Finite/ManifestEnumerable/Isomorphism.agda | oisdk/combinatorics-paper | 0 | 14864 | <reponame>oisdk/combinatorics-paper
{-# OPTIONS --cubical --safe #-}
module Cardinality.Finite.ManifestEnumerable.Isomorphism where
open import Prelude
import Cardinality.Finite.ManifestEnumerable.Container as ℒ
import Cardinality.Finite.ManifestEnumerable.Inductive as 𝕃
open import Container.List.Isomorphism
open import Data.Fin
open import HITs.PropositionalTruncation.Sugar
open import Data.List using (_∷_; [])
open import HITs.PropositionalTruncation
open import Cardinality.Finite.SplitEnumerable.Isomorphism
open import Data.Sigma.Properties
𝕃⇔ℒ⟨ℰ⟩ : 𝕃.ℰ A ⇔ ℒ.ℰ A
𝕃⇔ℒ⟨ℰ⟩ .fun (sup , cov) = 𝕃→ℒ sup , cov
𝕃⇔ℒ⟨ℰ⟩ .inv (sup , cov) = ℒ→𝕃 sup , λ x → ∈ℒ⇒∈𝕃 x sup ∥$∥ cov x
𝕃⇔ℒ⟨ℰ⟩ .rightInv (sup , cov) = ΣProp≡ (λ xs x y i t → squash (x t) (y t) i) (𝕃⇔ℒ .rightInv sup)
𝕃⇔ℒ⟨ℰ⟩ .leftInv (sup , cov) = ΣProp≡ (λ xs x y i t → squash (x t) (y t) i) (𝕃⇔ℒ .leftInv sup)
|
src/utils.asm | ISSOtm/smooth-player-demo | 4 | 2738 | <reponame>ISSOtm/smooth-player-demo
INCLUDE "src/include/hardware.inc/hardware.inc"
SECTION "Memset", ROM0[$08] ; So that it lands on a `rst`
Memset::
inc b
inc c
dec bc
.loop
ld [hli], a
dec c
jr nz, .loop
dec b
jr nz, .loop
ret
; And here is how you include the sample routines
SECTION "Sample routines", ROM0
INCLUDE "src/smooth-player/sample_lib.asm"
|
src/tests/histogramdescriptortests.adb | sebsgit/textproc | 0 | 10452 | with AUnit.Assertions; use AUnit.Assertions;
with Interfaces.C.Strings;
with Ada.Text_IO;
with Ada.Containers; use Ada.Containers;
with ImageIO;
with PixelArray;
with ImageRegions;
with Histogram;
with HistogramDescriptor;
with ShapeDatabase;
use PixelArray;
use ImageRegions;
use HistogramDescriptor;
package body HistogramDescriptorTests is
procedure Register_Tests (T: in out TestCase) is
use AUnit.Test_Cases.Registration;
begin
Register_Routine (T, testBasicDescriptor'Access, "basic descriptor");
Register_Routine (T, testDivergence'Access, "divergence");
end Register_Tests;
function Name(T: TestCase) return Test_String is
begin
return Format("Histogram Descriptor Tests");
end Name;
function loadImage(path: String) return Data is
regions: ImageRegions.RegionVector.Vector;
image: constant PixelArray.ImagePlane := ShapeDatabase.Preprocess_And_Detect_Regions(ImageIO.load("2.jpg"), regions);
begin
Assert(regions.Length = 1, "1 region");
return HistogramDescriptor.create(image, regions.Element(0).area);
end loadImage;
procedure testBasicDescriptor(T : in out Test_Cases.Test_Case'Class) is
d0, d1: Data;
distance: Float;
begin
d0 := loadImage("1.jpg");
d1 := loadImage("1_1.jpg");
distance := Histogram.compare(d0.horizontal, d1.horizontal, Histogram.Bhattacharyya);
Assert(distance < 0.01, "distance horizontal");
distance := Histogram.compare(d0.vertical, d1.vertical, Histogram.Bhattacharyya);
Assert(distance < 0.01, "distance vertical");
distance := Histogram.compare(d0.vertical, d1.horizontal, Histogram.Bhattacharyya);
Assert(distance > 0.2, "vertical != horizontal");
end testBasicDescriptor;
procedure testDivergence(T : in out Test_Cases.Test_Case'Class) is
h0, h1: Histogram.Data(3);
result: Float;
begin
h0.set(0, 0.36);
h0.set(1, 0.48);
h0.set(2, 0.16);
h1.set(0, 0.333);
h1.set(1, 0.333);
h1.set(2, 0.333);
result := HistogramDescriptor.computeDivergence(h0, h1, HistogramDescriptor.KullbackLeibler);
Assert(abs (result - 0.0863) < 0.001, "D(P||Q)");
result := HistogramDescriptor.computeDivergence(h1, h0, HistogramDescriptor.KullbackLeibler);
Assert(abs (result - 0.0964) < 0.001, "D(Q||P)");
result := HistogramDescriptor.computeDivergence(h0, h1, HistogramDescriptor.JensenShannon);
Assert(abs (result - 0.0224) < 0.001, "JSD(P||Q)");
declare
resulth1h0: Float;
begin
resulth1h0 := HistogramDescriptor.computeDivergence(h1, h0, HistogramDescriptor.JensenShannon);
Assert(result = resulth1h0, "JSD symmetry");
end;
end testDivergence;
end HistogramDescriptorTests;
|
code/ZeroLemmas.agda | DSLsofMath/ValiantAgda | 3 | 2428 | import Relation.Binary.EqReasoning as EqReasoning
open import SemiNearRingRecords
module ZeroLemmas (snr : SemiNearRing) where
open SemiNearRing snr -- public
open import CommAssocLemmas s _≃s_ _+s_ zers isCommMon hiding (_<+>_) renaming (SA to Ss)
zeroˡLemma : ∀ x y → zers *s x +s zers *s y ≃s zers
zeroˡLemma x y = begin
zers *s x +s zers *s y
≈⟨ zeroˡ x <+> zeroˡ y ⟩
zers +s zers
≈⟨ identityˡs zers ⟩
zers
∎
where open EqReasoning Ss
zeroʳLemma : ∀ x y → x *s zers +s y *s zers ≃s zers
zeroʳLemma x y =
begin
x *s zers +s y *s zers
≈⟨ zeroʳ x <+> zeroʳ y ⟩
zers +s zers
≈⟨ identityˡs zers ⟩
zers
∎
where open EqReasoning Ss
zeroˡʳLemma : ∀ w x y → w +s (zers *s x +s y *s zers) ≃s w
zeroˡʳLemma w x y = begin
w +s (zers *s x +s y *s zers)
≈⟨ refls <+> (zeroˡ x <+> zeroʳ y) ⟩
w +s (zers +s zers)
≈⟨ refls <+> identityˡs zers ⟩
w +s zers
≈⟨ identityʳs w ⟩
w
∎
where open EqReasoning Ss
-- Some lemmas are needed to eliminate the zers and massage the terms.
zeroLemma01 = lemmaCommAssoc01
zeroLemma10 : ∀ {a b c d e} → a +s ( ((zers *s b) +s c) +s (d +s (e *s zers)))
≃s a +s ( c +s d )
zeroLemma10 {a} {b} {c} {d} {e} = refls <+>
(begin
((zers *s b) +s c) +s (d +s (e *s zers))
≈⟨ (zeroˡ b <+> refls) <+> (refls <+> zeroʳ e) ⟩
( zers +s c) +s (d +s zers)
≈⟨ identityˡs c <+> identityʳs d ⟩
c +s d
∎)
where open EqReasoning Ss
zeroLemma00 : ∀ {a b c d e} → a +s ((c +s b) +s (d +s (e *s zers)) )
≃s (a +s b) +s (c +s d)
zeroLemma00 {a} {b} {c} {d} {e} =
(begin
a +s ((c +s b) +s (d +s (e *s zers)) )
≈⟨ refls <+> (comms c b <+> (refls <+> zeroʳ e)) ⟩
a +s ((b +s c) +s (d +s zers) )
≈⟨ refls <+> (refls <+> identityʳs d) ⟩
a +s ((b +s c) +s d)
≈⟨ refls <+> assocs b c d ⟩
a +s (b +s (c +s d))
≈⟨ syms (assocs a b _) ⟩
(a +s b) +s (c +s d)
∎)
where open EqReasoning Ss
zeroLemma11 : ∀ {a b c d e} → a +s (((zers *s e) +s c) +s (b +s d))
≃s (a +s b) +s (c +s d)
zeroLemma11 {a} {b} {c} {d} {e} =
(begin
a +s (((zers *s e) +s c) +s (b +s d))
≈⟨ refls <+> ((zeroˡ e <+> refls) <+> refls) ⟩
a +s ((zers +s c) +s (b +s d))
≈⟨ refls <+> (identityˡs c <+> refls) ⟩
a +s ( c +s (b +s d))
≈⟨ refls <+> syms (assocs c b d) ⟩
a +s ((c +s b) +s d)
≈⟨ refls <+> (comms c b <+> refls) ⟩
a +s ((b +s c) +s d)
≈⟨ refls <+> (assocs _ _ _) ⟩
a +s (b +s (c +s d))
≈⟨ syms (assocs _ _ _) ⟩
(a +s b) +s (c +s d)
∎)
where open EqReasoning Ss
|
x86-Win-NASM/src/Tables/bin_converter.asm | gramai/school-related | 0 | 92179 |
;English
;Read a binary number and convert in in decimal, octal and hexadecimal
;French
;Lisez un nombre binaire et vous devez le convertir en décimal, octal et hexadécimal.
ORG 100h
include "emu8086.inc"
.data
:
DB "0"
s1 DB "00000000", 0 ; s1 will be used to store the binary number
s2 DB "00", 0 ; stores the choice of the user
s_octal DB "GGGGGGGG", 0
l DB "0", 0 ;length of the binary number
sum DW 0 ; result.
flag DB 0
msg0 DB 0dh, 0ah, "Insert binary length (min 1 max 8) ", 0
msg1 DB 0dh, 0ah, "Insert binary ", 0
msg2 DB 0dh, 0ah, "decimal: ", 0
msg3 DB 0dh, 0ah, "unsigned decimal: ", 0
msg4 DB 0dh, 0ah, "signed decimal: ", 0
msg5 DB 0dh, 0ah, "error: only zeros and ones are allowed!", 0
msg6 DB 0dh, 0ah, "Execution finished...", 0
msg7 DB 0dh, 0ah, "1=to decimal, 2=to octal, 3= to hex : ", 0
msg8 DB 0dh, 0ah, "Octal: ", 0
msg9 DB 0dh, 0ah, "Hexadecimal: ", 0
msgok0 DB 0dh, 0ah, " is 0 ", 0
msgok1 DB 0dh, 0ah, " is 1 ", 0
msgokfalse DB 0dh, 0ah, " OK IS FALSE ", 0
.code
;print msg0
LEA SI, msg0
CALL print_string
;get the length of the binary number
MOV DX,2
LEA DI, l
CALL GET_STRING
LEA SI, msg1
CALL print_string
;get the binary number
MOV DX, 9
LEA DI, s1
CALL GET_STRING
;print the options
LEA SI, msg7
CALL print_string
;get the user option
MOV DX, 2
LEA DI, s2
CALL GET_STRING
MOV SI, OFFSET s2
CMP [SI], 32h ; compares the user option to 2
JL decim ; if less -> 1 -> transform binary to decimal
JE octal ; == 2 -> transform binary to octal
JG hexa ; == 3 -> transform binary to hexadecimal
;binary to decimal algorithm
;SI will point to the last element of the binary number
;Characters will be afterwards parsed right-to-left, and the corresponding decimal values (powers of 2)
;will be added to AL
decim:
MOV SI, OFFSET s1 ; SI will point to the first character of the binary number
MOV DI, OFFSET l ; get the length of the binary number
MOV AX, [DI] ;ax will store the length
SUB AX, 31h ; transforms it to integer
MOV CX, AX ; CX will take the length of the binary number, to be able to execute LOOPs
incr: ; go to the last element of the binary number
INC SI
LOOP incr
MOV BL, 1 ; BL will hold powers of 2 (1, 2, 4, 8...)
MOV AX, 0 ;AX will hold the value of the decimal number
MOV CX, 8 ; CX is the maximal length of the binary number
parser:
JCXZ stop ; if CX == 0, jump to stop
CMP [SI], 31h ; check if the current element is == 1
JL ok0 ; if [SI] == 0
JE ok1 ; if [SI] == 1
JG okfalse ; else -> error
JMP stop
ok0:
SHL BL, 1 ; Shift Left BL -> BL = BL * 2
DEC SI ; backwards parsing
DEC CX
JMP parser ;continues to parse the elements
ok1:
ADD AL, BL ;adds to AL BL, that is a power of 2
SHL BL, 1
DEC SI
DEC CX
JMP parser
okfalse: ;error
LEA SI, msgokfalse
CALL print_string
JMP parser
stop:
LEA SI, msg2
call print_string
call print_num
MOV AH, 0
INT 16h
RET
;the binary number will be parsed in batches of three characters
;BL will take the values : 1,2,4 in this order, and no other values
octal:
PUTC 10
PUTC 13
MOV SI, OFFSET s1
MOV DI, OFFSET l
MOV AX, [DI]
SUB AX, 31h
MOV CX, AX
incr_octal:
INC SI
LOOP incr_octal
MOV BL, 1
MOV AX, 0
MOV CX, 8
parser_octal:
JCXZ stop_octal
CMP [SI], 31h
JL ok0_octal
JE ok1_octal
JG okfalse
ok0_octal:
SHL BL, 1
DEC SI
DEC CX
CMP BL, 8 ;if BL == 8 -> the batch is finished ->BL has to retake the first value (1)
JGE redo
JMP parser_octal
ok1_octal:
ADD AL, BL
SHL BL, 1
DEC SI
DEC CX
CMP BL, 8
JGE redo
JMP parser_octal
redo:
MOV BL,1
MOV DI, SI ; the element that is stored in AX has to replace the value of the corresponding octal
;string character
MOV SI, OFFSET s_octal ;first element of the octal string
looper:
CMP [SI], 47h ; if character == 47h == "G" it means that the element hasn't been replaced and
;has to be replaces
JE replace
JL cont_redo
continue:
MOV SI, DI
MOV AX, 0
JMP parser_octal
replace:
ADD AX, 30h
MOV [SI], AX
JMP continue
cont_redo:
INC SI
JMP looper
stop_octal:
LEA SI, msg8
call print_string
MOV CX, 8
MOV SI, OFFSET s_octal
switcher: ;parses the elements of the octal string until it gets to an element that hasn't been replaced
CMP [SI], 47H ;checks if current element was replaced or is still == 47H == "G"
JNE go_go ;if it is replaced, get to the next element
JE stop_stop ; if it is == "G", we have reached the final element of the octal string
cont:
LOOP switcher
MOV CX, 8
printer: ;prints the octal number
JCXZ continue_gtp
JMP gtp
continue_gtp:
LEA SI, msg6
call print_string
PUTC 10
PUTC 13
MOV AH, 0
INT 16h
RET
gtp:
CMP AX, 0 ; if there is a value in AX, meaning that binary number length % 3 != 0, the number is printed
JG clean_up ;prints AX
CALL print_string ;prints the current element of the string
DEC SI
DEC CX
JMP printer
go_go:
INC SI
JMP cont
stop_stop:
DEC SI
JMP printer
clean_up:
CALL print_num
MOV AX, 0
JMP gtp
;hexa works similar to octal but in batches of 4 elements
;BL can take the values 1,2,4,8 in this order.
hexa:
PUTC 10
PUTC 13
MOV SI, OFFSET s1
MOV DI, OFFSET l
MOV AX, [DI]
SUB AX, 31h
MOV CX, AX
incr_hexa:
INC SI
LOOP incr_hexa
MOV BL, 1
MOV AX, 0
MOV CX, 8
parser_hexa:
JCXZ stop_hexa
CMP [SI], 31h
JL ok0_hexa
JE ok1_hexa
JG okfalse
ok0_hexa:
SHL BL, 1
DEC SI
DEC CX
CMP BL, 16
JGE redo_hexa
JMP parser_hexa
ok1_hexa:
ADD AL, BL
SHL BL, 1
DEC SI
DEC CX
CMP BL, 16
JGE redo_hexa
JMP parser_hexa
redo_hexa:
MOV BL,1
MOV DI, SI
MOV SI, OFFSET s_octal
looper_hexa:
CMP [SI], 47h
JE replace_hexa
JL cont_redo_hexa
continue_hexa:
MOV BL, 1
MOV SI, DI
MOV AX, 0
JMP parser_hexa
replace_hexa:
CMP AX, 9 ;checks if AX is greater than 9.
;If this is the case, that means that it has to be converted to the corresponding character
JG greater
JLE rh_continue
rh_continue:
ADD AX, 30h
MOV [SI], AX
JMP continue_hexa
greater:
MOV BX, AX ; the value of AX is stored as backup in BX
MOV AX, 0
MOV CX, 0
search_hex: ;substracts 1 from BX until it gets to the value 9
; the value held in CX will be the value of the character
;CX, 1 -> A, 2 -> B, 3->C, 4-> D, 5-> E, 6-> F
INC CX
DEC BX
CMP BX, 9
JG search_hex
JLE done_search_hex
done_search_hex:
;for CX, 1 -> A, 2 -> B, 3->C, 4-> D, 5-> E, 6-> F
CMP CX, 1
JE A_found
JG B_check
A_found:
MOV AX, 'A'
MOV [SI], AX
JMP continue_hexa
B_check:
CMP CX, 2
JE B_found
JG C_check
B_found:
MOV AX, 'B'
MOV [SI], AX
JMP continue_hexa
C_check:
CMP CX, 3
JE C_found
JG D_check
C_found:
MOV AX, 'C'
MOV [SI], AX
JMP continue_hexa
D_check:
CMP CX, 4
JE D_found
JG E_check
D_found:
MOV AX, 'D'
MOV [SI], AX
JMP continue_hexa
E_check:
CMP CX, 5
JE E_found
JG F_check
E_found:
MOV AX, 'E'
MOV [SI], AX
JMP continue_hexa
F_check:
CMP CX, 6
JE F_found
JG error_not_valid
F_found:
MOV AX, 'F'
MOV [SI], AX
JMP continue_hexa
cont_redo_hexa:
INC SI
JMP looper_hexa
stop_hexa:
LEA SI, msg9
call print_string
MOV CX, 8
MOV SI, OFFSET s_octal
switcher_hexa:
CMP [SI], 47H
JNE go_go_hexa
JE stop_stop_hexa
cont_hexa:
LOOP switcher_hexa
MOV CX, 8
printer_hexa:
JCXZ continue_gtp_hexa
CMP [SI], 47H
JL gtp_hexa
continue_gtp_hexa:
LEA SI, msg6
call print_string
PUTC 10
PUTC 13
MOV AH, 0
INT 16h
RET
gtp_hexa:
CALL print_string
DEC SI
DEC CX
JMP printer_hexa
go_go_hexa:
INC SI
JMP cont_hexa
stop_stop_hexa:
DEC SI
JMP printer_hexa
clean_up_hexa:
CALL print_num
MOV AX, 0
JMP gtp_hexa
error_not_valid:
LEA SI, msg5
call print_string
DEFINE_GET_STRING
DEFINE_PRINT_STRING
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_SCAN_NUM
END |
Examples/Compare.asm | Pyxxil/rust-lc3-as | 3 | 23084 | <gh_stars>1-10
;
; This program takes two inputs in succession, between -999 and 999, stores them
; in R1 and R2 after processing of input and then calculates the relation between
; the two numbers, prints the value of R0 and then sets the correct value into R0,
; the value of R0 being one of the below (mentioned in Calculation Method).
;
; Calculation Method
; First step, check on what side of 0 R1 and R2 are
; If R1 < 0, and R2 >= 0, then R1 < R2 so R0 <== -1
; If R1 >= 0, and R2 < 0, then R1 > R2 so R0 <== 1
; If R1 < 0, and R2 < 0, or If R1 >= 0, and R2 >= 0, Then:
; The calculation R3 <== R1 - R2 will be performed.
; If R3 -ve, then R1 < R2 so R0 <== -1
; If R3 +ve, then R1 > R2 so R0 <== 1
; If R0 = 0, then R1 = R2 so R0 <== 0
; This method is used to ensure that an overflow into R3 does not occur.
; Register Usage :
; R0 : final result/Input from GETC
; R1 : First Number
; R2 : Second Number
; R3 : Result from calculation if needed
; R4 : Null Character/minus Character
; R5 : Top of Input_Stack
; R6 : Pointer To Lookup Table
.ORIG x3000 ; Origin Memory
INIT_REGISTERS: ; Clear every register prior to operation of the program.
AND R0, R0, #0 ; Just to be safe.
AND R1, R1, #0
; For now, R2 will be used for converting the ASCII input to it's decimal
; value, i.e. '1' to 1
LD R2, ZERO
NOT R2, R2
ADD R2, R2, #1
AND R3, R3, #0
AND R4, R4, #0
LEA R5, INPUT_STACK ; Make R5 Point to the top of the InputStack
AND R6, R6, #0
AND R7, R7, #0
CREATE_NULL:
ADD R4, R4, #10 ; Newline character has ASCII value of 10 (dec) 0xA (hex)
NOT R4, R4 ; 2's compliment negation of newline value for comparison
ADD R4, R4, #1 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^
CREATE_STACK:
ADD R3, R3, #10 ; Create an illegal stack value of 10
STR R3, R5, #0 ; Store the illegal value so we know where the top of the stack is
ADD R5, R5, #1 ; Increment by one so we know when to stop when creating number
GET_R1:
GETC ; Get Next Digit
OUT ; Prints character to the console
AND R3, R3, #0 ; Clear R3
ADD R3, R0, R4 ; Check to see if null character was selected
BRz PROCESS_R1 ; Go and process the stack
ADD R0, R0, R2
STR R0, R5, #0 ; Put digit onto the stack
ADD R5, R5, #1 ; Increment Stack Counter
BR GET_R1 ; Loop back
PROCESS_R1:
ADD R5, R5, #-1 ; Deincrement stack counter as it one too much ahead
LDR R3, R5, #0 ; Load the value
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #-10 ; Check to see if top of stack is reached
BRz GET_R2 ; Branch to get R2 if top of stack was reached
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #0 ; Check to see if a minus sign has been read,
; due to conversion a minus sign will be -3,
; which is an illegal value
BRn MAKE_R1_NEGATIVE ; If minus sign has been reached, then go and Make R1 negative
ADD R1, R1, R3 ; Add the value from the top of the stack to R1
ADD R5, R5, #-1 ; Deincrement stack counter
LDR R3, R5, #0 ; Load the value
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #-10 ; Check to see if top of stack is reached
BRz GET_R2 ; Branch to get R2 if top of stack was reached
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #0 ; Store Value in R0
ADD R0, R3, #0 ; Check to see if a minus sign has been read,
; due to conversion a minus sign will be -3,
; which is an illegal value
BRn MAKE_R1_NEGATIVE ; If minus sign has been reached, then go and Make R1 negative
LEA R6, LookUp10 ; Make R6 point to the lookup10 table
ADD R6, R6, R3 ; Point at correct factor in LookUp10
AND R0, R0, #0 ; Clear R0
LDR R0, R6, #0 ; Load factor into R0
ADD R1, R1, R0 ; Add factor to total in R1
ADD R5, R5, #-1 ; Deincrement stack counter
LDR R3, R5, #0 ; Load the value
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #-10 ; Check to see if top of stack is reached
BRz GET_R2 ; Branch to get R2 if top of stack was reached
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #0 ; Check to see if a minus sign has been read,
; due to conversion a minus sign will be -3,
; which is an illegal value
BRn MAKE_R1_NEGATIVE ; If minus sign has been reached, then go and Make R1 negative
LEA R6, LookUp100 ; Make R6 point to the lookup100 table
ADD R6, R6, R3 ; Point at correct factor in LookUp100
AND R0, R0, #0 ; Clear R0
LDR R0, R6, #0 ; Load factor into R0
ADD R1, R1, R0 ; Add factor to total in R1
ADD R5, R5, #-1 ; Deincrement stack counter
LDR R3, R5, #0 ; Load the value
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #0 ; Check to see if a minus sign has been read,
; due to conversion a minus sign will be -3,
; which is an illegal value
BRn MAKE_R1_NEGATIVE ; If minus sign has been reached, then go and Make R1 negative
BR GET_R2 ; Computation of R1 complete, go and get R2
ADD R5, R5, #1 ; Increment stack counter
MAKE_R1_NEGATIVE:
NOT R1, R1 ; 2's compliment negation of R1
ADD R1, R1, #1 ; ^^^^^^^^^^^^^^^^^^^^^^
STR R5, R5, #0 ; Clear the Value at the top of the stack
GET_R2:
ADD R5, R5, #1 ; Increment stack counter, as it is currently
; pointing at the end of stack character
GET_R2_LOOP:
GETC ; Get Next Digit
OUT ; Prints character to the console
AND R3, R3, #0 ; Clear R3
ADD R3, R0, R4 ; Check to see if null character was selected
BRz PROCESS_R2 ; Go and process the stack
ADD R0, R0, R2
STR R0, R5, #0 ; Put digit onto the stack
ADD R5, R5, #1 ; Increment Stack Counter
BR GET_R2_LOOP ; Loop back
PROCESS_R2:
AND R2, R2, #0
ADD R5, R5, #-1 ; Deincrement stack counter as it one too much ahead
LDR R3, R5, #0 ; Load the value
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #-10 ; Check to see if top of stack is reached
BRz CHECKING_LOOP ; Branch to check both numbers if top of stack was reached
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #0 ; Store Value in R0
ADD R0, R3, #0 ; Check to see if a minus sign has been read,
; due to conversion a minus sign will be -3,
; which is an illegal value
BRn MAKE_R2_NEGATIVE ; If minus sign has been reached, then go and Make R1 negative
ADD R2, R2, R3 ; Add the value from the top of the stack to R2
ADD R5, R5, #-1 ; Deincrement stack counter
LDR R3, R5, #0 ; Load the value
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #-10 ; Check to see if top of stack is reached
BRz CHECKING_LOOP ; Branch to check both numbers if top of stack was reached
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #0 ; Store Value in R0
ADD R0, R3, #0 ; Check to see if a minus sign has been read,
; due to conversion a minus sign will be -3,
; which is an illegal value
BRn MAKE_R2_NEGATIVE ; If minus sign has been reached, then go and Make R1 negative
LEA R6, LookUp10 ; Make R6 point to the lookup10 table
ADD R6, R6, R3 ; Point at correct factor in LookUp10
AND R0, R0, #0 ; Clear R0
LDR R0, R6, #0 ; Load factor into R0
ADD R2, R2, R0 ; Add factor to total in R2
ADD R5, R5, #-1 ; Decrement stack counter
LDR R3, R5, #0 ; Load the value
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #-10 ; Check to see if top of stack is reached
BRz CHECKING_LOOP ; Branch to check both numbers if top of stack was reached
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #0 ; Check to see if a minus sign has been read,
; due to conversion a minus sign will be -3,
; which is an illegal value
BRn MAKE_R2_NEGATIVE ; If minus sign has been reached, then go and Make R1 negative
LEA R6, LookUp100 ; Make R6 point to the lookup100 table
ADD R6, R6, R3 ; Point at correct factor in LookUp100
AND R0, R0, #0 ; Clear R0
LDR R0, R6, #0 ; Load factor into R0
ADD R2, R2, R0 ; Add factor to total in R2
ADD R5, R5, #-1 ; Deincrement stack counter
LDR R3, R5, #0 ; Load the value
AND R0, R0, #0 ; Clear R0
ADD R0, R3, #0 ; Check to see if a minus sign has been read,
; due to conversion a minus sign will be -3,
; which is an illegal value
BRzp CHECKING_LOOP ; Go and compare the two numbers
MAKE_R2_NEGATIVE:
NOT R2, R2 ; 2's compliment negation of R2
ADD R2, R2, #1 ; ^^^^^^^^^^^^^^^^^^^^^^
STR R5, R5, #0 ; Clear the Value at the top of the stack
CHECKING_LOOP:
LEA R0, NEGATIVE_ONE
ADD R3, R1, #0 ; Check if R1 is negative or positive
BRn R1_NEGATIVE ; If negative, then branch to R1_negative Branch
AND R3, R3, #0 ; Clear value in R3
ADD R3, R2, #0 ; Check if R2 is negative or positive
BRn R1_POSITIVE_R2_NEGATIVE ; At this point it is known that R1 is positive
; or 0 and R2 is negative
BR R1_R2_SAME_SIGN ; If neither previous branch was triggered,
; it means that both R1 and R2 are positive
R1_NEGATIVE:
AND R3, R3, #0 ; Clear value in R3
ADD R3, R2, #0 ; Check if R2 is negative or positive
BRn R1_R2_SAME_SIGN ; If R2 Is negative, then both R1 and R2 are negative
R1_NEGATIVE_R2_POSITIVE:
LEA R0, NEGATIVE_ONE ; Make R0 point to top of negative result string
JSR PRINT
R1_POSITIVE_R2_NEGATIVE:
LEA R0, POSITIVE_ONE ; Make R0 point to top of positive result string
JSR PRINT ; Print result
R1_R2_SAME_SIGN:
NOT R2, R2 ; 2's Compliment Negation of R2
ADD R2, R2, #1 ; ^^^^^^^
AND R3, R3, #0 ; Clear value in R3
ADD R3, R1, R2 ; Subtraction of R2 from R1
BRn PRINT ; if result is negative then R1 < R2
AND R3, R3, #0 ; Clear value in R3
ADD R3, R1, R2 ; Subtraction of R2 from R1
BRp POSITIVE ; If Result was positive, then R1 > R2
ADD R0, R0, #2 ; Result is 0, so load the correct address
POSITIVE:
ADD R0, R0, #3
PRINT:
PUTS
SET_R0:
AND R0, R0, #0
ADD R0, R0, #-1
ADD R3, R3, #0
BRn DONE
BRz SET_R0_ZERO
ADD R0, R0, #1
SET_R0_ZERO:
ADD R0, R0, #1
DONE:
HALT ; End Program
; Reserve 5 memory spaces for input number
INPUT_STACK: .BLKW #5 0
; Lookup table for base 10 values
LookUp10:
.FILL #0
.FILL #10
.FILL #20
.FILL #30
.FILL #40
.FILL #50
.FILL #60
.FILL #70
.FILL #80
.FILL #90
; Lookup table for base 100 values
LookUp100:
.FILL #0
.FILL #100
.FILL #200
.FILL #300
.FILL #400
.FILL #500
.FILL #600
.FILL #700
.FILL #800
.FILL #900
NEGATIVE_ONE:
.STRINGZ "-1"
POSITIVE_ONE:
.STRINGZ "1"
ZERO:
.STRINGZ "0"
.END
|
libsrc/_DEVELOPMENT/adt/w_vector/c/sccz80/w_vector_insert_n_callee.asm | meesokim/z88dk | 0 | 245703 |
; size_t w_vector_insert_n(w_vector_t *v, size_t idx, size_t n, void *item)
SECTION code_adt_w_vector
PUBLIC w_vector_insert_n_callee
w_vector_insert_n_callee:
pop ix
pop af
pop de
pop bc
pop hl
push ix
INCLUDE "adt/w_vector/z80/asm_w_vector_insert_n.asm"
|
theorems/cw/cohomology/GridPtdMap.agda | mikeshulman/HoTT-Agda | 0 | 7559 | {-# OPTIONS --without-K --rewriting #-}
open import HoTT
module cw.cohomology.GridPtdMap {i j k}
{X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(f : X ⊙→ Y) (g : Y ⊙→ Z) where
open import cw.cohomology.GridMap (fst f) (fst g) public
Y/X = ⊙Cofiber f
Z/X = ⊙Cofiber (g ⊙∘ f)
Z/Y = ⊙Cofiber g
Y/X-to-Z/X : Y/X ⊙→ Z/X
Y/X-to-Z/X = B/A-to-C/A , idp
Z/X-to-Z/Y : Z/X ⊙→ Z/Y
Z/X-to-Z/Y = C/A-to-C/B , idp
|
source/runtime/pb_support-vectors.adb | mgrojo/protobuf | 12 | 27859 | -- MIT License
--
-- Copyright (c) 2020 <NAME>
--
-- Permission is hereby granted, free of charge, to any person obtaining a
-- copy of this software and associated documentation files (the "Software"),
-- to deal in the Software without restriction, including without limitation
-- the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
with Ada.Unchecked_Deallocation;
package body PB_Support.Vectors is
procedure Free is new Ada.Unchecked_Deallocation
(Element_Array, Element_Array_Access);
------------
-- Adjust --
------------
overriding procedure Adjust (Self : in out Vector) is
begin
if Self.Length > 0 then
Self.Data := new Element_Array'(Self.Data (1 .. Self.Length));
end if;
end Adjust;
------------
-- Append --
------------
procedure Append (Self : in out Vector; Value : Element_Type) is
Old : Element_Array_Access := Self.Data;
Init_Length : constant Positive :=
Positive'Max (1, 256 / Natural'Max (1, Element_Type'Size));
begin
if Self.Length = 0 then
Self.Data := new Element_Array (1 .. Init_Length);
elsif Self.Length = Self.Data'Last then
Self.Data := new Element_Array'
(Old.all & (1 .. Self.Length => <>));
Free (Old);
end if;
Self.Length := Self.Length + 1;
Self.Data (Self.Length) := Value;
end Append;
-----------
-- Clear --
-----------
procedure Clear (Self : in out Vector) is
begin
Self.Length := 0;
end Clear;
--------------
-- Finalize --
--------------
overriding procedure Finalize (Self : in out Vector) is
begin
if Self.Data /= null then
Free (Self.Data);
end if;
end Finalize;
---------
-- Get --
---------
function Get (Self : Vector; Index : Positive) return Element_Type is
begin
return Self.Data (Index);
end Get;
------------
-- Length --
------------
function Length (Self : Vector) return Natural is
begin
return Self.Length;
end Length;
end PB_Support.Vectors;
|
src/util/iterateur_mots.ads | SKNZ/BezierToSTL | 0 | 26973 | with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Iterateur_Mots is
Erreur_Syntaxe : exception;
type Iterateur_Mot is private;
-- Initialise le record
function Initialiser(Chaine : String; Separateur : Character) return Iterateur_Mot;
-- Indique si l'iterateur est à sa fin
function Fin(Iterateur : Iterateur_Mot) return Boolean;
-- Lit le mot suivant (sans déplacer le curseur)
-- lève Erreur_Syntaxe si caractère innatendu
function Lire_Mot_Suivant(Iterateur : Iterateur_Mot) return String;
-- Avance au mot suivant (déplace le curseur)
function Avancer_Mot_Suivant(Iterateur : in out Iterateur_Mot) return String;
private
function Lire_Mot_Suivant_Interne(Iterateur : Iterateur_Mot; Caracteres_Lus : out Natural) return String;
-- Regroupe les infos de la String
type Iterateur_Mot is record
Chaine : Unbounded_String;
Curseur : Positive;
Separateur : Character;
end record;
end;
|
child_processes-managed.adb | annexi-strayline/AURA | 13 | 18879 | <reponame>annexi-strayline/AURA<gh_stars>10-100
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- ANNEXI-STRAYLINE Reference Implementation --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * <NAME> (ANNEXI-STRAYLINE) --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- --
-- * Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A --
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
package body Child_Processes.Managed is
-----------------------
-- Termination_Watch --
-----------------------
task body Termination_Watch is
Exit_Code: Exit_Status;
begin
-- Note that this task is always activated after Proc.PID has been
-- set. This can happen either through an allocator, or once GNAT
-- if fixed, through the activation rules of tasks in objects returned
-- from a function (Span_Process)
Platform.Wait_Termination (ID => Proc.PID,
Exit_Code => Exit_Code);
loop
select
accept Wait_Terminate (Status: out Exit_Status) do
Status := Exit_Code;
end;
or
terminate;
end select;
end loop;
end Termination_Watch;
---------------
-- IO_Stream --
---------------
function IO_Stream (Process : in out Managed_Process;
Selector: in IO_Stream_Selector)
return not null access Root_Stream_Type'Class
is (Process.Streams(Selector)'Unchecked_Access);
------------------------
-- Set_Stream_Timeout --
------------------------
procedure Set_Stream_Timeout (Process : in out Managed_Process;
Selector : in IO_Stream_Selector;
Timeout : in Duration)
is begin
Process.Streams(Selector).Timeout := Timeout;
end Set_Stream_Timeout;
----------------
-- Terminated --
----------------
function Terminated (Process: Managed_Process)
return Boolean
is
Discard: Exit_Status;
begin
select
Process.Watch.Wait_Terminate (Discard);
return True;
else
return False;
end select;
end Terminated;
---------------------
-- Wait_Terminated --
---------------------
procedure Wait_Terminated (Process : in Managed_Process;
Timeout : in Duration;
Timed_Out: out Boolean;
Status : out Exit_Status)
is begin
if Timeout = 0.0 then
Timed_Out := False;
Process.Watch.Wait_Terminate (Status);
else
select
Process.Watch.Wait_Terminate (Status);
Timed_Out := False;
return;
or
delay Timeout;
Timed_Out := True;
return;
end select;
end if;
end Wait_Terminated;
----------
-- Kill --
----------
procedure Kill (Process: in out Managed_Process) is
begin
Platform.Kill (Process.PID);
end Kill;
----------
-- Nuke --
----------
procedure Nuke (Process: in out Managed_Process) is
begin
Platform.Nuke (Process.PID);
end Nuke;
--------------
-- Finalize --
--------------
overriding
procedure Finalize (Process: in out Managed_Process) is
procedure Free_Watch is new Ada.Unchecked_Deallocation
(Object => Termination_Watch,
Name => Termination_Watch_Access);
begin
for Stream of Process.Streams loop
Platform.Close_Stream (Stream.Handle);
end loop;
if not Process.Terminated then
-- No time to mess around
Platform.Nuke (Process.PID);
end if;
Free_Watch (Process.Watch);
end Finalize;
end Child_Processes.Managed;
|
P6/data_P6/testpoint/testpoint61.asm | alxzzhou/BUAA_CO_2020 | 1 | 6009 | <filename>P6/data_P6/testpoint/testpoint61.asm
ori $1, $0, 0
ori $2, $0, 15
ori $3, $0, 10
ori $4, $0, 0
sw $3, 0($0)
sw $2, 4($0)
sw $2, 8($0)
sw $2, 12($0)
sw $3, 16($0)
sw $1, 20($0)
sw $3, 24($0)
sw $2, 28($0)
sw $4, 32($0)
sw $1, 36($0)
sw $3, 40($0)
sw $1, 44($0)
sw $2, 48($0)
sw $4, 52($0)
sw $4, 56($0)
sw $3, 60($0)
sw $1, 64($0)
sw $3, 68($0)
sw $3, 72($0)
sw $3, 76($0)
sw $1, 80($0)
sw $2, 84($0)
sw $1, 88($0)
sw $2, 92($0)
sw $4, 96($0)
sw $4, 100($0)
sw $4, 104($0)
sw $3, 108($0)
sw $4, 112($0)
sw $2, 116($0)
sw $1, 120($0)
sw $3, 124($0)
mtlo $2
mfhi $2
sub $3, $2, $2
mtlo $3
TAG1:
mthi $3
multu $3, $3
ori $1, $3, 2
sll $3, $1, 3
TAG2:
bne $3, $3, TAG3
mthi $3
mfhi $4
sllv $3, $3, $4
TAG3:
sll $0, $0, 0
bgtz $3, TAG4
sllv $4, $3, $1
beq $4, $1, TAG4
TAG4:
sll $4, $4, 1
div $4, $4
mfhi $3
sw $4, 0($3)
TAG5:
sltu $3, $3, $3
mfhi $3
sw $3, 0($3)
lh $4, 0($3)
TAG6:
addiu $3, $4, 2
mfhi $2
lui $4, 8
beq $4, $2, TAG7
TAG7:
sll $0, $0, 0
bgez $2, TAG8
mtlo $4
slt $2, $2, $4
TAG8:
addu $3, $2, $2
mfhi $1
sh $1, 0($1)
mtlo $1
TAG9:
lhu $2, 0($1)
beq $1, $1, TAG10
lui $1, 3
beq $1, $2, TAG10
TAG10:
sll $0, $0, 0
mult $1, $1
sll $0, $0, 0
blez $3, TAG11
TAG11:
mthi $3
bgez $3, TAG12
mult $3, $3
sll $4, $3, 2
TAG12:
mthi $4
beq $4, $4, TAG13
sll $0, $0, 0
bltz $4, TAG13
TAG13:
mult $4, $4
bltz $4, TAG14
mtlo $4
bgtz $4, TAG14
TAG14:
and $3, $4, $4
mflo $2
sll $0, $0, 0
ori $1, $4, 8
TAG15:
blez $1, TAG16
mtlo $1
addu $1, $1, $1
mfhi $3
TAG16:
addiu $3, $3, 11
sb $3, 0($3)
lui $4, 13
bltz $3, TAG17
TAG17:
multu $4, $4
lui $2, 3
beq $2, $2, TAG18
mult $4, $4
TAG18:
bgtz $2, TAG19
mflo $3
srlv $1, $3, $3
mtlo $3
TAG19:
mfhi $2
blez $2, TAG20
mflo $4
sltu $4, $2, $2
TAG20:
sw $4, 0($4)
addu $2, $4, $4
lui $1, 11
sub $1, $2, $2
TAG21:
lhu $1, 0($1)
multu $1, $1
lui $3, 15
beq $1, $3, TAG22
TAG22:
xori $1, $3, 2
lui $3, 7
bgez $1, TAG23
mthi $3
TAG23:
mthi $3
beq $3, $3, TAG24
addu $1, $3, $3
srl $4, $3, 0
TAG24:
sra $4, $4, 8
beq $4, $4, TAG25
lb $4, 0($4)
mthi $4
TAG25:
mfhi $3
mtlo $4
lw $1, 0($4)
mult $4, $3
TAG26:
blez $1, TAG27
slti $1, $1, 8
mfhi $3
slti $2, $1, 0
TAG27:
lui $1, 4
mult $2, $2
multu $1, $2
mtlo $1
TAG28:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
bne $1, $1, TAG29
TAG29:
mthi $4
blez $4, TAG30
srl $4, $4, 0
lhu $2, 0($4)
TAG30:
mult $2, $2
mfhi $3
bne $3, $2, TAG31
nor $1, $3, $2
TAG31:
bgtz $1, TAG32
subu $2, $1, $1
mflo $4
mult $1, $1
TAG32:
addi $3, $4, 12
beq $3, $3, TAG33
lh $4, 0($4)
bltz $4, TAG33
TAG33:
xor $3, $4, $4
bgez $4, TAG34
sb $3, 0($3)
mtlo $4
TAG34:
srl $1, $3, 7
mult $3, $3
bltz $3, TAG35
mtlo $1
TAG35:
mthi $1
slti $3, $1, 5
bltz $1, TAG36
sh $3, 0($1)
TAG36:
lb $1, 0($3)
bne $3, $3, TAG37
mthi $1
srav $3, $1, $1
TAG37:
mfhi $1
lui $1, 2
sw $1, 0($3)
sll $0, $0, 0
TAG38:
beq $4, $4, TAG39
mflo $3
sltu $2, $3, $3
beq $2, $3, TAG39
TAG39:
mflo $2
sh $2, 0($2)
slt $4, $2, $2
mthi $2
TAG40:
beq $4, $4, TAG41
sra $1, $4, 2
lbu $4, 0($4)
mflo $2
TAG41:
lbu $2, 0($2)
srav $3, $2, $2
bgez $2, TAG42
sh $2, 0($3)
TAG42:
sh $3, 0($3)
lb $3, 0($3)
beq $3, $3, TAG43
multu $3, $3
TAG43:
mthi $3
mflo $4
bgez $4, TAG44
mtlo $4
TAG44:
bgez $4, TAG45
lhu $3, 0($4)
sh $4, 0($3)
xor $1, $3, $3
TAG45:
lui $4, 3
sll $0, $0, 0
lhu $3, 0($1)
mfhi $1
TAG46:
blez $1, TAG47
lb $2, 0($1)
divu $2, $1
subu $1, $1, $2
TAG47:
beq $1, $1, TAG48
mfhi $3
and $4, $3, $1
slt $3, $3, $1
TAG48:
addu $4, $3, $3
bne $4, $4, TAG49
sltiu $2, $4, 15
mtlo $4
TAG49:
sb $2, 0($2)
lui $1, 9
or $2, $2, $2
lui $4, 2
TAG50:
bne $4, $4, TAG51
addu $1, $4, $4
slti $1, $4, 1
mthi $1
TAG51:
nor $3, $1, $1
bgtz $3, TAG52
mthi $3
beq $1, $1, TAG52
TAG52:
sll $0, $0, 0
div $3, $3
addiu $4, $3, 2
and $1, $4, $3
TAG53:
beq $1, $1, TAG54
lui $2, 6
addi $1, $2, 0
mflo $2
TAG54:
mtlo $2
blez $2, TAG55
mfhi $1
ori $3, $1, 0
TAG55:
addiu $2, $3, 4
mthi $2
mtlo $2
blez $2, TAG56
TAG56:
mflo $2
sw $2, 0($2)
slt $3, $2, $2
mtlo $2
TAG57:
sh $3, 0($3)
sllv $3, $3, $3
srav $3, $3, $3
beq $3, $3, TAG58
TAG58:
add $2, $3, $3
mflo $3
sh $2, 0($2)
lui $4, 15
TAG59:
multu $4, $4
sll $0, $0, 0
bgez $4, TAG60
sll $0, $0, 0
TAG60:
mtlo $4
beq $4, $4, TAG61
sll $0, $0, 0
sb $4, 0($4)
TAG61:
subu $2, $4, $4
sb $2, 0($2)
sll $0, $0, 0
lui $3, 4
TAG62:
sll $0, $0, 0
beq $3, $3, TAG63
and $3, $3, $3
mflo $4
TAG63:
mtlo $4
mthi $4
mflo $4
bgez $4, TAG64
TAG64:
multu $4, $4
mult $4, $4
bgez $4, TAG65
mtlo $4
TAG65:
sll $0, $0, 0
mthi $2
blez $4, TAG66
andi $1, $2, 2
TAG66:
lui $2, 8
bgez $2, TAG67
sll $0, $0, 0
addi $1, $2, 11
TAG67:
lbu $2, 0($1)
ori $4, $1, 13
mfhi $4
multu $2, $4
TAG68:
mfhi $3
mthi $3
mfhi $3
mult $3, $3
TAG69:
mthi $3
bgtz $3, TAG70
lui $3, 14
lui $2, 13
TAG70:
blez $2, TAG71
mult $2, $2
beq $2, $2, TAG71
lui $2, 3
TAG71:
mthi $2
lui $4, 15
subu $1, $4, $4
mthi $4
TAG72:
bne $1, $1, TAG73
mtlo $1
blez $1, TAG73
xori $4, $1, 10
TAG73:
mfhi $2
bgez $4, TAG74
lui $2, 15
mfhi $3
TAG74:
sll $0, $0, 0
beq $3, $3, TAG75
sll $0, $0, 0
sltiu $3, $3, 0
TAG75:
mtlo $3
addiu $1, $3, 2
bgtz $1, TAG76
mtlo $3
TAG76:
div $1, $1
bne $1, $1, TAG77
lui $4, 7
divu $4, $4
TAG77:
mfhi $3
multu $4, $3
sll $0, $0, 0
lhu $3, 0($3)
TAG78:
bne $3, $3, TAG79
sw $3, 0($3)
sh $3, 0($3)
mfhi $2
TAG79:
lui $3, 4
bltz $3, TAG80
mfhi $3
addiu $4, $3, 8
TAG80:
addu $4, $4, $4
lui $1, 8
slt $1, $4, $1
mthi $1
TAG81:
mtlo $1
lb $4, 0($1)
beq $4, $1, TAG82
sh $1, 0($4)
TAG82:
multu $4, $4
sb $4, 0($4)
mthi $4
lw $1, 0($4)
TAG83:
sw $1, 0($1)
beq $1, $1, TAG84
multu $1, $1
lui $4, 0
TAG84:
mflo $3
mtlo $3
mtlo $3
sb $3, 0($3)
TAG85:
mult $3, $3
bne $3, $3, TAG86
mult $3, $3
mthi $3
TAG86:
sb $3, 0($3)
sw $3, 0($3)
lui $1, 12
sll $0, $0, 0
TAG87:
mfhi $2
mthi $1
multu $2, $2
lui $2, 7
TAG88:
bgtz $2, TAG89
lui $3, 14
mthi $2
bne $2, $3, TAG89
TAG89:
xori $1, $3, 12
srlv $1, $1, $3
divu $3, $1
sra $4, $1, 7
TAG90:
mthi $4
andi $3, $4, 2
mtlo $4
sub $3, $4, $3
TAG91:
divu $3, $3
sb $3, -7168($3)
subu $3, $3, $3
sh $3, 0($3)
TAG92:
add $4, $3, $3
mfhi $2
sb $2, 0($2)
sw $2, 0($2)
TAG93:
bne $2, $2, TAG94
mult $2, $2
beq $2, $2, TAG94
lui $3, 8
TAG94:
bne $3, $3, TAG95
mult $3, $3
srl $2, $3, 2
mfhi $2
TAG95:
mtlo $2
blez $2, TAG96
mthi $2
mflo $1
TAG96:
mthi $1
sw $1, 0($1)
srlv $2, $1, $1
mflo $4
TAG97:
subu $2, $4, $4
beq $2, $4, TAG98
sw $2, 0($2)
lb $4, 0($4)
TAG98:
div $4, $4
lhu $2, 0($4)
mfhi $3
mult $3, $2
TAG99:
mthi $3
lh $1, 0($3)
nor $3, $1, $3
nor $1, $1, $3
TAG100:
lui $2, 6
lui $4, 11
lhu $1, 0($1)
sb $4, 0($1)
TAG101:
lui $1, 7
bne $1, $1, TAG102
sll $0, $0, 0
multu $2, $2
TAG102:
bne $2, $2, TAG103
lui $1, 15
sll $0, $0, 0
mflo $3
TAG103:
blez $3, TAG104
xor $2, $3, $3
nor $4, $2, $3
beq $3, $3, TAG104
TAG104:
sll $0, $0, 0
lui $4, 6
lui $3, 4
mfhi $3
TAG105:
bne $3, $3, TAG106
slti $2, $3, 13
sb $3, 0($2)
mult $3, $2
TAG106:
mflo $2
mthi $2
bgtz $2, TAG107
mthi $2
TAG107:
srlv $2, $2, $2
bne $2, $2, TAG108
mult $2, $2
lbu $3, 0($2)
TAG108:
sll $1, $3, 13
sll $1, $1, 14
mult $1, $1
addu $4, $3, $3
TAG109:
mflo $2
lh $1, 0($2)
mflo $4
add $1, $4, $2
TAG110:
mfhi $3
lui $1, 4
sll $0, $0, 0
mthi $3
TAG111:
ori $3, $1, 0
sll $0, $0, 0
mflo $1
sll $0, $0, 0
TAG112:
beq $1, $1, TAG113
multu $1, $1
lw $2, 0($1)
lbu $1, 0($1)
TAG113:
mflo $4
lui $4, 9
beq $1, $1, TAG114
mthi $4
TAG114:
lui $2, 10
mflo $1
mfhi $3
sll $0, $0, 0
TAG115:
multu $3, $3
sll $0, $0, 0
div $3, $3
sll $3, $3, 12
TAG116:
mflo $4
blez $3, TAG117
sb $3, 0($4)
beq $3, $3, TAG117
TAG117:
mult $4, $4
mthi $4
beq $4, $4, TAG118
sll $4, $4, 2
TAG118:
addiu $3, $4, 0
bne $3, $4, TAG119
sh $3, 0($3)
lh $2, 0($4)
TAG119:
mult $2, $2
bne $2, $2, TAG120
mflo $1
mthi $2
TAG120:
bgez $1, TAG121
mfhi $3
mthi $3
lh $2, 0($3)
TAG121:
beq $2, $2, TAG122
sw $2, 0($2)
sub $3, $2, $2
mtlo $2
TAG122:
sllv $4, $3, $3
mflo $4
sltiu $1, $4, 1
lbu $3, 0($4)
TAG123:
bgez $3, TAG124
addu $4, $3, $3
lui $1, 1
lui $4, 14
TAG124:
xori $4, $4, 13
sb $4, 0($4)
xor $1, $4, $4
sw $4, 0($1)
TAG125:
mult $1, $1
mfhi $1
lui $1, 11
mthi $1
TAG126:
addiu $2, $1, 6
mthi $1
bltz $2, TAG127
mflo $2
TAG127:
lhu $4, 0($2)
sllv $2, $2, $2
mthi $2
bne $2, $2, TAG128
TAG128:
mfhi $1
mthi $2
bgtz $2, TAG129
lb $4, 0($2)
TAG129:
mflo $4
srav $4, $4, $4
bgez $4, TAG130
mthi $4
TAG130:
bltz $4, TAG131
slt $4, $4, $4
bne $4, $4, TAG131
mult $4, $4
TAG131:
beq $4, $4, TAG132
mtlo $4
mtlo $4
addiu $2, $4, 2
TAG132:
mtlo $2
andi $1, $2, 13
mtlo $2
lhu $3, 0($2)
TAG133:
mtlo $3
lb $3, 0($3)
lb $3, 0($3)
lb $2, 0($3)
TAG134:
beq $2, $2, TAG135
nor $1, $2, $2
and $2, $2, $1
mflo $4
TAG135:
bgtz $4, TAG136
srlv $3, $4, $4
bgez $4, TAG136
and $1, $4, $4
TAG136:
mthi $1
mflo $1
sltu $2, $1, $1
mfhi $4
TAG137:
andi $2, $4, 4
lui $1, 12
bne $2, $4, TAG138
mfhi $3
TAG138:
bgez $3, TAG139
mthi $3
slti $4, $3, 10
mfhi $1
TAG139:
sll $0, $0, 0
mfhi $3
mtlo $1
blez $1, TAG140
TAG140:
and $3, $3, $3
lui $4, 13
mflo $4
multu $3, $4
TAG141:
div $4, $4
mflo $3
sb $4, 0($3)
mthi $3
TAG142:
div $3, $3
mflo $2
mfhi $4
bne $4, $2, TAG143
TAG143:
multu $4, $4
lui $3, 7
sw $4, 0($4)
lui $1, 1
TAG144:
sll $0, $0, 0
nor $4, $1, $1
lui $4, 7
sll $0, $0, 0
TAG145:
bne $4, $4, TAG146
addiu $4, $4, 6
lui $4, 0
mfhi $1
TAG146:
lui $1, 13
or $4, $1, $1
srlv $2, $1, $4
sll $0, $0, 0
TAG147:
sll $0, $0, 0
bgtz $2, TAG148
mtlo $2
sllv $4, $2, $2
TAG148:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
slt $2, $4, $4
TAG149:
lui $3, 10
mtlo $3
beq $3, $3, TAG150
mflo $3
TAG150:
mtlo $3
and $4, $3, $3
sltu $2, $3, $4
multu $2, $2
TAG151:
sh $2, 0($2)
mflo $1
mthi $1
sll $1, $2, 3
TAG152:
sltiu $2, $1, 10
bgtz $1, TAG153
mtlo $2
slti $2, $1, 15
TAG153:
bltz $2, TAG154
mtlo $2
lbu $4, 0($2)
srav $3, $2, $4
TAG154:
mthi $3
blez $3, TAG155
mfhi $1
bne $3, $1, TAG155
TAG155:
lui $2, 13
mthi $1
mtlo $1
beq $1, $1, TAG156
TAG156:
xori $1, $2, 7
lui $1, 7
sll $0, $0, 0
addiu $2, $1, 12
TAG157:
beq $2, $2, TAG158
div $2, $2
subu $1, $2, $2
multu $2, $1
TAG158:
sll $0, $0, 0
sll $0, $0, 0
lui $4, 15
ori $3, $4, 8
TAG159:
multu $3, $3
sll $0, $0, 0
lui $1, 3
lui $3, 0
TAG160:
sub $1, $3, $3
multu $3, $1
sb $1, 0($1)
mtlo $1
TAG161:
sh $1, 0($1)
multu $1, $1
bltz $1, TAG162
lui $2, 11
TAG162:
sll $0, $0, 0
lui $2, 4
lui $4, 6
mult $2, $2
TAG163:
sll $0, $0, 0
sll $0, $0, 0
multu $2, $2
divu $4, $4
TAG164:
sll $0, $0, 0
mtlo $2
sll $0, $0, 0
bltz $2, TAG165
TAG165:
mflo $4
sll $0, $0, 0
bgtz $4, TAG166
lui $4, 2
TAG166:
bne $4, $4, TAG167
mult $4, $4
bne $4, $4, TAG167
lui $4, 7
TAG167:
xori $4, $4, 7
sll $0, $0, 0
sll $0, $0, 0
mflo $1
TAG168:
bltz $1, TAG169
sb $1, 0($1)
multu $1, $1
lbu $3, 0($1)
TAG169:
mflo $1
multu $3, $3
sh $1, 0($3)
mflo $2
TAG170:
sh $2, 0($2)
mtlo $2
slti $1, $2, 3
beq $2, $2, TAG171
TAG171:
andi $1, $1, 6
srl $2, $1, 6
subu $3, $1, $2
lh $2, 0($2)
TAG172:
mthi $2
multu $2, $2
lw $3, 0($2)
srlv $3, $2, $2
TAG173:
beq $3, $3, TAG174
lui $4, 14
mflo $4
bgtz $3, TAG174
TAG174:
multu $4, $4
sll $0, $0, 0
mtlo $4
srlv $3, $4, $4
TAG175:
divu $3, $3
multu $3, $3
divu $3, $3
mtlo $3
TAG176:
bne $3, $3, TAG177
divu $3, $3
beq $3, $3, TAG177
multu $3, $3
TAG177:
sll $0, $0, 0
bgez $3, TAG178
mflo $1
lw $4, 0($3)
TAG178:
mflo $1
lui $4, 4
bltz $4, TAG179
divu $1, $4
TAG179:
mtlo $4
or $1, $4, $4
sll $0, $0, 0
sll $3, $4, 4
TAG180:
mthi $3
sll $0, $0, 0
lui $1, 14
mtlo $3
TAG181:
sltiu $1, $1, 8
sll $2, $1, 12
multu $1, $1
bne $2, $1, TAG182
TAG182:
andi $4, $2, 9
sra $1, $2, 4
addu $2, $4, $4
sra $1, $2, 5
TAG183:
mflo $2
lui $2, 2
mthi $1
bltz $2, TAG184
TAG184:
sll $0, $0, 0
sll $4, $2, 7
multu $2, $4
mtlo $4
TAG185:
and $2, $4, $4
div $4, $4
sllv $2, $4, $4
beq $2, $4, TAG186
TAG186:
addiu $2, $2, 6
andi $3, $2, 10
bgtz $2, TAG187
mflo $4
TAG187:
lui $4, 8
bne $4, $4, TAG188
sll $0, $0, 0
sll $0, $0, 0
TAG188:
slti $3, $4, 1
mult $3, $4
sw $4, 0($3)
srlv $1, $4, $3
TAG189:
multu $1, $1
lui $1, 13
sll $0, $0, 0
mthi $1
TAG190:
bltz $1, TAG191
sltu $4, $1, $1
mult $1, $4
div $1, $1
TAG191:
lhu $2, 0($4)
lui $2, 2
lui $2, 1
multu $2, $2
TAG192:
mfhi $3
sll $0, $0, 0
multu $1, $1
srlv $2, $2, $3
TAG193:
bgez $2, TAG194
mflo $1
lui $4, 10
bgez $2, TAG194
TAG194:
addu $2, $4, $4
beq $4, $2, TAG195
multu $4, $2
beq $2, $2, TAG195
TAG195:
sra $1, $2, 12
lui $1, 2
sll $0, $0, 0
lui $4, 14
TAG196:
mthi $4
sra $1, $4, 7
bgtz $1, TAG197
mthi $4
TAG197:
divu $1, $1
mtlo $1
lui $3, 15
lui $2, 5
TAG198:
subu $1, $2, $2
bgtz $2, TAG199
mult $2, $2
lh $4, 0($1)
TAG199:
mthi $4
lui $1, 7
ori $1, $4, 0
bltz $1, TAG200
TAG200:
mthi $1
multu $1, $1
sra $3, $1, 13
divu $3, $1
TAG201:
bgtz $3, TAG202
slt $3, $3, $3
sw $3, 0($3)
slt $3, $3, $3
TAG202:
lb $3, 0($3)
lb $4, 0($3)
bgtz $4, TAG203
lui $2, 11
TAG203:
mflo $1
mtlo $1
mfhi $4
sh $4, 0($4)
TAG204:
mtlo $4
mflo $1
nor $4, $4, $1
beq $4, $1, TAG205
TAG205:
mtlo $4
srlv $2, $4, $4
lhu $4, 113($4)
blez $4, TAG206
TAG206:
sll $2, $4, 0
sb $2, 0($2)
bgtz $2, TAG207
lw $2, 0($4)
TAG207:
lui $1, 8
mflo $4
srav $2, $2, $2
sll $0, $0, 0
TAG208:
mtlo $2
sra $4, $2, 14
sll $0, $0, 0
sb $4, 0($4)
TAG209:
mult $4, $4
lui $4, 15
srl $1, $4, 11
mfhi $4
TAG210:
mfhi $2
subu $1, $2, $4
sh $2, 0($2)
lui $2, 14
TAG211:
lui $4, 4
lui $3, 10
bgez $4, TAG212
mthi $2
TAG212:
sll $0, $0, 0
multu $2, $2
divu $3, $3
mtlo $2
TAG213:
lui $2, 4
div $2, $2
mfhi $3
sub $2, $2, $3
TAG214:
multu $2, $2
lui $1, 0
lb $1, 0($1)
mflo $2
TAG215:
xori $3, $2, 14
mfhi $2
bne $3, $2, TAG216
mthi $2
TAG216:
sll $2, $2, 1
sb $2, 0($2)
mflo $1
sh $1, 0($2)
TAG217:
mfhi $4
lui $2, 15
bgtz $1, TAG218
lw $3, 0($4)
TAG218:
beq $3, $3, TAG219
sll $3, $3, 10
or $2, $3, $3
mthi $2
TAG219:
andi $2, $2, 2
bltz $2, TAG220
srl $4, $2, 11
sllv $2, $2, $4
TAG220:
lui $4, 6
bne $2, $2, TAG221
multu $4, $2
bgtz $4, TAG221
TAG221:
sll $0, $0, 0
lui $1, 0
bgtz $4, TAG222
lui $1, 1
TAG222:
mflo $3
mtlo $1
sll $3, $1, 8
sltiu $2, $3, 2
TAG223:
multu $2, $2
bgez $2, TAG224
lui $1, 7
mflo $2
TAG224:
and $3, $2, $2
lui $3, 9
mflo $2
bne $2, $2, TAG225
TAG225:
lui $3, 10
mflo $4
lui $1, 14
sll $0, $0, 0
TAG226:
beq $4, $4, TAG227
multu $4, $4
or $4, $4, $4
bltz $4, TAG227
TAG227:
lui $1, 13
andi $3, $1, 3
lh $2, 0($3)
bne $4, $2, TAG228
TAG228:
lui $3, 13
beq $2, $2, TAG229
lui $4, 12
xori $3, $3, 11
TAG229:
sra $2, $3, 2
multu $2, $3
mtlo $2
mthi $2
TAG230:
bne $2, $2, TAG231
sltiu $2, $2, 0
beq $2, $2, TAG231
mthi $2
TAG231:
sb $2, 0($2)
sw $2, 0($2)
mfhi $3
subu $4, $3, $2
TAG232:
sh $4, 0($4)
mfhi $2
mthi $4
sltiu $1, $4, 1
TAG233:
sra $1, $1, 2
multu $1, $1
sb $1, 0($1)
sltiu $1, $1, 11
TAG234:
srlv $1, $1, $1
mult $1, $1
lh $4, 0($1)
mult $1, $1
TAG235:
mthi $4
multu $4, $4
sb $4, 0($4)
lh $3, 0($4)
TAG236:
lbu $2, 0($3)
lw $2, 0($2)
lui $1, 10
mthi $1
TAG237:
andi $3, $1, 1
ori $2, $3, 9
mflo $1
lui $4, 14
TAG238:
divu $4, $4
beq $4, $4, TAG239
sll $0, $0, 0
mtlo $1
TAG239:
mtlo $1
lb $4, 0($1)
multu $4, $4
lui $2, 3
TAG240:
div $2, $2
sll $0, $0, 0
bne $2, $2, TAG241
mult $2, $2
TAG241:
lui $4, 3
slti $1, $4, 11
div $1, $2
mult $1, $4
TAG242:
or $1, $1, $1
lhu $3, 0($1)
mthi $1
beq $1, $3, TAG243
TAG243:
multu $3, $3
bgtz $3, TAG244
mfhi $2
bgez $2, TAG244
TAG244:
mtlo $2
lui $2, 15
bgez $2, TAG245
lui $1, 4
TAG245:
bne $1, $1, TAG246
or $4, $1, $1
mflo $2
mfhi $3
TAG246:
mtlo $3
mult $3, $3
xor $4, $3, $3
mflo $1
TAG247:
sltiu $1, $1, 8
mthi $1
mtlo $1
lb $2, 0($1)
TAG248:
xori $2, $2, 2
bgtz $2, TAG249
srav $1, $2, $2
lhu $4, 0($2)
TAG249:
multu $4, $4
mtlo $4
sh $4, 0($4)
lui $3, 3
TAG250:
mult $3, $3
sra $4, $3, 6
ori $4, $4, 4
lui $4, 9
TAG251:
div $4, $4
mult $4, $4
div $4, $4
sll $0, $0, 0
TAG252:
bgtz $4, TAG253
mflo $3
mfhi $1
mfhi $3
TAG253:
lui $4, 15
mfhi $3
mult $4, $3
srl $1, $3, 5
TAG254:
mult $1, $1
add $1, $1, $1
mult $1, $1
mthi $1
TAG255:
multu $1, $1
lui $1, 8
nor $2, $1, $1
sltiu $4, $2, 9
TAG256:
lw $2, 0($4)
bne $4, $2, TAG257
sh $2, 0($2)
add $2, $2, $2
TAG257:
sb $2, 0($2)
lbu $4, 0($2)
sh $2, 0($2)
beq $4, $2, TAG258
TAG258:
sh $4, 0($4)
bgtz $4, TAG259
lui $3, 4
lui $1, 6
TAG259:
beq $1, $1, TAG260
lui $4, 14
bgez $4, TAG260
sb $4, 0($4)
TAG260:
mult $4, $4
sll $0, $0, 0
sll $0, $0, 0
mfhi $3
TAG261:
slt $1, $3, $3
lb $2, -196($3)
sllv $3, $2, $1
lw $3, 0($3)
TAG262:
blez $3, TAG263
slti $4, $3, 0
lui $1, 8
bgez $4, TAG263
TAG263:
mthi $1
sb $1, 0($1)
addiu $1, $1, 4
blez $1, TAG264
TAG264:
mfhi $2
mfhi $3
sltiu $2, $3, 4
addiu $3, $2, 1
TAG265:
lui $4, 10
sltu $3, $4, $4
multu $3, $3
sh $3, 0($3)
TAG266:
lbu $2, 0($3)
mfhi $3
sw $3, 0($3)
lui $4, 12
TAG267:
bne $4, $4, TAG268
sll $1, $4, 5
slt $2, $4, $1
mflo $1
TAG268:
slti $4, $1, 13
slt $3, $1, $1
lui $1, 0
addi $2, $1, 15
TAG269:
lui $2, 9
lui $3, 5
bgtz $3, TAG270
sll $0, $0, 0
TAG270:
div $3, $3
mflo $3
sb $3, 0($3)
beq $3, $3, TAG271
TAG271:
lbu $3, 0($3)
blez $3, TAG272
srlv $2, $3, $3
sh $3, 0($2)
TAG272:
mfhi $4
beq $2, $4, TAG273
sll $1, $4, 1
multu $2, $1
TAG273:
sh $1, 0($1)
slti $3, $1, 10
mthi $3
slti $1, $1, 1
TAG274:
srl $2, $1, 4
lui $4, 11
mflo $4
mflo $1
TAG275:
lbu $2, 0($1)
lui $3, 10
mflo $2
or $2, $2, $3
TAG276:
sll $0, $0, 0
addiu $2, $2, 5
bltz $2, TAG277
addu $4, $2, $2
TAG277:
beq $4, $4, TAG278
mult $4, $4
bgez $4, TAG278
div $4, $4
TAG278:
mfhi $2
bne $2, $2, TAG279
mflo $2
beq $2, $2, TAG279
TAG279:
mtlo $2
or $2, $2, $2
blez $2, TAG280
lui $3, 2
TAG280:
sll $0, $0, 0
bgez $3, TAG281
nor $3, $3, $3
add $4, $3, $3
TAG281:
bltz $4, TAG282
lui $2, 3
multu $2, $4
slti $2, $2, 4
TAG282:
mtlo $2
blez $2, TAG283
slt $4, $2, $2
multu $4, $4
TAG283:
addiu $4, $4, 11
lui $2, 8
beq $4, $2, TAG284
lui $2, 1
TAG284:
addiu $4, $2, 1
sll $0, $0, 0
lui $1, 5
sll $0, $0, 0
TAG285:
sll $0, $0, 0
mfhi $4
mult $4, $1
multu $1, $4
TAG286:
mthi $4
mtlo $4
div $4, $4
mflo $3
TAG287:
lb $2, 0($3)
sh $2, 0($2)
sra $2, $3, 12
lui $2, 4
TAG288:
ori $2, $2, 6
bne $2, $2, TAG289
lui $1, 6
mflo $4
TAG289:
mult $4, $4
lui $2, 1
mtlo $4
mtlo $4
TAG290:
bgtz $2, TAG291
xori $4, $2, 8
bltz $4, TAG291
lhu $2, 0($2)
TAG291:
sll $0, $0, 0
mflo $2
sb $2, 0($2)
sb $2, 0($2)
TAG292:
bgez $2, TAG293
lbu $3, 0($2)
blez $2, TAG293
lh $2, 0($3)
TAG293:
mtlo $2
divu $2, $2
lbu $3, 0($2)
mflo $4
TAG294:
multu $4, $4
div $4, $4
lui $4, 11
sll $0, $0, 0
TAG295:
sltu $4, $3, $3
lbu $1, 0($4)
or $1, $4, $3
divu $4, $3
TAG296:
ori $1, $1, 4
beq $1, $1, TAG297
mflo $1
multu $1, $1
TAG297:
addiu $3, $1, 0
bne $1, $1, TAG298
srlv $3, $3, $1
mflo $2
TAG298:
lw $3, 0($2)
mtlo $3
mult $3, $2
lhu $4, 0($2)
TAG299:
sll $0, $0, 0
mtlo $4
blez $4, TAG300
mflo $1
TAG300:
bne $1, $1, TAG301
sllv $4, $1, $1
mflo $2
lbu $2, -256($1)
TAG301:
bgtz $2, TAG302
mult $2, $2
bgez $2, TAG302
sb $2, 0($2)
TAG302:
srlv $1, $2, $2
bgez $1, TAG303
sh $2, 0($2)
bgtz $1, TAG303
TAG303:
mtlo $1
multu $1, $1
sb $1, 0($1)
mtlo $1
TAG304:
bne $1, $1, TAG305
multu $1, $1
bne $1, $1, TAG305
sb $1, 0($1)
TAG305:
mult $1, $1
lh $3, 0($1)
lui $1, 3
sra $1, $1, 11
TAG306:
mfhi $4
bne $1, $4, TAG307
sw $1, 0($1)
sltu $3, $1, $4
TAG307:
mtlo $3
mthi $3
lbu $4, 0($3)
lui $2, 13
TAG308:
bgez $2, TAG309
mult $2, $2
mult $2, $2
lui $3, 2
TAG309:
mthi $3
ori $2, $3, 14
blez $3, TAG310
multu $3, $2
TAG310:
lbu $3, 0($2)
lh $2, 0($3)
lw $3, 0($3)
blez $3, TAG311
TAG311:
mthi $3
mult $3, $3
mflo $4
slti $2, $4, 7
TAG312:
mtlo $2
mtlo $2
bgtz $2, TAG313
sb $2, 0($2)
TAG313:
lui $4, 1
or $1, $2, $4
addiu $4, $4, 5
mthi $1
TAG314:
mflo $2
xor $3, $2, $4
mtlo $2
and $1, $4, $4
TAG315:
andi $1, $1, 4
divu $1, $1
lui $1, 14
xor $2, $1, $1
TAG316:
lb $4, 0($2)
lui $2, 1
addu $3, $4, $2
bne $3, $4, TAG317
TAG317:
mfhi $1
bgtz $1, TAG318
mtlo $1
lui $2, 14
TAG318:
bne $2, $2, TAG319
mtlo $2
div $2, $2
sltu $4, $2, $2
TAG319:
sra $2, $4, 6
xor $2, $4, $4
andi $4, $4, 9
lui $4, 8
TAG320:
bne $4, $4, TAG321
addu $2, $4, $4
lui $2, 10
lui $1, 11
TAG321:
sll $0, $0, 0
lui $1, 10
mthi $1
mtlo $1
TAG322:
mflo $1
mfhi $2
sll $0, $0, 0
blez $1, TAG323
TAG323:
divu $2, $2
multu $2, $2
div $2, $2
slt $3, $2, $2
TAG324:
lui $1, 2
div $1, $1
mtlo $1
bne $3, $3, TAG325
TAG325:
mtlo $1
sll $0, $0, 0
mthi $1
xori $2, $1, 5
TAG326:
lui $2, 15
mfhi $4
mflo $2
sll $0, $0, 0
TAG327:
mfhi $3
divu $1, $3
bne $1, $1, TAG328
sll $0, $0, 0
TAG328:
bne $3, $3, TAG329
sll $0, $0, 0
sll $0, $0, 0
and $1, $3, $3
TAG329:
sll $0, $0, 0
mtlo $1
mtlo $1
addiu $4, $1, 1
TAG330:
bgez $4, TAG331
slti $2, $4, 13
lui $3, 11
sh $2, 0($2)
TAG331:
subu $3, $3, $3
lui $4, 13
lb $1, 0($3)
bltz $4, TAG332
TAG332:
mflo $4
sll $0, $0, 0
mthi $4
mfhi $3
TAG333:
mthi $3
andi $4, $3, 3
mflo $2
sh $4, 0($4)
TAG334:
sll $0, $0, 0
xor $1, $2, $2
sll $0, $0, 0
lui $4, 5
TAG335:
addu $4, $4, $4
mult $4, $4
bgez $4, TAG336
sll $0, $0, 0
TAG336:
sll $0, $0, 0
bltz $2, TAG337
mthi $2
mflo $4
TAG337:
bne $4, $4, TAG338
lbu $4, 0($4)
bne $4, $4, TAG338
sra $3, $4, 10
TAG338:
lbu $3, 0($3)
sw $3, 0($3)
beq $3, $3, TAG339
multu $3, $3
TAG339:
mult $3, $3
mtlo $3
lui $4, 8
addu $1, $3, $4
TAG340:
andi $2, $1, 9
sb $2, 0($2)
multu $1, $2
mthi $2
TAG341:
blez $2, TAG342
sllv $3, $2, $2
beq $2, $2, TAG342
lui $4, 5
TAG342:
multu $4, $4
addiu $1, $4, 7
blez $1, TAG343
sll $0, $0, 0
TAG343:
mflo $3
sltiu $1, $4, 3
srav $2, $1, $4
lui $3, 5
TAG344:
lui $1, 4
bne $3, $3, TAG345
sll $0, $0, 0
divu $1, $3
TAG345:
lui $2, 14
bltz $2, TAG346
lui $4, 12
bgtz $2, TAG346
TAG346:
addiu $3, $4, 6
srl $2, $4, 6
bne $2, $2, TAG347
subu $4, $3, $2
TAG347:
srl $3, $4, 8
div $4, $3
mflo $1
sltiu $1, $3, 0
TAG348:
mflo $3
mfhi $4
sh $1, 0($4)
multu $1, $1
TAG349:
sra $3, $4, 1
mfhi $1
bgtz $1, TAG350
subu $3, $3, $3
TAG350:
xori $1, $3, 11
subu $3, $1, $3
lbu $4, 0($3)
lb $3, 0($3)
TAG351:
bltz $3, TAG352
mtlo $3
sll $3, $3, 10
mult $3, $3
TAG352:
sra $4, $3, 15
or $4, $4, $3
multu $4, $3
mflo $1
TAG353:
blez $1, TAG354
lb $1, 0($1)
blez $1, TAG354
sltiu $2, $1, 8
TAG354:
sll $0, $0, 0
addiu $2, $3, 6
lui $1, 1
sh $1, 0($2)
TAG355:
mthi $1
beq $1, $1, TAG356
lui $3, 13
mthi $3
TAG356:
lui $3, 9
mult $3, $3
slt $4, $3, $3
sw $3, 0($4)
TAG357:
lui $2, 8
bltz $4, TAG358
slti $2, $4, 1
mthi $2
TAG358:
bne $2, $2, TAG359
slt $2, $2, $2
lui $1, 13
mthi $2
TAG359:
mflo $2
lui $4, 7
sll $0, $0, 0
lh $3, 0($2)
TAG360:
mtlo $3
beq $3, $3, TAG361
lbu $4, 0($3)
mtlo $4
TAG361:
mfhi $3
bgez $4, TAG362
lhu $3, 0($4)
srlv $1, $3, $3
TAG362:
addiu $4, $1, 12
bne $1, $1, TAG363
mflo $3
srl $3, $3, 6
TAG363:
mtlo $3
sb $3, 0($3)
bne $3, $3, TAG364
slti $3, $3, 14
TAG364:
lbu $1, 0($3)
multu $1, $1
lui $2, 7
mflo $1
TAG365:
multu $1, $1
xor $4, $1, $1
sltiu $3, $4, 5
mult $3, $1
TAG366:
bgez $3, TAG367
div $3, $3
mflo $2
bgtz $2, TAG367
TAG367:
ori $4, $2, 4
sll $0, $0, 0
sltu $1, $2, $4
addu $1, $1, $1
TAG368:
div $1, $1
blez $1, TAG369
lui $4, 15
beq $4, $4, TAG369
TAG369:
mtlo $4
sll $0, $0, 0
beq $4, $4, TAG370
sll $0, $0, 0
TAG370:
beq $4, $4, TAG371
mfhi $1
mtlo $4
lui $1, 3
TAG371:
bgez $1, TAG372
mtlo $1
mfhi $3
multu $3, $3
TAG372:
lb $4, 0($3)
lui $1, 3
blez $3, TAG373
lw $3, 0($4)
TAG373:
divu $3, $3
lui $1, 9
sll $0, $0, 0
xori $1, $2, 15
TAG374:
sll $0, $0, 0
sll $0, $0, 0
div $3, $3
multu $1, $1
TAG375:
sll $0, $0, 0
bne $3, $3, TAG376
subu $4, $3, $3
bltz $4, TAG376
TAG376:
multu $4, $4
bne $4, $4, TAG377
mfhi $3
mtlo $4
TAG377:
lui $1, 12
sll $0, $0, 0
xori $2, $3, 4
sll $0, $0, 0
TAG378:
lw $4, 0($3)
sll $1, $3, 13
lbu $1, 0($1)
mthi $1
TAG379:
beq $1, $1, TAG380
sll $1, $1, 9
mtlo $1
mfhi $3
TAG380:
bgtz $3, TAG381
mtlo $3
and $4, $3, $3
bltz $3, TAG381
TAG381:
nor $3, $4, $4
xor $1, $3, $3
bltz $4, TAG382
lw $4, 1($3)
TAG382:
beq $4, $4, TAG383
mfhi $4
sllv $4, $4, $4
lui $3, 6
TAG383:
bne $3, $3, TAG384
ori $3, $3, 11
multu $3, $3
mfhi $1
TAG384:
sh $1, 2($1)
mfhi $3
addu $1, $1, $1
lh $3, 2($3)
TAG385:
mthi $3
blez $3, TAG386
mtlo $3
mtlo $3
TAG386:
beq $3, $3, TAG387
sw $3, 2($3)
mflo $1
mthi $1
TAG387:
mtlo $1
beq $1, $1, TAG388
mtlo $1
andi $3, $1, 10
TAG388:
sltiu $2, $3, 10
lh $2, 2($3)
bltz $2, TAG389
sll $1, $2, 12
TAG389:
bne $1, $1, TAG390
lb $4, 8192($1)
multu $1, $4
mfhi $2
TAG390:
mthi $2
bgtz $2, TAG391
multu $2, $2
lui $1, 7
TAG391:
slti $1, $1, 12
lui $1, 0
lui $1, 9
bne $1, $1, TAG392
TAG392:
lui $1, 3
sll $0, $0, 0
beq $1, $1, TAG393
mflo $3
TAG393:
addiu $1, $3, 10
beq $1, $1, TAG394
sll $0, $0, 0
mflo $2
TAG394:
multu $2, $2
addiu $2, $2, 14
divu $2, $2
bne $2, $2, TAG395
TAG395:
sh $2, 8180($2)
lw $3, 8180($2)
mtlo $3
sb $3, 8180($3)
TAG396:
sll $0, $0, 0
divu $2, $2
bgtz $3, TAG397
divu $2, $3
TAG397:
sh $2, 8180($2)
bne $2, $2, TAG398
mtlo $2
beq $2, $2, TAG398
TAG398:
mfhi $1
lbu $4, 0($1)
blez $1, TAG399
lhu $3, 0($4)
TAG399:
srl $4, $3, 0
sb $4, 0($3)
bgez $3, TAG400
mflo $2
TAG400:
div $2, $2
mflo $2
bgez $2, TAG401
mfhi $2
TAG401:
bgez $2, TAG402
sw $2, 0($2)
mfhi $4
sra $3, $4, 13
TAG402:
div $3, $3
mflo $1
bltz $3, TAG403
lui $3, 9
TAG403:
sll $0, $0, 0
blez $3, TAG404
slti $1, $3, 14
sllv $1, $3, $3
TAG404:
mthi $1
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG405:
mult $1, $1
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG406:
divu $1, $1
divu $1, $1
blez $1, TAG407
sll $0, $0, 0
TAG407:
sll $0, $0, 0
div $3, $1
sltu $3, $1, $1
lb $3, 0($3)
TAG408:
lh $1, 0($3)
mthi $3
beq $1, $3, TAG409
subu $2, $1, $1
TAG409:
xori $1, $2, 13
mtlo $1
mtlo $2
bgez $1, TAG410
TAG410:
mthi $1
addiu $2, $1, 2
sb $1, 0($2)
mtlo $2
TAG411:
mtlo $2
mfhi $1
mtlo $1
lbu $4, 0($1)
TAG412:
mfhi $1
mflo $2
multu $1, $1
bltz $4, TAG413
TAG413:
mthi $2
mflo $4
mfhi $4
mtlo $4
TAG414:
bne $4, $4, TAG415
xori $1, $4, 1
lbu $2, 0($4)
lh $1, 0($2)
TAG415:
mfhi $3
mthi $1
mfhi $1
lui $3, 15
TAG416:
bgez $3, TAG417
mflo $1
bne $1, $3, TAG417
mflo $3
TAG417:
bne $3, $3, TAG418
addu $2, $3, $3
bne $3, $2, TAG418
multu $3, $3
TAG418:
bgtz $2, TAG419
sll $0, $0, 0
andi $3, $2, 5
beq $3, $2, TAG419
TAG419:
mfhi $3
sh $3, -225($3)
mfhi $1
multu $3, $3
TAG420:
mfhi $2
srav $3, $2, $2
mult $1, $3
mtlo $1
TAG421:
ori $3, $3, 15
lb $2, 0($3)
multu $3, $3
bne $3, $2, TAG422
TAG422:
mult $2, $2
lb $3, 0($2)
beq $2, $3, TAG423
lbu $3, 0($2)
TAG423:
mult $3, $3
multu $3, $3
and $1, $3, $3
sltiu $1, $3, 3
TAG424:
mtlo $1
lui $1, 10
or $2, $1, $1
mfhi $4
TAG425:
lui $4, 0
mtlo $4
lui $4, 7
divu $4, $4
TAG426:
mtlo $4
sll $0, $0, 0
sll $0, $0, 0
mflo $1
TAG427:
mflo $2
sra $2, $2, 15
nor $4, $2, $1
mult $1, $4
TAG428:
div $4, $4
sll $0, $0, 0
sll $0, $0, 0
div $4, $4
TAG429:
sll $0, $0, 0
andi $4, $4, 10
blez $4, TAG430
ori $3, $4, 0
TAG430:
bgez $3, TAG431
sh $3, 0($3)
bgtz $3, TAG431
sh $3, 0($3)
TAG431:
sw $3, 0($3)
beq $3, $3, TAG432
multu $3, $3
divu $3, $3
TAG432:
or $1, $3, $3
mult $3, $3
lui $3, 6
mfhi $2
TAG433:
lhu $4, 0($2)
andi $4, $4, 11
bltz $4, TAG434
mult $4, $4
TAG434:
bgez $4, TAG435
lw $2, 0($4)
sra $4, $2, 14
beq $4, $4, TAG435
TAG435:
sub $3, $4, $4
bgez $4, TAG436
lhu $3, 0($4)
divu $4, $4
TAG436:
mthi $3
mfhi $4
bne $3, $3, TAG437
mflo $1
TAG437:
mflo $1
sb $1, 0($1)
lh $4, 0($1)
xori $1, $1, 6
TAG438:
srlv $1, $1, $1
addi $1, $1, 0
sb $1, 0($1)
mflo $3
TAG439:
bltz $3, TAG440
mthi $3
lb $4, 0($3)
lui $2, 13
TAG440:
srav $1, $2, $2
multu $1, $1
sll $0, $0, 0
mfhi $1
TAG441:
beq $1, $1, TAG442
sb $1, -169($1)
mflo $2
mtlo $2
TAG442:
mtlo $2
div $2, $2
xor $3, $2, $2
lui $3, 11
TAG443:
divu $3, $3
bgtz $3, TAG444
mthi $3
slt $4, $3, $3
TAG444:
lb $1, 0($4)
lui $4, 6
sll $0, $0, 0
bne $4, $1, TAG445
TAG445:
nor $3, $2, $2
beq $2, $3, TAG446
sll $0, $0, 0
srlv $3, $2, $2
TAG446:
blez $3, TAG447
sll $0, $0, 0
mult $3, $1
mfhi $3
TAG447:
lui $1, 4
sltiu $1, $3, 10
sh $1, 1($3)
lb $4, 0($1)
TAG448:
mflo $4
srl $1, $4, 13
mfhi $2
lui $1, 2
TAG449:
xori $4, $1, 4
sll $0, $0, 0
sll $0, $0, 0
mtlo $4
TAG450:
lui $3, 15
mflo $1
sll $0, $0, 0
andi $3, $3, 0
TAG451:
multu $3, $3
sb $3, 0($3)
srav $1, $3, $3
beq $3, $3, TAG452
TAG452:
lbu $2, 0($1)
mtlo $2
mult $2, $1
blez $2, TAG453
TAG453:
lui $2, 10
mtlo $2
sll $0, $0, 0
lui $2, 12
TAG454:
mfhi $2
bne $2, $2, TAG455
mtlo $2
blez $2, TAG455
TAG455:
mflo $3
lui $3, 4
mflo $4
lui $2, 14
TAG456:
addu $4, $2, $2
lui $1, 7
lui $1, 4
sll $0, $0, 0
TAG457:
sll $0, $0, 0
mfhi $1
bne $1, $3, TAG458
mflo $1
TAG458:
bltz $1, TAG459
addiu $4, $1, 5
lh $4, 0($1)
nor $1, $1, $1
TAG459:
sll $0, $0, 0
bltz $1, TAG460
mthi $1
blez $1, TAG460
TAG460:
mfhi $1
mtlo $2
mfhi $1
lui $3, 13
TAG461:
bne $3, $3, TAG462
multu $3, $3
mthi $3
beq $3, $3, TAG462
TAG462:
mthi $3
lui $3, 7
andi $3, $3, 3
beq $3, $3, TAG463
TAG463:
sra $2, $3, 12
addi $2, $2, 2
bne $3, $3, TAG464
lh $3, 0($2)
TAG464:
mtlo $3
mtlo $3
sb $3, 0($3)
bgtz $3, TAG465
TAG465:
lui $3, 7
beq $3, $3, TAG466
sll $0, $0, 0
mflo $3
TAG466:
subu $2, $3, $3
mfhi $3
bgtz $3, TAG467
addu $2, $2, $3
TAG467:
mtlo $2
sll $0, $0, 0
sll $0, $0, 0
bne $2, $2, TAG468
TAG468:
divu $2, $2
subu $4, $2, $2
mfhi $4
sll $0, $0, 0
TAG469:
sh $4, 0($4)
blez $4, TAG470
mtlo $4
sb $4, 0($4)
TAG470:
lui $4, 9
lui $3, 13
mflo $2
mthi $4
TAG471:
multu $2, $2
lb $2, 0($2)
lb $4, 0($2)
sllv $4, $2, $2
TAG472:
beq $4, $4, TAG473
mtlo $4
bltz $4, TAG473
xori $3, $4, 3
TAG473:
mthi $3
bne $3, $3, TAG474
mflo $3
mflo $2
TAG474:
mtlo $2
lhu $3, 0($2)
mflo $2
add $1, $3, $3
TAG475:
beq $1, $1, TAG476
mthi $1
bgtz $1, TAG476
xori $2, $1, 7
TAG476:
and $4, $2, $2
add $1, $4, $4
sb $1, 0($1)
mfhi $3
TAG477:
lui $1, 15
mtlo $1
mtlo $1
mflo $1
TAG478:
sll $0, $0, 0
and $3, $4, $4
mult $4, $3
sra $1, $3, 2
TAG479:
beq $1, $1, TAG480
multu $1, $1
div $1, $1
beq $1, $1, TAG480
TAG480:
srlv $3, $1, $1
srl $3, $1, 1
bne $1, $3, TAG481
addiu $1, $3, 1
TAG481:
lui $3, 13
sll $0, $0, 0
mtlo $3
beq $3, $1, TAG482
TAG482:
mult $3, $3
beq $3, $3, TAG483
mtlo $3
lhu $1, 0($3)
TAG483:
sb $1, 0($1)
sb $1, 0($1)
lui $4, 0
beq $1, $4, TAG484
TAG484:
lui $4, 13
blez $4, TAG485
div $4, $4
mfhi $1
TAG485:
mfhi $3
mtlo $3
or $2, $3, $3
lui $4, 1
TAG486:
lui $1, 4
bne $4, $1, TAG487
xor $4, $1, $4
lw $1, 0($4)
TAG487:
nor $1, $1, $1
sll $0, $0, 0
bltz $1, TAG488
mthi $1
TAG488:
sll $0, $0, 0
sll $0, $0, 0
mtlo $1
blez $1, TAG489
TAG489:
lw $2, 0($3)
sw $2, -256($2)
mfhi $2
divu $3, $2
TAG490:
beq $2, $2, TAG491
sll $0, $0, 0
mult $2, $3
sh $2, 0($3)
TAG491:
bne $3, $3, TAG492
lui $4, 13
mult $3, $3
lui $2, 10
TAG492:
slti $1, $2, 11
mthi $1
sll $0, $0, 0
sll $4, $1, 0
TAG493:
mflo $3
sll $1, $4, 13
nor $3, $4, $1
bltz $4, TAG494
TAG494:
srl $2, $3, 10
mfhi $2
sh $2, 1($3)
mfhi $1
TAG495:
sltiu $1, $1, 10
lbu $1, 0($1)
bne $1, $1, TAG496
mthi $1
TAG496:
sb $1, 0($1)
sb $1, 0($1)
lbu $4, 0($1)
bltz $4, TAG497
TAG497:
sll $4, $4, 8
mtlo $4
subu $1, $4, $4
sh $4, 0($4)
TAG498:
mtlo $1
mflo $1
addi $4, $1, 8
lui $4, 15
TAG499:
ori $2, $4, 9
div $4, $2
bgez $2, TAG500
srav $1, $2, $2
TAG500:
mflo $1
lui $4, 8
mflo $2
mtlo $1
TAG501:
bne $2, $2, TAG502
mfhi $3
bgez $2, TAG502
slti $1, $2, 15
TAG502:
mflo $1
sw $1, 0($1)
beq $1, $1, TAG503
or $4, $1, $1
TAG503:
lui $1, 13
mfhi $1
sll $0, $0, 0
lui $1, 0
TAG504:
ori $1, $1, 12
addu $4, $1, $1
bltz $1, TAG505
sllv $3, $4, $4
TAG505:
blez $3, TAG506
srl $2, $3, 2
sltiu $3, $2, 3
mtlo $3
TAG506:
sub $3, $3, $3
xori $4, $3, 12
blez $3, TAG507
mfhi $3
TAG507:
bltz $3, TAG508
xor $4, $3, $3
lb $1, 0($4)
beq $3, $4, TAG508
TAG508:
lui $1, 14
blez $1, TAG509
mfhi $3
bne $1, $3, TAG509
TAG509:
subu $1, $3, $3
bgez $1, TAG510
lui $4, 4
lui $4, 15
TAG510:
mthi $4
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG511:
sll $0, $0, 0
sll $0, $0, 0
mtlo $3
divu $3, $3
TAG512:
lui $2, 8
sll $0, $0, 0
mflo $1
bne $2, $2, TAG513
TAG513:
mfhi $4
lui $4, 8
sll $0, $0, 0
addiu $4, $4, 3
TAG514:
beq $4, $4, TAG515
mfhi $2
mtlo $4
lui $2, 15
TAG515:
xor $1, $2, $2
multu $1, $1
lui $1, 12
sll $0, $0, 0
TAG516:
sll $0, $0, 0
addu $2, $1, $1
lui $3, 15
sll $0, $0, 0
TAG517:
srlv $3, $3, $3
sll $0, $0, 0
ori $1, $3, 11
div $3, $3
TAG518:
bne $1, $1, TAG519
addiu $4, $1, 12
blez $4, TAG519
sll $0, $0, 0
TAG519:
blez $4, TAG520
slti $3, $4, 9
sw $4, 0($3)
bgtz $4, TAG520
TAG520:
lw $1, 0($3)
mtlo $1
sw $1, 0($3)
addu $1, $3, $3
TAG521:
mtlo $1
mtlo $1
sh $1, 0($1)
blez $1, TAG522
TAG522:
multu $1, $1
mtlo $1
lui $4, 0
lhu $4, 0($4)
TAG523:
lh $4, 0($4)
mtlo $4
beq $4, $4, TAG524
sb $4, 0($4)
TAG524:
bne $4, $4, TAG525
xori $3, $4, 11
lh $1, 0($4)
bgez $3, TAG525
TAG525:
sub $4, $1, $1
srlv $4, $1, $1
subu $3, $4, $4
mtlo $1
TAG526:
multu $3, $3
sh $3, 0($3)
add $3, $3, $3
sh $3, 0($3)
TAG527:
lui $2, 14
bne $2, $2, TAG528
mtlo $2
blez $2, TAG528
TAG528:
xori $1, $2, 13
mult $2, $1
sll $0, $0, 0
beq $2, $2, TAG529
TAG529:
mfhi $4
blez $1, TAG530
slt $2, $4, $1
multu $2, $4
TAG530:
mthi $2
bne $2, $2, TAG531
sltiu $4, $2, 15
lb $4, 0($4)
TAG531:
multu $4, $4
sw $4, 0($4)
sh $4, 0($4)
sh $4, 0($4)
TAG532:
ori $3, $4, 1
mtlo $4
bne $4, $3, TAG533
mthi $4
TAG533:
lb $3, 0($3)
bgtz $3, TAG534
lb $2, 0($3)
mfhi $3
TAG534:
xori $2, $3, 10
sllv $2, $3, $2
lbu $2, 0($3)
sll $2, $2, 13
TAG535:
sb $2, 0($2)
addu $1, $2, $2
xor $4, $2, $2
beq $2, $4, TAG536
TAG536:
srl $2, $4, 8
multu $4, $4
mthi $4
beq $4, $2, TAG537
TAG537:
mfhi $1
bltz $2, TAG538
lui $4, 15
bne $2, $1, TAG538
TAG538:
mfhi $4
lui $1, 5
multu $1, $4
multu $1, $4
TAG539:
lui $4, 6
ori $1, $4, 1
sll $0, $0, 0
divu $1, $4
TAG540:
mthi $4
slt $1, $4, $4
addiu $3, $4, 15
lui $3, 6
TAG541:
mult $3, $3
sll $0, $0, 0
sll $0, $0, 0
lui $3, 8
TAG542:
div $3, $3
bne $3, $3, TAG543
slt $3, $3, $3
blez $3, TAG543
TAG543:
sltu $3, $3, $3
mthi $3
multu $3, $3
lui $3, 1
TAG544:
mtlo $3
subu $4, $3, $3
srav $3, $4, $3
srl $4, $4, 1
TAG545:
bne $4, $4, TAG546
mfhi $1
bgtz $4, TAG546
sw $4, 0($1)
TAG546:
mfhi $2
lui $4, 13
beq $1, $2, TAG547
sra $1, $1, 11
TAG547:
multu $1, $1
lh $4, 0($1)
lui $2, 6
or $2, $2, $4
TAG548:
bne $2, $2, TAG549
sra $4, $2, 13
bgtz $4, TAG549
sll $0, $0, 0
TAG549:
beq $4, $4, TAG550
sh $4, 0($4)
sw $4, 0($4)
lui $1, 10
TAG550:
multu $1, $1
mult $1, $1
bne $1, $1, TAG551
lui $4, 0
TAG551:
sh $4, 0($4)
lui $1, 13
sw $1, 0($4)
mfhi $4
TAG552:
mult $4, $4
sltiu $1, $4, 5
mult $4, $1
mflo $2
TAG553:
beq $2, $2, TAG554
sw $2, 0($2)
lb $1, 0($2)
mfhi $3
TAG554:
bgtz $3, TAG555
addiu $1, $3, 6
divu $1, $1
lb $1, 0($3)
TAG555:
bgtz $1, TAG556
addiu $1, $1, 4
mfhi $3
bgez $1, TAG556
TAG556:
sw $3, 0($3)
bne $3, $3, TAG557
mult $3, $3
sw $3, 0($3)
TAG557:
bne $3, $3, TAG558
lui $3, 12
sll $0, $0, 0
div $3, $3
TAG558:
beq $1, $1, TAG559
lw $3, 0($1)
lui $4, 12
mtlo $3
TAG559:
bgez $4, TAG560
mult $4, $4
mtlo $4
lhu $4, 0($4)
TAG560:
lh $1, 0($4)
bltz $1, TAG561
multu $4, $1
mult $4, $1
TAG561:
mfhi $2
lbu $1, 0($2)
blez $1, TAG562
sub $4, $1, $1
TAG562:
mflo $4
mflo $1
mult $1, $4
mflo $4
TAG563:
mtlo $4
mtlo $4
sh $4, 0($4)
lhu $4, 0($4)
TAG564:
mult $4, $4
blez $4, TAG565
mult $4, $4
add $1, $4, $4
TAG565:
sw $1, 0($1)
bne $1, $1, TAG566
ori $1, $1, 8
and $4, $1, $1
TAG566:
or $2, $4, $4
lbu $2, 0($2)
bne $2, $2, TAG567
mthi $4
TAG567:
lui $1, 13
bltz $1, TAG568
lui $3, 10
sll $0, $0, 0
TAG568:
bgtz $3, TAG569
srlv $1, $3, $3
sra $1, $3, 4
blez $3, TAG569
TAG569:
lui $3, 15
beq $3, $1, TAG570
lui $3, 3
mflo $2
TAG570:
sw $2, 0($2)
bgtz $2, TAG571
lui $1, 0
lh $2, 0($2)
TAG571:
sll $1, $2, 6
sltu $2, $2, $2
add $2, $2, $2
mflo $1
TAG572:
lhu $1, 0($1)
lui $4, 12
mtlo $1
blez $1, TAG573
TAG573:
slti $3, $4, 9
sltu $4, $3, $4
lui $4, 5
mtlo $4
TAG574:
lui $1, 0
mthi $1
sra $2, $4, 14
bltz $2, TAG575
TAG575:
mtlo $2
mult $2, $2
slt $1, $2, $2
mult $2, $1
TAG576:
sltu $4, $1, $1
sh $1, 0($1)
beq $1, $4, TAG577
lui $2, 4
TAG577:
sll $0, $0, 0
sll $0, $0, 0
subu $3, $2, $2
div $2, $2
TAG578:
lw $3, 0($3)
bgez $3, TAG579
sra $4, $3, 9
sh $4, 0($3)
TAG579:
lb $2, 0($4)
beq $2, $4, TAG580
mflo $1
lh $1, 0($4)
TAG580:
lui $1, 7
lui $2, 9
nor $4, $2, $1
sll $0, $0, 0
TAG581:
multu $3, $3
bne $3, $3, TAG582
lui $2, 11
lui $3, 10
TAG582:
bne $3, $3, TAG583
xori $2, $3, 7
nor $3, $3, $3
srav $1, $2, $3
TAG583:
lhu $1, 0($1)
lui $2, 9
beq $1, $2, TAG584
mthi $2
TAG584:
sltu $3, $2, $2
lui $4, 5
lui $2, 11
sllv $4, $2, $2
TAG585:
bne $4, $4, TAG586
sll $0, $0, 0
sll $0, $0, 0
bne $4, $4, TAG586
TAG586:
subu $2, $4, $4
multu $4, $2
sltiu $2, $2, 6
mfhi $4
TAG587:
bne $4, $4, TAG588
sb $4, 0($4)
multu $4, $4
lh $3, 0($4)
TAG588:
sw $3, 0($3)
lh $3, 0($3)
lhu $2, 0($3)
mflo $3
TAG589:
sb $3, 0($3)
lhu $4, 0($3)
lui $3, 12
xori $1, $3, 14
TAG590:
mfhi $3
sb $3, 0($3)
mflo $3
sb $3, 0($3)
TAG591:
mult $3, $3
blez $3, TAG592
lui $2, 15
bne $2, $3, TAG592
TAG592:
sll $0, $0, 0
mflo $3
beq $3, $3, TAG593
mult $3, $3
TAG593:
lw $3, 0($3)
lb $1, 0($3)
mfhi $1
bne $3, $1, TAG594
TAG594:
mflo $3
mtlo $3
lbu $1, 0($3)
bne $3, $1, TAG595
TAG595:
lhu $3, 0($1)
lw $3, 0($1)
sh $3, 0($1)
mflo $4
TAG596:
multu $4, $4
beq $4, $4, TAG597
mthi $4
mthi $4
TAG597:
beq $4, $4, TAG598
xori $3, $4, 2
lh $3, 0($3)
lhu $3, 0($3)
TAG598:
bne $3, $3, TAG599
mtlo $3
bne $3, $3, TAG599
mfhi $2
TAG599:
mthi $2
mflo $2
bgtz $2, TAG600
sb $2, 0($2)
TAG600:
lhu $4, 0($2)
lui $4, 10
lh $3, 0($2)
lui $2, 3
TAG601:
sll $0, $0, 0
addiu $2, $2, 9
mtlo $2
beq $2, $2, TAG602
TAG602:
slti $3, $2, 12
bgez $2, TAG603
or $2, $3, $2
lh $3, 0($2)
TAG603:
sh $3, 0($3)
mthi $3
mult $3, $3
bltz $3, TAG604
TAG604:
or $2, $3, $3
mult $3, $3
bltz $3, TAG605
lw $4, 0($3)
TAG605:
mflo $1
sltiu $2, $1, 9
ori $3, $1, 13
mtlo $4
TAG606:
bgez $3, TAG607
mtlo $3
srav $4, $3, $3
lb $3, 0($4)
TAG607:
slt $1, $3, $3
mflo $3
lb $3, 0($3)
sh $3, 0($3)
TAG608:
multu $3, $3
sw $3, 0($3)
mthi $3
nor $4, $3, $3
TAG609:
div $4, $4
sw $4, 1($4)
lui $2, 8
multu $4, $2
TAG610:
div $2, $2
sll $0, $0, 0
sll $0, $0, 0
addiu $4, $4, 15
TAG611:
sb $4, 0($4)
sh $4, 0($4)
mtlo $4
lui $3, 7
TAG612:
mult $3, $3
bne $3, $3, TAG613
lui $4, 11
beq $3, $4, TAG613
TAG613:
mflo $4
mtlo $4
ori $4, $4, 9
mfhi $1
TAG614:
lb $4, 0($1)
add $2, $4, $4
mtlo $2
lbu $4, 0($1)
TAG615:
multu $4, $4
blez $4, TAG616
nor $3, $4, $4
lui $1, 4
TAG616:
sb $1, 0($1)
lbu $2, 0($1)
mtlo $2
lbu $1, 0($2)
TAG617:
lb $1, 0($1)
mthi $1
bgez $1, TAG618
sb $1, 0($1)
TAG618:
lb $2, 0($1)
mflo $4
mflo $4
addiu $3, $4, 10
TAG619:
blez $3, TAG620
divu $3, $3
mfhi $4
sb $3, 0($3)
TAG620:
bne $4, $4, TAG621
subu $1, $4, $4
mult $4, $1
lb $2, 0($1)
TAG621:
srav $2, $2, $2
mflo $3
lb $1, 1($2)
lhu $4, 1($2)
TAG622:
bltz $4, TAG623
addiu $2, $4, 2
xori $1, $4, 14
multu $1, $4
TAG623:
divu $1, $1
srl $1, $1, 13
divu $1, $1
srl $3, $1, 13
TAG624:
blez $3, TAG625
mflo $2
slti $1, $2, 2
mflo $3
TAG625:
mtlo $3
lh $3, 0($3)
sw $3, 1($3)
bne $3, $3, TAG626
TAG626:
mtlo $3
sltiu $4, $3, 3
lui $1, 0
sllv $1, $1, $1
TAG627:
bne $1, $1, TAG628
mflo $2
lhu $3, 1($2)
mfhi $4
TAG628:
bltz $4, TAG629
lhu $3, 0($4)
mtlo $4
slt $2, $4, $4
TAG629:
mtlo $2
sll $3, $2, 9
bne $2, $2, TAG630
mult $2, $3
TAG630:
lb $3, 0($3)
div $3, $3
mfhi $1
xor $2, $3, $3
TAG631:
mthi $2
sw $2, 0($2)
beq $2, $2, TAG632
xori $4, $2, 1
TAG632:
lb $3, 0($4)
xori $2, $4, 6
bgtz $2, TAG633
lbu $2, 0($3)
TAG633:
nor $4, $2, $2
multu $2, $2
multu $2, $4
slti $4, $4, 5
TAG634:
subu $4, $4, $4
slt $4, $4, $4
lw $3, 0($4)
sh $3, 0($3)
TAG635:
mtlo $3
mult $3, $3
lui $1, 4
lui $1, 9
TAG636:
div $1, $1
mflo $4
mthi $1
sll $0, $0, 0
TAG637:
lui $3, 13
mflo $4
mflo $2
slti $4, $3, 12
TAG638:
lui $2, 1
lui $3, 10
mthi $3
andi $4, $4, 2
TAG639:
mthi $4
bgez $4, TAG640
lb $1, 0($4)
sllv $3, $4, $4
TAG640:
bltz $3, TAG641
mtlo $3
sll $0, $0, 0
srl $2, $3, 5
TAG641:
mfhi $2
mtlo $2
multu $2, $2
mfhi $3
TAG642:
bne $3, $3, TAG643
mthi $3
multu $3, $3
lb $1, 0($3)
TAG643:
mult $1, $1
multu $1, $1
mult $1, $1
srl $4, $1, 0
TAG644:
mfhi $1
sll $3, $1, 6
mflo $4
sw $4, 0($1)
TAG645:
slt $4, $4, $4
bne $4, $4, TAG646
multu $4, $4
sh $4, 0($4)
TAG646:
mult $4, $4
beq $4, $4, TAG647
addi $2, $4, 15
mtlo $4
TAG647:
sb $2, 0($2)
lbu $1, 0($2)
lbu $2, 0($2)
or $2, $1, $1
TAG648:
lb $1, 0($2)
lui $2, 12
lui $2, 4
beq $2, $2, TAG649
TAG649:
lui $2, 2
sll $0, $0, 0
sll $0, $0, 0
lui $2, 1
TAG650:
addu $4, $2, $2
srav $4, $2, $4
lui $4, 1
addiu $1, $4, 2
TAG651:
ori $2, $1, 1
mtlo $2
sll $0, $0, 0
multu $2, $1
TAG652:
nor $2, $2, $2
blez $2, TAG653
mtlo $2
bne $2, $2, TAG653
TAG653:
lui $2, 3
sll $0, $0, 0
mthi $2
bne $2, $2, TAG654
TAG654:
mthi $2
sll $0, $0, 0
bne $4, $2, TAG655
sll $2, $4, 4
TAG655:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG656:
subu $3, $4, $4
lui $2, 12
mflo $4
blez $2, TAG657
TAG657:
sra $1, $4, 0
div $1, $1
divu $1, $4
sll $0, $0, 0
TAG658:
sll $0, $0, 0
mtlo $1
sll $0, $0, 0
mflo $3
TAG659:
xori $3, $3, 15
sra $3, $3, 12
beq $3, $3, TAG660
lui $1, 3
TAG660:
lui $4, 7
lui $4, 4
lui $1, 0
sll $0, $0, 0
TAG661:
mfhi $4
sb $4, 0($4)
lh $2, 0($4)
mfhi $2
TAG662:
mflo $1
sltiu $4, $1, 7
blez $1, TAG663
mult $4, $2
TAG663:
slti $4, $4, 13
xori $1, $4, 7
addiu $1, $4, 7
subu $1, $1, $4
TAG664:
beq $1, $1, TAG665
nor $2, $1, $1
mflo $3
mflo $1
TAG665:
sb $1, 0($1)
lbu $2, 0($1)
sltiu $2, $1, 9
mflo $1
TAG666:
bltz $1, TAG667
lh $1, 0($1)
xor $4, $1, $1
bgtz $4, TAG667
TAG667:
multu $4, $4
blez $4, TAG668
lhu $4, 0($4)
sll $1, $4, 9
TAG668:
mflo $4
srl $2, $4, 0
lbu $4, 0($1)
addi $1, $4, 1
TAG669:
beq $1, $1, TAG670
sb $1, 0($1)
mfhi $3
slti $1, $1, 12
TAG670:
lbu $4, 0($1)
or $2, $4, $1
sb $1, 0($1)
mflo $2
TAG671:
mfhi $2
multu $2, $2
mthi $2
sub $4, $2, $2
TAG672:
bltz $4, TAG673
srav $3, $4, $4
sltiu $1, $3, 3
lbu $4, 0($3)
TAG673:
beq $4, $4, TAG674
mflo $4
sb $4, 0($4)
bgez $4, TAG674
TAG674:
mthi $4
lbu $4, 0($4)
blez $4, TAG675
or $4, $4, $4
TAG675:
multu $4, $4
multu $4, $4
sw $4, 0($4)
mfhi $3
TAG676:
bltz $3, TAG677
lui $2, 5
srl $1, $2, 12
lui $2, 12
TAG677:
ori $4, $2, 0
lui $2, 3
mthi $2
bne $2, $2, TAG678
TAG678:
mthi $2
sll $0, $0, 0
lw $2, 0($1)
add $2, $2, $2
TAG679:
addi $1, $2, 14
mflo $2
bne $1, $2, TAG680
sll $4, $2, 12
TAG680:
lbu $3, 0($4)
bgtz $4, TAG681
xor $4, $3, $4
bne $4, $4, TAG681
TAG681:
lui $4, 4
sll $0, $0, 0
srl $3, $4, 13
sb $4, 0($3)
TAG682:
addu $4, $3, $3
lbu $4, 0($3)
sllv $1, $4, $3
lh $3, 0($4)
TAG683:
mtlo $3
addi $3, $3, 12
slt $2, $3, $3
div $3, $3
TAG684:
ori $1, $2, 12
mthi $1
sw $1, 0($2)
mtlo $1
TAG685:
sh $1, 0($1)
ori $1, $1, 3
lb $4, 0($1)
sb $1, 0($1)
TAG686:
sllv $4, $4, $4
sll $0, $0, 0
lui $4, 4
sltu $1, $4, $4
TAG687:
nor $4, $1, $1
blez $1, TAG688
subu $2, $4, $4
ori $3, $4, 13
TAG688:
sllv $1, $3, $3
nor $1, $3, $1
mflo $3
lui $3, 7
TAG689:
div $3, $3
mfhi $2
mult $2, $3
and $3, $2, $3
TAG690:
addiu $3, $3, 6
beq $3, $3, TAG691
lui $2, 9
divu $2, $3
TAG691:
addiu $3, $2, 10
lui $1, 13
mtlo $1
bgez $3, TAG692
TAG692:
lui $3, 9
mult $3, $1
mult $1, $3
mthi $3
TAG693:
ori $3, $3, 4
sll $0, $0, 0
sltu $2, $3, $3
mflo $4
TAG694:
blez $4, TAG695
lui $1, 13
bne $1, $4, TAG695
lb $1, 0($4)
TAG695:
ori $3, $1, 0
mtlo $1
sll $0, $0, 0
blez $1, TAG696
TAG696:
mfhi $4
sll $0, $0, 0
bne $4, $1, TAG697
mfhi $2
TAG697:
divu $2, $2
addiu $3, $2, 3
sltu $2, $3, $2
bgtz $2, TAG698
TAG698:
sb $2, 0($2)
mtlo $2
bgez $2, TAG699
mtlo $2
TAG699:
mult $2, $2
mfhi $4
mflo $3
lui $1, 15
TAG700:
sll $0, $0, 0
blez $1, TAG701
andi $4, $1, 4
bltz $4, TAG701
TAG701:
sb $4, 0($4)
bltz $4, TAG702
andi $2, $4, 5
sw $4, 0($2)
TAG702:
lh $3, 0($2)
lui $2, 15
addu $4, $2, $2
lui $4, 5
TAG703:
mtlo $4
addiu $4, $4, 14
divu $4, $4
bltz $4, TAG704
TAG704:
sll $0, $0, 0
subu $2, $4, $4
lui $2, 14
sll $0, $0, 0
TAG705:
mfhi $2
mflo $2
and $1, $2, $2
bgez $1, TAG706
TAG706:
div $1, $1
ori $2, $1, 9
mfhi $2
sb $2, 0($1)
TAG707:
sw $2, 0($2)
lh $1, 0($2)
xori $3, $1, 7
lui $1, 3
TAG708:
bne $1, $1, TAG709
lui $1, 3
lui $2, 15
divu $1, $1
TAG709:
addu $4, $2, $2
bne $2, $2, TAG710
sll $0, $0, 0
mflo $2
TAG710:
sb $2, 0($2)
beq $2, $2, TAG711
mthi $2
srl $1, $2, 11
TAG711:
lui $2, 12
mfhi $3
sllv $3, $2, $2
slt $2, $1, $2
TAG712:
divu $2, $2
lui $3, 5
lb $4, 0($2)
multu $2, $2
TAG713:
beq $4, $4, TAG714
mfhi $3
lui $3, 3
lui $2, 15
TAG714:
lb $4, 0($2)
lui $2, 12
sra $2, $4, 7
mtlo $2
TAG715:
mtlo $2
beq $2, $2, TAG716
lb $4, 0($2)
mfhi $1
TAG716:
addu $1, $1, $1
sra $1, $1, 5
blez $1, TAG717
sw $1, -12288($1)
TAG717:
mthi $1
lui $2, 3
beq $2, $2, TAG718
mfhi $4
TAG718:
lui $2, 14
mflo $4
bgez $4, TAG719
multu $4, $2
TAG719:
beq $4, $4, TAG720
or $3, $4, $4
mtlo $4
bne $4, $4, TAG720
TAG720:
mfhi $3
sh $3, 0($3)
bne $3, $3, TAG721
mfhi $1
TAG721:
addu $4, $1, $1
or $4, $1, $4
sb $1, 0($4)
lui $3, 5
TAG722:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
mflo $4
TAG723:
mthi $4
bgtz $4, TAG724
mult $4, $4
multu $4, $4
TAG724:
blez $4, TAG725
mthi $4
sw $4, 0($4)
lui $4, 7
TAG725:
mthi $4
lui $2, 15
addu $2, $4, $2
bne $2, $2, TAG726
TAG726:
xori $3, $2, 8
mfhi $4
bltz $3, TAG727
mtlo $4
TAG727:
sb $4, 0($4)
beq $4, $4, TAG728
sh $4, 0($4)
lui $3, 6
TAG728:
bne $3, $3, TAG729
sll $0, $0, 0
lui $4, 15
bltz $2, TAG729
TAG729:
div $4, $4
bltz $4, TAG730
sll $0, $0, 0
mtlo $2
TAG730:
sll $0, $0, 0
addu $3, $2, $2
bne $3, $3, TAG731
xor $2, $1, $3
TAG731:
slti $3, $2, 11
sra $1, $3, 12
lui $1, 3
sll $0, $0, 0
TAG732:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
beq $4, $4, TAG733
TAG733:
sllv $2, $4, $4
sll $0, $0, 0
mult $2, $2
mthi $4
TAG734:
addu $3, $2, $2
bne $2, $3, TAG735
mthi $2
nor $3, $3, $2
TAG735:
mult $3, $3
divu $3, $3
blez $3, TAG736
sll $0, $0, 0
TAG736:
blez $2, TAG737
sll $0, $0, 0
beq $1, $2, TAG737
mtlo $1
TAG737:
mtlo $1
addu $2, $1, $1
bne $2, $1, TAG738
addu $4, $1, $1
TAG738:
lui $1, 12
multu $4, $1
lui $3, 3
lui $1, 8
TAG739:
mthi $1
bltz $1, TAG740
sll $0, $0, 0
ori $2, $1, 3
TAG740:
sltiu $3, $2, 12
sra $2, $2, 10
mult $3, $3
bne $3, $3, TAG741
TAG741:
sb $2, -512($2)
lhu $2, -512($2)
sw $2, 0($2)
sltiu $3, $2, 7
TAG742:
beq $3, $3, TAG743
mfhi $3
lhu $1, 0($3)
mult $3, $3
TAG743:
nor $1, $1, $1
multu $1, $1
sll $0, $0, 0
sll $0, $0, 0
TAG744:
bgez $1, TAG745
sll $0, $0, 0
mflo $4
multu $1, $4
TAG745:
sll $0, $0, 0
beq $4, $4, TAG746
sll $0, $0, 0
bltz $4, TAG746
TAG746:
lui $2, 8
sll $0, $0, 0
mtlo $4
sll $0, $0, 0
TAG747:
sll $0, $0, 0
addu $1, $2, $2
lui $3, 6
mtlo $1
TAG748:
andi $4, $3, 1
mflo $4
sllv $2, $4, $3
sll $3, $4, 11
TAG749:
divu $3, $3
xori $1, $3, 8
sll $0, $0, 0
sll $0, $0, 0
TAG750:
nop
nop
test_end:
beq $0, $0, test_end
nop |
Transynther/x86/_processed/NONE/_un_/i9-9900K_12_0xa0_notsx.log_1_285.asm | ljhsiun2/medusa | 9 | 172958 | .global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r14
push %r15
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x12b8d, %rsi
lea addresses_normal_ht+0xd4d9, %rdi
nop
nop
nop
nop
and $44031, %r14
mov $60, %rcx
rep movsb
nop
nop
xor $45607, %rsi
lea addresses_UC_ht+0x11e0d, %rcx
clflush (%rcx)
nop
nop
and $9204, %r14
vmovups (%rcx), %ymm5
vextracti128 $1, %ymm5, %xmm5
vpextrq $1, %xmm5, %rbp
nop
nop
nop
xor %r14, %r14
lea addresses_D_ht+0x171d, %rsi
lea addresses_A_ht+0x9cad, %rdi
nop
nop
nop
nop
add %r12, %r12
mov $98, %rcx
rep movsb
nop
sub %r12, %r12
lea addresses_WT_ht+0x1314d, %r14
nop
nop
nop
nop
sub %r10, %r10
movups (%r14), %xmm6
vpextrq $1, %xmm6, %rsi
nop
nop
nop
sub $14956, %rcx
lea addresses_WT_ht+0x4651, %r10
nop
nop
nop
sub $28270, %rdi
mov (%r10), %ecx
dec %rsi
lea addresses_UC_ht+0x3d34, %rsi
sub %r14, %r14
mov $0x6162636465666768, %rdi
movq %rdi, %xmm6
and $0xffffffffffffffc0, %rsi
movaps %xmm6, (%rsi)
nop
nop
nop
nop
add %rbp, %rbp
lea addresses_WT_ht+0x1de0d, %r12
clflush (%r12)
nop
nop
and %rdi, %rdi
movw $0x6162, (%r12)
nop
nop
nop
nop
nop
dec %r12
lea addresses_A_ht+0xc68d, %rsi
lea addresses_D_ht+0xfa0d, %rdi
nop
nop
nop
xor %r15, %r15
mov $38, %rcx
rep movsw
nop
nop
xor $21501, %rdi
lea addresses_WC_ht+0x10e8d, %r12
clflush (%r12)
dec %rcx
mov (%r12), %rdi
nop
inc %rcx
lea addresses_A_ht+0x1760d, %r10
nop
nop
nop
nop
and $47319, %r12
mov (%r10), %ebp
sub $50339, %r15
lea addresses_A_ht+0x7a8d, %r14
nop
nop
nop
nop
nop
cmp $55686, %r15
mov (%r14), %r12w
nop
nop
nop
nop
sub $25661, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %r15
pop %r14
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r8
push %rax
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
// Store
mov $0x72422500000001cd, %r14
nop
nop
cmp $11655, %r8
movl $0x51525354, (%r14)
nop
nop
add $48206, %r8
// Load
lea addresses_UC+0xbffb, %rbp
nop
nop
inc %rdx
mov (%rbp), %r14d
nop
nop
nop
nop
nop
dec %rdx
// REPMOV
lea addresses_PSE+0x1020d, %rsi
lea addresses_WT+0x5411, %rdi
nop
nop
nop
nop
dec %rdx
mov $107, %rcx
rep movsb
nop
nop
inc %rdx
// Store
lea addresses_PSE+0xdd7d, %rdx
nop
nop
nop
nop
nop
and %r13, %r13
movb $0x51, (%rdx)
xor $10388, %rdx
// Store
lea addresses_PSE+0x3f9e, %r14
nop
nop
dec %rax
mov $0x5152535455565758, %rcx
movq %rcx, %xmm4
movups %xmm4, (%r14)
nop
nop
nop
nop
nop
and $41496, %rcx
// Store
lea addresses_PSE+0x10add, %rdx
nop
sub $59632, %rbp
movw $0x5152, (%rdx)
nop
nop
nop
nop
nop
xor $17514, %r14
// Store
lea addresses_PSE+0xfd0d, %rbp
add $60602, %rdx
mov $0x5152535455565758, %r14
movq %r14, %xmm7
movups %xmm7, (%rbp)
and %r14, %r14
// Load
lea addresses_UC+0x1cc61, %r8
xor $52965, %rdx
vmovups (%r8), %ymm3
vextracti128 $0, %ymm3, %xmm3
vpextrq $0, %xmm3, %rdi
nop
nop
add $16755, %r14
// Store
lea addresses_WT+0xf20d, %r13
nop
cmp %rax, %rax
movl $0x51525354, (%r13)
nop
add $21335, %rbp
// Store
lea addresses_UC+0xee0d, %r8
nop
nop
cmp $6718, %r14
movw $0x5152, (%r8)
nop
nop
nop
xor $30285, %r13
// Load
lea addresses_RW+0x160d, %rsi
nop
nop
cmp $8522, %rax
vmovups (%rsi), %ymm7
vextracti128 $0, %ymm7, %xmm7
vpextrq $0, %xmm7, %r8
nop
nop
nop
nop
nop
sub $1016, %rsi
// Store
lea addresses_US+0xb8dd, %r14
nop
sub $32020, %rcx
mov $0x5152535455565758, %r13
movq %r13, (%r14)
nop
nop
nop
nop
nop
sub $2979, %rcx
// Load
lea addresses_RW+0x1b5dc, %rdx
nop
nop
cmp $22358, %r14
mov (%rdx), %r13w
nop
nop
sub %rcx, %rcx
// Faulty Load
lea addresses_UC+0xee0d, %rdx
nop
nop
nop
nop
xor %rax, %rax
movb (%rdx), %cl
lea oracles, %rax
and $0xff, %rcx
shlq $12, %rcx
mov (%rax,%rcx,1), %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r8
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_UC', 'AVXalign': True, 'size': 16, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 2}}
{'src': {'type': 'addresses_UC', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 1}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_PSE', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT', 'congruent': 2, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 4}}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 4}}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 6}}
{'src': {'type': 'addresses_UC', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 10}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'size': 2, 'NT': False, 'same': True, 'congruent': 0}}
{'src': {'type': 'addresses_RW', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 11}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 4}}
{'src': {'type': 'addresses_RW', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_UC', 'AVXalign': False, 'size': 1, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}}
{'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 6}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}}
{'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 6}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 4, 'NT': True, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': True, 'size': 16, 'NT': False, 'same': True, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 11}}
{'src': {'type': 'addresses_A_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}}
{'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 7}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 4, 'NT': True, 'same': False, 'congruent': 11}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': True, 'congruent': 7}, 'OP': 'LOAD'}
{'ef': 1}
ef
*/
|
src/Util/HoTT/Equiv.agda | JLimperg/msc-thesis-code | 5 | 15472 | {-# OPTIONS --without-K --safe #-}
module Util.HoTT.Equiv where
open import Util.HoTT.Equiv.Core public
open import Relation.Binary using (Setoid ; IsEquivalence)
open import Util.Data.Product using (map₂)
open import Util.HoTT.HLevel.Core using (IsContr ; IsProp)
open import Util.HoTT.Section
open import Util.HoTT.Singleton using (IsContr-Singleton)
open import Util.Prelude
open import Util.Relation.Binary.PropositionalEquality using
( Σ-≡⁻ ; Σ-≡⁺ ; trans-symʳ ; trans-unassoc )
private
variable
α β γ : Level
A B C : Set α
IsIso→HasSection-forth : {f : A → B} → IsIso f → HasSection f
IsIso→HasSection-forth i = record
{ section = i .IsIso.back
; isSection = i .IsIso.forth∘back
}
IsIso→HasSection-back : {f : A → B} → (i : IsIso f) → HasSection (i .IsIso.back)
IsIso→HasSection-back {f = f} i = record
{ section = f
; isSection = i .IsIso.back∘forth
}
IsIso→Injective : {f : A → B} → IsIso f → Injective f
IsIso→Injective f-iso fx≡fy
= trans (sym (f-iso .IsIso.back∘forth _))
(trans (cong (f-iso .IsIso.back) fx≡fy)
(f-iso .IsIso.back∘forth _))
IsEquiv→IsIso : {f : A → B} → IsEquiv f → IsIso f
IsEquiv→IsIso {A = A} {B = B} {forth} equiv = record
{ back = back′ ; back∘forth = back∘forth′ ; forth∘back = forth∘back′ }
where
back′ : B → A
back′ b with equiv b
... | (a , _) , _ = a
back∘forth′ : ∀ x → back′ (forth x) ≡ x
back∘forth′ a with equiv (forth a)
... | (a′ , fortha′≡fortha) , unique = proj₁ (Σ-≡⁻ (unique (a , refl)))
forth∘back′ : ∀ x → forth (back′ x) ≡ x
forth∘back′ b with equiv b
... | (a , fortha≡b) , _ = fortha≡b
IsEquiv→Injective : {f : A → B} → IsEquiv f → Injective f
IsEquiv→Injective = IsIso→Injective ∘ IsEquiv→IsIso
-- This proof follows Martin Escardó's lecture notes
-- (https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#fibersandequivalences).
IsIso→IsEquiv : {f : A → B} → IsIso f → IsEquiv f
IsIso→IsEquiv {A = A} {B = B} {forth} iso b
= ◁-pres-IsContr (◁-trans ii iii) IsContr-Singleton
where
module I = IsIso iso
A◁B : A ◁ B
A◁B = record
{ retraction = I.back
; hasSection = IsIso→HasSection-back iso
}
i : ∀ b′ → (forth (I.back b′) ≡ b) ◁ (b′ ≡ b)
i b′ = record
{ retraction = λ b′≡b → trans (I.forth∘back b′) b′≡b
; hasSection = record
{ section = λ eq → trans (sym (I.forth∘back b′)) eq
; isSection = λ x → let open ≡-Reasoning in
begin
trans (I.forth∘back b′) (trans (sym (I.forth∘back b′)) x)
≡⟨ trans-unassoc (I.forth∘back b′) ⟩
trans (trans (I.forth∘back b′) (sym (I.forth∘back b′))) x
≡⟨ cong (λ p → trans p x) (trans-symʳ (I.forth∘back b′)) ⟩
x
∎
}
}
ii : ∃[ a ] (forth a ≡ b) ◁ ∃[ b′ ] (forth (I.back b′) ≡ b)
ii = Σ-◁-reindexing A◁B
iii : ∃[ b′ ] (forth (I.back b′) ≡ b) ◁ ∃[ b′ ] (b′ ≡ b)
-- aka Singleton b
iii = Σ-◁ i
≅-refl : A ≅ A
≅-refl .forth x = x
≅-refl .isIso .IsIso.back x = x
≅-refl .isIso .IsIso.forth∘back x = refl
≅-refl .isIso .IsIso.back∘forth x = refl
≅-sym : A ≅ B → B ≅ A
≅-sym A≅B .forth = A≅B .back
≅-sym A≅B .isIso .IsIso.back = A≅B .forth
≅-sym A≅B .isIso .IsIso.back∘forth = A≅B .forth∘back
≅-sym A≅B .isIso .IsIso.forth∘back = A≅B .back∘forth
≅-trans : A ≅ B → B ≅ C → A ≅ C
≅-trans A≅B B≅C .forth = B≅C .forth ∘ A≅B .forth
≅-trans A≅B B≅C .isIso .IsIso.back = A≅B .back ∘ B≅C .back
≅-trans A≅B B≅C .isIso .IsIso.back∘forth x
= trans (cong (A≅B .back) (B≅C .back∘forth _)) (A≅B .back∘forth _)
≅-trans A≅B B≅C .isIso .IsIso.forth∘back x
= trans (cong (B≅C .forth) (A≅B .forth∘back _)) (B≅C .forth∘back _)
≅-isEquivalence : IsEquivalence (_≅_ {α})
≅-isEquivalence .IsEquivalence.refl = ≅-refl
≅-isEquivalence .IsEquivalence.sym = ≅-sym
≅-isEquivalence .IsEquivalence.trans = ≅-trans
≅-setoid : ∀ α → Setoid (lsuc α) α
≅-setoid α .Setoid.Carrier = Set α
≅-setoid α .Setoid._≈_ = _≅_
≅-setoid α .Setoid.isEquivalence = ≅-isEquivalence
≅-reflexive : A ≡ B → A ≅ B
≅-reflexive refl = ≅-refl
≡→≅ = ≅-reflexive
≅-Injective : (i : A ≅ B) → Injective (i .forth)
≅-Injective i = IsIso→Injective (i .isIso)
≅→◁ : A ≅ B → A ◁ B
≅→◁ A≅B = record
{ retraction = A≅B .back
; hasSection = IsIso→HasSection-back (A≅B .isIso)
}
≅→▷ : A ≅ B → B ◁ A
≅→▷ A≅B = record
{ retraction = A≅B .forth
; hasSection = IsIso→HasSection-forth (A≅B .isIso)
}
≃→≅ : A ≃ B → A ≅ B
≃→≅ A≃B .forth = A≃B .forth
≃→≅ A≃B .isIso = IsEquiv→IsIso (A≃B .isEquiv)
≅→≃ : A ≅ B → A ≃ B
≅→≃ A≅B .forth = A≅B .forth
≅→≃ A≅B .isEquiv = IsIso→IsEquiv (A≅B .isIso)
id-IsEquiv : IsEquiv (id {A = A})
id-IsEquiv a = (a , refl) , λ { (b , refl) → refl }
≃-refl : A ≃ A
≃-refl = record { forth = id ; isEquiv = id-IsEquiv }
≃-reflexive : A ≡ B → A ≃ B
≃-reflexive refl = ≃-refl
≡→≃ = ≃-reflexive
≃-sym : A ≃ B → B ≃ A
≃-sym = ≅→≃ ∘ ≅-sym ∘ ≃→≅
≃-trans : A ≃ B → B ≃ C → A ≃ C
≃-trans A≃B B≃C = ≅→≃ (≅-trans (≃→≅ A≃B) (≃→≅ B≃C))
≃-isEquivalence : IsEquivalence (_≃_ {α})
≃-isEquivalence .IsEquivalence.refl = ≃-refl
≃-isEquivalence .IsEquivalence.sym = ≃-sym
≃-isEquivalence .IsEquivalence.trans = ≃-trans
≃-setoid : ∀ α → Setoid (lsuc α) α
≃-setoid α .Setoid.Carrier = Set α
≃-setoid α .Setoid._≈_ = _≃_
≃-setoid α .Setoid.isEquivalence = ≃-isEquivalence
≃-Injective : (e : A ≃ B) → Injective (e .forth)
≃-Injective = ≅-Injective ∘ ≃→≅
≃→◁ : A ≃ B → A ◁ B
≃→◁ = ≅→◁ ∘ ≃→≅
≃→▷ : A ≃ B → B ◁ A
≃→▷ = ≅→▷ ∘ ≃→≅
-- Special cases of ≃-pres-IsOfHLevel (in Util.HoTT.HLevel), but proven
-- directly. This means that A and B can be at different levels.
≅-pres-IsContr : A ≅ B → IsContr A → IsContr B
≅-pres-IsContr A≅B (a , canon) = A≅B .forth a , λ a′
→ trans (cong (A≅B .forth) (canon (A≅B .back a′))) (A≅B .forth∘back _)
≃-pres-IsContr : A ≃ B → IsContr A → IsContr B
≃-pres-IsContr A≃B = ≅-pres-IsContr (≃→≅ A≃B)
≅-pres-IsProp : A ≅ B → IsProp A → IsProp B
≅-pres-IsProp A≅B A-prop x y
= trans (sym (A≅B .forth∘back x))
(sym (trans (sym (A≅B .forth∘back y)) (cong (A≅B .forth) (A-prop _ _))))
≃-pres-IsProp : A ≃ B → IsProp A → IsProp B
≃-pres-IsProp A≃B = ≅-pres-IsProp (≃→≅ A≃B)
Σ-≅⁺ : {A : Set α} {B : A → Set β} {C : A → Set γ}
→ (∀ a → B a ≅ C a)
→ Σ A B ≅ Σ A C
Σ-≅⁺ eq = record
{ forth = λ { (a , b) → a , eq a .forth b }
; isIso = record
{ back = λ { (a , c) → a , eq a .back c }
; back∘forth = λ { (a , b) → Σ-≡⁺ (refl , eq a .back∘forth b) }
; forth∘back = λ { (a , c) → Σ-≡⁺ (refl , eq a .forth∘back c) }
}
}
Σ-≃⁺ : {A : Set α} {B : A → Set β} {C : A → Set γ}
→ (∀ a → B a ≃ C a)
→ Σ A B ≃ Σ A C
Σ-≃⁺ eq = ≅→≃ (Σ-≅⁺ λ a → ≃→≅ (eq a))
map₂-fiber-≃ : {A : Set α} {B : A → Set β} {C : A → Set γ}
→ (f : ∀ a → B a → C a)
→ ∀ a (c : C a)
→ ∃[ b ] (f a b ≡ c) ≃ ∃[ p ] (map₂ f p ≡ (a , c))
map₂-fiber-≃ f a c = ≅→≃ record
{ forth = λ { (b , refl) → (a , b) , refl }
; isIso = record
{ back = λ { ((.a , b) , refl) → b , refl }
; back∘forth = λ { (b , refl) → refl }
; forth∘back = λ { ((.a , b) , refl) → refl }
}
}
IsEquiv-map₂-f→IsEquiv-f : {A : Set α} {B : A → Set β} {C : A → Set γ}
→ (f : ∀ a → B a → C a)
→ IsEquiv (map₂ f)
→ ∀ a → IsEquiv (f a)
IsEquiv-map₂-f→IsEquiv-f {A = A} {B} {C} f equiv a c
= ≃-pres-IsContr (≃-sym (map₂-fiber-≃ f a c)) (equiv (a , c))
sym-≅ : {x y : A} → (x ≡ y) ≅ (y ≡ x)
sym-≅ = record
{ forth = sym
; isIso = record
{ back = sym
; back∘forth = λ { refl → refl }
; forth∘back = λ { refl → refl }
}
}
sym-≃ : {x y : A} → (x ≡ y) ≃ (y ≡ x)
sym-≃ = ≅→≃ sym-≅
IsContr→IsIso : IsContr A → IsContr B → (f : A → B) → IsIso f
IsContr→IsIso (a , a-uniq) (b , b-uniq) f = record
{ back = λ _ → a
; back∘forth = λ _ → a-uniq _
; forth∘back = λ b′ → trans (sym (b-uniq (f a))) (b-uniq b′)
}
IsContr→IsEquiv : IsContr A → IsContr B → (f : A → B) → IsEquiv f
IsContr→IsEquiv A-contr B-contr f
= IsIso→IsEquiv (IsContr→IsIso A-contr B-contr f)
proj₁-IsIso : {A : Set α} {B : A → Set β}
→ (∀ a → IsContr (B a))
→ IsIso (proj₁ {A = A} {B})
proj₁-IsIso B-contr = record
{ back = λ a → (a , B-contr a .proj₁)
; back∘forth = λ { (a , b) → Σ-≡⁺ (refl , (B-contr a .proj₂ b)) }
; forth∘back = λ _ → refl
}
proj₁-IsEquiv : {A : Set α} {B : A → Set β}
→ (∀ a → IsContr (B a))
→ IsEquiv (proj₁ {A = A} {B})
proj₁-IsEquiv B-contr = IsIso→IsEquiv (proj₁-IsIso B-contr)
Π-distr-Σ-≅ : (A : Set α) (B : A → Set β) (C : ∀ a → B a → Set γ)
→ (∀ a → Σ[ b ∈ B a ] (C a b))
≅ (Σ[ f ∈ (∀ a → B a) ] (∀ a → C a (f a)))
Π-distr-Σ-≅ A B C = record
{ forth = λ f → (λ a → f a .proj₁) , (λ a → f a .proj₂)
; isIso = record
{ back = λ { (f , g) → λ a → f a , g a }
; back∘forth = λ _ → refl
; forth∘back = λ _ → refl
}
}
|
src/main/fragment/mos6502-common/_deref_pwuz1=_deref_pwuz2_plus__deref_pwuz3.asm | jbrandwood/kickc | 2 | 169678 | <filename>src/main/fragment/mos6502-common/_deref_pwuz1=_deref_pwuz2_plus__deref_pwuz3.asm
ldy #0
lda ({z2}),y
clc
adc ({z3}),y
sta ({z1}),y
iny
lda ({z2}),y
adc ({z3}),y
sta ({z1}),y |
AS_iTerm_2018-10-18.scpt | blodely/Mac-Configurations | 2 | 3882 | <gh_stars>1-10
(*
SCRIPT CREATED BY <NAME>, <EMAIL>
THURSDAY, MAY 10, 2018
*)
tell application "System Events"
-- OPEN ITERMS
keystroke space using {control down}
-- WAIT FOR IT INITIALIZED
delay 1
-- CHANGE INPUT METHOD ENGLISH MODE
--key down shift
--key up shift
-- SPLIT WINDOWS AS THREE COLUMNS
keystroke "d" using {command down}
keystroke "d" using {command down}
-- RUN HTOP AT 3RD COLUMN
keystroke "htop"
keystroke return
-- MOVE TO 2ND COLUMN
keystroke "[" using {command down}
-- SPLIT UP & DOWN
keystroke "d" using {command down, shift down}
-- RUN UPDATE COCOAPODS AND BREW LIBS SHELL SCRIPT
keystroke "./updates.sh"
keystroke return
-- WAIT FOR IT RESPONSE
delay 1
-- MOVE UP
keystroke "[" using {command down}
-- MOVE TO GITHUB PROJECTS FOLDER AND LIST FILES
keystroke "la && cd Project/GitHub && la"
keystroke return
-- MOVE TO 1ST COLUMN
keystroke "[" using {command down}
-- MOVE TO WORKING PROJECT FOLDER AND LIST ALL FILES WITH GIT STATUS
keystroke "la && cd Project/com.company/workin_app && la && git status"
keystroke return
-- OPEN XCODE WORKSPACE
keystroke "openws"
keystroke return
-- WAIT XCODE TO RESPONSE
delay 3
-- GO BACK TO ITERMS
keystroke space using {control down}
end tell
|
src/main/antlr/MiniCalcLexer.g4 | tedneward/MiniCalc | 0 | 2770 | <gh_stars>0
lexer grammar MiniCalcLexer;
channels { WHITESPACE }
NEWLINE : '\r\n' | '\r' | '\n' ;
WS : [\t ]+ -> channel(WHITESPACE);
INPUT : 'input' ;
VAR : 'var' ;
PRINT : 'print' ;
AS : 'as' ;
INT : 'Int' ;
DECIMAL : 'Decimal' ;
STRING : 'String' ;
INTLIT : ('0'|[1-9][0-9]*) ;
DECLIT : ('0'|[1-9][0-9]*) '.' [0-9]+ ;
PLUS : '+';
MINUS : '-';
ASTERISK : '*';
DIVISION : '/';
ASSIGN : '=';
LPAREN : '(';
RPAREN : ')';
ID : [_]*[a-z][A-Za-z0-9_]* ;
STRING_OPEN : '"' -> pushMode(MODE_IN_STRING);
UNMATCHED : . ;
mode MODE_IN_STRING;
ESCAPE_STRING_DELIMITER : '\\"' ;
ESCAPE_SLASH : '\\\\';
ESCAPE_NEWLINE : '\\n';
ESCAPE_SHARP : '\\#';
STRING_CLOSE : '"' -> popMode ;
INTERPOLATION_OPEN : '#{' -> pushMode(MODE_IN_INTERPOLATION);
STRING_CONTENT : ~["\n\r\t\\#]+ ;
STR_UNMATCHED : . -> type(UNMATCHED);
mode MODE_IN_INTERPOLATION;
INTERPOLATION_CLOSE : '}' -> popMode;
INTERP_WS : [\t ]+ -> skip;
INTERP_AS : 'as' -> type(AS);
INTERP_INT : 'Int' -> type(INT);
INTERP_DECIMAL : 'Decimal' -> type(DECIMAL);
INTERP_STRING : 'String' -> type(STRING);
INTERP_INTLIT : ('0'|[1-9][0-9]*) -> type(INTLIT);
INTERP_DECLIT : ('0'|[1-9][0-9]*) '.' [0-9]+ -> type(DECLIT);
INTERP_PLUS : '+' -> type(PLUS);
INTERP_MINUS : '-' -> type(MINUS);
INTERP_ASTERISK : '*' -> type(ASTERISK);
INTERP_DIVISION : '/' -> type(DIVISION);
INTERP_ASSIGN : '=' -> type(ASSIGN);
INTERP_LPAREN : '(' -> type(LPAREN);
INTERP_RPAREN : ')' -> type(RPAREN);
INTERP_ID : [_]*[a-z][A-Za-z0-9_]* -> type(ID);
INTERP_STRING_OPEN : '"' -> type(STRING_OPEN), pushMode(MODE_IN_STRING);
INTERP_UNMATCHED : . -> type(UNMATCHED);
|
1A/S5/PIM/projet/src/input.adb | MOUDDENEHamza/ENSEEIHT | 4 | 14029 | --------------------------------------------------------------------------------
-- Fichier : input.ads
-- Auteur : <NAME> & <NAME>
-- Objectif : Implantation du module Input
-- Crée : <NAME> 01 2019
--------------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
package body Input is
-- lire au clavier un entier quelconque.
procedure Input_Integer (value : out Integer) is
begin
Get (value);
exception
when Data_Error =>
New_Line;
Put_Line (ESC & "[31m" & "ERREUR : " & ESC & "[0m" & "Vous n'avez pas saisi un entier.");
Skip_Line;
New_Line;
Put ("Réessayez encore une fois : ");
Input_Integer (value);
end Input_Integer;
-- Entrer le choix du menu.
procedure Input_Choice (Choice : out Integer) is
begin
Put ("Entrez votre choix : ");
loop
Input_Integer (Choice);
if (Choice < 0 or Choice > 13) then
Put_Line(ESC & "[31m" & "ERREUR : " & ESC & "[0m" & "Il faut entrer un entier entre 0 et 11.");
New_Line;
Put ("Réessayez encore une fois : ");
end if;
exit when Choice >= 0 and Choice <= 13;
end loop;
end Input_Choice;
-- Entrer le sex d'un individu.
function Input_Sex return Character is
Sex : Character;
begin
loop
Get (Sex);
if (Sex /= 'H' and Sex /= 'F' and Sex /= 'U') then
New_Line;
Put_Line (ESC & "[31m" & "ERREUR : " & ESC & "[0m" & "sexe introuvable.");
New_Line;
Put ("Veuillez saisir " & ESC & "[31m" & "F" & ESC & "[0m" & " pour une femme, " & ESC & "[32m" & "H" & ESC & "[0m" & " pour un homme ou " & ESC & "[34m" & "U" & ESC & "[0m" & " pour tout autre type de sexe : ");
end if;
exit when (Sex = 'H' or Sex = 'F' or Sex = 'U');
end loop;
return Sex;
end Input_Sex;
-- Entrer les données personnelles d'une personne.
function Demander_Donnee return T_Donnee is
Nom, Prenom, Lieu_N, Lieu_D, Email : Unbounded_String;
Tel, N_Jour, N_Mois, N_Annee, D_Jour, D_Mois, D_Annee: Integer;
Sexe : Character;
begin
New_Line;
Put ("Veuillez saisir un nom : ");
Nom := Get_Line;
Skip_Line;
New_Line;
Put ("Veuillez saisir un prenom : ");
Prenom := Get_Line;
New_Line;
Put ("Veuillez saisir un jour de naissance : ");
Input_Integer (N_Jour);
New_Line;
Put ("Veuillez saisir un mois de naissance : ");
Input_Integer (N_Mois);
New_Line;
Put ("Veuillez saisir une année de naissance : ");
Input_Integer (N_Annee);
New_Line;
Put ("Veuillez saisir un lieu de naissance : ");
Lieu_N := Get_Line;
Skip_Line;
New_Line;
Put ("Veuillez saisir un jour de décès : ");
Input_Integer (D_Jour);
New_Line;
Put ("Veuillez saisir un mois de décès : ");
Input_Integer (D_Mois);
New_Line;
Put ("Veuillez saisir une année de décès : ");
Input_Integer (D_Annee);
New_Line;
Put ("Veuillez saisir un lieu de décès : ");
Lieu_D := Get_Line;
Skip_Line;
New_Line;
Put ("Veuillez saisir " & ESC & "[31m" & "F" & ESC & "[0m" & " pour une femme, " & ESC & "[32m" & "H" & ESC & "[0m" & " pour un homme ou " & ESC & "[34m" & "U" & ESC & "[0m" & " pour tout autre type de sexe : ");
Sexe := Input_Sex;
New_Line;
Put ("Veuillez saisir un email : ");
Email := Get_Line;
Skip_Line;
New_Line;
Put ("Veuillez saisir un numéro de téléphone sous la forme 0612345678 : ");
Input_Integer (Tel);
return Initialiser_Donnee (Nom, Prenom, Initialiser_Date(N_Jour, N_Mois, N_Annee), Lieu_N, Initialiser_Date(D_Jour, D_Mois, D_Annee), Lieu_D, Sexe, Email, Tel);
end Demander_Donnee;
-- Entrer l'ID d'un individu.
procedure Input_ID (ID : out Integer; Message : in String) is
begin
New_Line;
Put (Message);
Input_Integer (ID);
end Input_ID;
-- Entrer si le parent que vous souhaiterez ajouter est le père ou la mère.
-- Entrer 0 s'il s'agit d'un père, 1 si c'est la mère.
procedure Input_Flag (Flag : out Integer) is
begin
loop
New_Line;
Put_Line ("Entrez " & ESC & "[32m" & "0" & ESC & "[0m" & " s'il s'agit du père, si c'est la mère entrez " & ESC & "[31m" & "1" & ESC & "[0m" & ".");
New_Line;
Put ("Entrez Votre choix : ");
Input_Integer (Flag);
if (Flag /=0 and Flag /= 1) then
New_Line;
Put_Line (ESC & "[31m" & "ERREUR : " & ESC & "[0m" & "Entrée éronnée.");
end if;
exit when (Flag = 0 or Flag = 1);
end loop;
end Input_Flag;
-- Entrez la géneration des ancetres.
procedure Input_Generation (Generation : out Integer) is
begin
New_Line;
Put ("Entrez la géneration des ancetres que vous souhaitez les trouver : ");
Input_Integer (Generation);
end Input_Generation;
end Input;
|
oeis/106/A106440.asm | neoneye/loda-programs | 11 | 17268 | <reponame>neoneye/loda-programs<filename>oeis/106/A106440.asm
; A106440: a(n) = binomial(2n+4,n)*binomial(n+4,4).
; Submitted by <NAME>
; 1,30,420,4200,34650,252252,1681680,10501920,62355150,355655300,1963217256,10546208400,55367594100,285028443000,1442592936000,7193730107520,35406640372950,172255143129300,829376615067000
mov $1,$0
sub $2,$0
sub $0,$2
mov $2,-5
bin $2,$0
bin $0,$1
mul $0,$2
|
src/main/antlr4/PlayPlusWords.g4 | opmvpc/compilateurPlayPlusNBC | 0 | 1194 | lexer grammar PlayPlusWords;
/**********
LEXER RULES
***********/
/** RESERVED WORDS **/
MAIN: 'main';
VOID : 'void';
IF : 'if';
ELSE : 'else';
THEN : 'then';
REPEAT : 'repeat';
WHILE : 'while';
TRUE : 'true';
FALSE : 'false';
IMPORT : 'import';
/** ACTION TYPES **/
LEFT : 'left';
RIGHT : 'right';
UP : 'up';
DOWN : 'down';
JUMP : 'jump';
FIGHT : 'fight';
DIG : 'dig';
/** TYPES **/
BOOL : 'bool';
INT : 'int';
CHAR : 'char';
STRUCT : 'struct';
CONST : 'const';
ENUM : 'enum';
TYPEDEF : 'typedef';
NATUREL : (CHIFFRE)+ ;
//ENTIER : (MINUS)? (CHIFFRE)+ ;
FILE : DOUBLEQUOTE ID '.map' DOUBLEQUOTE ;
STRING : DOUBLEQUOTE (~["\\,\r\n])+ DOUBLEQUOTE ;
CHARACTER : SINGLEQUOTE ( CHIFFRE | LETTRE | COLON | DOT | DIV | BACKSLASH | SEMICOLON )* SINGLEQUOTE ;
/** OPERATORS **/
PLUS : '+';
MINUS : '-';
MUL : '*';
DIV : '/';
MOD : '%';
POW : '^';
EQUAL: '==';
AFFECT: '=';
NOT : '!';
NOTEQUAL: '!=';
SMALLER : '<';
GREATER : '>';
EGREATER : '>=';
ESMALLER : '<=';
/** BLOCKS AND ENCLOSURES **/
LPAREN : '(';
RPAREN : ')';
LBRACE : '{';
RBRACE : '}';
LBRACKET : '[';
RBRACKET : ']';
/** KEY SYMBOLS **/
SINGLEQUOTE : '\'';
BACKSLASH : '\\';
SEMICOLON: ';';
COLON : ':';
COMMA : ',';
DOT : '.';
AND : '&&';
OR : '||';
//AMPERSAND : '&';
DOLLAR : '$';
/** COMMENTS **/
COMMENTAIRES : (BLOCK_COMMENT | LINE_COMMENT) -> channel(HIDDEN);
BLOCK_COMMENT : DIV MUL .*? MUL DIV -> channel(HIDDEN) ;
LINE_COMMENT : DIV DIV ~[\r\n]* -> channel(HIDDEN) ;
/** NEWLINES AND WHITESPACE **/
NEWLINE : ('\r'? '\n') -> skip;
WS : (' '| '\t')+ -> skip;
/** UTILS **/
MAPSTART: 'map' COLON ;
HASHTAG: '#';
RETURN: 'return';
MAP : DOT 'map';
/** Map */
ROBOT :'@';
TRESOR: 'X';
PELOUSE: 'G';
PALMIER: 'P';
PONT:'A';
BUISSON:'B';
TONNEAU:'T';
PUIT:'S';
VIDE:'_';
SQUELLETTE:'Q';
/********
FRAGMENTS
********/
ID : LETTRE (CHIFFRE| LETTRE)*;
fragment DOUBLEQUOTE : '"';
fragment LETTRE: LOWER | UPPER;
fragment LOWER: 'a'..'z';
fragment UPPER: 'A'..'Z';
fragment CHIFFRE: '0'..'9'; |
DoubleBuffer640x480/DoubleBuffer.asm | fraser125/N64_ASM_Videos | 23 | 93713 | arch n64.cpu
endian msb
output "DoubleBuffer.N64", create
fill $0010'1000 // Set ROM Size
// fill 1052672 also works because
// 4 KB (4096 B) header reserved for config and publisher data
// 1 MB (1024 KB * 1024 KB = 1,048,576 B) game code copied to n64 ram on boot
// 4096 + 1048576 = 1,052,672 B roughly a megabyte used for our game
// 1052672 Bytes is represented as $00101000 in hex
origin $00000000
base $80000000
include "../LIB/N64.INC"
include "../LIB/N64_GFX.INC"
include "N64_Header.asm"
insert "../LIB/N64_BOOTCODE.BIN"
constant fb1($A010'0000)
constant fb2($A020'0000)
macro EnableInterrupts() {
lui t0, MI_BASE
ori t0, MI_INTR_MASK
//ori t1, zero, 0x0AAA // 0x0AAA = All RCP Interrupts
ori t1, zero, 0x0080 // 0x0080 = RCP-VI Interrupts
sw t1, 0(t0)
mfc0 t0, Status
lui t1, 0xFFFF
and t0, t0, t1
ori t0, 0x0401 // Enable RCP Interrupts
mtc0 t0, Status
}
macro DisableInterrupts() {
mfc0 t0, Status
lui t1, 0xFFFF
and t0, t0, t1
mtc0 t0, Status
}
Start: // NOTE: base $80001000
init()
ScreenNTSC(320,240, BPP32, fb1)
nop
nop
nop
la t0, Handler
la t1, EndHandler
li t2, $8000'0180
// Copy Exception Handler to proper address
CopyDouble:
lw t3, 0(t0)
lw t4, 4(t0)
sw t3, 0(t2)
sw t4, 4(t2)
addi t0, t0, 8
bne t0, t1, CopyDouble
addi t2, t2, 8
nop
nop
nop
DPC(RDP_INIT, RDP_INIT_END)
nop
// Draw Rectangle on Frame Buffer 1
DPC(RDPFB_1, RDPFB_1_END)
nop
// Draw Rectangle on Frame Buffer 2
DPC(RDPFB_2, RDPFB_2_END)
nop
DPC(RDPFB_DONE, RDPFB_DONE_END)
nop
nop
nop
EnableInterrupts()
Loop: // while(true);
j Loop
nop
nop
nop
nop
scope SetFB: {
la t0, CURRENT_FB
jr ra
sw a0, 0(t0)
}
nop
nop
nop
ALIGN(8)
RDP_INIT:
arch n64.rdp
Set_Scissor 0<<2,0<<2, 0,0, 320<<2,240<<2
Set_Other_Modes CYCLE_TYPE_FILL
Sync_Pipe
RDP_INIT_END:
RDPFB_1:
arch n64.rdp
Set_Color_Image IMAGE_DATA_FORMAT_RGBA,SIZE_OF_PIXEL_32B,320-1, $00100000
Set_Fill_Color $FF00FFFF // 000000FF
Fill_Rectangle 319<<2,239<<2, 0<<2,0<<2
Set_Color_Image IMAGE_DATA_FORMAT_RGBA,SIZE_OF_PIXEL_32B,320-1, $00100000
Set_Fill_Color $FFFF00FF
Fill_Rectangle 179<<2,139<<2, 16<<2,8<<2
Sync_Pipe
RDPFB_1_END:
RDPFB_2:
arch n64.rdp
Set_Color_Image IMAGE_DATA_FORMAT_RGBA,SIZE_OF_PIXEL_32B,320-1, $00200000
Set_Fill_Color $FF00FFFF // 000000FF
Fill_Rectangle 319<<2,239<<2, 0<<2,0<<2
Set_Color_Image IMAGE_DATA_FORMAT_RGBA,SIZE_OF_PIXEL_32B,320-1, $00200000
Set_Fill_Color $00FFFFFF
Fill_Rectangle 309<<2,229<<2, 159<<2,129<<2
Sync_Pipe
RDPFB_2_END:
RDPFB_DONE:
Sync_Full
RDPFB_DONE_END:
arch n64.cpu
nop
nop
nop
ALIGN(4)
CURRENT_FB:
dw fb1
ALIGN(16)
scope Handler: {
base $80000180
la t0, CURRENT_FB
li t1, fb1
li t2, fb2
lw t3, 0(t0)
bne t1, t3, AssignFB
lui t4,VI_BASE
add t1, t2, zero
AssignFB:
sw t1,VI_ORIGIN(t4)
sw t1, 0(t0)
eret
FIXED_GAP(Handler, 128)
}
EndHandler:
|
programs/oeis/111/A111368.asm | karttu/loda | 0 | 105077 | <filename>programs/oeis/111/A111368.asm
; A111368: The number of maximal determinant {-1,1} matrices of order n.
; 1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,5,3,3,3,3,7
lpb $0,1
trn $0,4
mov $1,$0
add $2,$0
trn $0,1
add $1,$2
trn $1,2
sub $2,$0
lpe
mul $1,2
add $1,1
|
msdos/DOS/dos.asm | Cth1003/pcTest | 0 | 169395 | %include "struct.inc"
;In this file,we don't need interrupt_table_addr in struct.inc
ORG 0x100
CLI
MOV AX,0
MOV ES,AX
MOV AX,CS
MOV word [ES:(0x08*4)],timer_intrrrupt;Offset
MOV word [ES:(0x08*4+2)],AX;Segment
MOV word [ES:(0x09*4)],keyboard_interrupt;Offset
MOV word [ES:(0x09*4+2)],AX;Segment
MOV word [ES:(0x21*4)],dos_interrupt;Offset
MOV word [ES:(0x21*4+2)],AX;Segment
mov al,0b00000001;Enable all of the interrupt of the master 8259A
out 0x21,al;Master 8259A,OCW1
mov al,0b00000000;Enable all of the interrupt of the slave 8259A
out 0x0A1,al;Slave 8259A,OCW1
STI
MOV BX,in_dos_text
call reset_disk
;Address:0x3CA00
;H 0
;S 5
;C 6
MOV AX,0x00F0
MOV ES,AX
MOV AH,0x02
MOV AL,0x01
;Sector number
MOV CH,13
MOV CL,18
MOV DX,0
MOV BX,0x00
int 0x13
JC run_program_failed
MOV BX,0
PUSH BX
next_file:
MOV CX,command_name
CMP BX,512
JE command_not_found;There is no command.com
compare_next_char:
CMP CX,command_name+11
JE compare2
MOV AL,[ES:BX];AL name in root directory
PUSH BX
MOV BX,CX
MOV AH,[BX];AH name in command_name
POP BX
CMP AL,AH
JNE not_this_file
ADD BX,1
ADD CX,1
JMP compare_next_char
find_file:
POP BX
call cluster_translate
call reset_disk
CLI
MOV AH,0x02
;Read
MOV AL,2
;Sector number of each program
MOV DL,0x00
MOV BX,0x00
int 0x13
JC run_program_failed
MOV AX,0x0E0
MOV DS,AX
MOV ES,AX
JMP 0x0E0:0x100;0x0F00
loop:
JMP loop
reset_disk:
PUSHA
MOV AX,0x00
MOV DX,0x00
int 0x13
JC run_program_failed
POPA
ret
not_this_file:
POP BX
ADD BX,0x20
PUSH BX;Turn to start address
JMP next_file
compare2:
POP BX
PUSH BX;Turn to start
CMP byte [ES:BX],0xE5
JE not_this_file
ADD BX,0xB
CMP byte [ES:BX],0x0F
JE not_this_file
ADD BX,-0xB+0x1A
MOV AX,[ES:BX];Save cluster id
CMP AX,0x0002
JL not_this_file
ADD BX,-0x1A+0x1C
CMP dword [ES:BX],2048
JG not_this_file
JMP find_file
cluster_translate:
;0x40A00+cluster*8192
;cluster is in AX
;It will set CH CL and DH.
MOV CH,14
MOV CL,14
MOV DH,0x00
cluster_translate_start:
CMP AX,2
JLE cluster_translate_finished
ADD CL,16
ADD AX,-1
CMP CL,18
JLE cluster_translate_start
CMP DH,0x1
JE next_cylinder
cluster_translate_next:
NOT DH
AND DH,0x1
ADD CL,-18
JMP cluster_translate_start
cluster_translate_finished:
ret
next_cylinder:
ADD CH,1
JMP cluster_translate_next
in_dos_text:
db "DOS",0x00
%include "print.inc"
show_cursor:
PUSH AX
PUSH CX
MOV AH,0x01
MOV AL,0x00
MOV CX,0x0607
;INT 0x10
POP CX
POP AX
ret
hide_cursor:
PUSH AX
PUSH CX
MOV AH,0x01
MOV AL,0x00
MOV CX,0x0706
;OR MOV CX,0x2706
;http://en.wikipedia.org/wiki/INT_10H
;INT 0x10
POP CX
POP AX
ret
command_not_found:
MOV BX,command_not_found_text
call print_text
JMP loop
run_program_failed:
MOV BX,run_program_failed_text
call print_text
JMP loop
command_not_found_text:
db "There is no command.com.",0x00
run_program_failed_text:
db "Run command.com failed.",0x00
command_name:
db "COMMAND COM"
;times 512-($-$$) db 0
;You can save things in both sector
;Interrupt Sector
;timer interrupt
timer_intrrrupt:
;MOV BX,interrupt_text
;call print_text
PUSHA
PUSH DS
MOV AX,CS
MOV DS,AX
MOV BX,interrupt_table+interrupt_space0
MOV AL,[DS:BX]
CMP AL,9
;Cursor flash
JE deal_interrupt
ADD AL,1
MOV [DS:BX],AL;Add interrupt_space0
stop_interrupt:
mov al,20h;EOI
out 20h,al;Send EOI to master 8259A
out 0A0h,al;Send EOI to slave 8259A
PUSH DS
POPA
iret
deal_interrupt:
MOV BX,interrupt_table+interrupt_space0
MOV byte [DS:BX],0;Set interrupt_space0 to zero
MOV BX,interrupt_table+interrupt_space1
MOV AL,[DS:BX]
CMP AL,0
JE hide_cursor_interrupt
call show_cursor
MOV byte [DS:BX],0
JMP stop_interrupt
hide_cursor_interrupt:
call hide_cursor
MOV byte [DS:BX],1
JMP stop_interrupt
keyboard_interrupt:
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DS
MOV AX,CS
MOV DS,AX
in al,60h;Keyboard port
;Find ASCII
MOV BX,keyboard_table+1
MOV CX,special_keyboard_table
re_match:
PUSH BX
MOV BX,CX
MOV AH,[DS:BX]
POP BX
cmp al,ah
JE deal_with_special_key
CMP AH,0
JNE add_cx
;If special keys' table is end,ignore.
add_cx_next:
MOV AH,[DS:BX]
CMP AH,0
JE stop_keyboard_interrupt
;If normal keys' table is end,exit.
cmp al,ah
je print_keyboard
CMP AH,0
JNE add_bx
add_bx_next:
JMP re_match
stop_keyboard_interrupt:
mov al,20h;EOI
out 20h,al;Send EOI to master 8259A
out 0A0h,al;Send EOI to slave 8259A
POP DS
POP DX
POP CX
POP BX
POP AX
iret
add_cx:
ADD CX,3
JMP add_cx_next
add_bx:
ADD BX,2
JMP add_bx_next
print_keyboard:
PUSH BX
;Read caps lock
MOV BX,interrupt_table+interrupt_space2
MOV AH,[DS:BX];Caps lock
MOV BX,interrupt_table+interrupt_space3
MOV AL,[DS:BX];Shift
XOR AH,AL;Shift and Caps lock
;S C CAPITAL
;1 1 0
;0 1 1
;1 0 1
;0 0 0
POP BX
;Read ASCII code
ADD BX,-1
;DW is opposite
MOV AL,[DS:BX]
;Compare
CMP AH,1
JE capital_case1
keyboard_print_char:
MOV BX,interrupt_table+keyboard_buffer_pointer
MOV AH,[DS:BX]
CMP BX,interrupt_table+keyboard_buffer_length
;You can save default 32 chars.
JE stop_keyboard_interrupt;It's full
MOV BX,interrupt_table+keyboard_buffer
PUSH AX
MOV AL,AH
MOV AH,0
ADD AX,BX
MOV BX,AX
POP AX
MOV [DS:BX],AL
;Save char to buffer
MOV BX,interrupt_table+keyboard_buffer_pointer
MOV AH,[DS:BX]
ADD AH,1
MOV [DS:BX],AH
;Buffer's pointer
MOV BX,interrupt_table+interrupt_space5
MOV AH,[DS:BX]
CMP AH,0
JE stop_keyboard_interrupt
;Stop if program does not allow this program to print text
call print_char
JMP stop_keyboard_interrupt
capital_case1:
CMP AL,'a'
JL keyboard_print_char
;Jump If Less
CMP AL,'z'
JG keyboard_print_char
;Jump If Bigger(greater)
ADD AL,-('a'-'A')
JMP keyboard_print_char
press_enter_key:
;Enter
PUSH AX
MOV BX,interrupt_table+interrupt_space5
MOV AL,[DS:BX]
CMP AL,0
JE press_enter_key_next
call return
press_enter_key_next:
MOV BX,interrupt_table+interrupt_space4
MOV AL,[DS:BX]
CMP AL,1
JE press_enter_key_program_is_running
MOV BX,interrupt_table+interrupt_space4
MOV byte [DS:BX],1
;Run program.
press_enter_key_program_is_running:
POP AX
ret
press_caps_lock_key:
MOV BX,interrupt_table+interrupt_space2
;MOV AL,[DS:BX]
;ADD AL,'0'
;call print_char
NOT byte [DS:BX]
AND byte [DS:BX],1
ret
press_backspace_key:
MOV BX,interrupt_table+keyboard_buffer_pointer
MOV AL,[DS:BX]
CMP AL,0
JE press_backspace_key_end;It's empty
ADD AL,-1
MOV [DS:BX],AL
MOV AL,0x08
call print_char
MOV AL,0x20
call print_char
MOV AL,0x08
call print_char
press_backspace_key_end:
ret
press_shift_key:
MOV BX,interrupt_table+interrupt_space3
MOV byte [DS:BX],1
ret
release_shift_key:
MOV BX,interrupt_table+interrupt_space3
MOV byte [DS:BX],0
ret
deal_with_special_key:
ADD CX,1
MOV BX,CX
MOV AX,[DS:BX]
call [DS:BX]
JMP stop_keyboard_interrupt
dos_interrupt:
PUSH AX
PUSH BX
PUSH DS
PUSH AX
MOV AX,CS
MOV DS,AX
POP AX
CMP AH,0x4C
JE exit_dos_program
stop_dos_interrupt:
mov al,20h;EOI
out 20h,al;Send EOI to master 8259A
out 0A0h,al;Send EOI to slave 8259A
POP DS
POP BX
POP AX
iret
exit_dos_program:
POP DS
POP BX
POP AX
mov al,20h;EOI
out 20h,al;Send EOI to master 8259A
out 0A0h,al;Send EOI to slave 8259A
MOV AX,0xD0
MOV DS,AX
MOV ES,AX
MOV BX,interrupt_table+return_code
MOV [DS:BX],AL
MOV BX,interrupt_table+interrupt_space4
MOV byte [DS:BX],0
POP AX
POP AX
MOV AX,0
;Fake POP
PUSH 0x50;CS
PUSH 0x100;IP
;Replace the data in memory and execute iret to jump to run_cmd
iret
;JMP 0xD0:0x100
%include "keymap.asm"
times 1536-($-$$) db 0
interrupt_table:
istruc interrupt_table_type
at interrupt_space5, db 1
at keyboard_buffer_pointer, db 0
at keyboard_buffer,times keyboard_buffer_length db 0
at program_name_buffer, db " COM"
iend
times 2048-($-$$) db 0
times 8192-($-$$) db 0 |
other.7z/SFC.7z/SFC/ソースデータ/ゼルダの伝説神々のトライフォース/ドイツ_PAL/Ger_asm/zel_com1.asm | prismotizm/gigaleak | 0 | 160550 | <filename>other.7z/SFC.7z/SFC/ソースデータ/ゼルダの伝説神々のトライフォース/ドイツ_PAL/Ger_asm/zel_com1.asm
Name: zel_com1.asm
Type: file
Size: 5067
Last-Modified: '2016-05-13T04:23:03Z'
SHA-1: B06E927BB4C844318FB15FAC8692831AB8AC8C82
Description: null
|
oeis/051/A051697.asm | neoneye/loda-programs | 11 | 175072 | <reponame>neoneye/loda-programs
; A051697: Closest prime to n (break ties by taking the smaller prime).
; Submitted by <NAME>
; 2,2,2,3,3,5,5,7,7,7,11,11,11,13,13,13,17,17,17,19,19,19,23,23,23,23,23,29,29,29,29,31,31,31,31,37,37,37,37,37,41,41,41,43,43,43,47,47,47,47,47,53,53,53,53,53,53,59,59,59,59,61,61,61,61,67,67,67,67,67,71,71
sub $0,1
mul $0,2
trn $0,1
seq $0,76973 ; Starting with 2, largest prime divisor of the sum of all previous terms.
|
bugs/PENDING_SUBMIT/0433-BAD-IMAGE-Pixel5-29b7a44e-no-opt-test/work/reference/1_spirv_asm/shader.frag.asm | asuonpaa/ShaderTests | 0 | 87340 | <filename>bugs/PENDING_SUBMIT/0433-BAD-IMAGE-Pixel5-29b7a44e-no-opt-test/work/reference/1_spirv_asm/shader.frag.asm
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 164
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %113 %150
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 320
OpName %4 "main"
OpName %11 "ReallyApproxNormalizedAtan2(vf2;"
OpName %10 "v"
OpName %15 "polarize(vf2;"
OpName %14 "coord"
OpName %18 "pi2"
OpName %29 "a"
OpName %42 "z"
OpName %54 "th"
OpName %94 "center"
OpName %98 "dist"
OpName %101 "angle"
OpName %102 "param"
OpName %110 "coord"
OpName %113 "gl_FragCoord"
OpName %118 "coord1"
OpName %124 "param"
OpName %126 "coord2"
OpName %132 "param"
OpName %134 "coord3"
OpName %135 "param"
OpName %150 "_GLF_color"
OpName %154 "tex"
OpDecorate %113 BuiltIn FragCoord
OpDecorate %150 Location 0
OpDecorate %154 RelaxedPrecision
OpDecorate %154 DescriptorSet 0
OpDecorate %154 Binding 0
OpDecorate %155 RelaxedPrecision
OpDecorate %157 RelaxedPrecision
OpDecorate %159 RelaxedPrecision
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypeVector %6 2
%8 = OpTypePointer Function %7
%9 = OpTypeFunction %6 %8
%13 = OpTypeFunction %7 %8
%17 = OpTypePointer Function %6
%19 = OpConstant %6 0.318309873
%22 = OpConstant %6 0.00100000005
%23 = OpTypeBool
%27 = OpConstant %6 0
%32 = OpTypeInt 32 0
%33 = OpConstant %32 1
%36 = OpConstant %32 0
%55 = OpConstant %6 0.970000029
%56 = OpConstant %6 0.189999998
%73 = OpConstant %6 0.5
%81 = OpConstant %6 1
%96 = OpConstantComposite %7 %73 %73
%111 = OpTypeVector %6 4
%112 = OpTypePointer Input %111
%113 = OpVariable %112 Input
%116 = OpConstant %6 0.00390625
%120 = OpConstant %6 0.078125
%121 = OpConstant %6 -0.3125
%122 = OpConstantComposite %7 %120 %121
%128 = OpConstant %6 -0.234375
%129 = OpConstant %6 0.15625
%130 = OpConstantComposite %7 %128 %129
%144 = OpConstant %6 256
%149 = OpTypePointer Output %111
%150 = OpVariable %149 Output
%151 = OpTypeImage %6 2D 0 0 0 1 Unknown
%152 = OpTypeSampledImage %151
%153 = OpTypePointer UniformConstant %152
%154 = OpVariable %153 UniformConstant
%158 = OpTypeVector %6 3
%4 = OpFunction %2 None %3
%5 = OpLabel
%110 = OpVariable %8 Function
%118 = OpVariable %8 Function
%124 = OpVariable %8 Function
%126 = OpVariable %8 Function
%132 = OpVariable %8 Function
%134 = OpVariable %8 Function
%135 = OpVariable %8 Function
%114 = OpLoad %111 %113
%115 = OpVectorShuffle %7 %114 %114 0 1
%117 = OpVectorTimesScalar %7 %115 %116
OpStore %110 %117
%119 = OpLoad %7 %110
%123 = OpFAdd %7 %119 %122
OpStore %124 %123
%125 = OpFunctionCall %7 %15 %124
OpStore %118 %125
%127 = OpLoad %7 %110
%131 = OpFAdd %7 %127 %130
OpStore %132 %131
%133 = OpFunctionCall %7 %15 %132
OpStore %126 %133
%136 = OpLoad %7 %110
OpStore %135 %136
%137 = OpFunctionCall %7 %15 %135
OpStore %134 %137
%138 = OpLoad %7 %118
%139 = OpLoad %7 %126
%140 = OpFSub %7 %138 %139
%141 = OpLoad %7 %134
%142 = OpFAdd %7 %140 %141
OpStore %110 %142
%143 = OpLoad %7 %110
%145 = OpVectorTimesScalar %7 %143 %144
%146 = OpExtInst %7 %1 Floor %145
%147 = OpCompositeConstruct %7 %144 %144
%148 = OpFDiv %7 %146 %147
OpStore %110 %148
%155 = OpLoad %152 %154
%156 = OpLoad %7 %110
%157 = OpImageSampleImplicitLod %111 %155 %156
%159 = OpVectorShuffle %158 %157 %157 0 1 2
%160 = OpCompositeExtract %6 %159 0
%161 = OpCompositeExtract %6 %159 1
%162 = OpCompositeExtract %6 %159 2
%163 = OpCompositeConstruct %111 %160 %161 %162 %81
OpStore %150 %163
OpReturn
OpFunctionEnd
%11 = OpFunction %6 None %9
%10 = OpFunctionParameter %8
%12 = OpLabel
%18 = OpVariable %17 Function
%29 = OpVariable %8 Function
%42 = OpVariable %17 Function
%54 = OpVariable %17 Function
OpStore %18 %19
%20 = OpLoad %7 %10
%21 = OpExtInst %6 %1 Length %20
%24 = OpFOrdLessThan %23 %21 %22
OpSelectionMerge %26 None
OpBranchConditional %24 %25 %26
%25 = OpLabel
OpReturnValue %27
%26 = OpLabel
%30 = OpLoad %7 %10
%31 = OpExtInst %7 %1 FAbs %30
OpStore %29 %31
%34 = OpAccessChain %17 %29 %33
%35 = OpLoad %6 %34
%37 = OpAccessChain %17 %29 %36
%38 = OpLoad %6 %37
%39 = OpFOrdGreaterThan %23 %35 %38
OpSelectionMerge %41 None
OpBranchConditional %39 %40 %48
%40 = OpLabel
%43 = OpAccessChain %17 %29 %36
%44 = OpLoad %6 %43
%45 = OpAccessChain %17 %29 %33
%46 = OpLoad %6 %45
%47 = OpFDiv %6 %44 %46
OpStore %42 %47
OpBranch %41
%48 = OpLabel
%49 = OpAccessChain %17 %29 %33
%50 = OpLoad %6 %49
%51 = OpAccessChain %17 %29 %36
%52 = OpLoad %6 %51
%53 = OpFDiv %6 %50 %52
OpStore %42 %53
OpBranch %41
%41 = OpLabel
%57 = OpLoad %6 %42
%58 = OpFMul %6 %56 %57
%59 = OpLoad %6 %42
%60 = OpFMul %6 %58 %59
%61 = OpFSub %6 %55 %60
%62 = OpLoad %6 %42
%63 = OpFMul %6 %61 %62
%64 = OpLoad %6 %18
%65 = OpFMul %6 %63 %64
OpStore %54 %65
%66 = OpAccessChain %17 %29 %33
%67 = OpLoad %6 %66
%68 = OpAccessChain %17 %29 %36
%69 = OpLoad %6 %68
%70 = OpFOrdLessThan %23 %67 %69
OpSelectionMerge %72 None
OpBranchConditional %70 %71 %72
%71 = OpLabel
%74 = OpLoad %6 %54
%75 = OpFSub %6 %73 %74
OpStore %54 %75
OpBranch %72
%72 = OpLabel
%76 = OpAccessChain %17 %10 %36
%77 = OpLoad %6 %76
%78 = OpFOrdLessThan %23 %77 %27
OpSelectionMerge %80 None
OpBranchConditional %78 %79 %80
%79 = OpLabel
%82 = OpLoad %6 %54
%83 = OpFSub %6 %81 %82
OpStore %54 %83
OpBranch %80
%80 = OpLabel
%84 = OpAccessChain %17 %10 %33
%85 = OpLoad %6 %84
%86 = OpFOrdLessThan %23 %85 %27
OpSelectionMerge %88 None
OpBranchConditional %86 %87 %88
%87 = OpLabel
%89 = OpLoad %6 %54
%90 = OpFNegate %6 %89
OpStore %54 %90
OpBranch %88
%88 = OpLabel
%91 = OpLoad %6 %54
OpReturnValue %91
OpFunctionEnd
%15 = OpFunction %7 None %13
%14 = OpFunctionParameter %8
%16 = OpLabel
%94 = OpVariable %8 Function
%98 = OpVariable %17 Function
%101 = OpVariable %17 Function
%102 = OpVariable %8 Function
%95 = OpLoad %7 %14
%97 = OpFSub %7 %95 %96
OpStore %94 %97
%99 = OpLoad %7 %94
%100 = OpExtInst %6 %1 Length %99
OpStore %98 %100
%103 = OpLoad %7 %94
OpStore %102 %103
%104 = OpFunctionCall %6 %11 %102
OpStore %101 %104
%105 = OpLoad %6 %98
%106 = OpLoad %6 %101
%107 = OpCompositeConstruct %7 %105 %106
OpReturnValue %107
OpFunctionEnd
|
Transynther/x86/_processed/AVXALIGN/_st_zr_/i7-8650U_0xd2_notsx.log_7687_1335.asm | ljhsiun2/medusa | 9 | 161181 | .global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %r15
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_UC_ht+0x1b4a7, %rsi
lea addresses_D_ht+0x17d67, %rdi
and $45459, %r12
mov $60, %rcx
rep movsq
nop
nop
nop
nop
and %r15, %r15
lea addresses_normal_ht+0x3b37, %rsi
lea addresses_normal_ht+0x28a7, %rdi
nop
nop
nop
nop
nop
and $14018, %r12
mov $116, %rcx
rep movsb
nop
nop
nop
nop
nop
sub $493, %rcx
lea addresses_normal_ht+0x1c4a7, %r14
nop
nop
nop
nop
cmp %rsi, %rsi
vmovups (%r14), %ymm2
vextracti128 $1, %ymm2, %xmm2
vpextrq $0, %xmm2, %r12
and %rcx, %rcx
lea addresses_WT_ht+0x15b4e, %r14
nop
nop
nop
nop
nop
dec %rdi
vmovups (%r14), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $1, %xmm6, %rcx
nop
cmp %rcx, %rcx
lea addresses_WT_ht+0xd9d7, %r14
nop
nop
nop
nop
sub %rax, %rax
mov $0x6162636465666768, %rdi
movq %rdi, %xmm0
and $0xffffffffffffffc0, %r14
movntdq %xmm0, (%r14)
add $21503, %rcx
lea addresses_D_ht+0xc4a7, %rsi
lea addresses_normal_ht+0xca7, %rdi
nop
nop
and $46834, %r12
mov $69, %rcx
rep movsq
nop
nop
nop
nop
xor %r12, %r12
lea addresses_WT_ht+0x7c27, %rsi
lea addresses_WC_ht+0x270a, %rdi
cmp %rdx, %rdx
mov $56, %rcx
rep movsb
nop
nop
nop
nop
dec %rdx
lea addresses_WT_ht+0x112a7, %r14
clflush (%r14)
nop
nop
nop
and %r15, %r15
movw $0x6162, (%r14)
nop
nop
nop
nop
cmp $63993, %r15
lea addresses_A_ht+0x145bf, %rcx
nop
nop
cmp %r15, %r15
mov $0x6162636465666768, %r14
movq %r14, %xmm5
movups %xmm5, (%rcx)
add $27783, %rax
lea addresses_WT_ht+0x54a7, %rdx
clflush (%rdx)
nop
nop
nop
nop
inc %rsi
movw $0x6162, (%rdx)
add %rdx, %rdx
lea addresses_WC_ht+0x124a7, %rsi
lea addresses_WT_ht+0xb743, %rdi
nop
nop
add $4831, %r15
mov $0, %rcx
rep movsb
nop
nop
nop
sub $42686, %r12
lea addresses_normal_ht+0x115a7, %r12
nop
add %r14, %r14
mov $0x6162636465666768, %r15
movq %r15, %xmm6
movups %xmm6, (%r12)
nop
nop
nop
nop
nop
xor %r12, %r12
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r15
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r15
push %r9
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
// REPMOV
lea addresses_A+0xbca7, %rsi
lea addresses_UC+0x4627, %rdi
nop
cmp %rax, %rax
mov $56, %rcx
rep movsl
nop
nop
nop
nop
nop
add %rbp, %rbp
// Store
lea addresses_normal+0x10517, %rbp
nop
nop
cmp %rax, %rax
movb $0x51, (%rbp)
nop
nop
nop
cmp $24267, %rax
// Store
lea addresses_WT+0x140a7, %r9
nop
nop
nop
nop
add $81, %rbp
movl $0x51525354, (%r9)
nop
nop
nop
nop
nop
sub $41590, %rbp
// Load
lea addresses_A+0x431b, %r15
nop
nop
add $31885, %rsi
movups (%r15), %xmm6
vpextrq $0, %xmm6, %rbp
nop
nop
nop
nop
nop
add $42348, %rdi
// Load
lea addresses_WT+0xd3a7, %r15
nop
dec %rbp
mov (%r15), %rdi
nop
add %rax, %rax
// Faulty Load
lea addresses_A+0xdca7, %rax
nop
nop
nop
nop
sub $13355, %r9
movb (%rax), %cl
lea oracles, %r9
and $0xff, %rcx
shlq $12, %rcx
mov (%r9,%rcx,1), %rcx
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r9
pop %r15
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_UC', 'congruent': 7, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 4, 'AVXalign': False, 'NT': True, 'congruent': 10, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 1, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': True}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'00': 1, '35': 7686}
00 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35
*/
|
oeis/246/A246394.asm | neoneye/loda-programs | 11 | 89548 | <gh_stars>10-100
; A246394: Nonnegative integers k satisfying cos(k) <= 0 and cos(k+1) >= 0.
; Submitted by <NAME>
; 4,10,17,23,29,36,42,48,54,61,67,73,80,86,92,98,105,111,117,124,130,136,142,149,155,161,168,174,180,186,193,199,205,212,218,224,230,237,243,249,256,262,268,274,281,287,293,300,306,312,318,325,331,337,344,350,356,362,369,375,381,387,394,400,406,413,419,425,431,438,444,450,457,463,469,475,482,488,494,501,507,513,519,526,532,538,545,551,557,563,570,576,582,589,595,601,607,614,620,626
mul $0,2
add $0,1
seq $0,62389 ; a(n) = floor( (2n-1)*Pi/2 ).
|
programs/oeis/047/A047378.asm | karttu/loda | 1 | 173286 | <reponame>karttu/loda
; A047378: Numbers that are congruent to {2, 4, 5} mod 7.
; 2,4,5,9,11,12,16,18,19,23,25,26,30,32,33,37,39,40,44,46,47,51,53,54,58,60,61,65,67,68,72,74,75,79,81,82,86,88,89,93,95,96,100,102,103,107,109,110,114,116,117,121,123,124,128,130,131,135,137,138,142
mov $1,$0
mov $3,$0
div $3,3
cmp $1,$3
mov $2,$0
add $2,15
add $2,$3
mul $2,7
add $2,4
gcd $1,$2
div $1,4
trn $1,27
add $1,2
|
programs/oeis/127/A127276.asm | karttu/loda | 0 | 170056 | <reponame>karttu/loda<gh_stars>0
; A127276: Hankel transform of A127275.
; 1,1,-2,-16,-64,-208,-608,-1664,-4352,-11008,-27136,-65536,-155648,-364544,-843776,-1933312,-4390912,-9895936,-22151168,-49283072,-109051904,-240123904,-526385152,-1149239296,-2499805184,-5419040768,-11710496768,-25232932864,-54223962112,-116232552448,-248571232256,-530428461056,-1129576398848,-2400886718464,-5093831213056,-10788957847552,-22814866276352,-48172353191936,-101567386615808,-213855011602432,-449700255760384,-944480488259584,-1981319953252352,-4151755906482176,-8690539905941504
mov $1,1
mov $2,8
lpb $0,1
sub $1,$0
sub $0,1
mul $2,2
lpe
add $1,1
mul $1,$2
sub $1,16
div $1,16
add $1,1
|
programs/oeis/156/A156760.asm | neoneye/loda | 22 | 81769 | <filename>programs/oeis/156/A156760.asm
; A156760: 5*4^n-1.
; 4,19,79,319,1279,5119,20479,81919,327679,1310719,5242879,20971519,83886079,335544319,1342177279,5368709119,21474836479,85899345919,343597383679,1374389534719,5497558138879,21990232555519,87960930222079,351843720888319,1407374883553279,5629499534213119,22517998136852479,90071992547409919,360287970189639679,1441151880758558719,5764607523034234879,23058430092136939519,92233720368547758079,368934881474191032319,1475739525896764129279,5902958103587056517119,23611832414348226068479,94447329657392904273919,377789318629571617095679,1511157274518286468382719,6044629098073145873530879,24178516392292583494123519,96714065569170333976494079,386856262276681335905976319,1547425049106725343623905279,6189700196426901374495621119,24758800785707605497982484479,99035203142830421991929937919,396140812571321687967719751679,1584563250285286751870879006719,6338253001141147007483516026879,25353012004564588029934064107519,101412048018258352119736256430079,405648192073033408478945025720319,1622592768292133633915780102881279,6490371073168534535663120411525119,25961484292674138142652481646100479,103845937170696552570609926584401919,415383748682786210282439706337607679
mov $1,4
pow $1,$0
mul $1,5
sub $1,1
mov $0,$1
|
theorems/cw/cohomology/HigherCohomologyGroups.agda | mikeshulman/HoTT-Agda | 0 | 3184 | <filename>theorems/cw/cohomology/HigherCohomologyGroups.agda
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.Theory
open import groups.ExactSequence
open import groups.Exactness
open import groups.HomSequence
open import groups.KernelImageUniqueFactorization
import cw.cohomology.GridPtdMap as GPM
open import cw.CW
module cw.cohomology.HigherCohomologyGroups {i} (OT : OrdinaryTheory i)
{n} (⊙skel : ⊙Skeleton {i} (S (S (S n)))) (ac : ⊙has-cells-with-choice 0 ⊙skel i) where
private
Sn≤SSSn : S n ≤ S (S (S n))
Sn≤SSSn = lteSR lteS
n≤SSn : n ≤ S (S n)
n≤SSn = lteSR lteS
n≤SSSn : n ≤ S (S (S n))
n≤SSSn = lteSR (lteSR lteS)
⊙skel₋₁ = ⊙cw-init ⊙skel
ac₋₁ = ⊙init-has-cells-with-choice ⊙skel ac
⊙skel₋₂ = ⊙cw-init ⊙skel₋₁
⊙skel₋₃ = ⊙cw-take n≤SSSn ⊙skel
ac₋₃ = ⊙take-has-cells-with-choice n≤SSSn ⊙skel ac
open OrdinaryTheory OT
open import cw.cohomology.HigherCoboundaryGrid OT
open import cw.cohomology.Descending OT
open import cw.cohomology.InnerGrid OT (ℕ-to-ℤ (S (S n)))
(⊙cw-incl-last ⊙skel₋₂)
(⊙cw-incl-last ⊙skel₋₁)
(⊙cw-incl-last ⊙skel)
open import cw.cohomology.WedgeOfCells OT
open import cw.cohomology.HigherCoboundary OT ⊙skel
import cw.cohomology.HigherCoboundary OT ⊙skel₋₁ as LC
import cw.cohomology.GridLongExactSequence cohomology-theory as GLES
{-
H apex
Coker ≃ C(X₂/X₀)<---C(X₃/X₀) ≃ C(X)
^ ^
| |
| |
C(X₂/X₁)<---C(X₃/X₁) ≃ Ker
WoC G
WoC := Wedges of Cells
-}
private
C-apex : Group i
C-apex = C (ℕ-to-ℤ (S (S n))) (⊙Cofiber (⊙cw-incl-tail n≤SSSn ⊙skel))
open import cohomology.LongExactSequence cohomology-theory
(ℕ-to-ℤ (S n)) (⊙cw-incl-tail n≤SSSn ⊙skel)
C-apex-iso-C-cw : C-apex ≃ᴳ C (ℕ-to-ℤ (S (S n))) ⊙⟦ ⊙skel ⟧
C-apex-iso-C-cw = Exact2.G-trivial-and-L-trivial-implies-H-iso-K
(exact-seq-index 1 C-cofiber-exact-seq)
(exact-seq-index 2 C-cofiber-exact-seq)
(C-cw-at-higher ⊙skel₋₃ ltS ac₋₃)
(C-cw-at-higher ⊙skel₋₃ (ltSR ltS) ac₋₃)
G : Group i
G = C (ℕ-to-ℤ (S (S n))) (⊙Cofiber (⊙cw-incl-tail Sn≤SSSn ⊙skel))
G-iso-Ker : G ≃ᴳ Ker.grp cw-co∂-last
G-iso-Ker = Ker-cw-co∂-last ⊙skel ac
H : Group i
H = C (ℕ-to-ℤ (S (S n))) (⊙Cofiber (⊙cw-incl-tail n≤SSn ⊙skel₋₁))
Coker-iso-H : LC.CokerCo∂ ≃ᴳ H
Coker-iso-H = Coker-cw-co∂-last ⊙skel₋₁ ac₋₁
module GLES-top = GLES (ℕ-to-ℤ (S n))
(⊙cw-incl-nth Sn≤SSSn ⊙skel) (⊙cw-incl-tail Sn≤SSSn ⊙skel)
module GPM-top = GPM
(⊙cw-incl-nth Sn≤SSSn ⊙skel) (⊙cw-incl-tail Sn≤SSSn ⊙skel)
G-to-C-apex : G →ᴳ C-apex
G-to-C-apex = C-fmap (ℕ-to-ℤ (S (S n))) GPM-top.Z/X-to-Z/Y
abstract
G-to-C-apex-is-surj : is-surjᴳ G-to-C-apex
G-to-C-apex-is-surj = Exact.K-trivial-implies-φ-is-surj
(exact-seq-index 2 GLES-top.C-grid-cofiber-exact-seq)
(CXₙ/Xₙ₋₁->-is-trivial ⊙skel₋₂ ltS (⊙take-has-cells-with-choice Sn≤SSSn ⊙skel ac))
module GLES-right = GLES (ℕ-to-ℤ (S n))
(⊙cw-incl-tail n≤SSn ⊙skel₋₁) (⊙cw-incl-last ⊙skel)
module GPM-right = GPM
(⊙cw-incl-tail n≤SSn ⊙skel₋₁) (⊙cw-incl-last ⊙skel)
C-apex-to-H : C-apex →ᴳ H
C-apex-to-H = C-fmap (ℕ-to-ℤ (S (S n))) GPM-right.Y/X-to-Z/X
abstract
C-apex-to-H-is-inj : is-injᴳ C-apex-to-H
C-apex-to-H-is-inj = Exact.G-trivial-implies-ψ-is-inj
(exact-seq-index 2 GLES-right.C-grid-cofiber-exact-seq)
(CXₙ/Xₙ₋₁-<-is-trivial ⊙skel ltS ac)
C-WoC : Group i
C-WoC = C (ℕ-to-ℤ (S (S n))) (⊙Cofiber (⊙cw-incl-last ⊙skel₋₁))
G-to-C-WoC : G →ᴳ C-WoC
G-to-C-WoC = C-fmap (ℕ-to-ℤ (S (S n)))
(GPM.Y/X-to-Z/X (⊙cw-incl-last ⊙skel₋₁) (⊙cw-incl-last ⊙skel))
C-WoC-to-H : C-WoC →ᴳ H
C-WoC-to-H = C-fmap (ℕ-to-ℤ (S (S n)))
(GPM.Z/X-to-Z/Y (⊙cw-incl-nth Sn≤SSSn ⊙skel) (⊙cw-incl-last ⊙skel₋₁))
open import groups.KernelImage cw-co∂-last LC.cw-co∂-last
(CXₙ/Xₙ₋₁-is-abelian ⊙skel₋₁ (ℕ-to-ℤ (S (S n))))
C-cw-iso-ker/im : C (ℕ-to-ℤ (S (S n))) ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker/Im
C-cw-iso-ker/im = lemma ∘eᴳ C-apex-iso-C-cw ⁻¹ᴳ where
lemma : C-apex ≃ᴳ Ker/Im
lemma = H-iso-Ker/Im
cw-co∂-last LC.cw-co∂-last
(CXₙ/Xₙ₋₁-is-abelian ⊙skel₋₁ (ℕ-to-ℤ (S (S n))))
φ₁ φ₁-is-surj φ₂ φ₂-is-inj lemma-comm
where
φ₁ = G-to-C-apex ∘ᴳ GroupIso.g-hom G-iso-Ker
abstract
φ₁-is-surj : is-surjᴳ φ₁
φ₁-is-surj = ∘-is-surj G-to-C-apex-is-surj (equiv-is-surj (GroupIso.g-is-equiv G-iso-Ker))
φ₂ = GroupIso.g-hom Coker-iso-H ∘ᴳ C-apex-to-H
abstract
φ₂-is-inj : is-injᴳ φ₂
φ₂-is-inj = ∘-is-inj (equiv-is-inj (GroupIso.g-is-equiv Coker-iso-H)) C-apex-to-H-is-inj
abstract
lemma-comm : ∀ g →
GroupIso.g Coker-iso-H (GroupHom.f (C-apex-to-H ∘ᴳ G-to-C-apex) (GroupIso.g G-iso-Ker g))
== q[ fst g ]
lemma-comm g =
GroupIso.g Coker-iso-H (GroupHom.f C-apex-to-H (GroupHom.f G-to-C-apex (GroupIso.g G-iso-Ker g)))
=⟨ ap (GroupIso.g Coker-iso-H) (! (C-inner-grid-commutes □$ᴳ GroupIso.g G-iso-Ker g)) ⟩
GroupIso.g Coker-iso-H (GroupHom.f C-WoC-to-H (GroupHom.f G-to-C-WoC (GroupIso.g G-iso-Ker g)))
=⟨ ap (GroupIso.g Coker-iso-H ∘ GroupHom.f C-WoC-to-H ∘ fst) (GroupIso.f-g G-iso-Ker g) ⟩
GroupIso.g Coker-iso-H (GroupHom.f C-WoC-to-H (fst g))
=⟨ GroupIso.g-f Coker-iso-H q[ fst g ] ⟩
q[ fst g ]
=∎
|
java/src/main/antlr4/wtp/parser/Expr.g4 | andreaswitsch/cnlcsplib | 0 | 2688 | grammar Expr;
prog: (expr NEWLINE)* ;
expr: '~' expr
| expr '^' expr
| expr ('*'|'/') expr
| expr ('+'|'-') expr
| expr ('<'|'>'|'<='|'>=') expr
| '-' expr
| INT
| VARSY
| 'sqrt' '(' expr ')'
| 'sin' '(' expr ')'
| 'cos' '(' expr ')'
| 'abs' '(' expr ')'
| 'exp' '(' expr ')'
| 'log' '(' expr ')'
| 'atan2' '(' expr ',' expr ')'
| 'min' '(' expr ',' expr ')'
| 'max' '(' expr ',' expr ')'
| expr ('&&') expr
| expr ('and') expr
| expr ('||') expr
| expr ('or') expr
| '(' expr ')'
;
NEWLINE : [\r\n]+;
INT : [0-9]+ ;
DOUBLE : [0-9]+'.'[0-9]+ ;
VARSY : [a-zA-Z]+[1-9]* ;
//WS : [ \n\t\r];
WS : [ \t\r\n]+ -> skip ;
|
hacks/images/m6502/breakout.asm | MBrassey/xscreensaver_BlueMatrix | 2 | 101046 | <reponame>MBrassey/xscreensaver_BlueMatrix<filename>hacks/images/m6502/breakout.asm
; Brick Out by <NAME> <<EMAIL>> http://www.blakeramsdell.com
; A poor attempt at brick out with no player involved. Maybe someday I'll
; let you play it, or you can view this as an exercise for the reader to put
; in a paddle that is user-controlled.
; I guess this is Copyright (C) 2007 <NAME>, and you have a license to
; do whatever you want with it, just tell me what you did and give me a
; mention. If you want to sell it, and you make a billion dollars, then good
; for you. You might at least throw a party and invite me.
; The gist of it is pretty simple -- you have a ball, and the ball has an X
; and a Y velocity. When it hits something, it bounces off of it. If the thing
; that it hits is not a wall, then it erases it. Pretty dead-simple behavior.
; I don't like the vertical movement -- there's a shortcut in here somewhere
; to make it less computationally expensive I think. Right now it just does a
; two byte add and subtract of $20.
; The ball motion is also a bit weird looking. I don't know if this is an
; artifact of the simulation environment combined with a normal tearing
; artifact related to refresh or what.
; <NAME>, May 2007
init:
lda #$fe
sta $2 ; X velocity (0 = fast, ff = slow)
; (low bit is direction, 0 = down or right, 1 = up or left)
lda #$ee
sta $3 ; Y velocity
drawbox:
lda #0 ; Use $0-$1 as a screen address for drawing the field
sta $0
lda #2
sta $1
ldx #$20 ; Loop $20 times
boxloop:
lda #2 ; Line color (red)
sta $1ff,x ; Top line
sta $5df,x ; Bottom line
ldy #0
sta ($0),y ; Left line
ldy #$1f
sta ($0),y ; Right line
cpx #$1 ; If we're just before the bottom line...
beq noblocks ; Don't draw any blocks there
lda #3 ; First block for this row, Cyan in color
ldy #$17 ; It's at X position $17
sta ($0),y ; Draw it
lda #4 ; Second block for this row, Purple in color
iny ; It's at the next X position
sta ($0),y ; Draw it
lda #5 ; Third block for this row, Green in color
iny ; It's at the next X position
sta ($0),y ; Draw it
lda #6 ; Fourth block for this row, Blue in color
iny ; It's at the next X position
sta ($0),y ; Draw it
noblocks:
clc ; Get ready to increment the row, clear the carry for add
lda $0 ; Get the low byte
adc #$20 ; Add $20 to it for the next row
sta $0 ; Put it back
lda $1 ; Get the high byte
adc #0 ; Factor in the carry
sta $1 ; Put it back
dex ; Decrement the loop counter
bne boxloop ; Do it again unless it's zero
ldx $2 ; Load the X velocity
ldy $3 ; Load the Y velocity
lda #$44 ; Pick a start point
sta $0 ; Ball position low
lda #$02
sta $1 ; Ball position high
drawball:
txa ; Preserve X
pha
lda #1 ; Ball color (white)
ldx #0 ; Clear X for indirect addressing for writing to screen
sta ($0,x) ; Draw the ball
pla ; Restore X
tax
decloop:
dex ; Decrement the X velocity
beq updatexpos ; If it's zero, time to adjust X
dey ; Decrement the Y velocity
bne decloop ; If it's not zero, loop, otherwise fall through to adjust Y
updateypos:
txa ; Preserve X
pha
jsr clearball ; Put background over the current ball position
updateyposnoclear:
lda $3 ; Get the Y velocity
and #1 ; See if it's down
bne moveup ; If not, then it's up, otherwise fall through to down
movedown:
clc ; Prepare for moving to the next Y line and doing the add
lda $0 ; Low byte of the current ball position
adc #$20 ; Next row
sta $0 ; Put it back
bcc ycollision ; If no carry, go on to check for collision
inc $1 ; Had a carry, fix the high byte of the address
bne ycollision ; Z flag is always clear ($1 will never be zero)
moveup:
sec ; Prepare for moving to the previous Y line and subtracting
lda $0 ; Low byte of the current ball position
sbc #$20 ; Previous row
sta $0 ; Put it back
lda $1 ; High byte
sbc #$0 ; Factor out the carry
sta $1 ; Put it back
ycollision:
ldx #0 ; Prepare for indirect read
lda ($0,x) ; Get the current pixel at the new ball position
bne ycollided ; If it's not zero (the background color) then we hit
ldy $3 ; Otherwise, load up the current Y velocity
pla ; Restore the X velocity
tax
jmp drawball ; Back to the top
ycollided:
cmp #$2 ; Border color?
beq ycollided2 ; If so, then we just bounce, don't eat a brick
; Erase brick
lda #0 ; Background color (black)
sta ($0,x) ; Erase it
ycollided2:
lda #1 ; Get ready to change direction
eor $3 ; Flip the low bit on the Y velocity (change direction)
sta $3 ; Put it back
jmp updateyposnoclear ; Go back to make sure we didn't hit anything else
updatexpos:
jsr clearball ; Put background over the current ball position
updatexposnoclear:
lda $2 ; Get the current X velocity
and #1 ; See if it's right by testing the low bit
bne moveleft ; If not, move left
moveright:
inc $0 ; Move right
bne xcollision ; Z flag is always clear
moveleft:
dec $0 ; Move left
xcollision:
ldx #0 ; Prepare for indirect read
lda ($0,x) ; Get the current pixel at the new ball position
bne xcollided ; If it's not zero (the background color) then we hit
ldx $2 ; Otherwise, load up the current X velocity
jmp drawball ; Back to the top
xcollided:
cmp #$2 ; Border color?
beq xcollided2 ; If so, then we just bounce, don't eat a brick
; Erase brick
lda #0 ; Background color (black)
sta ($0,x) ; Erase it
xcollided2:
lda #1 ; Get ready to change direction
eor $2 ; Flip the low bit on the X velocity (change direction)
sta $2 ; Put it back
jmp updatexposnoclear ; Go back to make sure we didn't hit anything else
clearball:
lda #0 ; Background color (black)
tax ; Clear X for indirect
sta ($0,x) ; Black out the ball
rts ; Return to caller
|
SOAS/Construction/Structure.agda | JoeyEremondi/agda-soas | 39 | 17347 |
open import SOAS.Common
{-
Framework for constructing categories of objects with extra structure.
The definitions required to construct a category is:
* the category of carrier objects (e.g. sets, presheaves, etc.)
* the extra operations and laws that the carrier objects are equipped with
* the preservation properties of morphisms between the structures
* proofs that the identities and composition of the carrier category preserve
the extra structure
-}
module SOAS.Construction.Structure
(CarrierCat : Category 1ℓ 0ℓ 0ℓ)
(HasStruct : Category.Obj CarrierCat → Set) where
private module ℂ = Category CarrierCat
-- The carrier of the structure, e.g. sets, presheaves, etc.
Carrier : Set₁
Carrier = ℂ.Obj
infix 1 _⋉_
-- Objects in the category for the structure: a carrier object together with
-- the algebraic structure
record Object : Set₁ where
constructor _⋉_
field
𝐶 : Carrier
ˢ : HasStruct 𝐶
open Object public
-- Properties of the morphisms between two objects, usually concerning
-- the preservation of the extra operations
MorphismProps : Set₁
MorphismProps = {𝐶₁ 𝐶₂ : Carrier}
→ HasStruct 𝐶₁
→ HasStruct 𝐶₂
→ CarrierCat [ 𝐶₁ , 𝐶₂ ] → Set
-- Morphisms in the category for the algebraic structure: an underlying
-- morphism with preservation properties of the extra structure
record Morphism (IsHomomorphism : MorphismProps) (O₁ O₂ : Object) : Set where
constructor _⋉_
field
𝑓 : CarrierCat [ 𝐶 O₁ , 𝐶 O₂ ]
ˢ⇒ : IsHomomorphism (ˢ O₁)(ˢ O₂) 𝑓
open Morphism public
-- Properties required to turn the objects and morphisms into a category; namely
-- that the identity and composition in the carrier category are homomorphisms
record CategoryProps : Set₁ where
field
IsHomomorphism : MorphismProps
id-hom : {𝐶 : Carrier}{𝐶ˢ : HasStruct 𝐶} → IsHomomorphism 𝐶ˢ 𝐶ˢ ℂ.id
comp-hom : {𝐶 𝐷 𝐸 : Carrier}
{𝐶ˢ : HasStruct 𝐶}{𝐷ˢ : HasStruct 𝐷}{𝐸ˢ : HasStruct 𝐸} →
(𝑔 : CarrierCat [ 𝐷 , 𝐸 ])(𝑓 : CarrierCat [ 𝐶 , 𝐷 ]) →
(𝑔ʰ : IsHomomorphism 𝐷ˢ 𝐸ˢ 𝑔)(𝑓ʰ : IsHomomorphism 𝐶ˢ 𝐷ˢ 𝑓) →
IsHomomorphism 𝐶ˢ 𝐸ˢ (𝑔 ℂ.∘ 𝑓)
module _ (P : CategoryProps) where
open CategoryProps P
-- Category generated from the algebraic structure
StructCat : Category 1ℓ 0ℓ 0ℓ
StructCat = categoryHelper (record
{ Obj = Object
; _⇒_ = Morphism IsHomomorphism
; _≈_ = λ g₁ g₂ → 𝑓 g₁ ℂ.≈ 𝑓 g₂
; id = ℂ.id ⋉ id-hom
; _∘_ = λ{ (𝑔 ⋉ 𝑔ˢ⇒) (𝑓 ⋉ 𝑓ˢ⇒) → (𝑔 ℂ.∘ 𝑓) ⋉ (comp-hom 𝑔 𝑓 𝑔ˢ⇒ 𝑓ˢ⇒)}
; assoc = ℂ.assoc
; identityˡ = ℂ.identityˡ
; identityʳ = ℂ.identityʳ
; equiv = record { refl = ℂ.Equiv.refl ; sym = ℂ.Equiv.sym ; trans = ℂ.Equiv.trans }
; ∘-resp-≈ = ℂ.∘-resp-≈
})
-- Forget the structure of a carrier object
Forget : Object → Carrier
Forget (𝐶 ⋉ _) = 𝐶
-- Forgetful functor from the structure category to the carrier category
ForgetF : Functor StructCat CarrierCat
ForgetF = record
{ F₀ = Forget
; F₁ = λ (𝑓 ⋉ _) → 𝑓
; identity = ℂ.Equiv.refl
; homomorphism = ℂ.Equiv.refl
; F-resp-≈ = λ x → x
}
where
open ≡-Reasoning
-- Free constructions with respect to the forgetful functor
module Free where
open import SOAS.Construction.Free ForgetF public
|
timeit.asm | ILW8/gwnum | 0 | 789 | ; Copyright 1995-2020 Mersenne Research, Inc. All rights reserved
; Author: <NAME>
; Email: <EMAIL>
;
; Time low-level operations for optimizing macros and comparing CPUs
;
TITLE setup
IFNDEF X86_64
.686
.XMM
.MODEL FLAT
ENDIF
INCLUDE unravel.mac
INCLUDE extrn.mac
INCLUDE memory.mac
INCLUDE pfa.mac
INCLUDE lucas.mac
INCLUDE xarch.mac
INCLUDE xbasics.mac
INCLUDE xmult.mac
INCLUDE hg.mac
INCLUDE r4.mac
IFDEF X86_64
X87_CASES EQU 0
ELSE
X87_CASES EQU 13
ENDIF
SSE2_CASES EQU 216
AVX_CASES EQU 300
IFDEF X86_64
AVX512_CASES EQU 140
ELSE
AVX512_CASES EQU 0
ENDIF
IACA_TEST_CASE EQU 999
loopent MACRO y,z ; Create a entry in the loop entry table
DP &y&z
ENDM
looptab MACRO y, cnt ; Create the loop entry table
x = 0
REPT cnt
loopent y, %x
x = x + 1
ENDM
ENDM
;; Macros from p4notes.doc
read1 MACRO mem, c ;; Bytes to read
LOCAL loop1, loop2
cnt = mem/64 ;; Read 64 bytes per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: mov eax, [rsi] ;; Read one cache line
mov eax, [rsi+4] ;; 4 bytes at a time
mov eax, [rsi+8]
mov eax, [rsi+12]
mov eax, [rsi+16]
mov eax, [rsi+20]
mov eax, [rsi+24]
mov eax, [rsi+28]
mov eax, [rsi+32]
mov eax, [rsi+36]
mov eax, [rsi+40]
mov eax, [rsi+44]
mov eax, [rsi+48]
mov eax, [rsi+52]
mov eax, [rsi+56]
mov eax, [rsi+60]
lea rsi, [rsi+64] ; Next cache line
sub ecx, 1
jnz loop1
lea rsi, [rsi-mem] ; Restore esi
dec edx
jnz loop2
ENDM
read2 MACRO mem, c ;; Bytes to read
LOCAL loop1, loop2
cnt = mem/64 ; 64 bytes per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: movapd xmm1, [rsi] ; Read one cache line
movapd xmm1, [rsi+16] ; 16 bytes at a time
movapd xmm1, [rsi+32]
movapd xmm1, [rsi+48]
lea rsi, [rsi+64] ; Next cache line
sub ecx, 1
jnz loop1
lea rsi, [rsi-mem]
dec edx
jnz loop2
ENDM
read4 MACRO mem, c ;; Bytes to read
LOCAL loop1, loop2
cnt = mem/(4*64) ;; 4 cache lines per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: vmovapd ymm0, [rsi] ;; Read cache lines
vmovapd ymm1, [rsi+32]
vmovapd ymm2, [rsi+64]
vmovapd ymm3, [rsi+96]
vmovapd ymm4, [rsi+128]
vmovapd ymm5, [rsi+160]
vmovapd ymm6, [rsi+192]
vmovapd ymm7, [rsi+224]
add rsi, 4*64 ;; Next cache lines
sub ecx, 1
jnz loop1
sub rsi, cnt*4*64
dec edx
jnz loop2
ENDM
read8 MACRO mem, c ;; Bytes to read
LOCAL loop1, loop2
cnt = mem/(4*64) ;; 4 cache lines per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: vmovapd zmm0, [rsi] ;; Read cache lines
vmovapd zmm1, [rsi+64]
vmovapd zmm2, [rsi+128]
vmovapd zmm3, [rsi+192]
add rsi, 4*64 ;; Next cache lines
sub ecx, 1
jnz loop1
sub rsi, cnt*4*64
dec edx
jnz loop2
ENDM
write1 MACRO mem, c ;; Bytes to write
LOCAL loop1, loop2
cnt = mem/64 ; 64 bytes per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: movapd [rsi], xmm1 ; Write one cache line
movapd [rsi+16], xmm1 ; 16 bytes at a time
movapd [rsi+32], xmm1
movapd [rsi+48], xmm1
lea rsi, [rsi+64] ; Next cache line
sub ecx, 1
jnz loop1
lea rsi, [rsi-mem]
dec edx
jnz loop2
ENDM
write2 MACRO mem, c ;; Bytes to write
LOCAL loop1, loop2
cnt = mem/(4*128) ; 128 bytes per iteration
dist = 64
mov edx, c
sub ebx, ebx
loop2: mov ecx, cnt
loop1: movapd [rsi+0*dist], xmm1 ; Write 8 cache lines
movapd [rsi+1*dist], xmm1
movapd [rsi+2*dist], xmm1
movapd [rsi+3*dist], xmm1
movapd [rsi+4*dist], xmm1
movapd [rsi+5*dist], xmm1
movapd [rsi+6*dist], xmm1
movapd [rsi+7*dist], xmm1
lea rsi, [rsi+16] ; Same cache lines
add bl, 256/4 ; 4 inner loop iterations
jnc loop1
lea rsi, [rsi-4*16+8*dist] ; Next set of 8 cache lines
sub ecx, 1
jnz loop1
lea rsi, [rsi-mem]
dec edx
jnz loop2
ENDM
write4 MACRO mem, c ;; Bytes to write
LOCAL loop1, loop2
cnt = mem/(4*64) ;; 4 cache lines per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: vmovapd [rsi], ymm0 ;; Write cache lines
vmovapd [rsi+32], ymm1
vmovapd [rsi+64], ymm2
vmovapd [rsi+96], ymm3
vmovapd [rsi+128], ymm4
vmovapd [rsi+160], ymm5
vmovapd [rsi+192], ymm6
vmovapd [rsi+224], ymm7
add rsi, 4*64 ;; Next cache lines
sub ecx, 1
jnz loop1
sub rsi, cnt*4*64
dec edx
jnz loop2
ENDM
write8 MACRO mem, c ;; Bytes to write
LOCAL loop1, loop2
cnt = mem/(4*64) ;; 4 cache lines per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: vmovapd [rsi], zmm0 ;; Write cache lines
vmovapd [rsi+64], zmm1
vmovapd [rsi+128], zmm2
vmovapd [rsi+192], zmm3
add rsi, 4*64 ;; Next cache lines
sub ecx, 1
jnz loop1
sub rsi, cnt*4*64
dec edx
jnz loop2
ENDM
readwrite1 MACRO mem, c ;; Bytes to write
LOCAL loop1, loop2
cnt = mem/64
mov edx, c
loop2: mov ecx, cnt
loop1: movapd xmm0, [rsi] ; Read one cache line
movapd xmm1, [rsi+16]
movapd xmm2, [rsi+32]
movapd xmm3, [rsi+48]
subpd xmm0, xmm0 ; Operate on the data
pxor xmm1, xmm1
subpd xmm2, xmm2
pxor xmm3, xmm3
movapd [rsi], xmm0 ; Write the cache line
movapd [rsi+16], xmm1
movapd [rsi+32], xmm2
movapd [rsi+48], xmm3
lea rsi, [rsi+64] ; Next cache line
sub ecx, 1
jnz loop1
lea rsi, [rsi-mem]
dec edx
jnz loop2
ENDM
readwrite4 MACRO mem, c ;; Bytes to read/write
LOCAL loop1, loop2
cnt = mem/(4*64) ;; 4 cache lines per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: vmovapd ymm0, [rsi] ;; Read cache lines
vmovapd ymm1, [rsi+32]
vmovapd ymm2, [rsi+64]
vmovapd ymm3, [rsi+96]
vmovapd ymm4, [rsi+128]
vmovapd ymm5, [rsi+160]
vmovapd ymm6, [rsi+192]
vmovapd ymm7, [rsi+224]
vmovapd [rsi], ymm0 ;; Write cache lines
vmovapd [rsi+32], ymm1
vmovapd [rsi+64], ymm2
vmovapd [rsi+96], ymm3
vmovapd [rsi+128], ymm4
vmovapd [rsi+160], ymm5
vmovapd [rsi+192], ymm6
vmovapd [rsi+224], ymm7
add rsi, 4*64 ;; Next cache lines
sub ecx, 1
jnz loop1
sub rsi, cnt*4*64
dec edx
jnz loop2
ENDM
readwrite8 MACRO mem, c ;; Bytes to read/write
LOCAL loop1, loop2
cnt = mem/(4*64) ;; 4 cache lines per iteration
mov edx, c
loop2: mov ecx, cnt
loop1: vmovapd zmm0, [rsi] ;; Read cache lines
vmovapd zmm2, [rsi+64]
vmovapd zmm4, [rsi+128]
vmovapd zmm6, [rsi+192]
vmovapd [rsi], zmm0 ;; Write cache lines
vmovapd [rsi+64], zmm2
vmovapd [rsi+128], zmm4
vmovapd [rsi+192], zmm6
add rsi, 4*64 ;; Next cache lines
sub ecx, 1
jnz loop1
sub rsi, cnt*4*64 ;; Restore source pointer
dec edx
jnz loop2
ENDM
clocks50 MACRO
REPEAT 50
vpandq zmm0, zmm0, zmm1
ENDM
ENDM
sequential_readwrite8 MACRO mem, c ;; Bytes to read/write
LOCAL loop1, loop2, loop3
cnt = mem/(4*64) ;; 4 cache lines per iteration -- equivalent to clm=2
cnt1 = 1280 / 2 ;; Assumes pass 1 size of 1280, which equals 640 cache line pairs
cnt2 = cnt / cnt1 ;; This is number of pass 1 blocks
dist = 7680*16 + 29*64 ;; Assumes pass 2 does 7680 * 16 bytes + 29*64 pad bytes
mov edx, c
loop3: mov ecx, cnt1
loop2: mov ebx, cnt2
loop1: vmovapd zmm0, [rsi] ;; Read cache lines
vmovapd zmm2, [rsi+64]
vmovapd zmm4, [rsi+128]
vmovapd zmm6, [rsi+192]
prefetcht0 [rsi+4*64+0]
prefetcht0 [rsi+4*64+64]
; clocks50
prefetcht0 [rsi+4*64+128]
prefetcht0 [rsi+4*64+192]
clocks50
vmovapd [rsi], zmm0 ;; Write cache lines
vmovapd [rsi+64], zmm2
vmovapd [rsi+128], zmm4
vmovapd [rsi+192], zmm6
; vmovntpd [rsi], zmm0 ;; Write cache lines
; vmovntpd [rsi+64], zmm2
; vmovntpd [rsi+128], zmm4
; vmovntpd [rsi+192], zmm6
add rsi, 4*64 ;; Next cache lines
sub ebx, 1
jnz loop1
sub ecx, 1
jnz loop2
sub rsi, cnt2*cnt1*4*64 ;; Restore source pointer
dec edx
jnz loop3
ENDM
scatter_readwrite8 MACRO mem, c ;; Bytes to read/write
LOCAL loop1, loop2, loop3
cnt = mem/(4*64) ;; 4 cache lines per iteration -- equivalent to clm=2
cnt1 = 1280 / 2 ;; Assumes pass 1 size of 1280, which equals 640 cache line pairs
cnt2 = cnt / cnt1 ;; This is number of pass 1 blocks
dist = 7680*16 + 29*64 ;; Assumes pass 2 does 7680 * 16 bytes + 29*64 pad bytes
mov edx, c
loop3: mov ecx, cnt2
loop2: mov ebx, cnt1
loop1: vmovapd zmm0, [rsi] ;; Read cache lines
vmovapd zmm2, [rsi+64]
vmovapd zmm4, [rsi+128]
vmovapd zmm6, [rsi+192]
prefetcht0 [rsi+dist+0]
prefetcht0 [rsi+dist+64]
; clocks50
prefetcht0 [rsi+dist+128]
prefetcht0 [rsi+dist+192]
clocks50
vmovapd [rsi], zmm0 ;; Write cache lines
vmovapd [rsi+64], zmm2
vmovapd [rsi+128], zmm4
vmovapd [rsi+192], zmm6
; vmovntpd [rsi], zmm0 ;; Write cache lines
; vmovntpd [rsi+64], zmm2
; vmovntpd [rsi+128], zmm4
; vmovntpd [rsi+192], zmm6
add rsi, dist ;; Next cache lines
sub ebx, 1
jnz loop1
add rsi, -cnt1*dist+4*64 ;; Next cache lines
sub ecx, 1
jnz loop2
sub rsi, cnt2*4*64 ;; Restore source pointer
dec edx
jnz loop3
ENDM
;;newer version simulating half as many large strides
scatter_readwrite8 MACRO mem, c ;; Bytes to read/write
LOCAL loop1, loop2, loop3
cnt = mem/(8*64) ;; 4 cache lines per iteration -- equivalent to clm=4
cnt1 = 1280 / 2 ;; Assumes pass 1 size of 1280, which equals 640 cache line pairs
cnt2 = cnt / cnt1 ;; This is number of pass 1 blocks
dist = 7680*16 + 29*64 ;; Assumes pass 2 does 7680 * 16 bytes + 29*64 pad bytes
mov edx, c
loop3: mov ecx, cnt2
loop2: mov ebx, cnt1
loop1: vmovapd zmm0, [rsi] ;; Read cache lines
vmovapd zmm2, [rsi+64]
vmovapd zmm4, [rsi+128]
vmovapd zmm6, [rsi+192]
prefetcht0 [rsi+dist+0]
prefetcht0 [rsi+dist+64]
prefetcht0 [rsi+dist+128]
prefetcht0 [rsi+dist+192]
clocks50
vmovapd [rsi], zmm0 ;; Write cache lines
vmovapd [rsi+64], zmm2
vmovapd [rsi+128], zmm4
vmovapd [rsi+192], zmm6
vmovapd zmm0, [rsi+256] ;; Read cache lines
vmovapd zmm2, [rsi+256+64]
vmovapd zmm4, [rsi+256+128]
vmovapd zmm6, [rsi+256+192]
prefetcht0 [rsi+dist+256+0]
prefetcht0 [rsi+dist+256+64]
prefetcht0 [rsi+dist+256+128]
prefetcht0 [rsi+dist+256+192]
clocks50
vmovapd [rsi+256], zmm0 ;; Write cache lines
vmovapd [rsi+256+64], zmm2
vmovapd [rsi+256+128], zmm4
vmovapd [rsi+256+192], zmm6
add rsi, dist ;; Next cache lines
sub ebx, 1
jnz loop1
add rsi, -cnt1*dist+8*64 ;; Next cache lines
sub ecx, 1
jnz loop2
sub rsi, cnt2*8*64 ;; Restore source pointer
dec edx
jnz loop3
ENDM
sequential_read_scatter_write8 MACRO mem, c ;; Bytes to read/write
LOCAL loop1, loop2, loop3
cnt = mem/(4*64) ;; 4 cache lines per iteration -- equivalent to clm=2
cnt1 = 1280 / 2 ;; Assumes pass 1 size of 1280, which equals 640 cache line pairs
cnt2 = cnt / cnt1 ;; This is number of pass 1 blocks
dist = 7680*16 + 29*64 ;; Assumes pass 2 does 7680 * 16 bytes + 29*64 pad bytes
lea rdi, [rsi+96*1024*1024] ;; write to separate mem address 96MB away
mov edx, c
loop3: mov ecx, cnt2
loop2: mov ebx, cnt1
loop1: vmovapd zmm0, [rsi] ;; Read cache lines
vmovapd zmm2, [rsi+64]
vmovapd zmm4, [rsi+128]
vmovapd zmm6, [rsi+192]
prefetcht0 [rsi+4*64+0]
prefetcht0 [rsi+4*64+64]
; clocks50
prefetcht0 [rsi+4*64+128]
prefetcht0 [rsi+4*64+192]
clocks50
; vmovapd [rdi], zmm0 ;; Write cache lines
; vmovapd [rdi+64], zmm2
; vmovapd [rdi+128], zmm4
; vmovapd [rdi+192], zmm6
vmovntpd [rdi], zmm0 ;; Write cache lines
vmovntpd [rdi+64], zmm2
vmovntpd [rdi+128], zmm4
vmovntpd [rdi+192], zmm6
add rsi, 4*64 ;; Next cache lines
add rdi, dist ;; Next cache lines
sub ebx, 1
jnz loop1
add rdi, -cnt1*dist+4*64 ;; Next cache lines
sub ecx, 1
jnz loop2
sub rsi, cnt1*cnt2*4*64 ;; Restore source pointer
sub rdi, cnt2*4*64 ;; Restore dest pointer
dec edx
jnz loop3
ENDM
scatter_read_sequential_write8 MACRO mem, c ;; Bytes to read/write
LOCAL loop1, loop2, loop3
cnt = mem/(4*64) ;; 4 cache lines per iteration -- equivalent to clm=2
cnt1 = 1280 / 2 ;; Assumes pass 1 size of 1280, which equals 640 cache line pairs
cnt2 = cnt / cnt1 ;; This is number of pass 1 blocks
dist = 7680*16 + 29*64 ;; Assumes pass 2 does 7680 * 16 bytes + 29*64 pad bytes
lea rdi, [rsi+96*1024*1024] ;; write to separate mem address 96MB away
mov edx, c
loop3: mov ecx, cnt2
loop2: mov ebx, cnt1
loop1: vmovapd zmm0, [rsi] ;; Read cache lines
vmovapd zmm2, [rsi+64]
vmovapd zmm4, [rsi+128]
vmovapd zmm6, [rsi+192]
prefetcht0 [rsi+dist+0]
prefetcht0 [rsi+dist+64]
; clocks50
prefetcht0 [rsi+dist+128]
prefetcht0 [rsi+dist+192]
clocks50
; vmovapd [rdi], zmm0 ;; Write cache lines
; vmovapd [rdi+64], zmm2
; vmovapd [rdi+128], zmm4
; vmovapd [rdi+192], zmm6
vmovntpd [rdi], zmm0 ;; Write cache lines
vmovntpd [rdi+64], zmm2
vmovntpd [rdi+128], zmm4
vmovntpd [rdi+192], zmm6
add rsi, dist ;; Next cache lines
add rdi, 4*64 ;; Next cache lines
sub ebx, 1
jnz loop1
add rsi, -cnt1*dist+4*64 ;; Next cache lines
sub ecx, 1
jnz loop2
sub rsi, cnt2*4*64 ;; Restore source pointer
sub rdi, cnt1*cnt2*4*64 ;; Restore dest pointer
dec edx
jnz loop3
ENDM
x4cl_empty MACRO srcreg,srcinc,d1,d2,screg,scoff
xload xmm0, [srcreg+0]
xload xmm1, [srcreg+32]
xload xmm2, [srcreg+d1+0]
xload xmm3, [srcreg+d1+32]
xload xmm4, [srcreg+d2+0]
xload xmm5, [srcreg+d2+32]
xload xmm6, [srcreg+d2+d1+0]
xload xmm7, [srcreg+d2+d1+32]
xstore [srcreg+0], xmm0
xstore [srcreg+32], xmm1
xload xmm0, [srcreg+0+16]
xload xmm1, [srcreg+32+16]
xstore [srcreg+16], xmm2
xstore [srcreg+48], xmm3
xload xmm2, [srcreg+d1+0+16]
xload xmm3, [srcreg+d1+32+16]
xstore [srcreg+d1], xmm4
xstore [srcreg+d1+16], xmm5
xstore [srcreg+d1+32], xmm6
xstore [srcreg+d1+48], xmm7
xload xmm4, [srcreg+d2+0+16]
xload xmm5, [srcreg+d2+32+16]
xload xmm6, [srcreg+d2+d1+0+16]
xload xmm7, [srcreg+d2+d1+32+16]
xstore [srcreg+d2], xmm0
xstore [srcreg+d2+16], xmm1
xstore [srcreg+d2+32], xmm2
xstore [srcreg+d2+48], xmm3
xstore [srcreg+d2+d1], xmm4
xstore [srcreg+d2+d1+16], xmm5
xstore [srcreg+d2+d1+32], xmm6
xstore [srcreg+d2+d1+48], xmm7
bump srcreg, srcinc
ENDM
g4cl_empty MACRO srcreg,srcinc,d1,d2,dstreg,dstinc,e1,e2,screg,scoff
xload xmm0, [srcreg+0]
xload xmm1, [srcreg+32]
xload xmm2, [srcreg+d1+0]
xload xmm3, [srcreg+d1+32]
xload xmm4, [srcreg+d2+0]
xload xmm5, [srcreg+d2+32]
xload xmm6, [srcreg+d2+d1+0]
xload xmm7, [srcreg+d2+d1+32]
xstore [dstreg+0], xmm0
xstore [dstreg+32], xmm1
xload xmm0, [srcreg+0+16]
xload xmm1, [srcreg+32+16]
xstore [dstreg+16], xmm2
xstore [dstreg+48], xmm3
xload xmm2, [srcreg+d1+0+16]
xload xmm3, [srcreg+d1+32+16]
xstore [dstreg+e1], xmm4
xstore [dstreg+e1+16], xmm5
xstore [dstreg+e1+32], xmm6
xstore [dstreg+e1+48], xmm7
xload xmm4, [srcreg+d2+0+16]
xload xmm5, [srcreg+d2+32+16]
xload xmm6, [srcreg+d2+d1+0+16]
xload xmm7, [srcreg+d2+d1+32+16]
bump srcreg, srcinc
xstore [dstreg+e2], xmm0
xstore [dstreg+e2+16], xmm1
xstore [dstreg+e2+32], xmm2
xstore [dstreg+e2+48], xmm3
xstore [dstreg+e2+e1], xmm4
xstore [dstreg+e2+e1+16], xmm5
xstore [dstreg+e2+e1+32], xmm6
xstore [dstreg+e2+e1+48], xmm7
bump dstreg, dstinc
ENDM
g4cl_empty_nt MACRO srcreg,srcinc,d1,d2,dstreg,dstinc,e1,e2,screg,scoff
xload xmm0, [srcreg+0]
xload xmm1, [srcreg+32]
xload xmm2, [srcreg+d1+0]
xload xmm3, [srcreg+d1+32]
xload xmm4, [srcreg+d2+0]
xload xmm5, [srcreg+d2+32]
xload xmm6, [srcreg+d2+d1+0]
xload xmm7, [srcreg+d2+d1+32]
movntpd [dstreg+0], xmm0
movntpd [dstreg+32], xmm1
xload xmm0, [srcreg+0+16]
xload xmm1, [srcreg+32+16]
movntpd [dstreg+16], xmm2
movntpd [dstreg+48], xmm3
xload xmm2, [srcreg+d1+0+16]
xload xmm3, [srcreg+d1+32+16]
movntpd [dstreg+e1], xmm4
movntpd [dstreg+e1+16], xmm5
movntpd [dstreg+e1+32], xmm6
movntpd [dstreg+e1+48], xmm7
xload xmm4, [srcreg+d2+0+16]
xload xmm5, [srcreg+d2+32+16]
xload xmm6, [srcreg+d2+d1+0+16]
xload xmm7, [srcreg+d2+d1+32+16]
bump srcreg, srcinc
movntpd [dstreg+e2], xmm0
movntpd [dstreg+e2+16], xmm1
movntpd [dstreg+e2+32], xmm2
movntpd [dstreg+e2+48], xmm3
movntpd [dstreg+e2+e1], xmm4
movntpd [dstreg+e2+e1+16], xmm5
movntpd [dstreg+e2+e1+32], xmm6
movntpd [dstreg+e2+e1+48], xmm7
bump dstreg, dstinc
ENDM
;; Time one of the basic FFT building blocks
x87mac MACRO memused, memarea, ops:vararg
LOCAL ss0a, ss0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
mov eax, outer_iters
mov SRCARG, rdi ;; Save work buf addr
ss0a: mov rdi, SRCARG ;; Reload work buf addr
lea rsi, [rdi+4096]
mov ecx, inner_iters
ss0b: disp &ops
lea rsi, [rsi+memused] ;; Next source pointer
lea rdi, [rdi+SCD] ;; Next sine/cosine pointer
dec ecx
jnz ss0b
dec eax
jnz ss0a
ENDM
sse2mac MACRO lab, memused, memarea, ops:vararg
LOCAL ss0a, ss0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab: mov rbx, 0 ;; Offset for some sse2 macros (s.b. non-zero for with_mult macros)
mov rbp, 524288+256 ;; Offset for mulf sse2 macros
mov eax, outer_iters
mov ecx, odd_iters
mov SRCARG, rdi ;; Save work buf addr
ss0a: mov rdi, SRCARG ;; Reload work buf addr (sincos data)
lea rsi, [rdi+262144+4096+64] ;; Source & dest ptr
lea rdx, [rsi+524288+256] ;; Destination for "g" macros
ss0b: &ops
IF memused NE 192
lea rdi, [rdi+2*XMM_SCD] ;; Next sine/cosine pointer
ELSE
lea rdi, [rdi+XMM_SCD1] ;; Next sine/cosine pointer
ENDIF
dec ecx
jnz ss0b
mov ecx, inner_iters
dec eax
jnz ss0a
jmp exit
ENDM
sse2macbx MACRO lab, memused, memarea, ops:vararg
LOCAL ss0a, ss0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab: mov rbx, 262144+128 ;; Offset for some sse2 macros (s.b. non-zero for with_mult macros)
mov rbp, 524288+256 ;; Offset for mulf sse2 macros
mov eax, outer_iters
mov ecx, odd_iters
mov SRCARG, rdi ;; Save work buf addr
ss0a: mov rdi, SRCARG ;; Reload work buf addr (sincos data)
lea rsi, [rdi+262144+4096+64] ;; Source & dest ptr
lea rdx, [rsi+524288+256] ;; Destination for "g" macros
ss0b: &ops
IF memused NE 192
lea rdi, [rdi+2*XMM_SCD] ;; Next sine/cosine pointer
ELSE
lea rdi, [rdi+XMM_SCD1] ;; Next sine/cosine pointer
ENDIF
dec ecx
jnz ss0b
mov ecx, inner_iters
dec eax
jnz ss0a
jmp exit
ENDM
avxmac MACRO memused, memarea, rdi_incr, ops:vararg
LOCAL avxlabel
avxlabel CATSTR <avcase>,%avx_case_num
avx_case_num = avx_case_num + 1
avxmac1 avxlabel, memused, memarea, rdi_incr, ops
ENDM
avxmac1 MACRO lab, memused, memarea, rdi_incr, ops:vararg
LOCAL av00, av0a, av0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab: mov rbx, 0 ;; Offset for some avx macros (s.b. non-zero for with_mult macros)
mov rbp, 524288+256 ;; Offset for mulf avx macros
mov eax, outer_iters
mov ecx, odd_iters
IFDEF X86_64
mov r8, 0 ;; yr4 and yr8 macros use this for optional distance between the two destination registers
ENDIF
mov SRCARG, rdi ;; Save work buf addr
av0a: mov rdi, SRCARG ;; Reload work buf addr (sincos data)
lea rsi, [rdi+262144+4096+64] ;; Source & dest ptr
lea rdx, [rsi+524288+256] ;; Destination for "g" macros
av0b: &ops
bump rdi, rdi_incr ;; Next sine/cosine pointer
dec ecx
jnz av0b
mov ecx, inner_iters
dec eax
jnz av0a
jmp exit
ENDM
avxmacbx MACRO memused, memarea, rdi_incr, ops:vararg
LOCAL avxlabel
avxlabel CATSTR <avcase>,%avx_case_num
avx_case_num = avx_case_num + 1
avxmacbx1 avxlabel, memused, memarea, rdi_incr, ops
ENDM
avxmacbx1 MACRO lab, memused, memarea, rdi_incr, ops:vararg
LOCAL av0a, av0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab: mov rbx, 262144+128 ;; Offset for some sse2 macros (s.b. non-zero for with_mult macros)
mov rbp, 524288+256 ;; Offset for mulf sse2 macros
mov eax, outer_iters
mov ecx, odd_iters
mov SRCARG, rdi ;; Save work buf addr
av0a: mov rdi, SRCARG ;; Reload work buf addr (sincos data)
lea rsi, [rdi+262144+4096+64] ;; Source & dest ptr
lea rdx, [rsi+524288+256] ;; Destination for "g" macros
av0b: &ops
bump rdi, rdi_incr ;; Next sine/cosine pointer
dec ecx
jnz av0b
mov ecx, inner_iters
dec eax
jnz av0a
jmp exit
ENDM
ynormmac MACRO memused, memarea, ops:vararg
LOCAL avxlabel
avxlabel CATSTR <avcase>,%avx_case_num
avx_case_num = avx_case_num + 1
ynormmac1 avxlabel, memused, memarea, ops
ENDM
ynormmac1 MACRO lab, memused, memarea, ops:vararg
LOCAL av00, av0a, av0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab: mov edx, outer_iters
mov ebx, odd_iters
mov SRCARG, rdi ;; Save work buf addr
av0a: mov rsi, SRCARG ;; Reload work buf addr (FFT data)
lea rbp, [rsi+524288+256] ;; Addr of the multipliers
; mov rdi, norm_biglit_array ;; Addr of the big/little flags array
lea rdi, [rsi+5000000]
av0b: &ops
bump rsi, 64 ;; Next cache line
bump rbp, 128 ;; Next set of 8 multipliers
bump rdi, 2 ;; Next big/little flags
dec ebx
jnz av0b
mov ebx, inner_iters
dec edx
jnz av0a
jmp exit
ENDM
ynormwpnmac MACRO memused, memarea, ops:vararg
LOCAL avxlabel
avxlabel CATSTR <avcase>,%avx_case_num
avx_case_num = avx_case_num + 1
ynormwpnmac1 avxlabel, memused, memarea, ops
ENDM
ynormwpnmac1 MACRO lab, memused, memarea, ops:vararg
LOCAL av00, av0a, av0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab:
mov COPYZERO, outer_iters
mov ebp, odd_iters
mov SRCARG, rdi ;; Save work buf addr
av0a: mov rsi, SRCARG ;; Reload work buf addr (FFT data)
mov rdx, norm_grp_mults ;; Addr of the group multipliers
mov rdi, norm_biglit_array ;; Addr of the big/little flags array
IFDEF X86_64
lea r9, [rdx+2*YMM_GMD] ;; Prefetch pointer for group multipliers
ENDIF
movzx rbx, WORD PTR [rdi] ;; Preload 4 big vs. little & fudge flags
av0b: &ops
bump rsi, 64 ;; Next cache line
bump rdi, 2 ;; Next big/little flags
; bump rdx, 2*YMM_GMD ;; Next set of group multipliers
bump rdx, 64
dec rbp
jnz av0b
mov ebp, inner_iters
dec COPYZERO
jnz av0a
jmp exit
ENDM
IFNDEF X86_64
ynormwpn4mac MACRO memused, memarea, ops:vararg
ynormwpnmac memused, memarea, ops
ENDM
ELSE
ynormwpn4mac MACRO memused, memarea, ops:vararg
LOCAL avxlabel
avxlabel CATSTR <avcase>,%avx_case_num
avx_case_num = avx_case_num + 1
ynormwpn4mac1 avxlabel, memused, memarea, ops
ENDM
ynormwpn4mac1 MACRO lab, memused, memarea, ops:vararg
LOCAL av00, av0a, av0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab:
mov COPYZERO, outer_iters
mov ebp, odd_iters
mov SRCARG, rdi ;; Save work buf addr
av0a: mov rsi, SRCARG ;; Reload work buf addr (FFT data)
lea r13, [rsi+8192+256] ;; Source ptr #2
mov r12, norm_grp_mults ;; Addr of the group multipliers
lea r15, [r12+2*YMM_GMD] ;; Addr of the group multipliers #2
lea r9, [r15+2*YMM_GMD] ;; Prefetch pointer for group multipliers
mov rdi, norm_biglit_array ;; Addr of the big/little flags array
lea r14, [rdi+4096+128] ;; Addr of the big/little flags array #2
movzx rbx, WORD PTR [rdi] ;; Preload 4 big vs. little & fudge flags
movzx rcx, WORD PTR [r14] ;; Preload 4 big vs. little & fudge flags
av0b: &ops
bump rsi, 64 ;; Next cache line
bump rdi, 2 ;; Next big/little flags
bump r13, 64 ;; Next cache line
bump r14, 2 ;; Next big/little flags
; bump r12, 4*YMM_GMD ;; Next set of group multipliers
bump r12, 64
bump r15, 64
dec rbp
jnz av0b
mov ebp, inner_iters
dec COPYZERO
jnz av0a
jmp exit
ENDM
ENDIF
avx512mac MACRO memused, memarea, rdi_incr, ops:vararg
LOCAL avx512label
avx512label CATSTR <av512case>,%avx512_case_num
avx512mac1 avx512label, memused, memarea, rdi_incr, ops
avx512_case_num = avx512_case_num + 1
ENDM
avx512mac1 MACRO lab, memused, memarea, rdi_incr, ops:vararg
LOCAL av00, av0a, av0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab: mov rbx, 0 ;; Offset for some avx macros (s.b. non-zero for with_mult macros)
mov rbp, 524288+256 ;; Offset for mulf avx macros
mov r12, norm_grp_mults
mov r13, r12
IF (avx512_case_num GE 108 AND avx512_case_num LT 116)
mov r8, 128 ;; d1reg for "rsc" macros
mov r9, 384 ;; d3reg for "rsc" macros
ELSE
mov r8, 0 ;; zr64 macros use this for optional distance between the two destination registers
mov r9, 0 ;; unused by any macro
ENDIF
mov eax, outer_iters
mov ecx, odd_iters
mov SRCARG, rdi ;; Save work buf addr
av0a: mov rdi, SRCARG ;; Reload work buf addr (sincos data)
lea rsi, [rdi+262144+4096+64] ;; Source & dest ptr
lea rdx, [rsi+524288+8192+256] ;; Destination for "rsc" macros
lea r10, [rdx+512] ;; src4reg/dst4reg for "rsc" macros
lea r15, [rdx+262144+256+64] ;; s/c data for first macros
IF avx512_case_num-1 EQ IACA_TEST_CASE
IACA_START
ENDIF
av0b: &ops
bump rdi, rdi_incr ;; Next sine/cosine pointer
dec ecx
jnz av0b
IF avx512_case_num-1 EQ IACA_TEST_CASE
IACA_END
ENDIF
mov ecx, inner_iters
dec eax
jnz av0a
jmp exit
ENDM
avx512znormmac MACRO memused, memarea, rdi_incr, ops:vararg
LOCAL avx512label
avx512label CATSTR <av512case>,%avx512_case_num
avx512_case_num = avx512_case_num + 1
avx512znormmac1 avx512label, memused, memarea, rdi_incr, ops
ENDM
avx512znormmac1 MACRO lab, memused, memarea, rdi_incr, ops:vararg
LOCAL av00, av0a, av0b
inner_iters = memarea / (memused)
outer_iters = 10000 / inner_iters
odd_iters = 10000 - inner_iters * outer_iters
IF odd_iters EQ 0
odd_iters = inner_iters
ELSE
outer_iters = outer_iters + 1
ENDIF
lab: mov rbx, 0 ;; Offset for some avx macros (s.b. non-zero for with_mult macros)
mov rbp, 524288+256 ;; Offset for mulf avx macros
mov r12, norm_grp_mults
mov r13, r12
mov eax, outer_iters
mov ecx, odd_iters
mov SRCARG, rdi ;; Save work buf addr
av0a: mov rdi, SRCARG ;; Reload work buf addr (sincos data)
lea rsi, [rdi+262144+4096+64] ;; Source & dest ptr
mov r14, 262144+4096+64
lea r13, [rsi+r14*2]
lea r8, [rdi+4096]
lea r10, [r8+4096+64]
sub rdx, rdx
IF avx512_case_num-1 EQ IACA_TEST_CASE
IACA_START
ENDIF
av0b: &ops
bump rsi, 128
bump r13, 128
bump rdi, 1
dec ecx
jnz av0b
IF avx512_case_num-1 EQ IACA_TEST_CASE
IACA_END
ENDIF
mov ecx, inner_iters
dec eax
jnz av0a
jmp exit
ENDM
do2 MACRO ops:vararg
&ops
&ops
ENDM
do5 MACRO ops:vararg
do2 &ops
do2 &ops
&ops
ENDM
do10 MACRO ops:vararg
do2 do5 &ops
ENDM
fiveclocks MACRO
vaddpd ymm0, ymm0, ymm0
vaddpd ymm1, ymm1, ymm1
vaddpd ymm2, ymm2, ymm2
vaddpd ymm3, ymm3, ymm3
vaddpd ymm4, ymm4, ymm4
vaddpd ymm5, ymm5, ymm5
vaddpd ymm6, ymm6, ymm6
vaddpd ymm7, ymm7, ymm7
vaddpd ymm8, ymm8, ymm8
vaddpd ymm9, ymm9, ymm9
ENDM
tenclocks MACRO
fiveclocks
fiveclocks
ENDM
hundredclocks MACRO
do10 tenclocks
ENDM
fiveclocks512 MACRO
vaddpd zmm0, zmm0, zmm0
vaddpd zmm1, zmm1, zmm1
vaddpd zmm2, zmm2, zmm2
vaddpd zmm3, zmm3, zmm3
vaddpd zmm4, zmm4, zmm4
vaddpd zmm5, zmm5, zmm5
vaddpd zmm6, zmm6, zmm6
vaddpd zmm7, zmm7, zmm7
vaddpd zmm8, zmm8, zmm8
vaddpd zmm9, zmm9, zmm9
ENDM
tenclocks512 MACRO
fiveclocks512
fiveclocks512
ENDM
hundredclocks512 MACRO
do10 tenclocks512
ENDM
_TEXT SEGMENT
x87table: looptab case, X87_CASES
sse2table: looptab sscase, SSE2_CASES
avxtable: looptab avcase, AVX_CASES
avx512table: looptab av512case, AVX512_CASES
; gwtimeit (asm_data)
; Time a mini benchmark
; Windows 32-bit (_gwtimeit)
; Linux 32-bit (gwtimeit)
; Parameter asm_data = [esp+4]
; Windows 64-bit (gwtimeit)
; Parameter asm_data = rcx
; Linux 64-bit (gwtimeit)
; Parameter asm_data = rdi
PROCFL gwtimeit
ad_prolog 0,0,rbx,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15,xmm6,xmm7,xmm8,xmm9,xmm10,xmm11,xmm12,xmm13,xmm14,xmm15
mov rdi, PPTR [AD_BASE] ; Load work buf address
mov rsi, rdi
mov edx, DPTR [AD_BASE+8] ; Load n (which test to run)
sub ebx, ebx ; Clear registers
sub ecx, ecx
sub ebp, ebp
mov eax, X87_CASES
cmp edx, -1 ; -1 = get num x87 cases
je exit
mov eax, SSE2_CASES
cmp edx, -2 ; -2 = get num sse2 cases
je exit
mov eax, AVX_CASES
cmp edx, -3 ; -3 = get num avx cases
je exit
mov eax, AVX512_CASES
cmp edx, -4 ; -4 = get num avx512 cases
je exit
cmp edx, 1000 ; Tests below 1000 are x87 code
jl x87
cmp edx, 2000 ; Tests below 2000 are SSE2 code
jl short sse2
cmp edx, 3000 ; Tests below 3000 are AVX code
jl short avx
; Init registers and jump to desired AVX test case
vzeroall ; Clear ZMM registers
sub rdx, 3000
mov rax, OFFSET avx512table
mov rax, [rax+rdx*SZPTR]; Get address of test to execute
jmp rax
; Init registers and jump to desired AVX test case
avx: vzeroall ; Clear YMM registers
sub rdx, 2000
mov rax, OFFSET avxtable
mov rax, [rax+rdx*SZPTR]; Get address of test to execute
jmp rax
; Init registers and jump to desired SSE2 test case
sse2: subpd xmm0, xmm0 ; Clear XMM registers
subpd xmm1, xmm1
subpd xmm2, xmm2
subpd xmm3, xmm3
subpd xmm4, xmm4
subpd xmm5, xmm5
subpd xmm6, xmm6
subpd xmm7, xmm7
IFDEF X86_64
subpd xmm8, xmm8
subpd xmm9, xmm9
subpd xmm10, xmm10
subpd xmm11, xmm11
subpd xmm12, xmm12
subpd xmm13, xmm13
subpd xmm14, xmm14
subpd xmm15, xmm15
ENDIF
sub rdx, 1000
mov rax, OFFSET sse2table
mov rax, [rax+rdx*SZPTR]; Get address of test to execute
jmp rax
; Jump to desired x87 test case
x87: mov rax, OFFSET x87table
mov rax, [rax+rdx*SZPTR]; Get address of test to execute
jmp rax
; Time the "do-nothing" case.
IFNDEF X86_64
case0:
jmp exit
; Time the loop of "do-nothing" case. 1000 iterations.
case1:
mov ecx, 1000
c1a: dec ecx
jnz c1a
jmp exit
; This code reads a contiguous block of memory.
; Timings are done on 3 memory size. 4KB will read from the L1 cache
; only, 96KB will read from the L2 cache only, and 2MB will test reading
; from main memory.
case2: read1 4096, 1000 ; Read 4KB
jmp exit
case3: read1 96*1024, 100 ; Read 96KB
jmp exit
case4: read1 2048*1024, 2 ; Read 2MB
jmp exit
case5: x87mac 64, 4096, eight_reals_fft, 8, 16, 32
jmp exit
case6: x87mac 64, 100000, eight_reals_fft, 8, 16, 32
jmp exit
case7: x87mac 64, 4096, eight_reals_unfft, 8, 16, 32
jmp exit
case8: x87mac 64, 100000, eight_reals_unfft, 8, 16, 32
jmp exit
case9: x87mac 64, 4096, four_complex_fft, 8, 16, 32
jmp exit
case10: x87mac 64, 100000, four_complex_fft, 8, 16, 32
jmp exit
case11: x87mac 64, 4096, four_complex_unfft, 8, 16, 32
jmp exit
case12: x87mac 64, 100000, four_complex_unfft, 8, 16, 32
jmp exit
ENDIF
; This code reads a contiguous block of memory.
; Timings are done on 3 memory size. 4KB will read from the L1 cache
; only, 96KB will read from the L2 cache only, and 32MB will test reading
; from main memory.
sscase0:
read2 4096, 1000 ; Read 4KB
jmp exit
sscase1:
read2 96*1024, 100 ; Read 96KB
jmp exit
sscase2:
read2 32768*1024, 2 ; Read 32MB
jmp exit
; This code writes a contiguous block of memory.
; Timings are done on 3 memory size. 4KB will write to the L1 cache
; only, 96KB will write to L2 cache only, and 32MB will test writing
; to main memory.
sscase3:
write1 4096, 1000 ; Write 4KB
jmp exit
sscase4:
write1 96*1024, 100 ; Write 96KB
jmp exit
sscase5:
write1 32768*1024, 2 ; Write 32MB
jmp exit
; This code writes a block of memory non-contiguously.
; Timings are done on 3 memory size. 4KB will write to the L1 cache
; only, 96KB will write to L2 cache only, and 32MB will test writing
; to main memory.
sscase6:
write2 4096, 1000 ; Read 4KB
jmp exit
sscase7:
write2 96*1024, 100 ; Read 96KB
jmp exit
sscase8:
write2 32768*1024, 2 ; Read 32MB
jmp exit
; This code reads & writes a block of memory.
; Timings are done on 3 memory size. 4KB will write to the L1 cache
; only, 96KB will write to L2 cache only, and 32MB will test writing
; to main memory.
sscase9:
readwrite1 4096, 1000 ; Read 4KB
jmp exit
sscase10:
readwrite1 96*1024, 100 ; Read 96KB
jmp exit
sscase11:
readwrite1 32768*1024, 2 ; Read 32MB
jmp exit
; Time ~10000 iterations of the SSE2 macros in L1 and L2 caches
sse2mac sscase12, 128, 4096, x2cl_eight_reals_fft rsi, 2*64, 64
sse2mac sscase13, 128, 100000, x2cl_eight_reals_fft rsi, 2*64, 64
sse2mac sscase14, 128, 4096, x2cl_eight_reals_first_fft rsi, 2*64, 64
sse2mac sscase15, 128, 100000, x2cl_eight_reals_first_fft rsi, 2*64, 64
sse2mac sscase16, 128, 4096, x2cl_eight_reals_fft_2 rsi, 2*64, 64
sse2mac sscase17, 128, 100000, x2cl_eight_reals_fft_2 rsi, 2*64, 64
sse2mac sscase18, 128, 4096, x2cl_eight_reals_fft_1 rsi, 2*64, 64
sse2mac sscase19, 128, 100000, x2cl_eight_reals_fft_1 rsi, 2*64, 64
sse2mac sscase20, 128, 4096, s2cl_eight_reals_first_fft rsi, 2*64, 64
sse2mac sscase21, 128, 100000, s2cl_eight_reals_first_fft rsi, 2*64, 64
sse2mac sscase22, 128, 4096, s2cl_eight_reals_fft_1 rsi, 2*64, 64
sse2mac sscase23, 128, 100000, s2cl_eight_reals_fft_1 rsi, 2*64, 64
sse2mac sscase24, 128, 4096, s2cl_eight_reals_with_square_2 rsi, 2*64, 64
sse2mac sscase25, 128, 100000, s2cl_eight_reals_with_square_2 rsi, 2*64, 64
sse2mac sscase26, 128, 4096, s2cl_eight_reals_fft_2_final rsi, 2*64, 64
sse2mac sscase27, 128, 100000, s2cl_eight_reals_fft_2_final rsi, 2*64, 64
sse2mac sscase28, 128, 4096, s2cl_eight_reals_with_square_2 rsi, 2*64, 64
sse2mac sscase29, 128, 100000, s2cl_eight_reals_with_square_2 rsi, 2*64, 64
sse2macbx sscase30, 128, 4096, s2cl_eight_reals_with_mult_2 rsi, 2*64, 64
sse2macbx sscase31, 128, 100000, s2cl_eight_reals_with_mult_2 rsi, 2*64, 64
sse2macbx sscase32, 128, 4096, s2cl_eight_reals_with_mulf_2 rsi, 2*64, 64
sse2macbx sscase33, 128, 100000, s2cl_eight_reals_with_mulf_2 rsi, 2*64, 64
sse2mac sscase34, 256, 4096, x4cl_eight_reals_fft_2 rsi, 4*64, 64, 2*64, rdi
sse2mac sscase35, 256, 100000, x4cl_eight_reals_fft_2 rsi, 4*64, 64, 2*64, rdi
sse2mac sscase36, 256, 4096, g4cl_eight_reals_fft_2 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64
sse2mac sscase37, 256, 100000, g4cl_eight_reals_fft_2 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64
sse2mac sscase38, 128, 4096, x2cl_eight_reals_unfft_2 rsi, 2*64, 64
sse2mac sscase39, 128, 100000, x2cl_eight_reals_unfft_2 rsi, 2*64, 64
sse2mac sscase40, 128, 4096, x2cl_half_eight_reals_unfft_2 rsi, 2*64, 64
sse2mac sscase41, 128, 100000, x2cl_half_eight_reals_unfft_2 rsi, 2*64, 64
sse2mac sscase42, 128, 4096, g2cl_eight_reals_unfft_2 rsi, 2*64, 64, rdx, 2*64, 64
sse2mac sscase43, 128, 100000, g2cl_eight_reals_unfft_2 rsi, 2*64, 64, rdx, 2*64, 64
sse2mac sscase44, 256, 4096, x4cl_eight_reals_last_unfft rsi, 4*64, 64, 2*64
sse2mac sscase45, 256, 100000, x4cl_eight_reals_last_unfft rsi, 4*64, 64, 2*64
sse2mac sscase46, 256, 4096, x4cl_eight_reals_unfft_2 rsi, 4*64, 64, 2*64
sse2mac sscase47, 256, 100000, x4cl_eight_reals_unfft_2 rsi, 4*64, 64, 2*64
sse2mac sscase48, 256, 4096, s4cl_eight_reals_unfft_1 rsi, 4*64, 64, 2*64
sse2mac sscase49, 256, 100000, s4cl_eight_reals_unfft_1 rsi, 4*64, 64, 2*64
sse2mac sscase50, 128, 4096, x2cl_two_complex_fft rsi, 2*64, 64, rdi
sse2mac sscase51, 128, 100000, x2cl_two_complex_fft rsi, 2*64, 64, rdi
sse2mac sscase52, 128, 4096, x2cl_two_complex_fft_in_place rsi, 2*64, 64, rdi
sse2mac sscase53, 128, 100000, x2cl_two_complex_fft_in_place rsi, 2*64, 64, rdi
sse2mac sscase54, 128, 4096, x2cl_two_complex_unfft rsi, 2*64, 64
sse2mac sscase55, 128, 100000, x2cl_two_complex_unfft rsi, 2*64, 64
sse2mac sscase56, 128, 4096, x2cl_four_complex_fft rsi, 2*64, 64
sse2mac sscase57, 128, 100000, x2cl_four_complex_fft rsi, 2*64, 64
sse2mac sscase58, 128, 4096, x2cl_four_complex_first_fft rsi, 2*64, 64
sse2mac sscase59, 128, 100000, x2cl_four_complex_first_fft rsi, 2*64, 64
sse2mac sscase60, 128, 4096, s2cl_four_complex_gpm_fft rsi, 2*64, 64
sse2mac sscase61, 128, 100000, s2cl_four_complex_gpm_fft rsi, 2*64, 64
sse2mac sscase62, 128, 4096, s2cl_four_complex_first_fft rsi, 2*64, 64
sse2mac sscase63, 128, 100000, s2cl_four_complex_first_fft rsi, 2*64, 64
sse2mac sscase64, 128, 4096, s2cl_four_complex_fft_final rsi, 2*64, 64
sse2mac sscase65, 128, 100000, s2cl_four_complex_fft_final rsi, 2*64, 64
sse2mac sscase66, 128, 4096, s2cl_four_complex_with_square rsi, 2*64, 64
sse2mac sscase67, 128, 100000, s2cl_four_complex_with_square rsi, 2*64, 64
sse2macbx sscase68, 128, 4096, s2cl_four_complex_with_mult rsi, 2*64, 64
sse2macbx sscase69, 128, 100000, s2cl_four_complex_with_mult rsi, 2*64, 64
sse2macbx sscase70, 128, 4096, s2cl_four_complex_with_mulf rsi, 2*64, 64
sse2macbx sscase71, 128, 100000, s2cl_four_complex_with_mulf rsi, 2*64, 64
sse2mac sscase72, 256, 4096, x4cl_four_complex_fft rsi, 4*64, 64, 2*64, rdi
sse2mac sscase73, 256, 100000, x4cl_four_complex_fft rsi, 4*64, 64, 2*64, rdi
sse2mac sscase74, 256, 4096, x4cl_four_complex_cpm_fft rsi, 4*64, 64, 2*64, 0
sse2mac sscase75, 256, 100000, x4cl_four_complex_cpm_fft rsi, 4*64, 64, 2*64, 0
sse2mac sscase76, 256, 4096, g4cl_four_complex_fft rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64
sse2mac sscase77, 256, 100000, g4cl_four_complex_fft rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64
sse2mac sscase78, 256, 4096, x4cl_four_complex_with_square rsi, 4*64, 64, 2*64
sse2mac sscase79, 256, 100000, x4cl_four_complex_with_square rsi, 4*64, 64, 2*64
sse2macbx sscase80, 256, 4096, x4cl_four_complex_with_mult rsi, 4*64, 64, 2*64
sse2macbx sscase81, 256, 100000, x4cl_four_complex_with_mult rsi, 4*64, 64, 2*64
sse2macbx sscase82, 256, 4096, x4cl_four_complex_with_mulf rsi, 4*64, 64, 2*64
sse2macbx sscase83, 256, 100000, x4cl_four_complex_with_mulf rsi, 4*64, 64, 2*64
sse2mac sscase84, 128, 4096, x2cl_four_complex_unfft rsi, 2*64, 64
sse2mac sscase85, 128, 100000, x2cl_four_complex_unfft rsi, 2*64, 64
sse2mac sscase86, 128, 4096, g2cl_four_complex_unfft rsi, 2*64, 64, rdx, 2*64, 64
sse2mac sscase87, 128, 100000, g2cl_four_complex_unfft rsi, 2*64, 64, rdx, 2*64, 64
sse2mac sscase88, 256, 4096, x4cl_four_complex_unfft rsi, 4*64, 64, 2*64, rdi
sse2mac sscase89, 256, 100000, x4cl_four_complex_unfft rsi, 4*64, 64, 2*64, rdi
sse2mac sscase90, 256, 4096, x4cl_four_complex_last_unfft rsi, 4*64, 64, 2*64, 0
sse2mac sscase91, 256, 100000, x4cl_four_complex_last_unfft rsi, 4*64, 64, 2*64, 0
sse2mac sscase92, 256, 4096, s4cl_four_complex_gpm_unfft rsi, 4*64, 64, 2*64, 0
sse2mac sscase93, 256, 100000, s4cl_four_complex_gpm_unfft rsi, 4*64, 64, 2*64, 0
sse2mac sscase94, 256, 4096, x4cl_four_complex_cpm_unfft rsi, 4*64, 64, 2*64
sse2mac sscase95, 256, 100000, x4cl_four_complex_cpm_unfft rsi, 4*64, 64, 2*64
sse2mac sscase96, 192, 4096, x3cl_six_reals_first_fft rsi, 3*64, 64
sse2mac sscase97, 192, 100000, x3cl_six_reals_first_fft rsi, 3*64, 64
sse2mac sscase98, 192, 4096, g3cl_six_reals_first_fft rsi, 3*64, 64, rdx, 3*64, 64
sse2mac sscase99, 192, 100000, g3cl_six_reals_first_fft rsi, 3*64, 64, rdx, 3*64, 64
sse2mac sscase100, 192, 4096, s3cl_six_reals_first_fft rsi, 3*64, 64
sse2mac sscase101, 192, 100000, s3cl_six_reals_first_fft rsi, 3*64, 64
sse2mac sscase102, 192, 4096, x3cl_six_reals_last_unfft rsi, 3*64, 64
sse2mac sscase103, 192, 100000, x3cl_six_reals_last_unfft rsi, 3*64, 64
sse2mac sscase104, 192, 4096, x3cl_three_complex_first_fft rsi, 3*64, 64
sse2mac sscase105, 192, 100000, x3cl_three_complex_first_fft rsi, 3*64, 64
sse2mac sscase106, 192, 4096, s3cl_three_complex_first_fft rsi, 3*64, 64
sse2mac sscase107, 192, 100000, s3cl_three_complex_first_fft rsi, 3*64, 64
sse2mac sscase108, 192, 4096, x3cl_three_complex_last_unfft rsi, 3*64, 64
sse2mac sscase109, 192, 100000, x3cl_three_complex_last_unfft rsi, 3*64, 64
sse2mac sscase110, 320, 4096, x5cl_five_reals_first_fft rsi, 5*64, 64
sse2mac sscase111, 320, 100000, x5cl_five_reals_first_fft rsi, 5*64, 64
sse2mac sscase112, 320, 4096, g5cl_five_reals_first_fft rsi, 5*64, 64, rdx, 5*64, 64
sse2mac sscase113, 320, 100000, g5cl_five_reals_first_fft rsi, 5*64, 64, rdx, 5*64, 64
sse2mac sscase114, 320, 4096, s5cl_five_reals_first_fft rsi, 5*64, 64
sse2mac sscase115, 320, 100000, s5cl_five_reals_first_fft rsi, 5*64, 64
sse2mac sscase116, 320, 4096, x5cl_five_reals_last_unfft rsi, 5*64, 64
sse2mac sscase117, 320, 100000, x5cl_five_reals_last_unfft rsi, 5*64, 64
sse2mac sscase118, 448, 4096, x7cl_seven_reals_first_fft rsi, 7*64, 64
sse2mac sscase119, 448, 100000, x7cl_seven_reals_first_fft rsi, 7*64, 64
sse2mac sscase120, 448, 4096, g7cl_seven_reals_first_fft rsi, 7*64, 64, rdx, 7*64, 64
sse2mac sscase121, 448, 100000, g7cl_seven_reals_first_fft rsi, 7*64, 64, rdx, 7*64, 64
sse2mac sscase122, 448, 4096, s7cl_seven_reals_first_fft rsi, 7*64, 64
sse2mac sscase123, 448, 100000, s7cl_seven_reals_first_fft rsi, 7*64, 64
sse2mac sscase124, 448, 4096, x7cl_seven_reals_last_unfft rsi, 7*64, 64
sse2mac sscase125, 448, 100000, x7cl_seven_reals_last_unfft rsi, 7*64, 64
sse2mac sscase126, 256, 4096, x4cl_empty rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase127, 256, 100000, x4cl_empty rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase128, 256, 4096, g4cl_empty rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, 0
sse2mac sscase129, 256, 100000, g4cl_empty rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, 0
sse2mac sscase130, 256, 4096, g4cl_empty_nt rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, 0
sse2mac sscase131, 256, 100000, g4cl_empty_nt rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, 0
sse2mac sscase132, 128, 4096, r4_x2cl_four_complex_first_fft4_scratch rsi, 2*64, 64, rdi
sse2mac sscase133, 128, 100000, r4_x2cl_four_complex_first_fft4_scratch rsi, 2*64, 64, rdi
sse2mac sscase134, 256, 4096, r4_x4cl_four_complex_last_unfft4 rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase135, 256, 100000, r4_x4cl_four_complex_last_unfft4 rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase136, 256, 4096, r4_x4cl_four_complex_fft_final rsi, 4*64, 64, 2*64
sse2mac sscase137, 256, 100000, r4_x4cl_four_complex_fft_final rsi, 4*64, 64, 2*64
sse2mac sscase138, 256, 4096, r4_x4cl_four_complex_with_square rsi, 4*64, 64, 2*64
sse2mac sscase139, 256, 100000, r4_x4cl_four_complex_with_square rsi, 4*64, 64, 2*64
sse2macbx sscase140, 256, 4096, r4_x4cl_four_complex_with_mult rsi, 4*64, 64, 2*64
sse2macbx sscase141, 256, 100000, r4_x4cl_four_complex_with_mult rsi, 4*64, 64, 2*64
sse2macbx sscase142, 256, 4096, r4_x4cl_four_complex_with_mulf rsi, 4*64, 64, 2*64
sse2macbx sscase143, 256, 100000, r4_x4cl_four_complex_with_mulf rsi, 4*64, 64, 2*64
sse2mac sscase144, 128, 4096, r2_x2cl_two_complex_fft rsi, 2*64, 64, rdi
sse2mac sscase145, 128, 100000, r2_x2cl_two_complex_fft rsi, 2*64, 64, rdi
sse2mac sscase146, 128, 4096, r2_x2cl_two_complex_unfft rsi, 2*64, 64, rdi, 0
sse2mac sscase147, 128, 100000, r2_x2cl_two_complex_unfft rsi, 2*64, 64, rdi, 0
sse2mac sscase148, 128, 4096, r4_x2cl_four_complex_first_djbfft_scratch rsi, 2*64, 64, rdi, rdi
sse2mac sscase149, 128, 100000, r4_x2cl_four_complex_first_djbfft_scratch rsi, 2*64, 64, rdi, rdi
sse2mac sscase150, 256, 4096, r4_x4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi
sse2mac sscase151, 256, 100000, r4_x4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi
sse2mac sscase152, 256, 4096, r4_x4cl_wpn_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi
sse2mac sscase153, 256, 100000, r4_x4cl_wpn_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi
sse2mac sscase154, 256, 4096, r4_sg4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi
sse2mac sscase155, 256, 100000, r4_sg4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi
sse2macbx sscase156, 128, 4096, r4_f2cl_four_complex_djbfft rsi, 2*64, 64, rdi
sse2macbx sscase157, 128, 100000, r4_f2cl_four_complex_djbfft rsi, 2*64, 64, rdi
sse2mac sscase158, 256, 4096, r4_x4cl_four_complex_last_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, 0
sse2mac sscase159, 256, 100000, r4_x4cl_four_complex_last_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, 0
sse2mac sscase160, 256, 4096, r4_x4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase161, 256, 100000, r4_x4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase162, 256, 4096, r4_x4cl_wpn_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase163, 256, 100000, r4_x4cl_wpn_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase164, 128, 4096, r4_sg2cl_four_complex_djbunfft rsi, 2*64, 64, rdx, 2*64, 64, rdi
sse2mac sscase165, 128, 100000, r4_sg2cl_four_complex_djbunfft rsi, 2*64, 64, rdx, 2*64, 64, rdi
sse2mac sscase166, 256, 4096, r4_sg4cl_four_complex_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi
sse2mac sscase167, 256, 100000, r4_sg4cl_four_complex_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi
sse2mac sscase168, 128, 4096, r4_sg2cl_four_complex_unfft4 rsi, 2*64, 64, rdx, 2*64, 64, rdi
sse2mac sscase169, 128, 100000, r4_sg2cl_four_complex_unfft4 rsi, 2*64, 64, rdx, 2*64, 64, rdi
sse2mac sscase170, 128, 4096, r4_x2cl_eight_reals_first_fft_scratch rsi, 2*64, 64, rdi
sse2mac sscase171, 128, 100000, r4_x2cl_eight_reals_first_fft_scratch rsi, 2*64, 64, rdi
sse2mac sscase172, 256, 4096, r4_x4cl_eight_reals_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, rdi
sse2mac sscase173, 256, 100000, r4_x4cl_eight_reals_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, rdi
sse2mac sscase174, 256, 4096, r4_x4cl_wpn_eight_reals_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, rdi
sse2mac sscase175, 256, 100000, r4_x4cl_wpn_eight_reals_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, rdi
sse2mac sscase176, 256, 4096, r4_sg4cl_eight_reals_four_complex_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, rdi
sse2mac sscase177, 256, 100000, r4_sg4cl_eight_reals_four_complex_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, rdi
sse2mac sscase178, 256, 4096, r4_x4cl_eight_reals_last_unfft rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase179, 256, 100000, r4_x4cl_eight_reals_last_unfft rsi, 4*64, 64, 2*64, rdi, 0
sse2mac sscase180, 256, 4096, r4_x4cl_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, 0
sse2mac sscase181, 256, 100000, r4_x4cl_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, 0
sse2mac sscase182, 128, 4096, r4_sg2cl_eight_reals_unfft4 rsi, 2*64, 64, rdx, 2*64, 64, rdi, rdi
sse2mac sscase183, 128, 100000, r4_sg2cl_eight_reals_unfft4 rsi, 2*64, 64, rdx, 2*64, 64, rdi, rdi
sse2mac sscase184, 192, 4096, r3_x3cl_six_reals_three_complex_djbfft rsi, 3*64, 64, rdi, rdi
sse2mac sscase185, 192, 100000, r3_x3cl_six_reals_three_complex_djbfft rsi, 3*64, 64, rdi, rdi
sse2mac sscase186, 192, 4096, r3_x3cl_six_reals_unfft rsi, 3*64, 64, rdi, 0, rdi, 0
sse2mac sscase187, 192, 100000, r3_x3cl_six_reals_unfft rsi, 3*64, 64, rdi, 0, rdi, 0
sse2mac sscase188, 192, 4096, r3_x3cl_three_complex_djbfft rsi, 3*64, 64, rdi
sse2mac sscase189, 192, 100000, r3_x3cl_three_complex_djbfft rsi, 3*64, 64, rdi
sse2mac sscase190, 192, 4096, r3_x3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, 0
sse2mac sscase191, 192, 100000, r3_x3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, 0
sse2mac sscase192, 320, 4096, r5_x5cl_20_reals_first_fft_scratch rsi, 5*64, 64, rdi
sse2mac sscase193, 320, 100000, r5_x5cl_20_reals_first_fft_scratch rsi, 5*64, 64, rdi
sse2mac sscase194, 640, 4096, r5_x10cl_20_reals_last_unfft rsi, 10*64, 64, rdi, 8*XMM_SCD9
sse2mac sscase195, 640, 100000, r5_x10cl_20_reals_last_unfft rsi, 10*64, 64, rdi, 8*XMM_SCD9
sse2mac sscase196, 320, 4096, r5_x5cl_five_complex_djbfft rsi, 5*64, 64, rdi
sse2mac sscase197, 320, 100000, r5_x5cl_five_complex_djbfft rsi, 5*64, 64, rdi
sse2mac sscase198, 320, 4096, r5_x5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, 0
sse2mac sscase199, 320, 100000, r5_x5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, 0
sse2mac sscase200, 448, 4096, r7_x7cl_28_reals_first_fft_scratch rsi, 7*64, 64, rdi
sse2mac sscase201, 448, 100000, r7_x7cl_28_reals_first_fft_scratch rsi, 7*64, 64, rdi
sse2mac sscase202, 896, 4096, r7_x14cl_28_reals_last_unfft rsi, 14*64, 64, rdi, 8*XMM_SCD13
sse2mac sscase203, 896, 100000, r7_x14cl_28_reals_last_unfft rsi, 14*64, 64, rdi, 8*XMM_SCD13
sse2mac sscase204, 512, 4096, r8_x8cl_eight_complex_fft_final rsi, 8*64, 64, 2*64, 4*64
sse2mac sscase205, 512, 100000, r8_x8cl_eight_complex_fft_final rsi, 8*64, 64, 2*64, 4*64
sse2mac sscase206, 512, 4096, r8_x8cl_eight_complex_with_square rsi, 8*64, 64, 2*64, 4*64
sse2mac sscase207, 512, 100000, r8_x8cl_eight_complex_with_square rsi, 8*64, 64, 2*64, 4*64
sse2macbx sscase208, 512, 4096, r8_x8cl_eight_complex_with_mult rsi, 8*64, 64, 2*64, 4*64
sse2macbx sscase209, 512, 100000, r8_x8cl_eight_complex_with_mult rsi, 8*64, 64, 2*64, 4*64
sse2macbx sscase210, 512, 4096, r8_x8cl_eight_complex_with_mulf rsi, 8*64, 64, 2*64, 4*64
sse2macbx sscase211, 512, 100000, r8_x8cl_eight_complex_with_mulf rsi, 8*64, 64, 2*64, 4*64
sse2mac sscase212, 512, 4096, r8_sg8cl_eight_complex_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi
sse2mac sscase213, 512, 100000, r8_sg8cl_eight_complex_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi
sse2mac sscase214, 256, 4096, r8_sg4cl_eight_complex_unfft8 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi
sse2mac sscase215, 256, 100000, r8_sg4cl_eight_complex_unfft8 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi
; need 16 reals cases
; Time ~10000 iterations of the AVX macros in L1 and L2 caches
INCLUDE yarch.mac
INCLUDE ybasics.mac
INCLUDE ymult.mac
INCLUDE yr4.mac
INCLUDE ynormal.mac
IFDEF X86_64
EXTRNP ycomplex_mult_opcode1
EXTRNP ycomplex_mult_opcode2
EXTRNP ycomplex_mult_opcode3
EXTRNP ycomplex_mult_opcode4
EXTRNP ycomplex_mult_opcode5
EXTRNP ycomplex_mult_opcode6
EXTRNP ycomplex_mulf_opcode1
EXTRNP ycomplex_mulf_opcode2
EXTRNP ycomplex_mulf_opcode3
EXTRNP ycomplex_mulf_opcode4
EXTRNP ycomplex_mulf_opcode5
EXTRNP ycomplex_mulf_opcode6
EXTRN y8complex_mult_opcode1:PROC
EXTRN y8complex_mult_opcode2:PROC
EXTRN y8complex_mult_opcode3:PROC
EXTRN y8complex_mult_opcode4:PROC
EXTRN y8complex_mulf_opcode1:PROC
EXTRN y8complex_mulf_opcode2:PROC
EXTRN y8complex_mulf_opcode3:PROC
EXTRN y8complex_mulf_opcode4:PROC
ENDIF
; This code reads/writes 64MB (1M cache lines) in contiguous blocks. Timings are done
; on 4 memory sizes. 4KB will operate on the L1 cache only, 128KB will operate on the
; L2 cache only, 1MB will operate on the L3 cache and 32MB will operate on main memory.
avcase0: read4 4096, 16384 ; Read 4KB
jmp exit
avcase1: read4 128*1024, 512 ; Read 128KB
jmp exit
avcase2: read4 1024*1024, 64 ; Read 1MB
jmp exit
avcase3: read4 32768*1024, 2 ; Read 32MB
jmp exit
avcase4: write4 4096, 16384 ; Write 4KB
jmp exit
avcase5: write4 128*1024, 512 ; Write 128KB
jmp exit
avcase6: write4 1024*1024, 64 ; Write 1MB
jmp exit
avcase7: write4 32768*1024, 2 ; Write 32MB
jmp exit
avcase8: readwrite4 4096, 16384 ; Read/write 4KB
jmp exit
avcase9: readwrite4 128*1024, 512 ; Read/write 128KB
jmp exit
avcase10: readwrite4 1024*1024, 64 ; Read/write 1MB
jmp exit
avcase11: readwrite4 32768*1024, 2 ; Read/write 32MB
jmp exit
yloop_init 32 ;; Dummy call to yloop_init
avx_case_num = 12
;;12
avxmac 256*1, 8192, 0, yr4_4cl_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256*2, 8192, 0, yr4_4cl_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 2
avxmac 256*1, 100000, 0, yr4_4cl_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256*2, 100000, 0, yr4_4cl_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 2
avxmac 256*1, 8192, 0, yr4_s4cl_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256*1, 100000, 0, yr4_s4cl_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmacbx 256*1, 8192, 0, yr4_fs4cl_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmacbx 256*1, 100000, 0, yr4_fs4cl_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256, 8192, 0, yr4_b4cl_csc_wpn_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND4, 1
avxmac 256, 100000, 0, yr4_b4cl_csc_wpn_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND4, 1
avxmac 256*1, 8192, 0, yr4_sg4cl_2sc_eight_reals_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, rdi, YMM_SCD2, 1
avxmac 256*1, 100000, 0, yr4_sg4cl_2sc_eight_reals_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, rdi, YMM_SCD2, 1
;;24
avxmac 256*1, 8192, 0, yr4_4cl_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256*2, 8192, 0, yr4_4cl_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 2
avxmac 256*1, 100000, 0, yr4_4cl_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256*2, 100000, 0, yr4_4cl_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 2
avxmac 256*1, 8192, 0, yr4_s4cl_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256*1, 100000, 0, yr4_s4cl_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256, 8192, 0, yr4_b4cl_csc_wpn_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND4, 1
avxmac 256, 100000, 0, yr4_b4cl_csc_wpn_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND4, 1
avxmac 256, 8192, 0, yr4_sg4cl_2sc_eight_reals_unfft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, rdi, YMM_SCD2, 1
avxmac 256, 100000, 0, yr4_sg4cl_2sc_eight_reals_unfft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, rdi, YMM_SCD2, 1
;;34
avxmac 256*1, 8192, 0, yr4_4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1 ;;, L1PREFETCH_ALL, 2*256*1
avxmac 256*2, 8192, 0, yr4_4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2 ;;, L1PREFETCH_ALL, 2*256*2
avxmac 256*3, 8192, 0, yr4_4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 3 ;;, L1PREFETCH_ALL, 2*256*3
avxmac 256*4, 8192, 0, yr4_4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 4 ;;, L1PREFETCH_ALL, 2*256*4
avxmac 256*5, 8192, 0, yr4_4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 5 ;;, L1PREFETCH_ALL, 2*256*5
avxmac 256*1, 100000, 0, yr4_4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmac 256*2, 100000, 0, yr4_4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
avxmac 256*1, 8192, 0, yr4_b4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 1
avxmac 256*2, 8192, 0, yr4_b4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 2
avxmac 256*3, 8192, 0, yr4_b4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 3
avxmac 256*4, 8192, 0, yr4_b4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 4
avxmac 256*5, 8192, 0, yr4_b4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 5
avxmac 256*1, 100000, 0, yr4_b4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 1
avxmac 256*2, 100000, 0, yr4_b4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 2
avxmac 256*1, 8192, 0, yr4_rb4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256*2, 8192, 0, yr4_rb4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 2
avxmac 256*1, 100000, 0, yr4_rb4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256*2, 100000, 0, yr4_rb4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 2
;;52
avxmac 256*1, 8192, 0, yr4_s4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmac 256*2, 8192, 0, yr4_s4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
avxmac 256*3, 8192, 0, yr4_s4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 3
avxmac 256*4, 8192, 0, yr4_s4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 4
avxmac 256*1, 100000, 0, yr4_s4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmac 256*2, 100000, 0, yr4_s4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
avxmacbx 256*1, 8192, 0, yr4_fs4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmacbx 256*2, 8192, 0, yr4_fs4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
avxmacbx 256*1, 100000, 0, yr4_fs4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmacbx 256*2, 100000, 0, yr4_fs4cl_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
;;62
avxmac 256*1, 8192, 0, yr4_b4cl_wpn_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 1
avxmac 256*2, 8192, 0, yr4_b4cl_wpn_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 2
avxmac 256*1, 100000, 0, yr4_b4cl_wpn_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 1
avxmac 256*2, 100000, 0, yr4_b4cl_wpn_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 2
avxmac 256*1, 8192, 0, yr4_sg4cl_four_complex_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmac 256*1, 100000, 0, yr4_sg4cl_four_complex_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
;;68
avxmac 256*1, 8192, 0, yr4_4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmac 256*2, 8192, 0, yr4_4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
avxmac 256*3, 8192, 0, yr4_4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 3
avxmac 256*4, 8192, 0, yr4_4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 4
avxmac 256*5, 8192, 0, yr4_4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 5
avxmac 256*1, 100000, 0, yr4_4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmac 256*2, 100000, 0, yr4_4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
avxmac 256*1, 8192, 0, yr4_b4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 1
avxmac 256*2, 8192, 0, yr4_b4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 2
avxmac 256*3, 8192, 0, yr4_b4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 3
avxmac 256*4, 8192, 0, yr4_b4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 4
avxmac 256*5, 8192, 0, yr4_b4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 5
avxmac 256*1, 100000, 0, yr4_b4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 1
avxmac 256*2, 100000, 0, yr4_b4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2/4, 2
;; 82
avxmac 256*1, 8192, 0, yr4_s4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmac 256*2, 8192, 0, yr4_s4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
avxmac 256*3, 8192, 0, yr4_s4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 3
avxmac 256*4, 8192, 0, yr4_s4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 4
avxmac 256*1, 100000, 0, yr4_s4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 1
avxmac 256*2, 100000, 0, yr4_s4cl_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD2, 2
avxmac 256*1, 8192, 0, yr4_b4cl_wpn_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 1
avxmac 256*2, 8192, 0, yr4_b4cl_wpn_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 2
avxmac 256*1, 100000, 0, yr4_b4cl_wpn_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 1
avxmac 256*2, 100000, 0, yr4_b4cl_wpn_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 2
avxmac 256*1, 8192, 0, yr4_sg4cl_four_complex_unfft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmac 256*1, 100000, 0, yr4_sg4cl_four_complex_unfft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
;;94
avxmac 256*1, 8192, 0, yr4_4cl_csc_four_complex_first_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD6, 1
avxmac 256*2, 8192, 0, yr4_4cl_csc_four_complex_first_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD6, 2
avxmac 256*1, 100000, 0, yr4_4cl_csc_four_complex_first_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD6, 1
avxmac 256*2, 100000, 0, yr4_4cl_csc_four_complex_first_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD6, 2
avxmac 256*1, 8192, 0, yr4_fs4cl_four_complex_first_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmac 256*1, 100000, 0, yr4_fs4cl_four_complex_first_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmacbx 256*1, 8192, 0, yr4_fs4cl_four_complex_first_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmacbx 256*1, 100000, 0, yr4_fs4cl_four_complex_first_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
;;102
avxmac 256*1, 8192, 0, yr4_4cl_csc_four_complex_last_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD6, 1
avxmac 256*2, 8192, 0, yr4_4cl_csc_four_complex_last_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD6, 2
avxmac 256*1, 100000, 0, yr4_4cl_csc_four_complex_last_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD6, 1
avxmac 256*2, 100000, 0, yr4_4cl_csc_four_complex_last_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD6, 2
avxmac 256*1, 8192, 0, yr4_s4cl_four_complex_last_unfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmac 256*1, 100000, 0, yr4_s4cl_four_complex_last_unfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
;;108
avxmac 256, 8192, 0, yr4_4cl_four_complex_fft_final rsi, 4*64, 64, 2*64
avxmac 256, 100000, 0, yr4_4cl_four_complex_fft_final rsi, 4*64, 64, 2*64
avxmac 256*1, 8192, 0, yr4_4cl_four_complex_with_square rsi, 4*64, 64, 2*64, 1
avxmac 256*2, 8192, 0, yr4_4cl_four_complex_with_square rsi, 4*64, 64, 2*64, 2
avxmac 256*1, 100000, 0, yr4_4cl_four_complex_with_square rsi, 4*64, 64, 2*64, 1
avxmac 256*2, 100000, 0, yr4_4cl_four_complex_with_square rsi, 4*64, 64, 2*64, 2
avxmacbx 256, 8192, 0, yr4_4cl_four_complex_with_mult rsi, 4*64, 64, 2*64
avxmacbx 256, 100000, 0, yr4_4cl_four_complex_with_mult rsi, 4*64, 64, 2*64
avxmacbx 256, 8192, 0, yr4_4cl_four_complex_with_mulf rsi, 4*64, 64, 2*64
avxmacbx 256, 100000, 0, yr4_4cl_four_complex_with_mulf rsi, 4*64, 64, 2*64
;;118
avxmac 256, 8192, 0, yr4_4cl_eight_reals_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256, 100000, 0, yr4_4cl_eight_reals_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256, 8192, 0, yr4_4cl_eight_reals_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
avxmac 256, 100000, 0, yr4_4cl_eight_reals_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, YMM_SCD3, 1
;;122
avxmac 256, 8192, 0, yr4_4cl_eight_reals_four_complex_fft_final rsi, 4*64, 64, 2*64
avxmac 256, 100000, 0, yr4_4cl_eight_reals_four_complex_fft_final rsi, 4*64, 64, 2*64
avxmac 256, 8192, 0, yr4_4cl_eight_reals_four_complex_with_square rsi, 4*64, 64, 2*64
avxmac 256, 100000, 0, yr4_4cl_eight_reals_four_complex_with_square rsi, 4*64, 64, 2*64
avxmacbx 256, 8192, 0, yr4_4cl_eight_reals_four_complex_with_mult rsi, 4*64, 64, 2*64
avxmacbx 256, 100000, 0, yr4_4cl_eight_reals_four_complex_with_mult rsi, 4*64, 64, 2*64
avxmacbx 256, 8192, 0, yr4_4cl_eight_reals_four_complex_with_mulf rsi, 4*64, 64, 2*64
avxmacbx 256, 100000, 0, yr4_4cl_eight_reals_four_complex_with_mulf rsi, 4*64, 64, 2*64
;;130
avxmac 192*1, 8192, 0, yr3_3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 1
avxmac 192*2, 8192, 0, yr3_3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 2
avxmac 192*3, 8192, 0, yr3_3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 3
avxmac 192*4, 8192, 0, yr3_3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 4
avxmac 192*5, 8192, 0, yr3_3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 5
avxmac 192*1, 100000, 0, yr3_3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 1
avxmac 192*2, 100000, 0, yr3_3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 2
avxmacbx 192*1, 8192, 0, yr3_f3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 1
avxmacbx 192*2, 8192, 0, yr3_f3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 2
avxmacbx 192*1, 100000, 0, yr3_f3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 1
avxmacbx 192*2, 100000, 0, yr3_f3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1, 2
avxmac 192*1, 8192, 0, yr3_b3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 1
avxmac 192*2, 8192, 0, yr3_b3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 2
avxmac 192*3, 8192, 0, yr3_b3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 3
avxmac 192*4, 8192, 0, yr3_b3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 4
avxmac 192*5, 8192, 0, yr3_b3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 5
avxmac 192*1, 100000, 0, yr3_b3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 1
avxmac 192*2, 100000, 0, yr3_b3cl_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 2
;;148
avxmac 192*1, 8192, 0, yr3_3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1, 1
avxmac 192*2, 8192, 0, yr3_3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1, 2
avxmac 192*3, 8192, 0, yr3_3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1, 3
avxmac 192*4, 8192, 0, yr3_3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1, 4
avxmac 192*5, 8192, 0, yr3_3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1, 5
avxmac 192*1, 100000, 0, yr3_3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1, 1
avxmac 192*2, 100000, 0, yr3_3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1, 2
avxmac 192*1, 8192, 0, yr3_b3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 1
avxmac 192*2, 8192, 0, yr3_b3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 2
avxmac 192*3, 8192, 0, yr3_b3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 3
avxmac 192*4, 8192, 0, yr3_b3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 4
avxmac 192*5, 8192, 0, yr3_b3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 5
avxmac 192*1, 100000, 0, yr3_b3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 1
avxmac 192*2, 100000, 0, yr3_b3cl_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD1/4, 2
;;162
avxmac 192*1, 8192, 0, yr3_3cl_six_reals_fft rsi, 3*64, 64, rdi, YMM_SCD2, 1
avxmac 192*4, 8192, 0, yr3_3cl_six_reals_fft rsi, 3*64, 64, rdi, YMM_SCD2, 4
avxmacbx 192*1, 8192, 0, yr3_f3cl_six_reals_fft rsi, 3*64, 64, rdi, YMM_SCD2, 1
avxmacbx 192*1, 100000, 0, yr3_f3cl_six_reals_fft rsi, 3*64, 64, rdi, YMM_SCD2, 1
avxmac 192*1, 8192, 0, yr3_3cl_six_reals_unfft rsi, 3*64, 64, rdi, YMM_SCD2, 1
avxmac 192*4, 8192, 0, yr3_3cl_six_reals_unfft rsi, 3*64, 64, rdi, YMM_SCD2, 4
;;168
avxmac 192, 8192, 0, yr3_3cl_six_reals_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD2, 1
avxmac 192, 100000, 0, yr3_3cl_six_reals_three_complex_djbfft rsi, 3*64, 64, rdi, YMM_SCD2, 1
avxmac 192, 8192, 0, yr3_3cl_six_reals_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD2, 1
avxmac 192, 100000, 0, yr3_3cl_six_reals_three_complex_djbunfft rsi, 3*64, 64, rdi, YMM_SCD2, 1
;;172
avxmac 320*1, 8192, 0, yr5_5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2, 1
avxmac 320*2, 8192, 0, yr5_5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2, 2
avxmac 320*1, 100000, 0, yr5_5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2, 1
avxmac 320*2, 100000, 0, yr5_5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2, 2
avxmacbx 320*1, 8192, 0, yr5_f5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2, 1
avxmacbx 320*1, 100000, 0, yr5_f5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2, 1
avxmac 320*1, 8192, 0, yr5_b5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2/4, 1
avxmac 320*2, 8192, 0, yr5_b5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2/4, 2
avxmac 320*1, 100000, 0, yr5_b5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2/4, 1
avxmac 320*2, 100000, 0, yr5_b5cl_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD2/4, 2
;;182
avxmac 320*1, 8192, 0, yr5_5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD2, 1
avxmac 320*2, 8192, 0, yr5_5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD2, 2
avxmac 320*1, 100000, 0, yr5_5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD2, 1
avxmac 320*2, 100000, 0, yr5_5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD2, 2
avxmac 320*1, 8192, 0, yr5_b5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD2/4, 1
avxmac 320*2, 8192, 0, yr5_b5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD2/4, 2
avxmac 320*1, 100000, 0, yr5_b5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD2/4, 1
avxmac 320*2, 100000, 0, yr5_b5cl_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD2/4, 2
;;190
avxmac 192, 8192, 0, yr5_5cl_ten_reals_fft rsi, 5*64, 64, rdi, YMM_SCD4, 1
avxmac 192, 100000, 0, yr5_5cl_ten_reals_fft rsi, 5*64, 64, rdi, YMM_SCD4, 1
avxmacbx 192, 8192, 0, yr5_f5cl_ten_reals_fft rsi, 5*64, 64, rdi, YMM_SCD4, 1
avxmacbx 192, 100000, 0, yr5_f5cl_ten_reals_fft rsi, 5*64, 64, rdi, YMM_SCD4, 1
avxmac 192, 8192, 0, yr5_5cl_ten_reals_unfft rsi, 5*64, 64, rdi, YMM_SCD4, 1
avxmac 192, 100000, 0, yr5_5cl_ten_reals_unfft rsi, 5*64, 64, rdi, YMM_SCD4, 1
;;196
avxmac 320, 8192, 0, yr5_5cl_ten_reals_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD4, 1
avxmac 320, 100000, 0, yr5_5cl_ten_reals_five_complex_djbfft rsi, 5*64, 64, rdi, YMM_SCD4, 1
avxmac 320, 8192, 0, yr5_5cl_ten_reals_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD4, 1
avxmac 320, 100000, 0, yr5_5cl_ten_reals_five_complex_djbunfft rsi, 5*64, 64, rdi, YMM_SCD4, 1
;;200
avxmac 512*1, 8192, 0, yr8_sg8cl_eight_complex_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, YMM_SCD8, 1
avxmac 512*1, 100000, 0, yr8_sg8cl_eight_complex_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, YMM_SCD8, 1
avxmac 512*1, 8192, 0, yr8_sg8cl_eight_complex_unfft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, YMM_SCD8, 1
avxmac 512*1, 100000, 0, yr8_sg8cl_eight_complex_unfft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, YMM_SCD8, 1
;;204
avxmac 512, 8192, 0, yr8_8cl_eight_complex_fft_final rsi, 8*64, 64, 2*64, 4*64
avxmac 512, 100000, 0, yr8_8cl_eight_complex_fft_final rsi, 8*64, 64, 2*64, 4*64
avxmac 512, 8192, 0, yr8_8cl_eight_complex_with_square rsi, 8*64, 64, 2*64, 4*64
avxmac 512, 100000, 0, yr8_8cl_eight_complex_with_square rsi, 8*64, 64, 2*64, 4*64
avxmacbx 512, 8192, 0, yr8_8cl_eight_complex_with_mult rsi, 8*64, 64, 2*64, 4*64
avxmacbx 512, 100000, 0, yr8_8cl_eight_complex_with_mult rsi, 8*64, 64, 2*64, 4*64
avxmacbx 512, 8192, 0, yr8_8cl_eight_complex_with_mulf rsi, 8*64, 64, 2*64, 4*64
avxmacbx 512, 100000, 0, yr8_8cl_eight_complex_with_mulf rsi, 8*64, 64, 2*64, 4*64
;;212
avxmac 512*1, 8192, 0, yr8_sg8cl_2sc_sixteen_reals_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, 0, rdi, YMM_SCD8, 1
avxmac 512*1, 100000, 0, yr8_sg8cl_2sc_sixteen_reals_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, 0, rdi, YMM_SCD8, 1
avxmac 512*1, 8192, 0, yr8_sg8cl_2sc_sixteen_reals_unfft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, 0, rdi, YMM_SCD8, 1
avxmac 512*1, 100000, 0, yr8_sg8cl_2sc_sixteen_reals_unfft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, 0, rdi, YMM_SCD8, 1
;;216
avxmac 512*1, 8192, 0, yr8_8cl_16_reals_fft rsi, 8*64, 64, 128, 256, rdi, YMM_SCD7, 1
avxmac 512*1, 100000, 0, yr8_8cl_16_reals_fft rsi, 8*64, 64, 128, 256, rdi, YMM_SCD7, 1
avxmac 512*1, 8192, 0, yr8_8cl_16_reals_unfft rsi, 8*64, 64, 128, 256, rdi, YMM_SCD7, 1
avxmac 512*1, 100000, 0, yr8_8cl_16_reals_unfft rsi, 8*64, 64, 128, 256, rdi, YMM_SCD7, 1
;;220
avxmac 640*1, 8192, 0, yr5_10cl_20_reals_fft rsi, 10*64, 64, 128, rdi, YMM_SCD9, 1
avxmac 640*1, 100000, 0, yr5_10cl_20_reals_fft rsi, 10*64, 64, 128, rdi, YMM_SCD9, 1
avxmac 640*1, 8192, 0, yr5_10cl_20_reals_unfft rsi, 10*64, 64, 128, rdi, YMM_SCD9, 1
avxmac 640*1, 100000, 0, yr5_10cl_20_reals_unfft rsi, 10*64, 64, 128, rdi, YMM_SCD9, 1
;;224
avxmac 768*1, 8192, 0, yr6_12cl_24_reals_fft rsi, 12*64, 64, 128, rdi, YMM_SCD11, 1
avxmac 768*1, 100000, 0, yr6_12cl_24_reals_fft rsi, 12*64, 64, 128, rdi, YMM_SCD11, 1
avxmac 768*1, 8192, 0, yr6_12cl_24_reals_unfft rsi, 12*64, 64, 128, rdi, YMM_SCD11, 1
avxmac 768*1, 100000, 0, yr6_12cl_24_reals_unfft rsi, 12*64, 64, 128, rdi, YMM_SCD11, 1
;;228
avxmac 896*1, 8192, 0, yr7_14cl_28_reals_fft rsi, 14*64, 64, 128, rdi, YMM_SCD13, 1
avxmac 896*1, 100000, 0, yr7_14cl_28_reals_fft rsi, 14*64, 64, 128, rdi, YMM_SCD13, 1
avxmac 896*1, 8192, 0, yr7_14cl_28_reals_unfft rsi, 14*64, 64, 128, rdi, YMM_SCD13, 1
avxmac 896*1, 100000, 0, yr7_14cl_28_reals_unfft rsi, 14*64, 64, 128, rdi, YMM_SCD13, 1
;;232
ynormmac 64, 8192, ynorm_1d exec, exec, noexec, noexec, noexec ;; base2 ttp (the most common case)
ynormmac 64, 8192, ynorm_1d exec, exec, noexec, exec, noexec ;; base2 ttp echk
ynormmac 64, 8192, ynorm_1d exec, exec, noexec, noexec, exec ;; base2 ttp const
ynormmac 64, 8192, ynorm_1d exec, exec, noexec, exec, exec ;; base2 ttp const echk
ynormmac 64, 8192, ynorm_1d noexec, exec, noexec, noexec, noexec ;; base2 nottp
ynormmac 64, 8192, ynorm_1d exec, noexec, noexec, noexec, noexec ;; nobase2 ttp
ynormmac 64, 8192, ynorm_1d exec, noexec, noexec, exec, noexec ;; nobase2 ttp echk
ynormmac 64, 8192, ynorm_1d exec, noexec, noexec, noexec, exec ;; nobase2 ttp const
ynormmac 64, 8192, ynorm_1d exec, noexec, noexec, exec, exec ;; nobase2 ttp const echk
ynormmac 64, 8192, ynorm_1d noexec, noexec, noexec, noexec, noexec ;; nobase2 nottp
;;242
ynormmac 64, 8192, ynorm_1d_zpad exec, exec, noexec, noexec, noexec, exec, noexec ;; base2 ttp c1 (the most common case)
ynormmac 64, 8192, ynorm_1d_zpad exec, exec, exec, noexec, noexec, exec, noexec ;; base2 ttp c1 echk
ynormmac 64, 8192, ynorm_1d_zpad exec, exec, noexec, exec, noexec, noexec, noexec ;; base2 ttp const
ynormmac 64, 8192, ynorm_1d_zpad exec, exec, exec, exec, noexec, noexec, noexec ;; base2 ttp const echk
ynormmac 64, 8192, ynorm_1d_zpad exec, exec, noexec, noexec, noexec, exec, noexec ;; base2 ttp c1 khi
ynormmac 64, 8192, ynorm_1d_zpad exec, noexec, noexec, noexec, noexec, exec, noexec ;; nobase2 ttp c1 (the most common case)
ynormmac 64, 8192, ynorm_1d_zpad exec, noexec, exec, noexec, noexec, exec, noexec ;; nobase2 ttp c1 echk
ynormmac 64, 8192, ynorm_1d_zpad exec, noexec, noexec, exec, noexec, noexec, noexec ;; nobase2 ttp const
ynormmac 64, 8192, ynorm_1d_zpad exec, noexec, exec, exec, noexec, noexec, noexec ;; nobase2 ttp const echk
ynormmac 64, 8192, ynorm_1d_zpad exec, noexec, noexec, noexec, noexec, exec, noexec ;; nobase2 ttp c1 khi
;;252
ynormwpn4mac 64, 8192, ynorm_wpn exec, exec, noexec, noexec, noexec ;; base2 ttp (the most common case)
ynormwpn4mac 64, 8192, ynorm_wpn exec, exec, noexec, exec, noexec ;; base2 ttp echk
ynormwpn4mac 64, 8192, ynorm_wpn exec, exec, noexec, noexec, exec ;; base2 ttp const
ynormwpn4mac 64, 8192, ynorm_wpn exec, exec, noexec, exec, exec ;; base2 ttp const echk
ynormwpn4mac 64, 8192, ynorm_wpn noexec, exec, noexec, noexec, noexec ;; base2 nottp
ynormwpn4mac 64, 8192, ynorm_wpn exec, noexec, noexec, noexec, noexec ;; nobase2 ttp
ynormwpn4mac 64, 8192, ynorm_wpn exec, noexec, noexec, exec, noexec ;; nobase2 ttp echk
ynormwpn4mac 64, 8192, ynorm_wpn exec, noexec, noexec, noexec, exec ;; nobase2 ttp const
ynormwpn4mac 64, 8192, ynorm_wpn exec, noexec, noexec, exec, exec ;; nobase2 ttp const echk
ynormwpn4mac 64, 8192, ynorm_wpn noexec, noexec, noexec, noexec, noexec ;; nobase2 nottp
;;262
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, exec, noexec, noexec, noexec, exec, noexec ;; base2 ttp c1 (the most common case)
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, exec, exec, noexec, noexec, exec, noexec ;; base2 ttp c1 echk
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, exec, noexec, exec, noexec, noexec, noexec ;; base2 ttp const
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, exec, exec, exec, noexec, noexec, noexec ;; base2 ttp const echk
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, exec, noexec, noexec, noexec, exec, noexec ;; base2 ttp c1 khi
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, noexec, noexec, noexec, noexec, exec, noexec ;; nobase2 ttp c1 (the most common case)
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, noexec, exec, noexec, noexec, exec, noexec ;; nobase2 ttp c1 echk
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, noexec, noexec, exec, noexec, noexec, noexec ;; nobase2 ttp const
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, noexec, exec, exec, noexec, noexec, noexec ;; nobase2 ttp const echk
ynormwpn4mac 64, 8192, ynorm_wpn_zpad exec, noexec, noexec, noexec, noexec, exec, noexec ;; nobase2 ttp c1 khi
;;272
avxmac 256, 8192, 0, yr4_b4cl_csc_wpn4_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND4, 1
avxmac 256, 100000, 0, yr4_b4cl_csc_wpn4_eight_reals_fft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND4, 1
avxmac 256, 8192, 0, yr4_b4cl_csc_wpn4_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND4, 1
avxmac 256, 100000, 0, yr4_b4cl_csc_wpn4_eight_reals_unfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND4, 1
avxmac 256*1, 8192, 0, yr4_b4cl_wpn4_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 1
avxmac 256*2, 8192, 0, yr4_b4cl_wpn4_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 2
avxmac 256*1, 100000, 0, yr4_b4cl_wpn4_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 1
avxmac 256*2, 100000, 0, yr4_b4cl_wpn4_four_complex_djbfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 2
avxmac 256*1, 8192, 0, yr4_b4cl_wpn4_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 1
avxmac 256*2, 8192, 0, yr4_b4cl_wpn4_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 2
avxmac 256*1, 100000, 0, yr4_b4cl_wpn4_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 1
avxmac 256*2, 100000, 0, yr4_b4cl_wpn4_four_complex_djbunfft rsi, 4*64, 64, 2*64, rdi, 0, rdi, YMM_SCND2, 2
;;284
avxmac 256*1, 8192, 0, yr4_rsc_sg4cl_four_complex_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmac 256*1, 100000, 0, yr4_rsc_sg4cl_four_complex_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmac 256*1, 8192, 0, yr4_rsc_sg4cl_four_complex_unfft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmac 256*1, 100000, 0, yr4_rsc_sg4cl_four_complex_unfft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, 1
avxmac 256*1, 8192, 0, yr4_rsc_sg4cl_2sc_eight_reals_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, rdi, YMM_SCD2, 1
avxmac 256*1, 100000, 0, yr4_rsc_sg4cl_2sc_eight_reals_fft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, rdi, YMM_SCD2, 1
avxmac 256*1, 8192, 0, yr4_rsc_sg4cl_2sc_eight_reals_unfft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, rdi, YMM_SCD2, 1
avxmac 256*1, 100000, 0, yr4_rsc_sg4cl_2sc_eight_reals_unfft4 rsi, 4*64, 64, 2*64, rdx, 4*64, 64, 2*64, rdi, YMM_SCD4, rdi, YMM_SCD2, 1
;;292
avxmac 512*1, 8192, 0, yr8_rsc_sg8cl_eight_complex_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, YMM_SCD8, 1
avxmac 512*1, 100000, 0, yr8_rsc_sg8cl_eight_complex_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, YMM_SCD8, 1
avxmac 512*1, 8192, 0, yr8_rsc_sg8cl_eight_complex_unfft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, YMM_SCD8, 1
avxmac 512*1, 100000, 0, yr8_rsc_sg8cl_eight_complex_unfft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, YMM_SCD8, 1
avxmac 512*1, 8192, 0, yr8_rsc_sg8cl_2sc_sixteen_reals_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, 0, rdi, YMM_SCD8, 1
avxmac 512*1, 100000, 0, yr8_rsc_sg8cl_2sc_sixteen_reals_fft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, 0, rdi, YMM_SCD8, 1
avxmac 512*1, 8192, 0, yr8_rsc_sg8cl_2sc_sixteen_reals_unfft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, 0, rdi, YMM_SCD8, 1
avxmac 512*1, 100000, 0, yr8_rsc_sg8cl_2sc_sixteen_reals_unfft8 rsi, 8*64, 64, 2*64, 4*64, rdx, 8*64, 64, 2*64, 4*64, rdi, 0, rdi, YMM_SCD8, 1
; Time ~10000 iterations of the AVX-512 macros in L1 and L2 caches
IFDEF X86_64
ARCH EQU SKX
INCLUDE zarch.mac
INCLUDE zbasics.mac
INCLUDE zmult.mac
INCLUDE zonepass.mac
INCLUDE zr4.mac
INCLUDE znormal.mac
INCLUDE znormal_zpad.mac
EXTRN zcomplex_square_opcode:PROC
EXTRN zcomplex_mult_opcode:PROC
EXTRN zcomplex_mulf_opcode:PROC
FMApenalty_test1 MACRO ;; Test if latency is really 4 clocks, ideal macro timing is 4 clocks
zfmaddpd zmm0, zmm0, zmm0, zmm0
zfmaddpd zmm1, zmm1, zmm1, zmm1
zfmaddpd zmm2, zmm2, zmm2, zmm2
zfmaddpd zmm3, zmm3, zmm3, zmm3
zfmaddpd zmm4, zmm4, zmm4, zmm4
zfmaddpd zmm5, zmm5, zmm5, zmm5
zfmaddpd zmm6, zmm6, zmm6, zmm6
zfmaddpd zmm7, zmm7, zmm7, zmm7
ENDM
FMApenalty_test2 MACRO ;; Test if *average* latency is really 5 clocks, ideal macro timing is 5 clocks
zfmaddpd zmm0, zmm0, zmm0, zmm0
zfmaddpd zmm1, zmm1, zmm1, zmm1
zfmaddpd zmm2, zmm2, zmm2, zmm2
zfmaddpd zmm3, zmm3, zmm3, zmm3
zfmaddpd zmm4, zmm4, zmm4, zmm4
zfmaddpd zmm5, zmm5, zmm5, zmm5
zfmaddpd zmm6, zmm6, zmm6, zmm6
zfmaddpd zmm7, zmm7, zmm7, zmm7
zfmaddpd zmm8, zmm8, zmm8, zmm8
zfmaddpd zmm9, zmm9, zmm9, zmm9
ENDM
FMApenalty_test3 MACRO ;; Test if *average* latency is 6 clocks, ideal macro timing is 6 clocks
zfmaddpd zmm0, zmm0, zmm0, zmm0
zfmaddpd zmm1, zmm1, zmm1, zmm1
zfmaddpd zmm2, zmm2, zmm2, zmm2
zfmaddpd zmm3, zmm3, zmm3, zmm3
zfmaddpd zmm4, zmm4, zmm4, zmm4
zfmaddpd zmm5, zmm5, zmm5, zmm5
zfmaddpd zmm6, zmm6, zmm6, zmm6
zfmaddpd zmm7, zmm7, zmm7, zmm7
zfmaddpd zmm8, zmm8, zmm8, zmm8
zfmaddpd zmm9, zmm9, zmm9, zmm9
zfmaddpd zmm10, zmm10, zmm10, zmm10
zfmaddpd zmm11, zmm11, zmm11, zmm11
ENDM
FMApenalty_test4 MACRO ;; Test if there is a penalty switching between FMA and add/sub/mul, ideal macro timing is 6 clocks
zfmaddpd zmm0, zmm0, zmm0, zmm0
zfmaddpd zmm1, zmm1, zmm1, zmm1
zfmaddpd zmm2, zmm2, zmm2, zmm2
zfmaddpd zmm3, zmm3, zmm3, zmm3
zfmaddpd zmm12, zmm12, zmm12, zmm12
zfmaddpd zmm13, zmm13, zmm13, zmm13
vaddpd zmm4, zmm4, zmm4
vaddpd zmm5, zmm5, zmm5
vaddpd zmm6, zmm6, zmm6
vaddpd zmm7, zmm7, zmm7
vaddpd zmm16, zmm16, zmm16
vaddpd zmm17, zmm17, zmm17
ENDM
FMApenalty_test5 MACRO ;; Test if there is a penalty using FMA vs. add/sub/mul, ideal macro timing is 6 clocks
vaddpd zmm0, zmm0, zmm0
vaddpd zmm1, zmm1, zmm1
vaddpd zmm2, zmm2, zmm2
vaddpd zmm3, zmm3, zmm3
vaddpd zmm12, zmm12, zmm12
vaddpd zmm13, zmm13, zmm13
vaddpd zmm4, zmm4, zmm4
vaddpd zmm5, zmm5, zmm5
vaddpd zmm6, zmm6, zmm6
vaddpd zmm7, zmm7, zmm7
vaddpd zmm16, zmm16, zmm16
vaddpd zmm17, zmm17, zmm17
ENDM
do_nothing MACRO srcreg,srcinc,d1,d2,d4,screg,scinc,maxrpt,L1pt,L1pd
vmovapd zmm1, [srcreg+d1] ;; R2
vmovapd zmm2, [srcreg+d4+d1] ;; R6
vmovapd zmm3, [srcreg+d2+d1+64] ;; I4
vmovapd zmm4, [srcreg+d4+d2+d1+64] ;; I8
vmovapd zmm5, [srcreg+d2+d1] ;; R4
vmovapd zmm6, [srcreg+d4+d2+d1] ;; R8
vmovapd zmm7, [srcreg+d1+64] ;; I2
vmovapd zmm8, [srcreg+d4+d1+64] ;; I6
vmovapd zmm9, [srcreg] ;; R1
vmovapd zmm10, [srcreg+d4] ;; R5
vmovapd zmm11, [srcreg+d2] ;; R3
vmovapd zmm12, [srcreg+d4+d2] ;; R7
vmovapd zmm13, [srcreg+64] ;; I1
vmovapd zmm14, [srcreg+d4+64] ;; I5
vmovapd zmm15, [srcreg+d2+64] ;; I3
vmovapd zmm16, [srcreg+d4+d2+64] ;; I7
zstore [srcreg], zmm1 ;; Store R1
zstore [srcreg+d1], zmm2 ;; Store R2
zstore [srcreg+d2], zmm3 ;; Store R3
zstore [srcreg+d2+d1], zmm4 ;; Store R4
zstore [srcreg+d4], zmm5 ;; Store R5
zstore [srcreg+d4+d1], zmm6 ;; Store R6
zstore [srcreg+d4+d2], zmm7 ;; Store R7
zstore [srcreg+d4+d2+d1], zmm8 ;; Store R8
zstore [srcreg+64], zmm9 ;; Store I1
zstore [srcreg+d1+64], zmm10 ;; Store I2
zstore [srcreg+d2+64], zmm11 ;; Store I3
zstore [srcreg+d2+d1+64], zmm12 ;; Store I4
zstore [srcreg+d4+64], zmm13 ;; Store I5
zstore [srcreg+d4+d1+64], zmm14 ;; Store I6
zstore [srcreg+d4+d2+64], zmm15 ;; Store I7
zstore [srcreg+d4+d2+d1+64], zmm16 ;; Store I8
bump srcreg, srcinc
ENDM
do_nothing_plus_sincos MACRO srcreg,srcinc,d1,d2,d4,screg,scinc,maxrpt,L1pt,L1pd
vmovapd zmm1, [srcreg+d1] ;; R2
vmovapd zmm2, [srcreg+d4+d1] ;; R6
vmovapd zmm3, [srcreg+d2+d1+64] ;; I4
vmovapd zmm4, [srcreg+d4+d2+d1+64] ;; I8
vmovapd zmm5, [srcreg+d2+d1] ;; R4
vmovapd zmm6, [srcreg+d4+d2+d1] ;; R8
vmovapd zmm7, [srcreg+d1+64] ;; I2
vmovapd zmm8, [srcreg+d4+d1+64] ;; I6
vmovapd zmm9, [srcreg] ;; R1
vmovapd zmm10, [srcreg+d4] ;; R5
vmovapd zmm11, [srcreg+d2] ;; R3
vmovapd zmm12, [srcreg+d4+d2] ;; R7
vmovapd zmm13, [srcreg+64] ;; I1
vmovapd zmm14, [srcreg+d4+64] ;; I5
vmovapd zmm15, [srcreg+d2+64] ;; I3
vmovapd zmm16, [srcreg+d4+d2+64] ;; I7
vmovapd zmm17, [screg+1*128] ;; sine for R3/I3 and R4/I4
vmovapd zmm17, [screg+3*128+64] ;; cosine/sine for R2/I2
vmovapd zmm17, [screg+2*128+64] ;; cosine/sine for R7/I7 and R6/I6
vmovapd zmm17, [screg+0*128+64] ;; cosine/sine for R5/I5 and R8/I8
vmovapd zmm17, [screg+1*128+64] ;; cosine/sine for R3/I3 and R4/I4
vmovapd zmm17, [screg+3*128] ;; sine for R2/I2
vmovapd zmm17, [screg+2*128] ;; sine for R7/I7 and R6/I6
vmovapd zmm17, [screg+0*128] ;; sine for R5/I5 and R8/I8
bump screg, scinc
zstore [srcreg], zmm1 ;; Store R1
zstore [srcreg+d1], zmm2 ;; Store R2
zstore [srcreg+d2], zmm3 ;; Store R3
zstore [srcreg+d2+d1], zmm4 ;; Store R4
zstore [srcreg+d4], zmm5 ;; Store R5
zstore [srcreg+d4+d1], zmm6 ;; Store R6
zstore [srcreg+d4+d2], zmm7 ;; Store R7
zstore [srcreg+d4+d2+d1], zmm8 ;; Store R8
zstore [srcreg+64], zmm9 ;; Store I1
zstore [srcreg+d1+64], zmm10 ;; Store I2
zstore [srcreg+d2+64], zmm11 ;; Store I3
zstore [srcreg+d2+d1+64], zmm12 ;; Store I4
zstore [srcreg+d4+64], zmm13 ;; Store I5
zstore [srcreg+d4+d1+64], zmm14 ;; Store I6
zstore [srcreg+d4+d2+64], zmm15 ;; Store I7
zstore [srcreg+d4+d2+d1+64], zmm16 ;; Store I8
bump srcreg, srcinc
ENDM
do_nothing_plus_L1prefetch MACRO srcreg,srcinc,d1,d2,d4,screg,scinc,maxrpt,L1pt,L1pd
L1prefetchw srcreg+L1pd, L1pt
L1prefetchw srcreg+64+L1pd, L1pt
L1prefetchw srcreg+d1+L1pd, L1pt
L1prefetchw srcreg+d1+64+L1pd, L1pt
L1prefetchw srcreg+d2+L1pd, L1pt
L1prefetchw srcreg+d2+64+L1pd, L1pt
L1prefetchw srcreg+d2+d1+L1pd, L1pt
L1prefetchw srcreg+d2+d1+64+L1pd, L1pt
L1prefetchw srcreg+d4+L1pd, L1pt
L1prefetchw srcreg+d4+64+L1pd, L1pt
L1prefetchw srcreg+d4+d1+L1pd, L1pt
L1prefetchw srcreg+d4+d1+64+L1pd, L1pt
L1prefetchw srcreg+d4+d2+L1pd, L1pt
L1prefetchw srcreg+d4+d2+64+L1pd, L1pt
L1prefetchw srcreg+d4+d2+d1+L1pd, L1pt
L1prefetchw srcreg+d4+d2+d1+64+L1pd, L1pt
vmovapd zmm1, [srcreg+d1] ;; R2
vmovapd zmm2, [srcreg+d4+d1] ;; R6
vmovapd zmm3, [srcreg+d2+d1+64] ;; I4
vmovapd zmm4, [srcreg+d4+d2+d1+64] ;; I8
vmovapd zmm5, [srcreg+d2+d1] ;; R4
vmovapd zmm6, [srcreg+d4+d2+d1] ;; R8
vmovapd zmm7, [srcreg+d1+64] ;; I2
vmovapd zmm8, [srcreg+d4+d1+64] ;; I6
vmovapd zmm9, [srcreg] ;; R1
vmovapd zmm10, [srcreg+d4] ;; R5
vmovapd zmm11, [srcreg+d2] ;; R3
vmovapd zmm12, [srcreg+d4+d2] ;; R7
vmovapd zmm13, [srcreg+64] ;; I1
vmovapd zmm14, [srcreg+d4+64] ;; I5
vmovapd zmm15, [srcreg+d2+64] ;; I3
vmovapd zmm16, [srcreg+d4+d2+64] ;; I7
zstore [srcreg], zmm1 ;; Store R1
zstore [srcreg+d1], zmm2 ;; Store R2
zstore [srcreg+d2], zmm3 ;; Store R3
zstore [srcreg+d2+d1], zmm4 ;; Store R4
zstore [srcreg+d4], zmm5 ;; Store R5
zstore [srcreg+d4+d1], zmm6 ;; Store R6
zstore [srcreg+d4+d2], zmm7 ;; Store R7
zstore [srcreg+d4+d2+d1], zmm8 ;; Store R8
zstore [srcreg+64], zmm9 ;; Store I1
zstore [srcreg+d1+64], zmm10 ;; Store I2
zstore [srcreg+d2+64], zmm11 ;; Store I3
zstore [srcreg+d2+d1+64], zmm12 ;; Store I4
zstore [srcreg+d4+64], zmm13 ;; Store I5
zstore [srcreg+d4+d1+64], zmm14 ;; Store I6
zstore [srcreg+d4+d2+64], zmm15 ;; Store I7
zstore [srcreg+d4+d2+d1+64], zmm16 ;; Store I8
bump srcreg, srcinc
ENDM
; this code reads/writes 64MB (1M cache lines) in contiguous blocks. Timings are done
; on 4 memory sizes. 4KB will operate on the L1 cache only, 128KB will operate on the
; L2 cache only, 2MB will operate on the L3 cache and 32MB will operate on main memory.
av512case0: read8 4096, 16384 ; Read 4KB
jmp exit
av512case1: read8 128*1024, 512 ; Read 128KB
jmp exit
av512case2: read8 2048*1024, 32 ; Read 2MB
jmp exit
av512case3: read8 32768*1024, 2 ; Read 32MB
jmp exit
av512case4: write8 4096, 16384 ; Write 4KB
jmp exit
av512case5: write8 128*1024, 512 ; Write 128KB
jmp exit
av512case6: write8 2048*1024, 32 ; Write 2MB
jmp exit
av512case7: write8 32768*1024, 2 ; Write 32MB
jmp exit
av512case8: readwrite8 4096, 16384 ; Read/write 4KB
jmp exit
av512case9: readwrite8 128*1024, 512 ; Read/write 128KB
jmp exit
av512case10: readwrite8 2048*1024, 32 ; Read/write 2MB
jmp exit
av512case11: readwrite8 32768*1024, 2 ; Read/write 32MB
jmp exit
;; Simulate various ways to implement a 9600K FFT, pass 1 = 1280, pass 2 = 7680.
;; Our AVX512 implementation is much, much slower in pass 1 with it's scatter reads
;; and scatter writes vs. pass 2 with its sequential reads and sequential writes.
;; Optimal, but not possible - sequential read and write.
av512case12: sequential_readwrite8 1280*7680*8, 5 ; Read/write 78MB
jmp exit
;; Scatter read and scatter write -- simulates pass 1 with clm = 2
av512case13: scatter_readwrite8 1280*7680*8, 5 ; Read/write 78MB
jmp exit
;; Sequential read and scatter write -- simulates rewritten pass 1 & 2
av512case14: sequential_read_scatter_write8 1280*7680*8, 5 ; Read/write 78MB
jmp exit
;; For completeness, scatter read and sequential write
av512case15: scatter_read_sequential_write8 1280*7680*8, 5 ; Read/write 78MB
jmp exit
zloop_init 32 ;; Dummy call to zloop_init
avx512_case_num = 16
;;16
avx512mac 1, 10000, 0, tenclocks ; Macro that should take exactly 10 clocks (for calibration purposes)
avx512mac 1, 10000, 0, hundredclocks ; Macro that should take exactly 100 clocks (for calibration purposes)
avx512mac 1, 10000, 0, hundredclocks512 ; compare 100 clocks of zmm vs ymm
avx512mac 1, 10000, 0, do5 do5 FMApenalty_test1
avx512mac 1, 10000, 0, do2 do10 FMApenalty_test2
avx512mac 1, 10000, 0, do2 do10 FMApenalty_test3
avx512mac 1, 10000, 0, do2 do10 FMApenalty_test4
avx512mac 1, 10000, 0, do2 do10 FMApenalty_test5
;;24 ; Macros that do nothing but load and store -- tests best case scenario
avx512mac 10240, 16384, 0, do10 do_nothing rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1 ;; Fastest possible L1 cache macro
avx512mac 10240, 262144, 0, do10 do_nothing rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1 ;; Fastest possible L2 cache macro
avx512mac 10240, 4194304, 0, do10 do_nothing rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1 ;; Fastest possible L3 cache macro
avx512mac 10240, 32768*1024, 0, do10 do_nothing rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1 ;; Fastest possible memory macro
avx512mac 10240, 16384, 0, do10 do_nothing_plus_sincos rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1
avx512mac 10240, 262144, 0, do10 do_nothing_plus_sincos rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1
avx512mac 10240, 262144, 0, do10 do_nothing_plus_L1prefetch rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1, L1PREFETCH_ALL, 1*8*128
avx512mac 10240, 262144, 0, do10 do_nothing_plus_L1prefetch rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1, L1PREFETCH_ALL, 2*8*128
avx512mac 10240, 262144, 0, do10 do_nothing_plus_L1prefetch rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1, L1PREFETCH_ALL, 3*8*128
avx512mac 10240, 262144, 0, do10 do_nothing_plus_L1prefetch rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1, L1PREFETCH_ALL, 4*8*128
;;34
avx512mac 1024, 16384, 0, zr8_eight_complex_djbfft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1
avx512mac 1024, 262144, 0, zr8_eight_complex_djbfft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1
avx512mac 1024, 262144, 0, zr8_eight_complex_djbfft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1, L1PREFETCH_ALL, 1*8*128
avx512mac 1024, 262144, 0, zr8_eight_complex_djbfft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1, L1PREFETCH_ALL, 2*8*128
avx512mac 1024, 16384, 0, zr8_eight_complex_djbunfft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1
avx512mac 1024, 262144, 0, zr8_eight_complex_djbunfft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD4, 1
;;40
avx512mac 640, 16384, 0, zr5_five_complex_djbfft rsi, 5*128, 128, rdi, ZMM_SCD2, 1
avx512mac 640, 262144, 0, zr5_five_complex_djbfft rsi, 5*128, 128, rdi, ZMM_SCD2, 1
avx512mac 640, 16384, 0, zr5_five_complex_djbunfft rsi, 5*128, 128, rdi, ZMM_SCD2, 1
avx512mac 640, 262144, 0, zr5_five_complex_djbunfft rsi, 5*128, 128, rdi, ZMM_SCD2, 1
avx512mac 768, 16384, 0, zr6_six_complex_djbfft rsi, 6*128, 128, rdi, ZMM_SCD3, 1
avx512mac 768, 262144, 0, zr6_six_complex_djbfft rsi, 6*128, 128, rdi, ZMM_SCD3, 1
avx512mac 768, 16384, 0, zr6_six_complex_djbunfft rsi, 6*128, 128, rdi, ZMM_SCD3, 1
avx512mac 768, 262144, 0, zr6_six_complex_djbunfft rsi, 6*128, 128, rdi, ZMM_SCD3, 1
avx512mac 896, 16384, 0, zr7_seven_complex_djbfft rsi, 7*128, 128, rdi, ZMM_SCD3, 1
avx512mac 896, 262144, 0, zr7_seven_complex_djbfft rsi, 7*128, 128, rdi, ZMM_SCD3, 1
avx512mac 896, 16384, 0, zr7_seven_complex_djbunfft rsi, 7*128, 128, rdi, ZMM_SCD3, 1
avx512mac 896, 262144, 0, zr7_seven_complex_djbunfft rsi, 7*128, 128, rdi, ZMM_SCD3, 1
avx512mac 1536, 16384, 0, zr12_twelve_complex_djbfft rsi, 12*128, 128, 2*128, 4*128, rdi, ZMM_SCD6, 1
avx512mac 1536, 262144, 0, zr12_twelve_complex_djbfft rsi, 12*128, 128, 2*128, 4*128, rdi, ZMM_SCD6, 1
avx512mac 1536, 16384, 0, zr12_twelve_complex_djbunfft rsi, 12*128, 128, 2*128, 4*128, rdi, ZMM_SCD6, 1
avx512mac 1536, 262144, 0, zr12_twelve_complex_djbunfft rsi, 12*128, 128, 2*128, 4*128, rdi, ZMM_SCD6, 1
avx512mac 2048, 16384, 0, zr16_sixteen_complex_djbfft rsi, 16*128, 128, 2*128, 4*128, 8*128, rdi, ZMM_SCD8, 1
avx512mac 2048, 262144, 0, zr16_sixteen_complex_djbfft rsi, 16*128, 128, 2*128, 4*128, 8*128, rdi, ZMM_SCD8, 1
avx512mac 2048, 16384, 0, zr16_sixteen_complex_djbunfft rsi, 16*128, 128, 2*128, 4*128, 8*128, rdi, ZMM_SCD8, 1
avx512mac 2048, 262144, 0, zr16_sixteen_complex_djbunfft rsi, 16*128, 128, 2*128, 4*128, 8*128, rdi, ZMM_SCD8, 1
;;60
avx512mac 640, 16384, 0, zr5_csc_ten_reals_fft rsi, 5*128, 128, rdi, ZMM_SCD5, 1
avx512mac 640, 262144, 0, zr5_csc_ten_reals_fft rsi, 5*128, 128, rdi, ZMM_SCD5, 1
avx512mac 640, 16384, 0, zr5_csc_ten_reals_unfft rsi, 5*128, 128, rdi, ZMM_SCD5, 1
avx512mac 640, 262144, 0, zr5_csc_ten_reals_unfft rsi, 5*128, 128, rdi, ZMM_SCD5, 1
avx512mac 768, 16384, 0, zr6_csc_twelve_reals_fft rsi, 6*128, 128, rdi, ZMM_SCD6, 1
avx512mac 768, 262144, 0, zr6_csc_twelve_reals_fft rsi, 6*128, 128, rdi, ZMM_SCD6, 1
avx512mac 768, 16384, 0, zr6_csc_twelve_reals_unfft rsi, 6*128, 128, rdi, ZMM_SCD6, 1
avx512mac 768, 262144, 0, zr6_csc_twelve_reals_unfft rsi, 6*128, 128, rdi, ZMM_SCD6, 1
avx512mac 896, 16384, 0, zr7_csc_fourteen_reals_fft rsi, 7*128, 128, rdi, ZMM_SCD7, 1
avx512mac 896, 262144, 0, zr7_csc_fourteen_reals_fft rsi, 7*128, 128, rdi, ZMM_SCD7, 1
avx512mac 896, 16384, 0, zr7_csc_fourteen_reals_unfft rsi, 7*128, 128, rdi, ZMM_SCD7, 1
avx512mac 896, 262144, 0, zr7_csc_fourteen_reals_unfft rsi, 7*128, 128, rdi, ZMM_SCD7, 1
avx512mac 1024, 16384, 0, zr8_csc_sixteen_reals_fft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD8, 1
avx512mac 1024, 262144, 0, zr8_csc_sixteen_reals_fft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD8, 1
avx512mac 1024, 16384, 0, zr8_csc_sixteen_reals_unfft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD8, 1
avx512mac 1024, 262144, 0, zr8_csc_sixteen_reals_unfft rsi, 8*128, 128, 2*128, 4*128, rdi, ZMM_SCD8, 1
avx512mac 1536, 16384, 0, zr12_csc_twentyfour_reals_fft rsi, 12*128, 128, 2*128, 4*128, rdi, ZMM_SCD12, 1
avx512mac 1536, 262144, 0, zr12_csc_twentyfour_reals_fft rsi, 12*128, 128, 2*128, 4*128, rdi, ZMM_SCD12, 1
avx512mac 1536, 16384, 0, zr12_csc_twentyfour_reals_unfft rsi, 12*128, 128, 2*128, 4*128, rdi, ZMM_SCD12, 1
avx512mac 1536, 262144, 0, zr12_csc_twentyfour_reals_unfft rsi, 12*128, 128, 2*128, 4*128, rdi, ZMM_SCD12, 1
avx512mac 2048, 16384, 0, zr16_csc_thirtytwo_reals_fft rsi, 16*128, 128, 2*128, 4*128, 8*128, rdi, ZMM_SCD16, 1
avx512mac 2048, 262144, 0, zr16_csc_thirtytwo_reals_fft rsi, 16*128, 128, 2*128, 4*128, 8*128, rdi, ZMM_SCD16, 1
avx512mac 2048, 16384, 0, zr16_csc_thirtytwo_reals_unfft rsi, 16*128, 128, 2*128, 4*128, 8*128, rdi, ZMM_SCD16, 1
avx512mac 2048, 262144, 0, zr16_csc_thirtytwo_reals_unfft rsi, 16*128, 128, 2*128, 4*128, 8*128, rdi, ZMM_SCD16, 1
;;84
zr64_sixtyfour_complex_fft_final_preload
avx512mac 1024, 16384, 0, zr64_sixtyfour_complex_fft_final rsi, 8*128, 1*128, 2*128, 4*128, rdi, 0, 1
avx512mac 1024, 262144, 0, zr64_sixtyfour_complex_fft_final rsi, 8*128, 1*128, 2*128, 4*128, rdi, 0, 1
zr64_sixtyfour_complex_with_square_preload
avx512mac 1024, 16384, 0, zr64_sixtyfour_complex_with_square rsi, 8*128, 1*128, 2*128, 4*128, rdi, 0, 1
avx512mac 1024, 262144, 0, zr64_sixtyfour_complex_with_square rsi, 8*128, 1*128, 2*128, 4*128, rdi, 0, 1
zr64_sixtyfour_complex_with_mult_preload
avx512mac 1024, 16384, 0, zr64_sixtyfour_complex_with_mult rsi, 8*128, 1*128, 2*128, 4*128, rdi, 0, 1
avx512mac 1024, 262144, 0, zr64_sixtyfour_complex_with_mult rsi, 8*128, 1*128, 2*128, 4*128, rdi, 0, 1
zr64f_sixtyfour_complex_with_mulf_preload
avx512mac 1024, 16384, 0, zr64f_sixtyfour_complex_with_mulf rsi, 8*128, 1*128, 2*128, 4*128, rdi, 0, 1
avx512mac 1024, 262144, 0, zr64f_sixtyfour_complex_with_mulf rsi, 8*128, 1*128, 2*128, 4*128, rdi, 0, 1
;;92
zr8_csc_wpn_eight_complex_first_djbfft_preload
avx512mac 1024, 16384, 0, zr8_csc_wpn_eight_complex_first_djbfft rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
avx512mac 1024, 262144, 0, zr8_csc_wpn_eight_complex_first_djbfft rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
zr8_csc_wpn_eight_complex_last_djbunfft_preload
avx512mac 1024, 16384, 0, zr8_csc_wpn_eight_complex_last_djbunfft rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
avx512mac 1024, 262144, 0, zr8_csc_wpn_eight_complex_last_djbunfft rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
;;96
zr8_wpn_sixteen_reals_first_fft_preload
avx512mac 1024, 16384, 0, zr8_wpn_sixteen_reals_first_fft rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
avx512mac 1024, 262144, 0, zr8_wpn_sixteen_reals_first_fft rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
zr8_wpn_sixteen_reals_last_unfft_preload
avx512mac 1024, 16384, 0, zr8_wpn_sixteen_reals_last_unfft rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
avx512mac 1024, 262144, 0, zr8_wpn_sixteen_reals_last_unfft rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
;;100
zr12_csc_wpn_twelve_complex_first_djbfft_preload
avx512mac 1536, 16384, 0, zr12_csc_wpn_twelve_complex_first_djbfft rsi, 12*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
avx512mac 1536, 262144, 0, zr12_csc_wpn_twelve_complex_first_djbfft rsi, 12*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
zr12_csc_wpn_twelve_complex_last_djbunfft_preload
avx512mac 1536, 16384, 0, zr12_csc_wpn_twelve_complex_last_djbunfft rsi, 12*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
avx512mac 1536, 262144, 0, zr12_csc_wpn_twelve_complex_last_djbunfft rsi, 12*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
;;104
zr12_wpn_twentyfour_reals_first_fft_preload
avx512mac 1536, 16384, 0, zr12_wpn_twentyfour_reals_first_fft rsi, 12*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
avx512mac 1536, 262144, 0, zr12_wpn_twentyfour_reals_first_fft rsi, 12*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
zr12_wpn_twentyfour_reals_last_unfft_preload
avx512mac 1536, 16384, 0, zr12_wpn_twentyfour_reals_last_unfft rsi, 12*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
avx512mac 1536, 262144, 0, zr12_wpn_twentyfour_reals_last_unfft rsi, 12*128, 128, 2*128, 4*128, r15, 0, rdi, 16, rdx, 0, 1
;;108
avx512mac 1024, 8192, 0, zr8_rsc_wpn_sgreg_eight_complex_fft8 rsi, 1024, 128, 256, 512, rdx, 1024, r8, r9, r10, rdi, ZMM_SCD8, 1
avx512mac 1024, 262144, 0, zr8_rsc_wpn_sgreg_eight_complex_fft8 rsi, 1024, 128, 256, 512, rdx, 1024, r8, r9, r10, rdi, ZMM_SCD8, 1
avx512mac 1024, 8192, 0, zr8_rsc_wpn_sgreg_eight_complex_unfft8 rdx, 1024, r8, r9, r10, rsi, 1024, 128, 256, 512, rdi, ZMM_SCD8, 1
avx512mac 1024, 262144, 0, zr8_rsc_wpn_sgreg_eight_complex_unfft8 rdx, 1024, r8, r9, r10, rsi, 1024, 128, 256, 512, rdi, ZMM_SCD8, 1
avx512mac 1024, 8192, 0, zr8_rsc_wpn_sgreg_2sc_sixteen_reals_fft8 rsi, 1024, 128, 256, 512, rdx, 1024, r8, r9, r10, rdi, 0, rdi, 0, rdi, ZMM_SCD8, 1
avx512mac 1024, 262144, 0, zr8_rsc_wpn_sgreg_2sc_sixteen_reals_fft8 rsi, 1024, 128, 256, 512, rdx, 1024, r8, r9, r10, rdi, 0, rdi, 0, rdi, ZMM_SCD8, 1
avx512mac 1024, 8192, 0, zr8_rsc_wpn_sgreg_2sc_sixteen_reals_unfft8 rdx, 1024, r8, r9, r10, rsi, 1024, 128, 256, 512, rdi, 0, rdi, 0, rdi, ZMM_SCD8, 1
avx512mac 1024, 262144, 0, zr8_rsc_wpn_sgreg_2sc_sixteen_reals_unfft8 rdx, 1024, r8, r9, r10, rsi, 1024, 128, 256, 512, rdi, 0, rdi, 0, rdi, ZMM_SCD8, 1
;;116
zsf_onepass_real_fft_wrapper_preload
avx512mac 1024, 16384, 0, zsf_onepass_real_fft_wrapper rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 14, rdx, 0, 1
avx512mac 1024, 262144, 0, zsf_onepass_real_fft_wrapper rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 14, rdx, 0, 1
zs_onepass_real_unfft_wrapper_preload
avx512mac 1024, 16384, 0, zs_onepass_real_unfft_wrapper rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 14, 1
avx512mac 1024, 262144, 0, zs_onepass_real_unfft_wrapper rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 14, 1
zsf_onepass_complex_fft_wrapper_preload
avx512mac 1024, 16384, 0, zsf_onepass_complex_fft_wrapper rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 14, rdx, 0, 1
avx512mac 1024, 262144, 0, zsf_onepass_complex_fft_wrapper rsi, 8*128, 128, 2*128, 4*128, r15, 0, rdi, 14, rdx, 0, 1
zs_onepass_complex_unfft_wrapper_preload
avx512mac 1024, 16384, 0, zs_onepass_complex_unfft_wrapper rsi, 8*128, 128, 2*128, 4*128, r15, 0, r15, 0, rdi, 14, 1
avx512mac 1024, 262144, 0, zs_onepass_complex_unfft_wrapper rsi, 8*128, 128, 2*128, 4*128, r15, 0, r15, 0, rdi, 14, 1
;;124
znorm_wpn_preload noexec, noexec, noexec, noexec ;; ttp, zero, echk, const
avx512znormmac 1536, 16384, 0, znorm_wpn noexec, noexec, noexec, noexec
avx512znormmac 1536, 262144, 0, znorm_wpn noexec, noexec, noexec, noexec
znorm_wpn_preload noexec, noexec, exec, noexec ;; ttp, zero, echk, const
avx512znormmac 1536, 16384, 0, znorm_wpn noexec, noexec, exec, noexec
avx512znormmac 1536, 262144, 0, znorm_wpn noexec, noexec, exec, noexec
znorm_wpn_preload noexec, noexec, noexec, exec ;; ttp, zero, echk, const
avx512znormmac 1536, 16384, 0, znorm_wpn noexec, noexec, noexec, exec
avx512znormmac 1536, 262144, 0, znorm_wpn noexec, noexec, noexec, exec
znorm_wpn_preload noexec, noexec, exec, exec ;; ttp, zero, echk, const
avx512znormmac 1536, 16384, 0, znorm_wpn noexec, noexec, exec, exec
avx512znormmac 1536, 262144, 0, znorm_wpn noexec, noexec, exec, exec
;;132
znorm_wpn_preload exec, noexec, noexec, noexec ;; ttp, zero, echk, const
avx512znormmac 1536, 16384, 0, znorm_wpn exec, noexec, noexec, noexec
avx512znormmac 1536, 262144, 0, znorm_wpn exec, noexec, noexec, noexec
znorm_wpn_preload exec, noexec, exec, noexec ;; ttp, zero, echk, const
avx512znormmac 1536, 16384, 0, znorm_wpn exec, noexec, exec, noexec
avx512znormmac 1536, 262144, 0, znorm_wpn exec, noexec, exec, noexec
znorm_wpn_preload exec, noexec, noexec, exec ;; ttp, zero, echk, const
avx512znormmac 1536, 16384, 0, znorm_wpn exec, noexec, noexec, exec
avx512znormmac 1536, 262144, 0, znorm_wpn exec, noexec, noexec, exec
znorm_wpn_preload exec, noexec, exec, exec ;; ttp, zero, echk, const
avx512znormmac 1536, 16384, 0, znorm_wpn exec, noexec, exec, exec
avx512znormmac 1536, 262144, 0, znorm_wpn exec, noexec, exec, exec
ENDIF
; Exit the timing code
exit: ad_epilog 0,0,rbx,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15,xmm6,xmm7,xmm8,xmm9,xmm10,xmm11,xmm12,xmm13,xmm14,xmm15
gwtimeit ENDP
_TEXT ENDS
END
|
src/Parse/LL1.agda | WhatisRT/meta-cedille | 35 | 1109 | --------------------------------------------------------------------------------
-- This file contains the definition of a context-free grammar, as well as a
-- parser for those grammars that are actually of LL1 type. There is currently
-- no check if the grammar is actually a LL1 grammar, so the parser might loop
-- indefinitely or return an error message in certain cases, even if the string
-- actually matches the grammar.
--------------------------------------------------------------------------------
{-# OPTIONS --type-in-type #-}
module Parse.LL1 where
import Data.String as S
open import Data.Sum using (isInj₁)
open import Class.Monad.Except
open import Data.String using (fromList; toList; uncons)
open import Data.List using (boolDropWhile)
open import Data.Tree
open import Prelude
record CFG (V : Set) (MultiChar : Set) : Set₁ where
field
S : V
R : V → Set
AllRules : (v : V) → List (R v)
-- whether to keep track of the result
V' : Set
V' = V × Bool
field
Rstring'' : {v : V} → R v → List (V' ⊎ MultiChar ⊎ String)
Terminal : Set
Terminal = MultiChar ⊎ String
isMultiChar : Terminal → Bool
isMultiChar (inj₁ _) = true
isMultiChar (inj₂ _) = false
terminalLength : Terminal → ℕ
terminalLength (inj₁ x) = 1
terminalLength (inj₂ y) = S.length y
Rule : Set
Rule = ∃[ v ] R v
Rstring : {v : V} → R v → List (V ⊎ MultiChar ⊎ String)
Rstring r = map (Data.Sum.map₁ proj₁) (Rstring'' r)
Rstring' : Rule → List (V ⊎ Terminal)
Rstring' (_ , r) = Rstring r
SynTree : Set
SynTree = Tree (Rule ⊎ Char)
private variable v : V
produces-ε : R v → Bool
produces-ε = null ∘ Rstring
module _ {V MultiChar : Set} (showV : V → String)
(matchMulti : MultiChar → Char → Bool) (showMulti : MultiChar → String)
(G : CFG V MultiChar) (M : Set → Set) {{_ : Monad M}} {{_ : MonadExcept M String}} where
-- we don't care if it is actually a LL1 grammar
private variable v : V
open CFG G
showTerminal : Terminal → String
showTerminal (inj₁ x) = showMulti x
showTerminal (inj₂ y) = y
match : String → Terminal → Bool
match s (inj₁ x) with strHead s
... | nothing = false
... | just c = matchMulti x c
match s (inj₂ y) = strTake (S.length y) s ≣ y
-- select the first rule satisfying the predicate
firstRule : (v : V) → (R v → Bool) → Maybe (R v)
firstRule v P = head $ boolDropWhile (not ∘ P) $ AllRules v
{-# NON_TERMINATING #-}
parsingTable : V → String → Maybe Rule
parsingTable v' x = -,_ <$> firstRule v' (startWith x) <∣> firstRule v' produces-ε
-- select the first rule starting with x, or the first that is empty
where
startWith : String → R v → Bool
startWith x = helper x ∘ Rstring
where
helper : String → List (V ⊎ Terminal) → Bool
helper x [] = false
helper x (inj₁ v ∷ rest) with boolFilter (startWith x) (AllRules v)
... | [] = if null $ boolFilter produces-ε (AllRules v) then false else helper x rest
... | _ = true
helper x (inj₂ t ∷ _) = match x t
{-# NON_TERMINATING #-}
parseWithInitNT : V → String → M (SynTree × String)
parseWithInitNT v a = do
(y , rest) ← helper [ inj₁ v ] a
maybe
(λ z → return (z , rest)) (throwError "BUG: Error while creating syntax tree.")
(resToTree y)
where
helper : List (V ⊎ Terminal) → String → M (List (Rule ⊎ Char) × String)
helper [] s = return ([] , s)
helper (inj₁ x ∷ stack) s with parsingTable x s
... | just r = map₁ (inj₁ r ∷_) <$> helper (Rstring' r ++ stack) s
... | nothing = throwError $
"No applicable rule found for non-terminal " + showV x + "\nRemaining:\n" + s
helper (inj₂ y ∷ stack) s with uncons s | match s y
... | just (x , _) | true = let prepend = if isMultiChar y then inj₂ x ∷_ else id
in map₁ prepend <$> helper stack (strDrop (terminalLength y) s)
... | just _ | false = throwError $
"Mismatch while parsing characters: tried to parse " + showTerminal y +
" but got '" + s + "'"
... | nothing | _ = throwError ("Unexpected end of input while trying to parse " + showTerminal y)
resToTree : List (Rule ⊎ Char) → Maybe SynTree
resToTree x = proj₁ <$> resToTree' x
where
needsChild : V' ⊎ Terminal → Bool
needsChild (inj₁ x) = true
needsChild (inj₂ (inj₁ x)) = true
needsChild (inj₂ (inj₂ y)) = false
attachChild : V' ⊎ Terminal → Bool
attachChild (inj₁ (_ , b)) = b
attachChild _ = true
resToTree' : List (Rule ⊎ Char) → Maybe (SynTree × List (Rule ⊎ Char))
ruleChildren : List (V' ⊎ Terminal) → List (Rule ⊎ Char) → Maybe (List SynTree × List (Rule ⊎ Char))
resToTree' [] = nothing
resToTree' (inj₁ l ∷ l₁) with ruleChildren (Rstring'' (proj₂ l)) l₁
... | just (fst , snd) = just (Node (inj₁ l) fst , snd)
... | nothing = nothing
resToTree' (inj₂ l ∷ l₁) = just (Node (inj₂ l) [] , l₁)
ruleChildren [] l = just ([] , l)
ruleChildren (x ∷ s) l with needsChild x | resToTree' l
... | false | _ = ruleChildren s l
... | true | just (t , rest) = (if attachChild x then map₁ (t ∷_) else id) <$> ruleChildren s rest
... | true | nothing = nothing
|
checkout.adb | annexi-strayline/AURA | 13 | 23259 | <gh_stars>10-100
------------------------------------------------------------------------------
-- --
-- Ada User Repository Annex (AURA) --
-- Reference Implementation --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * <NAME> (ANNEXI-STRAYLINE) --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- --
-- * Neither the name of the copyright holder nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A --
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
with Ada.Directories;
with Ada.Assertions;
with Workers, Workers.Reporting;
with Unit_Names;
with User_Queries;
with Repositories;
with Registrar.Queries;
with Registrar.Registration;
with Registrar.Library_Units;
package body Checkout is
procedure Assert (Check: in Boolean; Message: in String)
renames Ada.Assertions.Assert;
New_Line: Character renames Workers.Reporting.New_Line;
-------------------------
-- Parse_Checkout_Spec --
-------------------------
function Parse_Checkout_Spec (Unit: Registrar.Library_Units.Library_Unit)
return Repositories.Repository_Index
is separate;
-------------------------
-- Write_Checkout_Spec --
-------------------------
procedure Write_Checkout_Spec (SS: in Registrar.Subsystems.Subsystem) is
separate;
--
-- Checkout_Orders
--
package Checkout_Orders is
type Checkout_Order is new Workers.Work_Order with
record
Target: Registrar.Subsystems.Subsystem;
end record;
overriding procedure Execute (Order: in out Checkout_Order);
overriding function Image (Order: Checkout_Order) return String;
end Checkout_Orders;
package body Checkout_Orders is separate;
-------------------
-- Checkout_Pass --
-------------------
procedure Checkout_Pass is
use Unit_Names;
use Registrar.Subsystems;
use Registrar.Library_Units;
package Queries renames Registrar.Queries;
Order: Checkout_Orders.Checkout_Order;
Candidates: Subsystem_Sets.Set := Queries.Requested_Subsystems;
begin
-- Get the tracker in order
Order.Tracker := Checkout_Pass_Progress'Access;
pragma Assert (Order.Tracker.Is_Complete);
-- This tracker should always be waited on for completion before
-- re-invoking checkout cycle
Order.Tracker.Increase_Total_Items_By (Natural (Candidates.Length));
for SS of Candidates loop
Order.Target := SS;
Workers.Enqueue_Order (Order);
end loop;
end Checkout_Pass;
end Checkout;
|
Assignment/main.adb | vivianjia123/Password-Manager | 0 | 5994 | -- Authors: <NAME> 965600, <NAME> 693241
-- Our implementation proves following security properties:
-- The Get, Put, Remove and Lock operations can only ever be performed
-- when the password manager is in the unlocked state.
-- We implemented procedures called Execute_xxx (i.e. Execute_Lock)
-- for each operation and only calls the operation if preconditions are true.
-- We specified the precondition IsLocked(Manager_Information) = False for all
-- four operations to ensure that they are only executed if the password manager
-- is unlocked. This ensures the confidentiality and integrity of the system as
-- only users who has knowledge of the master pin can access and carry out changes
-- to the database and master pin. We added the precondition PasswordDatabase.Has_Password_For
-- for Get and Remove operations to ensure that the operations are not carried out if
-- the database has no entry for the url in question. This ensures the safety of the system
-- and prevents from the system from crashing if Put or Remove operations are executed
-- for an entry that does not exist within the PasswordDatabase. For Put Command we
-- specified the precondition StoredDatabaseLength(Manager_Information) < PasswordDatabase.Max_Entries
-- in addition to IsLocked precondition to ensure that the number of database entries stored
-- currently do not the maximum entries specified. Likewise, this also ensures the safety
-- of the system and prevents the database from overflowing and causing the system to crash.
--
-- The Unlock operation can only ever be performed when the password manager is in the locked state.
-- We have an Execute_Unlock procedure which only calls the procedure Unlock_Manager if the
-- IsLocked(Manager_Information) and supplied input pin equals to the stored master pin preconditions
-- are true. We specified the post condition that if Unlock_Manager is executed then the Pin_Input
-- needs to be equal to the current master pin and that IsLocked(Manager_Information) = False. This
-- ensures the authentication of the system as only users who knows master pin can unlock the password manager.
--
-- The Lock operation, when it is performed, should update the master PIN with
-- the new PIN that is supplied.
-- We have Execute_Lock procedure which only calls the procedure Lock_Manager if the
-- IsLocked(Manager_Information) precondition is false. We specified post conditions
-- that if Lock_Manager is executed then the Master Pin needs to be updated to Pin_Input
-- and IsLocked(Manager_Information) is true. This ensures the authentication of the
-- system as only users who have unlocked the password manager can update
-- changes to the master pin and lock the system.
--
-- The password manager can be in one of two states, either locked or unlocked.
-- We implemented a private record type called information that records the database,
-- master pin and lock status of the system. Our implementation ensures encapsulation
-- and allows information hiding as this information cannot be accessed outside
-- of the PasswordManager package. Is_Locked represents the two states
-- of the Password Manager and can be only accessed through the Lock_Status function.
pragma SPARK_Mode (On);
with PasswordDatabase;
with MyCommandLine;
with MyString;
with MyStringTokeniser;
with PIN;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with PasswordManager;
with Utility;
procedure Main is
package Lines is new MyString(Max_MyString_Length => 2048);
S : Lines.MyString;
PM_Information : PasswordManager.Information;
GETDB : constant String := "get";
REMDB : constant String := "rem";
PUTDB : constant String := "put";
UNLOCK : constant String := "unlock";
LOCK : constant String := "lock";
TokensList : MyStringTokeniser.TokenArray(1..5):= (others => (Start => 1, Length => 0));
NumTokens : Natural;
begin
-- Program must initiate with 1 Pin input
if (MyCommandLine.Argument_Count = 1) then
declare
Temp_Pin : String := MyCommandLine.Argument(1);
begin
-- Pin must meet specified Pin requirements prior to Password Manager
-- initiation
if (MyCommandLine.Argument(1)'Length = 4 and
(for all I in Temp_Pin'Range => Temp_Pin(I)
>= '0' and Temp_Pin(I) <= '9')) then
PasswordManager.Init(MyCommandLine.Argument(1), PM_Information);
else
Put_Line("Invalid input, program will exit!");
return;
end if;
end;
else
Put_Line("Invalid input, program will exit!");
return;
end if;
-- While loop for the system
while True loop
-- Checks status of Password Manager
if (PasswordManager.Lock_Status(PM_Information)) then
Put("locked> ");Lines.Get_Line(S);
else
Put("unlocked> ");Lines.Get_Line(S);
end if;
-- Tokenises input
MyStringTokeniser.Tokenise(Lines.To_String(S),TokensList,NumTokens);
-- Checks input command validity and termiantes program if input
-- does not follow requirements
if (NumTokens < 1 or NumTokens > 3
or Lines.To_String(S)'Length < 1
or Lines.To_String(S)'Length > Utility.Max_Line_Length) then
Put_Line("Invalid input, program will exit!");
return;
else
declare
-- Converts command token into string
Command : String :=
To_Lower(Lines.To_String(Lines.Substring(S,TokensList(1).Start,
TokensList(1).Start+TokensList(1).Length-1)));
begin
-- Get Command
if (Command = GETDB and NumTokens = Utility.Get_Rem_Pin_Length) then
-- If validity check is met get command is executed
declare
-- Converts Url Token into String
TokUrl : String := Lines.To_String
(Lines.Substring(S,TokensList(2).Start,
TokensList(2).Start+TokensList(2).Length-1));
begin
-- If Url is within required length then get
-- execution is called
if (TokUrl'Length <= PasswordDatabase.Max_URL_Length) then
PasswordManager.Execute_Get_Command
(PM_Information,PasswordDatabase.From_String(TokUrl));
-- Else the program terminates with error message
else
Put_Line("Invalid input, program will exit!");
return;
end if;
end;
-- Put Command
elsif (Command = PUTDB and NumTokens = Utility.Put_Length) then
declare
-- Converts Url Token into String
TokUrl : String := Lines.To_String
(Lines.Substring(S,TokensList(2).Start,
TokensList(2).Start+TokensList(2).Length-1));
-- Converts Pwd Token into String
TokPwd : String := Lines.To_String
(Lines.Substring(S,TokensList(3).Start,
TokensList(3).Start+TokensList(3).Length-1));
begin
-- If url and password are within required length then
-- put execution is called
if (TokUrl'Length <= PasswordDatabase.Max_URL_Length and
TokPwd'Length <= PasswordDatabase.Max_Password_Length) then
PasswordManager.Execute_Put_Command
(PM_Information,PasswordDatabase.From_String(TokUrl),
PasswordDatabase.From_String(TokPwd));
-- Else the program terminates with error message
else
Put_Line("Invalid input, program will exit!");
return;
end if;
end;
-- Rem Command
elsif (Command = REMDB and NumTokens = Utility.Get_Rem_Pin_Length) then
declare
-- Converts Url Token into String
TokUrl : String := Lines.To_String
(Lines.Substring(S,TokensList(2).Start,
TokensList(2).Start+TokensList(2).Length-1));
begin
-- If Url is within required length then command is executed
if (TokUrl'Length <= PasswordDatabase.Max_URL_Length) then
PasswordManager.Execute_Rem_Command
(PM_Information,PasswordDatabase.From_String(TokUrl));
-- Else the program terminates with error message
else
Put_Line("Invalid input, program will exit!");
return;
end if;
end;
-- Unlock Command
elsif (Command = UNLOCK and NumTokens = Utility.Get_Rem_Pin_Length) then
declare
-- Converts Pin Token into String
TokPin : String := Lines.To_String
(Lines.Substring(S,TokensList(2).Start,
TokensList(2).Start+TokensList(2).Length - 1));
begin
-- If Pin validity is met then Password Manager will
-- be unlocked
if (TokPin'Length = 4 and
(for all I in TokPin'Range =>
TokPin(I) >= '0' and TokPin(I) <= '9')) then
PasswordManager.Execute_Unlock
(PM_Information, PIN.From_String(TokPin));
-- Else the program terminates with error message
else
Put_Line("Invalid input, program will exit!");
return;
end if;
end;
-- Lock Command
elsif(Command = LOCK and NumTokens = Utility.Get_Rem_Pin_Length) then
declare
TokPin : String := Lines.To_String
(Lines.Substring(S,TokensList(2).Start,
TokensList(2).Start+TokensList(2).Length-1));
begin
-- If validity check is met Lock command is executed
if (TokPin'Length = 4 and
(for all I in TokPin'Range =>
TokPin(I) >= '0' and TokPin(I) <= '9')) then
PasswordManager.Execute_Lock(PM_Information,
PIN.From_String(TokPin));
-- Else the program terminates with error message
else
Put_Line("Invalid input, program will exit!");
return;
end if;
end;
-- Other irregular commands will cause program to print out
-- error message and terminate
else
Put_Line("Invalid input, program will exit!");
return;
end if;
end;
end if;
end loop;
end Main;
|
v2.0/source/msdos/stdio.asm | neozeed/MS-DOS | 7 | 24559 | ;
; Standard device IO for MSDOS (first 12 function calls)
;
.xlist
.xcref
INCLUDE STDSW.ASM
INCLUDE DOSSEG.ASM
.cref
.list
TITLE STDIO - device IO for MSDOS
NAME STDIO
INCLUDE IO.ASM
|
other.7z/NEWS.7z/NEWS/テープリストア/NEWS_05/NEWS_05.tar/home/kimura/polygon.lzh/polygon/sf2/gastrats.asm | prismotizm/gigaleak | 0 | 19663 | Name: gastrats.asm
Type: file
Size: 4021
Last-Modified: '1993-03-02T01:36:57Z'
SHA-1: E2959A8E1DAD3D5C8CEE4F340FEA7C29099087F6
Description: null
|
libsrc/_DEVELOPMENT/math/float/math48/c/sccz80/cm48_sccz80_modf.asm | meesokim/z88dk | 0 | 90989 | <reponame>meesokim/z88dk
; double modf(double value, double *iptr)
SECTION code_fp_math48
PUBLIC cm48_sccz80_modf
EXTERN l0_cm48_sccz80_modf_callee, am48_dloadb
cm48_sccz80_modf:
pop af
pop hl ; hl = iptr
push hl
push af
exx
ld hl,9
add hl,sp
call am48_dloadb
jp l0_cm48_sccz80_modf_callee
|
Transynther/x86/_processed/NONE/_xt_/i9-9900K_12_0xa0_notsx.log_21829_1710.asm | ljhsiun2/medusa | 9 | 173849 | <filename>Transynther/x86/_processed/NONE/_xt_/i9-9900K_12_0xa0_notsx.log_21829_1710.asm
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %r8
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WC_ht+0x15061, %rdx
nop
sub $16980, %r11
movw $0x6162, (%rdx)
nop
nop
nop
nop
inc %rbp
lea addresses_UC_ht+0x7e7b, %rsi
lea addresses_D_ht+0x6afb, %rdi
nop
nop
cmp %r8, %r8
mov $87, %rcx
rep movsw
nop
nop
nop
nop
nop
and $64697, %r11
lea addresses_D_ht+0x8e7b, %rdx
nop
xor %rcx, %rcx
vmovups (%rdx), %ymm5
vextracti128 $1, %ymm5, %xmm5
vpextrq $0, %xmm5, %r11
nop
nop
nop
nop
nop
add %r8, %r8
lea addresses_A_ht+0xb2a8, %rbp
nop
xor %r11, %r11
movl $0x61626364, (%rbp)
nop
nop
nop
and $24621, %r14
lea addresses_normal_ht+0x103f7, %rsi
lea addresses_A_ht+0x63ab, %rdi
cmp $25499, %rbp
mov $94, %rcx
rep movsq
nop
nop
nop
nop
nop
add $23949, %r8
lea addresses_WT_ht+0x78fb, %rsi
lea addresses_WC_ht+0x1266b, %rdi
nop
sub %r11, %r11
mov $33, %rcx
rep movsl
nop
nop
nop
nop
nop
sub %rbp, %rbp
lea addresses_WT_ht+0x1e97b, %rbp
nop
nop
cmp %rcx, %rcx
mov (%rbp), %r14w
nop
nop
add $50880, %rcx
lea addresses_WC_ht+0x1b57b, %rsi
lea addresses_WT_ht+0x1acbb, %rdi
nop
cmp $51631, %r14
mov $51, %rcx
rep movsw
nop
add %rbp, %rbp
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r8
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %rbp
push %rdi
push %rdx
// Faulty Load
lea addresses_D+0xde7b, %rbp
xor $59191, %rdx
mov (%rbp), %r12d
lea oracles, %rdi
and $0xff, %r12
shlq $12, %r12
mov (%rdi,%r12,1), %r12
pop %rdx
pop %rdi
pop %rbp
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_D', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_D', 'AVXalign': False, 'size': 4, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 1}}
{'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}}
{'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 11}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 4, 'NT': True, 'same': False, 'congruent': 0}}
{'src': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}}
{'src': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}}
{'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': True, 'congruent': 5}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}}
{'36': 21829}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
00.BootLoader/BootLoader.asm | yeojin-dev/yeojinux | 0 | 82719 | [ORG 0x00] ; 코드의 시작 어드레스를 0x00으로 설정
[BITS 16] ; 이하 코드는 16비트 코드로 설정
SECTION .txt ; text 섹션(세그먼트) 정의
jmp 0x07C0:START ; CS 세그먼트 레지스터에 0x07C0을 복사하면서, START 레이블로 이동
; MINT64 OS에 관련된 환경 설정 값
TOTALSECTORCOUNT: dw 0x02 ; 부트 로더를 제외한 MINT64 OS 이미지의 크기, 최대 1152섹터(0x90000바이트)까지 가능
KERNEL32SECTORCOUNT:dw 0x02 ; 보호 모드 커널의 총 섹터 수
; 코드 영역
START:
mov ax, 0x07C0 ; 부트 로더의 시작 어드레스(0x7C00)를 세그먼트 레지스터 값으로 변환
mov ds, ax ; DS 세그먼트 레지스터에 설정
mov ax, 0xB800 ; 비디오 메모리의 시작 어드레스(0xB800)를 세그먼트 레지스터 값으로 변환
mov es, ax ; ES 세그먼트 레지스터에 설정
;스택을 0x0000:0000~0x0000:FFFF 영역에 64KB 크기로 생성
mov ax, 0x0000 ; 스택 세그먼트의 시작 어드레스(0x0000)를 세그먼트 레지스터 값으로 변환
mov ss, ax ; SS 세그먼트 레지스터에 저장
mov sp, 0xFFFE ; SP 레지스터의 어드레스를 0xFFFE로 설정
mov bp, 0xFFFE ; BP 레지스터의 어드레스를 0xFFFE로 설정
mov si, 0 ; SI 레지스터(문자열 원본 인덱스 레지스터)를 초기화
.SCREENCLEARLOOP: ; 화면을 지우는 루프
mov byte[es:si], 0 ; 비디오 메모리의 문자가 위치하는 어드레스에 0을 복사하여 문자를 삭제
mov byte[es:si + 1], 0x0A ; 비디오 메모리의 속성이 위치하는 어드레스에 0x0A(검은 바탕에 밝은 녹색)을 복사
add si, 2 ; 문자와 속성을 설정했으므로 다음 위치로 이동
cmp si, 80 * 25 * 2 ; 화면 전체 크기는 80문자 * 25라인, 출력한 문자의 수를 의미하는 SI 레지스터와 비교
jl .SCREENCLEARLOOP ; SI 레지스터가 80 * 25 * 2보다 작다면 아직 지우지 못 한 영역이 있으므로 .SCREENCLEARLOOP 레이블로 이동
; 화면 상단에 시작 메시지 출력
push MESSAGE1 ; 출력할 메시지의 어드레스를 스택에 삽입
push 0 ; 화면 Y 좌표를 스택에 삽입
push 0 ; 화면 X 좌표를 스택에 삽입
call PRINTMESSAGE ; PRINTMESSAGE 함수 호출
add sp, 6 ; 삽입한 파라미터 제거
; OS 이미지를 로딩한다는 메시지 출력
push IMAGELOADINGMESSAGE ; 출력할 메시지의 어드레스를 스택에 삽입
push 1 ; 화면 Y 좌표를 스택에 삽입
push 0 ; 화면 X 좌표를 스택에 삽입
call PRINTMESSAGE ; PRINTMESSAGE 함수 호출
add sp, 6 ; 삽입한 파라미터 제거
; 디스크에서 OS 이미지 로딩
; 디스크 읽기 전에 먼저 리셋
RESETDISK: ; 디스크 리셋 코드 시작
; BIOS Reset Function 호출
; 서비스 번호 0, 드라이브 번호 0(Floppy)
mov ax, 0
mov dl, 0
int 0x13
jc HANDLEDISKERROR ; 에러가 발생하면 에러 처리로 이동
; 디스크에서 섹터를 읽음
; 디스크의 내용을 메모리로 복사할 어드레스(ES:BX)를 0x10000으로 설정
mov si, 0x1000 ; OS 이미지를 복사할 어드레스(0x10000)를 세그먼트 레지스터 값으로 변환
mov es, si
mov bx, 0x0000 ; BX 레지스터에 0x0000을 설정하여 복사할 어드레스를 0x1000:0000(0x10000)으로 최종 설정
mov di, word [ TOTALSECTORCOUNT ] ; 복사할 OS 이미지의 섹터 수를 DI 레지스터에 설정
READDATA: ; 디스크를 읽는 코드의 시작
; 모든 섹터를 다 읽었는지 확인
cmp di, 0 ; 복사할 OS 이미지의 섹터 수를 0과 비교
je READEND ; 복사할 섹터 수가 0이라면 다 복사했으므로 READEND로 이동
sub di, 0x1 ; 복사할 섹터 수 1 감소
; BIOS Read Function 호출
mov ah, 0x02 ; BIOS 서비스 번호 2(Read Sector)
mov al, 0x1 ; 읽을 섹터 수는 1
mov ch, byte [ TRACKNUMBER ] ; 읽을 트랙 번호 설정
mov cl, byte [ SECTORNUMBER ] ; 읽을 섹터 번호 설정
mov dh, byte [ HEADNUMBER ] ; 읽을 헤드 번호 설정
mov dl, 0x00 ; 읽을 드라이브 번호 0(Floppy) 설정
int 0x13 ; 인터럽트 서비스 수행
jc HANDLEDISKERROR ; 에러가 발생했다면 HANDLEDISKERROR로 이동
; 복사할 어드레스와 트랙, 헤드, 섹터 어드레스 계산
; 읽은 섹터는 ES:BX 위치에 저장됨
add si, 0x0020 ; 512(0x200)바이트만큼 읽었으므로, 이를 세그먼트 레지스터 값으로 변환
mov es, si ; ES 세그먼트 레지스터에 더해서 어드레스를 한 섹터만큼 증가
; 한 섹터를 읽었으므로 섹터 번호를 증가시키고 마지막 섹터(18)까지 읽었는지 판단, 마지막 섹터가 아니면 섹터 읽기로 이동해서 다시 섹터 읽기 수행
mov al, byte [ SECTORNUMBER ] ; 섹터 번호를 AL 레지스터에 설정
add al, 0x1 ; 섹터 번호를 1 증가
mov byte [ SECTORNUMBER ], al ; 증가시킨 섹터 번호를 SECTORNUMBER에 다시 설정
cmp al, 37 ; 증가시킨 섹터 번호를 37과 비교
jl READDATA ; 섹터 번호가 37 미만이라면 READDATA로 이동
; 마지막 섹터까지 읽었으면(섹터 번호가 37이면) 헤드를 토글하고 섹터 번호를 1로 설정
xor byte[ HEADNUMBER ], 0x01 ; 헤드 번호를 0x01과 XOR 하여 토글
mov byte[ SECTORNUMBER ], 0x01 ; 섹터 번호를 다시 1로 설정
; 만약 헤드가 1 -> 0으로 바뀌었으면 양쪽 헤드를 모두 읽은 것이므로 아래로 이동하여 트랙 번호를 1 증가
cmp byte[ HEADNUMBER ], 0x00 ; 헤드 번호를 0x00과 비교
jne READDATA ; 헤드 번호가 0이 아니면 READDATA로 이동
; 트랙을 1 증가시킨 후 다시 섹터 읽기로 이동
add byte [ TRACKNUMBER ], 0x01 ; 트랙 번호를 1 증가
jmp READDATA
READEND:
; OS 이미지가 완료되었다는 메시지를 출력
push LOADINGCOMPLETEMESSAGE ; 출력할 메시지의 어드레스를 스택에 삽입
push 1
push 20
call PRINTMESSAGE
add sp, 6
jmp 0x1000:0x0000 ; 로딩한 가상 OS 이미지 실행
; 함수 코드 영역
HANDLEDISKERROR: ; 디스크 에러를 처리하는 함수
push DISKERRORMESSAGE ; 에러 문자열의 어드레스를 스택에 삽입
push 1
push 20
call PRINTMESSAGE
jmp $ ; 현재 위치에서 무한 루프 수행
PRINTMESSAGE:
push bp ; 베이스 포인터 레지스터를 스택에 삽입
mov bp, sp ; 베이스 포인터 레지스터에 스택 포인터 레지스터의 값을 설정
push es
push si
push di
push ax
push cx
push dx
mov ax, 0xB800 ; 비디오 메모리 시작 어드레스(0x0B8000)를 세그먼트 레지스터 값으로 변환
mov es, ax ; ES 세그먼트 레지스터에 설정
; X, Y의 좌표로 비디오 메모리 어드레스를 계산함
; Y 좌표를 이용해서 먼저 라인 어드레스를 계산함
mov ax, word [ bp + 6 ] ; 파라미터 2(화면 좌표 Y)를 AX 레지스터에 설정
mov si, 160 ; 한 라인의 바이트 수(2 * 80)를 SI 레지스터에 설정
mul si ; AX 레지스터와 SI 레지스터를 곱하여 화면 X 어드레스를 계산
add di, ax ; 화면 Y 어드레스와 계산된 X 어드레스를 더해서 실제 비디오 메모리 어드레스를 계산
; X 좌표를 이용해서 2를 곱한 후 최종 어드레스를 구함
mov ax, word [ bp + 4 ]
mov si, 2
mul si
add di, ax
; 출력할 문자열의 어드레스
mov si, word [ bp + 8 ] ; 파라미터 3
.MESSAGELOOP: ; 메시지를 출력하는 루프
mov cl, byte[ si ] ; SI 레지스터가 가리키는 문자열 위치에서 한 문자를 CL 레지스터(CX 레지스터의 하위 1바이트)에 복사
cmp cl, 0 ; 복사된 문자와 0을 비교
je .MESSAGEEND ; 복사한 문자의 값이 0이면 문자열이 종료되었음을 의미하므로 문자 출력 종료
mov byte[es:di], cl ; 0이 아니라면 비디오 메모리 어드레스 0xB800:di에 문자를 출력
add si, 1 ; SI 레지스터에 1을 더하여 다음 문자열로 이동
add di, 2 ; DI 레지스터에 2를 더하여 비디오 메모리의 다음 문자 위치로 이동, 비디오 메모리는 (문자, 속성)의 쌍으로 구성되므로 문자만 출력하라면 2를 더해야 함
jmp .MESSAGELOOP ; 메시지 출력 루프로 이동하여 다음 문자를 출력
.MESSAGEEND:
pop dx
pop cx
pop ax
pop di
pop si
pop es
pop bp ; 베이스 포인터 레지스터 복원
ret ; 함수를 호출한 다음 코드의 위치로 복귀
; 데이터 영역
MESSAGE1: db 'MINT64 OS Boot Loader Start~!!', 0 ; 출력할 메시지 정의, 마지막은 0으로 설정해서 문자열이 종료되었음을 알 수 있도록 함
DISKERRORMESSAGE: db 'DISK Error~!!', 0
IMAGELOADINGMESSAGE: db 'OS Image Loading...', 0
LOADINGCOMPLETEMESSAGE: db 'Complete~!!', 0
; 디스크 읽기 관련 변수
SECTORNUMBER: db 0x02 ; OS 이미지가 시작하는 섹터 번호를 저장하는 영역
HEADNUMBER: db 0x00
TRACKNUMBER: db 0x00
times 510 - ($ - $$) db 0x00; $: 현재 라인의 어드레스, $$: 현재 섹션(.text)의 시작 어드레스, $ - $$: 현재 섹션을 기준으로 하는 오프셋
; 510-($-$$): 현재부터 510 어드레스까지, db 0x00: 1바이트를 선언하고 값은 0x00, time: 반복 수행
; 현재 위치에서 어드레스 510까지 0x00으로 채움
db 0x55 ; 어드레스 511(1바이트)에 1바이트 선언하고 값은 0x55
db 0xAA ; 어드레스 512(1바이트)에 1바이트 선언하고 값은 0xAA
; 위 2줄이 없으면 부트 로더로 인식하지 못 함
|
simd/i386/jdcolext-mmx.asm | 1camper/libjpeg-turbo | 522 | 13777 | ;
; jdcolext.asm - colorspace conversion (MMX)
;
; Copyright 2009 Pierre Ossman <<EMAIL>> for Cendio AB
; Copyright (C) 2016, <NAME>.
;
; Based on the x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jcolsamp.inc"
; --------------------------------------------------------------------------
;
; Convert some rows of samples to the output colorspace.
;
; GLOBAL(void)
; jsimd_ycc_rgb_convert_mmx(JDIMENSION out_width, JSAMPIMAGE input_buf,
; JDIMENSION input_row, JSAMPARRAY output_buf,
; int num_rows)
;
%define out_width(b) (b) + 8 ; JDIMENSION out_width
%define input_buf(b) (b) + 12 ; JSAMPIMAGE input_buf
%define input_row(b) (b) + 16 ; JDIMENSION input_row
%define output_buf(b) (b) + 20 ; JSAMPARRAY output_buf
%define num_rows(b) (b) + 24 ; int num_rows
%define original_ebp ebp + 0
%define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_MMWORD
; mmword wk[WK_NUM]
%define WK_NUM 2
%define gotptr wk(0) - SIZEOF_POINTER ; void * gotptr
align 32
GLOBAL_FUNCTION(jsimd_ycc_rgb_convert_mmx)
EXTN(jsimd_ycc_rgb_convert_mmx):
push ebp
mov eax, esp ; eax = original ebp
sub esp, byte 4
and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
mov [esp], eax
mov ebp, esp ; ebp = aligned ebp
lea esp, [wk(0)]
pushpic eax ; make a room for GOT address
push ebx
; push ecx ; need not be preserved
; push edx ; need not be preserved
push esi
push edi
get_GOT ebx ; get GOT address
movpic POINTER [gotptr], ebx ; save GOT address
mov ecx, JDIMENSION [out_width(eax)] ; num_cols
test ecx, ecx
jz near .return
push ecx
mov edi, JSAMPIMAGE [input_buf(eax)]
mov ecx, JDIMENSION [input_row(eax)]
mov esi, JSAMPARRAY [edi+0*SIZEOF_JSAMPARRAY]
mov ebx, JSAMPARRAY [edi+1*SIZEOF_JSAMPARRAY]
mov edx, JSAMPARRAY [edi+2*SIZEOF_JSAMPARRAY]
lea esi, [esi+ecx*SIZEOF_JSAMPROW]
lea ebx, [ebx+ecx*SIZEOF_JSAMPROW]
lea edx, [edx+ecx*SIZEOF_JSAMPROW]
pop ecx
mov edi, JSAMPARRAY [output_buf(eax)]
mov eax, INT [num_rows(eax)]
test eax, eax
jle near .return
alignx 16, 7
.rowloop:
push eax
push edi
push edx
push ebx
push esi
push ecx ; col
mov esi, JSAMPROW [esi] ; inptr0
mov ebx, JSAMPROW [ebx] ; inptr1
mov edx, JSAMPROW [edx] ; inptr2
mov edi, JSAMPROW [edi] ; outptr
movpic eax, POINTER [gotptr] ; load GOT address (eax)
alignx 16, 7
.columnloop:
movq mm5, MMWORD [ebx] ; mm5=Cb(01234567)
movq mm1, MMWORD [edx] ; mm1=Cr(01234567)
pcmpeqw mm4, mm4
pcmpeqw mm7, mm7
psrlw mm4, BYTE_BIT
psllw mm7, 7 ; mm7={0xFF80 0xFF80 0xFF80 0xFF80}
movq mm0, mm4 ; mm0=mm4={0xFF 0x00 0xFF 0x00 ..}
pand mm4, mm5 ; mm4=Cb(0246)=CbE
psrlw mm5, BYTE_BIT ; mm5=Cb(1357)=CbO
pand mm0, mm1 ; mm0=Cr(0246)=CrE
psrlw mm1, BYTE_BIT ; mm1=Cr(1357)=CrO
paddw mm4, mm7
paddw mm5, mm7
paddw mm0, mm7
paddw mm1, mm7
; (Original)
; R = Y + 1.40200 * Cr
; G = Y - 0.34414 * Cb - 0.71414 * Cr
; B = Y + 1.77200 * Cb
;
; (This implementation)
; R = Y + 0.40200 * Cr + Cr
; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
; B = Y - 0.22800 * Cb + Cb + Cb
movq mm2, mm4 ; mm2=CbE
movq mm3, mm5 ; mm3=CbO
paddw mm4, mm4 ; mm4=2*CbE
paddw mm5, mm5 ; mm5=2*CbO
movq mm6, mm0 ; mm6=CrE
movq mm7, mm1 ; mm7=CrO
paddw mm0, mm0 ; mm0=2*CrE
paddw mm1, mm1 ; mm1=2*CrO
pmulhw mm4, [GOTOFF(eax,PW_MF0228)] ; mm4=(2*CbE * -FIX(0.22800))
pmulhw mm5, [GOTOFF(eax,PW_MF0228)] ; mm5=(2*CbO * -FIX(0.22800))
pmulhw mm0, [GOTOFF(eax,PW_F0402)] ; mm0=(2*CrE * FIX(0.40200))
pmulhw mm1, [GOTOFF(eax,PW_F0402)] ; mm1=(2*CrO * FIX(0.40200))
paddw mm4, [GOTOFF(eax,PW_ONE)]
paddw mm5, [GOTOFF(eax,PW_ONE)]
psraw mm4, 1 ; mm4=(CbE * -FIX(0.22800))
psraw mm5, 1 ; mm5=(CbO * -FIX(0.22800))
paddw mm0, [GOTOFF(eax,PW_ONE)]
paddw mm1, [GOTOFF(eax,PW_ONE)]
psraw mm0, 1 ; mm0=(CrE * FIX(0.40200))
psraw mm1, 1 ; mm1=(CrO * FIX(0.40200))
paddw mm4, mm2
paddw mm5, mm3
paddw mm4, mm2 ; mm4=(CbE * FIX(1.77200))=(B-Y)E
paddw mm5, mm3 ; mm5=(CbO * FIX(1.77200))=(B-Y)O
paddw mm0, mm6 ; mm0=(CrE * FIX(1.40200))=(R-Y)E
paddw mm1, mm7 ; mm1=(CrO * FIX(1.40200))=(R-Y)O
movq MMWORD [wk(0)], mm4 ; wk(0)=(B-Y)E
movq MMWORD [wk(1)], mm5 ; wk(1)=(B-Y)O
movq mm4, mm2
movq mm5, mm3
punpcklwd mm2, mm6
punpckhwd mm4, mm6
pmaddwd mm2, [GOTOFF(eax,PW_MF0344_F0285)]
pmaddwd mm4, [GOTOFF(eax,PW_MF0344_F0285)]
punpcklwd mm3, mm7
punpckhwd mm5, mm7
pmaddwd mm3, [GOTOFF(eax,PW_MF0344_F0285)]
pmaddwd mm5, [GOTOFF(eax,PW_MF0344_F0285)]
paddd mm2, [GOTOFF(eax,PD_ONEHALF)]
paddd mm4, [GOTOFF(eax,PD_ONEHALF)]
psrad mm2, SCALEBITS
psrad mm4, SCALEBITS
paddd mm3, [GOTOFF(eax,PD_ONEHALF)]
paddd mm5, [GOTOFF(eax,PD_ONEHALF)]
psrad mm3, SCALEBITS
psrad mm5, SCALEBITS
packssdw mm2, mm4 ; mm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
packssdw mm3, mm5 ; mm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
psubw mm2, mm6 ; mm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
psubw mm3, mm7 ; mm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
movq mm5, MMWORD [esi] ; mm5=Y(01234567)
pcmpeqw mm4, mm4
psrlw mm4, BYTE_BIT ; mm4={0xFF 0x00 0xFF 0x00 ..}
pand mm4, mm5 ; mm4=Y(0246)=YE
psrlw mm5, BYTE_BIT ; mm5=Y(1357)=YO
paddw mm0, mm4 ; mm0=((R-Y)E+YE)=RE=(R0 R2 R4 R6)
paddw mm1, mm5 ; mm1=((R-Y)O+YO)=RO=(R1 R3 R5 R7)
packuswb mm0, mm0 ; mm0=(R0 R2 R4 R6 ** ** ** **)
packuswb mm1, mm1 ; mm1=(R1 R3 R5 R7 ** ** ** **)
paddw mm2, mm4 ; mm2=((G-Y)E+YE)=GE=(G0 G2 G4 G6)
paddw mm3, mm5 ; mm3=((G-Y)O+YO)=GO=(G1 G3 G5 G7)
packuswb mm2, mm2 ; mm2=(G0 G2 G4 G6 ** ** ** **)
packuswb mm3, mm3 ; mm3=(G1 G3 G5 G7 ** ** ** **)
paddw mm4, MMWORD [wk(0)] ; mm4=(YE+(B-Y)E)=BE=(B0 B2 B4 B6)
paddw mm5, MMWORD [wk(1)] ; mm5=(YO+(B-Y)O)=BO=(B1 B3 B5 B7)
packuswb mm4, mm4 ; mm4=(B0 B2 B4 B6 ** ** ** **)
packuswb mm5, mm5 ; mm5=(B1 B3 B5 B7 ** ** ** **)
%if RGB_PIXELSIZE == 3 ; ---------------
; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **)
; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **)
; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **)
; mmG=(** ** ** ** ** ** ** **), mmH=(** ** ** ** ** ** ** **)
punpcklbw mmA, mmC ; mmA=(00 10 02 12 04 14 06 16)
punpcklbw mmE, mmB ; mmE=(20 01 22 03 24 05 26 07)
punpcklbw mmD, mmF ; mmD=(11 21 13 23 15 25 17 27)
movq mmG, mmA
movq mmH, mmA
punpcklwd mmA, mmE ; mmA=(00 10 20 01 02 12 22 03)
punpckhwd mmG, mmE ; mmG=(04 14 24 05 06 16 26 07)
psrlq mmH, 2*BYTE_BIT ; mmH=(02 12 04 14 06 16 -- --)
psrlq mmE, 2*BYTE_BIT ; mmE=(22 03 24 05 26 07 -- --)
movq mmC, mmD
movq mmB, mmD
punpcklwd mmD, mmH ; mmD=(11 21 02 12 13 23 04 14)
punpckhwd mmC, mmH ; mmC=(15 25 06 16 17 27 -- --)
psrlq mmB, 2*BYTE_BIT ; mmB=(13 23 15 25 17 27 -- --)
movq mmF, mmE
punpcklwd mmE, mmB ; mmE=(22 03 13 23 24 05 15 25)
punpckhwd mmF, mmB ; mmF=(26 07 17 27 -- -- -- --)
punpckldq mmA, mmD ; mmA=(00 10 20 01 11 21 02 12)
punpckldq mmE, mmG ; mmE=(22 03 13 23 04 14 24 05)
punpckldq mmC, mmF ; mmC=(15 25 06 16 26 07 17 27)
cmp ecx, byte SIZEOF_MMWORD
jb short .column_st16
movq MMWORD [edi+0*SIZEOF_MMWORD], mmA
movq MMWORD [edi+1*SIZEOF_MMWORD], mmE
movq MMWORD [edi+2*SIZEOF_MMWORD], mmC
sub ecx, byte SIZEOF_MMWORD
jz short .nextrow
add esi, byte SIZEOF_MMWORD ; inptr0
add ebx, byte SIZEOF_MMWORD ; inptr1
add edx, byte SIZEOF_MMWORD ; inptr2
add edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; outptr
jmp near .columnloop
alignx 16, 7
.column_st16:
lea ecx, [ecx+ecx*2] ; imul ecx, RGB_PIXELSIZE
cmp ecx, byte 2*SIZEOF_MMWORD
jb short .column_st8
movq MMWORD [edi+0*SIZEOF_MMWORD], mmA
movq MMWORD [edi+1*SIZEOF_MMWORD], mmE
movq mmA, mmC
sub ecx, byte 2*SIZEOF_MMWORD
add edi, byte 2*SIZEOF_MMWORD
jmp short .column_st4
.column_st8:
cmp ecx, byte SIZEOF_MMWORD
jb short .column_st4
movq MMWORD [edi+0*SIZEOF_MMWORD], mmA
movq mmA, mmE
sub ecx, byte SIZEOF_MMWORD
add edi, byte SIZEOF_MMWORD
.column_st4:
movd eax, mmA
cmp ecx, byte SIZEOF_DWORD
jb short .column_st2
mov DWORD [edi+0*SIZEOF_DWORD], eax
psrlq mmA, DWORD_BIT
movd eax, mmA
sub ecx, byte SIZEOF_DWORD
add edi, byte SIZEOF_DWORD
.column_st2:
cmp ecx, byte SIZEOF_WORD
jb short .column_st1
mov WORD [edi+0*SIZEOF_WORD], ax
shr eax, WORD_BIT
sub ecx, byte SIZEOF_WORD
add edi, byte SIZEOF_WORD
.column_st1:
cmp ecx, byte SIZEOF_BYTE
jb short .nextrow
mov BYTE [edi+0*SIZEOF_BYTE], al
%else ; RGB_PIXELSIZE == 4 ; -----------
%ifdef RGBX_FILLER_0XFF
pcmpeqb mm6, mm6 ; mm6=(X0 X2 X4 X6 ** ** ** **)
pcmpeqb mm7, mm7 ; mm7=(X1 X3 X5 X7 ** ** ** **)
%else
pxor mm6, mm6 ; mm6=(X0 X2 X4 X6 ** ** ** **)
pxor mm7, mm7 ; mm7=(X1 X3 X5 X7 ** ** ** **)
%endif
; mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **)
; mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **)
; mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **)
; mmG=(30 32 34 36 ** ** ** **), mmH=(31 33 35 37 ** ** ** **)
punpcklbw mmA, mmC ; mmA=(00 10 02 12 04 14 06 16)
punpcklbw mmE, mmG ; mmE=(20 30 22 32 24 34 26 36)
punpcklbw mmB, mmD ; mmB=(01 11 03 13 05 15 07 17)
punpcklbw mmF, mmH ; mmF=(21 31 23 33 25 35 27 37)
movq mmC, mmA
punpcklwd mmA, mmE ; mmA=(00 10 20 30 02 12 22 32)
punpckhwd mmC, mmE ; mmC=(04 14 24 34 06 16 26 36)
movq mmG, mmB
punpcklwd mmB, mmF ; mmB=(01 11 21 31 03 13 23 33)
punpckhwd mmG, mmF ; mmG=(05 15 25 35 07 17 27 37)
movq mmD, mmA
punpckldq mmA, mmB ; mmA=(00 10 20 30 01 11 21 31)
punpckhdq mmD, mmB ; mmD=(02 12 22 32 03 13 23 33)
movq mmH, mmC
punpckldq mmC, mmG ; mmC=(04 14 24 34 05 15 25 35)
punpckhdq mmH, mmG ; mmH=(06 16 26 36 07 17 27 37)
cmp ecx, byte SIZEOF_MMWORD
jb short .column_st16
movq MMWORD [edi+0*SIZEOF_MMWORD], mmA
movq MMWORD [edi+1*SIZEOF_MMWORD], mmD
movq MMWORD [edi+2*SIZEOF_MMWORD], mmC
movq MMWORD [edi+3*SIZEOF_MMWORD], mmH
sub ecx, byte SIZEOF_MMWORD
jz short .nextrow
add esi, byte SIZEOF_MMWORD ; inptr0
add ebx, byte SIZEOF_MMWORD ; inptr1
add edx, byte SIZEOF_MMWORD ; inptr2
add edi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; outptr
jmp near .columnloop
alignx 16, 7
.column_st16:
cmp ecx, byte SIZEOF_MMWORD/2
jb short .column_st8
movq MMWORD [edi+0*SIZEOF_MMWORD], mmA
movq MMWORD [edi+1*SIZEOF_MMWORD], mmD
movq mmA, mmC
movq mmD, mmH
sub ecx, byte SIZEOF_MMWORD/2
add edi, byte 2*SIZEOF_MMWORD
.column_st8:
cmp ecx, byte SIZEOF_MMWORD/4
jb short .column_st4
movq MMWORD [edi+0*SIZEOF_MMWORD], mmA
movq mmA, mmD
sub ecx, byte SIZEOF_MMWORD/4
add edi, byte 1*SIZEOF_MMWORD
.column_st4:
cmp ecx, byte SIZEOF_MMWORD/8
jb short .nextrow
movd DWORD [edi+0*SIZEOF_DWORD], mmA
%endif ; RGB_PIXELSIZE ; ---------------
alignx 16, 7
.nextrow:
pop ecx
pop esi
pop ebx
pop edx
pop edi
pop eax
add esi, byte SIZEOF_JSAMPROW
add ebx, byte SIZEOF_JSAMPROW
add edx, byte SIZEOF_JSAMPROW
add edi, byte SIZEOF_JSAMPROW ; output_buf
dec eax ; num_rows
jg near .rowloop
emms ; empty MMX state
.return:
pop edi
pop esi
; pop edx ; need not be preserved
; pop ecx ; need not be preserved
pop ebx
mov esp, ebp ; esp <- aligned ebp
pop esp ; esp <- original ebp
pop ebp
ret
; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this.
align 32
|
tools-src/gnu/gcc/gcc/ada/5htraceb.adb | enfoTek/tomato.linksys.e2000.nvram-mod | 80 | 14988 | ------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . T R A C E B A C K --
-- (HP/UX Version) --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1999-2001 Ada Core Technologies, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
package body System.Traceback is
-- This package implements the backtracing facility by way of a dedicated
-- HP library for stack unwinding described in the "Runtime Architecture
-- Document".
pragma Linker_Options ("/usr/lib/libcl.a");
-- The library basically offers services to fetch information about a
-- "previous" frame based on information about a "current" one.
type Current_Frame_Descriptor is record
cur_fsz : Address; -- Frame size of current routine.
cur_sp : Address; -- The current value of stack pointer.
cur_rls : Address; -- PC-space of the caller.
cur_rlo : Address; -- PC-offset of the caller.
cur_dp : Address; -- Data Pointer of the current routine.
top_rp : Address; -- Initial value of RP.
top_mrp : Address; -- Initial value of MRP.
top_sr0 : Address; -- Initial value of sr0.
top_sr4 : Address; -- Initial value of sr4.
top_r3 : Address; -- Initial value of gr3.
cur_r19 : Address; -- GR19 value of the calling routine.
top_r4 : Address; -- Initial value of gr4.
dummy : Address; -- Reserved.
out_rlo : Address; -- PC-offset of the caller after get_previous.
end record;
type Previous_Frame_Descriptor is record
prev_fsz : Address; -- frame size of calling routine.
prev_sp : Address; -- SP of calling routine.
prev_rls : Address; -- PC_space of calling routine's caller.
prev_rlo : Address; -- PC_offset of calling routine's caller.
prev_dp : Address; -- DP of calling routine.
udescr0 : Address; -- low word of calling routine's unwind desc.
udescr1 : Address; -- high word of calling routine's unwind desc.
ustart : Address; -- start of the unwind region.
uend : Address; -- end of the unwind region.
uw_index : Address; -- index into the unwind table.
prev_r19 : Address; -- GR19 value of the caller's caller.
top_r3 : Address; -- Caller's initial gr3.
top_r4 : Address; -- Caller's initial gr4.
end record;
-- Provide useful shortcuts for the names
subtype CFD is Current_Frame_Descriptor;
subtype PFD is Previous_Frame_Descriptor;
-- Frames with dynamic stack allocation are handled using the associated
-- frame pointer, but HP compilers and GCC setup this pointer differently.
-- HP compilers set it to point at the top (highest address) of the static
-- part of the frame, wheras GCC sets it to point at the bottom of this
-- region. We have to fake the unwinder to compensate for this difference,
-- for which we'll need to access some subprograms unwind descriptors.
type Bits_2_Value is mod 2 ** 2;
for Bits_2_Value'Size use 2;
type Bits_4_Value is mod 2 ** 4;
for Bits_4_Value'Size use 4;
type Bits_5_Value is mod 2 ** 5;
for Bits_5_Value'Size use 5;
type Bits_27_Value is mod 2 ** 27;
for Bits_27_Value'Size use 27;
type Unwind_Descriptor is record
cannot_unwind : Boolean;
mcode : Boolean;
mcode_save_restore : Boolean;
region_desc : Bits_2_Value;
reserved0 : Boolean;
entry_sr : Boolean;
entry_fr : Bits_4_Value;
entry_gr : Bits_5_Value;
args_stored : Boolean;
variable_frame : Boolean;
separate_package_body : Boolean;
frame_extension_mcode : Boolean;
stack_overflow_check : Boolean;
two_steps_sp_adjust : Boolean;
sr4_export : Boolean;
cxx_info : Boolean;
cxx_try_catch : Boolean;
sched_entry_seq : Boolean;
reserved1 : Boolean;
save_sp : Boolean;
save_rp : Boolean;
save_mrp : Boolean;
save_r19 : Boolean;
cleanups : Boolean;
hpe_interrupt_marker : Boolean;
hpux_interrupt_marker : Boolean;
large_frame : Boolean;
alloca_frame : Boolean;
reserved2 : Boolean;
frame_size : Bits_27_Value;
end record;
for Unwind_Descriptor'Size use 64;
for Unwind_Descriptor use record
cannot_unwind at 0 range 0 .. 0;
mcode at 0 range 1 .. 1;
mcode_save_restore at 0 range 2 .. 2;
region_desc at 0 range 3 .. 4;
reserved0 at 0 range 5 .. 5;
entry_sr at 0 range 6 .. 6;
entry_fr at 0 range 7 .. 10;
entry_gr at 1 range 3 .. 7;
args_stored at 2 range 0 .. 0;
variable_frame at 2 range 1 .. 1;
separate_package_body at 2 range 2 .. 2;
frame_extension_mcode at 2 range 3 .. 3;
stack_overflow_check at 2 range 4 .. 4;
two_steps_sp_adjust at 2 range 5 .. 5;
sr4_export at 2 range 6 .. 6;
cxx_info at 2 range 7 .. 7;
cxx_try_catch at 3 range 0 .. 0;
sched_entry_seq at 3 range 1 .. 1;
reserved1 at 3 range 2 .. 2;
save_sp at 3 range 3 .. 3;
save_rp at 3 range 4 .. 4;
save_mrp at 3 range 5 .. 5;
save_r19 at 3 range 6 .. 6;
cleanups at 3 range 7 .. 7;
hpe_interrupt_marker at 4 range 0 .. 0;
hpux_interrupt_marker at 4 range 1 .. 1;
large_frame at 4 range 2 .. 2;
alloca_frame at 4 range 3 .. 3;
reserved2 at 4 range 4 .. 4;
frame_size at 4 range 5 .. 31;
end record;
subtype UWD is Unwind_Descriptor;
type UWD_Ptr is access all UWD;
function To_UWD_Access is new Ada.Unchecked_Conversion (Address, UWD_Ptr);
-- The descriptor associated with a given code location is retrieved
-- using functions imported from the HP library, requiring the definition
-- of additional structures.
type Unwind_Table_Region is record
Table_Start : Address;
Table_End : Address;
end record;
-- An Unwind Table region, which is a memory area containing Unwind
-- Descriptors.
subtype UWT is Unwind_Table_Region;
type UWT_Ptr is access all UWT;
function To_UWT_Address is new Ada.Unchecked_Conversion (UWT_Ptr, Address);
-- The subprograms imported below are provided by the HP library
function U_get_unwind_table return UWT;
pragma Import (C, U_get_unwind_table, "U_get_unwind_table");
-- Get the unwind table region associated with the current executable.
-- This function is actually documented as having an argument, but which
-- is only used for the MPE/iX targets.
function U_get_shLib_unwind_table (r19 : Address) return UWT;
pragma Import (C, U_get_shLib_unwind_table, "U_get_shLib_unw_tbl");
-- Return the unwind table region associated with a possible shared
-- library, as determined by the provided r19 value.
function U_get_shLib_text_addr (r19 : Address) return Address;
pragma Import (C, U_get_shLib_text_addr, "U_get_shLib_text_addr");
-- Return the address at which the code for a shared library begins, or
-- -1 if the value provided for r19 does not identify shared library code.
function U_get_unwind_entry
(Pc : Address;
Space : Address;
Table_Start : Address;
Table_End : Address)
return Address;
pragma Import (C, U_get_unwind_entry, "U_get_unwind_entry");
-- Given the bounds of an unwind table, return the address of the
-- unwind descriptor associated with a code location/space. In the case
-- of shared library code, the offset from the beginning of the library
-- is expected as Pc.
procedure U_init_frame_record (Frame : access CFD);
pragma Import (C, U_init_frame_record, "U_init_frame_record");
procedure U_prep_frame_rec_for_unwind (Frame : access CFD);
pragma Import (C, U_prep_frame_rec_for_unwind,
"U_prep_frame_rec_for_unwind");
-- Fetch the description data of the frame in which these two procedures
-- are called.
function U_get_u_rlo (Cur : access CFD; Prev : access PFD) return Integer;
pragma Import (C, U_get_u_rlo, "U_IS_STUB_OR_CALLX");
-- From a complete current frame with a return location possibly located
-- into a linker generated stub, and basic information about the previous
-- frame, place the first non stub return location into the current frame.
-- Return -1 if something went wrong during the computation.
function U_is_shared_pc (rlo : Address; r19 : Address) return Address;
pragma Import (C, U_is_shared_pc, "U_is_shared_pc");
-- Return 0 if the provided return location does not correspond to code
-- in a shared library, or something non null otherwise.
function U_get_previous_frame_x
(current_frame : access CFD;
previous_frame : access PFD;
previous_size : Integer)
return Integer;
pragma Import (C, U_get_previous_frame_x, "U_get_previous_frame_x");
-- Fetch the data describing the "previous" frame relatively to the
-- "current" one. "previous_size" should be the size of the "previous"
-- frame descriptor provided.
--
-- The library provides a simpler interface without the size parameter
-- but it is not usable when frames with dynamically allocated space are
-- on the way.
------------------
-- C_Call_Chain --
------------------
function C_Call_Chain
(Traceback : System.Address;
Max_Len : Natural)
return Natural
is
Val : Natural;
begin
Call_Chain (Traceback, Max_Len, Val);
return Val;
end C_Call_Chain;
----------------
-- Call_Chain --
----------------
procedure Call_Chain
(Traceback : System.Address;
Max_Len : Natural;
Len : out Natural;
Exclude_Min : System.Address := System.Null_Address;
Exclude_Max : System.Address := System.Null_Address)
is
type Tracebacks_Array is array (1 .. Max_Len) of System.Address;
pragma Suppress_Initialization (Tracebacks_Array);
-- The code location returned by the unwinder is a return location but
-- what we need is a call point. Under HP-UX call instructions are 4
-- bytes long and the return point they specify is 4 bytes beyond the
-- next instruction because of the delay slot.
Call_Size : constant := 4;
DSlot_Size : constant := 4;
Rlo_Offset : constant := Call_Size + DSlot_Size;
-- Moreover, the return point is passed via a register which two least
-- significant bits specify a privilege level that we will have to mask.
Priv_Mask : constant := 16#00000003#;
Frame : aliased CFD;
Code : System.Address;
J : Natural := 1;
Pop_Success : Boolean;
Trace : Tracebacks_Array;
for Trace'Address use Traceback;
-- The backtracing process needs a set of subprograms :
function UWD_For_RLO_Of (Frame : access CFD) return UWD_Ptr;
-- Return an access to the unwind descriptor for the caller of
-- a given frame, using only the provided return location.
function UWD_For_Caller_Of (Frame : access CFD) return UWD_Ptr;
-- Return an access to the unwind descriptor for the user code caller
-- of a given frame, or null if the information is not available.
function Pop_Frame (Frame : access CFD) return Boolean;
-- Update the provided machine state structure so that it reflects
-- the state one call frame "above" the initial one.
--
-- Return True if the operation has been successful, False otherwise.
-- Failure typically occurs when the top of the call stack has been
-- reached.
function Prepare_For_Unwind_Of (Frame : access CFD) return Boolean;
-- Perform the necessary adaptations to the machine state before
-- calling the unwinder. Currently used for the specific case of
-- dynamically sized previous frames.
--
-- Return True if everything went fine, or False otherwise.
Program_UWT : constant UWT := U_get_unwind_table;
---------------
-- Pop_Frame --
---------------
function Pop_Frame (Frame : access CFD) return Boolean is
Up_Frame : aliased PFD;
State_Ready : Boolean;
begin
-- Check/adapt the state before calling the unwinder and return
-- if anything went wrong.
State_Ready := Prepare_For_Unwind_Of (Frame);
if not State_Ready then
return False;
end if;
-- Now, safely call the unwinder and use the results.
if U_get_previous_frame_x (Frame,
Up_Frame'Access,
Up_Frame'Size) /= 0
then
return False;
end if;
-- In case a stub is on the way, the usual previous return location
-- (the one in prev_rlo) is the one in the stub and the "real" one
-- is placed in the "current" record, so let's take this one into
-- account.
Frame.out_rlo := Frame.cur_rlo;
Frame.cur_fsz := Up_Frame.prev_fsz;
Frame.cur_sp := Up_Frame.prev_sp;
Frame.cur_rls := Up_Frame.prev_rls;
Frame.cur_rlo := Up_Frame.prev_rlo;
Frame.cur_dp := Up_Frame.prev_dp;
Frame.cur_r19 := Up_Frame.prev_r19;
Frame.top_r3 := Up_Frame.top_r3;
Frame.top_r4 := Up_Frame.top_r4;
return True;
end Pop_Frame;
---------------------------------
-- Prepare_State_For_Unwind_Of --
---------------------------------
function Prepare_For_Unwind_Of (Frame : access CFD) return Boolean
is
Caller_UWD : UWD_Ptr;
FP_Adjustment : Integer;
begin
-- No need to bother doing anything if the stack is already fully
-- unwound.
if Frame.cur_rlo = 0 then
return False;
end if;
-- When ALLOCA_FRAME is set in an unwind descriptor, the unwinder
-- uses the value provided in current.top_r3 or current.top_r4 as
-- a frame pointer to compute the size of the frame. What decides
-- between r3 or r4 is the unwind descriptor LARGE_FRAME bit, with
-- r4 chosen if the bit is set.
-- The size computed by the unwinder is STATIC_PART + (SP - FP),
-- which is correct with HP's frame pointer convention, but not
-- with GCC's one since we end up with the static part accounted
-- for twice.
-- We have to compute r4 when it is required because the unwinder
-- has looked for it at a place where it was not if we went through
-- GCC frames.
-- The size of the static part of a frame can be found in the
-- associated unwind descriptor.
Caller_UWD := UWD_For_Caller_Of (Frame);
-- If we cannot get it, we are unable to compute the potentially
-- necessary adjustments. We'd better not try to go on then.
if Caller_UWD = null then
return False;
end if;
-- If the caller frame is a GCC one, r3 is its frame pointer and
-- points to the bottom of the frame. The value to provide for r4
-- can then be computed directly from the one of r3, compensating
-- for the static part of the frame.
-- If the caller frame is an HP one, r3 is used to locate the
-- previous frame marker, that is it also points to the bottom of
-- the frame (this is why r3 cannot be used as the frame pointer in
-- the HP sense for large frames). The value to provide for r4 can
-- then also be computed from the one of r3 with the compensation
-- for the static part of the frame.
FP_Adjustment := Integer (Caller_UWD.frame_size * 8);
Frame.top_r4 := Address (Integer (Frame.top_r3) + FP_Adjustment);
return True;
end Prepare_For_Unwind_Of;
-----------------------
-- UWD_For_Caller_Of --
-----------------------
function UWD_For_Caller_Of (Frame : access CFD) return UWD_Ptr
is
UWD_Access : UWD_Ptr;
begin
-- First try the most direct path, using the return location data
-- associated with the frame.
UWD_Access := UWD_For_RLO_Of (Frame);
if UWD_Access /= null then
return UWD_Access;
end if;
-- If we did not get a result, we might face an in-stub return
-- address. In this case U_get_previous_frame can tell us what the
-- first not-in-stub return point is. We cannot call it directly,
-- though, because we haven't computed the potentially necessary
-- frame pointer adjustments, which might lead to SEGV in some
-- circumstances. Instead, we directly call the libcl routine which
-- is called by U_get_previous_frame and which only requires few
-- information. Take care, however, that the information is provided
-- in the "current" argument, so we need to work on a copy to avoid
-- disturbing our caller.
declare
U_Current : aliased CFD := Frame.all;
U_Previous : aliased PFD;
begin
U_Previous.prev_dp := U_Current.cur_dp;
U_Previous.prev_rls := U_Current.cur_rls;
U_Previous.prev_sp := U_Current.cur_sp - U_Current.cur_fsz;
if U_get_u_rlo (U_Current'Access, U_Previous'Access) /= -1 then
UWD_Access := UWD_For_RLO_Of (U_Current'Access);
end if;
end;
return UWD_Access;
end UWD_For_Caller_Of;
--------------------
-- UWD_For_RLO_Of --
--------------------
function UWD_For_RLO_Of (Frame : access CFD) return UWD_Ptr
is
UWD_Address : Address;
-- The addresses returned by the library point to full descriptors
-- including the frame information bits but also the applicable PC
-- range. We need to account for this.
Frame_Info_Offset : constant := 8;
begin
-- First try to locate the descriptor in the program's unwind table.
UWD_Address := U_get_unwind_entry (Frame.cur_rlo,
Frame.cur_rls,
Program_UWT.Table_Start,
Program_UWT.Table_End);
-- If we did not get it, we might have a frame from code in a
-- stub or shared library. For code in stub we would have to
-- compute the first non-stub return location but this is not
-- the role of this subprogram, so let's just try to see if we
-- can get a result from the tables in shared libraries.
if UWD_Address = -1
and then U_is_shared_pc (Frame.cur_rlo, Frame.cur_r19) /= 0
then
declare
Shlib_UWT : UWT := U_get_shLib_unwind_table (Frame.cur_r19);
Shlib_Start : Address := U_get_shLib_text_addr (Frame.cur_r19);
Rlo_Offset : Address := Frame.cur_rlo - Shlib_Start;
begin
UWD_Address := U_get_unwind_entry (Rlo_Offset,
Frame.cur_rls,
Shlib_UWT.Table_Start,
Shlib_UWT.Table_End);
end;
end if;
if UWD_Address /= -1 then
return To_UWD_Access (UWD_Address + Frame_Info_Offset);
else
return null;
end if;
end UWD_For_RLO_Of;
-- Start of processing for Call_Chain
begin
-- Fetch the state for this subprogram's frame and pop it so that the
-- backtrace starts at the right point for our caller, that is at its
-- own frame.
U_init_frame_record (Frame'Access);
Frame.top_sr0 := 0;
Frame.top_sr4 := 0;
U_prep_frame_rec_for_unwind (Frame'Access);
Pop_Success := Pop_Frame (Frame'Access);
-- Loop popping frames and storing locations until either a problem
-- occurs, or the top of the call chain is reached, or the provided
-- array is full.
loop
-- We have to test some conditions against the return location
-- as it is returned, so get it as is first.
Code := Frame.out_rlo;
exit when not Pop_Success or else Code = 0 or else J = Max_Len + 1;
-- Compute the call point from the retrieved return location :
-- Mask the privilege bits and account for the delta between the
-- call site and the return point.
Code := (Code and not Priv_Mask) - Rlo_Offset;
if Code < Exclude_Min or else Code > Exclude_Max then
Trace (J) := Code;
J := J + 1;
end if;
Pop_Success := Pop_Frame (Frame'Access);
end loop;
Len := J - 1;
end Call_Chain;
end System.Traceback;
|
oeis/114/A114283.asm | neoneye/loda-programs | 11 | 240968 | ; A114283: Sequence array for binomial transform of Jacobsthal numbers A001045(n+1).
; Submitted by <NAME>
; 1,2,1,6,2,1,18,6,2,1,54,18,6,2,1,162,54,18,6,2,1,486,162,54,18,6,2,1,1458,486,162,54,18,6,2,1,4374,1458,486,162,54,18,6,2,1,13122,4374,1458,486,162,54,18,6,2,1,39366,13122,4374,1458,486,162,54,18,6,2,1,118098,39366,13122,4374,1458,486,162,54,18,6,2,1,354294,118098,39366,13122,4374,1458,486,162,54,18,6,2,1,1062882,354294,118098,39366,13122,4374,1458,486,162
lpb $0
add $1,1
sub $0,$1
lpe
sub $1,$0
mov $0,3
pow $0,$1
mul $0,2
sub $0,2
div $0,3
add $0,1
|
Task/Range-extraction/AppleScript/range-extraction.applescript | LaudateCorpus1/RosettaCodeData | 1 | 343 | -- rangeFormat :: [Int] -> String
on rangeFormat(xs)
script rangeString
on |λ|(xs)
if length of xs > 2 then
(item 1 of xs as string) & "-" & (item -1 of xs as string)
else
intercalate(",", xs)
end if
end |λ|
end script
script nonConsec
on |λ|(a, b)
b - a > 1
end |λ|
end script
intercalate(",", map(rangeString, splitBy(nonConsec, xs)))
end rangeFormat
--TEST ------------------------------------------------------------------------
on run
set xs to {0, 1, 2, 4, 6, 7, 8, 11, 12, 14, 15, 16, ¬
17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, ¬
33, 35, 36, 37, 38, 39}
rangeFormat(xs)
--> "0-2,4,6-8,11,12,14-25,27-33,35-39"
end run
-- GENERIC FUNCTIONS ----------------------------------------------------------
-- splitBy :: (a -> a -> Bool) -> [a] -> [[a]]
on splitBy(f, xs)
set mf to mReturn(f)
if length of xs < 2 then
{xs}
else
script p
on |λ|(a, x)
set {acc, active, prev} to a
if mf's |λ|(prev, x) then
{acc & {active}, {x}, x}
else
{acc, active & x, x}
end if
end |λ|
end script
set h to item 1 of xs
set lstParts to foldl(p, {{}, {h}, h}, items 2 thru -1 of xs)
item 1 of lstParts & {item 2 of lstParts}
end if
end splitBy
-- foldl :: (a -> b -> a) -> a -> [b] -> a
on foldl(f, startValue, xs)
tell mReturn(f)
set v to startValue
set lng to length of xs
repeat with i from 1 to lng
set v to |λ|(v, item i of xs, i, xs)
end repeat
return v
end tell
end foldl
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to |λ|(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn
|
oeis/335/A335840.asm | neoneye/loda-programs | 11 | 8922 | <gh_stars>10-100
; A335840: Expansion of x*(1+2*x)/((1-2*x)*(1-x+4*x^2)).
; Submitted by <NAME>
; 1,5,9,5,1,45,169,245,81,125,1849,5445,6241,845,8649,70805,167281,146205,1369,465125,2556801,4890605,3052009,266805,21613201,87654845,135419769,53235845,48427681,909226125,2862999049,3521061845,659000241,3754622045
mov $1,1
mov $2,1
mov $3,2
lpb $0
sub $0,1
sub $3,$1
mul $3,4
add $3,3
add $1,$3
mul $2,2
add $2,1
sub $1,$2
lpe
mov $0,$1
|
theorems/homotopy/elims/CofPushoutSection.agda | cmknapp/HoTT-Agda | 0 | 3865 | <filename>theorems/homotopy/elims/CofPushoutSection.agda
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.elims.Lemmas
{- Given a span [A ←f– C –g→ B] and a map [h : A ⊔_C B → D] where
- [g] has a left inverse:
- To define a fundction [Π (Cof h) P], one can give only the [cfbase],
- [cfcod], [cfglue∘left], and [cfglue∘right] cases, and construct a map
- which has the right behavior on [cfbase], [cfcod], [cfglue∘left],
- with [cfglue∘right] edited to achieve the highest coherence.
- This is useful for for proving equivalences where (at least) one side
- involves one of these iterated pushouts. It could be generalized
- further by loosening from cofiber to some more general class of pushouts,
- but this is sufficient for the current applications. -}
module homotopy.elims.CofPushoutSection where
module _ {i j k l} {s : Span {i} {j} {k}} {D : Type l}
{h : Pushout s → D} where
open Span s
module CofPushoutSection (r : B → C) (inv : ∀ c → r (g c) == c) where
elim : ∀ {m} {P : Cofiber h → Type m}
(cfbase* : P cfbase) (cfcod* : (d : D) → P (cfcod d))
(cfglue-left* : (a : A) →
cfbase* == cfcod* (h (left a)) [ P ↓ cfglue (left a) ])
(cfglue-right* : (b : B) →
cfbase* == cfcod* (h (right b)) [ P ↓ cfglue (right b) ])
→ Π (Cofiber h) P
elim {P = P} cfbase* cfcod* cfglue-left* cfglue-right* =
Cofiber-elim
cfbase*
cfcod*
(Pushout-elim
cfglue-left*
(λ b → (fst (fill (r b))) ◃ cfglue-right* b)
(λ c → ↓↓-from-squareover $
transport
(λ c' → SquareOver P (natural-square cfglue (glue c))
(cfglue-left* (f c))
(↓-ap-in P (λ _ → cfbase) (apd (λ _ → cfbase*) (glue c)))
(↓-ap-in P (cfcod ∘ h) (apd (cfcod* ∘ h) (glue c)))
(fst (fill c') ◃ cfglue-right* (g c)))
(! (inv c))
(snd (fill c))))
where
fill : (c : C)
→ Σ (cfbase* == cfbase*)
(λ q → SquareOver P (natural-square cfglue (glue c))
(cfglue-left* (f c)) _ _ (q ◃ cfglue-right* (g c)))
fill c = fill-upper-right _ _ _ _ _
rec : ∀ {m} {E : Type m}
(cfbase* : E) (cfcod* : D → E)
(cfglue-left* : (a : A) → cfbase* == cfcod* (h (left a)))
(cfglue-right* : (b : B) → cfbase* == cfcod* (h (right b)))
→ (Cofiber h → E)
rec cfbase* cfcod* cfglue-left* cfglue-right* =
elim cfbase* cfcod* (↓-cst-in ∘ cfglue-left*) (↓-cst-in ∘ cfglue-right*)
|
dino/lcs/base/6B66.asm | zengfr/arcade_game_romhacking_sourcecode_top_secret_data | 6 | 2210 | copyright zengfr site:http://github.com/zengfr/romhack
00042A move.l D1, (A0)+
00042C dbra D0, $42a
004A66 move.w A0, ($6b66,A5)
004A6A moveq #$17, D0 [base+6B66]
004C0A movea.w ($6b66,A5), A4
004C0E move.w A6, -(A4) [base+6B66]
004C10 move.w A4, ($6b66,A5) [base+6B92, base+6B94, base+6B96]
004C14 addq.w #1, ($6b64,A5) [base+6B66]
01063A move.w A0, ($6b66,A5)
01063E move.w D0, ($6ac2,A5) [base+6B66]
011350 movea.w ($6b66,A5), A1
011354 movea.w (A1)+, A3 [base+6B66]
011AE2 movea.w ($6b66,A5), A1
011AE6 movea.w (A1)+, A3 [base+6B66]
011CF4 movea.w ($6b66,A5), A0
011CF8 subq.w #1, D7 [base+6B66]
011E5E movea.w ($6b66,A5), A0
011E62 subq.w #1, D7 [base+6B66]
0AAACA move.l (A0), D2
0AAACC move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, base+6FFE, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAACE move.w D0, ($2,A0)
0AAAD2 cmp.l (A0), D0
0AAAD4 bne $aaafc
0AAAD8 move.l D2, (A0)+
0AAADA cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, base+6FFE, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAAE6 move.l (A0), D2
0AAAE8 move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, base+6FFE, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAAF4 move.l D2, (A0)+
0AAAF6 cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, base+6FFE, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
copyright zengfr site:http://github.com/zengfr/romhack
|
data/github.com/pastorsj/RDTProtocol/af80f197abb9217917eb0d4fad0de1a9cd3fb3cb/Milestone2/RDT20.als | ajnavarro/language-dataset | 9 | 3196 | module Milestone2/RDT20
open util/ordering[State]
one sig ACK, NAK extends Data{}
sig Checksum{}
one sig CorruptChecksum extends Checksum{}
sig Data{}
sig Packet{
data: Data,
checksum : Checksum
}
sig Receiver{
sender: one Sender
}
sig Sender{
receiver: one Receiver
}
sig State{
sent: set Packet,
senders: (Sender -> Data),
receivers: (Receiver -> Data),
buffer: (Sender -> Packet),
lastSent: (Sender -> Data),
replyBuffer: (Receiver -> Packet),
replies: (Sender -> Data)
}
pred SendPacket[s,s':State]{
(one send:Sender |
(s.buffer[send] = none) and
(one p:(Packet - s.sent) |
p in s'.sent and
(one d:(Data - (ACK + NAK)) |
d = p.data and
(let sendPair = (send->p) |
(let sendData = (send -> d) |
((((send->NAK) in s.replies) => (sendData in s.lastSent)) and
(((send->ACK) in s.replies) => (sendData in s.senders)) and
#s.replyBuffer = 0 and
sendData !in s'.senders and
sendPair in s'.buffer and
sendData in s'.lastSent and
#s.buffer = 0 and
s'.senders = s.senders - sendData and
s.receivers = s'.receivers and
s'.lastSent = (s.lastSent) - (send->s.lastSent[send]) + sendData and
s.replies = s'.replies and
s.replyBuffer = s'.replyBuffer and
s.sent = s'.sent - p and
s.buffer = s'.buffer - sendPair))))))
}
pred ReceivePacket[s,s':State]{
(one send:Sender |
(one p:Packet |
(one d:(Data - (ACK + NAK)) |
(one r: Receiver|
d = p.data and
(let sendPair = (send->p) |
(let receiveData = (r -> d) |
((#s.replyBuffer = 0) and (#s'.replyBuffer = 1) and
(p.ErrorCheck[] => (r.(s'.replyBuffer)).data = ACK) and
(!p.ErrorCheck[] => (r.(s'.replyBuffer)).data = NAK) and
(#s'.buffer = 0) and
((s.buffer[send] = p) and
(send.receiver = r) and
s'.buffer = s.buffer - sendPair and
(p.ErrorCheck[] => receiveData in s'.receivers) and
(!p.ErrorCheck[] => receiveData !in s'.receivers) and
receiveData !in s.receivers and
s.lastSent = s'.lastSent and
s'.receivers - receiveData = s.receivers and
s.replies = s'.replies and
s.sent = s'.sent and
s.senders = s'.senders))))))))
}
pred ReceiveReply[s,s':State]{
(one r:Receiver|
(one d:(ACK + NAK)|
(one p:(Packet - s.sent) |
p.data = d and
p in s'.sent and
(one send:Sender|
send = r.sender and
((p.ErrorCheck[] => s'.replies = (s.replies - (send->s.replies[send]))+ (send->d))) and
(!p.ErrorCheck[] => (s'.replies = (s.replies - (send->s.replies[send])) + (send->((ACK + NAK) - d)))) and
s.lastSent = s'.lastSent and
s.receivers = s'.receivers and
s.buffer = s'.buffer and
s.senders = s'.senders and
s.sent = s'.sent - p and
(r->p) in s.replyBuffer and
s'.replyBuffer = s.replyBuffer - (r->p)))))
}
pred Packet.ErrorCheck{
this.checksum != CorruptChecksum
}
pred State.Done[]{
// #this.senders = 0 and #this.buffer = 0 and #this.replyBuffer = 0
all d:(Data - (ACK + NAK)) | d in Receiver.(this.receivers)
}
pred State.Init[]{
#this.receivers = 0 and #this.buffer = 0 and #this.replyBuffer = 0 and #this.lastSent = 0 and this.replies = {Sender->ACK}
and all s:Sender | (s->ACK) !in this.senders and (s->NAK) !in this.senders and this.sent = none
}
pred Transition[s, s':State]{
SendPacket[s, s'] or
ReceivePacket[s, s'] or ReceiveReply[s, s']
}
fact{
receiver = ~sender
}
fact{
// all d:Data | some p:Packet | p.data = d and p.checksum != CorruptChecksum
}
fact{
some p:Packet | p.checksum = CorruptChecksum
}
fact{
(no d:Data | (some r:Receiver | (some r2:Receiver - r | (r->d) in State.receivers and (r2->d) in State.receivers))
or (some s:Sender| (some s2:Sender -s | ((s->d) in State.senders and (s2->d) in State.senders)
or ((s->d) in State.lastSent and (s2->d) in State.lastSent)
or (some p:Packet | p.data = d and ((s->p) in State.buffer and (s2->p) in State.buffer)))))
}
fact{
(all st:State | no d:Data | (d in Sender.(st.senders) and d in Receiver.(st.receivers))
or (d in Sender.(st.senders) and d in (Sender.(st.buffer)).data)
or (d in (Sender.(st.buffer)).data and d in Receiver.(st.receivers)))
}
assert AlwaysWorks{
(first.Init[] and
all s:State - last |
let s' = s.next |
Transition[s, s'] )=> last.Done[]
}
pred Trace[]{
first.Init[] and
all s:State - last |
let s' = s.next |
Transition[s, s'] and last.Done[]
}
pred show{}
check AlwaysWorks for 1 but exactly 10 State, exactly 6 Packet, exactly 3 Data, exactly 2 Checksum
run Trace for 2 but exactly 9 State, exactly 5 Packet, exactly 4 Data
run show for 2 but exactly 5 State
|
google_translation/google_trans_auto.scpt | jojonki/TouchBarAppleScripts | 0 | 3426 | <gh_stars>0
tell application "System Events"
keystroke "c" using command down
delay 0.2
tell application "Google Chrome"
set text_ids to id of (the clipboard)
set is_eng to true
repeat with tid in text_ids
if tid ≥ 256 then
set is_eng to false
end if
end repeat
if is_eng then
open location "https://translate.google.com/#en/ja/" & (the clipboard)
else
open location "https://translate.google.com/#ja/en/" & (the clipboard)
end if
activate
end tell
end tell
|
exampl02/shellex/shellex.asm | AlexRogalskiy/Masm | 0 | 18720 | <gh_stars>0
; #########################################################################
; A simple useful toy, Shellex takes a command line which is a drive
; and directory path. Set it as a shortcut on your desktop with the
; path you require and it will start a window in explorer where you
; specify.
; If you set it with a URL, it will open that as well in your default
; browser so you can have a favourite site parked on your desktop that
; is only a double click away.
; #########################################################################
.386
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\kernel32.inc
include \MASM32\INCLUDE\shell32.inc
include \MASM32\INCLUDE\masm32.inc
includelib \MASM32\LIB\kernel32.lib
includelib \MASM32\LIB\shell32.lib
includelib \MASM32\LIB\masm32.lib
; #########################################################################
.data
open db "open",0
dir db 128 dup (0) ; buffer for command line
.code
start:
invoke GetCL,1,ADDR dir
invoke ShellExecute,0,ADDR open,ADDR dir,NULL,NULL,SW_SHOW
invoke ExitProcess,eax
end start
; #########################################################################
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.