home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / stdarg-impl.adb < prev    next >
Encoding:
Text File  |  1995-11-17  |  5.1 KB  |  162 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/xbind/stdarg-impl.adb,v $ 
  2. -- $Revision: 1.12 $ $Date: 95/06/29 16:01:29 $ $Author: mg $ 
  3. -------------------------------------------------------------------------------
  4. --
  5. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT 
  6. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
  7. -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR 
  8. -- PURPOSE.  The user assumes the entire risk as to the accuracy and the 
  9. -- use of this file.
  10. --
  11. -- Copyright (c) Intermetrics, Inc. 1995
  12. -- Royalty-free, unlimited, worldwide, non-exclusive use, modification, 
  13. -- reproduction and further distribution of this file is permitted.
  14. --
  15. -------------------------------------------------------------------------------
  16.  
  17.  
  18. with Stdarg.Machine,
  19.      Text_IO;
  20.  
  21. package body Stdarg.Impl is
  22.  
  23.     use Stdarg.Machine;
  24.  
  25.     -- ******************************
  26.     -- Getting arguments out of lists
  27.     -- ******************************
  28.  
  29.     type Which_Arg is (Ellipsis, VA_List);
  30.  
  31.     function Address_of_Arg (Args: ArgList; Which: Which_Arg) 
  32.     return Param_Access is
  33.     begin
  34.         if Args.Contents.CurrentArgs = 0 then
  35.             return null;                      -- might not be an error
  36.         end if;
  37.  
  38.     if This_Arch = Alpha then
  39.         return Args.Contents.Vector(7)'access;
  40.         elsif Stack_Growth = Up then
  41.             return Args.Contents.Vector(1)'access;
  42.         elsif Which = Ellipsis then
  43.             return Args.Contents.Vector(
  44.            MaxArguments-Args.Contents.CurrentArgs+1)'access;
  45.     else
  46.         declare
  47.         use Arith;
  48.         P: Pointer := Args.Contents.Vector(MaxArguments)'access;
  49.         begin
  50.         return Param_Access(P+1);
  51.         end;
  52.         end if;
  53.     end Address_of_Arg;
  54.  
  55.     function Address_of_First_Arg (Args: ArgList) return Param_Access is
  56.     begin
  57.         return Address_of_Arg(Args, Ellipsis);
  58.     end Address_of_First_Arg;
  59.  
  60.     function Address_of_Vararg_List (Args: ArgList) return Param_Access is
  61.     begin
  62.         return Address_of_Arg(Args, VA_List);
  63.     end Address_of_Vararg_List;
  64.  
  65.     function ArgCount (Args: ArgList) return Int is
  66.     begin
  67.     return Int(Args.Contents.CurrentArgs);
  68.     end ArgCount;
  69.  
  70.     -- **************
  71.     -- Concatenations
  72.     -- **************
  73.  
  74.     function "&" (Left, Right: ArgList) return ArgList is
  75.         Hole_Change : Integer := 0;
  76.         Incr        : Integer;
  77.     J           : Integer;
  78.         Left_Index,
  79.         Right_Index : Positive;
  80.         
  81.         procedure Do_Incr(Index: in out Natural) is
  82.         begin
  83.             Index := Index + Incr;
  84.         end Do_Incr;
  85.         pragma Inline(Do_Incr);
  86.     begin
  87.         if Left.Contents = null or else Left.Contents.CurrentArgs = 0 then
  88.             return Right;
  89.         elsif Right.Contents = null or else Right.Contents.CurrentArgs = 0 then
  90.             return Left;
  91.         end if;
  92.  
  93.     if This_Arch = Alpha then
  94.         for Right_Index in 7..Right.Contents.CurrentArgs loop
  95.         Left_Index := Left.Contents.CurrentArgs + Right_Index - 6;
  96.         if Left_Index <= 12 then
  97.             Left.Contents.Vector(Left_Index-6) := 
  98.             Right.Contents.Vector(Right_Index-6);
  99.         end if;
  100.         Left.Contents.Vector(Left_Index) := 
  101.             Right.Contents.Vector(Right_Index);
  102.         end loop;
  103.         Left.Contents.CurrentArgs := Left.Contents.CurrentArgs + 
  104.         Right.Contents.CurrentArgs - 6;
  105.  
  106.         -- Dump(Left.Contents.Vector(1)'access, 
  107.             -- Int(Left.Contents.CurrentArgs));
  108.  
  109.         return Left;
  110.         elsif Stack_Growth = Up then
  111.             Left_Index  := Left.Contents.CurrentArgs + 1;
  112.             Right_Index := 1;
  113.             Incr        := 1;
  114.             -- Dump(Left.Contents.Vector(1)'access, 
  115.                  -- Int(Left.Contents.CurrentArgs));
  116.             -- Dump(Right.Contents.Vector(1)'access, 
  117.                  -- Int(Right.Contents.CurrentArgs));
  118.         else
  119.             Left_Index  := MaxArguments - Left.Contents.CurrentArgs;
  120.             Right_Index := MaxArguments;
  121.             Incr        := -1;
  122.             -- Dump(Left.Contents.Vector(Left_Index+1)'access, 
  123.                  -- Int(Left.Contents.CurrentArgs));
  124.             -- Dump(Right.Contents.Vector(
  125.                  -- MaxArguments-Right.Contents.CurrentArgs+1)'access, 
  126.                  -- Int(Right.Contents.CurrentArgs));
  127.             -- Text_IO.Put_Line("Right first hole" & 
  128.                               -- Integer'Image(Right.Contents.FirstHole));
  129.         end if;
  130.  
  131.         for I in 1..Right.Contents.CurrentArgs loop
  132.             if Right.Contents.FirstHole = I and then
  133.            Left.Contents.CurrentArgs mod 2 /= 0 then
  134.                if Float_Param_Alignment > Int_Param_Alignment then 
  135.             if I mod 2 = 0 then
  136.             -- remove hole
  137.             Do_Incr(Right_Index);
  138.             Hole_Change := -1;
  139.             else
  140.             -- add hole
  141.             Do_Incr(Left_Index);
  142.             Hole_Change := 1;
  143.             end if;
  144.         end if;
  145.             end if;
  146.             Left.Contents.Vector(Left_Index) :=
  147.                 Right.Contents.Vector(Right_Index);
  148.             Do_Incr(Left_Index);
  149.             Do_Incr(Right_Index);
  150.         end loop;
  151.  
  152.         Left.Contents.CurrentArgs := Left.Contents.CurrentArgs + 
  153.             Right.Contents.CurrentArgs + Hole_Change;
  154.  
  155.         -- Dump(Left.Contents.Vector(1)'access, 
  156.         -- Int(Left.Contents.CurrentArgs));
  157.  
  158.         return Left;
  159.     end "&";
  160.  
  161. end Stdarg.Impl;
  162.