❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

Building a runtime system for arm-eabi

AdaCore provide a compiler (running on Windows and Linux) targeted to ARM (target arm-eabi) and a runtime system (RTS) supporting the Ravenscarprofile.

The public version of the AdaCore Ravenscar RTS is released under the full GPL. It seemed as if it would be a good idea (and fun!) to produce an independent RTS with the GCC Runtime Library Exception(FAQ).

Read more Β»

GCC 6.1 Ada Compiler From Scratch

29 April 2016 at 12:35

We will do the following tasks:

  1. The binutils build and installation,
  2. The gcc build and installation,
  3. Setting up a default configuration for gprbuild,
  4. The XML/Ada build and installation,
  5. The gprbuild build and installation.

Pre-requisites

First, prepare three distinct directories for the sources, the build materials and the installation. Make sure you have more than 1.5G for the source directory, reserve 7.0G for the build directory and arround 1.5G for the installation directory.

To simplify the commands, define the following shell variables:

BUILD_DIR=<Path of build directory>
INSTALL_DIR=<Path of installation directory>
SRC_DIR=<Path of directory containing the extracted sources>

Also, check that:

  • You have a GNAT Ada compiler installed (at least a 4.9 I guess).
  • You have the gprbuild tool installed and configured for the Ada compiler.
  • You have libmpfr-dev, libgmp3-dev and libgmp-dev installed (otherwise this is far more complex).
  • You have some time and can wait for gcc's compilation (it took more than 2h for me).

Create the directories:

mkdir -p $BUILD_DIR
mkdir -p $INSTALL_DIR/bin
mkdir -p $SRC_DIR

And setup your PATH so that you will use the new binutils and gcc commands while building everything:

export PATH=$INSTALL_DIR/bin:/usr/bin:/bin

Binutils

Download binutils 2.26 and extract the tar.bz2 in the source directory $SRC_DIR.

cd $SRC_DIR
tar xf binutils-2.26.tar.bz2

Never build the binutils within their sources, you must use the $BUILD_DIR for that. Define the installation prefix and configure the binutils as this:

mkdir $BUILD_DIR/binutils
cd $BUILD_DIR/binutils
$SRC_DIR/binutils-2.26/configure --prefix=$INSTALL_DIR

And proceed with the build in the same directory:

make

Compilation is now complete you can install the package:

make install

Gcc

Download gcc 6.1.0 and extract the tar.bz2 in the source directory $SRC_DIR.

cd $SRC_DIR
tar xf gcc-6.1.0.tar.bz2

Again, don't build gcc within its sources and use the $BUILD_DIR directory. At this stage, it is important that your PATH environment variable uses the $INSTALL_DIR/bin first to make sure you will use the new installed binutils tools. You may add the --disable-bootstrap to speed up the build process.

mkdir $BUILD_DIR/gcc
cd $BUILD_DIR/gcc
$SRC_DIR/gcc-6.1.0/configure --prefix=$INSTALL_DIR --enable-languages=c,c++,ada

And proceed with the build in the same directory (go to the restaurant or drink a couple of beers while it builds):

make

Compilation is now complete you can install the package:

make install

The Ada compiler installation does not install two symbolic links which are required during the link phase of Ada libraries and programs. You must create them manually after the install step:

ln -s libgnarl-6.so $INSTALL_DIR/lib/gcc/x86_64-pc-linux-gnu/6.1.0/adalib/libgnarl-6.1.so
ln -s libgnat-6.so $INSTALL_DIR/lib/gcc/x86_64-pc-linux-gnu/6.1.0/adalib/libgnat-6.1.so

Setup the default.cgpr file

The gnatmake command has been deprecated and it is now using gprbuild internally. This means we need a version of gprbuild that uses the new compiler. One way to achieve that is by setting up a gprbuild configuration file:

cd $BUILD_DIR
gprconfig

Select the Ada and C compiler and then edit the default.cgpr file that was generated to change the Toolchain_Version, Runtime_Library_Dir, Runtime_Source_Dir, Driver to indicate the new gcc 6.1 installation paths (replace <INSTALL_DIR> with your installation directory):

configuration project Default is
   ...
   for Toolchain_Version     ("Ada") use "GNAT 6.1";
   for Runtime_Library_Dir   ("Ada") use "<INSTALL_DIR>/lib/gcc/x86_64-pc-linux-gnu/6.1.0//adalib/";
   for Runtime_Source_Dir    ("Ada") use "<INSTALL_DIR>/lib/gcc/x86_64-pc-linux-gnu/6.1.0//adainclude/";
   package Compiler is
      for Driver ("C") use "<INSTALL_DIR>/bin/gcc";
      for Driver ("Ada") use "<INSTALL_DIR>/bin/gcc";
      ...
   end Compiler;
   ...
end Default;

This is the tricky part because if you missed it you may end up using the old Ada compiler. Make sure the Runtime_Library_Dir and Runtime_Source_Dir are correct otherwise you'll have problems during builds. As far as I'm concerned, the gcc target triplet was also changed from x86_64-linux-gnu to x86_64-pc-linux-gnu. Hopefully, once we have built a new gprbuild everything will be easier. The next step is to build XML/Ada which is used by gprbuild.

XML/Ada

Download and extract the XML/Ada sources. Using the git repository works pretty well:

cd $BUILD_DIR
git clone https://github.com/AdaCore/xmlada.git xmlada

This time we must build within the sources. Before running the configure script, the default.cgpr file is installed so that the new Ada compiler is used:

cp $BUILD_DIR/default.cgpr $BUILD_DIR/xmlada/
cd $BUILD_DIR/xmlada
./configure --prefix=$INSTALL_DIR

And proceed with the build in the same directory:

make static shared

Compilation is now complete you can install the package:

make install-static install-relocatable

gprbuild

Get the gprbuild sources from the git repository:

cd $BUILD_DIR
git clone https://github.com/AdaCore/gprbuild.git gprbuild

Copy the default.cgpr file to the gprbuild source tree and run the configure script:

cp $BUILD_DIR/default.cgpr $BUILD_DIR/gprbuild/
cd $BUILD_DIR/gprbuild
./configure --prefix=$INSTALL_DIR

Setup the ADA_PROJECT_PATH environment variable to use the XML/Ada library that was just compiled. If you miss this step, you'll get a file dom.ali is incorrectly formatted error during the bind process.

export ADA_PROJECT_PATH=$INSTALL_DIR/lib/gnat

And proceed with the build in the same directory:

make

Compilation is now complete you can install the package:

make install

Using the compiler

Now you can remove the build directory to make some space. You'll not need the default.cgpr file anymore nor define the ADA_PROJECT_PATH environment variable (except for other needs). To use the new Ada compiler you only need to setup your PATH:

export PATH=$INSTALL_DIR/bin:/usr/bin:/bin

You're now ready to play and use the GCC 6.1 Ada Compiler.

The application is damaged and can't be opened

I downloaded a new version of eclipseArduino(Arduino development within Eclipse). After unpacking and moving to /Applications, I get the message

"eclipseArduino" is damaged and can't be opened. You should move it to the Trash.

Huh.

After a lot of poking around, I found this:

  1. Open Gatekeeper settings located in System Preferences > Security & Privacy.
  2. Set Allow applications downloaded from: to Anywhereand confirm by pressing Allow From Anywhere.
  3. Run the application.
  4. Once the application has been successfully launched, it no longer goes through Gatekeeper; so, restore Gatekeeper settings to the default option Mac App Store and identified developers after successfully launching the application.

Mojave vs. GDB

Apple's software development tools are based on LLVM, and Apple don't seem to feel it necessary to keep GCC and friends up to date with changes in the Apple tools or security policies.

GDB has been particularly affected by this. You can see why a tool which is capable of interacting with running programs would have to be treated with caution.

Read more Β»

Mojave vs. GCC

After you've installed Xcode (or, my preference, the Command Line Tools via xcode-select -install) so that you can install and use GNAT, you may expect to be able to compile C code too.

Mojave may surprise you with

$ gcc casing.c -o casing
casing.c:1:10: fatal error: stdio.h: No such file or directory
    1 | #include <stdio.h>
      |          ^~~~~~~~~
      compilation terminated.

The reason, according to this question and its answers, is that Apple's developer tools, in particular the clang compiler, know where to find the include files under /Library/Developer; GCC doesn't (I'm sure it could be made to, but ...) and so we have to add an extra step to install them in the normal place:

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Password:
installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path /
installer: The install was successful.
You may need to repeat this after macOS or Command Line Tools (or Xcode) updates.

HAC - recursive maze generator demo

28 May 2020 at 19:53
New example/demo, adapted from Rosetta Code's recursive maze generator.
HAC's Web site isΒ here, source code is mirroredΒ here.
Behind the scenes, the compiler was improved a little bit for displaying fixed-sized strings.

C:\Ada\hac\exm>..\hax -v2 maze_gen.adb

*******[ HAX ]******* Compiler version: 0.061 dated 28-May-2020.
*******[ HAX ]******* Caution: HAC is not a real Ada compiler. Type "hax" for license.
. . . .[ HAX ]. . . . Compiling from file: maze_gen.adb
. . . .[ HAX ]. . . . Compilation finished in 0.000414700 seconds.
. . . .[ HAX ]. . . . Starting p-code VM interpreter...
Height: 15, Width: 24
Starting generation at 7, 12
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | | | |
+ +---+ +---+---+ + +---+ +---+ +---+---+ + + + + +---+---+---+---+---+ +
| | | | | | | | | | | | | | |
+---+ +---+ +---+ + +---+---+ + + +---+---+---+ + +---+---+ + +---+ +---+
| | | | | | | | | | | |
+ +---+ +---+---+---+ +---+ + + +---+---+---+ + +---+ +---+ + +---+---+ +
| | | | | | | | | | | | | | |
+ +---+ + + + + + + +---+---+ + + + +---+ +---+ +---+ +---+---+ +
| | | | | | | | | | | | | | | | | | |
+---+ + + + +---+ + + + + + + + +---+ +---+ + + + + +---+ +
| | | | | | | | | | | | | | | | |
+ +---+ +---+---+ + + +---+ + +---+ + + +---+ +---+---+ +---+ + +---+
| | | | | | X | | | | | | | | |
+ + +---+---+ +---+---+ + +---+---+ + + + + + +---+ +---+ +---+ + +
| | | | | | | | | | | | | | | | |
+ +---+ + +---+---+ +---+---+---+ +---+---+ +---+ +---+ +---+---+ + + + +
| | | | | | | | | |
+ + +---+ + +---+---+ +---+---+---+ + +---+ + +---+---+ +---+---+---+---+ +
| | | | | | | | | | | | | | |
+ + + + + + + + + + +---+ + + +---+---+---+ +---+---+---+---+ +---+
| | | | | | | | | | | | | |
+---+ + + +---+---+---+---+ +---+ +---+ + + + + +---+---+---+---+ +---+ +
| | | | | | | | | | | | |
+ +---+---+---+ +---+---+ +---+ + + +---+ +---+ +---+---+---+ +---+---+ + +
| | | | | | | | | | |
+ + +---+---+---+---+ +---+---+---+ +---+---+---+ + +---+---+---+---+ +---+---+ +
| | | | | | | | | | | | |
+ + + + + + + +---+ + +---+---+---+ + +---+---+---+ +---+ + +---+ +
| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
-------[ HAX ]------- VM interpreter done after 0.080759500 seconds.

C:\Ada\hac\exm>

HAC v.0.07 - Exceptions and trace-backs

1 June 2020 at 14:35
Since yesterday, errors are propagated by HAC, as expected, down the call stack.
You get by default a detailed trace-back, like the following one. HAC's output is:
  HAC VM: raised Constraint_Error
Out of range
Trace-back locations:
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 18
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 16
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 16
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 16
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift.Shift_n_add at line 16
exception_04.adb: Exception_04.Nest.NTF.Add_n_shift at line 23
exception_04.adb: Exception_04.Nest.NTF at line 27
exception_04.adb: Exception_04.Nest at line 34
exception_04.adb: Exception_04 at line 42
GNAT's output on the same program is:
  raised CONSTRAINT_ERROR : exception_04.adb:18 range check failed
[C:\Ada\hac\test\exception_04.exe]
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:18
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:16
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:16
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:16
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf.Add_N_Shift.Shift_N_Add at exception_04.adb:16
Exception_04.Nest.Ntf.Add_N_Shift at exception_04.adb:23
Exception_04.Nest.Ntf at exception_04.adb:27
Exception_04.Nest at exception_04.adb:34
Exception_04 at exception_04.adb:42
Main at b__exception_04.adb:294

You can look in the "test" directory at the files "exception_01.adb", "exception_02.adb", ... for playing with some examples.

HAC (HAC Ada Compiler) is available on two open-source development sites:

Β Β https://hacadacompiler.sourceforge.io/
Β Β https://github.com/zertovitch/hac

HAC is a small, quick, open-source Ada compiler, covering a subset of the Ada language.
Even though the HAC documentation is more or less non-existent, the good news is that you can use as a help Ada books and online documentation about Ada: HAC does not define a dialect of Ada, only a subset. A glimpse into the file "src/hac_pack.ads" gives you the currently available types and subprograms.

Enjoy!

LEA 0.71 - exception trace-back

3 June 2020 at 18:31
Following the implementation of trace-backs in HAC, this feature is now included in the LEA editor.

Better showing an example. Suppose your Ada program has a bug that was not detected at compile-time (it happens sometimes), like an array index being out-of-range. In this case HAC will raise a Constraint_Error exception (as expected from any Ada system).



Once you have closed the message box about the unhandled exception, the message list will display the trace-back, that is the chain of all subprogram calls at the moment the error has happened. Here we have an example with recursive calls, and the error was planted for the moment where the parameter Level is 0.
For your comfort, you can click on a line of the trace-back and LEA will find the correct file and the correct line as well!



Here is a link to LEA: https://l-e-a.sourceforge.io/.
You can download a read-to-use Windows executable there.

The LEA sources are available on the above site as well as on GitHub: https://github.com/zertovitch/lea .

Furthermore, the sources for the HAC system are located at
Β  Β  https://hacadacompiler.sourceforge.io/
and
Β  Β  https://github.com/zertovitch/hac .

Enjoy!


HAC v.0.072 - Subtype Indication

7 June 2020 at 19:44
One more step in our adventures in compiler construction...
Recently, we've moved the parsing of ranges to a new package, HAC.Parser.Ranges.
One chunk was about static ranges like "1 .. 5" for defining arrays.
The second chunk was the dynamic ranges in FOR loops (like in "for i in j + k .. l * 2 loop").
It was logical to put both pieces in the same package, especially since the Ada standard has a much more general definition: discrete_subtype_definition (RM 3.6 (6)).
Of course, with HAC, we don't try to implement the full standard or even the full dynamic aspects of a single syntactical element like discrete_subtype_definition, which allows constructs like this one:
    procedure SD3 is
begin
for I in 1 .. 3 loop
declare
type T1 is new Integer range 1 .. I * 5; -- I is dynamic
subtype T2 is T1 range 1 .. T1 (I);
type T3 is array (1 .. 2 * I) of T2;
type T4 is array (1 .. 3 * I) of T3;
B: T4;
begin
null;
end;
end loop;
end;

We prefer to add piece by piece features we find cool in Ada.
For instance, the subtype_indication (RM 3.2.2).
Again, something that sounds very bureaucratic, but what it represents is a very powerful shortcut:
Instead of writing
    x : array (False .. True) of Integer;

you can write in a nicer way:
    x : array (Boolean) of Integer;

same for loops:
    for b in Boolean loop
x (b) := ...
end loop;
As an illustration, here is an excerpt of the before/after comparison on one of the HAC examples:

Click to enlarge

LEA 0.74 - embedded Ada samples collection

27 June 2020 at 20:23
From now on, LEA has got the uber-gadget: a samples collection.
Are you looking for an example to start a script, or an algorithm, or some other inspiration?
The menu selection "Actions β†’ Code sample" will offer you a choice of programs of various sizes.
Actually, they are examples from the HAC project (the HAC compiler is embedded in LEA).
You don't even need to fish those examples in the Internet: they are embedded within LEA as well.
In a few clicks, an example will pop in a LEA window and you can run it immediately.

LEAΒ (Lightweight Editor for Ada) is a free, open-source software. It can be found here.

Feedback is appreciated.
Don't hesitate to sponsor the project with a small donation (from the link above: "Donate" link).

Enjoy!

New menu entry: Code sample (click to enlarge image)

Sample selector (click to enlarge image)

❌
❌