Code Examples

Home Products Sales Support Contacting Us Library Search

 

To demonstrate the quality of the generated code, we list the following examples. The code generation option used were "-O2 -gnatp", which mean optimize to level 2 and suppress checks.

Ada source Generated code
procedure T0 is
begin
   null;
end T0;
 
   1                            .file  "t0.adb"
   2                    gcc2_compiled.:
   3                    __gnu_compiled_ada:
   4                            .text
   5                    .global _ada_t0
   6                    _ada_t0:
   7 0000 7FF0                  urs    r15
 
with Interfaces;
package body t2 is
   use Interfaces;

   Bits : constant array (1 .. 16) of Unsigned_16 := (
      2#1000000000000000#, 2#0100000000000000#,
      2#0010000000000000#, 2#0001000000000000#,
      2#0000100000000000#, 2#0000010000000000#,
      2#0000001000000000#, 2#0000000100000000#,
      2#0000000010000000#, 2#0000000001000000#,
      2#0000000000100000#, 2#0000000000010000#,
      2#0000000000001000#, 2#0000000000000100#,
      2#0000000000000010#, 2#0000000000000001#);

   Word : Unsigned_16 := 0;


   procedure Search (Max : Unsigned_16) is
   begin
      for i in Unsigned_16 range 0 .. Max loop
         declare
            Tmp : Unsigned_16 := i;
            B : Natural := 1;
         begin
            while (Tmp and 1) /= 0 loop
               Tmp := Shift_Right (Tmp, 1);
               B := B + 1;
            end loop;

            Word := Word xor Bits (B);
         end;
      end loop;
   end Search;

end t2;

   1                            .file  "t2.adb"
   2                    gcc2_compiled.:
   3                    __gnu_compiled_ada:
   4                    .global t2_E
   5                            .data
   6                    t2_E:
   7 0000 0000                  .word  0
   8                            .section .rdata,"r"
   9                    .LC0:
  10 0000 8000                  .word  -32768
  11 0002 4000                  .word  16384
  12 0004 2000                  .word  8192
  13 0006 1000                  .word  4096
  14 0008 0800                  .word  2048
  15 000a 0400                  .word  1024
  16 000c 0200                  .word  512
  17 000e 0100                  .word  256
  18 0010 0080                  .word  128
  19 0012 0040                  .word  64
  20 0014 0020                  .word  32
  21 0016 0010                  .word  16
  22 0018 0008                  .word  8
  23 001a 0004                  .word  4
  24 001c 0002                  .word  2
  25 001e 0001                  .word  1
  26                            .data
  27                    word:
  28 0002 0000                  .word  0
  29                            .text
  30                    .global t2__search
  31                    t2__search:
  32 0000 8130                  lr     r3,r0
  33 0002 E522                  xorr   r2,r2
  34 0004 8340                  lisn   r4,1
  35                    .L6:
  36 0006 8102                  lr     r0,r2
  37 0008 8210                  lisp   r1,1
  38 000a 57F2                  tbr    15,r2
  39 000c 7505                  jez    .L8
  40                    .L9:
  41 000e 6100                  srl    r0,1
  42 0010 A210                  aisp   r1,1
  43 0012 57F0                  tbr    15,r0
  44 0014 7AFD                  jnz    .L9
  45                    .L8:
  46 0016 A114                  ar     r1,r4
  47 0018 8000 0001             l      r0,word
  48 001c E401 0000             xor    r0,.LC0,r1
  49 0020 9000 0001             st     r0,word
  50 0024 F123                  cr     r2,r3
  51 0026 7503                  jez    .L1
  52 0028 A220                  aisp   r2,1
  53 002a 74EE                  j      .L6
  54                    .L1:
  55 002c 7FF0                  urs    r15
  56                    .global t2___elabb
  57                    t2___elabb:
  58 002e 9110 0000             stc    1,t2_E
  59 0032 7FF0                  urs    r15
function Ave3 (X, Y, Z : Float) return Float is
begin
   return (X + Y + Z) / 3.0;
end Ave3;
 
   1                            .file  "ave3.adb"
   2                    gcc2_compiled.:
   3                    __gnu_compiled_ada:
   4                            .section .rdata,"r"
   5                    .LC0:
   6 0000 6000 0002             .float 0r3
   7                            .text
   8                    .global _ada_ave3
   9                    _ada_ave3:
  10 0000 A902                  far    r0,r2
  11 0002 A904                  far    r0,r4
  12 0004 D800 0000             fd     r0,.LC0
  13 0008 7FF0                  urs    r15
 
 
 
 
 
Updated May 11, 2005
Copyright XGC Software