Re: Specifying parameter passing convention and place (register)

From: Nick Roberts (nick.roberts_at_acm.org)
Date: 07/08/04


Date: Thu, 08 Jul 2004 16:29:43 +0100

On 8 Jul 2004 07:06:15 -0500, Larry Kilgallen <Kilgallen@SpamCop.net>
wrote:

> ...
> Did you look in section 13.9a of that document ?
> In particular, look for the word MECHANISM.

Aha! Eureka. Sort of.

> Certainly the mechanisms VALUE and REFERENCE are of general use.

Yes indeed, but they say nothing of the passing 'place' (specific
register, or location in the stack frame, or wherever).

> The mechanism DESCRIPTOR is only for where a large variety of string
> representations are supported on the operating system. For environments
> where data passed between languages will never include bounded strings,
> bit strings, non-contiguous arrays, then defaulting to your local form
> of DESCRIPTOR for a string starting at offset 1 is adequate.

As far as I'm concerned, the programmer must either specify or discover
the actual format (in memory) of such parameters, and program (external or
assembly) accordingly. In almost all cases, the type will be de facto be
passed by reference, and so the passing place will (to my mind) be the
place where the address is passed.

> You could add a mechanism called REGISTER,

It noe occurs to me that that would be confusing issues slightly, since a
mechanism can be by-copy or by-reference, and in either case it can also
be in-a-register or on-the-stack (or conceivably some other place).

> and if GNAT does this machine code insertion, I am surprised ACT
> has not added such a mechanism.

GNAT uses the GCC inline assembly syntax, which is transferred from GNU C,
and rather unAdalike. I don't want to replicate it (it would actually be a
lot of extra work to do so).

I'm very grateful for your help, Larry. All in all, however, I think I
need something different to suit my own needs.

I think I will have two pragmas:

    pragma Parameter_Mechanism (
       [ENTITY =>] callable_entity_simple_name,
       [PARAMETER =>] parameter_simple_name [,
       [MECHANISM =>] passing_mechanism] [,
       [PLACE =>] passing_place] );

    pragma Return_Mechanism (
       [ENTITY =>] callable_entity_simple_name,
       [MECHANISM =>] passing_mechanism] [,
       [PLACE =>] passing_place] );

    passing_mechanism ::= BY_COPY | BY_REFERENCE

    passing_place ::= qualified_expression

The callable_entity_simple_name identifies the subprogram or entry. The
pragma applies to the entity designated (regardless of the name), so
renamings can be used to isolate one of a set of overloadings.

The qualified expression of a passing place must be of a subtype declared
in System.Calling. For the IA-32, we might have the following declarations
in this package:

    type Register_8 is ( AL, CL, DL, BL, AH, CH, DH, BH); -- 8-bit
    type Register_16 is ( AX, CX, DX, BX, SP, BP, SI, DI); -- 16-bit
    type Register_32 is (EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI); -- 32-bit
    type Segment_Register is (ES, CS, SS, DS, FS, GS); -- 16-bit

    type Register_64 is
       record
          Upper, Lower: Register_32;
       end record;

    subtype Frame_Offset is Storage_Elements.Storage_Offset;
    -- Parameter or return value is to be located relative to the stack
frame
    -- pointer (EBP) for a subprogram, or the beginning of the shared data
area,
    -- for an entry.

In reality these would all be subtypes renaming types declared in another
package.

Any obvious flaws?

-- 
Nick Roberts


Relevant Pages

  • Re: blank response from curl when posting form data
    ... under 800 characters, everything works. ... I tried passing the post data in strings, ...
    (comp.lang.php)
  • something strange with new process Arguments
    ... I'm starting a new process and passing it some arguments to look at a ... The folder gets created correctly. ... I figure it has to be an encoding problem somewhere among the various ... possible encodings and passings of strings going on. ...
    (microsoft.public.dotnet.general)
  • Re: Conditionally Adding SQL
    ... If you are not blindly EXECing the strings that are passed in, ... passing a string into a VARCHAR parameter any safer than passing that same ... Just because you don't understand that SAFE date formats in SQL ...
    (microsoft.public.sqlserver.programming)
  • Re: C# Object parameters in Outlook and Office methods
    ... passing a strings to GetItemFromID works for me. ... object par = mystring; ...
    (microsoft.public.outlook.program_addins)
  • Passing strings to C++ DLL
    ... I am attempting to write a .NET wrapper for a C++ DLL file, ... problems with passing strings as parameters. ... SDCERR GetCurrentConfig(DWORD *num, char *name); ... C++ functions - the structures contain strings as well. ...
    (microsoft.public.dotnet.languages.csharp)