content stringlengths 23 1.05M |
|---|
with Computation_Type;
with Image_Types;
generic
with package CT is new Computation_Type (<>);
with package IT is new Image_Types (<>);
Escape_Threshold : CT.Real;
package Julia_Set is
use CT;
procedure Calculate_Pixel (Re : Real;
Im : Real;
Z_Escape : out Real;
Iter_Escape : out Natural);
end Julia_Set;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Elements.Formal_Access_Types;
with Program.Lexical_Elements;
with Program.Elements.Subtype_Indications;
package Program.Elements.Formal_Object_Access_Types is
pragma Pure (Program.Elements.Formal_Object_Access_Types);
type Formal_Object_Access_Type is
limited interface
and Program.Elements.Formal_Access_Types.Formal_Access_Type;
type Formal_Object_Access_Type_Access is
access all Formal_Object_Access_Type'Class with Storage_Size => 0;
not overriding function Subtype_Indication
(Self : Formal_Object_Access_Type)
return not null Program.Elements.Subtype_Indications
.Subtype_Indication_Access is abstract;
not overriding function Has_Not_Null
(Self : Formal_Object_Access_Type)
return Boolean is abstract;
not overriding function Has_All
(Self : Formal_Object_Access_Type)
return Boolean is abstract;
not overriding function Has_Constant
(Self : Formal_Object_Access_Type)
return Boolean is abstract;
type Formal_Object_Access_Type_Text is limited interface;
type Formal_Object_Access_Type_Text_Access is
access all Formal_Object_Access_Type_Text'Class with Storage_Size => 0;
not overriding function To_Formal_Object_Access_Type_Text
(Self : in out Formal_Object_Access_Type)
return Formal_Object_Access_Type_Text_Access is abstract;
not overriding function Not_Token
(Self : Formal_Object_Access_Type_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Null_Token
(Self : Formal_Object_Access_Type_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Access_Token
(Self : Formal_Object_Access_Type_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function All_Token
(Self : Formal_Object_Access_Type_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Constant_Token
(Self : Formal_Object_Access_Type_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
end Program.Elements.Formal_Object_Access_Types;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010-2011, Vadim Godunko <vgodunko@gmail.com> --
-- 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 League.Strings;
with Matreshka.Internals.Strings;
with Matreshka.Internals.Utf16;
package Matreshka.Internals.XML.Entity_Tables is
pragma Preelaborate;
type Entity_Table is limited private;
procedure New_Internal_Parameter_Entity
(Self : in out Entity_Table;
Enclosing_Entity : Entity_Identifier;
Name : Matreshka.Internals.XML.Symbol_Identifier;
Replacement_Text :
not null Matreshka.Internals.Strings.Shared_String_Access;
Entity : out Entity_Identifier);
-- Allocates space for the entity and returns identifier of the allocated
-- entity.
procedure New_External_Parameter_Entity
(Self : in out Entity_Table;
Enclosing_Entity : Entity_Identifier;
Name : Matreshka.Internals.XML.Symbol_Identifier;
Public_Id : League.Strings.Universal_String;
System_Id : League.Strings.Universal_String;
Enclosing_Base_URI : League.Strings.Universal_String;
Entity : out Entity_Identifier);
-- Allocates space for the entity and returns identifier of the allocated
-- entity.
procedure New_Internal_General_Entity
(Self : in out Entity_Table;
Enclosing_Entity : Entity_Identifier;
Name : Matreshka.Internals.XML.Symbol_Identifier;
Replacement_Text :
not null Matreshka.Internals.Strings.Shared_String_Access;
Entity : out Entity_Identifier);
-- Allocates space for the entity and returns identifier of the allocated
-- entity.
procedure New_External_Parsed_General_Entity
(Self : in out Entity_Table;
Enclosing_Entity : Entity_Identifier;
Name : Matreshka.Internals.XML.Symbol_Identifier;
Public_Id : League.Strings.Universal_String;
System_Id : League.Strings.Universal_String;
Enclosing_Base_URI : League.Strings.Universal_String;
Entity : out Entity_Identifier);
-- Allocates space for the entity and returns identifier of the allocated
-- entity.
procedure New_External_Unparsed_General_Entity
(Self : in out Entity_Table;
Enclosing_Entity : Entity_Identifier;
Name : Matreshka.Internals.XML.Symbol_Identifier;
Notation : Symbol_Identifier;
Entity : out Entity_Identifier);
-- Allocates space for the entity and returns identifier of the allocated
-- entity.
procedure New_Document_Entity
(Self : in out Entity_Table;
Public_Id : League.Strings.Universal_String;
System_Id : League.Strings.Universal_String;
Entity_Base_URI : League.Strings.Universal_String;
Entity : out Entity_Identifier);
-- Allocates space for the entity and returns identifier of the allocated
-- entity.
procedure New_External_Subset_Entity
(Self : in out Entity_Table;
Enclosing_Entity : Entity_Identifier;
Public_Id : League.Strings.Universal_String;
System_Id : League.Strings.Universal_String;
Enclosing_Base_URI : League.Strings.Universal_String;
Entity : out Entity_Identifier);
-- Allocates space for the entity and returns identifier of the allocated
-- entity.
function Is_Document_Entity
(Self : Entity_Table;
Entity : Entity_Identifier) return Boolean;
-- Returns True when entity is document entity.
function Is_External_Subset
(Self : Entity_Table;
Entity : Entity_Identifier) return Boolean;
-- Returns True when entity is enternal subset of the DTD.
function Is_Internal_General_Entity
(Self : Entity_Table;
Entity : Entity_Identifier) return Boolean;
-- Returns True when entity is internal general entity.
function Is_External_Parsed_General_Entity
(Self : Entity_Table;
Entity : Entity_Identifier) return Boolean;
-- Returns True when entity is external parsed general entity.
function Is_External_Unparsed_General_Entity
(Self : Entity_Table;
Entity : Entity_Identifier) return Boolean;
-- Returns True when entity is external unparsed general entity.
function Is_Parameter_Entity
(Self : Entity_Table;
Entity : Entity_Identifier) return Boolean;
-- Returns True when entity is parameter entity (internal or external).
function Is_Parsed_General_Entity
(Self : Entity_Table;
Entity : Entity_Identifier) return Boolean;
-- Returns True when entity is parsed general entity (internal or
-- external).
function Name
(Self : Entity_Table;
Entity : Entity_Identifier)
return Matreshka.Internals.XML.Symbol_Identifier;
function Enclosing_Entity
(Self : Entity_Table;
Entity : Entity_Identifier)
return Matreshka.Internals.XML.Entity_Identifier;
-- Returns entity which contains declaration of the entity.
function Public_Id
(Self : Entity_Table;
Entity : Entity_Identifier)
return not null Matreshka.Internals.Strings.Shared_String_Access;
function System_Id
(Self : Entity_Table;
Entity : Entity_Identifier)
return not null Matreshka.Internals.Strings.Shared_String_Access;
function Notation
(Self : Entity_Table;
Entity : Entity_Identifier)
return Matreshka.Internals.XML.Symbol_Identifier;
-- Returns identifier of notation of the entity for unparsed entity and
-- No_Symbol for others.
function Enclosing_Base_URI
(Self : Entity_Table;
Entity : Entity_Identifier)
return not null Matreshka.Internals.Strings.Shared_String_Access;
-- Returns base URI of entity's declaration element to be used to resolve
-- relative entity's system identifier.
function Entity_Base_URI
(Self : Entity_Table;
Entity : Entity_Identifier)
return not null Matreshka.Internals.Strings.Shared_String_Access;
-- Returns base URI of the entity.
procedure Set_Entity_Base_URI
(Self : in out Entity_Table;
Entity : Entity_Identifier;
Entity_Base_URI : League.Strings.Universal_String);
-- Sets base URI of the entity.
function Is_Resolved
(Self : Entity_Table;
Entity : Entity_Identifier) return Boolean;
-- Returns True when entity is marked as resolved.
procedure Set_Is_Resolved
(Self : in out Entity_Table;
Entity : Entity_Identifier;
To : Boolean);
-- Mark entity as resolved.
function Replacement_Text
(Self : Entity_Table;
Entity : Entity_Identifier)
return Matreshka.Internals.Strings.Shared_String_Access;
-- Returns entity's replacement text.
procedure Set_Replacement_Text
(Self : in out Entity_Table;
Entity : Entity_Identifier;
Replacement_Text :
not null Matreshka.Internals.Strings.Shared_String_Access);
-- Sets replacement text for the entity.
function First_Position
(Self : Entity_Table;
Entity : Entity_Identifier)
return Matreshka.Internals.Utf16.Utf16_String_Index;
-- Returns position of the first significant character after the text
-- declaration if any; otherwise returns zero.
procedure Set_First_Position
(Self : in out Entity_Table;
Entity : Entity_Identifier;
Position : Matreshka.Internals.Utf16.Utf16_String_Index);
-- Sets position of the first significant character after the text
-- declaration if any.
procedure Initialize (Self : in out Entity_Table);
-- Initializes entity table.
procedure Finalize (Self : in out Entity_Table);
-- Finalizes entity table.
procedure Reset (Self : in out Entity_Table);
-- Resets internal structures to initial state.
function First_Entity (Self : Entity_Table) return Entity_Identifier;
-- Returns first entity.
procedure Next_Entity
(Self : Entity_Table;
Entity : in out Entity_Identifier);
-- Sets Entity to next entity identifier or to No_Entity.
private
type Entity_Kinds is
(Document_Entity,
External_Subset_Entity,
Internal_Parameter_Entity,
External_Parameter_Entity,
Internal_General_Entity,
External_Parsed_General_Entity,
External_Unparsed_General_Entity);
type Entity_Record is record
Kind : Entity_Kinds;
Enclosing : Entity_Identifier;
Name : Symbol_Identifier;
Notation : Symbol_Identifier;
Public_Id : Matreshka.Internals.Strings.Shared_String_Access;
System_Id : Matreshka.Internals.Strings.Shared_String_Access;
Enclosing_Base_URI : Matreshka.Internals.Strings.Shared_String_Access;
Entity_Base_URI : Matreshka.Internals.Strings.Shared_String_Access;
Is_Resolved : Boolean;
Replacement_Text : Matreshka.Internals.Strings.Shared_String_Access;
First_Position : Matreshka.Internals.Utf16.Utf16_String_Index;
end record;
type Entity_Array is array (Entity_Identifier range <>) of Entity_Record;
type Entity_Array_Access is access all Entity_Array;
type Entity_Table is limited record
Data : Entity_Array_Access;
Last : Entity_Identifier := 0;
end record;
pragma Inline (First_Entity);
pragma Inline (Is_Document_Entity);
pragma Inline (Is_External_Subset);
pragma Inline (Is_Parameter_Entity);
pragma Inline (Is_Internal_General_Entity);
pragma Inline (Is_External_Parsed_General_Entity);
pragma Inline (Is_External_Unparsed_General_Entity);
pragma Inline (Next_Entity);
end Matreshka.Internals.XML.Entity_Tables;
|
with Ada.Text_IO;
procedure Harshad is
function Next(N: in out Positive) return Positive is
function Sum_Of_Digits(N: Natural) return Natural is
( if N = 0 then 0 else ((N mod 10) + Sum_Of_Digits(N / 10)) );
begin
while not (N mod Sum_Of_Digits(N) = 0) loop
N := N + 1;
end loop;
return N;
end Next;
Current: Positive := 1;
begin
for I in 1 .. 20 loop
Ada.Text_IO.Put(Integer'Image(Next(Current)));
Current := Current + 1;
end loop;
Current := 1000 + 1;
Ada.Text_IO.Put_Line(" ..." & Integer'Image(Next(Current)));
end Harshad;
|
pragma SPARK_Mode (On);
with Stack;
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
package Int_Stack is new Stack (Thing => Integer, Basic => 0);
S : Int_Stack.Stack (10);
T : Integer;
begin
Int_Stack.Put (S, -1);
Int_Stack.Put (S, -2);
Int_Stack.Put (S, -3);
Int_Stack.Put (S, -4);
Int_Stack.Put (S, -5);
pragma Assert (Int_Stack.Pushes (S) = 5); -- Prover can track amounts.
pragma Assert (Int_Stack.Buffer (S) (5) = -5); -- Prover can track content.
pragma Assert (Int_Stack.Top (S) = -5); -- Prover can track content.
T := Int_Stack.Top (S);
Int_Stack.Pop (S);
-- Ensure tracking functions even after a pop operation.
pragma Assert (Int_Stack.Pushes (S) = 4); -- Prover can track amounts.
pragma Assert (Int_Stack.Buffer (S) (4) = -4); -- Prover can track content.
pragma Assert (Int_Stack.Top (S) = -4); -- Prover can track content.
Put_Line (Integer'Image ( T ));
Put_Line (Integer'Image (Integer (Int_Stack.Top (S)))); Int_Stack.Pop (S);
Put_Line (Integer'Image (Integer (Int_Stack.Top (S)))); Int_Stack.Pop (S);
Put_Line (Integer'Image (Integer (Int_Stack.Top (S)))); Int_Stack.Pop (S);
Put_Line (Integer'Image (Integer (Int_Stack.Top (S)))); Int_Stack.Pop (S);
end Test;
|
--------------------------------------------------------------------------------
-- Fichier : input.ads
-- Auteur : MOUDDENE Hamza & CAZES Noa
-- Objectif : Spécification du module Input
-- Crée : Dimanche Déc 01 2019
--------------------------------------------------------------------------------
with Registre; use Registre;
package Input is
-- lire au clavier un entier quelconque.
--
-- Param Value : Value est l'entier lu au clavier.
--
-- Exception : DATA_ERROR_EXCEPTION.
procedure Input_Integer (Value : out Integer);
-- Entrer le choix du menu.
--
-- Param Choice : Choice est le choix d'une option dans le menu.
procedure Input_Choice (Choice : out Integer);
-- Entrer le sexe d'un individu.
function Input_Sex return Character;
-- Entrer les données personnelles d'une personne.
--
-- Return T_Donnee : T_Donnee est le type qui contient les données personnelles d'une personne.
function Demander_Donnee return T_Donnee;
-- Entrer l'ID d'un individu.
--
-- Param ID : ID lu au clavier.
-- Param Message : Message associé à chaque opération de saisie.
procedure Input_ID (ID : out Integer; Message : in String);
-- 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.
--
-- Param Flag : Flag 0 si c'est le père, 1 si c'est la mère.
procedure Input_Flag (Flag : out Integer);
-- Entrez la géneration des ancetres.
--
-- Param Generation : La génération des ancestres.
procedure Input_Generation (Generation : out Integer);
end Input;
|
pragma Ada_2012;
with Ada.Unchecked_Conversion;
package body Utilities is
----------------
-- Read_Chunk --
----------------
function Read_Chunk (From : Streams.Stream_IO.File_Type) return Chunk_Type
is
use Streams;
subtype Buffer_Type is
Stream_Element_Array (1 .. Chunk_Type'Size / Stream_Element'Size);
function Convert is
new Unchecked_Conversion (Source => Buffer_Type,
Target => Chunk_Type);
Buffer : Buffer_Type;
Last : Stream_Element_Count;
begin
Stream_IO.Read (File => From,
Item => Buffer,
Last => Last);
if Last /= Buffer'Last then
raise Stream_IO.End_Error;
end if;
return Convert (Buffer);
end Read_Chunk;
-----------------
-- Write_Chunk --
-----------------
procedure Write_Chunk (To : Streams.Stream_IO.File_Type;
Item : Chunk_Type)
is
use Streams;
subtype Buffer_Type is
Stream_Element_Array (1 .. Chunk_Type'Size / Stream_Element'Size);
function Convert is
new Unchecked_Conversion (Source => Chunk_Type,
Target => Buffer_Type);
Buffer : constant Buffer_Type := Convert (Item);
begin
Stream_IO.Write (File => To,
Item => Buffer);
end Write_Chunk;
end Utilities;
|
package Utilities is
generic
Width: Positive;
function LeftPad (Str : String; Level : Natural) return String;
end Utilities; |
with Other_Basic_Subprogram_Calls;
package Tagged_Subprogram_Calls is
package Inner is
type E is (A, B, C);
procedure P(A : E);
end Inner;
procedure Test(Param : Inner.E);
type T is tagged
null record;
procedure T_P(S : T);
procedure T_Q(J : Integer; S : T);
procedure T_R(S : T; J : Integer);
function T_F(S : T) return T'Class;
function T_G(S : T) return T;
function "+"(S : T) return Boolean;
type T1 is new T with
record
I : Integer;
end record;
overriding procedure T_P(S : T1);
overriding procedure T_Q(J : Integer; S : T1);
procedure T_R(S : T1; J : Integer);
overriding function T_F(S : T1) return T'Class;
function T_G(S : T1) return T1;
function "+"(S : T1) return Boolean;
type T2 is new T1 with
null record;
procedure T_P(S : T2);
procedure Test2;
type S is abstract tagged
null record;
procedure S_P(A : S) is abstract;
type I is interface;
procedure S_I(A : I) is abstract;
type I1 is new I with
null record;
procedure S_I(A : I1);
type S1 is new S and I with
null record;
procedure S_P(A : S1);
procedure S_I(A : S1);
type S2 is new S1 with
null record;
procedure S_P(A : S2);
procedure S_I(A : S2);
procedure Test3;
generic
type TP is abstract tagged private;
with procedure PP(I : TP) is abstract;
procedure GP1(I : TP'Class);
generic
type TP is abstract tagged private;
with procedure PP(I : TP) is abstract;
procedure GP2(I : TP'Class);
type J is limited interface;
task TI is
new J with
entry E;
end TI;
type K is limited interface;
task type TIT is
new K with
entry E;
end TIT;
type L is limited interface;
protected PI is
new L with
entry E;
end PI;
type M is limited interface;
protected type PIT is
new M with
entry E;
end PIT;
private
function T_F(S : T) return T'Class is
(S);
function T_G(S : T) return T is
(S);
function "+"(S : T) return Boolean is
(True);
function T_F(S : T1) return T'Class is
(S);
function T_G(S : T1) return T1 is
(S);
function "+"(S : T1) return Boolean is
(False);
end Tagged_Subprogram_Calls;
|
-- { dg-do compile }
-- { dg-skip-if "missing alias support" { *-*-darwin* hppa*-*-hpux* } }
package Linker_Alias is
Var : Integer; -- { dg-error "aliased to undefined symbol" }
pragma Export (C, Var, "my_var");
pragma Linker_Alias (Var, "var2");
end Linker_Alias;
|
--An example of inline assember. Originally written as a
--test for code-segment, the Ada95 standard way to do
--assembler, but apparently no one has ever used that in
--the history of the world.
with Interfaces; use Interfaces;
with System.Machine_Code; use System.Machine_Code;
with Ada.Text_IO; use Ada.Text_IO;
procedure Asm_Machine_Code is
function Incr (Value : Unsigned_32) return Unsigned_32 is
Result : Unsigned_32;
begin
Asm("incl %0",
Inputs => Unsigned_32'Asm_Input ("a", Value),
Outputs => Unsigned_32'Asm_Output ("=a", Result));
return Result;
end Incr;
Value : Unsigned_32;
begin
Value := 5;
Put_Line("Value before is " & Value'Image);
Value := Incr(Value);
Put_Line("Value after is " & Value'Image);
end Asm_Machine_Code;
|
-----------------------------------------------------------------------
-- Faces Context Tests - Unit tests for ASF.Contexts.Faces
-- Copyright (C) 2010, 2011, 2012, 2013, 2015 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- 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.Tests;
with ASF.Tests;
with ASF.Applications.Tests;
with ASF.Helpers.Beans;
package ASF.Contexts.Faces.Tests is
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);
function Get_Form_Bean is
new ASF.Helpers.Beans.Get_Bean (ASF.Applications.Tests.Form_Bean,
ASF.Applications.Tests.Form_Bean_Access);
type Test is new ASF.Tests.EL_Test with record
-- The ELContext, Variables, Resolver, Form area controlled object.
-- Due to AUnit implementation, we cannot store a controlled object in the Test object.
-- This is due to the 'for Obj'Address use Ret;' clause used by AUnit to allocate
-- a test object.
-- The application object is allocated dyanmically by Set_Up.
Form : ASF.Applications.Tests.Form_Bean_Access;
end record;
-- Cleanup the test instance.
overriding
procedure Tear_Down (T : in out Test);
-- Setup the faces context for the unit test.
procedure Setup (T : in out Test;
Context : in out Faces_Context);
-- Test getting an attribute from the faces context.
procedure Test_Get_Attribute (T : in out Test);
-- Test getting a bean object from the faces context.
procedure Test_Get_Bean (T : in out Test);
-- Test getting a bean object from the faces context and doing a conversion.
procedure Test_Get_Bean_Helper (T : in out Test);
-- Test the faces message queue.
procedure Test_Add_Message (T : in out Test);
procedure Test_Max_Severity (T : in out Test);
procedure Test_Get_Messages (T : in out Test);
-- Test the application message factory for the creation of localized messages.
procedure Test_Add_Localized_Message (T : in out Test);
-- Test adding some exception in the faces context.
procedure Test_Queue_Exception (T : in out Test);
-- Test the flash instance.
procedure Test_Flash_Context (T : in out Test);
-- Test the mockup faces context.
procedure Test_Mockup_Faces_Context (T : in out Test);
end ASF.Contexts.Faces.Tests;
|
with Ada.Containers.Functional_Vectors;
with TLSF.Proof.Util.Vectors;
package body TLSF.Proof.Test.Util with SPARK_Mode is
procedure Test_Util is
subtype Index_Type is Positive;
subtype Element_Type is Natural;
package V is new Ada.Containers.Functional_Vectors
(Index_Type, Element_Type);
package U is new TLSF.Proof.Util.Vectors(Element_Type, V);
use type V.Sequence;
T : V.Sequence;
begin
T := V.Add(T, 2);
pragma Assert(U.Find(T, 2) > 0);
pragma Assert(U.Find_Second(T, 2) = 0);
T := V.Add(T,2);
pragma Assert(U.Find(T, 2) > 0);
pragma Assert(U.Find_Second(T, 2) > 0);
T := V.Add(T, 3);
pragma Assert(U.Find_Second(T, 2) /= 0);
pragma Assert (U.At_Least_One(T,3));
pragma Assert (U.At_Most_One(T,3));
pragma Assert (U.At_Least_One(T,2));
pragma Assert (U.Find_Second(T, 2) /= 0);
pragma Assert (not U.At_Most_One(T,2));
pragma Assert (U.Exactly_One(T, 3));
pragma Assert (not U.Exactly_One(T, 2));
pragma Assert (U.At_Most_One(T, 4));
end Test_Util;
end TLSF.Proof.Test.Util;
|
package body Size_Attribute1_Pkg1 is
type Rec is
record
F : T;
end record;
procedure Dummy is
begin
null;
end;
end Size_Attribute1_Pkg1;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Adventofcode.Day_15.Main is
begin
Put_Line ("Day-15");
end Adventofcode.Day_15.Main;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . F O R M A T T E D _ S T R I N G --
-- --
-- B o d y --
-- --
-- Copyright (C) 2014-2016, 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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling;
with Ada.Float_Text_IO;
with Ada.Integer_Text_IO;
with Ada.Long_Float_Text_IO;
with Ada.Long_Integer_Text_IO;
with Ada.Strings.Fixed;
with Ada.Unchecked_Deallocation;
with System.Address_Image;
package body GNAT.Formatted_String is
type F_Kind is (Decimal_Int, -- %d %i
Unsigned_Decimal_Int, -- %u
Unsigned_Octal, -- %o
Unsigned_Hexadecimal_Int, -- %x
Unsigned_Hexadecimal_Int_Up, -- %X
Decimal_Float, -- %f %F
Decimal_Scientific_Float, -- %e
Decimal_Scientific_Float_Up, -- %E
Shortest_Decimal_Float, -- %g
Shortest_Decimal_Float_Up, -- %G
Char, -- %c
Str, -- %s
Pointer -- %p
);
type Sign_Kind is (Neg, Zero, Pos);
subtype Is_Number is F_Kind range Decimal_Int .. Decimal_Float;
type F_Sign is (If_Neg, Forced, Space) with Default_Value => If_Neg;
type F_Base is (None, C_Style, Ada_Style) with Default_Value => None;
Unset : constant Integer := -1;
type F_Data is record
Kind : F_Kind;
Width : Natural := 0;
Precision : Integer := Unset;
Left_Justify : Boolean := False;
Sign : F_Sign;
Base : F_Base;
Zero_Pad : Boolean := False;
Value_Needed : Natural range 0 .. 2 := 0;
end record;
procedure Next_Format
(Format : Formatted_String;
F_Spec : out F_Data;
Start : out Positive);
-- Parse the next format specifier, a format specifier has the following
-- syntax: %[flags][width][.precision][length]specifier
function Get_Formatted
(F_Spec : F_Data;
Value : String;
Len : Positive) return String;
-- Returns Value formatted given the information in F_Spec
procedure Raise_Wrong_Format (Format : Formatted_String) with No_Return;
-- Raise the Format_Error exception which information about the context
generic
type Flt is private;
with procedure Put
(To : out String;
Item : Flt;
Aft : Text_IO.Field;
Exp : Text_IO.Field);
function P_Flt_Format
(Format : Formatted_String;
Var : Flt) return Formatted_String;
-- Generic routine which handles all floating point numbers
generic
type Int is private;
with function To_Integer (Item : Int) return Integer;
with function Sign (Item : Int) return Sign_Kind;
with procedure Put
(To : out String;
Item : Int;
Base : Text_IO.Number_Base);
function P_Int_Format
(Format : Formatted_String;
Var : Int) return Formatted_String;
-- Generic routine which handles all the integer numbers
---------
-- "+" --
---------
function "+" (Format : String) return Formatted_String is
begin
return Formatted_String'
(Finalization.Controlled with
D => new Data'(Format'Length, 1, Format, 1,
Null_Unbounded_String, 0, 0, (0, 0)));
end "+";
---------
-- "-" --
---------
function "-" (Format : Formatted_String) return String is
F : String renames Format.D.Format;
J : Natural renames Format.D.Index;
R : Unbounded_String := Format.D.Result;
begin
-- Make sure we get the remaining character up to the next unhandled
-- format specifier.
while (J <= F'Length and then F (J) /= '%')
or else (J < F'Length - 1 and then F (J + 1) = '%')
loop
Append (R, F (J));
-- If we have two consecutive %, skip the second one
if F (J) = '%' and then J < F'Length - 1 and then F (J + 1) = '%' then
J := J + 1;
end if;
J := J + 1;
end loop;
return To_String (R);
end "-";
---------
-- "&" --
---------
function "&"
(Format : Formatted_String;
Var : Character) return Formatted_String
is
F : F_Data;
Start : Positive;
begin
Next_Format (Format, F, Start);
if F.Value_Needed > 0 then
Raise_Wrong_Format (Format);
end if;
case F.Kind is
when Char =>
Append (Format.D.Result, Get_Formatted (F, String'(1 => Var), 1));
when others =>
Raise_Wrong_Format (Format);
end case;
return Format;
end "&";
function "&"
(Format : Formatted_String;
Var : String) return Formatted_String
is
F : F_Data;
Start : Positive;
begin
Next_Format (Format, F, Start);
if F.Value_Needed > 0 then
Raise_Wrong_Format (Format);
end if;
case F.Kind is
when Str =>
declare
S : constant String := Get_Formatted (F, Var, Var'Length);
begin
if F.Precision = Unset then
Append (Format.D.Result, S);
else
Append
(Format.D.Result,
S (S'First .. S'First + F.Precision - 1));
end if;
end;
when others =>
Raise_Wrong_Format (Format);
end case;
return Format;
end "&";
function "&"
(Format : Formatted_String;
Var : Boolean) return Formatted_String is
begin
return Format & Boolean'Image (Var);
end "&";
function "&"
(Format : Formatted_String;
Var : Float) return Formatted_String
is
function Float_Format is new Flt_Format (Float, Float_Text_IO.Put);
begin
return Float_Format (Format, Var);
end "&";
function "&"
(Format : Formatted_String;
Var : Long_Float) return Formatted_String
is
function Float_Format is
new Flt_Format (Long_Float, Long_Float_Text_IO.Put);
begin
return Float_Format (Format, Var);
end "&";
function "&"
(Format : Formatted_String;
Var : Duration) return Formatted_String
is
package Duration_Text_IO is new Text_IO.Fixed_IO (Duration);
function Duration_Format is
new P_Flt_Format (Duration, Duration_Text_IO.Put);
begin
return Duration_Format (Format, Var);
end "&";
function "&"
(Format : Formatted_String;
Var : Integer) return Formatted_String
is
function Integer_Format is
new Int_Format (Integer, Integer_Text_IO.Put);
begin
return Integer_Format (Format, Var);
end "&";
function "&"
(Format : Formatted_String;
Var : Long_Integer) return Formatted_String
is
function Integer_Format is
new Int_Format (Long_Integer, Long_Integer_Text_IO.Put);
begin
return Integer_Format (Format, Var);
end "&";
function "&"
(Format : Formatted_String;
Var : System.Address) return Formatted_String
is
A_Img : constant String := System.Address_Image (Var);
F : F_Data;
Start : Positive;
begin
Next_Format (Format, F, Start);
if F.Value_Needed > 0 then
Raise_Wrong_Format (Format);
end if;
case F.Kind is
when Pointer =>
Append (Format.D.Result, Get_Formatted (F, A_Img, A_Img'Length));
when others =>
Raise_Wrong_Format (Format);
end case;
return Format;
end "&";
------------
-- Adjust --
------------
overriding procedure Adjust (F : in out Formatted_String) is
begin
F.D.Ref_Count := F.D.Ref_Count + 1;
end Adjust;
--------------------
-- Decimal_Format --
--------------------
function Decimal_Format
(Format : Formatted_String;
Var : Flt) return Formatted_String
is
function Flt_Format is new P_Flt_Format (Flt, Put);
begin
return Flt_Format (Format, Var);
end Decimal_Format;
-----------------
-- Enum_Format --
-----------------
function Enum_Format
(Format : Formatted_String;
Var : Enum) return Formatted_String is
begin
return Format & Enum'Image (Var);
end Enum_Format;
--------------
-- Finalize --
--------------
overriding procedure Finalize (F : in out Formatted_String) is
procedure Unchecked_Free is
new Unchecked_Deallocation (Data, Data_Access);
D : Data_Access := F.D;
begin
F.D := null;
D.Ref_Count := D.Ref_Count - 1;
if D.Ref_Count = 0 then
Unchecked_Free (D);
end if;
end Finalize;
------------------
-- Fixed_Format --
------------------
function Fixed_Format
(Format : Formatted_String;
Var : Flt) return Formatted_String
is
function Flt_Format is new P_Flt_Format (Flt, Put);
begin
return Flt_Format (Format, Var);
end Fixed_Format;
----------------
-- Flt_Format --
----------------
function Flt_Format
(Format : Formatted_String;
Var : Flt) return Formatted_String
is
function Flt_Format is new P_Flt_Format (Flt, Put);
begin
return Flt_Format (Format, Var);
end Flt_Format;
-------------------
-- Get_Formatted --
-------------------
function Get_Formatted
(F_Spec : F_Data;
Value : String;
Len : Positive) return String
is
use Ada.Strings.Fixed;
Res : Unbounded_String;
S : Positive := Value'First;
begin
-- Handle the flags
if F_Spec.Kind in Is_Number then
if F_Spec.Sign = Forced and then Value (Value'First) /= '-' then
Append (Res, "+");
elsif F_Spec.Sign = Space and then Value (Value'First) /= '-' then
Append (Res, " ");
end if;
if Value (Value'First) = '-' then
Append (Res, "-");
S := S + 1;
end if;
end if;
-- Zero padding if required and possible
if F_Spec.Left_Justify = False
and then F_Spec.Zero_Pad
and then F_Spec.Width > Len + Value'First - S
then
Append (Res, String'((F_Spec.Width - Len + Value'First - S) * '0'));
end if;
-- Add the value now
Append (Res, Value (S .. Value'Last));
declare
R : String (1 .. Natural'Max (Natural'Max (F_Spec.Width, Len),
Length (Res))) := (others => ' ');
begin
if F_Spec.Left_Justify then
R (1 .. Length (Res)) := To_String (Res);
else
R (R'Last - Length (Res) + 1 .. R'Last) := To_String (Res);
end if;
return R;
end;
end Get_Formatted;
----------------
-- Int_Format --
----------------
function Int_Format
(Format : Formatted_String;
Var : Int) return Formatted_String
is
function Sign (Var : Int) return Sign_Kind is
(if Var < 0 then Neg elsif Var = 0 then Zero else Pos);
function To_Integer (Var : Int) return Integer is
(Integer (Var));
function Int_Format is new P_Int_Format (Int, To_Integer, Sign, Put);
begin
return Int_Format (Format, Var);
end Int_Format;
----------------
-- Mod_Format --
----------------
function Mod_Format
(Format : Formatted_String;
Var : Int) return Formatted_String
is
function Sign (Var : Int) return Sign_Kind is
(if Var < 0 then Neg elsif Var = 0 then Zero else Pos);
function To_Integer (Var : Int) return Integer is
(Integer (Var));
function Int_Format is new P_Int_Format (Int, To_Integer, Sign, Put);
begin
return Int_Format (Format, Var);
end Mod_Format;
-----------------
-- Next_Format --
-----------------
procedure Next_Format
(Format : Formatted_String;
F_Spec : out F_Data;
Start : out Positive)
is
F : String renames Format.D.Format;
J : Natural renames Format.D.Index;
S : Natural;
Width_From_Var : Boolean := False;
begin
Format.D.Current := Format.D.Current + 1;
F_Spec.Value_Needed := 0;
-- Got to next %
while (J <= F'Last and then F (J) /= '%')
or else (J < F'Last - 1 and then F (J + 1) = '%')
loop
Append (Format.D.Result, F (J));
-- If we have two consecutive %, skip the second one
if F (J) = '%' and then J < F'Last - 1 and then F (J + 1) = '%' then
J := J + 1;
end if;
J := J + 1;
end loop;
if F (J) /= '%' or else J = F'Last then
raise Format_Error with "no format specifier found for parameter"
& Positive'Image (Format.D.Current);
end if;
Start := J;
J := J + 1;
-- Check for any flags
Flags_Check : while J < F'Last loop
if F (J) = '-' then
F_Spec.Left_Justify := True;
elsif F (J) = '+' then
F_Spec.Sign := Forced;
elsif F (J) = ' ' then
F_Spec.Sign := Space;
elsif F (J) = '#' then
F_Spec.Base := C_Style;
elsif F (J) = '~' then
F_Spec.Base := Ada_Style;
elsif F (J) = '0' then
F_Spec.Zero_Pad := True;
else
exit Flags_Check;
end if;
J := J + 1;
end loop Flags_Check;
-- Check width if any
if F (J) in '0' .. '9' then
-- We have a width parameter
S := J;
while J < F'Last and then F (J + 1) in '0' .. '9' loop
J := J + 1;
end loop;
F_Spec.Width := Natural'Value (F (S .. J));
J := J + 1;
elsif F (J) = '*' then
-- The width will be taken from the integer parameter
F_Spec.Value_Needed := 1;
Width_From_Var := True;
J := J + 1;
end if;
if F (J) = '.' then
-- We have a precision parameter
J := J + 1;
if F (J) in '0' .. '9' then
S := J;
while J < F'Length and then F (J + 1) in '0' .. '9' loop
J := J + 1;
end loop;
if F (J) = '.' then
-- No precision, 0 is assumed
F_Spec.Precision := 0;
else
F_Spec.Precision := Natural'Value (F (S .. J));
end if;
J := J + 1;
elsif F (J) = '*' then
-- The prevision will be taken from the integer parameter
F_Spec.Value_Needed := F_Spec.Value_Needed + 1;
J := J + 1;
end if;
end if;
-- Skip the length specifier, this is not needed for this implementation
-- but yet for compatibility reason it is handled.
Length_Check :
while J <= F'Last
and then F (J) in 'h' | 'l' | 'j' | 'z' | 't' | 'L'
loop
J := J + 1;
end loop Length_Check;
if J > F'Last then
Raise_Wrong_Format (Format);
end if;
-- Read next character which should be the expected type
case F (J) is
when 'c' => F_Spec.Kind := Char;
when 's' => F_Spec.Kind := Str;
when 'd' | 'i' => F_Spec.Kind := Decimal_Int;
when 'u' => F_Spec.Kind := Unsigned_Decimal_Int;
when 'f' | 'F' => F_Spec.Kind := Decimal_Float;
when 'e' => F_Spec.Kind := Decimal_Scientific_Float;
when 'E' => F_Spec.Kind := Decimal_Scientific_Float_Up;
when 'g' => F_Spec.Kind := Shortest_Decimal_Float;
when 'G' => F_Spec.Kind := Shortest_Decimal_Float_Up;
when 'o' => F_Spec.Kind := Unsigned_Octal;
when 'x' => F_Spec.Kind := Unsigned_Hexadecimal_Int;
when 'X' => F_Spec.Kind := Unsigned_Hexadecimal_Int_Up;
when others =>
raise Format_Error with "unknown format specified for parameter"
& Positive'Image (Format.D.Current);
end case;
J := J + 1;
if F_Spec.Value_Needed > 0
and then F_Spec.Value_Needed = Format.D.Stored_Value
then
if F_Spec.Value_Needed = 1 then
if Width_From_Var then
F_Spec.Width := Format.D.Stack (1);
else
F_Spec.Precision := Format.D.Stack (1);
end if;
else
F_Spec.Width := Format.D.Stack (1);
F_Spec.Precision := Format.D.Stack (2);
end if;
end if;
end Next_Format;
------------------
-- P_Flt_Format --
------------------
function P_Flt_Format
(Format : Formatted_String;
Var : Flt) return Formatted_String
is
F : F_Data;
Buffer : String (1 .. 50);
S, E : Positive := 1;
Start : Positive;
Aft : Text_IO.Field;
begin
Next_Format (Format, F, Start);
if F.Value_Needed > 0 then
Raise_Wrong_Format (Format);
end if;
if F.Precision = Unset then
Aft := 6;
else
Aft := F.Precision;
end if;
case F.Kind is
when Decimal_Float =>
Put (Buffer, Var, Aft, Exp => 0);
S := Strings.Fixed.Index_Non_Blank (Buffer);
E := Buffer'Last;
when Decimal_Scientific_Float
| Decimal_Scientific_Float_Up
=>
Put (Buffer, Var, Aft, Exp => 3);
S := Strings.Fixed.Index_Non_Blank (Buffer);
E := Buffer'Last;
if F.Kind = Decimal_Scientific_Float then
Buffer (S .. E) :=
Characters.Handling.To_Lower (Buffer (S .. E));
end if;
when Shortest_Decimal_Float
| Shortest_Decimal_Float_Up
=>
-- Without exponent
Put (Buffer, Var, Aft, Exp => 0);
S := Strings.Fixed.Index_Non_Blank (Buffer);
E := Buffer'Last;
-- Check with exponent
declare
Buffer2 : String (1 .. 50);
S2, E2 : Positive;
begin
Put (Buffer2, Var, Aft, Exp => 3);
S2 := Strings.Fixed.Index_Non_Blank (Buffer2);
E2 := Buffer2'Last;
-- If with exponent it is shorter, use it
if (E2 - S2) < (E - S) then
Buffer := Buffer2;
S := S2;
E := E2;
end if;
end;
if F.Kind = Shortest_Decimal_Float then
Buffer (S .. E) :=
Characters.Handling.To_Lower (Buffer (S .. E));
end if;
when others =>
Raise_Wrong_Format (Format);
end case;
Append (Format.D.Result,
Get_Formatted (F, Buffer (S .. E), Buffer (S .. E)'Length));
return Format;
end P_Flt_Format;
------------------
-- P_Int_Format --
------------------
function P_Int_Format
(Format : Formatted_String;
Var : Int) return Formatted_String
is
function Handle_Precision return Boolean;
-- Return True if nothing else to do
F : F_Data;
Buffer : String (1 .. 50);
S, E : Positive := 1;
Len : Natural := 0;
Start : Positive;
----------------------
-- Handle_Precision --
----------------------
function Handle_Precision return Boolean is
begin
if F.Precision = 0 and then Sign (Var) = Zero then
return True;
elsif F.Precision = Natural'Last then
null;
elsif F.Precision > E - S + 1 then
Len := F.Precision - (E - S + 1);
Buffer (S - Len .. S - 1) := (others => '0');
S := S - Len;
end if;
return False;
end Handle_Precision;
-- Start of processing for P_Int_Format
begin
Next_Format (Format, F, Start);
if Format.D.Stored_Value < F.Value_Needed then
Format.D.Stored_Value := Format.D.Stored_Value + 1;
Format.D.Stack (Format.D.Stored_Value) := To_Integer (Var);
Format.D.Index := Start;
return Format;
end if;
case F.Kind is
when Unsigned_Octal =>
if Sign (Var) = Neg then
Raise_Wrong_Format (Format);
end if;
Put (Buffer, Var, Base => 8);
S := Strings.Fixed.Index (Buffer, "8#") + 2;
E := Strings.Fixed.Index (Buffer (S .. Buffer'Last), "#") - 1;
if Handle_Precision then
return Format;
end if;
case F.Base is
when None => null;
when C_Style => Len := 1;
when Ada_Style => Len := 3;
end case;
when Unsigned_Hexadecimal_Int =>
if Sign (Var) = Neg then
Raise_Wrong_Format (Format);
end if;
Put (Buffer, Var, Base => 16);
S := Strings.Fixed.Index (Buffer, "16#") + 3;
E := Strings.Fixed.Index (Buffer (S .. Buffer'Last), "#") - 1;
Buffer (S .. E) := Characters.Handling.To_Lower (Buffer (S .. E));
if Handle_Precision then
return Format;
end if;
case F.Base is
when None => null;
when C_Style => Len := 2;
when Ada_Style => Len := 4;
end case;
when Unsigned_Hexadecimal_Int_Up =>
if Sign (Var) = Neg then
Raise_Wrong_Format (Format);
end if;
Put (Buffer, Var, Base => 16);
S := Strings.Fixed.Index (Buffer, "16#") + 3;
E := Strings.Fixed.Index (Buffer (S .. Buffer'Last), "#") - 1;
if Handle_Precision then
return Format;
end if;
case F.Base is
when None => null;
when C_Style => Len := 2;
when Ada_Style => Len := 4;
end case;
when Unsigned_Decimal_Int =>
if Sign (Var) = Neg then
Raise_Wrong_Format (Format);
end if;
Put (Buffer, Var, Base => 10);
S := Strings.Fixed.Index_Non_Blank (Buffer);
E := Buffer'Last;
if Handle_Precision then
return Format;
end if;
when Decimal_Int =>
Put (Buffer, Var, Base => 10);
S := Strings.Fixed.Index_Non_Blank (Buffer);
E := Buffer'Last;
if Handle_Precision then
return Format;
end if;
when Char =>
S := Buffer'First;
E := Buffer'First;
Buffer (S) := Character'Val (To_Integer (Var));
if Handle_Precision then
return Format;
end if;
when others =>
Raise_Wrong_Format (Format);
end case;
-- Then add base if needed
declare
N : String := Get_Formatted (F, Buffer (S .. E), E - S + 1 + Len);
P : constant Positive :=
(if F.Left_Justify
then N'First
else Natural'Max (Strings.Fixed.Index_Non_Blank (N) - 1,
N'First));
begin
case F.Base is
when None =>
null;
when C_Style =>
case F.Kind is
when Unsigned_Octal =>
N (P) := 'O';
when Unsigned_Hexadecimal_Int =>
if F.Left_Justify then
N (P .. P + 1) := "Ox";
else
N (P - 1 .. P) := "0x";
end if;
when Unsigned_Hexadecimal_Int_Up =>
if F.Left_Justify then
N (P .. P + 1) := "OX";
else
N (P - 1 .. P) := "0X";
end if;
when others =>
null;
end case;
when Ada_Style =>
case F.Kind is
when Unsigned_Octal =>
if F.Left_Justify then
N (N'First + 2 .. N'Last) := N (N'First .. N'Last - 2);
else
N (P .. N'Last - 1) := N (P + 1 .. N'Last);
end if;
N (N'First .. N'First + 1) := "8#";
N (N'Last) := '#';
when Unsigned_Hexadecimal_Int
| Unsigned_Hexadecimal_Int_Up
=>
if F.Left_Justify then
N (N'First + 3 .. N'Last) := N (N'First .. N'Last - 3);
else
N (P .. N'Last - 1) := N (P + 1 .. N'Last);
end if;
N (N'First .. N'First + 2) := "16#";
N (N'Last) := '#';
when others =>
null;
end case;
end case;
Append (Format.D.Result, N);
end;
return Format;
end P_Int_Format;
------------------------
-- Raise_Wrong_Format --
------------------------
procedure Raise_Wrong_Format (Format : Formatted_String) is
begin
raise Format_Error with
"wrong format specified for parameter"
& Positive'Image (Format.D.Current);
end Raise_Wrong_Format;
end GNAT.Formatted_String;
|
-- *************************************************************************************
--
-- The recipient is warned that this code should be handled in accordance
-- with the HM Government Security Classification indicated throughout.
--
-- This code and its contents shall not be used for other than UK Government
-- purposes.
--
-- The copyright in this code is the property of BAE SYSTEMS Electronic Systems Limited.
-- The Code is supplied by BAE SYSTEMS on the express terms that it is to be treated in
-- confidence and that it may not be copied, used or disclosed to others for any
-- purpose except in accordance with DEFCON 91 (Edn 10/92).
--
-- File Name: Many_To_Many_Associative.adb
-- Version: As detailed by ClearCase
-- Version Date: As detailed by ClearCase
-- Creation Date: 03-11-99
-- Security Classification: Unclassified
-- Project: SRLE (Sting Ray Life Extension)
-- Author: J Mann
-- Section: Tactical Software/ Software Architecture
-- Division: Underwater Systems Division
-- Description: Generic implementation of 1-M:M relationship
-- Comments:
--
-- MODIFICATION RECORD
-- --------------------
-- NAME DATE ECR No MODIFICATION
--
-- DB 24/09/01 PILOT_0000_2473 Rename Link, Unlink & Unassociate parameters
-- to match those for 1:1 type relationships,
-- at the request of George.
--
-- db 17/04/02 SRLE100003005 Correlated associative navigations supported.
--
-- db 22/04/02 SRLE100002907 Procedure initialise removed as surplus to requirements
--
-- db 09/05/02 SRLE100002899 Role phrase string is limited to 32 characters
-- by calling routine, no checks necessary here.
--
-- db 14/08/02 SRLE100003644 Correlated associative navigations leave
-- iteration lists on the heap, remove them.
--
-- db 10/10/02 SRLE100003928 Remove null checks on source navigates and
-- calls to log.
--
-- db 03/12/02 SRLE100004150 Add extra check for navigate from empty set
--
-- DNS 20/05/15 CR 10265 For Navigate procedures returning a list,
-- the Return is now an "in" parameter
--
-- **************************************************************************************
with Root_Object;
use type Root_Object.Object_Access;
use type Root_Object.Object_List.Node_Access_Type;
with Ada.Tags;
use type Ada.Tags.Tag;
with One_To_Many_Associative;
package body Many_To_Many_Associative is
------------------------------------------------------------------------
package M1_Single_M2_Multiple is new One_To_Many_Associative;
package M2_Single_M1_Multiple is new One_To_Many_Associative;
------------------------------------------------------------------------
M1_Side: Ada.Tags.Tag;
M2_Side: Ada.Tags.Tag;
Associative_Side: Ada.Tags.Tag;
---------------------------------------------------------------------
procedure Register_M1_End_Class (M1_Instance: in Ada.Tags.Tag) is
begin
M1_Side := M1_Instance;
M1_Single_M2_Multiple.Register_Single_End_Class (M1_Instance);
M2_Single_M1_Multiple.Register_Multiple_End_Class (M1_Instance);
end Register_M1_End_Class;
---------------------------------------------------------------------
function Report_M1_End_Class return Ada.Tags.Tag is
begin
return M1_Side;
end Report_M1_End_Class;
-----------------------------------------------------------------------
procedure Register_M2_End_Class (M2_Instance: in Ada.Tags.Tag) is
begin
M2_Side := M2_Instance;
M1_Single_M2_Multiple.Register_Multiple_End_Class (M2_Instance);
M2_Single_M1_Multiple.Register_Single_End_Class (M2_Instance);
end Register_M2_End_Class;
---------------------------------------------------------------------
function Report_M2_End_Class return Ada.Tags.Tag is
begin
return M2_Side;
end Report_M2_End_Class;
-----------------------------------------------------------------------
procedure Register_Associative_End_Class (Associative_Instance: in Ada.Tags.Tag) is
begin
Associative_Side := Associative_Instance;
M1_Single_M2_Multiple.Register_Associative_End_Class (Associative_Instance);
M2_Single_M1_Multiple.Register_Associative_End_Class (Associative_Instance);
end Register_Associative_End_Class;
---------------------------------------------------------------------
function Report_Associative_End_Class return Ada.Tags.Tag is
begin
return Associative_Side;
end Report_Associative_End_Class;
---------------------------------------------------------------------
procedure Link (
A_Instance : in Root_Object.Object_Access;
B_Instance : in Root_Object.Object_Access;
Using : in Root_Object.Object_Access) is
begin
M1_Single_M2_Multiple.Link (
A_Instance => A_Instance,
B_Instance => B_Instance,
Using => Using);
M2_Single_M1_Multiple.Link (
A_Instance => A_Instance,
B_Instance => B_Instance,
Using => Using);
end Link;
-----------------------------------------------------------------------
procedure Unassociate (
A_Instance : in Root_Object.Object_Access;
B_Instance : in Root_Object.Object_Access;
From : in Root_Object.Object_Access) is
begin
M1_Single_M2_Multiple.Unassociate (
A_Instance => A_Instance,
B_Instance => B_Instance,
From => From);
M2_Single_M1_Multiple.Unassociate (
A_Instance => B_Instance,
B_Instance => A_Instance,
From => From);
end Unassociate;
-----------------------------------------------------------------------
procedure Unlink (
A_Instance : in Root_Object.Object_Access;
B_Instance : in Root_Object.Object_Access) is
begin
M1_Single_M2_Multiple.Unlink (
A_Instance => A_Instance,
B_Instance => B_Instance);
M2_Single_M1_Multiple.Unlink (
A_Instance => B_Instance,
B_Instance => A_Instance);
end Unlink;
-----------------------------------------------------------------------
procedure Navigate (
From : in Root_Object.Object_List.List_Header_Access_Type;
Class : in Ada.Tags.Tag;
To : in Root_Object.Object_List.List_Header_Access_Type) is
The_A_Instance: Root_Object.Object_Access;
begin
The_A_Instance := Root_Object.Object_List.First_Entry_Of (From).Item;
if The_A_Instance /= null then
if The_A_Instance.all'tag = M1_Side then
M1_Single_M2_Multiple.Navigate (
From => From,
Class => Class,
To => To);
elsif The_A_Instance.all'tag = M2_Side then
M2_Single_M1_Multiple.Navigate (
From => From,
Class => Class,
To => To);
elsif The_A_Instance.all'tag = Associative_Side then
if Class = M2_Side then
M1_Single_M2_Multiple.Navigate (
From => From,
Class => Class,
To => To);
elsif Class = M1_Side then
M2_Single_M1_Multiple.Navigate (
From => From,
Class => Class,
To => To);
end if;
end if;
end if;
end Navigate;
---------------------------------------------------------------------
procedure Navigate (
From : in Root_Object.Object_Access;
Class : in Ada.Tags.Tag;
To : in Root_Object.Object_List.List_Header_Access_Type) is
--
-- navigate from a single to a set
-- valid for:
-- M1 -> M2
-- M1 -> A
-- M2 -> M1
-- M2 -> A
--
begin
if From.all'tag = M1_Side then
M1_Single_M2_Multiple.Navigate (
From => From,
Class => Class,
To => To);
elsif From.all'tag = M2_Side then
M2_Single_M1_Multiple.Navigate (
From => From,
Class => Class,
To => To);
elsif From.all'tag = Associative_Side then
if Class = M2_Side then
M1_Single_M2_Multiple.Navigate (
From => From,
Class => Class,
To => To);
elsif Class = M1_Side then
M2_Single_M1_Multiple.Navigate (
From => From,
Class => Class,
To => To);
end if;
end if;
end Navigate;
---------------------------------------------------------------------
procedure Navigate (
From : in Root_Object.Object_Access;
Class : in Ada.Tags.Tag;
To : out Root_Object.Object_Access) is
--
-- navigate from a single to a single
-- valid for:
-- A -> M1
-- A -> M2
--
begin
if From.all'tag = Associative_Side then
if Class = M2_Side then
M1_Single_M2_Multiple.Navigate (
From => From,
Class => Class,
To => To);
elsif Class = M1_Side then
M2_Single_M1_Multiple.Navigate (
From => From,
Class => Class,
To => To);
end if;
end if;
end Navigate;
---------------------------------------------------------------------
-- associative correlated navigation
procedure Navigate (
From : in Root_Object.Object_Access;
Also : in Root_Object.Object_Access;
Class : in Ada.Tags.Tag;
To : out Root_Object.Object_Access) is
--
-- navigate from two singles to a single
-- valid for:
-- M1 and M2 -> A
-- M1 and M2 -> A
Temp_Associative_One, Temp_Associative_Two : Root_Object.Object_Access := null;
Assoc_Set_One : Root_Object.Object_List.List_Header_Access_Type := Root_Object.Object_List.Initialise;
Assoc_Set_Two : Root_Object.Object_List.List_Header_Access_Type := Root_Object.Object_List.Initialise;
Matched, Inner_Matched : Boolean := FALSE;
begin
-- Reset the output pointer to null so that if we don't find anything
-- useful, the caller can check for it.
To := null;
if ((( From.all'tag = M1_Side) and then
( Also.all'Tag = M2_Side))
or else (( From.all'tag = M2_Side) and then
( Also.all'Tag = M1_Side)))
then
-- Navigate from single instance of first object
-- returns a set.
Navigate (
From => Also,
Class => Class,
To => Assoc_Set_One);
-- Navigate from single instance of second object
-- returns a set.
Navigate (
From => From,
Class => Class,
To => Assoc_Set_Two);
-- Compare results of the two sets from the above navigations.
-- A nice simple find operation on a set would be appropriate here, but
-- there isn't one available, so do it the hard way.
-- Outer loop
declare
use type Root_Object.Object_List.Node_Access_Type;
Temp_Entry : Root_Object.Object_List.Node_Access_Type;
Matched : boolean := FALSE;
begin
-- Grab the first entry of the set
Temp_Entry := Root_Object.Object_List.First_Entry_Of(Assoc_Set_One);
-- While the set is not empty and the entry does not match the
-- assoc instance already found, burn rubber
while (not Matched) and (Temp_Entry /= null) loop
Temp_Associative_One := Temp_Entry.Item;
-- Compare this entry against the other set.
-- Inner loop
declare
use type Root_Object.Object_List.Node_Access_Type;
Inner_Temp_Entry : Root_Object.Object_List.Node_Access_Type;
begin
-- Grab the first entry of the set
Inner_Temp_Entry := Root_Object.Object_List.First_Entry_Of(Assoc_Set_Two);
-- While the set is not empty and the entry does not match the
-- assoc instance already found, smoke 'em
while (not matched) and (Inner_Temp_Entry /= null) loop
Temp_Associative_Two := Inner_Temp_Entry.Item;
-- If M-M:M associative was ever implemented,
-- it would be easy to add the matched instance into a set for
-- return from this procedure.
Matched := Temp_Associative_One = Temp_Associative_Two;
if not Matched then
Inner_Temp_Entry := Root_Object.Object_List.Next_Entry_Of(Assoc_Set_Two);
end if;
end loop; -- end of (Temp_Entry /= null) or else Matched loop
end;
Temp_Entry := Root_Object.Object_List.Next_Entry_Of(Assoc_Set_One);
end loop; -- end of (Temp_Entry /= null) and not matched loop
if Matched and then Temp_associative_One /= null then
-- Gotcha
To := Temp_Associative_One;
end if;
end;
Root_Object.Object_List.Destroy_List(Assoc_Set_One);
Root_Object.Object_List.Destroy_List(Assoc_Set_Two);
end if;
end Navigate;
-----------------------------------------------------------------------
end Many_To_Many_Associative;
|
-------------------------------------------------------------------------------
-- Copyright (c) 2016 Daniel King
--
-- 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.
-------------------------------------------------------------------------------
pragma Profile(Ravenscar);
pragma Partition_Elaboration_Policy(Sequential);
with System;
-- Provides an API for writing ASCII text to the two-line LCD on the EVB1000
-- board.
--
-- The LCD has two rows capable of displaying ASCII text. Each row can display
-- a maximum of 16 characters.
--
-- The LCD driver is implemented as a protected object in order to protect
-- the SPI interface against race conditions.
--
-- Below is an example of using this API:
--
-- EVB1000.LCD.Driver.Put(Line_1 => "Hello",
-- Line_2 => "World!");
package EVB1000.LCD
with SPARK_Mode => On,
Abstract_State => (LCD_State with External),
Initializes => LCD_State
is
protected type Driver_Type with Priority => System.Priority'Last
is
procedure Clear_LCD
with Global => (In_Out => LCD_State),
Depends => (LCD_State => LCD_State,
Driver_Type => Driver_Type);
-- Clear the LCD.
procedure Put(Text_1 : in String;
Text_2 : in String)
with Global => (In_Out => LCD_State),
Depends => (LCD_State => + (Text_1, Text_2),
Driver_Type => Driver_Type),
Pre => Text_1'Length <= 16 and Text_2'Length <= 16;
-- Set the text for lines 1 (top line) and 2 (bottom line) on the LCD.
--
-- Both lines can display a maximum of 16 characters.
end Driver_Type;
Driver : Driver_Type;
end EVB1000.LCD;
|
package Vehicle_Controller is
type Colour is (Red, Green, Blue, Yellow);
type Direction is (Forward, Backward, Stop, Braking);
task Compute with Priority => 3;
task Status_Light with Priority => 1;
procedure Change_Direction;
private
Status_Light_Colour : Colour := Blue;
Current_Direction : Direction := Stop;
Next_Direction : Direction := Stop;
Stop_Distance_Front : Float := 50.0;
Stop_Distance_Back : Float := 40.0;
end Vehicle_Controller;
|
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, not taking more than you give.
--
with Ada.Text_IO;
with Ada.Directories;
-- with Ada.Exceptions;
with DK8543.Strings.Comments;
-- with DK8543.Errors;
with Options;
with GAWS_Log;
with Virtual_Hosts;
package body Config_File is
function Get_Host
(From_File : in out Ada.Text_IO.File_Type)
return String;
function Get_Host
(From_File : in out Ada.Text_IO.File_Type)
return String
is
use DK8543.Strings.Comments;
Line_Raw : constant String := Ada.Text_IO.Get_Line (From_File);
begin
return Trim_Comments (Line_Raw);
end Get_Host;
procedure Register_Hosts (Success : out Boolean)
is
use Ada.Text_IO;
Hosts_File : constant String := Options.Host_List_File.all;
Exists : constant Boolean := Ada.Directories.Exists (Hosts_File);
File : File_Type;
All_Success : Boolean := True;
Line_Number : Natural := 0;
begin
Success := False;
GAWS_Log.Put_Line ("Registering hosts");
GAWS_Log.Put_Horizontal_Line;
if not Exists then
GAWS_Log.Put_Line ("ERROR: Hosts file '" & Hosts_File & "' not found.");
return;
end if;
Open (File, In_File, Hosts_File);
loop
declare
Host_Name : constant String := Get_Host (File);
Append_Success : Boolean;
begin
Line_Number := Line_Number + 1;
if Host_Name /= "" then
Virtual_Hosts.Append_Respository (Host_Name, Append_Success);
if Append_Success then
GAWS_Log.Put_Line ("Registered '" & Host_Name & "'.");
else
All_Success := False;
GAWS_Log.Put_Line ("ERROR: Registering '" & Host_Name & "' failed.");
end if;
end if;
-- exception
--
-- when Occ : Constraint_Error =>
-- raise;
-- DK8543.Errors.Error
-- (Hosts_File, Line_Number,
-- Ada.Exceptions.Exception_Message (Occ));
end;
end loop;
exception
when End_Error =>
Close (File);
GAWS_Log.Put_Horizontal_Line;
Success := All_Success;
end Register_Hosts;
end Config_File;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from STM32H743x.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package STM32_SVD.QUADSPI is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype CR_FTHRES_Field is HAL.UInt5;
subtype CR_PRESCALER_Field is HAL.UInt8;
-- QUADSPI control register
type CR_Register is record
-- Enable Enable the QUADSPI.
EN : Boolean := False;
-- Abort request This bit aborts the on-going command sequence. It is
-- automatically reset once the abort is complete. This bit stops the
-- current transfer. In polling mode or memory-mapped mode, this bit
-- also reset the APM bit or the DM bit.
ABORT_k : Boolean := False;
-- DMA enable In indirect mode, DMA can be used to input or output data
-- via the QUADSPI_DR register. DMA transfers are initiated when the
-- FIFO threshold flag, FTF, is set.
DMAEN : Boolean := False;
-- Timeout counter enable This bit is valid only when memory-mapped mode
-- (FMODE = 11) is selected. Activating this bit causes the chip select
-- (nCS) to be released (and thus reduces consumption) if there has not
-- been an access after a certain amount of time, where this time is
-- defined by TIMEOUT[15:0] (QUADSPI_LPTR). Enable the timeout counter.
-- By default, the QUADSPI never stops its prefetch operation, keeping
-- the previous read operation active with nCS maintained low, even if
-- no access to the Flash memory occurs for a long time. Since Flash
-- memories tend to consume more when nCS is held low, the application
-- might want to activate the timeout counter (TCEN = 1, QUADSPI_CR[3])
-- so that nCS is released after a period of TIMEOUT[15:0]
-- (QUADSPI_LPTR) cycles have elapsed without an access since when the
-- FIFO becomes full with prefetch data. This bit can be modified only
-- when BUSY = 0.
TCEN : Boolean := False;
-- Sample shift By default, the QUADSPI samples data 1/2 of a CLK cycle
-- after the data is driven by the Flash memory. This bit allows the
-- data is to be sampled later in order to account for external signal
-- delays. Firmware must assure that SSHIFT = 0 when in DDR mode (when
-- DDRM = 1). This field can be modified only when BUSY = 0.
SSHIFT : Boolean := False;
-- unspecified
Reserved_5_5 : HAL.Bit := 16#0#;
-- Dual-flash mode This bit activates dual-flash mode, where two
-- external Flash memories are used simultaneously to double throughput
-- and capacity. This bit can be modified only when BUSY = 0.
DFM : Boolean := False;
-- Flash memory selection This bit selects the Flash memory to be
-- addressed in single flash mode (when DFM = 0). This bit can be
-- modified only when BUSY = 0. This bit is ignored when DFM = 1.
FSEL : Boolean := False;
-- FIFO threshold level Defines, in indirect mode, the threshold number
-- of bytes in the FIFO that will cause the FIFO threshold flag (FTF,
-- QUADSPI_SR[2]) to be set. In indirect write mode (FMODE = 00): ... In
-- indirect read mode (FMODE = 01): ... If DMAEN = 1, then the DMA
-- controller for the corresponding channel must be disabled before
-- changing the FTHRES value.
FTHRES : CR_FTHRES_Field := 16#0#;
-- unspecified
Reserved_13_15 : HAL.UInt3 := 16#0#;
-- Transfer error interrupt enable This bit enables the transfer error
-- interrupt.
TEIE : Boolean := False;
-- Transfer complete interrupt enable This bit enables the transfer
-- complete interrupt.
TCIE : Boolean := False;
-- FIFO threshold interrupt enable This bit enables the FIFO threshold
-- interrupt.
FTIE : Boolean := False;
-- Status match interrupt enable This bit enables the status match
-- interrupt.
SMIE : Boolean := False;
-- TimeOut interrupt enable This bit enables the TimeOut interrupt.
TOIE : Boolean := False;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Automatic poll mode stop This bit determines if automatic polling is
-- stopped after a match. This bit can be modified only when BUSY = 0.
APMS : Boolean := False;
-- Polling match mode This bit indicates which method should be used for
-- determining a match during automatic polling mode. This bit can be
-- modified only when BUSY = 0.
PMM : Boolean := False;
-- clock prescaler
PRESCALER : CR_PRESCALER_Field := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
EN at 0 range 0 .. 0;
ABORT_k at 0 range 1 .. 1;
DMAEN at 0 range 2 .. 2;
TCEN at 0 range 3 .. 3;
SSHIFT at 0 range 4 .. 4;
Reserved_5_5 at 0 range 5 .. 5;
DFM at 0 range 6 .. 6;
FSEL at 0 range 7 .. 7;
FTHRES at 0 range 8 .. 12;
Reserved_13_15 at 0 range 13 .. 15;
TEIE at 0 range 16 .. 16;
TCIE at 0 range 17 .. 17;
FTIE at 0 range 18 .. 18;
SMIE at 0 range 19 .. 19;
TOIE at 0 range 20 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
APMS at 0 range 22 .. 22;
PMM at 0 range 23 .. 23;
PRESCALER at 0 range 24 .. 31;
end record;
subtype DCR_CSHT_Field is HAL.UInt3;
subtype DCR_FSIZE_Field is HAL.UInt5;
-- QUADSPI device configuration register
type DCR_Register is record
-- indicates the level that clk takes between command
CKMODE : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
-- Chip select high time CSHT+1 defines the minimum number of CLK cycles
-- which the chip select (nCS) must remain high between commands issued
-- to the Flash memory. ... This field can be modified only when BUSY =
-- 0.
CSHT : DCR_CSHT_Field := 16#0#;
-- unspecified
Reserved_11_15 : HAL.UInt5 := 16#0#;
-- Flash memory size This field defines the size of external memory
-- using the following formula: Number of bytes in Flash memory =
-- 2[FSIZE+1] FSIZE+1 is effectively the number of address bits required
-- to address the Flash memory. The Flash memory capacity can be up to
-- 4GB (addressed using 32 bits) in indirect mode, but the addressable
-- space in memory-mapped mode is limited to 256MB. If DFM = 1, FSIZE
-- indicates the total capacity of the two Flash memories together. This
-- field can be modified only when BUSY = 0.
FSIZE : DCR_FSIZE_Field := 16#0#;
-- unspecified
Reserved_21_31 : HAL.UInt11 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for DCR_Register use record
CKMODE at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
CSHT at 0 range 8 .. 10;
Reserved_11_15 at 0 range 11 .. 15;
FSIZE at 0 range 16 .. 20;
Reserved_21_31 at 0 range 21 .. 31;
end record;
subtype SR_FLEVEL_Field is HAL.UInt6;
-- QUADSPI status register
type SR_Register is record
-- Read-only. Transfer error flag This bit is set in indirect mode when
-- an invalid address is being accessed in indirect mode. It is cleared
-- by writing 1 to CTEF.
TEF : Boolean;
-- Read-only. Transfer complete flag This bit is set in indirect mode
-- when the programmed number of data has been transferred or in any
-- mode when the transfer has been aborted.It is cleared by writing 1 to
-- CTCF.
TCF : Boolean;
-- Read-only. FIFO threshold flag In indirect mode, this bit is set when
-- the FIFO threshold has been reached, or if there is any data left in
-- the FIFO after reads from the Flash memory are complete. It is
-- cleared automatically as soon as threshold condition is no longer
-- true. In automatic polling mode this bit is set every time the status
-- register is read, and the bit is cleared when the data register is
-- read.
FTF : Boolean;
-- Read-only. Status match flag This bit is set in automatic polling
-- mode when the unmasked received data matches the corresponding bits
-- in the match register (QUADSPI_PSMAR). It is cleared by writing 1 to
-- CSMF.
SMF : Boolean;
-- Read-only. Timeout flag This bit is set when timeout occurs. It is
-- cleared by writing 1 to CTOF.
TOF : Boolean;
-- Read-only. Busy This bit is set when an operation is on going. This
-- bit clears automatically when the operation with the Flash memory is
-- finished and the FIFO is empty.
BUSY : Boolean;
-- unspecified
Reserved_6_7 : HAL.UInt2;
-- Read-only. FIFO level This field gives the number of valid bytes
-- which are being held in the FIFO. FLEVEL = 0 when the FIFO is empty,
-- and 16 when it is full. In memory-mapped mode and in automatic status
-- polling mode, FLEVEL is zero.
FLEVEL : SR_FLEVEL_Field;
-- unspecified
Reserved_14_31 : HAL.UInt18;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SR_Register use record
TEF at 0 range 0 .. 0;
TCF at 0 range 1 .. 1;
FTF at 0 range 2 .. 2;
SMF at 0 range 3 .. 3;
TOF at 0 range 4 .. 4;
BUSY at 0 range 5 .. 5;
Reserved_6_7 at 0 range 6 .. 7;
FLEVEL at 0 range 8 .. 13;
Reserved_14_31 at 0 range 14 .. 31;
end record;
-- QUADSPI flag clear register
type FCR_Register is record
-- Clear transfer error flag Writing 1 clears the TEF flag in the
-- QUADSPI_SR register
CTEF : Boolean := False;
-- Clear transfer complete flag Writing 1 clears the TCF flag in the
-- QUADSPI_SR register
CTCF : Boolean := False;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
-- Clear status match flag Writing 1 clears the SMF flag in the
-- QUADSPI_SR register
CSMF : Boolean := False;
-- Clear timeout flag Writing 1 clears the TOF flag in the QUADSPI_SR
-- register
CTOF : Boolean := False;
-- unspecified
Reserved_5_31 : HAL.UInt27 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for FCR_Register use record
CTEF at 0 range 0 .. 0;
CTCF at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
CSMF at 0 range 3 .. 3;
CTOF at 0 range 4 .. 4;
Reserved_5_31 at 0 range 5 .. 31;
end record;
subtype CCR_INSTRUCTION_Field is HAL.UInt8;
subtype CCR_IMODE_Field is HAL.UInt2;
subtype CCR_ADMODE_Field is HAL.UInt2;
subtype CCR_ADSIZE_Field is HAL.UInt2;
subtype CCR_ABMODE_Field is HAL.UInt2;
subtype CCR_ABSIZE_Field is HAL.UInt2;
subtype CCR_DCYC_Field is HAL.UInt5;
subtype CCR_DMODE_Field is HAL.UInt2;
subtype CCR_FMODE_Field is HAL.UInt2;
-- QUADSPI communication configuration register
type CCR_Register is record
-- Instruction Instruction to be send to the external SPI device. This
-- field can be written only when BUSY = 0.
INSTRUCTION : CCR_INSTRUCTION_Field := 16#0#;
-- Instruction mode This field defines the instruction phase mode of
-- operation: This field can be written only when BUSY = 0.
IMODE : CCR_IMODE_Field := 16#0#;
-- Address mode This field defines the address phase mode of operation:
-- This field can be written only when BUSY = 0.
ADMODE : CCR_ADMODE_Field := 16#0#;
-- Address size This bit defines address size: This field can be written
-- only when BUSY = 0.
ADSIZE : CCR_ADSIZE_Field := 16#0#;
-- Alternate bytes mode This field defines the alternate-bytes phase
-- mode of operation: This field can be written only when BUSY = 0.
ABMODE : CCR_ABMODE_Field := 16#0#;
-- Alternate bytes size This bit defines alternate bytes size: This
-- field can be written only when BUSY = 0.
ABSIZE : CCR_ABSIZE_Field := 16#0#;
-- Number of dummy cycles This field defines the duration of the dummy
-- phase. In both SDR and DDR modes, it specifies a number of CLK cycles
-- (0-31). This field can be written only when BUSY = 0.
DCYC : CCR_DCYC_Field := 16#0#;
-- unspecified
Reserved_23_23 : HAL.Bit := 16#0#;
-- Data mode This field defines the data phases mode of operation: This
-- field also determines the dummy phase mode of operation. This field
-- can be written only when BUSY = 0.
DMODE : CCR_DMODE_Field := 16#0#;
-- Functional mode This field defines the QUADSPI functional mode of
-- operation. If DMAEN = 1 already, then the DMA controller for the
-- corresponding channel must be disabled before changing the FMODE
-- value. This field can be written only when BUSY = 0.
FMODE : CCR_FMODE_Field := 16#0#;
-- Send instruction only once mode See Section15.3.11: Sending the
-- instruction only once on page13. This bit has no effect when IMODE =
-- 00. This field can be written only when BUSY = 0.
SIOO : Boolean := False;
-- unspecified
Reserved_29_29 : HAL.Bit := 16#0#;
-- DDR hold Delay the data output by 1/4 of the QUADSPI output clock
-- cycle in DDR mode: This feature is only active in DDR mode. This
-- field can be written only when BUSY = 0.
DHHC : Boolean := False;
-- Double data rate mode This bit sets the DDR mode for the address,
-- alternate byte and data phase: This field can be written only when
-- BUSY = 0.
DDRM : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CCR_Register use record
INSTRUCTION at 0 range 0 .. 7;
IMODE at 0 range 8 .. 9;
ADMODE at 0 range 10 .. 11;
ADSIZE at 0 range 12 .. 13;
ABMODE at 0 range 14 .. 15;
ABSIZE at 0 range 16 .. 17;
DCYC at 0 range 18 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
DMODE at 0 range 24 .. 25;
FMODE at 0 range 26 .. 27;
SIOO at 0 range 28 .. 28;
Reserved_29_29 at 0 range 29 .. 29;
DHHC at 0 range 30 .. 30;
DDRM at 0 range 31 .. 31;
end record;
subtype PIR_INTERVAL_Field is HAL.UInt16;
-- QUADSPI polling interval register
type PIR_Register is record
-- Polling interval Number of CLK cycles between to read during
-- automatic polling phases. This field can be written only when BUSY =
-- 0.
INTERVAL : PIR_INTERVAL_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PIR_Register use record
INTERVAL at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
subtype LPTR_TIMEOUT_Field is HAL.UInt16;
-- QUADSPI low-power timeout register
type LPTR_Register is record
-- Timeout period After each access in memory-mapped mode, the QUADSPI
-- prefetches the subsequent bytes and holds these bytes in the FIFO.
-- This field indicates how many CLK cycles the QUADSPI waits after the
-- FIFO becomes full until it raises nCS, putting the Flash memory in a
-- lower-consumption state. This field can be written only when BUSY =
-- 0.
TIMEOUT : LPTR_TIMEOUT_Field := 16#0#;
-- unspecified
Reserved_16_31 : HAL.UInt16 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for LPTR_Register use record
TIMEOUT at 0 range 0 .. 15;
Reserved_16_31 at 0 range 16 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- QUADSPI
type QUADSPI_Peripheral is record
-- QUADSPI control register
CR : aliased CR_Register;
-- QUADSPI device configuration register
DCR : aliased DCR_Register;
-- QUADSPI status register
SR : aliased SR_Register;
-- QUADSPI flag clear register
FCR : aliased FCR_Register;
-- QUADSPI data length register
DLR : aliased HAL.UInt32;
-- QUADSPI communication configuration register
CCR : aliased CCR_Register;
-- QUADSPI address register
AR : aliased HAL.UInt32;
-- QUADSPI alternate bytes registers
ABR : aliased HAL.UInt32;
-- QUADSPI data register
DR : aliased HAL.UInt32;
-- QUADSPI polling status mask register
PSMKR : aliased HAL.UInt32;
-- QUADSPI polling status match register
PSMAR : aliased HAL.UInt32;
-- QUADSPI polling interval register
PIR : aliased PIR_Register;
-- QUADSPI low-power timeout register
LPTR : aliased LPTR_Register;
end record
with Volatile;
for QUADSPI_Peripheral use record
CR at 16#0# range 0 .. 31;
DCR at 16#4# range 0 .. 31;
SR at 16#8# range 0 .. 31;
FCR at 16#C# range 0 .. 31;
DLR at 16#10# range 0 .. 31;
CCR at 16#14# range 0 .. 31;
AR at 16#18# range 0 .. 31;
ABR at 16#1C# range 0 .. 31;
DR at 16#20# range 0 .. 31;
PSMKR at 16#24# range 0 .. 31;
PSMAR at 16#28# range 0 .. 31;
PIR at 16#2C# range 0 .. 31;
LPTR at 16#30# range 0 .. 31;
end record;
-- QUADSPI
QUADSPI_Periph : aliased QUADSPI_Peripheral
with Import, Address => QUADSPI_Base;
end STM32_SVD.QUADSPI;
|
with Interfaces.C; use Interfaces.C;
procedure Execute_System is
function Sys (Arg : Char_Array) return Integer;
pragma Import(C, Sys, "system");
Ret_Val : Integer;
begin
Ret_Val := Sys(To_C("ls"));
end Execute_System;
|
-- This file cannot be processed by the SPARK Examiner.
with Ada.Numerics,
Ada.Numerics.Elementary_Functions;
package body PP_F_Rounded is
function Plus (Prec : Integer; X,Y : Float) return Float is
begin
return X+Y;
end Plus;
function Minus (Prec : Integer; X,Y : Float) return Float is
begin
return X-Y;
end Minus;
function Multiply (Prec : Integer; X,Y : Float) return Float is
begin
return X*Y;
end Multiply;
function Divide (Prec : Integer; X,Y : Float) return Float is
begin
return X/Y;
end Divide;
function Pi(Prec : Integer) return Float is
begin
return Ada.Numerics.Pi;
end Pi;
function Sqrt (Prec : Integer; X : Float) return Float is
begin
return Ada.Numerics.Elementary_Functions.Sqrt(X);
end Sqrt;
function Exp (Prec : Integer; X : Float) return Float is
begin
return Ada.Numerics.Elementary_Functions.Exp(X);
end Exp;
end PP_F_Rounded;
|
-- Copyright (c) 2021 Devin Hill
-- zlib License -- see LICENSE for details.
with GBA.Memory;
use GBA.Memory;
with GBA.Numerics;
use GBA.Numerics;
with GBA.Display.Tiles;
use GBA.Display.Tiles;
with GBA.Display.Palettes;
use GBA.Display.Palettes;
with Interfaces;
use Interfaces;
package GBA.Display.Backgrounds is
type Boundary_Behavior is
( Cutoff
, Wrap
) with Size => 2;
for Boundary_Behavior use
( Cutoff => 0
, Wrap => 1
);
type BG_ID is
( BG_0
, BG_1
, BG_2
, BG_3
);
type BG_Kind is
( Regular
, Affine
);
type BG_Size is range 0 ..3
with Size => 2;
type BG_Scroll_Offset is new Integer_16;
type BG_Control_Info is
record
Priority : Display_Priority;
Tile_Block : Tile_Block_Index;
Enable_Mosaic : Boolean;
Color_Mode : Palette_Mode;
Screen_Block : Screen_Block_Index;
Boundary_Mode : Boundary_Behavior;
Size : BG_Size;
end record
with Size => 16;
for BG_Control_Info use
record
Priority at 0 range 0 .. 1;
Tile_Block at 0 range 2 .. 3;
Enable_Mosaic at 0 range 6 .. 6;
Color_Mode at 0 range 7 .. 7;
Screen_Block at 1 range 0 .. 4;
Boundary_Mode at 1 range 5 .. 5;
Size at 1 range 6 .. 7;
end record;
BG_Control : array (BG_ID) of BG_Control_Info
with Import, Volatile_Components, Address => BG0CNT;
type BG_Offset_Info is
record
X, Y : BG_Scroll_Offset;
end record
with Size => 32;
for BG_Offset_Info use
record
X at 0 range 0 .. 15;
Y at 2 range 0 .. 15;
end record;
procedure Set_Offset (BG : BG_ID; X, Y : BG_Scroll_Offset)
with Inline;
procedure Set_Offset (BG : BG_ID; Offsets : BG_Offset_Info)
with Inline;
procedure Set_Offset_X (BG : BG_ID; Value : BG_Scroll_Offset)
with Inline;
procedure Set_Offset_Y (BG : BG_ID; Value : BG_Scroll_Offset)
with Inline;
subtype BG_Reference_Point_Coordinate is
GBA.Numerics.Fixed_20_8;
type BG_Reference_Point is
record
X, Y : BG_Reference_Point_Coordinate;
end record
with Size => 64;
for BG_Reference_Point use
record
X at 0 range 0 .. 31;
Y at 4 range 0 .. 31;
end record;
type BG_Transform_Info is
record
Affine_Matrix : Affine_Transform_Matrix;
Reference_Point : BG_Reference_Point;
end record
with Size => 128;
for BG_Transform_Info use
record
Affine_Matrix at 0 range 0 .. 63;
Reference_Point at 8 range 0 .. 63;
end record;
type BG_Transform_Info_Array is
array (Natural range <>) of BG_Transform_Info;
subtype Affine_BG_ID is BG_ID range BG_2 .. BG_3;
function Affine_Transform_Address (ID : Affine_BG_ID) return Address
with Pure_Function, Inline_Always;
procedure Set_Reference_X (BG : Affine_BG_ID; Value : BG_Reference_Point_Coordinate)
with Inline;
procedure Set_Reference_Y (BG : Affine_BG_ID; Value : BG_Reference_Point_Coordinate)
with Inline;
procedure Set_Reference_Point (BG : Affine_BG_ID; X, Y : BG_Reference_Point_Coordinate)
with Inline;
procedure Set_Reference_Point (BG : Affine_BG_ID; Reference_Point : BG_Reference_Point)
with Inline;
procedure Set_Affine_Matrix (BG : Affine_BG_ID; Matrix : Affine_Transform_Matrix)
with Inline;
procedure Set_Transform (BG : Affine_BG_ID; Transform : BG_Transform_Info)
with Inline;
private
-- This is private because it is a write-only set of registers.
-- Using the setter procedures above is therefore a more faithful interface.
BG_Offsets : array (BG_ID) of BG_Offset_Info
with Import, Volatile_Components, Address => BG0HOFS;
BG_Transforms : array (BG_2 .. BG_3) of BG_Transform_Info
with Import, Volatile_Components, Address => BG2PA;
end GBA.Display.Backgrounds; |
-- part of AdaYaml, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "copying.txt"
with Text;
with Yaml.Tags;
package body Yaml.Transformator.Canonical is
procedure Put (Object : in out Instance; E : Event) is
use type Text.Reference;
function Is_Non_Specific (Tag : Text.Reference) return Boolean is
(Tag = Text.Empty or Tag = Tags.Exclamation_Mark);
begin
if Object.Current_Exists then
raise Constraint_Error with
"Must retrieve current event before inputting another one";
end if;
Object.Current := E;
Object.Current_Exists := True;
case Object.Current.Kind is
when Document_Start =>
Object.Current.Implicit_Start := False;
when Mapping_Start =>
if Is_Non_Specific (Object.Current.Collection_Properties.Tag) then
Object.Current.Collection_Properties.Tag := Tags.Mapping;
end if;
Object.Current.Collection_Style := Flow;
when Sequence_Start =>
if Is_Non_Specific (Object.Current.Collection_Properties.Tag) then
Object.Current.Collection_Properties.Tag := Tags.Sequence;
end if;
Object.Current.Collection_Style := Flow;
when Scalar =>
if Is_Non_Specific (Object.Current.Scalar_Properties.Tag) then
Object.Current.Scalar_Properties.Tag := Tags.String; -- TODO
end if;
Object.Current.Scalar_Style := Double_Quoted;
when others => null;
end case;
end Put;
function Has_Next (Object : Instance) return Boolean is
(Object.Current_Exists);
function Next (Object : in out Instance) return Event is
begin
if Object.Current_Exists then
Object.Current_Exists := False;
return Object.Current;
else
raise Constraint_Error with "No next event!";
end if;
end Next;
end Yaml.Transformator.Canonical;
|
------------------------------------------------------------------------------
-- --
-- tiled-code-gen --
-- --
-- Copyright (C) 2018 Fabien Chouteau --
-- --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. 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. --
-- 3. 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 --
-- 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. --
-- --
------------------------------------------------------------------------------
with DOM.Core; use DOM.Core;
with DOM.Core.Nodes; use DOM.Core.Nodes;
with DOM.Core.Elements; use DOM.Core.Elements;
with TCG.Utils; use TCG.Utils;
with Ada.Strings.Fixed;
with Interfaces; use Interfaces;
package body TCG.Object_Groups is
function To_Float (Str : String) return Float;
function To_Point (Str : String) return Point;
function To_Polygon (Str : String)
return not null Polygon_Access;
function Load (N : Node) return Object;
--------------
-- To_Float --
--------------
function To_Float (Str : String) return Float
is (Float'Value (Str));
--------------
-- To_Point --
--------------
function To_Point (Str : String) return Point is
Index : constant Natural := Ada.Strings.Fixed.Index (Str, ",");
begin
return (To_Float (Str (Str'First .. Index - 1)),
To_Float (Str (Index + 1 .. Str'Last)));
end To_Point;
----------------
-- To_Polygon --
----------------
function To_Polygon (Str : String)
return not null Polygon_Access
is
Number_Of_Points : constant Natural :=
Ada.Strings.Fixed.Count (Str, " ") + 1;
Ret : constant not null Polygon_Access
:= new Polygon (1 .. Number_Of_Points);
Index : Natural;
Last_Index : Natural := Str'First;
begin
for Pt of Ret.all loop
Index := Ada.Strings.Fixed.Index (Str (Last_Index .. Str'Last), " ");
if Index = 0 then
-- Last point in the list
Pt := To_Point (Str (Last_Index .. Str'Last));
else
Pt := To_Point (Str (Last_Index .. Index - 1));
end if;
Last_Index := Index + 1;
end loop;
return Ret;
end To_Polygon;
----------
-- Load --
----------
function Load (N : Node) return Object is
Id : Natural;
X : constant Float := Item_As_Float (N, "x");
Y : constant Float := Item_As_Float (N, "y");
Has_Width : constant Boolean := Item_Exists (N, "width");
Has_Height : constant Boolean := Item_Exists (N, "height");
Has_GID : constant Boolean := Item_Exists (N, "gid");
Is_Ellipse : Boolean;
Is_Point : Boolean;
Str : String_Access := null;
Name : String_Access := null;
Height, Width : Float := 0.0;
GID : Unsigned_32 := 0;
List : Node_List;
Kind : Object_Kind;
Flip_Vertical : Boolean := False;
Flip_Horizontal : Boolean := False;
Poly : Polygon_Access;
begin
if Item_Exists (N, "id") then
Id := Item_As_Natural (N, "id");
else
-- When there is not ID it means that there is only one object
Id := 0;
end if;
if Has_Width then
Width := Item_As_Float (N, "width");
end if;
if Has_Height then
Height := Item_As_Float (N, "height");
end if;
if Has_GID then
GID := Item_As_UInt32 (N, "gid");
Flip_Vertical := (GID and 16#4000_0000#) /= 0;
Flip_Horizontal := (GID and 16#8000_0000#) /= 0;
GID := GID and 16#3FFF_FFFF#;
end if;
if Item_Exists (N, "name") then
Name := new String'(Item_As_String (N, "name"));
end if;
List := Get_Elements_By_Tag_Name (N, "text");
if Length (List) = 1 then
Str := new String'(Node_Value (First_Child (Item (List, 0))));
end if;
Free (List);
List := Get_Elements_By_Tag_Name (N, "polygon");
if Length (List) = 1 then
Poly := To_Polygon (Item_As_String (Item (List, 0), "points"));
end if;
Free (List);
List := Get_Elements_By_Tag_Name (N, "ellipse");
if Length (List) > 0 then
Is_Ellipse := True;
end if;
Free (List);
List := Get_Elements_By_Tag_Name (N, "point");
if Length (List) > 0 then
Is_Point := True;
end if;
Free (List);
if Poly /= null then
Kind := Polygon_Obj;
elsif Is_Ellipse then
Kind := Ellipse_Obj;
elsif Is_Point then
Kind := Point_Obj;
elsif Str /= null then
Kind := Text_Obj;
elsif Has_GID then
Kind := Tile_Obj;
else
Kind := Rectangle_Obj;
end if;
return (Kind => Kind,
Name => Name,
Id => Id,
Pt => (X, Y),
Width => Width,
Height => Height,
Points => Poly,
Str => Str,
Flip_Vertical => Flip_Vertical,
Flip_Horizontal => Flip_Horizontal,
Tile_Id => Tilesets.Map_Tile_Id (GID));
end Load;
----------
-- Load --
----------
function Load (Root : DOM.Core.Node) return Object_Group is
Id : Natural;
Name : constant String := Item_As_String (Root, "name");
List : Node_List;
N : Node;
Group : constant Object_Group := new Group_Data;
begin
if Item_Exists (Root, "id") then
Id := Item_As_Natural (Root, "id");
else
-- When there is not ID it means that there is only one group
Id := 0;
end if;
Group.Id := Object_Group_Id (Id);
Group.Name := new String'(Name);
List := Get_Elements_By_Tag_Name (Root, "object");
for Index in 1 .. Length (List) loop
N := Item (List, Index - 1);
Group.Objects.Append (Load (N));
end loop;
Free (List);
return Group;
end Load;
----------
-- Name --
----------
function Name
(This : Object_Group)
return String
is (This.Name.all);
--------
-- Id --
--------
function Id
(This : Object_Group)
return Object_Group_Id
is (This.Id);
------------
-- Length --
------------
function Length (This : Object_Group) return Natural
is (Natural (This.Objects.Length));
-----------------
-- First_Index --
-----------------
function First_Index (This : Object_Group) return Natural
is (This.Objects.First_Index);
----------------
-- Last_Index --
----------------
function Last_Index (This : Object_Group) return Natural
is (This.Objects.Last_Index);
----------------
-- Get_Object --
----------------
function Get_Object (This : Object_Group;
Index : Natural)
return Object
is (This.Objects.Element (Index));
end TCG.Object_Groups;
|
-----------------------------------------------------------------------
-- mat-formats - Format various types for the console or GUI interface
-- Copyright (C) 2015 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- 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 Ada.Strings.Unbounded;
with MAT.Types;
with MAT.Memory;
with MAT.Events.Tools;
package MAT.Formats is
type Format_Type is (BRIEF, NORMAL);
-- Set the size of a target address to format them.
procedure Set_Address_Size (Size : in Positive);
-- Format the PID into a string.
function Pid (Value : in MAT.Types.Target_Process_Ref) return String;
-- Format the address into a string.
function Addr (Value : in MAT.Types.Target_Addr) return String;
-- Format the size into a string.
function Size (Value : in MAT.Types.Target_Size) return String;
-- Format the memory growth size into a string.
function Size (Alloced : in MAT.Types.Target_Size;
Freed : in MAT.Types.Target_Size) return String;
-- Format the time relative to the start time.
function Time (Value : in MAT.Types.Target_Tick_Ref;
Start : in MAT.Types.Target_Tick_Ref) return String;
-- Format the duration in seconds, milliseconds or microseconds.
function Duration (Value : in MAT.Types.Target_Tick_Ref) return String;
-- Format a file, line, function information into a string.
function Location (File : in Ada.Strings.Unbounded.Unbounded_String;
Line : in Natural;
Func : in Ada.Strings.Unbounded.Unbounded_String) return String;
-- Format an event range description.
function Event (First : in MAT.Events.Target_Event_Type;
Last : in MAT.Events.Target_Event_Type) return String;
-- Format a short description of the event.
function Event (Item : in MAT.Events.Target_Event_Type;
Mode : in Format_Type := NORMAL) return String;
-- Format a short description of the event.
function Event (Item : in MAT.Events.Target_Event_Type;
Related : in MAT.Events.Tools.Target_Event_Vector;
Start_Time : in MAT.Types.Target_Tick_Ref) return String;
-- Format the difference between two event IDs (offset).
function Offset (First : in MAT.Events.Event_Id_Type;
Second : in MAT.Events.Event_Id_Type) return String;
-- Format a short description of the memory allocation slot.
function Slot (Value : in MAT.Types.Target_Addr;
Item : in MAT.Memory.Allocation;
Start_Time : in MAT.Types.Target_Tick_Ref) return String;
end MAT.Formats;
|
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;
procedure String_Append is
Str : Unbounded_String := To_Unbounded_String("Hello");
begin
Append(Str, ", world!");
Put_Line(Str);
end String_Append;
|
--
-- Jan & Uwe R. Zimmer, Australia, July 2011
--
with Ada.Real_Time; use Ada.Real_Time;
with Real_Type; use Real_Type;
package Graphics_FrameRates is
Smoothing_Buffer_Size : constant Positive := 24;
subtype Hz is Real range 0.0 .. Real'Last;
function Measure_Interval return Time_Span;
function Average_Framerate (Interval : Time_Span) return Hz;
procedure Framerate_Limiter (Max_Framerate : Hz);
end Graphics_FrameRates;
|
package body Opt23_Pkg is
function Get (R : Rec; I : Positive; M : Natural) return Path is
begin
return R.Val (I) (M);
end;
end Opt23_Pkg;
|
--
-- Copyright (C) 2015-2016 secunet Security Networks AG
-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
with HW;
use type HW.Pos64;
use type HW.Word32;
package HW.GFX is
-- such that the count of pixels in any framebuffer may fit
subtype Pixel_Type is Int32 range 0 .. 8192 * 8192;
subtype Pos_Pixel_Type is Pixel_Type range 1 .. Pixel_Type'Last;
-- Allow same range for width and height (for rotated framebuffers)
subtype Width_Type is Pos32 range 1 .. 8192;
subtype Height_Type is Pos32 range 1 .. 8192;
subtype Position_Type is Int32 range 0 .. 4095;
Auto_BPC : constant := 5;
subtype BPC_Type is Int64 range Auto_BPC .. 16;
type Tiling_Type is (Linear, X_Tiled, Y_Tiled);
subtype XY_Tiling is Tiling_Type range X_Tiled .. Y_Tiled;
type Rotation_Type is (No_Rotation, Rotated_90, Rotated_180, Rotated_270);
type Framebuffer_Type is
record
Width : Width_Type;
Height : Height_Type;
Start_X : Position_Type;
Start_Y : Position_Type;
BPC : BPC_Type;
Stride : Width_Type;
V_Stride : Height_Type;
Tiling : Tiling_Type;
Rotation : Rotation_Type;
Offset : Word32;
end record;
Default_FB : constant Framebuffer_Type := Framebuffer_Type'
(Width => 1,
Height => 1,
Start_X => 0,
Start_Y => 0,
BPC => 8,
Stride => 1,
V_Stride => 1,
Tiling => Linear,
Rotation => No_Rotation,
Offset => 0);
subtype Frequency_Type is Pos64 range 24_000_000 .. 600_000_000;
type DP_Lane_Count is (DP_Lane_Count_1, DP_Lane_Count_2, DP_Lane_Count_4);
subtype DP_Lane_Count_Type is Pos64 range 1 .. 4;
type DP_Lane_Count_Integers is array (DP_Lane_Count) of DP_Lane_Count_Type;
Lane_Count_As_Integer : constant DP_Lane_Count_Integers :=
DP_Lane_Count_Integers'
(DP_Lane_Count_1 => 1, DP_Lane_Count_2 => 2, DP_Lane_Count_4 => 4);
type DP_Bandwidth is (DP_Bandwidth_1_62, DP_Bandwidth_2_7, DP_Bandwidth_5_4);
for DP_Bandwidth use
(DP_Bandwidth_1_62 => 6, DP_Bandwidth_2_7 => 10, DP_Bandwidth_5_4 => 20);
for DP_Bandwidth'Size use 8;
subtype DP_Symbol_Rate_Type is Pos64 range 1 .. 810_000_000;
type DP_Symbol_Rate_Array is array (DP_Bandwidth) of DP_Symbol_Rate_Type;
DP_Symbol_Rate : constant DP_Symbol_Rate_Array := DP_Symbol_Rate_Array'
(DP_Bandwidth_1_62 => 162_000_000,
DP_Bandwidth_2_7 => 270_000_000,
DP_Bandwidth_5_4 => 540_000_000);
type DP_Caps is record
Rev : Word8;
Max_Link_Rate : DP_Bandwidth;
Max_Lane_Count : DP_Lane_Count;
TPS3_Supported : Boolean;
Enhanced_Framing : Boolean;
No_Aux_Handshake : Boolean;
Aux_RD_Interval : Word8;
end record;
type DP_Link is
record
Receiver_Caps : DP_Caps;
Lane_Count : DP_Lane_Count;
Bandwidth : DP_Bandwidth;
Enhanced_Framing : Boolean;
Opportunistic_Training : Boolean;
end record;
Default_DP : constant DP_Link := DP_Link'
(Receiver_Caps => DP_Caps'
(Rev => 16#00#,
Max_Link_Rate => DP_Bandwidth'First,
Max_Lane_Count => DP_Lane_Count'First,
TPS3_Supported => False,
Enhanced_Framing => False,
No_Aux_Handshake => False,
Aux_RD_Interval => 16#00#),
Lane_Count => DP_Lane_Count'First,
Bandwidth => DP_Bandwidth'First,
Enhanced_Framing => False,
Opportunistic_Training => False);
type Display_Type is (None, LVDS, DP, HDMI, VGA);
subtype Internal_Type is Display_Type range None .. DP;
type Mode_Type is
record
Dotclock : Frequency_Type;
H_Visible : Pos16;
H_Sync_Begin : Pos16;
H_Sync_End : Pos16;
H_Total : Pos16;
V_Visible : Pos16;
V_Sync_Begin : Pos16;
V_Sync_End : Pos16;
V_Total : Pos16;
H_Sync_Active_High : Boolean;
V_Sync_Active_High : Boolean;
BPC : BPC_Type;
end record;
----------------------------------------------------------------------------
-- Constants
----------------------------------------------------------------------------
-- modeline constants
-- Dotclock is calculated using: Refresh_Rate * H_Total * V_Total
M2560x1600_60 : constant Mode_Type := Mode_Type'
(60*(2720*1646), 2560, 2608, 2640, 2720, 1600, 1603, 1609, 1646, True, True, Auto_BPC);
M2560x1440_60 : constant Mode_Type := Mode_Type'
(60*(2720*1481), 2560, 2608, 2640, 2720, 1440, 1443, 1448, 1481, True, False, Auto_BPC);
M1920x1200_60 : constant Mode_Type := Mode_Type'
(60*(2080*1235), 1920, 1968, 2000, 2080, 1200, 1203, 1209, 1235, False, False, Auto_BPC);
M1920x1080_60 : constant Mode_Type := Mode_Type'
(60*(2185*1135), 1920, 2008, 2052, 2185, 1080, 1084, 1089, 1135, False, False, Auto_BPC);
M1680x1050_60 : constant Mode_Type := Mode_Type'
(60*(2256*1087), 1680, 1784, 1968, 2256, 1050, 1051, 1054, 1087, False, True, Auto_BPC);
M1600x1200_60 : constant Mode_Type := Mode_Type'
(60*(2160*1250), 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, True, True, Auto_BPC);
M1600x900_60 : constant Mode_Type := Mode_Type'
(60*(2010*912), 1600, 1664, 1706, 2010, 900, 903, 906, 912, False, False, Auto_BPC);
M1440x900_60 : constant Mode_Type := Mode_Type'
(60*(1834*920), 1440, 1488, 1520, 1834, 900, 903, 909, 920, False, False, Auto_BPC);
M1366x768_60 : constant Mode_Type := Mode_Type'
(60*(1446*788), 1366, 1414, 1446, 1466, 768, 769, 773, 788, False, False, Auto_BPC);
M1280x1024_60 : constant Mode_Type := Mode_Type'
(60*(1712*1063), 1280, 1368, 1496, 1712, 1024, 1027, 1034, 1063, False, True, Auto_BPC);
M1024x768_60 : constant Mode_Type := Mode_Type'
(60*(1344*806), 1024, 1048, 1184, 1344, 768, 771, 777, 806, False, False, Auto_BPC);
Invalid_Mode : constant Mode_Type := Mode_Type'
(Frequency_Type'First, 1, 1, 1, 1, 1, 1, 1, 1, False, False, Auto_BPC);
private
function Rotation_90 (FB : Framebuffer_Type) return Boolean is
(FB.Rotation = Rotated_90 or FB.Rotation = Rotated_270);
function Rotated_Width (FB : Framebuffer_Type) return Pos16 is
(if Rotation_90 (FB) then Pos16 (FB.Height) else Pos16 (FB.Width));
function Rotated_Height (FB : Framebuffer_Type) return Pos16 is
(if Rotation_90 (FB) then Pos16 (FB.Width) else Pos16 (FB.Height));
function Pixel_To_Bytes (Pixel : Pixel_Type; FB : Framebuffer_Type)
return Int32 is (Pixel * Pos32 (FB.BPC) / (8 / 4));
function FB_Size (FB : Framebuffer_Type) return Pos32 is
(Pixel_To_Bytes (FB.Stride * FB.V_Stride, FB));
function Requires_Scaling (FB : Framebuffer_Type; Mode : Mode_Type)
return Boolean is
(Rotated_Width (FB) /= Mode.H_Visible or
Rotated_Height (FB) /= Mode.V_Visible);
type Scaling_Aspect is (Uniform, Letterbox, Pillarbox);
function Scaling_Type (FB : Framebuffer_Type; Mode : Mode_Type)
return Scaling_Aspect is
(if Pos32 (Mode.H_Visible) * Pos32 (Rotated_Height (FB)) <
Pos32 (Mode.V_Visible) * Pos32 (Rotated_Width (FB))
then
Letterbox
elsif Pos32 (Mode.H_Visible) * Pos32 (Rotated_Height (FB)) >
Pos32 (Mode.V_Visible) * Pos32 (Rotated_Width (FB))
then
Pillarbox
else
Uniform);
end HW.GFX;
|
-- FastAPI
-- No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
--
-- The version of the OpenAPI document: 0.1.0
--
--
-- NOTE: This package is auto generated by OpenAPI-Generator 4.0.0.
-- https://openapi-generator.tech
-- Do not edit the class manually.
with .Models;
with Swagger.Clients;
package .Clients is
type Client_Type is new Swagger.Clients.Client_Type with null record;
-- Read Users
procedure Read_Users_Image_Image_Uncolorization_Users_Get
(Client : in out Client_Type;
Result : out Swagger.Object);
-- Root
procedure Root_Get
(Client : in out Client_Type;
Result : out Swagger.Object);
-- Read User
procedure Read_User_Image_Image_Uncolorization_Users_Username_Post
(Client : in out Client_Type;
Username : in Swagger.UString;
Result : out Swagger.Object);
-- Read User Me
procedure Read_User_Me_Image_Image_Uncolorization_Users_Me_Get
(Client : in out Client_Type;
Result : out Swagger.Object);
end .Clients;
|
with Giza.Timers;
package body Giza.Widget.Number_Selection is
---------------
-- Triggered --
---------------
overriding
function Triggered (This : Repeat_Event) return Boolean is
Reset : Boolean := False;
begin
if This.Nbr = null then
return False;
end if;
if This.Nbr.Plus /= null and then This.Nbr.Plus.Active then
This.Nbr.Do_Plus;
Reset := True;
elsif This.Nbr.Minus /= null and then This.Nbr.Minus.Active then
This.Nbr.Do_Minus;
Reset := True;
end if;
if Reset then
-- Reset timer
Giza.Timers.Set_Timer (This'Unchecked_Access,
Clock + This.Nbr.Repeat_Time);
end if;
return Reset;
end Triggered;
---------------
-- Set_Dirty --
---------------
overriding
procedure Set_Dirty (This : in out Instance;
Dirty : Boolean := True)
is
begin
This.Root.Set_Dirty (Dirty);
end Set_Dirty;
----------
-- Draw --
----------
overriding procedure Draw
(This : in out Instance;
Ctx : in out Context.Class;
Force : Boolean := True)
is
W1, W2, H1 : Integer;
Value_Rect, Lable_Rect : Rect_T;
begin
-- 0 W1 W2 W
-- +---------+-------------------------------------------+---------+
-- | |
-- | Value |
-- | |
-- +---------+-------------------------------------------+---------+ H1
-- | | | | |
-- | ----- | Label | ----- |
-- | | | | |
-- +---------+-------------------------------------------+---------+
H1 := (if This.Show_Value then This.Get_Size.H / 2 else 0);
W1 := This.Get_Size.H - H1;
W2 := This.Get_Size.W - W1;
Lable_Rect := ((W1 + 1, H1),
(W2 - W1 - 2, W1));
if not This.Init then
This.Init := True;
This.Root.Set_Size (This.Get_Size);
This.Minus := new Button.Instance;
This.Minus.Set_Text ("-");
This.Minus.Set_Size ((W1, W1));
This.Root.Add_Child (This.Minus, (0, H1));
This.Plus := new Button.Instance;
This.Plus.Set_Text ("+");
This.Plus.Set_Size ((W1, W1));
This.Root.Add_Child (This.Plus, (W2, H1));
end if;
if This.Dirty or else Force then
if This.Show_Value then
Value_Rect := ((0, 0), (This.Get_Size.W, H1 - 1));
declare
Str : constant String := This.Value'Img;
begin
Ctx.Set_Color (This.Get_Background);
Ctx.Fill_Rectangle (Value_Rect);
Ctx.Set_Color (This.Get_Foreground);
Ctx.Print_In_Rect (Str, Value_Rect);
end;
end if;
if This.Str /= null then
Ctx.Set_Color (This.Get_Background);
Ctx.Fill_Rectangle (Lable_Rect);
Ctx.Set_Color (This.Get_Foreground);
Ctx.Print_In_Rect (This.Str.all, Lable_Rect);
end if;
end if;
This.Root.Draw (Ctx, Force);
end Draw;
-----------------------
-- On_Position_Event --
-----------------------
overriding function On_Position_Event
(This : in out Instance;
Evt : Position_Event_Ref;
Pos : Point_T) return Boolean
is
begin
if This.Root.On_Position_Event (Evt, Pos) then
if This.Plus /= null and then This.Plus.Active then
This.Do_Plus;
elsif This.Minus /= null and then This.Minus.Active then
This.Do_Minus;
end if;
This.Repeat_Evt.Nbr := This'Unchecked_Access;
Giza.Timers.Set_Timer
(This.Repeat_Evt'Unchecked_Access, Clock + This.Repeat_Time);
return True;
else
return False;
end if;
end On_Position_Event;
--------------
-- On_Event --
--------------
overriding
function On_Event
(This : in out Instance;
Evt : Event_Not_Null_Ref) return Boolean is
begin
return This.Root.On_Event (Evt);
end On_Event;
---------------
-- Set_Value --
---------------
procedure Set_Value (This : in out Instance; Val : Integer) is
begin
This.Value := Val;
This.Set_Dirty;
end Set_Value;
--------------
-- Set_Step --
--------------
procedure Set_Step (This : in out Instance; Step : Integer) is
begin
This.Step := Step;
end Set_Step;
-------------
-- Set_Min --
-------------
procedure Set_Min (This : in out Instance; Min : Integer) is
begin
This.Min := Min;
end Set_Min;
-------------
-- Set_Max --
-------------
procedure Set_Max (This : in out Instance; Max : Integer) is
begin
This.Max := Max;
end Set_Max;
-----------
-- Value --
-----------
function Value (This : Instance) return Integer is
begin
return This.Value;
end Value;
---------------
-- Set_Label --
---------------
procedure Set_Label (This : in out Instance; Label : String) is
begin
This.Str := new String'(Label);
end Set_Label;
----------------
-- Show_Value --
----------------
procedure Show_Value (This : in out Instance;
Show : Boolean := True)
is
begin
This.Show_Value := Show;
end Show_Value;
-------------
-- Do_Plus --
-------------
procedure Do_Plus (This : in out Instance) is
begin
This.Value := This.Value + This.Step;
if This.Value > This.Max then
This.Value := This.Max;
end if;
end Do_Plus;
--------------
-- Do_Minus --
--------------
procedure Do_Minus (This : in out Instance) is
begin
This.Value := This.Value - This.Step;
if This.Value < This.Min then
This.Value := This.Min;
end if;
end Do_Minus;
end Giza.Widget.Number_Selection;
|
-----------------------------------------------------------------------
-- mat-consoles-text - Text console interface
-- Copyright (C) 2014 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- 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 Ada.Text_IO;
with Gtk.Enums;
with Gtk.Tree_View_Column;
with Util.Log.Loggers;
package body MAT.Consoles.Gtkmat is
-- The logger
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("MAT.Consoles.Gtkmat");
-- ------------------------------
-- Initialize the console to display the result in the Gtk frame.
-- ------------------------------
procedure Initialize (Console : in out Console_Type;
Frame : in Gtk.Frame.Gtk_Frame) is
begin
Gtk.Scrolled_Window.Gtk_New (Console.Scrolled);
Gtk.Cell_Renderer_Text.Gtk_New (Console.Col_Text);
Console.Scrolled.Set_Policy (Gtk.Enums.Policy_Always, Gtk.Enums.Policy_Always);
Console.Frame := Frame;
Console.Frame.Add (Console.Scrolled);
Console.Col_Text.Ref;
-- Console.Frame.Show_All;
end Initialize;
-- Report a notice message.
overriding
procedure Notice (Console : in out Console_Type;
Kind : in Notice_Type;
Message : in String) is
begin
null;
end Notice;
-- Report an error message.
overriding
procedure Error (Console : in out Console_Type;
Message : in String) is
begin
null;
end Error;
-- Print the field value for the given field.
overriding
procedure Print_Field (Console : in out Console_Type;
Field : in Field_Type;
Value : in String;
Justify : in Justify_Type := J_LEFT) is
begin
Log.Debug ("Field {0} - {1}", Field_Type'Image (Field), Value);
Gtk.Tree_Store.Set (Console.List, Console.Current_Row, Console.Indexes (Field), Value);
end Print_Field;
-- Print the title for the given field.
overriding
procedure Print_Title (Console : in out Console_Type;
Field : in Field_Type;
Title : in String) is
Pos : constant Positive := Console.Field_Count;
begin
Console.Indexes (Field) := Glib.Gint (Pos - 1);
Console.Columns (Pos).Field := Field;
Console.Columns (Pos).Title := Ada.Strings.Unbounded.To_Unbounded_String (Title);
end Print_Title;
-- Start a new title in a report.
overriding
procedure Start_Title (Console : in out Console_Type) is
begin
Console.Field_Count := 0;
Console.Sizes := (others => 0);
Console.Cols := (others => 1);
Console.Indexes := (others => 0);
end Start_Title;
-- Finish a new title in a report.
procedure End_Title (Console : in out Console_Type) is
use type Glib.Guint;
use type Glib.Gint;
use type Gtk.Tree_View.Gtk_Tree_View;
use Gtk.Tree_Store;
Types : Glib.GType_Array (0 .. Glib.Guint (Console.Field_Count) - 1)
:= (others => Glib.GType_String);
Col : Gtk.Tree_View_Column.Gtk_Tree_View_Column;
Num : Glib.Gint;
begin
Gtk.Tree_Store.Gtk_New (Console.List, Types);
if Console.Tree /= null then
Console.Tree.Destroy;
end if;
-- Gtk.Tree_View.Gtk_New (Console.Tree, +Console.List);
Gtk.Tree_View.Gtk_New (Console.Tree);
for I in 1 .. Console.Field_Count loop
Gtk.Tree_View_Column.Gtk_New (Col);
Num := Console.Tree.Append_Column (Col);
Col.Set_Sort_Column_Id (Glib.Gint (I) - 1);
Col.Set_Title (Ada.Strings.Unbounded.To_String (Console.Columns (I).Title));
Col.Pack_Start (Console.Col_Text, True);
Col.Set_Sizing (Gtk.Tree_View_Column.Tree_View_Column_Autosize);
Col.Add_Attribute (Console.Col_Text, "text", Glib.Gint (I) - 1);
end loop;
-- Console.Tree.Set_Model (Gtk.Tree_Model.Gtk_Tree_Model (Console.List));
Console.Scrolled.Add (Console.Tree);
Console.Scrolled.Show_All;
end End_Title;
-- Start a new row in a report.
overriding
procedure Start_Row (Console : in out Console_Type) is
begin
Console.List.Append (Console.Current_Row, Gtk.Tree_Model.Null_Iter);
end Start_Row;
-- Finish a new row in a report.
overriding
procedure End_Row (Console : in out Console_Type) is
begin
null;
end End_Row;
end MAT.Consoles.Gtkmat;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . T H R E A D S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This is the VxWorks 653 version of this package
pragma Restrictions (No_Tasking);
-- The VxWorks 653 version of this package is intended only for programs
-- which do not use Ada tasking. This restriction ensures that this
-- will be checked by the binder.
with System.Storage_Elements; use System.Storage_Elements;
with System.OS_Versions; use System.OS_Versions;
package body System.Threads is
use Interfaces.C;
package SSL renames System.Soft_Links;
Main_ATSD : aliased ATSD;
-- TSD for environment task
Current_ATSD : aliased System.Address := System.Null_Address;
pragma Thread_Local_Storage (Current_ATSD);
-- pragma TLS needed since TaskVarAdd no longer available
-- Assume guard pages for Helix APEX partitions, but leave
-- checking mechanism in for now, in case of surprises. ???
Stack_Limit : Address;
pragma Import (C, Stack_Limit, "__gnat_stack_limit");
type Set_Stack_Limit_Proc_Acc is access procedure;
pragma Convention (C, Set_Stack_Limit_Proc_Acc);
Set_Stack_Limit_Hook : Set_Stack_Limit_Proc_Acc;
pragma Import (C, Set_Stack_Limit_Hook, "__gnat_set_stack_limit_hook");
-- Procedure to be called when a task is created to set stack limit if
-- limit checking is used.
-- VxWorks specific API
ERROR : constant STATUS := Interfaces.C.int (-1);
OK : constant STATUS := Interfaces.C.int (0);
function taskIdVerify (tid : t_id) return STATUS;
pragma Import (C, taskIdVerify, "taskIdVerify");
function taskIdSelf return t_id;
pragma Import (C, taskIdSelf, "taskIdSelf");
-----------------------
-- Local Subprograms --
-----------------------
procedure Init_RTS;
-- This procedure performs the initialization of the run-time lib.
-- It installs System.Threads versions of certain operations of the
-- run-time lib.
procedure Install_Handler;
pragma Import (C, Install_Handler, "__gnat_install_handler");
function Get_Sec_Stack return SST.SS_Stack_Ptr;
procedure Set_Sec_Stack (Stack : SST.SS_Stack_Ptr);
-----------------------
-- Thread_Body_Enter --
-----------------------
procedure Thread_Body_Enter
(Sec_Stack_Ptr : SST.SS_Stack_Ptr;
Process_ATSD_Address : System.Address)
is
ATSD : constant ATSD_Access := From_Address (Process_ATSD_Address);
begin
ATSD.Sec_Stack_Ptr := Sec_Stack_Ptr;
SST.SS_Init (ATSD.Sec_Stack_Ptr);
Current_ATSD := Process_ATSD_Address;
Install_Handler;
-- Assume guard pages for Helix/Vx7, but leave in for now ???
-- Initialize stack limit if needed.
if Current_ATSD /= Main_ATSD'Address
and then Set_Stack_Limit_Hook /= null
then
Set_Stack_Limit_Hook.all;
end if;
end Thread_Body_Enter;
----------------------------------
-- Thread_Body_Exceptional_Exit --
----------------------------------
procedure Thread_Body_Exceptional_Exit
(EO : Ada.Exceptions.Exception_Occurrence)
is
pragma Unreferenced (EO);
begin
-- No action for this target
null;
end Thread_Body_Exceptional_Exit;
-----------------------
-- Thread_Body_Leave --
-----------------------
procedure Thread_Body_Leave is
begin
-- No action for this target
null;
end Thread_Body_Leave;
--------------
-- Init_RTS --
--------------
procedure Init_RTS is
-- Register environment task
Result : constant Interfaces.C.int := Register (taskIdSelf);
pragma Assert (Result /= ERROR);
begin
Main_ATSD.Sec_Stack_Ptr := SSL.Get_Sec_Stack_NT;
Current_ATSD := Main_ATSD'Address;
Install_Handler;
SSL.Get_Sec_Stack := Get_Sec_Stack'Access;
SSL.Set_Sec_Stack := Set_Sec_Stack'Access;
end Init_RTS;
-------------------
-- Get_Sec_Stack --
-------------------
function Get_Sec_Stack return SST.SS_Stack_Ptr is
CTSD : constant ATSD_Access := From_Address (Current_ATSD);
begin
pragma Assert (CTSD /= null);
return CTSD.Sec_Stack_Ptr;
end Get_Sec_Stack;
--------------
-- Register --
--------------
function Register (T : Thread_Id) return STATUS is
begin
-- It cannot be assumed that the caller of this routine has a ATSD;
-- so neither this procedure nor the procedures that it calls should
-- raise or handle exceptions, or make use of a secondary stack.
if taskIdVerify (T) = ERROR then
return ERROR;
end if;
Current_ATSD := To_Address (Integer_Address (T));
-- The same issue applies to the task variable that contains the stack
-- limit when that overflow checking mechanism is used instead of
-- probing. If stack checking is enabled and limit checking is used,
-- allocate the limit for this task. The environment task has this
-- initialized by the binder-generated main when
-- System.Stack_Check_Limits = True.
pragma Warnings (Off);
-- OS is a constant
if OS /= VxWorks_653 and then Set_Stack_Limit_Hook /= null then
-- Check that this is correct if limit checking left in. ???
Stack_Limit := To_Address (Integer_Address (T));
end if;
pragma Warnings (On);
return OK;
end Register;
-------------------
-- Set_Sec_Stack --
-------------------
procedure Set_Sec_Stack (Stack : SST.SS_Stack_Ptr) is
CTSD : constant ATSD_Access := From_Address (Current_ATSD);
begin
pragma Assert (CTSD /= null);
CTSD.Sec_Stack_Ptr := Stack;
end Set_Sec_Stack;
begin
-- Initialize run-time library
Init_RTS;
end System.Threads;
|
with unav;
with Units; use Units;
with Text_IO; use Text_IO;
procedure main with SPARK_Mode is
distance : Length_Type;
begin
distance := unav.Get_Distance;
Put_Line ("distance=" & Float'Image(Float(distance)) & " m");
end main;
|
with DDS.Topic;
with DDS.Entity_Params;
with DDS.Request_Reply.impl;
package DDS.Request_Reply.Replier.Impl is
type Ref is limited new DDS.Request_Reply.Impl.Ref and Replier.Ref with private;
type Ref_Access is access all Ref;
function Create_Writer_Topic
(Self : not null access Ref;
Params : DDS.Entity_Params.EntityParams;
Name : DDS.String) return DDS.Topic.Ref_Access;
function Create_Reader_Topic
(Self : not null access Ref;
Params : DDS.Entity_Params.EntityParams;
Name : DDS.String) return DDS.Topic.Ref_Access;
procedure Wait_For_Requests
(Self : not null access Ref;
Min_Count : DDS.Integer;
Max_Wait : DDS.Duration_T);
private
type Ref is limited new DDS.Request_Reply.Impl.Ref and Replier.Ref with record
null;
end record;
end DDS.Request_Reply.Replier.Impl;
|
with Ada.Text_IO, Digraphs, Set_Of_Names, Ada.Command_Line;
procedure Toposort is
-- shortcuts for package names, intantiation of generic package
package TIO renames Ada.Text_IO;
package DG renames Digraphs;
package SN is new Set_Of_Names(DG.Node_Idx_With_Null);
-- reat the graph from the file with the given Filename
procedure Read(Filename: String; G: out DG.Graph_Type; N: out SN.Set) is
-- finds the first word in S(Start .. S'Last), delimited by spaces
procedure Find_Token(S: String; Start: Positive;
First: out Positive; Last: out Natural) is
begin
First := Start;
while First <= S'Last and then S(First)= ' ' loop
First := First + 1;
end loop;
Last := First-1;
while Last < S'Last and then S(Last+1) /= ' ' loop
Last := Last + 1;
end loop;
end Find_Token;
File: TIO.File_Type;
begin
TIO.Open(File, TIO.In_File, Filename);
TIO.Skip_Line(File, 2);
-- the first two lines contain header and "===...==="
while not TIO.End_Of_File(File) loop
declare
Line: String := TIO.Get_Line(File);
First: Positive;
Last: Natural;
To, From: DG.Node_Index;
begin
Find_Token(Line, Line'First, First, Last);
if Last >= First then
N.Add(Line(First .. Last), From);
G.Add_Node(From);
loop
Find_Token(Line, Last+1, First, Last);
exit when Last < First;
N.Add(Line(First .. Last), To);
G.Add_Connection(From, To);
end loop;
end if;
end;
end loop;
TIO.Close(File);
end Read;
Graph: DG.Graph_Type;
Names: SN.Set;
begin
Read(Ada.Command_Line.Argument(1), Graph, Names);
-- eliminat self-cycles
for Start in 1 .. Graph.Node_Count loop
Graph.Del_Connection(Start, Start);
end loop;
-- perform the topological sort and output the result
declare
Result: DG.Node_Vec.Vector;
begin
Result := Graph.Top_Sort;
for Index in Result.First_Index .. Result.Last_Index loop
TIO.Put(Names.Name(Result.Element(Index)));
if Index < Result.Last_Index then
TIO.Put(" -> ");
end if;
end loop;
TIO.New_Line;
exception
when DG.Graph_Is_Cyclic =>
TIO.Put_Line("There is no topological sorting -- the Graph is cyclic!");
end;
end Toposort;
|
with Ada.Numerics.Generic_Elementary_Functions;
package body Pythagorean_Means is
package Math is new Ada.Numerics.Generic_Elementary_Functions (Float);
function "**" (Left, Right : Float) return Float renames Math."**";
function Arithmetic_Mean (Data : Set) return Float is
Sum : Float := 0.0;
begin
for I in Data'Range loop
Sum := Sum + Data (I);
end loop;
return Sum / Float (Data'Length);
end Arithmetic_Mean;
function Geometric_Mean (Data : Set) return Float is
Product : Float := 1.0;
begin
for I in Data'Range loop
Product := Product * Data (I);
end loop;
return Product**(1.0/Float(Data'Length));
end Geometric_Mean;
function Harmonic_Mean (Data : Set) return Float is
Reciprocal_Sum : Float := 0.0;
begin
for I in Data'Range loop
Reciprocal_Sum := Reciprocal_Sum + Data (I)**(-1);
end loop;
return Float (Data'Length) / Reciprocal_Sum;
end Harmonic_Mean;
end Pythagorean_Means;
|
-- CC1111A.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- OBJECTIVE:
-- CHECK THAT AFTER A GENERIC UNIT IS INSTANTIATED, THE SUBTYPE OF
-- AN IN OUT OBJECT PARAMETER IS DETERMINED BY THE ACTUAL PARAMETER
-- (TESTS INTEGER, ENUMERATION, FLOATING POINT, FIXED POINT, ARRAY,
-- ACCESS, AND DISCRIMINATED TYPES).
-- HISTORY:
-- BCB 03/28/88 CREATED ORIGINAL TEST.
-- PWN 01/31/95 REMOVED INCONSISTENCIES WITH ADA 9X.
WITH REPORT; USE REPORT;
PROCEDURE CC1111A IS
SUBTYPE INT IS INTEGER RANGE 0..5;
INTVAR : INTEGER RANGE 1..3;
TYPE ENUM IS (ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT);
SUBTYPE SUBENUM IS ENUM RANGE ONE .. FIVE;
ENUMVAR : ENUM RANGE TWO .. THREE;
TYPE FLT IS DIGITS 5 RANGE -5.0 .. 5.0;
SUBTYPE SUBFLT IS FLT RANGE -1.0 .. 1.0;
FLTVAR : FLT RANGE 0.0 .. 1.0;
TYPE FIX IS DELTA 0.5 RANGE -5.0 .. 5.0;
SUBTYPE SUBFIX IS FIX RANGE -1.0 .. 1.0;
FIXVAR : FIX RANGE 0.0 .. 1.0;
SUBTYPE STR IS STRING (1..10);
STRVAR : STRING (1..5);
TYPE REC (DISC : INTEGER := 5) IS RECORD
NULL;
END RECORD;
SUBTYPE SUBREC IS REC (6);
RECVAR : REC(5);
SUBRECVAR : SUBREC;
TYPE ACCREC IS ACCESS REC;
SUBTYPE A1 IS ACCREC(1);
SUBTYPE A2 IS ACCREC(2);
A1VAR : A1 := NEW REC(1);
A2VAR : A2 := NEW REC(2);
PACKAGE P IS
TYPE PRIV IS PRIVATE;
PRIVATE
TYPE PRIV IS RANGE 1 .. 100;
SUBTYPE SUBPRIV IS PRIV RANGE 5 .. 10;
PRIVVAR : PRIV RANGE 8 .. 10;
END P;
PACKAGE BODY P IS
FUNCTION PRIVEQUAL (ONE, TWO : SUBPRIV) RETURN BOOLEAN;
FUNCTION PRIVEQUAL (ONE, TWO : SUBPRIV) RETURN BOOLEAN IS
BEGIN
RETURN ONE = TWO;
END PRIVEQUAL;
GENERIC
INPUT : SUBPRIV;
OUTPUT : IN OUT SUBPRIV;
PROCEDURE I;
PROCEDURE I IS
BEGIN
OUTPUT := INPUT;
FAILED ("SUBTYPE NOT DETERMINED BY ACTUAL PARAMETER - " &
"PRIVATE TYPE");
IF PRIVEQUAL (OUTPUT, OUTPUT) THEN
COMMENT ("DON'T OPTIMIZE OUTPUT");
END IF;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
FAILED ("WRONG EXCEPTION RAISED");
END I;
PROCEDURE I1 IS NEW I (5, PRIVVAR);
PROCEDURE I2 IS NEW I (SUBPRIV'FIRST, PRIVVAR);
BEGIN
TEST ("CC1111A", "CHECK THAT AFTER A GENERIC UNIT IS " &
"INSTANTIATED, THE SUBTYPE OF AN IN OUT " &
"OBJECT PARAMETER IS DETERMINED BY THE " &
"ACTUAL PARAMETER (TESTS INTEGER, " &
"ENUMERATION, FLOATING POINT, FIXED POINT " &
", ARRAY, ACCESS, AND DISCRIMINATED TYPES)");
I1;
I2;
END P;
USE P;
GENERIC
TYPE GP IS PRIVATE;
FUNCTION GEN_IDENT (X : GP) RETURN GP;
GENERIC
INPUT : INT;
OUTPUT : IN OUT INT;
PROCEDURE B;
GENERIC
INPUT : SUBENUM;
OUTPUT : IN OUT SUBENUM;
PROCEDURE C;
GENERIC
INPUT : SUBFLT;
OUTPUT : IN OUT SUBFLT;
PROCEDURE D;
GENERIC
INPUT : SUBFIX;
OUTPUT : IN OUT SUBFIX;
PROCEDURE E;
GENERIC
INPUT : STR;
OUTPUT : IN OUT STR;
PROCEDURE F;
GENERIC
INPUT : A1;
OUTPUT : IN OUT A1;
PROCEDURE G;
GENERIC
INPUT : SUBREC;
OUTPUT : IN OUT SUBREC;
PROCEDURE H;
GENERIC
TYPE GP IS PRIVATE;
FUNCTION GENEQUAL (ONE, TWO : GP) RETURN BOOLEAN;
FUNCTION GENEQUAL (ONE, TWO : GP) RETURN BOOLEAN IS
BEGIN
RETURN ONE = TWO;
END GENEQUAL;
FUNCTION GEN_IDENT (X : GP) RETURN GP IS
BEGIN
RETURN X;
END GEN_IDENT;
FUNCTION INT_IDENT IS NEW GEN_IDENT (INT);
FUNCTION SUBENUM_IDENT IS NEW GEN_IDENT (SUBENUM);
FUNCTION SUBFLT_IDENT IS NEW GEN_IDENT (SUBFLT);
FUNCTION SUBFIX_IDENT IS NEW GEN_IDENT (SUBFIX);
FUNCTION ENUMEQUAL IS NEW GENEQUAL (SUBENUM);
FUNCTION FLTEQUAL IS NEW GENEQUAL (SUBFLT);
FUNCTION FIXEQUAL IS NEW GENEQUAL (SUBFIX);
FUNCTION STREQUAL IS NEW GENEQUAL (STR);
FUNCTION ACCEQUAL IS NEW GENEQUAL (A2);
FUNCTION RECEQUAL IS NEW GENEQUAL (REC);
PROCEDURE B IS
BEGIN
OUTPUT := INPUT;
FAILED ("SUBTYPE NOT DETERMINED BY ACTUAL PARAMETER - " &
"INTEGER TYPE");
IF EQUAL (OUTPUT, OUTPUT) THEN
COMMENT ("DON'T OPTIMIZE OUTPUT");
END IF;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
FAILED ("WRONG EXCEPTION RAISED");
END B;
PROCEDURE C IS
BEGIN
OUTPUT := INPUT;
FAILED ("SUBTYPE NOT DETERMINED BY ACTUAL PARAMETER - " &
"ENUMERATION TYPE");
IF ENUMEQUAL (OUTPUT, OUTPUT) THEN
COMMENT ("DON'T OPTIMIZE OUTPUT");
END IF;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
FAILED ("WRONG EXCEPTION RAISED");
END C;
PROCEDURE D IS
BEGIN
OUTPUT := INPUT;
FAILED ("SUBTYPE NOT DETERMINED BY ACTUAL PARAMETER - " &
"FLOATING POINT TYPE");
IF FLTEQUAL (OUTPUT, OUTPUT) THEN
COMMENT ("DON'T OPTIMIZE OUTPUT");
END IF;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
FAILED ("WRONG EXCEPTION RAISED");
END D;
PROCEDURE E IS
BEGIN
OUTPUT := INPUT;
FAILED ("SUBTYPE NOT DETERMINED BY ACTUAL PARAMETER - " &
"FIXED POINT TYPE");
IF FIXEQUAL (OUTPUT, OUTPUT) THEN
COMMENT ("DON'T OPTIMIZE OUTPUT");
END IF;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
FAILED ("WRONG EXCEPTION RAISED");
END E;
PROCEDURE F IS
BEGIN
OUTPUT := INPUT;
FAILED ("SUBTYPE NOT DETERMINED BY ACTUAL PARAMETER - " &
"ARRAY TYPE");
IF STREQUAL (OUTPUT, OUTPUT) THEN
COMMENT ("DON'T OPTIMIZE OUTPUT");
END IF;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
FAILED ("WRONG EXCEPTION RAISED");
END F;
PROCEDURE G IS
BEGIN
OUTPUT := INPUT;
FAILED ("SUBTYPE NOT DETERMINED BY ACTUAL PARAMETER - " &
"ACCESS TYPE");
IF ACCEQUAL (OUTPUT, OUTPUT) THEN
COMMENT ("DON'T OPTIMIZE OUTPUT");
END IF;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
FAILED ("WRONG EXCEPTION RAISED");
END G;
PROCEDURE H IS
BEGIN
OUTPUT := INPUT;
FAILED ("SUBTYPE NOT DETERMINED BY ACTUAL PARAMETER - " &
"DISCRIMINATED RECORD TYPE");
IF RECEQUAL (OUTPUT, OUTPUT) THEN
COMMENT ("DON'T OPTIMIZE OUTPUT");
END IF;
EXCEPTION
WHEN CONSTRAINT_ERROR =>
NULL;
WHEN OTHERS =>
FAILED ("WRONG EXCEPTION RAISED");
END H;
PROCEDURE B1 IS NEW B (4, INTVAR);
PROCEDURE C1 IS NEW C (FOUR, ENUMVAR);
PROCEDURE D1 IS NEW D (-1.0, FLTVAR);
PROCEDURE E1 IS NEW E (-1.0, FIXVAR);
PROCEDURE F1 IS NEW F ("9876543210", STRVAR);
PROCEDURE G1 IS NEW G (A1VAR, A2VAR);
PROCEDURE H1 IS NEW H (SUBRECVAR, RECVAR);
PROCEDURE B2 IS NEW B (INT_IDENT(INT'FIRST), INTVAR);
PROCEDURE C2 IS NEW C (SUBENUM_IDENT(SUBENUM'FIRST), ENUMVAR);
PROCEDURE D2 IS NEW D (SUBFLT_IDENT(SUBFLT'FIRST), FLTVAR);
PROCEDURE E2 IS NEW E (SUBFIX_IDENT(SUBFIX'FIRST), FIXVAR);
BEGIN
B1;
C1;
D1;
E1;
F1;
G1;
H1;
B2;
C2;
D2;
E2;
RESULT;
END CC1111A;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUNTIME COMPONENTS --
-- --
-- A D A . T A G S --
-- --
-- B o d y --
-- --
-- $Revision$
-- --
-- Copyright (C) 1992-2001 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 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. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Exceptions;
with Unchecked_Conversion;
with GNAT.HTable;
pragma Elaborate_All (GNAT.HTable);
package body Ada.Tags is
-- Structure of the GNAT Dispatch Table
-- +----------------------+
-- | TSD pointer ---|-----> Type Specific Data
-- +----------------------+ +-------------------+
-- | table of | | inheritance depth |
-- : primitive ops : +-------------------+
-- | pointers | | expanded name |
-- +----------------------+ +-------------------+
-- | external tag |
-- +-------------------+
-- | Hash table link |
-- +-------------------+
-- | Remotely Callable |
-- +-------------------+
-- | Rec Ctrler offset |
-- +-------------------+
-- | table of |
-- : ancestor :
-- | tags |
-- +-------------------+
use System;
subtype Cstring is String (Positive);
type Cstring_Ptr is access all Cstring;
type Tag_Table is array (Natural range <>) of Tag;
pragma Suppress_Initialization (Tag_Table);
type Wide_Boolean is (False, True);
for Wide_Boolean'Size use Standard'Address_Size;
type Type_Specific_Data is record
Idepth : Natural;
Expanded_Name : Cstring_Ptr;
External_Tag : Cstring_Ptr;
HT_Link : Tag;
Remotely_Callable : Wide_Boolean;
RC_Offset : SSE.Storage_Offset;
Ancestor_Tags : Tag_Table (Natural);
end record;
type Dispatch_Table is record
TSD : Type_Specific_Data_Ptr;
Prims_Ptr : Address_Array (Positive);
end record;
-------------------------------------------
-- Unchecked Conversions for Tag and TSD --
-------------------------------------------
function To_Type_Specific_Data_Ptr is
new Unchecked_Conversion (Address, Type_Specific_Data_Ptr);
function To_Address is new Unchecked_Conversion (Tag, Address);
function To_Address is
new Unchecked_Conversion (Type_Specific_Data_Ptr, Address);
---------------------------------------------
-- Unchecked Conversions for String Fields --
---------------------------------------------
function To_Cstring_Ptr is
new Unchecked_Conversion (Address, Cstring_Ptr);
function To_Address is
new Unchecked_Conversion (Cstring_Ptr, Address);
-----------------------
-- Local Subprograms --
-----------------------
function Length (Str : Cstring_Ptr) return Natural;
-- Length of string represented by the given pointer (treating the
-- string as a C-style string, which is Nul terminated).
-------------------------
-- External_Tag_HTable --
-------------------------
type HTable_Headers is range 1 .. 64;
-- The following internal package defines the routines used for
-- the instantiation of a new GNAT.HTable.Static_HTable (see
-- below). See spec in g-htable.ads for details of usage.
package HTable_Subprograms is
procedure Set_HT_Link (T : Tag; Next : Tag);
function Get_HT_Link (T : Tag) return Tag;
function Hash (F : Address) return HTable_Headers;
function Equal (A, B : Address) return Boolean;
end HTable_Subprograms;
package External_Tag_HTable is new GNAT.HTable.Static_HTable (
Header_Num => HTable_Headers,
Element => Dispatch_Table,
Elmt_Ptr => Tag,
Null_Ptr => null,
Set_Next => HTable_Subprograms.Set_HT_Link,
Next => HTable_Subprograms.Get_HT_Link,
Key => Address,
Get_Key => Get_External_Tag,
Hash => HTable_Subprograms.Hash,
Equal => HTable_Subprograms.Equal);
------------------------
-- HTable_Subprograms --
------------------------
-- Bodies of routines for hash table instantiation
package body HTable_Subprograms is
-----------
-- Equal --
-----------
function Equal (A, B : Address) return Boolean is
Str1 : Cstring_Ptr := To_Cstring_Ptr (A);
Str2 : Cstring_Ptr := To_Cstring_Ptr (B);
J : Integer := 1;
begin
loop
if Str1 (J) /= Str2 (J) then
return False;
elsif Str1 (J) = ASCII.NUL then
return True;
else
J := J + 1;
end if;
end loop;
end Equal;
-----------------
-- Get_HT_Link --
-----------------
function Get_HT_Link (T : Tag) return Tag is
begin
return T.TSD.HT_Link;
end Get_HT_Link;
----------
-- Hash --
----------
function Hash (F : Address) return HTable_Headers is
function H is new GNAT.HTable.Hash (HTable_Headers);
Str : Cstring_Ptr := To_Cstring_Ptr (F);
Res : constant HTable_Headers := H (Str (1 .. Length (Str)));
begin
return Res;
end Hash;
-----------------
-- Set_HT_Link --
-----------------
procedure Set_HT_Link (T : Tag; Next : Tag) is
begin
T.TSD.HT_Link := Next;
end Set_HT_Link;
end HTable_Subprograms;
--------------------
-- CW_Membership --
--------------------
-- Canonical implementation of Classwide Membership corresponding to:
-- Obj in Typ'Class
-- Each dispatch table contains a reference to a table of ancestors
-- (Ancestor_Tags) and a count of the level of inheritance "Idepth" .
-- Obj is in Typ'Class if Typ'Tag is in the table of ancestors that are
-- contained in the dispatch table referenced by Obj'Tag . Knowing the
-- level of inheritance of both types, this can be computed in constant
-- time by the formula:
-- Obj'tag.TSD.Ancestor_Tags (Obj'tag.TSD.Idepth - Typ'tag.TSD.Idepth)
-- = Typ'tag
function CW_Membership (Obj_Tag : Tag; Typ_Tag : Tag) return Boolean is
Pos : constant Integer := Obj_Tag.TSD.Idepth - Typ_Tag.TSD.Idepth;
begin
return Pos >= 0 and then Obj_Tag.TSD.Ancestor_Tags (Pos) = Typ_Tag;
end CW_Membership;
-------------------
-- Expanded_Name --
-------------------
function Expanded_Name (T : Tag) return String is
Result : Cstring_Ptr := T.TSD.Expanded_Name;
begin
return Result (1 .. Length (Result));
end Expanded_Name;
------------------
-- External_Tag --
------------------
function External_Tag (T : Tag) return String is
Result : Cstring_Ptr := T.TSD.External_Tag;
begin
return Result (1 .. Length (Result));
end External_Tag;
-----------------------
-- Get_Expanded_Name --
-----------------------
function Get_Expanded_Name (T : Tag) return Address is
begin
return To_Address (T.TSD.Expanded_Name);
end Get_Expanded_Name;
----------------------
-- Get_External_Tag --
----------------------
function Get_External_Tag (T : Tag) return Address is
begin
return To_Address (T.TSD.External_Tag);
end Get_External_Tag;
---------------------------
-- Get_Inheritance_Depth --
---------------------------
function Get_Inheritance_Depth (T : Tag) return Natural is
begin
return T.TSD.Idepth;
end Get_Inheritance_Depth;
-------------------------
-- Get_Prim_Op_Address --
-------------------------
function Get_Prim_Op_Address
(T : Tag;
Position : Positive)
return Address
is
begin
return T.Prims_Ptr (Position);
end Get_Prim_Op_Address;
-------------------
-- Get_RC_Offset --
-------------------
function Get_RC_Offset (T : Tag) return SSE.Storage_Offset is
begin
return T.TSD.RC_Offset;
end Get_RC_Offset;
---------------------------
-- Get_Remotely_Callable --
---------------------------
function Get_Remotely_Callable (T : Tag) return Boolean is
begin
return T.TSD.Remotely_Callable = True;
end Get_Remotely_Callable;
-------------
-- Get_TSD --
-------------
function Get_TSD (T : Tag) return Address is
begin
return To_Address (T.TSD);
end Get_TSD;
----------------
-- Inherit_DT --
----------------
procedure Inherit_DT
(Old_T : Tag;
New_T : Tag;
Entry_Count : Natural)
is
begin
if Old_T /= null then
New_T.Prims_Ptr (1 .. Entry_Count) :=
Old_T.Prims_Ptr (1 .. Entry_Count);
end if;
end Inherit_DT;
-----------------
-- Inherit_TSD --
-----------------
procedure Inherit_TSD (Old_TSD : Address; New_Tag : Tag) is
TSD : constant Type_Specific_Data_Ptr :=
To_Type_Specific_Data_Ptr (Old_TSD);
New_TSD : Type_Specific_Data renames New_Tag.TSD.all;
begin
if TSD /= null then
New_TSD.Idepth := TSD.Idepth + 1;
New_TSD.Ancestor_Tags (1 .. New_TSD.Idepth)
:= TSD.Ancestor_Tags (0 .. TSD.Idepth);
else
New_TSD.Idepth := 0;
end if;
New_TSD.Ancestor_Tags (0) := New_Tag;
end Inherit_TSD;
------------------
-- Internal_Tag --
------------------
function Internal_Tag (External : String) return Tag is
Ext_Copy : aliased String (External'First .. External'Last + 1);
Res : Tag;
begin
-- Make a copy of the string representing the external tag with
-- a null at the end
Ext_Copy (External'Range) := External;
Ext_Copy (Ext_Copy'Last) := ASCII.NUL;
Res := External_Tag_HTable.Get (Ext_Copy'Address);
if Res = null then
declare
Msg1 : constant String := "unknown tagged type: ";
Msg2 : String (1 .. Msg1'Length + External'Length);
begin
Msg2 (1 .. Msg1'Length) := Msg1;
Msg2 (Msg1'Length + 1 .. Msg1'Length + External'Length) :=
External;
Ada.Exceptions.Raise_Exception (Tag_Error'Identity, Msg2);
end;
end if;
return Res;
end Internal_Tag;
------------
-- Length --
------------
function Length (Str : Cstring_Ptr) return Natural is
Len : Integer := 1;
begin
while Str (Len) /= ASCII.Nul loop
Len := Len + 1;
end loop;
return Len - 1;
end Length;
-----------------
-- Parent_Size --
-----------------
-- Fake type with a tag as first component. Should match the
-- layout of all tagged types.
type T is record
A : Tag;
end record;
type T_Ptr is access all T;
function To_T_Ptr is new Unchecked_Conversion (Address, T_Ptr);
-- The profile of the implicitly defined _size primitive
type Acc_Size is access function (A : Address) return Long_Long_Integer;
function To_Acc_Size is new Unchecked_Conversion (Address, Acc_Size);
function Parent_Size (Obj : Address) return SSE.Storage_Count is
-- Get the tag of the object
Obj_Tag : constant Tag := To_T_Ptr (Obj).A;
-- Get the tag of the parent type through the dispatch table
Parent_Tag : constant Tag := Obj_Tag.TSD.Ancestor_Tags (1);
-- Get an access to the _size primitive of the parent. We assume that
-- it is always in the first slot of the distatch table
F : constant Acc_Size := To_Acc_Size (Parent_Tag.Prims_Ptr (1));
begin
-- Here we compute the size of the _parent field of the object
return SSE.Storage_Count (F.all (Obj));
end Parent_Size;
------------------
-- Register_Tag --
------------------
procedure Register_Tag (T : Tag) is
begin
External_Tag_HTable.Set (T);
end Register_Tag;
-----------------------
-- Set_Expanded_Name --
-----------------------
procedure Set_Expanded_Name (T : Tag; Value : Address) is
begin
T.TSD.Expanded_Name := To_Cstring_Ptr (Value);
end Set_Expanded_Name;
----------------------
-- Set_External_Tag --
----------------------
procedure Set_External_Tag (T : Tag; Value : Address) is
begin
T.TSD.External_Tag := To_Cstring_Ptr (Value);
end Set_External_Tag;
---------------------------
-- Set_Inheritance_Depth --
---------------------------
procedure Set_Inheritance_Depth
(T : Tag;
Value : Natural)
is
begin
T.TSD.Idepth := Value;
end Set_Inheritance_Depth;
-------------------------
-- Set_Prim_Op_Address --
-------------------------
procedure Set_Prim_Op_Address
(T : Tag;
Position : Positive;
Value : Address)
is
begin
T.Prims_Ptr (Position) := Value;
end Set_Prim_Op_Address;
-------------------
-- Set_RC_Offset --
-------------------
procedure Set_RC_Offset (T : Tag; Value : SSE.Storage_Offset) is
begin
T.TSD.RC_Offset := Value;
end Set_RC_Offset;
---------------------------
-- Set_Remotely_Callable --
---------------------------
procedure Set_Remotely_Callable (T : Tag; Value : Boolean) is
begin
if Value then
T.TSD.Remotely_Callable := True;
else
T.TSD.Remotely_Callable := False;
end if;
end Set_Remotely_Callable;
-------------
-- Set_TSD --
-------------
procedure Set_TSD (T : Tag; Value : Address) is
begin
T.TSD := To_Type_Specific_Data_Ptr (Value);
end Set_TSD;
end Ada.Tags;
|
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, not taking more than you give.
--
with Sessions;
with Parser_Data;
package Parser_FSM is
procedure Initialize_FSM (Session : in out Sessions.Session_Type;
Scanner : in out Parser_Data.Scanner_Record);
-- Initialize the parser finite state machine
procedure Do_State (Session : in out Sessions.Session_Type;
Scanner : in out Parser_Data.Scanner_Record;
Token : in String);
-- The parser state machine
end Parser_FSM;
|
-- POK header
--
-- The following file is a part of the POK project. Any modification should
-- be made according to the POK licence. You CANNOT use this file or a part
-- of a file for your own project.
--
-- For more information on the POK licence, please see our LICENCE FILE
--
-- Please follow the coding guidelines described in doc/CODING_GUIDELINES
--
-- Copyright (c) 2007-2020 POK team
-- This is a compilable Ada 95 specification for the APEX interface,
-- derived from section 3 of ARINC 653.
-- The declarations of the services given below are taken from the
-- standard, as are the enumerated types and the names of the others types.
-- However, the definitions given for these others types, and the
-- names and values given below for constants, are all implementation
-- specific.
-- All types have defining representation pragmas or clauses to ensure
-- representation compatibility with the C and Ada 83 bindings.
-- ---------------------------------------------------------------------------
-- --
-- Root package providing constant and type definitions --
-- --
-- ---------------------------------------------------------------------------
with System;
-- This is the Ada 95 predefined C interface package
with Interfaces.C;
package APEX is
pragma Pure;
-- ----------------------------
-- Domain limits --
-- ----------------------------
-- Domain dependent
-- These values define the domain limits and are implementation-dependent.
System_Limit_Number_Of_Partitions : constant := 32;
-- module scope
System_Limit_Number_Of_Messages : constant := 512;
-- module scope
System_Limit_Message_Size : constant := 16#10_0000#;
-- module scope
System_Limit_Number_Of_Processes : constant := 1024;
-- partition scope
System_Limit_Number_Of_Sampling_Ports : constant := 1024;
-- partition scope
System_Limit_Number_Of_Queuing_Ports : constant := 1024;
-- partition scope
System_Limit_Number_Of_Buffers : constant := 512;
-- partition scope
System_Limit_Number_Of_Blackboards : constant := 512;
-- partition scope
System_Limit_Number_Of_Semaphores : constant := 512;
-- partition scope
System_Limit_Number_Of_Events : constant := 512;
-- partition scope
-- ----------------------------
-- Base APEX types --
-- ----------------------------
-- The actual sizes of these base types are system-specific and must
-- match those of the underlying Operating System.
type APEX_Byte is new Interfaces.C.unsigned_char;
type APEX_Integer is new Interfaces.C.long;
type APEX_Unsigned is new Interfaces.C.unsigned_long;
type APEX_Long_Integer is new Interfaces.Integer_64;
-- If Integer_64 is not provided in package Interfaces, any implementation-
-- defined alternative 64-bit signed integer type may be used.
-- ----------------------------
-- General APEX types --
-- ----------------------------
type Return_Code_Type is (
No_Error, -- request valid and operation performed
No_Action, -- status of system unaffected by request
Not_Available, -- resource required by request unavailable
Invalid_Param, -- invalid parameter specified in request
Invalid_Config, -- parameter incompatible with configuration
Invalid_Mode, -- request incompatible with current mode
Timed_Out); -- time-out tied up with request has expired
pragma Convention (C, Return_Code_Type);
Max_Name_Length : constant := 30;
subtype Name_Type is String (1 .. Max_Name_Length);
subtype System_Address_Type is System.Address;
subtype Message_Addr_Type is System.Address;
subtype Message_Size_Type is APEX_Integer range
1 .. System_Limit_Message_Size;
subtype Message_Range_Type is APEX_Integer range
0 .. System_Limit_Number_Of_Messages;
type Port_Direction_Type is (Source, Destination);
pragma Convention (C, Port_Direction_Type);
type Queuing_Discipline_Type is (Fifo, Priority);
pragma Convention (C, Queuing_Discipline_Type);
subtype System_Time_Type is APEX_Long_Integer;
-- 64-bit signed integer with 1 nanosecond LSB
Infinite_Time_Value : constant System_Time_Type;
Aperiodic : constant System_Time_Type;
Zero_Time_Value : constant System_Time_Type;
private
Infinite_Time_Value : constant System_Time_Type := -1;
Aperiodic : constant System_Time_Type := 0;
Zero_Time_Value : constant System_Time_Type := 0;
end APEX;
|
-----------------------------------------------------------------------
-- gen-model -- Model for Code Generator
-- Copyright (C) 2009, 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- 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 Ada.Finalization;
with Ada.Strings.Unbounded;
with Util.Beans.Basic;
with Util.Beans.Objects;
with Util.Beans.Objects.Maps;
with DOM.Core;
package Gen.Model is
-- Exception raised if a name is already registered in the model.
-- This exception is raised if a table, an enum is already defined.
Name_Exist : exception;
-- ------------------------------
-- Model Definition
-- ------------------------------
type Definition is new Ada.Finalization.Limited_Controlled
and Util.Beans.Basic.Readonly_Bean with record
Row_Index : Natural;
Name : Ada.Strings.Unbounded.Unbounded_String;
Attrs : Util.Beans.Objects.Maps.Map_Bean;
Comment : Util.Beans.Objects.Object;
end record;
type Definition_Access is access all Definition'Class;
-- Prepare the generation of the model.
procedure Prepare (O : in out Definition) is null;
-- Get the object unique name.
function Get_Name (From : in Definition) return String;
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
function Get_Value (From : in Definition;
Name : in String) return Util.Beans.Objects.Object;
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
function Get_Attribute (From : in Definition;
Name : in String) return String;
-- Get the value identified by the name.
-- If the name cannot be found, the method should return the Null object.
function Get_Attribute (From : in Definition;
Name : in String) return Ada.Strings.Unbounded.Unbounded_String;
-- Set the comment associated with the element.
procedure Set_Comment (Def : in out Definition;
Comment : in String);
-- Initialize the definition from the DOM node attributes.
procedure Initialize (Def : in out Definition;
Name : in Ada.Strings.Unbounded.Unbounded_String;
Node : in DOM.Core.Node);
end Gen.Model;
|
with Project_Processor.Processors;
with Project_Processor.Parsers;
package Project_Processor.Configuration is
procedure Initialize;
type Processing_Call is
record
Name : Processors.Processor_ID;
Parameters : Processors.Processor_Parameter_Access;
end record;
procedure For_All_Calls
(Callback : not null access procedure (Call : Processing_Call));
function Input_Data return String;
function Input_Format return Parsers.Parser_ID;
function Parser_Parameters return Parsers.Parser_Parameter_Access;
Bad_Command_Line : exception;
end Project_Processor.Configuration;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . A U X _ D E C --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2009, 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. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
pragma Style_Checks (All_Checks);
-- Turn off alpha ordering check on subprograms, this unit is laid
-- out to correspond to the declarations in the DEC 83 System unit.
with System.Soft_Links;
package body System.Aux_DEC is
package SSL renames System.Soft_Links;
-----------------------------------
-- Operations on Largest_Integer --
-----------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type LIU is mod 2 ** Largest_Integer'Size;
-- Unsigned type of same length as Largest_Integer
function To_LI is new Ada.Unchecked_Conversion (LIU, Largest_Integer);
function From_LI is new Ada.Unchecked_Conversion (Largest_Integer, LIU);
function "not" (Left : Largest_Integer) return Largest_Integer is
begin
return To_LI (not From_LI (Left));
end "not";
function "and" (Left, Right : Largest_Integer) return Largest_Integer is
begin
return To_LI (From_LI (Left) and From_LI (Right));
end "and";
function "or" (Left, Right : Largest_Integer) return Largest_Integer is
begin
return To_LI (From_LI (Left) or From_LI (Right));
end "or";
function "xor" (Left, Right : Largest_Integer) return Largest_Integer is
begin
return To_LI (From_LI (Left) xor From_LI (Right));
end "xor";
--------------------------------------
-- Arithmetic Operations on Address --
--------------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
Asiz : constant Integer := Integer (Address'Size) - 1;
type SA is range -(2 ** Asiz) .. 2 ** Asiz - 1;
-- Signed type of same size as Address
function To_A is new Ada.Unchecked_Conversion (SA, Address);
function From_A is new Ada.Unchecked_Conversion (Address, SA);
function "+" (Left : Address; Right : Integer) return Address is
begin
return To_A (From_A (Left) + SA (Right));
end "+";
function "+" (Left : Integer; Right : Address) return Address is
begin
return To_A (SA (Left) + From_A (Right));
end "+";
function "-" (Left : Address; Right : Address) return Integer is
pragma Unsuppress (All_Checks);
-- Because this can raise Constraint_Error for 64-bit addresses
begin
return Integer (From_A (Left) - From_A (Right));
end "-";
function "-" (Left : Address; Right : Integer) return Address is
begin
return To_A (From_A (Left) - SA (Right));
end "-";
------------------------
-- Fetch_From_Address --
------------------------
function Fetch_From_Address (A : Address) return Target is
type T_Ptr is access all Target;
function To_T_Ptr is new Ada.Unchecked_Conversion (Address, T_Ptr);
Ptr : constant T_Ptr := To_T_Ptr (A);
begin
return Ptr.all;
end Fetch_From_Address;
-----------------------
-- Assign_To_Address --
-----------------------
procedure Assign_To_Address (A : Address; T : Target) is
type T_Ptr is access all Target;
function To_T_Ptr is new Ada.Unchecked_Conversion (Address, T_Ptr);
Ptr : constant T_Ptr := To_T_Ptr (A);
begin
Ptr.all := T;
end Assign_To_Address;
---------------------------------
-- Operations on Unsigned_Byte --
---------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type BU is mod 2 ** Unsigned_Byte'Size;
-- Unsigned type of same length as Unsigned_Byte
function To_B is new Ada.Unchecked_Conversion (BU, Unsigned_Byte);
function From_B is new Ada.Unchecked_Conversion (Unsigned_Byte, BU);
function "not" (Left : Unsigned_Byte) return Unsigned_Byte is
begin
return To_B (not From_B (Left));
end "not";
function "and" (Left, Right : Unsigned_Byte) return Unsigned_Byte is
begin
return To_B (From_B (Left) and From_B (Right));
end "and";
function "or" (Left, Right : Unsigned_Byte) return Unsigned_Byte is
begin
return To_B (From_B (Left) or From_B (Right));
end "or";
function "xor" (Left, Right : Unsigned_Byte) return Unsigned_Byte is
begin
return To_B (From_B (Left) xor From_B (Right));
end "xor";
---------------------------------
-- Operations on Unsigned_Word --
---------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type WU is mod 2 ** Unsigned_Word'Size;
-- Unsigned type of same length as Unsigned_Word
function To_W is new Ada.Unchecked_Conversion (WU, Unsigned_Word);
function From_W is new Ada.Unchecked_Conversion (Unsigned_Word, WU);
function "not" (Left : Unsigned_Word) return Unsigned_Word is
begin
return To_W (not From_W (Left));
end "not";
function "and" (Left, Right : Unsigned_Word) return Unsigned_Word is
begin
return To_W (From_W (Left) and From_W (Right));
end "and";
function "or" (Left, Right : Unsigned_Word) return Unsigned_Word is
begin
return To_W (From_W (Left) or From_W (Right));
end "or";
function "xor" (Left, Right : Unsigned_Word) return Unsigned_Word is
begin
return To_W (From_W (Left) xor From_W (Right));
end "xor";
-------------------------------------
-- Operations on Unsigned_Longword --
-------------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type LWU is mod 2 ** Unsigned_Longword'Size;
-- Unsigned type of same length as Unsigned_Longword
function To_LW is new Ada.Unchecked_Conversion (LWU, Unsigned_Longword);
function From_LW is new Ada.Unchecked_Conversion (Unsigned_Longword, LWU);
function "not" (Left : Unsigned_Longword) return Unsigned_Longword is
begin
return To_LW (not From_LW (Left));
end "not";
function "and" (Left, Right : Unsigned_Longword) return Unsigned_Longword is
begin
return To_LW (From_LW (Left) and From_LW (Right));
end "and";
function "or" (Left, Right : Unsigned_Longword) return Unsigned_Longword is
begin
return To_LW (From_LW (Left) or From_LW (Right));
end "or";
function "xor" (Left, Right : Unsigned_Longword) return Unsigned_Longword is
begin
return To_LW (From_LW (Left) xor From_LW (Right));
end "xor";
-------------------------------
-- Operations on Unsigned_32 --
-------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type U32 is mod 2 ** Unsigned_32'Size;
-- Unsigned type of same length as Unsigned_32
function To_U32 is new Ada.Unchecked_Conversion (U32, Unsigned_32);
function From_U32 is new Ada.Unchecked_Conversion (Unsigned_32, U32);
function "not" (Left : Unsigned_32) return Unsigned_32 is
begin
return To_U32 (not From_U32 (Left));
end "not";
function "and" (Left, Right : Unsigned_32) return Unsigned_32 is
begin
return To_U32 (From_U32 (Left) and From_U32 (Right));
end "and";
function "or" (Left, Right : Unsigned_32) return Unsigned_32 is
begin
return To_U32 (From_U32 (Left) or From_U32 (Right));
end "or";
function "xor" (Left, Right : Unsigned_32) return Unsigned_32 is
begin
return To_U32 (From_U32 (Left) xor From_U32 (Right));
end "xor";
-------------------------------------
-- Operations on Unsigned_Quadword --
-------------------------------------
-- It would be nice to replace these with intrinsics, but that does
-- not work yet (the back end would be ok, but GNAT itself objects)
type QWU is mod 2 ** 64; -- 64 = Unsigned_Quadword'Size
-- Unsigned type of same length as Unsigned_Quadword
function To_QW is new Ada.Unchecked_Conversion (QWU, Unsigned_Quadword);
function From_QW is new Ada.Unchecked_Conversion (Unsigned_Quadword, QWU);
function "not" (Left : Unsigned_Quadword) return Unsigned_Quadword is
begin
return To_QW (not From_QW (Left));
end "not";
function "and" (Left, Right : Unsigned_Quadword) return Unsigned_Quadword is
begin
return To_QW (From_QW (Left) and From_QW (Right));
end "and";
function "or" (Left, Right : Unsigned_Quadword) return Unsigned_Quadword is
begin
return To_QW (From_QW (Left) or From_QW (Right));
end "or";
function "xor" (Left, Right : Unsigned_Quadword) return Unsigned_Quadword is
begin
return To_QW (From_QW (Left) xor From_QW (Right));
end "xor";
-----------------------
-- Clear_Interlocked --
-----------------------
procedure Clear_Interlocked
(Bit : in out Boolean;
Old_Value : out Boolean)
is
begin
SSL.Lock_Task.all;
Old_Value := Bit;
Bit := False;
SSL.Unlock_Task.all;
end Clear_Interlocked;
procedure Clear_Interlocked
(Bit : in out Boolean;
Old_Value : out Boolean;
Retry_Count : Natural;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := Bit;
Bit := False;
Success_Flag := True;
SSL.Unlock_Task.all;
end Clear_Interlocked;
---------------------
-- Set_Interlocked --
---------------------
procedure Set_Interlocked
(Bit : in out Boolean;
Old_Value : out Boolean)
is
begin
SSL.Lock_Task.all;
Old_Value := Bit;
Bit := True;
SSL.Unlock_Task.all;
end Set_Interlocked;
procedure Set_Interlocked
(Bit : in out Boolean;
Old_Value : out Boolean;
Retry_Count : Natural;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := Bit;
Bit := True;
Success_Flag := True;
SSL.Unlock_Task.all;
end Set_Interlocked;
---------------------
-- Add_Interlocked --
---------------------
procedure Add_Interlocked
(Addend : Short_Integer;
Augend : in out Aligned_Word;
Sign : out Integer)
is
begin
SSL.Lock_Task.all;
Augend.Value := Augend.Value + Addend;
if Augend.Value < 0 then
Sign := -1;
elsif Augend.Value > 0 then
Sign := +1;
else
Sign := 0;
end if;
SSL.Unlock_Task.all;
end Add_Interlocked;
----------------
-- Add_Atomic --
----------------
procedure Add_Atomic
(To : in out Aligned_Integer;
Amount : Integer)
is
begin
SSL.Lock_Task.all;
To.Value := To.Value + Amount;
SSL.Unlock_Task.all;
end Add_Atomic;
procedure Add_Atomic
(To : in out Aligned_Integer;
Amount : Integer;
Retry_Count : Natural;
Old_Value : out Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := To.Value + Amount;
Success_Flag := True;
SSL.Unlock_Task.all;
end Add_Atomic;
procedure Add_Atomic
(To : in out Aligned_Long_Integer;
Amount : Long_Integer)
is
begin
SSL.Lock_Task.all;
To.Value := To.Value + Amount;
SSL.Unlock_Task.all;
end Add_Atomic;
procedure Add_Atomic
(To : in out Aligned_Long_Integer;
Amount : Long_Integer;
Retry_Count : Natural;
Old_Value : out Long_Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := To.Value + Amount;
Success_Flag := True;
SSL.Unlock_Task.all;
end Add_Atomic;
----------------
-- And_Atomic --
----------------
type IU is mod 2 ** Integer'Size;
type LU is mod 2 ** Long_Integer'Size;
function To_IU is new Ada.Unchecked_Conversion (Integer, IU);
function From_IU is new Ada.Unchecked_Conversion (IU, Integer);
function To_LU is new Ada.Unchecked_Conversion (Long_Integer, LU);
function From_LU is new Ada.Unchecked_Conversion (LU, Long_Integer);
procedure And_Atomic
(To : in out Aligned_Integer;
From : Integer)
is
begin
SSL.Lock_Task.all;
To.Value := From_IU (To_IU (To.Value) and To_IU (From));
SSL.Unlock_Task.all;
end And_Atomic;
procedure And_Atomic
(To : in out Aligned_Integer;
From : Integer;
Retry_Count : Natural;
Old_Value : out Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := From_IU (To_IU (To.Value) and To_IU (From));
Success_Flag := True;
SSL.Unlock_Task.all;
end And_Atomic;
procedure And_Atomic
(To : in out Aligned_Long_Integer;
From : Long_Integer)
is
begin
SSL.Lock_Task.all;
To.Value := From_LU (To_LU (To.Value) and To_LU (From));
SSL.Unlock_Task.all;
end And_Atomic;
procedure And_Atomic
(To : in out Aligned_Long_Integer;
From : Long_Integer;
Retry_Count : Natural;
Old_Value : out Long_Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := From_LU (To_LU (To.Value) and To_LU (From));
Success_Flag := True;
SSL.Unlock_Task.all;
end And_Atomic;
---------------
-- Or_Atomic --
---------------
procedure Or_Atomic
(To : in out Aligned_Integer;
From : Integer)
is
begin
SSL.Lock_Task.all;
To.Value := From_IU (To_IU (To.Value) or To_IU (From));
SSL.Unlock_Task.all;
end Or_Atomic;
procedure Or_Atomic
(To : in out Aligned_Integer;
From : Integer;
Retry_Count : Natural;
Old_Value : out Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := From_IU (To_IU (To.Value) or To_IU (From));
Success_Flag := True;
SSL.Unlock_Task.all;
end Or_Atomic;
procedure Or_Atomic
(To : in out Aligned_Long_Integer;
From : Long_Integer)
is
begin
SSL.Lock_Task.all;
To.Value := From_LU (To_LU (To.Value) or To_LU (From));
SSL.Unlock_Task.all;
end Or_Atomic;
procedure Or_Atomic
(To : in out Aligned_Long_Integer;
From : Long_Integer;
Retry_Count : Natural;
Old_Value : out Long_Integer;
Success_Flag : out Boolean)
is
pragma Warnings (Off, Retry_Count);
begin
SSL.Lock_Task.all;
Old_Value := To.Value;
To.Value := From_LU (To_LU (To.Value) or To_LU (From));
Success_Flag := True;
SSL.Unlock_Task.all;
end Or_Atomic;
------------------------------------
-- Declarations for Queue Objects --
------------------------------------
type QR;
type QR_Ptr is access QR;
type QR is record
Forward : QR_Ptr;
Backward : QR_Ptr;
end record;
function To_QR_Ptr is new Ada.Unchecked_Conversion (Address, QR_Ptr);
function From_QR_Ptr is new Ada.Unchecked_Conversion (QR_Ptr, Address);
------------
-- Insqhi --
------------
procedure Insqhi
(Item : Address;
Header : Address;
Status : out Insq_Status)
is
Hedr : constant QR_Ptr := To_QR_Ptr (Header);
Next : constant QR_Ptr := Hedr.Forward;
Itm : constant QR_Ptr := To_QR_Ptr (Item);
begin
SSL.Lock_Task.all;
Itm.Forward := Next;
Itm.Backward := Hedr;
Hedr.Forward := Itm;
if Next = null then
Status := OK_First;
else
Next.Backward := Itm;
Status := OK_Not_First;
end if;
SSL.Unlock_Task.all;
end Insqhi;
------------
-- Remqhi --
------------
procedure Remqhi
(Header : Address;
Item : out Address;
Status : out Remq_Status)
is
Hedr : constant QR_Ptr := To_QR_Ptr (Header);
Next : constant QR_Ptr := Hedr.Forward;
begin
SSL.Lock_Task.all;
Item := From_QR_Ptr (Next);
if Next = null then
Status := Fail_Was_Empty;
else
Hedr.Forward := To_QR_Ptr (Item).Forward;
if Hedr.Forward = null then
Status := OK_Empty;
else
Hedr.Forward.Backward := Hedr;
Status := OK_Not_Empty;
end if;
end if;
SSL.Unlock_Task.all;
end Remqhi;
------------
-- Insqti --
------------
procedure Insqti
(Item : Address;
Header : Address;
Status : out Insq_Status)
is
Hedr : constant QR_Ptr := To_QR_Ptr (Header);
Prev : constant QR_Ptr := Hedr.Backward;
Itm : constant QR_Ptr := To_QR_Ptr (Item);
begin
SSL.Lock_Task.all;
Itm.Backward := Prev;
Itm.Forward := Hedr;
Hedr.Backward := Itm;
if Prev = null then
Status := OK_First;
else
Prev.Forward := Itm;
Status := OK_Not_First;
end if;
SSL.Unlock_Task.all;
end Insqti;
------------
-- Remqti --
------------
procedure Remqti
(Header : Address;
Item : out Address;
Status : out Remq_Status)
is
Hedr : constant QR_Ptr := To_QR_Ptr (Header);
Prev : constant QR_Ptr := Hedr.Backward;
begin
SSL.Lock_Task.all;
Item := From_QR_Ptr (Prev);
if Prev = null then
Status := Fail_Was_Empty;
else
Hedr.Backward := To_QR_Ptr (Item).Backward;
if Hedr.Backward = null then
Status := OK_Empty;
else
Hedr.Backward.Forward := Hedr;
Status := OK_Not_Empty;
end if;
end if;
SSL.Unlock_Task.all;
end Remqti;
end System.Aux_DEC;
|
F1, F2 : File_Type;
begin
Open (F1, In_File, "city.ppm");
declare
X : Image := Get_PPM (F1);
Y : Grayscale_Image := Grayscale (X);
T : Luminance := Median (Get_Histogram (Y));
begin
Close (F1);
Create (F2, Out_File, "city_art.ppm");
for I in Y'Range (1) loop
for J in Y'Range (2) loop
if Y (I, J) < T then
X (I, J) := Black;
else
X (I, J) := White;
end if;
end loop;
end loop;
Put_PPM (F2, X);
end;
Close (F2);
|
------------------------------------------------------------------------------
-- Copyright (c) 2011, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
package body Natools.Accumulators.String_Accumulator_Linked_Lists is
procedure Initialize_If_Needed
(Object : in out String_Accumulator_Linked_List) is
begin
if Object.Stack.Is_Empty then
Object.Stack.Append (Object.Build (1));
Object.Position := Object.Stack.Last;
end if;
end Initialize_If_Needed;
procedure Append (To : in out String_Accumulator_Linked_List;
Text : String)
is
procedure Process (Element : in out String_Accumulator'Class);
procedure Process (Element : in out String_Accumulator'Class) is
begin
Element.Append (Text);
end Process;
begin
Initialize_If_Needed (To);
To.Stack.Update_Element (To.Position, Process'Access);
end Append;
procedure Hard_Reset (Acc : in out String_Accumulator_Linked_List) is
begin
Acc.Stack.Clear;
Acc.Position := Lists.No_Element;
end Hard_Reset;
function Length (Acc : String_Accumulator_Linked_List) return Natural is
procedure Process (Element : String_Accumulator'Class);
Result : Natural;
procedure Process (Element : String_Accumulator'Class) is
begin
Result := Element.Length;
end Process;
begin
if Acc.Stack.Is_Empty then
return 0;
else
Lists.Query_Element (Acc.Position, Process'Access);
return Result;
end if;
end Length;
procedure Push (Acc : in out String_Accumulator_Linked_List) is
procedure Process (Element : in out String_Accumulator'Class);
use type Lists.Cursor;
procedure Process (Element : in out String_Accumulator'Class) is
begin
Soft_Reset (Element);
end Process;
begin
Initialize_If_Needed (Acc);
Lists.Next (Acc.Position);
if Acc.Position = Lists.No_Element then
declare
Level_Created : constant Positive
:= Natural (Acc.Stack.Length) + 1;
begin
Acc.Stack.Append (Acc.Build (Level_Created));
Acc.Position := Acc.Stack.Last;
end;
else
Acc.Stack.Update_Element (Acc.Position, Process'Access);
end if;
end Push;
procedure Pop (Acc : in out String_Accumulator_Linked_List) is
use type Lists.Cursor;
begin
if Acc.Stack.Is_Empty then
raise Program_Error;
end if;
Lists.Previous (Acc.Position);
if Acc.Position = Lists.No_Element then
Acc.Position := Lists.First (Acc.Stack);
raise Program_Error;
end if;
end Pop;
procedure Soft_Reset (Acc : in out String_Accumulator_Linked_List) is
procedure Process (Element : in out String_Accumulator'Class);
procedure Process (Element : in out String_Accumulator'Class) is
begin
Element.Soft_Reset;
end Process;
begin
Initialize_If_Needed (Acc);
Acc.Position := Lists.First (Acc.Stack);
Acc.Stack.Update_Element (Acc.Position, Process'Access);
end Soft_Reset;
function Tail (Acc : String_Accumulator_Linked_List; Size : Natural)
return String
is
procedure Process (Element : String_Accumulator'Class);
Result : String (1 .. Size);
Actual_Size : Natural;
procedure Process (Element : String_Accumulator'Class)
is
Output : constant String := Tail (Element, Size);
begin
Actual_Size := Output'Length;
Result (1 .. Actual_Size) := Output;
end Process;
begin
if Acc.Stack.Is_Empty then
return "";
else
Lists.Query_Element (Acc.Position, Process'Access);
return Result (1 .. Actual_Size);
end if;
end Tail;
function To_String (Acc : String_Accumulator_Linked_List) return String is
begin
if Acc.Stack.Is_Empty then
return "";
end if;
declare
procedure Process (Element : String_Accumulator'Class);
Result : String (1 .. Acc.Length);
procedure Process (Element : String_Accumulator'Class) is
begin
Result := Element.To_String;
end Process;
begin
Lists.Query_Element (Acc.Position, Process'Access);
return Result;
end;
end To_String;
procedure To_String (Acc : String_Accumulator_Linked_List;
Output : out String) is
begin
if Acc.Stack.Is_Empty then
return;
end if;
declare
procedure Process (Element : String_Accumulator'Class);
procedure Process (Element : String_Accumulator'Class) is
begin
Element.To_String (Output);
end Process;
begin
Lists.Query_Element (Acc.Position, Process'Access);
end;
end To_String;
procedure Unappend (From : in out String_Accumulator_Linked_List;
Text : String)
is
procedure Process (Element : in out String_Accumulator'Class);
procedure Process (Element : in out String_Accumulator'Class) is
begin
Element.Unappend (Text);
end Process;
begin
if not From.Stack.Is_Empty then
From.Stack.Update_Element (From.Position, Process'Access);
end if;
end Unappend;
end Natools.Accumulators.String_Accumulator_Linked_Lists;
|
--
-- Copyright 2021 (C) Jeremy Grosser <jeremy@synack.me>
--
-- SPDX-License-Identifier: Apache-2.0
--
with Notcurses.Channel; use Notcurses.Channel;
with Notcurses_Direct_Thin;
package Notcurses.Direct is
type Notcurses_Direct is private;
procedure Initialize
(This : out Notcurses_Direct;
Terminal_Type : String := "");
procedure Set_Cursor_Enabled
(This : Notcurses_Direct;
Enabled : Boolean);
function Dimensions
(This : Notcurses_Direct)
return Coordinate;
procedure Put
(This : Notcurses_Direct;
Str : Wide_Wide_String;
Foreground : Notcurses_Channel :=
(Not_Default => False, others => <>);
Background : Notcurses_Channel :=
(Not_Default => False, others => <>));
procedure New_Line
(This : Notcurses_Direct);
procedure Set_Background_RGB
(This : Notcurses_Direct;
R, G, B : Color_Type);
procedure Set_Foreground_RGB
(This : Notcurses_Direct;
R, G, B : Color_Type);
procedure Stop
(This : in out Notcurses_Direct);
private
package Direct_Thin renames Notcurses_Direct_Thin;
type Notcurses_Direct is access all Direct_Thin.ncdirect;
end Notcurses.Direct;
|
-- Generated at 2014-07-02 17:53:59 +0000 by Natools.Static_Hash_Maps
-- from src/simple_webapps-upload_servers-commands.sx
with Simple_Webapps.Commands.Upload_Servers.Config;
with Simple_Webapps.Commands.Upload_Servers.File;
package body Simple_Webapps.Commands.Upload_Servers is
function To_Config_Command (Key : String) return Config_Command is
N : constant Natural
:= Simple_Webapps.Commands.Upload_Servers.Config.Hash (Key);
begin
if Map_1_Keys (N).all = Key then
return Map_1_Elements (N);
else
return Config_Error;
end if;
end To_Config_Command;
function To_File_Command (Key : String) return File_Command is
N : constant Natural
:= Simple_Webapps.Commands.Upload_Servers.File.Hash (Key);
begin
if Map_2_Keys (N).all = Key then
return Map_2_Elements (N);
else
return File_Error;
end if;
end To_File_Command;
end Simple_Webapps.Commands.Upload_Servers;
|
------------------------------------------------------------------------------
-- --
-- Internet Protocol Suite Package --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2020, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (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. --
-- --
------------------------------------------------------------------------------
-- This package implements an extension of TCP_Connection that is secured with
-- TLS.
with INET.TLS; use INET.TLS;
private with INET.Internal.TLS;
package INET.TCP.TLS is
Explicit_Handshake_Timeout: constant Duration := 30.0;
-- TODO: Migrate to AURA config. This might end up in TLS_Configuration, but
-- this seems problematic since libtls executes handshakes on it's own
-- volition, and we can't control the timeouts of those. It might be
-- misleading to put that property there
--------------------
-- TLS_Connection --
--------------------
type TLS_Connection is abstract limited new TCP_Connection with private;
-- TLS_Connection is an extension of TCP_Connection, and behaves in the
-- same way, with the underlying communications being secured by TLS.
--
-- If Configuration is null, the connection can only be established
-- via TLS_Listener.Dequeue (and thus is a server-side connection)
--
-- For security-concious applications where client authentication is
-- also requred (and thus the Configuration contains private keys),
-- Clear_Keys can be invoked on Configuration after the required
-- TCP_Connections have been established.
not overriding
function Secured (Connection: TLS_Connection) return Boolean;
-- True iff the Connection has successfull established a TLS session
-- over the underlying TCP connection.
--
-- Default initialized TLS_Connection'Class objects return False.
--
-- If a TLS_Connection is Dequeued from a TCP_Listener'Class object that
-- is not a member of TLS_Listener'Class, Established will return False.
--
-- Read or Write operations are illegal if Secured is false and
-- will cause Program_Error to be raised.
--
-- Unsecured connections can be secured by the Secure operation
--
-- See the description of Secure for example applications of
-- unsecured TLS_Connection objects.
overriding
procedure Read (Stream: in out TLS_Connection;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset)
with Pre => Stream.Secured;
-- Semantics are preserved as with TCP_Connection.
--
-- Program_Error is raised if the connection has not yet been Secured.
overriding
procedure Read_Immediate (Stream: in out TLS_Connection;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset)
with Pre => Stream.Secured;
-- Semantics are preserved as with TCP_Connection
--
-- Program_Error is raised if the connection has not yet been Secured.
overriding
procedure Write (Stream: in out TLS_Connection;
Item : in Stream_Element_Array)
with Pre => Stream.Secured;
-- Semantics are preserved as with TCP_Connection
--
-- Program_Error is raised if the connection has not yet been Secured.
overriding
procedure Write_Immediate (Stream: in out TLS_Connection;
Item : in Stream_Element_Array;
Last : out Stream_Element_Offset)
with Pre => Stream.Secured;
-- Semantics are preserved as with TCP_Connection
--
-- Program_Error is raised if the connection has not yet been Secured.
overriding procedure Shutdown (Connection: in out TLS_Connection);
overriding procedure Shutdown_Read (Connection: in out TLS_Connection);
overriding procedure Shutdown_Write (Connection: in out TLS_Connection);
-- Shutdown Read and Shutdown Write are not supported for TLS connections
-- at the socket (TCP) level. In order to preserve the behaviour as much as
-- possible, the _Read and _Write variations will cause raise End_Error if
-- a subsequent read/write is performed on the shutdown direction.
--
-- If both are invoked, Shutdown is invoked automatically.
---------------------------
-- TLS_Client_Connection --
---------------------------
type TLS_Client_Connection
(Configuration: not null access TLS_Client_Configuration'Class)
is limited new TLS_Connection with private;
-- A TLS_Client_Connection is only able to form outbound connections.
overriding
procedure Connect (Connection: in out TLS_Client_Connection;
Address : in IP.IP_Address;
Port : in TCP_Port)
with No_Return; -- Raises Program_Error
not overriding
procedure Connect (Connection : in out TLS_Client_Connection;
Address : in IP.IP_Address;
Port : in TCP_Port;
Server_Name: in String)
with Pre'Class => Server_Name'Length > 0;
overriding
procedure Connect (Connection: in out TLS_Client_Connection;
Host_Name : in String;
Port : in TCP_Port);
overriding
procedure Connect (Connection : in out TLS_Client_Connection;
Host_Name : in String;
Port : in TCP_Port;
Version : in IP.IP_Version);
-- Attempts to establish a TLS connection over an new TCP connection.
-- If Connection is already connected (or Secured), it is first shutdown.
--
-- TLS requires the verification of the server's hostname as part of the
-- handshake, therefore connecting with only an Address and a Port requires
-- a supplimental Server_Name. If the inherited Address-only Connect is
-- invoked, Program_Error is raised.
--
-- It is generally recommended to use the inhereted Host_Name lookup
-- operations for outbound TLS connections.
not overriding
procedure Secure (Connection : in out TLS_Client_Connection;
Server_Name: in String)
with Pre'Class => Server_Name'Length > 0,
Post'Class => Connection.Secured;
-- Secure completes a TLS handshake initiated by the remote peer
-- (the server). If it returns without error, TLS has been successfully
-- established for the connection, according to Connection.Configuration.
--
-- If the connection is already Secured, Secure forces another handshake.
-- This works even if Shutdown_Read or Shutdown_Write has been invoked
-- (but not both, nor Shutdown - which makes the connection inactive).
--
-- If a Server_Name is specified, this will be used to verify the server
-- name through the SNI extension (RFC4366). If Server_Name is a null string,
-- Constraint_Error is raised.
--
-- If the connection has been fully Shutdown, Program_Error is raised.
--
-- If Secure fails, the connection is shutdown, and an exception is
-- always propegated.
--
-- The remote peer must be a server, or else the TLS handshake will fail.
-- Therefore, if Connection was initialized by a Dequeue from a TCP_Listener,
-- TLS_Error is all but guaranteed.
--
-- For special application protocols that may start as plain-text,
-- such as SMTP with STARTTLS, the socket may be first view converted
-- upwards to a TCP_Connection, Connect invoked on that converion, and
-- the subsequent plain-text negotiation. When ready to establish a TLS
-- connection, Secure can be then be invoked on the underlying
-- TLS_Client_Connection object.
---------------------------
-- TLS_Server_Connection --
---------------------------
type TLS_Server_Connection is limited new TLS_Connection with private;
-- TLS_Server_Connection objects do not need a configuration if Dequeued
-- from a TLS_Listener. The context is implicitly configured from the
-- TLS_Listener, which is configured via a TLS_Server_Configuration
-- access discriminant
overriding
procedure Connect (Connection: in out TLS_Server_Connection;
Address : in IP.IP_Address;
Port : in TCP_Port)
with No_Return;
procedure Connect (Connection: in out TLS_Server_Connection;
Host_Name : in String;
Port : in TCP_Port)
with No_Return;
procedure Connect (Connection : in out TLS_Server_Connection;
Host_Name : in String;
Port : in TCP_Port;
Version : in IP.IP_Version)
with No_Return;
-- Connect is not legal on a server connection. Invoking Connect raises
-- Program_Error.
not overriding
procedure Secure (Connection : in out TLS_Server_Connection;
Configuration: in TLS_Server_Configuration'Class)
with Pre'Class => not Connection.Secured,
Post'Class => Connection.Secured;
-- Secure initiates a TLS handshake with the remote peer (the client).
-- If it returns without error, TLS has been successfully established for
-- the connection, according to the Configuration.
--
-- Due to the presence of the Configuration parameter, which is non-
-- sensical on an established connection, invoking Secure on a Secured
-- connection raises Program_Error.
--
-- To force a handshake, see Re_secure below.
--
-- If the connection has been fully Shutdown, Program_Error is raised.
--
-- If Secure fails, the connection is shutdown, and an exception is
-- always propegated.
--
-- The remote peer must be a client, or else the TLS handshake will fail.
-- Therefore, if Connection was initialized by a Connect via a upwards
-- view conversion. TLS_Error is all but guaranteed.
--
-- For special application protocols that may start as plain-text,
-- such as SMTP with STARTTLS, the socket may be dequeued from a
-- regular TCP_Listener (rather than a TLS_Listener), and then
-- view converted up to a regular TCP_Connection to perform the clear-text
-- negotiation. When ready to establish a TLS connection, Secure can be
-- then be invoked on the underlying TLS_Server_Connection object.
not overriding
procedure Re_Secure (Connection: in out TLS_Server_Connection) with
Pre'Class => Connection.Secured;
-- Connection must already be Secured, or else Program_Error is raised.
-- Otherwise, Re_secure forces a handshake immediately. If Re_secure
-- returns successfully, the handshake was successful.
--
-- If the connection has been fully Shutdown, Program_Error is raised.
--
-- If Re_secure fails, the connection is shutdown, and an exception is
-- always propegated.
------------------
-- TLS_Listener --
------------------
type TLS_Listener
(Queue_Size : Positive;
Configuration: not null access TLS_Server_Configuration'Class)
is limited new TCP_Listener with private;
-- Note that sessions can stil be managed separately via the Configuration
-- object, even while the listener is live (Bound)
overriding
procedure Bind (Listener: in out TLS_Listener;
Address : in IP.IP_Address;
Port : in TCP_Port);
-- Note that Clear_Keys may be invoked on Configuration after all
-- TLS_Listener objects that depend on it have been successfully
-- Bound. In other words, Bind is what establishes the listener context,
-- and is therefore that moment that the keys are copied to that
-- context.
overriding
procedure Dequeue (Listener : in out TLS_Listener;
Connection: in out TCP_Connection'Class)
with Pre => Connection in TLS_Server_Connection'Class;
overriding
function Dequeue (Listener: in out TLS_Listener) return TCP_Connection'Class
with Post'Class => Dequeue'Result in TLS_Server_Connection'Class
and then TLS_Connection'Class (Dequeue'Result).Secured;
-- Dequeues an established TLS_Server_Connection object from a TLS_Listener.
-- The dequeued TLS_Server_Connection will be secured, and ready for use.
--
-- To negotiate plain-text protocols before initiating TLS, a TCP_Listener
-- that is not a member of TLS_Listener'Class should be used to dequeue to
-- a TLS_Server_Connection object. See TLS_Server_Connection.Secure, above.
--
-- If using the procedure, if Connection is connected (secured or not), it
-- is first closed
private
type TLS_Connection is
limited new TCP.TCP_Connection with
record
Context: INET.Internal.TLS.TLS_Stream_Context;
TLS_Go: Boolean := False;
-- Set to True only if the connection and handshake attempt is
-- reported successful by libtls. This value must be True
-- for Reads or Writes to be allowed.
Read_Down, Write_Down: Boolean := False;
-- Used to track the use of Shutdown_Read/_Write. See the
-- comments for Shutdown above for more information.
end record;
-- All a TLS Connection really needs is a context. The context is sufficent
-- to send and receive, and to manage the state of the connection. Contexts
-- are created during Connect, Secure, or when Dequeing from a TLS_Listener
-- object Contexts are reset if possible, making it possible for the
-- underlying libtls to re-use memory, however this appears to be unlikely.
type TLS_Client_Connection
(Configuration: not null access TLS_Client_Configuration'Class)
is limited new TLS_Connection with null record;
type TLS_Server_Connection is limited new TLS_Connection with null record;
------------------
-- TLS_Listener --
------------------
type TLS_Listener
(Queue_Size : Positive;
Configuration: not null access TLS_Server_Configuration'Class)
is limited new TCP_Listener (Queue_Size) with
record
Context: INET.Internal.TLS.TLS_Listener_Context;
end record;
end INET.TCP.TLS;
|
-----------------------------------------------------------------------
-- util-http-clients -- HTTP Clients
-- Copyright (C) 2011, 2012, 2013, 2017, 2020 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- 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 Ada.Unchecked_Deallocation;
with Util.Log.Loggers;
package body Util.Http.Clients is
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Util.Http.Clients");
procedure Initialize (Form : in out Form_Data;
Size : in Positive) is
begin
Form.Buffer.Initialize (Output => null,
Size => Size);
Form.Initialize (Form.Buffer'Unchecked_Access);
end Initialize;
-- ------------------------------
-- Returns a boolean indicating whether the named response header has already
-- been set.
-- ------------------------------
overriding
function Contains_Header (Reply : in Response;
Name : in String) return Boolean is
begin
if Reply.Delegate = null then
return False;
else
return Reply.Delegate.Contains_Header (Name);
end if;
end Contains_Header;
-- ------------------------------
-- Returns the value of the specified response header as a String. If the response
-- did not include a header of the specified name, this method returns null.
-- If there are multiple headers with the same name, this method returns the
-- first head in the request. The header name is case insensitive. You can use
-- this method with any response header.
-- ------------------------------
overriding
function Get_Header (Reply : in Response;
Name : in String) return String is
begin
if Reply.Delegate = null then
return "";
else
return Reply.Delegate.Get_Header (Name);
end if;
end Get_Header;
-- ------------------------------
-- Sets a message header with the given name and value. If the header had already
-- been set, the new value overwrites the previous one. The containsHeader
-- method can be used to test for the presence of a header before setting its value.
-- ------------------------------
overriding
procedure Set_Header (Reply : in out Response;
Name : in String;
Value : in String) is
begin
Reply.Delegate.Set_Header (Name, Value);
end Set_Header;
-- ------------------------------
-- Adds a request header with the given name and value.
-- This method allows request headers to have multiple values.
-- ------------------------------
overriding
procedure Add_Header (Reply : in out Response;
Name : in String;
Value : in String) is
begin
Reply.Delegate.Add_Header (Name, Value);
end Add_Header;
-- ------------------------------
-- Iterate over the response headers and executes the <b>Process</b> procedure.
-- ------------------------------
overriding
procedure Iterate_Headers (Reply : in Response;
Process : not null access
procedure (Name : in String;
Value : in String)) is
begin
if Reply.Delegate /= null then
Reply.Delegate.Iterate_Headers (Process);
end if;
end Iterate_Headers;
-- ------------------------------
-- Get the response body as a string.
-- ------------------------------
overriding
function Get_Body (Reply : in Response) return String is
begin
if Reply.Delegate = null then
return "";
else
return Reply.Delegate.Get_Body;
end if;
end Get_Body;
-- ------------------------------
-- Get the response status code.
-- ------------------------------
function Get_Status (Reply : in Response) return Natural is
begin
return Reply.Delegate.Get_Status;
end Get_Status;
-- ------------------------------
-- Returns a boolean indicating whether the named response header has already
-- been set.
-- ------------------------------
overriding
function Contains_Header (Request : in Client;
Name : in String) return Boolean is
begin
if Request.Delegate = null then
return False;
else
return Request.Delegate.Contains_Header (Name);
end if;
end Contains_Header;
-- ------------------------------
-- Returns the value of the specified request header as a String. If the request
-- did not include a header of the specified name, this method returns null.
-- If there are multiple headers with the same name, this method returns the
-- first head in the request. The header name is case insensitive. You can use
-- this method with any response header.
-- ------------------------------
overriding
function Get_Header (Request : in Client;
Name : in String) return String is
begin
if Request.Delegate = null then
return "";
else
return Request.Delegate.Get_Header (Name);
end if;
end Get_Header;
-- ------------------------------
-- Sets a header with the given name and value. If the header had already
-- been set, the new value overwrites the previous one. The containsHeader
-- method can be used to test for the presence of a header before setting its value.
-- ------------------------------
overriding
procedure Set_Header (Request : in out Client;
Name : in String;
Value : in String) is
begin
Request.Delegate.Set_Header (Name, Value);
end Set_Header;
-- ------------------------------
-- Adds a header with the given name and value.
-- This method allows headers to have multiple values.
-- ------------------------------
overriding
procedure Add_Header (Request : in out Client;
Name : in String;
Value : in String) is
begin
Request.Delegate.Add_Header (Name, Value);
end Add_Header;
-- ------------------------------
-- Iterate over the request headers and executes the <b>Process</b> procedure.
-- ------------------------------
overriding
procedure Iterate_Headers (Request : in Client;
Process : not null access
procedure (Name : in String;
Value : in String)) is
begin
Request.Delegate.Iterate_Headers (Process);
end Iterate_Headers;
-- ------------------------------
-- Removes all headers with the given name.
-- ------------------------------
procedure Remove_Header (Request : in out Client;
Name : in String) is
begin
null;
end Remove_Header;
-- ------------------------------
-- Initialize the client
-- ------------------------------
overriding
procedure Initialize (Http : in out Client) is
begin
Http.Delegate := null;
Http.Manager := Default_Http_Manager;
if Http.Manager = null then
Log.Error ("No HTTP manager was defined");
raise Program_Error with "No HTTP manager was defined.";
end if;
Http.Manager.Create (Http);
end Initialize;
overriding
procedure Finalize (Http : in out Client) is
procedure Free is new Ada.Unchecked_Deallocation (Http_Request'Class,
Http_Request_Access);
begin
Free (Http.Delegate);
end Finalize;
-- ------------------------------
-- Execute an http GET request on the given URL. Additional request parameters,
-- cookies and headers should have been set on the client object.
-- ------------------------------
procedure Get (Request : in out Client;
URL : in String;
Reply : out Response'Class) is
begin
Request.Manager.Do_Get (Request, URL, Reply);
end Get;
-- ------------------------------
-- Execute an http POST request on the given URL. The post data is passed in <b>Data</b>.
-- Additional request cookies and headers should have been set on the client object.
-- ------------------------------
procedure Post (Request : in out Client;
URL : in String;
Data : in String;
Reply : out Response'Class) is
begin
Request.Manager.Do_Post (Request, URL, Data, Reply);
end Post;
procedure Post (Request : in out Client;
URL : in String;
Data : in Form_Data'Class;
Reply : out Response'Class) is
begin
Request.Manager.Do_Post (Request, URL, Util.Streams.Texts.To_String (Data.Buffer), Reply);
end Post;
-- ------------------------------
-- Execute an http PUT request on the given URL. The post data is passed in <b>Data</b>.
-- Additional request cookies and headers should have been set on the client object.
-- ------------------------------
procedure Put (Request : in out Client;
URL : in String;
Data : in String;
Reply : out Response'Class) is
begin
Request.Manager.Do_Put (Request, URL, Data, Reply);
end Put;
-- ------------------------------
-- Execute an http PATCH request on the given URL. The post data is passed in <b>Data</b>.
-- Additional request cookies and headers should have been set on the client object.
-- ------------------------------
procedure Patch (Request : in out Client;
URL : in String;
Data : in String;
Reply : out Response'Class) is
begin
Request.Manager.Do_Patch (Request, URL, Data, Reply);
end Patch;
-- ------------------------------
-- Execute a http DELETE request on the given URL.
-- ------------------------------
procedure Delete (Request : in out Client;
URL : in String;
Reply : out Response'Class) is
begin
Request.Manager.Do_Delete (Request, URL, Reply);
end Delete;
-- ------------------------------
-- Execute an http HEAD request on the given URL. Additional request parameters,
-- cookies and headers should have been set on the client object.
-- ------------------------------
procedure Head (Request : in out Client;
URL : in String;
Reply : out Response'Class) is
begin
Request.Manager.Do_Head (Request, URL, Reply);
end Head;
-- ------------------------------
-- Execute an http OPTIONS request on the given URL. Additional request parameters,
-- cookies and headers should have been set on the client object.
-- ------------------------------
procedure Options (Request : in out Client;
URL : in String;
Reply : out Response'Class) is
begin
Request.Manager.Do_Options (Request, URL, Reply);
end Options;
-- ------------------------------
-- Set the timeout for the connection.
-- ------------------------------
procedure Set_Timeout (Request : in out Client;
Timeout : in Duration) is
begin
Request.Manager.Set_Timeout (Request, Timeout);
end Set_Timeout;
-- ------------------------------
-- Adds the specified cookie to the request. This method can be called multiple
-- times to set more than one cookie.
-- ------------------------------
procedure Add_Cookie (Http : in out Client;
Cookie : in Util.Http.Cookies.Cookie) is
begin
null;
end Add_Cookie;
-- ------------------------------
-- Free the resource used by the response.
-- ------------------------------
overriding
procedure Finalize (Reply : in out Response) is
procedure Free is new Ada.Unchecked_Deallocation (Http_Response'Class,
Http_Response_Access);
begin
Free (Reply.Delegate);
end Finalize;
end Util.Http.Clients;
|
with Ada.Integer_Text_IO;
-- Copyright 2021 Melwyn Francis Carlo
procedure A021 is
use Ada.Integer_Text_IO;
Max_N : constant Integer := 10000 - 1;
Amicable_Numbers : array (Integer range 1 .. Max_N) of Integer :=
(others => 0);
Proper_Divisors_Sum_1 : Integer;
Proper_Divisors_Sum_2 : Integer;
N, J_Max : Integer;
begin
for I in 2 .. Max_N loop
Proper_Divisors_Sum_1 := 0;
Proper_Divisors_Sum_2 := 0;
J_Max := Integer (Float'Floor (Float (I) / 2.0));
for J in 1 .. J_Max loop
if (I mod J) = 0 then
Proper_Divisors_Sum_1 := Proper_Divisors_Sum_1 + J;
end if;
end loop;
J_Max := Integer (Float'Floor (Float (Proper_Divisors_Sum_1) / 2.0));
for J in 1 .. J_Max loop
if (Proper_Divisors_Sum_1 mod J) = 0 then
Proper_Divisors_Sum_2 := Proper_Divisors_Sum_2 + J;
end if;
end loop;
if I = Proper_Divisors_Sum_2 and I /= Proper_Divisors_Sum_1 then
Amicable_Numbers (I) := 1;
Amicable_Numbers (Proper_Divisors_Sum_1) := 1;
end if;
end loop;
N := 0;
for I in 1 .. Max_N loop
N := N + (I * Amicable_Numbers (I));
end loop;
Put (N, Width => 0);
end A021;
|
with System;
with Ada.Unchecked_Conversion;
package body ACO.Utils.Byte_Order is
use type System.Bit_Order;
function Unchecked_To_Unsigned_16 is
new Ada.Unchecked_Conversion (Octets_2, Unsigned_16);
function Unchecked_To_Unsigned_32 is
new Ada.Unchecked_Conversion (Octets_4, Unsigned_32);
function Unchecked_To_Octets_2 is
new Ada.Unchecked_Conversion (Unsigned_16, Octets_2);
function Unchecked_To_Octets_4 is
new Ada.Unchecked_Conversion (Unsigned_32, Octets_4);
function Swap_Bus (X : Unsigned_16) return Unsigned_16
is
O : Octets_2 with
Address => X'Address, Alignment => Unsigned_16'Alignment;
begin
if System.Default_Bit_Order = System.Low_Order_First then
return X;
else
return Unchecked_To_Unsigned_16 ((O (1), O (0)));
end if;
end Swap_Bus;
function Swap_Bus (X : Unsigned_32) return Unsigned_32
is
O : Octets_4 with
Address => X'Address, Alignment => Unsigned_32'Alignment;
begin
if System.Default_Bit_Order = System.Low_Order_First then
return X;
else
return Unchecked_To_Unsigned_32 ((O (3), O (2), O (1), O (0)));
end if;
end Swap_Bus;
function Swap_Bus (X : Octets_2) return Unsigned_16
is
begin
if System.Default_Bit_Order = System.Low_Order_First then
return Unchecked_To_Unsigned_16 (X);
else
return Unchecked_To_Unsigned_16 ((X (1), X (0)));
end if;
end Swap_Bus;
function Swap_Bus (X : Octets_4) return Unsigned_32
is
begin
if System.Default_Bit_Order = System.Low_Order_First then
return Unchecked_To_Unsigned_32 (X);
else
return Unchecked_To_Unsigned_32 ((X (3), X (2), X (1), X (0)));
end if;
end Swap_Bus;
function Swap_Bus (X : Unsigned_16) return Octets_2
is
begin
if System.Default_Bit_Order = System.Low_Order_First then
return Unchecked_To_Octets_2 (X);
else
declare
O : constant Octets_2 := Unchecked_To_Octets_2 (X);
begin
return (O (1), O (0));
end;
end if;
end Swap_Bus;
function Swap_Bus (X : Unsigned_32) return Octets_4
is
begin
if System.Default_Bit_Order = System.Low_Order_First then
return Unchecked_To_Octets_4 (X);
else
declare
O : constant Octets_4 := Unchecked_To_Octets_4 (X);
begin
return (O (3), O (2), O (1), O (0));
end;
end if;
end Swap_Bus;
procedure Swap (X : in out Octets)
is
Tmp : Unsigned_8;
I : Natural := 0;
begin
while X'First + I < X'Last - I loop
Tmp := X (X'First + I);
X (X'First + I) := X (X'Last - I);
X (X'Last - I) := Tmp;
I := I + 1;
end loop;
end Swap;
function Swap_Bus (X : in Octets) return Octets
is
begin
if System.Default_Bit_Order = System.Low_Order_First then
return X;
else
declare
Tmp : Octets := X;
begin
Swap (Tmp);
return Tmp;
end;
end if;
end Swap_Bus;
end ACO.Utils.Byte_Order;
|
-- Ascon.Compare_Tags
-- Compare two Tag_Type values using a constant-time approach. This is split
-- out into a separate child unit from Ascon so that different compilation flags
-- can be used. It is advisable to prevent optimisation of this function or
-- else a clever compiler might use a short-circuit approach. That might produce
-- logically identical results but it would leak information to attackers if the
-- timing of the decoding program can be observed.
-- Copyright (c) 2016, James Humphry - see LICENSE file for details
pragma Restrictions(No_Implementation_Attributes,
No_Implementation_Identifiers,
No_Implementation_Units,
No_Obsolescent_Features);
function Ascon.Compare_Tags (L, R : Tag_Type) return Boolean is
Result : Storage_Element := 0;
begin
for I in L'Range loop
Result := Result or (L(I) xor (R(I)));
end loop;
return (Result = 0);
end Ascon.Compare_Tags;
|
with Ada.Integer_Text_IO;
with Ada.Text_IO;
package body Problem_06 is
package IO renames Ada.Text_IO;
package I_IO renames Ada.Integer_Text_IO;
procedure Solve is
function Sum_Square(max : Integer) return Integer is
Sum : Integer := 0;
begin
for number in 1 .. max loop
Sum := Sum + number * number;
end loop;
return Sum;
end Sum_Square;
function Square_Sum(max : Integer) return Integer is
Sum : Integer := 0;
begin
for number in 1 .. max loop
Sum := Sum + number;
end Loop;
return Sum*Sum;
end Square_Sum;
begin
I_IO.Put(Square_Sum(100) - Sum_Square(100));
IO.New_Line;
end Solve;
end Problem_06;
|
with
Shell.Commands,
Ada.Text_IO;
procedure Test_Nonblocking_Pipe
is
-- To do this test, run this executable in one terminal, open
-- another terminal and start 'cat' (ie $ cat - >> test.log).
-- Then, type any string into the 'cat' terminal. Each entered
-- string should then appear in the 'Test_Nonblocking_Pipe' terminal.
--
-- Entering 'end' on the 'cat' terminal will terminate the test.
use Ada.Text_IO;
begin
Put_Line ("Begin 'Nonblocking_Pipe' test.");
New_Line (2);
declare
use Shell,
Shell.Commands;
The_Command : Command := Forge.To_Command ("tail -f test.log");
begin
Start (The_Command);
loop
declare
Results : constant Command_Results := Results_Of (The_Command);
Output : constant String := +Output_Of (Results);
begin
put_line ("'" & Output & "'");
delay 1.0;
exit when Output'Length >= 3
and then Output (1..3) = "end";
end;
end loop;
end;
New_Line (2);
Put_Line ("End 'Nonblocking_Pipe' test.");
end Test_Nonblocking_Pipe;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P R J . U T I L --
-- --
-- S p e c --
-- --
-- Copyright (C) 2001-2012, 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. --
-- --
------------------------------------------------------------------------------
-- Utilities for use in processing project files
package Prj.Util is
function Executable_Of
(Project : Project_Id;
Shared : Shared_Project_Tree_Data_Access;
Main : File_Name_Type;
Index : Int;
Ada_Main : Boolean := True;
Language : String := "";
Include_Suffix : Boolean := True) return File_Name_Type;
-- Return the value of the attribute Builder'Executable for file Main in
-- the project Project, if it exists. If there is no attribute Executable
-- for Main, remove the suffix from Main; then, if the attribute
-- Executable_Suffix is specified, add this suffix, otherwise add the
-- standard executable suffix for the platform.
--
-- If Include_Suffix is true, then the ".exe" suffix (or any suffix defined
-- in the config) will be added. The suffix defined by the user in his own
-- project file is always taken into account. Otherwise, such a suffix is
-- not added. In particular, the prefix should not be added if you are
-- potentially testing for cross-platforms, since the suffix might not be
-- known (its default value comes from the ...-gnatmake prefix).
--
-- What is Ada_Main???
-- What is Language???
procedure Put
(Into_List : in out Name_List_Index;
From_List : String_List_Id;
In_Tree : Project_Tree_Ref;
Lower_Case : Boolean := False);
-- Append a name list to a string list
-- Describe parameters???
procedure Duplicate
(This : in out Name_List_Index;
Shared : Shared_Project_Tree_Data_Access);
-- Duplicate a name list
function Value_Of
(Variable : Variable_Value;
Default : String) return String;
-- Get the value of a single string variable. If Variable is a string list,
-- is Nil_Variable_Value,or is defaulted, return Default.
function Value_Of
(Index : Name_Id;
In_Array : Array_Element_Id;
Shared : Shared_Project_Tree_Data_Access) return Name_Id;
-- Get a single string array component. Returns No_Name if there is no
-- component Index, if In_Array is null, or if the component is a String
-- list. Depending on the attribute (only attributes may be associative
-- arrays) the index may or may not be case sensitive. If the index is not
-- case sensitive, it is first set to lower case before the search in the
-- associative array.
function Value_Of
(Index : Name_Id;
Src_Index : Int := 0;
In_Array : Array_Element_Id;
Shared : Shared_Project_Tree_Data_Access;
Force_Lower_Case_Index : Boolean := False;
Allow_Wildcards : Boolean := False) return Variable_Value;
-- Get a string array component (single String or String list). Returns
-- Nil_Variable_Value if no component Index or if In_Array is null.
--
-- Depending on the attribute (only attributes may be associative arrays)
-- the index may or may not be case sensitive. If the index is not case
-- sensitive, it is first set to lower case before the search in the
-- associative array.
function Value_Of
(Name : Name_Id;
Index : Int := 0;
Attribute_Or_Array_Name : Name_Id;
In_Package : Package_Id;
Shared : Shared_Project_Tree_Data_Access;
Force_Lower_Case_Index : Boolean := False;
Allow_Wildcards : Boolean := False) return Variable_Value;
-- In a specific package:
-- - if there exists an array Attribute_Or_Array_Name with an index Name,
-- returns the corresponding component (depending on the attribute, the
-- index may or may not be case sensitive, see previous function),
-- - otherwise if there is a single attribute Attribute_Or_Array_Name,
-- returns this attribute,
-- - otherwise, returns Nil_Variable_Value.
-- If In_Package is null, returns Nil_Variable_Value.
function Value_Of
(Index : Name_Id;
In_Array : Name_Id;
In_Arrays : Array_Id;
Shared : Shared_Project_Tree_Data_Access) return Name_Id;
-- Get a string array component in an array of an array list. Returns
-- No_Name if there is no component Index, if In_Arrays is null, if
-- In_Array is not found in In_Arrays or if the component is a String list.
function Value_Of
(Name : Name_Id;
In_Arrays : Array_Id;
Shared : Shared_Project_Tree_Data_Access) return Array_Element_Id;
-- Returns a specified array in an array list. Returns No_Array_Element
-- if In_Arrays is null or if Name is not the name of an array in
-- In_Arrays. The caller must ensure that Name is in lower case.
function Value_Of
(Name : Name_Id;
In_Packages : Package_Id;
Shared : Shared_Project_Tree_Data_Access) return Package_Id;
-- Returns a specified package in a package list. Returns No_Package
-- if In_Packages is null or if Name is not the name of a package in
-- Package_List. The caller must ensure that Name is in lower case.
function Value_Of
(Variable_Name : Name_Id;
In_Variables : Variable_Id;
Shared : Shared_Project_Tree_Data_Access) return Variable_Value;
-- Returns a specified variable in a variable list. Returns null if
-- In_Variables is null or if Variable_Name is not the name of a
-- variable in In_Variables. Caller must ensure that Name is lower case.
procedure Write_Str
(S : String;
Max_Length : Positive;
Separator : Character);
-- Output string S using Output.Write_Str. If S is too long to fit in one
-- line of Max_Length, cut it in several lines, using Separator as the last
-- character of each line, if possible.
type Text_File is limited private;
-- Represents a text file (default is invalid text file)
function Is_Valid (File : Text_File) return Boolean;
-- Returns True if File designates an open text file that has not yet been
-- closed.
procedure Open (File : out Text_File; Name : String);
-- Open a text file to read (File is invalid if text file cannot be opened)
procedure Create (File : out Text_File; Name : String);
-- Create a text file to write (File is invalid if text file cannot be
-- created).
function End_Of_File (File : Text_File) return Boolean;
-- Returns True if the end of the text file File has been reached. Fails if
-- File is invalid. Return True if File is an out file.
procedure Get_Line
(File : Text_File;
Line : out String;
Last : out Natural);
-- Reads a line from an open text file (fails if File is invalid or in an
-- out file).
procedure Put (File : Text_File; S : String);
procedure Put_Line (File : Text_File; Line : String);
-- Output a string or a line to an out text file (fails if File is invalid
-- or in an in file).
procedure Close (File : in out Text_File);
-- Close an open text file. File becomes invalid. Fails if File is already
-- invalid or if an out file cannot be closed successfully.
-----------------------
-- Source info files --
-----------------------
procedure Write_Source_Info_File (Tree : Project_Tree_Ref);
-- Create a new source info file, with the path name specified in the
-- project tree data. Issue a warning if it is not possible to create
-- the new file.
procedure Read_Source_Info_File (Tree : Project_Tree_Ref);
-- Check if there is a source info file specified for the project Tree. If
-- so, attempt to read it. If the file exists and is successfully read, set
-- the flag Source_Info_File_Exists to True for the tree.
type Source_Info_Data is record
Project : Name_Id;
Language : Name_Id;
Kind : Source_Kind;
Display_Path_Name : Name_Id;
Path_Name : Name_Id;
Unit_Name : Name_Id := No_Name;
Index : Int := 0;
Naming_Exception : Naming_Exception_Type := No;
end record;
-- Data read from a source info file for a single source
type Source_Info is access all Source_Info_Data;
No_Source_Info : constant Source_Info := null;
type Source_Info_Iterator is private;
-- Iterator to get the sources for a single project
procedure Initialize
(Iter : out Source_Info_Iterator;
For_Project : Name_Id);
-- Initialize Iter for the project
function Source_Info_Of (Iter : Source_Info_Iterator) return Source_Info;
-- Get the source info for the source corresponding to the current value of
-- the iterator. Returns No_Source_Info if there is no source corresponding
-- to the iterator.
procedure Next (Iter : in out Source_Info_Iterator);
-- Advance the iterator to the next source in the project
generic
with procedure Action (Source : Source_Id);
procedure For_Interface_Sources
(Tree : Project_Tree_Ref;
Project : Project_Id);
-- Call Action for every sources that are needed to use Project. This is
-- either the sources corresponding to the units in attribute Interfaces
-- or all sources of the project. Note that only the bodies that are
-- needed (because the unit is generic or contains some inline pragmas)
-- are handled. This routine must be called only when the project has
-- been built successfully.
private
type Text_File_Data is record
FD : File_Descriptor := Invalid_FD;
Out_File : Boolean := False;
Buffer : String (1 .. 1_000);
Buffer_Len : Natural := 0;
Cursor : Natural := 0;
End_Of_File_Reached : Boolean := False;
end record;
type Text_File is access Text_File_Data;
type Source_Info_Iterator is record
Info : Source_Info;
Next : Natural;
end record;
end Prj.Util;
|
package body agar.gui.widget.progress_bar is
package cbinds is
procedure set_width
(bar : progress_bar_access_t;
width : c.int);
pragma import (c, set_width, "AG_ProgressBarPercent");
end cbinds;
procedure set_width
(bar : progress_bar_access_t;
width : natural) is
begin
cbinds.set_width
(bar => bar,
width => c.int (width));
end set_width;
function widget (bar : progress_bar_access_t) return widget_access_t is
begin
return bar.widget'access;
end widget;
end agar.gui.widget.progress_bar;
|
-- Auto_Counters_Suite
-- Unit tests for Auto_Counters packages
-- Copyright (c) 2016, James Humphry - see LICENSE file for details
with AUnit.Test_Suites;
package Auto_Counters_Suite is
function Suite return AUnit.Test_Suites.Access_Test_Suite;
end Auto_Counters_Suite;
|
------------------------------------------------------------------------------
-- --
-- GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . T A S K _ P R I M I T I V E S --
-- --
-- B o d y --
-- --
-- $Revision: 1.1 $ --
-- --
-- Copyright (C) 1991,1992,1993,1994,1996 Florida State University --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU Library General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. GNARL is distributed in the hope that it will be use- --
-- ful, but but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Gen- --
-- eral Library Public License for more details. You should have received --
-- a copy of the GNU Library General Public License along with GNARL; see --
-- file COPYING.LIB. If not, write to the Free Software Foundation, 675 --
-- Mass Ave, Cambridge, MA 02139, USA. --
-- --
------------------------------------------------------------------------------
with GNAT.IO;
with Interfaces.C.POSIX_timers;
with Interfaces.C.POSIX_Error;
use Interfaces.C.POSIX_Error;
with Interfaces.C.POSIX_RTE;
use Interfaces.C.POSIX_RTE;
with Interfaces.C.Pthreads;
use Interfaces.C.Pthreads;
with Interfaces.C;
use Interfaces.C;
with System.Tasking;
use System.Tasking;
with System.Storage_Elements;
use System.Storage_Elements;
with System.Compiler_Exceptions;
use System.Compiler_Exceptions;
with System.Task_Specific_Data;
use System.Task_Specific_Data;
with System.Secondary_Stack;
use System.Secondary_Stack;
with System.Tasking_Soft_Links;
with System.Task_Clock;
use System.Task_Clock;
with Unchecked_Conversion;
with Interfaces.C.System_Constants;
package body System.Task_Primitives is
use Interfaces.C.Pthreads;
use Interfaces.C.System_Constants;
package RTE renames Interfaces.C.POSIX_RTE;
package TSL renames System.Tasking_Soft_Links;
Test_And_Set_Mutex : Lock;
Abort_Signal : constant := 6;
Abort_Handler : Abort_Handler_Pointer;
ATCB_Key : aliased pthread_key_t;
Unblocked_Signal_Mask : aliased RTE.Signal_Set;
-- The set of signals that should be unblocked in a task.
-- This is in general the signals that can be generated synchronously,
-- and which should therefore be converted into Ada exceptions.
-- It also includes the Abort_Signal, to allow asynchronous abortion.
function To_void_ptr is new
Unchecked_Conversion (TCB_Ptr, void_ptr);
function To_TCB_Ptr is new
Unchecked_Conversion (void_ptr, TCB_Ptr);
function pthread_mutexattr_setprotocol
(attr : access pthread_attr_t; priority : integer) return int;
pragma Import (C,
pthread_mutexattr_setprotocol,
"pthread_mutexattr_setprotocol",
"pthread_mutexattr_setprotocol");
function pthread_mutexattr_setprio_ceiling
(attr : access pthread_attr_t; priority : int) return int;
pragma Import (C,
pthread_mutexattr_setprio_ceiling,
"pthread_mutexattr_setprio_ceiling",
"pthread_mutexattr_setprio_ceiling");
pthread_mutexattr_default : pthread_mutexattr_t;
pragma Import (C, pthread_mutexattr_default,
"pthread_mutexattr_default",
"pthread_mutexattr_default");
-----------------------
-- Local Subprograms --
-----------------------
procedure Abort_Wrapper
(signo : Integer;
info : RTE.siginfo_ptr;
context : System.Address);
-- This is a signal handler procedure which calls the user-specified
-- abort handler procedure.
procedure LL_Wrapper (T : TCB_Ptr);
-- A wrapper procedure that is called from a new low-level task.
-- It performs initializations for the new task and calls the
-- user-specified startup procedure.
-------------------------
-- Initialize_LL_Tasks --
-------------------------
procedure Initialize_LL_Tasks (T : TCB_Ptr) is
Result : int;
begin
T.LL_Entry_Point := null;
T.Thread := pthread_self;
Result := pthread_key_create (ATCB_Key'Access, null);
if Result = FUNC_ERR then
raise Storage_Error; -- Insufficient resources.
end if;
T.Thread := pthread_self;
Result := pthread_setspecific (ATCB_Key, To_void_ptr (T));
if Result = FUNC_ERR then
GNAT.IO.Put_Line ("Get specific failed");
raise Storage_Error; -- Insufficient resources.
end if;
pragma Assert (Result /= FUNC_ERR,
"GNULLI failure---pthread_setspecific");
end Initialize_LL_Tasks;
----------
-- Self --
----------
function Self return TCB_Ptr is
Temp : aliased void_ptr;
Result : int;
begin
Result := pthread_getspecific (ATCB_Key, Temp'Access);
pragma Assert (Result /= FUNC_ERR,
"GNULLI failure---pthread_getspecific");
return To_TCB_Ptr (Temp);
end Self;
---------------------
-- Initialize_Lock --
---------------------
procedure Initialize_Lock
(Prio : System.Any_Priority;
L : in out Lock)
is
Attributes : aliased pthread_mutexattr_t;
Result : int;
MUTEX_NONRECURSIVE_NP : constant := 2;
begin
Result := pthread_mutexattr_init (Attributes'Access);
if Result = FUNC_ERR then
raise STORAGE_ERROR; -- should be ENOMEM
end if;
Result := pthread_mutexattr_setkind
(Attributes'Access, MUTEX_NONRECURSIVE_NP);
if Result = FUNC_ERR then
raise STORAGE_ERROR; -- should be ENOMEM
end if;
Result := pthread_mutex_init (L.mutex'Access, Attributes);
if Result = FUNC_ERR then
Result := pthread_mutexattr_destroy (Attributes'Access);
raise STORAGE_ERROR; -- should be ENOMEM ???
end if;
Result := pthread_mutexattr_destroy (Attributes'Access);
end Initialize_Lock;
-------------------
-- Finalize_Lock --
-------------------
procedure Finalize_Lock (L : in out Lock) is
Result : int;
begin
Result := pthread_mutex_destroy (L.mutex'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_mutex_destroy");
end Finalize_Lock;
----------------
-- Write_Lock --
----------------
--
-- The current pthreads implementation does not check for Ceiling
-- violations.
--
procedure Write_Lock (L : in out Lock; Ceiling_Violation : out Boolean) is
Result : int;
begin
Ceiling_Violation := False;
Result := pthread_mutex_lock (L.mutex'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI FUNC_ERR---pthread_mutex_lock");
end Write_Lock;
---------------
-- Read_Lock --
---------------
procedure Read_Lock (L : in out Lock; Ceiling_Violation : out Boolean)
renames Write_Lock;
------------
-- Unlock --
------------
procedure Unlock (L : in out Lock) is
Result : int;
begin
Result := pthread_mutex_unlock (L.mutex'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI FUNC_ERR---pthread_mutex_unlock");
end Unlock;
---------------------
-- Initialize_Cond --
---------------------
procedure Initialize_Cond (Cond : in out Condition_Variable) is
Attributes : aliased Pthreads.pthread_condattr_t;
Result : int;
begin
Result := pthread_condattr_init (Attributes'Access);
if Result = FUNC_ERR then
raise STORAGE_ERROR; -- should be ENOMEM ???
end if;
-- Result := pthread_cond_init (Cond.CV'Access, Attributes'Access);
Result := pthread_cond_init (Cond.CV'Access, Attributes);
if Result = FUNC_ERR then
raise STORAGE_ERROR; -- should be ENOMEM ???
end if;
Result := pthread_condattr_destroy (Attributes'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI FUNC_ERR---pthread_condattr_destroy");
end Initialize_Cond;
-------------------
-- Finalize_Cond --
-------------------
procedure Finalize_Cond (Cond : in out Condition_Variable) is
Result : int;
begin
Result := pthread_cond_destroy (Cond.CV'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_cond_destroy");
end Finalize_Cond;
---------------
-- Cond_Wait --
---------------
procedure Cond_Wait (Cond : in out Condition_Variable; L : in out Lock) is
Result : int;
begin
Result := pthread_cond_wait (Cond.CV'Access, L.mutex'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_cond_wait");
end Cond_Wait;
---------------------
-- Cond_Timed_Wait --
---------------------
procedure Cond_Timed_Wait
(Cond : in out Condition_Variable;
L : in out Lock;
Abs_Time : System.Task_Clock.Stimespec;
Timed_Out : out Boolean) is
Result : int;
TV : aliased timespec;
use POSIX_Error;
begin
Timed_Out := False; -- Assume success until we know otherwise
TV.tv_sec := int (Interfaces.C.POSIX_timers.time_t
(Task_Clock.Stimespec_Seconds (Abs_Time)));
TV.tv_nsec := long (Interfaces.C.POSIX_timers.Nanoseconds
(Task_Clock.Stimespec_NSeconds (Abs_Time)));
Result := pthread_cond_timedwait
(Cond.CV'Access, L.mutex'Access, TV'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_cond_timedwait");
end Cond_Timed_Wait;
-----------------
-- Cond_Signal --
-----------------
procedure Cond_Signal (Cond : in out Condition_Variable) is
Result : int;
begin
Result := pthread_cond_signal (Cond.CV'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_cond_signal");
end Cond_Signal;
------------------
-- Set_Priority --
------------------
procedure Set_Priority
(T : TCB_Ptr;
Prio : System.Any_Priority) is
Result : int;
Thread : Pthreads.pthread_t renames T.Thread;
begin
Result := pthread_setprio (Thread, int (Prio));
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_setprio");
end Set_Priority;
----------------------
-- Set_Own_Priority --
----------------------
procedure Set_Own_Priority (Prio : System.Any_Priority) is
begin
null;
-- ENOSYS Result :=
-- pthread_setprio (pthread_self, int (Prio));
-- pragma Assert
-- (Result /= FUNC_ERR, "GNULLI failure---pthread_setprio");
end Set_Own_Priority;
------------------
-- Get_Priority --
------------------
function Get_Priority (T : TCB_Ptr) return System.Any_Priority is
Priority : aliased int := 0;
begin
-- ENOSYS Result := pthread_getprio (T.Thread, Priority'Access);
-- pragma Assert
-- (Result /= FUNC_ERR, "GNULLI failure---pthread_getprio");
return System.Priority (Priority);
end Get_Priority;
-----------------------
-- Get_Own_Priority --
-----------------------
function Get_Own_Priority return System.Any_Priority is
Result : int;
Priority : aliased int := 0;
begin
Result := pthread_getprio (pthread_self, Priority'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_getprio");
return System.Priority (Priority);
end Get_Own_Priority;
--------------------
-- Create_LL_Task --
--------------------
procedure Create_LL_Task
(Priority : System.Any_Priority;
Stack_Size : Task_Storage_Size;
Task_Info : System.Task_Info.Task_Info_Type;
LL_Entry_Point : LL_Task_Procedure_Access;
Arg : System.Address;
T : TCB_Ptr) is
use Pthreads;
Attributes : aliased pthread_attr_t;
Result : int;
L_Priority : System.Any_Priority := Priority;
function To_Start_Addr is new
Unchecked_Conversion (System.Address, start_addr);
begin
T.LL_Entry_Point := LL_Entry_Point;
T.LL_Arg := Arg;
T.Stack_Size := Stack_Size;
Result := pthread_attr_init (Attributes'Access);
pragma Assert (Result /= FUNC_ERR, "GNULLI failure---pthread_attr_init");
-- Result := pthread_attr_setdetachstate (Attributes'Access, 1);
-- pragma Assert
-- (Result /= FUNC_ERR, "GNULLI failure---pthread_setdetachstate");
Result := pthread_attr_setstacksize
(Attributes'Access, size_t (Stack_Size));
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_setstacksize");
Result := pthread_attr_setinheritsched
(Attributes'Access, PTHREAD_DEFAULT_SCHED);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_setinheritsched");
Result := pthread_attr_setsched
(Attributes'Access, SCHED_FIFO);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_setinheritsched");
-- The following priority adjustment is a kludge to get around needing
-- root privileges to run at higher than 18 for FIFO or 19 for OTHER.
if (L_Priority > 18) then
L_Priority := 18;
elsif (L_Priority < 14) then
L_Priority := 14;
end if;
Result := pthread_attr_setprio
(Attributes'Access, int (L_Priority));
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_attr_setprio");
Result := pthread_create
(T.Thread'Access,
Attributes,
To_Start_Addr (LL_Wrapper'Address),
T.all'Address);
if Result = FUNC_ERR then
GNAT.IO.Put_Line ("pthread create failed");
raise Storage_Error;
end if;
pragma Assert (Result /= FUNC_ERR, "GNULLI failure---pthread_create");
Result := pthread_attr_destroy (Attributes'Access);
pragma Assert
(Result /= FUNC_ERR, "GNULLI failure---pthread_attr_destroy");
end Create_LL_Task;
-----------------
-- Exit_LL_Task --
------------------
procedure Exit_LL_Task is
begin
pthread_exit (System.Null_Address);
end Exit_LL_Task;
----------------
-- Abort_Task --
----------------
procedure Abort_Task (T : TCB_Ptr) is
Result : int;
begin
-- Result := pthread_kill (T.Thread);
-- pragma Assert
-- (Result /= FUNC_ERR, "GNULLI failure---pthread_kill");
null;
end Abort_Task;
----------------
-- Test_Abort --
----------------
-- This procedure does nothing. It is intended for systems without
-- asynchronous abortion, where the runtime system would have to
-- synchronously poll for pending abortions. This should be done
-- at least at every synchronization point.
procedure Test_Abort is
begin
null;
end Test_Abort;
---------------------------
-- Install_Abort_Handler --
---------------------------
procedure Install_Abort_Handler (Handler : Abort_Handler_Pointer) is
act : aliased RTE.struct_sigaction;
old_act : aliased RTE.struct_sigaction;
Result : POSIX_Error.Return_Code;
SA_SIGINFO : constant := 64;
use type POSIX_Error.Return_Code;
begin
Abort_Handler := Handler;
act.sa_flags := SA_SIGINFO;
act.sa_handler := Abort_Wrapper'Address;
RTE.sigemptyset (act.sa_mask'Access, Result);
pragma Assert (Result /= FUNC_ERR, "GNULLI failure---sigemptyset");
RTE.sigaction (Abort_Signal, act'Access, old_act'Access, Result);
pragma Assert (Result /= FUNC_ERR, "GNULLI failure---sigaction");
end Install_Abort_Handler;
-------------------
-- Abort_Wrapper --
-------------------
-- This is the handler called by the OS when an abort signal is
-- received; it in turn calls the handler installed by the client.
-- This procedure serves to isolate the client from the
-- implementation-specific calling conventions of asynchronous
-- handlers.
procedure Abort_Wrapper
(signo : Integer;
info : RTE.siginfo_ptr;
context : System.Address)
is
function Address_To_Call_State is new
Unchecked_Conversion (System.Address, Pre_Call_State);
begin
Abort_Handler (Address_To_Call_State (context));
end Abort_Wrapper;
---------------------------
-- Install_Error_Handler --
---------------------------
procedure Install_Error_Handler (Handler : System.Address) is
Temp : Address;
use Pthreads;
begin
-- Set up the soft links to tasking services used in the absence of
-- tasking. These replace tasking-free defaults.
Temp := TSL.Get_Jmpbuf_Address.all;
-- pthread_set_jumpbuf_address (Temp);
Temp := TSL.Get_Sec_Stack_Addr.all;
-- pthread_set_sec_stack_addr (Temp);
-- TSL.Get_Jmpbuf_Address := pthread_get_jumpbuf_address'Access;
-- TSL.Set_Jmpbuf_Address := pthread_set_jumpbuf_address'Access;
-- TSL.Get_Gnat_Exception := pthread_get_exception'Access;
-- TSL.Set_Gnat_Exception := pthread_set_exception'Access;
end Install_Error_Handler;
---------------
-- LL_Assert --
---------------
procedure LL_Assert (B : Boolean; M : String) is
begin
null;
end LL_Assert;
----------------
-- LL_Wrapper --
----------------
procedure LL_Wrapper (T : TCB_Ptr) is
Result : POSIX_Error.Return_Code;
Result1 : int;
Exc_Stack : String (1 .. 256);
Exc_Base : Address := Exc_Stack (Exc_Stack'Last)'Address + 1;
Old_Set : aliased RTE.Signal_Set;
begin
Result1 := pthread_setspecific (ATCB_Key, T.all'Address);
RTE.sigprocmask (
RTE.SIG_UNBLOCK, Unblocked_Signal_Mask'Access, Old_Set'Access, Result);
pragma Assert (
Result /= Failure, "GNULLI failure---sigprocmask");
-- Note that the following call may not return!
T.LL_Entry_Point (T.LL_Arg);
end LL_Wrapper;
--------------------------
-- Test and Set support --
--------------------------
procedure Initialize_TAS_Cell (Cell : out TAS_Cell) is
begin
Cell.Value := 0;
end Initialize_TAS_Cell;
procedure Finalize_TAS_Cell (Cell : in out TAS_Cell) is
begin
null;
end Finalize_TAS_Cell;
procedure Clear (Cell : in out TAS_Cell) is
begin
Cell.Value := 1;
end Clear;
procedure Test_And_Set (Cell : in out TAS_Cell; Result : out Boolean) is
Error : Boolean;
begin
Write_Lock (Test_And_Set_Mutex, Error);
if Cell.Value = 1 then
Result := False;
else
Result := True;
Cell.Value := 1;
end if;
Unlock (Test_And_Set_Mutex);
end Test_And_Set;
function Is_Set (Cell : in TAS_Cell) return Boolean is
begin
return Cell.Value = 1;
end Is_Set;
begin
Initialize_Lock (System.Any_Priority'Last, Test_And_Set_Mutex);
end System.Task_Primitives;
|
with Ada.Text_IO; use Ada.Text_IO;
with Vecteurs_Creux; use Vecteurs_Creux;
-- Exemple d'utilisation des vecteurs creux.
procedure Exemple_Vecteurs_Creux is
V : T_Vecteur_Creux;
begin
Put_Line ("Début du scénario");
New_Line;
Initialiser (V); -- Initialiser un vecteur creux. Il est nul.
Afficher (V); -- Afficher le vecteur creux à des fins de mise au point.
Put_Line ("Est-ce que le vecteur V est nul : " & Boolean'Image(Est_Nul (V)));
Put ("Version récursive : la composante du vecteur V à l'indice Indice 18 : ");
Put_Line (Float'Image(Composante_Recursif (V, 18)));
Put ("Version itérative : la composante du vecteur V à l'indice Indice 18 : ");
Put_Line (Float'Image(Composante_Iteratif (V, 18)));
Modifier (V, 2, 5.9); -- Modifier la composante (2, 5.9).
Put_Line ("Modifier la composante (2, 5.9)");
Afficher (V); -- Afficher le vecteur creux à des fins de mise au point.
Modifier (V, 3, 1.3); -- Modifier la composante (2, 1.93).
Put_Line ("Modifier la composante (3, 1.3)");
Afficher (V); -- Afficher le vecteur creux à des fins de mise au point.
Modifier (V, 1, 99.15); -- Modifier la composante (1, 99.15).
Put_Line ("Modifier la composante (1, 99.15)");
Afficher (V); -- Afficher le vecteur creux à des fins de mise au point.
Modifier (V, 1, 10.0); -- Modifier la composante (1, 99.15).
Put_Line ("Modifier la composante (1, 99.15)");
Afficher (V); -- Afficher le vecteur creux à des fins de mise au point.
Detruire (V); -- Détruire le vecteur V.
New_Line;
Put_Line ("Fin du scénario");
end Exemple_Vecteurs_Creux;
|
-----------------------------------------------------------------------
-- wiki-helpers-parser -- Generic procedure for the wiki parser
-- Copyright (C) 2016, 2018 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- 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 Wiki.Helpers;
with Wiki.Streams;
procedure Wiki.Helpers.Parser (Engine : in out Engine_Type;
Content : in Element_Type;
Doc : in out Wiki.Documents.Document) is
type Wide_Input is new Wiki.Streams.Input_Stream with record
Pos : Positive;
Len : Natural;
end record;
overriding
procedure Read (Buf : in out Wide_Input;
Token : out Wiki.Strings.WChar;
Is_Eof : out Boolean);
procedure Read (Buf : in out Wide_Input;
Token : out Wiki.Strings.WChar;
Is_Eof : out Boolean) is
begin
if Buf.Pos <= Buf.Len then
Element (Content, Buf.Pos, Token);
Is_Eof := False;
else
Is_Eof := True;
Token := Wiki.Helpers.CR;
end if;
end Read;
Buffer : aliased Wide_Input;
begin
Buffer.Pos := 1;
Buffer.Len := Length (Content);
Parse (Engine, Buffer'Unchecked_Access, Doc);
end Wiki.Helpers.Parser;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . T R A C E S . S E N D --
-- --
-- B o d y --
-- --
-- Copyright (C) 2001-2005 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, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, 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. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This version is for VxWorks targets.
-- Trace information is sent to WindView using the wvEvent function.
-- Note that wvEvent is from the VxWorks API.
-- When adding a new event, just give an Id to then event, and then modify
-- the WindView events database.
-- Refer to WindView User's Guide for more details on how to add new events
-- to the events database.
----------------
-- Send_Trace --
----------------
-- This procedure formats the string, maps the event Id to an Id
-- recognized by WindView, and send the event using wvEvent
separate (System.Traces.Format)
procedure Send_Trace (Id : Trace_T; Info : String) is
procedure Wv_Event
(Id : Integer;
Buffer : System.Address;
Size : Integer);
pragma Import (C, Wv_Event, "wvEvent");
Info_Trace : String_Trace;
Id_Event : Integer;
begin
Info_Trace := Format_Trace (Info);
case Id is
when M_Accept_Complete => Id_Event := 30000;
when M_Select_Else => Id_Event := 30001;
when M_RDV_Complete => Id_Event := 30002;
when M_Call_Complete => Id_Event := 30003;
when M_Delay => Id_Event := 30004;
when E_Kill => Id_Event := 30005;
when E_Missed => Id_Event := 30006;
when E_Timeout => Id_Event := 30007;
when W_Call => Id_Event := 30010;
when W_Accept => Id_Event := 30011;
when W_Select => Id_Event := 30012;
when W_Completion => Id_Event := 30013;
when W_Delay => Id_Event := 30014;
when WT_Select => Id_Event := 30015;
when WT_Call => Id_Event := 30016;
when WT_Completion => Id_Event := 30017;
when WU_Delay => Id_Event := 30018;
when PO_Call => Id_Event := 30020;
when POT_Call => Id_Event := 30021;
when PO_Run => Id_Event := 30022;
when PO_Lock => Id_Event := 30023;
when PO_Unlock => Id_Event := 30024;
when PO_Done => Id_Event := 30025;
when T_Create => Id_Event := 30030;
when T_Activate => Id_Event := 30031;
when T_Abort => Id_Event := 30032;
when T_Terminate => Id_Event := 30033;
-- Unrecognized events are given the special Id_Event value 29999
when others => Id_Event := 29999;
end case;
Wv_Event (Id_Event, Info_Trace'Address, Max_Size);
end Send_Trace;
|
------------------------------------------------------------------------------
-- --
-- Copyright © AdaCore and other contributors, 2017-2020 --
-- See https://github.com/AdaCore/Ada_Drivers_Library/graphs/contributors --
-- for more information --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. 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. --
-- 3. 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 --
-- 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. --
-- --
------------------------------------------------------------------------------
with NRF_SVD.SAADC; use NRF_SVD.SAADC;
with nRF.Tasks; use nRF.Tasks;
with System.Storage_Elements;
package body nRF.ADC is
procedure Set_Resolution (Res : Bits_Resolution);
procedure Set_Reference (Ref : Reference_Selection);
procedure Wait_For_Result;
--------------------
-- Set_Resolution --
--------------------
procedure Set_Resolution (Res : Bits_Resolution) is
begin
SAADC_Periph.RESOLUTION.VAL :=
(case Res is
when Res_8bit => Val_8BIT,
when Res_10bit => Val_10BIT,
when Res_12bit => Val_12BIT);
end Set_Resolution;
-------------------
-- Set_Reference --
-------------------
procedure Set_Reference (Ref : Reference_Selection) is
begin
case Ref is
when Internal_0V6 =>
SAADC_Periph.CH (0).CONFIG.REFSEL := Internal;
when VDD_One_Forth =>
SAADC_Periph.CH (0).CONFIG.REFSEL := Vdd1_4;
end case;
end Set_Reference;
--------------------------
-- Start_Pin_Conversion --
--------------------------
function Do_Pin_Conversion
(Pin : Analog_Pin;
Input : Pin_Input_Selection;
Ref : Reference_Selection;
Res : Bits_Resolution) return UInt16
is
Result : UInt16 with Volatile;
begin
Set_Resolution (Res);
Set_Reference (Ref);
SAADC_Periph.RESULT.PTR := UInt32 (System.Storage_Elements.To_Integer (Result'Address));
SAADC_Periph.RESULT.MAXCNT.MAXCNT := 1;
case Input is
when Pin_Quadruple =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain4;
when Pin_Double =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain2;
when Pin_Full =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain1;
when Pin_Half =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain1_2;
when Pin_One_Third =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain1_3;
when Pin_One_Forth =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain1_4;
when Pin_One_Fifth =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain1_5;
when Pin_One_Sixth =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain1_6;
end case;
case Pin is
when 0 =>
SAADC_Periph.CH (0).PSELP.PSELP := Analoginput0;
when 1 =>
SAADC_Periph.CH (0).PSELP.PSELP := Analoginput1;
when 2 =>
SAADC_Periph.CH (0).PSELP.PSELP := Analoginput2;
when 3 =>
SAADC_Periph.CH (0).PSELP.PSELP := Analoginput3;
when 4 =>
SAADC_Periph.CH (0).PSELP.PSELP := Analoginput4;
when 5 =>
SAADC_Periph.CH (0).PSELP.PSELP := Analoginput5;
when 6 =>
SAADC_Periph.CH (0).PSELP.PSELP := Analoginput6;
when 7 =>
SAADC_Periph.CH (0).PSELP.PSELP := Analoginput7;
end case;
SAADC_Periph.ENABLE.ENABLE := Enabled;
Trigger (ADC_START);
Wait_For_Result;
return Result;
end Do_Pin_Conversion;
--------------------------
-- Start_VDD_Conversion --
--------------------------
function Do_VDD_Conversion
(Input : VDD_Input_Selection;
Ref : Reference_Selection;
Res : Bits_Resolution) return UInt16
is
Result : UInt16 with Volatile;
begin
Set_Resolution (Res);
Set_Reference (Ref);
SAADC_Periph.CH (0).PSELP.PSELP := Vdd;
SAADC_Periph.RESULT.PTR := UInt32 (System.Storage_Elements.To_Integer (Result'Address));
SAADC_Periph.RESULT.MAXCNT.MAXCNT := 1;
case Input is
when VDD_One_Fifth =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain1_5;
when VDD_One_Sixth =>
SAADC_Periph.CH (0).CONFIG.GAIN := Gain1_6;
end case;
SAADC_Periph.ENABLE.ENABLE := Enabled;
Trigger (ADC_START);
Wait_For_Result;
return Result;
end Do_VDD_Conversion;
----------
-- Busy --
----------
function Busy return Boolean
is (SAADC_Periph.STATUS.STATUS = Busy);
---------------------
-- Wait_For_Result --
---------------------
procedure Wait_For_Result is
begin
while Busy loop
null;
end loop;
SAADC_Periph.ENABLE.ENABLE := Enabled;
end Wait_For_Result;
end nRF.ADC;
|
-------------------------------------------------------------------------------
-- package body Disorderly.Random.Clock_Entropy, Random Number Initialization
-- Copyright (C) 1995-2018 Jonathan S. Parker
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-------------------------------------------------------------------------------
with Ada.Calendar;
with System; -- for Tick : Duration;
package body Disorderly.Random.Clock_Entropy is
-------------------------
-- Get_Seed_From_Clock --
-------------------------
-- Clock sets initial seed.
-- Seconds (T) is <= 86_400.0.
-- Day (T) is <= 31.0.
--
procedure Get_Seed_From_Clock
(Initiator : out Seed_Random_Int)
is
type Real is digits 15;
Fake_Ticks_per_Second : constant Real := 77_777_777.0;
Seconds_per_Day : constant Real := 86_400.0;
Fake_Ticks_per_Day : constant Real := Fake_Ticks_per_Second * Seconds_per_Day;
Min_Delay : constant Duration := System.Tick;
T : Ada.Calendar.Time;
Seed : Parent_Random_Int;
begin
delay Min_Delay * 3.0;
T := Ada.Calendar.Clock;
Seed := Random_Int (Real (Ada.Calendar.Seconds (T)) * Fake_Ticks_per_Second +
Real (Ada.Calendar.Day (T)) * Fake_Ticks_per_Day);
-- So Seed is the number of elapsed fake ticks in present month.
--
-- Even if Seconds (T) = 0.0000123 we want
-- Seconds (T)) * Fake_Ticks_per_Second to be big integer, so make
-- Fake_Ticks_per_Second very large.
--
-- Max val of Seed ~ 0.83 * 2^51.
Initiator := Seed + 777_777; -- 0 < Seed <= Random_Int'Last
delay Min_Delay * (7.0 + Duration (Initiator mod 77));
-- Minimize likelihood that next call to Reset_with_Calendar produces
-- the same Initiator1, and hence the same state S.
-- Doesn't guarantee that there is no relationship between successive
-- seeds, but such a relationship would be difficult to see.
-- All we need is 1 bit of difference between the outputs of two
-- successive calls to Ada.Calendar.Clock, and the two 256 bit
-- states generated by the successive calls will have no apparent
-- similarities.
end Get_Seed_From_Clock;
-----------
-- Reset --
-----------
procedure Reset
(S : out State)
is
Initiator1, Initiator2 : Seed_Random_Int;
begin
Get_Seed_From_Clock (Initiator1);
Get_Seed_From_Clock (Initiator2);
Disorderly.Random.Reset (S, Initiator1, Initiator2);
end Reset;
end Disorderly.Random.Clock_Entropy;
|
-- C36204D.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- CHECK THAT EACH ARRAY ATTRIBUTE YIELDS THE CORRECT VALUES.
-- BOTH ARRAY OBJECTS AND TYPES ARE CHECKED. THIS TEST CHECKS
-- THE ABOVE FOR ARRAYS WITHIN GENERIC PROGRAM UNITS.
-- HISTROY
-- EDWARD V. BERARD, 9 AUGUST 1990
WITH REPORT ;
WITH SYSTEM ;
PROCEDURE C36204D IS
SHORT_START : CONSTANT := -10 ;
SHORT_END : CONSTANT := 10 ;
TYPE SHORT_RANGE IS RANGE SHORT_START .. SHORT_END ;
SHORT_LENGTH : CONSTANT NATURAL := (SHORT_END - SHORT_START + 1) ;
TYPE MONTH_TYPE IS (JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG,
SEP, OCT, NOV, DEC) ;
SUBTYPE MID_YEAR IS MONTH_TYPE RANGE MAY .. AUG ;
TYPE DAY_TYPE IS RANGE 1 .. 31 ;
TYPE YEAR_TYPE IS RANGE 1904 .. 2050 ;
TYPE DATE IS RECORD
MONTH : MONTH_TYPE ;
DAY : DAY_TYPE ;
YEAR : YEAR_TYPE ;
END RECORD ;
TODAY : DATE := (MONTH => AUG,
DAY => 10,
YEAR => 1990) ;
FIRST_DATE : DATE := (DAY => 6,
MONTH => JUN,
YEAR => 1967) ;
FUNCTION "=" (LEFT : IN SYSTEM.ADDRESS ;
RIGHT : IN SYSTEM.ADDRESS ) RETURN BOOLEAN
RENAMES SYSTEM."=" ;
GENERIC
TYPE FIRST_INDEX IS (<>) ;
FIRST_INDEX_LENGTH : IN NATURAL ;
FIRST_TEST_VALUE : IN FIRST_INDEX ;
TYPE SECOND_INDEX IS (<>) ;
SECOND_INDEX_LENGTH : IN NATURAL ;
SECOND_TEST_VALUE : IN SECOND_INDEX ;
TYPE THIRD_INDEX IS (<>) ;
THIRD_INDEX_LENGTH : IN NATURAL ;
THIRD_TEST_VALUE : IN THIRD_INDEX ;
TYPE FIRST_COMPONENT_TYPE IS PRIVATE ;
FIRST_DEFAULT_VALUE : IN FIRST_COMPONENT_TYPE ;
SECOND_DEFAULT_VALUE : IN FIRST_COMPONENT_TYPE ;
TYPE SECOND_COMPONENT_TYPE IS PRIVATE ;
THIRD_DEFAULT_VALUE : IN SECOND_COMPONENT_TYPE ;
FOURTH_DEFAULT_VALUE : IN SECOND_COMPONENT_TYPE ;
PACKAGE ARRAY_ATTRIBUTE_TEST IS
TYPE MATRIX IS ARRAY (FIRST_INDEX, SECOND_INDEX)
OF FIRST_COMPONENT_TYPE ;
TYPE CUBE IS ARRAY (FIRST_INDEX, SECOND_INDEX, THIRD_INDEX)
OF SECOND_COMPONENT_TYPE ;
END ARRAY_ATTRIBUTE_TEST ;
PACKAGE BODY ARRAY_ATTRIBUTE_TEST IS
FIRST_ARRAY : MATRIX := (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
FIRST_DEFAULT_VALUE)) ;
SECOND_ARRAY : CUBE := (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
(THIRD_INDEX'FIRST .. THIRD_INDEX'LAST =>
THIRD_DEFAULT_VALUE))) ;
THIRD_ARRAY : CONSTANT MATRIX
:= (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
SECOND_DEFAULT_VALUE)) ;
FOURTH_ARRAY : CONSTANT CUBE
:= (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
(THIRD_INDEX'FIRST .. THIRD_INDEX'LAST =>
FOURTH_DEFAULT_VALUE))) ;
FA1 : FIRST_INDEX := FIRST_ARRAY'FIRST (1) ;
FA2 : FIRST_INDEX := FIRST_ARRAY'LAST (1) ;
FA3 : SECOND_INDEX := FIRST_ARRAY'FIRST (2) ;
FA4 : SECOND_INDEX := FIRST_ARRAY'LAST (2) ;
SA1 : FIRST_INDEX := SECOND_ARRAY'FIRST (1) ;
SA2 : FIRST_INDEX := SECOND_ARRAY'LAST (1) ;
SA3 : SECOND_INDEX := SECOND_ARRAY'FIRST (2) ;
SA4 : SECOND_INDEX := SECOND_ARRAY'LAST (2) ;
SA5 : THIRD_INDEX := SECOND_ARRAY'FIRST (3) ;
SA6 : THIRD_INDEX := SECOND_ARRAY'LAST (3) ;
FAL1 : NATURAL := FIRST_ARRAY'LENGTH (1) ;
FAL2 : NATURAL := FIRST_ARRAY'LENGTH (2) ;
SAL1 : NATURAL := SECOND_ARRAY'LENGTH (1) ;
SAL2 : NATURAL := SECOND_ARRAY'LENGTH (2) ;
SAL3 : NATURAL := SECOND_ARRAY'LENGTH (3) ;
MATRIX_SIZE : NATURAL := MATRIX'SIZE ;
CUBE_SIZE : NATURAL := CUBE'SIZE ;
FAA : SYSTEM.ADDRESS := FIRST_ARRAY'ADDRESS ;
SAA : SYSTEM.ADDRESS := SECOND_ARRAY'ADDRESS ;
TAA : SYSTEM.ADDRESS := THIRD_ARRAY'ADDRESS ;
FRAA : SYSTEM.ADDRESS := FOURTH_ARRAY'ADDRESS ;
BEGIN -- ARRAY_ATTRIBUTE_TEST
IF (FA1 /= FIRST_INDEX'FIRST) OR
(FA3 /= SECOND_INDEX'FIRST) OR
(SA1 /= FIRST_INDEX'FIRST) OR
(SA3 /= SECOND_INDEX'FIRST) OR
(SA5 /= THIRD_INDEX'FIRST) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'FIRST - PACKAGE") ;
END IF ;
IF (FA2 /= FIRST_INDEX'LAST) OR
(FA4 /= SECOND_INDEX'LAST) OR
(SA2 /= FIRST_INDEX'LAST) OR
(SA4 /= SECOND_INDEX'LAST) OR
(SA6 /= THIRD_INDEX'LAST) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'LAST - PACKAGE") ;
END IF ;
IF (FAL1 /= FIRST_INDEX_LENGTH) OR
(FAL2 /= SECOND_INDEX_LENGTH) OR
(SAL1 /= FIRST_INDEX_LENGTH) OR
(SAL2 /= SECOND_INDEX_LENGTH) OR
(SAL3 /= THIRD_INDEX_LENGTH) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'LENGTH - PACKAGE") ;
END IF ;
FOR OUTER_INDEX IN FIRST_ARRAY'RANGE (1) LOOP
FOR INNER_INDEX IN FIRST_ARRAY'RANGE (2) LOOP
FIRST_ARRAY (OUTER_INDEX, INNER_INDEX) :=
SECOND_DEFAULT_VALUE ;
END LOOP ;
END LOOP ;
IF FIRST_ARRAY /= THIRD_ARRAY THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"FOR 2-DIMENSIONAL ARRAY. - PACKAGE") ;
END IF ;
FOR OUTER_INDEX IN SECOND_ARRAY'RANGE (1) LOOP
FOR MIDDLE_INDEX IN SECOND_ARRAY'RANGE (2) LOOP
FOR INNER_INDEX IN SECOND_ARRAY'RANGE (3) LOOP
SECOND_ARRAY (OUTER_INDEX, MIDDLE_INDEX, INNER_INDEX)
:= FOURTH_DEFAULT_VALUE ;
END LOOP ;
END LOOP ;
END LOOP ;
IF SECOND_ARRAY /= FOURTH_ARRAY THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"FOR 3-DIMENSIONAL ARRAY. - PACKAGE") ;
END IF ;
IF (FIRST_TEST_VALUE NOT IN FIRST_ARRAY'RANGE (1)) OR
(FIRST_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (1)) OR
(SECOND_TEST_VALUE NOT IN FIRST_ARRAY'RANGE (2)) OR
(SECOND_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (2)) OR
(THIRD_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (3)) THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"- PACKAGE") ;
END IF ;
IF (MATRIX_SIZE = 0) OR (CUBE_SIZE = 0) THEN
REPORT.FAILED ("INCORRECT HANDLING OF THE 'SIZE ATTRIBUTE. " &
"- PACKAGE") ;
END IF ;
IF (FAA = TAA) OR (SAA = FRAA) OR (FAA = SAA) OR (FAA = FRAA)
OR (SAA = TAA) OR (TAA = FRAA) THEN
REPORT.FAILED ("INCORRECT HANDLING OF THE 'ADDRESS ATTRIBUTE. " &
"- PACKAGE") ;
END IF ;
END ARRAY_ATTRIBUTE_TEST ;
GENERIC
TYPE FIRST_INDEX IS (<>) ;
FIRST_INDEX_LENGTH : IN NATURAL ;
FIRST_TEST_VALUE : IN FIRST_INDEX ;
TYPE SECOND_INDEX IS (<>) ;
SECOND_INDEX_LENGTH : IN NATURAL ;
SECOND_TEST_VALUE : IN SECOND_INDEX ;
TYPE THIRD_INDEX IS (<>) ;
THIRD_INDEX_LENGTH : IN NATURAL ;
THIRD_TEST_VALUE : IN THIRD_INDEX ;
TYPE FIRST_COMPONENT_TYPE IS PRIVATE ;
FIRST_DEFAULT_VALUE : IN FIRST_COMPONENT_TYPE ;
SECOND_DEFAULT_VALUE : IN FIRST_COMPONENT_TYPE ;
TYPE SECOND_COMPONENT_TYPE IS PRIVATE ;
THIRD_DEFAULT_VALUE : IN SECOND_COMPONENT_TYPE ;
FOURTH_DEFAULT_VALUE : IN SECOND_COMPONENT_TYPE ;
PROCEDURE PROC_ARRAY_ATT_TEST ;
PROCEDURE PROC_ARRAY_ATT_TEST IS
TYPE MATRIX IS ARRAY (FIRST_INDEX, SECOND_INDEX)
OF FIRST_COMPONENT_TYPE ;
TYPE CUBE IS ARRAY (FIRST_INDEX, SECOND_INDEX, THIRD_INDEX)
OF SECOND_COMPONENT_TYPE ;
FIRST_ARRAY : MATRIX := (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
FIRST_DEFAULT_VALUE)) ;
SECOND_ARRAY : CUBE := (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
(THIRD_INDEX'FIRST .. THIRD_INDEX'LAST =>
THIRD_DEFAULT_VALUE))) ;
THIRD_ARRAY : CONSTANT MATRIX
:= (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
SECOND_DEFAULT_VALUE)) ;
FOURTH_ARRAY : CONSTANT CUBE
:= (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
(THIRD_INDEX'FIRST .. THIRD_INDEX'LAST =>
FOURTH_DEFAULT_VALUE))) ;
FA1 : FIRST_INDEX := FIRST_ARRAY'FIRST (1) ;
FA2 : FIRST_INDEX := FIRST_ARRAY'LAST (1) ;
FA3 : SECOND_INDEX := FIRST_ARRAY'FIRST (2) ;
FA4 : SECOND_INDEX := FIRST_ARRAY'LAST (2) ;
SA1 : FIRST_INDEX := SECOND_ARRAY'FIRST (1) ;
SA2 : FIRST_INDEX := SECOND_ARRAY'LAST (1) ;
SA3 : SECOND_INDEX := SECOND_ARRAY'FIRST (2) ;
SA4 : SECOND_INDEX := SECOND_ARRAY'LAST (2) ;
SA5 : THIRD_INDEX := SECOND_ARRAY'FIRST (3) ;
SA6 : THIRD_INDEX := SECOND_ARRAY'LAST (3) ;
FAL1 : NATURAL := FIRST_ARRAY'LENGTH (1) ;
FAL2 : NATURAL := FIRST_ARRAY'LENGTH (2) ;
SAL1 : NATURAL := SECOND_ARRAY'LENGTH (1) ;
SAL2 : NATURAL := SECOND_ARRAY'LENGTH (2) ;
SAL3 : NATURAL := SECOND_ARRAY'LENGTH (3) ;
MATRIX_SIZE : NATURAL := MATRIX'SIZE ;
CUBE_SIZE : NATURAL := CUBE'SIZE ;
FAA : SYSTEM.ADDRESS := FIRST_ARRAY'ADDRESS ;
SAA : SYSTEM.ADDRESS := SECOND_ARRAY'ADDRESS ;
TAA : SYSTEM.ADDRESS := THIRD_ARRAY'ADDRESS ;
FRAA : SYSTEM.ADDRESS := FOURTH_ARRAY'ADDRESS ;
BEGIN -- PROC_ARRAY_ATT_TEST
IF (FA1 /= FIRST_INDEX'FIRST) OR
(FA3 /= SECOND_INDEX'FIRST) OR
(SA1 /= FIRST_INDEX'FIRST) OR
(SA3 /= SECOND_INDEX'FIRST) OR
(SA5 /= THIRD_INDEX'FIRST) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'FIRST " &
"- PROCEDURE") ;
END IF ;
IF (FA2 /= FIRST_INDEX'LAST) OR
(FA4 /= SECOND_INDEX'LAST) OR
(SA2 /= FIRST_INDEX'LAST) OR
(SA4 /= SECOND_INDEX'LAST) OR
(SA6 /= THIRD_INDEX'LAST) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'LAST " &
"- PROCEDURE") ;
END IF ;
IF (FAL1 /= FIRST_INDEX_LENGTH) OR
(FAL2 /= SECOND_INDEX_LENGTH) OR
(SAL1 /= FIRST_INDEX_LENGTH) OR
(SAL2 /= SECOND_INDEX_LENGTH) OR
(SAL3 /= THIRD_INDEX_LENGTH) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'LENGTH " &
"- PROCEDURE") ;
END IF ;
FOR OUTER_INDEX IN FIRST_ARRAY'RANGE (1) LOOP
FOR INNER_INDEX IN FIRST_ARRAY'RANGE (2) LOOP
FIRST_ARRAY (OUTER_INDEX, INNER_INDEX) :=
SECOND_DEFAULT_VALUE ;
END LOOP ;
END LOOP ;
IF FIRST_ARRAY /= THIRD_ARRAY THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"FOR 2-DIMENSIONAL ARRAY. - PROCEDURE") ;
END IF ;
FOR OUTER_INDEX IN SECOND_ARRAY'RANGE (1) LOOP
FOR MIDDLE_INDEX IN SECOND_ARRAY'RANGE (2) LOOP
FOR INNER_INDEX IN SECOND_ARRAY'RANGE (3) LOOP
SECOND_ARRAY (OUTER_INDEX, MIDDLE_INDEX, INNER_INDEX)
:= FOURTH_DEFAULT_VALUE ;
END LOOP ;
END LOOP ;
END LOOP ;
IF SECOND_ARRAY /= FOURTH_ARRAY THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"FOR 3-DIMENSIONAL ARRAY. - PROCEDURE") ;
END IF ;
IF (FIRST_TEST_VALUE NOT IN FIRST_ARRAY'RANGE (1)) OR
(FIRST_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (1)) OR
(SECOND_TEST_VALUE NOT IN FIRST_ARRAY'RANGE (2)) OR
(SECOND_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (2)) OR
(THIRD_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (3)) THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"- PROCEDURE") ;
END IF ;
IF (MATRIX_SIZE = 0) OR (CUBE_SIZE = 0) THEN
REPORT.FAILED ("INCORRECT HANDLING OF THE 'SIZE ATTRIBUTE. " &
"- PROCEDURE") ;
END IF ;
IF (FAA = TAA) OR (SAA = FRAA) OR (FAA = SAA) OR (FAA = FRAA)
OR (SAA = TAA) OR (TAA = FRAA) THEN
REPORT.FAILED ("INCORRECT HANDLING OF THE 'ADDRESS ATTRIBUTE. " &
"- PROCEDURE") ;
END IF ;
END PROC_ARRAY_ATT_TEST ;
GENERIC
TYPE FIRST_INDEX IS (<>) ;
FIRST_INDEX_LENGTH : IN NATURAL ;
FIRST_TEST_VALUE : IN FIRST_INDEX ;
TYPE SECOND_INDEX IS (<>) ;
SECOND_INDEX_LENGTH : IN NATURAL ;
SECOND_TEST_VALUE : IN SECOND_INDEX ;
TYPE THIRD_INDEX IS (<>) ;
THIRD_INDEX_LENGTH : IN NATURAL ;
THIRD_TEST_VALUE : IN THIRD_INDEX ;
TYPE FIRST_COMPONENT_TYPE IS PRIVATE ;
FIRST_DEFAULT_VALUE : IN FIRST_COMPONENT_TYPE ;
SECOND_DEFAULT_VALUE : IN FIRST_COMPONENT_TYPE ;
TYPE SECOND_COMPONENT_TYPE IS PRIVATE ;
THIRD_DEFAULT_VALUE : IN SECOND_COMPONENT_TYPE ;
FOURTH_DEFAULT_VALUE : IN SECOND_COMPONENT_TYPE ;
FUNCTION FUNC_ARRAY_ATT_TEST RETURN BOOLEAN ;
FUNCTION FUNC_ARRAY_ATT_TEST RETURN BOOLEAN IS
TYPE MATRIX IS ARRAY (FIRST_INDEX, SECOND_INDEX)
OF FIRST_COMPONENT_TYPE ;
TYPE CUBE IS ARRAY (FIRST_INDEX, SECOND_INDEX, THIRD_INDEX)
OF SECOND_COMPONENT_TYPE ;
FIRST_ARRAY : MATRIX := (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
FIRST_DEFAULT_VALUE)) ;
SECOND_ARRAY : CUBE := (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
(THIRD_INDEX'FIRST .. THIRD_INDEX'LAST =>
THIRD_DEFAULT_VALUE))) ;
THIRD_ARRAY : CONSTANT MATRIX
:= (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
SECOND_DEFAULT_VALUE)) ;
FOURTH_ARRAY : CONSTANT CUBE
:= (FIRST_INDEX'FIRST .. FIRST_INDEX'LAST =>
(SECOND_INDEX'FIRST .. SECOND_INDEX'LAST =>
(THIRD_INDEX'FIRST .. THIRD_INDEX'LAST =>
FOURTH_DEFAULT_VALUE))) ;
FA1 : FIRST_INDEX := FIRST_ARRAY'FIRST (1) ;
FA2 : FIRST_INDEX := FIRST_ARRAY'LAST (1) ;
FA3 : SECOND_INDEX := FIRST_ARRAY'FIRST (2) ;
FA4 : SECOND_INDEX := FIRST_ARRAY'LAST (2) ;
SA1 : FIRST_INDEX := SECOND_ARRAY'FIRST (1) ;
SA2 : FIRST_INDEX := SECOND_ARRAY'LAST (1) ;
SA3 : SECOND_INDEX := SECOND_ARRAY'FIRST (2) ;
SA4 : SECOND_INDEX := SECOND_ARRAY'LAST (2) ;
SA5 : THIRD_INDEX := SECOND_ARRAY'FIRST (3) ;
SA6 : THIRD_INDEX := SECOND_ARRAY'LAST (3) ;
FAL1 : NATURAL := FIRST_ARRAY'LENGTH (1) ;
FAL2 : NATURAL := FIRST_ARRAY'LENGTH (2) ;
SAL1 : NATURAL := SECOND_ARRAY'LENGTH (1) ;
SAL2 : NATURAL := SECOND_ARRAY'LENGTH (2) ;
SAL3 : NATURAL := SECOND_ARRAY'LENGTH (3) ;
MATRIX_SIZE : NATURAL := MATRIX'SIZE ;
CUBE_SIZE : NATURAL := CUBE'SIZE ;
FAA : SYSTEM.ADDRESS := FIRST_ARRAY'ADDRESS ;
SAA : SYSTEM.ADDRESS := SECOND_ARRAY'ADDRESS ;
TAA : SYSTEM.ADDRESS := THIRD_ARRAY'ADDRESS ;
FRAA : SYSTEM.ADDRESS := FOURTH_ARRAY'ADDRESS ;
BEGIN -- FUNC_ARRAY_ATT_TEST
IF (FA1 /= FIRST_INDEX'FIRST) OR
(FA3 /= SECOND_INDEX'FIRST) OR
(SA1 /= FIRST_INDEX'FIRST) OR
(SA3 /= SECOND_INDEX'FIRST) OR
(SA5 /= THIRD_INDEX'FIRST) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'FIRST " &
"- FUNCTION") ;
END IF ;
IF (FA2 /= FIRST_INDEX'LAST) OR
(FA4 /= SECOND_INDEX'LAST) OR
(SA2 /= FIRST_INDEX'LAST) OR
(SA4 /= SECOND_INDEX'LAST) OR
(SA6 /= THIRD_INDEX'LAST) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'LAST " &
"- FUNCTION") ;
END IF ;
IF (FAL1 /= FIRST_INDEX_LENGTH) OR
(FAL2 /= SECOND_INDEX_LENGTH) OR
(SAL1 /= FIRST_INDEX_LENGTH) OR
(SAL2 /= SECOND_INDEX_LENGTH) OR
(SAL3 /= THIRD_INDEX_LENGTH) THEN
REPORT.FAILED ("INCORRECT VALUE RETURNED FOR 'LENGTH " &
"- FUNCTION") ;
END IF ;
FOR OUTER_INDEX IN FIRST_ARRAY'RANGE (1) LOOP
FOR INNER_INDEX IN FIRST_ARRAY'RANGE (2) LOOP
FIRST_ARRAY (OUTER_INDEX, INNER_INDEX) :=
SECOND_DEFAULT_VALUE ;
END LOOP ;
END LOOP ;
IF FIRST_ARRAY /= THIRD_ARRAY THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"FOR 2-DIMENSIONAL ARRAY. - FUNCTION") ;
END IF ;
FOR OUTER_INDEX IN SECOND_ARRAY'RANGE (1) LOOP
FOR MIDDLE_INDEX IN SECOND_ARRAY'RANGE (2) LOOP
FOR INNER_INDEX IN SECOND_ARRAY'RANGE (3) LOOP
SECOND_ARRAY (OUTER_INDEX, MIDDLE_INDEX, INNER_INDEX)
:= FOURTH_DEFAULT_VALUE ;
END LOOP ;
END LOOP ;
END LOOP ;
IF SECOND_ARRAY /= FOURTH_ARRAY THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"FOR 3-DIMENSIONAL ARRAY. - FUNCTION") ;
END IF ;
IF (FIRST_TEST_VALUE NOT IN FIRST_ARRAY'RANGE (1)) OR
(FIRST_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (1)) OR
(SECOND_TEST_VALUE NOT IN FIRST_ARRAY'RANGE (2)) OR
(SECOND_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (2)) OR
(THIRD_TEST_VALUE NOT IN SECOND_ARRAY'RANGE (3)) THEN
REPORT.FAILED ("INCORRECT HANDLING OF 'RANGE ATTRIBUTE " &
"- FUNCTION") ;
END IF ;
IF (MATRIX_SIZE = 0) OR (CUBE_SIZE = 0) THEN
REPORT.FAILED ("INCORRECT HANDLING OF THE 'SIZE ATTRIBUTE. " &
"- FUNCTION") ;
END IF ;
IF (FAA = TAA) OR (SAA = FRAA) OR (FAA = SAA) OR (FAA = FRAA)
OR (SAA = TAA) OR (TAA = FRAA) THEN
REPORT.FAILED ("INCORRECT HANDLING OF THE 'ADDRESS ATTRIBUTE. " &
"- FUNCTION") ;
END IF ;
RETURN TRUE ;
END FUNC_ARRAY_ATT_TEST ;
BEGIN -- C36204D
REPORT.TEST ("C36204D", "ARRAY ATTRIBUTES RETURN CORRECT " &
"VALUES WITHIN GENERIC PROGRAM UNITS.") ;
LOCAL_BLOCK:
DECLARE
DUMMY : BOOLEAN := FALSE ;
PACKAGE NEW_ARRAY_ATTRIBUTE_TEST IS NEW ARRAY_ATTRIBUTE_TEST (
FIRST_INDEX => SHORT_RANGE,
FIRST_INDEX_LENGTH => SHORT_LENGTH,
FIRST_TEST_VALUE => -7,
SECOND_INDEX => MONTH_TYPE,
SECOND_INDEX_LENGTH => 12,
SECOND_TEST_VALUE => AUG,
THIRD_INDEX => BOOLEAN,
THIRD_INDEX_LENGTH => 2,
THIRD_TEST_VALUE => FALSE,
FIRST_COMPONENT_TYPE => MONTH_TYPE,
FIRST_DEFAULT_VALUE => JAN,
SECOND_DEFAULT_VALUE => DEC,
SECOND_COMPONENT_TYPE => DATE,
THIRD_DEFAULT_VALUE => TODAY,
FOURTH_DEFAULT_VALUE => FIRST_DATE) ;
PROCEDURE NEW_PROC_ARRAY_ATT_TEST IS NEW PROC_ARRAY_ATT_TEST (
FIRST_INDEX => MONTH_TYPE,
FIRST_INDEX_LENGTH => 12,
FIRST_TEST_VALUE => AUG,
SECOND_INDEX => SHORT_RANGE,
SECOND_INDEX_LENGTH => SHORT_LENGTH,
SECOND_TEST_VALUE => -7,
THIRD_INDEX => BOOLEAN,
THIRD_INDEX_LENGTH => 2,
THIRD_TEST_VALUE => FALSE,
FIRST_COMPONENT_TYPE => DATE,
FIRST_DEFAULT_VALUE => TODAY,
SECOND_DEFAULT_VALUE => FIRST_DATE,
SECOND_COMPONENT_TYPE => MONTH_TYPE,
THIRD_DEFAULT_VALUE => JAN,
FOURTH_DEFAULT_VALUE => DEC) ;
FUNCTION NEW_FUNC_ARRAY_ATT_TEST IS NEW FUNC_ARRAY_ATT_TEST (
FIRST_INDEX => DAY_TYPE,
FIRST_INDEX_LENGTH => 31,
FIRST_TEST_VALUE => 25,
SECOND_INDEX => SHORT_RANGE,
SECOND_INDEX_LENGTH => SHORT_LENGTH,
SECOND_TEST_VALUE => -7,
THIRD_INDEX => MID_YEAR,
THIRD_INDEX_LENGTH => 4,
THIRD_TEST_VALUE => JUL,
FIRST_COMPONENT_TYPE => DATE,
FIRST_DEFAULT_VALUE => TODAY,
SECOND_DEFAULT_VALUE => FIRST_DATE,
SECOND_COMPONENT_TYPE => MONTH_TYPE,
THIRD_DEFAULT_VALUE => JAN,
FOURTH_DEFAULT_VALUE => DEC) ;
BEGIN -- LOCAL_BLOCK
NEW_PROC_ARRAY_ATT_TEST ;
DUMMY := NEW_FUNC_ARRAY_ATT_TEST ;
IF NOT DUMMY THEN
REPORT.FAILED ("WRONG VALUE RETURNED BY FUNCTION.") ;
END IF ;
END LOCAL_BLOCK ;
REPORT.RESULT ;
END C36204D ;
|
------------------------------------------------------------------------------
-- Copyright (c) 2013-2015, Natacha Porté --
-- --
-- Permission to use, copy, modify, and distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.S_Expressions.Printers mainly provides an interface for objects --
-- that are "printer-like", which means the client somehow transmits --
-- sequentially whatever information is needed to output a S-expression. --
-- This contrasts with Descriptor interface, in that the latter provides an --
-- interface for S-expression from the object to its client, while Printer --
-- interface is for S-epression transmitted from the client to its the --
-- object. --
-- --
-- The package also provide concrete type Canonical, which outputs the --
-- S-expression provided through the interface into the given output --
-- stream, using canonical encoding. --
------------------------------------------------------------------------------
with Ada.Streams;
package Natools.S_Expressions.Printers is
pragma Pure (Natools.S_Expressions.Printers);
type Printer is limited interface;
procedure Open_List (Output : in out Printer) is abstract;
procedure Append_Atom (Output : in out Printer; Data : in Atom) is abstract;
procedure Close_List (Output : in out Printer) is abstract;
procedure Append_String (Output : in out Printer'Class; Data : in String);
procedure Transfer
(Source : in out Descriptor'Class;
Target : in out Printer'Class;
Check_Level : in Boolean := False);
type Canonical (Stream : access Ada.Streams.Root_Stream_Type'Class) is
new Printer with null record;
overriding procedure Open_List (Output : in out Canonical);
overriding procedure Append_Atom (Output : in out Canonical;
Data : in Atom);
overriding procedure Close_List (Output : in out Canonical);
end Natools.S_Expressions.Printers;
|
--PRÁCTICA 2: César Borao Moratinos (client_collections)
with Ada.Text_IO;
with Chat_Messages;
with Ada.Exceptions;
with Lower_Layer_UDP;
with Ada.Command_Line;
with Ada.Strings.Unbounded;
with Ada.Unchecked_Deallocation;
package body Client_Collections is
package ATI renames Ada.Text_IO;
package CM renames Chat_Messages;
use ASU;
procedure Add_Client (Collection: in out Collection_Type;
EP: in LLU.End_Point_Type;
Nick: in ASU.Unbounded_String;
Unique: in Boolean) is
Aux: Cell_A;
Included: Boolean;
begin
Included := False;
if Collection.P_First = null then
Collection.P_First := new Cell'(EP, Nick, null);
Collection.Total := Collection.Total + 1;
Aux := Collection.P_First;
Included := True;
else
Aux := Collection.P_First;
while Aux /= null and not Included loop
if ASU.To_String(Aux.Nick) = ASU.To_String(Nick) and Unique then
Included := True;
raise Client_Collection_Error;
end if;
Aux := Aux.Next;
end loop;
Aux := new Cell'(EP, Nick, null);
Aux.Next := Collection.P_First;
Collection.P_First := Aux;
Collection.Total := Collection.Total + 1;
end if;
end Add_Client;
procedure Delete_Client (Collection: in out Collection_Type;
Nick: in ASU.Unbounded_String) is
Aux: Cell_A := Collection.P_First;
Prev: Cell_A := Aux;
Found: Boolean;
procedure Free is new Ada.Unchecked_Deallocation (Cell, Cell_A);
begin
Found := False;
while Aux /= null loop
if ASU.To_String(Prev.Nick) = ASU.To_String(Nick) then
Collection.P_First := Collection.P_First.Next;
Free(Aux);
Collection.Total := Collection.Total - 1;
Found := True;
elsif ASU.To_String(Aux.Nick) = ASU.To_String(Nick) then
Prev.Next := Aux.Next;
Collection.Total := Collection.Total - 1;
Free(Aux);
Found := True;
else
Prev := Aux;
Aux := Aux.Next;
end if;
end loop;
if not Found then
raise Client_Collection_Error;
end if;
end Delete_Client;
function Search_Client (Collection: in Collection_Type;
EP: in LLU.End_Point_Type) return ASU.Unbounded_String is
Finder: Cell_A := Collection.P_First;
Found: Boolean;
Result: ASU.Unbounded_String;
begin
Found := False;
while Finder /= null loop
if LLU."="(Finder.Client_EP, EP) then
Found := True;
Result := Finder.Nick;
end if;
Finder := Finder.Next;
end loop;
if not Found then
raise Client_Collection_Error;
end if;
return Result;
end Search_Client;
procedure Send_To_All (Collection: in Collection_Type;
P_Buffer: access LLU.Buffer_Type) is
Aux: Cell_A := Collection.P_First;
begin
while Aux /= null loop
LLU.Send (Aux.Client_EP, P_Buffer);
Aux := Aux.Next;
end loop;
end Send_To_All;
procedure Divide_EP (EP_Image: in out ASU.Unbounded_String;
Nick: in ASU.Unbounded_String;
Add_EP: out Unbounded_String) is
IP_Image: Unbounded_String;
Port_Image: Unbounded_String;
Position: Integer;
Delimiter: String := " ";
begin
for I in 1..2 loop
Position := ASU.Index(EP_Image, Delimiter);
ASU.Tail(EP_Image, ASU.Length(EP_Image) - Position);
end loop;
Position := ASU.Index(EP_Image, Delimiter);
IP_Image := ASU.Head (EP_Image, Position - 2);
ASU.Tail(EP_Image, ASU.Length(EP_Image) - Position);
Position := ASU.Index(EP_Image, Delimiter);
Port_Image := ASU.Tail(EP_Image, ASU.Length(EP_Image) - Position - 1);
Add_EP := IP_Image & ":" & Port_Image & " " & ASU.To_String(Nick);
end Divide_EP;
function Collection_Image (Collection: in Collection_Type) return String is
Aux: Cell_A := Collection.P_First;
EP_Image: ASU.Unbounded_String;
Add_EP: Unbounded_String;
Result: ASU.Unbounded_String;
begin
Aux := Collection.P_First;
while Aux /= null loop
EP_Image := ASU.To_Unbounded_String(LLU.Image(Aux.Client_EP));
Divide_EP (EP_Image, Aux.Nick, Add_EP);
Result := Result & ASCII.LF & Add_EP;
Aux := Aux.Next;
end loop;
return ASU.To_String(Result);
end Collection_Image;
end Client_Collections;
|
-----------------------------------------------------------------------
-- Util.Streams -- Stream utilities
-- Copyright (C) 2010 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- 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 Ada.Streams;
package Util.Streams is
pragma Preelaborate;
-- -----------------------
-- Output stream
-- -----------------------
-- The <b>Output_Stream</b> is an interface that accepts output bytes
-- and sends them to a sink.
type Output_Stream is limited interface;
type Output_Stream_Access is access all Output_Stream'Class;
-- Write the buffer array to the output stream.
procedure Write (Stream : in out Output_Stream;
Buffer : in Ada.Streams.Stream_Element_Array) is abstract;
-- Flush the buffer (if any) to the sink.
procedure Flush (Stream : in out Output_Stream) is null;
-- Close the sink.
procedure Close (Stream : in out Output_Stream) is null;
-- -----------------------
-- Input stream
-- -----------------------
-- The <b>Input_Stream</b> is the interface that reads input bytes
-- from a source and returns them.
type Input_Stream is limited interface;
type Input_Stream_Access is access all Input_Stream'Class;
-- Read into the buffer as many bytes as possible and return in
-- <b>last</b> the position of the last byte read.
procedure Read (Stream : in out Input_Stream;
Into : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset) is abstract;
-- Copy the input stream to the output stream until the end of the input stream
-- is reached.
procedure Copy (From : in out Input_Stream'Class;
Into : in out Output_Stream'Class);
-- Notes:
-- ------
-- The <b>Ada.Streams.Root_Stream_Type</b> implements the <b>Output_Stream</b>
-- and <b>Input_Stream</b>. It is however not easy to use for composing various
-- stream behaviors.
end Util.Streams;
|
-- part of AdaYaml, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "copying.txt"
with Ada.Unchecked_Deallocation;
package body Yaml.Events is
procedure Free is new Ada.Unchecked_Deallocation
(Event_Array, Event_Array_Access);
procedure Finalize (Object : in out Event_Holder) is
Ptr : Event_Array_Access := Object.Data;
begin
Free (Ptr);
end Finalize;
procedure Copy_Data (Source : Event_Holder;
Target : not null Event_Array_Access) is
begin
Target (Target.all'First .. Target.all'First + Source.Data.all'Length - 1)
:= Source.Data.all;
end Copy_Data;
procedure Grow (Object : in out Event_Holder'Class) is
New_Data : constant not null Event_Array_Access := new Event_Array
(1 .. Object.Data.all'Length * 2);
Old_Data : Event_Array_Access := Object.Data;
begin
Object.Copy_Data (New_Data); -- dispatches
Object.Data := New_Data;
Free (Old_Data);
end Grow;
end Yaml.Events;
|
--with Spark.Float_Arithmetic_Lemmas;
with Mathutil;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Text_IO;
package body perception with SPARK_Mode is
--use Spark.Float_Arithmetic_Lemmas;
function breakingDistance (s : in Speed) return Distance
is
Dist : Distance;
begin
pragma Assert(BreakConstant > 0.0);
Dist := Distance(S) * Distance(2);
return abs (Dist / BreakConstant);
end breakingDistance;
function GetDangerZone(S : in Speed; SteeringAngle : in Steering_Angle; Obj_Type : in C_type) return DangerZone
is
-- These values chage when test for real values
BreakingDist : Distance := BreakingDistance(S);
LidarAngle : Lidar_Angle := 45.0;
BreakingDistScale : constant Distance := 1.0;
begin
if Obj_Type /= UNKNOWN_UNMOVABLE then
if (BreakingDist >= Distance'Last / BreakingDistScale) then
BreakingDist := Distance'Last;
else
pragma Assume(BreakingDist * BreakingDistScale < Distance'Last);
pragma Assume(BreakingDist * BreakingDistScale > 0.0);
BreakingDist := BreakingDist * BreakingDistScale; -- Change this constant later
end if;
LidarAngle := 60.0;
end if;
return (ScopeAngle => LidarAngle, Radius => BreakingDist, SteeringAngleOffset => SteeringAngle);
end GetDangerZone;
function PointInDangerZone(P : in LocalPoint; DZ : in DangerZone) return Boolean
is
Ang : Lidar_Angle := 0.0;
pragma Assume(P.X * P.X + P.Y * P.Y > 0.0);
pragma Assume(P.X * P.X + P.Y * P.Y < 6000.0);
Dist2 : constant Distance := Distance(P.X * P.X + P.Y * P.Y);
pragma Assume(Dist2 > 0.0);
Dist : constant Distance := Mathutil.Sqrt(Dist2);
begin
if Dist > DZ.Radius or P.Y < 0.0 then -- outside radius or behind us
return False;
else
if P.X /= 0.0 and P.Y /= 0.0 then
Ang := Lidar_Angle(Mathutil.ArcTan(P.X, P.Y));
elsif P.Y = 0.0 then
pragma Assume(P.X / P.X = 1.0 or P.X / P.X = -1.0);
Ang := 90.0 * Lidar_Angle(P.X / P.X);
end if;
end if;
return (abs Ang) <= DZ.ScopeAngle;
end PointInDangerZone;
function GetDZEdge(DZ : DangerZone; Left : Boolean) return Line
is
Q : LocalPoint := (Mathutil.Cos(DZ.ScopeAngle) * DZ.Radius, Mathutil.Sin(DZ.ScopeAngle) * DZ.Radius, 0.0);
begin
if (Left) then
Q.X := (-Q.X);
end if;
return (P => (0.0, 0.0, 0.0), Q => Q);
end GetDZEdge;
function GetOrientation(P1 : LocalPoint; P2 : LocalPoint; P3 : LocalPoint) return Orientation
is
Val : constant Cartesian_Coordinate := (P2.Y - P1.Y) * (P3.X - P2.X) -
(P3.Y - P2.Y) * (P2.X - P1.X);
begin
if Val = 0.0 then
return CL;
elsif Val < 0.0 then
return CCW;
else
return CW;
end if;
end GetOrientation;
-- https://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/
function IsIntersecting(L1 : Line; L2 : Line) return Boolean
is
O1 : constant Orientation := GetOrientation(L1.P, L1.Q, L2.P);
O2 : constant Orientation := GetOrientation(L1.P, L1.Q, L2.Q);
O3 : constant Orientation := GetOrientation(L2.P, L2.Q, L1.P);
O4 : constant Orientation := GetOrientation(L2.P, L2.Q, L1.Q);
begin
-- general case
if O1 /= O2 and then O3 /= O4 then
return True;
end if;
-- we ignore the special case with colinear orientations since
-- that case is covered by the point in dz (we have a point on
-- the edge
return False;
end IsIntersecting;
function PerceptionCheck(Obstacle : in Perception_Obstacle_ada; Pose : in Pose_Ada; S : in Speed) return Boolean
is
DZ : constant DangerZone := GetDangerZone(S, 0.0, Obstacle.The_C_Type);
GX : constant FloatingNumber := FloatingNumber(Obstacle.Position.X);
GY : constant FloatingNumber := FloatingNumber(Obstacle.Position.Y);
X : constant FloatingNumber := FloatingNumber(Obstacle.Length) / 2.0;
Y : constant FloatingNumber := FloatingNumber(Obstacle.Width) / 2.0;
Stw : constant FloatingNumber := Mathutil.Sin_r(FloatingNumber(Obstacle.Theta));
Ctw : constant FloatingNumber := Mathutil.Cos_r(FloatingNumber(Obstacle.Theta));
-- these points are in the "world" coordinate system, whatever that means
P1w : constant Point := ( X * Ctw - Y * Stw + GX, X * Stw + Y * Ctw + GY, 0.0); -- top left
P2w : constant Point := ( X * Ctw - (-Y) * Stw + GX, X * Stw + (-Y) * Ctw + GY, 0.0); -- top right
P3w : constant Point := ((-X) * Ctw - (-Y) * Stw + GX, (-X) * Stw + (-Y) * Ctw + GY, 0.0); -- bot right
P4w : constant Point := ((-X) * Ctw - Y * Stw + GX, (-X) * Stw + Y * Ctw + GY, 0.0); -- bot left
XT : constant FloatingNumber := FloatingNumber(Pose.Position.X);
YT : constant FloatingNumber := FloatingNumber(Pose.Position.Y);
-- translated to the cars coordinate system
P1t : constant Point := (P1w.X - XT, P1w.Y - YT, 0.0); -- top left
P2t : constant Point := (P2w.X - XT, P2w.Y - YT, 0.0); -- top right
P3t : constant Point := (P3w.X - XT, P3w.Y - YT, 0.0); -- bot right
P4t : constant Point := (P4w.X - XT, P4w.Y - YT, 0.0); -- bot left
PI : constant FloatingNumber := 3.14159265;
St : constant FloatingNumber := Mathutil.Sin_r(-FloatingNumber(Pose.Heading) + PI/2.0);
Ct : constant FloatingNumber := Mathutil.Cos_r(-FloatingNumber(Pose.Heading) + PI/2.0);
-- these points are in the car's local coordinate system
-- to be checked against the dangerZone
P1 : constant Point := ( P1t.X * Ct - P1t.Y * St, P1t.X * St + P1t.Y * Ct, 0.0); -- top left
P2 : constant Point := ( P2t.X * Ct - P2t.Y * St, P2t.X * St + P2t.Y * Ct, 0.0); -- top right
P3 : constant Point := ( P3t.X * Ct - P3t.Y * St, P3t.X * St + P3t.Y * Ct, 0.0); -- bot right
P4 : constant Point := ( P4t.X * Ct - P4t.Y * St, P4t.X * St + P4t.Y * Ct, 0.0); -- bot left
-- Our lines to check for intersection with the dangerzone
L1 : constant Line := (P1, P2);
L2 : constant Line := (P2, P3);
L3 : constant Line := (P3, P4);
L4 : constant Line := (P4, P1);
-- DEBUG STUFF
-- procedure Print_Point(N : String; P : Point) is
-- begin
-- Ada.Text_IO.Put(N);
-- Put(Float(P.X), Exp => 0);
-- Ada.Text_IO.Put(",");
-- Put(Float(P.Y), Exp => 0);
-- Ada.Text_IO.New_Line(1);
-- end Print_Point;
begin
-- Put(Float(GX)); Ada.Text_IO.New_Line(1);
-- Put(Float(GY)); Ada.Text_IO.New_Line(1);
-- Ada.Text_IO.Put("XT,XY: "); Put(Float(XT)); Ada.Text_IO.Put(","); Put(Float(YT)); Ada.Text_IO.New_Line(1);
-- Ada.Text_IO.Put_Line("Points: ");
-- Print_Point("1: ", P1);
-- Print_Point("2: ", P2);
-- Print_Point("3: ", P3);
-- Print_Point("4: ", P4);
-- Ada.Text_IO.Put("");
if PointInDangerZone(P1, DZ) or
PointInDangerZone(P2, DZ) or
PointInDangerZone(P3, DZ) or
PointInDangerZone(P4, DZ) then
-- Ada.Text_IO.Put_Line("Unsafe, point in DZ");
return False;
end if;
-- one optimization is to find the 2 closest lines, but that might be overkill
if IsIntersecting(L1, GetDZEdge(DZ, False)) or
IsIntersecting(L1, GetDZEdge(DZ, True)) or
IsIntersecting(L2, GetDZEdge(DZ, False)) or
IsIntersecting(L2, GetDZEdge(DZ, True)) or
IsIntersecting(L3, GetDZEdge(DZ, False)) or
IsIntersecting(L3, GetDZEdge(DZ, True)) or
IsIntersecting(L4, GetDZEdge(DZ, False)) or
IsIntersecting(L4, GetDZEdge(DZ, True)) then
-- Ada.Text_IO.Put_Line("Unsafe, line crossing DZ");
return False;
end if;
return True;
end PerceptionCheck;
end;
|
-- { dg-do compile }
-- { dg-options "-flto" { target lto } }
package body Lto17 is
function To_Chunk_List(C : Chunk) return Chunk_List is
begin
return new Chunk_List_Element'(C.Size, C, null);
end;
end Lto17;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2018-2021, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. 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. --
-- 3. 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 --
-- 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. --
-- --
------------------------------------------------------------------------------
with System; use System;
with USB.Utils;
package body USB.Device.HID is
subtype Dispatch is Abstract_HID_Class'Class;
----------------
-- Initialize --
----------------
overriding
function Initialize (This : in out Abstract_HID_Class;
Dev : in out USB_Device_Stack'Class;
Base_Interface_Index : Interface_Id)
return Init_Result
is
begin
if not Dev.Request_Endpoint (Interrupt, This.EP) then
return Not_Enough_EPs;
end if;
This.Report_Buf := Dev.Request_Buffer ((This.EP, EP_Out),
UInt11 (This.Report_Size));
if This.Report_Buf = System.Null_Address then
return Not_Enough_EP_Buffer;
end if;
This.Interface_Index := Base_Interface_Index;
return Ok;
end Initialize;
--------------------
-- Get_Class_Info --
--------------------
overriding
procedure Get_Class_Info
(This : in out Abstract_HID_Class;
Number_Of_Interfaces : out Interface_Id;
Config_Descriptor_Length : out Natural)
is
pragma Unreferenced (This);
begin
Number_Of_Interfaces := 1;
Config_Descriptor_Length := 25;
end Get_Class_Info;
----------------------------
-- Fill_Config_Descriptor --
----------------------------
overriding
procedure Fill_Config_Descriptor (This : in out Abstract_HID_Class;
Data : out UInt8_Array)
is
F : constant Natural := Data'First;
USB_DESC_TYPE_INTERFACE : constant := 4;
USB_DESC_TYPE_ENDPOINT : constant := 5;
begin
Data (F + 0 .. F + 24) :=
(9,
USB_DESC_TYPE_INTERFACE,
0, -- This.Interface_Index,
0, -- Alternate setting
1, -- Number of endpoints
3, -- Class HID
0, -- Subclass
0, -- Interface protocol 0=none, 1=keyboard, 2=mouse
0, -- Str
9,
16#21#,
16#11#, 16#01#, -- Class spec release number
0,
1,
16#22#,
Dispatch (This).Report_Descriptor'Length, 0, -- Descriptor length
7,
USB_DESC_TYPE_ENDPOINT,
16#80# or UInt8 (This.EP), -- In EP
3, -- Interrupt EP
16#40#, 0, -- TODO: Max packet size
1 -- Polling interval
);
end Fill_Config_Descriptor;
---------------
-- Configure --
---------------
overriding
function Configure
(This : in out Abstract_HID_Class;
UDC : in out USB_Device_Controller'Class;
Index : UInt16)
return Setup_Request_Answer
is
begin
if Index = 1 then
UDC.EP_Setup (EP => (This.EP, EP_In),
Typ => Interrupt,
Max_Size => UInt16 (This.Report_Size));
return Handled;
else
return Not_Supported;
end if;
end Configure;
-------------------
-- Setup_Request --
-------------------
overriding
function Setup_Read_Request (This : in out Abstract_HID_Class;
Req : Setup_Data;
Buf : out System.Address;
Len : out Buffer_Len)
return Setup_Request_Answer
is
begin
Buf := System.Null_Address;
Len := 0;
if Req.RType.Typ = Class and then Req.RType.Recipient = Iface then
case Req.Request is
when 1 => -- GET_REPORT
return Not_Supported;
when 2 => -- GET_IDLE
return Not_Supported;
when 3 => -- GET_PROTOCOL
return Not_Supported;
when others =>
raise Program_Error with "Unknown HID request";
end case;
end if;
if Req.RType.Typ = Stand
and then
Req.Request = 6 -- GET_DESCRIPTOR
then
declare
-- Index : constant UInt8 := UInt8 (Req.Value and 16#FF#);
Desc_Type : constant UInt8 := Utils.High (Req.Value);
begin
case Desc_Type is
when 16#22# => -- HID_REPORT_DESC
declare
Report : constant not null Report_Descriptor_Access
:= Dispatch (This).Report_Descriptor;
begin
Buf := Report.all'Address;
Len := Buffer_Len (Report.all'Length);
end;
This.State := Idle;
return Handled;
when others =>
raise Program_Error with "Unknown desc in HID class";
end case;
end;
end if;
return Next_Callback;
end Setup_Read_Request;
-------------------------
-- Setup_Write_Request --
-------------------------
overriding
function Setup_Write_Request (This : in out Abstract_HID_Class;
Req : Setup_Data;
Data : UInt8_Array)
return Setup_Request_Answer
is
begin
if Req.RType.Typ = Class and then Req.RType.Recipient = Iface then
case Req.Request is
when 9 => -- SET_REPORT
declare
Typ : constant UInt8 := Utils.High (Req.Value);
ID : constant UInt8 := Utils.Low (Req.Value);
begin
return Dispatch (This).Set_Report (Typ, ID, Data);
end;
when 10 => -- SET_IDLE
This.Idle_State := Utils.High (Req.Value);
return Handled;
when 11 => -- SET_PROTOCOL
return Not_Supported;
when others =>
raise Program_Error with "Unknown HID request";
end case;
end if;
return Next_Callback;
end Setup_Write_Request;
-----------------------
-- Transfer_Complete --
-----------------------
overriding
procedure Transfer_Complete (This : in out Abstract_HID_Class;
UDC : in out USB_Device_Controller'Class;
EP : EP_Addr;
CNT : UInt11)
is
begin
pragma Assert (EP.Num = This.EP);
if EP = (This.EP, EP_In) then
This.State := Idle;
-- Setup for next TX
UDC.EP_Setup (EP => (This.EP, EP_In),
Typ => Interrupt,
Max_Size => UInt16 (This.Report_Size));
else
raise Program_Error with "Not expecting transfer on EP";
end if;
end Transfer_Complete;
-----------------
-- Send_Report --
-----------------
procedure Send_Report (This : in out Abstract_HID_Class;
UDC : in out USB_Device_Controller'Class)
is
Report : UInt8_Array (This.Report'Range)
with Address => This.Report_Buf;
begin
if This.Ready then
-- Copy the report to the transfer buffer
Report := This.Report;
-- Clear report
This.Report := (others => 0);
-- Send transfer buffer
UDC.EP_Write_Packet (This.EP,
This.Report_Buf,
UInt32 (This.Report_Size));
This.State := Busy;
end if;
end Send_Report;
-----------
-- Ready --
-----------
function Ready (This : in out Abstract_HID_Class) return Boolean
is (This.State = Idle);
end USB.Device.HID;
|
-- Copyright (c) 2013, Nordic Semiconductor ASA
-- 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 Nordic Semiconductor ASA 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.
--
-- This spec has been automatically generated from nrf51.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package NRF_SVD.QDEC is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Shortcut between REPORTRDY event and READCLRACC task.
type SHORTS_REPORTRDY_READCLRACC_Field is
(-- Shortcut disabled.
Disabled,
-- Shortcut enabled.
Enabled)
with Size => 1;
for SHORTS_REPORTRDY_READCLRACC_Field use
(Disabled => 0,
Enabled => 1);
-- Shortcut between SAMPLERDY event and STOP task.
type SHORTS_SAMPLERDY_STOP_Field is
(-- Shortcut disabled.
Disabled,
-- Shortcut enabled.
Enabled)
with Size => 1;
for SHORTS_SAMPLERDY_STOP_Field use
(Disabled => 0,
Enabled => 1);
-- Shortcuts for the QDEC.
type SHORTS_Register is record
-- Shortcut between REPORTRDY event and READCLRACC task.
REPORTRDY_READCLRACC : SHORTS_REPORTRDY_READCLRACC_Field :=
NRF_SVD.QDEC.Disabled;
-- Shortcut between SAMPLERDY event and STOP task.
SAMPLERDY_STOP : SHORTS_SAMPLERDY_STOP_Field :=
NRF_SVD.QDEC.Disabled;
-- unspecified
Reserved_2_31 : HAL.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SHORTS_Register use record
REPORTRDY_READCLRACC at 0 range 0 .. 0;
SAMPLERDY_STOP at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- Enable interrupt on SAMPLERDY event.
type INTENSET_SAMPLERDY_Field is
(-- Interrupt disabled.
Disabled,
-- Interrupt enabled.
Enabled)
with Size => 1;
for INTENSET_SAMPLERDY_Field use
(Disabled => 0,
Enabled => 1);
-- Enable interrupt on SAMPLERDY event.
type INTENSET_SAMPLERDY_Field_1 is
(-- Reset value for the field
Intenset_Samplerdy_Field_Reset,
-- Enable interrupt on write.
Set)
with Size => 1;
for INTENSET_SAMPLERDY_Field_1 use
(Intenset_Samplerdy_Field_Reset => 0,
Set => 1);
-- Enable interrupt on REPORTRDY event.
type INTENSET_REPORTRDY_Field is
(-- Interrupt disabled.
Disabled,
-- Interrupt enabled.
Enabled)
with Size => 1;
for INTENSET_REPORTRDY_Field use
(Disabled => 0,
Enabled => 1);
-- Enable interrupt on REPORTRDY event.
type INTENSET_REPORTRDY_Field_1 is
(-- Reset value for the field
Intenset_Reportrdy_Field_Reset,
-- Enable interrupt on write.
Set)
with Size => 1;
for INTENSET_REPORTRDY_Field_1 use
(Intenset_Reportrdy_Field_Reset => 0,
Set => 1);
-- Enable interrupt on ACCOF event.
type INTENSET_ACCOF_Field is
(-- Interrupt disabled.
Disabled,
-- Interrupt enabled.
Enabled)
with Size => 1;
for INTENSET_ACCOF_Field use
(Disabled => 0,
Enabled => 1);
-- Enable interrupt on ACCOF event.
type INTENSET_ACCOF_Field_1 is
(-- Reset value for the field
Intenset_Accof_Field_Reset,
-- Enable interrupt on write.
Set)
with Size => 1;
for INTENSET_ACCOF_Field_1 use
(Intenset_Accof_Field_Reset => 0,
Set => 1);
-- Interrupt enable set register.
type INTENSET_Register is record
-- Enable interrupt on SAMPLERDY event.
SAMPLERDY : INTENSET_SAMPLERDY_Field_1 :=
Intenset_Samplerdy_Field_Reset;
-- Enable interrupt on REPORTRDY event.
REPORTRDY : INTENSET_REPORTRDY_Field_1 :=
Intenset_Reportrdy_Field_Reset;
-- Enable interrupt on ACCOF event.
ACCOF : INTENSET_ACCOF_Field_1 := Intenset_Accof_Field_Reset;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for INTENSET_Register use record
SAMPLERDY at 0 range 0 .. 0;
REPORTRDY at 0 range 1 .. 1;
ACCOF at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
-- Disable interrupt on SAMPLERDY event.
type INTENCLR_SAMPLERDY_Field is
(-- Interrupt disabled.
Disabled,
-- Interrupt enabled.
Enabled)
with Size => 1;
for INTENCLR_SAMPLERDY_Field use
(Disabled => 0,
Enabled => 1);
-- Disable interrupt on SAMPLERDY event.
type INTENCLR_SAMPLERDY_Field_1 is
(-- Reset value for the field
Intenclr_Samplerdy_Field_Reset,
-- Disable interrupt on write.
Clear)
with Size => 1;
for INTENCLR_SAMPLERDY_Field_1 use
(Intenclr_Samplerdy_Field_Reset => 0,
Clear => 1);
-- Disable interrupt on REPORTRDY event.
type INTENCLR_REPORTRDY_Field is
(-- Interrupt disabled.
Disabled,
-- Interrupt enabled.
Enabled)
with Size => 1;
for INTENCLR_REPORTRDY_Field use
(Disabled => 0,
Enabled => 1);
-- Disable interrupt on REPORTRDY event.
type INTENCLR_REPORTRDY_Field_1 is
(-- Reset value for the field
Intenclr_Reportrdy_Field_Reset,
-- Disable interrupt on write.
Clear)
with Size => 1;
for INTENCLR_REPORTRDY_Field_1 use
(Intenclr_Reportrdy_Field_Reset => 0,
Clear => 1);
-- Disable interrupt on ACCOF event.
type INTENCLR_ACCOF_Field is
(-- Interrupt disabled.
Disabled,
-- Interrupt enabled.
Enabled)
with Size => 1;
for INTENCLR_ACCOF_Field use
(Disabled => 0,
Enabled => 1);
-- Disable interrupt on ACCOF event.
type INTENCLR_ACCOF_Field_1 is
(-- Reset value for the field
Intenclr_Accof_Field_Reset,
-- Disable interrupt on write.
Clear)
with Size => 1;
for INTENCLR_ACCOF_Field_1 use
(Intenclr_Accof_Field_Reset => 0,
Clear => 1);
-- Interrupt enable clear register.
type INTENCLR_Register is record
-- Disable interrupt on SAMPLERDY event.
SAMPLERDY : INTENCLR_SAMPLERDY_Field_1 :=
Intenclr_Samplerdy_Field_Reset;
-- Disable interrupt on REPORTRDY event.
REPORTRDY : INTENCLR_REPORTRDY_Field_1 :=
Intenclr_Reportrdy_Field_Reset;
-- Disable interrupt on ACCOF event.
ACCOF : INTENCLR_ACCOF_Field_1 := Intenclr_Accof_Field_Reset;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for INTENCLR_Register use record
SAMPLERDY at 0 range 0 .. 0;
REPORTRDY at 0 range 1 .. 1;
ACCOF at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
-- Enable or disable QDEC.
type ENABLE_ENABLE_Field is
(-- Disabled QDEC.
Disabled,
-- Enable QDEC.
Enabled)
with Size => 1;
for ENABLE_ENABLE_Field use
(Disabled => 0,
Enabled => 1);
-- Enable the QDEC.
type ENABLE_Register is record
-- Enable or disable QDEC.
ENABLE : ENABLE_ENABLE_Field := NRF_SVD.QDEC.Disabled;
-- unspecified
Reserved_1_31 : HAL.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ENABLE_Register use record
ENABLE at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
-- LED output pin polarity.
type LEDPOL_LEDPOL_Field is
(-- LED output is active low.
Activelow,
-- LED output is active high.
Activehigh)
with Size => 1;
for LEDPOL_LEDPOL_Field use
(Activelow => 0,
Activehigh => 1);
-- LED output pin polarity.
type LEDPOL_Register is record
-- LED output pin polarity.
LEDPOL : LEDPOL_LEDPOL_Field := NRF_SVD.QDEC.Activelow;
-- unspecified
Reserved_1_31 : HAL.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for LEDPOL_Register use record
LEDPOL at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
-- Sample period.
type SAMPLEPER_SAMPLEPER_Field is
(-- 128us sample period.
Val_128US,
-- 256us sample period.
Val_256US,
-- 512us sample period.
Val_512US,
-- 1024us sample period.
Val_1024US,
-- 2048us sample period.
Val_2048US,
-- 4096us sample period.
Val_4096US,
-- 8192us sample period.
Val_8192US,
-- 16384us sample period.
Val_16384US)
with Size => 3;
for SAMPLEPER_SAMPLEPER_Field use
(Val_128US => 0,
Val_256US => 1,
Val_512US => 2,
Val_1024US => 3,
Val_2048US => 4,
Val_4096US => 5,
Val_8192US => 6,
Val_16384US => 7);
-- Sample period.
type SAMPLEPER_Register is record
-- Sample period.
SAMPLEPER : SAMPLEPER_SAMPLEPER_Field := NRF_SVD.QDEC.Val_128US;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for SAMPLEPER_Register use record
SAMPLEPER at 0 range 0 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
-- Number of samples to generate an EVENT_REPORTRDY.
type REPORTPER_REPORTPER_Field is
(-- 10 samples per report.
Val_10Smpl,
-- 40 samples per report.
Val_40Smpl,
-- 80 samples per report.
Val_80Smpl,
-- 120 samples per report.
Val_120Smpl,
-- 160 samples per report.
Val_160Smpl,
-- 200 samples per report.
Val_200Smpl,
-- 240 samples per report.
Val_240Smpl,
-- 280 samples per report.
Val_280Smpl)
with Size => 3;
for REPORTPER_REPORTPER_Field use
(Val_10Smpl => 0,
Val_40Smpl => 1,
Val_80Smpl => 2,
Val_120Smpl => 3,
Val_160Smpl => 4,
Val_200Smpl => 5,
Val_240Smpl => 6,
Val_280Smpl => 7);
-- Number of samples to generate an EVENT_REPORTRDY.
type REPORTPER_Register is record
-- Number of samples to generate an EVENT_REPORTRDY.
REPORTPER : REPORTPER_REPORTPER_Field := NRF_SVD.QDEC.Val_10Smpl;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for REPORTPER_Register use record
REPORTPER at 0 range 0 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
-- Enable debounce input filters.
type DBFEN_DBFEN_Field is
(-- Debounce input filters disabled.
Disabled,
-- Debounce input filters enabled.
Enabled)
with Size => 1;
for DBFEN_DBFEN_Field use
(Disabled => 0,
Enabled => 1);
-- Enable debouncer input filters.
type DBFEN_Register is record
-- Enable debounce input filters.
DBFEN : DBFEN_DBFEN_Field := NRF_SVD.QDEC.Disabled;
-- unspecified
Reserved_1_31 : HAL.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for DBFEN_Register use record
DBFEN at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
subtype LEDPRE_LEDPRE_Field is HAL.UInt9;
-- Time LED is switched ON before the sample.
type LEDPRE_Register is record
-- Period in us the LED in switched on prior to sampling.
LEDPRE : LEDPRE_LEDPRE_Field := 16#10#;
-- unspecified
Reserved_9_31 : HAL.UInt23 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for LEDPRE_Register use record
LEDPRE at 0 range 0 .. 8;
Reserved_9_31 at 0 range 9 .. 31;
end record;
subtype ACCDBL_ACCDBL_Field is HAL.UInt4;
-- Accumulated double (error) transitions register.
type ACCDBL_Register is record
-- Read-only. Accumulated double (error) transitions.
ACCDBL : ACCDBL_ACCDBL_Field;
-- unspecified
Reserved_4_31 : HAL.UInt28;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ACCDBL_Register use record
ACCDBL at 0 range 0 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
subtype ACCDBLREAD_ACCDBLREAD_Field is HAL.UInt4;
-- Snapshot of ACCDBL register. Value generated by the TASKS_READCLEACC
-- task.
type ACCDBLREAD_Register is record
-- Read-only. Snapshot of accumulated double (error) transitions.
ACCDBLREAD : ACCDBLREAD_ACCDBLREAD_Field;
-- unspecified
Reserved_4_31 : HAL.UInt28;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ACCDBLREAD_Register use record
ACCDBLREAD at 0 range 0 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- Peripheral power control.
type POWER_POWER_Field is
(-- Module power disabled.
Disabled,
-- Module power enabled.
Enabled)
with Size => 1;
for POWER_POWER_Field use
(Disabled => 0,
Enabled => 1);
-- Peripheral power control.
type POWER_Register is record
-- Peripheral power control.
POWER : POWER_POWER_Field := NRF_SVD.QDEC.Disabled;
-- unspecified
Reserved_1_31 : HAL.UInt31 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for POWER_Register use record
POWER at 0 range 0 .. 0;
Reserved_1_31 at 0 range 1 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Rotary decoder.
type QDEC_Peripheral is record
-- Start the quadrature decoder.
TASKS_START : aliased HAL.UInt32;
-- Stop the quadrature decoder.
TASKS_STOP : aliased HAL.UInt32;
-- Transfers the content from ACC registers to ACCREAD registers, and
-- clears the ACC registers.
TASKS_READCLRACC : aliased HAL.UInt32;
-- A new sample is written to the sample register.
EVENTS_SAMPLERDY : aliased HAL.UInt32;
-- REPORTPER number of samples accumulated in ACC register, and ACC
-- register different than zero.
EVENTS_REPORTRDY : aliased HAL.UInt32;
-- ACC or ACCDBL register overflow.
EVENTS_ACCOF : aliased HAL.UInt32;
-- Shortcuts for the QDEC.
SHORTS : aliased SHORTS_Register;
-- Interrupt enable set register.
INTENSET : aliased INTENSET_Register;
-- Interrupt enable clear register.
INTENCLR : aliased INTENCLR_Register;
-- Enable the QDEC.
ENABLE : aliased ENABLE_Register;
-- LED output pin polarity.
LEDPOL : aliased LEDPOL_Register;
-- Sample period.
SAMPLEPER : aliased SAMPLEPER_Register;
-- Motion sample value.
SAMPLE : aliased HAL.UInt32;
-- Number of samples to generate an EVENT_REPORTRDY.
REPORTPER : aliased REPORTPER_Register;
-- Accumulated valid transitions register.
ACC : aliased HAL.UInt32;
-- Snapshot of ACC register. Value generated by the TASKS_READCLEACC
-- task.
ACCREAD : aliased HAL.UInt32;
-- Pin select for LED output.
PSELLED : aliased HAL.UInt32;
-- Pin select for phase A input.
PSELA : aliased HAL.UInt32;
-- Pin select for phase B input.
PSELB : aliased HAL.UInt32;
-- Enable debouncer input filters.
DBFEN : aliased DBFEN_Register;
-- Time LED is switched ON before the sample.
LEDPRE : aliased LEDPRE_Register;
-- Accumulated double (error) transitions register.
ACCDBL : aliased ACCDBL_Register;
-- Snapshot of ACCDBL register. Value generated by the TASKS_READCLEACC
-- task.
ACCDBLREAD : aliased ACCDBLREAD_Register;
-- Peripheral power control.
POWER : aliased POWER_Register;
end record
with Volatile;
for QDEC_Peripheral use record
TASKS_START at 16#0# range 0 .. 31;
TASKS_STOP at 16#4# range 0 .. 31;
TASKS_READCLRACC at 16#8# range 0 .. 31;
EVENTS_SAMPLERDY at 16#100# range 0 .. 31;
EVENTS_REPORTRDY at 16#104# range 0 .. 31;
EVENTS_ACCOF at 16#108# range 0 .. 31;
SHORTS at 16#200# range 0 .. 31;
INTENSET at 16#304# range 0 .. 31;
INTENCLR at 16#308# range 0 .. 31;
ENABLE at 16#500# range 0 .. 31;
LEDPOL at 16#504# range 0 .. 31;
SAMPLEPER at 16#508# range 0 .. 31;
SAMPLE at 16#50C# range 0 .. 31;
REPORTPER at 16#510# range 0 .. 31;
ACC at 16#514# range 0 .. 31;
ACCREAD at 16#518# range 0 .. 31;
PSELLED at 16#51C# range 0 .. 31;
PSELA at 16#520# range 0 .. 31;
PSELB at 16#524# range 0 .. 31;
DBFEN at 16#528# range 0 .. 31;
LEDPRE at 16#540# range 0 .. 31;
ACCDBL at 16#544# range 0 .. 31;
ACCDBLREAD at 16#548# range 0 .. 31;
POWER at 16#FFC# range 0 .. 31;
end record;
-- Rotary decoder.
QDEC_Periph : aliased QDEC_Peripheral
with Import, Address => QDEC_Base;
end NRF_SVD.QDEC;
|
-- { dg-do compile }
-- { dg-options "-fdump-tree-gimple" }
with Atomic6_Pkg; use Atomic6_Pkg;
procedure Atomic6_5 is
type Arr is array (Integer range 1 .. 4) of Boolean;
A : Arr;
B : Boolean;
begin
A (Integer(Counter1)) := True;
B := A (Timer1);
declare
pragma Suppress (Index_Check);
begin
A (Integer(Counter1)) := True;
B := A (Timer1);
end;
end;
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*&atomic6_pkg__counter1" 2 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*&atomic6_pkg__counter2" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*&atomic6_pkg__timer1" 2 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*&atomic6_pkg__timer2" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*&temp" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_load\[^\n\r\]*ptr" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*&atomic6_pkg__counter1" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*&atomic6_pkg__counter2" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*&atomic6_pkg__timer1" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*&atomic6_pkg__timer2" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*&temp" 0 "gimple"} }
-- { dg-final { scan-tree-dump-times "atomic_store\[^\n\r\]*ptr" 0 "gimple"} }
|
-- The MIT License (MIT)
-- Copyright (c) 2015 Pavel Zhukov <landgraf@fedoraproject.org>
-- 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_Conversion;
with Ada.Unchecked_Deallocation;
with Ada.Streams;
with Interfaces.C.Strings;
with Interfaces.C.Pointers;
with Nanomsg.Errors;
with Nanomsg.Sockopt;
with System;
with Syserrors;
use type Syserrors.Errno;
with Nanomsg.Socket_Pools;
package body Nanomsg.Socket is
package C renames Interfaces.C;
use type C.Int;
function Is_Null (Obj : in Socket_T) return Boolean is (Obj.Fd = -1);
procedure Init (Obj : out Socket_T;
Domain : in Nanomsg.Domains.Domain_T;
Protocol : in Protocol_T
) is
function C_Nn_Socket (Domain : in C.Int; Protocol : in C.Int) return C.Int
with Import, Convention => C, External_Name => "nn_socket";
begin
Obj.Fd := Integer (C_Nn_Socket (Nanomsg.Domains.To_C (Domain),
C.Int (Protocol)));
if Obj.Fd < 0 then
raise Socket_Exception with "Init: " & Nanomsg.Errors.Errno_Text;
end if;
end Init;
procedure Close (Obj : in out Socket_T) is
function C_Nn_Close (Socket : in C.Int) return C.Int
with Import, Convention => C, External_Name => "nn_close";
begin
Obj.Delete_Endpoint;
if C_Nn_Close (C.Int (Obj.Fd)) /= 0 then
raise Socket_Exception with "Close: " & Nanomsg.Errors.Errno_Text;
end if;
Obj.Fd := -1;
end Close;
procedure Bind (Obj : in out Socket_T;
Address : in String) is
function C_Bind (Socket : in C.Int; Address : in C.Strings.Chars_Ptr) return C.Int
with Import, Convention => C, External_Name => "nn_bind";
C_Address : C.Strings.Chars_Ptr := C.Strings.New_String (Address);
begin
Obj.Endpoint := Integer (C_Bind(C.Int (Obj.Fd), C_Address));
C.Strings.Free (C_Address);
if Obj.Endpoint < 0 then
raise Socket_Exception with "Bind: " & Nanomsg.Errors.Errno_Text;
end if;
-- FIXME
-- Add endpoints container
end Bind;
procedure Connect (Obj : in out Socket_T;
Address : in String) is
function C_Connect (Socket : in C.Int; Address : in C.Strings.Chars_Ptr) return C.Int
with Import, Convention => C, External_Name => "nn_connect";
C_Address : C.Strings.Chars_Ptr := C.Strings.New_String (Address);
begin
Obj.Endpoint := Integer (C_Connect(C.Int (Obj.Fd), C_Address));
C.Strings.Free (C_Address);
if Obj.Endpoint < 0 then
raise Socket_Exception with "Connect: " & Nanomsg.Errors.Errno_Text;
end if;
end Connect;
function Get_Fd (Obj : in Socket_T) return Integer is (Obj.Fd);
procedure Receive (Obj : in out Socket_T;
Message : out Nanomsg.Messages.Message_T;
Non_Blocking : in Boolean := False ) is
Payload : System.Address;
use type System.Address;
Received : Integer;
use type C.Size_T;
Flags : C.Int := (if Non_Blocking then 2 else 0);
Nn_Msg : constant C.Size_T := C.Size_T'Last;
function Nn_Recv (Socket : C.Int;
Buf_Access : out System.Address;
Size : C.Size_T;
Flags : C.Int
) return C.Int with Import, Convention => C, External_Name => "nn_recv";
function Free_Msg (Buf_Access :System.Address) return C.Int
with Import, Convention => C, External_Name => "nn_freemsg";
begin
Received := Integer (Nn_Recv (C.Int (Obj.Fd), Payload, Nn_Msg, Flags));
if Received < 0 then
if Non_Blocking and then Nanomsg.Errors.Errno = Syserrors.Value (Syserrors.Eagain) then
return;
end if;
raise Socket_Exception with "Receive: " & Nanomsg.Errors.Errno_Text;
end if;
Message.Set_Length (Received);
declare
Data : Ada.Streams.Stream_Element_Array (1 .. Ada.Streams.Stream_Element_Offset (Received));
for Data'Address use Payload;
begin
Message.Set_Payload (Data);
end;
if Free_Msg (Payload) < 0 then
raise Socket_Exception with "Deallocation failed";
end if;
end Receive;
procedure Send (Obj : in Socket_T; Message : Nanomsg.Messages.Message_T) is
Flags : C.Int := 0;
function Nn_Send (Socket : C.Int;
Buf_Access : Ada.Streams.Stream_Element_Array;
Size : C.Size_T;
Flags : C.Int
) return C.Int with Import, Convention => C, External_Name => "nn_send";
Sent : Integer;
begin
Sent := Integer (Nn_Send (C.Int (Obj.Fd),
Message.Get_Payload.all,
C.Size_T (Message.Get_Length),
Flags));
if Sent < 0 then
raise Socket_Exception with "Send: " & Nanomsg.Errors.Errno_Text;
end if;
if Sent /= Message.Get_Length then
raise Socket_Exception with "Send/Receive count doesn't match";
end if;
end Send;
procedure Delete_Endpoint (Obj : in out Socket_T) is
function Nn_Shutdown (Socket : C.Int;
Endpoint : C.Int) return C.Int
with Import, Convention => C, External_Name => "nn_shutdown";
begin
if Obj.Endpoint > 0 then
if Nn_Shutdown (C.Int (Obj.Fd), C.Int (Obj.Endpoint)) < 0 then
raise Socket_Exception with "Shutdown Error" & Nanomsg.Errors.Errno_Text;
end if;
Obj.Endpoint := -1;
end if;
end Delete_Endpoint;
function C_Setsockopt (Socket : C.Int;
Level : C.Int;
Option : C.Int;
Value : System.Address;
Size : C.Size_T) return C.Int with Import, Convention => C, External_Name => "nn_setsockopt";
procedure Set_Option (Obj : in out Socket_T;
Level : in Nanomsg.Sockopt.Option_Level_T;
Name : in Nanomsg.Sockopt.Option_Type_T;
Value : in Natural)
is
use Nanomsg.Sockopt;
Size : C.Size_T := C.Size_T (C.Int'Size);
begin
begin
if C_Setsockopt (C.Int (Obj.Fd),
C.Int (Level),
C.Int (Name),
Value'Address,
Size) < 0 then
raise Socket_Exception with "Setopt error";
end if;
end;
end Set_Option;
procedure Set_Option (Obj : in out Socket_T;
Level : in Nanomsg.Sockopt.Option_Level_T;
Name : in Nanomsg.Sockopt.Option_Type_T;
Value : in String) is
C_Value : C.Strings.Char_Array_Access := new C.Char_Array'(C.To_C (Value)) with Convention => C;
procedure Free is new Ada.Unchecked_Deallocation (Name => C.Strings.Char_Array_Access,
Object => C.Char_Array);
use type C.Size_T;
Size : C.Size_T := C_Value'Length - 1;
begin
if C_Setsockopt (C.Int (Obj.Fd),
C.Int (Level),
C.Int (Name),
C_Value.all'Address,
Size) < 0 then
raise Socket_Exception with "Setopt error" & Nanomsg.Errors.Errno_Text;
end if;
Free (C_Value);
end Set_Option;
function Get_Option (Obj : in Socket_T;
Level : in Nanomsg.Sockopt.Option_Level_T;
Name : in Nanomsg.Sockopt.Option_Type_T) return String is
type String_Access_T is access all String;
procedure Free is new Ada.Unchecked_Deallocation (Name => String_Access_T,
Object => String);
function Nn_Getsockopt (Socket : in C.Int;
Level : in C.Int;
Option_Name : in C.Int;
Value : in out String_Access_T;
Size : in System.Address) return C.Int
with Import, Convention => C, External_Name => "nn_getsockopt";
use Nanomsg.Sockopt;
Max_Size : constant := 63;
Ptr : String_Access_T := new String(1..Max_Size);
Size : C.Size_T := Max_Size;
use type C.Size_T;
begin
if Nn_Getsockopt (Socket => C.Int (Obj.Fd),
Level => C.Int (Level),
Option_Name => C.Int (Name),
Value => Ptr,
Size => Size'Address) < 0 then
raise Socket_Exception with "Getopt error" & Nanomsg.Errors.Errno_Text;
end if;
declare
Retval : constant String := Ptr.all(1.. Integer (Size));
begin
Free (Ptr);
return Retval;
end;
end Get_Option;
function Get_Option (Obj : in Socket_T;
Level : in Nanomsg.Sockopt.Option_Level_T;
Name : in Nanomsg.Sockopt.Option_Type_T) return Natural is
Retval : Natural := 0;
Size : C.Size_T := C.Int'Size;
function Nn_Getsockopt (Socket : in C.Int;
Level : in C.Int;
Option_Name : in C.Int;
Value : in out C.Int;
Size : in System.Address) return C.Int
with Import, Convention => C, External_Name => "nn_getsockopt";
begin
if Nn_Getsockopt (Socket => C.Int (Obj.Fd),
Level => C.Int (Level),
Option_Name => C.Int (Name),
Value => C.Int (Retval),
Size => Size'Address) < 0 then
raise Socket_Exception with "Getopt error" & Nanomsg.Errors.Errno_Text;
end if;
return Retval;
end Get_Option;
function Is_Ready (Obj : in Socket_T;
To_Send : in Boolean := False;
To_Receive : in Boolean := True) return Boolean
is
Pool : Nanomsg.Socket_Pools.Pool_T;
begin
Pool.Add_Socket (Obj);
if To_Send and then To_Receive then
return Pool.Ready_To_Send_Receive.Has_Socket (Obj);
elsif To_Send then
return Pool.Ready_To_Send.Has_Socket (Obj);
elsif To_Receive then
return Pool.Ready_To_Receive.Has_Socket (Obj);
else
raise Socket_Exception;
end if;
end Is_Ready;
function "=" (Left, Right : in Socket_T) return Boolean is (Left.Fd = Right.Fd);
function Receive (Obj : in out Socket_T;
Message : out Nanomsg.Messages.Message_T;
Non_Blocking : in Boolean := False) return Natural is
begin
Receive (Obj, Message, Non_Blocking);
return Message.Get_Length;
end Receive;
end Nanomsg.Socket;
|
--//////////////////////////////////////////////////////////
-- SFML - Simple and Fast Multimedia Library
-- Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
-- This software is provided 'as-is', without any express or implied warranty.
-- In no event will the authors be held liable for any damages arising from the use of this software.
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it freely,
-- subject to the following restrictions:
-- 1. The origin of this software must not be misrepresented;
-- you must not claim that you wrote the original software.
-- If you use this software in a product, an acknowledgment
-- in the product documentation would be appreciated but is not required.
-- 2. Altered source versions must be plainly marked as such,
-- and must not be misrepresented as being the original software.
-- 3. This notice may not be removed or altered from any source distribution.
--//////////////////////////////////////////////////////////
--//////////////////////////////////////////////////////////
with Sf.Graphics.Rect;
with Sf.System.Vector2;
package Sf.Graphics.View is
--//////////////////////////////////////////////////////////
--/ @brief Create a default view
--/
--/ This function creates a default view of (0, 0, 1000, 1000)
--/
--/ @return A new sfView object
--/
--//////////////////////////////////////////////////////////
function create return sfView_Ptr;
--//////////////////////////////////////////////////////////
--/ @brief Construct a view from a rectangle
--/
--/ @param rectangle Rectangle defining the zone to display
--/
--/ @return A new sfView object
--/
--//////////////////////////////////////////////////////////
function createFromRect (rectangle : Sf.Graphics.Rect.sfFloatRect) return sfView_Ptr;
--//////////////////////////////////////////////////////////
--/ @brief Copy an existing view
--/
--/ @param view View to copy
--/
--/ @return Copied object
--/
--//////////////////////////////////////////////////////////
function copy (view : sfView_Ptr) return sfView_Ptr;
--//////////////////////////////////////////////////////////
--/ @brief Destroy an existing view
--/
--/ @param view View to destroy
--/
--//////////////////////////////////////////////////////////
procedure destroy (view : sfView_Ptr);
--//////////////////////////////////////////////////////////
--/ @brief Set the center of a view
--/
--/ @param view View object
--/ @param center New center
--/
--//////////////////////////////////////////////////////////
procedure setCenter (view : sfView_Ptr; center : Sf.System.Vector2.sfVector2f);
--//////////////////////////////////////////////////////////
--/ @brief Set the size of a view
--/
--/ @param view View object
--/ @param size New size of the view
--/
--//////////////////////////////////////////////////////////
procedure setSize (view : sfView_Ptr; size : Sf.System.Vector2.sfVector2f);
--//////////////////////////////////////////////////////////
--/ @brief Set the orientation of a view
--/
--/ The default rotation of a view is 0 degree.
--/
--/ @param view View object
--/ @param angle New angle, in degrees
--/
--//////////////////////////////////////////////////////////
procedure setRotation (view : sfView_Ptr; angle : float);
--//////////////////////////////////////////////////////////
--/ @brief Set the target viewport of a view
--/
--/ The viewport is the rectangle into which the contents of the
--/ view are displayed, expressed as a factor (between 0 and 1)
--/ of the size of the render target to which the view is applied.
--/ For example, a view which takes the left side of the target would
--/ be defined by a rect of (0, 0, 0.5, 1).
--/ By default, a view has a viewport which covers the entire target.
--/
--/ @param view View object
--/ @param viewport New viewport rectangle
--/
--//////////////////////////////////////////////////////////
procedure setViewport (view : sfView_Ptr; viewport : Sf.Graphics.Rect.sfFloatRect);
--//////////////////////////////////////////////////////////
--/ @brief Reset a view to the given rectangle
--/
--/ Note that this function resets the rotation angle to 0.
--/
--/ @param view View object
--/ @param rectangle Rectangle defining the zone to display
--/
--//////////////////////////////////////////////////////////
procedure reset (view : sfView_Ptr; rectangle : Sf.Graphics.Rect.sfFloatRect);
--//////////////////////////////////////////////////////////
--/ @brief Get the center of a view
--/
--/ @param view View object
--/
--/ @return Center of the view
--/
--//////////////////////////////////////////////////////////
function getCenter (view : sfView_Ptr) return Sf.System.Vector2.sfVector2f;
--//////////////////////////////////////////////////////////
--/ @brief Get the size of a view
--/
--/ @param view View object
--/
--/ @return Size of the view
--/
--//////////////////////////////////////////////////////////
function getSize (view : sfView_Ptr) return Sf.System.Vector2.sfVector2f;
--//////////////////////////////////////////////////////////
--/ @brief Get the current orientation of a view
--/
--/ @param view View object
--/
--/ @return Rotation angle of the view, in degrees
--/
--//////////////////////////////////////////////////////////
function getRotation (view : sfView_Ptr) return float;
--//////////////////////////////////////////////////////////
--/ @brief Get the target viewport rectangle of a view
--/
--/ @param view View object
--/
--/ @return Viewport rectangle, expressed as a factor of the target size
--/
--//////////////////////////////////////////////////////////
function getViewport (view : sfView_Ptr) return Sf.Graphics.Rect.sfFloatRect;
--//////////////////////////////////////////////////////////
--/ @brief Move a view relatively to its current position
--/
--/ @param view View object
--/ @param offset Offset
--/
--//////////////////////////////////////////////////////////
procedure move (view : sfView_Ptr; offset : Sf.System.Vector2.sfVector2f);
--//////////////////////////////////////////////////////////
--/ @brief Rotate a view relatively to its current orientation
--/
--/ @param view View object
--/ @param angle Angle to rotate, in degrees
--/
--//////////////////////////////////////////////////////////
procedure rotate (view : sfView_Ptr; angle : float);
--//////////////////////////////////////////////////////////
--/ @brief Resize a view rectangle relatively to its current size
--/
--/ Resizing the view simulates a zoom, as the zone displayed on
--/ screen grows or shrinks.
--/ @a factor is a multiplier:
--/ @li 1 keeps the size unchanged
--/ @li > 1 makes the view bigger (objects appear smaller)
--/ @li < 1 makes the view smaller (objects appear bigger)
--/
--/ @param view View object
--/ @param factor Zoom factor to apply
--/
--//////////////////////////////////////////////////////////
procedure zoom (view : sfView_Ptr; factor : float);
private
pragma Import (C, create, "sfView_create");
pragma Import (C, createFromRect, "sfView_createFromRect");
pragma Import (C, copy, "sfView_copy");
pragma Import (C, destroy, "sfView_destroy");
pragma Import (C, setCenter, "sfView_setCenter");
pragma Import (C, setSize, "sfView_setSize");
pragma Import (C, setRotation, "sfView_setRotation");
pragma Import (C, setViewport, "sfView_setViewport");
pragma Import (C, reset, "sfView_reset");
pragma Import (C, getCenter, "sfView_getCenter");
pragma Import (C, getSize, "sfView_getSize");
pragma Import (C, getRotation, "sfView_getRotation");
pragma Import (C, getViewport, "sfView_getViewport");
pragma Import (C, move, "sfView_move");
pragma Import (C, rotate, "sfView_rotate");
pragma Import (C, zoom, "sfView_zoom");
end Sf.Graphics.View;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2018 onox <denkpadje@gmail.com>
--
-- 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 System;
with GL.API;
with GL.Enums.Getter;
with GL.Low_Level;
with GL.Types.Indirect;
package body GL.Compute is
Indices : constant array (Index_3D) of UInt := (X => 0, Y => 1, Z => 2);
procedure Dispatch_Compute (X, Y, Z : UInt := 1) is
begin
API.Dispatch_Compute.Ref (X, Y, Z);
end Dispatch_Compute;
procedure Dispatch_Compute_Indirect (Offset : Size := 0) is
use GL.Types.Indirect;
Offset_In_Bytes : constant Size
:= Offset * Dispatch_Indirect_Command'Size / System.Storage_Unit;
begin
API.Dispatch_Compute_Indirect.Ref (Low_Level.IntPtr (Offset_In_Bytes));
end Dispatch_Compute_Indirect;
function Max_Compute_Shared_Memory_Size return Size is
Value : Size := 0;
begin
API.Get_Size.Ref (Enums.Getter.Max_Compute_Shared_Memory_Size, Value);
return Value;
end Max_Compute_Shared_Memory_Size;
function Max_Compute_Work_Group_Invocations return Size is
Value : Size := 0;
begin
API.Get_Size.Ref (Enums.Getter.Max_Compute_Work_Group_Invocations, Value);
return Value;
end Max_Compute_Work_Group_Invocations;
function Max_Compute_Work_Group_Count return Dimension_Size_Array is
Values : Dimension_Size_Array := (others => 0);
begin
for Dimension in Values'Range loop
API.Get_Size_I.Ref (Enums.Getter.Max_Compute_Work_Group_Count,
Indices (Dimension), Values (Dimension));
end loop;
return Values;
end Max_Compute_Work_Group_Count;
function Max_Compute_Work_Group_Size return Dimension_Size_Array is
Values : Dimension_Size_Array := (others => 0);
begin
for Dimension in Values'Range loop
API.Get_Size_I.Ref (Enums.Getter.Max_Compute_Work_Group_Size,
Indices (Dimension), Values (Dimension));
end loop;
return Values;
end Max_Compute_Work_Group_Size;
end GL.Compute;
|
-- { dg-do run }
-- { dg-options "-O2" }
procedure self_aggregate_with_call is
type Values is array (1 .. 8) of Natural;
type Vector is record
Components : Values;
end record;
function Clone (Components: Values) return Values is
begin
return Components;
end;
procedure Process (V : in out Vector) is
begin
V.Components (Values'First) := 1;
V := (Components => Clone (V.Components));
if V.Components (Values'First) /= 1 then
raise Program_Error;
end if;
end;
V : Vector;
begin
Process (V);
end;
|
-- This spec has been automatically generated from STM32L4x3.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package STM32_SVD.RCC is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype CR_MSIRANGE_Field is HAL.UInt4;
-- Clock control register
type CR_Register is record
-- MSI clock enable
MSION : Boolean := True;
-- Read-only. MSI clock ready flag
MSIRDY : Boolean := True;
-- MSI clock PLL enable
MSIPLLEN : Boolean := False;
-- Write-only. MSI clock range selection
MSIRGSEL : Boolean := False;
-- MSI clock ranges
MSIRANGE : CR_MSIRANGE_Field := 16#6#;
-- HSI clock enable
HSION : Boolean := False;
-- HSI always enable for peripheral kernels
HSIKERON : Boolean := False;
-- Read-only. HSI clock ready flag
HSIRDY : Boolean := False;
-- HSI automatic start from Stop
HSIASFS : Boolean := False;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- HSE clock enable
HSEON : Boolean := False;
-- Read-only. HSE clock ready flag
HSERDY : Boolean := False;
-- HSE crystal oscillator bypass
HSEBYP : Boolean := False;
-- Write-only. Clock security system enable
CSSON : Boolean := False;
-- unspecified
Reserved_20_23 : HAL.UInt4 := 16#0#;
-- Main PLL enable
PLLON : Boolean := False;
-- Read-only. Main PLL clock ready flag
PLLRDY : Boolean := False;
-- SAI1 PLL enable
PLLSAI1ON : Boolean := False;
-- Read-only. SAI1 PLL clock ready flag
PLLSAI1RDY : Boolean := False;
-- unspecified
Reserved_28_31 : HAL.UInt4 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
MSION at 0 range 0 .. 0;
MSIRDY at 0 range 1 .. 1;
MSIPLLEN at 0 range 2 .. 2;
MSIRGSEL at 0 range 3 .. 3;
MSIRANGE at 0 range 4 .. 7;
HSION at 0 range 8 .. 8;
HSIKERON at 0 range 9 .. 9;
HSIRDY at 0 range 10 .. 10;
HSIASFS at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
HSEON at 0 range 16 .. 16;
HSERDY at 0 range 17 .. 17;
HSEBYP at 0 range 18 .. 18;
CSSON at 0 range 19 .. 19;
Reserved_20_23 at 0 range 20 .. 23;
PLLON at 0 range 24 .. 24;
PLLRDY at 0 range 25 .. 25;
PLLSAI1ON at 0 range 26 .. 26;
PLLSAI1RDY at 0 range 27 .. 27;
Reserved_28_31 at 0 range 28 .. 31;
end record;
subtype ICSCR_MSICAL_Field is HAL.UInt8;
subtype ICSCR_MSITRIM_Field is HAL.UInt8;
subtype ICSCR_HSICAL_Field is HAL.UInt8;
subtype ICSCR_HSITRIM_Field is HAL.UInt5;
-- Internal clock sources calibration register
type ICSCR_Register is record
-- Read-only. MSI clock calibration
MSICAL : ICSCR_MSICAL_Field := 16#0#;
-- MSI clock trimming
MSITRIM : ICSCR_MSITRIM_Field := 16#0#;
-- Read-only. HSI clock calibration
HSICAL : ICSCR_HSICAL_Field := 16#0#;
-- HSI clock trimming
HSITRIM : ICSCR_HSITRIM_Field := 16#10#;
-- unspecified
Reserved_29_31 : HAL.UInt3 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for ICSCR_Register use record
MSICAL at 0 range 0 .. 7;
MSITRIM at 0 range 8 .. 15;
HSICAL at 0 range 16 .. 23;
HSITRIM at 0 range 24 .. 28;
Reserved_29_31 at 0 range 29 .. 31;
end record;
subtype CFGR_SW_Field is HAL.UInt2;
subtype CFGR_SWS_Field is HAL.UInt2;
subtype CFGR_HPRE_Field is HAL.UInt4;
-- CFGR_PPRE array element
subtype CFGR_PPRE_Element is HAL.UInt3;
-- CFGR_PPRE array
type CFGR_PPRE_Field_Array is array (1 .. 2) of CFGR_PPRE_Element
with Component_Size => 3, Size => 6;
-- Type definition for CFGR_PPRE
type CFGR_PPRE_Field
(As_Array : Boolean := False)
is record
case As_Array is
when False =>
-- PPRE as a value
Val : HAL.UInt6;
when True =>
-- PPRE as an array
Arr : CFGR_PPRE_Field_Array;
end case;
end record
with Unchecked_Union, Size => 6;
for CFGR_PPRE_Field use record
Val at 0 range 0 .. 5;
Arr at 0 range 0 .. 5;
end record;
subtype CFGR_MCOSEL_Field is HAL.UInt3;
subtype CFGR_MCOPRE_Field is HAL.UInt3;
-- Clock configuration register
type CFGR_Register is record
-- System clock switch
SW : CFGR_SW_Field := 16#0#;
-- Read-only. System clock switch status
SWS : CFGR_SWS_Field := 16#0#;
-- AHB prescaler
HPRE : CFGR_HPRE_Field := 16#0#;
-- PB low-speed prescaler (APB1)
PPRE : CFGR_PPRE_Field := (As_Array => False, Val => 16#0#);
-- unspecified
Reserved_14_14 : HAL.Bit := 16#0#;
-- Wakeup from Stop and CSS backup clock selection
STOPWUCK : Boolean := False;
-- unspecified
Reserved_16_23 : HAL.UInt8 := 16#0#;
-- Microcontroller clock output
MCOSEL : CFGR_MCOSEL_Field := 16#0#;
-- unspecified
Reserved_27_27 : HAL.Bit := 16#0#;
-- Read-only. Microcontroller clock output prescaler
MCOPRE : CFGR_MCOPRE_Field := 16#0#;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CFGR_Register use record
SW at 0 range 0 .. 1;
SWS at 0 range 2 .. 3;
HPRE at 0 range 4 .. 7;
PPRE at 0 range 8 .. 13;
Reserved_14_14 at 0 range 14 .. 14;
STOPWUCK at 0 range 15 .. 15;
Reserved_16_23 at 0 range 16 .. 23;
MCOSEL at 0 range 24 .. 26;
Reserved_27_27 at 0 range 27 .. 27;
MCOPRE at 0 range 28 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype PLLCFGR_PLLSRC_Field is HAL.UInt2;
subtype PLLCFGR_PLLM_Field is HAL.UInt3;
subtype PLLCFGR_PLLN_Field is HAL.UInt7;
subtype PLLCFGR_PLLQ_Field is HAL.UInt2;
subtype PLLCFGR_PLLR_Field is HAL.UInt2;
-- PLL configuration register
type PLLCFGR_Register is record
-- Main PLL, PLLSAI1 and PLLSAI2 entry clock source
PLLSRC : PLLCFGR_PLLSRC_Field := 16#0#;
-- unspecified
Reserved_2_3 : HAL.UInt2 := 16#0#;
-- Division factor for the main PLL and audio PLL (PLLSAI1 and PLLSAI2)
-- input clock
PLLM : PLLCFGR_PLLM_Field := 16#0#;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Main PLL multiplication factor for VCO
PLLN : PLLCFGR_PLLN_Field := 16#10#;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#0#;
-- Main PLL PLLSAI3CLK output enable
PLLPEN : Boolean := False;
-- Main PLL division factor for PLLSAI3CLK (SAI1 and SAI2 clock)
PLLP : Boolean := False;
-- unspecified
Reserved_18_19 : HAL.UInt2 := 16#0#;
-- Main PLL PLLUSB1CLK output enable
PLLQEN : Boolean := False;
-- Main PLL division factor for PLLUSB1CLK(48 MHz clock)
PLLQ : PLLCFGR_PLLQ_Field := 16#0#;
-- unspecified
Reserved_23_23 : HAL.Bit := 16#0#;
-- Main PLL PLLCLK output enable
PLLREN : Boolean := False;
-- Main PLL division factor for PLLCLK (system clock)
PLLR : PLLCFGR_PLLR_Field := 16#0#;
-- unspecified
Reserved_27_31 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PLLCFGR_Register use record
PLLSRC at 0 range 0 .. 1;
Reserved_2_3 at 0 range 2 .. 3;
PLLM at 0 range 4 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
PLLN at 0 range 8 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
PLLPEN at 0 range 16 .. 16;
PLLP at 0 range 17 .. 17;
Reserved_18_19 at 0 range 18 .. 19;
PLLQEN at 0 range 20 .. 20;
PLLQ at 0 range 21 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
PLLREN at 0 range 24 .. 24;
PLLR at 0 range 25 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
subtype PLLSAI1CFGR_PLLSAI1N_Field is HAL.UInt7;
subtype PLLSAI1CFGR_PLLSAI1Q_Field is HAL.UInt2;
subtype PLLSAI1CFGR_PLLSAI1R_Field is HAL.UInt2;
-- PLLSAI1 configuration register
type PLLSAI1CFGR_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- SAI1PLL multiplication factor for VCO
PLLSAI1N : PLLSAI1CFGR_PLLSAI1N_Field := 16#10#;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#0#;
-- SAI1PLL PLLSAI1CLK output enable
PLLSAI1PEN : Boolean := False;
-- SAI1PLL division factor for PLLSAI1CLK (SAI1 or SAI2 clock)
PLLSAI1P : Boolean := False;
-- unspecified
Reserved_18_19 : HAL.UInt2 := 16#0#;
-- SAI1PLL PLLUSB2CLK output enable
PLLSAI1QEN : Boolean := False;
-- SAI1PLL division factor for PLLUSB2CLK (48 MHz clock)
PLLSAI1Q : PLLSAI1CFGR_PLLSAI1Q_Field := 16#0#;
-- unspecified
Reserved_23_23 : HAL.Bit := 16#0#;
-- PLLSAI1 PLLADC1CLK output enable
PLLSAI1REN : Boolean := False;
-- PLLSAI1 division factor for PLLADC1CLK (ADC clock)
PLLSAI1R : PLLSAI1CFGR_PLLSAI1R_Field := 16#0#;
-- unspecified
Reserved_27_31 : HAL.UInt5 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for PLLSAI1CFGR_Register use record
Reserved_0_7 at 0 range 0 .. 7;
PLLSAI1N at 0 range 8 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
PLLSAI1PEN at 0 range 16 .. 16;
PLLSAI1P at 0 range 17 .. 17;
Reserved_18_19 at 0 range 18 .. 19;
PLLSAI1QEN at 0 range 20 .. 20;
PLLSAI1Q at 0 range 21 .. 22;
Reserved_23_23 at 0 range 23 .. 23;
PLLSAI1REN at 0 range 24 .. 24;
PLLSAI1R at 0 range 25 .. 26;
Reserved_27_31 at 0 range 27 .. 31;
end record;
-- Clock interrupt enable register
type CIER_Register is record
-- LSI ready interrupt enable
LSIRDYIE : Boolean := False;
-- LSE ready interrupt enable
LSERDYIE : Boolean := False;
-- MSI ready interrupt enable
MSIRDYIE : Boolean := False;
-- HSI ready interrupt enable
HSIRDYIE : Boolean := False;
-- HSE ready interrupt enable
HSERDYIE : Boolean := False;
-- PLL ready interrupt enable
PLLRDYIE : Boolean := False;
-- PLLSAI1 ready interrupt enable
PLLSAI1RDYIE : Boolean := False;
-- unspecified
Reserved_7_8 : HAL.UInt2 := 16#0#;
-- LSE clock security system interrupt enable
LSECSSIE : Boolean := False;
-- HSI48 ready interrupt enable
HSI48RDYIE : Boolean := False;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CIER_Register use record
LSIRDYIE at 0 range 0 .. 0;
LSERDYIE at 0 range 1 .. 1;
MSIRDYIE at 0 range 2 .. 2;
HSIRDYIE at 0 range 3 .. 3;
HSERDYIE at 0 range 4 .. 4;
PLLRDYIE at 0 range 5 .. 5;
PLLSAI1RDYIE at 0 range 6 .. 6;
Reserved_7_8 at 0 range 7 .. 8;
LSECSSIE at 0 range 9 .. 9;
HSI48RDYIE at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- Clock interrupt flag register
type CIFR_Register is record
-- Read-only. LSI ready interrupt flag
LSIRDYF : Boolean;
-- Read-only. LSE ready interrupt flag
LSERDYF : Boolean;
-- Read-only. MSI ready interrupt flag
MSIRDYF : Boolean;
-- Read-only. HSI ready interrupt flag
HSIRDYF : Boolean;
-- Read-only. HSE ready interrupt flag
HSERDYF : Boolean;
-- Read-only. PLL ready interrupt flag
PLLRDYF : Boolean;
-- Read-only. PLLSAI1 ready interrupt flag
PLLSAI1RDYF : Boolean;
-- unspecified
Reserved_7_7 : HAL.Bit;
-- Read-only. Clock security system interrupt flag
CSSF : Boolean;
-- Read-only. LSE Clock security system interrupt flag
LSECSSF : Boolean;
-- Read-only. HSI48 ready interrupt flag
HSI48RDYF : Boolean;
-- unspecified
Reserved_11_31 : HAL.UInt21;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CIFR_Register use record
LSIRDYF at 0 range 0 .. 0;
LSERDYF at 0 range 1 .. 1;
MSIRDYF at 0 range 2 .. 2;
HSIRDYF at 0 range 3 .. 3;
HSERDYF at 0 range 4 .. 4;
PLLRDYF at 0 range 5 .. 5;
PLLSAI1RDYF at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
CSSF at 0 range 8 .. 8;
LSECSSF at 0 range 9 .. 9;
HSI48RDYF at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- Clock interrupt clear register
type CICR_Register is record
-- Write-only. LSI ready interrupt clear
LSIRDYC : Boolean := False;
-- Write-only. LSE ready interrupt clear
LSERDYC : Boolean := False;
-- Write-only. MSI ready interrupt clear
MSIRDYC : Boolean := False;
-- Write-only. HSI ready interrupt clear
HSIRDYC : Boolean := False;
-- Write-only. HSE ready interrupt clear
HSERDYC : Boolean := False;
-- Write-only. PLL ready interrupt clear
PLLRDYC : Boolean := False;
-- Write-only. PLLSAI1 ready interrupt clear
PLLSAI1RDYC : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- Write-only. Clock security system interrupt clear
CSSC : Boolean := False;
-- Write-only. LSE Clock security system interrupt clear
LSECSSC : Boolean := False;
-- Write-only. HSI48 oscillator ready interrupt clear
HSI48RDYC : Boolean := False;
-- unspecified
Reserved_11_31 : HAL.UInt21 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CICR_Register use record
LSIRDYC at 0 range 0 .. 0;
LSERDYC at 0 range 1 .. 1;
MSIRDYC at 0 range 2 .. 2;
HSIRDYC at 0 range 3 .. 3;
HSERDYC at 0 range 4 .. 4;
PLLRDYC at 0 range 5 .. 5;
PLLSAI1RDYC at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
CSSC at 0 range 8 .. 8;
LSECSSC at 0 range 9 .. 9;
HSI48RDYC at 0 range 10 .. 10;
Reserved_11_31 at 0 range 11 .. 31;
end record;
-- AHB1 peripheral reset register
type AHB1RSTR_Register is record
-- DMA1 reset
DMA1RST : Boolean := False;
-- DMA2 reset
DMA2RST : Boolean := False;
-- unspecified
Reserved_2_7 : HAL.UInt6 := 16#0#;
-- Flash memory interface reset
FLASHRST : Boolean := False;
-- unspecified
Reserved_9_10 : HAL.UInt2 := 16#0#;
-- CRC reset
CRCRST : Boolean := False;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- Touch Sensing Controller reset
TSCRST : Boolean := False;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB1RSTR_Register use record
DMA1RST at 0 range 0 .. 0;
DMA2RST at 0 range 1 .. 1;
Reserved_2_7 at 0 range 2 .. 7;
FLASHRST at 0 range 8 .. 8;
Reserved_9_10 at 0 range 9 .. 10;
CRCRST at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
TSCRST at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- AHB2 peripheral reset register
type AHB2RSTR_Register is record
-- IO port A reset
GPIOARST : Boolean := False;
-- IO port B reset
GPIOBRST : Boolean := False;
-- IO port C reset
GPIOCRST : Boolean := False;
-- IO port D reset
GPIODRST : Boolean := False;
-- IO port E reset
GPIOERST : Boolean := False;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- IO port H reset
GPIOHRST : Boolean := False;
-- unspecified
Reserved_8_12 : HAL.UInt5 := 16#0#;
-- ADC reset
ADCRST : Boolean := False;
-- unspecified
Reserved_14_15 : HAL.UInt2 := 16#0#;
-- AES hardware accelerator reset
AESRST : Boolean := False;
-- unspecified
Reserved_17_17 : HAL.Bit := 16#0#;
-- Random number generator reset
RNGRST : Boolean := False;
-- unspecified
Reserved_19_31 : HAL.UInt13 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB2RSTR_Register use record
GPIOARST at 0 range 0 .. 0;
GPIOBRST at 0 range 1 .. 1;
GPIOCRST at 0 range 2 .. 2;
GPIODRST at 0 range 3 .. 3;
GPIOERST at 0 range 4 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
GPIOHRST at 0 range 7 .. 7;
Reserved_8_12 at 0 range 8 .. 12;
ADCRST at 0 range 13 .. 13;
Reserved_14_15 at 0 range 14 .. 15;
AESRST at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
RNGRST at 0 range 18 .. 18;
Reserved_19_31 at 0 range 19 .. 31;
end record;
-- AHB3 peripheral reset register
type AHB3RSTR_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- Quad SPI memory interface reset
QSPIRST : Boolean := False;
-- unspecified
Reserved_9_31 : HAL.UInt23 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB3RSTR_Register use record
Reserved_0_7 at 0 range 0 .. 7;
QSPIRST at 0 range 8 .. 8;
Reserved_9_31 at 0 range 9 .. 31;
end record;
-- APB1 peripheral reset register 1
type APB1RSTR1_Register is record
-- TIM2 timer reset
TIM2RST : Boolean := False;
-- unspecified
Reserved_1_3 : HAL.UInt3 := 16#0#;
-- TIM6 timer reset
TIM6RST : Boolean := False;
-- TIM7 timer reset
TIM7RST : Boolean := False;
-- unspecified
Reserved_6_8 : HAL.UInt3 := 16#0#;
-- LCD interface reset
LCDRST : Boolean := False;
-- unspecified
Reserved_10_13 : HAL.UInt4 := 16#0#;
-- SPI2 reset
SPI2RST : Boolean := False;
-- SPI3 reset
SPI3RST : Boolean := False;
-- unspecified
Reserved_16_16 : HAL.Bit := 16#0#;
-- USART2 reset
USART2RST : Boolean := False;
-- USART3 reset
USART3RST : Boolean := False;
-- UART4 reset
UART4RST : Boolean := False;
-- UART5 reset
UART5RST : Boolean := False;
-- I2C1 reset
I2C1RST : Boolean := False;
-- I2C2 reset
I2C2RST : Boolean := False;
-- I2C3 reset
I2C3RST : Boolean := False;
-- unspecified
Reserved_24_24 : HAL.Bit := 16#0#;
-- CAN1 reset
CAN1RST : Boolean := False;
-- unspecified
Reserved_26_27 : HAL.UInt2 := 16#0#;
-- Power interface reset
PWRRST : Boolean := False;
-- DAC1 interface reset
DAC1RST : Boolean := False;
-- OPAMP interface reset
OPAMPRST : Boolean := False;
-- Low Power Timer 1 reset
LPTIM1RST : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB1RSTR1_Register use record
TIM2RST at 0 range 0 .. 0;
Reserved_1_3 at 0 range 1 .. 3;
TIM6RST at 0 range 4 .. 4;
TIM7RST at 0 range 5 .. 5;
Reserved_6_8 at 0 range 6 .. 8;
LCDRST at 0 range 9 .. 9;
Reserved_10_13 at 0 range 10 .. 13;
SPI2RST at 0 range 14 .. 14;
SPI3RST at 0 range 15 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
USART2RST at 0 range 17 .. 17;
USART3RST at 0 range 18 .. 18;
UART4RST at 0 range 19 .. 19;
UART5RST at 0 range 20 .. 20;
I2C1RST at 0 range 21 .. 21;
I2C2RST at 0 range 22 .. 22;
I2C3RST at 0 range 23 .. 23;
Reserved_24_24 at 0 range 24 .. 24;
CAN1RST at 0 range 25 .. 25;
Reserved_26_27 at 0 range 26 .. 27;
PWRRST at 0 range 28 .. 28;
DAC1RST at 0 range 29 .. 29;
OPAMPRST at 0 range 30 .. 30;
LPTIM1RST at 0 range 31 .. 31;
end record;
-- APB1 peripheral reset register 2
type APB1RSTR2_Register is record
-- Low-power UART 1 reset
LPUART1RST : Boolean := False;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#0#;
-- Single wire protocol reset
SWPMI1RST : Boolean := False;
-- unspecified
Reserved_3_4 : HAL.UInt2 := 16#0#;
-- Low-power timer 2 reset
LPTIM2RST : Boolean := False;
-- unspecified
Reserved_6_31 : HAL.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB1RSTR2_Register use record
LPUART1RST at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
SWPMI1RST at 0 range 2 .. 2;
Reserved_3_4 at 0 range 3 .. 4;
LPTIM2RST at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
-- APB2 peripheral reset register
type APB2RSTR_Register is record
-- System configuration (SYSCFG) reset
SYSCFGRST : Boolean := False;
-- unspecified
Reserved_1_9 : HAL.UInt9 := 16#0#;
-- SDMMC reset
SDMMCRST : Boolean := False;
-- TIM1 timer reset
TIM1RST : Boolean := False;
-- SPI1 reset
SPI1RST : Boolean := False;
-- unspecified
Reserved_13_13 : HAL.Bit := 16#0#;
-- USART1 reset
USART1RST : Boolean := False;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#0#;
-- TIM15 timer reset
TIM15RST : Boolean := False;
-- TIM16 timer reset
TIM16RST : Boolean := False;
-- unspecified
Reserved_18_20 : HAL.UInt3 := 16#0#;
-- Serial audio interface 1 (SAI1) reset
SAI1RST : Boolean := False;
-- unspecified
Reserved_22_31 : HAL.UInt10 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB2RSTR_Register use record
SYSCFGRST at 0 range 0 .. 0;
Reserved_1_9 at 0 range 1 .. 9;
SDMMCRST at 0 range 10 .. 10;
TIM1RST at 0 range 11 .. 11;
SPI1RST at 0 range 12 .. 12;
Reserved_13_13 at 0 range 13 .. 13;
USART1RST at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
TIM15RST at 0 range 16 .. 16;
TIM16RST at 0 range 17 .. 17;
Reserved_18_20 at 0 range 18 .. 20;
SAI1RST at 0 range 21 .. 21;
Reserved_22_31 at 0 range 22 .. 31;
end record;
-- AHB1 peripheral clock enable register
type AHB1ENR_Register is record
-- DMA1 clock enable
DMA1EN : Boolean := False;
-- DMA2 clock enable
DMA2EN : Boolean := False;
-- unspecified
Reserved_2_7 : HAL.UInt6 := 16#0#;
-- Flash memory interface clock enable
FLASHEN : Boolean := True;
-- unspecified
Reserved_9_10 : HAL.UInt2 := 16#0#;
-- CRC clock enable
CRCEN : Boolean := False;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#0#;
-- Touch Sensing Controller clock enable
TSCEN : Boolean := False;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB1ENR_Register use record
DMA1EN at 0 range 0 .. 0;
DMA2EN at 0 range 1 .. 1;
Reserved_2_7 at 0 range 2 .. 7;
FLASHEN at 0 range 8 .. 8;
Reserved_9_10 at 0 range 9 .. 10;
CRCEN at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
TSCEN at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- AHB2 peripheral clock enable register
type AHB2ENR_Register is record
-- IO port A clock enable
GPIOAEN : Boolean := False;
-- IO port B clock enable
GPIOBEN : Boolean := False;
-- IO port C clock enable
GPIOCEN : Boolean := False;
-- IO port D clock enable
GPIODEN : Boolean := False;
-- IO port E clock enable
GPIOEEN : Boolean := False;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#0#;
-- IO port H clock enable
GPIOHEN : Boolean := False;
-- unspecified
Reserved_8_12 : HAL.UInt5 := 16#0#;
-- ADC clock enable
ADCEN : Boolean := False;
-- unspecified
Reserved_14_15 : HAL.UInt2 := 16#0#;
-- AES accelerator clock enable
AESEN : Boolean := False;
-- unspecified
Reserved_17_17 : HAL.Bit := 16#0#;
-- Random Number Generator clock enable
RNGEN : Boolean := False;
-- unspecified
Reserved_19_31 : HAL.UInt13 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB2ENR_Register use record
GPIOAEN at 0 range 0 .. 0;
GPIOBEN at 0 range 1 .. 1;
GPIOCEN at 0 range 2 .. 2;
GPIODEN at 0 range 3 .. 3;
GPIOEEN at 0 range 4 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
GPIOHEN at 0 range 7 .. 7;
Reserved_8_12 at 0 range 8 .. 12;
ADCEN at 0 range 13 .. 13;
Reserved_14_15 at 0 range 14 .. 15;
AESEN at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
RNGEN at 0 range 18 .. 18;
Reserved_19_31 at 0 range 19 .. 31;
end record;
-- AHB3 peripheral clock enable register
type AHB3ENR_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#0#;
-- QSPIEN
QSPIEN : Boolean := False;
-- unspecified
Reserved_9_31 : HAL.UInt23 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB3ENR_Register use record
Reserved_0_7 at 0 range 0 .. 7;
QSPIEN at 0 range 8 .. 8;
Reserved_9_31 at 0 range 9 .. 31;
end record;
-- APB1ENR1
type APB1ENR1_Register is record
-- TIM2 timer clock enable
TIM2EN : Boolean := False;
-- unspecified
Reserved_1_3 : HAL.UInt3 := 16#0#;
-- TIM6 timer clock enable
TIM6EN : Boolean := False;
-- TIM7 timer clock enable
TIM7EN : Boolean := False;
-- unspecified
Reserved_6_8 : HAL.UInt3 := 16#0#;
-- LCD clock enable
LCDEN : Boolean := False;
-- RTC APB clock enable
RTCAPBEN : Boolean := False;
-- Window watchdog clock enable
WWDGEN : Boolean := False;
-- unspecified
Reserved_12_13 : HAL.UInt2 := 16#0#;
-- SPI2 clock enable
SPI2EN : Boolean := False;
-- SPI3 clock enable
SP3EN : Boolean := False;
-- unspecified
Reserved_16_16 : HAL.Bit := 16#0#;
-- USART2 clock enable
USART2EN : Boolean := False;
-- USART3 clock enable
USART3EN : Boolean := False;
-- unspecified
Reserved_19_20 : HAL.UInt2 := 16#0#;
-- I2C1 clock enable
I2C1EN : Boolean := False;
-- I2C2 clock enable
I2C2EN : Boolean := False;
-- I2C3 clock enable
I2C3EN : Boolean := False;
-- CRS clock enable
CRSEN : Boolean := False;
-- CAN1 clock enable
CAN1EN : Boolean := False;
-- USB FS clock enable
USBF : Boolean := False;
-- unspecified
Reserved_27_27 : HAL.Bit := 16#0#;
-- Power interface clock enable
PWREN : Boolean := False;
-- DAC1 interface clock enable
DAC1EN : Boolean := False;
-- OPAMP interface clock enable
OPAMPEN : Boolean := False;
-- Low power timer 1 clock enable
LPTIM1EN : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB1ENR1_Register use record
TIM2EN at 0 range 0 .. 0;
Reserved_1_3 at 0 range 1 .. 3;
TIM6EN at 0 range 4 .. 4;
TIM7EN at 0 range 5 .. 5;
Reserved_6_8 at 0 range 6 .. 8;
LCDEN at 0 range 9 .. 9;
RTCAPBEN at 0 range 10 .. 10;
WWDGEN at 0 range 11 .. 11;
Reserved_12_13 at 0 range 12 .. 13;
SPI2EN at 0 range 14 .. 14;
SP3EN at 0 range 15 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
USART2EN at 0 range 17 .. 17;
USART3EN at 0 range 18 .. 18;
Reserved_19_20 at 0 range 19 .. 20;
I2C1EN at 0 range 21 .. 21;
I2C2EN at 0 range 22 .. 22;
I2C3EN at 0 range 23 .. 23;
CRSEN at 0 range 24 .. 24;
CAN1EN at 0 range 25 .. 25;
USBF at 0 range 26 .. 26;
Reserved_27_27 at 0 range 27 .. 27;
PWREN at 0 range 28 .. 28;
DAC1EN at 0 range 29 .. 29;
OPAMPEN at 0 range 30 .. 30;
LPTIM1EN at 0 range 31 .. 31;
end record;
-- APB1 peripheral clock enable register 2
type APB1ENR2_Register is record
-- Low power UART 1 clock enable
LPUART1EN : Boolean := False;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#0#;
-- Single wire protocol clock enable
SWPMI1EN : Boolean := False;
-- unspecified
Reserved_3_4 : HAL.UInt2 := 16#0#;
-- LPTIM2EN
LPTIM2EN : Boolean := False;
-- unspecified
Reserved_6_31 : HAL.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB1ENR2_Register use record
LPUART1EN at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
SWPMI1EN at 0 range 2 .. 2;
Reserved_3_4 at 0 range 3 .. 4;
LPTIM2EN at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
-- APB2ENR
type APB2ENR_Register is record
-- SYSCFG clock enable
SYSCFGEN : Boolean := False;
-- unspecified
Reserved_1_6 : HAL.UInt6 := 16#0#;
-- Firewall clock enable
FIREWALLEN : Boolean := False;
-- unspecified
Reserved_8_9 : HAL.UInt2 := 16#0#;
-- SDMMC clock enable
SDMMCEN : Boolean := False;
-- TIM1 timer clock enable
TIM1EN : Boolean := False;
-- SPI1 clock enable
SPI1EN : Boolean := False;
-- unspecified
Reserved_13_13 : HAL.Bit := 16#0#;
-- USART1clock enable
USART1EN : Boolean := False;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#0#;
-- TIM15 timer clock enable
TIM15EN : Boolean := False;
-- TIM16 timer clock enable
TIM16EN : Boolean := False;
-- unspecified
Reserved_18_20 : HAL.UInt3 := 16#0#;
-- SAI1 clock enable
SAI1EN : Boolean := False;
-- unspecified
Reserved_22_31 : HAL.UInt10 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB2ENR_Register use record
SYSCFGEN at 0 range 0 .. 0;
Reserved_1_6 at 0 range 1 .. 6;
FIREWALLEN at 0 range 7 .. 7;
Reserved_8_9 at 0 range 8 .. 9;
SDMMCEN at 0 range 10 .. 10;
TIM1EN at 0 range 11 .. 11;
SPI1EN at 0 range 12 .. 12;
Reserved_13_13 at 0 range 13 .. 13;
USART1EN at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
TIM15EN at 0 range 16 .. 16;
TIM16EN at 0 range 17 .. 17;
Reserved_18_20 at 0 range 18 .. 20;
SAI1EN at 0 range 21 .. 21;
Reserved_22_31 at 0 range 22 .. 31;
end record;
-- AHB1 peripheral clocks enable in Sleep and Stop modes register
type AHB1SMENR_Register is record
-- DMA1 clocks enable during Sleep and Stop modes
DMA1SMEN : Boolean := True;
-- DMA2 clocks enable during Sleep and Stop modes
DMA2SMEN : Boolean := True;
-- unspecified
Reserved_2_7 : HAL.UInt6 := 16#0#;
-- Flash memory interface clocks enable during Sleep and Stop modes
FLASHSMEN : Boolean := True;
-- SRAM1 interface clocks enable during Sleep and Stop modes
SRAM1SMEN : Boolean := True;
-- unspecified
Reserved_10_10 : HAL.Bit := 16#0#;
-- CRCSMEN
CRCSMEN : Boolean := False;
-- unspecified
Reserved_12_15 : HAL.UInt4 := 16#1#;
-- Touch Sensing Controller clocks enable during Sleep and Stop modes
TSCSMEN : Boolean := True;
-- unspecified
Reserved_17_31 : HAL.UInt15 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB1SMENR_Register use record
DMA1SMEN at 0 range 0 .. 0;
DMA2SMEN at 0 range 1 .. 1;
Reserved_2_7 at 0 range 2 .. 7;
FLASHSMEN at 0 range 8 .. 8;
SRAM1SMEN at 0 range 9 .. 9;
Reserved_10_10 at 0 range 10 .. 10;
CRCSMEN at 0 range 11 .. 11;
Reserved_12_15 at 0 range 12 .. 15;
TSCSMEN at 0 range 16 .. 16;
Reserved_17_31 at 0 range 17 .. 31;
end record;
-- AHB2 peripheral clocks enable in Sleep and Stop modes register
type AHB2SMENR_Register is record
-- IO port A clocks enable during Sleep and Stop modes
GPIOASMEN : Boolean := True;
-- IO port B clocks enable during Sleep and Stop modes
GPIOBSMEN : Boolean := True;
-- IO port C clocks enable during Sleep and Stop modes
GPIOCSMEN : Boolean := True;
-- IO port D clocks enable during Sleep and Stop modes
GPIODSMEN : Boolean := True;
-- IO port E clocks enable during Sleep and Stop modes
GPIOESMEN : Boolean := True;
-- unspecified
Reserved_5_6 : HAL.UInt2 := 16#3#;
-- IO port H clocks enable during Sleep and Stop modes
GPIOHSMEN : Boolean := True;
-- unspecified
Reserved_8_8 : HAL.Bit := 16#0#;
-- SRAM2 interface clocks enable during Sleep and Stop modes
SRAM2SMEN : Boolean := True;
-- unspecified
Reserved_10_12 : HAL.UInt3 := 16#4#;
-- ADC clocks enable during Sleep and Stop modes
ADCFSSMEN : Boolean := True;
-- unspecified
Reserved_14_15 : HAL.UInt2 := 16#0#;
-- AES accelerator clocks enable during Sleep and Stop modes
AESSMEN : Boolean := True;
-- unspecified
Reserved_17_17 : HAL.Bit := 16#0#;
-- Random Number Generator clocks enable during Sleep and Stop modes
RNGSMEN : Boolean := True;
-- unspecified
Reserved_19_31 : HAL.UInt13 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB2SMENR_Register use record
GPIOASMEN at 0 range 0 .. 0;
GPIOBSMEN at 0 range 1 .. 1;
GPIOCSMEN at 0 range 2 .. 2;
GPIODSMEN at 0 range 3 .. 3;
GPIOESMEN at 0 range 4 .. 4;
Reserved_5_6 at 0 range 5 .. 6;
GPIOHSMEN at 0 range 7 .. 7;
Reserved_8_8 at 0 range 8 .. 8;
SRAM2SMEN at 0 range 9 .. 9;
Reserved_10_12 at 0 range 10 .. 12;
ADCFSSMEN at 0 range 13 .. 13;
Reserved_14_15 at 0 range 14 .. 15;
AESSMEN at 0 range 16 .. 16;
Reserved_17_17 at 0 range 17 .. 17;
RNGSMEN at 0 range 18 .. 18;
Reserved_19_31 at 0 range 19 .. 31;
end record;
-- AHB3 peripheral clocks enable in Sleep and Stop modes register
type AHB3SMENR_Register is record
-- unspecified
Reserved_0_7 : HAL.UInt8 := 16#1#;
-- QSPISMEN
QSPISMEN : Boolean := True;
-- unspecified
Reserved_9_31 : HAL.UInt23 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for AHB3SMENR_Register use record
Reserved_0_7 at 0 range 0 .. 7;
QSPISMEN at 0 range 8 .. 8;
Reserved_9_31 at 0 range 9 .. 31;
end record;
-- APB1SMENR1
type APB1SMENR1_Register is record
-- TIM2 timer clocks enable during Sleep and Stop modes
TIM2SMEN : Boolean := True;
-- unspecified
Reserved_1_3 : HAL.UInt3 := 16#7#;
-- TIM6 timer clocks enable during Sleep and Stop modes
TIM6SMEN : Boolean := True;
-- TIM7 timer clocks enable during Sleep and Stop modes
TIM7SMEN : Boolean := True;
-- unspecified
Reserved_6_8 : HAL.UInt3 := 16#0#;
-- LCD clocks enable during Sleep and Stop modes
LCDSMEN : Boolean := True;
-- RTC APB clock enable during Sleep and Stop modes
RTCAPBSMEN : Boolean := False;
-- Window watchdog clocks enable during Sleep and Stop modes
WWDGSMEN : Boolean := True;
-- unspecified
Reserved_12_13 : HAL.UInt2 := 16#0#;
-- SPI2 clocks enable during Sleep and Stop modes
SPI2SMEN : Boolean := True;
-- SPI3 clocks enable during Sleep and Stop modes
SP3SMEN : Boolean := True;
-- unspecified
Reserved_16_16 : HAL.Bit := 16#0#;
-- USART2 clocks enable during Sleep and Stop modes
USART2SMEN : Boolean := True;
-- USART3 clocks enable during Sleep and Stop modes
USART3SMEN : Boolean := True;
-- unspecified
Reserved_19_20 : HAL.UInt2 := 16#3#;
-- I2C1 clocks enable during Sleep and Stop modes
I2C1SMEN : Boolean := True;
-- I2C2 clocks enable during Sleep and Stop modes
I2C2SMEN : Boolean := True;
-- I2C3 clocks enable during Sleep and Stop modes
I2C3SMEN : Boolean := True;
-- unspecified
Reserved_24_24 : HAL.Bit := 16#0#;
-- CAN1 clocks enable during Sleep and Stop modes
CAN1SMEN : Boolean := True;
-- USB FS clock enable during Sleep and Stop modes
USBFSSMEN : Boolean := False;
-- unspecified
Reserved_27_27 : HAL.Bit := 16#0#;
-- Power interface clocks enable during Sleep and Stop modes
PWRSMEN : Boolean := True;
-- DAC1 interface clocks enable during Sleep and Stop modes
DAC1SMEN : Boolean := True;
-- OPAMP interface clocks enable during Sleep and Stop modes
OPAMPSMEN : Boolean := True;
-- Low power timer 1 clocks enable during Sleep and Stop modes
LPTIM1SMEN : Boolean := True;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB1SMENR1_Register use record
TIM2SMEN at 0 range 0 .. 0;
Reserved_1_3 at 0 range 1 .. 3;
TIM6SMEN at 0 range 4 .. 4;
TIM7SMEN at 0 range 5 .. 5;
Reserved_6_8 at 0 range 6 .. 8;
LCDSMEN at 0 range 9 .. 9;
RTCAPBSMEN at 0 range 10 .. 10;
WWDGSMEN at 0 range 11 .. 11;
Reserved_12_13 at 0 range 12 .. 13;
SPI2SMEN at 0 range 14 .. 14;
SP3SMEN at 0 range 15 .. 15;
Reserved_16_16 at 0 range 16 .. 16;
USART2SMEN at 0 range 17 .. 17;
USART3SMEN at 0 range 18 .. 18;
Reserved_19_20 at 0 range 19 .. 20;
I2C1SMEN at 0 range 21 .. 21;
I2C2SMEN at 0 range 22 .. 22;
I2C3SMEN at 0 range 23 .. 23;
Reserved_24_24 at 0 range 24 .. 24;
CAN1SMEN at 0 range 25 .. 25;
USBFSSMEN at 0 range 26 .. 26;
Reserved_27_27 at 0 range 27 .. 27;
PWRSMEN at 0 range 28 .. 28;
DAC1SMEN at 0 range 29 .. 29;
OPAMPSMEN at 0 range 30 .. 30;
LPTIM1SMEN at 0 range 31 .. 31;
end record;
-- APB1 peripheral clocks enable in Sleep and Stop modes register 2
type APB1SMENR2_Register is record
-- Low power UART 1 clocks enable during Sleep and Stop modes
LPUART1SMEN : Boolean := True;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#0#;
-- Single wire protocol clocks enable during Sleep and Stop modes
SWPMI1SMEN : Boolean := True;
-- unspecified
Reserved_3_4 : HAL.UInt2 := 16#0#;
-- LPTIM2SMEN
LPTIM2SMEN : Boolean := True;
-- unspecified
Reserved_6_31 : HAL.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB1SMENR2_Register use record
LPUART1SMEN at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
SWPMI1SMEN at 0 range 2 .. 2;
Reserved_3_4 at 0 range 3 .. 4;
LPTIM2SMEN at 0 range 5 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
-- APB2SMENR
type APB2SMENR_Register is record
-- SYSCFG clocks enable during Sleep and Stop modes
SYSCFGSMEN : Boolean := True;
-- unspecified
Reserved_1_9 : HAL.UInt9 := 16#0#;
-- SDMMC clocks enable during Sleep and Stop modes
SDMMCSMEN : Boolean := True;
-- TIM1 timer clocks enable during Sleep and Stop modes
TIM1SMEN : Boolean := True;
-- SPI1 clocks enable during Sleep and Stop modes
SPI1SMEN : Boolean := True;
-- unspecified
Reserved_13_13 : HAL.Bit := 16#1#;
-- USART1clocks enable during Sleep and Stop modes
USART1SMEN : Boolean := True;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#0#;
-- TIM15 timer clocks enable during Sleep and Stop modes
TIM15SMEN : Boolean := True;
-- TIM16 timer clocks enable during Sleep and Stop modes
TIM16SMEN : Boolean := True;
-- unspecified
Reserved_18_20 : HAL.UInt3 := 16#1#;
-- SAI1 clocks enable during Sleep and Stop modes
SAI1SMEN : Boolean := True;
-- unspecified
Reserved_22_31 : HAL.UInt10 := 16#5#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB2SMENR_Register use record
SYSCFGSMEN at 0 range 0 .. 0;
Reserved_1_9 at 0 range 1 .. 9;
SDMMCSMEN at 0 range 10 .. 10;
TIM1SMEN at 0 range 11 .. 11;
SPI1SMEN at 0 range 12 .. 12;
Reserved_13_13 at 0 range 13 .. 13;
USART1SMEN at 0 range 14 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
TIM15SMEN at 0 range 16 .. 16;
TIM16SMEN at 0 range 17 .. 17;
Reserved_18_20 at 0 range 18 .. 20;
SAI1SMEN at 0 range 21 .. 21;
Reserved_22_31 at 0 range 22 .. 31;
end record;
subtype CCIPR_USART1SEL_Field is HAL.UInt2;
subtype CCIPR_USART2SEL_Field is HAL.UInt2;
subtype CCIPR_USART3SEL_Field is HAL.UInt2;
subtype CCIPR_LPUART1SEL_Field is HAL.UInt2;
subtype CCIPR_I2C1SEL_Field is HAL.UInt2;
subtype CCIPR_I2C2SEL_Field is HAL.UInt2;
subtype CCIPR_I2C3SEL_Field is HAL.UInt2;
subtype CCIPR_LPTIM1SEL_Field is HAL.UInt2;
subtype CCIPR_LPTIM2SEL_Field is HAL.UInt2;
subtype CCIPR_SAI1SEL_Field is HAL.UInt2;
subtype CCIPR_CLK48SEL_Field is HAL.UInt2;
subtype CCIPR_ADCSEL_Field is HAL.UInt2;
-- CCIPR
type CCIPR_Register is record
-- USART1 clock source selection
USART1SEL : CCIPR_USART1SEL_Field := 16#0#;
-- USART2 clock source selection
USART2SEL : CCIPR_USART2SEL_Field := 16#0#;
-- USART3 clock source selection
USART3SEL : CCIPR_USART3SEL_Field := 16#0#;
-- unspecified
Reserved_6_9 : HAL.UInt4 := 16#0#;
-- LPUART1 clock source selection
LPUART1SEL : CCIPR_LPUART1SEL_Field := 16#0#;
-- I2C1 clock source selection
I2C1SEL : CCIPR_I2C1SEL_Field := 16#0#;
-- I2C2 clock source selection
I2C2SEL : CCIPR_I2C2SEL_Field := 16#0#;
-- I2C3 clock source selection
I2C3SEL : CCIPR_I2C3SEL_Field := 16#0#;
-- Low power timer 1 clock source selection
LPTIM1SEL : CCIPR_LPTIM1SEL_Field := 16#0#;
-- Low power timer 2 clock source selection
LPTIM2SEL : CCIPR_LPTIM2SEL_Field := 16#0#;
-- SAI1 clock source selection
SAI1SEL : CCIPR_SAI1SEL_Field := 16#0#;
-- unspecified
Reserved_24_25 : HAL.UInt2 := 16#0#;
-- 48 MHz clock source selection
CLK48SEL : CCIPR_CLK48SEL_Field := 16#0#;
-- ADCs clock source selection
ADCSEL : CCIPR_ADCSEL_Field := 16#0#;
-- SWPMI1 clock source selection
SWPMI1SEL : Boolean := False;
-- unspecified
Reserved_31_31 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CCIPR_Register use record
USART1SEL at 0 range 0 .. 1;
USART2SEL at 0 range 2 .. 3;
USART3SEL at 0 range 4 .. 5;
Reserved_6_9 at 0 range 6 .. 9;
LPUART1SEL at 0 range 10 .. 11;
I2C1SEL at 0 range 12 .. 13;
I2C2SEL at 0 range 14 .. 15;
I2C3SEL at 0 range 16 .. 17;
LPTIM1SEL at 0 range 18 .. 19;
LPTIM2SEL at 0 range 20 .. 21;
SAI1SEL at 0 range 22 .. 23;
Reserved_24_25 at 0 range 24 .. 25;
CLK48SEL at 0 range 26 .. 27;
ADCSEL at 0 range 28 .. 29;
SWPMI1SEL at 0 range 30 .. 30;
Reserved_31_31 at 0 range 31 .. 31;
end record;
subtype BDCR_LSEDRV_Field is HAL.UInt2;
subtype BDCR_RTCSEL_Field is HAL.UInt2;
-- BDCR
type BDCR_Register is record
-- LSE oscillator enable
LSEON : Boolean := False;
-- Read-only. LSE oscillator ready
LSERDY : Boolean := False;
-- LSE oscillator bypass
LSEBYP : Boolean := False;
-- SE oscillator drive capability
LSEDRV : BDCR_LSEDRV_Field := 16#0#;
-- LSECSSON
LSECSSON : Boolean := False;
-- Read-only. LSECSSD
LSECSSD : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
-- RTC clock source selection
RTCSEL : BDCR_RTCSEL_Field := 16#0#;
-- unspecified
Reserved_10_14 : HAL.UInt5 := 16#0#;
-- RTC clock enable
RTCEN : Boolean := False;
-- Backup domain software reset
BDRST : Boolean := False;
-- unspecified
Reserved_17_23 : HAL.UInt7 := 16#0#;
-- Low speed clock output enable
LSCOEN : Boolean := False;
-- Low speed clock output selection
LSCOSEL : Boolean := False;
-- unspecified
Reserved_26_31 : HAL.UInt6 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for BDCR_Register use record
LSEON at 0 range 0 .. 0;
LSERDY at 0 range 1 .. 1;
LSEBYP at 0 range 2 .. 2;
LSEDRV at 0 range 3 .. 4;
LSECSSON at 0 range 5 .. 5;
LSECSSD at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
RTCSEL at 0 range 8 .. 9;
Reserved_10_14 at 0 range 10 .. 14;
RTCEN at 0 range 15 .. 15;
BDRST at 0 range 16 .. 16;
Reserved_17_23 at 0 range 17 .. 23;
LSCOEN at 0 range 24 .. 24;
LSCOSEL at 0 range 25 .. 25;
Reserved_26_31 at 0 range 26 .. 31;
end record;
subtype CSR_MSISRANGE_Field is HAL.UInt4;
-- CSR
type CSR_Register is record
-- LSI oscillator enable
LSION : Boolean := False;
-- Read-only. LSI oscillator ready
LSIRDY : Boolean := False;
-- unspecified
Reserved_2_7 : HAL.UInt6 := 16#0#;
-- SI range after Standby mode
MSISRANGE : CSR_MSISRANGE_Field := 16#6#;
-- unspecified
Reserved_12_22 : HAL.UInt11 := 16#0#;
-- Remove reset flag
RMVF : Boolean := False;
-- Read-only. Firewall reset flag
FIREWALLRSTF : Boolean := False;
-- Read-only. Option byte loader reset flag
OBLRSTF : Boolean := False;
-- Read-only. Pin reset flag
PINRSTF : Boolean := True;
-- Read-only. BOR flag
BORRSTF : Boolean := True;
-- Read-only. Software reset flag
SFTRSTF : Boolean := False;
-- Read-only. Independent window watchdog reset flag
IWDGRSTF : Boolean := False;
-- Read-only. Window watchdog reset flag
WWDGRSTF : Boolean := False;
-- Read-only. Low-power reset flag
LPWRSTF : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CSR_Register use record
LSION at 0 range 0 .. 0;
LSIRDY at 0 range 1 .. 1;
Reserved_2_7 at 0 range 2 .. 7;
MSISRANGE at 0 range 8 .. 11;
Reserved_12_22 at 0 range 12 .. 22;
RMVF at 0 range 23 .. 23;
FIREWALLRSTF at 0 range 24 .. 24;
OBLRSTF at 0 range 25 .. 25;
PINRSTF at 0 range 26 .. 26;
BORRSTF at 0 range 27 .. 27;
SFTRSTF at 0 range 28 .. 28;
IWDGRSTF at 0 range 29 .. 29;
WWDGRSTF at 0 range 30 .. 30;
LPWRSTF at 0 range 31 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Reset and clock control
type RCC_Peripheral is record
-- Clock control register
CR : aliased CR_Register;
-- Internal clock sources calibration register
ICSCR : aliased ICSCR_Register;
-- Clock configuration register
CFGR : aliased CFGR_Register;
-- PLL configuration register
PLLCFGR : aliased PLLCFGR_Register;
-- PLLSAI1 configuration register
PLLSAI1CFGR : aliased PLLSAI1CFGR_Register;
-- Clock interrupt enable register
CIER : aliased CIER_Register;
-- Clock interrupt flag register
CIFR : aliased CIFR_Register;
-- Clock interrupt clear register
CICR : aliased CICR_Register;
-- AHB1 peripheral reset register
AHB1RSTR : aliased AHB1RSTR_Register;
-- AHB2 peripheral reset register
AHB2RSTR : aliased AHB2RSTR_Register;
-- AHB3 peripheral reset register
AHB3RSTR : aliased AHB3RSTR_Register;
-- APB1 peripheral reset register 1
APB1RSTR1 : aliased APB1RSTR1_Register;
-- APB1 peripheral reset register 2
APB1RSTR2 : aliased APB1RSTR2_Register;
-- APB2 peripheral reset register
APB2RSTR : aliased APB2RSTR_Register;
-- AHB1 peripheral clock enable register
AHB1ENR : aliased AHB1ENR_Register;
-- AHB2 peripheral clock enable register
AHB2ENR : aliased AHB2ENR_Register;
-- AHB3 peripheral clock enable register
AHB3ENR : aliased AHB3ENR_Register;
-- APB1ENR1
APB1ENR1 : aliased APB1ENR1_Register;
-- APB1 peripheral clock enable register 2
APB1ENR2 : aliased APB1ENR2_Register;
-- APB2ENR
APB2ENR : aliased APB2ENR_Register;
-- AHB1 peripheral clocks enable in Sleep and Stop modes register
AHB1SMENR : aliased AHB1SMENR_Register;
-- AHB2 peripheral clocks enable in Sleep and Stop modes register
AHB2SMENR : aliased AHB2SMENR_Register;
-- AHB3 peripheral clocks enable in Sleep and Stop modes register
AHB3SMENR : aliased AHB3SMENR_Register;
-- APB1SMENR1
APB1SMENR1 : aliased APB1SMENR1_Register;
-- APB1 peripheral clocks enable in Sleep and Stop modes register 2
APB1SMENR2 : aliased APB1SMENR2_Register;
-- APB2SMENR
APB2SMENR : aliased APB2SMENR_Register;
-- CCIPR
CCIPR : aliased CCIPR_Register;
-- BDCR
BDCR : aliased BDCR_Register;
-- CSR
CSR : aliased CSR_Register;
end record
with Volatile;
for RCC_Peripheral use record
CR at 16#0# range 0 .. 31;
ICSCR at 16#4# range 0 .. 31;
CFGR at 16#8# range 0 .. 31;
PLLCFGR at 16#C# range 0 .. 31;
PLLSAI1CFGR at 16#10# range 0 .. 31;
CIER at 16#18# range 0 .. 31;
CIFR at 16#1C# range 0 .. 31;
CICR at 16#20# range 0 .. 31;
AHB1RSTR at 16#28# range 0 .. 31;
AHB2RSTR at 16#2C# range 0 .. 31;
AHB3RSTR at 16#30# range 0 .. 31;
APB1RSTR1 at 16#38# range 0 .. 31;
APB1RSTR2 at 16#3C# range 0 .. 31;
APB2RSTR at 16#40# range 0 .. 31;
AHB1ENR at 16#48# range 0 .. 31;
AHB2ENR at 16#4C# range 0 .. 31;
AHB3ENR at 16#50# range 0 .. 31;
APB1ENR1 at 16#58# range 0 .. 31;
APB1ENR2 at 16#5C# range 0 .. 31;
APB2ENR at 16#60# range 0 .. 31;
AHB1SMENR at 16#68# range 0 .. 31;
AHB2SMENR at 16#6C# range 0 .. 31;
AHB3SMENR at 16#70# range 0 .. 31;
APB1SMENR1 at 16#78# range 0 .. 31;
APB1SMENR2 at 16#7C# range 0 .. 31;
APB2SMENR at 16#80# range 0 .. 31;
CCIPR at 16#88# range 0 .. 31;
BDCR at 16#90# range 0 .. 31;
CSR at 16#94# range 0 .. 31;
end record;
-- Reset and clock control
RCC_Periph : aliased RCC_Peripheral
with Import, Address => RCC_Base;
end STM32_SVD.RCC;
|
with HAL.SPI; use HAL.SPI;
with HAL.GPIO; use HAL.GPIO;
with Interfaces; use Interfaces;
package mpu6000_spi is
type Six_Axis_Accelerometer
(Port : not null Any_SPI_Port;
Chip_Select : not null Any_GPIO_Point) is limited private;
type Acc_Data is
record
Xacc, Yacc, Zacc : Short_Integer;
Xang, Yang, Zang : Short_Integer;
end record;
procedure Configure (this : in out Six_Axis_Accelerometer);
function Read (this : in out Six_Axis_Accelerometer) return Acc_Data;
function Id (this : in out Six_Axis_Accelerometer;
product : out Unsigned_8) return Unsigned_8;
private
type Six_Axis_Accelerometer
(Port : not null Any_SPI_Port;
Chip_Select : not null Any_GPIO_Point) is limited
record
Device_Configured : Boolean := False;
end record;
end mpu6000_spi;
|
-------------------------------------------------------------------------------
-- Copyright (c) 2016 Daniel King
--
-- 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_Conversion;
with DW1000.Constants; use DW1000.Constants;
with DW1000.Registers; use DW1000.Registers;
with DW1000.Register_Driver;
package body DW1000.Driver
with SPARK_Mode => On
is
-- These values for LDE_CFG1 are given by the user manual
LDE_CFG1_Value : constant LDE_CFG1_Type
:= (NTM => 13,
PMULT => 3);
-- These values for LDE_CFG2 are given by the user manual
LDE_CFG2_Values : constant array (PRF_Type) of LDE_CFG2_Field
:= (PRF_16MHz => LDE_CFG2_16MHz,
PRF_64MHz => LDE_CFG2_64MHz);
LDE_Replica_Coeffs : constant
array (Preamble_Code_Number) of LDE_REPC_Field
:= (1 => LDE_REPC_Field (0.35 * 2**16),
2 => LDE_REPC_Field (0.35 * 2**16),
3 => LDE_REPC_Field (0.32 * 2**16),
4 => LDE_REPC_Field (0.26 * 2**16),
5 => LDE_REPC_Field (0.27 * 2**16),
6 => LDE_REPC_Field (0.18 * 2**16),
7 => LDE_REPC_Field (0.50 * 2**16),
8 => LDE_REPC_Field (0.32 * 2**16),
9 => LDE_REPC_Field (0.16 * 2**16),
10 => LDE_REPC_Field (0.20 * 2**16),
11 => LDE_REPC_Field (0.23 * 2**16),
12 => LDE_REPC_Field (0.24 * 2**16),
13 => LDE_REPC_Field (0.23 * 2**16),
14 => LDE_REPC_Field (0.21 * 2**16),
15 => LDE_REPC_Field (0.27 * 2**16),
16 => LDE_REPC_Field (0.21 * 2**16),
17 => LDE_REPC_Field (0.20 * 2**16),
18 => LDE_REPC_Field (0.21 * 2**16),
19 => LDE_REPC_Field (0.21 * 2**16),
20 => LDE_REPC_Field (0.28 * 2**16),
21 => LDE_REPC_Field (0.23 * 2**16),
22 => LDE_REPC_Field (0.22 * 2**16),
23 => LDE_REPC_Field (0.19 * 2**16),
24 => LDE_REPC_Field (0.22 * 2**16));
-- These values for FS_PLLCFG are given by the user manual
FS_PLLCFG_Values : constant array (Positive range 1 .. 7) of FS_PLLCFG_Field
:= (1 => FS_PLLCFG_Channel_1,
2 => FS_PLLCFG_Channel_2,
3 => FS_PLLCFG_Channel_3,
4 => FS_PLLCFG_Channel_4,
5 => FS_PLLCFG_Channel_5,
7 => FS_PLLCFG_Channel_7,
-- Note that channel 6 is not a valid channel. However, Channel_Number
-- cannot be used as the array index type since it has a predicate.
6 => 0);
-- These values for FS_PLLTUNE are given by the user manual
FS_PLLTUNE_Values : constant array (Positive range 1 .. 7) of FS_PLLTUNE_Field
:= (1 => FS_PLLTUNE_Channel_1,
2 => FS_PLLTUNE_Channel_2,
3 => FS_PLLTUNE_Channel_3,
4 => FS_PLLTUNE_Channel_4,
5 => FS_PLLTUNE_Channel_5,
7 => FS_PLLTUNE_Channel_7,
-- Note that channel 6 is not a valid channel. However, Channel_Number
-- cannot be used as the array index type since it has a predicate.
6 => 0);
-- These values for FS_PLLCFG are ported from the C decadriver
FS_XTALT_Value : constant FS_XTALT_Type
:= (XTALT => 16,
Reserved => 2#011#);
-- These values for RF_TXCTRL are given by the user manual
RF_TXCTRL_Values : constant array (Positive range 1 .. 7) of RF_TXCTRL_Field
:= (1 => RF_TXCTRL_Channel_1,
2 => RF_TXCTRL_Channel_2,
3 => RF_TXCTRL_Channel_3,
4 => RF_TXCTRL_Channel_4,
5 => RF_TXCTRL_Channel_5,
7 => RF_TXCTRL_Channel_7,
-- Note that channel 6 is not a valid channel. However, Channel_Number
-- cannot be used as the array index type since it has a predicate.
6 => 0);
-- These values for RF_RXCTRLH are given by the user manual
RF_RXCTRLH_Values : constant array (Positive range 1 .. 7) of RF_RXCTRLH_Field
:= (1 .. 3 | 5 => RF_RXCTRLH_500MHz,
4 | 7 => RF_RXCTRLH_900MHz,
-- Note that channel 6 is not a valid channel. However, Channel_Number
-- cannot be used as the array index type since it has a predicate.
6 => 0);
-- These values for DRX_TUNE0b are given by the user manual
DRX_TUNE0b_Values : constant array (Data_Rates, Boolean) of DRX_TUNE0b_Field
:= (Data_Rate_110k => (False => DRX_TUNE0b_110K_STD,
True => DRX_TUNE0b_110K_Non_STD),
Data_Rate_850k => (False => DRX_TUNE0b_850K_STD,
True => DRX_TUNE0b_850K_Non_STD),
Data_Rate_6M8 => (False => DRX_TUNE0b_6M8_STD,
True => DRX_TUNE0b_6M8_Non_STD));
-- These values for DRX_TUNE1a are given by the user manual
DRX_TUNE1a_Values : constant array (PRF_Type) of DRX_TUNE1a_Field
:= (PRF_16MHz => DRX_TUNE1a_16MHz,
PRF_64MHz => DRX_TUNE1a_64MHz);
-- These values for DRX_TUNE2 are given by the user manual
DRX_TUNE2_Values : constant array (Preamble_Acq_Chunk_Length,
PRF_Type) of DRX_TUNE2_Field
:= (PAC_8 => (PRF_16MHz => DRX_TUNE2_PAC8_16MHz,
PRF_64MHz => DRX_TUNE2_PAC8_64MHz),
PAC_16 => (PRF_16MHz => DRX_TUNE2_PAC16_16MHz,
PRF_64MHz => DRX_TUNE2_PAC16_64MHz),
PAC_32 => (PRF_16MHz => DRX_TUNE2_PAC32_16MHz,
PRF_64MHz => DRX_TUNE2_PAC32_64MHz),
PAC_64 => (PRF_16MHz => DRX_TUNE2_PAC64_16MHz,
PRF_64MHz => DRX_TUNE2_PAC64_64MHz));
-- These values for AGC_TUNE1 are given by the user manual
AGC_TUNE1_Values : constant array (PRF_Type) of AGC_TUNE1_Field
:= (PRF_16MHz => AGC_TUNE1_PRF_16MHz,
PRF_64MHz => AGC_TUNE1_PRF_64MHz);
-- These values for TC_PGDELAY are given by the user manual
TC_PGDELAY_Values : constant array (Positive range 1 .. 7) of TC_PGDELAY_Field
:= (1 => TC_PGDELAY_Channel_1,
2 => TC_PGDELAY_Channel_2,
3 => TC_PGDELAY_Channel_3,
4 => TC_PGDELAY_Channel_4,
5 => TC_PGDELAY_Channel_5,
6 => 0, -- Channel 6 not in Channel_Number
7 => TC_PGDELAY_Channel_7);
-- This value for non-standard SFD lengths are given by the user manual
Non_Standard_SFD_Lengths : constant array (Data_Rates) of Types.Bits_8
:= (Data_Rate_110k => 64,
Data_Rate_850k => 16,
Data_Rate_6M8 => 8);
-------------------------
-- Load_LDE_From_ROM --
-------------------------
procedure Load_LDE_From_ROM is
use type Ada.Real_Time.Time;
Finish_Time : Ada.Real_Time.Time;
Now : Ada.Real_Time.Time;
PMSC_CTRL0_Reg : Register_Types.PMSC_CTRL0_Type;
begin
-- Set up clocks
PMSC_CTRL0.Read (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.SYSCLKS := Force_XTI;
PMSC_CTRL0_Reg.RXCLKS := Auto;
PMSC_CTRL0_Reg.TXCLKS := Auto;
PMSC_CTRL0_Reg.FACE := Disabled;
PMSC_CTRL0_Reg.ADCCE := Disabled;
PMSC_CTRL0_Reg.Reserved_1 := 2#110#;
-- Writing to these Reserved bits is undocumented in the User Manual,
-- but the DecaWave C code sets these bits, so it serves some purpose.
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
-- Kick off the NV MEM load
OTP_CTRL.Write ((OTPRDEN => Disabled,
OTPREAD => No_Action,
OTPMRWR => Clear,
OTPPROG => Clear,
OTPMR => Clear,
LDELOAD => Load_LDE_Microcode,
Reserved_1 => 0,
Reserved_2 => 0,
Reserved_3 => 0));
-- Code upload takes up to 150 us
-- A busy wait is used here to prevent blocking the calling task.
-- This permits calling this function from a protected object.
pragma Warnings (GNATprove, Off, "unused assignment",
Reason => "Assignment used for non-blocking delay");
Finish_Time := Ada.Real_Time.Clock;
Finish_Time := Finish_Time + Ada.Real_Time.Microseconds (150);
loop
Now := Ada.Real_Time.Clock;
pragma Warnings (GNATprove, Off, "statement has no effect",
Reason => "delay required for LDE code load");
exit when Now >= Finish_Time;
end loop;
pragma Warnings (GNATprove, On, "unused assignment");
pragma Warnings (GNATprove, On, "statement has no effect");
-- Default clocks
PMSC_CTRL0_Reg.SYSCLKS := Auto;
PMSC_CTRL0_Reg.Reserved_1 := 2#100#;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
end Load_LDE_From_ROM;
---------------------
-- Enable_Clocks --
---------------------
procedure Enable_Clocks (Clock : in Clocks) is
PMSC_CTRL0_Reg : PMSC_CTRL0_Type;
begin
PMSC_CTRL0.Read (PMSC_CTRL0_Reg);
case Clock is
when Enable_All_Seq =>
PMSC_CTRL0_Reg.SYSCLKS := Auto;
PMSC_CTRL0_Reg.RXCLKS := Auto;
PMSC_CTRL0_Reg.TXCLKS := Auto;
PMSC_CTRL0_Reg.FACE := Disabled;
-- Need to write the above changes before setting GPCE
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.Reserved_1 := PMSC_CTRL0_Reg.Reserved_1 and 2#100#;
-- Writing to the reserved bits is undocumented in the User Manual
-- but the DecaWave C code masks these bits.
when Force_Sys_XTI =>
PMSC_CTRL0_Reg.SYSCLKS := Force_XTI;
when Force_Sys_PLL =>
PMSC_CTRL0_Reg.SYSCLKS := Force_PLL;
when Read_Acc_On =>
PMSC_CTRL0_Reg.RXCLKS := Force_PLL;
PMSC_CTRL0_Reg.FACE := Enabled;
-- Need to write the above changes before setting SOFTRESET
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.SOFTRESET := PMSC_CTRL0_Reg.SOFTRESET or 2#1000#;
when Read_Acc_Off =>
PMSC_CTRL0_Reg.RXCLKS := Auto;
PMSC_CTRL0_Reg.FACE := Disabled;
-- Need to write the above changes before clearing SOFTRESET
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.SOFTRESET := PMSC_CTRL0_Reg.SOFTRESET and 2#0111#;
when Force_OTP_On =>
PMSC_CTRL0_Reg.Reserved_1 := PMSC_CTRL0_Reg.Reserved_1 or 2#100#;
when Force_OTP_Off =>
PMSC_CTRL0_Reg.Reserved_1 := PMSC_CTRL0_Reg.Reserved_1 and 2#011#;
when Force_Tx_PLL =>
PMSC_CTRL0_Reg.TXCLKS := Force_PLL;
end case;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
end Enable_Clocks;
----------------
-- Read_OTP --
----------------
procedure Read_OTP (Address : in OTP_ADDR_Field;
Word : out Bits_32) is
CTRL_Reg : OTP_CTRL_Type;
RDAT_Reg : OTP_RDAT_Type;
begin
-- Set OTP address to read
OTP_ADDR.Write ((OTP_ADDR => Address, others => <>));
-- Trigger OTP read
CTRL_Reg := (OTPRDEN => Enabled,
OTPREAD => Trigger_Read,
OTPMRWR => Clear,
OTPPROG => Clear,
OTPMR => Clear,
LDELOAD => No_Action,
Reserved_1 => 0,
Reserved_2 => 0,
Reserved_3 => 0);
OTP_CTRL.Write (CTRL_Reg);
-- OTPRDEN is not self-clearing. Also clear OPTREAD
CTRL_Reg.OTPRDEN := Disabled;
CTRL_Reg.OTPREAD := No_Action;
OTP_CTRL.Write (CTRL_Reg);
-- Read back the OTP word
OTP_RDAT.Read (RDAT_Reg);
Word := RDAT_Reg.OTP_RDAT;
end Read_OTP;
-----------------
-- Read_EUID --
-----------------
procedure Read_EUID (EUID : out Bits_64) is
EUI_Reg : EUI_Type;
begin
EUI.Read (EUI_Reg);
EUID := EUI_Reg.EUI;
end Read_EUID;
------------------
-- Write_EUID --
------------------
procedure Write_EUID (EUID : in Bits_64) is
begin
EUI.Write ((EUI => EUID));
end Write_EUID;
-------------------
-- Read_PAN_ID --
-------------------
procedure Read_PAN_ID (PAN_ID : out Bits_16) is
PANADR_Reg : PANADR_Type;
begin
PANADR.Read (PANADR_Reg);
PAN_ID := PANADR_Reg.PAN_ID;
end Read_PAN_ID;
--------------------
-- Write_PAN_ID --
--------------------
procedure Write_PAN_ID (PAN_ID : in Bits_16) is
PANADR_Reg : PANADR_Type;
begin
PANADR.Read (PANADR_Reg);
PANADR_Reg.PAN_ID := PAN_ID;
PANADR.Write (PANADR_Reg);
end Write_PAN_ID;
--------------------------
-- Read_Short_Address --
--------------------------
procedure Read_Short_Address (Short_Address : out Bits_16) is
PANADR_Reg : PANADR_Type;
begin
PANADR.Read (PANADR_Reg);
Short_Address := PANADR_Reg.SHORT_ADDR;
end Read_Short_Address;
---------------------------
-- Write_Short_Address --
---------------------------
procedure Write_Short_Address (Short_Address : in Bits_16) is
PANADR_Reg : PANADR_Type;
begin
PANADR.Read (PANADR_Reg);
PANADR_Reg.SHORT_ADDR := Short_Address;
PANADR.Write (PANADR_Reg);
end Write_Short_Address;
-------------------------------------
-- Read_PAN_ID_And_Short_Address --
-------------------------------------
procedure Read_PAN_ID_And_Short_Address (PAN_ID : out Bits_16;
Short_Address : out Bits_16) is
PANADR_Reg : PANADR_Type;
begin
PANADR.Read (PANADR_Reg);
PAN_ID := PANADR_Reg.PAN_ID;
Short_Address := PANADR_Reg.SHORT_ADDR;
end Read_PAN_ID_And_Short_Address;
--------------------------------------
-- Write_PAN_ID_And_Short_Address --
--------------------------------------
procedure Write_PAN_ID_And_Short_Address (PAN_ID : in Bits_16;
Short_Address : in Bits_16) is
begin
PANADR.Write ((PAN_ID => PAN_ID,
SHORT_ADDR => Short_Address));
end Write_PAN_ID_And_Short_Address;
-----------------------------
-- Read_Tx_Antenna_Delay --
-----------------------------
procedure Read_Tx_Antenna_Delay (Antenna_Delay : out Antenna_Delay_Time) is
TX_ANTD_Reg : TX_ANTD_Type;
begin
TX_ANTD.Read (TX_ANTD_Reg);
Antenna_Delay := TX_ANTD_Reg.TX_ANTD;
end Read_Tx_Antenna_Delay;
------------------------------
-- Write_Tx_Antenna_Delay --
------------------------------
procedure Write_Tx_Antenna_Delay (Antenna_Delay : in Antenna_Delay_Time) is
begin
TX_ANTD.Write ((TX_ANTD => Antenna_Delay));
end Write_Tx_Antenna_Delay;
-----------------------------
-- Read_Rx_Antenna_Delay --
-----------------------------
procedure Read_Rx_Antenna_Delay (Antenna_Delay : out Antenna_Delay_Time) is
LDE_RXANTD_Reg : LDE_RXANTD_Type;
begin
LDE_RXANTD.Read (LDE_RXANTD_Reg);
Antenna_Delay := LDE_RXANTD_Reg.LDE_RXANTD;
end Read_Rx_Antenna_Delay;
------------------------------
-- Write_Rx_Antenna_Delay --
------------------------------
procedure Write_Rx_Antenna_Delay (Antenna_Delay : in Antenna_Delay_Time) is
begin
LDE_RXANTD.Write ((LDE_RXANTD => Antenna_Delay));
end Write_Rx_Antenna_Delay;
---------------------
-- Configure_LDE --
---------------------
procedure Configure_LDE (PRF : in PRF_Type;
Rx_Preamble_Code : in Preamble_Code_Number;
Data_Rate : in Data_Rates) is
REPC_Coeff : LDE_REPC_Field;
begin
LDE_CFG1.Write (LDE_CFG1_Value);
LDE_CFG2.Write ((LDE_CFG2 => LDE_CFG2_Values (PRF)));
REPC_Coeff := LDE_Replica_Coeffs (Rx_Preamble_Code);
if Data_Rate = Data_Rate_110k then
-- 110 k data rate has special handling
LDE_REPC.Write ((LDE_REPC => REPC_Coeff / 8));
else
LDE_REPC.Write ((LDE_REPC => REPC_Coeff));
end if;
end Configure_LDE;
---------------------
-- Configure_PLL --
---------------------
procedure Configure_PLL (Channel : in Channel_Number) is
begin
FS_PLLCFG.Write ((FS_PLLCFG => FS_PLLCFG_Values (Positive (Channel))));
FS_PLLTUNE.Write ((FS_PLLTUNE => FS_PLLTUNE_Values (Positive (Channel))));
FS_XTALT.Write (FS_XTALT_Value);
end Configure_PLL;
--------------------
-- Configure_RF --
--------------------
procedure Configure_RF (Channel : in Channel_Number) is
begin
RF_RXCTRLH.Write ((RF_RXCTRLH => RF_RXCTRLH_Values (Positive (Channel))));
RF_TXCTRL.Write ((RF_TXCTRL => RF_TXCTRL_Values (Positive (Channel))));
end Configure_RF;
---------------------
-- Configure_DRX --
---------------------
procedure Configure_DRX (PRF : in PRF_Type;
Data_Rate : in Data_Rates;
Tx_Preamble_Length : in Preamble_Lengths;
PAC : in Preamble_Acq_Chunk_Length;
SFD_Timeout : in SFD_Timeout_Number;
Nonstandard_SFD : in Boolean) is
begin
DRX_TUNE0b.Write ((DRX_TUNE0b => DRX_TUNE0b_Values (Data_Rate,
Nonstandard_SFD)));
DRX_TUNE1a.Write ((DRX_TUNE1a => DRX_TUNE1a_Values (PRF)));
if Data_Rate = Data_Rate_110k then
DRX_TUNE1b.Write ((DRX_TUNE1b => DRX_TUNE1b_110K));
elsif Tx_Preamble_Length = PLEN_64 then
DRX_TUNE1b.Write ((DRX_TUNE1b => DRX_TUNE1b_6M8));
DRX_TUNE4H.Write ((DRX_TUNE4H => DRX_TUNE4H_Preamble_64));
else
DRX_TUNE1b.Write ((DRX_TUNE1b => DRX_TUNE1b_850K_6M8));
DRX_TUNE4H.Write ((DRX_TUNE4H => DRX_TUNE4H_Others));
end if;
DRX_TUNE2.Write ((DRX_TUNE2 => DRX_TUNE2_Values (PAC, PRF)));
DRX_SFDTOC.Write ((DRX_SFDTOC => DRX_SFDTOC_Field (SFD_Timeout)));
end Configure_DRX;
---------------------
-- Configure_AGC --
---------------------
procedure Configure_AGC (PRF : in PRF_Type) is
begin
AGC_TUNE2.Write ((AGC_TUNE2 => AGC_TUNE2_Value));
AGC_TUNE1.Write ((AGC_TUNE1 => AGC_TUNE1_Values (PRF)));
AGC_TUNE3.Write ((AGC_TUNE3 => AGC_TUNE3_Value));
end Configure_AGC;
--------------------
-- Configure_TC --
--------------------
procedure Configure_TC (Channel : in Channel_Number) is
begin
TC_PGDELAY.Write
((TC_PGDELAY => TC_PGDELAY_Values (Positive (Channel))));
end Configure_TC;
--------------------------
-- Configure_TX_FCTRL --
--------------------------
procedure Configure_TX_FCTRL (Frame_Length : in Natural;
Tx_Data_Rate : in Data_Rates;
Tx_PRF : in PRF_Type;
Ranging : in Boolean;
Preamble_Length : in Preamble_Lengths;
Tx_Buffer_Offset : in Natural;
Inter_Frame_Spacing : in Natural) is
begin
TX_FCTRL.Write
((TFLEN => TX_FCTRL_TFLEN_Field (Frame_Length mod 128),
TFLE => TX_FCTRL_TFLE_Field (Frame_Length / 128),
R => 0,
TXBR => (case Tx_Data_Rate is
when Data_Rate_110k => Data_Rate_110K,
when Data_Rate_850k => Data_Rate_850K,
when Data_Rate_6M8 => Data_Rate_6M8),
TR => (if Ranging then Enabled else Disabled),
TXPRF => (if Tx_PRF = PRF_16MHz
then PRF_16MHz else PRF_64MHz),
TXPSR =>
(case Preamble_Length is
when PLEN_64 | PLEN_128 | PLEN_256 | PLEN_512 => PLEN_64,
when PLEN_1024 | PLEN_1536 | PLEN_2048 => PLEN_1024,
when others => PLEN_4096),
PE =>
(case Preamble_Length is
when PLEN_64 | PLEN_1024 | PLEN_4096 => 2#00#,
when PLEN_128 | PLEN_1536 => 2#01#,
when PLEN_256 | PLEN_2048 => 2#10#,
when others => 2#11#),
TXBOFFS => TX_FCTRL_TXBOFFS_Field (Tx_Buffer_Offset),
IFSDELAY => TX_FCTRL_IFSDELAY_Field (Inter_Frame_Spacing)));
end Configure_TX_FCTRL;
---------------------------
-- Configure_CHAN_CTRL --
---------------------------
procedure Configure_CHAN_CTRL
(Tx_Channel : in Channel_Number;
Rx_Channel : in Channel_Number;
Use_DecaWave_SFD : in Boolean;
Use_Tx_User_Defined_SFD : in Boolean;
Use_Rx_User_Defined_SFD : in Boolean;
Rx_PRF : in PRF_Type;
Tx_Preamble_Code : in Preamble_Code_Number;
Rx_Preamble_Code : in Preamble_Code_Number) is
begin
CHAN_CTRL.Write ((TX_CHAN => CHAN_CTRL_Channel_Field (Tx_Channel),
RX_CHAN => CHAN_CTRL_Channel_Field (Rx_Channel),
DWSFD => (if Use_DecaWave_SFD
then Enabled
else Disabled),
RXPRF => (if Rx_PRF = PRF_16MHz
then PRF_16MHz else PRF_64MHz),
TNSSFD => (if Use_Tx_User_Defined_SFD
then Enabled
else Disabled),
RNSSFD => (if Use_Rx_User_Defined_SFD
then Enabled
else Disabled),
TX_PCODE => CHAN_CTRL_PCODE_Field (Tx_Preamble_Code),
RX_PCODE => CHAN_CTRL_PCODE_Field (Rx_Preamble_Code),
Reserved => 0));
end Configure_CHAN_CTRL;
----------------------------------------
-- Configure_Nonstandard_SFD_Length --
----------------------------------------
procedure Configure_Nonstandard_SFD_Length (Data_Rate : in Data_Rates) is
USR_SFD_Reg : Register_Types.USR_SFD_Type;
begin
USR_SFD.Read (USR_SFD_Reg);
USR_SFD_Reg.Sub_Registers (0) := Non_Standard_SFD_Lengths (Data_Rate);
USR_SFD.Write (USR_SFD_Reg);
end Configure_Nonstandard_SFD_Length;
----------------------------------
-- Configure_Non_Standard_SFD --
----------------------------------
procedure Configure_Non_Standard_SFD (Rx_SFD : in String;
Tx_SFD : in String) is
-- Takes a string of up to 8 SFD symbols and compute the value of one
-- of the USR_SFD register's magnitude sub-registers (8 bits).
function Magnitude (SFD : in String) return Types.Bits_8
with Pre =>
(SFD'Length in 1 .. 8
and (for all I in SFD'Range => SFD (I) in '+' | '-' | '0'));
function Polarity (SFD : in String) return Types.Bits_8
with Pre =>
(SFD'Length in 1 .. 8
and (for all I in SFD'Range => SFD (I) in '+' | '-' | '0'));
-----------------
-- Magnitude --
-----------------
function Magnitude (SFD : in String) return Types.Bits_8 is
Result : Bits_8 := 0;
begin
for I in Natural range 0 .. SFD'Length - 1 loop
if SFD (SFD'First + I) /= '0' then
Result := Result or Shift_Left (Bits_8 (1), I);
end if;
end loop;
return Result;
end Magnitude;
----------------
-- Polarity --
----------------
function Polarity (SFD : in String) return Types.Bits_8 is
Result : Bits_8 := 0;
begin
for I in Natural range 0 .. SFD'Length - 1 loop
if SFD (SFD'First + I) = '-' then
Result := Result or Shift_Left (Bits_8 (1), I);
end if;
end loop;
return Result;
end Polarity;
USR_SFD_Reg : USR_SFD_Type;
begin
if Tx_SFD'Length = 8 then
USR_SFD_Reg.Sub_Registers :=
(0 => Bits_8 (Tx_SFD'Length),
1 => Magnitude (Tx_SFD),
3 => Polarity (Tx_SFD),
5 => Magnitude (Rx_SFD),
7 => Polarity (Rx_SFD),
others => 0);
elsif Tx_SFD'Length <= 16 then
USR_SFD_Reg.Sub_Registers :=
(0 => Bits_8 (Tx_SFD'Length),
1 => Magnitude (Tx_SFD (Tx_SFD'First .. Tx_SFD'First + 7)),
2 => Magnitude (Tx_SFD (Tx_SFD'First + 8 .. Tx_SFD'Last)),
3 => Polarity (Tx_SFD (Tx_SFD'First .. Tx_SFD'First + 7)),
4 => Polarity (Tx_SFD (Tx_SFD'First + 8 .. Tx_SFD'Last)),
5 => Magnitude (Rx_SFD (Rx_SFD'First .. Rx_SFD'First + 7)),
6 => Magnitude (Rx_SFD (Rx_SFD'First + 8 .. Rx_SFD'Last)),
7 => Polarity (Rx_SFD (Rx_SFD'First .. Rx_SFD'First + 7)),
8 => Polarity (Rx_SFD (Rx_SFD'First + 8 .. Rx_SFD'Last)),
others => 0);
else
USR_SFD_Reg.Sub_Registers :=
(0 => Bits_8 (Tx_SFD'Length),
9 => Magnitude (Tx_SFD (Tx_SFD'First .. Tx_SFD'First + 7)),
10 => Magnitude (Tx_SFD (Tx_SFD'First + 8 .. Tx_SFD'First + 15)),
11 => Magnitude (Tx_SFD (Tx_SFD'First + 16 .. Tx_SFD'First + 23)),
12 => Magnitude (Tx_SFD (Tx_SFD'First + 24 .. Tx_SFD'First + 31)),
13 => Magnitude (Tx_SFD (Tx_SFD'First + 32 .. Tx_SFD'First + 39)),
14 => Magnitude (Tx_SFD (Tx_SFD'First + 40 .. Tx_SFD'First + 47)),
15 => Magnitude (Tx_SFD (Tx_SFD'First + 48 .. Tx_SFD'First + 55)),
16 => Magnitude (Tx_SFD (Tx_SFD'First + 56 .. Tx_SFD'Last)),
17 => Polarity (Tx_SFD (Tx_SFD'First .. Tx_SFD'First + 7)),
18 => Polarity (Tx_SFD (Tx_SFD'First + 8 .. Tx_SFD'First + 15)),
19 => Polarity (Tx_SFD (Tx_SFD'First + 16 .. Tx_SFD'First + 23)),
20 => Polarity (Tx_SFD (Tx_SFD'First + 24 .. Tx_SFD'First + 31)),
21 => Polarity (Tx_SFD (Tx_SFD'First + 32 .. Tx_SFD'First + 39)),
22 => Polarity (Tx_SFD (Tx_SFD'First + 40 .. Tx_SFD'First + 47)),
23 => Polarity (Tx_SFD (Tx_SFD'First + 48 .. Tx_SFD'First + 55)),
24 => Polarity (Tx_SFD (Tx_SFD'First + 56 .. Tx_SFD'Last)),
25 => Magnitude (Rx_SFD (Rx_SFD'First .. Rx_SFD'First + 7)),
26 => Magnitude (Rx_SFD (Rx_SFD'First + 8 .. Rx_SFD'First + 15)),
27 => Magnitude (Rx_SFD (Rx_SFD'First + 16 .. Rx_SFD'First + 23)),
28 => Magnitude (Rx_SFD (Rx_SFD'First + 24 .. Rx_SFD'First + 31)),
29 => Magnitude (Rx_SFD (Rx_SFD'First + 32 .. Rx_SFD'First + 39)),
30 => Magnitude (Rx_SFD (Rx_SFD'First + 40 .. Rx_SFD'First + 47)),
31 => Magnitude (Rx_SFD (Rx_SFD'First + 48 .. Rx_SFD'First + 55)),
32 => Magnitude (Rx_SFD (Rx_SFD'First + 56 .. Rx_SFD'Last)),
33 => Polarity (Rx_SFD (Rx_SFD'First .. Rx_SFD'First + 7)),
34 => Polarity (Rx_SFD (Rx_SFD'First + 8 .. Rx_SFD'First + 15)),
35 => Polarity (Rx_SFD (Rx_SFD'First + 16 .. Rx_SFD'First + 23)),
36 => Polarity (Rx_SFD (Rx_SFD'First + 24 .. Rx_SFD'First + 31)),
37 => Polarity (Rx_SFD (Rx_SFD'First + 32 .. Rx_SFD'First + 39)),
38 => Polarity (Rx_SFD (Rx_SFD'First + 40 .. Rx_SFD'First + 47)),
39 => Polarity (Rx_SFD (Rx_SFD'First + 48 .. Rx_SFD'First + 55)),
40 => Polarity (Rx_SFD (Rx_SFD'First + 56 .. Rx_SFD'Last)),
others => 0);
end if;
USR_SFD.Write (USR_SFD_Reg);
end Configure_Non_Standard_SFD;
-----------------------------------
-- Set_Frame_Filtering_Enabled --
-----------------------------------
procedure Set_Frame_Filtering_Enabled (Enable : in Boolean) is
SYS_CFG_Reg : SYS_CFG_Type;
begin
SYS_CFG.Read (SYS_CFG_Reg);
SYS_CFG_Reg.FFEN := (if Enable then Enabled else Disabled);
SYS_CFG.Write (SYS_CFG_Reg);
end Set_Frame_Filtering_Enabled;
-----------------------------
-- Set_FCS_Check_Enabled --
-----------------------------
procedure Set_FCS_Check_Enabled (Enable : in Boolean) is
SYS_CFG_Reg : SYS_CFG_Type;
begin
SYS_CFG.Read (SYS_CFG_Reg);
SYS_CFG_Reg.DIS_FCE := (if Enable then Not_Disabled else Disabled);
SYS_CFG.Write (SYS_CFG_Reg);
end Set_FCS_Check_Enabled;
---------------------------------
-- Configure_Frame_Filtering --
---------------------------------
procedure Configure_Frame_Filtering (Behave_As_Coordinator : in Boolean;
Allow_Beacon_Frame : in Boolean;
Allow_Data_Frame : in Boolean;
Allow_Ack_Frame : in Boolean;
Allow_MAC_Cmd_Frame : in Boolean;
Allow_Reserved_Frame : in Boolean;
Allow_Frame_Type_4 : in Boolean;
Allow_Frame_Type_5 : in Boolean) is
SYS_CFG_Reg : SYS_CFG_Type;
begin
SYS_CFG.Read (SYS_CFG_Reg);
SYS_CFG_Reg.FFBC := (if Behave_As_Coordinator then Enabled else Disabled);
SYS_CFG_Reg.FFAB := (if Allow_Beacon_Frame then Allowed else Not_Allowed);
SYS_CFG_Reg.FFAD := (if Allow_Data_Frame then Allowed else Not_Allowed);
SYS_CFG_Reg.FFAA := (if Allow_Ack_Frame then Allowed else Not_Allowed);
SYS_CFG_Reg.FFAM := (if Allow_MAC_Cmd_Frame then Allowed else Not_Allowed);
SYS_CFG_Reg.FFAR := (if Allow_Reserved_Frame then Allowed else Not_Allowed);
SYS_CFG_Reg.FFA4 := (if Allow_Frame_Type_4 then Allowed else Not_Allowed);
SYS_CFG_Reg.FFA5 := (if Allow_Frame_Type_5 then Allowed else Not_Allowed);
SYS_CFG.Write (SYS_CFG_Reg);
end Configure_Frame_Filtering;
--------------------------
-- Set_Smart_Tx_Power --
--------------------------
procedure Set_Smart_Tx_Power (Enable : in Boolean) is
SYS_CFG_Reg : SYS_CFG_Type;
begin
SYS_CFG.Read (SYS_CFG_Reg);
SYS_CFG_Reg.DIS_STXP := (if Enable then Not_Disabled else Disabled);
SYS_CFG.Write (SYS_CFG_Reg);
end Set_Smart_Tx_Power;
-------------------------------
-- Read_OTP_Tx_Power_Level --
-------------------------------
procedure Read_OTP_Tx_Power_Level (Channel : in Channel_Number;
PRF : in PRF_Type;
Power_Level : out TX_POWER_Type) is
Address : OTP_ADDR_Field;
Word : Bits_32;
function Word_To_TX_POWER is new Ada.Unchecked_Conversion
(Source => Bits_32,
Target => TX_POWER_Type);
begin
case Channel is
when 1 => Address := OTP_ADDR_CH1_TX_POWER_PRF_64;
when 2 => Address := OTP_ADDR_CH2_TX_POWER_PRF_64;
when 3 => Address := OTP_ADDR_CH3_TX_POWER_PRF_64;
when 4 => Address := OTP_ADDR_CH4_TX_POWER_PRF_64;
when 5 => Address := OTP_ADDR_CH5_TX_POWER_PRF_64;
when 7 => Address := OTP_ADDR_CH7_TX_POWER_PRF_64;
end case;
if PRF = PRF_64MHz then
Address := Address + 1;
end if;
Read_OTP (Address => Address,
Word => Word);
Power_Level := Word_To_TX_POWER (Word);
end Read_OTP_Tx_Power_Level;
------------------------------
-- Read_OTP_Antenna_Delay --
------------------------------
procedure Read_OTP_Antenna_Delay
(Antenna_Delay_16_MHz : out Antenna_Delay_Time;
Antenna_Delay_64_MHz : out Antenna_Delay_Time) is
Word : Bits_32;
Lo : Bits_16;
Hi : Bits_16;
begin
Read_OTP (Address => OTP_ADDR_ANTENNA_DELAY,
Word => Word);
Lo := Bits_16 (Word and 16#FFFF#);
Hi := Bits_16 (Shift_Right (Word, 16) and 16#FFFF#);
Antenna_Delay_16_MHz := To_Antenna_Delay_Time (Lo);
Antenna_Delay_64_MHz := To_Antenna_Delay_Time (Hi);
end Read_OTP_Antenna_Delay;
--------------------------
-- Configure_Tx_Power --
--------------------------
procedure Configure_Tx_Power (Config : Tx_Power_Config_Type) is
SYS_CFG_Reg : SYS_CFG_Type;
begin
if Config.Smart_Tx_Power_Enabled then
TX_POWER.Write ((BOOSTNORM => Config.Boost_Normal,
BOOSTP500 => Config.Boost_500us,
BOOSTP250 => Config.Boost_250us,
BOOSTP125 => Config.Boost_125us));
else
TX_POWER.Write ((BOOSTNORM => Config.Boost_PHR,
BOOSTP500 => Config.Boost_PHR,
BOOSTP250 => Config.Boost_SHR,
BOOSTP125 => Config.Boost_SHR));
end if;
SYS_CFG.Read (SYS_CFG_Reg);
SYS_CFG_Reg.DIS_STXP := (if Config.Smart_Tx_Power_Enabled
then Not_Disabled
else Disabled);
SYS_CFG.Write (SYS_CFG_Reg);
end Configure_Tx_Power;
-------------------
-- Set_Tx_Data --
-------------------
procedure Set_Tx_Data (Data : in Types.Byte_Array;
Offset : in Natural) is
begin
if Data'Length > 0 then
DW1000.Register_Driver.Write_Register
(Register_ID => Registers.TX_BUFFER_Reg_ID,
Sub_Address => Types.Bits_15 (Offset),
Data => Data);
end if;
end Set_Tx_Data;
---------------------------
-- Set_Tx_Frame_Length --
---------------------------
procedure Set_Tx_Frame_Length (Length : in Natural;
Offset : in Natural) is
TX_FCTRL_Reg : TX_FCTRL_Type;
begin
TX_FCTRL.Read (TX_FCTRL_Reg);
TX_FCTRL_Reg.TFLEN := TX_FCTRL_TFLEN_Field (Length mod 2**7);
TX_FCTRL_Reg.TFLE := TX_FCTRL_TFLE_Field (Length / 2**7);
TX_FCTRL_Reg.TXBOFFS := TX_FCTRL_TXBOFFS_Field (Offset);
TX_FCTRL.Write (TX_FCTRL_Reg);
end Set_Tx_Frame_Length;
--------------------------
-- Start_Tx_Immediate --
--------------------------
procedure Start_Tx_Immediate (Rx_After_Tx : in Boolean;
Auto_Append_FCS : in Boolean) is
SYS_CTRL_Reg : SYS_CTRL_Type;
begin
SYS_CTRL_Reg := (SFCST => (if Auto_Append_FCS
then Not_Suppressed
else Suppressed),
TXSTRT => Start_Tx,
TXDLYS => Not_Delayed,
CANSFCS => Not_Cancelled,
TRXOFF => No_Action,
WAIT4RESP => (if Rx_After_Tx then Wait else No_Wait),
RXENAB => No_Action,
RXDLYE => Not_Delayed,
HRBPT => No_Action,
Reserved_1 => 0,
Reserved_2 => 0,
Reserved_3 => 0);
SYS_CTRL.Write (SYS_CTRL_Reg);
end Start_Tx_Immediate;
------------------------
-- Start_Tx_Delayed --
------------------------
procedure Start_Tx_Delayed (Rx_After_Tx : in Boolean;
Result : out Result_Type) is
SYS_CTRL_Reg : SYS_CTRL_Type;
SYS_STATUS_Reg : SYS_STATUS_Type;
begin
SYS_CTRL_Reg := (SFCST => Not_Suppressed,
TXSTRT => Start_Tx,
TXDLYS => Delayed,
CANSFCS => Not_Cancelled,
TRXOFF => No_Action,
WAIT4RESP => (if Rx_After_Tx then Wait else No_Wait),
RXENAB => No_Action,
RXDLYE => Not_Delayed,
HRBPT => No_Action,
Reserved_1 => 0,
Reserved_2 => 0,
Reserved_3 => 0);
SYS_CTRL.Write (SYS_CTRL_Reg);
SYS_STATUS.Read (SYS_STATUS_Reg);
if SYS_STATUS_Reg.HPDWARN = 0 then
Result := Success;
else
-- Cancel the transmit
SYS_CTRL_Reg := (SFCST => Not_Suppressed,
TXSTRT => No_Action,
TXDLYS => Not_Delayed,
CANSFCS => Not_Cancelled,
TRXOFF => Transceiver_Off,
WAIT4RESP => No_Wait,
RXENAB => No_Action,
RXDLYE => Not_Delayed,
HRBPT => No_Action,
Reserved_1 => 0,
Reserved_2 => 0,
Reserved_3 => 0);
SYS_CTRL.Write (SYS_CTRL_Reg);
Set_Sleep_After_Tx (Enable => False);
Result := Error;
end if;
end Start_Tx_Delayed;
--------------------
-- Read_Rx_Data --
--------------------
procedure Read_Rx_Data (Data : out Types.Byte_Array;
Offset : in Natural) is
begin
DW1000.Register_Driver.Read_Register
(Register_ID => Registers.RX_BUFFER_Reg_ID,
Sub_Address => Types.Bits_15 (Offset),
Data => Data);
end Read_Rx_Data;
------------------------------
-- Set_Delayed_Tx_Rx_Time --
------------------------------
procedure Set_Delayed_Tx_Rx_Time (Delay_Time : in Coarse_System_Time) is
begin
DX_TIME.Write ((DX_TIME => Delay_Time));
end Set_Delayed_Tx_Rx_Time;
--------------------------
-- Set_Sleep_After_Tx --
--------------------------
procedure Set_Sleep_After_Tx (Enable : in Boolean) is
PMSC_CTRL1_Reg : PMSC_CTRL1_Type;
begin
PMSC_CTRL1.Read (PMSC_CTRL1_Reg);
PMSC_CTRL1_Reg.ATXSLP := (if Enable then Enabled else Disabled);
PMSC_CTRL1.Write (PMSC_CTRL1_Reg);
end Set_Sleep_After_Tx;
----------------------------------
-- Read_Rx_Adjusted_Timestamp --
----------------------------------
procedure Read_Rx_Adjusted_Timestamp (Timestamp : out Fine_System_Time) is
RX_TIME_Reg : RX_TIME_Type;
begin
RX_TIME.Read (RX_TIME_Reg);
Timestamp := RX_TIME_Reg.RX_STAMP;
end Read_Rx_Adjusted_Timestamp;
-----------------------------
-- Read_Rx_Raw_Timestamp --
-----------------------------
procedure Read_Rx_Raw_Timestamp (Timestamp : out Coarse_System_Time) is
RX_TIME_Reg : RX_TIME_Type;
begin
RX_TIME.Read (RX_TIME_Reg);
Timestamp := RX_TIME_Reg.RX_RAWST;
end Read_Rx_Raw_Timestamp;
--------------------------
-- Read_Rx_Timestamps --
--------------------------
procedure Read_Rx_Timestamps (Adjusted : out Fine_System_Time;
Raw : out Coarse_System_Time) is
RX_TIME_Reg : RX_TIME_Type;
begin
RX_TIME.Read (RX_TIME_Reg);
Adjusted := RX_TIME_Reg.RX_STAMP;
Raw := RX_TIME_Reg.RX_RAWST;
end Read_Rx_Timestamps;
----------------------------------
-- Read_Tx_Adjusted_Timestamp --
----------------------------------
procedure Read_Tx_Adjusted_Timestamp (Timestamp : out Fine_System_Time) is
TX_TIME_Reg : TX_TIME_Type;
begin
TX_TIME.Read (TX_TIME_Reg);
Timestamp := TX_TIME_Reg.TX_STAMP;
end Read_Tx_Adjusted_Timestamp;
-----------------------------
-- Read_Tx_Raw_Timestamp --
-----------------------------
procedure Read_Tx_Raw_Timestamp (Timestamp : out Coarse_System_Time) is
TX_TIME_Reg : TX_TIME_Type;
begin
TX_TIME.Read (TX_TIME_Reg);
Timestamp := TX_TIME_Reg.TX_RAWST;
end Read_Tx_Raw_Timestamp;
--------------------------
-- Read_Tx_Timestamps --
--------------------------
procedure Read_Tx_Timestamps (Adjusted : out Fine_System_Time;
Raw : out Coarse_System_Time) is
TX_TIME_Reg : TX_TIME_Type;
begin
TX_TIME.Read (TX_TIME_Reg);
Adjusted := TX_TIME_Reg.TX_STAMP;
Raw := TX_TIME_Reg.TX_RAWST;
end Read_Tx_Timestamps;
-----------------------------
-- Read_System_Timestamp --
-----------------------------
procedure Read_System_Timestamp (Timestamp : out Coarse_System_Time) is
SYS_TIME_Reg : SYS_TIME_Type;
begin
SYS_TIME.Read (SYS_TIME_Reg);
Timestamp := SYS_TIME_Reg.SYS_TIME;
end Read_System_Timestamp;
---------------------
-- Check_Overrun --
---------------------
procedure Check_Overrun (Overrun : out Boolean) is
SYS_STATUS_Reg : SYS_STATUS_Type;
begin
SYS_STATUS.Read (SYS_STATUS_Reg);
Overrun := SYS_STATUS_Reg.RXOVRR = 1;
end Check_Overrun;
-----------------------
-- Force_Tx_Rx_Off --
-----------------------
procedure Force_Tx_Rx_Off is
SYS_MASK_Reg : SYS_MASK_Type;
begin
-- Temporarily disable all interrupts
SYS_MASK.Read (SYS_MASK_Reg);
SYS_MASK.Write ((others => <>));
-- Force transceiver off;
SYS_CTRL.Write ((TRXOFF => Transceiver_Off, others => <>));
-- Clear any pending events.
SYS_STATUS.Write ((AAT => 1,
TXFRB => 1,
TXPRS => 1,
TXPHS => 1,
TXFRS => 1,
RXPRD => 1,
RXSFDD => 1,
LDEDONE => 1,
RXPHD => 1,
RXPHE => 1,
RXDFR => 1,
RXFCG => 1,
RXFCE => 1,
RXRFSL => 1,
RXRFTO => 1,
LDEERR => 1,
RXPTO => 1,
RXSFDTO => 1,
AFFREJ => 1,
Reserved_1 => 0,
Reserved_2 => 0,
others => 0));
Sync_Rx_Buffer_Pointers;
-- Restore previous interrupt settings.
SYS_MASK.Write (SYS_MASK_Reg);
end Force_Tx_Rx_Off;
----------------
-- Reset_Rx --
----------------
procedure Reset_Rx is
PMSC_CTRL0_Reg : PMSC_CTRL0_Type;
begin
-- Initiate a soft reset of the receiver only.
-- The DW1000 User Manual, Section 7.2.50.1, for the SOFTRESET bits
-- states "To apply a receiver-only soft reset, clear and set bit 28
-- only."
PMSC_CTRL0.Read (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.SOFTRESET := 2#1110#;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.SOFTRESET := 2#1111#;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
end Reset_Rx;
------------------------------------------
-- Toggle_Host_Side_Rx_Buffer_Pointer --
------------------------------------------
procedure Toggle_Host_Side_Rx_Buffer_Pointer is
SYS_CTRL_Reg : SYS_CTRL_Type;
begin
SYS_CTRL.Read (SYS_CTRL_Reg);
SYS_CTRL_Reg.HRBPT := Toggle;
SYS_CTRL.Write (SYS_CTRL_Reg);
end Toggle_Host_Side_Rx_Buffer_Pointer;
-------------------------------
-- Sync_Rx_Buffer_Pointers --
-------------------------------
procedure Sync_Rx_Buffer_Pointers is
SYS_STATUS_Reg : SYS_STATUS_Type;
begin
SYS_STATUS.Read (SYS_STATUS_Reg);
-- Check if the IC side receive buffer pointer is the same
-- as the host side receive buffer pointer.
if SYS_STATUS_Reg.ICRBP /= SYS_STATUS_Reg.HSRBP then
Toggle_Host_Side_Rx_Buffer_Pointer;
end if;
end Sync_Rx_Buffer_Pointers;
--------------------------
-- Start_Rx_Immediate --
--------------------------
procedure Start_Rx_Immediate is
SYS_CTRL_Reg : SYS_CTRL_Type;
begin
Sync_Rx_Buffer_Pointers;
SYS_CTRL_Reg := (SFCST => Not_Suppressed,
TXSTRT => No_Action,
TXDLYS => Not_Delayed,
CANSFCS => Not_Cancelled,
TRXOFF => No_Action,
WAIT4RESP => No_Wait,
RXENAB => Start_Rx,
RXDLYE => Not_Delayed,
HRBPT => No_Action,
Reserved_1 => 0,
Reserved_2 => 0,
Reserved_3 => 0);
SYS_CTRL.Write (SYS_CTRL_Reg);
end Start_Rx_Immediate;
------------------------
-- Start_Rx_Delayed --
------------------------
procedure Start_Rx_Delayed (Result : out Result_Type) is
SYS_CTRL_Reg : SYS_CTRL_Type;
SYS_STATUS_Reg : SYS_STATUS_Type;
begin
Sync_Rx_Buffer_Pointers;
SYS_CTRL_Reg := (SFCST => Not_Suppressed,
TXSTRT => No_Action,
TXDLYS => Not_Delayed,
CANSFCS => Not_Cancelled,
TRXOFF => No_Action,
WAIT4RESP => No_Wait,
RXENAB => Start_Rx,
RXDLYE => Delayed,
HRBPT => No_Action,
Reserved_1 => 0,
Reserved_2 => 0,
Reserved_3 => 0);
SYS_CTRL.Write (SYS_CTRL_Reg);
-- Check for errors
SYS_STATUS.Read (SYS_STATUS_Reg);
if SYS_STATUS_Reg.HPDWARN = 1 then
Force_Tx_Rx_Off;
-- Clear the delay bit
SYS_CTRL_Reg.RXDLYE := Not_Delayed;
SYS_CTRL.Write (SYS_CTRL_Reg);
Result := Error;
else
Result := Success;
end if;
end Start_Rx_Delayed;
-------------------
-- Set_Rx_Mode --
-------------------
procedure Set_Rx_Mode (Mode : in Rx_Modes;
Rx_On_Time : in RX_SNIFF_SNIFF_ONT_Field;
Rx_Off_Time : in Sniff_Off_Time) is
begin
if Mode = Normal then
RX_SNIFF.Write ((SNIFF_ONT => 0,
SNIFF_OFFT => 0.0,
others => <>));
else
RX_SNIFF.Write ((SNIFF_ONT => Rx_On_Time,
SNIFF_OFFT => Rx_Off_Time,
others => <>));
end if;
end Set_Rx_Mode;
----------------------------
-- Set_Auto_Rx_Reenable --
----------------------------
procedure Set_Auto_Rx_Reenable (Enable : in Boolean) is
SYS_CFG_Reg : SYS_CFG_Type;
begin
SYS_CFG.Read (SYS_CFG_Reg);
SYS_CFG_Reg.RXAUTR := (if Enable then Enabled else Disabled);
SYS_CFG.Write (SYS_CFG_Reg);
end Set_Auto_Rx_Reenable;
----------------------------
-- Set_Rx_Double_Buffer --
----------------------------
procedure Set_Rx_Double_Buffer (Enable : in Boolean) is
SYS_CFG_Reg : SYS_CFG_Type;
begin
SYS_CFG.Read (SYS_CFG_Reg);
SYS_CFG_Reg.DIS_DRXB := (if Enable then Not_Disabled else Disabled);
SYS_CFG.Write (SYS_CFG_Reg);
end Set_Rx_Double_Buffer;
---------------------------------
-- Set_Rx_Frame_Wait_Timeout --
---------------------------------
procedure Set_Rx_Frame_Wait_Timeout (Timeout : in Frame_Wait_Timeout_Time) is
SYS_CFG_Reg : SYS_CFG_Type;
begin
SYS_CFG.Read (SYS_CFG_Reg);
if Timeout > 0.0 then
SYS_CFG_Reg.RXWTOE := Enabled;
RX_FWTO.Write ((RXFWTO => Timeout));
else
SYS_CFG_Reg.RXWTOE := Disabled;
end if;
SYS_CFG.Write (SYS_CFG_Reg);
end Set_Rx_Frame_Wait_Timeout;
-----------------------------------
-- Set_Preamble_Detect_Timeout --
-----------------------------------
procedure Set_Preamble_Detect_Timeout (Timeout : in DRX_PRETOC_Field) is
begin
DRX_PRETOC.Write ((DRX_PRETOC => Timeout));
end Set_Preamble_Detect_Timeout;
-----------------------------
-- Calibrate_Sleep_Count --
-----------------------------
procedure Calibrate_Sleep_Count
(Half_XTAL_Cycles_Per_LP_Osc_Cycle : out Types.Bits_16) is
PMSC_CTRL0_Reg : PMSC_CTRL0_Type;
Data : Types.Byte_Array (1 .. 2);
begin
-- Enable calibration
AON_CFG1.Write ((SLEEP_CE => Disabled,
SMXX => Clear,
LPOSC_C => Enabled,
Reserved => 0));
Upload_AON_Config;
-- Disable calibration
AON_CFG1.Write ((SLEEP_CE => Disabled,
SMXX => Clear,
LPOSC_C => Disabled,
Reserved => 0));
Upload_AON_Config;
PMSC_CTRL0.Read (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.SYSCLKS := Force_XTI;
PMSC_CTRL0_Reg.RXCLKS := Auto;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
-- Read number of XTAL/2 cycles per LP osc cycle
AON_Contiguous_Read (Start_Address => 117,
Data => Data);
Half_XTAL_Cycles_Per_LP_Osc_Cycle
:= (Types.Bits_16 (Data (1))
or Shift_Left (Types.Bits_16 (Data (2)), 8));
-- Reset PMSC_CTRL0
PMSC_CTRL0_Reg.SYSCLKS := Auto;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
end Calibrate_Sleep_Count;
-------------------------
-- Upload_AON_Config --
-------------------------
procedure Upload_AON_Config is
begin
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => Upload,
DCA_READ => No_Action,
DCA_ENAB => Disabled,
Reserved => 0));
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Disabled,
Reserved => 0));
end Upload_AON_Config;
-----------------------------
-- Save_Registers_To_AON --
-----------------------------
procedure Save_Registers_To_AON is
begin
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => Save, -- This bit auto-clears
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Disabled,
Reserved => 0));
end Save_Registers_To_AON;
----------------------------------
-- Restore_Registers_From_AON --
----------------------------------
procedure Restore_Registers_From_AON is
begin
AON_CTRL.Write ((RESTORE => Restore, -- This bit auto-clears
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Disabled,
Reserved => 0));
end Restore_Registers_From_AON;
---------------------
-- AON_Read_Byte --
---------------------
procedure AON_Read_Byte (Address : in AON_ADDR_Field;
Data : out Types.Bits_8) is
AON_RDAT_Reg : AON_RDAT_Type;
begin
-- Load address
AON_ADDR.Write ((AON_ADDR => Address));
-- Enable DCA_ENAB
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Enabled,
Reserved => 0));
-- Now also enable DCA_READ
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => Trigger_Read,
DCA_ENAB => Enabled,
Reserved => 0));
-- Read the result
AON_RDAT.Read (AON_RDAT_Reg);
Data := AON_RDAT_Reg.AON_RDAT;
-- Clear DCA_ENAB and DCA_READ
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Disabled,
Reserved => 0));
end AON_Read_Byte;
---------------------------
-- AON_Contiguous_Read --
---------------------------
procedure AON_Contiguous_Read (Start_Address : in AON_ADDR_Field;
Data : out Types.Byte_Array) is
Address : AON_ADDR_Field := Start_Address;
AON_RDAT_Reg : AON_RDAT_Type;
begin
for I in Data'Range loop
-- Load address
AON_ADDR.Write ((AON_ADDR => Address));
-- Enable DCA_ENAB
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Enabled,
Reserved => 0));
-- Now also enable DCA_READ
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => Trigger_Read,
DCA_ENAB => Enabled,
Reserved => 0));
-- Read the result
AON_RDAT.Read (AON_RDAT_Reg);
Data (I) := AON_RDAT_Reg.AON_RDAT;
Address := Address + 1;
end loop;
-- Clear DCA_ENAB and DCA_READ
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Disabled,
Reserved => 0));
end AON_Contiguous_Read;
------------------------
-- AON_Scatter_Read --
------------------------
procedure AON_Scatter_Read (Addresses : in AON_Address_Array;
Data : out Types.Byte_Array) is
AON_RDAT_Reg : AON_RDAT_Type;
A_First : constant Integer := Addresses'First;
D_First : constant Integer := Data'First;
begin
Data := (others => 0); -- workaround for flow analysis.
for I in 0 .. Data'Length - 1 loop
-- Load address
AON_ADDR.Write ((AON_ADDR => Addresses (A_First + I)));
-- Enable DCA_ENAB
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Enabled,
Reserved => 0));
-- Now also enable DCA_READ
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => Trigger_Read,
DCA_ENAB => Enabled,
Reserved => 0));
-- Read the result
AON_RDAT.Read (AON_RDAT_Reg);
Data (D_First + I) := AON_RDAT_Reg.AON_RDAT;
end loop;
-- Clear DCA_ENAB and DCA_READ
AON_CTRL.Write ((RESTORE => No_Action,
SAVE => No_Action,
UPL_CFG => No_Action,
DCA_READ => No_Action,
DCA_ENAB => Disabled,
Reserved => 0));
end AON_Scatter_Read;
-----------------------------
-- Configure_Sleep_Count --
-----------------------------
procedure Configure_Sleep_Count (Sleep_Count : in AON_CFG0_SLEEP_TIM_Field) is
PMSC_CTRL0_Reg : PMSC_CTRL0_Type;
begin
PMSC_CTRL0.Read (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.SYSCLKS := Force_XTI;
PMSC_CTRL0_Reg.RXCLKS := Auto;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
-- Make sure we don't accidentally sleep
AON_CFG0.Write ((SLEEP_EN => Disabled,
WAKE_PIN => Disabled,
WAKE_SPI => Disabled,
WAKE_CNT => Disabled,
LPDIV_EN => Disabled,
LPCLKDIVA => <>,
SLEEP_TIM => <>));
AON_CFG1.Write ((SLEEP_CE => Disabled,
SMXX => Clear,
LPOSC_C => Disabled,
Reserved => 0));
-- Disable the sleep counter
Upload_AON_Config;
-- Set the new value
AON_CFG0.Write ((SLEEP_EN => Disabled,
WAKE_PIN => Disabled,
WAKE_SPI => Disabled,
WAKE_CNT => Disabled,
LPDIV_EN => Disabled,
LPCLKDIVA => <>,
SLEEP_TIM => Sleep_Count));
Upload_AON_Config;
-- Enable the new value
AON_CFG1.Write ((SLEEP_CE => Enabled,
SMXX => Clear,
LPOSC_C => Disabled,
Reserved => 0));
PMSC_CTRL0_Reg.SYSCLKS := Auto;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
end Configure_Sleep_Count;
---------------------
-- Set_XTAL_Trim --
---------------------
procedure Set_XTAL_Trim (Trim : in FS_XTALT_Field) is
FS_XTALT_Reg : FS_XTALT_Type;
begin
FS_XTALT.Read (FS_XTALT_Reg);
FS_XTALT_Reg.XTALT := Trim;
FS_XTALT.Write (FS_XTALT_Reg);
end Set_XTAL_Trim;
----------------------
-- Configure_LEDs --
----------------------
procedure Configure_LEDs (Tx_LED_Enable : in Boolean;
Rx_LED_Enable : in Boolean;
Rx_OK_LED_Enable : in Boolean;
SFD_LED_Enable : in Boolean;
Test_Flash : in Boolean) is
GPIO_MODE_Reg : Register_Types.GPIO_MODE_Type;
PMSC_LEDC_Reg : Register_Types.PMSC_LEDC_Type;
PMSC_CTRL0_Reg : Register_Types.PMSC_CTRL0_Type;
LED_Enabled : constant Boolean := (Tx_LED_Enable or
Rx_LED_Enable or
Rx_OK_LED_Enable or
SFD_LED_Enable);
begin
-- Configure LED GPIOs
GPIO_MODE.Read (GPIO_MODE_Reg);
GPIO_MODE_Reg.MSGP0 := (if Rx_OK_LED_Enable then RXOKLED else GPIO0);
GPIO_MODE_Reg.MSGP1 := (if SFD_LED_Enable then SFDLED else GPIO1);
GPIO_MODE_Reg.MSGP2 := (if Rx_LED_Enable then RXLED else GPIO2);
GPIO_MODE_Reg.MSGP3 := (if Tx_LED_Enable then TXLED else GPIO3);
GPIO_MODE.Write (GPIO_MODE_Reg);
-- Enable LP oscillator to run from counter, turn on debounce clock
PMSC_CTRL0.Read (PMSC_CTRL0_Reg);
PMSC_CTRL0_Reg.GPDCE := Enabled;
PMSC_CTRL0_Reg.KHZCLKEN := Enabled;
PMSC_CTRL0.Write (PMSC_CTRL0_Reg);
-- Enable LEDs
PMSC_LEDC.Read (PMSC_LEDC_Reg);
PMSC_LEDC_Reg.BLINK_TIM := 0.224;
PMSC_LEDC_Reg.BLNKEN := (if LED_Enabled then Enabled else Disabled);
PMSC_LEDC.Write (PMSC_LEDC_Reg);
if Test_Flash then
-- Blink each LED
PMSC_LEDC_Reg.BLNKNOW_RXOKLED := Blink_Now;
PMSC_LEDC_Reg.BLNKNOW_SFDLED := Blink_Now;
PMSC_LEDC_Reg.BLNKNOW_RXLED := Blink_Now;
PMSC_LEDC_Reg.BLNKNOW_TXLED := Blink_Now;
PMSC_LEDC.Write (PMSC_LEDC_Reg);
-- Clear forced bits
PMSC_LEDC_Reg.BLNKNOW_RXOKLED := No_Action;
PMSC_LEDC_Reg.BLNKNOW_SFDLED := No_Action;
PMSC_LEDC_Reg.BLNKNOW_RXLED := No_Action;
PMSC_LEDC_Reg.BLNKNOW_TXLED := No_Action;
PMSC_LEDC.Write (PMSC_LEDC_Reg);
end if;
end Configure_LEDs;
end DW1000.Driver;
|
------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding Samples --
-- --
-- ncurses --
-- --
-- B O D Y --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 2000,2004 Free Software Foundation, Inc. --
-- --
-- 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, distribute with modifications, 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 ABOVE 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. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000
-- Version Control
-- $Revision: 1.5 $
-- $Date: 2004/08/21 21:37:00 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with ncurses2.util; use ncurses2.util;
with Terminal_Interface.Curses; use Terminal_Interface.Curses;
with Interfaces.C;
with System.Storage_Elements;
with System.Address_To_Access_Conversions;
with Ada.Text_IO;
-- with Ada.Real_Time; use Ada.Real_Time;
-- TODO is there a way to use Real_Time or Ada.Calendar in place of
-- gettimeofday?
-- Demonstrate pads.
procedure ncurses2.demo_pad is
type timestruct is record
seconds : Integer;
microseconds : Integer;
end record;
type myfunc is access function (w : Window) return Key_Code;
function gettime return timestruct;
procedure do_h_line (y : Line_Position;
x : Column_Position;
c : Attributed_Character;
to : Column_Position);
procedure do_v_line (y : Line_Position;
x : Column_Position;
c : Attributed_Character;
to : Line_Position);
function padgetch (win : Window) return Key_Code;
function panner_legend (line : Line_Position) return Boolean;
procedure panner_legend (line : Line_Position);
procedure panner_h_cleanup (from_y : Line_Position;
from_x : Column_Position;
to_x : Column_Position);
procedure panner_v_cleanup (from_y : Line_Position;
from_x : Column_Position;
to_y : Line_Position);
procedure panner (pad : Window;
top_xp : Column_Position;
top_yp : Line_Position;
portyp : Line_Position;
portxp : Column_Position;
pgetc : myfunc);
function gettime return timestruct is
retval : timestruct;
use Interfaces.C;
type timeval is record
tv_sec : long;
tv_usec : long;
end record;
pragma Convention (C, timeval);
-- TODO function from_timeval is new Ada.Unchecked_Conversion(
-- timeval_a, System.Storage_Elements.Integer_Address);
-- should Interfaces.C.Pointers be used here?
package myP is new System.Address_To_Access_Conversions (timeval);
use myP;
t : constant Object_Pointer := new timeval;
function gettimeofday
(TP : System.Storage_Elements.Integer_Address;
TZP : System.Storage_Elements.Integer_Address) return int;
pragma Import (C, gettimeofday, "gettimeofday");
tmp : int;
begin
tmp := gettimeofday (System.Storage_Elements.To_Integer
(myP.To_Address (t)),
System.Storage_Elements.To_Integer
(myP.To_Address (null)));
if tmp < 0 then
retval.seconds := 0;
retval.microseconds := 0;
else
retval.seconds := Integer (t.tv_sec);
retval.microseconds := Integer (t.tv_usec);
end if;
return retval;
end gettime;
-- in C, The behavior of mvhline, mvvline for negative/zero length is
-- unspecified, though we can rely on negative x/y values to stop the
-- macro. Except Ada makes Line_Position(-1) = Natural - 1 so forget it.
procedure do_h_line (y : Line_Position;
x : Column_Position;
c : Attributed_Character;
to : Column_Position) is
begin
if to > x then
Move_Cursor (Line => y, Column => x);
Horizontal_Line (Line_Size => Natural (to - x), Line_Symbol => c);
end if;
end do_h_line;
procedure do_v_line (y : Line_Position;
x : Column_Position;
c : Attributed_Character;
to : Line_Position) is
begin
if to > y then
Move_Cursor (Line => y, Column => x);
Vertical_Line (Line_Size => Natural (to - y), Line_Symbol => c);
end if;
end do_v_line;
function padgetch (win : Window) return Key_Code is
c : Key_Code;
c2 : Character;
begin
c := Getchar (win);
c2 := Code_To_Char (c);
case c2 is
when '!' =>
ShellOut (False);
return Key_Refresh;
when Character'Val (Character'Pos ('r') mod 16#20#) => -- CTRL('r')
End_Windows;
Refresh;
return Key_Refresh;
when Character'Val (Character'Pos ('l') mod 16#20#) => -- CTRL('l')
return Key_Refresh;
when 'U' =>
return Key_Cursor_Up;
when 'D' =>
return Key_Cursor_Down;
when 'R' =>
return Key_Cursor_Right;
when 'L' =>
return Key_Cursor_Left;
when '+' =>
return Key_Insert_Line;
when '-' =>
return Key_Delete_Line;
when '>' =>
return Key_Insert_Char;
when '<' =>
return Key_Delete_Char;
-- when ERR=> /* FALLTHRU */
when 'q' =>
return (Key_Exit);
when others =>
return (c);
end case;
end padgetch;
show_panner_legend : Boolean := True;
function panner_legend (line : Line_Position) return Boolean is
legend : constant array (0 .. 3) of String (1 .. 61) :=
(
"Use arrow keys (or U,D,L,R) to pan, q to quit (?,t,s flags) ",
"Use ! to shell-out. Toggle legend:?, timer:t, scroll mark:s.",
"Use +,- (or j,k) to grow/shrink the panner vertically. ",
"Use <,> (or h,l) to grow/shrink the panner horizontally. ");
legendsize : constant := 4;
n : constant Integer := legendsize - Integer (Lines - line);
begin
if line < Lines and n >= 0 then
Move_Cursor (Line => line, Column => 0);
if show_panner_legend then
Add (Str => legend (n));
end if;
Clear_To_End_Of_Line;
return show_panner_legend;
end if;
return False;
end panner_legend;
procedure panner_legend (line : Line_Position) is
begin
if not panner_legend (line) then
Beep;
end if;
end panner_legend;
procedure panner_h_cleanup (from_y : Line_Position;
from_x : Column_Position;
to_x : Column_Position) is
begin
if not panner_legend (from_y) then
do_h_line (from_y, from_x, Blank2, to_x);
end if;
end panner_h_cleanup;
procedure panner_v_cleanup (from_y : Line_Position;
from_x : Column_Position;
to_y : Line_Position) is
begin
if not panner_legend (from_y) then
do_v_line (from_y, from_x, Blank2, to_y);
end if;
end panner_v_cleanup;
procedure panner (pad : Window;
top_xp : Column_Position;
top_yp : Line_Position;
portyp : Line_Position;
portxp : Column_Position;
pgetc : myfunc) is
function f (y : Line_Position) return Line_Position;
function f (x : Column_Position) return Column_Position;
function greater (y1, y2 : Line_Position) return Integer;
function greater (x1, x2 : Column_Position) return Integer;
top_x : Column_Position := top_xp;
top_y : Line_Position := top_yp;
porty : Line_Position := portyp;
portx : Column_Position := portxp;
-- f[x] returns max[x - 1, 0]
function f (y : Line_Position) return Line_Position is
begin
if y > 0 then
return y - 1;
else
return y; -- 0
end if;
end f;
function f (x : Column_Position) return Column_Position is
begin
if x > 0 then
return x - 1;
else
return x; -- 0
end if;
end f;
function greater (y1, y2 : Line_Position) return Integer is
begin
if y1 > y2 then
return 1;
else
return 0;
end if;
end greater;
function greater (x1, x2 : Column_Position) return Integer is
begin
if x1 > x2 then
return 1;
else
return 0;
end if;
end greater;
pymax : Line_Position;
basey : Line_Position := 0;
pxmax : Column_Position;
basex : Column_Position := 0;
c : Key_Code;
scrollers : Boolean := True;
before, after : timestruct;
timing : Boolean := True;
package floatio is new Ada.Text_IO.Float_IO (Long_Float);
begin
Get_Size (pad, pymax, pxmax);
Allow_Scrolling (Mode => False); -- we don't want stdscr to scroll!
c := Key_Refresh;
loop
-- During shell-out, the user may have resized the window. Adjust
-- the port size of the pad to accommodate this. Ncurses
-- automatically resizes all of the normal windows to fit on the
-- new screen.
if top_x > Columns then
top_x := Columns;
end if;
if portx > Columns then
portx := Columns;
end if;
if top_y > Lines then
top_y := Lines;
end if;
if porty > Lines then
porty := Lines;
end if;
case c is
when Key_Refresh | Character'Pos ('?') =>
if c = Key_Refresh then
Erase;
else -- '?'
show_panner_legend := not show_panner_legend;
end if;
panner_legend (Lines - 4);
panner_legend (Lines - 3);
panner_legend (Lines - 2);
panner_legend (Lines - 1);
when Character'Pos ('t') =>
timing := not timing;
if not timing then
panner_legend (Lines - 1);
end if;
when Character'Pos ('s') =>
scrollers := not scrollers;
-- Move the top-left corner of the pad, keeping the
-- bottom-right corner fixed.
when Character'Pos ('h') =>
-- increase-columns: move left edge to left
if top_x <= 0 then
Beep;
else
panner_v_cleanup (top_y, top_x, porty);
top_x := top_x - 1;
end if;
when Character'Pos ('j') =>
-- decrease-lines: move top-edge down
if top_y >= porty then
Beep;
else
if top_y /= 0 then
panner_h_cleanup (top_y - 1, f (top_x), portx);
end if;
top_y := top_y + 1;
end if;
when Character'Pos ('k') =>
-- increase-lines: move top-edge up
if top_y <= 0 then
Beep;
else
top_y := top_y - 1;
panner_h_cleanup (top_y, top_x, portx);
end if;
when Character'Pos ('l') =>
-- decrease-columns: move left-edge to right
if top_x >= portx then
Beep;
else
if top_x /= 0 then
panner_v_cleanup (f (top_y), top_x - 1, porty);
end if;
top_x := top_x + 1;
end if;
-- Move the bottom-right corner of the pad, keeping the
-- top-left corner fixed.
when Key_Insert_Char =>
-- increase-columns: move right-edge to right
if portx >= pxmax or portx >= Columns then
Beep;
else
panner_v_cleanup (f (top_y), portx - 1, porty);
portx := portx + 1;
-- C had ++portx instead of portx++, weird.
end if;
when Key_Insert_Line =>
-- increase-lines: move bottom-edge down
if porty >= pymax or porty >= Lines then
Beep;
else
panner_h_cleanup (porty - 1, f (top_x), portx);
porty := porty + 1;
end if;
when Key_Delete_Char =>
-- decrease-columns: move bottom edge up
if portx <= top_x then
Beep;
else
portx := portx - 1;
panner_v_cleanup (f (top_y), portx, porty);
end if;
when Key_Delete_Line =>
-- decrease-lines
if porty <= top_y then
Beep;
else
porty := porty - 1;
panner_h_cleanup (porty, f (top_x), portx);
end if;
when Key_Cursor_Left =>
-- pan leftwards
if basex > 0 then
basex := basex - 1;
else
Beep;
end if;
when Key_Cursor_Right =>
-- pan rightwards
-- if (basex + portx - (pymax > porty) < pxmax)
if basex + portx -
Column_Position (greater (pymax, porty)) < pxmax then
-- if basex + portx < pxmax or
-- (pymax > porty and basex + portx - 1 < pxmax) then
basex := basex + 1;
else
Beep;
end if;
when Key_Cursor_Up =>
-- pan upwards
if basey > 0 then
basey := basey - 1;
else
Beep;
end if;
when Key_Cursor_Down =>
-- pan downwards
-- same as if (basey + porty - (pxmax > portx) < pymax)
if basey + porty -
Line_Position (greater (pxmax, portx)) < pymax then
-- if (basey + porty < pymax) or
-- (pxmax > portx and basey + porty - 1 < pymax) then
basey := basey + 1;
else
Beep;
end if;
when Character'Pos ('H') |
Key_Home |
Key_Find =>
basey := 0;
when Character'Pos ('E') |
Key_End |
Key_Select =>
if pymax < porty then
basey := 0;
else
basey := pymax - porty;
end if;
when others =>
Beep;
end case;
-- more writing off the screen.
-- Interestingly, the exception is not handled if
-- we put a block around this.
-- delcare --begin
if top_y /= 0 and top_x /= 0 then
Add (Line => top_y - 1, Column => top_x - 1,
Ch => ACS_Map (ACS_Upper_Left_Corner));
end if;
if top_x /= 0 then
do_v_line (top_y, top_x - 1, ACS_Map (ACS_Vertical_Line), porty);
end if;
if top_y /= 0 then
do_h_line (top_y - 1, top_x, ACS_Map (ACS_Horizontal_Line), portx);
end if;
-- exception when Curses_Exception => null; end;
-- in C was ... pxmax > portx - 1
if scrollers and pxmax >= portx then
declare
length : constant Column_Position := portx - top_x - 1;
lowend, highend : Column_Position;
begin
-- Instead of using floats, I'll use integers only.
lowend := top_x + (basex * length) / pxmax;
highend := top_x + ((basex + length) * length) / pxmax;
do_h_line (porty - 1, top_x, ACS_Map (ACS_Horizontal_Line),
lowend);
if highend < portx then
Switch_Character_Attribute
(Attr => (Reverse_Video => True, others => False),
On => True);
do_h_line (porty - 1, lowend, Blank2, highend + 1);
Switch_Character_Attribute
(Attr => (Reverse_Video => True, others => False),
On => False);
do_h_line (porty - 1, highend + 1,
ACS_Map (ACS_Horizontal_Line), portx);
end if;
end;
else
do_h_line (porty - 1, top_x, ACS_Map (ACS_Horizontal_Line), portx);
end if;
if scrollers and pymax >= porty then
declare
length : constant Line_Position := porty - top_y - 1;
lowend, highend : Line_Position;
begin
lowend := top_y + (basey * length) / pymax;
highend := top_y + ((basey + length) * length) / pymax;
do_v_line (top_y, portx - 1, ACS_Map (ACS_Vertical_Line),
lowend);
if highend < porty then
Switch_Character_Attribute
(Attr => (Reverse_Video => True, others => False),
On => True);
do_v_line (lowend, portx - 1, Blank2, highend + 1);
Switch_Character_Attribute
(Attr => (Reverse_Video => True, others => False),
On => False);
do_v_line (highend + 1, portx - 1,
ACS_Map (ACS_Vertical_Line), porty);
end if;
end;
else
do_v_line (top_y, portx - 1, ACS_Map (ACS_Vertical_Line), porty);
end if;
if top_y /= 0 then
Add (Line => top_y - 1, Column => portx - 1,
Ch => ACS_Map (ACS_Upper_Right_Corner));
end if;
if top_x /= 0 then
Add (Line => porty - 1, Column => top_x - 1,
Ch => ACS_Map (ACS_Lower_Left_Corner));
end if;
declare
begin
-- Here is another place where it is possible
-- to write to the corner of the screen.
Add (Line => porty - 1, Column => portx - 1,
Ch => ACS_Map (ACS_Lower_Right_Corner));
exception
when Curses_Exception => null;
end;
before := gettime;
Refresh_Without_Update;
declare
-- the C version allows the panel to have a zero height
-- wich raise the exception
begin
Refresh_Without_Update
(
pad,
basey, basex,
top_y, top_x,
porty - Line_Position (greater (pxmax, portx)) - 1,
portx - Column_Position (greater (pymax, porty)) - 1);
exception
when Curses_Exception => null;
end;
Update_Screen;
if timing then declare
s : String (1 .. 7);
elapsed : Long_Float;
begin
after := gettime;
elapsed := (Long_Float (after.seconds - before.seconds) +
Long_Float (after.microseconds - before.microseconds)
/ 1.0e6);
Move_Cursor (Line => Lines - 1, Column => Columns - 20);
floatio.Put (s, elapsed, Aft => 3, Exp => 0);
Add (Str => s);
Refresh;
end;
end if;
c := pgetc (pad);
exit when c = Key_Exit;
end loop;
Allow_Scrolling (Mode => True);
end panner;
Gridsize : constant := 3;
Gridcount : Integer := 0;
Pad_High : constant Line_Count := 200;
Pad_Wide : constant Column_Count := 200;
panpad : Window := New_Pad (Pad_High, Pad_Wide);
begin
if panpad = Null_Window then
Cannot ("cannot create requested pad");
return;
end if;
for i in 0 .. Pad_High - 1 loop
for j in 0 .. Pad_Wide - 1 loop
if i mod Gridsize = 0 and j mod Gridsize = 0 then
if i = 0 or j = 0 then
Add (panpad, '+');
else
-- depends on ASCII?
Add (panpad,
Ch => Character'Val (Character'Pos ('A') +
Gridcount mod 26));
Gridcount := Gridcount + 1;
end if;
elsif i mod Gridsize = 0 then
Add (panpad, '-');
elsif j mod Gridsize = 0 then
Add (panpad, '|');
else
declare
-- handle the write to the lower right corner error
begin
Add (panpad, ' ');
exception
when Curses_Exception => null;
end;
end if;
end loop;
end loop;
panner_legend (Lines - 4);
panner_legend (Lines - 3);
panner_legend (Lines - 2);
panner_legend (Lines - 1);
Set_KeyPad_Mode (panpad, True);
-- Make the pad (initially) narrow enough that a trace file won't wrap.
-- We'll still be able to widen it during a test, since that's required
-- for testing boundaries.
panner (panpad, 2, 2, Lines - 5, Columns - 15, padgetch'Access);
Delete (panpad);
End_Windows; -- Hmm, Erase after End_Windows
Erase;
end ncurses2.demo_pad;
|
with OpenGL.Thin;
package body OpenGL.Fog is
function Equation_To_Constant
(Equation : in Equation_t) return Thin.Integer_t is
begin
case Equation is
when Linear => return Thin.GL_LINEAR;
when Exponential => return Thin.GL_EXP;
when Exponential_2 => return Thin.GL_EXP2;
end case;
end Equation_To_Constant;
procedure Fog_Mode (Equation : in Equation_t) is
begin
Thin.Fogi (Thin.GL_FOG_MODE, Equation_To_Constant (Equation));
end Fog_Mode;
procedure Fog_Density (Density : in Density_Integer_t) is
begin
Thin.Fogi (Thin.GL_FOG_DENSITY, Thin.Integer_t (Density));
end Fog_Density;
procedure Fog_Density (Density : in Density_Float_t) is
begin
Thin.Fogf (Thin.GL_FOG_DENSITY, Thin.Float_t (Density));
end Fog_Density;
procedure Fog_Start (Near : in Types.Integer_t) is
begin
Thin.Fogi (Thin.GL_FOG_START, Near);
end Fog_Start;
procedure Fog_Start (Near : in Types.Float_t) is
begin
Thin.Fogf (Thin.GL_FOG_START, Near);
end Fog_Start;
procedure Fog_End (Far : in Types.Integer_t) is
begin
Thin.Fogi (Thin.GL_FOG_END, Far);
end Fog_End;
procedure Fog_End (Far : in Types.Float_t) is
begin
Thin.Fogf (Thin.GL_FOG_END, Far);
end Fog_End;
procedure Fog_Index (Index : in Types.Integer_t) is
begin
Thin.Fogi (Thin.GL_FOG_INDEX, Index);
end Fog_Index;
procedure Fog_Color (Color : in Types.Vector_4i_t) is
begin
Thin.Fogiv (Thin.GL_FOG_COLOR, Color (Color'First)'Address);
end Fog_Color;
procedure Fog_Color (Color : in Types.Vector_4f_t) is
begin
Thin.Fogfv (Thin.GL_FOG_COLOR, Color (Color'First)'Address);
end Fog_Color;
function Source_To_Constant (Source : in Source_t) return Thin.Integer_t is
begin
case Source is
when Fragment_Depth => return Thin.GL_FRAGMENT_DEPTH;
when Coordinate => return Thin.GL_FOG_COORD;
end case;
end Source_To_Constant;
procedure Fog_Coordinate_Source (Source : in Source_t) is
begin
Thin.Fogi (Thin.GL_FOG_COORD_SRC, Source_To_Constant (Source));
end Fog_Coordinate_Source;
end OpenGL.Fog;
|
-- $Id: Source.md,v 1.5 1993/08/18 17:28:53 grosch rel $
package Source is
function BeginSource (FileName: String) return Integer;
-- BeginSource is called from the scanner to open files.
-- If not called then input is read form standard input.
procedure GetLine (File: Integer; Buffer: out String; Size: Integer; Last: out Integer);
-- GetLine is called to fill a buffer starting at address 'Buffer'
-- with a block of maximal 'Size' characters. Lines are terminated
-- by newline characters (ASCII = 0xa). GetLine returns the number
-- of characters transferred. Reasonable block sizes are between 128
-- and 2048 or the length of a line. Smaller block sizes -
-- especially block size 1 - will drastically slow down the scanner.
procedure CloseSource (File: Integer);
-- CloseSource is called from the scanner at end of file or
-- at end of input, respectively. It can be used to close files.
end Source;
|
with Ada.Text_IO;
procedure Vector is
type Float_Vector is array (Positive range <>) of Float;
package Float_IO is new Ada.Text_IO.Float_IO (Float);
procedure Vector_Put (X : Float_Vector) is
begin
Ada.Text_IO.Put ("(");
for I in X'Range loop
Float_IO.Put (X (I), Aft => 1, Exp => 0);
if I /= X'Last then
Ada.Text_IO.Put (", ");
end if;
end loop;
Ada.Text_IO.Put (")");
end Vector_Put;
-- cross product
function "*" (Left, Right : Float_Vector) return Float_Vector is
begin
if Left'Length /= Right'Length then
raise Constraint_Error with "vectors of different size in dot product";
end if;
if Left'Length /= 3 then
raise Constraint_Error with "dot product only implemented for R**3";
end if;
return Float_Vector'(Left (Left'First + 1) * Right (Right'First + 2) -
Left (Left'First + 2) * Right (Right'First + 1),
Left (Left'First + 2) * Right (Right'First) -
Left (Left'First) * Right (Right'First + 2),
Left (Left'First) * Right (Right'First + 1) -
Left (Left'First + 1) * Right (Right'First));
end "*";
-- scalar product
function "*" (Left, Right : Float_Vector) return Float is
Result : Float := 0.0;
I, J : Positive;
begin
if Left'Length /= Right'Length then
raise Constraint_Error with "vectors of different size in scalar product";
end if;
I := Left'First; J := Right'First;
while I <= Left'Last and then J <= Right'Last loop
Result := Result + Left (I) * Right (J);
I := I + 1; J := J + 1;
end loop;
return Result;
end "*";
-- stretching
function "*" (Left : Float_Vector; Right : Float) return Float_Vector is
Result : Float_Vector (Left'Range);
begin
for I in Left'Range loop
Result (I) := Left (I) * Right;
end loop;
return Result;
end "*";
A : constant Float_Vector := (3.0, 4.0, 5.0);
B : constant Float_Vector := (4.0, 3.0, 5.0);
C : constant Float_Vector := (-5.0, -12.0, -13.0);
begin
Ada.Text_IO.Put ("A: "); Vector_Put (A); Ada.Text_IO.New_Line;
Ada.Text_IO.Put ("B: "); Vector_Put (B); Ada.Text_IO.New_Line;
Ada.Text_IO.Put ("C: "); Vector_Put (C); Ada.Text_IO.New_Line;
Ada.Text_IO.New_Line;
Ada.Text_IO.Put ("A dot B = "); Float_IO.Put (A * B, Aft => 1, Exp => 0);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put ("A x B = "); Vector_Put (A * B);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put ("A dot (B x C) = "); Float_IO.Put (A * (B * C), Aft => 1, Exp => 0);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put ("A x (B x C) = "); Vector_Put (A * Float_Vector'(B * C));
Ada.Text_IO.New_Line;
end Vector;
|
with Asis.Statements;
package body Asis_Adapter.Element.Exception_Handlers is
-----------------------------
-- EXPORTED:
-----------------------------
procedure Do_Pre_Child_Processing
(Element : in Asis.Element;
State : in out Class)
is
Parent_Name : constant String := Module_Name;
Module_Name : constant String := Parent_Name & ".Process_Exception_Handler";
Result : a_nodes_h.Exception_Handler_Struct :=
a_nodes_h.Support.Default_Exception_Handler_Struct;
procedure Add_Choice_Parameter_Specification is
ID : constant a_nodes_h.Element_ID :=
Get_Element_ID (Asis.Statements.Choice_Parameter_Specification
(Element));
begin
State.Add_To_Dot_Label_And_Edge ("Choice_Parameter_Specification", ID);
Result.Choice_Parameter_Specification :=
ID;
end;
procedure Add_Exception_Choices is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Statements.Exception_Choices (Element),
Dot_Label_Name => "Exception_Choices",
List_Out => Result.Exception_Choices,
Add_Edges => True);
end;
procedure Add_Handler_Statements is
begin
Add_Element_List
(This => State,
Elements_In => Asis.Statements.Handler_Statements (Element),
Dot_Label_Name => "Handler_Statements",
List_Out => Result.Handler_Statements,
Add_Edges => True);
end;
begin
Add_Choice_Parameter_Specification;
Add_Exception_Choices;
Add_Handler_Statements;
State.A_Element.Element_Kind := a_nodes_h.An_Exception_Handler;
State.A_Element.the_union.exception_handler := Result;
end Do_Pre_Child_Processing;
end Asis_Adapter.Element.Exception_Handlers;
|
package body Problem_8 is
Number : constant String :=
"73167176531330624919225119674426574742355349194934" &
"96983520312774506326239578318016984801869478851843" &
"85861560789112949495459501737958331952853208805511" &
"12540698747158523863050715693290963295227443043557" &
"66896648950445244523161731856403098711121722383113" &
"62229893423380308135336276614282806444486645238749" &
"30358907296290491560440772390713810515859307960866" &
"70172427121883998797908792274921901699720888093776" &
"65727333001053367881220235421809751254540594752243" &
"52584907711670556013604839586446706324415722155397" &
"53697817977846174064955149290862569321978468622482" &
"83972241375657056057490261407972968652414535100474" &
"82166370484403199890008895243450658541227588666881" &
"16427171479924442928230863465674813919123162824586" &
"17866458359124566529476545682848912883142607690042" &
"24219022671055626321111109370544217506941658960408" &
"07198403850962455444362981230987879927244284909188" &
"84580156166097919133875499200524063689912560717606" &
"05886116467109405077541002256983155200055935729725" &
"71636269561882670428252483600823257530420752963450";
function Solution_1 return Int64 is
Index : Natural := 1;
Local_Index : Natural := 0;
Sum : Int64 := 1;
Total : Int64 := 1;
Temp : Int64;
begin
while Index <= Number'Length loop
Sum := 1;
Local_Index := 0;
while Local_Index < 13 loop
Temp := Int64'Value((1 => Number(Index + Local_Index)));
if Temp = 0 then
Sum := 1;
Index := Index + Local_Index + 1;
exit;
else
Sum := Sum * Temp;
Local_Index := Local_Index + 1;
end if;
end loop;
if Sum > Total then
Total := Sum;
end if;
Index := Index + 1;
end loop;
return Total;
end Solution_1;
procedure Test_Solution_1 is
Solution : constant Int64 := 23514624000;
begin
Assert( Solution_1 = Solution );
end Test_Solution_1;
function Get_Solutions return Solution_Case is
Ret : Solution_Case;
begin
Set_Name( Ret, "Problem 8");
Add_Test( Ret, Test_Solution_1'Access );
return Ret;
end Get_Solutions;
end Problem_8;
|
with Orthogonal_Polys;
with text_io; use text_io;
with Ada.Numerics.Generic_Elementary_Functions;
procedure opolys_tst_1 is -- fit data with a nth order polynomial
type Real is digits 15;
package Math is new Ada.Numerics.Generic_Elementary_Functions (Real);
function Sin (X : Real) return Real renames Math.Sin;
function Cos (X : Real) return Real renames Math.Cos;
type Points_Index is range 0..81;
-- This determines the maximum storage size of the Data array.
-- the Data array will start at Points_Index'First and end
-- at Points_Index'Last.
-- Least squares fitting can be done on any sub interval of
-- this array by setting the obvious parameters in the procedure
-- below.
type Data is array (Points_Index) of Real;
package LS is new Orthogonal_Polys (Real, Points_Index, Data, 0.0, 1.0);
-- "*", "+", "-", "/", "<", "**", "-");
use LS;
X_axis : Data;
Y_Data : Data;
Weights : constant Data := (others => 1.0);
F : constant Points_Index := Data'First;
L : constant Points_Index := Data'Last;
Poly_A, Poly_0, Poly_1, Poly_2 : Poly_Data; -- already initialized.
Norm01, Norm12, Norm02 : Real;
NormA2 : Real;
Delta_X : Real;
Order_Of_Deriv : Coeff_Index;
Q1, Q2, Q3, Q4, Max1, Max2, Max3, d1, d2, d3 : Real;
-- Variables for IO:
Answer : character;
X, Y : Real;
X0, Y0: Real;
X1, Y1 : Real;
Integral_At_0 : Real := 0.0;
Factorial : Real := 1.0;
E : Real;
Order : Real;
Degree_Of_Poly : Coeff_Index;
Best_Fit : Poly_Data;
Poly_Set : Polynomials;
C : Poly_Sum_Coeffs;
Derivatives : Derivative_List;
Deg_Of_Test_Poly_Plus : Coeff_Index;
X_Coeffs, X_Coeffs_2 : Powers_Of_X_Coeffs;
First : constant Points_Index := Points_Index'First;
Last : constant Points_Index := Points_Index'Last;
X_Start : constant Real := -Real (2.0);
X_end : constant Real := 2.0;
Degree_Of_Test_Poly : constant Coeff_Index := Coeff_Index'(5);
package rio is new Text_IO.FLoat_IO(Real);
use rio;
---------
-- Sum --
---------
function Sum (X : Real;
Coeffs : Powers_Of_X_Coeffs) return Real is
Result : Real := 0.0;
begin
Result := Coeffs(Coeff_Index'Last);
for I in reverse Coeff_Index'First..Coeff_Index'Last-1 loop
Result := Result * X;
Result := Result + Coeffs(I);
end loop;
return Result;
end Sum;
-----------
-- Pause --
-----------
procedure Pause (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13 : string := "") is
Continue : Character := ' ';
begin
new_line;
if S0 /= "" then put_line (S0); end if;
if S1 /= "" then put_line (S1); end if;
if S2 /= "" then put_line (S2); end if;
if S3 /= "" then put_line (S3); end if;
if S4 /= "" then put_line (S4); end if;
if S5 /= "" then put_line (S5); end if;
if S6 /= "" then put_line (S6); end if;
if S7 /= "" then put_line (S7); end if;
if S8 /= "" then put_line (S8); end if;
if S9 /= "" then put_line (S9); end if;
if S10 /= "" then put_line (S10); end if;
if S11 /= "" then put_line (S11); end if;
if S12 /= "" then put_line (S12); end if;
if S13 /= "" then put_line (S13); end if;
new_line;
begin
Put ("Press a key to continue: ");
Get_Immediate (Continue); New_Line;
exception
when others => null;
end;
end pause;
--------------------
-- Make_True_Poly --
--------------------
-- Make a polynomial of order Poly_Order. All of the
-- the coefficients of powers of X are 1.0.
-- Y = 15.0 + 14.0*X + 13.0*X**2 + 12.0*X**3 + ...
-- Below we fit least-squares polynomials to this data
-- in order to test package Least_Squares_Poly.
procedure Make_True_Poly
(Poly_Order : in Coeff_Index;
Coeffs : in Powers_Of_X_Coeffs;
X_Axis, Data1 : out Data;
X_Start,X_end : in Real)
is
X, Y : Real;
Delta_X : constant Real :=
(X_end - X_Start) / Real(Points_Index'Last - Points_Index'First);
begin
for I in Points_Index loop
X := X_Start + Delta_X * Real (I - Points_Index'First);
Y := Coeffs (Poly_Order); -- highest order coefficient
if Poly_Order > 0 then
for Power_Of_X in reverse Coeff_Index range 1..Poly_Order loop
Y := Y * X;
Y := Y + Coeffs (Power_Of_X - 1);
end loop;
end if;
X_axis(I) := X;
Data1 (I) := Y;
end loop;
end Make_True_Poly;
begin
Delta_X := (X_end - X_Start) / Real (X_axis'Length - 1);
for I in Points_Index loop
X_axis(I) := X_Start + Real (I - Points_Index'First) * Delta_X;
end loop;
-------------
-- Test 1. --
-------------
Pause ("Test 1. Check orthogonality of each polynomial with the three",
"preceding polys. Print out inner product... should be about 0.");
begin
Start_Gram_Schmidt_Poly_Recursion
(X_axis, Weights, Data'First, Data'Last, Poly_0, Poly_1, Poly_Set);
Norm01 := Inner_Product (Poly_0.Points, Poly_1.Points, F, L, Weights);
new_line;
put (Norm01);
new_line;
for I in Coeff_Index range 2..Coeff_Index'Last loop
Get_Next_Poly (Poly_0, Poly_1, Weights, poly_2, Poly_Set);
NormA2 := Inner_Product (Poly_A.Points, Poly_2.Points, F, L, Weights);
Norm02 := Inner_Product (Poly_0.Points, Poly_2.Points, F, L, Weights);
Norm12 := Inner_Product (Poly_1.Points, Poly_2.Points, F, L, Weights);
new_line;
--put (Norm2 / Poly_2.Squared);
put (NormA2); put(" "); put (Norm12); put (" "); put (Norm02);
Poly_A := Poly_0;
Poly_0 := Poly_1;
Poly_1 := Poly_2;
end loop;
exception
when others =>
put_line ("Some error.");
end;
Pause ("");
-------------
-- Test 2. --
-------------
Pause ("Test 2 compares various calculations of poly values at the X-axis",
"grid points. Four different methods are used.",
"0: Use the original polynomial - the values stored in Poly_Data.",
"1: Calculate the 0th order derivative using the derivative function.",
"2: Call Poly_Value (which also uses the Clenshaw summation formula).",
"3: Calculate the coefficients of powers of X, and then sum the polynomial",
" using these coefficients. The differences will be printed below.",
" ",
"The first column will print the differences between method 0 and method",
"1 above. The second column prints differences between 0 and 2 above.",
" ",
"The 3rd column prints the differences between method 0 above, and the",
"value calculated by summing over coefficients of powers of X.",
"You'll notice that method 3 is a terrible way to evaluate polynomials.");
Start_Gram_Schmidt_Poly_Recursion
(X_axis, Weights, Data'First, Data'Last, Poly_0, Poly_1, Poly_Set);
for I in Coeff_Index range 2..Coeff_Index'Last loop
Get_Next_Poly (Poly_0, Poly_1, Weights, poly_2, Poly_Set);
Poly_0 := Poly_1;
Poly_1 := Poly_2;
-- In what follows look at poly value at each grid point X_axis(I)
C := (others => +0.0);
C(I) := +1.0;
Get_Coeffs_Of_Powers_Of_X (X_Coeffs, C, Poly_Set);
Max1 := 0.0; Max2 := 0.0; Max3 := 0.0;
for J in Points_Index loop
X := X_axis(J);
Order_Of_Deriv := 0;
Poly_Derivatives (Derivatives, X, Order_Of_Deriv, C, Poly_Set);
Q1 := Derivatives(0);
Q2 := Poly_Value (X, C, Poly_Set);
Q3 := Sum (X, X_Coeffs);
Q4 := Poly_2.Points(J);
d1 := Q4 - Q1; d2 := Q4 - Q2; d3 := Q4 - Q3;
if Abs(d1) > Max1 then Max1 := Abs(d1); end if;
if Abs(d2) > Max2 then Max2 := Abs(d2); end if;
if Abs(d3) > Max3 then Max3 := Abs(d3); end if;
--new_line;
--put(d1); put(" "); put(d2); put(" "); put(d3);
end loop;
new_line;
put(Max1); put(" "); put(Max2); put(" "); put(Max3);
end loop;
-------------
-- Test 1 --
-------------
New_Line;
Pause ("New series of tests: create a test polynomial, calculate",
"series of least squares polynomial fits to it, and print the comparison.");
Pause ("Test 1: we create a polynomial of order 14, with coefficients",
"equal to 16.0, 15.0, 14.0 etc.: Y = 16.0 + 15.0*X + 14.0*X**2 + ...",
"In what follows, the user fits a",
"least squares polynomial of some given order to the data. As the user",
"raises the order of the polynomial fit, the mean square error between",
"the least-squares polynomial fit and the data should fall. It",
"should suddenly fall by a factor 10**23 at order 5 and higher.");
loop
begin
put ("Input order of polynomial fit (try 6 first, and exit):");
New_Line; Get (Order);
Degree_Of_Poly := Coeff_Index (Order);
X_Coeffs_2 := (others => 0.0);
for I in Coeff_Index range 0..Degree_Of_Test_Poly loop
X_Coeffs_2 (I) := 16.0 - Real(I);
end loop;
Make_True_Poly
(Poly_Order => Degree_Of_Test_Poly,
Coeffs => X_Coeffs_2,
X_axis => X_axis,
Data1 => Y_Data,
X_Start => X_Start,
X_end => X_end);
Poly_Fit (Y_Data, X_axis, Weights, First, Last, Degree_Of_Poly,
Best_Fit, C, Poly_Set, E);
put("Mean square error = "); put(E); New_Line;
put_line ("Exit loop? if Yes, enter a 'y', else a 'n' ");
get (Answer);
if Answer = 'y' then
Exit;
end if;
exception
when others =>
put_line ("Some error. Try again: ");
end;
end loop;
-------------
-- Test 2 --
-------------
pause ("Test 2: print the differences between the LS fit and the data.",
"This test compares the original data with the least squares fit",
"polynomial returned by procedure Poly_Fit.");
-- Print differences:
for I in Points_Index loop
New_Line; Put (Best_Fit.Points(I) - Y_Data(I)); put (" ");
end loop;
-------------
-- Test 3 --
-------------
pause;
pause("Test 3: print the differences between the Poly and the Data.",
"This is a test of the function Poly_Value, which uses Clenshaw's",
"formula to sum the least-squares polynomial. This is calculated",
"in a different way from the polynomial test previously. Also,",
"we redo the least-squares fit to make sure that the order of the",
"least-squares poly is greater than the order of the polynomial",
"used to generate the test data.");
if Degree_Of_Test_Poly < Coeff_Index'Last then
Deg_Of_Test_Poly_Plus := Degree_Of_Test_Poly + 1;
else
Deg_Of_Test_Poly_Plus := Degree_Of_Test_Poly;
end if;
Poly_Fit (Y_Data, X_axis, Weights, First, Last, Deg_Of_Test_Poly_Plus,
Best_Fit, C, Poly_Set, E);
for I in Points_Index loop
X := X_axis(I);
Y := Poly_Value (X, C, Poly_Set);
New_Line; Put (Y - Y_Data(I)); put (" ");
end loop;
------------
-- Test 4 --
------------
pause;
pause("Test 4: attempt to get the coefficients of the powers of X",
"in the least-squares fit polynomial. This is a process that",
"can result in a large loss of precision, underflows, overflows",
"etc. if the degree of the polynomial is high. In the present",
"case, a 14th order poly, things work out OK if you sample the",
"poly over a sufficiently large interval in X.");
Get_Coeffs_Of_Powers_Of_X (X_Coeffs, C, Poly_Set);
New_Line;
for I in Coeff_Index loop
New_Line; put (X_Coeffs(I));
end loop;
-------------
-- Test 5 --
-------------
pause;
pause("Test 5: take the first derivative of the polynomial,",
"and compare with the predictions of the analytical",
"derivative.");
X_Coeffs_2 := (others => 0.0);
Y_Data := (others => 0.0);
if Degree_Of_Test_Poly > 0 then
for I in Coeff_Index range 0..Degree_Of_Test_Poly-1 loop
X_Coeffs_2 (I) := Real(I+1) * (16.0 - Real(I+1));
end loop;
Make_True_Poly (Poly_Order => Degree_Of_Test_Poly-1,
Coeffs => X_Coeffs_2,
X_axis => X_axis,
Data1 => Y_Data,
X_Start => X_Start,
X_end => X_end);
end if;
for I in Points_Index loop
X := X_axis(I);
Poly_Derivatives (Derivatives, X, 1, C, Poly_Set);
New_Line; Put (Derivatives(1) - Y_Data(I)); put (" ");
end loop;
-------------
-- Test 6 --
-------------
pause;
pause("Test 6: take the second derivative of the polynomial,",
"and compare with the predictions of the analytical",
"derivative.");
X_Coeffs_2 := (others => 0.0);
Y_Data := (others => 0.0);
if Degree_Of_Test_Poly > 1 then
for I in Coeff_Index range 0..Degree_Of_Test_Poly-2 loop
X_Coeffs_2 (I) := Real(I+2) * Real(I+1) * (16.0 - Real(I+2));
end loop;
Make_True_Poly
(Poly_Order => Degree_Of_Test_Poly-2,
Coeffs => X_Coeffs_2,
X_axis => X_axis,
Data1 => Y_Data,
X_Start => X_Start,
X_end => X_end);
end if;
for I in Points_Index loop
X := X_axis(I);
Poly_Derivatives (Derivatives, X, 2, C, Poly_Set);
New_Line; Put (Derivatives(2) - Y_Data(I)); put (" ");
end loop;
-------------
-- Test 7 --
-------------
pause;
pause("Test 7: take the third derivative of the polynomial,",
"and compare with the predictions of the analytical",
"derivative.");
X_Coeffs_2 := (others => 0.0);
Y_Data := (others => 0.0);
if Degree_Of_Test_Poly > 2 then
for I in Coeff_Index range 0..Degree_Of_Test_Poly-3 loop
X_Coeffs_2 (I) :=
Real(I+3) * Real(I+2) * Real(I+1) * (16.0 - Real(I+3));
end loop;
Make_True_Poly
(Poly_Order => Degree_Of_Test_Poly-3,
Coeffs => X_Coeffs_2,
X_axis => X_axis,
Data1 => Y_Data,
X_Start => X_Start,
X_end => X_end);
end if;
for I in Points_Index loop
X := X_axis(I);
Poly_Derivatives (Derivatives, X, 3, C, Poly_Set);
New_Line; Put (Derivatives(3) - Y_Data(I)); put (" ");
end loop;
-------------
-- Test 8 --
-------------
pause;
pause("Test 8: check that the Derivative routine also gets the",
"correct zeroth order derivative:",
"Below are the differences between the predictions of procedure",
"Poly_Derivatives, and the least-squares fit polynomial.");
for I in Points_Index loop
X := X_axis(I);
Poly_Derivatives (Derivatives, X, 2, C, Poly_Set);
New_Line; Put (Derivatives(0) - Best_Fit.Points(I)); put (" ");
end loop;
-------------
-- Test 9 --
-------------
pause;
pause("Test 9: check that the Derivative routine is able to correctly",
"calculate the coefficients of powers of X of the polynomial. We",
"use the fact that the coefficient of the m-th power of X equals",
"m-th derivative of the least squares fit polynomial evaluated at",
"X = 0, and divided by m!.");
Factorial := 1.0;
Poly_Derivatives (Derivatives, 0.0, Coeff_Index'Last, C, Poly_Set);
for m in Coeff_Index loop
if m > Coeff_Index'First then
Factorial := Factorial * Real(m);
end if;
New_Line; put (Derivatives(m) / Factorial);
end loop;
-------------
-- Test 10 --
-------------
pause;
pause("Test 10: take the indefinite Integral of the polynomial,",
"and compare with the predictions of the analytical",
"integral.");
X_Coeffs_2 := (others => 0.0);
Y_Data := (others => 0.0);
if Degree_Of_Test_Poly > 0 then
for I in reverse Coeff_Index range 0..Degree_Of_Test_Poly loop
X_Coeffs_2 (I+1) := (16.0 - Real(I)) / Real(I+1);
end loop;
X_Coeffs_2 (0) := (0.0);
Make_True_Poly (Poly_Order => Degree_Of_Test_Poly+1,
Coeffs => X_Coeffs_2,
X_axis => X_axis,
Data1 => Y_Data,
X_Start => X_Start,
X_end => X_end);
end if;
Integral_At_0 := Poly_Integral (0.0, C, Poly_Set);
for I in Points_Index loop
X := X_axis(I);
Y := Poly_Integral (X, C, Poly_Set) - Integral_At_0;
New_Line; Put (Y - Y_Data(I)); put (" ");
end loop;
-------------
-- Test 1 --
-------------
New_Line;
Pause ("New series of tests: the previous series was",
"designed to discover gross errors, but it didn't say much about",
"the numerical accuracy of the fits, because the error may have",
"been in the calculation of the original data. In the following",
"series of tests we generate data with Sin's and Cos's so that we",
"can reliably measure numerical error in the least squares fits");
Delta_X := 16.0 / Real (X_axis'Length - 1);
for I in Points_Index loop
X_axis(I) := Real (I - Points_Index'First) * Delta_X;
end loop;
for I in Points_Index loop
Y_Data(I) := Sin (X_axis(I));
end loop;
Poly_Fit (Y_Data, X_axis, Weights, First, Last, 36,
Best_Fit, C, Poly_Set, E);
pause("Test 1: Make sinusoidal data, fit a high order poly to it,",
"and print the difference between the fit and the original data:");
for I in Points_Index loop
X := X_axis(I);
Y := Poly_Value (X, C, Poly_Set);
new_line; Put (Y - Y_Data(I)); put (" ");
end loop;
pause;
pause("Test 2: Make sinusoidal data, fit a high order poly to it,",
"and print the difference between the 1st derivative of the fit",
"and the 1st derivative of the original data:");
for I in Points_Index loop
X := X_axis(I);
Poly_Derivatives (Derivatives, X, 1, C, Poly_Set);
new_line; Put (Derivatives(1) - Cos(X_axis(I))); put (" ");
end loop;
pause;
pause("Test 3: Make sinusoidal data, fit a high order poly to it,",
"and print the difference between the 2nd derivative of the fit",
"and the 2nd derivative of the original data:");
for I in Points_Index loop
X := X_axis(I);
Poly_Derivatives (Derivatives, X, 2, C, Poly_Set);
new_line; Put (Derivatives(2) + Sin(X_axis(I))); put (" ");
end loop;
pause;
pause("Test 4: Make sinusoidal data, fit a high order poly to it,",
"and print the difference between the 3rd derivative of the fit",
"and the 3rd derivative of the original data:");
for I in Points_Index loop
X := X_axis(I);
Poly_Derivatives (Derivatives, X, 3, C, Poly_Set);
new_line; Put (Derivatives(3) + Cos(X_axis(I))); put (" ");
end loop;
pause;
pause("Test 5: Make sinusoidal data, fit a high order poly to it,",
"and print the difference between the integral of the fit",
"and the integral of the original data:");
Integral_At_0 := Poly_Integral (0.0, C, Poly_Set);
for I in Points_Index'first+1 .. Points_Index'last loop
X0 := X_axis(I-1);
Y0 := Poly_Integral (X0, C, Poly_Set);
X1 := X_axis(I);
Y1 := Poly_Integral (X1, C, Poly_Set);
new_line; put (Y1 - Y0 - (-Cos (X1) + Cos (X0)) ); put (" ");
end loop;
end opolys_tst_1;
|
with Ada.Strings.Naked_Maps.Case_Folding;
function Ada.Strings.Generic_Equal_Case_Insensitive (Left, Right : String_Type)
return Boolean
is
Mapping : constant not null Naked_Maps.Character_Mapping_Access :=
Naked_Maps.Case_Folding.Case_Folding_Map;
Left_Last : Natural := Left'First - 1;
Right_Last : Natural := Right'First - 1;
begin
while Left_Last < Left'Last and then Right_Last < Right'Last loop
declare
Left_Index : constant Positive := Left_Last + 1;
Left_Code : Wide_Wide_Character;
Left_Is_Illegal_Sequence : Boolean;
Right_Index : constant Positive := Right_Last + 1;
Right_Code : Wide_Wide_Character;
Right_Is_Illegal_Sequence : Boolean;
begin
Get (
Left (Left_Index .. Left'Last),
Left_Last,
Left_Code,
Left_Is_Illegal_Sequence);
Get (
Right (Right_Index .. Right'Last),
Right_Last,
Right_Code,
Right_Is_Illegal_Sequence);
if not Left_Is_Illegal_Sequence then
if not Right_Is_Illegal_Sequence then
-- Left and Right are legal
Left_Code := Naked_Maps.Value (Mapping.all, Left_Code);
Right_Code := Naked_Maps.Value (Mapping.all, Right_Code);
if Left_Code /= Right_Code then
return False;
end if;
else
-- Left is legal, Right is illegal
return False;
end if;
else
if not Right_Is_Illegal_Sequence then
-- Left is illegal, Right is legal
return False;
else
-- Left and Right are illegal
if Left (Left_Index .. Left_Last) /=
Right (Right_Index .. Right_Last)
then
return False;
end if;
end if;
end if;
end;
end loop;
return (Left_Last >= Left'Last) and then (Right_Last >= Right'Last);
end Ada.Strings.Generic_Equal_Case_Insensitive;
|
with Command_Line_Interface; use Command_Line_Interface;
with String_Pkg; use String_Pkg;
--VAX with Vms_Lib;
separate (Ayacc.Initialize)
procedure Get_Arguments (File : out String_Type;
C_Lex : out Switch;
Debug : out Switch;
Summary : out Switch;
Verbose : out Switch;
-- UMASS CODES :
Error_Recovery : out Switch;
-- END OF UMASS CODES.
Extension : out String_Type) is
C_Lex_Argument : String_Type;
Debug_Argument : String_Type;
Summary_Argument : String_Type;
Verbose_Argument : String_Type;
-- UMASS CODES :
Error_Recovery_Argument : String_Type;
-- END OF UMASS CODES.
Positional : Natural := 0;
-- Number of positional parameters
Total : Natural := 0;
-- Total number of parameters
Max_Parameters : constant := 7;
Incorrect_Call : exception;
---- function Convert_Switch is new
---- Convert (Parameter_Type => Switch,
---- Type_Name => "Switch");
function Convert_Switch (P: in String) return Switch is
begin
return Switch'Value ( P );
exception
when Constraint_Error =>
----CLI_Error ("Invalid Parameter, """ &
---- Value (Mixed (Parameter_Text)) &
---- """ is not a legal value for type " &
---- Value (Mixed (Type_Name)) & '.');
raise Invalid_Parameter;
end Convert_Switch;
procedure Put_Help_Message is
begin
New_Line;
Put_Line (" -- Ayacc: An Ada Parser Generator.");
New_Line;
Put_Line (" type Switch is (On, Off);");
New_Line;
Put_Line (" procedure Ayacc (File : in String;");
Put_Line (" C_Lex : in Switch := Off;");
Put_Line (" Debug : in Switch := Off;");
Put_Line (" Summary : in Switch := On;");
Put_Line (" Verbose : in Switch := Off;");
-- UMASS CODES :
Put_Line (" Error_Recovery : in Switch := Off;");
-- END OF UMASS CODES.
Put_Line (" Extension : in String := "".adb"");");
New_Line;
Put_Line (" -- File Specifies the Ayacc Input Source File.");
Put_Line (" -- C_Lex Specifies the Generation of a 'C' Lex Interface.");
Put_Line (" -- Debug Specifies the Production of Debugging Output");
Put_Line (" -- By the Generated Parser.");
Put_Line (" -- Summary Specifies the Printing of Statistics About the");
Put_Line (" -- Generated Parser.");
Put_Line (" -- Verbose Specifies the Production of a Human Readable");
Put_Line (" -- Report of States in the Generated Parser.");
-- UMASS CODES :
Put_Line (" -- Error_Recovery Specifies the Generation of extension of");
Put_Line (" -- error recovery.");
-- END OF UMASS CODES.
Put_Line (" -- Extension Specifies the file extension to be used for");
Put_Line (" generated Ada files.");
New_Line;
end Put_Help_Message;
begin
--VAX Vms_Lib.Set_Error;
Command_Line_Interface.Initialize (Tool_Name => "Ayacc");
Positional := Positional_Arg_Count;
Total := Named_Arg_Count + Positional;
if Total = 0 then
raise Incorrect_Call;
elsif Total > Max_Parameters then
Put_Line ("Ayacc: Too many parameters.");
raise Incorrect_Call;
end if;
-- Get named values
File := Named_Arg_Value ("File", "");
C_Lex_Argument := Named_Arg_Value ("C_Lex", "Off");
Debug_Argument := Named_Arg_Value ("Debug", "Off");
Summary_Argument := Named_Arg_Value ("Summary", "On");
Verbose_Argument := Named_Arg_Value ("Verbose", "Off");
-- UMASS CODES :
Error_Recovery_Argument := Named_Arg_Value ("Error_Recovery", "Off");
-- END OF UMASS CODES.
Extension := Named_Arg_Value ("Extension", ".a");
-- Get any positional associations
if Positional >= 1 then
File := Positional_Arg_Value (1);
if Positional >= 2 then
C_Lex_Argument := Positional_Arg_Value (2);
if Positional >= 3 then
Debug_Argument := Positional_Arg_Value (3);
if Positional >= 4 then
Summary_Argument := Positional_Arg_Value (4);
if Positional >= 5 then
Verbose_Argument := Positional_Arg_Value (5);
-- UMASS CODES :
if Positional >= 6 then
Error_Recovery_Argument := Positional_Arg_Value (5);
-- END OF UMASS CODES.
if Positional = Max_Parameters then
Extension := Positional_Arg_Value (Max_Parameters);
end if;
-- UMASS CODES :
end if;
-- END OF UMASS CODES.
end if;
end if;
end if;
end if;
end if;
Command_Line_Interface.Finalize;
C_Lex := Convert_Switch (Value (C_Lex_Argument));
Debug := Convert_Switch (Value (Debug_Argument));
Summary := Convert_Switch (Value (Summary_Argument));
Verbose := Convert_Switch (Value (Verbose_Argument));
-- UMASS CODES :
Error_Recovery := Convert_Switch (Value (Error_Recovery_Argument));
-- END OF UMASS CODES.
exception
when Incorrect_Call | Invalid_Parameter |
Invalid_Parameter_Order | Missing_Positional_Arg |
Unreferenced_Named_Arg | Invalid_Named_Association |
Unbalanced_Parentheses =>
Put_Help_Message ;
raise Invalid_Command_Line ;
end Get_Arguments;
|
--------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2013-2020, Luke A. Guest
--
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
--
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
--
-- 1. The origin of this software must not be misrepresented; you must not
-- claim that you wrote the original software. If you use this software
-- in a product, an acknowledgment in the product documentation would be
-- appreciated but is not required.
--
-- 2. Altered source versions must be plainly marked as such, and must not be
-- misrepresented as being the original software.
--
-- 3. This notice may not be removed or altered from any source
-- distribution.
--------------------------------------------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with Interfaces.C;
private with SDL.C_Pointers;
with SDL.Error;
package body SDL.Video.Textures.Makers is
package C renames Interfaces.C;
use type SDL.C_Pointers.Texture_Pointer;
function Get_Internal_Surface (Self : in SDL.Video.Surfaces.Surface)
return SDL.Video.Surfaces.Internal_Surface_Pointer with
Import => True,
Convention => Ada;
function Get_Internal_Renderer (Self : in SDL.Video.Renderers.Renderer) return SDL.C_Pointers.Renderer_Pointer with
Import => True,
Convention => Ada;
procedure Create
(Tex : in out Texture;
Renderer : in SDL.Video.Renderers.Renderer;
Format : in SDL.Video.Pixel_Formats.Pixel_Format_Names;
Kind : in Kinds;
Size : in SDL.Positive_Sizes) is
-- Convert the Pixel_Format_Name to an Unsigned_32 because the compiler is changing the value somewhere along
-- the lines from the start of this procedure to calling SDL_Create_Texture.
function To_Unsigned32 is new Ada.Unchecked_Conversion (Source => SDL.Video.Pixel_Formats.Pixel_Format_Names,
Target => Interfaces.Unsigned_32);
function SDL_Create_Texture
(R : in SDL.C_Pointers.Renderer_Pointer;
Format : in Interfaces.Unsigned_32;
Kind : in Kinds;
W, H : in C.int) return SDL.C_Pointers.Texture_Pointer with
Import => True,
Convention => C,
External_Name => "SDL_CreateTexture";
begin
Tex.Internal := SDL_Create_Texture (Get_Internal_Renderer (Renderer),
To_Unsigned32 (Format),
Kind,
Size.Width,
Size.Height);
if Tex.Internal = null then
raise Texture_Error with SDL.Error.Get;
end if;
Tex.Size := Size;
Tex.Pixel_Format := Format;
end Create;
procedure Create
(Tex : in out Texture;
Renderer : in SDL.Video.Renderers.Renderer;
Surface : in SDL.Video.Surfaces.Surface) is
function SDL_Create_Texture_From_Surface (R : in SDL.C_Pointers.Renderer_Pointer;
S : in SDL.Video.Surfaces.Internal_Surface_Pointer)
return SDL.C_Pointers.Texture_Pointer with
Import => True,
Convention => C,
External_Name => "SDL_CreateTextureFromSurface";
begin
Tex.Internal := SDL_Create_Texture_From_Surface (Get_Internal_Renderer (Renderer),
Get_Internal_Surface (Surface));
if Tex.Internal = null then
raise Texture_Error with SDL.Error.Get;
end if;
end Create;
end SDL.Video.Textures.Makers;
|
pragma Ada_2012;
package body Tokenize.Token_Vectors is
---------------
-- To_Vector --
---------------
function To_Vector (X : Token_Array) return Vector is
Result : Vector;
begin
for Tk of X loop
Result.Append (To_String (Tk));
end loop;
return Result;
end To_Vector;
end Tokenize.Token_Vectors;
|
package body Account.Default_Account is
procedure Set_Name(Item: in out Instance;
N: in String) is
begin
Item.Name := Ada.Strings.Unbounded.To_Unbounded_String(N);
end Set_Name;
function Name(Item: in Instance) return String is
begin
return Ada.Strings.Unbounded.To_String(Item.Name);
end Name;
procedure Set_Site(Item: in out Instance;
S: in String) is
begin
Item.Site := Ada.Strings.Unbounded.To_Unbounded_String(S);
end Set_Site;
function Site(Item: in Instance) return String is
begin
return Ada.Strings.Unbounded.To_String(Item.Site);
end Site;
procedure Set_Account_Name(Item: in out Instance;
AN: in String) is
begin
Item.Acc := Ada.Strings.Unbounded.To_Unbounded_String(AN);
end Set_Account_Name;
function Account_Name(Item: in Instance) return String is
begin
return Ada.Strings.Unbounded.To_String(Item.Acc);
end Account_Name;
procedure Set_Password(Item: in out Instance;
P: in String) is
begin
Item.Password := Ada.Strings.Unbounded.To_Unbounded_String(P);
end Set_Password;
function Password(Item: in Instance) return String is
begin
return Ada.Strings.Unbounded.To_String(Item.Password);
end Password;
procedure Set_Desc(Item: in out Instance;
D: in String) is
begin
Item.Desc := Ada.Strings.Unbounded.To_Unbounded_String(D);
end Set_Desc;
function Desc(Item: in Instance) return String is
begin
return Ada.Strings.Unbounded.To_String(Item.Desc);
end Desc;
end Account.Default_Account;
|
with impact.d2.Fixture,
impact.d2.Solid;
package body impact.d2.contact.Manager
is
use type int32;
type default_Listener is new world_Callbacks.b2ContactListener with null record;
b2_defaultListener : aliased default_Listener;
b2_defaultFilter : aliased world_Callbacks.b2ContactFilter;
function to_b2ContactManager return b2ContactManager
is
Self : b2ContactManager;
begin
Self.m_contactCount := 0;
Self.m_contactFilter := b2_defaultFilter'Access;
Self.m_contactListener := b2_defaultListener'Access;
return Self;
end to_b2ContactManager;
procedure Destroy (Self : in out b2ContactManager; c : in out impact.d2.Contact.view)
is
use type Contact.view;
fixtureA : constant access Fixture.b2Fixture := c.GetFixtureA;
fixtureB : constant access Fixture.b2Fixture := c.GetFixtureB;
bodyA : constant access Solid.b2Body'Class := fixtureA.GetBody;
bodyB : constant access Solid.b2Body'Class := fixtureB.GetBody;
begin
if Self.m_contactListener /= null
and then c.IsTouching
then
Self.m_contactListener.EndContact (c);
end if;
-- Remove from the world.
if c.m_prev /= null then
c.m_prev.m_next_is (c.m_next);
end if;
if c.m_next /= null then
c.m_next.m_prev_is (c.m_prev);
end if;
if c = Self.m_contactList then
Self.m_contactList := c.m_next;
end if;
-- Remove from body 1
if c.m_nodeA.prev /= null then
c.m_nodeA.prev.next := c.m_nodeA.next;
end if;
if c.m_nodeA.next /= null then
c.m_nodeA.next.prev := c.m_nodeA.prev;
end if;
if c.m_nodeA'Access = bodyA.getContactList then
bodyA.m_contactList_is (c.m_nodeA.next);
end if;
-- Remove from body 2
if c.m_nodeB.prev /= null then
c.m_nodeB.prev.next := c.m_nodeB.next;
end if;
if c.m_nodeB.next /= null then
c.m_nodeB.next.prev := c.m_nodeB.prev;
end if;
if c.m_nodeB'Access = bodyB.getContactList then
bodyB.m_contactList_is (c.m_nodeB.next);
end if;
-- Call the factory.
Contact.Destroy (c); --, m_allocator);
Self.m_contactCount := Self.m_contactCount - 1;
end Destroy;
-- This is the top level collision call for the time step. Here
-- all the narrow phase collision is processed for the world
-- contact list.
--
procedure Collide (Self : in out b2ContactManager)
is
use type Contact.view;
c : Contact.view := Contact.view (Self.m_contactList);
begin
-- Update awake contacts.
while c /= null loop
declare
fixtureA : constant access Fixture.b2Fixture'Class := c.GetFixtureA;
fixtureB : constant access Fixture.b2Fixture'Class := c.GetFixtureB;
bodyA : constant access Solid.b2Body'Class := fixtureA.GetBody;
bodyB : constant access Solid.b2Body'Class := fixtureB.GetBody;
procedure check
is
use type uint32;
cNuke : Contact.view;
proxyIdA,
proxyIdB : int32;
overlap : Boolean;
begin
-- Is this contact flagged for filtering?
if (c.m_flags and Contact.e_filterFlag) /= 0 then
-- Should these bodies collide?
if not bodyB.ShouldCollide (bodyA) then
cNuke := c;
c := cNuke.GetNext;
Destroy (cNuke);
return;
end if;
-- Check user filtering.
if Self.m_contactFilter /= null
and then not Self.m_contactFilter.ShouldCollide (fixtureA, fixtureB)
then
cNuke := c;
c := cNuke.GetNext;
Destroy (cNuke);
return;
end if;
-- Clear the filtering flag.
c.m_flags := c.m_flags and not Contact.e_filterFlag;
end if;
proxyIdA := fixtureA.m_proxyId;
proxyIdB := fixtureB.m_proxyId;
overlap := Self.m_broadPhase.TestOverlap (proxyIdA, proxyIdB);
-- Here we destroy contacts that cease to overlap in the broad-phase.
if not overlap then
cNuke := c;
c := cNuke.GetNext;
Destroy (cNuke);
return;
end if;
-- The contact persists.
c.Update (Self.m_contactListener);
c := c.GetNext;
end check;
begin
if not bodyA.IsAwake and then not bodyB.IsAwake then
c := c.GetNext;
else
check;
end if;
end;
end loop;
end Collide;
procedure FindNewContacts (Self : in out b2ContactManager)
is
procedure update_Pairs is new broadphase.UpdatePairs (callback_t => b2ContactManager,
addPair => manager.addPair);
begin
update_Pairs (self.m_broadPhase, Self'Access);
end FindNewContacts;
type Solid_view is access all Solid.b2Body'Class;
-- Broad-phase callback.
--
procedure addPair (Self : access b2ContactManager; userDataA, userDataB : access Any'Class)
is
fixtureA : access Fixture.b2Fixture := Fixture.view (userDataA);
fixtureB : access Fixture.b2Fixture := Fixture.view (userDataB);
-- b2Fixture* fixtureB = (b2Fixture*)proxyUserDataB;
bodyA : Solid_view := fixtureA.GetBody.all'Access;
bodyB : Solid_view := fixtureB.GetBody.all'Access;
-- b2Body* bodyB = fixtureB.GetBody();
edge : access b2ContactEdge;
c : Contact.view;
begin
-- Are the fixtures on the same body?
if bodyA = bodyB then
return;
end if;
-- Does a contact already exist?
edge := bodyB.GetContactList;
while edge /= null loop
if edge.other = bodyA then
declare
fA : constant access Fixture.b2Fixture := edge.contact.GetFixtureA;
fB : constant access Fixture.b2Fixture := edge.contact.GetFixtureB;
-- b2Fixture* fB := edge.contact.GetFixtureB();
begin
if fA = fixtureA and then fB = fixtureB then
-- A contact already exists.
return;
end if;
if fA = fixtureB and then fB = fixtureA then
-- A contact already exists.
return;
end if;
end;
end if;
edge := edge.next;
end loop;
-- Does a joint override collision? Is at least one body dynamic?
if bodyB.ShouldCollide (bodyA) = False then
return;
end if;
-- Check user filtering.
if Self.m_contactFilter /= null
and then not Self.m_contactFilter.ShouldCollide (fixtureA, fixtureB)
then
return;
end if;
-- Call the factory.
c := Contact.create (fixtureA, fixtureB).all'Access; --, m_allocator);
-- Contact creation may swap fixtures.
fixtureA := c.GetFixtureA;
fixtureB := c.GetFixtureB;
bodyA := fixtureA.GetBody.all'Access;
bodyB := fixtureB.GetBody.all'Access;
-- Insert into the world.
c.m_prev := null;
c.m_next := Contact.view (Self.m_contactList); --.all'unchecked_access;
if Self.m_contactList /= null then
Self.m_contactList.m_prev := Contact.view (c);
end if;
Self.m_contactList := c;
-- Connect to island graph.
-- Connect to body A
c.m_nodeA.contact := c;
c.m_nodeA.other := bodyB;
c.m_nodeA.prev := null;
c.m_nodeA.next := bodyA.m_contactList;
if bodyA.m_contactList /= null then
bodyA.m_contactList.prev := c.m_nodeA'Access;
end if;
bodyA.m_contactList_is (c.m_nodeA'Access);
-- Connect to body B
c.m_nodeB.contact := c;
c.m_nodeB.other := bodyA;
c.m_nodeB.prev := null;
c.m_nodeB.next := bodyB.m_contactList;
if bodyB.m_contactList /= null then
bodyB.m_contactList.prev := c.m_nodeB'Access;
end if;
bodyB.m_contactList_is (c.m_nodeB'Access);
Self.m_contactCount := Self.m_contactCount + 1;
end addPair;
end impact.d2.contact.Manager;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- F R O N T E N D --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2016, 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 System.Strings; use System.Strings;
with Atree; use Atree;
with Checks;
with CStand;
with Debug; use Debug;
with Elists;
with Exp_Dbug;
with Exp_Unst;
with Fmap;
with Fname.UF;
with Ghost; use Ghost;
with Inline; use Inline;
with Lib; use Lib;
with Lib.Load; use Lib.Load;
with Lib.Xref; use Lib.Xref;
with Live; use Live;
with Namet; use Namet;
with Nlists; use Nlists;
with Opt; use Opt;
with Osint;
with Par;
with Prep;
with Prepcomp;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Snames; use Snames;
with Sprint;
with Scn; use Scn;
with Sem; use Sem;
with Sem_Aux;
with Sem_Ch8; use Sem_Ch8;
with Sem_SCIL;
with Sem_Elab; use Sem_Elab;
with Sem_Prag; use Sem_Prag;
with Sem_Warn; use Sem_Warn;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
with Sinput.L; use Sinput.L;
with SCIL_LL; use SCIL_LL;
with Tbuild; use Tbuild;
with Types; use Types;
procedure Frontend is
Config_Pragmas : List_Id;
-- Gather configuration pragmas
begin
-- Carry out package initializations. These are initializations which might
-- logically be performed at elaboration time, were it not for the fact
-- that we may be doing things more than once in the big loop over files.
-- Like elaboration, the order in which these calls are made is in some
-- cases important. For example, Lib cannot be initialized before Namet,
-- since it uses names table entries.
Rtsfind.Initialize;
Nlists.Initialize;
Elists.Initialize;
Lib.Load.Initialize;
Sem_Aux.Initialize;
Sem_Ch8.Initialize;
Sem_Prag.Initialize;
Fname.UF.Initialize;
Checks.Initialize;
Sem_Warn.Initialize;
Prep.Initialize;
if Generate_SCIL then
SCIL_LL.Initialize;
end if;
-- Create package Standard
CStand.Create_Standard;
-- Check possible symbol definitions specified by -gnateD switches
Prepcomp.Process_Command_Line_Symbol_Definitions;
-- If -gnatep= was specified, parse the preprocessing data file
if Preprocessing_Data_File /= null then
Name_Len := Preprocessing_Data_File'Length;
Name_Buffer (1 .. Name_Len) := Preprocessing_Data_File.all;
Prepcomp.Parse_Preprocessing_Data_File (Name_Find);
-- Otherwise, check if there were preprocessing symbols on the command
-- line and set preprocessing if there are.
else
Prepcomp.Check_Symbols;
end if;
-- We set Parsing_Main_Extended_Source true here to cover processing of all
-- the configuration pragma files, as well as the main source unit itself.
Parsing_Main_Extended_Source := True;
-- Now that the preprocessing situation is established, we are able to
-- load the main source (this is no longer done by Lib.Load.Initialize).
Lib.Load.Load_Main_Source;
-- Return immediately if the main source could not be found
if Sinput.Main_Source_File = No_Source_File then
return;
end if;
-- Read and process configuration pragma files if present
declare
Save_Style_Check : constant Boolean := Opt.Style_Check;
-- Save style check mode so it can be restored later
Source_Config_File : Source_File_Index;
-- Source reference for -gnatec configuration file
Prag : Node_Id;
Temp_File : Boolean;
begin
-- We always analyze config files with style checks off, since we
-- don't want a miscellaneous gnat.adc that is around to discombobulate
-- intended -gnatg or -gnaty compilations. We also disconnect checking
-- for maximum line length.
Opt.Style_Check := False;
Style_Check := False;
-- Capture current suppress options, which may get modified
Scope_Suppress := Opt.Suppress_Options;
-- First deal with gnat.adc file
if Opt.Config_File then
Name_Buffer (1 .. 8) := "gnat.adc";
Name_Len := 8;
Source_gnat_adc := Load_Config_File (Name_Enter);
-- Case of gnat.adc file present
if Source_gnat_adc /= No_Source_File then
-- Parse the gnat.adc file for configuration pragmas
Initialize_Scanner (No_Unit, Source_gnat_adc);
Config_Pragmas := Par (Configuration_Pragmas => True);
-- We unconditionally add a compilation dependency for gnat.adc
-- so that if it changes, we force a recompilation. This is a
-- fairly recent (2014-03-28) change.
Prepcomp.Add_Dependency (Source_gnat_adc);
-- Case of no gnat.adc file present
else
Config_Pragmas := Empty_List;
end if;
else
Config_Pragmas := Empty_List;
end if;
-- Now deal with specified config pragmas files if there are any
if Opt.Config_File_Names /= null then
-- Loop through config pragmas files
for Index in Opt.Config_File_Names'Range loop
-- See if extension is .TMP/.tmp indicating a temporary config
-- file (which we ignore from the dependency point of view).
Name_Len := Config_File_Names (Index)'Length;
Name_Buffer (1 .. Name_Len) := Config_File_Names (Index).all;
Temp_File :=
Name_Len > 4
and then
(Name_Buffer (Name_Len - 3 .. Name_Len) = ".TMP"
or else
Name_Buffer (Name_Len - 3 .. Name_Len) = ".tmp");
-- Load the file, error if we did not find it
Source_Config_File := Load_Config_File (Name_Enter);
if Source_Config_File = No_Source_File then
Osint.Fail
("cannot find configuration pragmas file "
& Config_File_Names (Index).all);
-- If we did find the file, and it is not a temporary file, then
-- we unconditionally add a compilation dependency for it so
-- that if it changes, we force a recompilation. This is a
-- fairly recent (2014-03-28) change.
elsif not Temp_File then
Prepcomp.Add_Dependency (Source_Config_File);
end if;
-- Parse the config pragmas file, and accumulate results
Initialize_Scanner (No_Unit, Source_Config_File);
Append_List_To
(Config_Pragmas, Par (Configuration_Pragmas => True));
end loop;
end if;
-- Now analyze all pragmas except those whose analysis must be
-- deferred till after the main unit is analyzed.
if Config_Pragmas /= Error_List
and then Operating_Mode /= Check_Syntax
then
Prag := First (Config_Pragmas);
while Present (Prag) loop
if not Delay_Config_Pragma_Analyze (Prag) then
Analyze_Pragma (Prag);
end if;
Next (Prag);
end loop;
end if;
-- Restore style check, but if config file turned on checks, leave on
Opt.Style_Check := Save_Style_Check or Style_Check;
-- Capture any modifications to suppress options from config pragmas
Opt.Suppress_Options := Scope_Suppress;
end;
-- If a target dependency info file has been read through switch -gnateT=,
-- add it to the dependencies.
if Target_Dependent_Info_Read_Name /= null then
declare
Index : Source_File_Index;
begin
Name_Len := 0;
Add_Str_To_Name_Buffer (Target_Dependent_Info_Read_Name.all);
Index := Load_Config_File (Name_Enter);
Prepcomp.Add_Dependency (Index);
end;
end if;
-- This is where we can capture the value of the compilation unit specific
-- restrictions that have been set by the config pragma files (or from
-- Targparm), for later restoration when processing e.g. subunits.
Save_Config_Cunit_Boolean_Restrictions;
-- If there was a -gnatem switch, initialize the mappings of unit names to
-- file names and of file names to path names from the mapping file.
if Mapping_File_Name /= null then
Fmap.Initialize (Mapping_File_Name.all);
end if;
-- Adjust Optimize_Alignment mode from debug switches if necessary
if Debug_Flag_Dot_SS then
Optimize_Alignment := 'S';
elsif Debug_Flag_Dot_TT then
Optimize_Alignment := 'T';
end if;
-- We have now processed the command line switches, and the configuration
-- pragma files, so this is the point at which we want to capture the
-- values of the configuration switches (see Opt for further details).
Opt.Register_Opt_Config_Switches;
-- Check for file which contains No_Body pragma
if Source_File_Is_No_Body (Source_Index (Main_Unit)) then
Change_Main_Unit_To_Spec;
end if;
-- Initialize the scanner. Note that we do this after the call to
-- Create_Standard, which uses the scanner in its processing of
-- floating-point bounds.
Initialize_Scanner (Main_Unit, Source_Index (Main_Unit));
-- Here we call the parser to parse the compilation unit (or units in
-- the check syntax mode, but in that case we won't go on to the
-- semantics in any case).
Discard_List (Par (Configuration_Pragmas => False));
Parsing_Main_Extended_Source := False;
-- The main unit is now loaded, and subunits of it can be loaded,
-- without reporting spurious loading circularities.
Set_Loading (Main_Unit, False);
-- Now that the main unit is installed, we can complete the analysis
-- of the pragmas in gnat.adc and the configuration file, that require
-- a context for their semantic processing.
if Config_Pragmas /= Error_List
and then Operating_Mode /= Check_Syntax
-- Do not attempt to process deferred configuration pragmas if the main
-- unit failed to load, to avoid cascaded inconsistencies that can lead
-- to a compiler crash.
and then Fatal_Error (Main_Unit) /= Error_Detected
then
-- Pragmas that require some semantic activity, such as Interrupt_State,
-- cannot be processed until the main unit is installed, because they
-- require a compilation unit on which to attach with_clauses, etc. So
-- analyze them now.
declare
Prag : Node_Id;
begin
Prag := First (Config_Pragmas);
while Present (Prag) loop
-- Guard against the case where a configuration pragma may be
-- split into multiple pragmas and the original rewritten as a
-- null statement.
if Nkind (Prag) = N_Pragma
and then Delay_Config_Pragma_Analyze (Prag)
then
Analyze_Pragma (Prag);
end if;
Next (Prag);
end loop;
end;
end if;
-- If we have restriction No_Exception_Propagation, and we did not have an
-- explicit switch turning off Warn_On_Non_Local_Exception, then turn on
-- this warning by default if we have encountered an exception handler.
if Restriction_Check_Required (No_Exception_Propagation)
and then not No_Warn_On_Non_Local_Exception
and then Exception_Handler_Encountered
then
Warn_On_Non_Local_Exception := True;
end if;
-- Now on to the semantics. Skip if in syntax only mode
if Operating_Mode /= Check_Syntax then
-- Install the configuration pragmas in the tree
Set_Config_Pragmas (Aux_Decls_Node (Cunit (Main_Unit)), Config_Pragmas);
-- Following steps are skipped if we had a fatal error during parsing
if Fatal_Error (Main_Unit) /= Error_Detected then
-- Reset Operating_Mode to Check_Semantics for subunits. We cannot
-- actually generate code for subunits, so we suppress expansion.
-- This also corrects certain problems that occur if we try to
-- incorporate subunits at a lower level.
if Operating_Mode = Generate_Code
and then Nkind (Unit (Cunit (Main_Unit))) = N_Subunit
then
Operating_Mode := Check_Semantics;
end if;
-- Analyze (and possibly expand) main unit
Scope_Suppress := Suppress_Options;
Semantics (Cunit (Main_Unit));
-- Cleanup processing after completing main analysis
-- Comment needed for ASIS mode test and GNATprove mode test???
pragma Assert
(Operating_Mode = Generate_Code
or else Operating_Mode = Check_Semantics);
if Operating_Mode = Generate_Code
or else (ASIS_Mode or GNATprove_Mode)
then
Instantiate_Bodies;
end if;
-- Analyze inlined bodies and check elaboration rules in GNATprove
-- mode as well as during compilation.
if Operating_Mode = Generate_Code or else GNATprove_Mode then
if Inline_Processing_Required then
Analyze_Inlined_Bodies;
end if;
-- Remove entities from program that do not have any execution
-- time references.
if Debug_Flag_UU then
Collect_Garbage_Entities;
end if;
Check_Elab_Calls;
-- Remove any ignored Ghost code as it must not appear in the
-- executable.
Remove_Ignored_Ghost_Code;
end if;
-- At this stage we can unnest subprogram bodies if required
Exp_Unst.Unnest_Subprograms (Cunit (Main_Unit));
-- List library units if requested
if List_Units then
Lib.List;
end if;
-- Output waiting warning messages
Lib.Xref.Process_Deferred_References;
Sem_Warn.Output_Non_Modified_In_Out_Warnings;
Sem_Warn.Output_Unreferenced_Messages;
Sem_Warn.Check_Unused_Withs;
Sem_Warn.Output_Unused_Warnings_Off_Warnings;
end if;
end if;
-- Qualify all entity names in inner packages, package bodies, etc
Exp_Dbug.Qualify_All_Entity_Names;
-- SCIL backend requirement. Check that SCIL nodes associated with
-- dispatching calls reference subprogram calls.
if Generate_SCIL then
pragma Debug (Sem_SCIL.Check_SCIL_Nodes (Cunit (Main_Unit)));
null;
end if;
-- Dump the source now. Note that we do this as soon as the analysis
-- of the tree is complete, because it is not just a dump in the case
-- of -gnatD, where it rewrites all source locations in the tree.
Sprint.Source_Dump;
-- Check again for configuration pragmas that appear in the context
-- of the main unit. These pragmas only affect the main unit, and the
-- corresponding flag is reset after each call to Semantics, but they
-- may affect the generated ali for the unit, and therefore the flag
-- must be set properly after compilation. Currently we only check for
-- Initialize_Scalars, but others should be checked: as well???
declare
Item : Node_Id;
begin
Item := First (Context_Items (Cunit (Main_Unit)));
while Present (Item) loop
if Nkind (Item) = N_Pragma
and then Pragma_Name (Item) = Name_Initialize_Scalars
then
Initialize_Scalars := True;
end if;
Next (Item);
end loop;
end;
-- If a mapping file has been specified by a -gnatem switch, update
-- it if there has been some sources that were not in the mappings.
if Mapping_File_Name /= null then
Fmap.Update_Mapping_File (Mapping_File_Name.all);
end if;
return;
end Frontend;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . R I D E N T --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2005, 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 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, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, 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. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package defines the set of restriction identifiers. It is a generic
-- package that is instantiated by the compiler/binder in package Rident, and
-- is instantiated in package System.Restrictions for use at run-time.
-- The reason that we make this a generic package is so that in the case of
-- the instantiation in Rident for use at compile time and bind time, we can
-- generate normal image tables for the enumeration types, which are needed
-- for diagnostic and informational messages. At run-time we really do not
-- want to waste the space for these image tables, and they are not needed,
-- so we can do the instantiation under control of Discard_Names to remove
-- the tables.
generic
package System.Rident is
-- The following enumeration type defines the set of restriction
-- identifiers that are implemented in GNAT.
-- To add a new restriction identifier, add an entry with the name
-- to be used in the pragma, and add appropriate calls to the
-- Restrict.Check_Restriction routine.
type Restriction_Id is
-- The following cases are checked for consistency in the binder
(Simple_Barriers, -- GNAT (Ravenscar)
No_Abort_Statements, -- (RM D.7(5), H.4(3))
No_Access_Subprograms, -- (RM H.4(17))
No_Allocators, -- (RM H.4(7))
No_Asynchronous_Control, -- (RM D.7(10))
No_Calendar, -- GNAT
No_Delay, -- (RM H.4(21))
No_Direct_Boolean_Operators, -- GNAT
No_Dispatch, -- (RM H.4(19))
No_Dispatching_Calls, -- GNAT
No_Dynamic_Attachment, -- GNAT
No_Dynamic_Priorities, -- (RM D.9(9))
No_Enumeration_Maps, -- GNAT
No_Entry_Calls_In_Elaboration_Code, -- GNAT
No_Entry_Queue, -- GNAT (Ravenscar)
No_Exception_Handlers, -- GNAT
No_Exception_Registration, -- GNAT
No_Exceptions, -- (RM H.4(12))
No_Finalization, -- GNAT
No_Fixed_Point, -- (RM H.4(15))
No_Floating_Point, -- (RM H.4(14))
No_IO, -- (RM H.4(20))
No_Implicit_Conditionals, -- GNAT
No_Implicit_Dynamic_Code, -- GNAT
No_Implicit_Heap_Allocations, -- (RM D.8(8), H.4(3))
No_Implicit_Loops, -- GNAT
No_Initialize_Scalars, -- GNAT
No_Local_Allocators, -- (RM H.4(8))
No_Local_Protected_Objects, -- GNAT
No_Nested_Finalization, -- (RM D.7(4))
No_Protected_Type_Allocators, -- GNAT
No_Protected_Types, -- (RM H.4(5))
No_Recursion, -- (RM H.4(22))
No_Reentrancy, -- (RM H.4(23))
No_Relative_Delay, -- GNAT (Ravenscar)
No_Requeue_Statements, -- GNAT
No_Secondary_Stack, -- GNAT
No_Select_Statements, -- GNAT (Ravenscar)
No_Standard_Storage_Pools, -- GNAT
No_Streams, -- GNAT
No_Task_Allocators, -- (RM D.7(7))
No_Task_Attributes_Package, -- GNAT
No_Task_Hierarchy, -- (RM D.7(3), H.4(3))
No_Task_Termination, -- GNAT (Ravenscar)
No_Tasking, -- GNAT
No_Terminate_Alternatives, -- (RM D.7(6))
No_Unchecked_Access, -- (RM H.4(18))
No_Unchecked_Conversion, -- (RM H.4(16))
No_Unchecked_Deallocation, -- (RM H.4(9))
Static_Priorities, -- GNAT
Static_Storage_Size, -- GNAT
-- The following cases do not require partition-wide checks
Immediate_Reclamation, -- (RM H.4(10))
No_Implementation_Attributes, -- Ada 2005 AI-257
No_Implementation_Pragmas, -- Ada 2005 AI-257
No_Implementation_Restrictions, -- GNAT
No_Elaboration_Code, -- GNAT
No_Obsolescent_Features, -- Ada 2005 AI-368
No_Wide_Characters, -- GNAT
-- The following cases require a parameter value
-- The following entries are fully checked at compile/bind time,
-- which means that the compiler can in general tell the minimum
-- value which could be used with a restrictions pragma. The binder
-- can deduce the appropriate minimum value for the partition by
-- taking the maximum value required by any unit.
Max_Protected_Entries, -- (RM D.7(14))
Max_Select_Alternatives, -- (RM D.7(12))
Max_Task_Entries, -- (RM D.7(13), H.4(3))
-- The following entries are also fully checked at compile/bind
-- time, and the compiler can also at least in some cases tell
-- the minimum value which could be used with a restriction pragma.
-- The difference is that the contributions are additive, so the
-- binder deduces this value by adding the unit contributions.
Max_Tasks, -- (RM D.7(19), H.4(3))
-- The following entries are checked at compile time only for
-- zero/nonzero entries. This means that the compiler can tell
-- at compile time if a restriction value of zero is (would be)
-- violated, but that is all. The compiler cannot distinguish
-- between different non-zero values.
Max_Asynchronous_Select_Nesting, -- (RM D.7(18), H.4(3))
Max_Entry_Queue_Length, -- GNAT
-- The remaining entries are not checked at compile/bind time
Max_Storage_At_Blocking, -- (RM D.7(17))
Not_A_Restriction_Id);
-- Synonyms permitted for historical purposes of compatibility.
-- Must be coordinated with Restrict.Process_Restriction_Synonym.
Boolean_Entry_Barriers : Restriction_Id renames Simple_Barriers;
Max_Entry_Queue_Depth : Restriction_Id renames Max_Entry_Queue_Length;
No_Dynamic_Interrupts : Restriction_Id renames No_Dynamic_Attachment;
No_Requeue : Restriction_Id renames No_Requeue_Statements;
No_Task_Attributes : Restriction_Id renames No_Task_Attributes_Package;
subtype All_Restrictions is Restriction_Id range
Simple_Barriers .. Max_Storage_At_Blocking;
-- All restrictions (excluding only Not_A_Restriction_Id)
subtype All_Boolean_Restrictions is Restriction_Id range
Simple_Barriers .. No_Wide_Characters;
-- All restrictions which do not take a parameter
subtype Partition_Boolean_Restrictions is All_Boolean_Restrictions range
Simple_Barriers .. Static_Storage_Size;
-- Boolean restrictions that are checked for partition consistency.
-- Note that all parameter restrictions are checked for partition
-- consistency by default, so this distinction is only needed in the
-- case of Boolean restrictions.
subtype Cunit_Boolean_Restrictions is All_Boolean_Restrictions range
Immediate_Reclamation .. No_Wide_Characters;
-- Boolean restrictions that are not checked for partition consistency
-- and that thus apply only to the current unit. Note that for these
-- restrictions, the compiler does not apply restrictions found in
-- with'ed units, parent specs etc to the main unit.
subtype All_Parameter_Restrictions is
Restriction_Id range
Max_Protected_Entries .. Max_Storage_At_Blocking;
-- All restrictions that are take a parameter
subtype Checked_Parameter_Restrictions is
All_Parameter_Restrictions range
Max_Protected_Entries .. Max_Entry_Queue_Length;
-- These are the parameter restrictions that can be at least partially
-- checked at compile/binder time. Minimally, the compiler can detect
-- violations of a restriction pragma with a value of zero reliably.
subtype Checked_Max_Parameter_Restrictions is
Checked_Parameter_Restrictions range
Max_Protected_Entries .. Max_Task_Entries;
-- Restrictions with parameters that can be checked in some cases by
-- maximizing among statically detected instances where the compiler
-- can determine the count.
subtype Checked_Add_Parameter_Restrictions is
Checked_Parameter_Restrictions range
Max_Tasks .. Max_Tasks;
-- Restrictions with parameters that can be checked in some cases by
-- summing the statically detected instances where the compiler can
-- determine the count.
subtype Checked_Val_Parameter_Restrictions is
Checked_Parameter_Restrictions range
Max_Protected_Entries .. Max_Tasks;
-- Restrictions with parameter where the count is known at least in
-- some cases by the compiler/binder.
subtype Checked_Zero_Parameter_Restrictions is
Checked_Parameter_Restrictions range
Max_Asynchronous_Select_Nesting .. Max_Entry_Queue_Length;
-- Restrictions with parameters where the compiler can detect the use of
-- the feature, and hence violations of a restriction specifying a value
-- of zero, but cannot detect specific values other than zero/nonzero.
subtype Unchecked_Parameter_Restrictions is
All_Parameter_Restrictions range
Max_Storage_At_Blocking .. Max_Storage_At_Blocking;
-- Restrictions with parameters where the compiler cannot ever detect
-- corresponding compile time usage, so the binder and compiler never
-- detect violations of any restriction.
-------------------------------------
-- Restriction Status Declarations --
-------------------------------------
-- The following declarations are used to record the current status
-- or restrictions (for the current unit, or related units, at compile
-- time, and for all units in a partition at bind time or run time).
type Restriction_Flags is array (All_Restrictions) of Boolean;
type Restriction_Values is array (All_Parameter_Restrictions) of Natural;
type Parameter_Flags is array (All_Parameter_Restrictions) of Boolean;
type Restrictions_Info is record
Set : Restriction_Flags := (others => False);
-- An entry is True in the Set array if a restrictions pragma has
-- been encountered for the given restriction. If the value is
-- True for a parameter restriction, then the corresponding entry
-- in the Value array gives the minimum value encountered for any
-- such restriction.
Value : Restriction_Values;
-- If the entry for a parameter restriction in Set is True (i.e. a
-- restrictions pragma for the restriction has been encountered), then
-- the corresponding entry in the Value array is the minimum value
-- specified by any such restrictions pragma. Note that a restrictions
-- pragma specifying a value greater than Int'Last is simply ignored.
Violated : Restriction_Flags := (others => False);
-- An entry is True in the violations array if the compiler has
-- detected a violation of the restriction. For a parameter
-- restriction, the Count and Unknown arrays have additional
-- information.
Count : Restriction_Values := (others => 0);
-- If an entry for a parameter restriction is True in Violated,
-- the corresponding entry in the Count array may record additional
-- information. If the actual minimum count is known (by taking
-- maximums, or sums, depending on the restriction), it will be
-- recorded in this array. If not, then the value will remain zero.
Unknown : Parameter_Flags := (others => False);
-- If an entry for a parameter restriction is True in Violated,
-- the corresponding entry in the Unknown array may record additional
-- information. If the actual count is not known by the compiler (but
-- is known to be non-zero), then the entry in Unknown will be True.
-- This indicates that the value in Count is not known to be exact,
-- and the actual violation count may be higher.
-- Note: If Violated (K) is True, then either Count (K) > 0 or
-- Unknown (K) = True. It is possible for both these to be set.
-- For example, if Count (K) = 3 and Unknown (K) is True, it means
-- that the actual violation count is at least 3 but might be higher.
end record;
----------------------------------
-- Profile Definitions and Data --
----------------------------------
type Profile_Name is (Ravenscar, Restricted);
-- Names of recognized pfofiles
type Profile_Data is record
Set : Restriction_Flags;
-- Set to True if given restriction must be set for the profile,
-- and False if it need not be set (False does not mean that it
-- must not be set, just that it need not be set). If the flag
-- is True for a parameter restriction, then the Value array
-- gives the maximum value permitted by the profile.
Value : Restriction_Values;
-- An entry in this array is meaningful only if the corresponding
-- flag in Set is True. In that case, the value in this array is
-- the maximum value of the parameter permitted by the profile.
end record;
Profile_Info : array (Profile_Name) of Profile_Data :=
-- Restricted Profile
(Restricted =>
-- Restrictions for Restricted profile
(Set =>
(No_Abort_Statements => True,
No_Asynchronous_Control => True,
No_Dynamic_Attachment => True,
No_Dynamic_Priorities => True,
No_Entry_Queue => True,
No_Local_Protected_Objects => True,
No_Protected_Type_Allocators => True,
No_Requeue_Statements => True,
No_Task_Allocators => True,
No_Task_Attributes_Package => True,
No_Task_Hierarchy => True,
No_Terminate_Alternatives => True,
Max_Asynchronous_Select_Nesting => True,
Max_Protected_Entries => True,
Max_Select_Alternatives => True,
Max_Task_Entries => True,
others => False),
-- Value settings for Restricted profile
Value =>
(Max_Asynchronous_Select_Nesting => 0,
Max_Protected_Entries => 1,
Max_Select_Alternatives => 0,
Max_Task_Entries => 0,
others => 0)),
-- Ravenscar Profile
-- Note: the table entries here only represent the
-- required restriction profile for Ravenscar. The
-- full Ravenscar profile also requires:
-- pragma Dispatching_Policy (FIFO_Within_Priorities);
-- pragma Locking_Policy (Ceiling_Locking);
-- pragma Detect_Blocking
Ravenscar =>
-- Restrictions for Ravenscar = Restricted profile ..
(Set =>
(No_Abort_Statements => True,
No_Asynchronous_Control => True,
No_Dynamic_Attachment => True,
No_Dynamic_Priorities => True,
No_Entry_Queue => True,
No_Local_Protected_Objects => True,
No_Protected_Type_Allocators => True,
No_Requeue_Statements => True,
No_Task_Allocators => True,
No_Task_Attributes_Package => True,
No_Task_Hierarchy => True,
No_Terminate_Alternatives => True,
Max_Asynchronous_Select_Nesting => True,
Max_Protected_Entries => True,
Max_Select_Alternatives => True,
Max_Task_Entries => True,
-- plus these additional restrictions:
No_Calendar => True,
No_Implicit_Heap_Allocations => True,
No_Relative_Delay => True,
No_Select_Statements => True,
No_Task_Termination => True,
Simple_Barriers => True,
others => False),
-- Value settings for Ravenscar (same as Restricted)
Value =>
(Max_Asynchronous_Select_Nesting => 0,
Max_Protected_Entries => 1,
Max_Select_Alternatives => 0,
Max_Task_Entries => 0,
others => 0)));
end System.Rident;
|
pragma License (GPL);
------------------------------------------------------------------------------
-- EMAIL: <darkestkhan@gmail.com> --
-- License: GNU GPLv3 or any later as published by Free Software Foundation --
-- (see README file) --
-- Copyright © 2013, 2015 darkestkhan --
------------------------------------------------------------------------------
-- This Program is Free Software: You can redistribute it and/or modify --
-- it under the terms of The GNU General Public License as published by --
-- the Free Software Foundation, either version 3 of the license, or --
-- (at Your option) any later version. --
-- --
-- This Program is distributed in the hope that it will be useful, --
-- but WITHOUT 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 --
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
------------------------------------------------------------------------------
--------------------------------------------------------------------------
-- Test ability to read content of variables and their default values --
-- if not set. --
--------------------------------------------------------------------------
with Ada.Environment_Variables;
with Ada.Command_Line;
with Ada.Text_IO;
with XDG;
procedure XDG_Vars is
package EV renames Ada.Environment_Variables;
package TIO renames Ada.Text_IO;
package CLI renames Ada.Command_Line;
type String_Access is access String;
type XDG_Variable is
( Data_Home, Config_Home, Cache_Home, Runtime_Dir, Data_Dirs, Config_Dirs );
type XDG_Wrapped is
record
Name : String_Access := null; -- Variable name
Value : String_Access := null; -- Test value
Default : String_Access := null; -- Default value
Variable: XDG_Variable;
end record;
procedure Set
( This: in out XDG_Wrapped; Name: in String;
Value: in String; Default: in String; Var: XDG_Variable
)
is
begin
This.Name := new String'(Name);
This.Value := new String'(Value);
This.Default := new String'(Default);
This.Variable := Var;
end Set;
-- Error count;
Errors: Natural := 0;
procedure Test (This: in XDG_Wrapped)
is
-- Wrapper to call correct function from XDG package.
function Call_Function return String
is
begin
case This.Variable is
when Data_Home => return XDG.Data_Home;
when Config_Home => return XDG.Config_Home;
when Cache_Home => return XDG.Cache_Home;
when Runtime_Dir => return XDG.Runtime_Dir;
when Data_Dirs => return XDG.Data_Dirs;
when Config_Dirs => return XDG.Config_Dirs;
end case;
end Call_Function;
procedure Put_Error (This: in XDG_Wrapped; Test_Step: in Positive)
is
Message: constant String := "Test error when testing: ";
begin
TIO.Put_Line
( File => TIO.Standard_Error, Item => Message & " " &
XDG_Variable'Image (This.Variable) & " : at test step : " &
Positive'Image (Test_Step)
);
end Put_Error;
begin
begin
if Call_Function /= This.Default.all then
Put_Error (This, 1);
Errors := Errors + 1;
end if;
exception
when others =>
Put_Error (This, 1);
Errors := Errors + 1;
end;
begin
EV.Set (This.Name.all, This.Value.all);
if Call_Function /= This.Value.all then
Put_Error (This, 2);
Errors := Errors + 1;
end if;
exception
when others =>
Put_Error (This, 2);
Errors := Errors + 1;
end;
end Test;
Home_Path: constant String := EV.Value ("HOME");
type XDG_Data is array (Positive range <>) of XDG_Wrapped;
Test_Data: XDG_Data (1 .. 6);
Error_Message: constant String :=
"xdg_vars: Total number of unexpected failures triggered: ";
begin
-- Clear variable values as they may have been carried from environment,
-- which could make it hard to test this functionality, and restore HOME
-- as it is being used.
EV.Clear;
EV.Set ("HOME", Home_Path);
-- Set up entire test
Set ( Test_Data (1), "XDG_DATA_HOME", EV.Value ("HOME") & "/data/",
EV.Value ("HOME") & "/.local/share/", Data_Home
);
Set ( Test_Data (2), "XDG_CONFIG_HOME", EV.Value ("HOME") & "/config/",
EV.Value ("HOME") & "/.config/", Config_Home
);
Set ( Test_Data (3), "XDG_CACHE_HOME", EV.Value ("HOME") & "/cache/",
EV.Value ("HOME") & "/.cache/", Cache_Home
);
Set ( Test_Data (4), "XDG_RUNTIME_DIR", EV.Value ("HOME") & "/runtime/", "",
Runtime_Dir
);
Set ( Test_Data (5), "XDG_DATA_DIRS", EV.Value ("HOME") & "/data_dirs/",
"/usr/local/share/:/usr/share/", Data_Dirs
);
Set ( Test_Data (6), "XDG_CONFIG_DIRS", EV.Value ("HOME") & "/xdg/",
"/etc/xdg/", Config_Dirs
);
-- Actually perform test
for I in Test_Data'Range loop
Test (Test_Data (I));
end loop;
if Errors /= 0 then
TIO.Put_Line
( File => TIO.Standard_Error,
Item => Error_Message & Natural'Image (Errors)
);
CLI.Set_Exit_Status (CLI.Failure);
end if;
end XDG_Vars;
|
--------------------------------------------------------------------------------
-- --
-- Copyright (C) 2004, RISC OS Ada Library (RASCAL) developers. --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU Lesser General Public --
-- License as published by the Free Software Foundation; either --
-- version 2.1 of the License, or (at your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- Lesser General Public License for more details. --
-- --
-- You should have received a copy of the GNU Lesser General Public --
-- License along with this library; if not, write to the Free Software --
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
-- --
--------------------------------------------------------------------------------
-- $Author$
-- $Date$
-- $Revision$
with Interfaces.C.Strings; use Interfaces.C.Strings;
with Interfaces.C; use Interfaces.C;
with RASCAL.MessageTrans; use RASCAL.MessageTrans;
with RASCAL.Utility; use RASCAL.Utility;
with RASCAL.OS; use RASCAL.OS;
package body RASCAL.Flex is
--
function flex_alloc (anchor : flex_ptr; n : int) return int;
pragma Import (C,flex_alloc);
function Alloc (Anchor : in Flex_Ptr;
Bytes : in Integer) return Integer is
C_Bytes : Int;
C_Return: Int;
begin
C_Bytes := Int(Bytes);
C_Return := flex_alloc (Anchor,C_Bytes);
return Integer(C_Return);
end Alloc;
--
procedure flex_free (anchor : flex_ptr);
pragma Import (C,flex_free);
procedure Free (Anchor : in Flex_Ptr) is
begin
flex_free(Anchor);
end Free;
--
function flex_size (anchor : flex_ptr) return int;
pragma Import (C,flex_size);
function Get_Size (Anchor : in Flex_Ptr) return Integer is
C_Return : Int;
begin
C_Return := flex_size (Anchor);
return Integer(C_Return);
end Get_Size;
--
function flex_extend (anchor : flex_ptr; newsize : int) return int;
pragma Import (C,flex_extend);
function Extend (Anchor : in Flex_Ptr;
New_Size : in Integer) return Integer is
C_New_Size : Int;
C_Result : Int;
begin
C_New_Size := Int(New_Size);
C_Result := flex_extend (Anchor,C_New_Size);
return Integer(C_Result);
end Extend;
--
function flex_midextend (anchor : flex_ptr; att : int; by : int) return int;
pragma Import (C,flex_midextend);
function Mid_Extend (Anchor : in Flex_Ptr;
Location : in Integer;
Extent : in Integer) return Integer is
C_Location : Int;
C_Extent : Int;
C_Return : Int;
begin
C_Location := Int(Location);
C_Extent := Int(Extent);
C_Return := flex_midextend (Anchor, C_Location, C_Extent);
return Integer(C_Return);
end Mid_Extend;
--
function flex_reanchor (to : flex_ptr; from : flex_ptr) return int;
pragma Import (C,flex_reanchor);
function Re_Anchor (To : in Flex_Ptr;
From : in Flex_Ptr) return Integer is
C_Return : Int;
begin
C_Return := flex_reanchor (To,From);
return Integer(C_Return);
end Re_Anchor;
--
function flex_set_budge (newstate : int) return int;
pragma Import (C,flex_set_budge);
function Set_Budge (New_State : Integer) return Integer is
C_New_State : Int;
C_Previous_State : Int;
begin
C_New_State := Int(New_State);
C_Previous_State := flex_set_budge (C_New_State);
return Integer(C_Previous_State);
end Set_Budge;
--
procedure flex_init(program_name : chars_ptr ; errors_fd : int; dynamic_size : int);
pragma Import (C,flex_init);
procedure Init (Program_Name : in String;
Errors : in Messages_Handle_Type;
Max_DA_Size : in Integer := 0) is
C_Program_Name : Chars_Ptr;
C_Max_DA_Size : Int;
begin
C_Max_DA_Size := Int(Max_DA_Size);
C_Program_Name := New_String (Program_Name);
if Errors = null then
flex_init (C_Program_Name,0,C_Max_DA_Size);
else
flex_init (C_Program_Name,Adr_To_Int(Errors.all'Address),C_Max_DA_Size);
end if;
Free (C_Program_Name);
end Init;
--
procedure flex_save_heap_info (filename : chars_ptr);
pragma Import (C,flex_save_heap_info);
procedure Save_HeapInfo (Filename : in String) is
C_Filename : Chars_Ptr;
begin
C_Filename := New_String (Filename);
flex_save_heap_info (C_Filename);
Free (C_Filename);
end Save_HeapInfo;
--
function flex_compact return int;
pragma Import (C,flex_compact);
function Compact return Integer is
C_Int : Int;
begin
C_Int := flex_compact;
return Integer(C_Int);
end Compact;
--
function flex_set_deferred_compaction (newstate : int) return int;
pragma Import (C,flex_set_deferred_compaction);
function Set_Deferred_Compaction (New_State : Integer) return Integer is
C_New_State : Int;
C_Previous_State : Int;
begin
C_New_State := Int (New_State);
C_Previous_State := flex_set_deferred_compaction (C_New_State);
return Integer(C_Previous_State);
end Set_Deferred_Compaction;
--
end RASCAL.Flex;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.