content stringlengths 23 1.05M |
|---|
with AWS.Messages;
with AWS.MIME;
package body @_Project_Name_@.Callbacks is
-------------
-- Default --
-------------
function Default (Request : in Status.Data) return Response.Data is
URI : constant String := Status.URI (Request);
begin
if URI = "/" then
return Response.Build
(MIME.Text_HTML, "<p>Hello World!");
else
return Response.Acknowledge (Messages.S404);
end if;
end Default;
end @_Project_Name_@.Callbacks;
|
package body Taszkseged is
task body Szemafor is
Bent: Natural := 0;
begin
loop
select
when Bent < Max => accept P; Bent := Bent + 1;
or
accept V; Bent := Bent - 1;
or
terminate;
end select;
end loop;
end Szemafor;
protected body Veletlen is
procedure Reset is begin Ada.Numerics.Float_Random.Reset(G); Inicializalt := True; end Reset;
entry General( F: out Float ) when Inicializalt is begin F := Ada.Numerics.Float_Random.Random(G); end General;
end Veletlen;
begin
Veletlen.Reset;
end Taszkseged;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Extensions;
package asm_generic_int_ll64_h is
-- * asm-generic/int-ll64.h
-- *
-- * Integer declarations for architectures which use "long long"
-- * for 64-bit types.
--
-- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
-- * header files exported to user space
--
subtype uu_s8 is signed_char; -- /usr/include/asm-generic/int-ll64.h:19
subtype uu_u8 is unsigned_char; -- /usr/include/asm-generic/int-ll64.h:20
subtype uu_s16 is short; -- /usr/include/asm-generic/int-ll64.h:22
subtype uu_u16 is unsigned_short; -- /usr/include/asm-generic/int-ll64.h:23
subtype uu_s32 is int; -- /usr/include/asm-generic/int-ll64.h:25
subtype uu_u32 is unsigned; -- /usr/include/asm-generic/int-ll64.h:26
subtype uu_s64 is Long_Long_Integer; -- /usr/include/asm-generic/int-ll64.h:29
subtype uu_u64 is Extensions.unsigned_long_long; -- /usr/include/asm-generic/int-ll64.h:30
end asm_generic_int_ll64_h;
|
with Libadalang.Common; use Libadalang.Common;
with Rejuvenation.Finder; use Rejuvenation.Finder;
with Rejuvenation.Node_Locations; use Rejuvenation.Node_Locations;
with Rejuvenation.Text_Rewrites; use Rejuvenation.Text_Rewrites;
package body Rewriters_Minimal_Parentheses is
overriding function Rewrite_Context
(RMP : Rewriter_Minimal_Parentheses; Node : Ada_Node'Class)
return Ada_Node
is
begin
if Node.Is_Null
or else Node.Kind not in Ada_Expr
or else Node.Parent.Is_Null
then
return Node.As_Ada_Node;
else
return Node.Parent;
end if;
end Rewrite_Context;
function Are_Brackets_Syntactically_Mandatory
(ParenExpr : Paren_Expr) return Boolean;
function Are_Brackets_Syntactically_Mandatory
(ParenExpr : Paren_Expr) return Boolean
-- for more info: see https://gt3-prod-2.adacore.com/#/tickets/U908-032
is
Parent : constant Ada_Node := ParenExpr.Parent;
begin
return
Parent.Is_Null
or else Parent.Kind in Ada_Expr_Function | Ada_Qual_Expr;
end Are_Brackets_Syntactically_Mandatory;
function Are_Brackets_Necessary (ParenExpr : Paren_Expr) return Boolean;
-- Are Brackets necessary for this ParenExpr?
function Are_Brackets_Necessary (ParenExpr : Paren_Expr) return Boolean
-- A conservative implementation
is
begin
case ParenExpr.F_Expr.Kind is
when Ada_If_Expr | Ada_Case_Expr | Ada_Quantified_Expr |
Ada_Decl_Expr =>
-- see http://www.ada-auth.org/standards/12rat/html/Rat12-3-2.html
-- conservative: we don't remove when used in positional call
-- with single parameter
return True;
when Ada_Bin_Op | Ada_Relation_Op | Ada_Un_Op | Ada_Membership_Expr |
Ada_Paren_Expr =>
-- conservative: we don't remove when used in left operand
-- e.g. (a + b) + c <==> a + b + c
-- conservative, yet local handling of special case
-- 'parenthesis directly within parenthesis'
-- assume most inner-expression in parenthesis would require brackets
declare
Parent : constant Ada_Node := ParenExpr.Parent;
begin
return
Parent.Is_Null
or else Parent.Kind in Ada_Bin_Op | Ada_Relation_Op |
Ada_Un_Op | Ada_Membership_Expr;
end;
when others =>
return False;
end case;
end Are_Brackets_Necessary;
overriding function Rewrite
(RMP : Rewriter_Minimal_Parentheses; Node : Ada_Node'Class;
Top_Level : Boolean := True) return String
is
TR : Text_Rewrite :=
Make_Text_Rewrite_Node
(Node, Trivia_On_Same_Line, Trivia_On_Same_Line);
begin
for PE_Node of Find (Node, Ada_Paren_Expr) loop
declare
ParenExpr : constant Paren_Expr := PE_Node.As_Paren_Expr;
begin
if not Are_Brackets_Syntactically_Mandatory (ParenExpr)
and then not Are_Brackets_Necessary (ParenExpr)
then
TR.ReplaceAround
(Node => ParenExpr, Before_Text => "",
Innernode => ParenExpr.F_Expr, After_Text => "",
Charset => Node.Unit.Get_Charset);
end if;
end;
end loop;
return TR.ApplyToString;
end Rewrite;
end Rewriters_Minimal_Parentheses;
|
-- Copyright (c) 2015-2019 Marcel Schneider
-- for details see License.txt
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
-- with Ada.Strings; use Ada.Strings;
with Ada.Text_IO; use Ada.Text_IO;
with Punctuation; use Punctuation;
package body Lexer_Base is
procedure OpenFile (O : in out Object;
File_Name : String) is
B : Boolean;
begin
O.File_Name := To_Unbounded_String (File_Name);
B := IsPunctuation('.');
Put_Line(Boolean'Image(B));
end OpenFile;
function ReadToken (O : Object) return TokenValue.Object is
TO : TokenValue.Object;
begin
return TO;
end ReadToken;
function ReadWhiteSpace return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadWhiteSpace;
function ReadString return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadString;
function ReadLineComment return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadLineComment;
function ReadBlockComment return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadBlockComment;
function ReadRegEx return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadRegEx;
function ReadOperator return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadOperator;
function ReadNumber return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end ReadNumber;
function IsPunctuationUsed (C : Character) return Boolean is
-- B : Boolean;
begin
return false;
end IsPunctuationUsed;
function SetNumberPunctuation (C : Character;
IsHexNumber : Boolean) return Boolean is
begin
return false;
end SetNumberPunctuation;
function ReadIdentifier return TokenValue.Object is
O : TokenValue.Object;
C : Character;
P : Punctuation.Object;
begin
while True loop
C := Peek;
if IsName(C) OR IsDigit(C) then
C := Advance;
else
if P.FutureReservedWords.Contains(To_Unbounded_String("")) then
return O;
end if;
if P.Keywords.Contains(To_Unbounded_String("")) then
return O;
end if;
return O;
end if;
end loop;
-- return O;
end ReadIdentifier;
function IsName (C : Character) return Boolean is
begin
return (C >= 'a' AND C <= 'z')
OR (C >= 'A' AND C <= 'Z')
OR C = '$'
OR C = '_';
end IsName;
function IsOperator (C : Character) return Boolean is
Op : constant String := "~!%^&*/-=+|/?<>:";
I : Integer := 1;
begin
while I <= Op'Length loop
if (Op(I) = C) then
return true;
end if;
I := I + 1;
end loop;
return false;
end IsOperator;
function IsDigit (C : Character) return Boolean is
begin
return C >= '0' AND C <= '9';
end IsDigit;
function IsPunctuation (C : Character) return Boolean is
P : constant String := "(){}[];,.";
I : Integer := 1;
begin
while I <= P'Length loop
if (P(I) = C) then
return true;
end if;
I := I + 1;
end loop;
return false;
end IsPunctuation;
function Peek return Character is
C : Character;
begin
return C;
end Peek;
function Advance return Character is
C : Character;
begin
return C;
end Advance;
function CreateToken (TokenId : Token;
Literal : Unbounded_String;
Message : Unbounded_String) return TokenValue.Object is
O : TokenValue.Object;
begin
return O;
end CreateToken;
function CreatePosition return Position.Object is
O : Position.Object;
begin
return O;
end CreatePosition;
end Lexer_Base;
|
with Ada.Containers.Indefinite_Ordered_Maps;
package String_Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Key_Type => String, Element_Type => String);
|
-----------------------------------------------------------------------
-- mat-readers-tests -- Unit tests for MAT readers
-- Copyright (C) 2014, 2015, 2019, 2021 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.Test_Caller;
with MAT.Readers.Streams.Files;
package body MAT.Targets.Tests is
package Caller is new Util.Test_Caller (Test, "Files");
procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
begin
Caller.Add_Test (Suite, "Test MAT.Targets.Read_File",
Test_Read_File'Access);
Caller.Add_Test (Suite, "Test MAT.Types.Tick_Value",
Test_Conversions'Access);
end Add_Tests;
-- ------------------------------
-- Test reading a file into a string
-- Reads this ada source file and checks we have read it correctly
-- ------------------------------
procedure Test_Read_File (T : in out Test) is
pragma Unreferenced (T);
Path : constant String := Util.Tests.Get_Path ("regtests/files/file-v1.dat");
Target : MAT.Targets.Target_Type;
Reader : MAT.Readers.Streams.Files.File_Reader_Type;
begin
Target.Initialize (Reader);
Reader.Open (Path);
Reader.Read_All;
end Test_Read_File;
-- ------------------------------
-- Test various type conversions.
-- ------------------------------
procedure Test_Conversions (T : in out Test) is
use MAT.Types;
Time : MAT.Types.Target_Tick_Ref;
begin
Time := MAT.Types.Tick_Value ("1.1");
Util.Tests.Assert_Equals (T, 1, Natural (Time / 1_000000), "Invalid Tick_Value conversion");
Util.Tests.Assert_Equals (T, 100_000, Natural (Time mod 1_000000),
"Invalid Tick_Value conversion");
Time := MAT.Types.Tick_Value ("12.001234");
Util.Tests.Assert_Equals (T, 12, Natural (Time / 1_000000), "Invalid Tick_Value conversion");
Util.Tests.Assert_Equals (T, 1_234, Natural (Time mod 1_000000),
"Invalid Tick_Value conversion");
end Test_Conversions;
end MAT.Targets.Tests;
|
-------------------------------------------------------------------------------
-- Copyright 2021, The Septum Developers (see AUTHORS file)
-- 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.Directories;
with Ada.Strings.Unbounded;
with Ada.Streams.Stream_IO;
with Ada.Text_IO;
with Dir_Iterators.Ancestor;
with SP.File_System;
with SP.Platform;
package body SP.Config is
package AD renames Ada.Directories;
package ASU renames Ada.Strings.Unbounded;
package FS renames SP.File_System;
use type ASU.Unbounded_String;
procedure Create_Local_Config is
Current_Dir : constant String := AD.Current_Directory;
Config_Dir : constant String := Current_Dir & "/" & Config_Dir_Name;
Config_File : constant String := Config_Dir & "/" & Config_File_Name;
begin
if not AD.Exists (Config_Dir) then
begin
AD.Create_Directory (Config_Dir);
exception
when AD.Name_Error | AD.Use_Error =>
return;
end;
end if;
if SP.File_System.Is_File (Config_File)
or else SP.File_System.Is_Dir (Config_File) then
Ada.Text_IO.Put_Line ("Unable to create config file, something already exists there: " &
Config_File);
return;
end if;
declare
File : Ada.Streams.Stream_IO.File_Type;
use Ada.Streams;
begin
Stream_IO.Create (File, Ada.Streams.Stream_IO.Out_File, Config_File);
Stream_IO.Close (File);
-- Compiler bug?
-- warning: "File" modified by call, but value might not be referenced
pragma Unreferenced (File);
Ada.Text_IO.Put_Line ("Configuration directory: " & Ada.Directories.Full_Name (Config_Dir));
Ada.Text_IO.Put_Line ("Configuration file: " & Ada.Directories.Full_Name (Config_File));
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line (Config_Dir_Name & " is for Septum settings and configuration.");
Ada.Text_IO.Put_Line (Config_File_Name & " contains commands to run when starting in this directory.");
exception
when Stream_IO.Name_Error | Stream_IO.Use_Error =>
Ada.Text_IO.Put_Line ("Unable to create configuration file.");
end;
end Create_Local_Config;
-- Finds the config which is the closest ancestor to the given directory.
function Closest_Config (Dir_Name : String) return ASU.Unbounded_String with
Pre => AD.Exists (Dir_Name),
Post => (Closest_Config'Result = ASU.Null_Unbounded_String)
or else FS.Is_File (ASU.To_String (Closest_Config'Result))
is
Ancestors : constant Dir_Iterators.Ancestor.Ancestor_Dir_Walk := Dir_Iterators.Ancestor.Walk (Dir_Name);
Next_Trial : ASU.Unbounded_String;
begin
for Ancestor of Ancestors loop
Next_Trial := ASU.To_Unbounded_String (Ancestor & "/" & Config_Dir_Name & "/" & Config_File_Name);
if FS.Is_File (ASU.To_String (Next_Trial)) then
return Next_Trial;
end if;
end loop;
return ASU.Null_Unbounded_String;
end Closest_Config;
function Config_Locations return String_Vectors.Vector is
Home_Dir_Config : constant ASU.Unbounded_String :=
ASU.To_Unbounded_String
(SP.Platform.Home_Dir & "/" & Config_Dir_Name & "/" & Config_File_Name);
Current_Dir_Config : constant ASU.Unbounded_String := Closest_Config (Ada.Directories.Current_Directory);
begin
return V : String_Vectors.Vector do
-- Look for the global user config.
if FS.Is_File (ASU.To_String (Home_Dir_Config)) then
V.Append (Home_Dir_Config);
end if;
if Current_Dir_Config /= ASU.Null_Unbounded_String
and then FS.Is_File (ASU.To_String (Current_Dir_Config))
then
V.Append (Current_Dir_Config);
end if;
end return;
end Config_Locations;
end SP.Config;
|
procedure Choice_Parameter_Specification is
begin
null;
exception
when Choice_Parameter : Constraint_Error =>
null;
end Choice_Parameter_Specification;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Elements.Type_Definitions;
with Program.Lexical_Elements;
with Program.Elements.Expressions;
package Program.Elements.Signed_Integer_Types is
pragma Pure (Program.Elements.Signed_Integer_Types);
type Signed_Integer_Type is
limited interface and Program.Elements.Type_Definitions.Type_Definition;
type Signed_Integer_Type_Access is access all Signed_Integer_Type'Class
with Storage_Size => 0;
not overriding function Lower_Bound
(Self : Signed_Integer_Type)
return not null Program.Elements.Expressions.Expression_Access
is abstract;
not overriding function Upper_Bound
(Self : Signed_Integer_Type)
return not null Program.Elements.Expressions.Expression_Access
is abstract;
type Signed_Integer_Type_Text is limited interface;
type Signed_Integer_Type_Text_Access is
access all Signed_Integer_Type_Text'Class with Storage_Size => 0;
not overriding function To_Signed_Integer_Type_Text
(Self : in out Signed_Integer_Type)
return Signed_Integer_Type_Text_Access is abstract;
not overriding function Range_Token
(Self : Signed_Integer_Type_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Double_Dot_Token
(Self : Signed_Integer_Type_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
end Program.Elements.Signed_Integer_Types;
|
with Ada.Containers;
with Ada.Containers.Hashed_Maps;
with Ada.Containers.Hashed_Sets;
with Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Hash;
with Ada.Streams.Stream_IO;
package GraphML_Writers is
package S_U renames Ada.Strings.Unbounded;
type GraphML_Type is (GraphML_Boolean, GraphML_Int, GraphML_String);
package Attribute_Definition_Sets is new Ada.Containers.Hashed_Maps
(Key_Type => S_U.Unbounded_String, Element_Type => GraphML_Type,
Hash => S_U.Hash, Equivalent_Keys => S_U."=");
package Attribute_Value_Sets is new Ada.Containers.Hashed_Maps
(Key_Type => S_U.Unbounded_String, Element_Type => S_U.Unbounded_String,
Hash => S_U.Hash, Equivalent_Keys => S_U."=", "=" => S_U."=");
type Node_Type is new String;
type Node_Subtype is new String;
type Edge_Type is new String;
type GraphML_File is tagged limited private;
procedure Close (This : in out GraphML_File);
procedure Write_Node
(This : in out GraphML_File; Node_Key : String; Node_Name : String;
Node_Ty : Node_Type;
Node_Attributes : Attribute_Value_Sets.Map :=
Attribute_Value_Sets.Empty_Map);
procedure Write_Node
(This : in out GraphML_File; Node_Key : String; Node_Name : String;
Node_Ty : Node_Type; Node_Subty : Node_Subtype;
Node_Attributes : Attribute_Value_Sets.Map :=
Attribute_Value_Sets.Empty_Map);
procedure Write_Edge
(This : in out GraphML_File; Source_Node_Key : String;
Target_Node_Key : String; Edge_Ty : Edge_Type;
Edge_Attributes : Attribute_Value_Sets.Map :=
Attribute_Value_Sets.Empty_Map);
function Create_GraphML_Writer
(Filename : String;
Node_Attributes : Attribute_Definition_Sets.Map :=
Attribute_Definition_Sets.Empty_Map;
Edge_Attributes : Attribute_Definition_Sets.Map :=
Attribute_Definition_Sets.Empty_Map)
return GraphML_File;
private
type Node_Id is new Positive;
type Node_Data is record
Id : Node_Id;
Ty : S_U.Unbounded_String;
Subty : S_U.Unbounded_String;
Attributes : Attribute_Value_Sets.Map;
end record;
package Known_Node_Sets is new Ada.Containers.Hashed_Maps
(Key_Type => S_U.Unbounded_String, Element_Type => Node_Data,
Hash => S_U.Hash, Equivalent_Keys => S_U."=");
type Edge_Data is record
Source_Id : Node_Id;
Target_Id : Node_Id;
Edge_Ty : S_U.Unbounded_String;
Attributes : Attribute_Value_Sets.Map;
end record;
function Edge_Data_Hash (Id : Edge_Data) return Ada.Containers.Hash_Type;
package Known_Edge_Sets is new Ada.Containers.Hashed_Sets
(Element_Type => Edge_Data, Hash => Edge_Data_Hash,
Equivalent_Elements => "=");
type GraphML_File is tagged limited record
File : Ada.Streams.Stream_IO.File_Type;
Stream : Ada.Streams.Stream_IO.Stream_Access;
Node_Attributes : Attribute_Definition_Sets.Map;
Edge_Attributes : Attribute_Definition_Sets.Map;
Next_Node_Id : Node_Id := 1;
Known_Nodes : Known_Node_Sets.Map;
Known_Edges : Known_Edge_Sets.Set;
end record;
end GraphML_Writers;
|
-- 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 GL.Debug;
package body Orka.Instances is
use GL.Debug;
package Messages is new GL.Debug.Messages (Third_Party, Other);
function Create_Manager (Capacity, Parts : Positive) return Manager is
Transforms : constant Positive := Capacity * Parts;
Data : Instances_Type (Capacity);
begin
return Result : Manager do
Result.Added := 0;
Result.Capacity := Capacity;
Result.Parts := Parts;
for Index in Data.Instances'Range loop
Data.Instances (Index) := Index;
Data.Indices (Index) := Index;
end loop;
Result.Instances := Instances_Holder.To_Holder (Data);
-- Set-up a mapped buffer for world transform matrices
Result.Transforms := PMB.Create_Buffer
(Orka.Types.Single_Matrix_Type, Transforms, Rendering.Buffers.Mapped.Write);
Messages.Log (Notification, "Created group for" &
Capacity'Image & " instances");
Messages.Log (Notification, " " &
Capacity'Image & " instances x" & Parts'Image & " parts =" &
Transforms'Image & " transforms");
end return;
end Create_Manager;
function Add_Instance (Object : in out Manager) return Cursor is
Instance_Index : constant Index := Object.Added + 1;
Instance_ID : Instance;
procedure Get_Instance (Data : Instances_Type) is
begin
Instance_ID := Data.Instances (Instance_Index);
pragma Assert (Data.Indices (Instance_ID) = Instance_Index);
end Get_Instance;
begin
if Object.Length = Object.Capacity then
raise Constraint_Error with "Transforms buffer already has maximum number of instances";
end if;
Object.Instances.Query_Element (Get_Instance'Access);
Object.Added := Object.Added + 1;
return Cursor (Instance_ID);
end Add_Instance;
procedure Remove_Instance (Object : in out Manager; Instance : Cursor) is
Left_Instance : constant Instances.Instance := Instances.Instance (Instance);
Left_Index : constant Index := Object.Instances.Element.Indices (Left_Instance);
Right_Index : constant Index := Object.Added;
pragma Assert (Object.Instances.Element.Instances (Left_Index) = Left_Instance);
procedure Swap_Instances (Data : in out Instances_Type) is
Right_Instance : constant Instances.Instance := Data.Instances (Right_Index);
begin
Data.Instances (Left_Index) := Right_Instance;
Data.Instances (Right_Index) := Left_Instance;
Data.Indices (Left_Instance) := Right_Index;
Data.Indices (Right_Instance) := Left_Index;
end Swap_Instances;
begin
if Left_Index > Right_Index then
raise Constraint_Error with "Instance index out of range";
end if;
Object.Instances.Update_Element (Swap_Instances'Access);
Object.Added := Object.Added - 1;
end Remove_Instance;
procedure Set_Transform
(Object : in out Manager;
Value : Orka.Types.Singles.Matrix4;
Instance : Cursor;
Part : Natural)
is
Instance_Index : Index;
procedure Get_Instance (Data : Instances_Type) is
begin
Instance_Index := Data.Indices (Instances.Instance (Instance));
end Get_Instance;
begin
Object.Instances.Query_Element (Get_Instance'Access);
if Instance_Index > Object.Added then
raise Constraint_Error with "Instance index out of range";
end if;
if Part >= Object.Parts then
raise Constraint_Error with "Part index out of range";
end if;
Object.Transforms.Write_Data (Value, (Instance_Index - Index'First) + Part * Object.Added);
end Set_Transform;
function Transforms (Object : Manager) return Rendering.Buffers.Bindable_Buffer'Class is
(Object.Transforms);
function Parts (Object : Manager) return Positive is (Object.Parts);
function Length (Object : Manager) return Natural is (Object.Added);
function Capacity (Object : Manager) return Positive is (Object.Capacity);
procedure Complete_Frame (Object : in out Manager) is
begin
Object.Transforms.Advance_Index;
end Complete_Frame;
end Orka.Instances;
|
pragma License (Unrestricted);
-- Ada 2012
package Ada.Strings.UTF_Encoding.Conversions is
pragma Pure;
-- Conversions between various encoding schemes
function Convert (
Item : UTF_String;
Input_Scheme : Encoding_Scheme;
Output_Scheme : Encoding_Scheme;
Output_BOM : Boolean := False)
return UTF_String;
-- function from binary to 8 is missing, use from binary to binary
function Convert (
Item : UTF_String;
Input_Scheme : Encoding_Scheme;
Output_BOM : Boolean := False)
return UTF_16_Wide_String;
-- extended
-- This function convets from binary to 32.
function Convert (
Item : UTF_String;
Input_Scheme : Encoding_Scheme;
Output_BOM : Boolean := False)
return UTF_32_Wide_Wide_String;
-- function from 8 to binary is missing, use from binary to binary
function Convert (
Item : UTF_8_String;
Output_BOM : Boolean := False)
return UTF_16_Wide_String;
-- extended
-- This function convets from 8 to 32.
function Convert (
Item : UTF_8_String;
Output_BOM : Boolean := False)
return UTF_32_Wide_Wide_String;
function Convert (
Item : UTF_16_Wide_String;
Output_Scheme : Encoding_Scheme;
Output_BOM : Boolean := False)
return UTF_String;
function Convert (
Item : UTF_16_Wide_String;
Output_BOM : Boolean := False)
return UTF_8_String;
-- extended
-- This function convets from 16 to 32.
function Convert (
Item : UTF_16_Wide_String;
Output_BOM : Boolean := False)
return UTF_32_Wide_Wide_String;
-- extended
-- This function convets from 32 to binary.
function Convert (
Item : UTF_32_Wide_Wide_String;
Output_Scheme : Encoding_Scheme;
Output_BOM : Boolean := False)
return UTF_String;
-- extended
-- This function convets from 32 to 8.
function Convert (
Item : UTF_32_Wide_Wide_String;
Output_BOM : Boolean := False)
return UTF_8_String;
-- extended
-- This function convets from 32 to 16.
function Convert (
Item : UTF_32_Wide_Wide_String;
Output_BOM : Boolean := False)
return UTF_16_Wide_String;
end Ada.Strings.UTF_Encoding.Conversions;
|
with
ada.unchecked_Deallocation;
package body physics.Space
is
procedure free (Self : in out View)
is
procedure deallocate is new ada.unchecked_Deallocation (Item'Class, View);
begin
Self.destruct;
deallocate (Self);
end free;
end physics.Space;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . D A T A _ D E C O M P O S I T I O N . E X T E N S I O N S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2010, Free Software Foundation, Inc. --
-- --
-- ASIS-for-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 --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY 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 ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 59 Temple Place --
-- - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by Ada Core Technologies Inc --
-- (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with System; use System;
with Asis.Data_Decomposition.Vcheck; use Asis.Data_Decomposition.Vcheck;
with Asis.Data_Decomposition.Set_Get; use Asis.Data_Decomposition.Set_Get;
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.DDA_Aux; use A4G.DDA_Aux;
with A4G.Vcheck; use A4G.Vcheck;
with Einfo; use Einfo;
with Namet; use Namet;
with Uintp; use Uintp;
with Urealp; use Urealp;
package body Asis.Data_Decomposition.Extensions is
Package_Name : constant String := "Asis.Data_Decomposition.Extensions.";
-----------------------
-- Local subprograms --
-----------------------
procedure Write_Real_To_Buffer (U : Ureal);
-- Puts nnn/ddd to Name_Buffer, where nnn and ddd are integer values of
-- the normalized numerator and denominator of the given real value.
-- This procedure is supposed to be used to output images of positive
-- real values only, so it assumes, that nnn is always positive.
procedure Add_Uint_To_Buffer (U : Uint);
-- Add image of universal integer to Name_Buffer, updating Name_Len
-- (This procedure is the simplified version of the local procedure
-- Exp_Dbug.Add_Uint_To_Buffer - it always consider its argument
-- being positive)
------------------------
-- Add_Uint_To_Buffer --
------------------------
procedure Add_Uint_To_Buffer (U : Uint) is
begin
UI_Image (U, Decimal);
Add_Str_To_Name_Buffer (UI_Image_Buffer (1 .. UI_Image_Length));
end Add_Uint_To_Buffer;
-------------------------------
-- Component_Name_Definition --
-------------------------------
function Component_Name_Definition
(Component : Record_Component)
return Asis.Declaration
is
Result : Asis.Element;
begin
Check_Validity (Component, Package_Name & "Component_Name_Definition");
if Is_Nil (Component) then
Raise_ASIS_Inappropriate_Component
(Diagnosis => Package_Name & "Component_Name_Definition",
Component_Kind => Rec);
end if;
Result := Component_Name (Component);
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Component_Name_Definition");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Component_Name_Definition",
Ex => Ex);
end Component_Name_Definition;
--------------------------
-- Delta_Value (String) --
--------------------------
function Delta_Value
(Fixed_Point_Subtype : Asis.Element)
return String
is
Arg_Node : Node_Id;
Res_Ureal : Ureal;
begin
Check_Validity
(Fixed_Point_Subtype, Package_Name & "Delta_Value (String)");
Arg_Node := R_Node (Fixed_Point_Subtype);
if not (Int_Kind (Fixed_Point_Subtype) = A_Defining_Identifier and then
Is_Fixed_Point_Type (Arg_Node))
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Delta_Value (String)",
Wrong_Kind => Int_Kind (Fixed_Point_Subtype));
end if;
Res_Ureal := Einfo.Delta_Value (Arg_Node);
Write_Real_To_Buffer (Res_Ureal);
return Namet.Name_Buffer (1 .. Namet.Name_Len);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Delta_Value (String)",
Argument => Fixed_Point_Subtype);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Delta_Value (String)",
Ex => Ex,
Arg_Element => Fixed_Point_Subtype);
end Delta_Value;
----------------------------
-- Delta_Value (Fraction) --
----------------------------
function Delta_Value
(Fixed_Point_Subtype : Asis.Element)
return Fraction
is
Arg_Node : Node_Id;
Res_Ureal : Ureal;
Result : Fraction;
begin
Check_Validity
(Fixed_Point_Subtype, Package_Name & "Delta_Value (Fraction)");
Arg_Node := R_Node (Fixed_Point_Subtype);
if not (Int_Kind (Fixed_Point_Subtype) = A_Defining_Identifier and then
Is_Fixed_Point_Type (Arg_Node))
then
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Delta_Value (Fraction)",
Wrong_Kind => Int_Kind (Fixed_Point_Subtype));
end if;
Res_Ureal := Einfo.Delta_Value (Arg_Node);
Result.Num := UI_To_Aint (Norm_Num (Res_Ureal));
Result.Denum := UI_To_Aint (Norm_Den (Res_Ureal));
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Delta_Value (Fraction)",
Argument => Fixed_Point_Subtype);
end if;
raise;
when Invalid_Data =>
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Delta_Value (Fraction)",
Wrong_Kind => Int_Kind (Fixed_Point_Subtype),
Status => Data_Error);
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Delta_Value (Fraction)",
Ex => Ex,
Arg_Element => Fixed_Point_Subtype);
end Delta_Value;
------------------
-- Digits_Value --
------------------
function Digits_Value
(Floating_Point_Subtype : Asis.Element)
return ASIS_Natural
is
Arg_Node : Node_Id;
begin
Check_Validity (Floating_Point_Subtype, Package_Name & "Digits_Value");
Arg_Node := R_Node (Floating_Point_Subtype);
if not (Int_Kind (Floating_Point_Subtype) = A_Defining_Identifier
and then
(Is_Decimal_Fixed_Point_Type (Arg_Node) or else
Is_Floating_Point_Type (Arg_Node)))
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Digits_Value",
Wrong_Kind => Int_Kind (Floating_Point_Subtype));
end if;
return ASIS_Natural (UI_To_Int (Einfo.Digits_Value (Arg_Node)));
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Digits_Value",
Argument => Floating_Point_Subtype);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Digits_Value",
Ex => Ex,
Arg_Element => Floating_Point_Subtype);
end Digits_Value;
--------------------------
-- Portable_Data_Value --
--------------------------
function Portable_Data_Value
(Value : Constrained_Subtype)
return Portable_Data
is
Local_Value : aliased constant Constrained_Subtype := Value;
for Local_Value'Alignment use Standard'Maximum_Alignment;
-- We force the maximum alignment for Local_Value to make it
-- compatible with maximum alignment set for Portable_Data
-- in the spec of Asis.Data_Decomposition
subtype Result_Portable_Data is
Portable_Data (1 .. (Constrained_Subtype'Object_Size + 7) / 8);
type Result_Portable_Data_Access is access Result_Portable_Data;
function To_Result_Portable_Data_Access is new
Ada.Unchecked_Conversion (Address, Result_Portable_Data_Access);
Result : constant Result_Portable_Data_Access :=
To_Result_Portable_Data_Access (Local_Value'Address);
begin
return Result.all;
exception
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Portable_Data_Value");
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Portable_Data_Value",
Ex => Ex);
end Portable_Data_Value;
-----------------
-- Scale_Value --
-----------------
function Scale_Value
(Desimal_Fixed_Point_Subtype : Asis.Element)
return ASIS_Natural
is
Arg_Node : Node_Id;
begin
Check_Validity
(Desimal_Fixed_Point_Subtype, Package_Name & "Scale_Value");
Arg_Node := R_Node (Desimal_Fixed_Point_Subtype);
if not (Int_Kind (Desimal_Fixed_Point_Subtype) = A_Defining_Identifier
and then
Is_Decimal_Fixed_Point_Type (Arg_Node))
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Scale_Value",
Wrong_Kind => Int_Kind (Desimal_Fixed_Point_Subtype));
end if;
return ASIS_Natural (UI_To_Int (Einfo.Scale_Value (Arg_Node)));
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Scale_Value",
Argument => Desimal_Fixed_Point_Subtype);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Scale_Value",
Ex => Ex,
Arg_Element => Desimal_Fixed_Point_Subtype);
end Scale_Value;
--------------------------
-- Small_Value (String) --
--------------------------
function Small_Value
(Fixed_Point_Subtype : Asis.Element)
return String
is
Arg_Node : Node_Id;
Res_Ureal : Ureal;
begin
Check_Validity
(Fixed_Point_Subtype, Package_Name & "Small_Value (String)");
Arg_Node := R_Node (Fixed_Point_Subtype);
if not (Int_Kind (Fixed_Point_Subtype) = A_Defining_Identifier and then
Is_Fixed_Point_Type (Arg_Node))
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Small_Value (String)",
Wrong_Kind => Int_Kind (Fixed_Point_Subtype));
end if;
Res_Ureal := Einfo.Small_Value (Arg_Node);
Write_Real_To_Buffer (Res_Ureal);
return Namet.Name_Buffer (1 .. Namet.Name_Len);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Small_Value (String)",
Argument => Fixed_Point_Subtype);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Small_Value (String)",
Ex => Ex,
Arg_Element => Fixed_Point_Subtype);
end Small_Value;
----------------------------
-- Small_Value (Fraction) --
----------------------------
function Small_Value
(Fixed_Point_Subtype : Asis.Element)
return Fraction
is
Arg_Node : Node_Id;
Res_Ureal : Ureal;
Result : Fraction;
begin
Check_Validity
(Fixed_Point_Subtype, Package_Name & "Small_Value (Fraction)");
Arg_Node := R_Node (Fixed_Point_Subtype);
if not (Int_Kind (Fixed_Point_Subtype) = A_Defining_Identifier and then
Is_Fixed_Point_Type (Arg_Node))
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Small_Value (Fraction)",
Wrong_Kind => Int_Kind (Fixed_Point_Subtype));
end if;
Res_Ureal := Einfo.Small_Value (Arg_Node);
Result.Num := UI_To_Aint (Norm_Num (Res_Ureal));
Result.Denum := UI_To_Aint (Norm_Den (Res_Ureal));
return Result;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Small_Value (Fraction)",
Argument => Fixed_Point_Subtype);
end if;
raise;
when Invalid_Data =>
Raise_ASIS_Inappropriate_Element
(Diagnosis => Package_Name & "Small_Value (Fraction)",
Wrong_Kind => Int_Kind (Fixed_Point_Subtype),
Status => Data_Error);
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Small_Value (Fraction)",
Ex => Ex,
Arg_Element => Fixed_Point_Subtype);
end Small_Value;
--------------------------
-- Write_Real_To_Buffer --
--------------------------
procedure Write_Real_To_Buffer (U : Ureal) is
begin
Namet.Name_Len := 0;
Add_Uint_To_Buffer (Norm_Num (U));
Add_Str_To_Name_Buffer ("/");
Add_Uint_To_Buffer (Norm_Den (U));
end Write_Real_To_Buffer;
end Asis.Data_Decomposition.Extensions;
|
with ARM_Output;
package ARM_Index is
--
-- Ada reference manual formatter (ARM_Form).
--
-- This package contains the routines to manage and generate the index.
--
-- ---------------------------------------
-- Copyright 2000, 2005, 2006, 2011
-- AXE Consultants. All rights reserved.
-- P.O. Box 1512, Madison WI 53701
-- E-Mail: randy@rrsoftware.com
--
-- ARM_Form is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3
-- as published by the Free Software Foundation.
--
-- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS"
-- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY,
-- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL.
-- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL,
-- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES,
-- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-- DAMAGES.
--
-- A copy of the GNU General Public License is available in the file
-- gpl-3-0.txt in the standard distribution of the ARM_Form tool.
-- Otherwise, see <http://www.gnu.org/licenses/>.
--
-- If the GPLv3 license is not satisfactory for your needs, a commercial
-- use license is available for this tool. Contact Randy at AXE Consultants
-- for more information.
--
-- ---------------------------------------
--
-- Edit History:
--
-- 5/28/00 - RLB - Created package.
-- 8/11/00 - RLB - Made Clean visible.
-- 10/28/05 - RLB - Added key reuse.
-- 10/30/05 - RLB - Added subtype declaration.
-- 2/17/06 - RLB - Added Remove_Soft_Hyphens flag to Clean (for output).
-- 10/18/11 - RLB - Changed to GPLv3 license.
Not_Valid_Error : exception;
subtype Index_Key is Natural range 0 .. 20000;
procedure Create;
-- Initialize this package.
procedure Destroy;
-- Finalize this package; make sure the index is empty.
type Index_Item_Kind_Type is (
Primary_Term, -- A primary index term.
Partial_Term, -- A partial index term.
Primary_Term_and_Subterm, -- A primary index term with a subterm.
Partial_Term_with_Subterm, -- A partial index term with a subterm.
Syntax_NT_Used, -- A non-terminal, with a subterm of "Used".
Child_Unit_Parent, -- A child unit, with a subterm of "child of <subterm>".
Declaration_in_Package, -- A declaration, with a subterm of "in <package>".
SubDeclaration_in_Package, -- A term, with a subterm of "<item> in <package>".
Subtype_Declaration_in_Package, -- A term (of the form "<item> subtype of <item2>, with a subterm of "in <package>".
See_Term, -- A "see <subterm>" with reference.
See_Also_Term, -- A "see also <subterm>" with reference.
See_Other_Term, -- A "see <subterm>" without reference.
See_Also_Other_Term); -- A "see also <subterm>" without reference.
-- Note: These are declared in the sorting order.
function Get_Key return Index_Key;
-- Returns a Key value to refer to one or more index entries
-- (for a single entity).
procedure Add (Term : in String;
Subterm : in String := "";
Kind : in Index_Item_Kind_Type := Primary_Term;
Clause : in String := "";
Paragraph : in String := "";
Key : out Index_Key);
-- Add an index reference to the index. Returns a Key value to
-- refer to this index entry.
-- Raises Not_Valid_Error if Subterm, Clause, or Paragraph is not
-- empty when the kind does not use it.
procedure Add_Reusing_Key (Term : in String;
Subterm : in String := "";
Kind : in Index_Item_Kind_Type := Primary_Term;
Clause : in String := "";
Paragraph : in String := "";
Key : in Index_Key);
-- Add an index reference to the index, (re)using the specified Key
-- to refer to this index entry. Key must have previously
-- returned by Add or Get_Key.
-- Raises Not_Valid_Error if Subterm, Clause, or Paragraph is not
-- empty when the kind does not use it.
function Clean (Item : in String;
Remove_Soft_Hyphens : in Boolean) return String;
-- Remove any commands from Item. (Except for soft hyphens
-- if Remove_Soft_Hyphens is False.)
procedure Generate_Index_Body (Output_Object : in out ARM_Output.Output_Type'Class;
Use_Paragraphs : in Boolean := True);
-- Generate the index body. (The section header has already been
-- generated). References include paragraph numbers if Use_Paragraphs
-- is true.
end ARM_Index;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A _ T Y P E S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2010, Free Software Foundation, Inc. --
-- --
-- ASIS-for-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 --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY 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 ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with System; use System;
with Hostparm;
package body A4G.A_Types is
---------------
-- A_OS_Time --
---------------
function A_OS_Time return ASIS_OS_Time is
begin
return ASIS_Clock;
end A_OS_Time;
-----------------------------
-- Asis_Normalize_Pathname --
-----------------------------
Asis_Normalize_Pathname_Result : String_Access;
function Asis_Normalize_Pathname
(Name : String;
Directory : String := "";
Resolve_Links : Boolean := True;
Case_Sensitive : Boolean := True) return String
is
-- ???
-- All the stuff in the declarative part is copied from Osint...
function C_String_Length (S : Address) return Integer;
-- Returns length of a C string (zero for a null address)
function To_Path_String_Access
(Path_Addr : Address;
Path_Len : Integer) return String_Access;
-- Converts a C String to an Ada String. Are we doing this to avoid
-- withing Interfaces.C.Strings ???
-- Caller must free result.
function To_Host_Dir_Spec
(Canonical_Dir : String;
Prefix_Style : Boolean) return String_Access;
-- Convert a canonical syntax directory specification to host syntax.
-- The Prefix_Style flag is currently ignored but should be set to
-- False. Note that the caller must free result.
-- ???
-- Copied from Osint...
function C_String_Length (S : Address) return Integer is
function Strlen (S : Address) return Integer;
pragma Import (C, Strlen, "strlen");
begin
if S = Null_Address then
return 0;
else
return Strlen (S);
end if;
end C_String_Length;
function To_Path_String_Access
(Path_Addr : Address;
Path_Len : Integer) return String_Access
is
subtype Path_String is String (1 .. Path_Len);
type Path_String_Access is access Path_String;
function Address_To_Access is new
Ada.Unchecked_Conversion (Source => Address,
Target => Path_String_Access);
Path_Access : constant Path_String_Access :=
Address_To_Access (Path_Addr);
Return_Val : String_Access;
begin
Return_Val := new String (1 .. Path_Len);
for J in 1 .. Path_Len loop
Return_Val (J) := Path_Access (J);
end loop;
return Return_Val;
end To_Path_String_Access;
function To_Host_Dir_Spec
(Canonical_Dir : String;
Prefix_Style : Boolean) return String_Access
is
function To_Host_Dir_Spec
(Canonical_Dir : Address;
Prefix_Flag : Integer) return Address;
pragma Import (C, To_Host_Dir_Spec, "__gnat_to_host_dir_spec");
C_Canonical_Dir : String (1 .. Canonical_Dir'Length + 1);
Host_Dir_Addr : Address;
Host_Dir_Len : Integer;
begin
C_Canonical_Dir (1 .. Canonical_Dir'Length) := Canonical_Dir;
C_Canonical_Dir (C_Canonical_Dir'Last) := ASCII.NUL;
if Prefix_Style then
Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 1);
else
Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 0);
end if;
Host_Dir_Len := C_String_Length (Host_Dir_Addr);
if Host_Dir_Len = 0 then
return null;
else
return To_Path_String_Access (Host_Dir_Addr, Host_Dir_Len);
end if;
end To_Host_Dir_Spec;
begin
if Name = "" then
return "";
else
Free (Asis_Normalize_Pathname_Result);
Asis_Normalize_Pathname_Result := To_Host_Dir_Spec (
Canonical_Dir =>
Normalize_Pathname (
Name => Name,
Directory => Directory,
Resolve_Links => Resolve_Links,
Case_Sensitive => Case_Sensitive),
Prefix_Style => False);
return Asis_Normalize_Pathname_Result.all;
end if;
end Asis_Normalize_Pathname;
---------------------------
-- Increase_ASIS_OS_Time --
---------------------------
procedure Increase_ASIS_OS_Time is
begin
ASIS_Clock := ASIS_Clock + 1;
end Increase_ASIS_OS_Time;
-----------
-- Later --
-----------
function Later (L, R : ASIS_OS_Time) return Boolean is
begin
return L <= R;
end Later;
------------------------------
-- Parameter_String_To_List --
------------------------------
function Parameter_String_To_List
(Par_String : String)
return Argument_List_Access
is
Max_Pars : constant Integer := Par_String'Length;
New_Parv : Argument_List (1 .. Max_Pars);
New_Parc : Natural := 0;
Idx : Integer;
Old_Idx : Integer;
function Move_To_Next_Par (Ind : Integer) return Integer;
-- Provided that Ind points somewhere inside Par_String, moves
-- it ahead to point to the beginning of the next parameter if
-- Ind points to the character considering as a parameter separator,
-- otherwise returns Ind unchanged. If Ind points to a separator and
-- there is no more parameters ahead, Par_String'Last + 1 is returned.
-- (See the definition of the syntax of the Parameters string in the
-- ASIS Reference Manual)
function Move_To_Par_End (Ind : Integer) return Integer;
-- Provided that Ind points to some character of a separate parameters
-- being a part of Par_String, returns the index of the last character
-- of this parameter
function Move_To_Next_Par (Ind : Integer) return Integer is
Result : Integer := Ind;
begin
while Result <= Par_String'Last and then
(Par_String (Result) = ' ' or else
Par_String (Result) = ASCII.HT or else
Par_String (Result) = ASCII.LF or else
Par_String (Result) = ASCII.CR)
loop
Result := Result + 1;
end loop;
return Result;
end Move_To_Next_Par;
function Move_To_Par_End (Ind : Integer) return Integer is
Result : Integer := Ind;
Quoted : Boolean := False;
begin
loop
-- Am unquoted white space or EOL is the end of an argument
if not Quoted
and then
(Par_String (Result) = ' ' or else
Par_String (Result) = ASCII.HT or else
Par_String (Result) = ASCII.LF or else
Par_String (Result) = ASCII.CR)
then
exit;
-- Start of quoted string
elsif not Quoted
and then Par_String (Result) = '"'
then
Quoted := True;
-- End of a quoted string and end of an argument
elsif Quoted
and then Par_String (Result) = '"'
then
Result := Result + 1;
exit;
end if;
Result := Result + 1;
exit when Result > Par_String'Last;
end loop;
Result := Result - 1;
return Result;
end Move_To_Par_End;
begin
Idx := Move_To_Next_Par (Par_String'First);
while Idx <= Par_String'Last loop
Old_Idx := Idx;
Idx := Move_To_Par_End (Idx);
New_Parc := New_Parc + 1;
New_Parv (New_Parc) :=
new String'(Par_String (Old_Idx .. Idx));
Idx := Move_To_Next_Par (Idx + 1);
end loop;
return new Argument_List'(New_Parv (1 .. New_Parc));
end Parameter_String_To_List;
begin
if Hostparm.OpenVMS then
ASIS_Path_Separator := ',';
ASIS_Current_Directory := new String'("[]");
else
ASIS_Path_Separator := GNAT.OS_Lib.Path_Separator;
ASIS_Current_Directory := new String'(".");
end if;
end A4G.A_Types;
|
generic
Number_Of_Statements: Positive;
package Logic is
--types
subtype Indices is Natural range 1 .. Number_Of_Statements;
type Table is array(Indices range <>) of Boolean;
type Predicate is access function(T: Table) return Boolean;
type Statements is array(Indices) of Predicate;
type Even_Odd is (Even, Odd);
-- convenience functions
function Sum(T: Table) return Natural;
function Half(T: Table; Which: Even_Odd) return Table;
end Logic;
|
-- 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.VREF is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- VREF control and status register
type CSR_Register is record
-- Voltage reference buffer enable
ENVR : Boolean := False;
-- High impedance mode
HIZ : Boolean := True;
-- Voltage reference scale
VRS : Boolean := False;
-- Read-only. Voltage reference buffer ready
VRR : Boolean := False;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CSR_Register use record
ENVR at 0 range 0 .. 0;
HIZ at 0 range 1 .. 1;
VRS at 0 range 2 .. 2;
VRR at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
subtype CCR_TRIM_Field is HAL.UInt6;
-- calibration control register
type CCR_Register is record
-- Trimming code
TRIM : CCR_TRIM_Field := 16#0#;
-- unspecified
Reserved_6_31 : HAL.UInt26 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CCR_Register use record
TRIM at 0 range 0 .. 5;
Reserved_6_31 at 0 range 6 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Voltage reference buffer
type VREFBUF_Peripheral is record
-- VREF control and status register
CSR : aliased CSR_Register;
-- calibration control register
CCR : aliased CCR_Register;
end record
with Volatile;
for VREFBUF_Peripheral use record
CSR at 16#0# range 0 .. 31;
CCR at 16#4# range 0 .. 31;
end record;
-- Voltage reference buffer
VREFBUF_Periph : aliased VREFBUF_Peripheral
with Import, Address => VREFBUF_Base;
end STM32_SVD.VREF;
|
with Ada.Finalization;
package Pak is
type T is new Ada.Finalization.Controlled with null record;
procedure Initialize (X : in out T);
procedure Finalize (X : in out T);
procedure Assign (X : out T'Class);
end Pak;
|
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- 18 package Asis.Statements
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
package Asis.Statements is
pragma Preelaborate;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Asis.Statements encapsulates a set of queries that operate on A_Statement,
-- A_Path, and An_Exception_Handler elements.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- 18.1 function Label_Names
-------------------------------------------------------------------------------
function Label_Names (Statement : in Asis.Statement)
return Asis.Defining_Name_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the statement to query
--
-- Returns label_statement_identifier elements (A_Defining_Name elements)
-- that define the labels attached to the statement, in their order of
-- appearance.
--
-- Returns a Nil_Element_List if there are no labels attached to the
-- statement.
--
-- The Enclosing_Element of the A_Defining_Name elements is the statement.
--
-- Appropriate Element_Kinds:
-- A_Statement
--
-- Returns Defining_Name_Kinds:
-- A_Defining_Identifier
--
-------------------------------------------------------------------------------
-- 18.2 function Assignment_Variable_Name
-------------------------------------------------------------------------------
function Assignment_Variable_Name (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the assignment statement to query
--
-- Returns the expression that names the left hand side of the assignment.
--
-- Appropriate Element_Kinds:
-- A_Statement
--
-- Appropriate Statement_Kinds:
-- An_Assignment_Statement
--
-- Returns Element_Kinds:
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.3 function Assignment_Expression
-------------------------------------------------------------------------------
function Assignment_Expression (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the assignment statement to query
--
-- Returns the expression from the right hand side of the assignment.
--
-- Appropriate Element_Kinds:
-- A_Statement
--
-- Appropriate Statement_Kinds:
-- An_Assignment_Statement
--
-- Returns Element_Kinds:
-- An_Expression
-------------------------------------------------------------------------------
-- 18.4 function Statement_Paths
-------------------------------------------------------------------------------
function Statement_Paths (Statement : in Asis.Statement;
Include_Pragmas : in Boolean := False)
return Asis.Path_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the statement to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of the execution paths of the statement, in
-- their order of appearance.
--
-- The only pragmas returned are those preceding the first alternative in
-- a case statement.
--
-- Appropriate Statement_Kinds:
-- An_If_Statement
-- A_Case_Statement
-- A_Selective_Accept_Statement
-- A_Timed_Entry_Call_Statement
-- A_Conditional_Entry_Call_Statement
-- An_Asynchronous_Select_Statement
--
-- Returns Element_Kinds:
-- A_Path
-- A_Pragma
--
-------------------------------------------------------------------------------
-- 18.5 function Condition_Expression
-------------------------------------------------------------------------------
function Condition_Expression (Path : in Asis.Path)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Path - Specifies the execution path to query
--
-- Returns the condition expression for an IF path or an ELSIF path.
--
-- Appropriate Path_Kinds:
-- An_If_Path
-- An_Elsif_Path
--
-- Returns Element_Kinds:
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.6 function Sequence_Of_Statements
-------------------------------------------------------------------------------
function Sequence_Of_Statements (Path : in Asis.Path;
Include_Pragmas : in Boolean := False)
return Asis.Statement_List;
-------------------------------------------------------------------------------
-- Path - Specifies the execution path to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of the statements and pragmas from an execution path,
-- in their order of appearance.
--
-- Appropriate Element_Kinds:
-- A_Path
--
-- Returns Element_Kinds:
-- A_Statement
-- A_Pragma
--
-------------------------------------------------------------------------------
-- 18.7 function Case_Expression
-------------------------------------------------------------------------------
function Case_Expression (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the case statement to query
--
-- Returns the expression of the case statement that determines which
-- execution path is taken.
--
-- Appropriate Element_Kinds:
-- A_Statement
--
-- Appropriate Statement_Kinds:
-- A_Case_Statement
--
-- Returns Element_Kinds:
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.8 function Case_Statement_Alternative_Choices
-------------------------------------------------------------------------------
function Case_Statement_Alternative_Choices (Path : in Asis.Path)
return Asis.Element_List;
-------------------------------------------------------------------------------
-- Path - Specifies the case_statement_alternative execution path to query
--
-- Returns a list of the 'when <choice> | <choice>' elements, in their
-- order of appearance.
--
-- Appropriate Path_Kinds:
-- A_Case_Path
--
-- Returns Element_Kinds:
-- An_Expression
-- A_Definition
--
-- Returns Definition_Kinds:
-- A_Discrete_Range
-- An_Others_Choice
--
-------------------------------------------------------------------------------
-- 18.9 function Statement_Identifier
-------------------------------------------------------------------------------
function Statement_Identifier (Statement : in Asis.Statement)
return Asis.Defining_Name;
-------------------------------------------------------------------------------
-- Statement - Specifies the statement to query
--
-- Returns the identifier for the loop_statement or block_statement.
--
-- Returns a Nil_Element if the loop has no identifier.
--
-- The Enclosing_Element of the name is the statement.
--
-- Appropriate Statement_Kinds:
-- A_Loop_Statement
-- A_While_Loop_Statement
-- A_For_Loop_Statement
-- A_Block_Statement
--
-- Returns Defining_Name_Kinds:
-- Not_A_Defining_Name
-- A_Defining_Identifier
--
-------------------------------------------------------------------------------
-- 18.10 function Is_Name_Repeated
-------------------------------------------------------------------------------
function Is_Name_Repeated (Statement : in Asis.Statement) return Boolean;
-------------------------------------------------------------------------------
-- Statement - Specifies the statement to query
--
-- Returns True if the name of the accept, loop, or block is repeated after
-- the end of the statement. Always returns True for loop or block
-- statements since the name is required.
--
-- Returns False for any unexpected Element.
--
-- Expected Statement_Kinds:
-- A_Block_Statement
-- A_Loop_Statement
-- An_Accept_Statement
--
-------------------------------------------------------------------------------
-- 18.11 function While_Condition
-------------------------------------------------------------------------------
function While_Condition (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the loop statement to query
--
-- Returns the condition expression associated with the while loop.
--
-- Appropriate Element_Kinds:
-- A_Statement
--
-- Appropriate Statement_Kinds:
-- A_While_Loop_Statement
--
-- Returns Element_Kinds:
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.12 function For_Loop_Parameter_Specification
-------------------------------------------------------------------------------
function For_Loop_Parameter_Specification (Statement : in Asis.Statement)
return Asis.Declaration;
-------------------------------------------------------------------------------
-- Statement - Specifies the loop statement to query
--
-- Returns the declaration of the A_Loop_Parameter_Specification.
--
-- Appropriate Statement_Kinds:
-- A_For_Loop_Statement
--
-- Returns Declaration_Kinds:
-- A_Loop_Parameter_Specification
--
-------------------------------------------------------------------------------
-- 18.13 function Loop_Statements
-------------------------------------------------------------------------------
function Loop_Statements (Statement : in Asis.Statement;
Include_Pragmas : in Boolean := False)
return Asis.Statement_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the loop statement to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns the sequence_of_statements and any pragmas from the loop_statement,
-- in their order of appearance.
--
-- Appropriate Statement_Kinds:
-- A_Loop_Statement
-- A_While_Loop_Statement
-- A_For_Loop_Statement
--
-- Returns Element_Kinds:
-- A_Pragma
-- A_Statement
--
-------------------------------------------------------------------------------
-- 18.14 function Is_Declare_Block
-------------------------------------------------------------------------------
function Is_Declare_Block (Statement : in Asis.Statement) return Boolean;
-------------------------------------------------------------------------------
-- Statement - Specifies the statement to query
--
-- Returns True if the statement is a block_statement and it was created with
-- the use of the "declare" reserved word. The presence or absence of any
-- declarative_item elements is not relevant.
--
-- Returns False if the "declare" reserved word does not appear in the
-- block_statement, or for any unexpected Element.
--
-- Expected Statement_Kinds::
-- A_Block_Statement
--
-------------------------------------------------------------------------------
-- 18.15 function Block_Declarative_Items
-------------------------------------------------------------------------------
function Block_Declarative_Items
(Statement : in Asis.Statement;
Include_Pragmas : in Boolean := False)
return Asis.Declarative_Item_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the block statement to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of the declarations, representation_clause elements,
-- pragmas, and use_clause elements in the declarative_part of the
-- block_statement, in their order of appearance.
--
-- Returns a Nil_Element_List if there are no declarative items.
--
-- Appropriate Statement_Kinds:
-- A_Block_Statement
--
-- Returns Element_Kinds:
-- A_Declaration
-- A_Pragma
-- A_Clause
--
-------------------------------------------------------------------------------
-- 18.16 function Block_Statements
-------------------------------------------------------------------------------
function Block_Statements (Statement : in Asis.Statement;
Include_Pragmas : in Boolean := False)
return Asis.Statement_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the block statement to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of the statements and pragmas for the block_statement, in
-- their order of appearance.
--
-- Returns a Nil_Element_List if there are no statements or pragmas. This
-- can only occur for a block_statement obtained from the obsolescent query
-- Body_Block_Statement when its argument is a package_body
-- that has no sequence_of_statements.
--
-- Appropriate Statement_Kinds:
-- A_Block_Statement
--
-- Returns Element_Kinds:
-- A_Pragma
-- A_Statement
--
-------------------------------------------------------------------------------
-- 18.17 function Block_Exception_Handlers
-------------------------------------------------------------------------------
function Block_Exception_Handlers (Statement : in Asis.Statement;
Include_Pragmas : in Boolean := False)
return Asis.Exception_Handler_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the block statement to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns a list of the exception_handler elements of the block_statement,
-- in their order of appearance.
--
-- The only pragmas returned are those following the reserved word "exception"
-- and preceding the reserved word "when" of first exception handler.
--
-- Returns a Nil_Element_List if there are no exception_handler elements.
--
-- Appropriate Statement_Kinds:
-- A_Block_Statement
--
-- Returns Element_Kinds:
-- An_Exception_Handler
-- A_Pragma
--
-------------------------------------------------------------------------------
-- 18.18 function Exit_Loop_Name
-------------------------------------------------------------------------------
function Exit_Loop_Name (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the exit statement to query
--
-- Returns the name of the exited loop.
--
-- Returns a Nil_Element if no loop name is present.
--
-- Appropriate Statement_Kinds:
-- An_Exit_Statement
--
-- Returns Expression_Kinds:
-- Not_An_Expression
-- An_Identifier
-- A_Selected_Component
--
-------------------------------------------------------------------------------
-- 18.19 function Exit_Condition
-------------------------------------------------------------------------------
function Exit_Condition (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the exit statement to query
--
-- Returns the "when" condition of the exit statement.
--
-- Returns a Nil_Element if no condition is present.
--
-- Appropriate Statement_Kinds:
-- An_Exit_Statement
--
-- Returns Element_Kinds:
-- Not_An_Element
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.20 function Corresponding_Loop_Exited
-------------------------------------------------------------------------------
function Corresponding_Loop_Exited (Statement : in Asis.Statement)
return Asis.Statement;
-------------------------------------------------------------------------------
-- Statement - Specifies the exit statement to query
--
-- Returns the loop statement exited by the exit statement.
--
-- Appropriate Statement_Kinds:
-- An_Exit_Statement
--
-- Returns Element_Kinds:
-- A_Loop_Statement
-- A_While_Loop_Statement
-- A_For_Loop_Statement
--
-------------------------------------------------------------------------------
-- 18.21 function Return_Expression
-------------------------------------------------------------------------------
function Return_Expression (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the return statement to query
--
-- Returns the expression in the return statement.
--
-- Returns a Nil_Element if no expression is present.
--
-- Appropriate Statement_Kinds:
-- A_Return_Statement
--
-- Returns Element_Kinds:
-- Not_An_Element
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.xx function Return_Object_Specification
-------------------------------------------------------------------------------
function Return_Object_Specification (Statement : Asis.Statement)
return Asis.Declaration;
-------------------------------------------------------------------------------
-- Statement specifies the extended return statement to query.
--
-- Returns the specification of the return object.
--
-- Appropriate Statement_Kinds:
-- An_Extended_Return_Statement
--
-- Returns Declaration_Kinds:
-- A_Return_Object_Specification
--
-------------------------------------------------------------------------------
-- 18.xx function Extended_Return_Statements
-------------------------------------------------------------------------------
function Extended_Return_Statements
(Statement : Asis.Statement;
Include_Pragmas : Boolean := False)
return Asis.Statement_List;
-------------------------------------------------------------------------------
-- Statement specifies the extended return statement to query.
-- Include_Pragmas specifies whether pragmas are to be returned.
--
-- Returns a list of the statements and pragmas from the extended return
-- statement, in their order of appearance.
--
-- Returns a Nil_Element_List if the argument extended return statement does
-- not include handled_sequence_of_statements.
--
-- Appropriate Statement_Kinds:
-- An_Extended_Return_Statement
--
-- Returns Element_Kinds:
-- A_Statement
-- A_Pragma
--
-------------------------------------------------------------------------------
-- 18.xx function Extended_Return_Exception_Handlers
-------------------------------------------------------------------------------
function Extended_Return_Exception_Handlers
(Statement : Asis.Statement;
Include_Pragmas : Boolean := False)
return Asis.Exception_Handler_List;
-------------------------------------------------------------------------------
-- Statement specifies the extended return statement to query.
-- Include_Pragmas specifies whether pragmas are to be returned.
--
-- Returns a list of the exception_handler elements of the extended return
-- statement, in their order of appearance.
--
-- The only pragmas returned are those following the reserved word "exception"
-- and preceding the reserved word "when" of first exception handler.
--
-- Returns a Nil_Element_List if there are no exception_handler elements.
--
-- Appropriate Statement_Kinds:
-- An_Extended_Return_Statement
--
-- Returns Element_Kinds:
-- An_Exception_Handler
-- A_Pragma
--
-------------------------------------------------------------------------------
-- 18.22 function Goto_Label
-------------------------------------------------------------------------------
function Goto_Label (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the goto statement to query
--
-- Returns the expression reference for the label, as specified by the goto
-- statement.
--
-- Appropriate Statement_Kinds:
-- A_Goto_Statement
--
-- Returns Expression_Kinds:
-- An_Identifier
--
-------------------------------------------------------------------------------
-- 18.23 function Corresponding_Destination_Statement
-------------------------------------------------------------------------------
function Corresponding_Destination_Statement
(Statement : in Asis.Statement)
return Asis.Statement;
-------------------------------------------------------------------------------
-- Statement - Specifies the goto statement to query
--
-- Returns the target statement specified by the goto statement.
--
-- Appropriate Statement_Kinds:
-- A_Goto_Statement
--
-- Returns Element_Kinds:
-- A_Statement
--
-- |AN Application Note:
-- |AN
-- |AN The Reference Manual allows a pragma between a statement and a label
-- |AN attached to it. If so, when the label is passed as an actual parameter
-- |AN to this query, the query returns the statement, but not the label. The
-- |AN only way for an application to know that there are any pragmas between
-- |AN a statement and its label is to get the spans of these program
-- |AN elements and analyze the corresponding positions in the source text.
--
-------------------------------------------------------------------------------
-- 18.24 function Called_Name
-------------------------------------------------------------------------------
function Called_Name (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the procedure call or entry call statement to query
--
-- Returns the name of the called procedure or entry. The name of an entry
-- family takes the form of An_Indexed_Component.
--
-- Appropriate Statement_Kinds:
-- An_Entry_Call_Statement
-- A_Procedure_Call_Statement
--
-- Returns Element_Kinds:
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.25 function Corresponding_Called_Entity
-------------------------------------------------------------------------------
function Corresponding_Called_Entity (Statement : in Asis.Statement)
return Asis.Declaration;
-------------------------------------------------------------------------------
-- Statement - Specifies the procedure_call_statement or
-- entry_call_statement to query
--
-- Returns the declaration of the procedure or entry denoted by the call.
--
-- Returns a Nil_Element if the:
--
-- - prefix of the call denotes an access to a procedure implicit
-- or explicit dereference,
--
-- - argument is a dispatching call,
--
-- - argument is a call to a dispatching operation of a tagged type which
-- is not statically determined.
--
-- If procedure_prefix denotes an attribute_reference, and if the
-- corresponding attribute is (re)defined by an attribute definition clause,
-- an implementation is encouraged, but not required, to return the
-- definition of the corresponding subprogram whose name is used after "use"
-- in this attribute definition clause. If an implementation cannot return
-- such a subprogram definition, a Nil_Element should be returned. For an
-- attribute reference which is not (re)defined by an attribute definition
-- clause, a Nil_Element should be returned.
--
-- Appropriate Statement_Kinds:
-- An_Entry_Call_Statement
-- A_Procedure_Call_Statement
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- A_Procedure_Declaration
-- A_Procedure_Body_Declaration
-- A_Procedure_Body_Stub
-- A_Procedure_Renaming_Declaration
-- A_Procedure_Instantiation
-- A_Formal_Procedure_Declaration
-- An_Entry_Declaration
-- A_Generic_Procedure_Declaration
--
-- |IP Implementation Permissions
-- |IP
-- |IP An implementation may choose to return any part of multi-part
-- |IP declarations and definitions. Multi-part declaration/definitions
-- |IP can occur for:
-- |IP
-- |IP - Subprogram specification in package specification, package body,
-- |IP and subunits (is separate);
-- |IP - Entries in package specification, package body, and subunits
-- |IP (is separate);
-- |IP - Private type and full type declarations;
-- |IP - Incomplete type and full type declarations; and
-- |IP - Deferred constant and full constant declarations.
-- |IP
-- |IP No guarantee is made that the element will be the first part or
-- |IP that the determination will be made due to any visibility rules.
-- |IP An application should make its own analysis for each case based
-- |IP on which part is returned.
--
-------------------------------------------------------------------------------
-- 18.26 function Call_Statement_Parameters
-------------------------------------------------------------------------------
function Call_Statement_Parameters (Statement : in Asis.Statement;
Normalized : in Boolean := False)
return Asis.Association_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the procedure_call_statement or
-- entry_call_statement to query
-- Normalized - Specifies whether the normalized form is desired
--
-- Returns a list of parameter_association elements of the call.
--
-- Returns a Nil_Element_List if there are no parameter_association elements.
--
-- An unnormalized list contains only explicit associations ordered as they
-- appear in the program text. Each unnormalized association has an optional
-- formal_parameter_selector_name and an explicit_actual_parameter component.
--
-- A normalized list contains artificial associations representing all
-- explicit and default associations. It has a length equal to the number of
-- parameter_specification elements of the formal_part of the
-- parameter_and_result_profile. The order of normalized associations matches
-- the order of parameter_specification elements.
--
-- Each normalized association represents a one on one mapping of a
-- parameter_specification elements to the explicit or default expression.
-- A normalized association has one A_Defining_Name component that denotes the
-- parameter_specification, and one An_Expression component that is either the
-- explicit_actual_parameter or a default_expression.
--
-- If the prefix of the call denotes an access to a procedure implicit or
-- explicit deference, normalized associations are constructed on the basis
-- of the formal_part of the parameter_profile from the corresponding
-- access_to_subprogram definition.
--
-- Returns Nil_Element for normalized associations in the case where
-- the called procedure can be determined only dynamically (dispatching
-- calls). ASIS cannot produce any meaningful result in this case.
--
-- The exception ASIS_Inappropriate_Element is raised when the procedure
-- call is an attribute reference and Is_Normalized is True.
--
-- Appropriate Statement_Kinds:
-- An_Entry_Call_Statement
-- A_Procedure_Call_Statement
--
-- Returns Element_Kinds:
-- A_Parameter_Association
--
-- |IR Implementation Requirements:
-- |IR
-- |IR Normalized associations are Is_Normalized and Is_Part_Of_Implicit.
-- |IR Normalized associations provided by default are
-- |IR Is_Defaulted_Association.
-- |IR Normalized associations are never Is_Equal to unnormalized
-- |IR associations.
--
-- |IP Implementation Permissions:
-- |IP
-- |IP An implementation may choose to always include default parameters in
-- |IP its internal representation.
-- |IP
-- |IP An implementation may also choose to normalize its representation
-- |IP to use defining_identifier elements rather than
-- |IP formal_parameter_selector_name elements.
-- |IP
-- |IP In either case, this query will return Is_Normalized associations even
-- |IP if Normalized is False, and the query
-- |IP Call_Statement_Parameters_Normalized will return True.
--
-------------------------------------------------------------------------------
-- 18.27 function Accept_Entry_Index
-------------------------------------------------------------------------------
function Accept_Entry_Index (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the accept statement to query
--
-- Returns the entry index expression in the accept statement.
--
-- Returns a Nil_Element if the statement has no explicit entry index,
--
-- Appropriate Statement_Kinds:
-- An_Accept_Statement
--
-- Returns Element_Kinds:
-- Not_An_Element
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.28 function Accept_Entry_Direct_Name
-------------------------------------------------------------------------------
function Accept_Entry_Direct_Name (Statement : in Asis.Statement)
return Asis.Name;
-------------------------------------------------------------------------------
-- Statement - Specifies the accept statement to query
--
-- Returns the direct name of the entry. The name follows the reserved word
-- "accept".
--
-- Appropriate Statement_Kinds:
-- An_Accept_Statement
--
-- Returns Expression_Kinds:
-- An_Identifier
--
-------------------------------------------------------------------------------
-- 18.29 function Accept_Parameters
-------------------------------------------------------------------------------
function Accept_Parameters (Statement : in Asis.Statement)
return Asis.Parameter_Specification_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the accept statement to query
--
-- Returns a list of parameter specifications in the formal part of the
-- accept statement, in their order of appearance.
--
-- Returns a Nil_Element_List if the accept_statement has no parameters.
--
-- Results of this query may vary across ASIS implementations. Some
-- implementations normalize all multiple name parameter specifications into
-- an equivalent sequence of corresponding single name parameter
-- specifications. See Reference Manual 3.3.1(7).
--
-- Appropriate Statement_Kinds:
-- An_Accept_Statement
--
-- Returns Declaration_Kinds:
-- A_Parameter_Specification
--
-------------------------------------------------------------------------------
-- 18.30 function Accept_Body_Statements
-------------------------------------------------------------------------------
function Accept_Body_Statements (Statement : in Asis.Statement;
Include_Pragmas : in Boolean := False)
return Asis.Statement_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the accept statement to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns the list of statements and pragmas from the body of the accept
-- statement, in their order of appearance.
--
-- Appropriate Statement_Kinds:
-- An_Accept_Statement
--
-- Returns Element_Kinds:
-- A_Pragma
-- A_Statement
--
-------------------------------------------------------------------------------
-- 18.31 function Accept_Body_Exception_Handlers
-------------------------------------------------------------------------------
function Accept_Body_Exception_Handlers
(Statement : in Asis.Statement;
Include_Pragmas : in Boolean := False)
return Asis.Statement_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the accept statement to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns the list of exception handlers and pragmas from the body of the
-- accept statement, in their order of appearance.
--
-- Appropriate Statement_Kinds:
-- An_Accept_Statement
--
-- Returns Element_Kinds:
-- A_Pragma
-- An_Exception_Handler
--
-------------------------------------------------------------------------------
-- 18.32 function Corresponding_Entry
-------------------------------------------------------------------------------
function Corresponding_Entry (Statement : in Asis.Statement)
return Asis.Declaration;
-------------------------------------------------------------------------------
-- Statement - Specifies the accept statement to query
--
-- Returns the declaration of the entry accepted in this statement.
--
-- Appropriate Statement_Kinds:
-- An_Accept_Statement
--
-- Returns Declaration_Kinds:
-- An_Entry_Declaration
--
-------------------------------------------------------------------------------
-- 18.33 function Requeue_Entry_Name
-------------------------------------------------------------------------------
function Requeue_Entry_Name (Statement : in Asis.Statement)
return Asis.Name;
-------------------------------------------------------------------------------
-- Statement - Specifies the requeue statement to query
--
-- Returns the name of the entry requeued by the statement.
-- The name follows the reserved word "requeue".
--
-- Appropriate Statement_Kinds:
-- A_Requeue_Statement
-- A_Requeue_Statement_With_Abort
--
-- Returns Element_Kinds:
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.34 function Delay_Expression
-------------------------------------------------------------------------------
function Delay_Expression (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the delay statement to query
--
-- Returns the expression for the duration of the delay.
--
-- Appropriate Statement_Kinds:
-- A_Delay_Until_Statement
-- A_Delay_Relative_Statement
--
-- Returns Element_Kinds:
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.35 function Guard
-------------------------------------------------------------------------------
function Guard (Path : in Asis.Path)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Path - Specifies the select statement execution path to query
--
-- Returns the conditional expression guard for the path.
--
-- Returns a Nil_Element if there is no guard, or if the path is from a
-- timed_entry_call, a conditional_entry_call, or an asynchronous_select
-- statement where a guard is not legal.
--
-- Appropriate Path_Kinds:
-- A_Select_Path
-- An_Or_Path
--
-- Returns Element_Kinds:
-- Not_An_Element
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.36 function Aborted_Tasks
-------------------------------------------------------------------------------
function Aborted_Tasks (Statement : in Asis.Statement)
return Asis.Expression_List;
-------------------------------------------------------------------------------
-- Statement - Specifies the abort statement to query
--
-- Returns a list of the task names from the ABORT statement, in their order
-- of appearance.
--
-- Appropriate Statement_Kinds:
-- An_Abort_Statement
--
-- Returns Element_Kinds:
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.37 function Choice_Parameter_Specification
-------------------------------------------------------------------------------
function Choice_Parameter_Specification
(Handler : in Asis.Exception_Handler)
return Asis.Declaration;
-------------------------------------------------------------------------------
-- Handler - Specifies the exception handler to query
--
-- Returns the choice parameter specification following the reserved word
-- "when" in the exception handler.
--
-- Returns a Nil_Element if there is no explicit choice parameter.
--
-- Appropriate Element_Kinds:
-- An_Exception_Handler
--
-- Returns Declaration_Kinds:
-- Not_A_Declaration
-- A_Choice_Parameter_Specification
--
-------------------------------------------------------------------------------
-- 18.38 function Exception_Choices
-------------------------------------------------------------------------------
function Exception_Choices (Handler : in Asis.Exception_Handler)
return Asis.Element_List;
-------------------------------------------------------------------------------
-- Handler - Specifies the exception handler to query
--
-- Returns a list of the 'when <choice> | <choice>' elements, in their
-- order of appearance. Choices are either the exception name expression or
-- an others choice.
--
-- Appropriate Element_Kinds:
-- An_Exception_Handler
--
-- Returns Expression_Kinds:
-- An_Identifier
-- A_Selected_Component
--
-- Returns Definition_Kinds:
-- An_Others_Choice
--
-------------------------------------------------------------------------------
-- 18.39 function Handler_Statements
-------------------------------------------------------------------------------
function Handler_Statements (Handler : in Asis.Exception_Handler;
Include_Pragmas : in Boolean := False)
return Asis.Statement_List;
-------------------------------------------------------------------------------
-- Handler - Specifies the exception handler to query
-- Include_Pragmas - Specifies whether pragmas are to be returned
--
-- Returns the list of statements and pragmas from the body of the
-- exception handler, in their order of appearance.
--
-- Appropriate Element_Kinds:
-- An_Exception_Handler
--
-- Returns Element_Kinds:
-- A_Pragma
-- A_Statement
--
-------------------------------------------------------------------------------
-- 18.40 function Raised_Exception
-------------------------------------------------------------------------------
function Raised_Exception (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the raise statement to query
--
-- Returns the expression that names the raised exception.
--
-- Returns a Nil_Element if there is no explicitly named exception.
--
-- Appropriate Statement_Kinds:
-- A_Raise_Statement
--
-- Returns Expression_Kinds:
-- Not_An_Expression
-- An_Identifier
-- A_Selected_Component
--
-------------------------------------------------------------------------------
-- 18.xx function Raise_Statement_Message
-------------------------------------------------------------------------------
function Raise_Statement_Message -- 13.3(2)
(Statement : Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement specifies the raise statement to query.
--
-- Returns the string expression that is associated with the raised
-- exception and follows the WITH keyword in the raise statement.
--
-- Returns a Nil_Element if there is no string expression.
--
-- Appropriate Statement_Kinds:
-- A_Raise_Statement
--
-- Returns Element_Kinds:
-- Not_An_Element
-- An_Expression
--
-------------------------------------------------------------------------------
-- 18.41 function Qualified_Expression
-------------------------------------------------------------------------------
function Qualified_Expression (Statement : in Asis.Statement)
return Asis.Expression;
-------------------------------------------------------------------------------
-- Statement - Specifies the code statement to query
--
-- Returns the qualified aggregate expression representing the code statement.
--
-- Appropriate Statement_Kinds:
-- A_Code_Statement
--
-- Returns Expression_Kinds:
-- A_Qualified_Expression
--
-------------------------------------------------------------------------------
-- 18.42 function Is_Dispatching_Call
-------------------------------------------------------------------------------
function Is_Dispatching_Call (Call : in Asis.Element) return Boolean;
-------------------------------------------------------------------------------
-- Call - Specifies the element to query.
--
-- Returns True if the controlling tag of Call is dynamically determined.
--
-- This function shall always return False when
-- pragma Restrictions(No_Dispatch) applies.
--
-- Returns False for any unexpected Element.
--
-- Expected Expression_Kinds:
-- A_Function_Call
--
-- Expected Statement_Kinds:
-- A_Procedure_Call_Statement
--
-------------------------------------------------------------------------------
-- 18.43 function Is_Call_On_Dispatching_Operation
-------------------------------------------------------------------------------
function Is_Call_On_Dispatching_Operation (Call : in Asis.Element)
return Boolean;
-------------------------------------------------------------------------------
-- Call - Specifies the element to query.
--
-- Returns True if the name or prefix of Call denotes the declaration of a
-- primitive operation of a tagged type.
--
-- Returns False for any unexpected Element.
--
-- Expected Element_Kinds:
-- A_Function_Call
-- A_Procedure_Call_Statement
--
-------------------------------------------------------------------------------
end Asis.Statements;
------------------------------------------------------------------------------
-- Copyright (c) 2006-2013, Maxim Reznik
-- 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 Maxim Reznik, 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 OWNER OR CONTRIBUTORS BE
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
|
with Ada.Text_IO;
with Ada.Command_Line;
with Config;
procedure Show_Config is
use Config;
C : constant Content_Type := Get_Content ("example.conf");
begin
if C.Content = null then
Ada.Text_IO.Put_Line ("FAIL: No configuration file 'example.conf'");
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
return;
end if;
for Val of C.Content.all loop
Ada.Text_IO.Put (Character'Val (Val));
end loop;
end Show_Config;
|
-- MIT License
-- Copyright (c) 2021 Stephen Merrony
-- 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.Containers; use Ada.Containers;
with Ada.Containers.Hashed_Maps;
with Interfaces; use Interfaces;
with DG_Types; use DG_Types;
package Memory is
Words_Per_Page : constant Natural := 1024;
Ring_7_Page_0 : constant Natural := 16#001c_0000#;
-- Physical stuff that has to exist...
Mem_Size_Words : constant Integer := 8_388_608;
-- MemSizeLCPID is the code returned by the LCPID to indicate the size of RAM in half megabytes
Mem_Size_LCPID : constant Dword_T := 63;
-- MemSizeNCLID is the code returned by NCLID to indicate size of RAM in 32Kb increments
Mem_Size_NCLID : constant Word_T := Word_T(((Mem_Size_Words * 2) / (32 * 1024)) - 1);
type Memory_Region is array (Natural range <>) of Word_T;
type Page_T is array (0 .. Words_Per_Page - 1) of Word_T;
type Page_Arr_T is array (Natural range <>) of Page_T;
-- Page 0 special locations for stacks
WSFH_Loc : constant Phys_Addr_T := 8#14#;
WFP_Loc : constant Phys_Addr_T := 8#20#;
WSP_Loc : constant Phys_Addr_T := 8#22#;
WSL_Loc : constant Phys_Addr_T := 8#24#;
WSB_Loc : constant Phys_Addr_T := 8#26#;
NSP_Loc : constant Phys_Addr_T := 8#40#;
NFP_Loc : constant Phys_Addr_T := 8#41#;
NSL_Loc : constant Phys_Addr_T := 8#42#;
NSF_Loc : constant Phys_Addr_T := 8#43#;
-- Wide Stack Fault codes
WSF_Overflow : constant Dword_T := 0;
WSF_Pending : constant Dword_T := 1;
WSF_Too_Many_Args : constant Dword_T := 2;
WSF_Underflow : constant Dword_T := 3;
WSF_Return_Overflow : constant Dword_T := 4;
function NaturalHash (K : Natural) return Hash_Type is (Hash_Type (K));
package VRAM_Map is new Ada.Containers.Hashed_Maps (
Key_Type => Natural,
Hash => NaturalHash,
Equivalent_Keys => "=",
Element_Type => Page_T );
protected RAM is
procedure Init (Debug_Logging : in Boolean);
procedure Map_Page (Page : in Natural; Is_Shared : in Boolean);
function Page_Mapped (Page : in Natural) return Boolean;
function Get_Last_Unshared_Page return Dword_T;
function Get_First_Shared_Page return Dword_T;
function Get_Num_Shared_Pages return Dword_T;
function Get_Num_Unshared_Pages return Dword_T;
procedure Map_Range (Start_Addr : in Phys_Addr_T;
Region : in Memory_Region;
Is_Shared : in Boolean);
procedure Map_Shared_Pages (Start_Addr : in Phys_Addr_T; Pages : in Page_Arr_T);
-- function Address_Mapped (Addr : in Phys_Addr_T) return Boolean;
function Read_Word (Word_Addr : in Phys_Addr_T) return Word_T with Inline;
function Read_Dword (Word_Addr : in Phys_Addr_T) return Dword_T;
function Read_Qword (Word_Addr : in Phys_Addr_T) return Qword_T;
procedure Write_Word (Word_Addr : in Phys_Addr_T; Datum : Word_T);
procedure Write_Dword (Word_Addr : in Phys_Addr_T; Datum : Dword_T);
procedure Write_Qword (Word_Addr : in Phys_Addr_T; Datum : Qword_T);
function Read_Byte (Word_Addr : in Phys_Addr_T; Low_Byte : in Boolean) return Byte_T;
function Read_Byte_BA (BA : in Dword_T) return Byte_T;
procedure Write_Byte (Word_Addr : in Phys_Addr_T; Low_Byte : in Boolean; Byt : in Byte_T);
procedure Write_Byte_BA (BA : in Dword_T; Datum : in Byte_T);
procedure Copy_Byte_BA (Src, Dest : in Dword_T);
function Read_Byte_Eclipse_BA (Segment : in Phys_Addr_T; BA_16 : in Word_T) return Byte_T;
procedure Write_Byte_Eclipse_BA (Segment : in Phys_Addr_T; BA_16 : in Word_T; Datum : in Byte_T);
function Read_Bytes_BA (BA : in Dword_T; Num : in Natural) return Byte_Arr_T;
-- specific support for VS/Emua...
function Read_String_BA (BA : in Dword_T; Keep_NUL : in Boolean) return String;
procedure Write_String_BA (BA : in Dword_T; Str : in String);
private
VRAM : VRAM_Map.Map;
Logging : Boolean;
First_Shared_Page,
Last_Unshared_Page,
Num_Unshared_Pages,
Num_Shared_Pages : Natural;
end RAM;
protected Narrow_Stack is
procedure Push (Segment : in Phys_Addr_T; Datum : in Word_T);
function Pop (Segment : in Phys_Addr_T) return Word_T;
end Narrow_Stack;
Page_Already_Mapped,
Read_From_Unmapped_Page,
Write_To_Unmapped_Page : exception;
end Memory; |
--
-- 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.Config;
with HW.PCI.MMConf;
with HW.Debug;
with HW.MMIO_Range;
pragma Elaborate_All (HW.MMIO_Range);
package body HW.PCI.Dev
with
Refined_State =>
(Address_State => MM.Address_State,
PCI_State => MM.PCI_State)
is
package MM is new HW.PCI.MMConf (Dev);
procedure Read8 (Value : out Word8; Offset : Index) renames MM.Read8;
procedure Read16 (Value : out Word16; Offset : Index) renames MM.Read16;
procedure Read32 (Value : out Word32; Offset : Index) renames MM.Read32;
procedure Write8 (Offset : Index; Value : Word8) renames MM.Write8;
procedure Write16 (Offset : Index; Value : Word16) renames MM.Write16;
procedure Write32 (Offset : Index; Value : Word32) renames MM.Write32;
procedure Map
(Addr : out Word64;
Res : in Resource;
Length : in Natural := 0;
Offset : in Natural := 0;
WC : in Boolean := False)
is
use type HW.Word8;
use type HW.Word32;
Header_Type : Word8;
Reg32 : Word32;
begin
Addr := 0;
Read8 (Header_Type, PCI.Header_Type);
if (Header_Type and Header_Type_Mask) = Header_Type_Normal then
Read32 (Reg32, Base_Address (Res));
if (Reg32 and Base_Address_Space_Mask) = Base_Address_Space_Mem then
case Reg32 and Base_Address_Mem_Type_Mask is
when Base_Address_Mem_Type_64 =>
if Res < Res5 then
Addr := Word64 (Reg32 and Base_Address_Mem_Mask);
Read32 (Reg32, Base_Address (Resource'Succ (Res)));
Addr := Addr or Shift_Left (Word64 (Reg32), 32);
end if;
when others =>
Addr := Word64 (Reg32 and Base_Address_Mem_Mask);
end case;
end if;
end if;
if Addr /= 0 then
if Length = 0 or else
Addr <= Word64'Last - Word64 (Length) - Word64 (Offset) + 1
then
Addr := Addr + Word64 (Offset);
else
Addr := 0;
end if;
end if;
end Map;
procedure Resource_Size (Length : out Natural; Res : Resource)
is
use Type HW.Word16;
use Type HW.Word32;
Cmd : Word16;
Base, Backup : Word32;
begin
Length := 0;
Read16 (Cmd, PCI.Command);
Write16 (PCI.Command, Cmd and not PCI.Command_Memory);
Read32 (Backup, Base_Address (Res));
if (Backup and Base_Address_Space_Mask) = Base_Address_Space_Mem then
Write32 (Base_Address (Res), 16#ffff_ffff#);
Read32 (Base, Base_Address (Res));
Base := not (Base and Base_Address_Mem_Mask) + 1;
if Base <= Word32 (Natural'Last) then
Length := Natural (Base);
end if;
Write32 (Base_Address (Res), Backup);
end if;
Write16 (PCI.Command, Cmd);
end Resource_Size;
procedure Initialize (Success : out Boolean; MMConf_Base : Word64 := 16#b0000000#)
is
begin
Debug.Put ("Initialize MMIO: ");
MM.Set_Base_Address(MMConf_Base);
Debug.Put_Word64(MMConf_Base);
Debug.Put_Line("");
Debug.Put ("Initialize MMIO: ");
Debug.Put_Line("");
Success := True ; --MMConf_Base /= 0 or Config.Default_MMConf_Base_Set;
end Initialize;
end HW.PCI.Dev;
|
-- This demonstration illustrates the use of PWM to control the brightness of
-- an LED. The effect is to make the LED increase and decrease in brightness,
-- iteratively, for as long as the application runs. In effect the LED light
-- waxes and wanes as function of a PWM sine wave generated with the CORDIC
-- coprocessor.
--
-- The demo uses an abstract data type PWM_Modulator to control the power to
-- the LED via pulse-width-modulation. A timer is still used underneath, but
-- the details are hidden. For direct use of the timer see the other demo.
with HAL; use HAL;
with STM32.Device; use STM32.Device;
with STM32.Timers; use STM32.Timers;
with STM32.PWM; use STM32.PWM;
with STM32.CORDIC.Polling; use STM32.CORDIC;
with STM_Board; use STM_Board;
with Last_Chance_Handler; pragma Unreferenced (Last_Chance_Handler);
-- The "last chance handler" is the user-defined routine that is called when
-- an exception is propagated. We need it in the executable, therefore it
-- must be somewhere in the closure of the context clauses.
procedure Test_LED_PWM is
-- The LD2 green led at GPIO PA5 is the TIM2_CH1 timer output when
-- programmed as AF1 alternate function.
Selected_Timer : Timer renames Timer_2;
Timer_AF : constant STM32.GPIO_Alternate_Function := GPIO_AF_TIM2_1;
Output_Channel : constant Timer_Channel := Channel_1;
Requested_Frequency : constant Hertz := 25_000;
Power_Control : PWM_Modulator;
begin
Configure_PWM_Timer (Selected_Timer'Access, Requested_Frequency);
Power_Control.Attach_PWM_Channel
(Selected_Timer'Access,
Channel => Output_Channel,
Point => Green_LED,
PWM_AF => Timer_AF);
Power_Control.Enable_Output;
-- Configure CORDIC coprocessor with sine function
Enable_Clock (CORDIC_Unit);
Configure_CORDIC_Coprocessor
(CORDIC_Unit,
Operation => Sine,
Precision => Iteration_12,
Data_Size => Data_32_Bit);
declare
-- The CORDIC operates in fixed point signed integer format. Input and
-- output values can be either q1.31 or q1.15.
-- In q1.31 format, numbers are represented by one sign bit and 31
-- fractional bits (binary decimal places). The numeric range is
-- therefore -1 (0x80000000) to 1 - 2**(-31) (0x7FFFFFFF).
-- In q1.15 format, the numeric range is 1 (0x8000) to 1 - 2**(-15)
-- (0x7FFF).
Angle : Q1_31 := -0.5;
-- The start angle is -0.5, that corresponds to -Pi/2, so with sine
-- funtion the LED start off.
Modulus : constant UInt32 := 16#7FFFFFFF#; -- 1 - 2**(-31)
-- For sine function, the first argument is the angle, while the second
-- argument is the modulus, that in this case doesn't change.
Increment : Q1_31 := 1.0 / 4_194_304; -- = 1.0 / 2**22
-- This value must be a multiple of delta (2.0**(-31)).
-- The Increment value controls the rate at which the brightness
-- increases and decreases and depends on the CPU clock frequency.
Data_In : UInt32_Array := (Q1_31_To_UInt32 (Angle), Modulus);
-- The sine function goes from -1.0 to 0.0 to 1.0 in a complete sine
-- period, that corresponds to -Pi to 0 to Pi.
Data_Out : UInt32_Array := (0, 0);
Value : Percentage;
begin
loop
-- Calculate sine function
Polling.Calculate_CORDIC_Function
(CORDIC_Unit,
Argument => Data_In,
Result => Data_Out);
-- The input (WDATA) and output (RDATA) data of the CORDIC uses UInt32
-- to represent the fixed point values. So we need to convert the type
-- Fraction_32 to UInt32 and vice-versa.
Value := Percentage (100.0 * (Float (UInt32_To_Q1_31 (Data_Out (1)))));
Power_Control.Set_Duty_Cycle (Value);
-- Data input to CORDIC must be between -1.0 and 1.0 - 1 / 2**(-31),
-- and this corresponds to -pi and pi. The value calculation considers
-- that the LED is OFF when the Angle is -0.5 (-Pi/2), it is half
-- bright when the Angle is 0 and it is ON when the Angle is 0.5 (Pi/2).
-- When the angle value reaches any of these maximum, it must be
-- incremented/decremented.
if (Angle + Increment > 0.5) or (Angle + Increment < -0.5) then
Increment := -Increment;
end if;
Angle := Angle + Increment;
-- Write the new angle value into the first position of the buffer.
Data_In (1) := Q1_31_To_UInt32 (Angle);
end loop;
end;
end Test_LED_PWM;
|
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
package Exported is
function Query (Data : chars_ptr; Size : access size_t)
return int;
pragma Export (C, Query, "Query");
end Exported;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- M E M R O O T --
-- --
-- S p e c --
-- --
-- Copyright (C) 1997-2005, AdaCore --
-- --
-- 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. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package offers basic types that deal with gdb backtraces related
-- to memory allocation. A memory root (root_id) is a backtrace
-- referencing the actual point of allocation along with counters
-- recording various information concerning allocation at this root.
-- A back trace is composed of Frames (Frame_Id) which themselves are
-- nothing else than a subprogram call at a source location which can be
-- represented by three strings: subprogram name, file name and line
-- number. All the needed strings are entered in a table and referenced
-- through a Name_Id in order to avoid duplication.
with System.Storage_Elements; use System.Storage_Elements;
package Memroot is
-- Simple abstract type for names. A name is a sequence of letters
type Name_Id is new Natural;
No_Name_Id : constant Name_Id := 0;
function Enter_Name (S : String) return Name_Id;
function Image (N : Name_Id) return String;
-- Simple abstract type for a backtrace frame. A frame is composed by
-- a subprogram name, a file name and a line reference.
type Frame_Id is new Natural;
No_Frame_Id : constant Frame_Id := 0;
function Enter_Frame
(Addr : System.Address;
Name : Name_Id;
File : Name_Id;
Line : Name_Id)
return Frame_Id;
type Frame_Array is array (Natural range <>) of Frame_Id;
-- Simple abstract type for an allocation root. It is composed by a set
-- of frames, the number of allocation, the total size of allocated
-- memory, and the high water mark. An iterator is also provided to
-- iterate over all the entered allocation roots.
type Root_Id is new Natural;
No_Root_Id : constant Root_Id := 0;
function Read_BT (BT_Depth : Integer) return Root_Id;
-- Reads a backtrace whose maximum frame number is given by
-- BT_Depth and returns the corresponding Allocation root.
function Enter_Root (Fr : Frame_Array) return Root_Id;
-- Create an allocation root from the frames that compose it
function Frames_Of (B : Root_Id) return Frame_Array;
-- Retreives the Frames of the root's backtrace
procedure Print_BT (B : Root_Id; Short : Boolean := False);
-- Prints on standard out the backtrace associated with the root B
-- When Short is set to True, only the filename & line info is printed.
-- When it is set to false, the subprogram name is also printed.
function Get_First return Root_Id;
function Get_Next return Root_Id;
-- Iterator to iterate over roots
procedure Set_Nb_Alloc (B : Root_Id; V : Integer);
function Nb_Alloc (B : Root_Id) return Integer;
-- Access and modify the number of allocation counter associated with
-- this allocation root. If the value is negative, it means that this is
-- not an allocation root but a deallocation root (this can only happen
-- in erroneous situations where there are more frees than allocations).
procedure Set_Alloc_Size (B : Root_Id; V : Storage_Count);
function Alloc_Size (B : Root_Id) return Storage_Count;
-- Access and modify the total allocated memory counter associated with
-- this allocation root.
procedure Set_High_Water_Mark (B : Root_Id; V : Storage_Count);
function High_Water_Mark (B : Root_Id) return Storage_Count;
-- Access and modify the high water mark associated with this
-- allocation root. The high water mark is the maximum value, over
-- time, of the Alloc_Size.
end Memroot;
|
-------------------------------------------------------------------------------
-- 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 DW1000.Types;
-- This package defines low-level procedures for interfacing with the DW1000
-- at the physical layer.
--
-- The body for this package is not included in this project as it is very
-- specific to the target hardware. Therefore, the body for this package
-- must be implemented by the user for their target board.
package DW1000.BSP
with SPARK_Mode => On,
Abstract_State => (Device_State with Synchronous, External),
Initializes => Device_State
is
procedure Reset_DW1000
with Global => (Output => Device_State),
Depends => (Device_State => null);
-- Resets the DW1000 via the RSTn line.
procedure Get_Reset_State (State : out DW1000.Types.Bits_1)
with Global => (Input => Device_State),
Depends => (State => Device_State);
-- Read the current state of the RSTn line.
--
-- The State is 0 when the RSTn line is asserted (low), and 1 when the
-- RSTn line is de-asserted (high).
--
-- Reading the state of the RSTn is useful when waking up from the SLEEP
-- or DEEPSLEEP states, as the DW1000 asserts the RSTn line whilst it is in
-- the WAKEUP state. RSTn is de-asserted once it has entered the INIT
-- state.
procedure Acknowledge_DW1000_IRQ
with Global => (In_Out => Device_State);
-- Acknowledge the IRQ request from the DW1000.
--
-- This should be called from the interrupt handler of the DW1000 IRQ line
-- to acknowledge the interrupt.
--
--- Failure to call this procedure from the interrupt handler may result in
-- an infinite interrupt loop.
procedure Disable_DW1000_IRQ
with Global => (In_Out => Device_State);
-- Disables the DW1000 IRQ to prevent the DW1000 interrupt from being
-- triggered.
--
-- Any IRQs requested after calling this function should be held pending
-- until Enable_DW1000_IRQ is called.
procedure Enable_DW1000_IRQ
with Global => (In_Out => Device_State);
-- Enables the DW1000 IRQ.
procedure Use_Slow_SPI_Clock
with Global => (In_Out => Device_State);
-- Switch the BSP to use a slow SPI clock speed (no faster than 3 MHz).
--
-- The slow SPI clock speed should be used when the DW1000 is in the INIT
-- state.
procedure Use_Fast_SPI_Clock
with Global => (In_Out => Device_State);
-- Switch the BSP to use a faster SPI clock speed (no faster than 20 MHz).
--
-- The fast SPI clock speed can be used when the DW1000 has left the INIT
-- state.
procedure Wakeup (Wait_For_INIT : in Boolean)
with Global => (In_Out => Device_State);
-- Perform the Wakeup sequence.
--
-- This asserts the WAKEUP condition for a minimum of 500 microseconds.
--
-- If Wait_For_INIT is True, then this function will then also wait for up
-- to an additional 4 milliseconds for the DW1000 to enter the INIT state.
-- This guarantees that the SPI interface is ready after the return of this
-- procedure.
--
-- This is a non-blocking function (the Ada 'delay' statement is not used).
-- Instead, a busy wait is be used for the delays.
procedure Write_Transaction (Header : in DW1000.Types.Byte_Array;
Data : in DW1000.Types.Byte_Array)
with Global => (In_Out => Device_State),
Depends => (Device_State =>+ (Header, Data)),
Pre => (Header'Length in 1 .. 3
and Data'Length > 0);
-- Perform a "write" transaction to the DW1000.
--
-- This procedure executes a write transaction by performing the following
-- steps:z
-- 1. Select the DW1000 on the SPI bus.
-- 2. Send the transaction header bytes (1 .. 3 bytes) via the SPI
-- interface.
-- 3. Send the transaction data (variable length) to the DW1000 via the
-- SPI interface.
-- 4. Deselect the DW1000 on the SPI bus.
--
-- Note: This procedure must not block. I.e. the procedure must not use
-- the 'delay until' statement, nor call any protected entries.
procedure Read_Transaction (Header : in DW1000.Types.Byte_Array;
Data : out DW1000.Types.Byte_Array)
with Global => (In_Out => Device_State),
Depends => (Device_State =>+ (Header, Data),
Data => (Header, Device_State)),
Pre => (Header'Length in 1 .. 3
and Data'Length > 0);
-- Perform a "read" transaction from the DW1000.
--
-- This procedure executes a write transaction by performing the following
-- steps:
-- 1. Select the DW1000 on the SPI bus.
-- 2. Send the transaction header bytes (1 .. 3 bytes) via the SPI
-- interface.
-- 3. Read the transaction data (variable length) from the DW1000 via
-- the SPI interface, and write the received bytes to the 'Data' byte
-- array.
-- 4. Deselect the DW1000 on the SPI bus.
--
-- Note: This procedure must not block. I.e. the procedure must not use
-- the 'delay until' statement, nor call any protected entries.
end DW1000.BSP;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2016, 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 STM32_SVD.RTC; use STM32_SVD.RTC;
with STM32_SVD.RCC; use STM32_SVD.RCC;
with STM32.Power_Control;
with HAL.Real_Time_Clock; use HAL.Real_Time_Clock;
package body STM32.RTC is
-- procedure Disable_Write_Protection;
-- procedure Enable_Write_Protection;
------------------------------
-- Disable_Write_Protection --
------------------------------
procedure Disable_Write_Protection is
begin
Power_Control.Disable_Backup_Domain_Protection;
RTC_Periph.WPR.KEY := 16#CA#;
RTC_Periph.WPR.KEY := 16#53#;
end Disable_Write_Protection;
-----------------------------
-- Enable_Write_Protection --
-----------------------------
procedure Enable_Write_Protection is
begin
-- Write any wrong key to enable protection
RTC_Periph.WPR.KEY := 16#FF#;
Power_Control.Enable_Backup_Domain_Protection;
end Enable_Write_Protection;
---------
-- Set --
---------
overriding
procedure Set (This : in out RTC_Device;
Time : HAL.Real_Time_Clock.RTC_Time;
Date : HAL.Real_Time_Clock.RTC_Date)
is
pragma Unreferenced (This);
DR : DR_Register;
TR : TR_Register;
begin
Disable_Write_Protection;
if not RTC_Periph.ISR.INITF then
-- Enter initialization mode
RTC_Periph.ISR.INIT := True;
-- Wait for init mode
while not RTC_Periph.ISR.INITF loop
null;
end loop;
end if;
-- RTC prescaler for LSE source clock
RTC_Periph.PRER.PREDIV_S := 16#FF#;
RTC_Periph.PRER.PREDIV_A := 16#7F#;
-- 24H format
TR.PM := False;
TR.HT := UInt2 (Time.Hour / 10);
TR.HU := UInt4 (Time.Hour mod 10);
TR.MNT := UInt3 (Time.Min / 10);
TR.MNU := UInt4 (Time.Min mod 10);
TR.ST := UInt3 (Time.Sec / 10);
TR.SU := UInt4 (Time.Sec mod 10);
DR.YT := UInt4 (Date.Year / 10);
DR.YU := UInt4 (Date.Year mod 10);
DR.WDU := UInt3 (RTC_Day_Of_Week'Enum_Rep (Date.Day_Of_Week));
DR.MT := (RTC_Month'Enum_Rep (Date.Month) / 10) /= 0;
DR.MU := UInt4 (RTC_Month'Enum_Rep (Date.Month) mod 10);
DR.DT := UInt2 (Date.Day / 10);
DR.DU := UInt4 (Date.Day mod 10);
-- TR and DR are shadow registers, we have to write them all at once
RTC_Periph.TR := TR;
RTC_Periph.DR := DR;
-- Leave init mode
RTC_Periph.ISR.INIT := False;
Enable_Write_Protection;
while not RTC_Periph.ISR.RSF loop
null;
end loop;
end Set;
---------
-- Get --
---------
overriding
procedure Get (This : in out RTC_Device;
Time : out HAL.Real_Time_Clock.RTC_Time;
Date : out HAL.Real_Time_Clock.RTC_Date)
is
begin
loop
Time := This.Get_Time;
Date := This.Get_Date;
-- Check if the time changed when we were reading the date. If it
-- did, we have to read both values again to ensure coherence.
exit when This.Get_Time = Time;
end loop;
end Get;
--------------
-- Get_Time --
--------------
overriding
function Get_Time (This : RTC_Device) return HAL.Real_Time_Clock.RTC_Time
is
pragma Unreferenced (This);
Ret : RTC_Time;
TR : constant TR_Register := RTC_Periph.TR;
begin
Ret.Hour := RTC_Hour (TR.HT) * 10 + RTC_Hour (RTC_Periph.TR.HU);
Ret.Min := RTC_Minute (TR.MNT) * 10 + RTC_Minute (TR.MNU);
Ret.Sec := RTC_Second (TR.ST) * 10 + RTC_Second (TR.SU);
return Ret;
end Get_Time;
--------------
-- Get_Date --
--------------
overriding
function Get_Date (This : RTC_Device) return HAL.Real_Time_Clock.RTC_Date
is
pragma Unreferenced (This);
Ret : RTC_Date;
DR : constant DR_Register := RTC_Periph.DR;
begin
Ret.Day_Of_Week := RTC_Day_Of_Week'Enum_Val (DR.WDU);
Ret.Day := RTC_Day (Integer (DR.DT) * 10 + Integer (DR.DU));
Ret.Year := RTC_Year (DR.YT) * 10 + RTC_Year (DR.YU);
Ret.Month := RTC_Month'Enum_Val ((if DR.MT then 10 else 0) + DR.MU);
return Ret;
end Get_Date;
------------
-- Enable --
------------
procedure Enable (This : in out RTC_Device) is
pragma Unreferenced (This);
begin
Power_Control.Enable;
Power_Control.Disable_Backup_Domain_Protection;
-- Turn on internal low speed oscillator
RCC_Periph.CSR.LSI1ON := True;
while not RCC_Periph.CSR.LSI1RDY loop
null;
end loop;
-- Select LSI as source clock
RCC_Periph.BDCR.RTC_SEL := 2#10#;
if RCC_Periph.BDCR.RTC_SEL /= 2#10# then
raise Program_Error with "Cannot select RTC clock";
end if;
RCC_Periph.BDCR.RTCEN := True;
while not RTC_Periph.ISR.RSF loop
null;
end loop;
-- Power_Control.Enable_Backup_Domain_Protection;
end Enable;
-------------
-- Disable --
-------------
procedure Disable (This : in out RTC_Device) is
pragma Unreferenced (This);
begin
-- Power_Control.Disable_Backup_Domain_Protection;
RCC_Periph.BDCR.RTCEN := False;
-- Power_Control.Enable_Backup_Domain_Protection;
end Disable;
end STM32.RTC;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, 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 STM32_SVD.RCC; use STM32_SVD.RCC;
with STM32_SVD.CRC; use STM32_SVD.CRC;
with STM32.RCC; use STM32.RCC;
package body STM32.Device is
HPRE_Presc_Table : constant array (UInt4) of UInt32 :=
(1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 8, 16, 64, 128, 256, 512);
PPRE_Presc_Table : constant array (UInt3) of UInt32 :=
(1, 1, 1, 1, 2, 4, 8, 16);
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : aliased GPIO_Port) is
begin
if This'Address = GPIOA_Base then
RCC_Periph.AHB4ENR.GPIOAEN := True;
elsif This'Address = GPIOB_Base then
RCC_Periph.AHB4ENR.GPIOBEN := True;
elsif This'Address = GPIOC_Base then
RCC_Periph.AHB4ENR.GPIOCEN := True;
elsif This'Address = GPIOD_Base then
RCC_Periph.AHB4ENR.GPIODEN := True;
elsif This'Address = GPIOE_Base then
RCC_Periph.AHB4ENR.GPIOEEN := True;
elsif This'Address = GPIOF_Base then
RCC_Periph.AHB4ENR.GPIOFEN := True;
elsif This'Address = GPIOG_Base then
RCC_Periph.AHB4ENR.GPIOGEN := True;
elsif This'Address = GPIOH_Base then
RCC_Periph.AHB4ENR.GPIOHEN := True;
elsif This'Address = GPIOI_Base then
RCC_Periph.AHB4ENR.GPIOIEN := True;
elsif This'Address = GPIOJ_Base then
RCC_Periph.AHB4ENR.GPIOJEN := True;
elsif This'Address = GPIOK_Base then
RCC_Periph.AHB4ENR.GPIOKEN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (Point : GPIO_Point)
is
begin
Enable_Clock (Point.Periph.all);
end Enable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (Points : GPIO_Points)
is
begin
for Point of Points loop
Enable_Clock (Point.Periph.all);
end loop;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : aliased GPIO_Port) is
begin
if This'Address = GPIOA_Base then
RCC_Periph.AHB4RSTR.GPIOARST := True;
RCC_Periph.AHB4RSTR.GPIOARST := False;
elsif This'Address = GPIOB_Base then
RCC_Periph.AHB4RSTR.GPIOBRST := True;
RCC_Periph.AHB4RSTR.GPIOBRST := False;
elsif This'Address = GPIOC_Base then
RCC_Periph.AHB4RSTR.GPIOCRST := True;
RCC_Periph.AHB4RSTR.GPIOCRST := False;
elsif This'Address = GPIOD_Base then
RCC_Periph.AHB4RSTR.GPIODRST := True;
RCC_Periph.AHB4RSTR.GPIODRST := False;
elsif This'Address = GPIOE_Base then
RCC_Periph.AHB4RSTR.GPIOERST := True;
RCC_Periph.AHB4RSTR.GPIOERST := False;
elsif This'Address = GPIOF_Base then
RCC_Periph.AHB4RSTR.GPIOFRST := True;
RCC_Periph.AHB4RSTR.GPIOFRST := False;
elsif This'Address = GPIOG_Base then
RCC_Periph.AHB4RSTR.GPIOGRST := True;
RCC_Periph.AHB4RSTR.GPIOGRST := False;
elsif This'Address = GPIOH_Base then
RCC_Periph.AHB4RSTR.GPIOHRST := True;
RCC_Periph.AHB4RSTR.GPIOHRST := False;
elsif This'Address = GPIOI_Base then
RCC_Periph.AHB4RSTR.GPIOIRST := True;
RCC_Periph.AHB4RSTR.GPIOIRST := False;
elsif This'Address = GPIOJ_Base then
RCC_Periph.AHB4RSTR.GPIOJRST := True;
RCC_Periph.AHB4RSTR.GPIOJRST := False;
elsif This'Address = GPIOK_Base then
RCC_Periph.AHB4RSTR.GPIOKRST := True;
RCC_Periph.AHB4RSTR.GPIOKRST := False;
else
raise Unknown_Device;
end if;
end Reset;
-----------
-- Reset --
-----------
procedure Reset (Point : GPIO_Point) is
begin
Reset (Point.Periph.all);
end Reset;
-----------
-- Reset --
-----------
procedure Reset (Points : GPIO_Points)
is
Do_Reset : Boolean;
begin
for J in Points'Range loop
Do_Reset := True;
for K in Points'First .. J - 1 loop
if Points (K).Periph = Points (J).Periph then
Do_Reset := False;
exit;
end if;
end loop;
if Do_Reset then
Reset (Points (J).Periph.all);
end if;
end loop;
end Reset;
------------------------------
-- GPIO_Port_Representation --
------------------------------
function GPIO_Port_Representation (Port : GPIO_Port) return UInt4 is
begin
-- TODO: rather ugly to have this board-specific range here
if Port'Address = GPIOA_Base then
return 0;
elsif Port'Address = GPIOB_Base then
return 1;
elsif Port'Address = GPIOC_Base then
return 2;
elsif Port'Address = GPIOD_Base then
return 3;
elsif Port'Address = GPIOE_Base then
return 4;
elsif Port'Address = GPIOF_Base then
return 5;
elsif Port'Address = GPIOG_Base then
return 6;
elsif Port'Address = GPIOH_Base then
return 7;
elsif Port'Address = GPIOI_Base then
return 8;
elsif Port'Address = GPIOJ_Base then
return 9;
elsif Port'Address = GPIOK_Base then
return 10;
else
raise Program_Error;
end if;
end GPIO_Port_Representation;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : aliased Analog_To_Digital_Converter)
is
begin
if This'Address = ADC1_Base then
RCC_Periph.AHB1ENR.ADC12EN := True;
elsif This'Address = ADC2_Base then
RCC_Periph.AHB1ENR.ADC12EN := True;
elsif This'Address = ADC3_Base then
RCC_Periph.AHB4ENR.ADC3EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-------------------------
-- Reset_All_ADC_Units --
-------------------------
procedure Reset_All_ADC_Units is
begin
RCC_Periph.AHB1RSTR.ADC12RST := True;
RCC_Periph.AHB1RSTR.ADC12RST := False;
RCC_Periph.AHB4RSTR.ADC3RST := True;
RCC_Periph.AHB4RSTR.ADC3RST := False;
end Reset_All_ADC_Units;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source (This : Analog_To_Digital_Converter;
Source : ADC_Clock_Source)
is
begin
if This'Address = ADC1_Base or
This'Address = ADC2_Base or
This'Address = ADC3_Base
then
RCC_Periph.D3CCIPR.ADCSEL := Source'Enum_Rep;
else
raise Unknown_Device;
end if;
end Select_Clock_Source;
-----------------------
-- Read_Clock_Source --
-----------------------
function Read_Clock_Source (This : Analog_To_Digital_Converter)
return ADC_Clock_Source
is
begin
if This'Address = ADC1_Base or
This'Address = ADC2_Base or
This'Address = ADC3_Base
then
return ADC_Clock_Source'Val (RCC_Periph.D3CCIPR.ADCSEL);
else
raise Unknown_Device;
end if;
end Read_Clock_Source;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock
(This : aliased Digital_To_Analog_Converter)
is
begin
if This'Address = DAC_Base then
RCC_Periph.APB1LENR.DAC12EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : aliased Digital_To_Analog_Converter)
is
begin
if This'Address = DAC_Base then
RCC_Periph.APB1LRSTR.DAC12RST := True;
RCC_Periph.APB1LRSTR.DAC12RST := False;
else
raise Unknown_Device;
end if;
end Reset;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : SAI_Port)
is
begin
if This'Address = SAI1_Base then
RCC_Periph.APB2ENR.SAI1EN := True;
elsif This'Address = SAI2_Base then
RCC_Periph.APB2ENR.SAI2EN := True;
elsif This'Address = SAI3_Base then
RCC_Periph.APB2ENR.SAI3EN := True;
elsif This'Address = SAI4_Base then
RCC_Periph.APB4ENR.SAI4EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : SAI_Port)
is
begin
if This'Address = SAI1_Base then
RCC_Periph.APB2RSTR.SAI1RST := True;
RCC_Periph.APB2RSTR.SAI1RST := False;
elsif This'Address = SAI2_Base then
RCC_Periph.APB2RSTR.SAI2RST := True;
RCC_Periph.APB2RSTR.SAI2RST := False;
elsif This'Address = SAI3_Base then
RCC_Periph.APB2RSTR.SAI3RST := True;
RCC_Periph.APB2RSTR.SAI3RST := False;
elsif This'Address = SAI4_Base then
RCC_Periph.APB4RSTR.SAI4RST := True;
RCC_Periph.APB4RSTR.SAI4RST := False;
else
raise Unknown_Device;
end if;
end Reset;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source (This : SAI_Port;
Source : SAI_Clock_Source)
is
begin
if This'Address = SAI1_Base then
RCC_Periph.D2CCIP1R.SAI1SEL := Source'Enum_Rep;
elsif This'Address = SAI2_Base or
This'Address = SAI3_Base
then
RCC_Periph.D2CCIP1R.SAI23SEL := Source'Enum_Rep;
elsif This'Address = SAI4_Base then
RCC_Periph.D3CCIPR.SAI4ASEL := Source'Enum_Rep;
RCC_Periph.D3CCIPR.SAI4BSEL := Source'Enum_Rep;
else
raise Unknown_Device;
end if;
end Select_Clock_Source;
------------------------
-- Read_Clock_Source --
------------------------
function Read_Clock_Source (This : SAI_Port) return SAI_Clock_Source
is
begin
if This'Address = SAI1_Base then
return SAI_Clock_Source'Val (RCC_Periph.D2CCIP1R.SAI1SEL);
elsif This'Address = SAI2_Base or
This'Address = SAI3_Base
then
return SAI_Clock_Source'Val (RCC_Periph.D2CCIP1R.SAI23SEL);
elsif This'Address = SAI4_Base then
return SAI_Clock_Source'Val (RCC_Periph.D3CCIPR.SAI4ASEL);
else
raise Unknown_Device;
end if;
end Read_Clock_Source;
-------------------------
-- Get_Clock_Frequency --
-------------------------
function Get_Clock_Frequency (This : SAI_Port) return UInt32
is
Input_Selector : SAI_Clock_Source;
VCO_Input : UInt32;
begin
if This'Address = SAI1_Base then
Input_Selector := SAI_Clock_Source'Val (RCC_Periph.D2CCIP1R.SAI1SEL);
elsif This'Address = SAI2_Base or
This'Address = SAI3_Base
then
Input_Selector := SAI_Clock_Source'Val (RCC_Periph.D2CCIP1R.SAI23SEL);
elsif This'Address = SAI4_Base then
Input_Selector := SAI_Clock_Source'Val (RCC_Periph.D3CCIPR.SAI4ASEL);
else
raise Unknown_Device;
end if;
case Input_Selector is
when PLL1Q =>
VCO_Input := System_Clock_Frequencies.PCLK1; -- PLL1Q;
when PLL2P =>
VCO_Input := System_Clock_Frequencies.PCLK1; -- PLL2P;
when PLL3P =>
VCO_Input := System_Clock_Frequencies.PCLK1; -- PLL3P;
when I2S_CKIN =>
VCO_Input := I2SCLK;
when PER =>
VCO_Input := System_Clock_Frequencies.PERCLK;
end case;
return VCO_Input;
end Get_Clock_Frequency;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : CRC_32) is
pragma Unreferenced (This);
begin
RCC_Periph.AHB4ENR.CRCEN := True;
end Enable_Clock;
-------------------
-- Disable_Clock --
-------------------
procedure Disable_Clock (This : CRC_32) is
pragma Unreferenced (This);
begin
RCC_Periph.AHB4ENR.CRCEN := False;
end Disable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : CRC_32) is
pragma Unreferenced (This);
begin
RCC_Periph.AHB4RSTR.CRCRST := True;
RCC_Periph.AHB4RSTR.CRCRST := False;
end Reset;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : RNG_Generator) is
pragma Unreferenced (This);
begin
RCC_Periph.AHB2ENR.RNGEN := True;
end Enable_Clock;
-------------------
-- Disable_Clock --
-------------------
procedure Disable_Clock (This : RNG_Generator) is
pragma Unreferenced (This);
begin
RCC_Periph.AHB2ENR.RNGEN := False;
end Disable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : RNG_Generator) is
pragma Unreferenced (This);
begin
RCC_Periph.AHB2RSTR.RNGRST := True;
RCC_Periph.AHB2RSTR.RNGRST := False;
end Reset;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : aliased DMA_Controller) is
begin
if This'Address = STM32_SVD.DMA1_Base then
RCC_Periph.AHB1ENR.DMA1EN := True;
elsif This'Address = STM32_SVD.DMA2_Base then
RCC_Periph.AHB1ENR.DMA2EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : aliased DMA_Controller) is
begin
if This'Address = STM32_SVD.DMA1_Base then
RCC_Periph.AHB1RSTR.DMA1RST := True;
RCC_Periph.AHB1RSTR.DMA1RST := False;
elsif This'Address = STM32_SVD.DMA2_Base then
RCC_Periph.AHB1RSTR.DMA2RST := True;
RCC_Periph.AHB1RSTR.DMA2RST := False;
else
raise Unknown_Device;
end if;
end Reset;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : aliased USART) is
begin
if This.Periph.all'Address = USART1_Base then
RCC_Periph.APB2ENR.USART1EN := True;
elsif This.Periph.all'Address = USART2_Base then
RCC_Periph.APB1LENR.USART2EN := True;
elsif This.Periph.all'Address = USART3_Base then
RCC_Periph.APB1LENR.USART3EN := True;
elsif This.Periph.all'Address = UART4_Base then
RCC_Periph.APB1LENR.UART4EN := True;
elsif This.Periph.all'Address = UART5_Base then
RCC_Periph.APB1LENR.UART5EN := True;
elsif This.Periph.all'Address = USART6_Base then
RCC_Periph.APB2ENR.USART6EN := True;
elsif This.Periph.all'Address = UART7_Base then
RCC_Periph.APB1LENR.UART7EN := True;
elsif This.Periph.all'Address = UART8_Base then
RCC_Periph.APB1LENR.UART8EN := True;
elsif This.Periph.all'Address = LPUART1_Base then
RCC_Periph.APB4ENR.LPUART1EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : aliased USART) is
begin
if This.Periph.all'Address = USART1_Base then
RCC_Periph.APB2RSTR.USART1RST := True;
RCC_Periph.APB2RSTR.USART1RST := False;
elsif This.Periph.all'Address = USART2_Base then
RCC_Periph.APB1LRSTR.USART2RST := True;
RCC_Periph.APB1LRSTR.USART2RST := False;
elsif This.Periph.all'Address = USART3_Base then
RCC_Periph.APB1LRSTR.USART3RST := True;
RCC_Periph.APB1LRSTR.USART3RST := False;
elsif This.Periph.all'Address = UART4_Base then
RCC_Periph.APB1LRSTR.UART4RST := True;
RCC_Periph.APB1LRSTR.UART4RST := False;
elsif This.Periph.all'Address = UART5_Base then
RCC_Periph.APB1LRSTR.UART5RST := True;
RCC_Periph.APB1LRSTR.UART5RST := False;
elsif This.Periph.all'Address = USART6_Base then
RCC_Periph.APB2RSTR.USART6RST := True;
RCC_Periph.APB2RSTR.USART6RST := False;
elsif This.Periph.all'Address = UART7_Base then
RCC_Periph.APB1LRSTR.UART7RST := True;
RCC_Periph.APB1LRSTR.UART7RST := False;
elsif This.Periph.all'Address = UART8_Base then
RCC_Periph.APB1LRSTR.UART8RST := True;
RCC_Periph.APB1LRSTR.UART8RST := False;
elsif This.Periph.all'Address = LPUART1_Base then
RCC_Periph.APB4RSTR.LPUART1RST := True;
RCC_Periph.APB4RSTR.LPUART1RST := False;
else
raise Unknown_Device;
end if;
end Reset;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source (This : aliased USART;
Source : USART_Clock_Source)
is
begin
if This'Address = USART1_Base or
This'Address = USART6_Base
then
RCC_Periph.D2CCIP2R.USART16SEL := Source'Enum_Rep;
elsif This'Address = USART2_Base or
This'Address = USART3_Base or
This'Address = UART4_Base or
This'Address = UART5_Base or
This'Address = UART7_Base or
This'Address = UART8_Base
then
RCC_Periph.D2CCIP2R.USART234578SEL := Source'Enum_Rep;
elsif This'Address = LPUART1_Base then
RCC_Periph.D3CCIPR.LPUART1SEL := Source'Enum_Rep;
else
raise Unknown_Device;
end if;
end Select_Clock_Source;
-----------------------
-- Read_Clock_Source --
-----------------------
function Read_Clock_Source (This : aliased USART)
return USART_Clock_Source
is
begin
if This'Address = USART1_Base or
This'Address = USART6_Base
then
return USART_Clock_Source'Val (RCC_Periph.D2CCIP2R.USART16SEL);
elsif This'Address = USART2_Base or
This'Address = USART3_Base or
This'Address = UART4_Base or
This'Address = UART5_Base or
This'Address = UART7_Base or
This'Address = UART8_Base
then
return USART_Clock_Source'Val (RCC_Periph.D2CCIP2R.USART234578SEL);
elsif This'Address = LPUART1_Base then
return USART_Clock_Source'Val (RCC_Periph.D3CCIPR.LPUART1SEL);
else
raise Unknown_Device;
end if;
end Read_Clock_Source;
-------------------------
-- Get_Clock_Frequency --
-------------------------
function Get_Clock_Frequency (This : USART) return UInt32
is
Input_Selector : USART_Clock_Source;
Clock_Input : UInt32;
begin
if This'Address = USART1_Base or
This'Address = USART6_Base
then
Input_Selector := USART_Clock_Source'Val (RCC_Periph.D2CCIP2R.USART16SEL);
elsif This'Address = USART2_Base or
This'Address = USART3_Base or
This'Address = UART4_Base or
This'Address = UART5_Base or
This'Address = UART7_Base or
This'Address = UART8_Base
then
Input_Selector := USART_Clock_Source'Val (RCC_Periph.D2CCIP2R.USART234578SEL);
elsif This'Address = LPUART1_Base then
Input_Selector := USART_Clock_Source'Val (RCC_Periph.D3CCIPR.LPUART1SEL);
else
raise Unknown_Device;
end if;
case Input_Selector is
when Option_1 =>
if This'Address = USART1_Base or
This'Address = USART6_Base
then
Clock_Input := System_Clock_Frequencies.PCLK2;
elsif This'Address = USART2_Base or
This'Address = USART3_Base or
This'Address = UART4_Base or
This'Address = UART5_Base or
This'Address = UART7_Base or
This'Address = UART8_Base
then
Clock_Input := System_Clock_Frequencies.PCLK1;
else -- LPUART1
Clock_Input := System_Clock_Frequencies.PCLK3;
end if;
when PLL2Q =>
Clock_Input := System_Clock_Frequencies.PCLK1;
when PLL3Q =>
Clock_Input := System_Clock_Frequencies.PCLK1;
when HSI =>
Clock_Input := HSI_VALUE;
when CSI =>
Clock_Input := CSI_VALUE;
when LSE =>
Clock_Input := LSE_VALUE;
end case;
return Clock_Input;
end Get_Clock_Frequency;
----------------
-- As_Port_Id --
----------------
function As_Port_Id (Port : I2C_Port'Class) return I2C_Port_Id is
begin
if Port.Periph.all'Address = I2C1_Base then
return I2C_Id_1;
elsif Port.Periph.all'Address = I2C2_Base then
return I2C_Id_2;
elsif Port.Periph.all'Address = I2C3_Base then
return I2C_Id_3;
elsif Port.Periph.all'Address = I2C4_Base then
return I2C_Id_4;
else
raise Unknown_Device;
end if;
end As_Port_Id;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : aliased I2C_Port'Class) is
begin
Enable_Clock (As_Port_Id (This));
end Enable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : I2C_Port_Id) is
begin
case This is
when I2C_Id_1 =>
RCC_Periph.APB1LENR.I2C1EN := True;
when I2C_Id_2 =>
RCC_Periph.APB1LENR.I2C2EN := True;
when I2C_Id_3 =>
RCC_Periph.APB1LENR.I2C3EN := True;
when I2C_Id_4 =>
RCC_Periph.APB4ENR.I2C4EN := True;
end case;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : I2C_Port'Class) is
begin
Reset (As_Port_Id (This));
end Reset;
-----------
-- Reset --
-----------
procedure Reset (This : I2C_Port_Id) is
begin
case This is
when I2C_Id_1 =>
RCC_Periph.APB1LRSTR.I2C1RST := True;
RCC_Periph.APB1LRSTR.I2C1RST := False;
when I2C_Id_2 =>
RCC_Periph.APB1LRSTR.I2C2RST := True;
RCC_Periph.APB1LRSTR.I2C2RST := False;
when I2C_Id_3 =>
RCC_Periph.APB1LRSTR.I2C3RST := True;
RCC_Periph.APB1LRSTR.I2C3RST := False;
when I2C_Id_4 =>
RCC_Periph.APB4RSTR.I2C4RST := True;
RCC_Periph.APB4RSTR.I2C4RST := False;
end case;
end Reset;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source (This : I2C_Port'Class;
Source : I2C_Clock_Source)
is
begin
Select_Clock_Source (As_Port_Id (This), Source);
end Select_Clock_Source;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source (This : I2C_Port_Id;
Source : I2C_Clock_Source)
is
begin
case This is
when I2C_Id_1 | I2C_Id_2 | I2C_Id_3 =>
RCC_Periph.D2CCIP2R.I2C123SEL := Source'Enum_Rep;
when I2C_Id_4 =>
RCC_Periph.D3CCIPR.I2C4SEL := Source'Enum_Rep;
end case;
end Select_Clock_Source;
-----------------------
-- Read_Clock_Source --
-----------------------
function Read_Clock_Source (This : I2C_Port'Class) return I2C_Clock_Source
is
begin
return Read_Clock_Source (As_Port_Id (This));
end Read_Clock_Source;
------------------------
-- Read_Clock_Source --
------------------------
function Read_Clock_Source (This : I2C_Port_Id) return I2C_Clock_Source
is
begin
case This is
when I2C_Id_1 | I2C_Id_2 | I2C_Id_3 =>
return I2C_Clock_Source'Val (RCC_Periph.D2CCIP2R.I2C123SEL);
when I2C_Id_4 =>
return I2C_Clock_Source'Val (RCC_Periph.D3CCIPR.I2C4SEL);
end case;
end Read_Clock_Source;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : SPI_Port'Class) is
begin
if This.Periph.all'Address = SPI1_Base then
RCC_Periph.APB2ENR.SPI1EN := True;
elsif This.Periph.all'Address = SPI2_Base then
RCC_Periph.APB1LENR.SPI2EN := True;
elsif This.Periph.all'Address = SPI3_Base then
RCC_Periph.APB1LENR.SPI3EN := True;
elsif This.Periph.all'Address = SPI4_Base then
RCC_Periph.APB2ENR.SPI4EN := True;
elsif This.Periph.all'Address = SPI5_Base then
RCC_Periph.APB2ENR.SPI5EN := True;
elsif This.Periph.all'Address = SPI6_Base then
RCC_Periph.APB4ENR.SPI6EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : SPI_Port'Class) is
begin
if This.Periph.all'Address = SPI1_Base then
RCC_Periph.APB2RSTR.SPI1RST := True;
RCC_Periph.APB2RSTR.SPI1RST := False;
elsif This.Periph.all'Address = SPI2_Base then
RCC_Periph.APB1LRSTR.SPI2RST := True;
RCC_Periph.APB1LRSTR.SPI2RST := False;
elsif This.Periph.all'Address = SPI3_Base then
RCC_Periph.APB1LRSTR.SPI3RST := True;
RCC_Periph.APB1LRSTR.SPI3RST := False;
elsif This.Periph.all'Address = SPI4_Base then
RCC_Periph.APB2RSTR.SPI4RST := True;
RCC_Periph.APB2RSTR.SPI4RST := False;
elsif This.Periph.all'Address = SPI5_Base then
RCC_Periph.APB2RSTR.SPI5RST := True;
RCC_Periph.APB2RSTR.SPI5RST := False;
elsif This.Periph.all'Address = SPI6_Base then
RCC_Periph.APB4RSTR.SPI6RST := True;
RCC_Periph.APB4RSTR.SPI6RST := False;
else
raise Unknown_Device;
end if;
end Reset;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source (This : SPI_Port'Class;
Source : SPI_Clock_Source)
is
begin
if This.Periph.all'Address = SPI1_Base or
This.Periph.all'Address = SPI2_Base or
This.Periph.all'Address = SPI3_Base
then
RCC_Periph.D2CCIP1R.SPI123SEL := Source'Enum_Rep;
elsif This.Periph.all'Address = SPI4_Base or
This.Periph.all'Address = SPI5_Base
then
RCC_Periph.D2CCIP1R.SPI45SEL := Source'Enum_Rep;
elsif This.Periph.all'Address = SPI6_Base
then
RCC_Periph.D3CCIPR.SPI6SEL := Source'Enum_Rep;
else
raise Unknown_Device;
end if;
end Select_Clock_Source;
------------------------
-- Read_Clock_Source --
------------------------
function Read_Clock_Source (This : SPI_Port'Class) return SPI_Clock_Source
is
begin
if This.Periph.all'Address = SPI1_Base or
This.Periph.all'Address = SPI2_Base or
This.Periph.all'Address = SPI3_Base
then
return SPI_Clock_Source'Val (RCC_Periph.D2CCIP1R.SPI123SEL);
elsif This.Periph.all'Address = SPI4_Base or
This.Periph.all'Address = SPI5_Base
then
return SPI_Clock_Source'Val (RCC_Periph.D2CCIP1R.SPI45SEL);
elsif This.Periph.all'Address = SPI6_Base
then
return SPI_Clock_Source'Val (RCC_Periph.D3CCIPR.SPI6SEL);
else
raise Unknown_Device;
end if;
end Read_Clock_Source;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : I2S_Port) is
begin
if This.Periph.all'Address = SPI1_Base then
RCC_Periph.APB2ENR.SPI1EN := True;
elsif This.Periph.all'Address = SPI2_Base then
RCC_Periph.APB1LENR.SPI2EN := True;
elsif This.Periph.all'Address = SPI3_Base then
RCC_Periph.APB1LENR.SPI3EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : I2S_Port) is
begin
if This.Periph.all'Address = SPI1_Base then
RCC_Periph.APB2RSTR.SPI1RST := True;
RCC_Periph.APB2RSTR.SPI1RST := False;
elsif This.Periph.all'Address = SPI2_Base then
RCC_Periph.APB1LRSTR.SPI2RST := True;
RCC_Periph.APB1LRSTR.SPI2RST := False;
elsif This.Periph.all'Address = SPI3_Base then
RCC_Periph.APB1LRSTR.SPI3RST := True;
RCC_Periph.APB1LRSTR.SPI3RST := False;
else
raise Unknown_Device;
end if;
end Reset;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source (This : I2S_Port'Class;
Source : I2S_Clock_Source)
is
begin
if This.Periph.all'Address = SPI1_Base or
This.Periph.all'Address = SPI2_Base or
This.Periph.all'Address = SPI3_Base
then
RCC_Periph.D2CCIP1R.SPI123SEL := Source'Enum_Rep;
else
raise Unknown_Device;
end if;
end Select_Clock_Source;
-----------------------
-- Read_Clock_Source --
-----------------------
function Read_Clock_Source (This : I2S_Port'Class) return I2S_Clock_Source
is
begin
if This.Periph.all'Address = SPI1_Base or
This.Periph.all'Address = SPI2_Base or
This.Periph.all'Address = SPI3_Base
then
return I2S_Clock_Source'Val (RCC_Periph.D2CCIP1R.SPI123SEL);
else
raise Unknown_Device;
end if;
end Read_Clock_Source;
-------------------------
-- Get_Clock_Frequency --
-------------------------
function Get_Clock_Frequency (This : I2S_Port) return UInt32 is
Source : constant I2S_Clock_Source :=
I2S_Clock_Source'Val (RCC_Periph.D2CCIP1R.SPI123SEL);
begin
if This.Periph.all'Address = SPI1_Base or
This.Periph.all'Address = SPI2_Base or
This.Periph.all'Address = SPI3_Base
then
case Source is
when PLL1Q =>
return System_Clock_Frequencies.PCLK1;
when PLL2P =>
return System_Clock_Frequencies.PCLK1;
when PLL3P =>
return System_Clock_Frequencies.PCLK1;
when I2S_CKIN =>
return I2SCLK;
when PER =>
return System_Clock_Frequencies.PERCLK;
end case;
else
raise Unknown_Device;
end if;
end Get_Clock_Frequency;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : RTC_Device) is
pragma Unreferenced (This);
begin
RCC_Periph.BDCR.RTCEN := True;
end Enable_Clock;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source
(This : RTC_Device;
Source : RTC_Clock_Source;
HSE_Pre : RTC_HSE_Prescaler_Range := RTC_HSE_Prescaler_Range'First)
is
pragma Unreferenced (This);
begin
RCC_Periph.BDCR.RTCSEL := Source'Enum_Rep;
if Source = HSE then
RCC_Periph.CFGR.RTCPRE := UInt6 (HSE_Pre);
end if;
end Select_Clock_Source;
------------------------
-- Read_Clock_Source --
------------------------
function Read_Clock_Source (This : RTC_Device) return RTC_Clock_Source
is
pragma Unreferenced (This);
begin
return RTC_Clock_Source'Val (RCC_Periph.BDCR.RTCSEL);
end Read_Clock_Source;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : Timer) is
begin
if This'Address = TIM1_Base then
RCC_Periph.APB2ENR.TIM1EN := True;
elsif This'Address = TIM2_Base then
RCC_Periph.APB1LENR.TIM2EN := True;
elsif This'Address = TIM3_Base then
RCC_Periph.APB1LENR.TIM3EN := True;
elsif This'Address = TIM4_Base then
RCC_Periph.APB1LENR.TIM4EN := True;
elsif This'Address = TIM5_Base then
RCC_Periph.APB1LENR.TIM5EN := True;
elsif This'Address = TIM6_Base then
RCC_Periph.APB1LENR.TIM6EN := True;
elsif This'Address = TIM7_Base then
RCC_Periph.APB1LENR.TIM7EN := True;
elsif This'Address = TIM8_Base then
RCC_Periph.APB2ENR.TIM8EN := True;
elsif This'Address = TIM12_Base then
RCC_Periph.APB1LENR.TIM12EN := True;
elsif This'Address = TIM13_Base then
RCC_Periph.APB1LENR.TIM13EN := True;
elsif This'Address = TIM14_Base then
RCC_Periph.APB1LENR.TIM14EN := True;
elsif This'Address = TIM15_Base then
RCC_Periph.APB2ENR.TIM15EN := True;
elsif This'Address = TIM16_Base then
RCC_Periph.APB2ENR.TIM16EN := True;
elsif This'Address = TIM17_Base then
RCC_Periph.APB2ENR.TIM17EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : Timer) is
begin
if This'Address = TIM1_Base then
RCC_Periph.APB2RSTR.TIM1RST := True;
RCC_Periph.APB2RSTR.TIM1RST := False;
elsif This'Address = TIM2_Base then
RCC_Periph.APB1LRSTR.TIM2RST := True;
RCC_Periph.APB1LRSTR.TIM2RST := False;
elsif This'Address = TIM3_Base then
RCC_Periph.APB1LRSTR.TIM3RST := True;
RCC_Periph.APB1LRSTR.TIM3RST := False;
elsif This'Address = TIM4_Base then
RCC_Periph.APB1LRSTR.TIM4RST := True;
RCC_Periph.APB1LRSTR.TIM4RST := False;
elsif This'Address = TIM5_Base then
RCC_Periph.APB1LRSTR.TIM5RST := True;
RCC_Periph.APB1LRSTR.TIM5RST := False;
elsif This'Address = TIM6_Base then
RCC_Periph.APB1LRSTR.TIM6RST := True;
RCC_Periph.APB1LRSTR.TIM6RST := False;
elsif This'Address = TIM7_Base then
RCC_Periph.APB1LRSTR.TIM7RST := True;
RCC_Periph.APB1LRSTR.TIM7RST := False;
elsif This'Address = TIM8_Base then
RCC_Periph.APB2RSTR.TIM8RST := True;
RCC_Periph.APB2RSTR.TIM8RST := False;
elsif This'Address = TIM12_Base then
RCC_Periph.APB1LRSTR.TIM12RST := True;
RCC_Periph.APB1LRSTR.TIM12RST := False;
elsif This'Address = TIM13_Base then
RCC_Periph.APB1LRSTR.TIM13RST := True;
RCC_Periph.APB1LRSTR.TIM13RST := False;
elsif This'Address = TIM14_Base then
RCC_Periph.APB1LRSTR.TIM14RST := True;
RCC_Periph.APB1LRSTR.TIM14RST := False;
elsif This'Address = TIM15_Base then
RCC_Periph.APB2RSTR.TIM15RST := True;
RCC_Periph.APB2RSTR.TIM15RST := False;
elsif This'Address = TIM16_Base then
RCC_Periph.APB2RSTR.TIM16RST := True;
RCC_Periph.APB2RSTR.TIM16RST := False;
elsif This'Address = TIM17_Base then
RCC_Periph.APB2RSTR.TIM17RST := True;
RCC_Periph.APB2RSTR.TIM17RST := False;
else
raise Unknown_Device;
end if;
end Reset;
-------------------------
-- Get_Clock_Frequency --
-------------------------
function Get_Clock_Frequency (This : Timer) return UInt32 is
begin
-- TIMs 2 .. 7, 12 .. 14
if This'Address = TIM2_Base or
This'Address = TIM3_Base or
This'Address = TIM4_Base or
This'Address = TIM5_Base or
This'Address = TIM6_Base or
This'Address = TIM7_Base or
This'Address = TIM12_Base or
This'Address = TIM13_Base or
This'Address = TIM14_Base
then
return System_Clock_Frequencies.TIMCLK1;
-- TIMs 1, 8, 15 .. 17
elsif This'Address = TIM1_Base or
This'Address = TIM8_Base or
This'Address = TIM15_Base or
This'Address = TIM16_Base or
This'Address = TIM17_Base
then
return System_Clock_Frequencies.TIMCLK2;
else
raise Unknown_Device;
end if;
end Get_Clock_Frequency;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : LPTimer) is
begin
if This'Address = LPTIM1_Base then
RCC_Periph.APB1LENR.LPTIM1EN := True;
elsif This'Address = LPTIM2_Base then
RCC_Periph.APB4ENR.LPTIM2EN := True;
elsif This'Address = LPTIM3_Base then
RCC_Periph.APB4ENR.LPTIM3EN := True;
elsif This'Address = LPTIM4_Base then
RCC_Periph.APB4ENR.LPTIM4EN := True;
elsif This'Address = LPTIM5_Base then
RCC_Periph.APB4ENR.LPTIM5EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : LPTimer) is
begin
if This'Address = LPTIM1_Base then
RCC_Periph.APB1LRSTR.LPTIM1RST := True;
RCC_Periph.APB1LRSTR.LPTIM1RST := False;
elsif This'Address = LPTIM2_Base then
RCC_Periph.APB4RSTR.LPTIM2RST := True;
RCC_Periph.APB4RSTR.LPTIM2RST := False;
elsif This'Address = LPTIM3_Base then
RCC_Periph.APB4RSTR.LPTIM3RST := True;
RCC_Periph.APB4RSTR.LPTIM3RST := False;
elsif This'Address = LPTIM4_Base then
RCC_Periph.APB4RSTR.LPTIM4RST := True;
RCC_Periph.APB4RSTR.LPTIM4RST := False;
elsif This'Address = LPTIM5_Base then
RCC_Periph.APB4RSTR.LPTIM5RST := True;
RCC_Periph.APB4RSTR.LPTIM5RST := False;
else
raise Unknown_Device;
end if;
end Reset;
-------------------------
-- Select_Clock_Source --
-------------------------
procedure Select_Clock_Source (This : LPTimer;
Source : LPTimer_Clock_Source)
is
begin
if This'Address = LPTIM1_Base then
RCC_Periph.D2CCIP2R.LPTIM1SEL := Source'Enum_Rep;
elsif This'Address = LPTIM2_Base then
RCC_Periph.D3CCIPR.LPTIM2SEL := Source'Enum_Rep;
elsif This'Address = LPTIM3_Base or
This'Address = LPTIM4_Base or
This'Address = LPTIM5_Base
then
RCC_Periph.D3CCIPR.LPTIM345SEL := Source'Enum_Rep;
else
raise Unknown_Device;
end if;
end Select_Clock_Source;
-----------------------
-- Read_Clock_Source --
-----------------------
function Read_Clock_Source (This : LPTimer) return LPTimer_Clock_Source is
begin
if This'Address = LPTIM1_Base then
return LPTimer_Clock_Source'Val (RCC_Periph.D2CCIP2R.LPTIM1SEL);
elsif This'Address = LPTIM2_Base then
return LPTimer_Clock_Source'Val (RCC_Periph.D3CCIPR.LPTIM2SEL);
elsif This'Address = LPTIM3_Base or
This'Address = LPTIM4_Base or
This'Address = LPTIM5_Base
then
return LPTimer_Clock_Source'Val (RCC_Periph.D3CCIPR.LPTIM345SEL);
else
raise Unknown_Device;
end if;
end Read_Clock_Source;
-------------------------
-- Get_Clock_Frequency --
-------------------------
function Get_Clock_Frequency (This : LPTimer) return UInt32 is
begin
if This'Address = LPTIM1_Base then
return System_Clock_Frequencies.PCLK1;
elsif This'Address = LPTIM2_Base or
This'Address = LPTIM3_Base or
This'Address = LPTIM4_Base or
This'Address = LPTIM5_Base
then
return System_Clock_Frequencies.PCLK4;
else
raise Unknown_Device;
end if;
end Get_Clock_Frequency;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : HRTimer_Master) is
begin
if This'Address = HRTIM_Master_Base then
RCC_Periph.APB2ENR.HRTIMEN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : HRTimer_Channel) is
begin
if This'Address = HRTIM_TIMA_Base or
This'Address = HRTIM_TIMB_Base or
This'Address = HRTIM_TIMC_Base or
This'Address = HRTIM_TIMD_Base or
This'Address = HRTIM_TIME_Base
then
RCC_Periph.APB2ENR.HRTIMEN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : HRTimer_Master) is
begin
if This'Address = HRTIM_Master_Base then
RCC_Periph.APB2RSTR.HRTIMRST := True;
RCC_Periph.APB2RSTR.HRTIMRST := False;
else
raise Unknown_Device;
end if;
end Reset;
-----------
-- Reset --
-----------
procedure Reset (This : HRTimer_Channel) is
begin
if This'Address = HRTIM_TIMA_Base or
This'Address = HRTIM_TIMB_Base or
This'Address = HRTIM_TIMC_Base or
This'Address = HRTIM_TIMD_Base or
This'Address = HRTIM_TIME_Base
then
RCC_Periph.APB2RSTR.HRTIMRST := True;
RCC_Periph.APB2RSTR.HRTIMRST := False;
else
raise Unknown_Device;
end if;
end Reset;
----------------------------
-- Select_Clock_Frequency --
----------------------------
procedure Select_Clock_Source (This : HRTimer_Master;
Source : HRTimer_Clock_Source)
is
pragma Unreferenced (This);
begin
RCC_Periph.CFGR.HRTIMSEL := Source = CPUCLK;
end Select_Clock_Source;
-------------------------
-- Get_Clock_Frequency --
-------------------------
function Read_Clock_Source
(This : HRTimer_Master) return HRTimer_Clock_Source
is
pragma Unreferenced (This);
begin
if RCC_Periph.CFGR.HRTIMSEL then
return CPUCLK;
else
return TIMCLK;
end if;
end Read_Clock_Source;
-------------------------
-- Get_Clock_Frequency --
-------------------------
function Get_Clock_Frequency (This : HRTimer_Master) return UInt32 is
pragma Unreferenced (This);
begin
return System_Clock_Frequencies.TIMCLK3;
end Get_Clock_Frequency;
-------------------------
-- Get_Clock_Frequency --
-------------------------
function Get_Clock_Frequency (This : HRTimer_Channel) return UInt32 is
pragma Unreferenced (This);
begin
return System_Clock_Frequencies.TIMCLK3;
end Get_Clock_Frequency;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock
(This : aliased Comparator)
is
begin
if This'Address = Comp_1'Address or
This'Address = Comp_2'Address
then
RCC_Periph.APB4ENR.COMP12EN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : aliased Comparator)
is
begin
if This'Address = Comp_1'Address or
This'Address = Comp_2'Address
then
RCC_Periph.APB4RSTR.COMP12RST := True;
RCC_Periph.APB4RSTR.COMP12RST := False;
else
raise Unknown_Device;
end if;
end Reset;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock
(This : aliased Operational_Amplifier)
is
begin
if This'Address = Opamp_1'Address or
This'Address = Opamp_2'Address
then
RCC_Periph.APB1HENR.OPAMPEN := True;
else
raise Unknown_Device;
end if;
end Enable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : aliased Operational_Amplifier)
is
begin
if This'Address = Opamp_1'Address or
This'Address = Opamp_2'Address
then
RCC_Periph.APB1HRSTR.OPAMPRST := True;
RCC_Periph.APB1HRSTR.OPAMPRST := False;
else
raise Unknown_Device;
end if;
end Reset;
------------------------------
-- System_Clock_Frequencies --
------------------------------
function System_Clock_Frequencies return RCC_System_Clocks
is
Source : constant SYSCLK_Clock_Source :=
SYSCLK_Clock_Source'Val (RCC_Periph.CFGR.SWS);
-- Get System_Clock_Mux selection
Result : RCC_System_Clocks;
begin
-- System clock Mux
case Source is
-- HSE as source
when SYSCLK_SRC_HSE =>
Result.SYSCLK := HSE_VALUE;
-- HSI as source
when SYSCLK_SRC_HSI =>
Result.SYSCLK := HSI_VALUE / (2 ** Natural (RCC_Periph.CR.HSIDIV));
-- CSI as source
when SYSCLK_SRC_CSI =>
Result.SYSCLK := CSI_VALUE;
-- PLL1 as source
when SYSCLK_SRC_PLL1 =>
declare
Pllm : constant UInt32 := UInt32 (RCC_Periph.PLLCKSELR.DIVM1);
-- Get the correct value of Pll M divisor
Plln : constant UInt32 :=
UInt32 (RCC_Periph.PLL1DIVR.DIVN1 + 1);
-- Get the correct value of Pll N multiplier
Pllp : constant UInt32 :=
UInt32 (RCC_Periph.PLL1DIVR.DIVR1 + 1);
-- Get the correct value of Pll R divisor
PLLSRC : constant PLL_Clock_Source :=
PLL_Clock_Source'Val (RCC_Periph.PLLCKSELR.PLLSRC);
-- Get PLL Source Mux
PLLCLK : UInt32;
begin
case PLLSRC is
when PLL_SRC_HSE => -- HSE as source
PLLCLK := ((HSE_VALUE / Pllm) * Plln) / Pllp;
when PLL_SRC_HSI => -- HSI as source
PLLCLK := ((HSI_VALUE / Pllm) * Plln) / Pllp;
when PLL_SRC_CSI => -- CSI as source
PLLCLK := ((CSI_VALUE / Pllm) * Plln) / Pllp;
end case;
Result.SYSCLK := PLLCLK;
end;
end case;
declare
HPRE1 : constant UInt4 := RCC_Periph.D1CFGR.D1CPRE;
HPRE2 : constant UInt4 := RCC_Periph.D1CFGR.HPRE;
PPRE1 : constant UInt3 := RCC_Periph.D2CFGR.D2PPRE1;
PPRE2 : constant UInt3 := RCC_Periph.D2CFGR.D2PPRE2;
PPRE3 : constant UInt3 := RCC_Periph.D1CFGR.D1PPRE;
PPRE4 : constant UInt3 := RCC_Periph.D3CFGR.D3PPRE;
begin
Result.HCLK1 := Result.SYSCLK / HPRE_Presc_Table (HPRE1);
Result.HCLK2 := Result.HCLK1 / HPRE_Presc_Table (HPRE2);
Result.PCLK1 := Result.HCLK2 / PPRE_Presc_Table (PPRE1);
Result.PCLK2 := Result.HCLK2 / PPRE_Presc_Table (PPRE2);
Result.PCLK3 := Result.HCLK2 / PPRE_Presc_Table (PPRE3);
Result.PCLK4 := Result.HCLK2 / PPRE_Presc_Table (PPRE4);
-- Timer clocks
-- If APB1 (D2PPRE1) and APB2 (D2PPRE2) prescaler (D2PPRE1, D2PPRE2
-- in the RCC_D2CFGR register) are configured to a division factor of
-- 1 or 2 with RCC_CFGR.TIMPRE = 0 (or also 4 with RCC_CFGR.TIMPRE
-- = 1), then TIMxCLK = PCLKx.
-- Otherwise, the timer clock frequencies are set to twice to the
-- frequency of the APB domain to which the timers are connected with
-- RCC_CFGR.TIMPRE = 0, so TIMxCLK = 2 x PCLKx (or TIMxCLK =
-- 4 x PCLKx with RCC_CFGR.TIMPRE = 1).
if not RCC_Periph.CFGR.TIMPRE then
-- TIMs 2 .. 7, 12 .. 14
if PPRE1 <= 2 then
Result.TIMCLK1 := Result.PCLK1;
else
Result.TIMCLK1 := Result.PCLK1 * 2;
end if;
-- TIMs TIMs 1, 8, 15 .. 17
if PPRE2 <= 2 then
Result.TIMCLK2 := Result.PCLK2;
else
Result.TIMCLK2 := Result.PCLK2 * 2;
end if;
else
-- TIMs 2 .. 7, 12 .. 14
if PPRE1 <= 4 then
Result.TIMCLK1 := Result.PCLK1;
else
Result.TIMCLK1 := Result.PCLK1 * 4;
end if;
-- TIMs 1, 8, 15 .. 17
if PPRE2 <= 4 then
Result.TIMCLK2 := Result.PCLK2;
else
Result.TIMCLK2 := Result.PCLK2 * 4;
end if;
end if;
-- HRTIM clock
-- If RCC_CFGR.HRTIMSEL = 0, HRTIM prescaler clock cource is the same
-- as timer 2 (TIMCLK1), otherwise it is the CPU clock (HCLK2).
if not RCC_Periph.CFGR.HRTIMSEL then
Result.TIMCLK3 := Result.TIMCLK1;
else
Result.TIMCLK3 := Result.HCLK1;
end if;
end;
declare
Source : constant PER_Clock_Source :=
PER_Clock_Source'Val (RCC_Periph.D1CCIPR.CKPERSEL);
-- Get PER_Clock_Mux selection
begin
case Source is
-- HSE as source
when PER_SRC_HSE =>
Result.PERCLK := HSE_VALUE;
-- HSI as source
when PER_SRC_HSI =>
Result.SYSCLK := HSI_VALUE / (2 ** Natural (RCC_Periph.CR.HSIDIV));
-- CSI as source
when PER_SRC_CSI =>
Result.PERCLK := CSI_VALUE;
end case;
end;
return Result;
end System_Clock_Frequencies;
end STM32.Device;
|
-- { dg-do compile }
-- { dg-options "-gnatc" }
package interface5 is
type Lim_Iface is limited interface;
protected type Prot_Typ is new Lim_Iface with
private
end Prot_Typ;
end interface5;
|
with HAL.Framebuffer; use HAL.Framebuffer;
with Framebuffer_LTDC;
package Framebuffer_RK043FN48H is
LCD_Natural_Width : constant := 480;
LCD_Natural_Height : constant := 272;
type Frame_Buffer is limited new Framebuffer_LTDC.Frame_Buffer with private;
procedure Initialize
(Display : in out Frame_Buffer;
Orientation : HAL.Framebuffer.Display_Orientation := Default;
Mode : HAL.Framebuffer.Wait_Mode := Interrupt);
private
type Frame_Buffer is limited new Framebuffer_LTDC.Frame_Buffer with
null record;
end Framebuffer_RK043FN48H;
|
generic
type Real is digits <>;
package pc_2_coeff_21 is
subtype PC_Rule_Range is Integer range 0..31;
type Integration_Rule is array(PC_Rule_Range) of Real;
Starting_Id_of_First_Deriv_of_Y : constant PC_Rule_Range := 15;
-- Center_Integration Rule, applied to (d/dt)**2 Y, takes a dY/dt here, and
-- Integrates it one indice forward.
Extrap_Factor: constant Real := 1.0 / 19.5;
-- rt val unkwnown
Corrector_33_21 : constant Integration_Rule :=
(
8.39227515406179728514500983914039183E-4,
-1.18028223076234773078669092609184921E-2,
7.31564974607134244421853699856249961E-2,
-2.57460363765467950987160763812391690E-1,
5.43275858758308120861868756463269386E-1,
-6.28082394112848805743898363922127637E-1,
1.66362752606816509651760205787125034E-1,
4.90789439944049643097797604387767836E-1,
-4.01474416729281104610993364936476902E-1,
-3.76440646196353555356088956447950953E-1,
4.54514373042954980953396089403587993E-1,
3.77569171617851821769092525945631949E-1,
-4.31952248877685637481930362708264052E-1,
-4.63135274769924172677969275414707821E-1,
3.31919054645749071786043793582199428E-1,
6.29580884580403793573276132429579944E-1,
1.88212765588327200749334042985019967E-1,
2.57192363659735247856824274560227544E-1,
1.25798779993360609523019437184588664E+0,
1.78233957118809891409677869695080893E+0,
9.22536144264591014993579834428525395E-1,
1.46696347311869237104492375376795376E-1,
9.82822613706953466912610741077996350E-1,
1.95333883842770662018944996413661247E+0,
9.44776892043559390934659203275629274E-1,
-9.87043597843318876597385773605422630E-2,
1.52317436073783040830001043611888380E+0,
2.00586885292856860330606095502627248E+0,
-7.24201752028513415862025198005362007E-1,
2.33634064545695009780091798061523621E+0,
3.60575583986868405294075221496582988E-1,
1.10885972247246195388448154899049301E+0
);
Final_Step_Corrector_33_21 : constant Real
:= 5.45245166926498051702671460150707331E-2;
Predictor_31_21 : constant Integration_Rule :=
(
0.0,
-3.76658789186745925058252152533908716E-2,
5.67928842039518928510970147912050422E-1,
-3.82926207303865435462186918945387604E+0,
1.49937372089424856284394953289038602E+1,
-3.66664900435733744206799901045792473E+1,
5.43564359833234758784667734950027661E+1,
-3.72441660612677085759657145349229679E+1,
-1.74694142343480879369195871851692255E+1,
4.92320460657452483269335144928459893E+1,
-6.64491030559101381755670180420816041E+0,
-4.77651142779538437557083447698412815E+1,
1.73293114329246181785799693357315130E+1,
4.70302337758355971984282091069699762E+1,
-2.11109978864513690140785415031078277E+1,
-4.88213660588897028591616672126824653E+1,
2.22125383601620792778873230835801331E+1,
5.34101465461652895090004133662581621E+1,
-2.12602266653438627407844451791571210E+1,
-5.57209119313868712461201627441943070E+1,
2.76722676096069404865159928630093821E+1,
6.10666251448596019782775543303643536E+1,
-3.96762172868191997234159288218731636E+1,
-5.54311782675496040578799507499480335E+1,
7.28176066713933903979118677503875922E+1,
2.18980635241011035788623073189610057E+1,
-1.05408021585492928249322357181431290E+2,
1.12572955426059367818475889462988068E+2,
-6.58946271293435403979999817060975942E+1,
2.69594461309580514327210630512831221E+1,
-5.59615770312664822554627115699044105E+0,
1.95738466697831534925599592471241917E+0
);
Center_Integration_32_21 : constant Integration_Rule :=
(
3.15713968194170133919540213875143917E-5,
-4.68054008955732353100985646310188096E-4,
3.07872579249862231519513009405313968E-3,
-1.15997994611621236175002511977323250E-2,
2.65427741706869908147987953876501056E-2,
-3.41143206815192906544786599038747983E-2,
1.20645063820463013734131783866792169E-2,
2.94493218168506239920090546327231263E-2,
-3.18445717486473259824967360646315308E-2,
-2.50397085225343097687547550717275702E-2,
4.76987615793932385807965774292440943E-2,
3.07886851486023175023595502260427314E-2,
-7.38315319596948536351414208989101596E-2,
-6.07773034846435767063660851642605318E-2,
1.69131632098663497836012986946412281E-1,
4.18889311481596203289861666823254893E-1,
4.18889311481596203289861666823254893E-1,
1.69131632098663497836012986946412281E-1,
-6.07773034846435767063660851642605318E-2,
-7.38315319596948536351414208989101596E-2,
3.07886851486023175023595502260427314E-2,
4.76987615793932385807965774292440943E-2,
-2.50397085225343097687547550717275702E-2,
-3.18445717486473259824967360646315308E-2,
2.94493218168506239920090546327231263E-2,
1.20645063820463013734131783866792169E-2,
-3.41143206815192906544786599038747983E-2,
2.65427741706869908147987953876501056E-2,
-1.15997994611621236175002511977323250E-2,
3.07872579249862231519513009405313968E-3,
-4.68054008955732353100985646310188096E-4,
3.15713968194170133919540213875143917E-5
);
Center_to_End_Integration_32_21 : constant Integration_Rule :=
(
2.67676113993981001763809319754072371E-3,
-3.90414124872012608319921156146467020E-2,
2.52897305138324833065939788870923100E-1,
-9.41422643837414610774370025514649935E-1,
2.14850368051169799522144914234748153E+0,
-2.84597581722151283363164795921442741E+0,
1.39544227000034673428155722515887098E+0,
1.60217256593568644054691955308769836E+0,
-2.33684708581854938457931124406942042E+0,
-6.99469557657931647462943965444505190E-1,
2.54206159359924808517252057468457114E+0,
4.15826557605733909242147235579095361E-1,
-2.64474292104835540935350358708282987E+0,
-5.60524318406041607135984469627897759E-1,
2.78013606887083999365842894448864354E+0,
1.31267282288605930122990769828404270E+0,
-1.83745642535805258947599407540582716E+0,
-1.64491719484757509954584629286234845E-1,
3.84178065074193534815651322745527819E+0,
2.60951009235448927579580917661058525E+0,
-2.01282031523759572328372305407819331E+0,
-8.19518792060407429876302910591644700E-1,
4.54380874530246277239172359511529107E+0,
2.42736921885735578206607920544316634E+0,
-3.63441574631461110834005685630745714E+0,
1.74506731927578551656514296328591567E+0,
6.16952522205945152115268462360400868E+0,
-6.04962355330430886553253297561475371E+0,
6.04310831668287702035797795033002054E+0,
-1.40169443829686851269046425183043729E+0,
1.89799017094858231321012627961699879E+0,
2.57495384622791840790846842522793468E-1
);
Center_to_End_Integration
: Integration_Rule renames Center_to_End_Integration_32_21;
Predictor_Rule : Integration_Rule renames Predictor_31_21;
Corrector_Rule : Integration_Rule renames Corrector_33_21;
Center_Integration : Integration_Rule renames Center_Integration_32_21;
Final_Step_Corrector : Real renames Final_Step_Corrector_33_21;
end pc_2_coeff_21;
|
-----------------------------------------------------------------------
-- util-streams-encoders -- Streams with encoding and decoding capabilities
-- Copyright (C) 2017, 2019, 2021 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.Encoders;
-- == Encoding Streams ==
-- The <tt>Encoding_Stream</tt> tagged record represents a stream with encoding capabilities.
-- The stream passes the data to be written to the <tt>Transformer</tt> interface that
-- allows to make transformations on the data before being written.
--
-- Encode : Util.Streams.Buffered.Encoders.Encoding_Stream;
--
-- The encoding stream manages a buffer that is used to hold the encoded data before it is
-- written to the target stream. The <tt>Initialize</tt> procedure must be called to indicate
-- the target stream, the size of the buffer and the encoding format to be used.
--
-- Encode.Initialize (Output => File'Access, Size => 4096, Format => "base64");
--
generic
type Encoder is limited new Util.Encoders.Transformer with private;
package Util.Streams.Buffered.Encoders is
-- -----------------------
-- Encoding stream
-- -----------------------
-- The <b>Encoding_Stream</b> is an output stream which uses an encoder to
-- transform the data before writing it to the output. The transformer can
-- change the data by encoding it in Base64, Base16 or encrypting it.
type Encoder_Stream is limited new Util.Streams.Buffered.Input_Output_Buffer_Stream
with record
Transform : Encoder;
Flushed : Boolean := False;
end record;
-- Initialize the stream with a buffer of <b>Size</b> bytes.
procedure Initialize (Stream : in out Encoder_Stream;
Size : in Positive);
-- Initialize the stream to write on the given stream.
-- An internal buffer is allocated for writing the stream.
procedure Produces (Stream : in out Encoder_Stream;
Output : access Output_Stream'Class;
Size : in Positive);
-- Initialize the stream to read the given streams.
procedure Consumes (Stream : in out Encoder_Stream;
Input : access Input_Stream'Class;
Size : in Positive);
-- Close the sink.
overriding
procedure Close (Stream : in out Encoder_Stream);
-- Write the buffer array to the output stream.
overriding
procedure Write (Stream : in out Encoder_Stream;
Buffer : in Ada.Streams.Stream_Element_Array);
-- Read into the buffer as many bytes as possible and return in
-- `last` the position of the last byte read.
overriding
procedure Read (Stream : in out Encoder_Stream;
Into : out Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset);
-- Flush the buffer by writing on the output stream.
-- Raises Data_Error if there is no output stream.
overriding
procedure Flush (Stream : in out Encoder_Stream);
overriding
procedure Finalize (Stream : in out Encoder_Stream);
-- Fill the buffer by reading the input stream.
-- Raises Data_Error if there is no input stream;
procedure Fill (Stream : in out Encoder_Stream);
end Util.Streams.Buffered.Encoders;
|
with CSV, Ada.Text_IO; use Ada.Text_IO;
procedure CSV_Data_Manipulation is
Header: String := Get_Line;
begin
Put_Line(Header & ", SUM");
while not End_Of_File loop
declare
R: CSV.Row := CSV.Line(Get_Line);
Sum: Integer := 0;
begin
while R.Next loop
Sum := Sum + Integer'Value(R.Item);
Put(R.Item & ",");
end loop;
Put_Line(Integer'Image(Sum));
end;
end loop;
end CSV_Data_Manipulation;
|
package Longest_Common_Prefix
with SPARK_Mode => On,
Initializes => A
is
type Text is array (Positive range <>) of Integer;
A : Text (1 .. 1000) := (others => 0);
function LCP (X, Y : Positive) return Natural;
end Longest_Common_Prefix;
|
with Ada.Text_IO;
use Ada.Text_IO;
--Print a message out to the screen
-- date Saturday 13 April 2013
-- https://gcc.gnu.org/onlinedocs/gnat_ugn/Running-a-Simple-Ada-Program.html
-- https://stackoverflow.com/questions/12462461/is-it-worth-to-learn-ada-instead-of-another-languages-c-c
procedure Hello2 is
begin
Put_Line("Hello Mike from Ada");
Put_Line("second line");
end hello2;
|
with Libtcod.Console, Ada.Text_IO, Ada.Exceptions, Libtcod.Input, Libtcod.Maps.Paths;
use type Libtcod.Input.Event_Type;
procedure Keys is
use Ada.Exceptions, Libtcod, Libtcod.Input;
package IO renames Ada.Text_IO;
context : Console.Context := Console.make_context(w => 100, h => 100, title => "Test");
screen : Console.Screen := Console.make_screen(100, 100);
mouse : aliased Input.Mouse;
key : aliased Input.Key;
event : Event_Type;
map : Maps.Map := Maps.make_map(100, 100);
path : Maps.Paths.Path := Maps.Paths.make_path(map, diagonal_cost => 1.0);
status : Boolean;
x : aliased Maps.X_Pos;
y : aliased Maps.Y_Pos;
begin
map.set_properties_all(walkable => True, transparent => False);
status := Maps.Paths.compute(path, 0, 0, 10, 99);
if not status then
raise Constraint_Error with "Pathfinding failed";
end if;
while Maps.Paths.walk(path, x, y) loop
IO.Put_Line(x'Image & " " & y'Image);
end loop;
while not Console.is_window_closed loop
event := check_for_event(Event_Key_Press, mouse, key);
screen.put_char(x => 4, y => 25, ch => '@');
if event = Event_Key_Press then
case get_key_type(key) is
when Function_Key_Type => IO.Put_Line("Function Key");
when Key_Backspace => IO.Put_Line("Backspace");
when Key_Text =>
case get_char(key) is
when '0' .. '9' => IO.Put_Line("Digit: " & get_char(key)'Image);
when 'a' .. 'z' | 'A' .. 'Z' => IO.Put_Line("Letter: " & get_char(key)'Image);
when others => IO.Put_Line("Character: " & get_char(key)'Image);
end case;
when others => null;
end case;
end if;
context.present(screen);
end loop;
exception
when err : others => IO.Put_Line(IO.Standard_Error, Exception_Information(err));
end Keys;
|
with agar.core.event;
with agar.core.timeout;
package agar.gui.widget.scrollbar is
use type c.unsigned;
type type_t is (SCROLLBAR_HORIZ, SCROLLBAR_VERT);
for type_t use (SCROLLBAR_HORIZ => 0, SCROLLBAR_VERT => 1);
for type_t'size use c.unsigned'size;
pragma convention (c, type_t);
type button_t is (
SCROLLBAR_BUTTON_NONE,
SCROLLBAR_BUTTON_DEC,
SCROLLBAR_BUTTON_INC,
SCROLLBAR_BUTTON_SCROLL
);
for button_t use (
SCROLLBAR_BUTTON_NONE => 0,
SCROLLBAR_BUTTON_DEC => 1,
SCROLLBAR_BUTTON_INC => 2,
SCROLLBAR_BUTTON_SCROLL => 3
);
for button_t'size use c.unsigned'size;
pragma convention (c, button_t);
type flags_t is new c.unsigned;
SCROLLBAR_HFILL : constant flags_t := 16#01#;
SCROLLBAR_VFILL : constant flags_t := 16#02#;
SCROLLBAR_EXPAND : constant flags_t := SCROLLBAR_HFILL or SCROLLBAR_VFILL;
type scrollbar_t is limited private;
type scrollbar_access_t is access all scrollbar_t;
pragma convention (c, scrollbar_access_t);
-- API
function allocate_integer
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
min : agar.core.types.integer_access_t;
max : agar.core.types.integer_access_t;
visible : agar.core.types.integer_access_t) return scrollbar_access_t;
pragma import (c, allocate_integer, "AG_ScrollbarNewInt");
function allocate_unsigned
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
min : agar.core.types.unsigned_access_t;
max : agar.core.types.unsigned_access_t;
visible : agar.core.types.unsigned_access_t) return scrollbar_access_t;
pragma import (c, allocate_unsigned, "AG_ScrollbarNewUint");
function allocate_float
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
min : agar.core.types.float_access_t;
max : agar.core.types.float_access_t;
visible : agar.core.types.float_access_t) return scrollbar_access_t;
pragma import (c, allocate_float, "AG_ScrollbarNewFloat");
function allocate_double
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
min : agar.core.types.double_access_t;
max : agar.core.types.double_access_t;
visible : agar.core.types.double_access_t) return scrollbar_access_t;
pragma import (c, allocate_double, "AG_ScrollbarNewDouble");
function allocate_uint8
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
value : agar.core.types.uint8_ptr_t;
min : agar.core.types.uint8_ptr_t;
max : agar.core.types.uint8_ptr_t;
visible : agar.core.types.uint8_ptr_t) return scrollbar_access_t;
pragma import (c, allocate_uint8, "AG_ScrollbarNewUint8");
function allocate_int8
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
value : agar.core.types.int8_ptr_t;
min : agar.core.types.int8_ptr_t;
max : agar.core.types.int8_ptr_t;
visible : agar.core.types.int8_ptr_t) return scrollbar_access_t;
pragma import (c, allocate_int8, "AG_ScrollbarNewSint8");
function allocate_uint16
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
value : agar.core.types.uint16_ptr_t;
min : agar.core.types.uint16_ptr_t;
max : agar.core.types.uint16_ptr_t;
visible : agar.core.types.uint16_ptr_t) return scrollbar_access_t;
pragma import (c, allocate_uint16, "AG_ScrollbarNewUint16");
function allocate_int16
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
value : agar.core.types.int16_ptr_t;
min : agar.core.types.int16_ptr_t;
max : agar.core.types.int16_ptr_t;
visible : agar.core.types.int16_ptr_t) return scrollbar_access_t;
pragma import (c, allocate_int16, "AG_ScrollbarNewSint16");
function allocate_uint32
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
value : agar.core.types.uint32_ptr_t;
min : agar.core.types.uint32_ptr_t;
max : agar.core.types.uint32_ptr_t;
visible : agar.core.types.uint32_ptr_t) return scrollbar_access_t;
pragma import (c, allocate_uint32, "AG_ScrollbarNewUint32");
function allocate_int32
(parent : widget_access_t;
bar_type : type_t;
flags : flags_t;
value : agar.core.types.int32_ptr_t;
min : agar.core.types.int32_ptr_t;
max : agar.core.types.int32_ptr_t;
visible : agar.core.types.int32_ptr_t) return scrollbar_access_t;
pragma import (c, allocate_int32, "AG_ScrollbarNewSint32");
procedure set_size
(scrollbar : scrollbar_access_t;
size : natural);
pragma inline (set_size);
function get_size (scrollbar : scrollbar_access_t) return natural;
pragma inline (get_size);
function visible (scrollbar : scrollbar_access_t) return boolean;
pragma inline (visible);
procedure set_increment
(scrollbar : scrollbar_access_t;
increment : positive);
pragma inline (set_increment);
procedure set_increment
(scrollbar : scrollbar_access_t;
increment : long_float);
pragma inline (set_increment);
function widget (scrollbar : scrollbar_access_t) return widget_access_t;
pragma inline (widget);
private
type scrollbar_t is record
widget : aliased widget_t;
flags : flags_t;
value : c.int;
min : c.int;
max : c.int;
visible : c.int;
bar_type : type_t;
bar_button : button_t;
button_width : c.int;
bar_width : c.int;
arrow_height : c.int;
button_inc_func : access agar.core.event.event_t;
button_dec_func : access agar.core.event.event_t;
scroll_to : agar.core.timeout.timeout_t;
inc_to : agar.core.timeout.timeout_t;
dec_to : agar.core.timeout.timeout_t;
x_offset : c.int;
extent : c.int;
r_inc : c.double;
i_inc : c.int;
end record;
pragma convention (c, scrollbar_t);
end agar.gui.widget.scrollbar;
|
package body GDB_Remote is
--------------
-- From_Hex --
--------------
function From_Hex (Str : String) return Unsigned_64
is
Res : Unsigned_64 := 0;
begin
for C of Str loop
Res := Shift_Left (Res, 4);
Res := Res + Unsigned_64 (From_Hex (C));
end loop;
return Res;
end From_Hex;
------------------
-- Parse_Packet --
------------------
function Parse_Packet (Str : String; Cursor : out Natural) return Packet is
begin
Cursor := Str'First + 1;
case Str (Str'First) is
when 'c' =>
return Parse_Continue (Str, Cursor);
when 'D' =>
return (Kind => Detach);
when 's' =>
return Parse_Single_Step (Str, Cursor);
when 'q' =>
return Parse_General_Query (Str, Cursor);
when 'v' =>
return Parse_v_Packet (Str, Cursor);
when 'H' =>
return Parse_Set_Thread (Str, Cursor);
when '?' =>
return (Kind => Question_Halt);
when 'g' =>
return (Kind => Read_General_Registers);
when 'p' =>
return Parse_Read_Register (Str, Cursor);
when 'm' =>
return Parse_Read_Memory (Str, Cursor);
when 'M' =>
return Parse_Write_Memory (Str, Cursor, Hexadecimal);
when 'X' =>
return Parse_Write_Memory (Str, Cursor, Binary);
when 'z' =>
return Parse_Breakpoint (Str, Cursor, Insert => False);
when 'Z' =>
return Parse_Breakpoint (Str, Cursor, Insert => True);
when others => return (Kind => Unknown_Packet);
end case;
end Parse_Packet;
-------------------------
-- Parse_General_Query --
-------------------------
function Parse_General_Query (Str : String;
Cursor : in out Natural)
return Packet
is
Topic_Str : constant String := Next_Field (Str, Cursor);
Topic : General_Query_Topic := Unknown_General_Query;
begin
if Topic_Str = "Supported" then
Topic := Supported;
elsif Topic_Str = "TStatus" then
Topic := TStatus;
elsif Topic_Str = "Attached" then
Topic := Attached;
elsif Topic_Str = "fThreadInfo" then
Topic := Thread_Info_Start;
elsif Topic_Str = "sThreadInfo" then
Topic := Thread_Info_Cont;
end if;
return (Kind => General_Query,
Q_Topic => Topic);
end Parse_General_Query;
-------------------
-- Parse_v_Query --
-------------------
function Parse_v_Packet (Str : String;
Cursor : in out Natural)
return Packet
is
Id_Str : constant String := Next_Field (Str, Cursor);
begin
Cursor := Str'Last + 1;
if Id_Str = "MustReplyEmpty" then
return (Kind => Must_Reply_Empty);
elsif Id_Str = "Cont?" then
return (Kind => Query_Supported_Continue);
else
return (Kind => Unknown_Packet);
end if;
end Parse_v_Packet;
----------------------
-- Parse_Set_Thread --
----------------------
function Parse_Set_Thread (Str : String;
Cursor : in out Natural)
return Packet
is
Res : Packet := (Kind => Set_Thread, others => <>);
begin
if Str'Length < 3 then
return (Kind => Bad_Packet);
end if;
Res.Op := Str (Cursor);
Res.Thread_ID := To_Int (Str (Cursor + 1 .. Str'Last));
Cursor := Str'Last + 1;
return Res;
end Parse_Set_Thread;
-------------------------
-- Parse_Read_Register --
-------------------------
function Parse_Read_Register (Str : String;
Cursor : in out Natural)
return Packet
is
Res : Packet := (Kind => Read_Register, others => <>);
begin
if Str'Length < 2 then
return (Kind => Bad_Packet);
end if;
Res.Register_Id := To_Int (Str (Cursor .. Str'Last));
Cursor := Str'Last + 1;
return Res;
end Parse_Read_Register;
-----------------------
-- Parse_Read_Memory --
-----------------------
function Parse_Read_Memory (Str : String;
Cursor : in out Natural)
return Packet
is
Res : Packet := (Kind => Read_Memory, others => <>);
Addr_Str : constant String := Next_Field (Str, Cursor);
Size_Str : constant String := Next_Field (Str, Cursor);
begin
Res.M_Address := From_Hex (Addr_Str);
Res.M_Size := From_Hex (Size_Str);
return Res;
end Parse_Read_Memory;
------------------------
-- Parse_Write_Memory --
------------------------
function Parse_Write_Memory (Str : String;
Cursor : in out Natural;
Fmt : Data_Format)
return Packet
is
Res : Packet := (Kind => Write_Memory, others => <>);
Addr_Str : constant String := Next_Field (Str, Cursor);
Size_Str : constant String := Next_Field (Str, Cursor);
begin
Res.M_Address := From_Hex (Addr_Str);
Res.M_Size := From_Hex (Size_Str);
Res.M_Data_Fmt := Fmt;
return Res;
end Parse_Write_Memory;
--------------------
-- Parse_Continue --
--------------------
function Parse_Continue (Str : String;
Cursor : in out Natural)
return Packet
is
Addr : Integer;
begin
if Str'Length > 1 then
Addr := To_Int (Str (Cursor .. Str'Last));
Cursor := Str'Last + 1;
return (Kind => Continue_Addr, C_Address => Unsigned_64 (Addr));
else
return (Kind => Continue);
end if;
end Parse_Continue;
-----------------------
-- Parse_Single_Step --
-----------------------
function Parse_Single_Step (Str : String;
Cursor : in out Natural)
return Packet
is
Addr : Integer;
begin
if Str'Length > 1 then
Addr := To_Int (Str (Cursor .. Str'Last));
Cursor := Str'Last + 1;
return (Kind => Single_Step_Addr, C_Address => Unsigned_64 (Addr));
else
return (Kind => Single_Step);
end if;
end Parse_Single_Step;
----------------------
-- Parse_Breakpoint --
----------------------
function Parse_Breakpoint (Str : String;
Cursor : in out Natural;
Insert : Boolean)
return Packet
is
Type_Str : constant String := Next_Field (Str, Cursor);
Addr_Str : constant String := Next_Field (Str, Cursor);
Kind_Str : constant String := Next_Field (Str, Cursor);
B_Type : Breakpoint_Type;
B_Kind : Natural;
B_Addr : Unsigned_64;
begin
if Type_Str'Length /= 1 then
return (Kind => Bad_Packet);
end if;
case Type_Str (Type_Str'First) is
when '0' => B_Type := Software_Breakpoint;
when '1' => B_Type := Hardware_Breakpoint;
when '2' => B_Type := Write_Watchpoint;
when '3' => B_Type := Read_Watchpoint;
when '4' => B_Type := Access_Watchpoint;
when others => return (Kind => Bad_Packet);
end case;
B_Addr := From_Hex (Addr_Str);
B_Kind := Natural (From_Hex (Kind_Str));
if Insert then
return (Kind => Insert_Breakpoint,
B_Type => B_Type,
B_Addr => B_Addr,
B_Kind => B_Kind);
else
return (Kind => Remove_Breakpoint,
B_Type => B_Type,
B_Addr => B_Addr,
B_Kind => B_Kind);
end if;
end Parse_Breakpoint;
----------------
-- Next_Field --
----------------
function Next_Field (P : String;
Cursor : in out Natural)
return String
is
From : constant Natural := Cursor;
To : Natural;
begin
while Cursor in P'First .. P'Last
and then
P (Cursor) not in ':' | ';' | ','
loop
Cursor := Cursor + 1;
end loop;
To := Cursor - 1;
Cursor := Cursor + 1;
return P (From .. To);
end Next_Field;
---------------
-- Next_Data --
---------------
function Next_Data (P : String;
Cursor : in out Natural;
Fmt : Data_Format;
Success : out Boolean)
return Unsigned_8
is
Res : Unsigned_8;
begin
case Fmt is
when Hexadecimal =>
if Cursor in P'First .. P'Last - 1 then
Success := True;
return Unsigned_8 (From_Hex (P (Cursor .. Cursor + 1)));
end if;
when Binary =>
if Cursor in P'First .. P'Last then
if P (Cursor) = '}' then
-- Escape character
Cursor := Cursor + 1;
if Cursor <= P'Last then
Res := Unsigned_8 (P (Cursor)'Enum_Rep) xor 16#20#;
Cursor := Cursor + 1;
Success := True;
return Res;
end if;
else
Res := Unsigned_8 (P (Cursor)'Enum_Rep);
Cursor := Cursor + 1;
Success := True;
return Res;
end if;
end if;
end case;
Success := False;
return 0;
end Next_Data;
------------
-- To_Int --
------------
function To_Int (Str : String) return Integer is
Res : Integer := 0;
Cursor : Natural;
begin
if Str (Str'First) = '-' then
Cursor := Str'First + 1;
else
Cursor := Str'First;
end if;
while Cursor <= Str'Last loop
Res := Res * 16 + Integer (From_Hex (Str (Cursor)));
Cursor := Cursor + 1;
end loop;
if Str (Str'First) = '-' then
return -Res;
else
return Res;
end if;
end To_Int;
end GDB_Remote;
|
with Interfaces; use Interfaces;
with STM32.GPIO;
with STM32.RCC;
package body EVB1000.USB
with SPARK_Mode => Off
is
Connected : Boolean := False;
Configured : Boolean := False;
Suspended : Boolean := False;
----------------------------------------------------------------------------
-- Imported subprograms from the ST USB library
-- (implemented in C, called by Ada)
----------------------------------------------------------------------------
procedure USB_Init
with Convention => C,
Import => True,
External_Name => "USB_Init";
procedure OTG_FS_IRQHandler
with Convention => C,
Import => True,
External_Name => "OTG_FS_IRQHandler";
function VCP_DataTx (Buffer : in System.Address;
Length : in Interfaces.Unsigned_32)
return Interfaces.Unsigned_16
with Convention => C,
Import => True,
External_Name => "VCP_DataTx";
----------------------------------------------------------------------------
-- Exported programs
-- (implemented in Ada, called by C)
----------------------------------------------------------------------------
function VCP_DataRx (Buffer_Ptr : in System.Address;
Length : in Interfaces.Unsigned_32)
return Interfaces.Unsigned_16
with Convention => C,
Export => True,
External_Name => "VCP_DataRx";
procedure USBD_USR_DeviceConfigured
with Convention => C,
Export => True,
External_Name => "USBD_USR_DeviceConfigured";
procedure USBD_USR_DeviceConnected
with Convention => C,
Export => True,
External_Name => "USBD_USR_DeviceConnected";
procedure USBD_USR_DeviceDisconnected
with Convention => C,
Export => True,
External_Name => "USBD_USR_DeviceDisconnected";
procedure USBD_USR_DeviceSuspended
with Convention => C,
Export => True,
External_Name => "USBD_USR_DeviceSuspended";
procedure USBD_USR_DeviceResumed
with Convention => C,
Export => True,
External_Name => "USBD_USR_DeviceResumed";
function VCP_DataRx (Buffer_Ptr : in System.Address;
Length : in Interfaces.Unsigned_32)
return Interfaces.Unsigned_16
is
subtype Overlay_String is String (1 .. Natural (Length));
Buffer_Overlay : aliased Overlay_String
with Address => Buffer_Ptr;
begin
if Connected and Configured then
Buffer.Data_Received (Buffer_Overlay);
end if;
return 0; -- USBD_OK
end VCP_DataRx;
procedure USBD_USR_DeviceConfigured
is
begin
Configured := True;
end USBD_USR_DeviceConfigured;
procedure USBD_USR_DeviceConnected
is
begin
Connected := True;
end USBD_USR_DeviceConnected;
procedure USBD_USR_DeviceDisconnected
is
begin
Connected := False;
Configured := False;
end USBD_USR_DeviceDisconnected;
procedure USBD_USR_DeviceSuspended
is
begin
Suspended := True;
end USBD_USR_DeviceSuspended;
procedure USBD_USR_DeviceResumed
is
begin
Suspended := False;
end USBD_USR_DeviceResumed;
protected body Buffer
is
function Is_Connected return Boolean
is
begin
return Connected;
end Is_Connected;
function Can_Read return Boolean
is
begin
return Has_Data;
end Can_Read;
entry Read (Str : in out String;
Count : out Natural)
when Has_Data
is
Str_Pos : Integer := Str'First;
begin
Count := 0;
while Count < Str'Length and Count < Rx_Length loop
Str (Str_Pos) := Rx_Buffer (Integer (Rx_First) + 1);
Str_Pos := Str_Pos + 1;
Rx_First := Rx_First + 1;
Count := Count + 1;
end loop;
Rx_Length := Rx_Length - Count;
Has_Data := Rx_Length > 0;
end Read;
procedure Write (Str : in String)
is
begin
--if Is_Connected then
Driver.Write (Str);
--end if;
end Write;
procedure Data_Received (Str : in String)
is
Str_Length : Natural;
Free_Space : Rx_Length_Number;
Buffer_Pos : Rx_Index;
Str_Pos : Integer;
begin
if Str'Length > 0 then
if Str'Length <= Rx_Buffer_Size then
Str_Length := Str'Length;
else
-- Discard any data past the maximum buffer size.
Str_Length := Rx_Buffer_Size;
end if;
if Rx_Length = 0 then
-- Rx buffer is empty.
Rx_Buffer (1 .. Str_Length) :=
Str (Str'First .. Str'First + Str_Length - 1);
Rx_Length := Str_Length;
Rx_First := 0;
else
Free_Space := Rx_Buffer_Size - Rx_Length;
if Free_Space > 0 then
if Str_Length > Free_Space then
-- Not enough free space to store all data.
-- Only store the first data.
Str_Length := Free_Space;
end if;
Buffer_Pos := Rx_First + Rx_Index (Rx_Length);
Str_Pos := Str'First;
while Str_Length > 0 loop
Rx_Buffer (Integer (Buffer_Pos) + 1) := Str (Str_Pos);
Buffer_Pos := Buffer_Pos + 1;
Str_Pos := Str_Pos + 1;
Str_Length := Str_Length - 1;
end loop;
end if;
end if;
Has_Data := True;
end if;
end Data_Received;
end Buffer;
protected body Driver
is
procedure Write (Str : in String)
is
Result : Unsigned_16;
begin
Result := VCP_DataTx (Str'Address, Unsigned_32 (Str'Length));
pragma Unreferenced (Result);
end Write;
procedure USB_OTG_Interrupt_Handler
is
begin
-- Forward to ST's USB library in C land.
OTG_FS_IRQHandler;
end USB_OTG_Interrupt_Handler;
end Driver;
begin
-- Set PA9 to floating input
-- Set PA10 to input with pull-up
-- Set PA11 and PA12 to output push-pull @ 50 MHz
STM32.GPIO.GPIOA_Periph.CRH.MODE9 := 2#00#; -- input
STM32.GPIO.GPIOA_Periph.CRH.MODE10 := 2#00#; -- input
STM32.GPIO.GPIOA_Periph.CRH.MODE11 := 2#11#; -- output 50 MHz
STM32.GPIO.GPIOA_Periph.CRH.MODE12 := 2#11#; -- output 50 MHz
STM32.GPIO.GPIOA_Periph.CRH.CNF9 := 2#01#; -- Floating input
STM32.GPIO.GPIOA_Periph.CRH.CNF10 := 2#10#; -- Input with pull up/down
STM32.GPIO.GPIOA_Periph.CRH.CNF11 := 2#00#; -- GP output push-pull
STM32.GPIO.GPIOA_Periph.CRH.CNF12 := 2#00#; -- GP output push-pull
STM32.GPIO.GPIOA_Periph.BSRR.BS.Arr (10) := 1; -- Use pull-up
-- Enable USB peripheral clock
STM32.RCC.RCC_Periph.AHBENR.OTGFSEN := 1;
USB_Init; -- ST's C library initialization routine.
end EVB1000.USB;
|
with SPARKNaCl; use SPARKNaCl;
with SPARKNaCl.Core; use SPARKNaCl.Core;
with SPARKNaCl.Debug; use SPARKNaCl.Debug;
with SPARKNaCl.Secretbox; use SPARKNaCl.Secretbox;
with SPARKNaCl.Stream;
with Ada.Text_IO; use Ada.Text_IO;
procedure Secretbox2
is
Firstkey : constant Core.Salsa20_Key :=
Construct ((16#1b#, 16#27#, 16#55#, 16#64#,
16#73#, 16#e9#, 16#85#, 16#d4#,
16#62#, 16#cd#, 16#51#, 16#19#,
16#7a#, 16#9a#, 16#46#, 16#c7#,
16#60#, 16#09#, 16#54#, 16#9e#,
16#ac#, 16#64#, 16#74#, 16#f2#,
16#06#, 16#c4#, 16#ee#, 16#08#,
16#44#, 16#f6#, 16#83#, 16#89#));
Nonce : constant Stream.HSalsa20_Nonce :=
(16#69#, 16#69#, 16#6e#, 16#e9#, 16#55#, 16#b6#, 16#2b#, 16#73#,
16#cd#, 16#62#, 16#bd#, 16#a8#, 16#75#, 16#fc#, 16#73#, 16#d6#,
16#82#, 16#19#, 16#e0#, 16#03#, 16#6b#, 16#7a#, 16#0b#, 16#37#);
C : constant Byte_Seq (0 .. 162) :=
(16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#F3#, 16#FF#, 16#C7#, 16#70#, 16#3F#, 16#94#, 16#00#, 16#E5#,
16#2A#, 16#7D#, 16#FB#, 16#4B#, 16#3D#, 16#33#, 16#05#, 16#D9#,
16#8E#, 16#99#, 16#3B#, 16#9F#, 16#48#, 16#68#, 16#12#, 16#73#,
16#C2#, 16#96#, 16#50#, 16#BA#, 16#32#, 16#FC#, 16#76#, 16#CE#,
16#48#, 16#33#, 16#2E#, 16#A7#, 16#16#, 16#4D#, 16#96#, 16#A4#,
16#47#, 16#6F#, 16#B8#, 16#C5#, 16#31#, 16#A1#, 16#18#, 16#6A#,
16#C0#, 16#DF#, 16#C1#, 16#7C#, 16#98#, 16#DC#, 16#E8#, 16#7B#,
16#4D#, 16#A7#, 16#F0#, 16#11#, 16#EC#, 16#48#, 16#C9#, 16#72#,
16#71#, 16#D2#, 16#C2#, 16#0F#, 16#9B#, 16#92#, 16#8F#, 16#E2#,
16#27#, 16#0D#, 16#6F#, 16#B8#, 16#63#, 16#D5#, 16#17#, 16#38#,
16#B4#, 16#8E#, 16#EE#, 16#E3#, 16#14#, 16#A7#, 16#CC#, 16#8A#,
16#B9#, 16#32#, 16#16#, 16#45#, 16#48#, 16#E5#, 16#26#, 16#AE#,
16#90#, 16#22#, 16#43#, 16#68#, 16#51#, 16#7A#, 16#CF#, 16#EA#,
16#BD#, 16#6B#, 16#B3#, 16#73#, 16#2B#, 16#C0#, 16#E9#, 16#DA#,
16#99#, 16#83#, 16#2B#, 16#61#, 16#CA#, 16#01#, 16#B6#, 16#DE#,
16#56#, 16#24#, 16#4A#, 16#9E#, 16#88#, 16#D5#, 16#F9#, 16#B3#,
16#79#, 16#73#, 16#F6#, 16#22#, 16#A4#, 16#3D#, 16#14#, 16#A6#,
16#59#, 16#9B#, 16#1F#, 16#65#, 16#4C#, 16#B4#, 16#5A#, 16#74#,
16#E3#, 16#55#, 16#A5#);
M : Byte_Seq (0 .. 162);
S : Boolean;
begin
Open (M, S, C, Nonce, Firstkey);
Put_Line ("Status is " & S'Img);
DH ("M is", M);
end Secretbox2;
|
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_IO; use Ada.Text_IO;
procedure Mean_Main is
type Vector is array(Positive range <>) of Float;
function Mean(Item : Vector) return Float is
Sum : Float := 0.0;
Result : Float := 0.0;
begin
for I in Item'range loop
Sum := Sum + Item(I);
end loop;
if Item'Length > 0 then
Result := Sum / Float(Item'Length);
end if;
return Result;
end Mean;
A : Vector := (3.0, 1.0, 4.0, 1.0, 5.0, 9.0);
begin
Put(Item => Mean(A), Fore => 1, Exp => 0);
New_Line;
-- test for zero length vector
Put(Item => Mean(A(1..0)), Fore => 1, Exp => 0);
New_Line;
end Mean_Main;
|
with Posix;
generic
with procedure Encode (Source_File_Name : Posix.C_String;
Output_File_Name : Posix.C_String;
Offset : Natural;
Text : String) is <>;
procedure Hide.Encode_Generic;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- B I N D O . V A L I D A T O R S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2019-2020, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- For full architecture, see unit Bindo.
-- The following unit contains facilities to verify the validity of the
-- various graphs used in determining the elaboration order of units.
with Bindo.Graphs;
use Bindo.Graphs;
use Bindo.Graphs.Invocation_Graphs;
use Bindo.Graphs.Library_Graphs;
package Bindo.Validators is
----------------------
-- Cycle_Validators --
----------------------
package Cycle_Validators is
Invalid_Cycle : exception;
-- Exception raised when the library graph contains an invalid cycle
procedure Validate_Cycles (G : Library_Graph);
-- Ensure that all cycles of library graph G meet the following
-- requirements:
--
-- * Are of proper kind
-- * Have enough edges to form a circuit
-- * No edge is repeated
--
-- Diagnose issues and raise Invalid_Cycle if this is not the case.
end Cycle_Validators;
----------------------------------
-- Elaboration_Order_Validators --
----------------------------------
package Elaboration_Order_Validators is
Invalid_Elaboration_Order : exception;
-- Exception raised when the elaboration order contains invalid data
procedure Validate_Elaboration_Order (Order : Unit_Id_Table);
-- Ensure that elaboration order Order meets the following requirements:
--
-- * All units that must be elaborated appear in the order
-- * No other units appear in the order
--
-- Diagnose issues and raise Invalid_Elaboration_Order if this is not
-- the case.
end Elaboration_Order_Validators;
---------------------------------
-- Invocation_Graph_Validators --
---------------------------------
package Invocation_Graph_Validators is
Invalid_Invocation_Graph : exception;
-- Exception raised when the invocation graph contains invalid data
procedure Validate_Invocation_Graph (G : Invocation_Graph);
-- Ensure that invocation graph G meets the following requirements:
--
-- * All attributes of edges are properly set
-- * All attributes of vertices are properly set
--
-- Diagnose issues and raise Invalid_Invocation_Graph if this is not the
-- case.
end Invocation_Graph_Validators;
------------------------------
-- Library_Graph_Validators --
------------------------------
package Library_Graph_Validators is
Invalid_Library_Graph : exception;
-- Exception raised when the library graph contains invalid data
procedure Validate_Library_Graph (G : Library_Graph);
-- Ensure that library graph G meets the following requirements:
--
-- * All attributes edges are properly set
-- * All attributes of vertices are properly set
--
-- Diagnose issues and raise Invalid_Library_Graph if this is not the
-- case.
end Library_Graph_Validators;
end Bindo.Validators;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- ADA.CONTAINERS.RED_BLACK_TREES.GENERIC_BOUNDED_KEYS --
-- --
-- B o d y --
-- --
-- Copyright (C) 2004-2015, 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/>. --
-- --
-- This unit was originally developed by Matthew J Heaney. --
------------------------------------------------------------------------------
package body Ada.Containers.Red_Black_Trees.Generic_Bounded_Keys is
package Ops renames Tree_Operations;
-------------
-- Ceiling --
-------------
-- AKA Lower_Bound
function Ceiling
(Tree : Tree_Type'Class;
Key : Key_Type) return Count_Type
is
Y : Count_Type;
X : Count_Type;
N : Nodes_Type renames Tree.Nodes;
begin
Y := 0;
X := Tree.Root;
while X /= 0 loop
if Is_Greater_Key_Node (Key, N (X)) then
X := Ops.Right (N (X));
else
Y := X;
X := Ops.Left (N (X));
end if;
end loop;
return Y;
end Ceiling;
----------
-- Find --
----------
function Find
(Tree : Tree_Type'Class;
Key : Key_Type) return Count_Type
is
Y : Count_Type;
X : Count_Type;
N : Nodes_Type renames Tree.Nodes;
begin
Y := 0;
X := Tree.Root;
while X /= 0 loop
if Is_Greater_Key_Node (Key, N (X)) then
X := Ops.Right (N (X));
else
Y := X;
X := Ops.Left (N (X));
end if;
end loop;
if Y = 0 then
return 0;
end if;
if Is_Less_Key_Node (Key, N (Y)) then
return 0;
end if;
return Y;
end Find;
-----------
-- Floor --
-----------
function Floor
(Tree : Tree_Type'Class;
Key : Key_Type) return Count_Type
is
Y : Count_Type;
X : Count_Type;
N : Nodes_Type renames Tree.Nodes;
begin
Y := 0;
X := Tree.Root;
while X /= 0 loop
if Is_Less_Key_Node (Key, N (X)) then
X := Ops.Left (N (X));
else
Y := X;
X := Ops.Right (N (X));
end if;
end loop;
return Y;
end Floor;
--------------------------------
-- Generic_Conditional_Insert --
--------------------------------
procedure Generic_Conditional_Insert
(Tree : in out Tree_Type'Class;
Key : Key_Type;
Node : out Count_Type;
Inserted : out Boolean)
is
Y : Count_Type;
X : Count_Type;
N : Nodes_Type renames Tree.Nodes;
begin
-- This is a "conditional" insertion, meaning that the insertion request
-- can "fail" in the sense that no new node is created. If the Key is
-- equivalent to an existing node, then we return the existing node and
-- Inserted is set to False. Otherwise, we allocate a new node (via
-- Insert_Post) and Inserted is set to True.
-- Note that we are testing for equivalence here, not equality. Key must
-- be strictly less than its next neighbor, and strictly greater than
-- its previous neighbor, in order for the conditional insertion to
-- succeed.
-- We search the tree to find the nearest neighbor of Key, which is
-- either the smallest node greater than Key (Inserted is True), or the
-- largest node less or equivalent to Key (Inserted is False).
Y := 0;
X := Tree.Root;
Inserted := True;
while X /= 0 loop
Y := X;
Inserted := Is_Less_Key_Node (Key, N (X));
X := (if Inserted then Ops.Left (N (X)) else Ops.Right (N (X)));
end loop;
if Inserted then
-- Either Tree is empty, or Key is less than Y. If Y is the first
-- node in the tree, then there are no other nodes that we need to
-- search for, and we insert a new node into the tree.
if Y = Tree.First then
Insert_Post (Tree, Y, True, Node);
return;
end if;
-- Y is the next nearest-neighbor of Key. We know that Key is not
-- equivalent to Y (because Key is strictly less than Y), so we move
-- to the previous node, the nearest-neighbor just smaller or
-- equivalent to Key.
Node := Ops.Previous (Tree, Y);
else
-- Y is the previous nearest-neighbor of Key. We know that Key is not
-- less than Y, which means either that Key is equivalent to Y, or
-- greater than Y.
Node := Y;
end if;
-- Key is equivalent to or greater than Node. We must resolve which is
-- the case, to determine whether the conditional insertion succeeds.
if Is_Greater_Key_Node (Key, N (Node)) then
-- Key is strictly greater than Node, which means that Key is not
-- equivalent to Node. In this case, the insertion succeeds, and we
-- insert a new node into the tree.
Insert_Post (Tree, Y, Inserted, Node);
Inserted := True;
return;
end if;
-- Key is equivalent to Node. This is a conditional insertion, so we do
-- not insert a new node in this case. We return the existing node and
-- report that no insertion has occurred.
Inserted := False;
end Generic_Conditional_Insert;
------------------------------------------
-- Generic_Conditional_Insert_With_Hint --
------------------------------------------
procedure Generic_Conditional_Insert_With_Hint
(Tree : in out Tree_Type'Class;
Position : Count_Type;
Key : Key_Type;
Node : out Count_Type;
Inserted : out Boolean)
is
N : Nodes_Type renames Tree.Nodes;
begin
-- The purpose of a hint is to avoid a search from the root of
-- tree. If we have it hint it means we only need to traverse the
-- subtree rooted at the hint to find the nearest neighbor. Note
-- that finding the neighbor means merely walking the tree; this
-- is not a search and the only comparisons that occur are with
-- the hint and its neighbor.
-- If Position is 0, this is interpreted to mean that Key is
-- large relative to the nodes in the tree. If the tree is empty,
-- or Key is greater than the last node in the tree, then we're
-- done; otherwise the hint was "wrong" and we must search.
if Position = 0 then -- largest
if Tree.Last = 0
or else Is_Greater_Key_Node (Key, N (Tree.Last))
then
Insert_Post (Tree, Tree.Last, False, Node);
Inserted := True;
else
Conditional_Insert_Sans_Hint (Tree, Key, Node, Inserted);
end if;
return;
end if;
pragma Assert (Tree.Length > 0);
-- A hint can either name the node that immediately follows Key,
-- or immediately precedes Key. We first test whether Key is
-- less than the hint, and if so we compare Key to the node that
-- precedes the hint. If Key is both less than the hint and
-- greater than the hint's preceding neighbor, then we're done;
-- otherwise we must search.
-- Note also that a hint can either be an anterior node or a leaf
-- node. A new node is always inserted at the bottom of the tree
-- (at least prior to rebalancing), becoming the new left or
-- right child of leaf node (which prior to the insertion must
-- necessarily be null, since this is a leaf). If the hint names
-- an anterior node then its neighbor must be a leaf, and so
-- (here) we insert after the neighbor. If the hint names a leaf
-- then its neighbor must be anterior and so we insert before the
-- hint.
if Is_Less_Key_Node (Key, N (Position)) then
declare
Before : constant Count_Type := Ops.Previous (Tree, Position);
begin
if Before = 0 then
Insert_Post (Tree, Tree.First, True, Node);
Inserted := True;
elsif Is_Greater_Key_Node (Key, N (Before)) then
if Ops.Right (N (Before)) = 0 then
Insert_Post (Tree, Before, False, Node);
else
Insert_Post (Tree, Position, True, Node);
end if;
Inserted := True;
else
Conditional_Insert_Sans_Hint (Tree, Key, Node, Inserted);
end if;
end;
return;
end if;
-- We know that Key isn't less than the hint so we try again,
-- this time to see if it's greater than the hint. If so we
-- compare Key to the node that follows the hint. If Key is both
-- greater than the hint and less than the hint's next neighbor,
-- then we're done; otherwise we must search.
if Is_Greater_Key_Node (Key, N (Position)) then
declare
After : constant Count_Type := Ops.Next (Tree, Position);
begin
if After = 0 then
Insert_Post (Tree, Tree.Last, False, Node);
Inserted := True;
elsif Is_Less_Key_Node (Key, N (After)) then
if Ops.Right (N (Position)) = 0 then
Insert_Post (Tree, Position, False, Node);
else
Insert_Post (Tree, After, True, Node);
end if;
Inserted := True;
else
Conditional_Insert_Sans_Hint (Tree, Key, Node, Inserted);
end if;
end;
return;
end if;
-- We know that Key is neither less than the hint nor greater
-- than the hint, and that's the definition of equivalence.
-- There's nothing else we need to do, since a search would just
-- reach the same conclusion.
Node := Position;
Inserted := False;
end Generic_Conditional_Insert_With_Hint;
-------------------------
-- Generic_Insert_Post --
-------------------------
procedure Generic_Insert_Post
(Tree : in out Tree_Type'Class;
Y : Count_Type;
Before : Boolean;
Z : out Count_Type)
is
N : Nodes_Type renames Tree.Nodes;
begin
TC_Check (Tree.TC);
if Checks and then Tree.Length >= Tree.Capacity then
raise Capacity_Error with "not enough capacity to insert new item";
end if;
Z := New_Node;
pragma Assert (Z /= 0);
if Y = 0 then
pragma Assert (Tree.Length = 0);
pragma Assert (Tree.Root = 0);
pragma Assert (Tree.First = 0);
pragma Assert (Tree.Last = 0);
Tree.Root := Z;
Tree.First := Z;
Tree.Last := Z;
elsif Before then
pragma Assert (Ops.Left (N (Y)) = 0);
Ops.Set_Left (N (Y), Z);
if Y = Tree.First then
Tree.First := Z;
end if;
else
pragma Assert (Ops.Right (N (Y)) = 0);
Ops.Set_Right (N (Y), Z);
if Y = Tree.Last then
Tree.Last := Z;
end if;
end if;
Ops.Set_Color (N (Z), Red);
Ops.Set_Parent (N (Z), Y);
Ops.Rebalance_For_Insert (Tree, Z);
Tree.Length := Tree.Length + 1;
end Generic_Insert_Post;
-----------------------
-- Generic_Iteration --
-----------------------
procedure Generic_Iteration
(Tree : Tree_Type'Class;
Key : Key_Type)
is
procedure Iterate (Index : Count_Type);
-------------
-- Iterate --
-------------
procedure Iterate (Index : Count_Type) is
J : Count_Type;
N : Nodes_Type renames Tree.Nodes;
begin
J := Index;
while J /= 0 loop
if Is_Less_Key_Node (Key, N (J)) then
J := Ops.Left (N (J));
elsif Is_Greater_Key_Node (Key, N (J)) then
J := Ops.Right (N (J));
else
Iterate (Ops.Left (N (J)));
Process (J);
J := Ops.Right (N (J));
end if;
end loop;
end Iterate;
-- Start of processing for Generic_Iteration
begin
Iterate (Tree.Root);
end Generic_Iteration;
-------------------------------
-- Generic_Reverse_Iteration --
-------------------------------
procedure Generic_Reverse_Iteration
(Tree : Tree_Type'Class;
Key : Key_Type)
is
procedure Iterate (Index : Count_Type);
-------------
-- Iterate --
-------------
procedure Iterate (Index : Count_Type) is
J : Count_Type;
N : Nodes_Type renames Tree.Nodes;
begin
J := Index;
while J /= 0 loop
if Is_Less_Key_Node (Key, N (J)) then
J := Ops.Left (N (J));
elsif Is_Greater_Key_Node (Key, N (J)) then
J := Ops.Right (N (J));
else
Iterate (Ops.Right (N (J)));
Process (J);
J := Ops.Left (N (J));
end if;
end loop;
end Iterate;
-- Start of processing for Generic_Reverse_Iteration
begin
Iterate (Tree.Root);
end Generic_Reverse_Iteration;
----------------------------------
-- Generic_Unconditional_Insert --
----------------------------------
procedure Generic_Unconditional_Insert
(Tree : in out Tree_Type'Class;
Key : Key_Type;
Node : out Count_Type)
is
Y : Count_Type;
X : Count_Type;
N : Nodes_Type renames Tree.Nodes;
Before : Boolean;
begin
Y := 0;
Before := False;
X := Tree.Root;
while X /= 0 loop
Y := X;
Before := Is_Less_Key_Node (Key, N (X));
X := (if Before then Ops.Left (N (X)) else Ops.Right (N (X)));
end loop;
Insert_Post (Tree, Y, Before, Node);
end Generic_Unconditional_Insert;
--------------------------------------------
-- Generic_Unconditional_Insert_With_Hint --
--------------------------------------------
procedure Generic_Unconditional_Insert_With_Hint
(Tree : in out Tree_Type'Class;
Hint : Count_Type;
Key : Key_Type;
Node : out Count_Type)
is
N : Nodes_Type renames Tree.Nodes;
begin
-- There are fewer constraints for an unconditional insertion
-- than for a conditional insertion, since we allow duplicate
-- keys. So instead of having to check (say) whether Key is
-- (strictly) greater than the hint's previous neighbor, here we
-- allow Key to be equal to or greater than the previous node.
-- There is the issue of what to do if Key is equivalent to the
-- hint. Does the new node get inserted before or after the hint?
-- We decide that it gets inserted after the hint, reasoning that
-- this is consistent with behavior for non-hint insertion, which
-- inserts a new node after existing nodes with equivalent keys.
-- First we check whether the hint is null, which is interpreted
-- to mean that Key is large relative to existing nodes.
-- Following our rule above, if Key is equal to or greater than
-- the last node, then we insert the new node immediately after
-- last. (We don't have an operation for testing whether a key is
-- "equal to or greater than" a node, so we must say instead "not
-- less than", which is equivalent.)
if Hint = 0 then -- largest
if Tree.Last = 0 then
Insert_Post (Tree, 0, False, Node);
elsif Is_Less_Key_Node (Key, N (Tree.Last)) then
Unconditional_Insert_Sans_Hint (Tree, Key, Node);
else
Insert_Post (Tree, Tree.Last, False, Node);
end if;
return;
end if;
pragma Assert (Tree.Length > 0);
-- We decide here whether to insert the new node prior to the
-- hint. Key could be equivalent to the hint, so in theory we
-- could write the following test as "not greater than" (same as
-- "less than or equal to"). If Key were equivalent to the hint,
-- that would mean that the new node gets inserted before an
-- equivalent node. That wouldn't break any container invariants,
-- but our rule above says that new nodes always get inserted
-- after equivalent nodes. So here we test whether Key is both
-- less than the hint and equal to or greater than the hint's
-- previous neighbor, and if so insert it before the hint.
if Is_Less_Key_Node (Key, N (Hint)) then
declare
Before : constant Count_Type := Ops.Previous (Tree, Hint);
begin
if Before = 0 then
Insert_Post (Tree, Hint, True, Node);
elsif Is_Less_Key_Node (Key, N (Before)) then
Unconditional_Insert_Sans_Hint (Tree, Key, Node);
elsif Ops.Right (N (Before)) = 0 then
Insert_Post (Tree, Before, False, Node);
else
Insert_Post (Tree, Hint, True, Node);
end if;
end;
return;
end if;
-- We know that Key isn't less than the hint, so it must be equal
-- or greater. So we just test whether Key is less than or equal
-- to (same as "not greater than") the hint's next neighbor, and
-- if so insert it after the hint.
declare
After : constant Count_Type := Ops.Next (Tree, Hint);
begin
if After = 0 then
Insert_Post (Tree, Hint, False, Node);
elsif Is_Greater_Key_Node (Key, N (After)) then
Unconditional_Insert_Sans_Hint (Tree, Key, Node);
elsif Ops.Right (N (Hint)) = 0 then
Insert_Post (Tree, Hint, False, Node);
else
Insert_Post (Tree, After, True, Node);
end if;
end;
end Generic_Unconditional_Insert_With_Hint;
-----------------
-- Upper_Bound --
-----------------
function Upper_Bound
(Tree : Tree_Type'Class;
Key : Key_Type) return Count_Type
is
Y : Count_Type;
X : Count_Type;
N : Nodes_Type renames Tree.Nodes;
begin
Y := 0;
X := Tree.Root;
while X /= 0 loop
if Is_Less_Key_Node (Key, N (X)) then
Y := X;
X := Ops.Left (N (X));
else
X := Ops.Right (N (X));
end if;
end loop;
return Y;
end Upper_Bound;
end Ada.Containers.Red_Black_Trees.Generic_Bounded_Keys;
|
package body openGL.Light
is
function Id (Self : in Item) return light.Id_t
is
begin
return Self.Id;
end Id;
procedure Id_is (Self : in out Item; Now : in light.Id_t)
is
begin
Self.Id := Now;
end Id_is;
function Kind (Self : in Item) return light.Kind_t
is
begin
return Self.Kind;
end Kind;
procedure Kind_is (Self : in out Item; Now : in light.Kind_t)
is
begin
Self.Kind := Now;
end Kind_is;
function is_On (Self : in Item) return Boolean
is
begin
return Self.On;
end is_On;
procedure is_On (Self : in out Item; Now : in Boolean := True)
is
begin
Self.On := Now;
end is_On;
function Site (Self : in Item) return openGL.Site
is
begin
return Self.Site;
end Site;
procedure Site_is (Self : in out Item; Now : in openGL.Site)
is
begin
Self.Site := Now;
end Site_is;
function Color (Self : in Item) return openGL.Color
is
begin
return Self.Color;
end Color;
function Attenuation (Self : in Item) return Real
is
begin
return Self.Attenuation;
end Attenuation;
function ambient_Coefficient (Self : in Item) return Real
is
begin
return Self.ambient_Coefficient;
end ambient_Coefficient;
function cone_Angle (Self : in Item) return Degrees
is
begin
return Self.cone_Angle;
end cone_Angle;
function cone_Direction (Self : in Item) return Vector_3
is
begin
return Self.cone_Direction;
end cone_Direction;
procedure Color_is (Self : in out Item; Now : in openGL.Color)
is
begin
Self.Color := Now;
end Color_is;
procedure Attenuation_is (Self : in out Item; Now : in Real)
is
begin
Self.Attenuation := Now;
end Attenuation_is;
procedure ambient_Coefficient_is (Self : in out Item; Now : in Real)
is
begin
Self.ambient_Coefficient := Now;
end ambient_Coefficient_is;
procedure cone_Angle_is (Self : in out Item; Now : in Degrees)
is
begin
Self.cone_Angle := Now;
end cone_Angle_is;
procedure cone_Direction_is (Self : in out Item; Now : in Vector_3)
is
begin
Self.cone_Direction := Now;
end cone_Direction_is;
end openGL.Light;
|
------------------------------------------------------------------------------
-- --
-- GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS --
-- --
-- I N T E R F A C E S . C . P O S I X _ T I M E R S --
-- --
-- S p e c --
-- --
-- $Revision: 2 $ --
-- --
-- Copyright (c) 1991,1992,1993,1994, FSU, All Rights Reserved --
-- --
-- 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 Interfaces.C.POSIX_Error; use Interfaces.C.POSIX_Error;
-- Used for Return_Code
package Interfaces.C.POSIX_Timers is
type time_t is new long;
type Nanoseconds is new long;
subtype Fractional_Second is Nanoseconds range 0 .. 10#1#E9 - 1;
-- This is dependent on the stdtypes.h header file.
type timespec is record
tv_sec : time_t;
tv_nsec : Fractional_Second;
end record;
timespec_First : constant timespec :=
timespec' (time_t'First, Fractional_Second'First);
timespec_Last : constant timespec :=
timespec' (time_t'Last, Fractional_Second'Last);
timespec_Zero : constant timespec :=
timespec' (time_t'First, Fractional_Second'First);
timespec_Unit : constant timespec :=
timespec' (time_t'First, Fractional_Second'First + 1);
-- This is dependent on the POSIX.4 implementation; the draft standard
-- only says that fields of these names and types (with Integer for long)
-- will be in the record. There may be other fields, and these do not
-- have to be in the indicated position. This should really be done by
-- getting the sizes and offsets using get_POSIX_Constants and building
-- the record to match using representation clauses.
-- temporarily, should really only be for 1???
type clock_id_t is private;
CLOCK_REALTIME : constant clock_id_t;
procedure clock_gettime
(ID : clock_id_t;
CT : out timespec;
Result : out Return_Code);
private
type clock_id_t is new long;
-- This clock_id_t is defined as an long in POSIX
CLOCK_REALTIME : constant clock_id_t := 0;
-- We currently implement only Realtime clock.
end Interfaces.C.POSIX_Timers;
|
-- Copyright (c) 2015-2017 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Ada.Wide_Wide_Text_IO;
with Ada.Characters.Wide_Wide_Latin_1;
with Ada_Pretty;
with League.Strings;
with Anagram.Grammars.LR;
with Anagram.Grammars.LR_Tables;
procedure Gen.Write_Parser_Data
(Plain : Anagram.Grammars.Grammar;
Table : Anagram.Grammars.LR_Tables.Table)
is
function "+" (Text : Wide_Wide_String)
return League.Strings.Universal_String
renames League.Strings.To_Universal_String;
function AD_Init return Ada_Pretty.Node_Access;
function SD_Init return Ada_Pretty.Node_Access;
function CD_Init return Ada_Pretty.Node_Access;
function NT_Init return Ada_Pretty.Node_Access;
function Name_Case return Ada_Pretty.Node_Access;
function To_Kind
(Index : Anagram.Grammars.Non_Terminal_Index) return Natural;
F : aliased Ada_Pretty.Factory;
LF : constant Wide_Wide_Character := Ada.Characters.Wide_Wide_Latin_1.LF;
-------------
-- AD_Init --
-------------
function AD_Init return Ada_Pretty.Node_Access is
use Anagram.Grammars.LR_Tables;
List : Ada_Pretty.Node_Access;
List_2 : Ada_Pretty.Node_Access;
begin
for State in 1 .. Last_State (Table) loop
for Term in 0 .. Plain.Last_Terminal loop
declare
Item : Ada_Pretty.Node_Access;
S : constant Anagram.Grammars.LR.State_Count :=
Shift (Table, State, Term);
R : constant Reduce_Iterator := Reduce (Table, State, Term);
begin
if Term in 0 and Finish (Table, State) then
Item := F.New_Name (+"F");
elsif S not in 0 then
Item := F.New_Parentheses
(F.New_List
((F.New_Component_Association
(Value => F.New_Name (+"S")),
F.New_Component_Association
(Value => F.New_Literal (Natural (S))))));
elsif not Is_Empty (R) then
Item := F.New_Parentheses
(F.New_List
((F.New_Component_Association
(Value => F.New_Name (+"R")),
F.New_Component_Association
(Value => F.New_Literal
(Natural (Production (R)))))));
else
Item := F.New_Name (+"E");
end if;
List_2 := F.New_List
(List_2, F.New_Component_Association (Value => Item));
end;
end loop;
for NT in 1 .. Plain.Last_Non_Terminal loop
declare
Item : Ada_Pretty.Node_Access;
S : constant Anagram.Grammars.LR.State_Count :=
Shift (Table, State, NT);
R : constant Reduce_Iterator := Reduce (Table, State, NT);
begin
if S not in 0 then
Item := F.New_Parentheses
(F.New_List
((F.New_Component_Association
(Value => F.New_Name (+"S")),
F.New_Component_Association
(Value => F.New_Literal (Natural (S))))));
elsif not Is_Empty (R) then
Item := F.New_Parentheses
(F.New_List
((F.New_Component_Association
(Value => F.New_Name (+"R")),
F.New_Component_Association
(Value => F.New_Literal
(Natural (Production (R)))))));
else
Item := F.New_Name (+"E");
end if;
List_2 := F.New_List
(List_2, F.New_Component_Association (Value => Item));
end;
end loop;
List := F.New_List
(List,
F.New_Component_Association
(Choices => F.New_Literal (Natural (State)),
Value => F.New_Parentheses (List_2)));
List_2 := null;
end loop;
return F.New_Parentheses (List);
end AD_Init;
-------------
-- CD_Init --
-------------
function CD_Init return Ada_Pretty.Node_Access is
use type Anagram.Grammars.Part_Count;
List : Ada_Pretty.Node_Access;
begin
for Prod of Plain.Production loop
List := F.New_List
(List,
F.New_Component_Association
(Choices => F.New_Literal (Natural (Prod.Index)),
Value => F.New_Literal
(Natural (Prod.Last - Prod.First + 1))));
end loop;
return F.New_Parentheses (List);
end CD_Init;
---------------
-- Name_Case --
---------------
function Name_Case return Ada_Pretty.Node_Access is
List : Ada_Pretty.Node_Access := F.New_Case_Path
(Choice => F.New_Literal (0),
List => F.New_Return (F.New_String_Literal (+"EOF")));
begin
for Term in 1 .. Plain.Last_Terminal loop
List := F.New_List
(List,
F.New_Case_Path
(Choice => F.New_Literal (Natural (Term)),
List => F.New_Return
(F.New_String_Literal (Plain.Terminal (Term).Image))));
end loop;
for NT in 1 .. Plain.Last_Non_Terminal loop
List := F.New_List
(List,
F.New_Case_Path
(Choice => F.New_Literal (To_Kind (NT)),
List => F.New_Return
(F.New_String_Literal (Plain.Non_Terminal (NT).Name))));
end loop;
List := F.New_List
(List,
F.New_Case_Path
(Choice => F.New_Name (+"others"),
List => F.New_Return (F.New_String_Literal (+"unknown"))));
return List;
end Name_Case;
-------------
-- NT_Init --
-------------
function NT_Init return Ada_Pretty.Node_Access is
List : Ada_Pretty.Node_Access;
begin
for NT of Plain.Non_Terminal loop
List := F.New_List
(List,
F.New_Component_Association
(Choices => F.New_List
(F.New_Literal (Natural (NT.First)),
F.New_Infix (+"..", F.New_Literal (Natural (NT.Last)))),
Value => F.New_Literal (To_Kind (NT.Index))));
end loop;
return F.New_Parentheses (List);
end NT_Init;
-------------
-- SD_Init --
-------------
function SD_Init return Ada_Pretty.Node_Access is
use Anagram.Grammars.LR_Tables;
List : Ada_Pretty.Node_Access;
List_2 : Ada_Pretty.Node_Access;
begin
for State in 1 .. Last_State (Table) loop
for NT in 1 .. Plain.Last_Non_Terminal loop
declare
S : constant Anagram.Grammars.LR.State_Count :=
Shift (Table, State, NT);
begin
List_2 := F.New_List
(List_2,
F.New_Component_Association
(Choices => F.New_Literal (To_Kind (NT)),
Value => F.New_Literal (Natural (S))));
end;
end loop;
List := F.New_List
(List,
F.New_Component_Association
(Choices => F.New_Literal (Natural (State)),
Value => F.New_Parentheses (List_2)));
List_2 := null;
end loop;
return F.New_Parentheses (List);
end SD_Init;
-------------
-- To_Kind --
-------------
function To_Kind
(Index : Anagram.Grammars.Non_Terminal_Index) return Natural is
begin
return Positive (Plain.Last_Terminal) + Positive (Index);
end To_Kind;
Clause : constant Ada_Pretty.Node_Access := F.New_With
(F.New_Selected_Name (+"Incr.Nodes.Joints"));
Name : constant Ada_Pretty.Node_Access :=
F.New_Selected_Name (+"Incr.Ada_Parser_Data");
Rename_List : constant Ada_Pretty.Node_Access :=
F.New_List
((F.New_Variable
(Name => F.New_Name (+"S"),
Type_Definition => F.New_Selected_Name (+"P.Action_Kinds"),
Initialization => F.New_Selected_Name (+"P.Shift"),
Is_Constant => True),
F.New_Variable
(Name => F.New_Name (+"R"),
Type_Definition => F.New_Selected_Name (+"P.Action_Kinds"),
Initialization => F.New_Selected_Name (+"P.Reduce"),
Is_Constant => True),
F.New_Variable
(Name => F.New_Name (+"E"),
Type_Definition => F.New_Selected_Name (+"P.Action"),
Initialization => F.New_Parentheses
(F.New_Component_Association
(Choices => F.New_Name (+"Kind"),
Value => F.New_Selected_Name (+"P.Error"))),
Is_Constant => True),
F.New_Variable
(Name => F.New_Name (+"F"),
Type_Definition => F.New_Selected_Name (+"P.Action"),
Initialization => F.New_Parentheses
(F.New_Component_Association
(Choices => F.New_Name (+"Kind"),
Value => F.New_Selected_Name (+"P.Finish"))),
Is_Constant => True)));
Action_Data : constant Ada_Pretty.Node_Access :=
F.New_Variable
(Name => F.New_Name (+"Action_Data"),
Type_Definition => F.New_Selected_Name (+"P.Action_Table"),
Initialization => AD_Init,
Is_Constant => True,
Is_Aliased => True);
State_Data : constant Ada_Pretty.Node_Access :=
F.New_Variable
(Name => F.New_Name (+"State_Data"),
Type_Definition => F.New_Selected_Name (+"P.State_Table"),
Initialization => SD_Init,
Is_Constant => True,
Is_Aliased => True);
Count_Data : constant Ada_Pretty.Node_Access :=
F.New_Variable
(Name => F.New_Name (+"Count_Data"),
Type_Definition => F.New_Selected_Name (+"P.Parts_Count_Table"),
Initialization => CD_Init,
Is_Constant => True,
Is_Aliased => True);
NT : constant Ada_Pretty.Node_Access :=
F.New_Variable
(Name => F.New_Name (+"NT"),
Type_Definition => F.New_Name (+"Node_Kind_Array"),
Initialization => NT_Init,
Is_Constant => True);
Self : constant Ada_Pretty.Node_Access :=
F.New_Parameter
(Name => F.New_Name (+"Self"),
Type_Definition => F.New_Name (+"Provider"));
Self_Unreferenced : constant Ada_Pretty.Node_Access :=
F.New_Pragma
(Name => F.New_Name (+"Unreferenced"),
Arguments => F.New_Name (+"Self"));
Actions : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Body
(F.New_Subprogram_Specification
(Is_Overriding => True,
Name => F.New_Name (+"Actions"),
Parameters => Self,
Result => F.New_Selected_Name (+"P.Action_Table_Access")),
Declarations => Self_Unreferenced,
Statements => F.New_Return (F.New_Name (+"Action_Data'Access")));
Kind_Image : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Body
(F.New_Subprogram_Specification
(Is_Overriding => True,
Name => F.New_Name (+"Kind_Image"),
Parameters => F.New_List
(Self,
F.New_Parameter
(Name => F.New_Name (+"Kind"),
Type_Definition =>
F.New_Selected_Name (+"Incr.Nodes.Node_Kind"))),
Result => F.New_Name
(+"Wide_Wide_String")),
Declarations => Self_Unreferenced,
Statements => F.New_Case
(Expression => F.New_Name (+"Kind"),
List => Name_Case));
Part_Counts : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Body
(F.New_Subprogram_Specification
(Is_Overriding => True,
Name => F.New_Name (+"Part_Counts"),
Parameters => Self,
Result => F.New_Selected_Name
(+"P.Parts_Count_Table_Access")),
Declarations => Self_Unreferenced,
Statements => F.New_Return (F.New_Name (+"Count_Data'Access")));
States : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Body
(F.New_Subprogram_Specification
(Is_Overriding => True,
Name => F.New_Name (+"States"),
Parameters => Self,
Result => F.New_Selected_Name
(+"P.State_Table_Access")),
Declarations => Self_Unreferenced,
Statements => F.New_Return (F.New_Name (+"State_Data'Access")));
Joint_Access : constant Ada_Pretty.Node_Access := F.New_Selected_Name
(+"Incr.Nodes.Joints.Joint_Access");
Statements : constant Ada_Pretty.Node_Access :=
F.New_List
((
F.New_Assignment
(Left => F.New_Name (+"Kind"),
Right => F.New_Apply
(Prefix => F.New_Name (+"NT"),
Arguments => F.New_Name (+"Prod"))),
F.New_Assignment
(Left => F.New_Name (+"Result"),
Right => F.New_Apply
(Prefix => F.New_Selected_Name
(+"new Incr.Nodes.Joints.Joint"),
Arguments => F.New_List
(F.New_Argument_Association
(F.New_Selected_Name (+"Self.Document")),
F.New_Argument_Association
(F.New_Name (+"Children'Length"))))),
F.New_Statement
(F.New_Apply
(Prefix => F.New_Selected_Name
(+"Incr.Nodes.Joints.Constructors.Initialize"),
Arguments => F.New_List
((F.New_Argument_Association
(F.New_Selected_Name (+"Result.all")),
F.New_Argument_Association
(F.New_Selected_Name (+"Kind")),
F.New_Argument_Association
(F.New_Selected_Name (+"Children")))))),
F.New_Assignment
(Left => F.New_Name (+"Node"),
Right => F.New_Apply
(Prefix => F.New_Selected_Name (+"Incr.Nodes.Node_Access"),
Arguments => F.New_Name (+"Result")))
));
Create_Node : constant Ada_Pretty.Node_Access :=
F.New_Subprogram_Body
(F.New_Subprogram_Specification
(Is_Overriding => True,
Name => F.New_Name (+"Create_Node"),
Parameters => F.New_List
((F.New_Parameter
(Name => F.New_Name (+"Self"),
Type_Definition => F.New_Name (+"Node_Factory"),
Is_In => True,
Is_Out => True,
Is_Aliased => True),
F.New_Parameter
(Name => F.New_Name (+"Prod"),
Type_Definition => F.New_Selected_Name
(+"P.Production_Index")),
F.New_Parameter
(Name => F.New_Name (+"Children"),
Type_Definition => F.New_Selected_Name
(+"Incr.Nodes.Node_Array")),
F.New_Parameter
(Name => F.New_Name (+"Node"),
Type_Definition => F.New_Selected_Name
(+"Incr.Nodes.Node_Access"),
Is_Out => True),
F.New_Parameter
(Name => F.New_Name (+"Kind"),
Type_Definition => F.New_Selected_Name
(+"Incr.Nodes.Node_Kind"),
Is_Out => True)))),
Declarations => F.New_Variable
(Name => F.New_Name (+"Result"),
Type_Definition => Joint_Access),
Statements => Statements);
Tables : constant Ada_Pretty.Node_Access :=
F.New_List
((F.New_Pragma (F.New_Name (+"Page")),
Action_Data, State_Data, Count_Data, NT,
Actions, Kind_Image, Part_Counts, States, Create_Node));
List : constant Ada_Pretty.Node_Access := F.New_List (Rename_List, Tables);
Root : constant Ada_Pretty.Node_Access :=
F.New_Package_Body (Name, List);
Unit : constant Ada_Pretty.Node_Access :=
F.New_Compilation_Unit (Root, Clause);
begin
Ada.Wide_Wide_Text_IO.Put_Line
(F.To_Text (Unit).Join (LF).To_Wide_Wide_String);
end Gen.Write_Parser_Data;
|
package body System.Wide_Startup is
pragma Suppress (All_Checks);
-- main generated by gnatbind
function main (argc : Integer; argv : Address; envp : Address)
return Integer
with Import, Convention => C;
-- implementation
function wmain (argc : Integer; argv : Address; envp : Address)
return Integer is
begin
wargc := argc;
wargv := argv;
wenvp := envp;
return main (0, Null_Address, Null_Address);
end wmain;
end System.Wide_Startup;
|
package FLTK.Widgets.Groups.Wizards is
type Wizard is new Group with private;
type Wizard_Reference (Data : not null access Wizard'Class) is limited null record
with Implicit_Dereference => Data;
package Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Wizard;
end Forge;
procedure Next
(This : in out Wizard);
procedure Prev
(This : in out Wizard);
function Get_Visible
(This : in Wizard)
return access Widget'Class;
procedure Set_Visible
(This : in out Wizard;
Item : in out Widget'Class);
procedure Draw
(This : in out Wizard);
function Handle
(This : in out Wizard;
Event : in Event_Kind)
return Event_Outcome;
private
type Wizard is new Group with null record;
overriding procedure Finalize
(This : in out Wizard);
pragma Inline (Next);
pragma Inline (Prev);
pragma Inline (Get_Visible);
pragma Inline (Set_Visible);
pragma Inline (Draw);
pragma Inline (Handle);
end FLTK.Widgets.Groups.Wizards;
|
package body System.Startup is
pragma Suppress (All_Checks);
-- weak reference for System.Unwind.Mapping
procedure Install_Exception_Handler (SEH : Address)
with Import, -- weak linking
Convention => Ada,
External_Name => "__drake_install_exception_handler";
pragma Weak_External (Install_Exception_Handler);
-- implementation
procedure Initialize (SEH : Address) is
begin
if Install_Exception_Handler'Address /= Null_Address then
Install_Exception_Handler (SEH);
end if;
end Initialize;
end System.Startup;
|
declare
type Int_Ptr is access all Integer;
Ref : Int_Ptr;
Var : aliased Integer := 3;
Val : Integer := Var;
begin
Ref := Var'Access; -- "Ref := Val'Access;" would be a syntax error
|
with Numworks.Display;
with Numworks.Backlight;
with HAL; use HAL;
with Bitmap_Color_Conversion;
with HAL.Bitmap; use HAL.Bitmap;
package body Render is
Buffer : aliased GESTE.Output_Buffer :=
(1 .. Numworks.Display.Width * 10 => 0);
Screen_Pt : GESTE.Point := (0, 0);
---------
-- Put --
---------
procedure Push_Pixels (Buffer : GESTE.Output_Buffer) is
Temp : UInt16_Array (Buffer'Range)
with Address => Buffer'Address;
begin
Numworks.Display.Push_Pixels (Temp, DMA_Theshold => 5000);
Numworks.Display.Wait_End_Of_Push;
end Push_Pixels;
----------------------
-- Set_Drawing_Area --
----------------------
procedure Set_Drawing_Area (Area : GESTE.Rect) is
begin
Numworks.Display.Set_Drawing_Area (((Area.TL.X - Screen_Pt.X,
Area.TL.Y - Screen_Pt.Y),
Area.BR.X - Area.TL.X + 1,
Area.BR.Y - Area.TL.Y + 1));
Numworks.Display.Start_Pixel_Write;
end Set_Drawing_Area;
-----------------------
-- Set_Screen_Offset --
-----------------------
procedure Set_Screen_Offset (Pt : GESTE.Point) is
begin
Screen_Pt := Pt;
end Set_Screen_Offset;
----------------
-- Render_All --
----------------
procedure Render_All (Background : GESTE_Config.Output_Color) is
begin
GESTE.Render_All
((Screen_Pt,
(Screen_Pt.X + Numworks.Display.Width - 1,
Screen_Pt.Y + Numworks.Display.Height - 1)),
Background,
Buffer,
Push_Pixels'Access,
Set_Drawing_Area'Access);
end Render_All;
------------------
-- Render_Dirty --
------------------
procedure Render_Dirty (Background : GESTE_Config.Output_Color) is
begin
GESTE.Render_Dirty
((Screen_Pt,
(Screen_Pt.X + Numworks.Display.Width - 1,
Screen_Pt.Y + Numworks.Display.Height - 1)),
Background,
Buffer,
Push_Pixels'Access,
Set_Drawing_Area'Access);
end Render_Dirty;
---------------
-- Dark_Cyan --
---------------
function Dark_Cyan return GESTE_Config.Output_Color
is (GESTE_Config.Output_Color (Bitmap_Color_Conversion.Bitmap_Color_To_Word
(RGB_565, HAL.Bitmap.Dark_Cyan)));
-----------
-- Black --
-----------
function Black return GESTE_Config.Output_Color
is (0);
begin
Numworks.Backlight.Set_Level (16);
end Render;
|
-- WORDS, a Latin dictionary, by Colonel William Whitaker (USAF, Retired)
--
-- Copyright William A. Whitaker (1936–2010)
--
-- This is a free program, which means it is proper to copy it and pass
-- it on to your friends. Consider it a developmental item for which
-- there is no charge. However, just for form, it is Copyrighted
-- (c). Permission is hereby freely given for any and all use of program
-- and data. You can sell it as your own, but at least tell me.
--
-- This version is distributed without obligation, but the developer
-- would appreciate comments and suggestions.
--
-- All parts of the WORDS system, source code and data files, are made freely
-- available to anyone who wishes to use them, for whatever purpose.
separate (Latin_Utils.Dictionary_Package)
package body Kind_Entry_IO is
---------------------------------------------------------------------------
use type Ada.Text_IO.Positive_Count;
---------------------------------------------------------------------------
procedure Get
(File : in Ada.Text_IO.File_Type;
POFS : in Part_Of_Speech_Type;
Item : out Kind_Entry
)
is
--------------------------------------------------------------------------
-- Helper variables
Noun_Kind : Noun_Kind_Type;
Pronoun_Kind : Pronoun_Kind_Type;
Propack_Kind : Pronoun_Kind_Type;
Verb_Kind : Verb_Kind_Type;
Vpar_Kind : Verb_Kind_Type;
Supine_Kind : Verb_Kind_Type;
Numeral_Value : Numeral_Value_Type;
--------------------------------------------------------------------------
-- Small helper procedure
procedure Set_Col (File : Ada.Text_IO.File_Type) is
begin
Ada.Text_IO.Set_Col
(File,
Ada.Text_IO.Col (File) +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
end Set_Col;
--------------------------------------------------------------------------
begin
case POFS is
when N =>
Noun_Kind_Type_IO.Get (File, Noun_Kind);
Item := (N, Noun_Kind);
when Pron =>
Pronoun_Kind_Type_IO.Get (File, Pronoun_Kind);
Item := (Pron, Pronoun_Kind);
when Pack =>
Pronoun_Kind_Type_IO.Get (File, Propack_Kind);
Item := (Pack, Propack_Kind);
when Adj =>
Set_Col (File);
Item := (Pofs => Adj);
when Num =>
Inflections_Package.Integer_IO.Get (File, Numeral_Value);
Item := (Num, Numeral_Value);
when Adv =>
Set_Col (File);
Item := (Pofs => Adv);
when V =>
Verb_Kind_Type_IO.Get (File, Verb_Kind);
Item := (V, Verb_Kind);
when Vpar =>
Verb_Kind_Type_IO.Get (File, Vpar_Kind);
Item := (Vpar, Vpar_Kind);
when Supine =>
Verb_Kind_Type_IO.Get (File, Supine_Kind);
Item := (Supine, Supine_Kind);
when Prep =>
Set_Col (File);
Item := (Pofs => Prep);
when Conj =>
Set_Col (File);
Item := (Pofs => Conj);
when Interj =>
Set_Col (File);
Item := (Pofs => Interj);
when Tackon =>
Set_Col (File);
Item := (Pofs => Tackon);
when Prefix =>
Set_Col (File);
Item := (Pofs => Prefix);
when Suffix =>
Set_Col (File);
Item := (Pofs => Suffix);
when X =>
Set_Col (File);
Item := (Pofs => X);
end case;
end Get;
---------------------------------------------------------------------------
procedure Get (POFS : in Part_Of_Speech_Type; Item : out Kind_Entry)
is
--------------------------------------------------------------------------
-- Helper variables
Noun_Kind : Noun_Kind_Type;
Pronoun_Kind : Pronoun_Kind_Type;
Propack_Kind : Pronoun_Kind_Type;
Verb_Kind : Verb_Kind_Type;
Vpar_Kind : Verb_Kind_Type;
Supine_Kind : Verb_Kind_Type;
Numeral_Value : Numeral_Value_Type;
--------------------------------------------------------------------------
begin
case POFS is
when N =>
Noun_Kind_Type_IO.Get (Noun_Kind);
Item := (N, Noun_Kind);
when Pron =>
Pronoun_Kind_Type_IO.Get (Pronoun_Kind);
Item := (Pron, Pronoun_Kind);
when Pack =>
Pronoun_Kind_Type_IO.Get (Propack_Kind);
Item := (Pack, Propack_Kind);
when Adj =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => Adj);
when Num =>
Inflections_Package.Integer_IO.Get (Numeral_Value);
Item := (Num, Numeral_Value);
when Adv =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => Adv);
when V =>
Verb_Kind_Type_IO.Get (Verb_Kind);
Item := (V, Verb_Kind);
when Vpar =>
Verb_Kind_Type_IO.Get (Vpar_Kind);
Item := (Vpar, Vpar_Kind);
when Supine =>
Verb_Kind_Type_IO.Get (Supine_Kind);
Item := (Supine, Supine_Kind);
when Prep =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => Prep);
when Conj =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => Conj);
when Interj =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => Interj);
when Tackon =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => Tackon);
when Prefix =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => Prefix);
when Suffix =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => Suffix);
when X =>
Ada.Text_IO.Set_Col
(Ada.Text_IO.Col +
Ada.Text_IO.Positive_Count (Kind_Entry_IO.Default_Width)
);
Item := (Pofs => X);
end case;
end Get;
---------------------------------------------------------------------------
procedure Put
(File : in Ada.Text_IO.File_Type;
POFS : in Part_Of_Speech_Type;
Item : in Kind_Entry
)
is
pragma Unreferenced (POFS);
-- Used for computing bounds of substring for filling
Ending_Col : constant Positive :=
Kind_Entry_IO.Default_Width + Positive (Ada.Text_IO.Col (File)) - 1;
begin
case Item.Pofs is
when N =>
Noun_Kind_Type_IO.Put (File, Item.N_Kind);
when Pron =>
Pronoun_Kind_Type_IO.Put (File, Item.Pron_Kind);
when Pack =>
Pronoun_Kind_Type_IO.Put (File, Item.Pack_Kind);
when Num =>
Inflections_Package.Integer_IO.Put
(File, Item.Num_Value, Numeral_Value_Type_IO_Default_Width);
when V =>
Verb_Kind_Type_IO.Put (File, Item.V_Kind);
when Vpar =>
Verb_Kind_Type_IO.Put (File, Item.Vpar_Kind);
when Supine =>
Verb_Kind_Type_IO.Put (File, Item.Supine_Kind);
when X | Adj | Adv =>
null;
when Prep .. Suffix =>
null;
end case;
Ada.Text_IO.Put
(File,
String'(Integer (Ada.Text_IO.Col (File)) .. Ending_Col => ' ')
);
end Put;
---------------------------------------------------------------------------
procedure Put (POFS : in Part_Of_Speech_Type; Item : in Kind_Entry)
is
pragma Unreferenced (POFS);
-- Used for computing bounds of substring for filling
Ending_Col : constant Positive :=
Kind_Entry_IO.Default_Width + Positive (Ada.Text_IO.Col) - 1;
begin
case Item.Pofs is
when N =>
Noun_Kind_Type_IO.Put (Item.N_Kind);
when Pron =>
Pronoun_Kind_Type_IO.Put (Item.Pron_Kind);
when Pack =>
Pronoun_Kind_Type_IO.Put (Item.Pack_Kind);
when Num =>
Inflections_Package.Integer_IO.Put
(Item.Num_Value, Numeral_Value_Type_IO_Default_Width);
when V =>
Verb_Kind_Type_IO.Put (Item.V_Kind);
when Vpar =>
Verb_Kind_Type_IO.Put (Item.Vpar_Kind);
when Supine =>
Verb_Kind_Type_IO.Put (Item.Supine_Kind);
when X | Adj | Adv =>
null;
when Prep .. Suffix =>
null;
end case;
Ada.Text_IO.Put (String'(Integer (Ada.Text_IO.Col) .. Ending_Col => ' '));
end Put;
---------------------------------------------------------------------------
procedure Get
(Source : in String;
POFS : in Part_Of_Speech_Type;
Target : out Kind_Entry;
Last : out Integer
)
is
--------------------------------------------------------------------------
-- Helper variables
Noun_Kind : Noun_Kind_Type;
Pronoun_Kind : Pronoun_Kind_Type;
Propack_Kind : Pronoun_Kind_Type;
Verb_Kind : Verb_Kind_Type;
Vpar_Kind : Verb_Kind_Type;
Supine_Kind : Verb_Kind_Type;
Numeral_Value : Numeral_Value_Type;
--------------------------------------------------------------------------
-- Used to get lower bound of substring
Low : constant Integer := Source'First - 1;
begin
Last := Low; -- In case it is not set later
case POFS is
when N =>
Noun_Kind_Type_IO.Get
(Source (Low + 1 .. Source'Last), Noun_Kind, Last);
Target := (N, Noun_Kind);
when Pron =>
Pronoun_Kind_Type_IO.Get
(Source (Low + 1 .. Source'Last), Pronoun_Kind, Last);
Target := (Pron, Pronoun_Kind);
when Pack =>
Pronoun_Kind_Type_IO.Get
(Source (Low + 1 .. Source'Last), Propack_Kind, Last);
Target := (Pack, Propack_Kind);
when Adj =>
Target := (Pofs => Adj);
when Num =>
Inflections_Package.Integer_IO.Get
(Source (Low + 1 .. Source'Last), Numeral_Value, Last);
Target := (Num, Numeral_Value);
when Adv =>
Target := (Pofs => Adv);
when V =>
Verb_Kind_Type_IO.Get
(Source (Low + 1 .. Source'Last), Verb_Kind, Last);
Target := (V, Verb_Kind);
when Vpar =>
Verb_Kind_Type_IO.Get
(Source (Low + 1 .. Source'Last), Vpar_Kind, Last);
Target := (Vpar, Vpar_Kind);
when Supine =>
Verb_Kind_Type_IO.Get
(Source (Low + 1 .. Source'Last), Supine_Kind, Last);
Target := (Supine, Supine_Kind);
when Prep =>
Target := (Pofs => Prep);
when Conj =>
Target := (Pofs => Conj);
when Interj =>
Target := (Pofs => Interj);
when Tackon =>
Target := (Pofs => Tackon);
when Prefix =>
Target := (Pofs => Prefix);
when Suffix =>
Target := (Pofs => Suffix);
when X =>
Target := (Pofs => X);
end case;
end Get;
---------------------------------------------------------------------------
procedure Put
(Target : out String;
POFS : in Part_Of_Speech_Type;
Item : in Kind_Entry
)
is
pragma Unreferenced (POFS);
-- Used to get bounds of substrings
Low : constant Integer := Target'First - 1;
High : Integer := 0;
begin
-- Put Kind_Entry
case Item.Pofs is
when N =>
High := Low + Noun_Kind_Type_IO.Default_Width;
Noun_Kind_Type_IO.Put (Target (Low + 1 .. High), Item.N_Kind);
when Pron =>
High := Low + Pronoun_Kind_Type_IO.Default_Width;
Pronoun_Kind_Type_IO.Put (Target (Low + 1 .. High), Item.Pron_Kind);
when Pack =>
High := Low + Pronoun_Kind_Type_IO.Default_Width;
Pronoun_Kind_Type_IO.Put (Target (Low + 1 .. High), Item.Pack_Kind);
when Num =>
High := Low + Numeral_Value_Type_IO_Default_Width;
Inflections_Package.Integer_IO.Put
(Target (Low + 1 .. High), Item.Num_Value);
when V =>
High := Low + Verb_Kind_Type_IO.Default_Width;
Verb_Kind_Type_IO.Put (Target (Low + 1 .. High), Item.V_Kind);
when Vpar =>
High := Low + Verb_Kind_Type_IO.Default_Width;
Verb_Kind_Type_IO.Put (Target (Low + 1 .. High), Item.Vpar_Kind);
when Supine =>
High := Low + Verb_Kind_Type_IO.Default_Width;
Verb_Kind_Type_IO.Put (Target (Low + 1 .. High), Item.Supine_Kind);
when X | Adj | Adv =>
null;
when Prep .. Suffix =>
null;
end case;
-- Fill remainder of string
Target (High + 1 .. Target'Last) := (others => ' ');
end Put;
---------------------------------------------------------------------------
end Kind_Entry_IO;
|
pragma License (Unrestricted);
-- implementation unit required by compiler
package System.Val_Dec is
pragma Pure;
-- required for Fixed'Value by compiler (s-valdec.ads)
function Value_Decimal (Str : String; Scale : Integer) return Integer;
end System.Val_Dec;
|
With
NSO.Types;
-- Section_to_Vector takes a section by name, and returns
-- the children by value, converted to string if necessary.
Function INI.Section_to_Vector( Object : in Instance;
Section: in String:= ""
) return NSO.Types.String_Vector.Vector;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from ATSAMD51G19A.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package SAM_SVD.TRNG is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Control A
type TRNG_CTRLA_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit := 16#0#;
-- Enable
ENABLE : Boolean := False;
-- unspecified
Reserved_2_5 : HAL.UInt4 := 16#0#;
-- Run in Standby
RUNSTDBY : Boolean := False;
-- unspecified
Reserved_7_7 : HAL.Bit := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for TRNG_CTRLA_Register use record
Reserved_0_0 at 0 range 0 .. 0;
ENABLE at 0 range 1 .. 1;
Reserved_2_5 at 0 range 2 .. 5;
RUNSTDBY at 0 range 6 .. 6;
Reserved_7_7 at 0 range 7 .. 7;
end record;
-- Event Control
type TRNG_EVCTRL_Register is record
-- Data Ready Event Output
DATARDYEO : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for TRNG_EVCTRL_Register use record
DATARDYEO at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt Enable Clear
type TRNG_INTENCLR_Register is record
-- Data Ready Interrupt Enable
DATARDY : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for TRNG_INTENCLR_Register use record
DATARDY at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt Enable Set
type TRNG_INTENSET_Register is record
-- Data Ready Interrupt Enable
DATARDY : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for TRNG_INTENSET_Register use record
DATARDY at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-- Interrupt Flag Status and Clear
type TRNG_INTFLAG_Register is record
-- Data Ready Interrupt Flag
DATARDY : Boolean := False;
-- unspecified
Reserved_1_7 : HAL.UInt7 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 8,
Bit_Order => System.Low_Order_First;
for TRNG_INTFLAG_Register use record
DATARDY at 0 range 0 .. 0;
Reserved_1_7 at 0 range 1 .. 7;
end record;
-----------------
-- Peripherals --
-----------------
-- True Random Generator
type TRNG_Peripheral is record
-- Control A
CTRLA : aliased TRNG_CTRLA_Register;
-- Event Control
EVCTRL : aliased TRNG_EVCTRL_Register;
-- Interrupt Enable Clear
INTENCLR : aliased TRNG_INTENCLR_Register;
-- Interrupt Enable Set
INTENSET : aliased TRNG_INTENSET_Register;
-- Interrupt Flag Status and Clear
INTFLAG : aliased TRNG_INTFLAG_Register;
-- Output Data
DATA : aliased HAL.UInt32;
end record
with Volatile;
for TRNG_Peripheral use record
CTRLA at 16#0# range 0 .. 7;
EVCTRL at 16#4# range 0 .. 7;
INTENCLR at 16#8# range 0 .. 7;
INTENSET at 16#9# range 0 .. 7;
INTFLAG at 16#A# range 0 .. 7;
DATA at 16#20# range 0 .. 31;
end record;
-- True Random Generator
TRNG_Periph : aliased TRNG_Peripheral
with Import, Address => TRNG_Base;
end SAM_SVD.TRNG;
|
-- MIT License
--
-- Copyright (c) 2020 Max Reznik
--
-- 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.Containers.Ordered_Sets;
package body Compiler.Enum_Descriptors is
F : Ada_Pretty.Factory renames Compiler.Context.Factory;
function "+" (Text : Wide_Wide_String)
return League.Strings.Universal_String
renames League.Strings.To_Universal_String;
function Type_Name
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto)
return League.Strings.Universal_String;
-- Return Ada type (simple) name
function Default
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto)
return League.Strings.Universal_String;
-- Return default value for given enum type as string
function Literal_Name
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto;
Index : Positive)
return League.Strings.Universal_String;
-- Return default value for given enum type as string
function Max_Value
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto) return Integer;
-- Maximum representation value
function Min_Value
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto) return Integer;
-- Minimum representation value
-------------
-- Default --
-------------
function Default
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto)
return League.Strings.Universal_String is
begin
return Literal_Name (Self, 1);
end Default;
-----------------
-- Get_Literal --
-----------------
function Get_Literal (Value : Integer) return Ada_Pretty.Node_Access is
Result : Ada_Pretty.Node_Access := F.New_Literal (abs Value);
begin
if Value < 0 then
Result := F.New_Infix (+"-", Result);
end if;
return Result;
end Get_Literal;
------------------
-- Literal_Name --
------------------
function Literal_Name
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto;
Index : Positive)
return League.Strings.Universal_String
is
use type League.Strings.Universal_String;
Name : constant League.Strings.Universal_String := Type_Name (Self);
Literal : League.Strings.Universal_String :=
Self.Value (Index).Name.Value;
begin
if Literal.To_Lowercase = Name.To_Lowercase then
Literal.Prepend ("PB_");
end if;
return Literal;
end Literal_Name;
---------------
-- Max_Value --
---------------
function Max_Value
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto) return Integer
is
Result : Integer := Integer (Self.Value (1).Number.Value);
Next : Integer;
begin
for J in 2 .. Self.Value.Length loop
Next := Integer (Self.Value (J).Number.Value);
Result := Integer'Max (Result, Next);
end loop;
return Result;
end Max_Value;
---------------
-- Min_Value --
---------------
function Min_Value
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto) return Integer
is
Result : Integer := Integer (Self.Value (1).Number.Value);
Next : Integer;
begin
for J in 2 .. Self.Value.Length loop
Next := Integer (Self.Value (J).Number.Value);
Result := Integer'Min (Result, Next);
end loop;
return Result;
end Min_Value;
--------------------------
-- Populate_Named_Types --
--------------------------
procedure Populate_Named_Types
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto;
PB_Prefix : League.Strings.Universal_String;
Ada_Package : League.Strings.Universal_String;
Map : in out Compiler.Context.Named_Type_Maps.Map)
is
Name : constant League.Strings.Universal_String := Type_Name (Self);
Key : League.Strings.Universal_String := PB_Prefix;
Value : constant Compiler.Context.Named_Type :=
(Is_Enumeration => True,
Ada_Type =>
(Package_Name => Ada_Package,
Type_Name => Name),
Enum =>
(Min => Min_Value (Self),
Max => Max_Value (Self),
Default => Default (Self)));
begin
Key.Append (".");
if Self.Name.Is_Set then
Key.Append (Self.Name.Value);
end if;
Map.Insert (Key, Value);
end Populate_Named_Types;
-----------------
-- Public_Spec --
-----------------
function Public_Spec
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto)
return Ada_Pretty.Node_Access
is
use type League.Strings.Universal_String;
type Enum is record
Value : Integer;
Name : League.Strings.Universal_String;
end record;
function Less (Left, Right : Enum) return Boolean;
function Less (Left, Right : Enum) return Boolean is
begin
return Left.Value < Right.Value
or else (Left.Value = Right.Value and then Left.Name < Right.Name);
end Less;
package Enum_Sets is new Ada.Containers.Ordered_Sets (Enum, Less);
Name : constant League.Strings.Universal_String := Type_Name (Self);
Result : Ada_Pretty.Node_Access;
Clause : Ada_Pretty.Node_Access;
Item : Ada_Pretty.Node_Access;
Aliases : Ada_Pretty.Node_Access;
Enums : Enum_Sets.Set;
Done : Compiler.Context.String_Sets.Set;
First : Boolean := True;
Prev : Enum;
begin
for J in 1 .. Self.Value.Length loop
Enums.Include
((Value => Integer (Self.Value (J).Number.Value),
Name => Literal_Name (Self, J)));
end loop;
Prev := Enums.Last_Element;
for J of Enums loop
if Done.Contains (J.Name.To_Lowercase) then
null; -- Skip name that differs only in character case
elsif not First and Prev.Value = J.Value then
Done.Insert (J.Name.To_Lowercase);
Aliases := F.New_List
(Aliases,
F.New_Subprogram_Declaration
(Specification =>
F.New_Subprogram_Specification
(Name => F.New_Name (J.Name),
Result => F.New_Name (Name)),
Expression =>
F.New_Name (Prev.Name)));
else
Done.Insert (J.Name.To_Lowercase);
Item := F.New_Argument_Association (F.New_Name (J.Name));
Result := F.New_List (Result, Item);
Clause := F.New_List
(Clause,
F.New_Argument_Association
(Choice => F.New_Name (J.Name),
Value => Get_Literal (J.Value)));
end if;
Prev := J;
First := False;
end loop;
Result := F.New_Type
(Name => F.New_Name (Name),
Definition => F.New_Parentheses (Result));
Clause := F.New_Statement
(F.New_Apply
(F.New_Name ("for " & Name & " use"),
Clause));
Item := F.New_List
(Aliases,
F.New_Package_Instantiation
(Name => F.New_Name (Name & "_Vectors"),
Template => F.New_Selected_Name (+"PB_Support.Vectors"),
Actual_Part => F.New_Name (Name)));
Result := F.New_List ((Result, Clause, Item));
return Result;
end Public_Spec;
---------------
-- Type_Name --
---------------
function Type_Name
(Self : Google.Protobuf.Descriptor.Enum_Descriptor_Proto)
return League.Strings.Universal_String is
begin
if Self.Name.Is_Set then
return Compiler.Context.To_Ada_Name (Self.Name.Value);
else
return +"Enum";
end if;
end Type_Name;
end Compiler.Enum_Descriptors;
|
with Ada.Text_IO; use Ada.Text_IO;
with System.Storage_Elements; use System.Storage_Elements;
with BBqueue;
with System; use System;
procedure Main_Offsets
with SPARK_Mode
is
use type BBqueue.Result_Kind;
Buffer : Storage_Array (0 .. 34) := (others => 0);
Q : aliased BBqueue.Offsets_Only (Buffer'Length);
procedure Fill (WG : BBqueue.Write_Grant;
Val : Storage_Element)
with Pre => BBqueue.State (WG) = BBqueue.Valid
and then BBqueue.Valid_Slice (Q, BBqueue.Slice (WG));
procedure Print (G : BBqueue.Write_Grant);
procedure Print (G : BBqueue.Read_Grant);
procedure Print_Content (RG : BBqueue.Read_Grant)
with Pre => BBqueue.State (RG) = BBqueue.Valid
and then BBqueue.Valid_Slice (Q, BBqueue.Slice (RG));
procedure Print_Buffer;
----------
-- Fill --
----------
procedure Fill (WG : BBqueue.Write_Grant;
Val : Storage_Element)
is
S : constant BBqueue.Slice_Rec := BBqueue.Slice (WG);
begin
Buffer (Buffer'First + S.From .. Buffer'First + S.To)
:= (others => Val);
end Fill;
-----------
-- Print --
-----------
procedure Print (G : BBqueue.Write_Grant) is
begin
Put ("Write Grant - " & BBqueue.State (G)'Img);
if BBqueue.State (G) = BBqueue.Valid then
Put_Line (" Size:" & BBqueue.Slice (G).Length'Img);
else
New_Line;
end if;
end Print;
-----------
-- Print --
-----------
procedure Print (G : BBqueue.Read_Grant) is
begin
Put ("Read Grant - " & BBqueue.State (G)'Img);
if BBqueue.State (G) = BBqueue.Valid then
Put_Line (" Size:" & BBqueue.Slice (G).Length'Img);
else
New_Line;
end if;
end Print;
-------------------
-- Print_Content --
-------------------
procedure Print_Content (RG : BBqueue.Read_Grant) is
S : constant BBqueue.Slice_Rec := BBqueue.Slice (RG);
begin
Put ("Print" & S.Length'Img & " bytes -> ");
for Elt of Buffer (Buffer'First + S.From .. Buffer'First + S.To) loop
Put (Elt'Img);
end loop;
New_Line;
end Print_Content;
------------------
-- Print_Buffer --
------------------
procedure Print_Buffer is
begin
Put ("Buffer => ");
for Elt of Buffer loop
Put (Elt'Img);
end loop;
New_Line;
end Print_Buffer;
WG : BBqueue.Write_Grant := BBqueue.Empty;
RG : BBqueue.Read_Grant := BBqueue.Empty;
V : Storage_Element := 1;
begin
for X in 1 .. 7 loop
Put_Line ("-- Loop" & X'Img & " --");
Print_Buffer;
BBqueue.Grant (Q, WG, 10);
if BBqueue.State (WG) /= BBqueue.Valid then
exit;
end if;
Put ("BBqueue.Grant (Q, 10) -> ");
Print (WG);
Print_Buffer;
Put_Line ("Fill (WG, " & V'Img & ")");
Fill (WG, V);
V := V + 1;
Print_Buffer;
BBqueue.Commit (Q, WG, 10);
Put ("BBqueue.Commit (WG, 10); ->");
Print (WG);
Print_Buffer;
BBqueue.Read (Q, RG);
if BBqueue.State (RG) /= BBqueue.Valid then
exit;
end if;
Put ("BBqueue.Read (Q); -> ");
Print (RG);
Print_Content (RG);
Print_Buffer;
BBqueue.Release (Q, RG);
Put ("BBqueue.Release (RG); -> ");
Print (RG);
Print_Buffer;
pragma Assert (BBqueue.State (WG) = BBqueue.Empty);
pragma Assert (BBqueue.State (RG) = BBqueue.Empty);
end loop;
end Main_Offsets;
|
with System;
package TM_Receiver is
task TM_Receiver_Task
with Priority => System.Default_Priority;
end TM_Receiver;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Elements.Type_Definitions;
with Program.Lexical_Elements;
with Program.Elements.Subtype_Indications;
with Program.Elements.Expressions;
with Program.Elements.Definitions;
package Program.Elements.Derived_Record_Extensions is
pragma Pure (Program.Elements.Derived_Record_Extensions);
type Derived_Record_Extension is
limited interface and Program.Elements.Type_Definitions.Type_Definition;
type Derived_Record_Extension_Access is
access all Derived_Record_Extension'Class with Storage_Size => 0;
not overriding function Parent
(Self : Derived_Record_Extension)
return not null Program.Elements.Subtype_Indications
.Subtype_Indication_Access is abstract;
not overriding function Progenitors
(Self : Derived_Record_Extension)
return Program.Elements.Expressions.Expression_Vector_Access is abstract;
not overriding function Record_Definition
(Self : Derived_Record_Extension)
return not null Program.Elements.Definitions.Definition_Access
is abstract;
not overriding function Has_Abstract
(Self : Derived_Record_Extension)
return Boolean is abstract;
not overriding function Has_Limited
(Self : Derived_Record_Extension)
return Boolean is abstract;
type Derived_Record_Extension_Text is limited interface;
type Derived_Record_Extension_Text_Access is
access all Derived_Record_Extension_Text'Class with Storage_Size => 0;
not overriding function To_Derived_Record_Extension_Text
(Self : in out Derived_Record_Extension)
return Derived_Record_Extension_Text_Access is abstract;
not overriding function Abstract_Token
(Self : Derived_Record_Extension_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Limited_Token
(Self : Derived_Record_Extension_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function New_Token
(Self : Derived_Record_Extension_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function And_Token
(Self : Derived_Record_Extension_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function With_Token
(Self : Derived_Record_Extension_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
end Program.Elements.Derived_Record_Extensions;
|
-----------------------------------------------------------------------------
-- Implementation of delay provider
--
-- Copyright 2022 (C) Holger Rodriguez
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with RP.Timer;
package body Delay_Provider is
procedure Delay_MS (MS : Integer) is
My_Delay : RP.Timer.Delays;
begin
if MS > 0 then
RP.Timer.Delay_Milliseconds (This => My_Delay,
Ms => MS);
end if;
end Delay_MS;
end Delay_Provider;
|
pragma License (Unrestricted);
-- implementation unit required by compiler
package System.Wid_WChar is
pragma Pure;
-- required for Wide_Character'Width by compiler (s-widwch.ads)
function Width_Wide_Character (Lo, Hi : Wide_Character) return Natural;
-- required for Wide_Wide_Character'Width by compiler (s-widwch.ads)
function Width_Wide_Wide_Character (Lo, Hi : Wide_Wide_Character)
return Natural;
end System.Wid_WChar;
|
-- { dg-do compile }
-- { dg-options "-O1 -gnatp -gnatn" }
with Dse_Step; use Dse_Step;
procedure Test_Dse_Step is
Start : My_Counter := (Value => 0, Step => 1);
Steps : Natural := Nsteps;
begin
Step_From (Start);
if Mv /= Steps then
raise Program_Error;
end if;
end;
|
package TLSF.Proof.Test.Relation with SPARK_Mode is
procedure Test_Find;
end TLSF.Proof.Test.Relation;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- A D A B K E N D --
-- --
-- B o d y --
-- --
-- Copyright (C) 2001-2019, AdaCore --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- This is the version of the Back_End package for back ends written in Ada
with Atree; use Atree;
with Debug;
with Lib;
with Opt; use Opt;
with Output; use Output;
with Osint; use Osint;
with Osint.C; use Osint.C;
with Switch.C; use Switch.C;
with Types; use Types;
with System.OS_Lib; use System.OS_Lib;
package body Adabkend is
use Switch;
-------------------
-- Call_Back_End --
-------------------
procedure Call_Back_End is
begin
if (Opt.Verbose_Mode or Opt.Full_List)
and then not Debug.Debug_Flag_7
then
Write_Eol;
Write_Str (Product_Name);
Write_Str (", Copyright ");
Write_Str (Copyright_Years);
Write_Str (" Ada Core Technologies, Inc.");
Write_Str (" (http://www.adacore.com)");
Write_Eol;
Write_Eol;
end if;
-- The front end leaves the Current_Error_Node at a location that is
-- meaningless and confusing when emitting bug boxes from the back end.
-- Reset the global variable in order to emit "No source file position
-- information available" messages on back end crashes.
Current_Error_Node := Empty;
Driver (Lib.Cunit (Types.Main_Unit));
end Call_Back_End;
-----------------------------
-- Scan_Compiler_Arguments --
-----------------------------
procedure Scan_Compiler_Arguments is
Output_File_Name_Seen : Boolean := False;
-- Set to True after having scanned the file_name for switch
-- "-gnatO file_name"
Argument_Count : constant Integer := Arg_Count - 1;
-- Number of arguments (excluding program name)
Args : Argument_List (1 .. Argument_Count);
Next_Arg : Positive := 1;
procedure Scan_Back_End_Switches (Switch_Chars : String);
-- Procedure to scan out switches stored in Switch_Chars. The first
-- character is known to be a valid switch character, and there are no
-- blanks or other switch terminator characters in the string, so the
-- entire string should consist of valid switch characters, except that
-- an optional terminating NUL character is allowed.
--
-- If the switch is not valid, control will not return. The switches
-- must still be scanned to skip the "-o" arguments, or internal GCC
-- switches, which may be safely ignored by other back ends.
----------------------------
-- Scan_Back_End_Switches --
----------------------------
procedure Scan_Back_End_Switches (Switch_Chars : String) is
First : constant Positive := Switch_Chars'First + 1;
Last : constant Natural := Switch_Last (Switch_Chars);
begin
-- Process any back end switches, returning if the switch does not
-- affect code generation or falling through if it does, so the
-- switch will get stored.
-- Skip -o, -G or internal GCC switches together with their argument.
if Switch_Chars (First .. Last) = "o"
or else Switch_Chars (First .. Last) = "G"
or else Is_Internal_GCC_Switch (Switch_Chars)
then
Next_Arg := Next_Arg + 1;
return; -- ignore this switch
-- Set optimization indicators appropriately. In gcc-based GNAT this
-- is picked up from imported variables set by the gcc driver, but
-- for compilers with non-gcc back ends we do it here to allow use
-- of these switches by the front end. Allowed optimization switches
-- are -Os (optimize for size), -O[0123], and -O (same as -O1).
elsif Switch_Chars (First) = 'O' then
if First = Last then
Optimization_Level := 1;
elsif Last - First = 1 then
if Switch_Chars (Last) = 's' then
Optimize_Size := 1;
Optimization_Level := 2; -- Consistent with gcc setting
elsif Switch_Chars (Last) in '0' .. '3' then
Optimization_Level :=
Character'Pos (Switch_Chars (Last)) - Character'Pos ('0');
else
Fail ("invalid switch: " & Switch_Chars);
end if;
else
Fail ("invalid switch: " & Switch_Chars);
end if;
elsif Switch_Chars (First .. Last) = "quiet" then
return; -- ignore this switch
elsif Switch_Chars (First .. Last) = "c" then
return; -- ignore this switch
-- The -x switch and its language name argument will generally be
-- ignored by non-gcc back ends. In any case, we save the switch and
-- argument in the compilation switches.
elsif Switch_Chars (First .. Last) = "x" then
Lib.Store_Compilation_Switch (Switch_Chars);
Next_Arg := Next_Arg + 1;
declare
Argv : constant String := Args (Next_Arg).all;
begin
if Is_Switch (Argv) then
Fail ("language name missing after -x");
else
Lib.Store_Compilation_Switch (Argv);
end if;
end;
return;
-- Special check, the back end switch -fno-inline also sets the
-- front end flags to entirely inhibit all inlining. So we store it
-- and set the appropriate flags.
elsif Switch_Chars (First .. Last) = "fno-inline" then
Lib.Store_Compilation_Switch (Switch_Chars);
Opt.Disable_FE_Inline := True;
Opt.Disable_FE_Inline_Always := True;
return;
-- Similar processing for -fpreserve-control-flow
elsif Switch_Chars (First .. Last) = "fpreserve-control-flow" then
Lib.Store_Compilation_Switch (Switch_Chars);
Opt.Suppress_Control_Flow_Optimizations := True;
return;
-- Recognize -gxxx switches
elsif Switch_Chars (First) = 'g' then
Debugger_Level := 2;
if First < Last then
case Switch_Chars (First + 1) is
when '0' =>
Debugger_Level := 0;
when '1' =>
Debugger_Level := 1;
when '2' =>
Debugger_Level := 2;
when '3' =>
Debugger_Level := 3;
when others =>
null;
end case;
end if;
-- Ignore all other back end switches
elsif Is_Back_End_Switch (Switch_Chars) then
null;
-- Give error for junk switch
else
Fail ("invalid switch: " & Switch_Chars);
end if;
-- Store any other GCC switches
Lib.Store_Compilation_Switch (Switch_Chars);
end Scan_Back_End_Switches;
-- Start of processing for Scan_Compiler_Args
begin
-- Put all the arguments in argument list Args
for Arg in 1 .. Argument_Count loop
declare
Argv : String (1 .. Len_Arg (Arg));
begin
Fill_Arg (Argv'Address, Arg);
Args (Arg) := new String'(Argv);
end;
end loop;
-- Loop through command line arguments, storing them for later access
while Next_Arg <= Argument_Count loop
Look_At_Arg : declare
Argv : constant String := Args (Next_Arg).all;
begin
if Argv'Length = 0 then
Fail ("Empty argument");
end if;
-- If the previous switch has set the Output_File_Name_Present
-- flag (that is we have seen a -gnatO), then the next argument
-- is the name of the output object file.
if Opt.Output_File_Name_Present
and then not Output_File_Name_Seen
then
if Is_Switch (Argv) then
Fail ("Object file name missing after -gnatO");
else
Set_Output_Object_File_Name (Argv);
Output_File_Name_Seen := True;
end if;
-- If the previous switch has set the Search_Directory_Present
-- flag (that is if we have just seen -I), then the next
-- argument is a search directory path.
elsif Search_Directory_Present then
if Is_Switch (Argv) then
Fail ("search directory missing after -I");
else
Add_Src_Search_Dir (Argv);
-- Add directory to lib search so that back end can take as
-- input ALI files if needed. Otherwise this won't have any
-- impact on the compiler.
Add_Lib_Search_Dir (Argv);
Search_Directory_Present := False;
end if;
-- If not a switch, must be a file name
elsif not Is_Switch (Argv) then
Add_File (Argv);
-- We must recognize -nostdinc to suppress visibility on the
-- standard GNAT RTL sources.
elsif Argv (Argv'First + 1 .. Argv'Last) = "nostdinc" then
Opt.No_Stdinc := True;
-- Front end switch
elsif Is_Front_End_Switch (Argv) then
Scan_Front_End_Switches (Argv, Args, Next_Arg);
-- All non-front-end switches are back-end switches
else
Scan_Back_End_Switches (Argv);
end if;
end Look_At_Arg;
Next_Arg := Next_Arg + 1;
end loop;
end Scan_Compiler_Arguments;
end Adabkend; |
with Ada.Containers.Indefinite_Vectors;
with Ada.Containers.Vectors;
package Benchmark_Containers is
subtype Long is Long_Integer;
procedure Test_Indefinite (N : Long; File_Name : String);
procedure Test_Non_Indefinite (N : Long; File_Name : String);
end Benchmark_Containers;
|
with AAA.Strings;
with Ada.Strings.Unbounded;
with Ada.Containers.Vectors;
package FSmaker is
function Valid_Path_Char (C : Character) return Boolean
is (C in '/' | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' |
' ' | '-' | '_' | '.');
function Valid_Target_Path (Str : String) return Boolean
is (Str'Length > 0
and then Str (Str'First) = '/'
and then (for all C of Str => Valid_Path_Char (C)));
subtype Target_Path is AAA.Strings.Vector;
Empty_Path : Target_Path renames AAA.Strings.Empty_Vector;
function To_Target_Path (Str : String) return Target_Path;
type Node_Kind is (Dir, File);
type Node (Kind : Node_Kind);
type Node_Access is access all Node;
package Node_Vectors
is new Ada.Containers.Vectors (Natural, Node_Access);
subtype Directory_Tree is Node_Vectors.Vector;
type Node (Kind : Node_Kind) is record
Name : Ada.Strings.Unbounded.Unbounded_String;
case Kind is
when Dir =>
Entries : Directory_Tree;
when File =>
null;
end case;
end record;
procedure Pretty_Print (Tree : Directory_Tree;
Indent : String := "|");
end FSmaker;
|
pragma License (Unrestricted);
-- extended unit
with Ada.Command_Line;
with Ada.IO_Exceptions;
with Ada.Streams.Stream_IO.Standard_Files;
private with Ada.Finalization;
private with System.Native_Processes;
package Ada.Processes is
-- Spawning child processes.
type Command_Type is limited private;
function Image (Command : Command_Type) return String;
function Value (Command_Line : String) return Command_Type;
procedure Append (Command : in out Command_Type; New_Item : String);
procedure Append (
Command : in out Command_Type;
New_Item :
Ada.Command_Line.Iterator_Interfaces.Reversible_Iterator'Class);
-- Copy arguments from (subsequence of) Ada.Command_Line.
procedure Append_Argument (
Command_Line : in out String;
Last : in out Natural;
Argument : String);
pragma Inline (Append_Argument); -- renamed
type Process is limited private;
-- subtype Open_Process is Process
-- with
-- Dynamic_Predicate => Is_Open (Open_Process),
-- Predicate_Failure => raise Status_Error;
-- Child process management
function Is_Open (Child : Process) return Boolean;
pragma Inline (Is_Open);
procedure Create (
Child : in out Process;
Command : Command_Type;
Directory : String := "";
Search_Path : Boolean := False;
Input : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Input.all;
Output : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Output.all;
Error : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Error.all);
procedure Create (
Child : in out Process;
Command_Line : String;
Directory : String := "";
Search_Path : Boolean := False;
Input : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Input.all;
Output : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Output.all;
Error : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Error.all);
function Create (
Command : Command_Type;
Directory : String := "";
Search_Path : Boolean := False;
Input : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Input.all;
Output : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Output.all;
Error : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Error.all)
return Process;
function Create (
Command_Line : String;
Directory : String := "";
Search_Path : Boolean := False;
Input : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Input.all;
Output : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Output.all;
Error : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Error.all)
return Process;
pragma Inline (Create); -- renamed
procedure Wait (
Child : in out Process; -- Open_Process
Status : out Ada.Command_Line.Exit_Status);
procedure Wait (
Child : in out Process); -- Open_Process
pragma Inline (Wait);
procedure Wait_Immediate (
Child : in out Process; -- Open_Process
Terminated : out Boolean;
Status : out Ada.Command_Line.Exit_Status);
procedure Wait_Immediate (
Child : in out Process; -- Open_Process
Terminated : out Boolean);
pragma Inline (Wait_Immediate);
procedure Abort_Process (Child : in out Process); -- Open_Process
procedure Forced_Abort_Process (Child : in out Process); -- Open_Process
pragma Inline (Abort_Process);
pragma Inline (Forced_Abort_Process);
-- Pass a command to the shell
procedure Shell (
Command : Command_Type;
Status : out Ada.Command_Line.Exit_Status);
procedure Shell (
Command_Line : String;
Status : out Ada.Command_Line.Exit_Status);
procedure Shell (Command : Command_Type);
procedure Shell (Command_Line : String);
pragma Inline (Shell); -- for shorthand
-- Exceptions
Status_Error : exception
renames IO_Exceptions.Status_Error;
Name_Error : exception
renames IO_Exceptions.Name_Error;
Use_Error : exception
renames IO_Exceptions.Use_Error;
Device_Error : exception
renames IO_Exceptions.Device_Error;
private
package Controlled_Commands is
type Command_Type is limited private;
function Reference (Object : Processes.Command_Type)
return not null access System.Native_Processes.Command_Type;
pragma Inline (Reference);
private
type Command_Type is
limited new Finalization.Limited_Controlled
with record
Native_Command : aliased System.Native_Processes.Command_Type := null;
end record;
overriding procedure Finalize (Object : in out Command_Type);
end Controlled_Commands;
type Command_Type is new Controlled_Commands.Command_Type;
procedure Append_Argument (
Command_Line : in out String;
Last : in out Natural;
Argument : String)
renames System.Native_Processes.Append_Argument;
package Controlled_Processes is
type Process is limited private;
function Reference (Object : Processes.Process)
return not null access System.Native_Processes.Process;
pragma Inline (Reference);
function Create (
Command : Command_Type;
Directory : String := "";
Search_Path : Boolean := False;
Input : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Input.all;
Output : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Output.all;
Error : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Error.all)
return Processes.Process;
function Create (
Command_Line : String;
Directory : String := "";
Search_Path : Boolean := False;
Input : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Input.all;
Output : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Output.all;
Error : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Error.all)
return Processes.Process;
-- [gcc-7] strange error if this function is placed outside of
-- the package Controlled, and Disable_Controlled => True
private
type Process is limited new Finalization.Limited_Controlled with record
Data : aliased System.Native_Processes.Process :=
System.Native_Processes.Null_Process;
end record
with
Disable_Controlled =>
System.Native_Processes.Process_Disable_Controlled;
overriding procedure Finalize (Object : in out Process);
end Controlled_Processes;
type Process is new Controlled_Processes.Process;
function Create (
Command : Command_Type;
Directory : String := "";
Search_Path : Boolean := False;
Input : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Input.all;
Output : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Output.all;
Error : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Error.all)
return Process
renames Controlled_Processes.Create;
function Create (
Command_Line : String;
Directory : String := "";
Search_Path : Boolean := False;
Input : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Input.all;
Output : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Output.all;
Error : Streams.Stream_IO.File_Type :=
Streams.Stream_IO.Standard_Files.Standard_Error.all)
return Process
renames Controlled_Processes.Create;
end Ada.Processes;
|
-- Ascon_Test_Vectors
-- Copyright (c) 2016-2018, James Humphry - see LICENSE file for details
with Ada.Text_IO;
use Ada.Text_IO;
with Ascon128v11;
with Ascon128av11;
with Ascon128v12;
with Ascon128av12;
with Display_Ascon_Traces;
procedure Ascon_Test_Vectors is
procedure Ascon128v11_Display is
new Display_Ascon_Traces(Ascon_Package => Ascon128v11);
procedure Ascon128av11_Display is
new Display_Ascon_Traces(Ascon_Package => Ascon128av11);
procedure Ascon128v12_Display is
new Display_Ascon_Traces(Ascon_Package => Ascon128v12);
procedure Ascon128av12_Display is
new Display_Ascon_Traces(Ascon_Package => Ascon128av12);
begin
Put_Line("Ascon Test Vectors");
New_Line;
Put_Line("-----------");
Put_Line("Ascon128v11");
Put_Line("-----------");
Ascon128v11_Display;
New_Line;
Put_Line("------------");
Put_Line("Ascon128av11");
Put_Line("------------");
Ascon128av11_Display;
New_Line;
Put_Line("-----------");
Put_Line("Ascon128v12");
Put_Line("-----------");
Ascon128v12_Display;
New_Line;
Put_Line("------------");
Put_Line("Ascon128av12");
Put_Line("------------");
Ascon128av12_Display;
New_Line;
end Ascon_Test_Vectors;
|
with Input_Sources.File; use Input_Sources.File;
with Sax.Readers; use Sax.Readers;
with DOM.Readers; use DOM.Readers;
with DOM.Core; use DOM.Core;
with DOM.Core.Documents; use DOM.Core.Documents;
with DOM.Core.Nodes; use DOM.Core.Nodes;
with DOM.Core.Attrs; use DOM.Core.Attrs;
with Ada.Text_IO; use Ada.Text_IO;
package body tracker.datasource is
procedure Load is
Input : File_Input;
Reader : Tree_Reader;
Doc : Document;
Activities_List : Node_List;
Activity_Node : Node;
Focus_Attrib : Attr;
Current_Child : Node;
begin
Set_Public_Id (Input, "Activities file");
Open ("activities.xml", Input);
Set_Feature (Reader, Validation_Feature, False);
Set_Feature (Reader, Namespace_Feature, False);
Parse (Reader, Input);
Close (Input);
Doc := Get_Tree (Reader);
Activities_List := Get_Elements_By_Tag_Name (Doc, "activity");
for Index in 1 .. Length (Activities_List) loop
READING_COL : declare
Col : Collection;
begin
Activity_Node := DOM.Core.Nodes.Item (Activities_List, Index - 1);
Focus_Attrib := Get_Named_Item (Attributes (Activity_Node), "focus");
if Focus_Attrib = null then
Col.Focused := False;
else
Col.Focused := Boolean'Value (Value (Focus_Attrib));
end if;
Current_Child := First_Child (Activity_Node);
loop
exit when Current_Child = null;
if Node_Type (Current_Child) = Element_Node then
if Node_Name (Current_Child) = "name" then
Set_Name (Col, Node_Value (First_Child (Current_Child)));
else
Add_Item (
Col,
Node_Value (First_Child (Current_Child)),
Item_Status'Value (
Value (
Get_Named_Item (Attributes(Current_Child),
"state"))));
end if;
end if;
Current_Child := Next_Sibling (Current_Child);
end loop;
Add_Collection (Activities, Col);
end READING_COL;
end loop;
Free (Activities_List);
Free (Reader);
end Load;
end tracker.datasource;
|
with AdaCar.Parametros;
with AdaCar.Motores;
package body AdaCar.Organizador_Movimiento is
Minima_Distancia: constant Unidades_Distancia:= Parametros.Distancia_Minima;
--------------------
-- Organizador_PO --
--------------------
protected Organizador_PO
with Priority => Parametros.Techo_Organizador_PO
is
procedure Nueva_Distancia_Sensor(Valor: Unidades_Distancia);
end Organizador_PO;
----------------------------
-- Nueva_Distancia_Sensor --
----------------------------
procedure Nueva_Distancia_Sensor (Valor : Unidades_Distancia) is
begin
Organizador_PO.Nueva_Distancia_Sensor(Valor);
end Nueva_Distancia_Sensor;
-------------------------------
-- Organizador_Movimiento_PO --
-------------------------------
protected body Organizador_PO is
procedure Nueva_Distancia_Sensor(Valor: Unidades_Distancia) is
begin
if Valor > Minima_Distancia then
Motores.Actua_Direccion(Ambos_Motores,Hacia_Delante);
else
Motores.Actua_Direccion(Ambos_Motores,Hacia_Detras);
end if;
Motores.Actua_Step(Ambos_Motores,1);
end Nueva_Distancia_Sensor;
end Organizador_PO;
end AdaCar.Organizador_Movimiento;
|
--
-- Jan & Uwe R. Zimmer, Australia, July 2011
--
with Callback_Procedures; use Callback_Procedures;
with Graphics_Setup; use Graphics_Setup;
with Exceptions; use Exceptions;
with GLUT;
procedure Swarm is
begin
Initialize_Graphics (Main_Operations'Access);
GLUT.MainLoop;
exception
when E : others => Show_Exception (E);
end Swarm;
|
----------------------------------------
-- Copyright (C) 2019 Dmitriy Shadrin --
-- All rights reserved. --
----------------------------------------
with Sax.Readers; use Sax.Readers;
with Input_Sources.File; use Input_Sources.File;
with Unicode.CES;
with Sax.Attributes;
with Sax.Utils;
with Sax.Symbols;
--------------------------------------------------------------------------------
package body ConfigTree.SaxParser is
-----------------------------------------------------------------------------
type Reader is new Sax.Readers.Reader with
record
parent : NodePtr;
current : NodePtr;
end record;
-----------------------------------------------------------------------------
procedure Start_Element (Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "";
Atts : Sax.Attributes.Attributes'Class);
-----------------------------------------------------------------------------
procedure End_Element (Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "");
-----------------------------------------------------------------------------
procedure Characters (Handler : in out Reader;
Ch : Unicode.CES.Byte_Sequence);
-----------------------------------------------------------------------------
procedure Start_Element (Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "";
Atts : Sax.Attributes.Attributes'Class) is
temp : NodePtr := new Node;
begin
if Handler.current.childFirst = null then
Handler.current.childFirst := temp;
Handler.current.childLast := temp;
else
Handler.current.childLast.next := temp;
temp.previous := Handler.current.childLast;
Handler.current.childLast := temp;
end if;
temp.parent := Handler.current;
Handler.parent := Handler.current;
Handler.current := temp;
Handler.current.name := Ada.Strings.Unbounded.To_Unbounded_String (Qname);
end Start_Element;
-----------------------------------------------------------------------------
procedure End_Element (Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "") is
x : Integer := 0;
use type Ada.Strings.Unbounded.Unbounded_String;
begin
if Handler.current.name = Ada.Strings.Unbounded.To_Unbounded_String (Qname) then
Handler.current := Handler.parent;
Handler.parent := Handler.current.parent;
else
raise Program_Error;
end if;
end End_Element;
-----------------------------------------------------------------------------
procedure Characters (Handler : in out Reader;
Ch : Unicode.CES.Byte_Sequence) is
use type Ada.Strings.Unbounded.Unbounded_String;
begin
Handler.current.data := Handler.current.data & Ada.Strings.Unbounded.To_Unbounded_String (Ch);
end Characters;
-----------------------------------------------------------------------------
procedure Parse (root : in out ConfigTree.NodePtr) is
saxReader : Reader;
input : File_Input;
begin
Set_Public_Id (input, "Configure file");
Set_System_Id (input, "proxy.xml");
Open ("proxy.xml", input);
Set_Feature (saxReader, Namespace_Prefixes_Feature, False);
Set_Feature (saxReader, Namespace_Feature, False);
Set_Feature (saxReader, Validation_Feature, False);
saxReader.parent := null;
saxReader.current := root;
Parse (saxReader, input);
Close (input);
end Parse;
end ConfigTree.SaxParser;
|
-- licenselist.adb --
-- run under GPS 4.3-5 (Sidux/Debian)
-- process rosetta.org text_processing/3 example
-- uses linked-list to hold times
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded,
Ada.Strings.Unbounded.Text_IO,
Ada.Containers.Doubly_Linked_Lists;
use Ada.Text_IO, Ada.Integer_Text_IO,
Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO,
Ada.Containers;
procedure licenselist is
type logrec is record -- define a record 'logrec' to place in a list
logtext : String(1..19);
end record;
package dblist is new Doubly_Linked_Lists(logrec);
use dblist;
-- declare dblist as a list of logrec's
licenselog : list;
logtime : logrec;
-- to record the time of max OUT licenses
infile : File_Type; -- file handle
str : Unbounded_String; -- input string buffer of unknown length
outcnt, maxoutcnt : integer := 0;
infilename : string := "license.log";
procedure trace_times is
-- loop thru times list and print
pntr : cursor := licenselog.first;
-- pntr is of system type cursor reference to local list 'licenselog'
begin
new_line;
while has_element(pntr) loop
put(element(pntr).logtext); new_line;
next(pntr);
end loop;
end trace_times;
begin -- main program --
open ( infile,
mode=> in_file,
name=> infilename );
loop
exit when End_of_file ( infile );
str := get_line( infile );
if index( str, "OUT" ) > 0 then -- test if OUT record
outcnt := outcnt +1;
else -- else assume IN record
outcnt := outcnt -1;
end if;
if outcnt > maxoutcnt then
maxoutcnt := outcnt;
logtime.logtext := slice(str,15,33); -- date_time field
licenselog.clear; -- reset list for new time(s)
licenselog.append (logtime); -- put current time into list
elsif outcnt = maxoutcnt then
logtime.logtext := slice(str,15,33); -- date_time field
licenselog.append (logtime); -- add current time into list
end if; -- have to account for possibility of equal number of OUT's
end loop;
put("The max. number of licenses OUT is ");put(maxoutcnt,5); new_line;
put(" at these times ");
trace_times;
close ( infile );
end licenselist;
|
with ada.text_io;
use ada.text_io;
procedure euler9 is
c : integer;
begin
for a in 1 .. 999 loop
for b in a + 1 .. 999 loop
c := 1000 - a - b;
if c > 0 and then a * a + b * b = c * c then
put_line(integer'image(a * b * c));
end if;
end loop;
end loop;
end;
|
--------------------------------------------------------------------------------------------------------------------
-- 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 Interfaces.C;
with Ada.Unchecked_Conversion;
with SDL.Error;
package body SDL.Video.Textures is
package C renames Interfaces.C;
use type C.int;
use type SDL.C_Pointers.Texture_Pointer;
procedure Destroy (Self : in out Texture) is
procedure SDL_Destroy_Texture (T : in SDL.C_Pointers.Texture_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_DestroyTexture";
begin
SDL_Destroy_Texture (Self.Internal);
Self.Internal := null;
end Destroy;
function Get_Alpha (Self : in Texture) return SDL.Video.Palettes.Colour_Component is
function SDL_Get_Texture_Alpha_Mod (T : in SDL.C_Pointers.Texture_Pointer;
Alpha : out SDL.Video.Palettes.Colour_Component) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetTextureAlphaMod";
Data : SDL.Video.Palettes.Colour_Component;
Result : C.int := SDL_Get_Texture_Alpha_Mod (Self.Internal, Data);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
return Data;
end Get_Alpha;
procedure Set_Alpha (Self : in out Texture; Alpha : in SDL.Video.Palettes.Colour_Component) is
function SDL_Set_Texture_Alpha_Mod (T : in SDL.C_Pointers.Texture_Pointer;
Alpha : in SDL.Video.Palettes.Colour_Component) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetTextureAlphaMod";
Result : C.int := SDL_Set_Texture_Alpha_Mod (Self.Internal, Alpha);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
end Set_Alpha;
function Get_Blend_Mode (Self : in Texture) return Blend_Modes is
function SDL_Get_Texture_Blend_Mode (T : in SDL.C_Pointers.Texture_Pointer;
Blend : out Blend_Modes) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetTextureBlendMode";
Data : Blend_Modes;
Result : C.int := SDL_Get_Texture_Blend_Mode (Self.Internal, Data);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
return Data;
end Get_Blend_Mode;
procedure Set_Blend_Mode (Self : in out Texture; Mode : in Blend_Modes) is
function SDL_Set_Texture_Blend_Mode (T : in SDL.C_Pointers.Texture_Pointer;
Mode : in Blend_Modes) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetTextureBlendMode";
Result : C.int := SDL_Set_Texture_Blend_Mode (Self.Internal, Mode);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
end Set_Blend_Mode;
function Get_Modulate_Colour (Self : in Texture) return SDL.Video.Palettes.RGB_Colour is
function SDL_Get_Texture_Color_Mod (T : in SDL.C_Pointers.Texture_Pointer;
R, G, B : out SDL.Video.Palettes.Colour_Component) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_GetTextureColorMod";
Data : SDL.Video.Palettes.RGB_Colour;
Result : C.int := SDL_Get_Texture_Color_Mod (Self.Internal, Data.Red, Data.Green, Data.Blue);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
return Data;
end Get_Modulate_Colour;
procedure Set_Modulate_Colour (Self : in out Texture; Colour : in SDL.Video.Palettes.RGB_Colour) is
function SDL_Set_Texture_Color_Mod (T : in SDL.C_Pointers.Texture_Pointer;
R, G, B : in SDL.Video.Palettes.Colour_Component) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_SetTextureColorMod";
Result : C.int := SDL_Set_Texture_Color_Mod (Self.Internal, Colour.Red, Colour.Green, Colour.Blue);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
end Set_Modulate_Colour;
-- procedure Lock_Texture (Self : in out Texture;
-- Pixels : out SDL.Video.Pixels.Pixel_ARGB_8888_Array_Access) is
-- type Int_Ptr is access C.int with
-- Convention => C;
--
-- function SDL_Lock_Texture (T : in System.Address;
-- Area : in System.Address;
-- Pixels : out SDL.Video.Pixels.C_Pixel_Ptr;
-- Pitch : out Int_Ptr) return C.int with
-- Import => True,
-- Convention => C,
-- External_Name => "SDL_LockTexture";
--
-- C_Pixels : SDL.Video.Pixels.C_Pixel_Ptr := null;
-- C_Pitch : Int_Ptr := null;
-- Result : C.int := SDL_Lock_Texture (Self.Internal, System.Null_Address, C_Pixels, C_Pitch);
-- begin
-- if Result /= Success then
-- raise Texture_Error with SDL.Error.Get;
-- end if;
--
-- Self.Locked := True;
--
-- Pixels := SDL.Video.Pixels.Create (C_Pixels, C_Pitch.all, Self.Size);
-- end Lock_Texture;
procedure Lock (Self : in out Texture;
Pixels : out Pixel_Pointer_Type) is
function SDL_Lock_Texture (T : in SDL.C_Pointers.Texture_Pointer;
Area : in System.Address;
Pixels : out Pixel_Pointer_Type;
Pitch : out SDL.Video.Pixels.Pitches) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_LockTexture";
-- Don't care about Pitch value.
Dummy : SDL.Video.Pixels.Pitches := 0;
Result : C.int := SDL_Lock_Texture (Self.Internal, System.Null_Address, Pixels, Dummy);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
Self.Locked := True;
end Lock;
procedure Lock_Area (Self : in out Texture;
Area : in SDL.Video.Rectangles.Rectangle;
Pixels : out Pixel_Pointer_Type;
Pitch : out SDL.Video.Pixels.Pitches) is
function SDL_Lock_Texture (T : in SDL.C_Pointers.Texture_Pointer;
Area : in SDL.Video.Rectangles.Rectangle;
Pixels : out Pixel_Pointer_Type;
Pitch : out SDL.Video.Pixels.Pitches) return C.int with
Import => True,
Convention => C,
External_Name => "SDL_LockTexture";
Result : C.int := SDL_Lock_Texture (Self.Internal, Area, Pixels, Pitch);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
Self.Locked := True;
end Lock_Area;
procedure Unlock (Self : in out Texture) is
procedure SDL_Unlock_Texture (T : in SDL.C_Pointers.Texture_Pointer) with
Import => True,
Convention => C,
External_Name => "SDL_UnlockTexture";
begin
if Self.Locked then
SDL_Unlock_Texture (Self.Internal);
Self.Locked := False;
end if;
end Unlock;
procedure Query (Self : in Texture;
Pixel_Format_Name : out SDL.Video.Pixel_Formats.Pixel_Format_Names;
Kind : out Kinds;
Size : out SDL.Sizes) is
function SDL_Query_Texture (T : in SDL.C_Pointers.Texture_Pointer;
Pixel_Format_Name : out SDL.Video.Pixel_Formats.Pixel_Format_Names;
Kind : out Kinds;
Width : out SDL.Dimension;
Height : out SDL.Dimension) return C.int with
import => True,
Convention => C,
External_Name => "SDL_QueryTexture";
W : SDL.Dimension := 0;
H : SDL.Dimension := 0;
Result : C.int := SDL_Query_Texture (Self.Internal, Pixel_Format_Name, Kind, W, H);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
Size := SDL.Sizes'(W, H);
end Query;
function Get_Pixel_Format (Self : in Texture) return SDL.Video.Pixel_Formats.Pixel_Format_Names is
function SDL_Query_Texture (T : in SDL.C_Pointers.Texture_Pointer;
Pixel_Format_Name : out SDL.Video.Pixel_Formats.Pixel_Format_Names;
Kind : in System.Address := System.Null_Address;
Width : in System.Address := System.Null_Address;
Height : in System.Address := System.Null_Address) return C.int with
import => True,
Convention => C,
External_Name => "SDL_QueryTexture";
Format_Name : SDL.Video.Pixel_Formats.Pixel_Format_Names;
Result : C.int := SDL_Query_Texture (T => Self.Internal, Pixel_Format_Name => Format_Name);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
return Format_Name;
end Get_Pixel_Format;
function Get_Kind (Self : in Texture) return Kinds is
function SDL_Query_Texture (T : in SDL.C_Pointers.Texture_Pointer;
Pixel_Format_Name : in System.Address := System.Null_Address;
Kind : out Kinds;
Width : in System.Address := System.Null_Address;
Height : in System.Address := System.Null_Address) return C.int with
import => True,
Convention => C,
External_Name => "SDL_QueryTexture";
Kind : Kinds;
Result : C.int := SDL_Query_Texture (T => Self.Internal, Kind => Kind);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
return Kind;
end Get_Kind;
function Get_Size (Self : in Texture) return SDL.Sizes is
function SDL_Query_Texture (T : in SDL.C_Pointers.Texture_Pointer;
Pixel_Format_Name : in System.Address := System.Null_Address;
Kind : in System.Address := System.Null_Address;
Width : out SDL.Dimension;
Height : out SDL.Dimension) return C.int with
import => True,
Convention => C,
External_Name => "SDL_QueryTexture";
Size : SDL.Sizes := SDL.Zero_Size;
Result : C.int := SDL_Query_Texture (T => Self.Internal, Width => Size.Width, Height => Size.Height);
begin
if Result /= Success then
raise Texture_Error with SDL.Error.Get;
end if;
return Size;
end Get_Size;
procedure Update_YUV_Texture (Self : in out Texture;
Y_Plane : in Pixel_Pointer_Type;
Y_Pitch : in Natural;
U_Plane : in Pixel_Pointer_Type;
U_Pitch : in Natural;
V_Plane : in Pixel_Pointer_Type;
V_Pitch : in Natural) is
procedure SDL_UpdateYUVTexture (T : in SDL.C_Pointers.Texture_Pointer;
Area : in System.Address;
YPlane : in Pixel_Pointer_Type;
YPitch : in Natural;
UPlane : in Pixel_Pointer_Type;
UPitch : in Natural;
VPlane : in Pixel_Pointer_Type;
VPitch : in Natural) with
Import => True,
Convention => C,
External_Name => "SDL_UpdateYUVTexture";
-- extern DECLSPEC int SDLCALL SDL_UpdateYUVTexture (SDL_Texture * texture,
-- const SDL_Rect * rect,
-- const Uint8 * Yplane, int Ypitch,
-- const Uint8 * Uplane, int Upitch,
-- const Uint8 *Vplane, int Vpitch);
begin
SDL_UpdateYUVTexture (T => Self.Internal, Area => System.Null_Address,
YPlane => Y_Plane, YPitch => Y_Pitch,
UPlane => U_Plane, UPitch => U_Pitch,
VPlane => V_Plane, VPitch => V_Pitch);
end Update_YUV_Texture;
overriding
procedure Finalize (Self : in out Texture) is
begin
if Self.Internal /= null and then Self.Owns then
Destroy (Self);
end if;
end Finalize;
function Get_Internal_Texture (Self : in Texture) return SDL.C_Pointers.Texture_Pointer is
begin
return Self.Internal;
end Get_Internal_Texture;
end SDL.Video.Textures;
|
--
-- Copyright (C) 2019, AdaCore
--
-- Copyright (c) 2010 - 2018, 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:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form, except as embedded into a Nordic
-- Semiconductor ASA integrated circuit in a product or a software update
-- for such product, 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 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.
--
-- 4. This software, with or without modification, must only be used with a
-- Nordic Semiconductor ASA integrated circuit.
--
-- 5. Any software provided in binary form under this license must not be
-- reverse engineered, decompiled, modified and/or disassembled.
--
-- THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-- WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR
-- ASA 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 nrf52840.svd
-- This is a version for the nRF52840 reference description for radio MCU with
-- ARM 32-bit Cortex-M4 Microcontroller MCU
package Ada.Interrupts.Names is
-- All identifiers in this unit are implementation defined
pragma Implementation_Defined;
----------------
-- Interrupts --
----------------
-- System tick
Sys_Tick_Interrupt : constant Interrupt_ID := -1;
POWER_CLOCK_Interrupt : constant Interrupt_ID := 0;
RADIO_Interrupt : constant Interrupt_ID := 1;
UARTE0_UART0_Interrupt : constant Interrupt_ID := 2;
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_Interrupt : constant Interrupt_ID := 3;
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_Interrupt : constant Interrupt_ID := 4;
NFCT_Interrupt : constant Interrupt_ID := 5;
GPIOTE_Interrupt : constant Interrupt_ID := 6;
SAADC_Interrupt : constant Interrupt_ID := 7;
TIMER0_Interrupt : constant Interrupt_ID := 8;
TIMER1_Interrupt : constant Interrupt_ID := 9;
TIMER2_Interrupt : constant Interrupt_ID := 10;
RTC0_Interrupt : constant Interrupt_ID := 11;
TEMP_Interrupt : constant Interrupt_ID := 12;
RNG_Interrupt : constant Interrupt_ID := 13;
ECB_Interrupt : constant Interrupt_ID := 14;
CCM_AAR_Interrupt : constant Interrupt_ID := 15;
WDT_Interrupt : constant Interrupt_ID := 16;
RTC1_Interrupt : constant Interrupt_ID := 17;
QDEC_Interrupt : constant Interrupt_ID := 18;
COMP_LPCOMP_Interrupt : constant Interrupt_ID := 19;
SWI0_EGU0_Interrupt : constant Interrupt_ID := 20;
SWI1_EGU1_Interrupt : constant Interrupt_ID := 21;
SWI2_EGU2_Interrupt : constant Interrupt_ID := 22;
SWI3_EGU3_Interrupt : constant Interrupt_ID := 23;
SWI4_EGU4_Interrupt : constant Interrupt_ID := 24;
SWI5_EGU5_Interrupt : constant Interrupt_ID := 25;
TIMER3_Interrupt : constant Interrupt_ID := 26;
TIMER4_Interrupt : constant Interrupt_ID := 27;
PWM0_Interrupt : constant Interrupt_ID := 28;
PDM_Interrupt : constant Interrupt_ID := 29;
MWU_Interrupt : constant Interrupt_ID := 32;
PWM1_Interrupt : constant Interrupt_ID := 33;
PWM2_Interrupt : constant Interrupt_ID := 34;
SPIM2_SPIS2_SPI2_Interrupt : constant Interrupt_ID := 35;
RTC2_Interrupt : constant Interrupt_ID := 36;
I2S_Interrupt : constant Interrupt_ID := 37;
FPU_Interrupt : constant Interrupt_ID := 38;
USBD_Interrupt : constant Interrupt_ID := 39;
UARTE1_Interrupt : constant Interrupt_ID := 40;
QSPI_Interrupt : constant Interrupt_ID := 41;
CRYPTOCELL_Interrupt : constant Interrupt_ID := 42;
PWM3_Interrupt : constant Interrupt_ID := 45;
SPIM3_Interrupt : constant Interrupt_ID := 47;
end Ada.Interrupts.Names;
|
with Ada.Exception_Identification.From_Here;
with Ada.Exceptions.Finally;
with System.Address_To_Named_Access_Conversions;
with System.Soft_Links;
with System.Synchronous_Objects.Abortable;
with System.Tasks;
package body System.Tasking.Protected_Objects.Operations is
use Ada.Exception_Identification.From_Here;
use type Ada.Exceptions.Exception_Id;
use type Synchronous_Objects.Queue_Node_Access;
function Filter (
The_Node : not null Synchronous_Objects.Queue_Node_Access;
Params : Address)
return Boolean;
function Filter (
The_Node : not null Synchronous_Objects.Queue_Node_Access;
Params : Address)
return Boolean is
begin
return Entries.Downcast (The_Node).E = Protected_Entry_Index (Params);
end Filter;
package Task_Id_Conv is
new Address_To_Named_Access_Conversions (
Tasks.Task_Record,
Tasks.Task_Id);
package QNA_Conv is
new Address_To_Named_Access_Conversions (
Synchronous_Objects.Queue_Node,
Synchronous_Objects.Queue_Node_Access);
function Uncall_Filter (
The_Node : not null Synchronous_Objects.Queue_Node_Access;
Params : Address)
return Boolean;
function Uncall_Filter (
The_Node : not null Synchronous_Objects.Queue_Node_Access;
Params : Address)
return Boolean is
begin
return The_Node = QNA_Conv.To_Pointer (Params);
end Uncall_Filter;
procedure Uncall (
Object : not null access Entries.Protection_Entries'Class;
Item : not null Synchronous_Objects.Queue_Node_Access;
Already_Taken : out Boolean);
procedure Uncall (
Object : not null access Entries.Protection_Entries'Class;
Item : not null Synchronous_Objects.Queue_Node_Access;
Already_Taken : out Boolean)
is
Taken : Synchronous_Objects.Queue_Node_Access;
begin
Synchronous_Objects.Take (
Object.Calling,
Taken,
QNA_Conv.To_Address (Item),
Uncall_Filter'Access);
Already_Taken := Taken = null;
pragma Assert (Taken = null or else Taken = Item);
end Uncall;
function Invoke_Filter (
The_Node : not null Synchronous_Objects.Queue_Node_Access;
Params : Address)
return Boolean;
function Invoke_Filter (
The_Node : not null Synchronous_Objects.Queue_Node_Access;
Params : Address)
return Boolean
is
-- The_Node to Entries.Node
Node : constant not null Entries.Node_Access :=
Entries.Downcast (The_Node);
-- Params to access Entries.Protection_Entries'Class
function To_Pointer (Value : Address)
return access Entries.Protection_Entries'Class
with Import, Convention => Intrinsic;
Object : constant not null access Entries.Protection_Entries'Class :=
To_Pointer (Params);
Index : constant Positive_Protected_Entry_Index :=
Object.Find_Body_Index (Object.Compiler_Info, Node.E);
Result : Boolean;
begin
-- queue is locked in filter
Node.Action := False;
Node.Requeued := False;
begin
Result :=
Object.Entry_Bodies (Index).Barrier (Object.Compiler_Info, Node.E);
Node.Action := Result; -- execute the body after removing node
exception
when others =>
Object.Raised_On_Barrier := True;
Result := True;
-- C953001
Ada.Exceptions.Save_Exception (Node.X, Program_Error'Identity);
end;
return Result;
end Invoke_Filter;
procedure Invoke (
Object : not null access Entries.Protection_Entries'Class);
procedure Invoke (
Object : not null access Entries.Protection_Entries'Class)
is
function To_Address (Value : access Entries.Protection_Entries'Class)
return Address
with Import, Convention => Intrinsic;
Taken : Synchronous_Objects.Queue_Node_Access;
begin
pragma Assert (Object.Entry_Bodies'First = 1);
loop
Synchronous_Objects.Unsynchronized_Take (
Object.Calling,
Taken,
To_Address (Object),
Invoke_Filter'Access);
exit when Taken = null;
declare
Node : constant not null Entries.Node_Access :=
Entries.Downcast (Taken);
begin
if Node.Action then
declare
Index : constant Positive_Protected_Entry_Index :=
Object.Find_Body_Index (Object.Compiler_Info, Node.E);
begin
Object.Current_Calling := Node;
begin
Object.Entry_Bodies (Index).Action (
Object.Compiler_Info,
Node.Uninterpreted_Data,
Node.E);
exception
when E : others =>
Ada.Exceptions.Save_Occurrence (Node.X, E);
end;
Object.Current_Calling := null;
end;
end if;
if Node.Requeued then
-- internal requeue is a part of a single protected operation.
declare
Canceled : Boolean;
begin
Synchronous_Objects.Unsynchronized_Prepend (
Object.Calling,
Taken,
Canceled);
if Canceled then -- it does not happen ?
Ada.Exceptions.Save_Exception (
Node.X,
Tasking_Error'Identity);
end if;
end;
else
Synchronous_Objects.Set (Node.Waiting);
if Object.Raised_On_Barrier then
-- cancel all current callers, RM 9.5.3(7/3)
Object.Raised_On_Barrier := False;
Entries.Unlock_Entries (Object);
Entries.Cancel_Calls (Object.all);
Entries.Lock_Entries (Object);
end if;
end if;
end;
end loop;
end Invoke;
-- implementation
procedure Service_Entries (
Object : not null access Entries.Protection_Entries'Class) is
begin
-- already locked
Invoke (Object);
Entries.Unlock_Entries (Object);
end Service_Entries;
procedure Complete_Entry_Body (
Object : not null access Entries.Protection_Entries'Class) is
begin
null;
end Complete_Entry_Body;
procedure Exceptional_Complete_Entry_Body (
Object : not null access Entries.Protection_Entries'Class;
Id : Ada.Exceptions.Exception_Id)
is
Current_X : constant Ada.Exceptions.Exception_Occurrence_Access :=
Soft_Links.Get_Current_Excep.all;
begin
pragma Assert (Ada.Exceptions.Exception_Identity (Current_X.all) = Id);
Ada.Exceptions.Save_Occurrence (Object.Current_Calling.X, Current_X.all);
end Exceptional_Complete_Entry_Body;
procedure Protected_Entry_Call (
Object : not null access Entries.Protection_Entries'Class;
E : Protected_Entry_Index;
Uninterpreted_Data : Address;
Mode : Call_Modes;
Block : out Communication_Block)
is
pragma Unreferenced (Block);
begin
case Mode is
when Simple_Call =>
declare
package Holder is
new Ada.Exceptions.Finally.Scoped_Holder (
Synchronous_Objects.Event,
Synchronous_Objects.Finalize);
The_Node : aliased Entries.Node := (
Super => <>,
E => E,
Uninterpreted_Data => Uninterpreted_Data,
Caller => Task_Id_Conv.To_Address (Tasks.Current_Task_Id),
Action => False,
Requeued => False,
Waiting => <>, -- default initializer
X => <>); -- default initializer
Canceled : Boolean;
Aborted : Boolean;
begin
Synchronous_Objects.Initialize (The_Node.Waiting);
Holder.Assign (The_Node.Waiting);
Synchronous_Objects.Add (
Object.Calling,
The_Node.Super'Unchecked_Access,
Canceled);
if Canceled then
Raise_Exception (Tasking_Error'Identity);
end if;
Tasks.Enable_Abort;
Entries.Lock_Entries (Object);
Invoke (Object);
Entries.Unlock_Entries (Object);
Synchronous_Objects.Abortable.Wait (
The_Node.Waiting,
Aborted => Aborted);
if Aborted then
declare
Already_Taken : Boolean;
begin
Uncall (
Object,
The_Node.Super'Unchecked_Access,
Already_Taken => Already_Taken);
if Already_Taken then
Synchronous_Objects.Wait (The_Node.Waiting);
-- without abort checking
end if;
end;
end if;
Tasks.Disable_Abort (Aborted); -- if aborted, raise here
if Ada.Exceptions.Exception_Identity (The_Node.X) /=
Ada.Exceptions.Null_Id
then
Ada.Exceptions.Reraise_Nonnull_Occurrence (The_Node.X);
end if;
end;
when Conditional_Call =>
raise Program_Error;
when Asynchronous_Call =>
raise Program_Error;
end case;
end Protected_Entry_Call;
procedure Timed_Protected_Entry_Call (
Object : not null access Entries.Protection_Entries'Class;
E : Protected_Entry_Index;
Uninterpreted_Data : Address;
Timeout : Duration;
Mode : Integer;
Entry_Call_Successful : out Boolean) is
begin
raise Program_Error;
end Timed_Protected_Entry_Call;
function Enqueued (Block : Communication_Block) return Boolean is
begin
raise Program_Error;
return Enqueued (Block);
end Enqueued;
function Cancelled (Block : Communication_Block) return Boolean is
begin
raise Program_Error;
return Cancelled (Block);
end Cancelled;
procedure Cancel_Protected_Entry_Call (
Block : in out Communication_Block) is
begin
raise Program_Error;
end Cancel_Protected_Entry_Call;
procedure Requeue_Protected_Entry (
Object : not null access Entries.Protection_Entries'Class;
New_Object : not null access Entries.Protection_Entries'Class;
E : Protected_Entry_Index;
With_Abort : Boolean) is
begin
if With_Abort then
raise Program_Error;
end if;
if Object = New_Object then
-- internal requeue
Object.Current_Calling.E := E;
Object.Current_Calling.Requeued := True;
else
raise Program_Error;
end if;
end Requeue_Protected_Entry;
procedure Requeue_Task_To_Protected_Entry (
New_Object : not null access Entries.Protection_Entries'Class;
E : Protected_Entry_Index;
With_Abort : Boolean) is
begin
raise Program_Error;
end Requeue_Task_To_Protected_Entry;
function Protected_Entry_Caller (
Object : Entries.Protection_Entries'Class)
return Task_Id is
begin
return Object.Current_Calling.Caller;
end Protected_Entry_Caller;
function Protected_Count (
Object : Entries.Protection_Entries'Class;
E : Protected_Entry_Index)
return Natural is
begin
-- locked because 'Count is called only from barriers or bodies
return Synchronous_Objects.Unsynchronized_Count (
Object.Calling,
System'To_Address (E),
Filter'Access);
end Protected_Count;
end System.Tasking.Protected_Objects.Operations;
|
with Ada.Text_IO, Ada.Numerics.Generic_Elementary_Functions;
procedure Arith_Geom_Mean is
type Num is digits 18; -- the largest value gnat/gcc allows
package N_IO is new Ada.Text_IO.Float_IO(Num);
package Math is new Ada.Numerics.Generic_Elementary_Functions(Num);
function AGM(A, G: Num) return Num is
Old_G: Num;
New_G: Num := G;
New_A: Num := A;
begin
loop
Old_G := New_G;
New_G := Math.Sqrt(New_A*New_G);
New_A := (Old_G + New_A) * 0.5;
exit when (New_A - New_G) <= Num'Epsilon;
-- Num'Epsilon denotes the relative error when performing arithmetic over Num
end loop;
return New_G;
end AGM;
begin
N_IO.Put(AGM(1.0, 1.0/Math.Sqrt(2.0)), Fore => 1, Aft => 17, Exp => 0);
end Arith_Geom_Mean;
|
pragma License (Unrestricted);
with Ada.Numerics.Generic_Complex_Arrays;
with Ada.Numerics.Long_Complex_Types;
with Ada.Numerics.Long_Real_Arrays;
package Ada.Numerics.Long_Complex_Arrays is
new Generic_Complex_Arrays (Long_Real_Arrays, Long_Complex_Types);
pragma Pure (Ada.Numerics.Long_Complex_Arrays);
|
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Numerics.Discrete_Random;
use Ada.Text_IO, Ada.Integer_Text_IO;
package body stats is
Package RNG is new Ada.Numerics.Discrete_Random(Integer);
Use RNG;
Gen : Generator;
Procedure Instantiate is
begin
Reset(Gen);
End Instantiate;
function randomRange(to : Integer) return Integer is
begin
return Random(Gen) mod to + 1;
end randomRange;
function randomZero(to: Integer) return Integer is
begin
return Random(Gen) mod to;
end randomZero;
function "*" (L:Integer; R:Float) return Integer is
begin
return Integer(Float(L) * R);
end "*";
function rand return Integer is
begin
return RNG.Random(Gen);
end rand;
Procedure calculateDamage(by, to : in out statType; damage : out integer; ignoreDefense : Boolean := false) is
defensePercent : Integer;
hit : Integer;
begin
defensePercent := (100*to.defense)/to.MaxHP;
hit := randomRange(200);
if (ignoreDefense = false) then
damage := by.attack - (defensePercent * by.attack)/100;
if damage < 1 then
damage := 1;
end if;
else
hit := 200;
damage := by.attack;
end if;
if hit > to.agility then
to.HP := to.HP - damage;
if to.HP < 0 then
to.HP := 0;
end if;
else
damage := 0;
end if;
end calculateDamage;
procedure setStats(obj : in out statType;HP, MG, ATK, DEF, AGT, LV : Integer) is
begin
obj.Level := LV;
obj.HP := HP;
obj.MaxHP := HP;
obj.Magic := MG;
obj.MaxMag := MG;
obj.Attack := ATK;
obj.Defense := DEF;
obj.Agility := AGT;
obj.XP := 0;
end setStats;
Procedure addXP(exp : in integer; stats : in out statType) is
xpTilNextLvl : Integer := (50 + (stats.Level * 50));
magicBuffs : Integer;
attackBuffs : Integer;
defenseBuffs : Integer;
currHPpercent : Integer;
currMagPercent : Integer;
begin
stats.XP := stats.XP + exp;
magicBuffs := stats.MaxMag - (90 + (stats.Level * 10));
attackBuffs := stats.attack - (stats.Level * 10);
defenseBuffs := stats.defense - (stats.Level * 5);
loop
exit when stats.XP < xpTilNextLvl;
stats.Level := stats.Level + 1;
stats.XP := stats.XP - xpTilNextLvl;
xpTilNextLvl := (50 + (stats.Level * 50));
currHPpercent := (100*stats.HP)/stats.MaxHP;
currMagPercent := (100*stats.Magic)/stats.MaxMag;
stats.MaxHP := (90 + (stats.Level * 10));
stats.MaxMag := (90 + (stats.Level * 10));
--put(" Magic Buffs:");
--put(magicBuffs);
stats.MaxMag := stats.MaxMag + magicBuffs;
stats.attack := (stats.Level * 10);
--put(" Attack Buffs:");
--put(attackBuffs);
stats.attack := stats.attack + attackBuffs;
stats.defense := (stats.Level * 5);
--put(" Defense Buffs:");
--put(defenseBuffs);
stats.defense := stats.defense + defenseBuffs;
stats.agility := (stats.Level * 2);
stats.HP := (currHPpercent * stats.MaxHP)/100;
stats.Magic := (currMagPercent * stats.MaxMag)/100;
end loop;
end addXP;
end stats; |
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 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.
package Orka.SIMD.SSE.Singles.Swizzle is
pragma Pure;
function Shuffle (Left, Right : m128; Mask : Unsigned_32) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_shufps";
-- Shuffle the 32-bit floats in Left and Right using the given Mask. The first
-- and second floats (lower half) are retrieved from Left, the third and fourth
-- floats (upper half) from Right.
--
-- The compiler needs access to the Mask at compile-time, thus construct it
-- as follows:
--
-- Mask_a_b_c_d : constant Unsigned_32 := a or b * 4 or c * 16 or d * 64;
--
-- a and b select the floats to use from Left, c and d from Right.
function Unpack_High (Left, Right : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_unpckhps";
-- Unpack and interleave the 32-bit floats from the upper halves of
-- Left and Right as follows: Left (3), Right (3), Left (4), Right (4)
function Unpack_Low (Left, Right : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_unpcklps";
-- Unpack and interleave the 32-bit floats from the lower halves of
-- Left and Right as follows: Left (1), Right (1), Left (2), Right (2)
function Move_LH (Left, Right : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_movlhps";
-- Move the two lower floats from Right to the two upper floats of Left:
-- Left (1), Left (2), Right (1), Right (2)
function Move_HL (Left, Right : m128) return m128
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_movhlps";
-- Move the two upper floats from Right to the two lower floats of Left:
-- Right (3), Right (4), Left (3), Left (4)
function Duplicate_LH (Elements : m128) return m128 is
(Move_LH (Elements, Elements))
with Inline;
function Duplicate_HL (Elements : m128) return m128 is
(Move_HL (Elements, Elements))
with Inline;
procedure Transpose (Matrix : in out m128_Array)
with Inline;
function Transpose (Matrix : m128_Array) return m128_Array
with Inline;
end Orka.SIMD.SSE.Singles.Swizzle;
|
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- A D A . C O N T A I N E R S . R E D _ B L A C K _ T R E E S . --
-- G E N E R I C _ S E T _ O P E R A T I O N S --
-- --
-- S p e c --
-- --
-- This specification is adapted from the Ada Reference Manual for use with --
-- GNAT. In accordance with the copyright of that document, you can freely --
-- copy and modify this specification, provided that if you redistribute a --
-- modified version, any changes that you have made are clearly indicated. --
-- --
------------------------------------------------------------------------------
with Ada.Containers.Red_Black_Trees.Generic_Operations;
generic
with package Tree_Operations is new Generic_Operations (<>);
use Tree_Operations.Tree_Types;
with procedure Insert_With_Hint
(Dst_Tree : in out Tree_Type;
Dst_Hint : Node_Access;
Src_Node : Node_Access;
Dst_Node : out Node_Access);
with function Copy_Tree (Source_Root : Node_Access)
return Node_Access;
with procedure Delete_Tree (X : in out Node_Access);
with function Is_Less (Left, Right : Node_Access) return Boolean;
with procedure Free (X : in out Node_Access);
package Ada.Containers.Red_Black_Trees.Generic_Set_Operations is
pragma Pure;
procedure Union (Target : in out Tree_Type; Source : Tree_Type);
function Union (Left, Right : Tree_Type) return Tree_Type;
procedure Intersection (Target : in out Tree_Type; Source : Tree_Type);
function Intersection (Left, Right : Tree_Type) return Tree_Type;
procedure Difference (Target : in out Tree_Type; Source : Tree_Type);
function Difference (Left, Right : Tree_Type) return Tree_Type;
procedure Symmetric_Difference
(Target : in out Tree_Type;
Source : Tree_Type);
function Symmetric_Difference (Left, Right : Tree_Type) return Tree_Type;
function Is_Subset (Subset : Tree_Type; Of_Set : Tree_Type) return Boolean;
function Overlap (Left, Right : Tree_Type) return Boolean;
end Ada.Containers.Red_Black_Trees.Generic_Set_Operations;
|
with Interfaces;
with Atomic.Signed;
package Atomic.Signed_16 is new Atomic.Signed (Interfaces.Integer_16);
|
with System.Formatting.Fixed;
with System.Formatting.Float;
package body System.Img_Real is
procedure Image_Ordinary_Fixed_Point (
V : Long_Long_Float;
S : in out String;
P : out Natural;
Aft : Natural)
is
Fore_Last : Natural;
begin
Formatting.Fixed.Image (
V,
S,
Fore_Last,
P,
Aft_Width => Aft);
end Image_Ordinary_Fixed_Point;
procedure Image_Floating_Point (
V : Long_Long_Float;
S : in out String;
P : out Natural;
Digs : Natural)
is
Fore_Last : Natural;
begin
Formatting.Float.Image (
V,
S,
Fore_Last,
P,
Aft_Width => Digs - 1);
end Image_Floating_Point;
end System.Img_Real;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Ejercicio1 is
task Tarea1;
task Tarea2;
task Tarea3;
task body Tarea1 is
begin
for I in 1..10 loop
Put_Line("Soy T1");
--delay 1.0;
end loop;
end Tarea1;
task body Tarea2 is
begin
for I in 1..15 loop
Put_Line("Soy T2");
--delay 1.0;
end loop;
end Tarea2;
task body Tarea3 is
begin
for I in 1..4 loop
Put_Line("Soy T3");
--delay 1.0;
end loop;
end Tarea3;
begin
for I in 0..7 loop
Put_Line("Soy P");
end loop;
end Ejercicio1;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with Glfw.Display;
with Glfw.Display.Modes;
with Glfw.Events;
with Glfw.Events.Keys;
with Ada.Text_IO;
procedure Glfw_Test.Display is
procedure Write_Mode (Subject : Glfw.Display.Modes.Mode) is
begin
Ada.Text_IO.Put (Subject.Width'Img & " x" & Subject.Height'Img);
Ada.Text_IO.Put ("; RGB:" & Subject.Red_Bits'Img & " +"
& Subject.Green_Bits'Img & " +"
& Subject.Blue_Bits'Img);
Ada.Text_IO.New_Line;
end Write_Mode;
begin
Glfw.Init;
Glfw.Display.Open (Mode => Glfw.Display.Window);
Glfw.Events.Keys.Set_Key_Callback (Glfw_Test.Key_To_Title'Access);
declare
Mode_List : Glfw.Display.Modes.Mode_List := Glfw.Display.Modes.Available_Modes;
Desktop_Mode : Glfw.Display.Modes.Mode := Glfw.Display.Modes.Desktop_Mode;
begin
Ada.Text_IO.Put_Line ("---- Video Modes ----");
for Index in Mode_List'Range loop
Write_Mode (Mode_List (Index));
end loop;
Ada.Text_IO.Put ("Current: ");
Write_Mode (Desktop_Mode);
end;
while Glfw.Display.Opened loop
Glfw.Events.Wait_For_Events;
end loop;
Glfw.Terminate_Glfw;
end Glfw_Test.Display;
|
with Ada.Unchecked_Conversion;
with System.Storage_Map;
with C.basetsd;
with C.winternl;
package body System.Native_Tasks is
use type C.char_array;
use type C.windef.DWORD;
use type C.windef.WINBOOL;
use type C.winnt.HANDLE; -- C.void_ptr
type struct_THREAD_BASIC_INFORMATION is record
ExitStatus : C.winternl.NTSTATUS;
TebBaseAddress : C.winnt.struct_TEB_ptr; -- PVOID;
ClientId : C.winternl.CLIENT_ID;
AffinityMask : C.basetsd.KAFFINITY;
Priority : C.winternl.KPRIORITY;
BasePriority : C.winternl.KPRIORITY;
end record
with Convention => C;
pragma Suppress_Initialization (struct_THREAD_BASIC_INFORMATION);
type NtQueryInformationThread_Type is access function (
ThreadHandle : C.winnt.HANDLE;
ThreadInformationClass : C.winternl.THREADINFOCLASS;
ThreadInformation : C.winnt.PVOID;
ThreadInformationLength : C.windef.ULONG;
ReturnLength : access C.windef.ULONG)
return C.winternl.NTSTATUS
with Convention => WINAPI;
NtQueryInformationThread_Name : constant C.char_array (0 .. 24) :=
"NtQueryInformationThread" & C.char'Val (0);
procedure Nop is null;
Installed_Abort_Handler : not null Abort_Handler := Nop'Access;
-- implementation of thread
procedure Create (
Handle : aliased out Handle_Type;
Parameter : Parameter_Type;
Thread_Body : Thread_Body_Type;
Error : out Boolean)
is
Id : aliased C.windef.DWORD;
begin
Handle := C.winbase.CreateThread (
lpThreadAttributes => null,
dwStackSize => 0,
lpStartAddress => Thread_Body,
lpParameter => Parameter,
dwCreationFlags => 0,
lpThreadId => Id'Access);
Error := Handle = C.winbase.INVALID_HANDLE_VALUE;
end Create;
procedure Join (
Handle : Handle_Type;
Current_Abort_Event : access Synchronous_Objects.Event;
Result : aliased out Result_Type;
Error : out Boolean)
is
Signaled : C.windef.DWORD;
begin
Error := False;
if Current_Abort_Event /= null then
declare
Handles : aliased array (0 .. 1) of aliased C.winnt.HANDLE :=
(Handle, Synchronous_Objects.Handle (Current_Abort_Event.all));
begin
Signaled :=
C.winbase.WaitForMultipleObjects (
2,
Handles (0)'Access,
0,
C.winbase.INFINITE);
if Signaled /= C.winbase.WAIT_OBJECT_0 + 1 then
goto Done;
end if;
Installed_Abort_Handler.all; -- may abort child tasks
end;
end if;
Signaled := C.winbase.WaitForSingleObject (Handle, C.winbase.INFINITE);
<<Done>>
case Signaled is
when C.winbase.WAIT_OBJECT_0 =>
if C.winbase.GetExitCodeThread (Handle, Result'Access) =
C.windef.FALSE
then
Error := True;
end if;
when others =>
Error := True;
end case;
if C.winbase.CloseHandle (Handle) = C.windef.FALSE then
Error := True;
end if;
end Join;
procedure Detach (
Handle : in out Handle_Type;
Error : out Boolean) is
begin
Error := False;
if C.winbase.CloseHandle (Handle) = C.windef.FALSE then
Error := True;
else
Handle := C.winbase.GetCurrentThread;
-- magic value meaning current thread
pragma Assert (
Handle = C.winnt.HANDLE (System'To_Address (16#fffffffe#)));
end if;
end Detach;
-- implementation of stack
function Info_Block (Handle : Handle_Type) return C.winnt.struct_TEB_ptr is
function To_NtQueryInformationThread_Type is
new Ada.Unchecked_Conversion (
C.windef.FARPROC,
NtQueryInformationThread_Type);
NtQueryInformationThread : NtQueryInformationThread_Type;
begin
NtQueryInformationThread :=
To_NtQueryInformationThread_Type (
C.winbase.GetProcAddress (
Storage_Map.NTDLL,
NtQueryInformationThread_Name (0)'Access));
if NtQueryInformationThread = null then
return null; -- ???
else
declare
TBI : aliased struct_THREAD_BASIC_INFORMATION;
ReturnLength : aliased C.windef.ULONG;
Dummy_Status : C.winternl.NTSTATUS;
begin
Dummy_Status := NtQueryInformationThread (
Handle,
C.winternl.ThreadBasicInformation,
C.windef.LPVOID (TBI'Address),
struct_THREAD_BASIC_INFORMATION'Size / Standard'Storage_Unit,
ReturnLength'Access);
return TBI.TebBaseAddress;
end;
end if;
end Info_Block;
-- implementation of signals
procedure Install_Abort_Handler (Handler : Abort_Handler) is
begin
Installed_Abort_Handler := Handler;
end Install_Abort_Handler;
procedure Uninstall_Abort_Handler is
begin
Installed_Abort_Handler := Nop'Access;
end Uninstall_Abort_Handler;
procedure Send_Abort_Signal (
Handle : Handle_Type;
Abort_Event : in out Synchronous_Objects.Event;
Error : out Boolean)
is
pragma Unreferenced (Handle);
begin
Synchronous_Objects.Set (Abort_Event);
Error := False;
end Send_Abort_Signal;
procedure Block_Abort_Signal (Abort_Event : Synchronous_Objects.Event) is
begin
-- check aborted
if Synchronous_Objects.Get (Abort_Event) then
Installed_Abort_Handler.all;
end if;
end Block_Abort_Signal;
procedure Yield is
begin
C.winbase.Sleep (0);
end Yield;
end System.Native_Tasks;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure main is
G : Integer := 659;
P : Integer := 929;
Privkey1 : Integer := 397;
PrivKey2 : Integer := 800;
bit : array (0 .. 1) of Character := ('0', '1');
function bin_image(N : Natural) return string is
(if N < 2 then (1 => bit(n)) else bin_image(n/2) & bit (n mod 2));
function ModularExponentiation(b : Integer; n : String; m : Natural) return Integer is
X : Integer := 1;
Power : Integer := b mod m;
begin
for i in reverse 0 .. n'length -1 loop
if n(n'first + i) = '1' then
X:= (X * Power) mod m;
end if;
power := (Power * Power) mod m;
end loop;
return X;
end ModularExponentiation;
protected type Person is
procedure SetPrivKey(i : in Natural);
function GetPublicKey return Integer;
procedure CalcSharedPrivateKey(PubKey : in Integer);
function GetPrivKey return Integer;
function GetSharedPrivateKey return Integer;
private
PrivKey : Natural;
SharedPrivKey : Integer;
end Person;
protected body Person is
function GetPrivKey return Integer is
begin
return PrivKey;
end GetPrivKey;
procedure SetPrivKey(i : in Natural) is
begin
PrivKey := i;
end SetPrivKey;
function GetPublicKey return Integer is
begin
--return (G ** PrivKey) mod P;
return ModularExponentiation(G, bin_image(PrivKey), P);
end GetPublicKey;
procedure CalcSharedPrivateKey(PubKey : in Integer) is
begin
--SharedPrivKey := (PubKey ** PrivKey) mod P;
SharedPrivKey := ModularExponentiation(PubKey, bin_image(PrivKey), P);
end CalcSharedPrivateKey;
function GetSharedPrivateKey return Integer is
begin
return SharedPrivKey;
end GetSharedPrivateKey;
end Person;
Alice : Person;
Bob : Person;
begin
Alice.SetPrivKey(PrivKey1);
Bob.SetPrivKey(PrivKey2);
Put_Line("Generator: " & Integer'Image(G));
Put_Line("Primenumb: " & Integer'Image(P));
Put_Line("Alice Priv: " & Integer'Image(Alice.GetPrivKey));
Put_Line("Bob Priv: " & Integer'Image(Bob.GetPrivKey));
Put_Line("Alice PUB: " & Integer'Image(Alice.GetPublicKey));
Put_Line("Bob PUB: " & Integer'Image(Bob.GetPublicKey));
Alice.CalcSharedPrivateKey(Bob.GetPublicKey);
Bob.CalcSharedPrivateKey(Alice.GetPublicKey);
Put_Line("Alice Shared Private Key is: " & Integer'Image(Alice.GetSharedPrivateKey));
Put_Line("Bob Shared Private Key is: " & Integer'Image(Bob.GetSharedPrivateKey));
end main; |
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . I M A G E _ F --
-- --
-- S p e c --
-- --
-- Copyright (C) 2020-2021, 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. --
-- --
-- --
-- --
-- --
-- --
-- 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 package contains the routines for supporting the Image attribute for
-- ordinary fixed point types whose Small is the ratio of two Int values, and
-- also for conversion operations required in Text_IO.Fixed_IO for such types.
generic
type Int is range <>;
with procedure Scaled_Divide
(X, Y, Z : Int;
Q, R : out Int;
Round : Boolean);
package System.Image_F is
pragma Pure;
procedure Image_Fixed
(V : Int;
S : in out String;
P : out Natural;
Num : Int;
Den : Int;
For0 : Natural;
Aft0 : Natural);
-- Computes fixed_type'Image (V), where V is the integer value (in units of
-- small) of an ordinary fixed point type with small Num/Den, and stores
-- the result in S (1 .. P), updating P on return. The result is computed
-- according to the rules for image for fixed-point types (RM 3.5(34)).
-- For0 and Aft0 are the values of the Fore and Aft attributes for the
-- fixed point type whose mantissa type is Int and whose small is Num/Den.
-- This function is used only for fixed point whose Small is an integer or
-- its reciprocal (see package System.Image_R for the handling of other
-- ordinary fixed-point types). The caller guarantees that S is long enough
-- to hold the result and has a lower bound of 1.
procedure Set_Image_Fixed
(V : Int;
S : in out String;
P : in out Natural;
Num : Int;
Den : Int;
For0 : Natural;
Aft0 : Natural;
Fore : Natural;
Aft : Natural;
Exp : Natural);
-- Sets the image of V, where V is the integer value (in units of small)
-- of a fixed point type with small Num/Den, starting at S (P + 1) and
-- updating P to point to the last character stored, the caller promises
-- that the buffer is large enough and no check is made. Constraint_Error
-- will not necessarily be raised if this requirement is violated, since
-- it is perfectly valid to compile this unit with checks off. For0 and
-- Aft0 are the values of the Fore and Aft attributes for the fixed point
-- type whose mantissa type is Int and whose small is Num/Den. The Fore,
-- Aft and Exp can be set to any valid values for use by Text_IO.Fixed_IO.
end System.Image_F;
|
-- Copyright (c) 2021 Devin Hill
-- zlib License -- see LICENSE for details.
with GBA.BIOS;
with GBA.BIOS.Arm;
with GBA.BIOS.Thumb;
with GBA.Display;
with GBA.Display.Backgrounds;
with GBA.Display.Objects;
with GBA.Display.Palettes;
with GBA.Display.Tiles;
with GBA.Memory;
with GBA.Numerics;
with GBA.Input;
with GBA.Input.Buffered;
with GBA.Interrupts;
with Interfaces;
procedure Sprites is
use GBA.BIOS;
use GBA.BIOS.Arm;
use GBA.Display;
use GBA.Display.Backgrounds;
use GBA.Display.Objects;
use GBA.Display.Palettes;
use GBA.Display.Tiles;
use GBA.Input;
use GBA.Input.Buffered;
use GBA.Numerics;
use Interfaces;
Tile_Red : constant Tile_Data_4 :=
( ( 0, 0, 1, 1, 1, 1, 0, 0 )
, ( 0, 1, 1, 1, 1, 1, 1, 0 )
, ( 1, 1, 1, 1, 1, 1, 1, 1 )
, ( 1, 1, 1, 1, 1, 1, 1, 1 )
, ( 1, 1, 1, 1, 1, 1, 1, 1 )
, ( 1, 1, 1, 1, 1, 1, 1, 1 )
, ( 0, 1, 1, 1, 1, 1, 1, 0 )
, ( 0, 0, 1, 1, 1, 1, 0, 0 ) );
Tile_Blue : constant Tile_Data_4 :=
( ( 0, 0, 2, 2, 2, 2, 0, 0 )
, ( 0, 2, 2, 2, 2, 2, 2, 0 )
, ( 2, 2, 2, 2, 2, 2, 2, 2 )
, ( 2, 2, 2, 2, 2, 2, 2, 2 )
, ( 2, 2, 2, 2, 2, 2, 2, 2 )
, ( 2, 2, 2, 2, 2, 2, 2, 2 )
, ( 0, 2, 2, 2, 2, 2, 2, 0 )
, ( 0, 0, 2, 2, 2, 2, 0, 0 ) );
Tile_Green : constant Tile_Data_4 :=
( ( 0, 0, 3, 3, 3, 3, 0, 0 )
, ( 0, 3, 3, 3, 3, 3, 3, 0 )
, ( 3, 3, 3, 3, 3, 3, 3, 3 )
, ( 3, 3, 3, 3, 3, 3, 3, 3 )
, ( 3, 3, 3, 3, 3, 3, 3, 3 )
, ( 3, 3, 3, 3, 3, 3, 3, 3 )
, ( 0, 3, 3, 3, 3, 3, 3, 0 )
, ( 0, 0, 3, 3, 3, 3, 0, 0 ) );
Tile_Red_ID : constant OBJ_Tile_Index := 1;
Tile_Blue_ID : constant OBJ_Tile_Index := 2;
Tile_Green_ID : constant OBJ_Tile_Index := 3;
function Initial_Attributes_State (Tile : OBJ_Tile_Index) return OBJ_Attributes;
pragma Machine_Attribute (Initial_Attributes_State, "target", "thumb");
function Initial_Attributes_State (Tile : OBJ_Tile_Index)
return OBJ_Attributes is
begin
return
( Kind => Regular
, Mode => Normal
, Tile_Index => Tile
, Palette_Index => 0
, Color_Mode => Colors_16
, Disabled => False
, Priority => 0
, Shape => Square
, Scale => 0
, X => 120
, Y => 80
, Enable_Mosaic => False
, Flip_Horizontal => False
, Flip_Vertical => False
);
end Initial_Attributes_State;
procedure BIOS_Sin_Cos (Theta : Radians_32; Sin, Cos : out Fixed_8_8)
with No_Inline;
pragma Machine_Attribute (BIOS_Sin_Cos, "target", "thumb");
procedure BIOS_Sin_Cos (Theta : Radians_32; Sin, Cos : out Fixed_8_8) is
Affine_Sin_Cos : Affine_Transform_Matrix;
begin
GBA.BIOS.Thumb.Affine_Set
( Transform => Affine_Sin_Cos
, Parameters =>
( Scale_X | Scale_Y => 1.0
, Angle => Radians_16 (Theta)
)
);
Sin := Affine_Sin_Cos.DY;
Cos := Affine_Sin_Cos.DX;
end;
X_Center : constant OBJ_X_Coordinate := 116;
Y_Center : constant OBJ_Y_Coordinate := 76;
procedure Set_Position (ID : OBJ_ID; X : OBJ_X_Coordinate; Y : OBJ_Y_Coordinate)
with Linker_Section => ".iwram" is
Attrs : OBJ_Attributes := Attributes_Of_Object (ID);
begin
Attrs.X := X_Center + X;
Attrs.Y := Y_Center + Y;
Set_Object_Attributes (ID, Attrs);
end;
Color_Palette : Palette_16_Ptr := OBJ_Palette_16x16 (0)'Access;
Theta : Radians_32 := 0.0;
X_Scale : constant Fixed_20_8 := 70.0;
Y_Scale : constant Fixed_20_8 := 70.0;
begin
OBJ_Tile_Memory_4 (Tile_Red_ID) := Tile_Red;
OBJ_Tile_Memory_4 (Tile_Blue_ID) := Tile_Blue;
OBJ_Tile_Memory_4 (Tile_Green_ID) := Tile_Green;
Color_Palette (0 .. 5) :=
( ( 0, 0, 0)
, (29, 9, 11)
, (00, 26, 26)
, (19, 26, 21)
, (31, 25, 21)
, (31, 16, 15)
);
Set_Object_Attributes (0, Initial_Attributes_State (Tile_Red_ID));
Set_Object_Attributes (1, Initial_Attributes_State (Tile_Blue_ID));
Set_Object_Attributes (2, Initial_Attributes_State (Tile_Green_ID));
GBA.Interrupts.Enable_Receiving_Interrupts;
GBA.Interrupts.Enable_Interrupt (GBA.Interrupts.VBlank);
Request_VBlank_Interrupt;
Wait_For_VBlank;
Set_Display_Mode (Mode_0);
Enable_Display_Element (Object_Sprites);
loop
Update_Key_State;
declare
Sin, Cos : Fixed_Snorm_32;
begin
Sin_Cos (Theta, Sin, Cos);
Set_Position
( 0
, OBJ_X_Coordinate (Integer (Fixed_20_8 (Sin) * X_Scale) / (2 ** 8))
, OBJ_Y_Coordinate (Integer (Fixed_20_8 (Cos) * Y_Scale) / (2 ** 8))
);
end;
declare
Sin, Cos : Fixed_Snorm_16;
One_Third : constant Radians_32 := 1.0 / 3.0;
begin
Sin_Cos_LUT (Radians_16 (Theta + One_Third), Sin, Cos);
Set_Position
( 1
, OBJ_X_Coordinate (Integer (Fixed_20_8 (Sin) * X_Scale) / (2 ** 8))
, OBJ_Y_Coordinate (Integer (Fixed_20_8 (Cos) * Y_Scale) / (2 ** 8))
);
end;
declare
Sin, Cos : Fixed_8_8;
Two_Thirds : constant Radians_32 := 2.0 / 3.0;
begin
BIOS_Sin_Cos (Theta + Two_Thirds, Sin, Cos);
Set_Position
( 2
, OBJ_X_Coordinate (Integer (Fixed_20_8 (Sin) * X_Scale) / (2 ** 8))
, OBJ_Y_Coordinate (Integer (Fixed_20_8 (Cos) * Y_Scale) / (2 ** 8))
);
end;
if Are_Any_Down (A_Button or B_Button) then
Theta := @ + (1.0 / 128.0);
else
Theta := @ + (1.0 / 512.0);
end if;
Wait_For_VBlank;
end loop;
end;
|
with Ada.Streams.Stream_IO, Ada.Directories;
use Ada.Streams.Stream_IO, Ada.Directories;
procedure File_Creation is
File_Handle : File_Type;
begin
Create (File_Handle, Out_File, "output.txt");
Close (File_Handle);
Create_Directory("docs");
Create (File_Handle, Out_File, "/output.txt");
Close (File_Handle);
Create_Directory("/docs");
end File_Creation;
|
with
FLTK.Menu_Items;
package FLTK.Widgets.Menus.Menu_Buttons is
type Menu_Button is new Menu with private;
type Menu_Button_Reference (Data : access Menu_Button'Class) is limited null record
with Implicit_Dereference => Data;
-- signifies which mouse buttons cause the menu to appear
type Popup_Buttons is (No_Popup, Popup1, Popup2, Popup12, Popup3, Popup13, Popup23, Popup123);
package Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Menu_Button;
end Forge;
procedure Set_Popup_Kind
(This : in out Menu_Button;
Pop : in Popup_Buttons);
function Popup
(This : in out Menu_Button)
return FLTK.Menu_Items.Menu_Item;
procedure Draw
(This : in out Menu_Button);
function Handle
(This : in out Menu_Button;
Event : in Event_Kind)
return Event_Outcome;
private
type Menu_Button is new Menu with null record;
overriding procedure Finalize
(This : in out Menu_Button);
pragma Inline (Set_Popup_Kind);
pragma Inline (Popup);
pragma Inline (Draw);
pragma Inline (Handle);
end FLTK.Widgets.Menus.Menu_Buttons;
|
with Multivectors;
package Multivector_Utilities is
MV_Utilities_Exception : Exception;
function Factorize_Blades (MV_B : Multivectors.Multivector; Scale : out Float)
return Multivectors.Multivector_List;
function Factorize_Blade_Fast (MV_B : Multivectors.Multivector;
Scale : out Float)
return Multivectors.Multivector_List;
function Reflect (MV : Multivectors.Multivector;
DP: Multivectors.Dual_Plane)
return Multivectors.Multivector;
function Rotate (MV : Multivectors.Multivector;
aVersor: Multivectors.TR_Versor)
return Multivectors.Multivector;
end Multivector_Utilities;
|
-- Task 2 of RTPL WS17/18
-- Team members: Hannes B. and Gabriel Z.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; -- For float input
-- with Ada.Numerics.Generic_Elementary_Functions;
package body calculate with SPARK_Mode is
-- Procedure for option 4
procedure opt4 is
begin
-- User input
Put_Line ("Please input (x / y / z) values of a vector:");
Put ("x: ");
Ada.Float_Text_IO.Get (V1.x);
Put ("y: ");
Ada.Float_Text_IO.Get (V1.y);
Put ("z: ");
Ada.Float_Text_IO.Get (V1.z);
-- Print results
Put ("Result: ");
Ada.Float_Text_IO.Put (myVecAbs (V1), 2, 2, 0);
end opt4;
function myVecAbs (vec : myVec) return Float is
sum : Float := 0.0;
mag : Float := 0.0;
begin
-- Replace this with the correct function
sum := vec.x * vec.x + vec.y * vec.y + vec.z * vec.z;
mag := sqrt (sum);
return mag;
end myVecAbs;
function sqrt (x : Float) return Float is
root : Float := x / 3.0;
root_prev : Float := root;
begin
if x <= 0.0 then
return 0.0;
end if;
for i in Integer range 0 .. 31 loop
root_prev := root;
root := (root + x / root) / 2.0;
exit when root_prev = root;
end loop;
return root;
end sqrt;
-- Declaration of generic function
generic
type Element_T is private;
with function "+" (x, y : Element_T) return Element_T;
function myAdd (x, y : in Element_T) return Element_T;
-- Definition of generic function
function myAdd (x, y : in Element_T) return Element_T is
begin
return x + y;
end myAdd;
-- Procedure for option 9
procedure opt9 is
-- Instanciation of generic function
function Add_Float is new myAdd (Element_T => Float, "+" => "+");
-- Float values for user input
F1 : Float := 0.0;
F2 : Float := 0.0;
F3 : Float;
begin
-- User input
Put_Line ("Please input two floats to be added:");
Put ("First: ");
Ada.Float_Text_IO.Get (F1);
Put ("Second: ");
Ada.Float_Text_IO.Get (F2);
-- Calculate Sum
F3 := Add_Float (F1, F2);
-- Print Sum
Put ("Sum is: ");
Ada.Float_Text_IO.Put (F3, 2, 2, 0);
end opt9;
end calculate;
|
package PrimitivePropertyTypes is
type SomeClass is record
someInteger : Integer := 1;
someNatural : Natural := 2;
someBoolean : Boolean := False;
someString : String(1 .. 5) := "hello";
someFloat : Float := 1.1;
end record;
end PrimitivePropertyTypes;
|
-- { dg-do run }
-- { dg-options "-O" }
with Array28_Pkg; use Array28_Pkg;
procedure Array28 is
function Get return Outer_type is
Ret : Outer_Type;
begin
Ret (Inner_Type'Range) := F;
return Ret;
end;
A : Outer_Type := Get;
B : Inner_Type := A (Inner_Type'Range);
begin
if B /= "12345" then
raise Program_Error;
end if;
end;
|
with Vecteurs; use Vecteurs;
package STL is
-- Prend une liste de segments et cree l'objet 3d par rotations
-- Requiert Taille(Segments) > 0
procedure Creation(
Segments : in out Liste_Points.Liste ;
Facettes : out Liste_Facettes.Liste;
Nombre_Facettes : Positive);
-- Sauvegarde le fichier stl
procedure Sauvegarder(
Nom_Fichier : String ;
Facettes : Liste_Facettes.Liste);
end;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.