<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AdaCore - The GNAT Pro Company &#187; Development Log</title>
	<atom:link href="http://www.adacore.com/category/developers-center/development-log/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adacore.com</link>
	<description>AdaCore technology and news</description>
	<lastBuildDate>Sun, 14 Mar 2010 08:49:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Gem #81: GNAT Semaphores</title>
		<link>http://www.adacore.com/2010/03/08/gem-81/</link>
		<comments>http://www.adacore.com/2010/03/08/gem-81/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 11:00:42 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Ada / Ada 2005]]></category>
		<category><![CDATA[Development Log]]></category>
		<category><![CDATA[Devt log - Gem of the Week]]></category>

		<guid isPermaLink="false">http://www2.adacore.com/?p=3689</guid>
		<description><![CDATA[Ada Gem #81 &#8212; A previous Gem (#70, "The Scope Lock Idiom") discussed the occasional necessity of using low-level synchronization mechanisms instead of the higher-level protected object construct.  The code in that Gem referenced the facilities of the Semaphores package located in the GNAT hierarchy.  In this Gem, we examine the abstractions provided by that package, focusing especially on the design choices. ]]></description>
			<content:encoded><![CDATA[<h3>Let&#8217;s get started&#8230;</h3><br/>


<p>A number of semaphore definitions exist, although the general concept remains as introduced by Dijkstra in 1968.  We assume the reader has some familiarity with semaphores and their semantics, and so we will not cover them here.  Many books are available for those requiring additional information. See especially <em>Principles of Concurrent and Distributed Programming</em> by M. Ben-Ari.</p>



<p>The GNAT.Semaphores package defines two semaphore abstractions, both in terms of protected types.  We use protected types, rather than defining abstract data types based on operating-system facilities, for the sake of portability.  A simple wrapper around the facilities of an operating system or RTOS would be reasonable, but the resulting interface (and implementation, of course) would not have the portability required of the general-purpose GNAT hierarchy.</p>



<p>The first abstraction defines a &#8220;counting&#8221; semaphore, in which an integer count is maintained by the operations, such that the acquire operation only executes (and thus returns, allowing the caller to continue) when the count is greater than zero.  Counting semaphores are convenient for expressing condition synchronization in terms of the availability of some number of resources.  For example, with a circular bounded buffer, a semaphore&#8217;s count can represent the number of available buffer slots.  Callers must wait for the buffer to be non-full when attempting to insert a new item, and the blocking call to acquire the semaphore will achieve that effect directly.</p>



<p>The declaration for the counting semaphore is as follows.  Note that we have removed the in-line comments for the sake of brevity, but will cover their content.</p>

<pre>
   <b>protected</b> <b>type</b> Counting_Semaphore
      (Initial_Value : Natural;
      Ceiling : System.Priority)
   <b>is</b>
      <b>pragma</b> Priority (Ceiling);

      <b>entry</b> Seize;
      <b>procedure</b> Release;

   <b>private</b>
      Count : Natural := Initial_Value;
   <b>end</b> Counting_Semaphore;
</pre>


<p>The second type implements &#8220;binary&#8221; semaphores.  This kind of semaphore is less flexible than the counting semaphore, in that no notion of a count is maintained.  The abstraction is simply that of a flag indicating whether or not the semaphore is available.  (If the value of a counting semaphore varied between zero and one, the effect would be the same.)</p>

<pre>
   <b>protected</b> <b>type</b> Binary_Semaphore
     (Initially_Available : Boolean;
      Ceiling : System.Priority)
   <b>is</b>
      <b>pragma</b> Priority (Ceiling);

      <b>entry</b> Seize;
      <b>procedure</b> Release;

   <b>private</b>
      Available : Boolean := Initially_Available;
   <b>end</b> Binary_Semaphore;
</pre>



<p>In both cases, the provided operations consist of an entry &#8220;Seize&#8221; to acquire the semaphore with mutually exclusive access, and a protected procedure &#8220;Release&#8221; to release it.  The Seize operation must be an entry for the sake of the barrier expressing the required condition synchronization.  Releasing the semaphore has no such requirement, so it need not be an entry.</p>



<p>Both types are visibly defined as protected types so that users can make conditional and timed calls when appropriate.  This capability addresses one of the portability problems with semaphores.  Although the basic &#8220;acquire&#8221; and &#8220;release&#8221; operations will always be provided (by whatever name), there is no &#8220;standard&#8221; interface for other forms of interaction.  Language-defined constructs provide some of those kinds of interactions, and do so portably.</p>



<p>Both types require discriminants.  The counting semaphore type uses a discriminant to specify the initial nonnegative value of the count.  The binary semaphore type uses a Boolean discriminant to specify whether the semaphore should be initially available.  For example, a binary semaphore would be initially available when used to express mutual exclusion, but might not be initially available when used to express condition synchronization.</p>



<p>In addition, both types use another discriminant to specify the ceiling priority for objects of the type. The discriminant is then passed as the argument to pragma Priority.  If the Real-Time Systems Annex is in force this part is essential; otherwise it has no effect.  Note that a default value cannot be provided for the Ceiling discriminant because that would require a default for the other discriminant, too.  The best we can do is to define a convenient value to be used in declarations of individual objects when the Real-Time Annex is not in force, so the following constant is provided in GNAT.Semaphores:</p>

<pre>
   Default_Ceiling : <b>constant</b> System.Priority := System.Default_Priority;
</pre>


<p>However, subtypes can be used to enhance convenience, readability and robustness.  The earlier Gem (#70) provided an example:</p>

<pre>
   <b>subtype</b> Mutual_Exclusion <b>is</b> Binary_Semaphore
     (Initially_Available =&gt; True,
      Ceiling             =&gt; Default_Ceiling);
</pre>


<p>The subtype ensures that corresponding objects are initially available, but also conveniently supplies the Ceiling discriminant value (assuming the Real-Time Annex is not in force) and gives the reader an indication of the intended use.</p>



<p>As you can see, the declarations of protected types can be very expressive.  The discriminants are the part you might not have considered using, although that is by no means an unusual approach. The protected bodies of both types are trivial and will not be shown here.  You can see them in the GNAT hierarchy, along with the implementations of all the other GNAT hierarchy packages.</p>]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/03/08/gem-81/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[GPS] Better external run under Windows</title>
		<link>http://www.adacore.com/2010/03/05/NF-45-J120-032-gps/</link>
		<comments>http://www.adacore.com/2010/03/05/NF-45-J120-032-gps/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 12:00:00 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[GPS]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[  Under Windows, running commands under an external terminal now keeps the
  terminal open after execution.
]]></description>
			<content:encoded><![CDATA[  Under Windows, running commands under an external terminal now keeps the
  terminal open after execution.
]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/03/05/NF-45-J120-032-gps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[GNAT] More efficient packed array indexing on AAMP target</title>
		<link>http://www.adacore.com/2010/03/02/NF-64-C318-011-gnat/</link>
		<comments>http://www.adacore.com/2010/03/02/NF-64-C318-011-gnat/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 12:00:00 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[GNAT Compilation System]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[   The GNAAMP compiler now generates more efficient code sequences for indexing
   of packed arrays with component sizes of 1, 2, and 4 bits.
]]></description>
			<content:encoded><![CDATA[   The GNAAMP compiler now generates more efficient code sequences for indexing
   of packed arrays with component sizes of 1, 2, and 4 bits.
]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/03/02/NF-64-C318-011-gnat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[PolyORB] Allow CORBA.Any to be used at library level</title>
		<link>http://www.adacore.com/2010/02/27/NF-27-J225-018-polyorb/</link>
		<comments>http://www.adacore.com/2010/02/27/NF-27-J225-018-polyorb/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 12:00:00 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[PolyORB]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[   Objects of CORBA.Any type can be declared at library level now, and
   be elaborated before initialization of ORB.
]]></description>
			<content:encoded><![CDATA[   Objects of CORBA.Any type can be declared at library level now, and
   be elaborated before initialization of ORB.
]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/02/27/NF-27-J225-018-polyorb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gem #80: Speedy Shift and Rotate in SPARK</title>
		<link>http://www.adacore.com/2010/02/25/gem-80/</link>
		<comments>http://www.adacore.com/2010/02/25/gem-80/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 13:50:16 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Ada / Ada 2005]]></category>
		<category><![CDATA[Development Log]]></category>
		<category><![CDATA[Devt log - Gem of the Week]]></category>

		<guid isPermaLink="false">http://www2.adacore.com/?p=3502</guid>
		<description><![CDATA[Ada Gem #80 &#8212; This Gem covers a topic that I recently encountered
while working on a crypto algorithm in SPARK: how
to use Ada's predefined shift and rotate functions
with modular types from a SPARK program.]]></description>
			<content:encoded><![CDATA[<h3>Let&#8217;s get started&#8230;</h3><br/>

<p><strong>Introduction</strong></p>


<p>Ada 95 brought us the predefined package Interfaces, with its standard
definitions for types like Unsigned_32 and so on.
It also defines various functions to do common
shift and rotate operations on those types, such as:</p>

<pre>
   <b>function</b> Shift_Left
     (Value  : Unsigned_32;
      Amount : Natural) <b>return</b> Unsigned_32;
</pre>


<p>In GNAT Pro, these function declarations are
also followed by a curious-looking pragma:</p>

<pre>
   <b>pragma</b> Import (Intrinsic, Shift_Left);
</pre>


<p>The Ada 95 RM (6.3.1) says:</p>



<p>   &#8216;The intrinsic calling convention represents subprograms that
    are &#8220;built in&#8221; to the compiler.&#8217;</p>



<p>This basically means that the code generator &#8220;knows&#8221; how
to implement these functions. In the case of shifts and rotates,
this means that a call to one of these functions results in
very few (possibly just one) machine instructions &#8212; giving the
performance you&#8217;d expect from such a simple operation.</p>



<p>Shifts and rotates are useful in a wide variety of applications, 
but are endemic in cryptographic algorithms, where they
appear all over the place.</p>



<strong><p>So how can we get at them in SPARK?</p></strong>


<p>Unfortunately, the standard specification of package Interfaces
is not legal SPARK, since the various shift and rotate functions
are overloaded for each of the modular types, and overloading
within a scope is not allowed.  Darn&#8230;</p>



<p>To get round this, we first introduce a &#8220;shadow&#8221; specification
of Interfaces that supplies the legal SPARK bits that
we&#8217;re interested in &#8212; specifically the type declarations,
thus:</p>

<pre>
   <b>package</b> Interfaces <b>is</b>
      <b>type</b> Unsigned_8  <b>is</b> <b>mod</b> 2**8;
      <b>type</b> Unsigned_16 <b>is</b> <b>mod</b> 2**16;
      <b>type</b> Unsigned_32 <b>is</b> <b>mod</b> 2**32;
      <b>type</b> Unsigned_64 <b>is</b> <b>mod</b> 2**64;
   <b>end</b> Interfaces;
</pre>


<p>This is legal SPARK, and goes in a file called
interfaces.shs.  We then use the Examiner&#8217;s index-file
mechanism to make sure that the Examiner sees
this version of the package specification.</p>



<p>To get at the shift and rotate functions, we need
to introduce a new package that &#8220;de-overloads&#8221;
the names.  Let&#8217;s call this package &#8220;SR&#8221; &#8212; this is
also a &#8220;shadow&#8221;, so it goes in sr.shs or a similar file.
It looks like this:</p>

<pre>
   <b>with</b> Interfaces;
   <EM>&#45;&#45;# inherit Interfaces;</EM>
   <b>package</b> SR <b>is</b>

      <b>function</b> Rotate_Left_16
        (Value  : Interfaces.Unsigned_16;
         Amount : Natural) <b>return</b> Interfaces.Unsigned_16;

      <b>function</b> Rotate_Left_32
        (Value  : Interfaces.Unsigned_32;
         Amount : Natural) <b>return</b> Interfaces.Unsigned_32;

      <EM>&#45;&#45; ...and so on for all required functions...</EM>
   <b>end</b> SR;
</pre>


<p>Note how we removed the overloading of the function names.</p>



<p>OK&#8230; so how do we glue package SR to the
predefined intrinsic functions in package Interfaces?</p>



<p>It&#8217;s tempting to just implement the body of SR (in Ada, not SPARK)
to &#8220;call through&#8221; to the appropriate function in Interfaces,
but this might involve the overhead of a full-blown
function call/return sequence, losing all that juicy performance
that the intrinsic functions give us.  We could try using
pragma Inline to get rid of that overhead, but, as car
salesmen say, &#8220;your mileage may vary&#8221; with that idea.</p>



<p>Fortunately, there is a way out that preserves the
efficiency of the intrinsic version.  Remember that the
specification of SR above is a shadow?  We supply
the following slightly different version to the
compiler in sr.ads:</p>

<pre>
   <b>with</b> Interfaces;
   <b>package</b> SR <b>is</b>

      <b>function</b> Rotate_Left_16
        (Value  : Interfaces.Unsigned_16;
         Amount : Natural) <b>return</b> Interfaces.Unsigned_16 <b>renames</b> Interfaces.Rotate_Left;

      <b>function</b> Rotate_Left_32
        (Value  : Interfaces.Unsigned_32;
         Amount : Natural) <b>return</b> Interfaces.Unsigned_32 <b>renames</b> Interfaces.Rotate_Left;

      <EM>&#45;&#45; ...and so on</EM>
   <b>end</b> SR;
</pre>


<p>The renaming here ensures that our SPARK-friendly &#8220;un-overloaded&#8221; functions
are synonymous with the intrinsic &#8220;built in&#8221; functions, getting us
the best of both worlds &#8212; the type safety of SPARK, with the efficiency
of intrinsic machine code!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/02/25/gem-80/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[GPS] Better handling of incomplete with/use clauses</title>
		<link>http://www.adacore.com/2010/02/25/NF-45-J225-017-gps/</link>
		<comments>http://www.adacore.com/2010/02/25/NF-45-J225-017-gps/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 12:00:00 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[GPS]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[  The outline and smart completion will now work correctly even when the user
  is in the process of writing use and with clauses, and the file is parsed
  before the clause is completely written.
]]></description>
			<content:encoded><![CDATA[  The outline and smart completion will now work correctly even when the user
  is in the process of writing use and with clauses, and the file is parsed
  before the clause is completely written.
]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/02/25/NF-45-J225-017-gps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[GPS] Quick fix icons on the side of editors</title>
		<link>http://www.adacore.com/2010/02/25/NF-45-J208-006-gps/</link>
		<comments>http://www.adacore.com/2010/02/25/NF-45-J208-006-gps/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 12:00:00 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[GPS]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[  When compiling, icons that propose automatic code fixing appear on the side
  of the source editors, in addition to the Locations View.
]]></description>
			<content:encoded><![CDATA[  When compiling, icons that propose automatic code fixing appear on the side
  of the source editors, in addition to the Locations View.
]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/02/25/NF-45-J208-006-gps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating static analysis with a compiler and database</title>
		<link>http://www.adacore.com/2010/02/25/integrating-static-analysis-with-a-compiler-and-database-2/</link>
		<comments>http://www.adacore.com/2010/02/25/integrating-static-analysis-with-a-compiler-and-database-2/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 08:42:56 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Ada / Ada 2005]]></category>
		<category><![CDATA[Development Log]]></category>
		<category><![CDATA[codepeer]]></category>
		<category><![CDATA[static analysis]]></category>

		<guid isPermaLink="false">http://www2.adacore.com/?p=3684</guid>
		<description><![CDATA[
In this article published in Embedded Computing Design, S. Tucker Taft looks at the advantages of integrating static analysis with a compiler and a database:



&#8220;Static analysis tools are becoming more integrated into the software development process. Saving data from the compiler, change history, and error information during the process instead of as a post-code step [...]]]></description>
			<content:encoded><![CDATA[
<p>In this article published in <a href="http://embedded-computing.com/" target="_blank">Embedded Computing Design</a>, S. Tucker Taft looks at the advantages of integrating static analysis with a compiler and a database:<br/>
<br/>


&#8220;Static analysis tools are becoming more integrated into the software development process. Saving data from the compiler, change history, and error information during the process instead of as a post-code step can make static analysis more productive.&#8221; </p>


<p>The full article can be found at:<br/>

<a href="http://embedded-computing.com/integrating-static-analysis-a-compiler-database">http://embedded-computing.com/integrating-static-analysis-a-compiler-database</a></p>

]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/02/25/integrating-static-analysis-with-a-compiler-and-database-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[GNAT] Order of symbols in SALs on VMS</title>
		<link>http://www.adacore.com/2010/02/24/NF-64-J211-022-gnat/</link>
		<comments>http://www.adacore.com/2010/02/24/NF-64-J211-022-gnat/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 12:00:00 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[GNAT Compilation System]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[   To allow the exported symbols of an extended Stand-Alone Library on VMS
   to be the same as the SAL being extended, the object files are now processed
   in increasing alphabetical order when looking for the exported symbols.
]]></description>
			<content:encoded><![CDATA[   To allow the exported symbols of an extended Stand-Alone Library on VMS
   to be the same as the SAL being extended, the object files are now processed
   in increasing alphabetical order when looking for the exported symbols.
]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/02/24/NF-64-J211-022-gnat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[GPS] Support for interfaces in completion</title>
		<link>http://www.adacore.com/2010/02/24/NF-45-I702-007-gps/</link>
		<comments>http://www.adacore.com/2010/02/24/NF-45-I702-007-gps/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 12:00:00 +0000</pubDate>
		<dc:creator>AdaCore</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[GPS]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[  On completion like Iface., Iface being typed after an interface, all
  primitives will now be offered by the completion, even the ones coming from
  multiple inheritance.
]]></description>
			<content:encoded><![CDATA[  On completion like Iface., Iface being typed after an interface, all
  primitives will now be offered by the completion, even the ones coming from
  multiple inheritance.
]]></content:encoded>
			<wfw:commentRss>http://www.adacore.com/2010/02/24/NF-45-I702-007-gps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
