content
stringlengths
23
1.05M
with STM32GD.GPIO; with STM32GD.GPIO.Pin; with STM32GD.I2C; with STM32GD.I2C.Peripheral; with Drivers.Si7006; package Peripherals is package GPIO renames STM32GD.GPIO; package SCL is new GPIO.Pin (Pin => GPIO.Pin_6, Port => GPIO.Port_B, Mode => GPIO.Mode_AF, Alternate_Function => 1); package SCL_OUT is new GPIO.Pin (Pin => GPIO.Pin_6, Port => GPIO.Port_B, Mode => GPIO.Mode_Out); package SDA is new GPIO.Pin (Pin => GPIO.Pin_7, Port => GPIO.Port_B, Mode => GPIO.Mode_AF, Alternate_Function => 1); package I2C is new STM32GD.I2C.Peripheral ( I2C => STM32GD.I2C.I2C_1); package Si7006 is new Drivers.Si7006 (I2C => I2C); procedure Init; end Peripherals;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2015, 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 Ada.Unchecked_Conversion; with STM32_SVD.RCC; use STM32_SVD.RCC; with STM32_SVD.PWR; use STM32_SVD.PWR; with STM32_SVD.SYSCFG; use STM32_SVD.SYSCFG; with STM32_SVD.Flash; use STM32_SVD.Flash; package body STM32.RCC is function To_AHB1RSTR_T is new Ada.Unchecked_Conversion (UInt32, AHB1RSTR_Register); function To_AHB2RSTR_T is new Ada.Unchecked_Conversion (UInt32, AHB2RSTR_Register); function To_AHB3RSTR_T is new Ada.Unchecked_Conversion (UInt32, AHB3RSTR_Register); function To_AHB4RSTR_T is new Ada.Unchecked_Conversion (UInt32, AHB4RSTR_Register); function To_APB1LRSTR_T is new Ada.Unchecked_Conversion (UInt32, APB1LRSTR_Register); function To_APB1HRSTR_T is new Ada.Unchecked_Conversion (UInt32, APB1HRSTR_Register); function To_APB2RSTR_T is new Ada.Unchecked_Conversion (UInt32, APB2RSTR_Register); function To_APB3RSTR_T is new Ada.Unchecked_Conversion (UInt32, APB3RSTR_Register); function To_APB4RSTR_T is new Ada.Unchecked_Conversion (UInt32, APB4RSTR_Register); --------------------------------------------------------------------------- ------- Enable/Disable/Reset Routines ----------------------------------- --------------------------------------------------------------------------- procedure AHB_Force_Reset is begin RCC_Periph.AHB1RSTR := To_AHB1RSTR_T (16#FFFF_FFFF#); RCC_Periph.AHB2RSTR := To_AHB2RSTR_T (16#FFFF_FFFF#); RCC_Periph.AHB3RSTR := To_AHB3RSTR_T (16#FFFF_FFFF#); RCC_Periph.AHB4RSTR := To_AHB4RSTR_T (16#FFFF_FFFF#); end AHB_Force_Reset; procedure AHB_Release_Reset is begin RCC_Periph.AHB1RSTR := To_AHB1RSTR_T (0); RCC_Periph.AHB2RSTR := To_AHB2RSTR_T (0); RCC_Periph.AHB3RSTR := To_AHB3RSTR_T (0); RCC_Periph.AHB4RSTR := To_AHB4RSTR_T (0); end AHB_Release_Reset; procedure APB1_Force_Reset is begin RCC_Periph.APB1LRSTR := To_APB1LRSTR_T (16#FFFF_FFFF#); RCC_Periph.APB1HRSTR := To_APB1HRSTR_T (16#FFFF_FFFF#); end APB1_Force_Reset; procedure APB1_Release_Reset is begin RCC_Periph.APB1LRSTR := To_APB1LRSTR_T (0); RCC_Periph.APB1HRSTR := To_APB1HRSTR_T (0); end APB1_Release_Reset; procedure APB2_Force_Reset is begin RCC_Periph.APB2RSTR := To_APB2RSTR_T (16#FFFF_FFFF#); end APB2_Force_Reset; procedure APB2_Release_Reset is begin RCC_Periph.APB2RSTR := To_APB2RSTR_T (0); end APB2_Release_Reset; procedure APB3_Force_Reset is begin RCC_Periph.APB3RSTR := To_APB3RSTR_T (16#FFFF_FFFF#); end APB3_Force_Reset; procedure APB3_Release_Reset is begin RCC_Periph.APB3RSTR := To_APB3RSTR_T (0); end APB3_Release_Reset; procedure APB4_Force_Reset is begin RCC_Periph.APB4RSTR := To_APB4RSTR_T (16#FFFF_FFFF#); end APB4_Force_Reset; procedure APB4_Release_Reset is begin RCC_Periph.APB4RSTR := To_APB4RSTR_T (0); end APB4_Release_Reset; procedure Backup_Domain_Reset is begin RCC_Periph.BDCR.BDRST := True; RCC_Periph.BDCR.BDRST := False; end Backup_Domain_Reset; --------------------------------------------------------------------------- -- Clock Configuration -------------------------------------------------- --------------------------------------------------------------------------- ------------------- -- Set_HSE Clock -- ------------------- procedure Set_HSE_Clock (Enable : Boolean; Bypass : Boolean := False; Enable_CSS : Boolean := False) is begin if Enable and not RCC_Periph.CR.HSEON then RCC_Periph.CR.HSEON := True; loop exit when RCC_Periph.CR.HSERDY; end loop; end if; RCC_Periph.CR.HSEBYP := Bypass; RCC_Periph.CR.HSECSSON := Enable_CSS; end Set_HSE_Clock; ----------------------- -- HSE Clock_Enabled -- ----------------------- function HSE_Clock_Enabled return Boolean is begin return RCC_Periph.CR.HSEON; end HSE_Clock_Enabled; ------------------- -- Set_LSE Clock -- ------------------- procedure Set_LSE_Clock (Enable : Boolean; Bypass : Boolean := False; Enable_CSS : Boolean := False; Capability : HSE_Capability) is begin if Enable and not RCC_Periph.BDCR.LSEON then RCC_Periph.BDCR.LSEON := True; loop exit when RCC_Periph.BDCR.LSERDY; end loop; end if; RCC_Periph.BDCR.LSEBYP := Bypass; RCC_Periph.BDCR.LSECSSON := Enable_CSS; RCC_Periph.BDCR.LSEDRV := Capability'Enum_Rep; end Set_LSE_Clock; ----------------------- -- LSE Clock_Enabled -- ----------------------- function LSE_Clock_Enabled return Boolean is begin return RCC_Periph.BDCR.LSEON; end LSE_Clock_Enabled; ------------------- -- Set_HSI_Clock -- ------------------- procedure Set_HSI_Clock (Enable : Boolean; Value : HSI_Prescaler) is begin if Enable then if not RCC_Periph.CR.HSION then RCC_Periph.CR.HSION := True; loop exit when RCC_Periph.CR.HSIRDY; end loop; end if; RCC_Periph.CR.HSIDIV := Value'Enum_Rep; loop exit when RCC_Periph.CR.HSIDIVF; end loop; else RCC_Periph.CR.HSION := False; end if; end Set_HSI_Clock; ----------------------- -- HSI_Clock_Enabled -- ----------------------- function HSI_Clock_Enabled return Boolean is begin return RCC_Periph.CR.HSION; end HSI_Clock_Enabled; --------------------- -- Set_HSI48 Clock -- --------------------- procedure Set_HSI48_Clock (Enable : Boolean) is begin if Enable and not RCC_Periph.CR.HSI48ON then RCC_Periph.CR.HSI48ON := True; loop exit when RCC_Periph.CR.HSI48RDY; end loop; end if; end Set_HSI48_Clock; ------------------------- -- HSI48 Clock_Enabled -- ------------------------- function HSI48_Clock_Enabled return Boolean is begin return RCC_Periph.CR.HSI48ON; end HSI48_Clock_Enabled; ------------------- -- Set_LSI Clock -- ------------------- procedure Set_LSI_Clock (Enable : Boolean) is begin if Enable and not RCC_Periph.CSR.LSION then RCC_Periph.CSR.LSION := True; loop exit when RCC_Periph.CSR.LSIRDY; end loop; end if; end Set_LSI_Clock; ----------------------- -- LSI Clock_Enabled -- ----------------------- function LSI_Clock_Enabled return Boolean is begin return RCC_Periph.CSR.LSION; end LSI_Clock_Enabled; ------------------- -- Set_CSI Clock -- ------------------- procedure Set_CSI_Clock (Enable : Boolean) is begin if Enable and not RCC_Periph.CR.CSION then RCC_Periph.CR.CSION := True; loop exit when RCC_Periph.CR.CSIRDY; end loop; end if; end Set_CSI_Clock; ----------------------- -- CSI Clock_Enabled -- ----------------------- function CSI_Clock_Enabled return Boolean is begin return RCC_Periph.CR.CSION; end CSI_Clock_Enabled; -------------------------------- -- Configure_System_Clock_Mux -- -------------------------------- procedure Configure_System_Clock_Mux (Source : SYSCLK_Clock_Source) is begin RCC_Periph.CFGR.SW := Source'Enum_Rep; loop exit when RCC_Periph.CFGR.SWS = Source'Enum_Rep; end loop; end Configure_System_Clock_Mux; ----------------------------------- -- Configure_AHB_Clock_Prescaler -- ----------------------------------- procedure Configure_AHB_Clock_Prescaler (Bus : AHB_Clock_Range; Value : AHB_Prescaler) is function To_AHB is new Ada.Unchecked_Conversion (AHB_Prescaler, UInt4); begin case Bus is when AHB_1 => RCC_Periph.D1CFGR.D1CPRE := To_AHB (Value); when AHB_2 => RCC_Periph.D1CFGR.HPRE := To_AHB (Value); end case; end Configure_AHB_Clock_Prescaler; ----------------------------------- -- Configure_APB_Clock_Prescaler -- ----------------------------------- procedure Configure_APB_Clock_Prescaler (Bus : APB_Clock_Range; Value : APB_Prescaler) is function To_APB is new Ada.Unchecked_Conversion (APB_Prescaler, UInt3); begin case Bus is when APB_1 => RCC_Periph.D2CFGR.D2PPRE1 := To_APB (Value); when APB_2 => RCC_Periph.D2CFGR.D2PPRE2 := To_APB (Value); when APB_3 => RCC_Periph.D1CFGR.D1PPRE := To_APB (Value); when APB_4 => RCC_Periph.D3CFGR.D3PPRE := To_APB (Value); end case; end Configure_APB_Clock_Prescaler; ------------------------------ -- Configure_PLL_Source_Mux -- ------------------------------ procedure Configure_PLL_Source_Mux (Source : PLL_Clock_Source) is begin RCC_Periph.PLLCKSELR.PLLSRC := Source'Enum_Rep; end Configure_PLL_Source_Mux; ------------------- -- Configure_PLL -- ------------------- procedure Configure_PLL (PLL : PLL_Range; Enable : Boolean; Fractional_Mode : Boolean; Fraction : UInt13 := 16#0#; PLLM : PLLM_Range; PLLN : PLLN_Range; PLLP : PLLP_Range; Enable_Output_P : Boolean; PLLQ : PLLQ_Range; Enable_Output_Q : Boolean; PLLR : PLLR_Range; Enable_Output_R : Boolean; Input : PLL_Input_Frequency; VCO : PLL_VCO_Selector) is begin case PLL is when PLL_1 => -- Disable the main PLL before configuring it RCC_Periph.CR.PLL1ON := False; if Enable then -- Configure multiplication and division factors RCC_Periph.PLLCKSELR.DIVM1 := UInt6 (PLLM); if Fractional_Mode then RCC_Periph.PLL1FRACR.FRACN1 := Fraction; end if; RCC_Periph.PLLCFGR := (PLL1VCOSEL => VCO = Medium_150_To_420MHz, PLL1RGE => Input'Enum_Rep, PLL1FRACEN => Fractional_Mode, DIVP1EN => Enable_Output_P, DIVQ1EN => Enable_Output_Q, DIVR1EN => Enable_Output_R, others => <>); RCC_Periph.PLL1DIVR := (DIVN1 => UInt9 (PLLN - 1), DIVP1 => UInt7 (PLLP - 1), DIVQ1 => UInt7 (PLLQ - 1), DIVR1 => UInt7 (PLLR - 1), others => <>); -- Setup PLL and wait for stabilization. RCC_Periph.CR.PLL1ON := Enable; loop exit when RCC_Periph.CR.PLL1RDY; end loop; end if; when PLL_2 => -- Disable the main PLL before configuring it RCC_Periph.CR.PLL2ON := False; if Enable then -- Configure multiplication and division factors RCC_Periph.PLLCKSELR.DIVM2 := UInt6 (PLLM); if Fractional_Mode then RCC_Periph.PLL2FRACR.FRACN2 := Fraction; end if; RCC_Periph.PLLCFGR := (PLL2VCOSEL => VCO = Medium_150_To_420MHz, PLL2RGE => Input'Enum_Rep, PLL2FRACEN => Fractional_Mode, DIVP2EN => Enable_Output_P, DIVQ2EN => Enable_Output_Q, DIVR2EN => Enable_Output_R, others => <>); RCC_Periph.PLL2DIVR := (DIVN2 => UInt9 (PLLN - 1), DIVP2 => UInt7 (PLLP - 1), DIVQ2 => UInt7 (PLLQ - 1), DIVR2 => UInt7 (PLLR - 1), others => <>); -- Setup PLL and wait for stabilization. RCC_Periph.CR.PLL2ON := Enable; loop exit when RCC_Periph.CR.PLL2RDY; end loop; end if; when PLL_3 => -- Disable the main PLL before configuring it RCC_Periph.CR.PLL3ON := False; if Enable then -- Configure multiplication and division factors RCC_Periph.PLLCKSELR.DIVM3 := UInt6 (PLLM); if Fractional_Mode then RCC_Periph.PLL3FRACR.FRACN3 := Fraction; end if; RCC_Periph.PLLCFGR := (PLL3VCOSEL => VCO = Medium_150_To_420MHz, PLL3RGE => Input'Enum_Rep, PLL3FRACEN => Fractional_Mode, DIVP3EN => Enable_Output_P, DIVQ3EN => Enable_Output_Q, DIVR3EN => Enable_Output_R, others => <>); RCC_Periph.PLL3DIVR := (DIVN3 => UInt9 (PLLN - 1), DIVP3 => UInt7 (PLLP - 1), DIVQ3 => UInt7 (PLLQ - 1), DIVR3 => UInt7 (PLLR - 1), others => <>); -- Setup PLL and wait for stabilization. RCC_Periph.CR.PLL3ON := Enable; loop exit when RCC_Periph.CR.PLL3RDY; end loop; end if; end case; end Configure_PLL; ---------------------------- -- Configure_PLL_Fraction -- ---------------------------- procedure Configure_PLL_Fraction (PLL : PLL_Range; Fraction : UInt13) is begin case PLL is when PLL_1 => RCC_Periph.PLLCFGR.PLL1FRACEN := False; RCC_Periph.PLL1FRACR.FRACN1 := Fraction; RCC_Periph.PLLCFGR.PLL1FRACEN := True; when PLL_2 => RCC_Periph.PLLCFGR.PLL2FRACEN := False; RCC_Periph.PLL2FRACR.FRACN2 := Fraction; RCC_Periph.PLLCFGR.PLL2FRACEN := True; when PLL_3 => RCC_Periph.PLLCFGR.PLL3FRACEN := False; RCC_Periph.PLL3FRACR.FRACN3 := Fraction; RCC_Periph.PLLCFGR.PLL3FRACEN := True; end case; end Configure_PLL_Fraction; ------------------------------ -- Configure_PER_Source_Mux -- ------------------------------ procedure Configure_PER_Source_Mux (Source : PER_Clock_Source) is begin RCC_Periph.D1CCIPR.CKPERSEL := Source'Enum_Rep; end Configure_PER_Source_Mux; ------------------------------- -- Configure_TIM_Source_Mode -- ------------------------------- procedure Configure_TIM_Source_Mode (Source : TIM_Source_Mode) is begin RCC_Periph.CFGR.TIMPRE := Source = Factor_4; end Configure_TIM_Source_Mode; -------------------------------- -- Configure_MCO_Output_Clock -- -------------------------------- procedure Configure_MCO_Output_Clock (MCO : MCO_Range; Source : MCO_Clock_Source; Value : MCO_Prescaler) is begin case MCO is when MCO_1 => RCC_Periph.CFGR.MCO1SEL := Source'Enum_Rep; RCC_Periph.CFGR.MCO1PRE := Value'Enum_Rep; when MCO_2 => RCC_Periph.CFGR.MCO2SEL := Source'Enum_Rep; RCC_Periph.CFGR.MCO2PRE := Value'Enum_Rep; end case; end Configure_MCO_Output_Clock; ----------------------- -- Set_FLASH_Latency -- ----------------------- procedure Set_FLASH_Latency (Latency : FLASH_Wait_State) is begin Flash_Periph.ACR.LATENCY := Latency'Enum_Rep; end Set_FLASH_Latency; ----------------------- -- Set_VCORE_Scaling -- ----------------------- procedure Set_VCORE_Scaling (Scale : VCORE_Scaling_Selection) is begin PWR_Periph.D3CR.VOS := Scale'Enum_Rep; end Set_VCORE_Scaling; -------------------------- -- PWR_Overdrive_Enable -- -------------------------- procedure PWR_Overdrive_Enable is begin -- The system maximum frequency with VOS1 is 400 MHz, but 480 MHz can be -- reached by boosting the voltage scaling level to VOS0. This is done -- through the ODEN bit in the SYSCFG_PWRCR register, after configuring -- level VOS1. See RM0433 ver 7 pg. 277 chapter 6.6.2 for this sequence. if PWR_Periph.D3CR.VOS /= Scale_1'Enum_Rep then PWR_Periph.D3CR.VOS := Scale_1'Enum_Rep; -- Set VOS1 end if; RCC_Periph.APB4ENR.SYSCFGEN := True; -- Enable SYSCFG clock SYSCFG_Periph.PWRCR.ODEN := True; -- Wait for stabilization -- loop -- exit when PWR_Periph.D3CR.VOSRDY; -- end loop; end PWR_Overdrive_Enable; end STM32.RCC;
----------------------------------------------------------------------- -- hyperion-monitoring-modules -- Module monitoring -- Copyright (C) 2018 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Strings.Hash; with AWA.Modules.Beans; with AWA.Modules.Get; with ADO.Utils.Streams; with Util.Streams.Texts; with Util.Log.Loggers; with Util.Serialize.IO.JSON; with Hyperion.Monitoring.Beans; package body Hyperion.Monitoring.Modules is Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Hyperion.Monitoring.Module"); package Register is new AWA.Modules.Beans (Module => Monitoring_Module, Module_Access => Monitoring_Module_Access); -- ------------------------------ -- Initialize the monitoring module. -- ------------------------------ overriding procedure Initialize (Plugin : in out Monitoring_Module; App : in AWA.Modules.Application_Access; Props : in ASF.Applications.Config) is begin Log.Info ("Initializing the monitoring module"); -- Register here any bean class, servlet, filter. Register.Register (Plugin => Plugin, Name => "Hyperion.Monitoring.Beans.Monitoring_Bean", Handler => Hyperion.Monitoring.Beans.Create_Monitoring_Bean'Access); AWA.Modules.Module (Plugin).Initialize (App, Props); -- Add here the creation of manager instances. end Initialize; -- ------------------------------ -- Get the monitoring module. -- ------------------------------ function Get_Monitoring_Module return Monitoring_Module_Access is function Get is new AWA.Modules.Get (Monitoring_Module, Monitoring_Module_Access, NAME); begin return Get; end Get_Monitoring_Module; -- ------------------------------ -- Create a hash value for the host-source key. -- ------------------------------ function Hash (Key : in Host_Source_Key) return Ada.Containers.Hash_Type is use type Ada.Containers.Hash_Type; begin return ADO.Utils.Hash (Key.Host) xor Ada.Strings.Hash (Key.Name); end Hash; protected body All_Snapshots is procedure Host_Snapshot (Host_Id : in ADO.Identifier; Name : in String; Snapshot : out Snapshot_Data_Access) is Key : constant Host_Source_Key := Host_Source_Key '(Len => Name'Length, Host => Host_Id, Name => Name); Source_Pos : constant Host_Source_Maps.Cursor := Source_Map.Find (Key); Pos : Source_Snapshot_Maps.Cursor; begin if not Host_Source_Maps.Has_Element (Source_Pos) then -- Create null; end if; Pos := Snapshots.Find (Host_Source_Maps.Element (Source_Pos)); Snapshot := Source_Snapshot_Maps.Element (Pos); end Host_Snapshot; end All_Snapshots; function Serialize (Data : in Value_Builders.Builder) return ADO.Blob_Ref is Stream : aliased ADO.Utils.Streams.Blob_Output_Stream; Printer : aliased Util.Streams.Texts.Print_Stream; Json : Util.Serialize.IO.JSON.Output_Stream; procedure Serialize_Values (Content : in Value_Array) is begin for V of Content loop Json.Write_Long_Entity ("", V); end loop; end Serialize_Values; begin Stream.Initialize (Size => 100000); Printer.Initialize (Output => Stream'Unchecked_Access, Size => 100000); Json.Initialize (Printer'Unchecked_Access); Json.Start_Document; Json.Start_Array (""); Value_Builders.Iterate (Data, Serialize_Values'Access); Json.End_Array (""); Json.End_Document; Json.Flush; return Stream.Get_Blob; end Serialize; protected body Snapshot_Data is procedure Collect (DB : in out ADO.Sessions.Master_Session; From : in Ada.Calendar.Time; To : in Ada.Calendar.Time; Values : in UBO.Vectors.Vector_Bean) is begin for V of Values loop Value_Builders.Append (Data, UBO.To_Long_Long_Integer (V)); end loop; End_Time := To; Serie.Set_Start_Date (Start_Time); Serie.Set_End_Date (End_Time); Serie.Set_Content (Serialize (Data)); Serie.Set_Count (Value_Builders.Length (Data)); Serie.Set_Format (Hyperion.Monitoring.Models.FORMAT_JSON); Serie.Save (DB); end Collect; end Snapshot_Data; end Hyperion.Monitoring.Modules;
with Ada.Unchecked_Conversion; with Ada.Unchecked_Deallocation; with System.Address_To_Access_Conversions; with C.string; with C.libxml.globals; with C.libxml.parser; with C.libxml.tree; with C.libxml.xmlIO; with C.libxml.xmlmemory; with C.libxml.xmlstring; with C.libxml.xmlversion; package body XML is use type System.Address; use type C.char_array; use type C.signed_int; use type C.size_t; use type C.libxml.encoding.xmlCharEncodingHandlerPtr; use type C.libxml.xmlstring.xmlChar_const_ptr; use type C.libxml.tree.xmlOutputBufferPtr; use type C.libxml.xmlreader.xmlTextReaderPtr; use type C.libxml.xmlwriter.xmlTextWriterPtr; procedure Free is new Ada.Unchecked_Deallocation (String, String_Access); procedure memcpy (dst, src : System.Address; n : C.size_t) with Import, Convention => Intrinsic, External_Name => "__builtin_memcpy"; procedure memset ( s : System.Address; c : Standard.C.signed_int; n : Standard.C.size_t) with Import, Convention => Intrinsic, External_Name => "__builtin_memset"; type xmlChar_array is array (C.size_t range <>) of aliased C.libxml.xmlstring.xmlChar with Convention => C; pragma Suppress_Initialization (xmlChar_array); function To_char_const_ptr is new Ada.Unchecked_Conversion ( C.libxml.xmlstring.xmlChar_const_ptr, C.char_const_ptr); function To_Address is new Ada.Unchecked_Conversion (C.char_const_ptr, System.Address); function Length (S : access constant C.char) return Natural is begin if S = null then return 0; else return Natural (C.string.strlen (S)); end if; end Length; function To_String (S : access constant C.char; Length : Natural) return String is Result : String (1 .. Length); for Result'Address use To_Address (C.char_const_ptr (S)); begin return Result; end To_String; function To_String (S : access constant C.char) return String is begin return To_String (S, Length (S)); end To_String; function To_String_Without_LF (S : access constant C.char) return String is L : Natural := Length (S); Result : String (1 .. L); for Result'Address use To_Address (C.char_const_ptr (S)); begin if L >= 1 and then Result (L) = Character'Val (10) then L := L - 1; end if; return To_String (S, L); end To_String_Without_LF; -- dirty trick function Copy_String_Access ( S : not null String_Access; Constraint : not null access String_Constraint) return String_Access is type Fat_Type is record Data : System.Address; Constraints : System.Address; end record; Fat : Fat_Type; Result : aliased String_Access; for Fat'Address use Result'Address; begin Fat.Data := S.all'Address; Fat.Constraints := Constraint.all'Address; Constraint.First := S'First; Constraint.Last := S'Last; return Result; end Copy_String_Access; Version_Checked : Boolean := False; -- implementation function Version return String is begin Check_Version; return To_String (C.libxml.globals.xmlParserVersion); end Version; procedure Check_Version is begin if not Version_Checked then Version_Checked := True; C.libxml.xmlversion.xmlCheckVersion (C.libxml.xmlversion.LIBXML_VERSION); end if; end Check_Version; procedure Cleanup is begin C.libxml.parser.xmlCleanupParser; C.libxml.xmlmemory.xmlMemoryDump; end Cleanup; function No_Encoding return Encoding_Type is begin return null; end No_Encoding; function Find (Name : String) return Encoding_Type is Name_Length : constant C.size_t := Name'Length; C_Name : C.char_array (0 .. Name_Length); -- NUL Result : C.libxml.encoding.xmlCharEncodingHandlerPtr; begin memcpy (C_Name'Address, Name'Address, Name_Length); C_Name (Name_Length) := C.char'Val (0); Result := C.libxml.encoding.xmlFindCharEncodingHandler (C_Name (C_Name'First)'Access); if Result = null then raise Name_Error; end if; return Encoding_Type (Result); end Find; function Name (Encoding : Encoding_Type) return String is begin if Encoding = null then raise Constraint_Error; else return To_String (Encoding.name); end if; end Name; -- reader function Read_Handler ( context : C.void_ptr; buffer : access C.char; len : C.signed_int) return C.signed_int with Convention => C; function Read_Handler ( context : C.void_ptr; buffer : access C.char; len : C.signed_int) return C.signed_int is type I is access procedure (Item : out String; Last : out Natural); function To_Input is new Ada.Unchecked_Conversion (C.void_ptr, I); Item : String (1 .. Natural (len)); for Item'Address use buffer.all'Address; Last : Natural; begin To_Input (context) (Item, Last); return C.signed_int (Last); end Read_Handler; procedure Reader_Error_Handler ( userData : C.void_ptr; error : access C.libxml.xmlerror.xmlError) with Convention => C; procedure Reader_Error_Handler ( userData : C.void_ptr; error : access C.libxml.xmlerror.xmlError) is package Conv is new System.Address_To_Access_Conversions (Non_Controlled_Reader); NC_Object : Non_Controlled_Reader renames Conv.To_Pointer (System.Address (userData)).all; begin if NC_Object.Error then C.libxml.xmlerror.xmlResetError (NC_Object.U.Last_Error'Access); else memset (NC_Object.U.Last_Error'Address, 0, C.libxml.xmlerror.xmlError'Size / Standard'Storage_Unit); end if; NC_Object.Error := not ( C.libxml.xmlerror.xmlCopyError ( from => error, to => NC_Object.U.Last_Error'Access) < 0); end Reader_Error_Handler; procedure Next (NC_Object : in out Non_Controlled_Reader) is begin Reset_Last_Error (NC_Object); if C.libxml.xmlreader.xmlTextReaderRead (NC_Object.Raw) < 0 then Raise_Last_Error (NC_Object); end if; end Next; procedure Read_Start (NC_Object : in out Non_Controlled_Reader) is begin if NC_Object.State = Start then Next (NC_Object); NC_Object.State := Next; end if; end Read_Start; procedure Read ( NC_Object : in out Non_Controlled_Reader; Parsed_Data : out Parsed_Data_Type) is begin case NC_Object.State is when Next | Start | Remaining => if NC_Object.State /= Next then Next (NC_Object); end if; declare Node_Type : constant C.signed_int := C.libxml.xmlreader.xmlTextReaderNodeType (NC_Object.Raw); begin if Node_Type < 0 then Raise_Last_Error (NC_Object); else case Node_Type is when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_NONE) => Parsed_Data.Event := (Event_Type => No_Event); NC_Object.State := Remaining; when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_ATTRIBUTE) => declare C_Name : constant C.libxml.xmlstring.xmlChar_const_ptr := C.libxml.xmlreader.xmlTextReaderConstName (NC_Object.Raw); Name : String (1 .. Natural (C.string.strlen (To_char_const_ptr (C_Name)))); for Name'Address use C_Name.all'Address; C_Value : constant C.libxml.xmlstring.xmlChar_const_ptr := C.libxml.xmlreader.xmlTextReaderConstValue (NC_Object.Raw); Value : String (1 .. Natural (C.string.strlen (To_char_const_ptr (C_Value)))); for Value'Address use C_Value.all'Address; begin Parsed_Data.Event := ( Event_Type => Attribute, Name => Copy_String_Access ( Name'Unrestricted_Access, Parsed_Data.Name_Constraint'Access), Value => Copy_String_Access ( Value'Unrestricted_Access, Parsed_Data.Value_Constraint'Access)); end; Reset_Last_Error (NC_Object); declare Moved : constant C.signed_int := C.libxml.xmlreader.xmlTextReaderMoveToNextAttribute (NC_Object.Raw); begin if Moved < 0 then Raise_Last_Error (NC_Object); elsif Moved > 0 then NC_Object.State := Next; -- more attributes else -- end of attributes Reset_Last_Error (NC_Object); if C.libxml.xmlreader.xmlTextReaderMoveToElement (NC_Object.Raw) < 0 then Raise_Last_Error (NC_Object); end if; if C.libxml.xmlreader.xmlTextReaderIsEmptyElement (NC_Object.Raw) > 0 then NC_Object.State := Empty_Element; else -- move to children NC_Object.State := Remaining; end if; end if; end; when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_ELEMENT) => declare C_Name : constant C.libxml.xmlstring.xmlChar_const_ptr := C.libxml.xmlreader.xmlTextReaderConstName (NC_Object.Raw); Name : String (1 .. Natural (C.string.strlen (To_char_const_ptr (C_Name)))); for Name'Address use C_Name.all'Address; begin Parsed_Data.Event := ( Event_Type => Element_Start, Name => Copy_String_Access ( Name'Unrestricted_Access, Parsed_Data.Name_Constraint'Access)); end; if C.libxml.xmlreader.xmlTextReaderHasAttributes (NC_Object.Raw) > 0 then NC_Object.State := Next; Reset_Last_Error (NC_Object); if C.libxml.xmlreader.xmlTextReaderMoveToFirstAttribute ( NC_Object.Raw) < 0 then Raise_Last_Error (NC_Object); end if; elsif C.libxml.xmlreader.xmlTextReaderIsEmptyElement (NC_Object.Raw) > 0 then NC_Object.State := Empty_Element; else -- move to children NC_Object.State := Remaining; end if; when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_TEXT) | C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_CDATA) | C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_COMMENT) | C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_WHITESPACE) | C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_SIGNIFICANT_WHITESPACE) => declare C_Content : constant C.libxml.xmlstring.xmlChar_const_ptr := C.libxml.xmlreader.xmlTextReaderConstValue (NC_Object.Raw); Content : String (1 .. Natural (C.string.strlen (To_char_const_ptr (C_Content)))); for Content'Address use C_Content.all'Address; Content_Access : constant String_Access := Copy_String_Access ( Content'Unrestricted_Access, Parsed_Data.Content_Constraint'Access); begin case Node_Type is when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_TEXT) => Parsed_Data.Event := (Event_Type => Text, Content => Content_Access); when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_CDATA) => Parsed_Data.Event := (Event_Type => CDATA, Content => Content_Access); when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_COMMENT) => Parsed_Data.Event := (Event_Type => Comment, Content => Content_Access); when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_WHITESPACE) => Parsed_Data.Event := (Event_Type => Whitespace, Content => Content_Access); when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_SIGNIFICANT_WHITESPACE) => Parsed_Data.Event := (Event_Type => Significant_Whitespace, Content => Content_Access); when others => pragma Assert (False); null; end case; end; NC_Object.State := Remaining; when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_PROCESSING_INSTRUCTION) => declare C_Name : constant C.libxml.xmlstring.xmlChar_const_ptr := C.libxml.xmlreader.xmlTextReaderConstName (NC_Object.Raw); Name : String (1 .. Natural (C.string.strlen (To_char_const_ptr (C_Name)))); for Name'Address use C_Name.all'Address; begin Parsed_Data.Event := ( Event_Type => Processing_Instruction, Name => Copy_String_Access ( Name'Unrestricted_Access, Parsed_Data.Name_Constraint'Access)); -- it's not able to get attributes info with libxml2 (?) pragma Assert ( C.libxml.xmlreader.xmlTextReaderHasAttributes (NC_Object.Raw) = 0); end; NC_Object.State := Remaining; when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_DOCUMENT_TYPE) => declare C_Name : constant C.libxml.xmlstring.xmlChar_const_ptr := C.libxml.xmlreader.xmlTextReaderConstName (NC_Object.Raw); Name : String (1 .. Natural (C.string.strlen (To_char_const_ptr (C_Name)))); for Name'Address use C_Name.all'Address; begin Parsed_Data.Event := ( Event_Type => Document_Type, Name => Copy_String_Access ( Name'Unrestricted_Access, Parsed_Data.Name_Constraint'Access), Public_Id => null, System_Id => null, Subset => null); -- it's not able to get extra DTD info with libxml2 (?) pragma Assert ( C.libxml.xmlreader.xmlTextReaderHasAttributes (NC_Object.Raw) = 0); end; NC_Object.State := Remaining; when C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_END_ELEMENT) => Parsed_Data.Event := (Event_Type => Element_End); NC_Object.State := Remaining; when others => raise Program_Error with "in XML.Read, unimplemented" & Node_Type'Img; end case; end if; end; when Empty_Element => Parsed_Data.Event := (Event_Type => Element_End); NC_Object.State := Remaining; end case; end Read; procedure Read (Object : in out Reader; Parsed_Data : out Parsed_Data_Type) is procedure Process (NC_Object : in out Non_Controlled_Reader) is begin Read (NC_Object, Parsed_Data); end Process; procedure Do_Read is new Controlled_Readers.Update (Process); begin Do_Read (Object); end Read; -- implementation of reader function Is_Assigned (Parsing_Entry : Parsing_Entry_Type) return Boolean is begin return Parsing_Entry.Assigned; end Is_Assigned; function Value (Parsing_Entry : aliased Parsing_Entry_Type) return Event_Reference_Type is pragma Check (Pre, Check => Is_Assigned (Parsing_Entry) or else raise Status_Error); begin return (Element => Parsing_Entry.Data.Event'Access); end Value; function Create ( Input : not null access procedure (Item : out String; Last : out Natural); Encoding : Encoding_Type := No_Encoding; URI : String := "") return Reader is type I is access procedure (Item : out String; Last : out Natural); function To_void_ptr is new Ada.Unchecked_Conversion (I, C.void_ptr); begin Check_Version; declare P_Encoding : C.char_const_ptr := null; P_URI : access constant C.char := null; URI_Length : constant C.size_t := URI'Length; C_URI : aliased C.char_array (0 .. URI_Length); -- NUL begin if Encoding /= null then P_Encoding := C.char_const_ptr (Encoding.name); end if; if URI'Length > 0 then memcpy (C_URI'Address, URI'Address, URI_Length); C_URI (URI_Length) := C.char'Val (0); P_URI := C_URI (C_URI'First)'Access; end if; return Result : aliased Reader do declare NC_Result : Non_Controlled_Reader renames Controlled_Readers.Reference (Result).all; begin NC_Result.Raw := C.libxml.xmlreader.xmlReaderForIO ( Read_Handler'Access, null, To_void_ptr (Input), P_URI, P_Encoding, 0); if NC_Result.Raw = null then raise Use_Error; end if; Install_Error_Handler (NC_Result); end; end return; end; end Create; procedure Set_DTD_Loading (Object : in out Reader; Value : in Boolean) is procedure Process (NC_Object : in out Non_Controlled_Reader) is begin if C.libxml.xmlreader.xmlTextReaderSetParserProp ( NC_Object.Raw, C.libxml.xmlreader.xmlParserProperties'Enum_Rep ( C.libxml.xmlreader.XML_PARSER_LOADDTD), Boolean'Pos (Value)) < 0 then raise Use_Error; end if; end Process; procedure Do_Set_DTD_Loading is new Controlled_Readers.Update (Process); begin Do_Set_DTD_Loading (Object); end Set_DTD_Loading; procedure Set_Default_Attributes ( Object : in out Reader; Value : in Boolean) is procedure Process (NC_Object : in out Non_Controlled_Reader) is begin if C.libxml.xmlreader.xmlTextReaderSetParserProp ( NC_Object.Raw, C.libxml.xmlreader.xmlParserProperties'Enum_Rep ( C.libxml.xmlreader.XML_PARSER_DEFAULTATTRS), Boolean'Pos (Value)) < 0 then raise Use_Error; end if; end Process; procedure Do_Set_Default_Attributes is new Controlled_Readers.Update (Process); begin Do_Set_Default_Attributes (Object); end Set_Default_Attributes; procedure Set_Validation (Object : in out Reader; Value : in Boolean) is procedure Process (NC_Object : in out Non_Controlled_Reader) is begin if C.libxml.xmlreader.xmlTextReaderSetParserProp ( NC_Object.Raw, C.libxml.xmlreader.xmlParserProperties'Enum_Rep ( C.libxml.xmlreader.XML_PARSER_VALIDATE), Boolean'Pos (Value)) < 0 then raise Use_Error; end if; end Process; procedure Do_Set_Validation is new Controlled_Readers.Update (Process); begin Do_Set_Validation (Object); end Set_Validation; procedure Set_Substitute_Entities ( Object : in out Reader; Value : in Boolean) is procedure Process (NC_Object : in out Non_Controlled_Reader) is begin if C.libxml.xmlreader.xmlTextReaderSetParserProp ( NC_Object.Raw, C.libxml.xmlreader.xmlParserProperties'Enum_Rep ( C.libxml.xmlreader.XML_PARSER_SUBST_ENTITIES), Boolean'Pos (Value)) < 0 then raise Use_Error; end if; end Process; procedure Do_Set_Substitute_Entities is new Controlled_Readers.Update (Process); begin Do_Set_Substitute_Entities (Object); end Set_Substitute_Entities; function Version (Object : in out Reader) return access constant String is Result : access constant String; procedure Process (NC_Object : in out Non_Controlled_Reader) is begin if NC_Object.Version = null then Read_Start (NC_Object); declare C_Version : constant C.libxml.xmlstring.xmlChar_const_ptr := C.libxml.xmlreader.xmlTextReaderConstXmlVersion (NC_Object.Raw); begin if C_Version /= null then declare A_Version : String (1 .. Natural (C.string.strlen (To_char_const_ptr (C_Version)))); for A_Version'Address use C_Version.all'Address; begin NC_Object.Version := new String'(A_Version); end; end if; end; end if; Result := NC_Object.Version; end Process; procedure Do_Version is new Controlled_Readers.Update (Process); begin Do_Version (Object); return Result; end Version; function Encoding (Object : in out Reader) return Encoding_Type is Result : Encoding_Type; procedure Process (NC_Object : in out Non_Controlled_Reader) is begin Read_Start (NC_Object); Result := Encoding_Type ( C.libxml.encoding.xmlFindCharEncodingHandler ( To_char_const_ptr ( C.libxml.xmlreader.xmlTextReaderConstEncoding (NC_Object.Raw)))); end Process; procedure Do_Encoding is new Controlled_Readers.Update (Process); begin Do_Encoding (Object); return Result; end Encoding; function Standalone (Object : in out Reader) return Standalone_Type is Result : Standalone_Type; procedure Process (NC_Object : in out Non_Controlled_Reader) is begin Read_Start (NC_Object); declare Standalone_Value : constant C.signed_int := C.libxml.xmlreader.xmlTextReaderStandalone (NC_Object.Raw); begin if Standalone_Value < -1 then Result := No_Specific; -- undocumented error else Result := Standalone_Type'Enum_Val (Standalone_Value); end if; end; end Process; procedure Do_Standalone is new Controlled_Readers.Update (Process); begin Do_Standalone (Object); return Result; end Standalone; function Base_URI (Object : in out Reader) return String is Result : C.libxml.xmlstring.xmlChar_const_ptr; procedure Process (NC_Object : in out Non_Controlled_Reader) is begin Read_Start (NC_Object); Result := C.libxml.xmlreader.xmlTextReaderConstBaseUri (NC_Object.Raw); end Process; procedure Do_Base_URI is new Controlled_Readers.Update (Process); begin Do_Base_URI (Object); return To_String (To_char_const_ptr (Result)); end Base_URI; procedure Get ( Object : in out Reader; Process : not null access procedure (Event : in XML.Event)) is Parsed_Data : Parsed_Data_Type; begin Read (Object, Parsed_Data); Process (Parsed_Data.Event); end Get; procedure Get ( Object : in out Reader; Parsing_Entry : out Parsing_Entry_Type) is begin Read (Object, Parsing_Entry.Data); Parsing_Entry.Assigned := True; end Get; procedure Get_Until_Element_End (Object : in out Reader) is begin loop declare T : Event_Type; begin declare Parsed_Data : Parsed_Data_Type; begin Read (Object, Parsed_Data); T := Parsed_Data.Event.Event_Type; end; case T is when Element_Start => Get_Until_Element_End (Object); when Element_End => exit; when others => null; end case; end; end loop; end Get_Until_Element_End; procedure Finish (Object : in out Reader) is procedure Process (NC_Object : in out Non_Controlled_Reader) is begin case NC_Object.State is when Next => null; when Start | Remaining => Next (NC_Object); when Empty_Element => raise Data_Error; -- Element_End end case; declare Node_Type : constant C.signed_int := C.libxml.xmlreader.xmlTextReaderNodeType (NC_Object.Raw); begin if Node_Type /= C.libxml.xmlreader.xmlReaderTypes'Enum_Rep ( C.libxml.xmlreader.XML_READER_TYPE_NONE) then raise Data_Error; end if; end; end Process; procedure Do_Finish is new Controlled_Readers.Update (Process); begin Do_Finish (Object); end Finish; function Last_Error_Line (Object : Reader) return Natural is function Process (NC_Object : Non_Controlled_Reader) return Natural is Line : Natural := 0; begin if NC_Object.Error then Line := Integer (NC_Object.U.Last_Error.line - 1); end if; return Line; end Process; function Do_Last_Error_Line is new Controlled_Readers.Query (Natural, Process); begin return Do_Last_Error_Line (Object); end Last_Error_Line; function Last_Error_Message (Object : Reader) return String is function Process (NC_Object : Non_Controlled_Reader) return String is Message : C.char_const_ptr := null; begin if NC_Object.Error then Message := C.char_const_ptr (NC_Object.U.Last_Error.message); end if; return To_String_Without_LF (Message); end Process; function Do_Last_Error_Message is new Controlled_Readers.Query (String, Process); begin return Do_Last_Error_Message (Object); end Last_Error_Message; procedure Install_Error_Handler ( NC_Object : aliased in out Non_Controlled_Reader) is package Conv is new System.Address_To_Access_Conversions (Non_Controlled_Reader); begin C.libxml.xmlreader.xmlTextReaderSetStructuredErrorHandler ( NC_Object.Raw, Reader_Error_Handler'Access, C.void_ptr (Conv.To_Address (NC_Object'Access))); end Install_Error_Handler; procedure Reset_Last_Error (NC_Object : in out Non_Controlled_Reader) is begin if NC_Object.Error then NC_Object.Error := False; C.libxml.xmlerror.xmlResetError (NC_Object.U.Last_Error'Access); end if; end Reset_Last_Error; procedure Raise_Last_Error (NC_Object : in Non_Controlled_Reader) is begin if not NC_Object.Error then raise Use_Error; -- API reported a failure, but did not callbacked else Raise_Error (NC_Object.U.Last_Error'Access); end if; end Raise_Last_Error; package body Controlled_Readers is function Reference (Object : aliased in out Reader) return not null access Non_Controlled_Reader; pragma Inline (Reference); function Reference (Object : aliased in out Reader) return not null access Non_Controlled_Reader is begin return Object.Data'Access; end Reference; -- implementation function Reference (Object : aliased in out XML.Reader) return not null access Non_Controlled_Reader is begin return Reference (Reader (Object)); end Reference; function Query (Object : XML.Reader) return Result_Type is function Query (Object : Reader) return Result_Type; pragma Inline (Query); function Query (Object : Reader) return Result_Type is begin return Process (Object.Data); end Query; begin return Query (Reader (Object)); end Query; procedure Update (Object : in out XML.Reader) is procedure Update (Object : in out Reader); pragma Inline (Update); procedure Update (Object : in out Reader) is begin Process (Object.Data); end Update; begin Update (Reader (Object)); end Update; overriding procedure Finalize (Object : in out Reader) is begin C.libxml.xmlreader.xmlFreeTextReader (Object.Data.Raw); Free (Object.Data.Version); if Object.Data.Error then C.libxml.xmlerror.xmlResetError (Object.Data.U.Last_Error'Access); end if; end Finalize; end Controlled_Readers; -- writer function Write_Handler ( context : C.void_ptr; buffer : access constant C.char; len : C.signed_int) return C.signed_int with Convention => C; function Write_Handler ( context : C.void_ptr; buffer : access constant C.char; len : C.signed_int) return C.signed_int is type O is access procedure (Item : in String); function To_Output is new Ada.Unchecked_Conversion (C.void_ptr, O); Item : String (1 .. Natural (len)); for Item'Address use buffer.all'Address; begin To_Output (context) (Item); return len; end Write_Handler; procedure Flush (NC_Object : in Non_Controlled_Writer) is begin if C.libxml.xmlwriter.xmlTextWriterFlush (NC_Object.Raw) < 0 then raise Use_Error; end if; end Flush; procedure Check_No_Zero (S : in String) is begin -- one of the design problems of libxml2, -- it uses zero-terminated strings. -- user's data may be lost if the data contains '\0', check it here. if System.Address ( C.string.memchr (C.void_const_ptr (S'Address), 0, S'Length)) /= System.Null_Address then raise Constraint_Error; end if; end Check_No_Zero; -- for standalone No_Image : constant C.char_array := "no" & C.char'Val (0); Yes_Image : constant C.char_array := "yes" & C.char'Val (0); Standalone_Image : constant array (Standalone_Type) of C.char_const_ptr := ( No_Specific => null, No => No_Image (No_Image'First)'Access, Yes => Yes_Image (Yes_Image'First)'Access); -- implementation of writer function Create ( Output : not null access procedure (Item : in String); Encoding : Encoding_Type := No_Encoding) return Writer is type O is access procedure (Item : in String); function To_void_ptr is new Ada.Unchecked_Conversion (O, C.void_ptr); begin Check_Version; declare Buffer : constant C.libxml.tree.xmlOutputBufferPtr := C.libxml.xmlIO.xmlOutputBufferCreateIO ( Write_Handler'Access, null, To_void_ptr (Output), Encoding); begin if Buffer = null then raise Use_Error; end if; return Result : Writer do declare procedure Process (NC_Result : in out Non_Controlled_Writer) is begin NC_Result.Raw := C.libxml.xmlwriter.xmlNewTextWriter (Buffer); if NC_Result.Raw = null then declare Dummy : C.signed_int; begin Dummy := C.libxml.xmlIO.xmlOutputBufferClose (Buffer); end; raise Use_Error; end if; end Process; procedure Do_Create is new Controlled_Writers.Update (Process); begin Do_Create (Result); end; end return; end; end Create; function Finished (Object : Writer) return Boolean is function Process (NC_Object : Non_Controlled_Writer) return Boolean is begin return NC_Object.Finished; end Process; function Do_Finished is new Controlled_Writers.Query (Boolean, Process); begin return Do_Finished (Object); end Finished; procedure Flush (Object : in out Writer) is procedure Process (NC_Object : in out Non_Controlled_Writer) is begin Flush (NC_Object); end Process; procedure Do_Flush is new Controlled_Writers.Update (Process); begin Do_Flush (Object); end Flush; procedure Set_Indent (Object : in out Writer; Indent : in Natural) is procedure Process (NC_Object : in out Non_Controlled_Writer) is begin if C.libxml.xmlwriter.xmlTextWriterSetIndent ( NC_Object.Raw, C.signed_int (Indent)) < 0 then raise Use_Error; end if; end Process; procedure Do_Set_Indent is new Controlled_Writers.Update (Process); begin Do_Set_Indent (Object); end Set_Indent; procedure Set_Indent (Object : in out Writer; Indent : in String) is procedure Process (NC_Object : in out Non_Controlled_Writer) is Indent_Length : constant C.size_t := Indent'Length; C_Indent : xmlChar_array (0 .. Indent_Length); -- NUL begin memcpy (C_Indent'Address, Indent'Address, Indent_Length); C_Indent (Indent_Length) := C.libxml.xmlstring.xmlChar'Val (0); if C.libxml.xmlwriter.xmlTextWriterSetIndentString ( NC_Object.Raw, C_Indent (C_Indent'First)'Access) < 0 then raise Use_Error; end if; end Process; procedure Do_Set_Indent is new Controlled_Writers.Update (Process); begin Do_Set_Indent (Object); end Set_Indent; procedure Put (Object : in out Writer; Event : in XML.Event) is pragma Check (Pre, Check => not Finished (Object) or else raise Status_Error); procedure Process (NC_Object : in out Non_Controlled_Writer) is begin case Event.Event_Type is when No_Event => raise Data_Error; when Element_Start => Check_No_Zero (Event.Name.all); declare Name : String renames Event.Name.all; Name_Length : constant C.size_t := Name'Length; C_Name : xmlChar_array (0 .. Name_Length); -- NUL begin memcpy (C_Name'Address, Name'Address, Name_Length); C_Name (Name_Length) := C.libxml.xmlstring.xmlChar'Val (0); C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterStartElement ( NC_Object.Raw, C_Name (C_Name'First)'Access) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; end; when Attribute => Check_No_Zero (Event.Name.all); Check_No_Zero (Event.Value.all); declare Name : String renames Event.Name.all; Name_Length : constant C.size_t := Name'Length; C_Name : xmlChar_array (0 .. Name_Length); -- NUL Value : String renames Event.Value.all; Value_Length : constant C.size_t := Value'Length; C_Value : xmlChar_array (0 .. Value_Length); -- NUL begin memcpy (C_Name'Address, Name'Address, Name_Length); C_Name (Name_Length) := C.libxml.xmlstring.xmlChar'Val (0); memcpy (C_Value'Address, Value'Address, Value_Length); C_Value (Value_Length) := C.libxml.xmlstring.xmlChar'Val (0); C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterWriteAttribute ( NC_Object.Raw, C_Name (C_Name'First)'Access, C_Value (C_Value'First)'Access) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; end; when Text => Check_No_Zero (Event.Content.all); declare Content : String renames Event.Content.all; Content_Length : constant C.size_t := Content'Length; C_Content : xmlChar_array (0 .. Content_Length); -- NUL begin memcpy (C_Content'Address, Content'Address, Content_Length); C_Content (Content_Length) := C.libxml.xmlstring.xmlChar'Val (0); C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterWriteString ( NC_Object.Raw, C_Content (C_Content'First)'Access) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; end; when CDATA => Check_No_Zero (Event.Content.all); declare Content : String renames Event.Content.all; Content_Length : constant C.size_t := Content'Length; C_Content : xmlChar_array (0 .. Content_Length); -- NUL begin memcpy (C_Content'Address, Content'Address, Content_Length); C_Content (Content_Length) := C.libxml.xmlstring.xmlChar'Val (0); C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterWriteCDATA ( NC_Object.Raw, C_Content (C_Content'First)'Access) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; end; when Entity_Reference => raise Program_Error; -- unimplemented when Entity_Start => raise Program_Error; -- unimplemented when Processing_Instruction => raise Program_Error; -- unimplemented when Comment => Check_No_Zero (Event.Content.all); declare Content : String renames Event.Content.all; Content_Length : constant C.size_t := Content'Length; C_Content : xmlChar_array (0 .. Content_Length); -- NUL begin memcpy (C_Content'Address, Content'Address, Content_Length); C_Content (Content_Length) := C.libxml.xmlstring.xmlChar'Val (0); C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterWriteComment ( NC_Object.Raw, C_Content (C_Content'First)'Access) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; end; when Document => raise Program_Error; -- unimplemented when Document_Type => declare Public_Id_Length : C.size_t := 0; System_Id_Length : C.size_t := 0; Subset_Length : C.size_t := 0; begin Check_No_Zero (Event.Name.all); if Event.Public_Id /= null then Check_No_Zero (Event.Public_Id.all); Public_Id_Length := Event.Public_Id'Length + 1; end if; if Event.System_Id /= null then Check_No_Zero (Event.System_Id.all); System_Id_Length := Event.System_Id'Length + 1; end if; if Event.Subset /= null then Check_No_Zero (Event.Subset.all); Subset_Length := Event.Subset'Length + 1; end if; declare Name : String renames Event.Name.all; Name_Length : constant C.size_t := Name'Length; C_Name : xmlChar_array (0 .. Name_Length); -- NULL C_Public_Id : xmlChar_array (0 .. Public_Id_Length); -- NUL P_Public_Id : access constant C.libxml.xmlstring.xmlChar; C_System_Id : xmlChar_array (0 .. System_Id_Length); -- NUL P_System_Id : access constant C.libxml.xmlstring.xmlChar; C_Subset : xmlChar_array (0 .. Subset_Length); -- NUL P_Subset : access constant C.libxml.xmlstring.xmlChar; begin memcpy (C_Name'Address, Name'Address, Name_Length); C_Name (Name_Length) := C.libxml.xmlstring.xmlChar'Val (0); if Event.Public_Id /= null then memcpy (C_Public_Id'Address, Event.Public_Id.all'Address, Public_Id_Length); C_Public_Id (Public_Id_Length) := C.libxml.xmlstring.xmlChar'Val (0); P_Public_Id := C_Public_Id (C_Public_Id'First)'Access; end if; if Event.System_Id /= null then memcpy (C_System_Id'Address, Event.System_Id.all'Address, System_Id_Length); C_System_Id (System_Id_Length) := C.libxml.xmlstring.xmlChar'Val (0); P_System_Id := C_System_Id (C_System_Id'First)'Access; end if; if Event.Subset /= null then memcpy (C_Subset'Address, Event.Subset.all'Address, Subset_Length); C_Subset (Subset_Length) := C.libxml.xmlstring.xmlChar'Val (0); P_Subset := C_Subset (C_Subset'First)'Access; end if; C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterWriteDocType ( NC_Object.Raw, C_Name (C_Name'First)'Access, P_Public_Id, P_System_Id, P_Subset) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; end; end; when Document_Fragment => raise Program_Error; -- unimplemented when Notation => raise Program_Error; -- unimplemented when Whitespace => raise Program_Error; -- unimplemented when Significant_Whitespace => raise Program_Error; -- unimplemented when Element_End => C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterEndElement (NC_Object.Raw) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; when Entity_End => raise Program_Error; -- unimplemented when XML_Declaration => raise Program_Error; -- unimplemented end case; end Process; procedure Do_Put is new Controlled_Writers.Update (Process); begin Do_Put (Object); end Put; procedure Put_Document_Start ( Object : in out Writer; Version : access constant String := null; Encoding : Encoding_Type := No_Encoding; Standalone : Standalone_Type := No_Specific) is pragma Check (Pre, Check => not Finished (Object) or else raise Status_Error); procedure Process (NC_Object : in out Non_Controlled_Writer) is Version_Length : C.size_t := 0; begin if Version /= null then Check_No_Zero (Version.all); Version_Length := Version'Length + 1; end if; declare C_Version : C.char_array (0 .. Version_Length); -- NUL P_Version : access constant C.char := null; P_Encoding : access constant C.char := null; begin if Version /= null then memcpy (C_Version'Address, Version.all'Address, Version_Length); C_Version (Version_Length) := C.char'Val (0); P_Version := C_Version (C_Version'First)'Access; end if; if Encoding /= null then P_Encoding := Encoding.name; end if; C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterStartDocument ( NC_Object.Raw, P_Version, P_Encoding, Standalone_Image (Standalone)) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; end; end Process; procedure Do_Put_Document_Start is new Controlled_Writers.Update (Process); begin Do_Put_Document_Start (Object); end Put_Document_Start; procedure Put_Document_End (Object : in out Writer) is pragma Check (Pre, Check => not Finished (Object) or else raise Status_Error); procedure Process (NC_Object : in out Non_Controlled_Writer) is begin C.libxml.xmlerror.xmlResetLastError; if C.libxml.xmlwriter.xmlTextWriterEndDocument (NC_Object.Raw) < 0 then Raise_Error (C.libxml.xmlerror.xmlGetLastError); end if; end Process; procedure Do_Put_Document_End is new Controlled_Writers.Update (Process); begin Do_Put_Document_End (Object); end Put_Document_End; procedure Finish (Object : in out Writer) is pragma Check (Pre, Check => not Finished (Object) or else raise Status_Error); procedure Process (NC_Object : in out Non_Controlled_Writer) is begin NC_Object.Finished := True; Flush (NC_Object); end Process; procedure Do_Finish is new Controlled_Writers.Update (Process); begin Do_Finish (Object); end Finish; package body Controlled_Writers is function Query (Object : XML.Writer) return Result_Type is function Query (Object : Writer) return Result_Type; pragma Inline (Query); function Query (Object : Writer) return Result_Type is begin return Process (Object.Data); end Query; begin return Query (Writer (Object)); end Query; procedure Update (Object : in out XML.Writer) is procedure Update (Object : in out Writer); pragma Inline (Update); procedure Update (Object : in out Writer) is begin Process (Object.Data); end Update; begin Update (Writer (Object)); end Update; overriding procedure Finalize (Object : in out Writer) is begin C.libxml.xmlwriter.xmlFreeTextWriter (Object.Data.Raw); end Finalize; end Controlled_Writers; -- implementation of exceptions procedure Raise_Error (Error : access constant C.libxml.xmlerror.xmlError) is function Location return String is begin if Error.line = 0 then return ""; else return "line" & C.signed_int'Image (Error.line - 1) & ": "; end if; end Location; begin if Error = null then raise Use_Error; -- ??? else case Error.code is when C.libxml.xmlerror.xmlParserErrors'Enum_Rep ( C.libxml.xmlerror.XML_ERR_OK) => raise Use_Error; when C.libxml.xmlerror.xmlParserErrors'Enum_Rep ( C.libxml.xmlerror.XML_ERR_NO_MEMORY) => raise Storage_Error; when others => raise Data_Error with Location & To_String_Without_LF (Error.message); end case; end if; end Raise_Error; end XML;
-- { dg-do run } with Init3; use Init3; with Text_IO; use Text_IO; with Dump; procedure S3 is A1 : R1 := My_R1; A2 : R2 := My_R2; N1 : Nested1; N2 : Nested2; C1 : Init3.Count; C2 : Init3.Count; C3 : Init3.Count; begin Put ("A1 :"); Dump (A1'Address, R1'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "A1 : e2 59 d1 48 b4 aa d9 bb.*\n" } Put ("A2 :"); Dump (A2'Address, R1'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "A2 : 84 8d 15 9e 15 5b 35 df.*\n" } N1 := A1.N; C1 := N1.C1; C2 := N1.C2; C3 := N1.C3; Put_Line("C1 :" & C1'Img); -- { dg-output "C1 : 171.*\n" } Put_Line("C2 :" & C2'Img); -- { dg-output "C2 : 205.*\n" } Put_Line("C3 :" & C3'Img); -- { dg-output "C3 : 239.*\n" } N1.C1 := C1; N1.C2 := C2; N1.C3 := C3; A1.N := N1; N2 := A2.N; C1 := N2.C1; C2 := N2.C2; C3 := N2.C3; Put_Line("C1 :" & C1'Img); -- { dg-output "C1 : 171.*\n" } Put_Line("C2 :" & C2'Img); -- { dg-output "C2 : 205.*\n" } Put_Line("C3 :" & C3'Img); -- { dg-output "C3 : 239.*\n" } N2.C1 := C1; N2.C2 := C2; N2.C3 := C3; A2.N := N2; Put ("A1 :"); Dump (A1'Address, R1'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "A1 : e2 59 d1 48 b4 aa d9 bb.*\n" } Put ("A2 :"); Dump (A2'Address, R1'Max_Size_In_Storage_Elements); New_Line; -- { dg-output "A2 : 84 8d 15 9e 15 5b 35 df.*\n" } end;
with AUnit; use AUnit; with AUnit.Reporter.Text; use AUnit.Reporter.Text; with AUnit.Run; use AUnit.Run; with GNAT.OS_Lib; use GNAT.OS_Lib; with Rejuvenation_Suite; use Rejuvenation_Suite; procedure Tests is function Runner is new Test_Runner_With_Status (Suite); Reporter : Text_Reporter; begin if Runner (Reporter) /= Success then OS_Exit (1); end if; end Tests;
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2017 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 Ada.Finalization; with GL.Objects; with GL.Types; private with GL.Low_Level; package GL.Debug is pragma Preelaborate; use GL.Types; type Source is (OpenGL, Window_System, Shader_Compiler, Third_Party, Application, Other); type Message_Type is (Error, Deprecated_Behavior, Undefined_Behavior, Portability, Performance, Other, Marker, Push_Group, Pop_Group); type Severity is (Notification, High, Medium, Low); type Callback_Reference is access procedure (From : Source; Kind : Message_Type; Level : Severity; ID : UInt; Message : String); -- By default Debug_Output_Synchronous is disabled (see GL.Toggles). -- The graphics driver may call the procedure from multiple tasks, -- concurrently, and/or asynchronously after executing an OpenGL command. procedure Set_Message_Callback (Callback : not null Callback_Reference); -- Set a message callback in order to receive debug messages -- -- Generated messages will no longer be appended to the message log, -- but instead passed to the given callback. Initially, messages with -- severity Low are not enabled. procedure Disable_Message_Callback; -- Clear current message callback and disable message output -- -- After having called this procedure, generated messages will instead -- be added to the message log. procedure Set (From : Source; Kind : Message_Type; Level : Severity; Enabled : Boolean); -- Enable or disable specific messages or groups of messages procedure Set (Level : Severity; Enabled : Boolean); -- Enable messages that have the given severity procedure Set (From : Source; Kind : Message_Type; Identifiers : UInt_Array; Enabled : Boolean) with Pre => Identifiers'Length > 0; -- Enable or disable messages that have one of the given message IDs procedure Insert_Message (From : Source; Kind : Message_Type; Level : Severity; Identifier : UInt; Message : String); -- Generate a new debug message -- -- From must be either Third_Party or Application. Instantiate the -- generic package Messages below if you need to print multiple -- messages with the same source and message type. -- -- The generated debug message will either be passed to the callback -- (if there is one), or added to the message log (if not full). type Active_Group is limited new Ada.Finalization.Limited_Controlled with private; function Push_Debug_Group (From : Source; Identifier : UInt; Message : String) return Active_Group'Class; -- Add a new debug group to the stack -- -- From must be either Third_Party or Application. -- -- The value returned is of a controlled type. This means you must -- assign it to some local variable, so that the debug group will be -- automatically removed when the variable goes out of scope. -- -- When the debug group is pushed onto the stack, a message -- is generated with the type Push_Group and severity Notification. -- -- Any further calls to Set will only apply to the active debug -- group. The currently active debug group inherits the message -- filtering from the previous active group. -- -- When the debug group is popped off the stack, a message is -- generated with type Pop_Group and severity Notification. procedure Annotate (Object : GL.Objects.GL_Object'Class; Message : String); -- Attach a label to the given object in order for the debug -- output to describe the object function Get_Label (Object : GL.Objects.GL_Object'Class) return String; -- Return the label attached to the given object function Max_Message_Length return Size with Post => Max_Message_Length'Result >= 1; generic From : Source; Kind : Message_Type; ID : UInt := 0; package Messages is procedure Log (Level : Severity; Message : String); -- Generate a new debug message end Messages; private for Source use (OpenGL => 16#8246#, Window_System => 16#8247#, Shader_Compiler => 16#8248#, Third_Party => 16#8249#, Application => 16#824A#, Other => 16#824B#); for Source'Size use Low_Level.Enum'Size; for Message_Type use (Error => 16#824C#, Deprecated_Behavior => 16#824D#, Undefined_Behavior => 16#824E#, Portability => 16#824F#, Performance => 16#8250#, Other => 16#8251#, Marker => 16#8268#, Push_Group => 16#8269#, Pop_Group => 16#826A#); for Message_Type'Size use Low_Level.Enum'Size; for Severity use (Notification => 16#826B#, High => 16#9146#, Medium => 16#9147#, Low => 16#9148#); for Severity'Size use Low_Level.Enum'Size; type Active_Group is limited new Ada.Finalization.Limited_Controlled with record Finalized : Boolean; end record; overriding procedure Finalize (Object : in out Active_Group); end GL.Debug;
------------------------------------------------------------------------------ -- Copyright (C) 2020 by Heisenbug Ltd. (gh+spat@heisenbug.eu) -- -- This work is free. You can redistribute it and/or modify it under the -- terms of the Do What The Fuck You Want To Public License, Version 2, -- as published by Sam Hocevar. See the LICENSE file for more details. ------------------------------------------------------------------------------ pragma License (Unrestricted); ------------------------------------------------------------------------------ -- -- SPARK Proof Analysis Tool -- -- S.P.A.T. - Main program -- ------------------------------------------------------------------------------ with Ada.Command_Line; with Ada.Directories; with Ada.Real_Time; with GNATCOLL.JSON; with GNATCOLL.Projects; with GNATCOLL.VFS; with SI_Units.Metric; with SI_Units.Names; with SPAT.Command_Line; with SPAT.GPR_Support; with SPAT.Log; with SPAT.Spark_Files; with SPAT.Spark_Info; with SPAT.Strings; with SPAT.Version; with System; ------------------------------------------------------------------------------ -- Run_SPAT ------------------------------------------------------------------------------ procedure Run_SPAT is --------------------------------------------------------------------------- -- Image --------------------------------------------------------------------------- function Image is new SI_Units.Metric.Fixed_Image (Item => Duration, Default_Aft => 0, Unit => SI_Units.Names.Second); --------------------------------------------------------------------------- -- Print_Entities --------------------------------------------------------------------------- procedure Print_Entities (Info : in SPAT.Spark_Info.T; Sort_By : in SPAT.Spark_Info.Sorting_Criterion); --------------------------------------------------------------------------- -- Print_Summary --------------------------------------------------------------------------- procedure Print_Summary (Info : in SPAT.Spark_Info.T; Sort_By : in SPAT.Spark_Info.Sorting_Criterion); --------------------------------------------------------------------------- -- Print_Entities --------------------------------------------------------------------------- procedure Print_Entities (Info : in SPAT.Spark_Info.T; Sort_By : in SPAT.Spark_Info.Sorting_Criterion) is separate; --------------------------------------------------------------------------- -- Print_Summary --------------------------------------------------------------------------- procedure Print_Summary (Info : in SPAT.Spark_Info.T; Sort_By : in SPAT.Spark_Info.Sorting_Criterion) is separate; use type Ada.Real_Time.Time; use type SPAT.Subject_Name; begin if not SPAT.Command_Line.Parser.Parse then SPAT.Spark_Files.Shutdown; Ada.Command_Line.Set_Exit_Status (Code => Ada.Command_Line.Failure); return; end if; if SPAT.Command_Line.Version.Get then SPAT.Log.Message (Message => "run_spat V" & SPAT.Version.Number & " (compiled by " & System.System_Name'Image & " " & SPAT.Version.Compiler & ")"); SPAT.Spark_Files.Shutdown; Ada.Command_Line.Set_Exit_Status (Code => Ada.Command_Line.Success); return; end if; if SPAT.Command_Line.Project.Get = SPAT.Null_Name then -- The project file option is mandatory (AFAICS there is no way to -- require an option argument). SPAT.Log.Message (Message => "Argument parsing failed: Missing project file argument"); SPAT.Log.Message (Message => SPAT.Command_Line.Parser.Help); SPAT.Spark_Files.Shutdown; Ada.Command_Line.Set_Exit_Status (Code => Ada.Command_Line.Failure); return; end if; Do_Run_SPAT : declare SPARK_Files : SPAT.Spark_Files.T; Start_Time : Ada.Real_Time.Time; Sort_By : constant SPAT.Spark_Info.Sorting_Criterion := SPAT.Command_Line.Sort_By.Get; Report_Mode : constant SPAT.Command_Line.Report_Mode := SPAT.Command_Line.Report.Get; Project_File : constant GNATCOLL.VFS.Filesystem_String := GNATCOLL.VFS."+" (S => SPAT.To_String (SPAT.Command_Line.Project.Get)); use type SPAT.Command_Line.Report_Mode; begin Collect_And_Parse : declare -- Step 1: Collect all .spark files. File_List : constant SPAT.Strings.File_Names := SPAT.GPR_Support.Get_SPARK_Files (GPR_File => Project_File); begin -- Step 2: Parse the files into JSON values. if not File_List.Is_Empty then SPAT.Log.Debug (Message => "Using up to" & SPAT.Spark_Files.Num_Workers'Image & " parsing threads."); Start_Time := Ada.Real_Time.Clock; SPARK_Files.Read (Names => File_List); SPAT.Log.Debug (Message => "Parsing completed in " & Image (Value => Ada.Real_Time.To_Duration (TS => Ada.Real_Time.Clock - Start_Time)) & "."); end if; end Collect_And_Parse; Process_And_Output : declare Info : SPAT.Spark_Info.T; begin -- Step 3: Process the JSON data. if not SPARK_Files.Is_Empty then Start_Time := Ada.Real_Time.Clock; for C in SPARK_Files.Iterate loop Parse_JSON_File : declare Read_Result : constant GNATCOLL.JSON.Read_Result := SPARK_Files (C); File : constant SPAT.File_Name := SPAT.Spark_Files.Key (C); begin if Read_Result.Success then Info.Map_Spark_File (Root => Read_Result.Value, File => File); else SPAT.Log.Warning (Message => SPAT.To_String (Source => File) & ": " & GNATCOLL.JSON.Format_Parsing_Error (Error => Read_Result.Error)); end if; end Parse_JSON_File; end loop; SPAT.Log.Debug (Message => "Reading completed in " & Image (Value => Ada.Real_Time.To_Duration (TS => Ada.Real_Time.Clock - Start_Time)) & "."); end if; -- Step 4: Output the JSON data. if SPAT.Command_Line.Summary.Get then Print_Summary (Info => Info, Sort_By => Sort_By); end if; if Report_Mode /= SPAT.Command_Line.None then Print_Entities (Info => Info, Sort_By => Sort_By); end if; end Process_And_Output; end Do_Run_SPAT; SPAT.Spark_Files.Shutdown; Ada.Command_Line.Set_Exit_Status (Code => Ada.Command_Line.Success); exception when others => SPAT.Spark_Files.Shutdown; raise; end Run_SPAT;
package FLTK.Widgets.Groups.Color_Choosers is type Color_Chooser is new Group with private; type Color_Chooser_Reference (Data : not null access Color_Chooser'Class) is limited null record with Implicit_Dereference => Data; type Color_Mode is (RGB, Byte, Hex, HSV); package Forge is function Create (X, Y, W, H : in Integer; Text : in String) return Color_Chooser; end Forge; function Get_Red (This : in Color_Chooser) return Long_Float; function Get_Green (This : in Color_Chooser) return Long_Float; function Get_Blue (This : in Color_Chooser) return Long_Float; procedure Set_RGB (This : in out Color_Chooser; R, G, B : in Long_Float); function Get_Hue (This : in Color_Chooser) return Long_Float; function Get_Saturation (This : in Color_Chooser) return Long_Float; function Get_Value (This : in Color_Chooser) return Long_Float; procedure Set_HSV (This : in out Color_Chooser; H, S, V : in Long_Float); procedure HSV_To_RGB (H, S, V : in Long_Float; R, G, B : out Long_Float); procedure RGB_To_HSV (R, G, B : in Long_Float; H, S, V : out Long_Float); function Color_Was_Changed (This : in Color_Chooser) return Boolean; procedure Clear_Changed (This : in out Color_Chooser); function Get_Mode (This : in Color_Chooser) return Color_Mode; procedure Set_Mode (This : in out Color_Chooser; To : in Color_Mode); procedure Draw (This : in out Color_Chooser); function Handle (This : in out Color_Chooser; Event : in Event_Kind) return Event_Outcome; private type Color_Chooser is new Group with record Was_Changed : Boolean := False; end record; overriding procedure Finalize (This : in out Color_Chooser); pragma Inline (Get_Red); pragma Inline (Get_Green); pragma Inline (Get_Blue); pragma Inline (Set_RGB); pragma Inline (Get_Hue); pragma Inline (Get_Saturation); pragma Inline (Get_Value); pragma Inline (Set_HSV); pragma Inline (HSV_To_RGB); pragma Inline (RGB_To_HSV); pragma Inline (Color_Was_Changed); pragma Inline (Clear_Changed); pragma Inline (Get_Mode); pragma Inline (Set_Mode); pragma Inline (Draw); pragma Inline (Handle); end FLTK.Widgets.Groups.Color_Choosers;
with deref1; package deref2 is type NT is tagged limited private; function PT_View (Obj : not null access NT) return not null access deref1.T'Class; private type PT (Obj : not null access NT) is new deref1.T with null record; type NT is tagged limited record PT_View : aliased PT (NT'Access); end record; end;
with STM32_SVD; use STM32_SVD; with STM32_SVD.GPIO; with STM32_SVD.USB; with Ada.Interrupts.Names; with System; generic Number : Integer; package STM32GD.USB.Endpoint is procedure Handle_Ctr; end STM32GD.USB.Endpoint;
-- C43214E.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- CHECK THAT THE LOWER BOUND FOR THE STRING LITERAL IS DETERMINED BY -- THE APPLICABLE INDEX CONSTRAINT, WHEN ONE EXISTS. -- EG 02/10/84 WITH REPORT; PROCEDURE C43214E IS USE REPORT; BEGIN TEST("C43214E", "INITIALIZATION OF CONSTRAINED ARRAY"); BEGIN CASE_D : BEGIN -- COMMENT ("CASE D1 : INITIALIZATION OF CONSTRAINED " & -- "ARRAY CONSTANT"); CASE_D1 : DECLARE D1 : CONSTANT STRING(11 .. 13) := "ABC"; BEGIN IF D1'FIRST /= 11 THEN FAILED ("CASE 1 : LOWER BOUND INCORRECT"); ELSIF D1'LAST /= 13 THEN FAILED ("CASE 1 : UPPER BOUND INCORRECT"); ELSIF D1 /= "ABC" THEN FAILED ("CASE 1 : ARRAY DOES NOT " & "CONTAIN THE CORRECT VALUES"); END IF; END CASE_D1; -- COMMENT ("CASE D2 : INITIALIZATION OF CONSTRAINED " & -- "ARRAY VARIABLE"); CASE_D2 : DECLARE D2 : STRING(11 .. 13) := "ABC"; BEGIN IF D2'FIRST /= 11 THEN FAILED ("CASE 2 : LOWER BOUND INCORRECT"); ELSIF D2'LAST /= 13 THEN FAILED ("CASE 2 : UPPER BOUND INCORRECT"); ELSIF D2 /= "ABC" THEN FAILED ("CASE 2 : INCORRECT VALUES"); END IF; END CASE_D2; -- COMMENT ("CASE D3 : INITIALIZATION OF CONSTRAINED " & -- "ARRAY FORMAL PARAMETER OF A SUBPROGRAM"); CASE_D3 : DECLARE SUBTYPE STD3 IS STRING(IDENT_INT(5) .. 7); PROCEDURE PROC1 (A : STD3 := "ABC") IS BEGIN IF A'FIRST /= 5 THEN FAILED ("CASE 3 : LOWER BOUND " & "INCORRECT"); ELSIF A'LAST /= 7 THEN FAILED ("CASE 3 : UPPER BOUND " & "INCORRECT"); ELSIF A /= "ABC" THEN FAILED ("CASE 3 : INCORRECT VALUES"); END IF; END PROC1; BEGIN PROC1; END CASE_D3; -- COMMENT ("CASE D4 : INITIALIZATION OF CONSTRAINED " & -- "ARRAY FORMAL PARAMETER OF A GENERIC UNIT"); CASE_D4 : DECLARE SUBTYPE STD4 IS STRING(5 .. 8); GENERIC D4 : STD4 := "ABCD"; PROCEDURE PROC1; PROCEDURE PROC1 IS BEGIN IF D4'FIRST /= 5 THEN FAILED ("CASE 4 : LOWER BOUND " & "INCORRECT"); ELSIF D4'LAST /= 8 THEN FAILED ("CASE 4 : UPPER BOUND " & "INCORRECT"); ELSIF D4 /= "ABCD" THEN FAILED ("CASE 4 : INCORRECT VALUES"); END IF; END PROC1; PROCEDURE PROC2 IS NEW PROC1; BEGIN PROC2; END CASE_D4; END CASE_D; END; RESULT; END C43214E;
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr> -- MIT license. Please refer to the LICENSE file. package body Apsepp.Generic_Array_Operations is ---------------------------------------------------------------------------- procedure Insert_Incr (A : in out Array_Type; Max_Insert_Index : Index_Type; Elem : Element_Type; Rev : Boolean := False) is -- TODO: Write a faster implementation (dichotomic search). <2019-04-06> ----------------------------------------------------- type Insert_Index_Ini_Func is not null access function return Index_Type; function I_I_I return Index_Type is (A'First); function I_I_I_R return Index_Type is (Max_Insert_Index); Insert_Index_Ini : constant Insert_Index_Ini_Func := (if Rev then I_I_I_R'Access else I_I_I'Access); ----------------------------------------------------- Insert_Index : Index_Type := Insert_Index_Ini.all; ----------------------------------------------------- type Shift_Insert_Index_Proc is not null access procedure; procedure S_I_I is begin Insert_Index := D.Su (Insert_Index); end S_I_I; procedure S_I_I_R is begin Insert_Index := D.Pr (Insert_Index); end S_I_I_R; Shift_Insert_Index : constant Shift_Insert_Index_Proc := (if Rev then S_I_I_R'Access else S_I_I'Access); ----------------------------------------------------- type Insert_Index_Found_Func is not null access function return Boolean; function I_I_F return Boolean is (Insert_Index = Max_Insert_Index or else Elem < A(Insert_Index) or else Elem = A(Insert_Index)); function I_I_F_R return Boolean is (Insert_Index = A'First or else A(D.Pr (Insert_Index)) < Elem or else A(D.Pr (Insert_Index)) = Elem); Insert_Index_Found : constant Insert_Index_Found_Func := (if Rev then I_I_F_R'Access else I_I_F'access); ----------------------------------------------------- begin while not Insert_Index_Found.all loop Shift_Insert_Index.all; end loop; A(D.Su (Insert_Index) .. Max_Insert_Index) := A(Insert_Index .. D.Pr (Max_Insert_Index)); A(Insert_Index) := Elem; end Insert_Incr; ---------------------------------------------------------------------------- end Apsepp.Generic_Array_Operations;
----------------------------------------------------------------------- -- hestia-network -- Hestia Network Manager -- Copyright (C) 2016, 2017 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Synchronous_Task_Control; with Net.Interfaces; with Net.Headers; with Net.Protos.Arp; with Net.Protos.Dispatchers; with HAL; with STM32.RNG.Interrupts; with STM32.Eth; with STM32.SDRAM; package body Hestia.Network is use type Ada.Real_Time.Time; Ready : Ada.Synchronous_Task_Control.Suspension_Object; -- ------------------------------ -- Initialize and start the network stack. -- ------------------------------ procedure Initialize is begin STM32.RNG.Interrupts.Initialize_RNG; -- STMicroelectronics OUI = 00 81 E1 Ifnet.Mac := (0, 16#81#, 16#E1#, 15, 5, 1); -- Setup some receive buffers and initialize the Ethernet driver. Net.Buffers.Add_Region (STM32.SDRAM.Reserve (Amount => HAL.UInt32 (NET_BUFFER_SIZE)), NET_BUFFER_SIZE); -- Initialize the Ethernet driver. STM32.Eth.Initialize_RMII; Ifnet.Initialize; Ada.Synchronous_Task_Control.Set_True (Ready); -- Initialize the DHCP client. Dhcp.Initialize (Ifnet'Access); Time_Ntp.Ttl_Deadline := Ada.Real_Time.Clock; end Initialize; -- ------------------------------ -- Do the network housekeeping and return the next deadline. -- ------------------------------ procedure Process (Deadline : out Ada.Real_Time.Time) is use type Net.DHCP.State_Type; use type Net.NTP.Status_Type; Dhcp_Deadline : Ada.Real_Time.Time; Ntp_Deadline : Ada.Real_Time.Time; Now : Ada.Real_Time.Time; Error : Net.Error_Code; begin Net.Protos.Arp.Timeout (Ifnet); Dhcp.Process (Dhcp_Deadline); Ntp_Deadline := Dhcp_Deadline; -- We have an IP address, do the NTP processing. if Dhcp.Get_State in Net.DHCP.STATE_BOUND | Net.DHCP.STATE_RENEWING | Net.DHCP.STATE_REBINDING then Now := Ada.Real_Time.Clock; if Time_Ntp.Ttl_Deadline < Now then Time_Ntp.Ttl_Deadline := Now + Ada.Real_Time.Seconds (5); Time_Ntp.Resolve (Ifnet'Access, "ntp.ubuntu.com", Error); elsif Time_Ntp.Server.Get_Status /= Net.NTP.NOSERVER then Time_Ntp.Server.Process (Ntp_Deadline); end if; end if; Deadline := (if Ntp_Deadline < Dhcp_Deadline then Ntp_Deadline else Dhcp_Deadline); end Process; -- ------------------------------ -- Get the NTP time reference. -- ------------------------------ function Get_Time return Net.NTP.NTP_Reference is begin return Time_Ntp.Server.Get_Reference; end Get_Time; -- ------------------------------ -- Save the answer received from the DNS server. This operation is called for each answer -- found in the DNS response packet. The Index is incremented at each answer. For example -- a DNS server can return a CNAME_RR answer followed by an A_RR: the operation is called -- two times. -- -- This operation can be overriden to implement specific actions when an answer is received. -- ------------------------------ overriding procedure Answer (Request : in out NTP_Client_Type; Status : in Net.DNS.Status_Type; Response : in Net.DNS.Response_Type; Index : in Natural) is pragma Unreferenced (Index); use type Net.DNS.Status_Type; use type Net.DNS.RR_Type; use type Net.Uint16; begin if Status = Net.DNS.NOERROR and then Response.Of_Type = Net.DNS.A_RR then Request.Ttl_Deadline := Ada.Real_Time.Clock + Ada.Real_Time.Seconds (Natural (Response.Ttl)); Request.Server.Initialize (Ifnet'Access, Response.Ip, Request.Port); end if; end Answer; -- ------------------------------ -- The task that waits for packets. -- ------------------------------ task body Controller is use type Net.Uint16; Packet : Net.Buffers.Buffer_Type; Ether : Net.Headers.Ether_Header_Access; begin -- Wait until the Ethernet driver is ready. Ada.Synchronous_Task_Control.Suspend_Until_True (Ready); loop if Packet.Is_Null then Net.Buffers.Allocate (Packet); end if; if not Packet.Is_Null then Ifnet.Receive (Packet); Ether := Packet.Ethernet; if Ether.Ether_Type = Net.Headers.To_Network (Net.Protos.ETHERTYPE_ARP) then Net.Protos.Arp.Receive (Ifnet, Packet); elsif Ether.Ether_Type = Net.Headers.To_Network (Net.Protos.ETHERTYPE_IP) then Net.Protos.Dispatchers.Receive (Ifnet, Packet); end if; else delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100); end if; end loop; end Controller; end Hestia.Network;
package body Concat1_Pkg is function Ident (I : Integer) return Integer is begin return I; end; end Concat1_Pkg;
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- P R J . E N V -- -- -- -- S p e c -- -- -- -- Copyright (C) 2001-2014, 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. -- -- -- ------------------------------------------------------------------------------ -- This package implements services for Project-aware tools, mostly related -- to the environment (configuration pragma files, path files, mapping files). with GNAT.Dynamic_HTables; with GNAT.OS_Lib; package Prj.Env is procedure Initialize (In_Tree : Project_Tree_Ref); -- Initialize global components relative to environment variables procedure Print_Sources (In_Tree : Project_Tree_Ref); -- Output the list of sources after Project files have been scanned procedure Create_Mapping (In_Tree : Project_Tree_Ref); -- Create in memory mapping from the sources of all the projects (in body -- of package Fmap), so that Osint.Find_File will find the correct path -- corresponding to a source. procedure Create_Temp_File (Shared : Shared_Project_Tree_Data_Access; Path_FD : out File_Descriptor; Path_Name : out Path_Name_Type; File_Use : String); -- Create temporary file, fail with an error if it could not be created procedure Create_Mapping_File (Project : Project_Id; Language : Name_Id; In_Tree : Project_Tree_Ref; Name : out Path_Name_Type); -- Create a temporary mapping file for project Project. For each source or -- template of Language in the Project, put the mapping of its file name -- and path name in this file. See fmap for a description of the format -- of the mapping file. -- -- Implementation note: we pass a language name, not a language_index here, -- since the latter would have to match exactly the index of that language -- for the specified project, and that is not information available in -- buildgpr.adb. procedure Create_Config_Pragmas_File (For_Project : Project_Id; In_Tree : Project_Tree_Ref); -- If we need SFN pragmas, either for non standard naming schemes or for -- individual units. procedure Create_New_Path_File (Shared : Shared_Project_Tree_Data_Access; Path_FD : out File_Descriptor; Path_Name : out Path_Name_Type); -- Create a new temporary path file, placing file name in Path_Name function Ada_Include_Path (Project : Project_Id; In_Tree : Project_Tree_Ref; Recursive : Boolean := False) return String; -- Get the source search path of a Project file. If Recursive it True, get -- all the source directories of the imported and modified project files -- (recursively). If Recursive is False, just get the path for the source -- directories of Project. Note: the resulting String may be empty if there -- is no source directory in the project file. function Ada_Objects_Path (Project : Project_Id; In_Tree : Project_Tree_Ref; Including_Libraries : Boolean := True) return String_Access; -- Get the ADA_OBJECTS_PATH of a Project file. For the first call with the -- exact same parameters, compute it and cache it. When Including_Libraries -- is True, the object directory of a library project is replaced with the -- library ALI directory of this project (usually the library directory of -- the project, except when attribute Library_ALI_Dir is declared) except -- when the library ALI directory does not contain any ALI file. procedure Set_Ada_Paths (Project : Project_Id; In_Tree : Project_Tree_Ref; Including_Libraries : Boolean; Include_Path : Boolean := True; Objects_Path : Boolean := True); -- Set the environment variables for additional project path files, after -- creating the path files if necessary. function File_Name_Of_Library_Unit_Body (Name : String; Project : Project_Id; In_Tree : Project_Tree_Ref; Main_Project_Only : Boolean := True; Full_Path : Boolean := False) return String; -- Returns the file name of a library unit, in canonical case. Name may or -- may not have an extension (corresponding to the naming scheme of the -- project). If there is no body with this name, but there is a spec, the -- name of the spec is returned. -- -- If Full_Path is False (the default), the simple file name is returned. -- If Full_Path is True, the absolute path name is returned. -- -- If neither a body nor a spec can be found, an empty string is returned. -- If Main_Project_Only is True, the unit must be an immediate source of -- Project. If it is False, it may be a source of one of its imported -- projects. function Project_Of (Name : String; Main_Project : Project_Id; In_Tree : Project_Tree_Ref) return Project_Id; -- Get the project of a source. The source file name may be truncated -- (".adb" or ".ads" may be missing). If the source is in a project being -- extended, return the ultimate extending project. If it is not a source -- of any project, return No_Project. procedure Get_Reference (Source_File_Name : String; In_Tree : Project_Tree_Ref; Project : out Project_Id; Path : out Path_Name_Type); -- Returns the project of a source and its path in displayable form generic with procedure Action (Path : String); procedure For_All_Source_Dirs (Project : Project_Id; In_Tree : Project_Tree_Ref); -- Iterate through all the source directories of a project, including those -- of imported or modified projects. Only returns those directories that -- potentially contain Ada sources (ie ignore projects that have no Ada -- sources generic with procedure Action (Path : String); procedure For_All_Object_Dirs (Project : Project_Id; Tree : Project_Tree_Ref); -- Iterate through all the object directories of a project, including those -- of imported or modified projects. ------------------ -- Project Path -- ------------------ type Project_Search_Path is private; -- An abstraction of the project path. This object provides subprograms -- to search for projects on the path (and caches the results to improve -- efficiency). No_Project_Search_Path : constant Project_Search_Path; procedure Initialize_Default_Project_Path (Self : in out Project_Search_Path; Target_Name : String; Runtime_Name : String := ""); -- Initialize Self. It will then contain the default project path on -- the given target and runtime (including directories specified by the -- environment variables GPR_PROJECT_PATH_FILE, GPR_PROJECT_PATH and -- ADA_PROJECT_PATH). If one of the directory or Target_Name is "-", then -- the path contains only those directories specified by the environment -- variables (except "-"). This does nothing if Self has already been -- initialized. procedure Copy (From : Project_Search_Path; To : out Project_Search_Path); -- Copy From into To procedure Initialize_Empty (Self : in out Project_Search_Path); -- Initialize self with an empty list of directories. If Self had already -- been set, it is reset. function Is_Initialized (Self : Project_Search_Path) return Boolean; -- Whether Self has been initialized procedure Free (Self : in out Project_Search_Path); -- Free the memory used by Self procedure Add_Directories (Self : in out Project_Search_Path; Path : String; Prepend : Boolean := False); -- Add one or more directories to the path. Directories added with this -- procedure are added in order after the current directory and before the -- path given by the environment variable GPR_PROJECT_PATH. A value of "-" -- will remove the default project directory from the project path. -- -- Calls to this subprogram must be performed before the first call to -- Find_Project below, or PATH will be added at the end of the search path. procedure Get_Path (Self : Project_Search_Path; Path : out String_Access); -- Return the current value of the project path, either the value set -- during elaboration of the package or, if procedure Set_Project_Path has -- been called, the value set by the last call to Set_Project_Path. The -- returned value must not be modified. -- Self must have been initialized first. procedure Set_Path (Self : in out Project_Search_Path; Path : String); -- Override the value of the project path. This also removes the implicit -- default search directories. generic with function Check_Filename (Name : String) return Boolean; function Find_Name_In_Path (Self : Project_Search_Path; Path : String) return String_Access; -- Find a name in the project search path of Self. Check_Filename is -- the predicate to valid the search. If Path is an absolute filename, -- simply calls the predicate with Path. Otherwise, calls the predicate -- for each component of the path. Stops as soon as the predicate -- returns True and returns the name, or returns null in case of failure. procedure Find_Project (Self : in out Project_Search_Path; Project_File_Name : String; Directory : String; Path : out Namet.Path_Name_Type); -- Search for a project with the given name either in Directory (which -- often will be the directory contain the project we are currently parsing -- and which we found a reference to another project), or in the project -- path Self. Self must have been initialized first. -- -- Project_File_Name can optionally contain directories, and the extension -- (.gpr) for the file name is optional. -- -- Returns No_Name if no such project was found function Get_Runtime_Path (Self : Project_Search_Path; Name : String) return String_Access; -- Compute the full path for the project-based runtime name. -- Name is simply searched on the project path. private package Projects_Paths is new GNAT.Dynamic_HTables.Simple_HTable (Header_Num => Header_Num, Element => Path_Name_Type, No_Element => No_Path, Key => Name_Id, Hash => Hash, Equal => "="); type Project_Search_Path is record Path : GNAT.OS_Lib.String_Access; -- As a special case, if the first character is '#:" or this variable -- is unset, this means that the PATH has not been fully initialized -- yet (although subprograms above will properly take care of that). Cache : Projects_Paths.Instance; end record; No_Project_Search_Path : constant Project_Search_Path := (Path => null, Cache => Projects_Paths.Nil); end Prj.Env;
with System; with System.Storage_Elements; with SAM.Main_Clock; with SAM.DMAC; with HAL; package body PyGamer is System_Vectors : constant HAL.UInt32; pragma Import (Asm, System_Vectors, "__vectors"); VTOR : System.Address with Volatile, Address => System.Storage_Elements.To_Address (16#E000_ED08#); procedure Unknown_Interrupt; pragma Export (C, Unknown_Interrupt, "__unknown_interrupt_handler"); ----------------------- -- Unknown_Interrupt -- ----------------------- procedure Unknown_Interrupt is begin raise Program_Error; end Unknown_Interrupt; begin -- Set the vector table address VTOR := System_Vectors'Address; -- Setup the clock system SAM.Clock_Setup_120Mhz.Initialize_Clocks; -- Turn on and enable DMAC SAM.Main_Clock.DMAC_On; SAM.DMAC.Enable (DMA_Descs'Access, DMA_WB'Access); end PyGamer;
-- Copyright 2016-2019 NXP -- All rights reserved.SPDX-License-Identifier: BSD-3-Clause -- This spec has been automatically generated from LPC55S6x.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package NXP_SVD.PUF is pragma Preelaborate; --------------- -- Registers -- --------------- -- PUF Control register type CTRL_Register is record -- Begin Zeroize operation for PUF and go to Error state zeroize : Boolean := False; -- Begin Enroll operation enroll : Boolean := False; -- Begin Start operation start : Boolean := False; -- Begin Set Intrinsic Key operation GENERATEKEY : Boolean := False; -- Begin Set User Key operation SETKEY : Boolean := False; -- unspecified Reserved_5_5 : HAL.Bit := 16#0#; -- Begin Get Key operation GETKEY : Boolean := False; -- unspecified Reserved_7_31 : HAL.UInt25 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CTRL_Register use record zeroize at 0 range 0 .. 0; enroll at 0 range 1 .. 1; start at 0 range 2 .. 2; GENERATEKEY at 0 range 3 .. 3; SETKEY at 0 range 4 .. 4; Reserved_5_5 at 0 range 5 .. 5; GETKEY at 0 range 6 .. 6; Reserved_7_31 at 0 range 7 .. 31; end record; subtype KEYINDEX_KEYIDX_Field is HAL.UInt4; -- PUF Key Index register type KEYINDEX_Register is record -- Key index for Set Key operations KEYIDX : KEYINDEX_KEYIDX_Field := 16#0#; -- unspecified Reserved_4_31 : HAL.UInt28 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for KEYINDEX_Register use record KEYIDX at 0 range 0 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; subtype KEYSIZE_KEYSIZE_Field is HAL.UInt6; -- PUF Key Size register type KEYSIZE_Register is record -- Key size for Set Key operations KEYSIZE : KEYSIZE_KEYSIZE_Field := 16#0#; -- unspecified Reserved_6_31 : HAL.UInt26 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for KEYSIZE_Register use record KEYSIZE at 0 range 0 .. 5; Reserved_6_31 at 0 range 6 .. 31; end record; -- PUF Status register type STAT_Register is record -- Read-only. Indicates that operation is in progress busy : Boolean; -- Read-only. Last operation was successful SUCCESS : Boolean; -- Read-only. PUF is in the Error state and no operations can be -- performed error : Boolean; -- unspecified Reserved_3_3 : HAL.Bit; -- Read-only. Request for next part of key KEYINREQ : Boolean; -- Read-only. Next part of key is available KEYOUTAVAIL : Boolean; -- Read-only. Request for next part of AC/KC CODEINREQ : Boolean; -- Read-only. Next part of AC/KC is available CODEOUTAVAIL : Boolean; -- unspecified Reserved_8_31 : HAL.UInt24; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for STAT_Register use record busy at 0 range 0 .. 0; SUCCESS at 0 range 1 .. 1; error at 0 range 2 .. 2; Reserved_3_3 at 0 range 3 .. 3; KEYINREQ at 0 range 4 .. 4; KEYOUTAVAIL at 0 range 5 .. 5; CODEINREQ at 0 range 6 .. 6; CODEOUTAVAIL at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- PUF Allow register type ALLOW_Register is record -- Read-only. Enroll operation is allowed ALLOWENROLL : Boolean; -- Read-only. Start operation is allowed ALLOWSTART : Boolean; -- Read-only. Set Key operations are allowed ALLOWSETKEY : Boolean; -- Read-only. Get Key operation is allowed ALLOWGETKEY : Boolean; -- unspecified Reserved_4_31 : HAL.UInt28; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for ALLOW_Register use record ALLOWENROLL at 0 range 0 .. 0; ALLOWSTART at 0 range 1 .. 1; ALLOWSETKEY at 0 range 2 .. 2; ALLOWGETKEY at 0 range 3 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; subtype KEYOUTINDEX_KEYOUTIDX_Field is HAL.UInt4; -- PUF Key Output Index register type KEYOUTINDEX_Register is record -- Read-only. Key index for the key that is currently output via the Key -- Output register KEYOUTIDX : KEYOUTINDEX_KEYOUTIDX_Field; -- unspecified Reserved_4_31 : HAL.UInt28; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for KEYOUTINDEX_Register use record KEYOUTIDX at 0 range 0 .. 3; Reserved_4_31 at 0 range 4 .. 31; end record; -- PUF Interface Status and clear register type IFSTAT_Register is record -- Indicates that an APB error has occurred,Writing logic1 clears the -- if_error bit ERROR : Boolean := False; -- unspecified Reserved_1_31 : HAL.UInt31 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for IFSTAT_Register use record ERROR at 0 range 0 .. 0; Reserved_1_31 at 0 range 1 .. 31; end record; -- PUF Interrupt Enable type INTEN_Register is record -- Enable corresponding interrupt. Note that bit numbers match those -- assigned in QK_SR (Quiddikey Status Register) READYEN : Boolean := False; -- Enable corresponding interrupt. Note that bit numbers match those -- assigned in QK_SR (Quiddikey Status Register) SUCCESEN : Boolean := False; -- Enable corresponding interrupt. Note that bit numbers match those -- assigned in QK_SR (Quiddikey Status Register) ERROREN : Boolean := False; -- unspecified Reserved_3_3 : HAL.Bit := 16#0#; -- Enable corresponding interrupt. Note that bit numbers match those -- assigned in QK_SR (Quiddikey Status Register) KEYINREQEN : Boolean := False; -- Enable corresponding interrupt. Note that bit numbers match those -- assigned in QK_SR (Quiddikey Status Register) KEYOUTAVAILEN : Boolean := False; -- Enable corresponding interrupt. Note that bit numbers match those -- assigned in QK_SR (Quiddikey Status Register) CODEINREQEN : Boolean := False; -- Enable corresponding interrupt. Note that bit numbers match those -- assigned in QK_SR (Quiddikey Status Register) CODEOUTAVAILEN : Boolean := False; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for INTEN_Register use record READYEN at 0 range 0 .. 0; SUCCESEN at 0 range 1 .. 1; ERROREN at 0 range 2 .. 2; Reserved_3_3 at 0 range 3 .. 3; KEYINREQEN at 0 range 4 .. 4; KEYOUTAVAILEN at 0 range 5 .. 5; CODEINREQEN at 0 range 6 .. 6; CODEOUTAVAILEN at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- PUF interrupt status type INTSTAT_Register is record -- Triggers on falling edge of busy, write 1 to clear READY : Boolean := False; -- Level sensitive interrupt, cleared when interrupt source clears SUCCESS : Boolean := False; -- Level sensitive interrupt, cleared when interrupt source clears ERROR : Boolean := False; -- unspecified Reserved_3_3 : HAL.Bit := 16#0#; -- Level sensitive interrupt, cleared when interrupt source clears KEYINREQ : Boolean := False; -- Level sensitive interrupt, cleared when interrupt source clears KEYOUTAVAIL : Boolean := False; -- Level sensitive interrupt, cleared when interrupt source clears CODEINREQ : Boolean := False; -- Level sensitive interrupt, cleared when interrupt source clears CODEOUTAVAIL : Boolean := False; -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for INTSTAT_Register use record READY at 0 range 0 .. 0; SUCCESS at 0 range 1 .. 1; ERROR at 0 range 2 .. 2; Reserved_3_3 at 0 range 3 .. 3; KEYINREQ at 0 range 4 .. 4; KEYOUTAVAIL at 0 range 5 .. 5; CODEINREQ at 0 range 6 .. 6; CODEOUTAVAIL at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- PUF RAM Power Control type PWRCTRL_Register is record -- Power on the PUF RAM. RAMON : Boolean := False; -- PUF RAM status. RAMSTAT : Boolean := False; -- unspecified Reserved_2_31 : HAL.UInt30 := 16#3E#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for PWRCTRL_Register use record RAMON at 0 range 0 .. 0; RAMSTAT at 0 range 1 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; -- PUF config register for block bits type CFG_Register is record -- Block enroll operation. Write 1 to set, cleared on reset. BLOCKENROLL_SETKEY : Boolean := False; -- Block set key operation. Write 1 to set, cleared on reset. BLOCKKEYOUTPUT : Boolean := False; -- unspecified Reserved_2_31 : HAL.UInt30 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CFG_Register use record BLOCKENROLL_SETKEY at 0 range 0 .. 0; BLOCKKEYOUTPUT at 0 range 1 .. 1; Reserved_2_31 at 0 range 2 .. 31; end record; -- KEYLOCK_KEY array element subtype KEYLOCK_KEY_Element is HAL.UInt2; -- KEYLOCK_KEY array type KEYLOCK_KEY_Field_Array is array (0 .. 3) of KEYLOCK_KEY_Element with Component_Size => 2, Size => 8; -- Type definition for KEYLOCK_KEY type KEYLOCK_KEY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- KEY as a value Val : HAL.UInt8; when True => -- KEY as an array Arr : KEYLOCK_KEY_Field_Array; end case; end record with Unchecked_Union, Size => 8; for KEYLOCK_KEY_Field use record Val at 0 range 0 .. 7; Arr at 0 range 0 .. 7; end record; -- Only reset in case of full IC reset type KEYLOCK_Register is record -- "10:Write access to KEY0MASK, KEYENABLE.KEY0 and KEYRESET.KEY0 is -- allowed. 00, 01, 11:Write access to KEY0MASK, KEYENABLE.KEY0 and -- KEYRESET.KEY0 is NOT allowed. Important Note : Once this field is -- written with a value different from '10', its value can no longer be -- modified until un Power On Reset occurs." KEY : KEYLOCK_KEY_Field := (As_Array => False, Val => 16#2#); -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for KEYLOCK_Register use record KEY at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- KEYENABLE_KEY array element subtype KEYENABLE_KEY_Element is HAL.UInt2; -- KEYENABLE_KEY array type KEYENABLE_KEY_Field_Array is array (0 .. 3) of KEYENABLE_KEY_Element with Component_Size => 2, Size => 8; -- Type definition for KEYENABLE_KEY type KEYENABLE_KEY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- KEY as a value Val : HAL.UInt8; when True => -- KEY as an array Arr : KEYENABLE_KEY_Field_Array; end case; end record with Unchecked_Union, Size => 8; for KEYENABLE_KEY_Field use record Val at 0 range 0 .. 7; Arr at 0 range 0 .. 7; end record; -- no description available type KEYENABLE_Register is record -- "10: Data coming out from PUF Index 0 interface are shifted in KEY0 -- register. 00, 01, 11 : Data coming out from PUF Index 0 interface are -- NOT shifted in KEY0 register." KEY : KEYENABLE_KEY_Field := (As_Array => False, Val => 16#1#); -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for KEYENABLE_Register use record KEY at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- KEYRESET_KEY array element subtype KEYRESET_KEY_Element is HAL.UInt2; -- KEYRESET_KEY array type KEYRESET_KEY_Field_Array is array (0 .. 3) of KEYRESET_KEY_Element with Component_Size => 2, Size => 8; -- Type definition for KEYRESET_KEY type KEYRESET_KEY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- KEY as a value Val : HAL.UInt8; when True => -- KEY as an array Arr : KEYRESET_KEY_Field_Array; end case; end record with Unchecked_Union, Size => 8; for KEYRESET_KEY_Field use record Val at 0 range 0 .. 7; Arr at 0 range 0 .. 7; end record; -- Reinitialize Keys shift registers counters type KEYRESET_Register is record -- Write-only. 10: Reset KEY0 shift register. Self clearing. Must be -- done before loading any new key. KEY : KEYRESET_KEY_Field := (As_Array => False, Val => 16#0#); -- unspecified Reserved_8_31 : HAL.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for KEYRESET_Register use record KEY at 0 range 0 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; -- IDXBLK_L_IDX array element subtype IDXBLK_L_IDX_Element is HAL.UInt2; -- IDXBLK_L_IDX array type IDXBLK_L_IDX_Field_Array is array (1 .. 7) of IDXBLK_L_IDX_Element with Component_Size => 2, Size => 14; -- Type definition for IDXBLK_L_IDX type IDXBLK_L_IDX_Field (As_Array : Boolean := False) is record case As_Array is when False => -- IDX as a value Val : HAL.UInt14; when True => -- IDX as an array Arr : IDXBLK_L_IDX_Field_Array; end case; end record with Unchecked_Union, Size => 14; for IDXBLK_L_IDX_Field use record Val at 0 range 0 .. 13; Arr at 0 range 0 .. 13; end record; subtype IDXBLK_L_LOCK_IDX_Field is HAL.UInt2; -- no description available type IDXBLK_L_Register is record -- unspecified Reserved_0_1 : HAL.UInt2 := 16#2#; -- Use to block PUF index 1 IDX : IDXBLK_L_IDX_Field := (As_Array => False, Val => 16#2#); -- unspecified Reserved_16_29 : HAL.UInt14 := 16#0#; -- Write-only. Lock 0 to 7 PUF key indexes LOCK_IDX : IDXBLK_L_LOCK_IDX_Field := 16#2#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for IDXBLK_L_Register use record Reserved_0_1 at 0 range 0 .. 1; IDX at 0 range 2 .. 15; Reserved_16_29 at 0 range 16 .. 29; LOCK_IDX at 0 range 30 .. 31; end record; -- IDXBLK_H_DP_IDX array element subtype IDXBLK_H_DP_IDX_Element is HAL.UInt2; -- IDXBLK_H_DP_IDX array type IDXBLK_H_DP_IDX_Field_Array is array (8 .. 15) of IDXBLK_H_DP_IDX_Element with Component_Size => 2, Size => 16; -- Type definition for IDXBLK_H_DP_IDX type IDXBLK_H_DP_IDX_Field (As_Array : Boolean := False) is record case As_Array is when False => -- IDX as a value Val : HAL.UInt16; when True => -- IDX as an array Arr : IDXBLK_H_DP_IDX_Field_Array; end case; end record with Unchecked_Union, Size => 16; for IDXBLK_H_DP_IDX_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; -- no description available type IDXBLK_H_DP_Register is record -- Use to block PUF index 8 IDX : IDXBLK_H_DP_IDX_Field := (As_Array => False, Val => 16#2#); -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for IDXBLK_H_DP_Register use record IDX at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- Only reset in case of full IC reset -- Only reset in case of full IC reset type KEYMASK_Registers is array (0 .. 3) of HAL.UInt32 with Volatile; -- IDXBLK_H_IDX array element subtype IDXBLK_H_IDX_Element is HAL.UInt2; -- IDXBLK_H_IDX array type IDXBLK_H_IDX_Field_Array is array (8 .. 15) of IDXBLK_H_IDX_Element with Component_Size => 2, Size => 16; -- Type definition for IDXBLK_H_IDX type IDXBLK_H_IDX_Field (As_Array : Boolean := False) is record case As_Array is when False => -- IDX as a value Val : HAL.UInt16; when True => -- IDX as an array Arr : IDXBLK_H_IDX_Field_Array; end case; end record with Unchecked_Union, Size => 16; for IDXBLK_H_IDX_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; subtype IDXBLK_H_LOCK_IDX_Field is HAL.UInt2; -- no description available type IDXBLK_H_Register is record -- Use to block PUF index 8 IDX : IDXBLK_H_IDX_Field := (As_Array => False, Val => 16#2#); -- unspecified Reserved_16_29 : HAL.UInt14 := 16#0#; -- Write-only. Lock 8 to 15 PUF key indexes LOCK_IDX : IDXBLK_H_LOCK_IDX_Field := 16#2#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for IDXBLK_H_Register use record IDX at 0 range 0 .. 15; Reserved_16_29 at 0 range 16 .. 29; LOCK_IDX at 0 range 30 .. 31; end record; -- IDXBLK_L_DP_IDX array element subtype IDXBLK_L_DP_IDX_Element is HAL.UInt2; -- IDXBLK_L_DP_IDX array type IDXBLK_L_DP_IDX_Field_Array is array (1 .. 7) of IDXBLK_L_DP_IDX_Element with Component_Size => 2, Size => 14; -- Type definition for IDXBLK_L_DP_IDX type IDXBLK_L_DP_IDX_Field (As_Array : Boolean := False) is record case As_Array is when False => -- IDX as a value Val : HAL.UInt14; when True => -- IDX as an array Arr : IDXBLK_L_DP_IDX_Field_Array; end case; end record with Unchecked_Union, Size => 14; for IDXBLK_L_DP_IDX_Field use record Val at 0 range 0 .. 13; Arr at 0 range 0 .. 13; end record; -- no description available type IDXBLK_L_DP_Register is record -- unspecified Reserved_0_1 : HAL.UInt2 := 16#2#; -- Use to block PUF index 1 IDX : IDXBLK_L_DP_IDX_Field := (As_Array => False, Val => 16#2#); -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for IDXBLK_L_DP_Register use record Reserved_0_1 at 0 range 0 .. 1; IDX at 0 range 2 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; -- SHIFT_STATUS_KEY array element subtype SHIFT_STATUS_KEY_Element is HAL.UInt4; -- SHIFT_STATUS_KEY array type SHIFT_STATUS_KEY_Field_Array is array (0 .. 3) of SHIFT_STATUS_KEY_Element with Component_Size => 4, Size => 16; -- Type definition for SHIFT_STATUS_KEY type SHIFT_STATUS_KEY_Field (As_Array : Boolean := False) is record case As_Array is when False => -- KEY as a value Val : HAL.UInt16; when True => -- KEY as an array Arr : SHIFT_STATUS_KEY_Field_Array; end case; end record with Unchecked_Union, Size => 16; for SHIFT_STATUS_KEY_Field use record Val at 0 range 0 .. 15; Arr at 0 range 0 .. 15; end record; -- no description available type SHIFT_STATUS_Register is record -- Read-only. Index counter from key 0 shift register KEY : SHIFT_STATUS_KEY_Field; -- unspecified Reserved_16_31 : HAL.UInt16; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SHIFT_STATUS_Register use record KEY at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- PUFCTRL type PUF_Peripheral is record -- PUF Control register CTRL : aliased CTRL_Register; -- PUF Key Index register KEYINDEX : aliased KEYINDEX_Register; -- PUF Key Size register KEYSIZE : aliased KEYSIZE_Register; -- PUF Status register STAT : aliased STAT_Register; -- PUF Allow register ALLOW : aliased ALLOW_Register; -- PUF Key Input register KEYINPUT : aliased HAL.UInt32; -- PUF Code Input register CODEINPUT : aliased HAL.UInt32; -- PUF Code Output register CODEOUTPUT : aliased HAL.UInt32; -- PUF Key Output Index register KEYOUTINDEX : aliased KEYOUTINDEX_Register; -- PUF Key Output register KEYOUTPUT : aliased HAL.UInt32; -- PUF Interface Status and clear register IFSTAT : aliased IFSTAT_Register; -- PUF version register. VERSION : aliased HAL.UInt32; -- PUF Interrupt Enable INTEN : aliased INTEN_Register; -- PUF interrupt status INTSTAT : aliased INTSTAT_Register; -- PUF RAM Power Control PWRCTRL : aliased PWRCTRL_Register; -- PUF config register for block bits CFG : aliased CFG_Register; -- Only reset in case of full IC reset KEYLOCK : aliased KEYLOCK_Register; -- no description available KEYENABLE : aliased KEYENABLE_Register; -- Reinitialize Keys shift registers counters KEYRESET : aliased KEYRESET_Register; -- no description available IDXBLK_L : aliased IDXBLK_L_Register; -- no description available IDXBLK_H_DP : aliased IDXBLK_H_DP_Register; -- Only reset in case of full IC reset KEYMASK : aliased KEYMASK_Registers; -- no description available IDXBLK_H : aliased IDXBLK_H_Register; -- no description available IDXBLK_L_DP : aliased IDXBLK_L_DP_Register; -- no description available SHIFT_STATUS : aliased SHIFT_STATUS_Register; end record with Volatile; for PUF_Peripheral use record CTRL at 16#0# range 0 .. 31; KEYINDEX at 16#4# range 0 .. 31; KEYSIZE at 16#8# range 0 .. 31; STAT at 16#20# range 0 .. 31; ALLOW at 16#28# range 0 .. 31; KEYINPUT at 16#40# range 0 .. 31; CODEINPUT at 16#44# range 0 .. 31; CODEOUTPUT at 16#48# range 0 .. 31; KEYOUTINDEX at 16#60# range 0 .. 31; KEYOUTPUT at 16#64# range 0 .. 31; IFSTAT at 16#DC# range 0 .. 31; VERSION at 16#FC# range 0 .. 31; INTEN at 16#100# range 0 .. 31; INTSTAT at 16#104# range 0 .. 31; PWRCTRL at 16#108# range 0 .. 31; CFG at 16#10C# range 0 .. 31; KEYLOCK at 16#200# range 0 .. 31; KEYENABLE at 16#204# range 0 .. 31; KEYRESET at 16#208# range 0 .. 31; IDXBLK_L at 16#20C# range 0 .. 31; IDXBLK_H_DP at 16#210# range 0 .. 31; KEYMASK at 16#214# range 0 .. 127; IDXBLK_H at 16#254# range 0 .. 31; IDXBLK_L_DP at 16#258# range 0 .. 31; SHIFT_STATUS at 16#25C# range 0 .. 31; end record; -- PUFCTRL PUF_Periph : aliased PUF_Peripheral with Import, Address => System'To_Address (16#4003B000#); end NXP_SVD.PUF;
-- Task 2 of RTPL WS17/18 -- Team members: Hannes B. and Gabriel Z. package dice is -- Procedure for option 8 procedure opt8; private -- Counting procedure procedure myDice; end dice;
-- reqrep_task_pool.adb -- A task pool system for simple request-response activity -- Copyright (c) 2015, James Humphry -- -- Permission to use, copy, modify, and/or distribute this software for any -- purpose with or without fee is hereby granted, provided that the above -- copyright notice and this permission notice appear in all copies. -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -- PERFORMANCE OF THIS SOFTWARE. pragma Profile(No_Implementation_Extensions); with Ada.Containers; use all type Ada.Containers.Count_Type; with Ada.Containers.Doubly_Linked_Lists; with Ada.Task_Identification, Ada.Task_Termination; use all type Ada.Task_Identification.Task_Id; use all type Ada.Task_Termination.Cause_Of_Termination; package body Reqrep_Task_Pools is --------------- -- Task_Pool -- --------------- package body Task_Pool is function Status (R : Reqrep_Job) return Reqrep_Status is (R.Status); package Work_Queues is new Ada.Containers.Doubly_Linked_Lists (Element_Type => Reqrep_Job); use all type Work_Queues.List; ------------ -- Queues -- ------------ protected Queues is procedure Push_Job (R : in Reqrep_Job); procedure Push_Result (R : in Reqrep_Job); entry Push_Exception (R : in Reqrep_Job; E : in Ada.Exceptions.Exception_Occurrence); entry Get_Job (R : out Reqrep_Job); entry Get_Result (R : out Reqrep_Job); entry Get_Exception (E : out Ada.Exceptions.Exception_Occurrence); procedure Discard_Exception; procedure Initiate_Shutdown; private Input_Queue : Work_Queues.List := Work_Queues.Empty_List; Output_Queue : Work_Queues.List := Work_Queues.Empty_List; Unhandled_Exception : Boolean := False; Unhandled_Occurrence : Ada.Exceptions.Exception_Occurrence; In_Shutdown : Boolean := False; end Queues; protected body Queues is procedure Push_Job (R : in Reqrep_Job) is begin Input_Queue.Append (R); end Push_Job; procedure Push_Result (R : in Reqrep_Job) is begin Output_Queue.Append (R); end Push_Result; entry Push_Exception (R : in Reqrep_Job; E : in Ada.Exceptions.Exception_Occurrence) when not Unhandled_Exception is begin Unhandled_Exception := True; Ada.Exceptions.Save_Occurrence(Unhandled_Occurrence, E); Output_Queue.Append (R); end Push_Exception; entry Get_Job (R : out Reqrep_Job) when In_Shutdown or Input_Queue.Length > 0 is begin if In_Shutdown then R := Reqrep_Job'(Shutdown => True, others => <>); else R := Input_Queue.First_Element; Input_Queue.Delete_First; end if; end Get_Job; entry Get_Result (R : out Reqrep_Job) when Output_Queue.Length > 0 is begin R := Output_Queue.First_Element; Output_Queue.Delete_First; end Get_Result; entry Get_Exception (E : out Ada.Exceptions.Exception_Occurrence) when Unhandled_Exception is begin Ada.Exceptions.Save_Occurrence(E, Unhandled_Occurrence); Unhandled_Exception := False; end Get_Exception; procedure Discard_Exception is begin Unhandled_Exception := False; end Discard_Exception; procedure Initiate_Shutdown is begin In_Shutdown := True; end Initiate_Shutdown; end Queues; procedure Push_Job (R : in Reqrep; Timeout : Duration := Default_Timeout) is begin Queues.Push_Job (Reqrep_Job' (R with Status => Ready, Timeout => Timeout, Shutdown => False)); end Push_Job; function Get_Result return Reqrep_Job is R : Reqrep_Job; begin Queues.Get_Result (R); return R; end Get_Result; function Get_Result return Reqrep is R : Reqrep_Job; begin Queues.Get_Result (R); return Reqrep (R); end Get_Result; procedure Get_Exception(E : out Ada.Exceptions.Exception_Occurrence) is begin select Queues.Get_Exception(E); else Ada.Exceptions.Save_Occurrence(E, Ada.Exceptions.Null_Occurrence); end select; end Get_Exception; procedure Discard_Exception is begin Queues.Discard_Exception; end Discard_Exception; procedure Shutdown is begin Queues.Initiate_Shutdown; end Shutdown; ------------------- -- Reqrep_Worker -- ------------------- task type Reqrep_Worker is entry Start; end; task body Reqrep_Worker is R : Reqrep_Job; begin accept Start; loop Queues.Get_Job (R); if R.Shutdown then exit; else R.Status := Active; select delay R.Timeout; R.Status := Timeout; then abort begin R.Status := Execute (Reqrep (R)); exception when Event : Inject_Worker_Crash => raise; when Event : others => R.Status := Unhandled_Exception; Queues.Push_Exception(R, Event); end; end select; if R.Status /= Unhandled_Exception then Queues.Push_Result (R); end if; end if; end loop; end Reqrep_Worker; Workers : array (Positive range 1 .. Number_Workers) of access Reqrep_Worker; function Active_Workers return Natural is Result : Natural := 0; begin for I in Workers'Range loop if not Ada.Task_Identification.Is_Terminated(Workers(I)'Identity) then Result := Result + 1; end if; end loop; return Result; end Active_Workers; protected body Termination_Handler is procedure Handle_Termination(Cause : in Ada.Task_Termination.Cause_Of_Termination; T : in Ada.Task_Identification.Task_Id; X : in Ada.Exceptions.Exception_Occurrence) is begin case Cause is when Normal => null; when Abnormal => Queues.Push_Result(Reqrep_Job'(Status => Internal_Error, others => <>)); when Unhandled_Exception => select Queues.Push_Exception(Reqrep_Job'(Status => Internal_Error, others => <>), X); else Queues.Push_Result(Reqrep_Job'(Status => Internal_Error, others => <>)); end select; end case; end Handle_Termination; end Termination_Handler; begin for I in Workers'Range loop Workers(I) := new Reqrep_Worker; Ada.Task_Termination.Set_Specific_Handler(Workers(I).all'Identity, Termination_Handler_Access); Workers(I).Start; end loop; end Task_Pool; end Reqrep_Task_Pools;
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Ada.Containers.Hashed_Maps; package body Program.Visibility is use all type Program.Visibility.Symbol; type Allocated_Snapshot is access all Snapshot; procedure Append_Item (Self : in out Context'Class; Value : Item); function Get_View (Env : access constant Context; Index : Item_Offset_Positive) return View; function To_Vector (List : View_Array) return Item_Offset_Vectors.Vector; function Immediate_Visible (Self : access constant Context; Region : Item_Offset; Symbol : Program.Visibility.Symbol) return View_Array; ----------------- -- Append_Item -- ----------------- procedure Append_Item (Self : in out Context'Class; Value : Item) is begin Self.Last_Entity := Self.Last_Entity + 1; Self.Data.Append (Value); if not Self.Stack.Is_Empty then Self.Data (Self.Stack.Last_Element.Enclosing_Item).Region.Append (Self.Data.Last_Index); end if; end Append_Item; --------------- -- Component -- --------------- function Component (Self : View) return View is Type_Item : Item renames Self.Env.Data (Self.Index); begin return Self.Env.Get_View (Type_Item.Component); end Component; ----------------------- -- Create_Array_Type -- ----------------------- not overriding procedure Create_Array_Type (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name; Indexes : View_Array; Component : View) is Value : constant Item := (Kind => Array_Type_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1, Indexes => To_Vector (Indexes), Component => Component.Index); begin Self.Append_Item (Value); end Create_Array_Type; ------------------------------ -- Create_Character_Literal -- ------------------------------ not overriding procedure Create_Character_Literal (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name; Enumeration_Type : View) is Value : constant Item := (Kind => Character_Literal_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1, Character_Type => Enumeration_Type.Index); begin Self.Append_Item (Value); declare Type_Item : Item renames Self.Data (Enumeration_Type.Index); begin Type_Item.Enumeration_Literals.Append (Self.Data.Last_Index); end; end Create_Character_Literal; ------------------------------ -- Create_Character_Literal -- ------------------------------ not overriding procedure Create_Character_Literal (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name; Meta_Character : Meta_Character_Literal_Kind; Enumeration_Type : View) is pragma Unreferenced (Meta_Character); Value : constant Item := (Kind => Character_Literal_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1, Character_Type => Enumeration_Type.Index); begin Self.Append_Item (Value); declare Type_Item : Item renames Self.Data (Enumeration_Type.Index); begin Type_Item.Enumeration_Literals.Append (Self.Data.Last_Index); end; end Create_Character_Literal; -------------------------- -- Create_Empty_Context -- -------------------------- not overriding procedure Create_Empty_Context (Self : aliased in out Context) is begin Self.Last_Entity := 0; Self.Data := Item_Vectors.Empty_Vector; Self.Stack := Region_Vectors.Empty_Vector; end Create_Empty_Context; -------------------------------- -- Create_Enumeration_Literal -- -------------------------------- not overriding procedure Create_Enumeration_Literal (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name; Enumeration_Type : View) is Value : constant Item := (Kind => Enumeration_Literal_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1, Enumeration_Type => Enumeration_Type.Index); begin Self.Append_Item (Value); declare Type_Item : Item renames Self.Data (Enumeration_Type.Index); begin Type_Item.Enumeration_Literals.Append (Self.Data.Last_Index); end; end Create_Enumeration_Literal; ----------------------------- -- Create_Enumeration_Type -- ----------------------------- not overriding procedure Create_Enumeration_Type (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name) is Value : constant Item := (Kind => Enumeration_Type_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1, Enumeration_Literals => Item_Offset_Vectors.Empty_Vector, Is_Character_Type => False); begin Self.Append_Item (Value); end Create_Enumeration_Type; ---------------------- -- Create_Exception -- ---------------------- not overriding procedure Create_Exception (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name) is Value : constant Item := (Kind => Exception_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1); begin Self.Append_Item (Value); end Create_Exception; ----------------------------- -- Create_Float_Point_Type -- ----------------------------- not overriding procedure Create_Float_Point_Type (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name) is Value : constant Item := (Kind => Float_Point_Type_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1); begin Self.Append_Item (Value); end Create_Float_Point_Type; -------------------------- -- Create_Implicit_Type -- -------------------------- not overriding procedure Create_Implicit_Type (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name) is Value : constant Item := (Kind => Implicit_Type_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1); begin Self.Append_Item (Value); end Create_Implicit_Type; ------------------------- -- Create_Modular_Type -- ------------------------- not overriding procedure Create_Modular_Type (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name) is Value : constant Item := (Kind => Modular_Type_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1); begin Self.Append_Item (Value); end Create_Modular_Type; -------------------- -- Create_Package -- -------------------- not overriding procedure Create_Package (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name) is Value : constant Item := (Kind => Package_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1, Region => Item_Offset_Vectors.Empty_Vector); begin Self.Append_Item (Value); Self.Stack.Append ((Enclosing_Item => Self.Data.Last_Index)); end Create_Package; -------------------------------- -- Create_Signed_Integer_Type -- -------------------------------- not overriding procedure Create_Signed_Integer_Type (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name) is Value : constant Item := (Kind => Signed_Integer_Type_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1); begin Self.Append_Item (Value); end Create_Signed_Integer_Type; --------------------- -- Create_Snapshot -- --------------------- not overriding function Create_Snapshot (Self : aliased in out Context) return Snapshot_Access is Result : constant Allocated_Snapshot := new Snapshot'(Stack => Self.Stack, Data => Self.Data); begin return Snapshot_Access (Result); end Create_Snapshot; -------------------- -- Create_Subtype -- -------------------- not overriding procedure Create_Subtype (Self : in out Context; Symbol : Program.Visibility.Symbol; Name : Defining_Name; Subtype_Mark : View; Has_Constraint : Boolean) is Value : constant Item := (Kind => Subtype_View, Symbol => Symbol, Name => Name, Entity_Id => Self.Last_Entity + 1, Subtype_Mark => Subtype_Mark.Index, Has_Constraint => Has_Constraint); begin Self.Append_Item (Value); end Create_Subtype; -------------------- -- Enter_Snapshot -- -------------------- not overriding procedure Enter_Snapshot (Self : in out Context; Snapshot : not null Snapshot_Access) is -- We create 3 maps: -- Keep_Map - elements to keep in context (above subtree) -- Update_Map - elements of subtree to be replaced by Snapshot elements -- Added_Map - new elements to be added from Snapshot function Hash (Value : Entity_Identifier) return Ada.Containers.Hash_Type is (Ada.Containers.Hash_Type (Value)); package Entity_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Entity_Identifier, Element_Type => Item_Offset_Positive, Hash => Hash, Equivalent_Keys => "=", "=" => "="); procedure Append (Data : Item_Vectors.Vector; Region : Item_Offset_Positive; Map : in out Entity_Maps.Map); function Update_Index (Index : Item_Offset_Positive) -- In Snapshot return Item_Offset_Positive; -- In Env procedure Update_Index (Index : in out Item_Offset_Positive); procedure Update_Vector (Region : in out Item_Offset_Vectors.Vector); ------------ -- Append -- ------------ procedure Append (Data : Item_Vectors.Vector; Region : Item_Offset_Positive; Map : in out Entity_Maps.Map) is Region_Item : Item renames Data (Region); begin Map.Insert (Region_Item.Entity_Id, Region); if Region_Item.Kind not in Has_Region_Kind then return; end if; for Index of Region_Item.Region loop declare Value : constant Item := Data (Index); begin if not Map.Contains (Value.Entity_Id) then Append (Data, Index, Map); end if; end; end loop; end Append; Replaced_Items : Entity_Maps.Map; -- In Env Replacing_Items : Entity_Maps.Map; -- In Snapshot Added_Items : Entity_Maps.Map; -- In Env ------------------ -- Update_Index -- ------------------ function Update_Index (Index : Item_Offset_Positive) -- In Snapshot return Item_Offset_Positive -- In Env is Id : constant Entity_Identifier := Snapshot.Data (Index).Entity_Id; begin if Replaced_Items.Contains (Id) then return Replaced_Items (Id); else return Added_Items.Element (Id); end if; end Update_Index; ------------------ -- Update_Index -- ------------------ procedure Update_Index (Index : in out Item_Offset_Positive) is begin Index := Update_Index (Index); end Update_Index; ------------------- -- Update_Vector -- ------------------- procedure Update_Vector (Region : in out Item_Offset_Vectors.Vector) is begin for Ref of Region loop Ref := Update_Index (Ref); end loop; end Update_Vector; Env_Map : Entity_Maps.Map; Top_In_Snapshot : constant Item_Offset_Positive := -- In Snapshot Snapshot.Stack.Last_Element.Enclosing_Item; Top_Item_In_Snapshot : Item renames Snapshot.Data (Top_In_Snapshot); Replaced_Item : Item_Offset_Positive; -- In Env begin for Region of reverse Self.Stack loop Append (Self.Data, Region.Enclosing_Item, Env_Map); end loop; Replaced_Item := Env_Map.Element (Top_Item_In_Snapshot.Entity_Id); Append (Self.Data, Replaced_Item, Replaced_Items); Append (Snapshot.Data, Top_In_Snapshot, Replacing_Items); -- Assign indexes to added items declare Key : Entity_Identifier; Last : Item_Offset := Self.Data.Last_Index; begin for Cursor in Replacing_Items.Iterate loop Key := Entity_Maps.Key (Cursor); if not Replaced_Items.Contains (Key) then Last := Last + 1; Added_Items.Insert (Key, Last); end if; end loop; Self.Data.Set_Length (Ada.Containers.Count_Type (Last)); end; -- Copy items from snapshot to env for Index of Replacing_Items loop declare Value : Item := Snapshot.Data (Index); To : constant Item_Offset_Positive := Update_Index (Index); begin case Value.Kind is when Has_Region_Kind => Update_Vector (Value.Region); when others => case Value.Kind is when Enumeration_Type_View => Update_Vector (Value.Enumeration_Literals); when Enumeration_Literal_View => Update_Index (Value.Enumeration_Type); when Subtype_View => Update_Index (Value.Subtype_Mark); when Array_Type_View => Update_Vector (Value.Indexes); Update_Index (Value.Component); when others => null; end case; end case; Replaced_Items.Exclude (Value.Entity_Id); Self.Data.Replace_Element (To, Value); end; end loop; pragma Assert (Replaced_Items.Is_Empty); Self.Stack.Append ((Enclosing_Item => Replaced_Item)); end Enter_Snapshot; -------------------------- -- Enumeration_Literals -- -------------------------- function Enumeration_Literals (Self : View) return View_Array is Type_Item : Item renames Self.Env.Data (Self.Index); Last : Positive := 1; begin return Result : View_Array (1 .. Type_Item.Enumeration_Literals.Last_Index) do for J of Type_Item.Enumeration_Literals loop Result (Last) := Self.Env.Get_View (J); Last := Last + 1; end loop; end return; end Enumeration_Literals; ---------------------- -- Enumeration_Type -- ---------------------- function Enumeration_Type (Self : View) return View is Literal_Item : Item renames Self.Env.Data (Self.Index); begin return Self.Env.Get_View (Literal_Item.Enumeration_Type); end Enumeration_Type; -------------- -- Get_View -- -------------- function Get_View (Env : access constant Context; Index : Item_Offset_Positive) return View is Value : Item renames Env.Data (Index); begin return (Kind => Value.Kind, Env => Env, Index => Index); end Get_View; -------------------- -- Has_Constraint -- -------------------- function Has_Constraint (Self : View) return Boolean is Subtype_Item : Item renames Self.Env.Data (Self.Index); begin return Subtype_Item.Has_Constraint; end Has_Constraint; ---------------- -- Has_Region -- ---------------- function Has_Region (Self : View) return Boolean is begin return Self.Kind in Package_View; end Has_Region; ----------------------- -- Immediate_Visible -- ----------------------- function Immediate_Visible (Self : access constant Context; Region : Item_Offset; Symbol : Program.Visibility.Symbol) return View_Array is Result : View_Array (1 .. 10); Last : Natural := 0; Value : Item renames Self.Data (Region); begin if Value.Kind in Has_Region_Kind then for Index of Value.Region loop declare Value : constant Item := Self.Data (Index); begin if Value.Symbol = Symbol then Last := Last + 1; Result (Last) := (Value.Kind, Self, Index); end if; end; end loop; end if; return Result (1 .. Last); end Immediate_Visible; ----------------------- -- Immediate_Visible -- ----------------------- function Immediate_Visible (Self : View; Symbol : Program.Visibility.Symbol) return View_Array is begin return Immediate_Visible (Self.Env, Self.Index, Symbol); end Immediate_Visible; ----------------------- -- Immediate_Visible -- ----------------------- not overriding function Immediate_Visible (Self : aliased Context; Symbol : Program.Visibility.Symbol) return View_Array is procedure Append (List : View_Array); Result : View_Array (1 .. 10); Last : Natural := 0; procedure Append (List : View_Array) is begin Result (Last + 1 .. Last + List'Length) := List; Last := Last + List'Length; end Append; begin for J of reverse Self.Stack loop Append (Immediate_Visible (Self'Access, J.Enclosing_Item, Symbol)); end loop; if Symbol = Standard and then not Self.Stack.Is_Empty then declare Top : constant View := (Package_View, Self'Access, Self.Stack.First_Element.Enclosing_Item); begin Append ((1 => Top)); end; end if; return Result (1 .. Last); end Immediate_Visible; ------------- -- Indexes -- ------------- function Indexes (Self : View) return View_Array is Type_Item : Item renames Self.Env.Data (Self.Index); Last : Positive := 1; begin return Result : View_Array (1 .. Type_Item.Indexes.Last_Index) do for J of Type_Item.Indexes loop Result (Last) := Self.Env.Get_View (J); Last := Last + 1; end loop; end return; end Indexes; ----------------------- -- Is_Character_Type -- ----------------------- function Is_Character_Type (Self : View) return Boolean is Type_Item : Item renames Self.Env.Data (Self.Index); begin return Type_Item.Is_Character_Type; end Is_Character_Type; ----------------- -- Latest_View -- ----------------- not overriding function Latest_View (Self : aliased Context) return View is begin return (Self.Data.Last_Element.Kind, Self'Access, Self.Data.Last_Index); end Latest_View; ------------------------------ -- Leave_Declarative_Region -- ------------------------------ not overriding procedure Leave_Declarative_Region (Self : in out Context) is begin Self.Stack.Delete_Last; end Leave_Declarative_Region; ---------- -- Name -- ---------- function Name (Self : View) return Defining_Name is begin return Self.Env.Data (Self.Index).Name; end Name; ---------------------- -- Restore_Snapshot -- ---------------------- not overriding procedure Restore_Snapshot (Self : in out Context; Snapshot : not null Snapshot_Access) is begin Self.Stack := Snapshot.Stack; Self.Data := Snapshot.Data; end Restore_Snapshot; ------------------ -- Subtype_Mark -- ------------------ function Subtype_Mark (Self : View) return View is Subtype_Item : Item renames Self.Env.Data (Self.Index); begin return Self.Env.Get_View (Subtype_Item.Subtype_Mark); end Subtype_Mark; --------------- -- To_Vector -- --------------- function To_Vector (List : View_Array) return Item_Offset_Vectors.Vector is begin return Result : Item_Offset_Vectors.Vector do Result.Reserve_Capacity (List'Length); for View of List loop Result.Append (View.Index); end loop; end return; end To_Vector; end Program.Visibility;
----------------------------------------------------------------------- -- css-comments -- CSS comments recording -- Copyright (C) 2017 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. ----------------------------------------------------------------------- private with Ada.Finalization; -- == CSS Comments == -- The CSS comments can be recorded during the parsing of CSS content. -- When a comment is recorded, a comment reference represented by the -- <tt>Comment_Type</tt> type is returned. The CSS comment can be a multi-line -- comment and the package provides several operations to either retrieve -- the full comment or a specific line. package CSS.Comments is type Comment_Type is private; NULL_COMMENT : constant Comment_Type; -- Get the line number where the comment was written. function Get_Line_Number (Comment : in Comment_Type) return Natural; -- Get the number of lines that the comment span. function Get_Line_Count (Comment : in Comment_Type) return Natural; -- Get the full or stripped comment text. function Get_Text (Comment : in Comment_Type; Strip : in Boolean := False) return String; -- Get the given line of the comment text. function Get_Text (Comment : in Comment_Type; Line : in Positive; Strip : in Boolean := False) return String; -- Definition of the list of comments found in the CSS document. type CSSComment_List is tagged limited private; -- Insert in the comment list the comment described by <tt>Text</tt> -- and associated with source line number <tt>Line</tt>. After insertion -- the comment reference is returned to identify the new comment. procedure Insert (List : in out CSSComment_List; Text : in String; Line : in Natural; Index : out Comment_Type); private type Comment; type Const_Comment_Access is access constant Comment; type Comment_Access is access all Comment; type Line_Info is record Start : Natural := 0; Finish : Natural := 0; end record; type Line_Info_Array is array (Natural range <>) of Line_Info; type Comment (Len : Natural; Line_Count : Natural) is limited record Next : Comment_Access; Line : Natural := 0; Text : String (1 .. Len); Lines : Line_Info_Array (1 .. Line_Count); end record; type CSSComment_List is limited new Ada.Finalization.Limited_Controlled with record Chain : Comment_Access; end record; -- Release the memory used by the comment list. overriding procedure Finalize (List : in out CSSComment_List); EMPTY_COMMENT : aliased constant Comment := Comment '(Len => 0, Line_Count => 0, Next => null, Text => "", Line => 0, others => <>); type Comment_Type is record Object : Const_Comment_Access := EMPTY_COMMENT'Access; end record; NULL_COMMENT : constant Comment_Type := Comment_Type '(Object => EMPTY_COMMENT'Access); end CSS.Comments;
with Ada.Text_IO; with Interfaces.C; with Asis_Adapter.Tool; with a_nodes_h.Support; package body adapter_wrapper_h is package anhS renames a_nodes_h.Support; ------------ -- EXPORTED: ------------ function adapter_wrapper (target_file_in : in Interfaces.C.Strings.chars_ptr; gnat_home : in Interfaces.C.Strings.chars_ptr; AsisArgs : in Interfaces.C.Strings.chars_ptr; output_dir : in Interfaces.C.Strings.chars_ptr ) return a_nodes_h.Nodes_Struct is package ICE renames Interfaces.C.Extensions; begin return adapter_wrapper_with_flags (target_file_in => target_file_in, gnat_home => gnat_home, AsisArgs => AsisArgs, output_dir => output_dir, process_predefined_units => ICE.bool(False), process_implementation_units => ICE.bool(False), debug => ICE.bool(False)); end adapter_wrapper; ------------ -- EXPORTED: ------------ function adapter_wrapper_with_flags (target_file_in : in Interfaces.C.Strings.chars_ptr; gnat_home : in Interfaces.C.Strings.chars_ptr; AsisArgs : in Interfaces.C.Strings.chars_ptr; output_dir : in Interfaces.C.Strings.chars_ptr; process_predefined_units : in Interfaces.C.Extensions.bool; process_implementation_units : in Interfaces.C.Extensions.bool; debug : in Interfaces.C.Extensions.bool ) return a_nodes_h.Nodes_Struct is Parent_Name : constant String := Module_Name; Module_Name : constant String := Parent_Name & ".adapter_wrapper_with_flags"; procedure Log (Message : in String) is begin if Boolean (debug) then Ada.Text_Io.Put_Line (Module_Name & ": " & Message); end if; end; Target_File_In_String_Access : access String := new String'(Interfaces.C.To_Ada (Interfaces.C.Strings.Value (target_file_in))); GNAT_Home_String_Access : access String := new String'(Interfaces.C.To_Ada (Interfaces.C.Strings.Value (gnat_home))); ASIS_Args_String_Access : access String := new String'(Interfaces.C.To_Ada (Interfaces.C.Strings.Value (AsisArgs))); Output_Dir_String_Access : access String := new String'(Interfaces.C.To_Ada (Interfaces.C.Strings.Value (output_dir))); Compile_Succeeded : Boolean := False; Tool : Asis_Adapter.Tool.Class; -- Initialized Result : a_nodes_h.Nodes_Struct := anhs.Default_Nodes_Struct; begin Log ("BEGIN"); Tool.Process (File_Name => Target_File_In_String_Access.all, GNAT_Home => GNAT_Home_String_Access.all, AsisArgs => ASIS_Args_String_Access.all, Output_Dir => Output_Dir_String_Access.all, Process_Predefined_Units => Boolean (process_predefined_units), Process_Implementation_Units => Boolean (process_implementation_units), Debug => Boolean (debug)); Result := Tool.Get_Nodes; -- Can't take 'Image of an expression, so " + 1" below: Log ("Returning " & Result.Units.Next_Count'Image & " + 1 Units."); Log ("Returning " & Result.Elements.Next_Count'Image & " + 1 Elements."); Log ("END"); return Result; end adapter_wrapper_with_flags; end adapter_wrapper_h;
package afrl.impact.ImpactPointSearchTask.SPARK_Boundary with SPARK_Mode is pragma Annotate (GNATprove, Terminating, SPARK_Boundary); -- This wrapper is only introduced for termination function Get_SearchLocationID (X : ImpactPointSearchTask) return Int64; end afrl.impact.ImpactPointSearchTask.SPARK_Boundary;
-- Generated at 2017-04-01 17:51:32 +0000 by Natools.Static_Hash_Maps -- from src/natools-web-fallback_render-maps.sx function Natools.Static_Maps.Web.Fallback_Render.T return Boolean; pragma Pure (Natools.Static_Maps.Web.Fallback_Render.T);
-- network.ada -- -- Title: Network -- Created: Tue Apr 13 00:56:28 1993 -- Author: Eric Gustafson -- <egustafs@play-doh> -- -- Interface: -- All nodes will be lettered sequentially from 'A' nodes are -- case insensitive. lambda and gama values are integer values -- in the range of 0..max_int. with TEXT_IO; procedure NETWORK is package INT_IO is new TEXT_IO.INTEGER_IO( INTEGER ); use TEXT_IO; use INT_IO; MAX_NUMBER_NODES : constant INTEGER := 26; type NETWORK_MATRIX_TYPE is array(1..MAX_NUMBER_NODES, 1..MAX_NUMBER_NODES) of INTEGER; GAMA_IJ : NETWORK_MATRIX_TYPE; -- End to end trafic GAMA : INTEGER; -- Total end to end trafic LAMBDA_IJ : NETWORK_MATRIX_TYPE; -- Link trafic LAMBDA : INTEGER; -- Total link trafic CAPACITY_I : NETWORK_MATRIX_TYPE; -- Link Capacities C_BAR : INTEGER; -- Average Link Capacity TIME_I : NETWORK_MATRIX_TYPE; -- Link time delayes TIME_BAR : INTEGER; -- Average time delay N_BAR : INTEGER; -- Average number of packets in the net TEMPORARY : INTEGER; -- ===================================================================================== procedure GET_INTEGER( X : out INTEGER ) is VALID_INPUT : BOOLEAN := false; begin -- GET_INTEGER while NOT( VALID_INPUT ) loop begin GET( X ); VALID_INPUT := TRUE; exception when DATA_ERROR => SKIP_LINE; PUT_LINE("Invalid format!"); when others => raise; end; end loop; end GET_INTEGER; -- ===================================================================================== procedure GET_CHARACTER( X : out CHARACTER ) is VALID_INPUT : BOOLEAN := false; CH : CHARACTER; begin -- GET_CHARACTER while NOT( VALID_INPUT ) loop GET( CH ); if ( CH >= 'A' and CH <= 'Z' ) then VALID_INPUT := true; elsif ( CH >= 'a' and CH <= 'z' ) then VALID_INPUT := true; CH := CHARACTER'VAL( CHARACTER'POS(CH) - (CHARACTER'POS('a') - CHARACTER'POS('A'))); end if; if NOT( VALID_INPUT ) then SKIP_LINE; PUT_LINE("Invalid format!"); end if; end loop; X := CH; end GET_CHARACTER; -- ===================================================================================== procedure GET_GAMA( GAMA_IJ : out NETWORK_MATRIX_TYPE ) is CH : CHARACTER; START_NODE : INTEGER; END_NODE : INTEGER; LINK_WEIGHT : INTEGER; begin -- GET_GAMA PUT_LINE("Please enter each gama value in the following form:"); PUT_LINE(" <node><node> <weight>"); NEW_LINE; PUT("1: "); GET_CHARACTER( CH ); START_NODE := CHARACTER'POS( CH ) - CHARACTER'POS('A') + 1; GET_CHARACTER( CH ); END_NODE := CHARACTER'POS( CH ) - CHARACTER'POS('A') + 1; GET_INTEGER( LINK_WEIGHT ); NEW_LINE; PUT("From: "); PUT( START_NODE ); NEW_LINE; PUT("To: "); PUT( END_NODE ); NEW_LINE; PUT("Weight: "); PUT( LINK_WEIGHT ); NEW_LINE; end GET_GAMA; -- ===================================================================================== begin -- NETWORK GET_GAMA( GAMA_IJ ); end NETWORK;
-- -- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr> -- - Ryad Benadjila -- - Arnauld Michelizza -- - Mathieu Renard -- - Philippe Thierry -- - Philippe Trebuchet -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- with system; package soc.usart with spark_mode => off is -------------------------------- -- Status register (USART_SR) -- -------------------------------- type t_USART_SR is record PE : boolean; -- Parity error FE : boolean; -- Framing error NF : boolean; -- Noise detected flag ORE : boolean; -- Overrun error IDLE : boolean; -- IDLE line detected RXNE : boolean; -- Read data register not empty TC : boolean; -- Transmission complete TXE : boolean; -- Transmit data register empty LBD : boolean; -- LIN break detection flag CTS : boolean; -- CTS flag end record with volatile_full_access, size => 32; for t_USART_SR use record PE at 0 range 0 .. 0; FE at 0 range 1 .. 1; NF at 0 range 2 .. 2; ORE at 0 range 3 .. 3; IDLE at 0 range 4 .. 4; RXNE at 0 range 5 .. 5; TC at 0 range 6 .. 6; TXE at 0 range 7 .. 7; LBD at 0 range 8 .. 8; CTS at 0 range 9 .. 9; end record; ------------------------------ -- Data register (USART_DR) -- ------------------------------ type t_USART_DR is new bits_9 with volatile_full_access, size => 32; ------------------------------------ -- Baud rate register (USART_BRR) -- ------------------------------------ type t_USART_BRR is record DIV_FRACTION : bits_4; DIV_MANTISSA : bits_12; end record with volatile_full_access, size => 32; for t_USART_BRR use record DIV_FRACTION at 0 range 0 .. 3; DIV_MANTISSA at 0 range 4 .. 15; end record; ------------------------------------ -- Control register 1 (USART_CR1) -- ------------------------------------ type t_parity is (PARITY_EVEN, PARITY_ODD) with size => 1; for t_parity use (PARITY_EVEN => 0, PARITY_ODD => 1); type t_data_len is (DATA_8BITS, DATA_9BITS) with size => 1; for t_data_len use (DATA_8BITS => 0, DATA_9BITS => 1); type t_USART_CR1 is record SBK : boolean; -- Send break RWU : boolean; -- Receiver wakeup RE : boolean; -- Receiver enable TE : boolean; -- Transmitter enable IDLEIE : boolean; -- IDLE interrupt enable RXNEIE : boolean; -- RXNE interrupt enable TCIE : boolean; -- Transmission complete interrupt enable TXEIE : boolean; -- TXE interrupt enable PEIE : boolean; -- PE interrupt enable PS : t_parity; -- Parity selection PCE : boolean; -- Parity control enable WAKE : boolean; -- Wakeup method M : t_data_len; -- Word length UE : boolean; -- USART enable reserved_14_14 : bit; OVER8 : boolean; -- Oversampling mode end record with volatile_full_access, size => 32; for t_USART_CR1 use record SBK at 0 range 0 .. 0; RWU at 0 range 1 .. 1; RE at 0 range 2 .. 2; TE at 0 range 3 .. 3; IDLEIE at 0 range 4 .. 4; RXNEIE at 0 range 5 .. 5; TCIE at 0 range 6 .. 6; TXEIE at 0 range 7 .. 7; PEIE at 0 range 8 .. 8; PS at 0 range 9 .. 9; PCE at 0 range 10 .. 10; WAKE at 0 range 11 .. 11; M at 0 range 12 .. 12; UE at 0 range 13 .. 13; Reserved_14_14 at 0 range 14 .. 14; OVER8 at 0 range 15 .. 15; end record; ------------------------------------ -- Control register 2 (USART_CR2) -- ------------------------------------ type t_stop_bits is (STOP_1, STOP_0_dot_5, STOP_2, STOP_1_dot_5) with size => 2; for t_stop_bits use (STOP_1 => 2#00#, STOP_0_dot_5 => 2#01#, STOP_2 => 2#10#, STOP_1_dot_5 => 2#11#); type t_USART_CR2 is record ADD : bits_4; -- Address of the USART node reserved_4_4 : bit; LBDL : boolean; -- lin break detection length LBDIE : boolean; -- LIN break detection interrupt enable reserved_7_7 : bit; LBCL : boolean; -- Last bit clock pulse CPHA : boolean; -- Clock phase CPOL : boolean; -- Clock polarity CLKEN : boolean; -- Clock enable STOP : t_stop_bits; -- STOP bits LINEN : boolean; -- LIN mode enable end record with volatile_full_access, size => 32; for t_USART_CR2 use record ADD at 0 range 0 .. 3; reserved_4_4 at 0 range 4 .. 4; LBDL at 0 range 5 .. 5; LBDIE at 0 range 6 .. 6; reserved_7_7 at 0 range 7 .. 7; LBCL at 0 range 8 .. 8; CPHA at 0 range 9 .. 9; CPOL at 0 range 10 .. 10; CLKEN at 0 range 11 .. 11; STOP at 0 range 12 .. 13; LINEN at 0 range 14 .. 14; end record; ------------------------------------ -- Control register 3 (USART_CR3) -- ------------------------------------ type t_USART_CR3 is record EIE : boolean; -- Error interrupt enable IREN : boolean; -- IrDA mode enable IRLP : boolean; -- IrDA low-power HDSEL : boolean; -- Half-duplex selection NACK : boolean; -- Smartcard NACK enable SCEN : boolean; -- Smartcard mode enable DMAR : boolean; -- DMA enable receiver DMAT : boolean; -- DMA enable transmitter RTSE : boolean; -- RTS enable CTSE : boolean; -- CTS enable CTSIE : boolean; -- CTS interrupt enable ONEBIT : boolean; -- One sample bit method enable end record with volatile_full_access, size => 32; for t_USART_CR3 use record EIE at 0 range 0 .. 0; IREN at 0 range 1 .. 1; IRLP at 0 range 2 .. 2; HDSEL at 0 range 3 .. 3; NACK at 0 range 4 .. 4; SCEN at 0 range 5 .. 5; DMAR at 0 range 6 .. 6; DMAT at 0 range 7 .. 7; RTSE at 0 range 8 .. 8; CTSE at 0 range 9 .. 9; CTSIE at 0 range 10 .. 10; ONEBIT at 0 range 11 .. 11; end record; ---------------------------------------------------- -- Guard time and prescaler register (USART_GTPR) -- ---------------------------------------------------- type t_USART_GTPR is record PSC : unsigned_8; -- Prescaler value GT : unsigned_8; -- Guard time value end record with volatile_full_access, size => 32; for t_USART_GTPR use record PSC at 0 range 0 .. 7; GT at 0 range 8 .. 15; end record; ---------------------- -- USART peripheral -- ---------------------- type t_USART_peripheral is record SR : t_USART_SR; DR : t_USART_DR; BRR : t_USART_BRR; CR1 : t_USART_CR1; CR2 : t_USART_CR2; CR3 : t_USART_CR3; GTPR : t_USART_GTPR; end record with volatile; for t_USART_peripheral use record SR at 16#00# range 0 .. 31; DR at 16#04# range 0 .. 31; BRR at 16#08# range 0 .. 31; CR1 at 16#0C# range 0 .. 31; CR2 at 16#10# range 0 .. 31; CR3 at 16#14# range 0 .. 31; GTPR at 16#18# range 0 .. 31; end record; type t_USART_peripheral_access is access all t_USART_peripheral; USART1 : aliased t_USART_peripheral with import, volatile, address => system'to_address(16#4001_1000#); USART6 : aliased t_USART_peripheral with import, volatile, address => system'to_address(16#4001_1400#); UART4 : aliased t_USART_peripheral with import, volatile, address => system'to_address(16#4000_4C00#); procedure set_baudrate (usart : in t_USART_peripheral_access; baudrate : in unsigned_32); procedure transmit (usart : in t_USART_peripheral_access; data : in t_USART_DR); procedure receive (usart : in t_USART_peripheral_access; data : out t_USART_DR); end soc.usart;
package Fat_Fields is pragma Elaborate_Body; type A is array (Positive range <>) of Boolean; type A_Ptr is access A; P : A_Ptr := null; end;
package input_2 is type Generator is null record; generic type Unsigned is mod <>; type Real is digits <>; with function Random (G: Generator) return Unsigned is <>; function Random (G: Generator) return Real; end input_2;
with STM32.Device; package body STM32.LPTimers is ------------ -- Enable -- ------------ procedure Enable (This : in out LPTimer) is begin This.CR.ENABLE := True; end Enable; ------------- -- Disable -- ------------- procedure Disable (This : in out LPTimer) is begin This.CR.ENABLE := False; end Disable; ------------- -- Enabled -- ------------- function Enabled (This : LPTimer) return Boolean is begin return This.CR.ENABLE; end Enabled; ------------------------- -- Configure_Prescaler -- ------------------------- procedure Configure_Prescaler (This : in out LPTimer; Prescaler : LPTimer_Prescaler) is begin This.CFGR.PRESC := Prescaler'Enum_Rep; end Configure_Prescaler; ----------------------- -- Current_Prescaler -- ----------------------- function Current_Prescaler (This : LPTimer) return LPTimer_Prescaler is begin return LPTimer_Prescaler'Val (This.CFGR.PRESC); end Current_Prescaler; ----------------------- -- Set_Compare_Value -- ----------------------- procedure Set_Compare_Value (This : in out LPTimer; Value : UInt16) is begin This.CMP.CMP := Value; end Set_Compare_Value; --------------------------- -- Current_Compare_Value -- --------------------------- function Current_Compare_Value (This : LPTimer) return UInt16 is begin return This.CMP.CMP; end Current_Compare_Value; -------------------------- -- Set_Autoreload_Value -- -------------------------- procedure Set_Autoreload_Value (This : in out LPTimer; Value : UInt16) is begin This.ARR.ARR := Value; end Set_Autoreload_Value; ------------------------ -- Current_Autoreload -- ------------------------ function Current_Autoreload (This : LPTimer) return UInt16 is begin return This.ARR.ARR; end Current_Autoreload; --------------- -- Configure -- --------------- procedure Configure (This : in out LPTimer; Prescaler : LPTimer_Prescaler; Period : UInt16) is begin This.CFGR.PRESC := Prescaler'Enum_Rep; This.ARR.ARR := Period; end Configure; ---------------------------------- -- Compute_Prescaler_and_Period -- ---------------------------------- procedure Compute_Prescaler_And_Period (This : LPTimer; Requested_Frequency : UInt32; Prescaler : out LPTimer_Prescaler; Period : out UInt32) is Max_Prescaler : constant LPTimer_Prescaler := LPTimer_Prescaler'Last; Max_Period : constant := 16#FFFF#; -- UInt16'Last Prescaler_Enum : UInt8; -- Counter for LPTimer_Prescaler'Enum_Rep Hardware_Frequency : UInt32; CK_CNT : UInt32; begin Hardware_Frequency := STM32.Device.Get_Clock_Frequency (This); if Requested_Frequency > Hardware_Frequency then raise Invalid_Request with "Frequency too high"; end if; -- We use a numeric prescaler value to calculate the Hardware_Frequency -- division considering that the clock prescaler is a power of 2 of this -- value, as are the LPTimer_Prescaler discrete values. Prescaler_Enum := 0; loop -- Compute the Counter's clock CK_CNT := Hardware_Frequency / UInt32 (2**Integer (Prescaler_Enum)); -- Determine the CK_CNT periods to achieve the requested frequency Period := CK_CNT / Requested_Frequency; exit when ((Period <= Max_Period) or (Prescaler_Enum > Max_Prescaler'Enum_Rep)); Prescaler_Enum := Prescaler_Enum + 1; end loop; if Prescaler_Enum > Max_Prescaler'Enum_Rep then raise Invalid_Request with "Frequency too low"; end if; Prescaler := LPTimer_Prescaler'Val (Prescaler_Enum); end Compute_Prescaler_And_Period; ------------------------------ -- Set_Counter_Clock_Source -- ------------------------------ procedure Set_Counter_Clock_Source (This : in out LPTimer; Mode : LPTimer_Clock_Source) is begin This.CFGR.COUNTMODE := Mode = External; end Set_Counter_Clock_Source; ----------------------- -- Set_Counter_Value -- ----------------------- procedure Set_Counter_Value (This : in out LPTimer; Value : UInt16) is begin This.CNT.CNT := Value; end Set_Counter_Value; --------------------- -- Current_Counter -- --------------------- function Current_Counter (This : LPTimer) return UInt16 is begin return This.CNT.CNT; end Current_Counter; ---------------------------- -- Set_Counter_Reset_Mode -- ---------------------------- procedure Set_Counter_Reset_Mode (This : in out LPTimer; Mode : LPTimer_Counter_Reset_Mode; Enable : Boolean := True) is begin case Mode is when After_Read_Counter => This.CR.RSTARE := Enable; when Now => if Enable then while This.CR.COUNTRST loop null; end loop; This.CR.COUNTRST := True; end if; end case; end Set_Counter_Reset_Mode; ---------------------- -- Set_Preload_Mode -- ---------------------- procedure Set_Preload_Mode (This : in out LPTimer; Mode : LPTimer_Preload_Mode) is begin This.CFGR.PRELOAD := Mode = End_Current_Period; end Set_Preload_Mode; ---------------------- -- Enable_Interrupt -- ---------------------- procedure Enable_Interrupt (This : in out LPTimer; Source : LPTimer_Interrupt) is begin case Source is when Compare_Match => This.IER.CMPMIE := True; when Autorreload_Match => This.IER.ARRMIE := True; when External_Trigger_Valid_Edge => This.IER.EXTTRIGIE := True; when Compare_Register_Update_Ok => This.IER.CMPOKIE := True; when Autorreload_Register_Update_Ok => This.IER.ARROKIE := True; when Direction_Change_To_Up => This.IER.UPIE := True; when Direction_Change_To_Down => This.IER.DOWNIE := True; end case; end Enable_Interrupt; ----------------------- -- Disable_Interrupt -- ----------------------- procedure Disable_Interrupt (This : in out LPTimer; Source : LPTimer_Interrupt) is begin case Source is when Compare_Match => This.IER.CMPMIE := False; when Autorreload_Match => This.IER.ARRMIE := False; when External_Trigger_Valid_Edge => This.IER.EXTTRIGIE := False; when Compare_Register_Update_Ok => This.IER.CMPOKIE := False; when Autorreload_Register_Update_Ok => This.IER.ARROKIE := False; when Direction_Change_To_Up => This.IER.UPIE := False; when Direction_Change_To_Down => This.IER.DOWNIE := False; end case; end Disable_Interrupt; ---------------------- -- Enable_Interrupt -- ---------------------- procedure Enable_Interrupt (This : in out LPTimer; Sources : LPTimer_Interrupt_List) is begin for Source of Sources loop case Source is when Compare_Match => This.IER.CMPMIE := True; when Autorreload_Match => This.IER.ARRMIE := True; when External_Trigger_Valid_Edge => This.IER.EXTTRIGIE := True; when Compare_Register_Update_Ok => This.IER.CMPOKIE := True; when Autorreload_Register_Update_Ok => This.IER.ARROKIE := True; when Direction_Change_To_Up => This.IER.UPIE := True; when Direction_Change_To_Down => This.IER.DOWNIE := True; end case; end loop; end Enable_Interrupt; ----------------------------- -- Clear_Pending_Interrupt -- ----------------------------- procedure Clear_Pending_Interrupt (This : in out LPTimer; Source : LPTimer_Interrupt) is begin case Source is when Compare_Match => This.ICR.CMPMCF := True; when Autorreload_Match => This.ICR.ARRMCF := True; when External_Trigger_Valid_Edge => This.ICR.EXTTRIGCF := True; when Compare_Register_Update_Ok => This.ICR.CMPOKCF := True; when Autorreload_Register_Update_Ok => This.ICR.ARROKCF := True; when Direction_Change_To_Up => This.ICR.UPCF := True; when Direction_Change_To_Down => This.ICR.DOWNCF := True; end case; end Clear_Pending_Interrupt; ----------------------- -- Interrupt_Enabled -- ----------------------- function Interrupt_Enabled (This : LPTimer; Source : LPTimer_Interrupt) return Boolean is begin case Source is when Compare_Match => return This.IER.CMPMIE; when Autorreload_Match => return This.IER.ARRMIE; when External_Trigger_Valid_Edge => return This.IER.EXTTRIGIE; when Compare_Register_Update_Ok => return This.IER.CMPOKIE; when Autorreload_Register_Update_Ok => return This.IER.ARROKIE; when Direction_Change_To_Up => return This.IER.UPIE; when Direction_Change_To_Down => return This.IER.DOWNIE; end case; end Interrupt_Enabled; ------------ -- Status -- ------------ function Status (This : LPTimer; Flag : LPTimer_Status_Flag) return Boolean is begin case Flag is when Compare_Match => return This.IER.CMPMIE; when Autorreload_Match => return This.IER.ARRMIE; when External_Trigger_Valid_Edge => return This.IER.EXTTRIGIE; when Compare_Register_Update_Ok => return This.IER.CMPOKIE; when Autorreload_Register_Update_Ok => return This.IER.ARROKIE; when Direction_Change_To_Up => return This.IER.UPIE; when Direction_Change_To_Down => return This.IER.DOWNIE; end case; end Status; ------------------ -- Clear_Status -- ------------------ procedure Clear_Status (This : in out LPTimer; Flag : LPTimer_Status_Flag) is begin case Flag is when Compare_Match => This.ICR.CMPMCF := True; when Autorreload_Match => This.ICR.ARRMCF := True; when External_Trigger_Valid_Edge => This.ICR.EXTTRIGCF := True; when Compare_Register_Update_Ok => This.ICR.CMPOKCF := True; when Autorreload_Register_Update_Ok => This.ICR.ARROKCF := True; when Direction_Change_To_Up => This.ICR.UPCF := True; when Direction_Change_To_Down => This.ICR.DOWNCF := True; end case; end Clear_Status; ------------------------- -- Select_Clock_Source -- ------------------------- procedure Select_Clock_Source (This : in out LPTimer; Source : LPTimer_Clock_Source) is begin This.CFGR.CKSEL := Source = External; end Select_Clock_Source; ---------------------- -- Get_Clock_Source -- ---------------------- function Get_Clock_Source (This : LPTimer) return LPTimer_Clock_Source is begin if This.CFGR.CKSEL then return External; else return Internal; end if; end Get_Clock_Source; ------------------------------ -- Configure_External_Clock -- ------------------------------ procedure Configure_External_Clock (This : in out LPTimer; Polarity : LPTimer_External_Clock_Polarity; Filter : LPTimer_Digital_Filter) is begin This.CFGR.CKPOL := Polarity'Enum_Rep; This.CFGR.CKFLT := Filter'Enum_Rep; end Configure_External_Clock; --------------------------- -- Configure_Input_Clock -- --------------------------- procedure Configure_Input_Clock (This : in out LPTimer; Input : LPTimer_Input; Clock : LPTimer_Input_Clock) is begin case Input is when Input_1 => This.OR_k.IN1_0 := Clock.Internal; This.OR_k.IN1_1 := Clock.Value'Enum_Rep; when Input_2 => This.OR_k.IN2_0 := Clock.Internal; This.OR_k.IN2_1 := Clock.Value'Enum_Rep; end case; end Configure_Input_Clock; --------------------------- -- Select_Trigger_Source -- --------------------------- procedure Select_Trigger_Source (This : in out LPTimer; Source : LPTimer_Trigger_Source) is begin if Source'Enum_Rep > 7 then This.CFGR.TRIGSEL_1 := True; else This.CFGR.TRIGSEL_1 := False; end if; This.CFGR.TRIGSEL_0 := UInt3 (Source'Enum_Rep); end Select_Trigger_Source; --------------------------- -- Select_Trigger_Filter -- --------------------------- procedure Select_Trigger_Filter (This : in out LPTimer; Filter : LPTimer_Digital_Filter) is begin This.CFGR.TRGFLT := Filter'Enum_Rep; end Select_Trigger_Filter; ---------------------- -- Set_Trigger_Timeout -- ---------------------- procedure Set_Trigger_Timeout (This : in out LPTimer; Enable : Boolean) is begin This.CFGR.TIMOUT := not Enable; end Set_Trigger_Timeout; ----------------------- -- Configure_Trigger -- ----------------------- procedure Configure_Trigger (This : in out LPTimer; Source : LPTimer_Trigger_Source; Filter : LPTimer_Digital_Filter; Timeout : Boolean) is begin if Source'Enum_Rep > 7 then This.CFGR.TRIGSEL_1 := True; else This.CFGR.TRIGSEL_1 := False; end if; This.CFGR.TRIGSEL_0 := UInt3 (Source'Enum_Rep); This.CFGR.TRGFLT := Filter'Enum_Rep; This.CFGR.TIMOUT := not Timeout; end Configure_Trigger; ----------------------- -- Select_Pulse_Mode -- ----------------------- procedure Select_Pulse_Mode (This : in out LPTimer; Mode : LPTimer_Pulse_Mode) is begin case Mode is when Repetitive => This.CR.CNTSTRT := True; This.CR.SNGSTRT := False; when Single => This.CR.CNTSTRT := False; This.CR.SNGSTRT := True; end case; end Select_Pulse_Mode; ------------------------ -- Set_Waveform_Shape -- ------------------------ procedure Set_Waveform_Shape (This : in out LPTimer; Shape : LPTimer_Waveform_Shape) is begin This.CFGR.WAVE := Shape = Set_Once; end Set_Waveform_Shape; --------------------------- -- Set_Waveform_Polarity -- --------------------------- procedure Set_Waveform_Polarity (This : in out LPTimer; Polarity : LPTimer_Waveform_Polarity) is begin This.CFGR.WAVPOL := Polarity = Inverse; end Set_Waveform_Polarity; ------------------------------ -- Configure_Waveform_Shape -- ------------------------------ procedure Configure_Waveform_Shape (This : in out LPTimer; Shape : LPTimer_Waveform_Shape; Polarity : LPTimer_Waveform_Polarity) is begin This.CFGR.WAVE := Shape = Set_Once; This.CFGR.WAVPOL := Polarity = Inverse; end Configure_Waveform_Shape; ---------------------- -- Set_Encoder_Mode -- ---------------------- procedure Set_Encoder_Mode (This : in out LPTimer; Enable : Boolean) is begin This.CFGR.ENC := Enable; end Set_Encoder_Mode; end STM32.LPTimers;
-- -- 6.1 Subprogram Declarations -- -- NOTE: This module is not compilation is used only for testing purposes -- package Subprogram_Declarations is -- Examples of subprogram declarations: procedure Traverse_Tree; procedure Increment(X : in out Integer); procedure Right_Indent(Margin : out Line_Size); -- see 3.5.4 procedure Switch(From, To : in out Link); -- see 3.10.1 function Random return Probability; -- see 3.5.7 function Min_Cell(X : Link) return Cell; -- see 3.10.1 function Next_Frame(K : Positive) return Frame; -- see 3.10 function Dot_Product(Left, Right : Vector) return Real; -- see 3.6 function "*"(Left, Right : Matrix) return Matrix; -- see 3.6 -- Examples of in parameters with default expressions: procedure Print_Header (Pages : in Natural; Center : in Boolean := True); end Subprogram_Declarations;
with physics.Shape, box2d_c.Pointers, physics.Space; package box2d_Physics.Shape -- -- Provides glue between a physics shape and a Box2D shape. -- is type Item is abstract new physics.Shape.item with -- TODO: Make private. record C : box2d_c.Pointers.Shape_pointer; end record; type View is access all Item'Class; use Math; overriding procedure define (Self : in out Item); overriding procedure destruct (Self : in out Item); overriding procedure Scale_is (Self : in out Item; Now : Vector_3); --------- -- Forge -- -- Shapes procedure free (the_Shape : in out physics.Shape.view); -- 3D function new_box_Shape (half_Extents : in Vector_3) return physics.Shape.view; function new_capsule_Shape (Radii : in Vector_2; Height : in Real) return physics.Shape.view; function new_cone_Shape (Radius, Height : in Real) return physics.Shape.view; function new_convex_hull_Shape (Points : in physics.Vector_3_array) return physics.Shape.view; function new_cylinder_Shape (half_Extents : in Vector_3) return physics.Shape.view; function new_heightfield_Shape (Width, Depth : in Positive; Heights : access constant Real; min_Height, max_Height : in Real; Scale : in Vector_3) return physics.Shape.view; function new_multiSphere_Shape (Positions : in physics.Vector_3_array; Radii : in Vector) return physics.Shape.view; function new_plane_Shape (Normal : in Vector_3; Offset : in Real) return physics.Shape.view; function new_sphere_Shape (Radius : in Real) return physics.Shape.view; -- 2D function new_circle_Shape (Radius : in Real) return physics.Shape.view; function new_polygon_Shape (Vertices : in physics.Space.polygon_Vertices) return physics.Shape.view; private type Circle is new Item with record Radius : Real; end record; overriding procedure define (Self : in out Circle); type Polygon (vertex_Count : Positive) is new Item with record Vertices : physics.Space.polygon_Vertices (1 .. vertex_Count); end record; overriding procedure define (Self : in out Polygon); type Box is new Item with null record; type Capsule is new Item with null record; type Cone is new Item with null record; type Cylinder is new Item with null record; type Heightfield is new Item with null record; type multiSphere is new Item with null record; type Plane is new Item with null record; type Sphere is new Item with null record; type convex_Hull is new Item with null record; end box2d_Physics.Shape;
with AUnit.Assertions; use AUnit.Assertions; with PixelArray; use PixelArray; with ImageThresholds; with ImageIO; package body ImageTests is procedure Register_Tests (T: in out ImageTest) is use AUnit.Test_Cases.Registration; begin Register_Routine(T, testPixelArray'Access, "pixel array"); Register_Routine(T, testImageThresholding'Access, "image thresholds"); Register_Routine(T, testImageIO'Access, "image IO"); end Register_Tests; function Name(T: ImageTest) return Test_String is begin return Format("Image tests"); end Name; procedure testPixelArray(T : in out Test_Cases.Test_Case'Class) is testImage: PixelArray.ImagePlane := PixelArray.allocate(120, 120); begin Assert(testImage.isInside(0, 0), ""); Assert(not testImage.isInside(120, 120), ""); Assert(not testImage.isInside(-1, -2), ""); testImage.set(10, 10, Pixel(99)); Assert(testImage.get(10, 10) = Pixel(99), ""); end testPixelArray; procedure testImageThresholding(T: in out Test_Cases.Test_Case'Class) is testImage: PixelArray.ImagePlane := PixelArray.allocate(20, 20); begin testImage.set(Pixel(0)); testImage.set(10, 10, Pixel(45)); testImage.set(11, 11, Pixel(46)); testImage.set(12, 16, Pixel(99)); ImageThresholds.simple(testImage, threshold => Pixel(45)); Assert(ImageThresholds.isBinary(testImage), "binary output"); Assert(testImage.get(10, 10) = Pixel(0), ""); Assert(testImage.get(11, 11) = Pixel(255), ""); Assert(testImage.get(12, 16) = Pixel(255), ""); Assert(testImage.get(15, 15) = Pixel(0), ""); end testImageThresholding; procedure testImageIO(T: in out Test_Cases.Test_Case'Class) is testImage: PixelArray.ImagePlane := PixelArray.allocate(width => 128, height => 128); saveResult: Boolean; begin testImage.set(Pixel(56)); for i in 0 .. testImage.width - 1 loop testImage.set(i, i, Pixel(i)); end loop; saveResult := ImageIO.save(filename => "test_image_IO.png", image => testImage); testImage.set(Pixel(0)); declare loadedImage: constant PixelArray.ImagePlane := ImageIO.load("test_image_IO.png"); begin for i in 0 .. testImage.height - 1 loop for j in 0 .. testImage.width - 1 loop if i = j then Assert(loadedImage.get(j, i) = Pixel(i), "diagonal pixel"); else Assert(loadedImage.get(j, i) = Pixel(56), "background pixel"); end if; end loop; end loop; end; end testImageIO; end ImageTests;
pragma License (Unrestricted); -- implementation unit specialized for Darwin with C.mach.mach_time; with C.stdint; package System.Native_Real_Time is pragma Preelaborate; subtype Native_Time is C.stdint.uint64_t; function To_Native_Time (T : Duration) return Native_Time; function To_Duration (T : Native_Time) return Duration; pragma Pure_Function (To_Native_Time); pragma Pure_Function (To_Duration); pragma Inline (To_Native_Time); pragma Inline (To_Duration); function Clock return Native_Time renames C.mach.mach_time.mach_absolute_time; -- same as Ada.Real_Time subtype Time is Duration; Tick : constant := 1.0 / 1_000_000_000; -- mach_absolute_time returns nano-seconds. -- for delay until procedure Delay_Until (T : Native_Time); -- no hook for Darwin end System.Native_Real_Time;
-- Copyright 2015,2016,2017 Steven Stewart-Gallus -- -- 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.Real_Time; with Linted.IO_Pool; with Linted.Triggers; package Linted.Timer is subtype Event is Linted.IO_Pool.Remind_Me_Event; subtype Future is Linted.IO_Pool.Remind_Me_Future; function Future_Is_Live (F : Future) return Boolean renames IO_Pool.Remind_Me_Future_Is_Live; procedure Remind_Me (Time : Ada.Real_Time.Time; Signaller : Triggers.Signaller; F : out Future) renames IO_Pool.Remind_Me; procedure Remind_Me_Wait (F : in out Future; E : out Event) renames IO_Pool.Remind_Me_Wait; procedure Remind_Me_Poll (F : in out Future; E : out Event; Init : out Boolean) renames IO_Pool.Remind_Me_Poll; end Linted.Timer;
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2020, 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 RISCV.CSR; use RISCV.CSR; with RISCV.Types; use RISCV.Types; package body FE310.Performance_Monitor is subtype Event_Group is Unsigned_XLEN range 0 .. 2; generic type Events is (<>); type Set_Of_Events is array (Events) of Boolean; Event_Group_Selector : Event_Group; function Compute_Event_Mask (S : in Set_Of_Events) return Unsigned_XLEN; -- Computes and returns the counter event selector value given a set of -- events and the group selector. See the FE310 Manual Section 3.8, -- Table 3. function Compute_Event_Mask (S : in Set_Of_Events) return Unsigned_XLEN is Event_Mask : Unsigned_XLEN := Event_Group_Selector; begin for I in Events loop if S (I) then -- Events'First has position number 0, but is -- enabled by bit 8 of the mask and so on. Event_Mask := Event_Mask or (2 ** (Events'Pos (I) + 8)); end if; end loop; return Event_Mask; end Compute_Event_Mask; ----------------------- -- Set_Commit_Events -- ----------------------- procedure Set_Commit_Events (C : in Counter_Id; S : in Set_Of_Commit_Events) is function F is new Compute_Event_Mask (Commit_Events, Set_Of_Commit_Events, 0); Event_Mask : Unsigned_XLEN; begin Event_Mask := F (S); case C is when 3 => Mhpmevent3.Write (Event_Mask); when 4 => Mhpmevent4.Write (Event_Mask); end case; end Set_Commit_Events; --------------------------- -- Set_Micro_Arch_Events -- --------------------------- procedure Set_Micro_Arch_Events (C : in Counter_Id; S : in Set_Of_Micro_Arch_Events) is function F is new Compute_Event_Mask (Micro_Arch_Events, Set_Of_Micro_Arch_Events, 1); Event_Mask : Unsigned_XLEN; begin Event_Mask := F (S); case C is when 3 => Mhpmevent3.Write (Event_Mask); when 4 => Mhpmevent4.Write (Event_Mask); end case; end Set_Micro_Arch_Events; ------------------------------ -- Set_Memory_System_Events -- ------------------------------ procedure Set_Memory_System_Events (C : in Counter_Id; S : in Set_Of_Memory_System_Events) is function F is new Compute_Event_Mask (Memory_System_Events, Set_Of_Memory_System_Events, 2); Event_Mask : Unsigned_XLEN; begin Event_Mask := F (S); case C is when 3 => Mhpmevent3.Write (Event_Mask); when 4 => Mhpmevent4.Write (Event_Mask); end case; end Set_Memory_System_Events; ------------------ -- Zero_Counter -- ------------------ procedure Zero_Counter (C : in Counter_Id) is begin case C is when 3 => Mhpmcounter3.Write (0); when 4 => Mhpmcounter4.Write (0); end case; end Zero_Counter; ------------------ -- Read_Counter -- ------------------ function Read_Counter (C : in Counter_Id) return UInt64 is begin case C is when 3 => return Mhpmcounter3.Read; when 4 => return Mhpmcounter4.Read; end case; end Read_Counter; end FE310.Performance_Monitor;
Foo : constant := 42; Foo : constant Blahtype := Blahvalue;
with Ada.Wide_Wide_Text_IO; with League.Strings; with League.JSON.Arrays; with League.JSON.Objects; with League.JSON.Values; with WebDriver.Drivers; with WebDriver.Elements; with WebDriver.Remote; with WebDriver.Sessions; procedure Test is function "+" (Text : Wide_Wide_String) return League.Strings.Universal_String renames League.Strings.To_Universal_String; function Headless return League.JSON.Values.JSON_Value; -------------- -- Headless -- -------------- function Headless return League.JSON.Values.JSON_Value is Cap : League.JSON.Objects.JSON_Object; Options : League.JSON.Objects.JSON_Object; Args : League.JSON.Arrays.JSON_Array; begin return Cap.To_JSON_Value; pragma Warnings (Off); Args.Append (League.JSON.Values.To_JSON_Value (+"--headless")); Args.Append (League.JSON.Values.To_JSON_Value (+"--disable-extensions")); Args.Append (League.JSON.Values.To_JSON_Value (+"--no-sandbox")); Options.Insert (+"args", Args.To_JSON_Value); Options.Insert (+"binary", League.JSON.Values.To_JSON_Value (+"/usr/lib64/chromium-browser/headless_shell")); Cap.Insert (+"chromeOptions", Options.To_JSON_Value); return Cap.To_JSON_Value; end Headless; Web_Driver : aliased WebDriver.Drivers.Driver'Class := WebDriver.Remote.Create (+"http://127.0.0.1:9515"); Session : constant WebDriver.Sessions.Session_Access := Web_Driver.New_Session (Headless); begin Session.Go (+"http://www.ada-ru.org/"); Ada.Wide_Wide_Text_IO.Put_Line (Session.Get_Current_URL.To_Wide_Wide_String); declare Body_Element : constant WebDriver.Elements.Element_Access := Session.Find_Element (Strategy => WebDriver.Tag_Name, Selector => +"body"); begin Ada.Wide_Wide_Text_IO.Put_Line ("Selected=" & Boolean'Wide_Wide_Image (Body_Element.Is_Selected)); Ada.Wide_Wide_Text_IO.Put_Line ("itemtype=" & Body_Element.Get_Attribute (+"itemtype").To_Wide_Wide_String); Ada.Wide_Wide_Text_IO.Put_Line ("height=" & Body_Element.Get_CSS_Value (+"height").To_Wide_Wide_String); Ada.Wide_Wide_Text_IO.Put_Line ("tag=" & Body_Element.Get_Tag_Name.To_Wide_Wide_String); end; end Test;
-- This spec has been automatically generated from FE310.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package FE310_SVD.PWM is pragma Preelaborate; --------------- -- Registers -- --------------- subtype CONFIG_SCALE_Field is HAL.UInt4; -- PWM Configuration Register. type CONFIG_Register is record SCALE : CONFIG_SCALE_Field := 16#0#; -- unspecified Reserved_4_7 : HAL.UInt4 := 16#0#; STICKY : Boolean := False; ZEROCMP : Boolean := False; DEGLITCH : Boolean := False; -- unspecified Reserved_11_11 : HAL.Bit := 16#0#; ENALWAYS : Boolean := False; ENONESHOT : Boolean := False; -- unspecified Reserved_14_15 : HAL.UInt2 := 16#0#; CMP_CENTER_0 : Boolean := False; CMP_CENTER_1 : Boolean := False; CMP_CENTER_2 : Boolean := False; CMP_CENTER_3 : Boolean := False; -- unspecified Reserved_20_23 : HAL.UInt4 := 16#0#; CMP_GANG_0 : Boolean := False; CMP_GANG_1 : Boolean := False; CMP_GANG_2 : Boolean := False; CMP_GANG_3 : Boolean := False; CMP_IP_0 : Boolean := False; CMP_IP_1 : Boolean := False; CMP_IP_2 : Boolean := False; CMP_IP_3 : Boolean := False; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CONFIG_Register use record SCALE at 0 range 0 .. 3; Reserved_4_7 at 0 range 4 .. 7; STICKY at 0 range 8 .. 8; ZEROCMP at 0 range 9 .. 9; DEGLITCH at 0 range 10 .. 10; Reserved_11_11 at 0 range 11 .. 11; ENALWAYS at 0 range 12 .. 12; ENONESHOT at 0 range 13 .. 13; Reserved_14_15 at 0 range 14 .. 15; CMP_CENTER_0 at 0 range 16 .. 16; CMP_CENTER_1 at 0 range 17 .. 17; CMP_CENTER_2 at 0 range 18 .. 18; CMP_CENTER_3 at 0 range 19 .. 19; Reserved_20_23 at 0 range 20 .. 23; CMP_GANG_0 at 0 range 24 .. 24; CMP_GANG_1 at 0 range 25 .. 25; CMP_GANG_2 at 0 range 26 .. 26; CMP_GANG_3 at 0 range 27 .. 27; CMP_IP_0 at 0 range 28 .. 28; CMP_IP_1 at 0 range 29 .. 29; CMP_IP_2 at 0 range 30 .. 30; CMP_IP_3 at 0 range 31 .. 31; end record; subtype COUNT_16_CNT_Field is HAL.UInt31; -- PWM Count Register. type COUNT_16_Register is record CNT : COUNT_16_CNT_Field := 16#0#; -- unspecified Reserved_31_31 : HAL.Bit := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COUNT_16_Register use record CNT at 0 range 0 .. 30; Reserved_31_31 at 0 range 31 .. 31; end record; subtype COUNT_8_CNT_Field is HAL.UInt23; -- PWM Count Register. type COUNT_8_Register is record CNT : COUNT_8_CNT_Field := 16#0#; -- unspecified Reserved_23_31 : HAL.UInt9 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COUNT_8_Register use record CNT at 0 range 0 .. 22; Reserved_23_31 at 0 range 23 .. 31; end record; subtype SCALE_COUNT_16_CNT_Field is HAL.UInt16; -- PWM Scaled Conunter Register. type SCALE_COUNT_16_Register is record CNT : SCALE_COUNT_16_CNT_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SCALE_COUNT_16_Register use record CNT at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype SCALE_COUNT_8_CNT_Field is HAL.UInt9; -- PWM Scaled Conunter Register. type SCALE_COUNT_8_Register is record CNT : SCALE_COUNT_8_CNT_Field := 16#0#; -- unspecified Reserved_9_31 : HAL.UInt23 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SCALE_COUNT_8_Register use record CNT at 0 range 0 .. 8; Reserved_9_31 at 0 range 9 .. 31; end record; subtype COMPARE_0_16_COMPARE_Field is HAL.UInt16; -- PWM Compare Register. type COMPARE_0_16_Register is record COMPARE : COMPARE_0_16_COMPARE_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COMPARE_0_16_Register use record COMPARE at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype COMPARE_0_8_COMPARE_Field is HAL.UInt16; -- PWM Compare Register. type COMPARE_0_8_Register is record COMPARE : COMPARE_0_8_COMPARE_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COMPARE_0_8_Register use record COMPARE at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype COMPARE_1_16_COMPARE_Field is HAL.UInt16; -- PWM Compare Register. type COMPARE_1_16_Register is record COMPARE : COMPARE_1_16_COMPARE_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COMPARE_1_16_Register use record COMPARE at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype COMPARE_1_8_COMPARE_Field is HAL.UInt16; -- PWM Compare Register. type COMPARE_1_8_Register is record COMPARE : COMPARE_1_8_COMPARE_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COMPARE_1_8_Register use record COMPARE at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype COMPARE_2_16_COMPARE_Field is HAL.UInt16; -- PWM Compare Register. type COMPARE_2_16_Register is record COMPARE : COMPARE_2_16_COMPARE_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COMPARE_2_16_Register use record COMPARE at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype COMPARE_2_8_COMPARE_Field is HAL.UInt16; -- PWM Compare Register. type COMPARE_2_8_Register is record COMPARE : COMPARE_2_8_COMPARE_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COMPARE_2_8_Register use record COMPARE at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype COMPARE_3_16_COMPARE_Field is HAL.UInt16; -- PWM Compare Register. type COMPARE_3_16_Register is record COMPARE : COMPARE_3_16_COMPARE_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COMPARE_3_16_Register use record COMPARE at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; subtype COMPARE_3_8_COMPARE_Field is HAL.UInt16; -- PWM Compare Register. type COMPARE_3_8_Register is record COMPARE : COMPARE_3_8_COMPARE_Field := 16#0#; -- unspecified Reserved_16_31 : HAL.UInt16 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for COMPARE_3_8_Register use record COMPARE at 0 range 0 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; ----------------- -- Peripherals -- ----------------- type PWM0_Disc is ( PWM0_Disc_16, PWM0_Disc_8); -- Pulse-Width Modulation. type PWM_Peripheral (Discriminent : PWM0_Disc := PWM0_Disc_16) is record -- PWM Configuration Register. CONFIG : aliased CONFIG_Register; case Discriminent is when PWM0_Disc_16 => -- PWM Count Register. COUNT_16 : aliased COUNT_16_Register; -- PWM Scaled Conunter Register. SCALE_COUNT_16 : aliased SCALE_COUNT_16_Register; -- PWM Compare Register. COMPARE_0_16 : aliased COMPARE_0_16_Register; -- PWM Compare Register. COMPARE_1_16 : aliased COMPARE_1_16_Register; -- PWM Compare Register. COMPARE_2_16 : aliased COMPARE_2_16_Register; -- PWM Compare Register. COMPARE_3_16 : aliased COMPARE_3_16_Register; when PWM0_Disc_8 => -- PWM Count Register. COUNT_8 : aliased COUNT_8_Register; -- PWM Scaled Conunter Register. SCALE_COUNT_8 : aliased SCALE_COUNT_8_Register; -- PWM Compare Register. COMPARE_0_8 : aliased COMPARE_0_8_Register; -- PWM Compare Register. COMPARE_1_8 : aliased COMPARE_1_8_Register; -- PWM Compare Register. COMPARE_2_8 : aliased COMPARE_2_8_Register; -- PWM Compare Register. COMPARE_3_8 : aliased COMPARE_3_8_Register; end case; end record with Unchecked_Union, Volatile; for PWM_Peripheral use record CONFIG at 16#0# range 0 .. 31; COUNT_16 at 16#8# range 0 .. 31; SCALE_COUNT_16 at 16#10# range 0 .. 31; COMPARE_0_16 at 16#20# range 0 .. 31; COMPARE_1_16 at 16#24# range 0 .. 31; COMPARE_2_16 at 16#28# range 0 .. 31; COMPARE_3_16 at 16#2C# range 0 .. 31; COUNT_8 at 16#8# range 0 .. 31; SCALE_COUNT_8 at 16#10# range 0 .. 31; COMPARE_0_8 at 16#20# range 0 .. 31; COMPARE_1_8 at 16#24# range 0 .. 31; COMPARE_2_8 at 16#28# range 0 .. 31; COMPARE_3_8 at 16#2C# range 0 .. 31; end record; -- Pulse-Width Modulation. PWM0_Periph : aliased PWM_Peripheral with Import, Address => System'To_Address (16#10015000#); -- Pulse-Width Modulation. PWM1_Periph : aliased PWM_Peripheral with Import, Address => System'To_Address (16#10025000#); -- Pulse-Width Modulation. PWM2_Periph : aliased PWM_Peripheral with Import, Address => System'To_Address (16#10035000#); end FE310_SVD.PWM;
-- 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.Strings.Unbounded; use Ada.Strings.Unbounded; with GNAT.Sockets; with DG_Types; use DG_Types; package Devices.Console is type TTI_T is record One_Char_Buff : Byte_T; end record; protected TTIn is procedure Init; procedure Reset; procedure Insert_Byte (B : in Byte_T); procedure Data_In (ABC : in IO_Reg_T; IO_Flag : in IO_Flag_T; Datum : out Word_T); procedure Data_Out( Datum : in Word_T; ABC : in IO_Reg_T; IO_Flag : in IO_Flag_T); private TTI_Dev : TTI_T; end TTIn; protected TTOut is procedure Init (Sock : in GNAT.Sockets.Socket_Type); procedure Reset; procedure Put_Byte (B : in Byte_T); procedure Put_Char (C : in Character); procedure Put_String (S : in String); procedure Data_Out( Datum : in Word_T; ABC : in IO_Reg_T; IO_Flag : in IO_Flag_T); private SCP_Chan : GNAT.Sockets.Stream_Access; end TTOut; task SCP_Handler is entry Set_SCP_IO (SCP : in Boolean); entry Get_SCP_IO (SCP : out Boolean); entry Set_SCP_Line_Ready (Buffer : in Unbounded_String); entry SCP_Get_Line (Line : out Unbounded_String); end SCP_Handler; task Console_Handler is entry Start (Sock : in GNAT.Sockets.Socket_Type); end Console_Handler; SCP_IO : Boolean := true; IO_Error : exception; end Devices.Console;
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT ------------------------------------------------------------- with Program.Lexical_Elements; with Program.Source_Buffers; with Program.Symbols; private with Ada.Containers.Vectors; package Program.Plain_Lexical_Elements is pragma Preelaborate; type Lexical_Element (<>) is new Program.Lexical_Elements.Lexical_Element with private; function Symbol (Self : Lexical_Element'Class) return Program.Symbols.Symbol; type Line_Buffer is limited interface; not overriding function Text (Self : Line_Buffer; Span : Program.Source_Buffers.Span) return Program.Text is abstract; not overriding procedure Get_Span (Self : Line_Buffer; Span : Program.Source_Buffers.Span; From_Line : out Positive; To_Line : out Positive; From_Column : out Positive; To_Column : out Positive) is abstract; type Line_Buffer_Access is access all Line_Buffer'Class with Storage_Size => 0; type Lexical_Element_Vector (Buffer : not null Line_Buffer_Access) is limited new Program.Lexical_Elements.Lexical_Element_Vector with private; not overriding procedure Append (Self : aliased in out Lexical_Element_Vector; Span : Program.Source_Buffers.Span; Kind : Program.Lexical_Elements.Lexical_Element_Kind; Symbol : Program.Symbols.Symbol); private type Lexical_Element_Vector_Access is access all Lexical_Element_Vector with Storage_Size => 0; type Lexical_Element (Vector : Lexical_Element_Vector_Access) is new Program.Lexical_Elements.Lexical_Element with record Span : Program.Source_Buffers.Span; Kind : Program.Lexical_Elements.Lexical_Element_Kind; Symbol : Program.Symbols.Symbol; end record; overriding function Image (Self : Lexical_Element) return Program.Text; overriding function Kind (Self : Lexical_Element) return Program.Lexical_Elements.Lexical_Element_Kind; overriding function From (Self : Lexical_Element) return Program.Lexical_Elements.Location; package Vectors is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => Program.Lexical_Elements.Lexical_Element_Access, "=" => Program.Lexical_Elements."="); type Lexical_Element_Vector (Buffer : not null Line_Buffer_Access) is limited new Program.Lexical_Elements.Lexical_Element_Vector with record Vector : Vectors.Vector; end record; overriding function First_Index (Self : Lexical_Element_Vector) return Positive is (1); overriding function Last_Index (Self : Lexical_Element_Vector) return Positive; overriding function Element (Self : Lexical_Element_Vector; Index : Positive) return not null Program.Lexical_Elements.Lexical_Element_Access; end Program.Plain_Lexical_Elements;
-- Precompiled instantiations of Integer_IO and -- Float_IO for the predefined Integer and Float types WITH Text_IO; PACKAGE My_Int_IO IS NEW Text_IO.Integer_IO (Num => Integer); WITH Text_IO; PACKAGE My_Flt_IO IS NEW Text_IO.Float_IO (Num => Float);
------------------------------------------------------------------------------- -- Copyright (C) 2020-2030, per.s.sandberg@bahnhof.se -- -- -- -- 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 ZMQ.Sockets; with ZMQ.Contexts; with Ada.Text_IO; with GNAT.Sockets; procedure ZMQ.Examples.Prompt is Ctx : aliased Contexts.Context; S : Sockets.Socket; begin Ctx.Set_Number_Of_IO_Threads (1); S.Initialize (Ctx, Sockets.PUB); S.Connect ("tcp://localhost:5555"); Read_Loop : loop Ada.Text_IO.Put (">"); declare Textbuf : constant String := Ada.Text_IO.Get_Line; begin exit Read_Loop when Textbuf'Length = 0; S.Send ("Hello " & ASCII.NUL & GNAT.Sockets.Host_Name & ":" & Textbuf); delay 0.02; end; end loop Read_Loop; S.Send (END_MESSAGE); end ZMQ.Examples.Prompt;
-- This spec has been automatically generated from xyzzy pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; pragma Style_Checks (Off); with HAL; with System; package STM32_SVD.PKA is pragma Preelaborate; --------------- -- Registers -- --------------- subtype PKA_CR_MODE_Field is HAL.UInt6; -- PKA control register type PKA_CR_Register is record -- PKA Enable EN : Boolean := False; -- Start the operation START : Boolean := False; -- unspecified Reserved_2_7 : HAL.UInt6 := 16#0#; -- PKA operation code MODE : PKA_CR_MODE_Field := 16#0#; -- unspecified Reserved_14_16 : HAL.UInt3 := 16#0#; -- End of operation interrupt enable PROCENDIE : Boolean := False; -- unspecified Reserved_18_18 : HAL.Bit := 16#0#; -- RAM error interrupt enable RAMERRIE : Boolean := False; -- Address error interrupt enable ADDRERRIE : Boolean := False; -- unspecified Reserved_21_31 : HAL.UInt11 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for PKA_CR_Register use record EN at 0 range 0 .. 0; START at 0 range 1 .. 1; Reserved_2_7 at 0 range 2 .. 7; MODE at 0 range 8 .. 13; Reserved_14_16 at 0 range 14 .. 16; PROCENDIE at 0 range 17 .. 17; Reserved_18_18 at 0 range 18 .. 18; RAMERRIE at 0 range 19 .. 19; ADDRERRIE at 0 range 20 .. 20; Reserved_21_31 at 0 range 21 .. 31; end record; -- PKA status register type PKA_SR_Register is record -- unspecified Reserved_0_15 : HAL.UInt16; -- Read-only. PKA operation in progress BUSY : Boolean; -- Read-only. PKA end of operation flag PROCENDF : Boolean; -- unspecified Reserved_18_18 : HAL.Bit; -- Read-only. PKA ram error flag RAMERRF : Boolean; -- Read-only. address er flag ADDRERRF : Boolean; -- unspecified Reserved_21_31 : HAL.UInt11; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for PKA_SR_Register use record Reserved_0_15 at 0 range 0 .. 15; BUSY at 0 range 16 .. 16; PROCENDF at 0 range 17 .. 17; Reserved_18_18 at 0 range 18 .. 18; RAMERRF at 0 range 19 .. 19; ADDRERRF at 0 range 20 .. 20; Reserved_21_31 at 0 range 21 .. 31; end record; -- PKA clear flag register type PKA_CLRFR_Register is record -- unspecified Reserved_0_16 : HAL.UInt17 := 16#0#; -- Write-only. clear PKA end of operation flag PROCENDFC : Boolean := False; -- unspecified Reserved_18_18 : HAL.Bit := 16#0#; -- Write-only. CLEAR PKA RAM ERROR FLAG RAMERRFC : Boolean := False; -- Write-only. clear address error flag ADDRERRFC : Boolean := False; -- unspecified Reserved_21_31 : HAL.UInt11 := 16#0#; end record with Volatile_Full_Access, Object_Size => 32, Bit_Order => System.Low_Order_First; for PKA_CLRFR_Register use record Reserved_0_16 at 0 range 0 .. 16; PROCENDFC at 0 range 17 .. 17; Reserved_18_18 at 0 range 18 .. 18; RAMERRFC at 0 range 19 .. 19; ADDRERRFC at 0 range 20 .. 20; Reserved_21_31 at 0 range 21 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- PKA type PKA_Peripheral is record -- PKA control register PKA_CR : aliased PKA_CR_Register; -- PKA status register PKA_SR : aliased PKA_SR_Register; -- PKA clear flag register PKA_CLRFR : aliased PKA_CLRFR_Register; end record with Volatile; for PKA_Peripheral use record PKA_CR at 16#0# range 0 .. 31; PKA_SR at 16#4# range 0 .. 31; PKA_CLRFR at 16#8# range 0 .. 31; end record; -- PKA PKA_Periph : aliased PKA_Peripheral with Import, Address => PKA_Base; -- PKA SEC_PKA_Periph : aliased PKA_Peripheral with Import, Address => SEC_PKA_Base; end STM32_SVD.PKA;
-- { dg-do compile } package body Discr9 is procedure Proc (From : in R; To : out R) is begin To := R'(D1 => False, D2 => From.D2, Field => From.Field); end; end Discr9;
with avtas.lmcp.types; use avtas.lmcp.types; with afrl.cmasi.object; use afrl.cmasi.object; with afrl.cmasi.enumerations; use afrl.cmasi.enumerations; with Ada.Containers.Vectors; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package afrl.cmasi.payloadConfiguration is type PayloadConfiguration is new afrl.cmasi.object.Object with private; type PayloadConfiguration_Acc is access all PayloadConfiguration; type PayloadConfiguration_Class_Acc is access all PayloadConfiguration'Class; package Vect_Unbounded_String is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Unbounded_String); type Vect_Unbounded_String_Acc is access all Vect_Unbounded_String.Vector; function getFullLmcpTypeName(this : PayloadConfiguration) return String; function getLmcpTypeName(this : PayloadConfiguration) return String; function getLmcpType(this : PayloadConfiguration) return UInt32_t; function getPayloadID(this : PayloadConfiguration'Class) return Int64_t; procedure setPayloadID(this : out PayloadConfiguration'Class; PayloadID : in Int64_t); function getPayloadKind(this : PayloadConfiguration'Class) return Unbounded_String; procedure setPayloadKind(this : out PayloadConfiguration'Class; PayloadKind : in Unbounded_String); function getParameters(this : PayloadConfiguration'Class) return Vect_Unbounded_String_Acc; private type PayloadConfiguration is new afrl.cmasi.object.Object with record PayloadID : Int64_t := 0; PayloadKind : Unbounded_String; Parameters : Vect_Unbounded_String_Acc := new Vect_Unbounded_String.Vector; end record; end afrl.cmasi.payloadConfiguration;
package Debug6_Pkg is type Vkind is (Int, Undefined); for Vkind use (Int => -2 ** 31, Undefined => 0); type Value (Kind : Vkind) is record case Kind is when Undefined => null; when Int => Value : Integer; when others => null; end case; end record; procedure Process (V : Value); end Debug6_Pkg;
with Ada.Unchecked_Deallocation; with Ada.Streams; use Ada.Streams; package body DNSCatcher.DNS.Processor.RData.Domain_Name_Response_Parser is -- A records are simply four octlets which we need to turn into integers -- then decode back into an ASCII string pragma Warnings (Off, "formal parameter ""DNS_Header"" is not referenced"); procedure From_Parsed_RR (This : in out Parsed_DNR_RData; DNS_Header : DNS_Packet_Header; Parsed_RR : Parsed_DNS_Resource_Record) is Offset : Stream_Element_Offset := Parsed_RR.RData_Offset; begin This.Domain_Name := Parse_DNS_Packet_Name_Records (Parsed_RR.Raw_Packet, Offset); end From_Parsed_RR; pragma Warnings (On, "formal parameter ""DNS_Header"" is not referenced"); function RData_To_String (This : in Parsed_DNR_RData) return String is begin return To_String (This.Domain_Name); end RData_To_String; function Print_Packet (This : in Parsed_DNR_RData) return String is begin return This.RType'Image & " " & RData_To_String (This); end Print_Packet; -- Obliberate ourselves procedure Delete (This : in out Parsed_DNR_RData) is procedure Free_Parsed_DNR_Record is new Ada.Unchecked_Deallocation (Object => Parsed_DNR_RData, Name => Parsed_DNR_RData_Access); Ptr : aliased Parsed_DNR_RData_Access := This'Unchecked_Access; begin Free_Parsed_DNR_Record (Ptr); end Delete; end DNSCatcher.DNS.Processor.RData.Domain_Name_Response_Parser;
-- { dg-do compile } -- { dg-options "-gnatwa" } package body return1 is function X_Func (O : access Child) return access Base'Class is begin return X_Local : access Base'Class do X_Local := O; end return; end X_Func; end return1;
-- C74407B.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- OBJECTIVE: -- CHECK, FOR A LIMITED PRIVATE TYPE, THAT PRE-DEFINED EQUALITY AND -- ASSIGNMENT ARE DEFINED AND AVAILABLE WITHIN THE PRIVATE PART AND -- THE BODY OF A PACKAGE, AFTER THE FULL DECLARATION, IF THE FULL -- DECLARATION IS NOT LIMITED. -- HISTORY: -- BCB 07/15/88 CREATED ORIGINAL TEST. WITH REPORT; USE REPORT; PROCEDURE C74407B IS PACKAGE PP IS TYPE PRIV IS PRIVATE; C1 : CONSTANT PRIV; C2 : CONSTANT PRIV; PRIVATE TYPE PRIV IS (ONE, TWO, THREE, FOUR, FIVE, SIX); C1 : CONSTANT PRIV := ONE; C2 : CONSTANT PRIV := TWO; END PP; USE PP; PACKAGE P IS TYPE INT IS LIMITED PRIVATE; TYPE COMP IS LIMITED PRIVATE; TYPE DER IS LIMITED PRIVATE; PRIVATE TYPE INT IS RANGE 1 .. 100; TYPE COMP IS ARRAY(1..5) OF INTEGER; TYPE DER IS NEW PRIV; D, E : INT := 10; F : INT := 20; CONS_INT1 : CONSTANT INT := 30; G : BOOLEAN := D = E; H : BOOLEAN := D /= F; CONS_BOOL1 : CONSTANT BOOLEAN := D = E; CONS_BOOL2 : CONSTANT BOOLEAN := D /= F; I : COMP := (1,2,3,4,5); CONS_COMP1 : CONSTANT COMP := (6,7,8,9,10); J : DER := DER(C1); CONS_DER1 : CONSTANT DER := DER(C2); END P; PACKAGE BODY P IS A, B, C : INT; X, Y, Z : COMP; L, M, N : DER; CONS_INT2 : CONSTANT INT := 10; CONS_COMP2 : CONSTANT COMP := (1,2,3,4,5); CONS_DER2 : CONSTANT DER := DER(C1); BEGIN TEST ("C74407B", "CHECK, FOR A LIMITED PRIVATE TYPE, THAT " & "PRE-DEFINED EQUALITY AND ASSIGNMENT ARE " & "DEFINED AND AVAILABLE WITHIN THE PRIVATE " & "PART AND THE BODY OF A PACKAGE, AFTER " & "THE FULL DECLARATION, IF THE FULL " & "DECLARATION IS NOT LIMITED"); A := 10; B := 10; C := 20; IF A = C THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED EQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 1"); END IF; IF A /= B THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED INEQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 1"); END IF; IF CONS_INT2 = C THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED EQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 2"); END IF; IF CONS_INT2 /= B THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED INEQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 2"); END IF; IF NOT G THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED EQUALITY " & "OPERATION WITHIN THE PRIVATE PART OF THE " & "PACKAGE - 1"); END IF; IF NOT H THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED INEQUALITY " & "OPERATION WITHIN THE PRIVATE PART OF THE " & "PACKAGE - 1"); END IF; IF NOT CONS_BOOL1 THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED EQUALITY " & "OPERATION WITHIN THE PRIVATE PART OF THE " & "PACKAGE - 2"); END IF; IF NOT CONS_BOOL2 THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED INEQUALITY " & "OPERATION WITHIN THE PRIVATE PART OF THE " & "PACKAGE - 2"); END IF; X := (1,2,3,4,5); Y := (1,2,3,4,5); Z := (5,4,3,2,1); IF X = Z THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED EQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 3"); END IF; IF X /= Y THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED INEQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 3"); END IF; IF CONS_COMP2 = Z THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED EQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 4"); END IF; IF CONS_COMP2 /= Y THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED INEQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 4"); END IF; L := DER(C1); M := DER(C1); N := DER(C2); IF L = N THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED EQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 5"); END IF; IF L /= M THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED INEQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 5"); END IF; IF CONS_DER2 = N THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED EQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 6"); END IF; IF CONS_DER2 /= M THEN FAILED ("IMPROPER RESULT FROM PRE-DEFINED INEQUALITY " & "OPERATION WITHIN THE PACKAGE BODY - 6"); END IF; RESULT; END P; USE P; BEGIN NULL; END C74407B;
with Ada.Interrupts; with Ada.Interrupts.Names; package usb_handler is protected Device_Interface is pragma Interrupt_Priority; procedure Handler; pragma Attach_Handler (Handler, Ada.Interrupts.Names.OTG_FS_Interrupt); end Device_Interface; end usb_handler;
-- Copyright (c) 2017 Maxim Reznik <reznikmm@gmail.com> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- package body LSP.Notification_Dispatchers is -------------- -- Dispatch -- -------------- not overriding procedure Dispatch (Self : in out Notification_Dispatcher; Method : LSP.Types.LSP_String; Stream : access Ada.Streams.Root_Stream_Type'Class; Handler : not null LSP.Message_Handlers.Notification_Handler_Access) is Cursor : Maps.Cursor := Self.Map.Find (Method); begin if not Maps.Has_Element (Cursor) then Cursor := Self.Map.Find (League.Strings.Empty_Universal_String); end if; Maps.Element (Cursor) (Stream, Handler); end Dispatch; -------------- -- Register -- -------------- not overriding procedure Register (Self : in out Notification_Dispatcher; Method : League.Strings.Universal_String; Value : Parameter_Handler_Access) is begin Self.Map.Insert (Method, Value); end Register; end LSP.Notification_Dispatchers;
with Text_IO; use Text_IO; procedure Fibtest is Passed : Boolean := True; function Fib(N : in Positive) return Positive is separate; procedure Compare (N : in Positive; Right_Answer : in Positive) is package Int_IO is new Integer_IO(Integer); use Int_IO; My_Answer : Positive := Fib(N); begin if My_Answer /= Right_Answer then Put("N:"); Put(N); Put(" My answer:"); Put(My_Answer); Put(" Right answer:"); Put(Right_Answer); New_Line; Passed := False; end if; end Compare; begin Compare(1, 1); Compare(2, 1); Compare(3, 2); Compare(4, 3); Compare(5, 5); Compare(6, 8); Compare(7, 13); Compare(10, 55); Compare(15, 610); Compare(20, 6765); if Passed then Put_Line("Congratulations, you completed the assignment!"); end if; end Fibtest;
package Deferred_Const2_Pkg is I : Integer := 16#20_3A_2D_28#; pragma Warnings (Off); S : constant string(1..4); for S'address use I'address; pragma Import (Ada, S); procedure Dummy; end Deferred_Const2_Pkg;
package body Opt13_Pkg is subtype Index_Type is Natural range 0 .. 16; type Arr is array (Index_Type range <>) of Integer; type Rec is record F1, F2, F3 : Float; N : Natural; B1, B2 : Boolean; F4 : Float; end record; type Data (D : Index_Type) is record A : Arr (1 .. D); R : Rec; end record; Zero : constant Rec := (0.0, 0.0, 0.0, 0, False, False, 0.0); procedure Allocate (T : out My_Type) is begin T := new Data (Index_Type'last); T.R := Zero; for I in 1 .. T.A'last loop N := 1; end loop; end; end Opt13_Pkg;
------------------------------------------------------------------------------ -- -- -- ASIS-for-GNAT IMPLEMENTATION COMPONENTS -- -- -- -- A 4 G . S I N P U T -- -- -- -- S p e c -- -- -- -- Copyright (C) 1995-2008, 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). -- -- -- ------------------------------------------------------------------------------ -- This package adds to the GNAT Sinput package some utility routines -- used for obtaining and/or analyzing the pieces of the compilation -- unit's source code from the source buffer. -- -- Note, that up to the version 3.09, the Tree_Read procedure in the GNAT -- Sinput package contains a bug - it does not reset to the initial values -- the global variables used to implement caching for searching for -- a source file index. The ASIS implementation includes the corrected -- version of Sinput package -- -- The routines defined in this package are intended to be used in the -- implementation of the Asis.Text package and for implementing queries -- from other ASIS packages having String or Asis_String as the returned -- (sub)type. -- -- All the routines defined in this package rely on the fact that all -- the source buffers being accessed correspond to the compilable units, -- so they do not care about error finding and recovery. with Asis.Text; use Asis.Text; with Types; use Types; package A4G.A_Sinput is function A_Get_Column_Number (P : Source_Ptr) return Source_Ptr; -- This function differs from the Sinput.Get_Column_Number function in two -- aspects. First, it does not make any transformations of Tab characters -- into equivalent sequences of blanks to represent the standard 1,9,17.. -- spacing pattern, it returns the column number of the specified -- Source_Ptr value as the "distance" from the beginning of the -- corresponding line in the source text. Second, this function considers a -- content of the source buffer as a possible encoding of wide character -- string and counts the column number in wide characters that make up -- the source code. function Wide_String_Image (Node : Node_Id) return Wide_String; -- for Node of N_String_Literal, N_Defining_Operator_Symbol or -- N_Operator_Symbol kind returns the string image of the corresponding -- represented string literal, including string quoters, as it is -- required by the ASIS queries Value_Image, Name_Image and -- Defining_Name_Image. It is an error to call this function for -- a node of some other node kind. This function transformes the internal -- representation of the argument construct taking into account the -- encoding method. function Operator_Image (Node : Node_Id) return String; -- this function returns the string imege of an operator_symbol -- from infix calls to operator functions. It works on nodes of -- N_Identifier and N_Op_Xxx kind. The result includes string quotes -- as for the prefix call to operator function. function Get_Character (P : Source_Ptr) return Character; -- Returns the character pointed by P. -- This function is not "tree-swapping-safe" -- FROM S_B_Serv and from Subservises function Get_Wide_Word (P_Start : Source_Ptr; P_End : Source_Ptr) return Wide_String; -- Returns a part of the source text corresponding to the part of ints -- internal representation bounded by P_Start .. P_End. Takes into account -- the encoding of wide characters and makes the corresponding conversions. -- This function does not check, that P_Start and P_End both point into the -- same source. -- This function is not "tree-swapping-safe" function Source_Locations_To_Span (Span_Beg : Source_Ptr; Span_End : Source_Ptr) return Span; -- Transforms the pair of locations in the source buffer into an -- ASIS Span. Note, that ASIS Span counts the source positions in wide -- characters, whereas Span_Beg and Span_End are pointers to the internal -- string (but not wide string!) representation of the source text! -- This function is not "tree-swapping-safe" function Get_Location (E : Asis.Element) return Source_Ptr; -- Returns the value of the Sloc field of the (original) node -- on which E is based -- This function is "tree-swapping-safe" -- FROM Subservises function Number_Of_Lines (E : Asis.Element) return Integer; -- Returns the number of the last line in the source file accessable -- through this Element, taking into account Source_Reference pragma if -- it presents in the source file. -- -- This function is "tree-swapping-safe" -- FROM Subservises function Identifier_Image (Ident : Node_Id) return String; -- For a node, which is of N_Identifier or N_Defining_Identifier kind, -- this function returns the string image of the corresponding -- (defining) identifier -- Note, that this function does not take into account the possible -- encoding of upper half wide characters. The results of this function are -- used in internal Compilation Unit table only, so this function does not -- make any problem for proper encoding processing in Asis.Text. But anyway -- this should be revised to completely conform to the source -- representation required by the Ada standard. function Exp_Name_Image (Name : Node_Id) return String; -- For a node, which is of N_Defining_Program_Unit_Name, -- N_Defining_Identifier, N_Expanded_Name or N_Identifier kind, -- this function returns the string image of the corresponding name function Comment_Beginning (Line_Image : Text_Buffer) return Source_Ptr; -- Returns position of the first _comment_ hyphen in the argument string. -- If there is no comment, then returns No_Location. -- The string has to correspond to a legal Ada program fragment, -- otherwise a constraint error may be raised. -- -- Note, that this function can be used for detecting the comment beginning -- in the line buffer of the Standard String type, because the index range -- of Text_Buffer (and the range of Source_Ptr) includes the low bound of -- Positive. ------------------------------------------------------------------------ -- Staring from this point, some mess exists, which originates from -- -- collecting all the text processing/source buffer-processing -- -- routines from Subservices and S_B_Serv -- ------------------------------------------------------------------------ function Next_Identifier (P : Source_Ptr) return Source_Ptr; -- Returns the location of the first charaster of the identifier which -- should follow the position indicated by P. Initially this -- function was intended to find the beginning of the pragma identifier, -- so two requirements should be met for its correct use: P points to -- some separator (as defined by RM 95 2.2 (3-6), and the next lexem -- should be either comment or identifier. -- This function is not "tree-swapping-safe" -- FROM S_B_Serv function Get_String_End (P : Source_Ptr) return Source_Ptr; -- Supposing that P points to the leading quotation of the string -- literal, this function defines the location of the quotation -- ending the string constant. -- This function is not "tree-swapping-safe" -- FROM S_B_Serv function Get_Num_Literal_End (P : Source_Ptr) return Source_Ptr; -- Supposing that P points to the first character of a numeric -- literal, this function defines the location of the last character -- of the literal. -- This function is not "tree-swapping-safe" -- FROM S_B_Serv function Search_Rightmost_Symbol (P : Source_Ptr; Char : Character := ';') return Source_Ptr; -- The function returns the location of the rightmost symbol equial -- to Char for the position indicated by P (including P itself). -- Comments are skipped during the search -- This function is not "tree-swapping-safe" -- FROM S_B_Serv function Rightmost_Non_Blank (P : Source_Ptr) return Source_Ptr; -- returns the first non-blank symbol (excluding format effectors) -- following P (if P itself is a non-blank symbol, P is returned). -- Comments are skipped type In_Word_Condition is access function (P : Source_Ptr) return Boolean; -- I wish I had time to get rid of this awkward approach based on -- In_Word_Condition! :(( function Get_Word_End (P : Source_Ptr; In_Word : In_Word_Condition) return Source_Ptr; -- The function returns the location of the firs/last character of the -- lexical element which contains character pointed by P. It is supposed -- that P does not point inside comment, separator or delimiter (RM95 2.2) -- -- The first version of these function (with the second parameters of -- In_Word_Char_Condition type is used when it is enough to test only one -- character to get the answer. But if it is necessary to examine some -- characters before/after the given character, the second form should be -- used with the corresponding test function. -- -- The initial idea is to use these functions to get the start/end of -- identifiers, numeric literals and string literals. -- This function is not "tree-swapping-safe" -- FROM S_B_Serv function In_Identifier (P : Source_Ptr) return Boolean; -- Returns true if P points somewhere inside an identifier, and False -- otherwise -- This function is not "tree-swapping-safe" -- FROM S_B_Serv function Search_Prev_Word (S : Source_Ptr) return Source_Ptr; -- Returns the location of the previous word end. -- The comments are skipped. -- This function is not "tree-swapping-safe" -- FROM Subservises function Search_Beginning_Of_Word (S : Source_Ptr) return Source_Ptr; -- Returns the location of the beginning of the word to which S points. -- This function is not "tree-swapping-safe" -- FROM Subservises function Search_Prev_Word_Start (S : Source_Ptr) return Source_Ptr; -- Equivalent to Search_Beginning_Of_Word (Search_Prev_Word (S)) function Search_End_Of_Word (S : Source_Ptr) return Source_Ptr; -- Returns the location of the end of the word to which S points. -- This function is not "tree-swapping-safe" -- FROM Subservises -- It's crazy to have it along with Get_Word_End!!! function Search_Next_Word (S : Source_Ptr) return Source_Ptr; -- Returns the location of the next word beginning. The comments -- are skipped. -- This function is not "tree-swapping-safe" -- FROM Subservises function Search_Left_Parenthesis (S : Source_Ptr) return Source_Ptr; -- Returns the location of the first inclusion of left parenthesis before -- the location in source file to which S points. -- This function is not "tree-swapping-safe" -- FROM Subservises function Is_EOL_Char (Ch : Character) return Boolean; -- Checks if Ch is a character defining an end of line. According to RM05 -- 2.2(2/2), "a sequence of one or more format_effectors other than the -- character whose code position is 16#09# (CHARACTER TABULATION) signifies -- at least one end of line." function Get_Wide_Ch (S : Source_Ptr) return Wide_Character; -- Provided that S points to the first character of the internal -- representation of some character from the original source, returns -- this riginal source character, taking into account the encoding method function Is_Start_Of_Wide_Char_For_ASIS (S : Source_Buffer_Ptr; P : Source_Ptr; C : Source_Ptr := No_Location) return Boolean; -- Determines if S (P) is the start of a wide character sequence. This -- function differs from Widechar in two aspects: first, it assumes that -- the bracket encoding can not be used in a comment text, and if set, the -- actual for C should point to the beginning of the comment that in the -- source buffer, and second, in any non-comment text it assumes that a -- bracket encoding is always set ON (see the description of -gnatW option -- in GNAT UGN). procedure Skip_Wide_For_ASIS (S : Source_Buffer_Ptr; P : in out Source_Ptr); -- Similar to Widechar.Skip_Wide, but always skips bracked encoding -- sequense. Before calling this function, the caller should check thar -- Is_Start_Of_Wide_Char_For_ASIS (S, P) is True end A4G.A_Sinput;
with Interfaces.C; package Crypto with SPARK_Mode, Abstract_State => key_store, Initializes => key_store is subtype Byte is Interfaces.C.unsigned_char; subtype Key_Slot is Interfaces.C.int range 0 .. 3; type Key_Index is range 1 .. 128; type Key is array (Key_Index) of Byte; type Data_Index is range 1 .. 1_024; type Data is array (Data_Index) of Byte; procedure loadkey (keyslot : in Key_Slot; the_key : in Key; result : out Boolean) with Global => (in_out => key_store); procedure encrypt (keyslot : in Key_Slot; the_data : in out Data; result : out Boolean) with Global => (in_out => key_store); end Crypto;
------------------------------------------------------------------------------- -- 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; use DW1000.Types; -- @summary -- Types and functions for dealing with time derived from the DW1000 system -- time (clocked at 63.8976 GHz). -- -- @description -- The DW1000's system time is used for several 40-bit timestamps which are -- measured in units of approx. 15.65 picoseconds. The timestamps which use -- this 40-bit 63.8976 GHz system time are listed below: -- * System Time Counter (SYS_TIME register) -- * Delayed Send or Receive Time (DX_TIME register) -- * Adjusted Receive Timestamp (RX_STAMP field in the RX_TIME register) -- * Raw Receive Timestamp (RX_RAWST field in the RX_TIME register) -- * Adjusted Transmit Timestamp (TX_STAMP field in the TX_TIME register) -- * Raw Transmit Timestamp (TX_RAWST field in the TX_TIME register) -- -- Out of the above registers, not all are capable of measuring to the full -- 40-bit granularity of 15.65 picoseconds. In some registers the 9 least -- significant bits are ignored which gives 512x less precision, i.e. the -- effective granularity is 8.013 nanoseconds. The registers that are capable -- of the FULL precision of 15.65 picoseconds are listed below: -- * Adjusted Receive Timestamp (RX_STAMP field in the RX_TIME register) -- * Adjusted Transmit Timestamp (TX_STAMP field in the TX_TIME register) -- -- The following registers ignore the 9 least significant bits, providing a -- granularity of 8.013 nanoseconds: -- * System Time Counter (SYS_TIME register) -- * Delayed Send or Receive Time (DX_TIME register) -- * Raw Receive Timestamp (RX_RAWST field in the RX_TIME register) -- * Raw Transmit Timestamp (TX_RAWST field in the TX_TIME register) -- -- To manage the two time stamp precisions, the System_Time package defines -- two types: -- * Fine_System_Time, capable of the full 15.65 picosecond precision. -- * Coarse_System_Time, capable of the restricted 8.013 nanosecond -- precision. -- -- For both of these types, conversion functions are defined to convert to and -- from the 40-bit representation type that is used by the DW1000 register -- set. The To_Bits_40 function converts from either Fine_System_Time or -- Coarse_System_Time to the Bits_40 type. The To_Fine_System_Time and -- To_Coarse_System_Time functions convert from the Bits_40 representation to -- the Fine_System_Time and Coarse_System_Time types respectively. -- -- Furthermore, the antenna delay is also measured in units of -- 15.65 picoseconds, but only has a 16-bit range (compared to the 40-bit -- timestamps with a much bigger range). The antenna delay is represented -- as the type Antenna_Delay_Time, which is a subtype of Fine_System_Time -- with a maximum value of about 1.0256 microseconds. -- -- For the antenna delay there are two conversion functions: To_Bits_16 and -- To_Antenna_Delay_Time. The To_Bits_16 function converts from the -- Antenna_Delay_Time type to its 16-bit representation. The -- To_Antenna_Delay_Time function converts the other way; from the 16-bit -- representation to the Antenna_Delay_Time type. package DW1000.System_Time with SPARK_Mode => On is Chipping_Rate_Hz : constant := 499_200_000.0; -- DW1000 system clocks are referenced to the 499.2 MHz chipping rate -- defined in the IEEE 802.15.4-2011 standard. System_Time_Clock_Hz : constant := Chipping_Rate_Hz * 128.0; -- System time and time stamps are based on time units which are at -- 63.8976 GHz (499.2 MHz * 128). This yields a resolution of -- approximately 15.65 picoseconds. type Fine_System_Time is delta 1.0 / System_Time_Clock_Hz range 0.0 .. (2.0**40 - 1.0) / System_Time_Clock_Hz with Small => 1.0 / System_Time_Clock_Hz, Size => 40; -- Type for representing the DW1000 fine-grained system time in seconds, -- with a precision of at least 15.65 picoseconds. -- -- The DW1000 uses Bits_40 to represent timestamp values (e.g. system time, -- and tx/rx timestamps), which is measured in units of 499.2 MHz * 128, -- i.e. it increments in units of about 15.65 picoseconds (when using the -- PLL clock). -- -- The Fine_System_Time is used for the transmit and receive time stamps. -- -- WARNING: This type represents the system time when the PLL clock is -- used. On power up, before the digital PLL is enabled, the System Time -- increments in units of about 52.08 nanoseconds (3328x slower than the -- PLL), and so this Fine_System_Time type is not appropriate in such -- circumstances. type Coarse_System_Time is delta 512.0 / System_Time_Clock_Hz range 0.0 .. (2.0**40 - 1.0) / System_Time_Clock_Hz with Small => 1.0 / System_Time_Clock_Hz, Size => 40; -- Type for representing the DW1000 coarsely-grained system time in seconds, -- with a precision of at least 8.013 nanoseconds. -- -- The DW1000 uses Bits_40 to represent the system time counter and the -- delayed tx/rx times, but ignores the low 9 order bits giving an -- effective precision of 8.013 nanoseconds (512x less precise than the -- fine-grained system time used for the transmit and receive timestamps). -- -- The Coarse_System_Time is used for the System Time Counter, and the -- delayed tx/rx times. -- -- WARNING: This type represents the system time when the PLL clock is -- used. On power up, before the digital PLL is enabled, the System Time -- increments in units of about 26.67 microseconds (3328x slower than the -- PLL), and so this Coarse_System_Time type is not appropriate in such -- circumstances. type System_Time_Span is new Fine_System_Time; type Antenna_Delay_Time is delta Fine_System_Time'Delta range 0.0 .. Fine_System_Time'Delta * (2**16 - 1) with Small => Fine_System_Time'Small, Size => 16; -- Type to represent an antenna delay time. type Frame_Wait_Timeout_Time is delta 512.0 / Chipping_Rate_Hz range 0.0 .. ((2.0**16 - 1.0) * 512.0) / Chipping_Rate_Hz with Small => 512.0 / Chipping_Rate_Hz, Size => 16; -- Type to represent the frame wait timeout. -- -- The range of this type is 0.0 .. 0.067215385, i.e. the maximum value -- is 67.215385 milliseconds. -- -- The resolution of this type is 128 system block cycle -- (about 1 microsecond). type Response_Wait_Timeout_Time is delta 512.0 / Chipping_Rate_Hz range 0.0 .. ((2.0**20 - 1.0) * 512.0) / Chipping_Rate_Hz with Small => 512.0 / Chipping_Rate_Hz, Size => 20; -- Type to represent the wait-for-response turnaround time. -- -- The range of this type is 0.0 .. 1.0754615 i.e. the maximum value is -- about 1.0754615 seconds. -- -- The resolution of this type is 128 system block cycle -- (about 1 microsecond). type Sniff_Off_Time is delta 512.0 / Chipping_Rate_Hz range 0.0 .. ((2.0**8 - 1.0) * 512.0) / Chipping_Rate_Hz with Small => 512.0 / Chipping_Rate_Hz, Size => 8; -- Type to represent the SNIFF mode OFF time. -- -- The range of this type is 0.0 .. 0.000_262_051 i.e. the maximum value is -- about 0.000_262_051 seconds (about 262 microseconds). -- -- The resolution of this type is 128 system block cycle -- (about 1 microsecond). type Snooze_Time is delta 1.0 / 37_500.0 range 0.0 .. (2.0**8 - 1.0) / 37_500.0 with Small => 1.0 / 37_500.0, Size => 8; -- Type to represent the snooze time (in seconds). -- -- This represents the upper 8 bits of a 17-bit timer clocked from the -- 19.2 MHz XTI internal clock. This means that this snooze time value -- is in units of 37.5 KHz, i.e. about 26.7 microseconds. -- -- The maximum value of this type is 0.0068 (6.8 milliseconds). type Blink_Time is delta 0.014 range 0.0 .. (2.0**8 - 1.0) * 0.014 with Small => 0.014, Size => 8; -- Type to represent the LED blink time (in seconds). -- -- This is in units of 14 milliseconds, so a value of 0.4 will give a -- blink time of 400 ms followed by an off blink of 400 ms. -- -- The maximum value of this type is 3.57 seconds. function To_Bits_40 (Time : in Fine_System_Time) return Bits_40 is (Bits_40 (Time / Fine_System_Time (Fine_System_Time'Delta))); -- Convert a Fine_System_Time value to its equivalent Bits_40 -- representation. -- -- Note that is a surjective function, i.e. some values of System_Time -- map to the same Bits_40 value. This is due System_Time supporting a -- smaller granularity (approx. 0.9 picoseconds) than Bits_40 -- (approx. 15.65 picoseconds). function To_Bits_40 (Time : in Coarse_System_Time) return Bits_40 is (Bits_40 (Time / Coarse_System_Time (Coarse_System_Time'Delta)) * 512) with Post => (To_Bits_40'Result and 2#1_1111_1111#) = 0; -- Convert a Coarse_System_Time value to its 40-bit integer representation. -- -- Note that for registers using a coarse time the 9 least significant bits -- are 0. function To_Bits_40 (Span : in System_Time_Span) return Bits_40 is (To_Bits_40 (Fine_System_Time (Span))); -- Convert a System_Time_Span value to its equivalent Bits_40 -- representation. -- -- System_Time_Span has the same resolution as Fine_System_Time, so the -- LSB in the Bits_40 representation is approx. 15.65 picoseconds. function To_Bits_16 (Time : in Antenna_Delay_Time) return Bits_16 is (Bits_16 (Time / Antenna_Delay_Time (Antenna_Delay_Time'Delta))); -- Convert a Antenna_Delay_Time value to its 16-bit representation. function To_Bits_16 (Time : in Frame_Wait_Timeout_Time) return Bits_16 is (Bits_16 (Time / Frame_Wait_Timeout_Time (Frame_Wait_Timeout_Time'Delta))); -- Convert a Frame_Wait_Timeout_Time to its 16-bit representation. function To_Fine_System_Time (Bits : in Bits_40) return Fine_System_Time with Inline, Global => null; -- Convert a Bits_40 value to Fine_System_Time. -- -- The DW1000 register set uses a 40-bit integer to represent the system -- time and rx/tx timestamp values. This function converts the 40-bit -- integer representation to the System_Time fixed-point representation. function To_Coarse_System_Time (Bits : in Bits_40) return Coarse_System_Time with Inline, Global => null; -- Convert a 40-bit register value to Coarse_System_Time. function To_System_Time_Span (Bits : in Bits_40) return System_Time_Span is (System_Time_Span (To_Fine_System_Time (Bits))) with Inline, Global => null; -- Convert a 40-bit time span to the equivalent System_Time_Span value. function To_Antenna_Delay_Time (Bits : in Bits_16) return Antenna_Delay_Time with Inline, Global => null; -- Convert a 16-bit antenna delay register value to Antenna_Delay_Time. function System_Time_Offset (Time : in Fine_System_Time; Span : in System_Time_Span) return Fine_System_Time; -- Calculate the offset of a system time, with wrap-around. -- -- Since the system time on the DW1000 is a counter which wraps-around, -- it is also permitted to have System_Time wrap-around when calculating -- a specific System_Time offset set in the future. This function handles -- this wrap-around case correctly. -- -- This function is particularly useful when calculating a specific time -- at which the next packet should be set, relative to the previously -- received packet's timestamp. function System_Time_Offset (Time : in Coarse_System_Time; Span : in System_Time_Span) return Fine_System_Time is (System_Time_Offset (Fine_System_Time (Time), Span)); function Calculate_Span (Start_Time : in Fine_System_Time; End_Time : in Fine_System_Time) return System_Time_Span; -- Calculate the time span between two points in time. -- -- Note that since the DW1000 system time wraps-around after about every -- 17 seconds, so it is possible for the End_Time to be less than the -- Start_Time. This function takes this wrap-around behavior into account. function Calculate_Span (Start_Time : in Coarse_System_Time; End_Time : in Coarse_System_Time) return System_Time_Span is (Calculate_Span (Fine_System_Time (Start_Time), Fine_System_Time (End_Time))); -- Calculate the time span between two points in time. -- -- Note that since the DW1000 system time wraps-around after about every -- 17 seconds, so it is possible for the End_Time to be less than the -- Start_Time. This function takes this wrap-around behavior into account. function Calculate_Span (Start_Time : in Fine_System_Time; End_Time : in Coarse_System_Time) return System_Time_Span is (Calculate_Span (Start_Time, Fine_System_Time (End_Time))); -- Calculate the time span between two points in time. -- -- Note that since the DW1000 system time wraps-around after about every -- 17 seconds, so it is possible for the End_Time to be less than the -- Start_Time. This function takes this wrap-around behavior into account. function Calculate_Span (Start_Time : in Coarse_System_Time; End_Time : in Fine_System_Time) return System_Time_Span is (Calculate_Span (Fine_System_Time (Start_Time), End_Time)); -- Calculate the time span between two points in time. -- -- Note that since the DW1000 system time wraps-around after about every -- 17 seconds, so it is possible for the End_Time to be less than the -- Start_Time. This function takes this wrap-around behavior into account. private type FP_40 is delta 1.0 range 0.0 .. 2.0**40 - 1.0 with Small => 1.0; -- Helper fixed-point type to represent a 40-bit integer type. function To_Fine_System_Time (Bits : in Bits_40) return Fine_System_Time is (Fine_System_Time (Fine_System_Time'Delta) * FP_40 (Bits)); function To_Coarse_System_Time (Bits : in Bits_40) return Coarse_System_Time is (Coarse_System_Time (Coarse_System_Time'Delta) * FP_40 (Bits / 512)); function To_Antenna_Delay_Time (Bits : in Bits_16) return Antenna_Delay_Time is (Antenna_Delay_Time'Delta * Integer (Bits)); end DW1000.System_Time;
with Ada.Command_Line; with Ada.Numerics.Long_Elementary_Functions; with Ada.Text_IO; with DDS.DomainParticipant; with DDS.DomainParticipantFactory; with Primes.PrimeNumberReplier; with Primes.PrimeNumberRequest_TypeSupport; with RTIDDS.Config; procedure Primes.Replier_Main is use Ada.Numerics.Long_Elementary_Functions; use Ada.Text_IO; use Primes; use type DDS.DomainParticipant.Ref_Access; use type DDS.ReturnCode_T; use type DDS.long; Factory : constant DDS.DomainParticipantFactory.Ref_Access := DDS.DomainParticipantFactory.Get_Instance; MAX_WAIT : constant DDS.Duration_T := DDS.To_Duration_T (20.0); procedure Replier_Shutdown (Participant : in out DDS.DomainParticipant.Ref_Access; Replier : in Primes.PrimeNumberReplier.Ref_Access; Request : in out PrimeNumberRequest_Access) is pragma Unreferenced (Request); begin -- Delete_Data (Request); Replier.Delete; Participant.Delete_Contained_Entities; Factory.Delete_Participant (Participant); Factory.Finalize_Instance; end; procedure Send_Error_Reply (Replier : PrimeNumberReplier.Ref_Access; Request : PrimeNumberRequest; Request_Id : DDS.SampleIdentity_T) is pragma Unreferenced (Request); Reply : aliased PrimeNumberReply; begin Initialize (Reply); Reply.Status := REPLY_ERROR; Replier.Send_Reply (Reply, Request_Id); Finalize (Reply); end; procedure Calculate_And_Send_Primes (Replier : PrimeNumberReplier.Ref_Access; Request : PrimeNumberRequest; Request_Id : DDS.SampleIdentity_T) is M, Length : DDS.long; N : constant DDS.long := Request.N; Primes_Per_Reply : constant DDS.Natural := Request.Primes_Per_Reply; Reply : aliased PrimeNumberReply; type Prime_Type is array (0 .. N) of Integer; Prime : Prime_Type := (0 => 0, 1 => 0, others => 1); use DDS.Long_Seq; begin Length := 0; Initialize (Reply); Set_Maximum (Reply.Primes'Access, Primes_Per_Reply); Reply.Status := REPLY_IN_PROGRESS; M := DDS.long (Sqrt (Long_Float (N))); for I in 2 .. M loop if Prime (I) /= 0 then for K in I * I .. N loop Prime (K) := 0; end loop; Append (Reply.Primes'Access, I); if Length + 1 = Primes_Per_Reply then Replier.Send_Reply (Reply, Request_Id); Set_Length (Reply.Primes'Access, 0); end if; end if; end loop; -- Calculation is done. Send remaining prime numbers for I in M + 1 .. N loop if Prime (I) /= 0 then Length := Get_Length (Reply.Primes'Access); Append (Reply.Primes'Access, I); if Length + 1 = Primes_Per_Reply then Replier.Send_Reply (Reply, Request_Id); Set_Length (Reply.Primes'Access, 0); end if; end if; end loop; -- Send the last reply. Indicate that the calculation is complete and -- send any prime number left in the sequence Reply.Status := REPLY_COMPLETED; Replier.Send_Reply (Reply, Request_Id); end; procedure Replier_Main (Domain_Id : DDS.DomainId_T) is Participant : DDS.DomainParticipant.Ref_Access; Replier : PrimeNumberReplier.Ref_Access; Request_Id : Dds.SampleIdentity_T; Request_Info : aliased DDS.SampleInfo; Request : PrimeNumberRequest_Access := PrimeNumberRequest_TypeSupport.Create_Data; RetCode : DDS.ReturnCode_T := DDS.RETCODE_OK; begin -- /* Create the participant */ Participant := Factory.Create_Participant (Domain_Id); if Participant = null then Put_Line (Standard_Error, "create_participant error"); return; end if; -- Create the replier with that participant, and a QoS profile -- * defined in USER_QOS_PROFILES.xml Replier := PrimeNumberReplier.Create (Participant, Service_Name , Qos_Library_Name, Qos_Profile_Name); Request := PrimeNumberRequest_TypeSupport.Create_Data; -- /* -- * Receive requests and process them -- */ Retcode := Replier.Receive_Request (Request.all, Request_Info, Timeout => MAX_WAIT); while Retcode = DDS.RETCODE_OK loop if Request_Info.Valid_Data then DDS.Get_Sample_Identity (Request_Info, Request_Id); -- This constant is defined in Primes.idl */ if Request.N <= 0 or Request.Primes_Per_Reply <= 0 or Request.Primes_Per_Reply > PRIME_SEQUENCE_MAX_LENGTH then Put_Line (Standard_Error, "Cannot process request"); Send_Error_Reply (Replier, Request.all, Request_Id); else Put_Line ("Calculating prime numbers below " & Request.N'Img & "... "); -- This operation could be executed in a separate thread, -- to process requests in parallel Calculate_And_Send_Primes (Replier => Replier, Request => Request.all, Request_Id => Request_Id); Put_Line ("DONE"); end if; end if; Retcode := Replier.Receive_Request (Request => Request.all, Info_Seq => Request_Info, Timeout => MAX_WAIT); end loop; if Retcode = DDS.RETCODE_TIMEOUT then Put_Line ("No request received for " & MAX_WAIT.Sec'Img & " seconds. Shutting down replier"); else Put_Line (Standard_Error, "Error in replier " & Retcode'Img); end if; Replier_Shutdown (Participant, Replier, Request); end; Domain_Id : DDS.DomainId_T := 0; begin if Ada.Command_Line.Argument_Count > 0 then Domain_Id := DDS.DomainId_T'Value (Ada.Command_Line.Argument (1)); end if; RTIDDS.Config.Logger.Get_Instance.Set_Verbosity (RTIDDS.Config.VERBOSITY_WARNING); -- Uncomment this to turn on additional logging -- RTIDDS.Config.Logger.Get_Instance.Set_Verbosity (RTIDDS.Config.VERBOSITY_ERROR); Put_Line ("PrimeNumberRequester: Sending a request to calculate the " & "(on domain " & Domain_Id'Img & ")"); Replier_Main (Domain_Id); end Primes.Replier_Main;
with ada.text_io, ada.integer_text_io; use ada.text_io, ada.integer_text_io; procedure multiplosdetres (n1,n2: in Integer; resultado: out Integer) is auxiliar: Integer; begin resultado:=0; auxiliar:=n1; while auxiliar rem 3 /= 0 loop auxiliar:=auxiliar+1; end loop; while n2 >= auxiliar loop put(auxiliar); resultado:=resultado+auxiliar; auxiliar:=auxiliar+3; end loop; new_line; end multiplosdetres;
package Trendy_Terminal.Example.Input is procedure Run_Print_Input; end Trendy_Terminal.Example.Input;
with Interfaces; use Interfaces; with Bounded_Image; use Bounded_Image; with HMC5883L; use HMC5883L; with HMC5883L.Driver; with Logger; with Interfaces; use Interfaces; package body Magnetometer with SPARK_Mode is --overriding procedure initialize (Self : in out Magnetometer_Tag) is begin Driver.initialize; Self.state := READY; end initialize; --overriding procedure read_Measurement(Self : in out Magnetometer_Tag) is mag_x, mag_y, mag_z : Integer_16; begin null; --Driver.update_val; Driver.getHeading(mag_x, mag_y, mag_z); -- raw values in micro tesla Logger.log_console(Logger.TRACE, "Mag: " & Integer_Img (Integer (mag_x)) & ", " & Integer_Img (Integer (mag_y)) & ", " & Integer_Img (Integer (mag_z))); Self.sample.data(X) := Unit_Type(mag_x) * Micro * Tesla; Self.sample.data(Y) := Unit_Type(mag_y) * Micro * Tesla; Self.sample.data(Z) := Unit_Type(mag_z) * Micro * Tesla; -- page 13/19: LSB/Gauss 230 .. 1370, 1090 default end read_Measurement; end Magnetometer;
package body simulation is procedure init is begin if not CSV_here.Open then Put_Line ("Simulation: Error opening file"); Simulation.Finished := True; return; else Put_Line ("Simulation: Replay from file"); have_data := True; CSV_here.Parse_Header; end if; end init; procedure update is begin if CSV_here.End_Of_File then Finished := True; Put_Line ("Simulation: EOF"); return; end if; if not CSV_here.Parse_Row then Simulation.Finished := True; Put_Line ("Simulation: Row error"); else CSV_here.Dump_Columns; declare t : float := CSV_here.Get_Column("time"); begin Put_Line ("t=" & t'Img); end; end if; end; procedure close is begin CSV_here.Close; end close; end simulation;
with Ada.Unchecked_Conversion; with Interfaces; use Interfaces; package foo with SPARK_Mode is type Byte is mod 2**8; type Byte_Array is array (Natural range <>) of Byte; type Byte_Array_4 is array (1..4) of Byte; subtype Data_Type is Byte_Array; -- essential function From_Byte_Array_To_Integer_32 is new Ada.Unchecked_Conversion (Source => Byte_Array_4, Target => Integer_32); function toInteger_32 (bytes : Byte_Array) return Integer_32 is (From_Byte_Array_To_Integer_32 (Byte_Array_4 (bytes))) with Pre => bytes'Length = 4; end foo;
with Ada.Containers; use Ada.Containers; with Ada.Containers.Hashed_Maps; with Tarmi.Symbols; use Tarmi.Symbols; -- TODO: Support multiple environment parents. package Tarmi.Environments is function Hash_Symbol (S : Symbol) return Hash_Type; package Hashed_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Symbol, Element_Type => Datum, Hash => Hash_Symbol, Equivalent_Keys => "="); type Environment_R is new Datum_R with record Bindings : Hashed_Maps.Map ; Parent : access all Environment_R ; end record; type Environment is not null access all Environment_R; type Bindings_Spec is array (Positive range <>) of Datum; function Make_Environment (Bindings : Bindings_Spec) return Environment; -- TODO: Remove after development. function Child_Environment (Env : Environment) return Environment; function Lookup (Name : Symbol; Env : Environment) return Datum; procedure Bind (Env : Environment; Name : Datum; Val : Datum); procedure Match_Bind (Env : Environment; Param_Tree : Datum; Obj : Datum); end Tarmi.Environments;
with Ada.Unchecked_Conversion; with System.Startup; with System.Unwind.Occurrences; with System.Unwind.Raising; package body System.Finally is pragma Suppress (All_Checks); use type Ada.Exceptions.Exception_Occurrence_Access; use type Startup.Finalize_Library_Objects_Handler; use type Unwind.Exception_Data_Access; procedure Finalize_Library_Objects; pragma Linker_Destructor (Finalize_Library_Objects); -- after atexit procedure Finalize_Library_Objects is begin if Startup.Finalize_Library_Objects /= null then Startup.Finalize_Library_Objects.all; end if; end Finalize_Library_Objects; type Uninitialized_Exception_Occurrence is record X : Unwind.Exception_Occurrence; end record; pragma Suppress_Initialization (Uninitialized_Exception_Occurrence); Library_Exception : Uninitialized_Exception_Occurrence; Library_Exception_Set : Boolean := False; -- implementation procedure Save_Library_Occurrence ( X : Ada.Exceptions.Exception_Occurrence_Access) is function Cast is new Ada.Unchecked_Conversion ( Ada.Exceptions.Exception_Occurrence_Access, Unwind.Exception_Occurrence_Access); begin if not Library_Exception_Set then Library_Exception_Set := True; if X /= null then Unwind.Occurrences.Save_Occurrence ( Library_Exception.X, Cast (X).all); end if; end if; end Save_Library_Occurrence; procedure Reraise_Library_Exception_If_Any is begin if Library_Exception_Set then declare X : Unwind.Exception_Occurrence renames Library_Exception.X; begin if X.Id = null then Unwind.Raising.Finalize_Raised_Exception; else Unwind.Raising.Reraise_From_Controlled_Operation (X); end if; end; end if; end Reraise_Library_Exception_If_Any; end System.Finally;
with Ada.Text_IO; use Ada.Text_IO; procedure aaa is begin loop Put ('a'); end loop; end aaa;
with GL.Objects.Programs; with E3GA; with Multivectors; use Multivectors; package Draw_1_1 is function Draw_Circle (Render_Program : GL.Objects.Programs.Program; C1, C2, C3 : Normalized_Point) return Circle; function Draw_Line (Render_Program : GL.Objects.Programs.Program; P1, P2 : Normalized_Point) return Line; procedure Draw_Plane (Render_Program : GL.Objects.Programs.Program; DP : Dual_Plane); procedure Draw_Reflected_Circle (Render_Program : GL.Objects.Programs.Program; C : Circle; DP : Dual_Plane); procedure Draw_Reflected_Line (Render_Program : GL.Objects.Programs.Program; L : Line; DP : Dual_Plane); function Draw_Rotated_Circle (Render_Program : GL.Objects.Programs.Program; C : Circle; RV : TR_Versor) return Circle; function New_Dual_Plane (P1 : Normalized_Point; Normal : E3GA.E3_Vector) return Dual_Plane; function New_TR_Versor (L1 : Line) return TR_Versor; end Draw_1_1;
pragma Ada_2005; pragma Style_Checks (Off); pragma Warnings (Off); with Interfaces.C; use Interfaces.C; with glib; package GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_photography_enumtypes_h is -- unsupported macro: GST_TYPE_PHOTOGRAPHY_NOISE_REDUCTION (gst_photography_noise_reduction_get_type()) -- unsupported macro: GST_TYPE_WHITE_BALANCE_MODE (gst_white_balance_mode_get_type()) -- unsupported macro: GST_TYPE_COLOUR_TONE_MODE (gst_colour_tone_mode_get_type()) -- unsupported macro: GST_TYPE_SCENE_MODE (gst_scene_mode_get_type()) -- unsupported macro: GST_TYPE_FLASH_MODE (gst_flash_mode_get_type()) -- unsupported macro: GST_TYPE_FOCUS_STATUS (gst_focus_status_get_type()) -- unsupported macro: GST_TYPE_PHOTO_CAPS (gst_photo_caps_get_type()) -- unsupported macro: GST_TYPE_PHOTO_SHAKE_RISK (gst_photo_shake_risk_get_type()) -- unsupported macro: GST_TYPE_FLICKER_REDUCTION_MODE (gst_flicker_reduction_mode_get_type()) -- unsupported macro: GST_TYPE_FOCUS_MODE (gst_focus_mode_get_type()) -- enumerations from "photography.h" function gst_photography_noise_reduction_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:12 pragma Import (C, gst_photography_noise_reduction_get_type, "gst_photography_noise_reduction_get_type"); function gst_white_balance_mode_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:14 pragma Import (C, gst_white_balance_mode_get_type, "gst_white_balance_mode_get_type"); function gst_colour_tone_mode_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:16 pragma Import (C, gst_colour_tone_mode_get_type, "gst_colour_tone_mode_get_type"); function gst_scene_mode_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:18 pragma Import (C, gst_scene_mode_get_type, "gst_scene_mode_get_type"); function gst_flash_mode_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:20 pragma Import (C, gst_flash_mode_get_type, "gst_flash_mode_get_type"); function gst_focus_status_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:22 pragma Import (C, gst_focus_status_get_type, "gst_focus_status_get_type"); function gst_photo_caps_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:24 pragma Import (C, gst_photo_caps_get_type, "gst_photo_caps_get_type"); function gst_photo_shake_risk_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:26 pragma Import (C, gst_photo_shake_risk_get_type, "gst_photo_shake_risk_get_type"); function gst_flicker_reduction_mode_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:28 pragma Import (C, gst_flicker_reduction_mode_get_type, "gst_flicker_reduction_mode_get_type"); function gst_focus_mode_get_type return GLIB.GType; -- gst/interfaces/photography-enumtypes.h:30 pragma Import (C, gst_focus_mode_get_type, "gst_focus_mode_get_type"); end GStreamer.GST_Low_Level.gstreamer_0_10_gst_interfaces_photography_enumtypes_h;
with RASCAL.OS; use RASCAL.OS; package Controller_Dummy is type TEL_Dummy is new Toolbox_UserEventListener(16#59#,-1,-1) with null record; -- -- This does nothing. -- procedure Handle (The : in TEL_Dummy); end Controller_Dummy;
-- Generated at 2016-07-04 19:19:16 +0000 by Natools.Static_Hash_Maps -- from src/natools-web-comments-maps.sx function Natools.Static_Maps.Web.Comments.T return Boolean; pragma Pure (Natools.Static_Maps.Web.Comments.T);
-- This spec has been automatically generated from STM32F105xx.svd pragma Restrictions (No_Elaboration_Code); pragma Ada_2012; with System; package STM32.USART is pragma Preelaborate; --------------- -- Registers -- --------------- ----------------- -- SR_Register -- ----------------- subtype SR_PE_Field is STM32.Bit; subtype SR_FE_Field is STM32.Bit; subtype SR_NE_Field is STM32.Bit; subtype SR_ORE_Field is STM32.Bit; subtype SR_IDLE_Field is STM32.Bit; subtype SR_RXNE_Field is STM32.Bit; subtype SR_TC_Field is STM32.Bit; subtype SR_TXE_Field is STM32.Bit; subtype SR_LBD_Field is STM32.Bit; subtype SR_CTS_Field is STM32.Bit; -- Status register type SR_Register is record -- Read-only. Parity error PE : SR_PE_Field := 16#0#; -- Read-only. Framing error FE : SR_FE_Field := 16#0#; -- Read-only. Noise error flag NE : SR_NE_Field := 16#0#; -- Read-only. Overrun error ORE : SR_ORE_Field := 16#0#; -- Read-only. IDLE line detected IDLE : SR_IDLE_Field := 16#0#; -- Read data register not empty RXNE : SR_RXNE_Field := 16#0#; -- Transmission complete TC : SR_TC_Field := 16#1#; -- Read-only. Transmit data register empty TXE : SR_TXE_Field := 16#1#; -- LIN break detection flag LBD : SR_LBD_Field := 16#0#; -- CTS flag CTS : SR_CTS_Field := 16#0#; -- unspecified Reserved_10_31 : STM32.UInt22 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register use record PE at 0 range 0 .. 0; FE at 0 range 1 .. 1; NE at 0 range 2 .. 2; ORE at 0 range 3 .. 3; IDLE at 0 range 4 .. 4; RXNE at 0 range 5 .. 5; TC at 0 range 6 .. 6; TXE at 0 range 7 .. 7; LBD at 0 range 8 .. 8; CTS at 0 range 9 .. 9; Reserved_10_31 at 0 range 10 .. 31; end record; ----------------- -- DR_Register -- ----------------- subtype DR_DR_Field is STM32.UInt9; -- Data register type DR_Register is record -- Data value DR : DR_DR_Field := 16#0#; -- unspecified Reserved_9_31 : STM32.UInt23 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for DR_Register use record DR at 0 range 0 .. 8; Reserved_9_31 at 0 range 9 .. 31; end record; ------------------ -- BRR_Register -- ------------------ subtype BRR_DIV_Fraction_Field is STM32.UInt4; subtype BRR_DIV_Mantissa_Field is STM32.UInt12; -- Baud rate register type BRR_Register is record -- fraction of USARTDIV DIV_Fraction : BRR_DIV_Fraction_Field := 16#0#; -- mantissa of USARTDIV DIV_Mantissa : BRR_DIV_Mantissa_Field := 16#0#; -- unspecified Reserved_16_31 : STM32.Short := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for BRR_Register use record DIV_Fraction at 0 range 0 .. 3; DIV_Mantissa at 0 range 4 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; ------------------ -- CR1_Register -- ------------------ subtype CR1_SBK_Field is STM32.Bit; subtype CR1_RWU_Field is STM32.Bit; subtype CR1_RE_Field is STM32.Bit; subtype CR1_TE_Field is STM32.Bit; subtype CR1_IDLEIE_Field is STM32.Bit; subtype CR1_RXNEIE_Field is STM32.Bit; subtype CR1_TCIE_Field is STM32.Bit; subtype CR1_TXEIE_Field is STM32.Bit; subtype CR1_PEIE_Field is STM32.Bit; subtype CR1_PS_Field is STM32.Bit; subtype CR1_PCE_Field is STM32.Bit; subtype CR1_WAKE_Field is STM32.Bit; subtype CR1_M_Field is STM32.Bit; subtype CR1_UE_Field is STM32.Bit; -- Control register 1 type CR1_Register is record -- Send break SBK : CR1_SBK_Field := 16#0#; -- Receiver wakeup RWU : CR1_RWU_Field := 16#0#; -- Receiver enable RE : CR1_RE_Field := 16#0#; -- Transmitter enable TE : CR1_TE_Field := 16#0#; -- IDLE interrupt enable IDLEIE : CR1_IDLEIE_Field := 16#0#; -- RXNE interrupt enable RXNEIE : CR1_RXNEIE_Field := 16#0#; -- Transmission complete interrupt enable TCIE : CR1_TCIE_Field := 16#0#; -- TXE interrupt enable TXEIE : CR1_TXEIE_Field := 16#0#; -- PE interrupt enable PEIE : CR1_PEIE_Field := 16#0#; -- Parity selection PS : CR1_PS_Field := 16#0#; -- Parity control enable PCE : CR1_PCE_Field := 16#0#; -- Wakeup method WAKE : CR1_WAKE_Field := 16#0#; -- Word length M : CR1_M_Field := 16#0#; -- USART enable UE : CR1_UE_Field := 16#0#; -- unspecified Reserved_14_31 : STM32.UInt18 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR1_Register use record SBK at 0 range 0 .. 0; RWU at 0 range 1 .. 1; RE at 0 range 2 .. 2; TE at 0 range 3 .. 3; IDLEIE at 0 range 4 .. 4; RXNEIE at 0 range 5 .. 5; TCIE at 0 range 6 .. 6; TXEIE at 0 range 7 .. 7; PEIE at 0 range 8 .. 8; PS at 0 range 9 .. 9; PCE at 0 range 10 .. 10; WAKE at 0 range 11 .. 11; M at 0 range 12 .. 12; UE at 0 range 13 .. 13; Reserved_14_31 at 0 range 14 .. 31; end record; ------------------ -- CR2_Register -- ------------------ subtype CR2_ADD_Field is STM32.UInt4; subtype CR2_LBDL_Field is STM32.Bit; subtype CR2_LBDIE_Field is STM32.Bit; subtype CR2_LBCL_Field is STM32.Bit; subtype CR2_CPHA_Field is STM32.Bit; subtype CR2_CPOL_Field is STM32.Bit; subtype CR2_CLKEN_Field is STM32.Bit; subtype CR2_STOP_Field is STM32.UInt2; subtype CR2_LINEN_Field is STM32.Bit; -- Control register 2 type CR2_Register is record -- Address of the USART node ADD : CR2_ADD_Field := 16#0#; -- unspecified Reserved_4_4 : STM32.Bit := 16#0#; -- lin break detection length LBDL : CR2_LBDL_Field := 16#0#; -- LIN break detection interrupt enable LBDIE : CR2_LBDIE_Field := 16#0#; -- unspecified Reserved_7_7 : STM32.Bit := 16#0#; -- Last bit clock pulse LBCL : CR2_LBCL_Field := 16#0#; -- Clock phase CPHA : CR2_CPHA_Field := 16#0#; -- Clock polarity CPOL : CR2_CPOL_Field := 16#0#; -- Clock enable CLKEN : CR2_CLKEN_Field := 16#0#; -- STOP bits STOP : CR2_STOP_Field := 16#0#; -- LIN mode enable LINEN : CR2_LINEN_Field := 16#0#; -- unspecified Reserved_15_31 : STM32.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR2_Register use record ADD at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; LBDL at 0 range 5 .. 5; LBDIE at 0 range 6 .. 6; Reserved_7_7 at 0 range 7 .. 7; LBCL at 0 range 8 .. 8; CPHA at 0 range 9 .. 9; CPOL at 0 range 10 .. 10; CLKEN at 0 range 11 .. 11; STOP at 0 range 12 .. 13; LINEN at 0 range 14 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; ------------------ -- CR3_Register -- ------------------ subtype CR3_EIE_Field is STM32.Bit; subtype CR3_IREN_Field is STM32.Bit; subtype CR3_IRLP_Field is STM32.Bit; subtype CR3_HDSEL_Field is STM32.Bit; subtype CR3_NACK_Field is STM32.Bit; subtype CR3_SCEN_Field is STM32.Bit; subtype CR3_DMAR_Field is STM32.Bit; subtype CR3_DMAT_Field is STM32.Bit; subtype CR3_RTSE_Field is STM32.Bit; subtype CR3_CTSE_Field is STM32.Bit; subtype CR3_CTSIE_Field is STM32.Bit; -- Control register 3 type CR3_Register is record -- Error interrupt enable EIE : CR3_EIE_Field := 16#0#; -- IrDA mode enable IREN : CR3_IREN_Field := 16#0#; -- IrDA low-power IRLP : CR3_IRLP_Field := 16#0#; -- Half-duplex selection HDSEL : CR3_HDSEL_Field := 16#0#; -- Smartcard NACK enable NACK : CR3_NACK_Field := 16#0#; -- Smartcard mode enable SCEN : CR3_SCEN_Field := 16#0#; -- DMA enable receiver DMAR : CR3_DMAR_Field := 16#0#; -- DMA enable transmitter DMAT : CR3_DMAT_Field := 16#0#; -- RTS enable RTSE : CR3_RTSE_Field := 16#0#; -- CTS enable CTSE : CR3_CTSE_Field := 16#0#; -- CTS interrupt enable CTSIE : CR3_CTSIE_Field := 16#0#; -- unspecified Reserved_11_31 : STM32.UInt21 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR3_Register use record EIE at 0 range 0 .. 0; IREN at 0 range 1 .. 1; IRLP at 0 range 2 .. 2; HDSEL at 0 range 3 .. 3; NACK at 0 range 4 .. 4; SCEN at 0 range 5 .. 5; DMAR at 0 range 6 .. 6; DMAT at 0 range 7 .. 7; RTSE at 0 range 8 .. 8; CTSE at 0 range 9 .. 9; CTSIE at 0 range 10 .. 10; Reserved_11_31 at 0 range 11 .. 31; end record; ------------------- -- GTPR_Register -- ------------------- subtype GTPR_PSC_Field is STM32.Byte; subtype GTPR_GT_Field is STM32.Byte; -- Guard time and prescaler register type GTPR_Register is record -- Prescaler value PSC : GTPR_PSC_Field := 16#0#; -- Guard time value GT : GTPR_GT_Field := 16#0#; -- unspecified Reserved_16_31 : STM32.Short := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for GTPR_Register use record PSC at 0 range 0 .. 7; GT at 0 range 8 .. 15; Reserved_16_31 at 0 range 16 .. 31; end record; ----------------- -- SR_Register -- ----------------- -- UART4 SR type SR_Register_1 is record -- Read-only. Parity error PE : SR_PE_Field := 16#0#; -- Read-only. Framing error FE : SR_FE_Field := 16#0#; -- Read-only. Noise error flag NE : SR_NE_Field := 16#0#; -- Read-only. Overrun error ORE : SR_ORE_Field := 16#0#; -- Read-only. IDLE line detected IDLE : SR_IDLE_Field := 16#0#; -- Read data register not empty RXNE : SR_RXNE_Field := 16#0#; -- Transmission complete TC : SR_TC_Field := 16#0#; -- Read-only. Transmit data register empty TXE : SR_TXE_Field := 16#0#; -- LIN break detection flag LBD : SR_LBD_Field := 16#0#; -- unspecified Reserved_9_31 : STM32.UInt23 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for SR_Register_1 use record PE at 0 range 0 .. 0; FE at 0 range 1 .. 1; NE at 0 range 2 .. 2; ORE at 0 range 3 .. 3; IDLE at 0 range 4 .. 4; RXNE at 0 range 5 .. 5; TC at 0 range 6 .. 6; TXE at 0 range 7 .. 7; LBD at 0 range 8 .. 8; Reserved_9_31 at 0 range 9 .. 31; end record; ------------------ -- BRR_Register -- ------------------ ------------------ -- CR1_Register -- ------------------ ------------------ -- CR2_Register -- ------------------ -- UART4 CR2 type CR2_Register_1 is record -- Address of the USART node ADD : CR2_ADD_Field := 16#0#; -- unspecified Reserved_4_4 : STM32.Bit := 16#0#; -- lin break detection length LBDL : CR2_LBDL_Field := 16#0#; -- LIN break detection interrupt enable LBDIE : CR2_LBDIE_Field := 16#0#; -- unspecified Reserved_7_11 : STM32.UInt5 := 16#0#; -- STOP bits STOP : CR2_STOP_Field := 16#0#; -- LIN mode enable LINEN : CR2_LINEN_Field := 16#0#; -- unspecified Reserved_15_31 : STM32.UInt17 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR2_Register_1 use record ADD at 0 range 0 .. 3; Reserved_4_4 at 0 range 4 .. 4; LBDL at 0 range 5 .. 5; LBDIE at 0 range 6 .. 6; Reserved_7_11 at 0 range 7 .. 11; STOP at 0 range 12 .. 13; LINEN at 0 range 14 .. 14; Reserved_15_31 at 0 range 15 .. 31; end record; ------------------ -- CR3_Register -- ------------------ -- UART4 CR3 type CR3_Register_1 is record -- Error interrupt enable EIE : CR3_EIE_Field := 16#0#; -- IrDA mode enable IREN : CR3_IREN_Field := 16#0#; -- IrDA low-power IRLP : CR3_IRLP_Field := 16#0#; -- Half-duplex selection HDSEL : CR3_HDSEL_Field := 16#0#; -- unspecified Reserved_4_5 : STM32.UInt2 := 16#0#; -- DMA enable receiver DMAR : CR3_DMAR_Field := 16#0#; -- DMA enable transmitter DMAT : CR3_DMAT_Field := 16#0#; -- unspecified Reserved_8_31 : STM32.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR3_Register_1 use record EIE at 0 range 0 .. 0; IREN at 0 range 1 .. 1; IRLP at 0 range 2 .. 2; HDSEL at 0 range 3 .. 3; Reserved_4_5 at 0 range 4 .. 5; DMAR at 0 range 6 .. 6; DMAT at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; ------------------ -- CR3_Register -- ------------------ -- UART5 CR3 type CR3_Register_2 is record -- Error interrupt enable EIE : CR3_EIE_Field := 16#0#; -- IrDA mode enable IREN : CR3_IREN_Field := 16#0#; -- IrDA low-power IRLP : CR3_IRLP_Field := 16#0#; -- Half-duplex selection HDSEL : CR3_HDSEL_Field := 16#0#; -- unspecified Reserved_4_6 : STM32.UInt3 := 16#0#; -- DMA enable transmitter DMAT : CR3_DMAT_Field := 16#0#; -- unspecified Reserved_8_31 : STM32.UInt24 := 16#0#; end record with Volatile_Full_Access, Size => 32, Bit_Order => System.Low_Order_First; for CR3_Register_2 use record EIE at 0 range 0 .. 0; IREN at 0 range 1 .. 1; IRLP at 0 range 2 .. 2; HDSEL at 0 range 3 .. 3; Reserved_4_6 at 0 range 4 .. 6; DMAT at 0 range 7 .. 7; Reserved_8_31 at 0 range 8 .. 31; end record; ----------------- -- Peripherals -- ----------------- -- Universal synchronous asynchronous receiver transmitter type USART2_Peripheral is record -- Status register SR : SR_Register; -- Data register DR : DR_Register; -- Baud rate register BRR : BRR_Register; -- Control register 1 CR1 : CR1_Register; -- Control register 2 CR2 : CR2_Register; -- Control register 3 CR3 : CR3_Register; -- Guard time and prescaler register GTPR : GTPR_Register; end record with Volatile; for USART2_Peripheral use record SR at 0 range 0 .. 31; DR at 4 range 0 .. 31; BRR at 8 range 0 .. 31; CR1 at 12 range 0 .. 31; CR2 at 16 range 0 .. 31; CR3 at 20 range 0 .. 31; GTPR at 24 range 0 .. 31; end record; -- Universal synchronous asynchronous receiver transmitter USART2_Periph : aliased USART2_Peripheral with Import, Address => USART2_Base; -- Universal synchronous asynchronous receiver transmitter USART3_Periph : aliased USART2_Peripheral with Import, Address => USART3_Base; -- Universal synchronous asynchronous receiver transmitter USART1_Periph : aliased USART2_Peripheral with Import, Address => USART1_Base; -- Universal asynchronous receiver transmitter type UART4_Peripheral is record -- UART4 SR SR : SR_Register_1; -- UART4 DR DR : DR_Register; -- UART4 BRR BRR : BRR_Register; -- UART4 CR1 CR1 : CR1_Register; -- UART4 CR2 CR2 : CR2_Register_1; -- UART4 CR3 CR3 : CR3_Register_1; end record with Volatile; for UART4_Peripheral use record SR at 0 range 0 .. 31; DR at 4 range 0 .. 31; BRR at 8 range 0 .. 31; CR1 at 12 range 0 .. 31; CR2 at 16 range 0 .. 31; CR3 at 20 range 0 .. 31; end record; -- Universal asynchronous receiver transmitter UART4_Periph : aliased UART4_Peripheral with Import, Address => UART4_Base; -- Universal asynchronous receiver transmitter type UART5_Peripheral is record -- UART5 SR SR : SR_Register_1; -- UART5 DR DR : DR_Register; -- UART5 BRR BRR : BRR_Register; -- UART5 CR1 CR1 : CR1_Register; -- UART5 CR2 CR2 : CR2_Register_1; -- UART5 CR3 CR3 : CR3_Register_2; end record with Volatile; for UART5_Peripheral use record SR at 0 range 0 .. 31; DR at 4 range 0 .. 31; BRR at 8 range 0 .. 31; CR1 at 12 range 0 .. 31; CR2 at 16 range 0 .. 31; CR3 at 20 range 0 .. 31; end record; -- Universal asynchronous receiver transmitter UART5_Periph : aliased UART5_Peripheral with Import, Address => UART5_Base; end STM32.USART;
with Offmt_Lib.Fmt_Data.Unsigned_8; with Offmt_Lib.Fmt_Data.Unsigned_16; with Offmt_Lib.Fmt_Data.Unsigned_32; package body Offmt_Lib.Fmt_Data is ------------ -- Create -- ------------ function Create (Typ : Format_Type) return Instance'Class is begin case Typ is when Type_U8 => declare Ret : Fmt_Data.Unsigned_8.Instance; begin return Ret; end; when Type_U16 => declare Ret : Fmt_Data.Unsigned_16.Instance; begin return Ret; end; when Type_U32 => declare Ret : Fmt_Data.Unsigned_32.Instance; begin return Ret; end; end case; end Create; end Offmt_Lib.Fmt_Data;
----------------------------------------------------------------------- -- security-policies -- Security Policies -- Copyright (C) 2010, 2011, 2012, 2013 Stephane Carrez -- Written by Stephane Carrez (Stephane.Carrez@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Unchecked_Deallocation; with Util.Log.Loggers; with Util.Serialize.Mappers; with Util.Serialize.Mappers.Record_Mapper; with Security.Controllers; with Security.Contexts; package body Security.Policies is use type Permissions.Permission_Index; -- The logger Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Security.Policies"); procedure Free is new Ada.Unchecked_Deallocation (Security.Controllers.Controller'Class, Security.Controllers.Controller_Access); -- ------------------------------ -- Default Security Controllers -- ------------------------------ -- The <b>Auth_Controller</b> grants the permission if there is a principal. type Auth_Controller is limited new Security.Controllers.Controller with null record; -- Returns true if the user associated with the security context <b>Context</b> was -- authentified (ie, it has a principal). overriding function Has_Permission (Handler : in Auth_Controller; Context : in Security.Contexts.Security_Context'Class; Permission : in Security.Permissions.Permission'Class) return Boolean; -- The <b>Pass_Through_Controller</b> grants access to anybody. type Pass_Through_Controller is limited new Security.Controllers.Controller with null record; -- Returns true if the user associated with the security context <b>Context</b> has -- the permission to access the URL defined in <b>Permission</b>. overriding function Has_Permission (Handler : in Pass_Through_Controller; Context : in Security.Contexts.Security_Context'Class; Permission : in Security.Permissions.Permission'Class) return Boolean; -- ------------------------------ -- Returns true if the user associated with the security context <b>Context</b> was -- authentified (ie, it has a principal). -- ------------------------------ overriding function Has_Permission (Handler : in Auth_Controller; Context : in Security.Contexts.Security_Context'Class; Permission : in Security.Permissions.Permission'Class) return Boolean is pragma Unreferenced (Handler, Permission); use type Security.Principal_Access; P : constant Security.Principal_Access := Context.Get_User_Principal; begin if P /= null then Log.Debug ("Grant permission because a principal exists"); return True; else return False; end if; end Has_Permission; -- ------------------------------ -- Returns true if the user associated with the security context <b>Context</b> has -- the permission to access the URL defined in <b>Permission</b>. -- ------------------------------ overriding function Has_Permission (Handler : in Pass_Through_Controller; Context : in Security.Contexts.Security_Context'Class; Permission : in Security.Permissions.Permission'Class) return Boolean is pragma Unreferenced (Handler, Context, Permission); begin Log.Debug ("Pass through controller grants the permission"); return True; end Has_Permission; -- ------------------------------ -- Get the policy index. -- ------------------------------ function Get_Policy_Index (From : in Policy'Class) return Policy_Index is begin return From.Index; end Get_Policy_Index; -- ------------------------------ -- Add a permission under the given permission name and associated with the controller. -- To verify the permission, the controller will be called. -- ------------------------------ procedure Add_Permission (Manager : in out Policy; Name : in String; Permission : in Controller_Access) is begin Manager.Manager.Add_Permission (Name, Permission); end Add_Permission; -- ------------------------------ -- Get the policy with the name <b>Name</b> registered in the policy manager. -- Returns null if there is no such policy. -- ------------------------------ function Get_Policy (Manager : in Policy_Manager; Name : in String) return Policy_Access is begin for I in Manager.Policies'Range loop if Manager.Policies (I) = null then return null; elsif Manager.Policies (I).Get_Name = Name then return Manager.Policies (I); end if; end loop; return null; end Get_Policy; -- ------------------------------ -- Add the policy to the policy manager. After a policy is added in the manager, -- it can participate in the security policy. -- Raises Policy_Error if the policy table is full. -- ------------------------------ procedure Add_Policy (Manager : in out Policy_Manager; Policy : in Policy_Access) is Name : constant String := Policy.Get_Name; begin Log.Info ("Adding policy {0}", Name); for I in Manager.Policies'Range loop if Manager.Policies (I) = null then Manager.Policies (I) := Policy; Policy.Manager := Manager'Unchecked_Access; Policy.Index := I; return; end if; end loop; Log.Error ("Policy table is full, increase policy manager table to {0} to add policy {1}", Policy_Index'Image (Manager.Max_Policies + 1), Name); raise Policy_Error; end Add_Policy; -- ------------------------------ -- Add a permission under the given permission name and associated with the controller. -- To verify the permission, the controller will be called. -- ------------------------------ procedure Add_Permission (Manager : in out Policy_Manager; Name : in String; Permission : in Controller_Access) is Index : Permission_Index; begin Log.Info ("Adding permission {0}", Name); Permissions.Add_Permission (Name, Index); if Index >= Manager.Last_Index then declare Count : constant Permission_Index := Index + 32; Perms : constant Controller_Access_Array_Access := new Controller_Access_Array (0 .. Count); begin if Manager.Permissions /= null then Perms (Manager.Permissions'Range) := Manager.Permissions.all; end if; Manager.Permissions := Perms; Manager.Last_Index := Count; end; end if; -- If the permission has a controller, release it. if Manager.Permissions (Index) /= null then Log.Warn ("Permission {0} is redefined", Name); -- SCz 2011-12-03: GNAT 2011 reports a compilation error: -- 'missing "with" clause on package "Security.Controllers"' -- if we use the 'Security.Controller_Access' type, even if this "with" -- clause exist. -- gcc 4.4.3 under Ubuntu does not have this issue. -- We use the 'Security.Controllers.Controller_Access' type to avoid the compiler -- bug but we have to use a temporary variable and do some type conversion... declare P : Security.Controllers.Controller_Access := Manager.Permissions (Index).all'Access; begin Free (P); end; end if; Manager.Permissions (Index) := Permission; end Add_Permission; -- ------------------------------ -- Checks whether the permission defined by the <b>Permission</b> is granted -- for the security context passed in <b>Context</b>. -- Returns true if such permission is granted. -- ------------------------------ function Has_Permission (Manager : in Policy_Manager; Context : in Security.Contexts.Security_Context'Class; Permission : in Security.Permissions.Permission'Class) return Boolean is begin if Permission.Id >= Manager.Last_Index then return False; end if; declare C : constant Controller_Access := Manager.Permissions (Permission.Id); begin if C = null then return False; else return C.Has_Permission (Context, Permission); end if; end; end Has_Permission; -- ------------------------------ -- Returns True if the security controller is defined for the given permission index. -- ------------------------------ function Has_Controller (Manager : in Policy_Manager; Index : in Permissions.Permission_Index) return Boolean is begin return Index < Manager.Last_Index and then Manager.Permissions (Index) /= null; end Has_Controller; -- ------------------------------ -- Create the policy contexts to be associated with the security context. -- ------------------------------ function Create_Policy_Contexts (Manager : in Policy_Manager) return Policy_Context_Array_Access is begin return new Policy_Context_Array (1 .. Manager.Max_Policies); end Create_Policy_Contexts; -- ---- type Policy_Fields is (FIELD_GRANT_PERMISSION, FIELD_AUTH_PERMISSION); procedure Set_Member (P : in out Policy_Manager'Class; Field : in Policy_Fields; Value : in Util.Beans.Objects.Object); procedure Set_Member (P : in out Policy_Manager'Class; Field : in Policy_Fields; Value : in Util.Beans.Objects.Object) is Name : constant String := Util.Beans.Objects.To_String (Value); begin case Field is when FIELD_GRANT_PERMISSION => P.Add_Permission (Name, new Pass_Through_Controller); when FIELD_AUTH_PERMISSION => P.Add_Permission (Name, new Auth_Controller); end case; end Set_Member; package Policy_Mapper is new Util.Serialize.Mappers.Record_Mapper (Element_Type => Policy_Manager'Class, Element_Type_Access => Policy_Manager_Access, Fields => Policy_Fields, Set_Member => Set_Member); Policy_Mapping : aliased Policy_Mapper.Mapper; -------------------------- -- Prepare the XML parser to read the policy configuration. -- ------------------------------ procedure Prepare_Config (Manager : in out Policy_Manager; Reader : in out Util.Serialize.IO.XML.Parser) is begin Reader.Add_Mapping ("policy-rules", Policy_Mapping'Access); Reader.Add_Mapping ("module", Policy_Mapping'Access); Policy_Mapper.Set_Context (Reader, Manager'Unchecked_Access); -- Prepare the reader to parse the policy configuration. for I in Manager.Policies'Range loop exit when Manager.Policies (I) = null; Manager.Policies (I).Prepare_Config (Reader); end loop; end Prepare_Config; -- ------------------------------ -- Finish reading the XML policy configuration. The security policy implementation can use -- this procedure to perform any configuration setup after the configuration is parsed. -- ------------------------------ procedure Finish_Config (Manager : in out Policy_Manager; Reader : in out Util.Serialize.IO.XML.Parser) is begin -- Finish the policy configuration. for I in Manager.Policies'Range loop exit when Manager.Policies (I) = null; Manager.Policies (I).Finish_Config (Reader); end loop; end Finish_Config; -------------------------- -- Read the policy file -------------------------- procedure Read_Policy (Manager : in out Policy_Manager; File : in String) is use Util; Reader : Util.Serialize.IO.XML.Parser; package Policy_Config is new Reader_Config (Reader, Manager'Unchecked_Access); pragma Warnings (Off, Policy_Config); begin Log.Info ("Reading policy file {0}", File); Manager.Prepare_Config (Reader); -- Read the configuration file. Reader.Parse (File); Manager.Finish_Config (Reader); end Read_Policy; -- ------------------------------ -- Initialize the policy manager. -- ------------------------------ overriding procedure Initialize (Manager : in out Policy_Manager) is begin null; end Initialize; -- ------------------------------ -- Finalize the policy manager. -- ------------------------------ overriding procedure Finalize (Manager : in out Policy_Manager) is procedure Free is new Ada.Unchecked_Deallocation (Controller_Access_Array, Controller_Access_Array_Access); procedure Free is new Ada.Unchecked_Deallocation (Policy'Class, Policy_Access); begin -- Release the security controllers. if Manager.Permissions /= null then for I in Manager.Permissions.all'Range loop if Manager.Permissions (I) /= null then -- SCz 2011-12-03: GNAT 2011 reports a compilation error: -- 'missing "with" clause on package "Security.Controllers"' -- if we use the 'Security.Controller_Access' type, even if this "with" -- clause exist. -- gcc 4.4.3 under Ubuntu does not have this issue. -- We use the 'Security.Controllers.Controller_Access' type to avoid the compiler -- bug but we have to use a temporary variable and do some type conversion... declare P : Security.Controllers.Controller_Access := Manager.Permissions (I).all'Access; begin Free (P); Manager.Permissions (I) := null; end; end if; end loop; Free (Manager.Permissions); end if; -- Release the policy instances. for I in Manager.Policies'Range loop exit when Manager.Policies (I) = null; Free (Manager.Policies (I)); end loop; end Finalize; begin Policy_Mapping.Add_Mapping ("grant-permission/name", FIELD_GRANT_PERMISSION); Policy_Mapping.Add_Mapping ("auth-permission/name", FIELD_AUTH_PERMISSION); end Security.Policies;
package NewLineExamples is function Text_New_Lines (Text : String) return String; function Twice_Text_New_Line (Text : String) return String; function Text_Duplicate (Text : String) return String; function Text_Dupl (Text : String) return String; function Text_Twice (Text : String) return String; function Text_Thrice (Text : String) return String; function Twice_Text (Text : String) return String; end NewLineExamples;
package lace.Text.utility -- -- Provides utility subprograms. -- is function replace (Self : in Text.item; Pattern : in String; By : in String) return Text.item; -- -- If the replacement exceeds the capacity of 'Self', the result will be expanded. procedure replace (Self : in out Text.item; Pattern : in String; By : in String); -- -- 'Text.Error' will be raised if the replacement exceeds the capacity of 'Self'. end lace.Text.utility;
with AdaBase; with Connect; with Ada.Text_IO; with CommonText; with AdaBase.Results.Sets; with AdaBase.Logger.Facility; procedure Prep_Stmt is package CON renames Connect; package TIO renames Ada.Text_IO; package CT renames CommonText; package AR renames AdaBase.Results; package ARS renames AdaBase.Results.Sets; package ALF renames AdaBase.Logger.Facility; begin CON.DR.command_standard_logger (device => ALF.screen, action => ALF.attach); CON.connect_database; declare max_calories : aliased AR.Byte2 := 200; min_calories : constant AR.Byte2 := 5; row : ARS.Datarow; stmt : CON.Stmt_Type := CON.DR.prepare_select (tables => "fruits", columns => "*", conditions => "color = ? and calories > :mincal and calories < ?"); begin stmt.assign (1, "red"); stmt.assign ("mincal", min_calories); stmt.assign (3, max_calories'Unchecked_Access); if stmt.execute then TIO.Put_Line ("execute succeeded"); for c in Natural range 1 .. stmt.column_count loop TIO.Put_Line ("Column" & c'Img & " heading: " & stmt.column_name (c)); end loop; TIO.Put_Line ("returned rows: " & stmt.rows_returned'Img); loop row := stmt.fetch_next; exit when row.data_exhausted; TIO.Put_Line (row.column (2).as_string & " (" & row.column ("color").as_string & ") " & row.column ("calories").as_string & " calories"); end loop; else TIO.Put_Line ("execute failed"); end if; end; declare sql : String := "INSERT INTO fruits (fruit, color, calories) " & "VALUES ('potato','tan', 77)"; stmt : CON.Stmt_Type := CON.DR.prepare (sql); begin if stmt.execute then TIO.Put_Line ("Inserted row " & stmt.last_insert_id'Img); TIO.Put_Line ("Affected rows: " & stmt.rows_affected'Img); end if; CON.DR.rollback; end; CON.DR.disconnect; end Prep_Stmt;
with Interfaces.C.Strings, System; use type Interfaces.C.Strings.chars_ptr, System.Address; package body FLTK.Widgets.Inputs.File is procedure file_input_set_draw_hook (W, D : in System.Address); pragma Import (C, file_input_set_draw_hook, "file_input_set_draw_hook"); pragma Inline (file_input_set_draw_hook); procedure file_input_set_handle_hook (W, H : in System.Address); pragma Import (C, file_input_set_handle_hook, "file_input_set_handle_hook"); pragma Inline (file_input_set_handle_hook); function new_fl_file_input (X, Y, W, H : in Interfaces.C.int; Text : in Interfaces.C.char_array) return System.Address; pragma Import (C, new_fl_file_input, "new_fl_file_input"); pragma Inline (new_fl_file_input); procedure free_fl_file_input (F : in System.Address); pragma Import (C, free_fl_file_input, "free_fl_file_input"); pragma Inline (free_fl_file_input); function fl_file_input_get_down_box (F : in System.Address) return Interfaces.C.int; pragma Import (C, fl_file_input_get_down_box, "fl_file_input_get_down_box"); pragma Inline (fl_file_input_get_down_box); procedure fl_file_input_set_down_box (F : in System.Address; T : in Interfaces.C.int); pragma Import (C, fl_file_input_set_down_box, "fl_file_input_set_down_box"); pragma Inline (fl_file_input_set_down_box); function fl_file_input_get_errorcolor (F : in System.Address) return Interfaces.C.unsigned; pragma Import (C, fl_file_input_get_errorcolor, "fl_file_input_get_errorcolor"); pragma Inline (fl_file_input_get_errorcolor); procedure fl_file_input_set_errorcolor (F : in System.Address; T : in Interfaces.C.unsigned); pragma Import (C, fl_file_input_set_errorcolor, "fl_file_input_set_errorcolor"); pragma Inline (fl_file_input_set_errorcolor); function fl_file_input_get_value (F : in System.Address) return Interfaces.C.Strings.chars_ptr; pragma Import (C, fl_file_input_get_value, "fl_file_input_get_value"); pragma Inline (fl_file_input_get_value); procedure fl_file_input_set_value (I : in System.Address; T : in Interfaces.C.char_array; L : in Interfaces.C.int); pragma Import (C, fl_file_input_set_value, "fl_file_input_set_value"); pragma Inline (fl_file_input_set_value); procedure fl_file_input_draw (W : in System.Address); pragma Import (C, fl_file_input_draw, "fl_file_input_draw"); pragma Inline (fl_file_input_draw); function fl_file_input_handle (W : in System.Address; E : in Interfaces.C.int) return Interfaces.C.int; pragma Import (C, fl_file_input_handle, "fl_file_input_handle"); pragma Inline (fl_file_input_handle); procedure Finalize (This : in out File_Input) is begin if This.Void_Ptr /= System.Null_Address and then This in File_Input'Class then free_fl_file_input (This.Void_Ptr); This.Void_Ptr := System.Null_Address; end if; Finalize (Input (This)); end Finalize; package body Forge is function Create (X, Y, W, H : in Integer; Text : in String) return File_Input is begin return This : File_Input do This.Void_Ptr := new_fl_file_input (Interfaces.C.int (X), Interfaces.C.int (Y), Interfaces.C.int (W), Interfaces.C.int (H), Interfaces.C.To_C (Text)); fl_widget_set_user_data (This.Void_Ptr, Widget_Convert.To_Address (This'Unchecked_Access)); file_input_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); file_input_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); end return; end Create; end Forge; function Get_Down_Box (This : in File_Input) return Box_Kind is begin return Box_Kind'Val (fl_file_input_get_down_box (This.Void_Ptr)); end Get_Down_Box; procedure Set_Down_Box (This : in out File_Input; To : in Box_Kind) is begin fl_file_input_set_down_box (This.Void_Ptr, Box_Kind'Pos (To)); end Set_Down_Box; function Get_Error_Color (This : in File_Input) return Color is begin return Color (fl_file_input_get_errorcolor (This.Void_Ptr)); end Get_Error_Color; procedure Set_Error_Color (This : in out File_Input; To : in Color) is begin fl_file_input_set_errorcolor (This.Void_Ptr, Interfaces.C.unsigned (To)); end Set_Error_Color; function Get_Value (This : in Input) return String is Ptr : Interfaces.C.Strings.chars_ptr := fl_file_input_get_value (This.Void_Ptr); begin if Ptr = Interfaces.C.Strings.Null_Ptr then return ""; else -- pointer to internal buffer only, so no Free required return Interfaces.C.Strings.Value (Ptr); end if; end Get_Value; procedure Set_Value (This : in out Input; To : in String) is begin fl_file_input_set_value (This.Void_Ptr, Interfaces.C.To_C (To), To'Length); end Set_Value; procedure Draw (This : in out File_Input) is begin fl_file_input_draw (This.Void_Ptr); end Draw; function Handle (This : in out File_Input; Event : in Event_Kind) return Event_Outcome is begin return Event_Outcome'Val (fl_file_input_handle (This.Void_Ptr, Event_Kind'Pos (Event))); end Handle; end FLTK.Widgets.Inputs.File;
-- Used for all testcases for SQLite driver -- Modify connection parameters as necessary package body Connect is procedure connect_database is begin DR.basic_connect (database => "file:///home/marino/adabase.sqlite"); end connect_database; end Connect;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; with bintree; procedure demo is type Tomb is array (Integer range <>) of Integer; function beta(item : Integer; parent : Integer) return Boolean is begin return item / 2 = parent; end beta; function tree is new bintree(Integer, Tomb, beta); result : Boolean; arrLength : Integer := 10000; arrItem : Integer; arr : Tomb(1 .. arrLength); begin Put("Length of array: "); Get(arrLength); for i in 1 .. arrLength loop Put("Item "); Put(i, 0); Put(": "); Get(arrItem); arr(i) := arrItem; end loop; result := tree(arr); if result then Put("true"); else Put("false"); end if; end demo;
-- C37405A.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- CHECK THAT WHEN ASSIGNING TO A CONSTRAINED OR UNCONSTRAINED -- OBJECT OR FORMAL PARAMETER OF A TYPE DECLARED WITH DEFAULT -- DISCRIMINANTS, THE ASSIGNMENT DOES NOT CHANGE THE 'CONSTRAINED -- ATTRIBUTE VALUE ASSOCIATED WITH THE OBJECT OR PARAMETER. -- ASL 7/21/81 -- TBN 1/20/86 RENAMED FROM C37209A.ADA AND REVISED THE ASSIGNMENTS -- OF CONSTRAINED AND UNCONSTRAINED OBJECTS TO ARRAY AND -- RECORD COMPONENTS. WITH REPORT; USE REPORT; PROCEDURE C37405A IS TYPE REC(DISC : INTEGER := 25) IS RECORD COMP : INTEGER; END RECORD; SUBTYPE CONSTR IS REC(10); SUBTYPE UNCONSTR IS REC; TYPE REC_C IS RECORD COMP: CONSTR; END RECORD; TYPE REC_U IS RECORD COMP: UNCONSTR; END RECORD; C1,C2 : CONSTR; U1,U2 : UNCONSTR; -- C2 AND U2 ARE NOT PASSED TO EITHER PROC1 OR PROC2. ARR_C : ARRAY (1..5) OF CONSTR; ARR_U : ARRAY (1..5) OF UNCONSTR; REC_COMP_C : REC_C; REC_COMP_U : REC_U; PROCEDURE PROC11(PARM : IN OUT UNCONSTR; B : IN BOOLEAN) IS BEGIN PARM := C2; IF IDENT_BOOL(B) /= PARM'CONSTRAINED THEN FAILED ("'CONSTRAINED ATTRIBUTE CHANGED BY " & "ASSIGNMENT - 1"); END IF; END PROC11; PROCEDURE PROC12(PARM : IN OUT UNCONSTR; B : IN BOOLEAN) IS BEGIN PARM := U2; IF B /= PARM'CONSTRAINED THEN FAILED ("'CONSTRAINED ATTRIBUTE CHANGED BY " & "ASSIGNMENT - 2"); END IF; END PROC12; PROCEDURE PROC1(PARM : IN OUT UNCONSTR; B : IN BOOLEAN) IS BEGIN IF B /= PARM'CONSTRAINED THEN FAILED ("'CONSTRAINED ATTRIBUTE CHANGED BY " & "PASSING PARAMETER"); END IF; PROC11(PARM, B); PROC12(PARM, B); END PROC1; PROCEDURE PROC2(PARM : IN OUT CONSTR) IS BEGIN COMMENT ("CALLING PROC1 FROM PROC2"); -- IN CASE TEST FAILS. PROC1(PARM,TRUE); PARM := U2; IF NOT PARM'CONSTRAINED THEN FAILED ("'CONSTRAINED ATTRIBUTE CHANGED BY " & "ASSIGNMENT - 3"); END IF; END PROC2; BEGIN TEST("C37405A", "'CONSTRAINED ATTRIBUTE OF OBJECTS, FORMAL " & "PARAMETERS CANNOT BE CHANGED BY ASSIGNMENT"); C2 := (DISC => IDENT_INT(10), COMP => 3); U2 := (DISC => IDENT_INT(10), COMP => 4); ARR_C := (1..5 => U2); ARR_U := (1..5 => C2); REC_COMP_C := (COMP => U2); REC_COMP_U := (COMP => C2); C1 := U2; U1 := C2; IF U1'CONSTRAINED OR NOT C1'CONSTRAINED THEN FAILED ("'CONSTRAINED ATTRIBUTE CHANGED BY ASSIGNMENT - 4"); END IF; IF ARR_U(3)'CONSTRAINED OR NOT ARR_C(4)'CONSTRAINED THEN FAILED ("'CONSTRAINED ATTRIBUTE CHANGED BY ASSIGNMENT - 5"); END IF; IF REC_COMP_U.COMP'CONSTRAINED OR NOT REC_COMP_C.COMP'CONSTRAINED THEN FAILED ("'CONSTRAINED ATTRIBUTE CHANGED BY ASSIGNMENT - 6"); END IF; COMMENT("CALLING PROC1 DIRECTLY"); PROC1(C1,TRUE); PROC2(C1); COMMENT("CALLING PROC1 DIRECTLY"); PROC1(U1,FALSE); PROC2(U1); COMMENT("CALLING PROC1 DIRECTLY"); PROC1(ARR_C(4), TRUE); PROC2(ARR_C(5)); COMMENT("CALLING PROC1 DIRECTLY"); PROC1(ARR_U(2), FALSE); PROC2(ARR_U(3)); COMMENT("CALLING PROC1 DIRECTLY"); PROC1(REC_COMP_C.COMP, TRUE); PROC2(REC_COMP_C.COMP); COMMENT("CALLING PROC1 DIRECTLY"); PROC1(REC_COMP_U.COMP, FALSE); PROC2(REC_COMP_U.COMP); RESULT; END C37405A;
with Ada.Containers.Hashed_Maps, Ada.Execution_Time, Ada.Integer_Text_IO, Ada.Long_Long_Integer_Text_IO, Ada.Real_Time, Ada.Text_IO; with Utils, Dijkstra; procedure Main is use Ada.Execution_Time, Ada.Real_Time, Ada.Text_IO; use Utils; Nb_Tiles : constant := 1; subtype Risk_Level is Natural range 1 .. 9; type Location is record Line : Natural; Column : Natural; end record; subtype Adjacent_Index is Integer range -1 .. 1; type Adjacent_Location is record Line : Adjacent_Index; Column : Adjacent_Index; end record; type Adjacent is (Top, Right, Bottom, Left); type Adjacent_Array is array (Adjacent) of Adjacent_Location; -- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration. -- @param Loc A 2 dimensional location -- @returns Return the corresponding hash -- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function function Hash (Loc : Location) return Ada.Containers.Hash_Type is (Ada.Containers.Hash_Type (((Loc.Line + Loc.Column) * (Loc.Line + Loc.Column + 1) / 2) + Loc.Column)); package Location_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Location, Element_Type => Risk_Level, Hash => Hash, Equivalent_Keys => "=", "=" => "="); use Location_Maps; Adjacents : constant Adjacent_Array := (Top => (-1, 0), Right => (0, 1), Bottom => (1, 0), Left => (0, -1)); function Equivalent_Keys (Left, Right : Location) return Boolean is (Left.Line = Right.Line and Left.Column = Right.Column); -- Display the location procedure Put (Loc : Location); --------- -- Put -- --------- procedure Put (Loc : Location) is begin Put ("("); Ada.Integer_Text_IO.Put (Item => Loc.Line, Width => 0); Put (","); Ada.Integer_Text_IO.Put (Item => Loc.Column, Width => 0); Put (")"); end Put; package Chiton_Dijkstra is new Dijkstra (Node => Location, Hash => Hash, Equivalent_Keys => Equivalent_Keys, Put => Put, Is_Directed => True); -- This heuristic compute the Manhattan distance from Current to To function Heuristic (Current, To : Location) return Long_Long_Natural; function Heuristic (Current, To : Location) return Long_Long_Natural is begin return Long_Long_Natural (abs (To.Line - Current.Line) + abs (To.Column - Current.Column)); end Heuristic; use Chiton_Dijkstra; File : File_Type; Start_Time, End_Time : CPU_Time; Execution_Duration : Time_Span; Array_Width, Array_Height : Natural := Natural'First; Result : Long_Long_Natural := Long_Long_Natural'First; Nodes : Map; Edges : Edges_Lists.Vector := Edges_Lists.Empty_Vector; Graph : Graph_Access; begin Get_File (File); -- Get all values while not End_Of_File (File) loop declare Str : constant String := Get_Line (File); Value : Risk_Level; Last : Positive; Current_Colum : Natural := Natural'First; begin if Array_Width = Natural'First then Array_Width := Str'Length; end if; for Char of Str loop Ada.Integer_Text_IO.Get (Char & "", Value, Last); Nodes.Insert ((Array_Height, Current_Colum), Value); Current_Colum := Current_Colum + 1; end loop; Create_Horizontal_Tiles : for Column in Array_Width .. Array_Width * Nb_Tiles - 1 loop Last := Nodes.Element ((Array_Height, Column - Array_Width)) + 1; if Last > 9 then Last := Last - 9; end if; Nodes.Insert ((Array_Height, Column), Last); end loop Create_Horizontal_Tiles; end; Array_Height := Array_Height + 1; end loop; -- Exit the program if there is no values if Nodes.Is_Empty then Close_If_Open (File); Put_Line ("The input file is empty."); return; end if; Create_Vertical_Tiles : declare Value : Natural; begin for Line in Array_Height .. Array_Height * Nb_Tiles - 1 loop for Column in 0 .. Array_Width * Nb_Tiles - 1 loop Value := Nodes.Element ((Line - Array_Height, Column)) + 1; if Value > 9 then Value := Value - 9; end if; Nodes.Insert ((Line, Column), Risk_Level (Value)); end loop; end loop; end Create_Vertical_Tiles; Create_Graph : declare Current_Loc : Location; begin for Line in 0 .. Array_Height * Nb_Tiles - 1 loop for Column in 0 .. Array_Width * Nb_Tiles - 1 loop for Adjacent : Adjacent_Location of Adjacents loop if Line + Adjacent.Line in 0 .. Array_Height * Nb_Tiles - 1 and Column + Adjacent.Column in 0 .. Array_Width * Nb_Tiles - 1 then Current_Loc := (Line + Adjacent.Line, Column + Adjacent.Column); Edges.Append (( Start_Node => (Line, Column), End_Node => (Current_Loc.Line, Current_Loc.Column), Cost => Long_Long_Natural (Nodes.Element ((Current_Loc.Line, Current_Loc.Column))) )); end if; end loop; end loop; end loop; Graph := new Graph_T '(Initialize (Edges)); end Create_Graph; -- Do the puzzle Start_Time := Ada.Execution_Time.Clock; Solve_Puzzle : declare begin Result := Graph.Shortest_Cost (From => (0, 0), To => (Array_Height * Nb_Tiles - 1, Array_Width * Nb_Tiles - 1), Heuristic => Heuristic'Access); end Solve_Puzzle; End_Time := Ada.Execution_Time.Clock; Execution_Duration := End_Time - Start_Time; Put ("Result: "); Ada.Long_Long_Integer_Text_IO.Put (Item => Result, Width => 0); New_Line; Put_Line ("(Took " & Duration'Image (To_Duration (Execution_Duration) * 1_000_000) & "µs)"); exception when others => Close_If_Open (File); raise; end Main;
with freetype_c.Pointers; package freetype_c.pointer_Pointers is use freetype_c.Pointers; type FT_UShort_Pointer_Pointer is access all FT_UShort_Pointer; type FT_Int_Pointer_Pointer is access all FT_Int_Pointer; type FT_UInt_Pointer_Pointer is access all FT_UInt_Pointer; type FT_Long_Pointer_Pointer is access all FT_Long_Pointer; type FT_ULong_Pointer_Pointer is access all FT_ULong_Pointer; type FT_Fixed_Pointer_Pointer is access all FT_Fixed_Pointer; type FT_Pos_Pointer_Pointer is access all FT_Pos_Pointer; type FT_Error_Pointer_Pointer is access all FT_Error_Pointer; type FT_Encoding_Pointer_Pointer is access all FT_Encoding_Pointer; type FT_F26Dot6_Pointer_Pointer is access all FT_F26Dot6_Pointer; type FT_Int32_Pointer_Pointer is access all FT_Int32_Pointer; type FT_UInt32_Pointer_Pointer is access all FT_UInt32_Pointer; type FT_Render_Mode_Pointer_Pointer is access all FT_Render_Mode_Pointer; type FT_Outline_Pointer_Pointer is access all FT_Outline_Pointer; type FT_LibraryRec_Pointer_Pointer is access all FT_LibraryRec_Pointer; type FT_GlyphSlotRec_Pointer_Pointer is access all FT_GlyphSlotRec_Pointer; type FT_FaceRec_Pointer_Pointer is access all FT_FaceRec_Pointer; type FT_Kerning_Mode_Pointer_Pointer is access all FT_Kerning_Mode_Pointer; type FT_SizeRec_Pointer_Pointer is access all FT_SizeRec_Pointer; end freetype_c.pointer_Pointers;
with Ada.Text_IO; use Ada.Text_IO; with Interfaces; use Interfaces; with Ada.Containers.Vectors; procedure Day23 is type Coordinates is record X : Integer_64; Y : Integer_64; Z : Integer_64; end record; function Manhattan_Distance (Pos1, Pos2 : Coordinates) return Integer_64 is (abs (Pos1.X - Pos2.X) + abs (Pos1.Y - Pos2.Y) + abs (Pos1.Z - Pos2.Z)); type Nanobot is record Pos : Coordinates; Radius : Integer_64; end record; package Vectors is new Ada.Containers.Vectors (Index_Type => Positive, Element_Type => Nanobot); use Vectors; Bots : Vector; File : File_Type; Max_Bot : Nanobot := ((0, 0, 0), 0); begin Open (File, In_File, "input.txt"); while not End_Of_File (File) loop declare Line : constant String := Get_Line (File); XYZ : array (Positive range 1 .. 3) of Integer_64; I : Positive := XYZ'First; F, L : Positive := 6; Radius : Integer_64; Bot : Nanobot; begin while I <= XYZ'Last loop if Line (L) = ',' or Line (L) = '>' then XYZ (I) := Integer_64'Value (Line (F .. L - 1)); I := I + 1; F := L + 1; end if; L := L + 1; end loop; while F <= Line'Last and Line (F) /= '=' loop F := F + 1; end loop; Radius := Integer_64'Value (Line (F + 1 .. Line'Last)); Bot := ((XYZ (1), XYZ (2), XYZ (3)), Radius); Bots.Append (Bot); if Bot.Radius > Max_Bot.Radius then Max_Bot := Bot; end if; end; end loop; Close (File); declare Count : Natural := 0; begin for Bot of Bots loop if Manhattan_Distance (Max_Bot.Pos, Bot.Pos) <= Max_Bot.Radius then Count := Count + 1; end if; end loop; Put_Line ("Part 1 =" & Natural'Image (Count)); end; end Day23;
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- A D A . S T R I N G S . F I X E D -- -- -- -- S p e c -- -- -- -- This specification is derived 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.Strings.Maps; with Ada.Strings; use Ada.Strings; package String_Fixed with SPARK_Mode is pragma Preelaborate; ------------------------ -- Search Subprograms -- ------------------------ function Index (Source : String; Set : Maps.Character_Set; From : Positive; Test : Membership := Inside; Going : Direction := Forward) return Natural; -- Index searches for the first or last occurrence of any of a set of -- characters (when Test=Inside), or any of the complement of a set of -- characters (when Test=Outside). If Source is the null string, Index -- returns 0; otherwise, if From is not in Source'Range, then Index_Error -- is propagated. Otherwise, it returns the smallest index I >= From (if -- Going=Forward) or the largest index I <= From (if Going=Backward) such -- that Source(I) satisfies the Test condition with respect to Set; it -- returns 0 if there is no such Character in Source. function Index (Source : String; Set : Maps.Character_Set; Test : Membership := Inside; Going : Direction := Forward) return Natural; -- If Going = Forward, -- returns Index (Source, Set, Source'First, Test, Forward); -- otherwise, returns -- Index (Source, Set, Source'Last, Test, Backward); function Index_Non_Blank (Source : String; From : Positive; Going : Direction := Forward) return Natural; -- Returns Index (Source, Maps.To_Set(Space), From, Outside, Going); function Index_Non_Blank (Source : String; Going : Direction := Forward) return Natural; -- Returns Index(Source, Maps.To_Set(Space), Outside, Going) --------------------------------------- -- String Transformation Subprograms -- --------------------------------------- function Insert (Source : String; Before : Positive; New_Item : String) return String; -- Propagates Index_Error if Before is not in Source'First .. Source'Last+1; -- otherwise, returns Source(Source'First..Before-1) & New_Item & -- Source(Before..Source'Last), but with lower bound 1. -- Beware of the overflow of the string length ! function Overwrite (Source : String; Position : Positive; New_Item : String) return String; -- Propagates Index_Error if Position is not in Source'First .. -- Source'Last+1; otherwise, returns the string obtained from Source by -- consecutively replacing characters starting at Position with -- corresponding characters from New_Item with lower bound 1. If the end of -- Source is reached before the characters in New_Item are exhausted, the -- remaining characters from New_Item are appended to the string. -- Beware of the overflow of the string length ! function Delete (Source : String; From : Positive; Through : Natural) return String; -- If From > Through, the returned string is Source with lower bound 1. -- If From not in Source'Range, or Through > Source'Last, then Index_Error -- is propagated. Otherwise, the returned string comprises -- Source(Source'First..From - 1) & Source(Through+1..Source'Last), but -- with lower bound 1. --------------------------------- -- String Selector Subprograms -- --------------------------------- function Trim (Source : String; Left : Maps.Character_Set; Right : Maps.Character_Set) return String; -- Returns the string obtained by removing from Source all leading -- characters in Left and all trailing characters in Right. function Trim (Source : String; Side : Trim_End) return String; -- Returns the string obtained by removing from Source all leading Space -- characters (if Side = Left), all trailing Space characters -- (if Side = Right), or all leading and trailing Space characters -- (if Side = Both). function Head (Source : String; Count : Natural; Pad : Character := Space) return String; -- Returns a string of length Count. If Count <= Source'Length, the string -- comprises the first Count characters of Source. Otherwise, its contents -- are Source concatenated with Count-Source'Length Pad characters. function Tail (Source : String; Count : Natural; Pad : Character := Space) return String; -- Returns a string of length Count. If Count <= Source'Length, the string -- comprises the last Count characters of Source. Otherwise, its contents -- are Count-Source'Length Pad characters concatenated with Source. ---------------------------------- -- String Constructor Functions -- ---------------------------------- function "*" (Left : Natural; Right : Character) return String; -- This function replicates a character a specified number of times. It -- returns a string whose length is Left and each of whose elements is -- Right. end String_Fixed;
-- C64103F.ADA -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687, -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein. -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- OBJECTIVE: -- CHECK THAT, FOR OUT PARAMETERS OF AN ACCESS TYPE, -- CONSTRAINT_ERROR IS RAISED: -- AFTER A SUBPROGRAM CALL WHEN THE BOUNDS OR DISCRIMINANTS -- OF THE FORMAL DESIGNATED PARAMETER ARE DIFFERENT FROM -- THOSE OF THE ACTUAL DESIGNATED PARAMETER. -- HISTORY: -- CPP 07/23/84 CREATED ORIGINAL TEST. -- VCL 10/27/87 MODIFIED THIS HEADER; ADDED STATEMENTS WHICH -- REFERENCE THE ACTUAL PARAMETERS. WITH REPORT; USE REPORT; PROCEDURE C64103F IS BEGIN TEST ("C64103F", "FOR OUT PARAMETERS OF AN ACCESS TYPE, " & "CONSTRAINT_ERROR IS RAISED: AFTER A " & "SUBPROGRAM CALL WHEN THE BOUNDS OR " & "DISCRIMINANTS OF THE FORMAL DESIGNATED " & "PARAMETER ARE DIFFERENT FROM THOSE OF THE " & "ACTUAL DESIGNATED PARAMETER"); BEGIN DECLARE TYPE AST IS ACCESS STRING; SUBTYPE AST_3 IS AST(IDENT_INT(1)..IDENT_INT(3)); SUBTYPE AST_5 IS AST(3..5); X_3 : AST_3 := NEW STRING'(1..IDENT_INT(3) => 'A'); CALLED : BOOLEAN := FALSE; PROCEDURE P1 (X : OUT AST_5) IS BEGIN CALLED := TRUE; X := NEW STRING'(3..5 => 'C'); END P1; BEGIN P1 (AST_5 (X_3)); IF X_3.ALL = STRING'(1 .. 3 => 'A') THEN FAILED ("EXCEPTION NOT RAISED AFTER CALL -P1 (A1)"); ELSE FAILED ("EXCEPTION NOT RAISED AFTER CALL -P1 (A2)"); END IF; EXCEPTION WHEN CONSTRAINT_ERROR => IF NOT CALLED THEN FAILED ("EXCEPTION RAISED BEFORE CALL " & "-P1 (A)"); END IF; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED -P1 (A)"); END; DECLARE TYPE ARRAY_TYPE IS ARRAY (INTEGER RANGE <>) OF BOOLEAN; TYPE A_ARRAY IS ACCESS ARRAY_TYPE; SUBTYPE A1_ARRAY IS A_ARRAY (1..IDENT_INT(3)); TYPE A2_ARRAY IS NEW A_ARRAY (2..4); A0 : A1_ARRAY := NEW ARRAY_TYPE'(1..3 => TRUE); CALLED : BOOLEAN := FALSE; PROCEDURE P2 (X : OUT A2_ARRAY) IS BEGIN CALLED := TRUE; X := NEW ARRAY_TYPE'(2..4 => FALSE); END P2; BEGIN P2 (A2_ARRAY (A0)); IF A0.ALL = ARRAY_TYPE'(1 .. 3 => TRUE) THEN FAILED ("EXCEPTION NOT RAISED AFTER CALL -P2 (A1)"); ELSE FAILED ("EXCEPTION NOT RAISED AFTER CALL -P2 (A2)"); END IF; EXCEPTION WHEN CONSTRAINT_ERROR => IF NOT CALLED THEN FAILED ("EXCEPTION RAISED BEFORE CALL " & "-P1 (A)"); END IF; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED -P2 (A)"); END; DECLARE TYPE SUBINT IS RANGE 0..8; TYPE REC1 (DISC : SUBINT := 8) IS RECORD FIELD : SUBINT := DISC; END RECORD; TYPE A1_REC IS ACCESS REC1; TYPE A2_REC IS NEW A1_REC (3); A0 : A1_REC(4) := NEW REC1(4); CALLED : BOOLEAN := FALSE; PROCEDURE P3 (X : OUT A2_REC) IS BEGIN CALLED := TRUE; X := NEW REC1(3); END P3; BEGIN P3 (A2_REC (A0)); IF A0.ALL = REC1'(4,4) THEN FAILED ("EXCEPTION NOT RAISED AFTER CALL -P3 (A1)"); ELSE FAILED ("EXCEPTION NOT RAISED AFTER CALL -P3 (A2)"); END IF; EXCEPTION WHEN CONSTRAINT_ERROR => IF NOT CALLED THEN FAILED ("EXCEPTION RAISED BEFORE CALL " & "-P1 (A)"); END IF; WHEN OTHERS => FAILED ("WRONG EXCEPTION RAISED -P3 (A)"); END; END; RESULT; END C64103F;
------------------------------------------------------------------------------- -- Copyright 2021, The Trendy Terminal 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. ------------------------------------------------------------------------------- -- Platform agnostic VT100 commands. -- -- ECMA-48 (ISO 6429) -- C0 (7-bit) control codes -- C1 (8-bit) control codes -- CSI = Control Sequence Introducer -- https://vt100.net/ -- https://vt100.net/docs/vt510-rm/chapter4.html -- https://en.wiktionary.org/wiki/Appendix:Control_characters -- https://mudhalla.net/tintin/info/vt100/ -- https://www.aivosto.com/articles/control-characters.html -- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html -- https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences package Trendy_Terminal.VT100 is procedure Cursor_Left; procedure Cursor_Right; procedure Cursor_Down; procedure Cursor_Up; procedure Hide_Cursor; procedure Show_Cursor; procedure Scroll_Down; procedure Scroll_Up; procedure Cursor_Next_Line; procedure Erase; procedure Beginning_Of_Line; procedure Clear_Line; procedure Report_Cursor_Position; -- A position on screen. Due to scrolling it is possible for these values -- to be negative. type Cursor_Position is record Row : Integer; Col : Integer; end record; procedure Set_Cursor_Position (C : Cursor_Position); function Get_Cursor_Position return Cursor_Position; end Trendy_Terminal.VT100;
-- Mojang API -- No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) -- ------------ EDIT NOTE ------------ -- This file was generated with openapi-generator. You can modify it to implement -- the server. After you modify this file, you should add the following line -- to the .openapi-generator-ignore file: -- -- src/com-github-asyncmc-mojang-status-ada-server-model.ads -- -- Then, you can drop this edit note comment. -- ------------ EDIT NOTE ------------ package com.github is end com.github;
----------------------------------------------------------------------- -- awa-questions-beans -- Beans for module questions -- Copyright (C) 2012, 2013 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 ADO.Queries; with ADO.Utils; with ADO.Sessions; with ADO.Sessions.Entities; with Util.Beans.Lists.Strings; with AWA.Tags.Modules; with AWA.Services.Contexts; package body AWA.Questions.Beans is package ASC renames AWA.Services.Contexts; -- ------------------------------ -- Get the value identified by the name. -- ------------------------------ overriding function Get_Value (From : in Question_Bean; Name : in String) return Util.Beans.Objects.Object is begin if Name = "tags" then return Util.Beans.Objects.To_Object (From.Tags_Bean, Util.Beans.Objects.STATIC); elsif From.Is_Null then return Util.Beans.Objects.Null_Object; else return AWA.Questions.Models.Question_Bean (From).Get_Value (Name); end if; end Get_Value; -- ------------------------------ -- Set the value identified by the name. -- ------------------------------ overriding procedure Set_Value (From : in out Question_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin if Name = "title" then From.Set_Title (Util.Beans.Objects.To_String (Value)); elsif Name = "description" then From.Set_Description (Util.Beans.Objects.To_String (Value)); elsif Name = "id" and not Util.Beans.Objects.Is_Empty (Value) then declare Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current; DB : constant ADO.Sessions.Session := AWA.Services.Contexts.Get_Session (Ctx); Id : constant ADO.Identifier := ADO.Utils.To_Identifier (Value); begin From.Service.Load_Question (From, Id); From.Tags.Load_Tags (DB, Id); end; end if; end Set_Value; -- ------------------------------ -- Create or save the question. -- ------------------------------ procedure Save (Bean : in out Question_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Service.Save_Question (Bean); Bean.Tags.Update_Tags (Bean.Get_Id); end Save; -- ------------------------------ -- Delete the question. -- ------------------------------ procedure Delete (Bean : in out Question_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Service.Delete_Question (Bean); end Delete; -- ------------------------------ -- Create the Question_Bean bean instance. -- ------------------------------ function Create_Question_Bean (Module : in AWA.Questions.Modules.Question_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is Object : constant Question_Bean_Access := new Question_Bean; begin Object.Service := Module; Object.Tags_Bean := Object.Tags'Access; Object.Tags.Set_Entity_Type (AWA.Questions.Models.QUESTION_TABLE); Object.Tags.Set_Permission ("question-edit"); return Object.all'Access; end Create_Question_Bean; -- Get the value identified by the name. overriding function Get_Value (From : in Answer_Bean; Name : in String) return Util.Beans.Objects.Object is begin if Name = "question_id" then return Util.Beans.Objects.To_Object (Long_Long_Integer (From.Question.Get_Id)); elsif From.Is_Null then return Util.Beans.Objects.Null_Object; else return AWA.Questions.Models.Answer_Bean (From).Get_Value (Name); end if; end Get_Value; -- ------------------------------ -- Set the value identified by the name. -- ------------------------------ overriding procedure Set_Value (From : in out Answer_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin if Name = "id" and not Util.Beans.Objects.Is_Empty (Value) then From.Service.Load_Answer (From, From.Question, ADO.Utils.To_Identifier (Value)); elsif Name = "answer" then From.Set_Answer (Util.Beans.Objects.To_String (Value)); elsif Name = "question_id" and not Util.Beans.Objects.Is_Null (Value) then From.Service.Load_Question (From.Question, ADO.Utils.To_Identifier (Value)); end if; end Set_Value; -- ------------------------------ -- Create or save the answer. -- ------------------------------ procedure Save (Bean : in out Answer_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Service.Save_Answer (Question => Bean.Question, Answer => Bean); end Save; -- ------------------------------ -- Delete the question. -- ------------------------------ procedure Delete (Bean : in out Answer_Bean; Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is pragma Unreferenced (Outcome); begin Bean.Service.Delete_Answer (Answer => Bean); end Delete; -- ------------------------------ -- Create the answer bean instance. -- ------------------------------ function Create_Answer_Bean (Module : in AWA.Questions.Modules.Question_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is Object : constant Answer_Bean_Access := new Answer_Bean; begin Object.Service := Module; return Object.all'Access; end Create_Answer_Bean; -- ------------------------------ -- Get the value identified by the name. -- ------------------------------ overriding function Get_Value (From : in Question_List_Bean; Name : in String) return Util.Beans.Objects.Object is Pos : Natural; begin if Name = "tags" then Pos := From.Questions.Get_Row_Index; if Pos = 0 then return Util.Beans.Objects.Null_Object; end if; declare Item : constant Models.Question_Info := From.Questions.List.Element (Pos - 1); begin return From.Tags.Get_Tags (Item.Id); end; elsif Name = "questions" then return Util.Beans.Objects.To_Object (Value => From.Questions_Bean, Storage => Util.Beans.Objects.STATIC); elsif Name = "tag" then return Util.Beans.Objects.To_Object (From.Tag); else return From.Questions.Get_Value (Name); end if; end Get_Value; -- ------------------------------ -- Set the value identified by the name. -- ------------------------------ overriding procedure Set_Value (From : in out Question_List_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin if Name = "tag" then From.Tag := Util.Beans.Objects.To_Unbounded_String (Value); From.Load_List; end if; end Set_Value; -- ------------------------------ -- Load the list of question. If a tag was set, filter the list of questions with the tag. -- ------------------------------ procedure Load_List (Into : in out Question_List_Bean) is use AWA.Questions.Models; use AWA.Services; use type ADO.Identifier; Session : ADO.Sessions.Session := Into.Service.Get_Session; Query : ADO.Queries.Context; Tag_Id : ADO.Identifier; begin AWA.Tags.Modules.Find_Tag_Id (Session, Ada.Strings.Unbounded.To_String (Into.Tag), Tag_Id); if Tag_Id /= ADO.NO_IDENTIFIER then Query.Set_Query (AWA.Questions.Models.Query_Question_Tag_List); Query.Bind_Param (Name => "tag", Value => Tag_Id); else Query.Set_Query (AWA.Questions.Models.Query_Question_List); end if; ADO.Sessions.Entities.Bind_Param (Params => Query, Name => "entity_type", Table => AWA.Questions.Models.QUESTION_TABLE, Session => Session); AWA.Questions.Models.List (Into.Questions, Session, Query); declare List : ADO.Utils.Identifier_Vector; Iter : Question_Info_Vectors.Cursor := Into.Questions.List.First; begin while Question_Info_Vectors.Has_Element (Iter) loop List.Append (Question_Info_Vectors.Element (Iter).Id); Question_Info_Vectors.Next (Iter); end loop; Into.Tags.Load_Tags (Session, AWA.Questions.Models.QUESTION_TABLE.Table.all, List); end; end Load_List; -- ------------------------------ -- Create the Question_Info_List_Bean bean instance. -- ------------------------------ function Create_Question_List_Bean (Module : in AWA.Questions.Modules.Question_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is use AWA.Questions.Models; use AWA.Services; Object : constant Question_List_Bean_Access := new Question_List_Bean; -- Session : ADO.Sessions.Session := Module.Get_Session; -- Query : ADO.Queries.Context; begin Object.Service := Module; Object.Questions_Bean := Object.Questions'Unchecked_Access; -- Query.Set_Query (AWA.Questions.Models.Query_Question_List); -- ADO.Sessions.Entities.Bind_Param (Params => Query, -- Name => "entity_type", -- Table => AWA.Questions.Models.QUESTION_TABLE, -- Session => Session); -- AWA.Questions.Models.List (Object.Questions, Session, Query); Object.Load_List; return Object.all'Access; end Create_Question_List_Bean; -- ------------------------------ -- Get the value identified by the name. -- ------------------------------ overriding function Get_Value (From : in Question_Display_Bean; Name : in String) return Util.Beans.Objects.Object is begin if Name = "answers" then return Util.Beans.Objects.To_Object (Value => From.Answer_List_Bean, Storage => Util.Beans.Objects.STATIC); elsif Name = "question" then return Util.Beans.Objects.To_Object (Value => From.Question_Bean, Storage => Util.Beans.Objects.STATIC); elsif Name = "tags" then return Util.Beans.Objects.To_Object (Value => From.Tags_Bean, Storage => Util.Beans.Objects.STATIC); else return Util.Beans.Objects.Null_Object; end if; end Get_Value; -- ------------------------------ -- Set the value identified by the name. -- ------------------------------ overriding procedure Set_Value (From : in out Question_Display_Bean; Name : in String; Value : in Util.Beans.Objects.Object) is begin if Name = "id" and not Util.Beans.Objects.Is_Empty (Value) then declare package ASC renames AWA.Services.Contexts; use AWA.Questions.Models; use AWA.Services; Session : ADO.Sessions.Session := From.Service.Get_Session; Query : ADO.Queries.Context; List : AWA.Questions.Models.Question_Display_Info_List_Bean; Ctx : constant ASC.Service_Context_Access := ASC.Current; Id : constant ADO.Identifier := ADO.Utils.To_Identifier (Value); begin Query.Set_Query (AWA.Questions.Models.Query_Question_Info); Query.Bind_Param ("question_id", Id); Query.Bind_Param ("user_id", Ctx.Get_User_Identifier); ADO.Sessions.Entities.Bind_Param (Params => Query, Name => "entity_type", Table => AWA.Questions.Models.QUESTION_TABLE, Session => Session); AWA.Questions.Models.List (List, Session, Query); if not List.List.Is_Empty then From.Question := List.List.Element (0); end if; Query.Clear; Query.Bind_Param ("question_id", Util.Beans.Objects.To_Integer (Value)); Query.Bind_Param ("user_id", Ctx.Get_User_Identifier); ADO.Sessions.Entities.Bind_Param (Params => Query, Name => "entity_type", Table => AWA.Questions.Models.ANSWER_TABLE, Session => Session); Query.Set_Query (AWA.Questions.Models.Query_Answer_List); AWA.Questions.Models.List (From.Answer_List, Session, Query); -- Load the tags if any. From.Tags.Load_Tags (Session, Id); end; end if; end Set_Value; -- ------------------------------ -- Create the Question_Display_Bean bean instance. -- ------------------------------ function Create_Question_Display_Bean (Module : in AWA.Questions.Modules.Question_Module_Access) return Util.Beans.Basic.Readonly_Bean_Access is Object : constant Question_Display_Bean_Access := new Question_Display_Bean; begin Object.Service := Module; Object.Question_Bean := Object.Question'Access; Object.Answer_List_Bean := Object.Answer_List'Access; Object.Tags_Bean := Object.Tags'Access; Object.Tags.Set_Entity_Type (AWA.Questions.Models.QUESTION_TABLE); return Object.all'Access; end Create_Question_Display_Bean; end AWA.Questions.Beans;
------------------------------------------------------------------------------ -- G E L A A S I S -- -- ASIS implementation for Gela project, a portable Ada compiler -- -- http://gela.ada-ru.org -- -- - - - - - - - - - - - - - - - -- -- Read copyright and license at the end of this file -- ------------------------------------------------------------------------------ -- $Revision: 209 $ $Date: 2013-11-30 21:03:24 +0200 (Сб., 30 нояб. 2013) $ -- Purpose: -- Procedural wrapper over Object-Oriented ASIS implementation with XASIS.Utils; package body Asis.Expressions is ---------------------- -- Actual_Parameter -- ---------------------- function Actual_Parameter (Association : in Asis.Association) return Asis.Expression is begin Check_Nil_Element (Association, "Actual_Parameter"); return Actual_Parameter (Association.all); end Actual_Parameter; ------------------------------------ -- Allocator_Qualified_Expression -- ------------------------------------ function Allocator_Qualified_Expression (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Allocator_Qualified_Expression"); return Allocator_Qualified_Expression (Expression.all); end Allocator_Qualified_Expression; ---------------------------------- -- Allocator_Subtype_Indication -- ---------------------------------- function Allocator_Subtype_Indication (Expression : in Asis.Expression) return Asis.Subtype_Indication is begin Check_Nil_Element (Expression, "Allocator_Subtype_Indication"); return Allocator_Subtype_Indication (Expression.all); end Allocator_Subtype_Indication; ---------------------------------- -- Array_Component_Associations -- ---------------------------------- function Array_Component_Associations (Expression : in Asis.Expression) return Asis.Association_List is begin Check_Nil_Element (Expression, "Array_Component_Associations"); return Array_Component_Associations (Expression.all); end Array_Component_Associations; ----------------------------- -- Array_Component_Choices -- ----------------------------- function Array_Component_Choices (Association : in Asis.Association) return Asis.Expression_List is begin Check_Nil_Element (Association, "Array_Component_Choices"); return Array_Component_Choices (Association.all); end Array_Component_Choices; -------------------------------------- -- Attribute_Designator_Expressions -- -------------------------------------- function Attribute_Designator_Expressions (Expression : in Asis.Expression) return Asis.Expression_List is begin Check_Nil_Element (Expression, "Attribute_Designator_Expressions"); return Attribute_Designator_Expressions (Expression.all); end Attribute_Designator_Expressions; ------------------------------------- -- Attribute_Designator_Identifier -- ------------------------------------- function Attribute_Designator_Identifier (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Attribute_Designator_Identifier"); return Attribute_Designator_Identifier (Expression.all); end Attribute_Designator_Identifier; -------------------------- -- Component_Expression -- -------------------------- function Component_Expression (Association : in Asis.Association) return Asis.Expression is begin Check_Nil_Element (Association, "Component_Expression"); return Component_Expression (Association.all); end Component_Expression; --------------------------------------- -- Converted_Or_Qualified_Expression -- --------------------------------------- function Converted_Or_Qualified_Expression (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Converted_Or_Qualified_Expression"); return Converted_Or_Qualified_Expression (Expression.all); end Converted_Or_Qualified_Expression; ----------------------------------------- -- Converted_Or_Qualified_Subtype_Mark -- ----------------------------------------- function Converted_Or_Qualified_Subtype_Mark (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Converted_Or_Qualified_Subtype_Mark"); return Converted_Or_Qualified_Subtype_Mark (Expression.all); end Converted_Or_Qualified_Subtype_Mark; ----------------------------------- -- Corresponding_Called_Function -- ----------------------------------- function Corresponding_Called_Function (Expression : in Asis.Expression) return Asis.Declaration is begin Check_Nil_Element (Expression, "Corresponding_Called_Function"); return Corresponding_Called_Function (Expression.all); end Corresponding_Called_Function; ----------------------------------- -- Corresponding_Expression_Type -- ----------------------------------- function Corresponding_Expression_Type (Expression : in Asis.Expression) return Asis.Declaration is begin Check_Nil_Element (Expression, "Corresponding_Expression_Type"); return Corresponding_Expression_Type (Expression.all); end Corresponding_Expression_Type; ------------------------------------ -- Corresponding_Name_Declaration -- ------------------------------------ function Corresponding_Name_Declaration (Reference : in Asis.Expression) return Asis.Element is begin Check_Nil_Element (Reference, "Corresponding_Name_Declaration"); return Corresponding_Name_Declaration (Reference.all); end Corresponding_Name_Declaration; ----------------------------------- -- Corresponding_Name_Definition -- ----------------------------------- function Corresponding_Name_Definition (Reference : in Asis.Expression) return Asis.Defining_Name is List : constant Asis.Defining_Name_List := Corresponding_Name_Definition_List (Reference.all); begin if List'Length = 0 then return Nil_Element; else return List (List'First); end if; end Corresponding_Name_Definition; ---------------------------------------- -- Corresponding_Name_Definition_List -- ---------------------------------------- function Corresponding_Name_Definition_List (Reference : in Asis.Element) return Asis.Defining_Name_List is begin Check_Nil_Element (Reference, "Corresponding_Name_Definition_List"); return Corresponding_Name_Definition_List (Reference.all); end Corresponding_Name_Definition_List; ----------------------------- -- Discriminant_Expression -- ----------------------------- function Discriminant_Expression (Association : in Asis.Discriminant_Association) return Asis.Expression is begin Check_Nil_Element (Association, "Discriminant_Expression"); return Discriminant_Expression (Association.all); end Discriminant_Expression; --------------------------------- -- Discriminant_Selector_Names -- --------------------------------- function Discriminant_Selector_Names (Association : in Asis.Discriminant_Association) return Asis.Expression_List is begin Check_Nil_Element (Association, "Discriminant_Selector_Names"); if Is_Normalized (Association) then return (1 => Discriminant_Selector_Name (Association.all)); else return Discriminant_Selector_Names (Association.all); end if; end Discriminant_Selector_Names; ------------------------------ -- Expression_Parenthesized -- ------------------------------ function Expression_Parenthesized (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Expression_Parenthesized"); return Expression_Parenthesized (Expression.all); end Expression_Parenthesized; ------------------------------------ -- Extension_Aggregate_Expression -- ------------------------------------ function Extension_Aggregate_Expression (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Extension_Aggregate_Expression"); return Extension_Aggregate_Expression (Expression.all); end Extension_Aggregate_Expression; ---------------------- -- Formal_Parameter -- ---------------------- function Formal_Parameter (Association : in Asis.Association) return Asis.Element is begin Check_Nil_Element (Association, "Formal_Parameter"); return Formal_Parameter (Association.all); end Formal_Parameter; ------------------------------ -- Function_Call_Parameters -- ------------------------------ function Function_Call_Parameters (Expression : in Asis.Expression; Normalized : in Boolean := False) return Asis.Association_List is begin Check_Nil_Element (Expression, "Function_Call_Parameters"); if Normalized then return Normalized_Function_Call_Parameters (Expression.all); else return Function_Call_Parameters (Expression.all); end if; end Function_Call_Parameters; ----------------------- -- Index_Expressions -- ----------------------- function Index_Expressions (Expression : in Asis.Expression) return Asis.Expression_List is begin Check_Nil_Element (Expression, "Index_Expressions"); return Index_Expressions (Expression.all); end Index_Expressions; ------------------------------ -- Is_Defaulted_Association -- ------------------------------ function Is_Defaulted_Association (Association : in Asis.Association) return Boolean is begin Check_Nil_Element (Association, "Is_Defaulted_Association"); return Is_Defaulted_Association (Association.all); end Is_Defaulted_Association; ------------------- -- Is_Normalized -- ------------------- function Is_Normalized (Association : in Asis.Association) return Boolean is begin Check_Nil_Element (Association, "Is_Normalized"); return Is_Normalized (Association.all); end Is_Normalized; -------------------- -- Is_Prefix_Call -- -------------------- function Is_Prefix_Call (Expression : in Asis.Expression) return Boolean is begin Check_Nil_Element (Expression, "Is_Prefix_Call"); return Is_Prefix_Call (Expression.all); end Is_Prefix_Call; ------------------- -- Is_Referenced -- ------------------- function Is_Referenced (Name : in Asis.Element; Within_Element : in Asis.Element; Implicitly : in Boolean := False) return Boolean is begin return References (Name, Within_Element, Implicitly)'Length > 0; end Is_Referenced; -------------------------------- -- Membership_Test_Expression -- -------------------------------- function Membership_Test_Expression (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Membership_Test_Expression"); return Membership_Test_Expression (Expression.all); end Membership_Test_Expression; --------------------------- -- Membership_Test_Range -- --------------------------- function Membership_Test_Range (Expression : in Asis.Expression) return Asis.Range_Constraint is begin Check_Nil_Element (Expression, "Membership_Test_Range"); return Membership_Test_Range (Expression.all); end Membership_Test_Range; ---------------------------------- -- Membership_Test_Subtype_Mark -- ---------------------------------- function Membership_Test_Subtype_Mark (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Membership_Test_Subtype_Mark"); return Membership_Test_Subtype_Mark (Expression.all); end Membership_Test_Subtype_Mark; ---------------- -- Name_Image -- ---------------- function Name_Image (Expression : in Asis.Expression) return Program_Text is begin Check_Nil_Element (Expression, "Name_Image"); return Name_Image (Expression.all); end Name_Image; ------------ -- Prefix -- ------------ function Prefix (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Prefix"); return Prefix (Expression.all); end Prefix; ----------------------------------- -- Record_Component_Associations -- ----------------------------------- function Record_Component_Associations (Expression : in Asis.Expression; Normalized : in Boolean := False) return Asis.Association_List is begin Check_Nil_Element (Expression, "Record_Component_Associations"); if Normalized then return Normalized_Record_Component_Associations (Expression.all); else return Record_Component_Associations (Expression.all); end if; end Record_Component_Associations; ------------------------------ -- Record_Component_Choices -- ------------------------------ function Record_Component_Choices (Association : in Asis.Association) return Asis.Expression_List is begin Check_Nil_Element (Association, "Record_Component_Choices"); if Is_Normalized (Association) then return (1 => Record_Component_Choice (Association.all)); else return Record_Component_Choices (Association.all); end if; end Record_Component_Choices; ---------------- -- References -- ---------------- function References (Name : in Asis.Element; Within_Element : in Asis.Element; Implicitly : in Boolean := False) return Asis.Name_List is Result : Asis.Name_List := References (Name.all, True); Last : Asis.List_Index := 1; begin for I in Result'Range loop if (Implicitly or else not Is_Part_Of_Implicit (Result (I).all)) and then XASIS.Utils.Is_Child_Of (Result (I), Within_Element) then Result (Last) := Result (I); Last := Last + 1; end if; end loop; return Result (1 .. Last - 1); end References; -------------- -- Selector -- -------------- function Selector (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Selector"); return Selector (Expression.all); end Selector; --------------------------------------------- -- Short_Circuit_Operation_Left_Expression -- --------------------------------------------- function Short_Circuit_Operation_Left_Expression (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Short_Circuit_Operation_Left_Expression"); return Short_Circuit_Operation_Left_Expression (Expression.all); end Short_Circuit_Operation_Left_Expression; ---------------------------------------------- -- Short_Circuit_Operation_Right_Expression -- ---------------------------------------------- function Short_Circuit_Operation_Right_Expression (Expression : in Asis.Expression) return Asis.Expression is begin Check_Nil_Element (Expression, "Short_Circuit_Operation_Right_Expression"); return Short_Circuit_Operation_Right_Expression (Expression.all); end Short_Circuit_Operation_Right_Expression; ----------------- -- Slice_Range -- ----------------- function Slice_Range (Expression : in Asis.Expression) return Asis.Discrete_Range is begin Check_Nil_Element (Expression, "Slice_Range"); return Slice_Range (Expression.all); end Slice_Range; ----------------- -- Value_Image -- ----------------- function Value_Image (Expression : in Asis.Expression) return Wide_String is begin Check_Nil_Element (Expression, "Value_Image"); return Value_Image (Expression.all); end Value_Image; end Asis.Expressions; ------------------------------------------------------------------------------ -- 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; use Ada.Text_IO; with regge; with regge.io; procedure check is type Real is digits 18; package regge_lib is new regge (Real); use regge_lib; package regge_lib_io is new regge_lib.io; use regge_lib_io; package Real_IO is new Ada.Text_IO.Float_IO (Real); use Real_IO; package Integer_IO is new Ada.Text_IO.Integer_IO (Integer); use Integer_IO; txt : File_Type; defect : Real; deriv : Real; bone : Integer; begin num := read_command_arg (1); read_lattice; bone := 1; bone_signature := get_signature (bone); Create (txt,Out_file,"results/data-0"&str(num,1)&".txt"); get_defect (defect, bone, n_loop02(bone)); put_line (txt,"# defect"); put_line (txt, str(defect,25)); new_line (txt); put_line (txt,"# i j d(defect)/d(lsq(i,j))"); for a in 1..n_simp1 loop get_defect_deriv (deriv, bone, n_loop02(bone), a); put_line (txt, str (simp01(a)(1),3) &' '& str (simp01(a)(2),2) &' '& str (deriv,25)); end loop; Close (txt); end check;
------------------------------------------------------------------------------ -- Copyright (c) 2021, Lev Kujawski. -- -- 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 sell copies of the Software, and to permit persons to whom the -- Software is furnished to do so. -- -- 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. -- -- SPDX-License-Identifier: MIT-0 -- -- File: cstandio.ads (Ada Package Specification) -- Language: Ada (1987) [1] -- Author: Lev Kujawski -- Description: C Standard Input/Output (stdio.h) interface for Ada -- -- References: -- [1] Programming languages - Ada, ISO/IEC 8652:1987, 15 Jun. 1987. ------------------------------------------------------------------------------ with System; package C_Standard_IO is pragma Preelaborate; POSIX_Error : exception; Usage_Error : exception; Error : exception; type File_T is limited private; type File_Mode_T is (Read, Write, Read_Write); function File_Mode (File : in File_T) return File_Mode_T; function Is_Readable (File : in File_T) return Boolean; function Is_Writable (File : in File_T) return Boolean; function Standard_Input return File_T; function Standard_Output return File_T; function Standard_Error return File_T; procedure Open_File (File : in out File_T; With_Name : in String; With_Mode : in File_Mode_T); procedure Open_Null (File : in out File_T); procedure Close_File (File : in out File_T); procedure Put (File : in File_T; Item : in Character); procedure Put (Item : in Character); procedure Put (File : in File_T; Item : in String); procedure Put (Item : in String); procedure Put_Line (File : in File_T; Item : in String); procedure Put_Line (Item : in String); -- IMAGE FUNCTIONS ------------------------------------------------------- function Address_Image (Value : in System.Address; Format : in String := "") return String; function Integer_Image (Value : in Integer; Format : in String := "") return String; function Long_Integer_Image (Value : in Long_Integer; Format : in String := "") return String; function Long_Float_Image (Value : in Long_Float; Format : in String := "") return String; function Long_Long_Float_Image (Value : in Long_Long_Float; Format : in String := "") return String; private -- C_Standard_IO --------------------------------------------------- type File_T is record Address : System.Address := System.Null_Address; Mode : File_Mode_T; end record; pragma Pack (File_T); end C_Standard_IO;
with GNAT.Byte_Swapping; package body avtas.lmcp.byteBuffers is function To_Int16(Input : ByteArray2) return Int16_t is subtype sourceType is ByteArray2; subtype swapType is ByteArray2; subtype targetType is Int16_t; function Convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped2 (swapType); begin return Convert(SwapBytes(Input)); end To_Int16; function To_Int32(Input : ByteArray4) return Int32_t is subtype sourceType is ByteArray4; subtype swapType is ByteArray4; subtype targetType is Int32_t; function Convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped4 (swapType); begin return Convert(SwapBytes(Input)); end To_Int32; function To_Int64(Input : ByteArray8) return Int64_t is subtype sourceType is ByteArray8; subtype swapType is ByteArray8; subtype targetType is Int64_t; function Convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped8 (swapType); begin return Convert(SwapBytes(Input)); end To_Int64; function To_UInt16(Input : ByteArray2) return UInt16_t is subtype sourceType is ByteArray2; subtype swapType is ByteArray2; subtype targetType is UInt16_t; function Convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped2 (swapType); begin return Convert(SwapBytes(Input)); end To_UInt16; function To_UInt32(Input : ByteArray4) return UInt32_t is subtype sourceType is ByteArray4; subtype swapType is ByteArray4; subtype targetType is UInt32_t; function Convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped4 (swapType); begin return Convert(SwapBytes(Input)); end To_UInt32; function To_Float(Input : ByteArray4) return Float_t is subtype sourceType is ByteArray4; subtype swapType is ByteArray4; subtype targetType is Float_t; function Convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped4 (swapType); begin return Convert(SwapBytes(Input)); end To_Float; function To_Double(Input : ByteArray8) return Double_t is subtype sourceType is ByteArray8; subtype swapType is ByteArray8; subtype targetType is Double_t; function Convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped8 (swapType); begin return Convert(SwapBytes(Input)); end To_Double; function To_BooleanArray(Input : ByteArray) return BooleanArray is subtype sourceType is ByteArray(Input'Range); subtype targetType is BooleanArray(Input'Range); function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); begin return convert(Input); end To_BooleanArray; function To_Int16Array (Input : ByteArray) return Int16Array is subtype sourceType is ByteArray(Input'Range); subtype swapType is ByteArray(1 .. 2); subtype targetType is Int16Array(1 .. Input'Length/2); function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped2 (swapType); tempArray : ByteArray := Input; begin for i in 1 .. tempArray'Length/2 loop tempArray(Nat(2*i - 1) .. Nat(2*i)) := SwapBytes(tempArray(Nat(2*i - 1) .. Nat(2*i))); end loop; return convert(tempArray); end To_Int16Array; function To_Int32Array (Input : ByteArray) return Int32Array is subtype sourceType is ByteArray(Input'Range); subtype swapType is ByteArray(1 .. 4); subtype targetType is Int32Array(1 .. Input'Length/4); function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped4 (swapType); tempArray : ByteArray := Input; begin for i in 1 .. tempArray'Length/4 loop tempArray(Nat(4*i - 3) .. Nat(4*i)) := SwapBytes(tempArray(Nat(4*i - 3) .. Nat(4*i))); end loop; return convert(tempArray); end To_Int32Array; function To_Int64Array (Input : ByteArray) return Int64Array is subtype sourceType is ByteArray(Input'Range); subtype swapType is ByteArray(1 .. 8); subtype targetType is Int64Array(1 .. Input'Length/8); function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped8 (swapType); tempArray : ByteArray := Input; begin for i in 1 .. tempArray'Length/8 loop tempArray(Nat(8*i - 7) .. Nat(8*i)) := SwapBytes(tempArray(Nat(8*i - 7) .. Nat(8*i))); end loop; return convert(tempArray); end To_Int64Array; function To_UInt16Array (Input : ByteArray) return UInt16Array is subtype sourceType is ByteArray(Input'Range); subtype swapType is ByteArray(1 .. 2); subtype targetType is UInt16Array(1 .. Input'Length/2); function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped2 (swapType); tempArray : ByteArray := Input; begin for i in 1 .. tempArray'Length/2 loop tempArray(Nat(2*i - 1) .. Nat(2*i)) := SwapBytes(tempArray(Nat(2*i - 1) .. Nat(2*i))); end loop; return convert(tempArray); end To_UInt16Array; function To_UInt32Array (Input : ByteArray) return UInt32Array is subtype sourceType is ByteArray(Input'Range); subtype swapType is ByteArray(1 .. 4); subtype targetType is UInt32Array(1 .. Input'Length/4); function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped4 (swapType); tempArray : ByteArray := Input; begin for i in 1 .. tempArray'Length/4 loop tempArray(Nat(4*i - 3) .. Nat(4*i)) := SwapBytes(tempArray(Nat(4*i - 3) .. Nat(4*i))); end loop; return convert(tempArray); end To_UInt32Array; function To_FloatArray(Input : ByteArray) return FloatArray is subtype sourceType is ByteArray(Input'Range); subtype swapType is ByteArray(1 .. 4); subtype targetType is FloatArray(1 .. Input'Length/4); function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped4 (swapType); tempArray : ByteArray := Input; begin for i in 1 .. tempArray'Length/4 loop tempArray(Nat(4*i - 3) .. Nat(4*i)) := SwapBytes(tempArray(Nat(4*i - 3) .. Nat(4*i))); end loop; return convert(tempArray); end To_FloatArray; function To_DoubleArray(Input : ByteArray) return DoubleArray is subtype sourceType is ByteArray(Input'Range); subtype swapType is ByteArray(1 .. 8); subtype targetType is DoubleArray(1 .. Input'Length/8); function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); function SwapBytes is new GNAT.Byte_Swapping.Swapped8 (swapType); tempArray : ByteArray := Input; begin for i in 1 .. tempArray'Length/8 loop tempArray(Nat(8*i - 7) .. Nat(8*i)) := SwapBytes(tempArray(Nat(8*i - 7) .. Nat(8*i))); end loop; return convert(tempArray); end To_DoubleArray; function To_String(Input : ByteArray) return Unbounded_String is subtype sourceType is ByteArray(Input'Range); subtype targetType is Unbounded_String; function convert is new Ada.Unchecked_Conversion(Source => sourceType, Target => targetType); begin return convert(Input); end To_String; function To_StringArray(Input : ByteArray) return StringArray is arrayElements : UInt16_t := To_UInt16(ByteArray2(Input(1 .. 2))); position : UInt32_t := 3; stringLength : UInt16_t; tempString : Unbounded_String; output : StringArray(Nat(1) .. Nat(arrayElements)); function convert is new Ada.Unchecked_Conversion(Source => Byte, Target => Character); begin Put(arrayElements'Image); New_Line; for i in 1 .. arrayElements loop stringLength := To_UInt16(ByteArray2(Input(Nat(position) .. Nat(position + 1)))); Put(stringLength'Image); New_Line; tempString := To_Unbounded_String(""); position := position + 2; for j in 1 .. stringLength loop tempString := tempString & convert(Input(Nat(position) + Nat(j) - Nat(1))); end loop; position := position + UInt32_t(stringLength); output(Nat(i)) := tempString; end loop; return output; end To_StringArray; end avtas.lmcp.byteBuffers;
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- A D A . S T R E A M S . S T O R A G E . B O U N D E D -- -- -- -- S p e c -- -- -- -- Copyright (C) 2020, Free Software Foundation, Inc. -- -- -- -- This specification is derived from the Ada Reference Manual for use with -- -- GNAT. The copyright notice above, and the license provisions that follow -- -- apply solely to the contents of the part following the private keyword. -- -- -- -- 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/>. -- -- -- ------------------------------------------------------------------------------ package Ada.Streams.Storage.Bounded with Pure is type Stream_Type (Max_Elements : Stream_Element_Count) is new Storage_Stream_Type with private with Default_Initial_Condition => Element_Count (Stream_Type) = 0; overriding procedure Read (Stream : in out Stream_Type; Item : out Stream_Element_Array; Last : out Stream_Element_Offset) with Post => (declare Num_Read : constant Stream_Element_Count := Stream_Element_Count'Min (Element_Count (Stream)'Old, Item'Length); begin Last = Num_Read + Item'First - 1 and Element_Count (Stream) = Element_Count (Stream)'Old - Num_Read); overriding procedure Write (Stream : in out Stream_Type; Item : Stream_Element_Array) with Post => Element_Count (Stream) = Element_Count (Stream)'Old + Item'Length; overriding function Element_Count (Stream : Stream_Type) return Stream_Element_Count with Post => Element_Count'Result <= Stream.Max_Elements; overriding procedure Clear (Stream : in out Stream_Type) with Post => Element_Count (Stream) = 0; private type Stream_Type (Max_Elements : Stream_Element_Count) is new Storage_Stream_Type with record Count : Stream_Element_Count := 0; Elements : Stream_Element_Array (1 .. Max_Elements); end record; end Ada.Streams.Storage.Bounded;
------------------------------------------------------------------------------ -- -- -- GNAT SYSTEM UTILITIES -- -- -- -- X S I N F O -- -- -- -- B o d y -- -- -- -- Copyright (C) 1992-2005, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- -- Boston, MA 02110-1301, USA. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Program to construct C header file sinfo.h (C version of sinfo.ads spec, -- for use by Gigi, contains all definitions and access functions, but does -- not contain set procedures, since Gigi never modifies the GNAT tree) -- Input files: -- sinfo.ads Spec of Sinfo package -- Output files: -- sinfo.h Corresponding c header file -- Note: this program assumes that sinfo.ads has passed the error checks -- which are carried out by the CSinfo utility, so it does not duplicate -- these checks and assumes the soruce is correct. -- An optional argument allows the specification of an output file name to -- override the default sinfo.h file name for the generated output file. with Ada.Command_Line; use Ada.Command_Line; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO; with Ada.Text_IO; use Ada.Text_IO; with GNAT.Spitbol; use GNAT.Spitbol; with GNAT.Spitbol.Patterns; use GNAT.Spitbol.Patterns; procedure XSinfo is Done : exception; Err : exception; A : VString := Nul; Arg : VString := Nul; Comment : VString := Nul; Line : VString := Nul; N : VString := Nul; N1, N2 : VString := Nul; Nam : VString := Nul; Rtn : VString := Nul; Term : VString := Nul; InS : File_Type; Ofile : File_Type; wsp : Pattern := Span (' ' & ASCII.HT); Wsp_For : Pattern := wsp & "for"; Is_Cmnt : Pattern := wsp & "--"; Typ_Nod : Pattern := wsp * A & "type Node_Kind is"; Get_Nam : Pattern := wsp * A & "N_" & Break (",)") * Nam & Len (1) * Term; Sub_Typ : Pattern := wsp * A & "subtype " & Break (' ') * N; No_Cont : Pattern := wsp & Break (' ') * N1 & " .. " & Break (';') * N2; Cont_N1 : Pattern := wsp & Break (' ') * N1 & " .." & Rpos (0); Cont_N2 : Pattern := Span (' ') & Break (';') * N2; Is_Func : Pattern := wsp * A & "function " & Rest * Nam; Get_Arg : Pattern := wsp & "(N : " & Break (')') * Arg & ") return " & Break (';') * Rtn & ';' & wsp & "--" & wsp & Rest * Comment; NKV : Natural; M : Match_Result; procedure Getline; -- Get non-comment, non-blank line. Also skips "for " rep clauses ------------- -- Getline -- ------------- procedure Getline is begin loop Line := Get_Line (InS); if Line /= "" and then not Match (Line, Wsp_For) and then not Match (Line, Is_Cmnt) then return; elsif Match (Line, " -- End functions (note") then raise Done; end if; end loop; end Getline; -- Start of processing for XSinfo begin Set_Exit_Status (1); Anchored_Mode := True; if Argument_Count > 0 then Create (Ofile, Out_File, Argument (1)); else Create (Ofile, Out_File, "sinfo.h"); end if; Open (InS, In_File, "sinfo.ads"); -- Write header to output file loop Line := Get_Line (InS); exit when Line = ""; Match (Line, "-- S p e c ", "-- C Header File "); Match (Line, "--", "/*"); Match (Line, Rtab (2) * A & "--", M); Replace (M, A & "*/"); Put_Line (Ofile, Line); end loop; -- Skip to package line loop Getline; exit when Match (Line, "package"); end loop; -- Skip to first node kind line loop Getline; exit when Match (Line, Typ_Nod); Put_Line (Ofile, Line); end loop; Put_Line (Ofile, ""); NKV := 0; -- Loop through node kind codes loop Getline; if Match (Line, Get_Nam) then Put_Line (Ofile, A & "#define N_" & Nam & ' ' & NKV); NKV := NKV + 1; exit when not Match (Term, ","); else Put_Line (Ofile, Line); end if; end loop; Put_Line (Ofile, ""); Put_Line (Ofile, A & "#define Number_Node_Kinds " & NKV); -- Loop through subtype declarations loop Getline; if not Match (Line, Sub_Typ) then exit when Match (Line, " function"); Put_Line (Ofile, Line); else Put_Line (Ofile, A & "SUBTYPE (" & N & ", Node_Kind, "); Getline; -- Normal case if Match (Line, No_Cont) then Put_Line (Ofile, A & " " & N1 & ", " & N2 & ')'); -- Continuation case else if not Match (Line, Cont_N1) then raise Err; end if; Getline; if not Match (Line, Cont_N2) then raise Err; end if; Put_Line (Ofile, A & " " & N1 & ','); Put_Line (Ofile, A & " " & N2 & ')'); end if; end if; end loop; -- Loop through functions. Note that this loop is terminated by -- the call to Getfile encountering the end of functions sentinel loop if Match (Line, Is_Func) then Getline; if not Match (Line, Get_Arg) then raise Err; end if; Put_Line (Ofile, A & "INLINE " & Rpad (Rtn, 9) & ' ' & Rpad (Nam, 30) & " (" & Arg & " N)"); Put_Line (Ofile, A & " { return " & Comment & " (N); }"); else Put_Line (Ofile, Line); end if; Getline; end loop; exception when Done => Put_Line (Ofile, ""); Set_Exit_Status (0); end XSinfo;
-- part of FreeTypeAda, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "COPYING" with Ada.Text_IO; use Ada.Text_IO; with FT.Glyphs; package body FT.Utilities is use Interfaces.C; procedure Print_Bitmap_Metadata (Bitmap : FT.Bitmap_Record) is begin New_Line; Put_Line ("Bitmap data:"); Put_Line ("Rows: " & Interfaces.C.unsigned'Image (Bitmap.Rows)); Put_Line ("Width: " & Interfaces.C.unsigned'Image (Bitmap.Width)); Put_Line ("Pitch: " & Interfaces.C.int'Image (Bitmap.Pitch)); Put_Line ("Num_Grays: " & Interfaces.C.short'Image (Bitmap.Num_Grays)); Put_Line ("Pixel_mode: " & unsigned_char'Image (Bitmap.Pixel_Mode)); Put_Line ("Palette_mode: " & unsigned_char'Image (Bitmap.Palette_Mode)); New_Line; end Print_Bitmap_Metadata; -- ------------------------------------------------------------------------- procedure Print_Character_Metadata (aFace : FT.Faces.Face_Reference; aChar : Character) is Slot : constant FT.Glyph_Slot_Reference := aFace.Glyph_Slot; Bitmap : constant FT.Bitmap_Record := Glyphs.Bitmap (Slot); begin Put_Line ("Character " & aChar & " Data"); Put_Line ("Width: " & Interfaces.C.unsigned'Image (Bitmap.Width)); Put_Line ("Rows: " & Interfaces.C.unsigned'Image (Bitmap.Rows)); Put_Line ("Left: " & Interfaces.C.int'Image (Glyphs.Bitmap_Left (Slot))); Put_Line ("Top: " & Interfaces.C.int'Image (Glyphs.Bitmap_Top (Slot))); Put_Line ("Advance X: " & Position'Image (Glyphs.Advance (Slot).X) & " bits"); Put_Line ("Glyph format: " & FT.Glyph_Format'Image (Glyphs.Format (Slot))); New_Line; end Print_Character_Metadata; -- ------------------------------------------------------------------------ end FT.Utilities;
pragma Ada_2012; with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with AUnit.Assertions; use AUnit.Assertions; with AUnit.Test_Caller; package body PBKDF2.Tests is package Caller is new AUnit.Test_Caller (Fixture); Test_Suite : aliased AUnit.Test_Suites.Test_Suite; function Suite return AUnit.Test_Suites.Access_Test_Suite is Name : constant String := "[PBKDF2] "; begin Test_Suite.Add_Test (Caller.Create (Name & "PBKDF2_HMAC_SHA_1()", PBKDF2_HMAC_SHA_1_Test'Access)); Test_Suite.Add_Test (Caller.Create (Name & "PBKDF2_HMAC_SHA_256()", PBKDF2_HMAC_SHA_256_Test'Access)); Test_Suite.Add_Test (Caller.Create (Name & "PBKDF2_HMAC_SHA_512()", PBKDF2_HMAC_SHA_512_Test'Access)); return Test_Suite'Access; end Suite; procedure PBKDF2_HMAC_SHA_1_Test (Object : in out Fixture) is begin Assert (PBKDF2_HMAC_SHA_1 ("password", "salt", Iterations => 1, Derived_Key_Length => 20) = (16#0c#, 16#60#, 16#c8#, 16#0f#, 16#96#, 16#1f#, 16#0e#, 16#71#, 16#f3#, 16#a9#, 16#b5#, 16#24#, 16#af#, 16#60#, 16#12#, 16#06#, 16#2f#, 16#e0#, 16#37#, 16#a6#), "RFC6070-1"); Assert (PBKDF2_HMAC_SHA_1 ("password", "salt", Iterations => 2, Derived_Key_Length => 20) = (16#ea#, 16#6c#, 16#01#, 16#4d#, 16#c7#, 16#2d#, 16#6f#, 16#8c#, 16#cd#, 16#1e#, 16#d9#, 16#2a#, 16#ce#, 16#1d#, 16#41#, 16#f0#, 16#d8#, 16#de#, 16#89#, 16#57#), "RFC6070-2"); Assert (PBKDF2_HMAC_SHA_1 ("password", "salt", Iterations => 4_096, Derived_Key_Length => 20) = (16#4b#, 16#00#, 16#79#, 16#01#, 16#b7#, 16#65#, 16#48#, 16#9a#, 16#be#, 16#ad#, 16#49#, 16#d9#, 16#26#, 16#f7#, 16#21#, 16#d0#, 16#65#, 16#a4#, 16#29#, 16#c1#), "RFC6070-3"); Assert (PBKDF2_HMAC_SHA_1 ("password", "salt", Iterations => 16_777_216, Derived_Key_Length => 20) = (16#ee#, 16#fe#, 16#3d#, 16#61#, 16#cd#, 16#4d#, 16#a4#, 16#e4#, 16#e9#, 16#94#, 16#5b#, 16#3d#, 16#6b#, 16#a2#, 16#15#, 16#8c#, 16#26#, 16#34#, 16#e9#, 16#84#), "RFC6070-4"); Assert (PBKDF2_HMAC_SHA_1 ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", Iterations => 4_096, Derived_Key_Length => 25) = (16#3d#, 16#2e#, 16#ec#, 16#4f#, 16#e4#, 16#1c#, 16#84#, 16#9b#, 16#80#, 16#c8#, 16#d8#, 16#36#, 16#62#, 16#c0#, 16#e4#, 16#4a#, 16#8b#, 16#29#, 16#1a#, 16#96#, 16#4c#, 16#f2#, 16#f0#, 16#70#, 16#38#), "RFC6070-5"); Assert (PBKDF2_HMAC_SHA_1 ("pass" & NUL & "word", "sa" & NUL & "lt", Iterations => 4_096, Derived_Key_Length => 16) = (16#56#, 16#fa#, 16#6a#, 16#a7#, 16#55#, 16#48#, 16#09#, 16#9d#, 16#cc#, 16#37#, 16#d7#, 16#f0#, 16#34#, 16#25#, 16#e0#, 16#c3#), "RFC6070-6"); end PBKDF2_HMAC_SHA_1_Test; procedure PBKDF2_HMAC_SHA_256_Test (Object : in out Fixture) is begin Assert (PBKDF2_HMAC_SHA_256 ("passwd", "salt", Iterations => 1, Derived_Key_Length => 64) = (16#55#, 16#ac#, 16#04#, 16#6e#, 16#56#, 16#e3#, 16#08#, 16#9f#, 16#ec#, 16#16#, 16#91#, 16#c2#, 16#25#, 16#44#, 16#b6#, 16#05#, 16#f9#, 16#41#, 16#85#, 16#21#, 16#6d#, 16#de#, 16#04#, 16#65#, 16#e6#, 16#8b#, 16#9d#, 16#57#, 16#c2#, 16#0d#, 16#ac#, 16#bc#, 16#49#, 16#ca#, 16#9c#, 16#cc#, 16#f1#, 16#79#, 16#b6#, 16#45#, 16#99#, 16#16#, 16#64#, 16#b3#, 16#9d#, 16#77#, 16#ef#, 16#31#, 16#7c#, 16#71#, 16#b8#, 16#45#, 16#b1#, 16#e3#, 16#0b#, 16#d5#, 16#09#, 16#11#, 16#20#, 16#41#, 16#d3#, 16#a1#, 16#97#, 16#83#), "Test 1"); Assert (PBKDF2_HMAC_SHA_256 ("Password", "NaCl", Iterations => 80_000, Derived_Key_Length => 64) = (16#4d#, 16#dc#, 16#d8#, 16#f6#, 16#0b#, 16#98#, 16#be#, 16#21#, 16#83#, 16#0c#, 16#ee#, 16#5e#, 16#f2#, 16#27#, 16#01#, 16#f9#, 16#64#, 16#1a#, 16#44#, 16#18#, 16#d0#, 16#4c#, 16#04#, 16#14#, 16#ae#, 16#ff#, 16#08#, 16#87#, 16#6b#, 16#34#, 16#ab#, 16#56#, 16#a1#, 16#d4#, 16#25#, 16#a1#, 16#22#, 16#58#, 16#33#, 16#54#, 16#9a#, 16#db#, 16#84#, 16#1b#, 16#51#, 16#c9#, 16#b3#, 16#17#, 16#6a#, 16#27#, 16#2b#, 16#de#, 16#bb#, 16#a1#, 16#d0#, 16#78#, 16#47#, 16#8f#, 16#62#, 16#b3#, 16#97#, 16#f3#, 16#3c#, 16#8d#), "Test 2"); Assert (PBKDF2_HMAC_SHA_256 ("password", "salt", Iterations => 1, Derived_Key_Length => 32) = (16#12#, 16#0f#, 16#b6#, 16#cf#, 16#fc#, 16#f8#, 16#b3#, 16#2c#, 16#43#, 16#e7#, 16#22#, 16#52#, 16#56#, 16#c4#, 16#f8#, 16#37#, 16#a8#, 16#65#, 16#48#, 16#c9#, 16#2c#, 16#cc#, 16#35#, 16#48#, 16#08#, 16#05#, 16#98#, 16#7c#, 16#b7#, 16#0b#, 16#e1#, 16#7b#), "Test 3"); Assert (PBKDF2_HMAC_SHA_256 ("password", "salt", Iterations => 2, Derived_Key_Length => 32) = (16#ae#, 16#4d#, 16#0c#, 16#95#, 16#af#, 16#6b#, 16#46#, 16#d3#, 16#2d#, 16#0a#, 16#df#, 16#f9#, 16#28#, 16#f0#, 16#6d#, 16#d0#, 16#2a#, 16#30#, 16#3f#, 16#8e#, 16#f3#, 16#c2#, 16#51#, 16#df#, 16#d6#, 16#e2#, 16#d8#, 16#5a#, 16#95#, 16#47#, 16#4c#, 16#43#), "Test 4"); Assert (PBKDF2_HMAC_SHA_256 ("password", "salt", Iterations => 4_096, Derived_Key_Length => 32) = (16#c5#, 16#e4#, 16#78#, 16#d5#, 16#92#, 16#88#, 16#c8#, 16#41#, 16#aa#, 16#53#, 16#0d#, 16#b6#, 16#84#, 16#5c#, 16#4c#, 16#8d#, 16#96#, 16#28#, 16#93#, 16#a0#, 16#01#, 16#ce#, 16#4e#, 16#11#, 16#a4#, 16#96#, 16#38#, 16#73#, 16#aa#, 16#98#, 16#13#, 16#4a#), "Test 5"); Assert (PBKDF2_HMAC_SHA_256 ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", Iterations => 4_096, Derived_Key_Length => 40) = (16#34#, 16#8c#, 16#89#, 16#db#, 16#cb#, 16#d3#, 16#2b#, 16#2f#, 16#32#, 16#d8#, 16#14#, 16#b8#, 16#11#, 16#6e#, 16#84#, 16#cf#, 16#2b#, 16#17#, 16#34#, 16#7e#, 16#bc#, 16#18#, 16#00#, 16#18#, 16#1c#, 16#4e#, 16#2a#, 16#1f#, 16#b8#, 16#dd#, 16#53#, 16#e1#, 16#c6#, 16#35#, 16#51#, 16#8c#, 16#7d#, 16#ac#, 16#47#, 16#e9#), "Test 6"); Assert (PBKDF2_HMAC_SHA_256 ("", "salt", Iterations => 1_024, Derived_Key_Length => 32) = (16#9e#, 16#83#, 16#f2#, 16#79#, 16#c0#, 16#40#, 16#f2#, 16#a1#, 16#1a#, 16#a4#, 16#a0#, 16#2b#, 16#24#, 16#c4#, 16#18#, 16#f2#, 16#d3#, 16#cb#, 16#39#, 16#56#, 16#0c#, 16#96#, 16#27#, 16#fa#, 16#4f#, 16#47#, 16#e3#, 16#bc#, 16#c2#, 16#89#, 16#7c#, 16#3d#), "Test 7"); Assert (PBKDF2_HMAC_SHA_256 ("password", "", Iterations => 1_024, Derived_Key_Length => 32) = (16#ea#, 16#58#, 16#08#, 16#41#, 16#1e#, 16#b0#, 16#c7#, 16#e8#, 16#30#, 16#de#, 16#ab#, 16#55#, 16#09#, 16#6c#, 16#ee#, 16#58#, 16#27#, 16#61#, 16#e2#, 16#2a#, 16#9b#, 16#c0#, 16#34#, 16#e3#, 16#ec#, 16#e9#, 16#25#, 16#22#, 16#5b#, 16#07#, 16#bf#, 16#46#), "Test 8"); Assert (PBKDF2_HMAC_SHA_256 ("pass" & NUL & "word", "sa" & NUL & "lt", Iterations => 4_096, Derived_Key_Length => 16) = (16#89#, 16#b6#, 16#9d#, 16#05#, 16#16#, 16#f8#, 16#29#, 16#89#, 16#3c#, 16#69#, 16#62#, 16#26#, 16#65#, 16#0a#, 16#86#, 16#87#), "Test 9"); end PBKDF2_HMAC_SHA_256_Test; procedure PBKDF2_HMAC_SHA_512_Test (Object : in out Fixture) is begin Assert (PBKDF2_HMAC_SHA_512 ("password", "salt", Iterations => 1, Derived_Key_Length => 32) = (16#86#, 16#7f#, 16#70#, 16#cf#, 16#1a#, 16#de#, 16#02#, 16#cf#, 16#f3#, 16#75#, 16#25#, 16#99#, 16#a3#, 16#a5#, 16#3d#, 16#c4#, 16#af#, 16#34#, 16#c7#, 16#a6#, 16#69#, 16#81#, 16#5a#, 16#e5#, 16#d5#, 16#13#, 16#55#, 16#4e#, 16#1c#, 16#8c#, 16#f2#, 16#52#), "Test 1"); Assert (PBKDF2_HMAC_SHA_512 ("password", "salt", Iterations => 2, Derived_Key_Length => 32) = (16#e1#, 16#d9#, 16#c1#, 16#6a#, 16#a6#, 16#81#, 16#70#, 16#8a#, 16#45#, 16#f5#, 16#c7#, 16#c4#, 16#e2#, 16#15#, 16#ce#, 16#b6#, 16#6e#, 16#01#, 16#1a#, 16#2e#, 16#9f#, 16#00#, 16#40#, 16#71#, 16#3f#, 16#18#, 16#ae#, 16#fd#, 16#b8#, 16#66#, 16#d5#, 16#3c#), "Test 2"); Assert (PBKDF2_HMAC_SHA_512 ("password", "salt", Iterations => 4_096, Derived_Key_Length => 32) = (16#d1#, 16#97#, 16#b1#, 16#b3#, 16#3d#, 16#b0#, 16#14#, 16#3e#, 16#01#, 16#8b#, 16#12#, 16#f3#, 16#d1#, 16#d1#, 16#47#, 16#9e#, 16#6c#, 16#de#, 16#bd#, 16#cc#, 16#97#, 16#c5#, 16#c0#, 16#f8#, 16#7f#, 16#69#, 16#02#, 16#e0#, 16#72#, 16#f4#, 16#57#, 16#b5#), "Test 3"); Assert (PBKDF2_HMAC_SHA_512 ("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", Iterations => 1, Derived_Key_Length => 72) = (16#6e#, 16#23#, 16#f2#, 16#76#, 16#38#, 16#08#, 16#4b#, 16#0f#, 16#7e#, 16#a1#, 16#73#, 16#4e#, 16#0d#, 16#98#, 16#41#, 16#f5#, 16#5d#, 16#d2#, 16#9e#, 16#a6#, 16#0a#, 16#83#, 16#44#, 16#66#, 16#f3#, 16#39#, 16#6b#, 16#ac#, 16#80#, 16#1f#, 16#ac#, 16#1e#, 16#eb#, 16#63#, 16#80#, 16#2f#, 16#03#, 16#a0#, 16#b4#, 16#ac#, 16#d7#, 16#60#, 16#3e#, 16#36#, 16#99#, 16#c8#, 16#b7#, 16#44#, 16#37#, 16#be#, 16#83#, 16#ff#, 16#01#, 16#ad#, 16#7f#, 16#55#, 16#da#, 16#c1#, 16#ef#, 16#60#, 16#f4#, 16#d5#, 16#64#, 16#80#, 16#c3#, 16#5e#, 16#e6#, 16#8f#, 16#d5#, 16#2c#, 16#69#, 16#36#), "Test 4"); end PBKDF2_HMAC_SHA_512_Test; end PBKDF2.Tests;
package body AdaM.Assist.Query.find_Entities.Actuals_for_traversing is ------------- -- Post_Op -- ------------- procedure Post_Op (Element : Asis.Element; Control : in out Asis.Traverse_Control; State : in out Traversal_State) is separate; ------------ -- Pre_Op -- ------------ procedure Pre_Op (Element : Asis.Element; Control : in out Asis.Traverse_Control; State : in out Traversal_State) is separate; end AdaM.Assist.Query.find_Entities.Actuals_for_traversing;
with Ada.Text_Io; use Ada.Text_Io; procedure Counting_Sort is type Data is array (Integer range <>) of Natural; procedure Sort(Item : out Data) is begin for I in Item'range loop Item(I) := I; end loop; end Sort; Stuff : Data(1..140); begin Sort(Stuff); for I in Stuff'range loop Put(Natural'Image(Stuff(I))); end loop; New_Line; end Counting_Sort;
with Ada.Numerics.Discrete_Random; with STM32.Board; use STM32.Board; with Gfx; use Gfx; with Stack; use Stack; package body Instruction is function Fetch (Cpu : Chip8) return Opcode is Op : Opcode; begin Op := Word(Cpu.Mem(Cpu.PC)); Op := Shift_Left(Op, 8); Op := Op + Word(Cpu.Mem(Cpu.PC + 1)); return Op; end Fetch; procedure Execute (Cpu : in out Chip8; Op : Opcode) is I : Integer; begin I := Integer(Shift_Right(Op, 12)); Instr_Handlers(I)(Cpu, Op); if Cpu.Delay_Timer /= 0 then Cpu.Delay_Timer := Cpu.Delay_Timer - 1; end if; if Cpu.Sound_Timer /= 0 then Cpu.Sound_Timer := Cpu.Sound_Timer - 1; end if; end Execute; procedure Handler_0 (Cpu : in out Chip8; Op : Opcode) is N : constant Address := Op mod 16#1000#; begin case Op is when 16#00E0# => -- clear the screen Cpu.Screen := (others => (others => False)); Clear_Layer(2); Display.Update_Layer(2, True); when 16#00EE# => Cpu.PC := Pop_Stack(Cpu.Stack); when others => Cpu.PC := N; return; end case; Cpu.PC := Cpu.PC + 2; end Handler_0; procedure Handler_1 (Cpu : in out Chip8; Op : Opcode) is N : constant Address := Op mod 16#1000#; begin Cpu.PC := N; end Handler_1; procedure Handler_2 (Cpu : in out Chip8; Op : Opcode) is N : constant Address := Op mod 16#1000#; begin Push_Stack(Cpu.Stack, Cpu.PC); Cpu.PC := N; end Handler_2; procedure Handler_3 (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); N : constant Byte := Byte(Op mod 16#100#); begin if Cpu.Regs(X) = N then Cpu.PC := Cpu.PC + 2; end if; Cpu.PC := Cpu.PC + 2; end Handler_3; procedure Handler_4 (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); N : constant Byte := Byte(Op mod 16#100#); begin if Cpu.Regs(X) /= N then Cpu.PC := Cpu.PC + 2; end if; Cpu.PC := Cpu.PC + 2; end Handler_4; procedure Handler_5 (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); Y : constant Integer := Integer(Shift_Right(Op, 4) and 16#F#); begin if Cpu.Regs(X) = Cpu.Regs(Y) then Cpu.PC := Cpu.PC + 2; end if; Cpu.PC := Cpu.PC + 2; end Handler_5; procedure Handler_6 (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); N : constant Byte := Byte(Op mod 16#100#); begin Cpu.Regs(X) := N; Cpu.PC := Cpu.PC + 2; end Handler_6; procedure Handler_7 (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); N : constant Byte := Byte(Op mod 16#100#); begin Cpu.Regs(X) := Cpu.Regs(X) + N; Cpu.PC := Cpu.PC + 2; end Handler_7; procedure Handler_8 (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); Y : constant Integer := Integer(Shift_Right(Op, 4) and 16#F#); begin case Op mod 16#10# is when 0 => Cpu.Regs(X) := Cpu.Regs(Y); when 1 => Cpu.Regs(X) := Cpu.Regs(X) or Cpu.Regs(Y); when 2 => Cpu.Regs(X) := Cpu.Regs(X) and Cpu.Regs(Y); when 3 => Cpu.Regs(X) := Cpu.Regs(X) xor Cpu.Regs(Y); when 4 => if Cpu.Regs(X) > Byte'Last - Cpu.Regs(Y) then Cpu.Regs(16#F#) := 1; else Cpu.Regs(16#F#) := 0; end if; Cpu.Regs(X) := Cpu.Regs(X) + Cpu.Regs(Y); when 5 => if Cpu.Regs(X) < Cpu.Regs(Y) then Cpu.Regs(16#F#) := 1; else Cpu.Regs(16#F#) := 0; end if; Cpu.Regs(X) := Cpu.Regs(X) - Cpu.Regs(Y); when 6 => Cpu.Regs(16#F#) := Cpu.Regs(X) and 1; Cpu.Regs(X) := Shift_Right(Cpu.Regs(X), 1); when 7 => if Cpu.Regs(Y) < Cpu.Regs(X) then Cpu.Regs(16#F#) := 1; else Cpu.Regs(16#F#) := 0; end if; Cpu.Regs(X) := Cpu.Regs(Y) - Cpu.Regs(X); when 16#E# => Cpu.Regs(16#F#) := Cpu.Regs(X) and 16#80#; Cpu.Regs(X) := Shift_Left(Cpu.Regs(X), 1); when others => -- checked by the contract null; end case; Cpu.PC := Cpu.PC + 2; end Handler_8; procedure Handler_9 (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); Y : constant Integer := Integer(Shift_Right(Op, 4) and 16#F#); begin if Cpu.Regs(X) /= Cpu.Regs(Y) then Cpu.PC := Cpu.PC + 2; end if; Cpu.PC := Cpu.PC + 2; end Handler_9; procedure Handler_A (Cpu : in out Chip8; Op : Opcode) is N : constant Address := Op mod 16#1000#; begin Cpu.I := N; Cpu.PC := Cpu.PC + 2; end Handler_A; procedure Handler_B (Cpu : in out Chip8; Op : Opcode) is N : constant Address := Op mod 16#1000#; begin Cpu.PC := N + Word(Cpu.Regs(0)); end Handler_B; procedure Handler_C (Cpu : in out Chip8; Op : Opcode) is package Random_Byte is new Ada.Numerics.Discrete_Random (Byte); use Random_Byte; G : Generator; X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); N : constant Byte := Byte(Op mod 16#100#); begin Reset(G); Cpu.Regs(X) := Random(G) and N; Cpu.PC := Cpu.PC + 2; end Handler_C; procedure Handler_D (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); Y : constant Integer := Integer(Shift_Right(Op, 4) and 16#F#); Height : constant Integer := Integer(Op mod 16#10#); Pixel : Byte; begin -- Reset VF Cpu.Regs(16#F#) := 0; for Y_Line in 0 .. Height - 1 loop Pixel := Cpu.Mem(Cpu.I + Word(Y_Line)); for X_Line in 0 .. 7 loop if (Pixel and Shift_Right(16#80#, X_Line)) /= 0 then declare X_Reg : constant Integer := Integer(Cpu.Regs(X)); Y_Reg : constant Integer := Integer(Cpu.Regs(Y)); Pos_X : constant Integer := (X_Reg + X_Line) mod 64; Pos_Y : constant Integer := (Y_Reg + Y_Line) mod 32; Tmp : constant Boolean := Cpu.Screen(Pos_Y, Pos_X); begin if Tmp then Cpu.Regs(16#F#) := 1; end if; Cpu.Screen(Pos_Y, Pos_X) := Tmp xor True; Draw_Pixel(Pos_X, Pos_Y, Cpu.Screen(Pos_Y, Pos_X)); end; end if; end loop; end loop; Cpu.PC := Cpu.PC + 2; Display.Update_Layer(2, True); end Handler_D; procedure Handler_E (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); I : constant Integer := Integer(Cpu.Regs(X)); begin case Op mod 16#100# is when 16#9E# => if Cpu.Keys(I) then Cpu.PC := Cpu.PC + 2; end if; when 16#A1# => if not Cpu.Keys(I) then Cpu.PC := Cpu.PC + 2; end if; when others => -- checked by the contract null; end case; Cpu.Keys(I) := False; Cpu.PC := Cpu.PC + 2; end Handler_E; procedure Handler_F (Cpu : in out Chip8; Op : Opcode) is X : constant Integer := Integer(Shift_Right(Op, 8) and 16#F#); begin case Op mod 16#100# is when 16#07# => Cpu.Regs(X) := Cpu.Delay_Timer; when 16#0A# => for I in Cpu.Keys'Range loop if Cpu.Keys(I) then Cpu.Regs(X) := Byte(I); Cpu.Keys(I) := False; Cpu.PC := Cpu.PC + 2; return; end if; end loop; return; when 16#15# => Cpu.Delay_Timer := Cpu.Regs(X); when 16#18# => Cpu.Sound_Timer := Cpu.Regs(X); when 16#1E# => Cpu.I := Cpu.I + Word(Cpu.Regs(X)); when 16#29# => Cpu.I := Word(Cpu.Regs(X)) * 5; when 16#33# => Cpu.Mem(Cpu.I) := Cpu.Regs(X) / 100; Cpu.Mem(Cpu.I + 1) := Cpu.Regs(X) / 10 mod 10; Cpu.Mem(Cpu.I + 2) := Cpu.Regs(X) mod 10; when 16#55# => for I in Cpu.Regs'First .. X loop Cpu.Mem(Cpu.I + Word(I)) := Cpu.Regs(I); pragma Loop_Invariant (I in Cpu.Regs'Range); pragma Loop_Invariant (for all J in Cpu.Regs'First .. I => Cpu.Mem(Cpu.I + Word(J)) = Cpu.Regs'Loop_Entry(J)); end loop; when 16#65# => for I in Cpu.Regs'First .. X loop Cpu.Regs(I) := Cpu.Mem(Cpu.I + Word(I)); pragma Loop_Invariant (I in Cpu.Regs'Range); pragma Loop_Invariant (for all J in Cpu.Regs'First .. I => Cpu.Regs(J) = Cpu.Mem'Loop_Entry(Cpu.I + Word(J))); end loop; when others => -- check by the contract null; end case; Cpu.PC := Cpu.PC + 2; end Handler_F; end Instruction;