gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposed module attributes


From: Gaius Mulley
Subject: Proposed module attributes
Date: Fri, 17 Nov 2023 20:10:19 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

Hello,

Here are some proposed ideas for per module attributes.  The exact
attribute syntax will probably differ and all these ideas are up for
debate anyway :-).  Many of the ideas are in response to
queries/suggestions over the last 6 months or so.  But I thought I'd
post them and solicit feedback.  In summary these proposals don't change
the language - rather they just allow flags to be contained inside
modules.


Module flag attributes
======================

The intent of this attribute is to improve mixed dialect support and
ease of use (-fm2-whole-program for example allows the whole project to
be compiled from a single gm2 invocation).  It also allows
-fsoft-check-all or specific runtime checks to be default configured on
a per module basis also working with -fm2-whole-program.  For many
modula-2 projects a single 'gm2 modulename.mod' invocation would
suffice.

Only flags which relate to cc1gm2 can be set by the attribute.
There are four categories of flags:

 (i)   -g or -no-g module level debugging.
 (ii)  -fm2-whole-program compile a project.
 (iii)  backend gcc flags such as -O2.
 (iv)   m2 front end flags such as -fpim2, -fcase -fbounds, -fsoft-check-all.

All (iv) flags set from within the attribute compiler_flag exist per
module.  (ii) and (iii) can be set in the module specified on the
command line (typically the program module) but have no effect in a
library module even when -fm2-whole-program is supplied.  (i) can
be set in any module and will be the default (unless the
-fm2-attribute-override option is used on the command line).  This
allows for runtime modules to be recompiled without debugging information.

All command line options would be checked against <* compiler_flag *>
for conflicts and a note would always be generated showing the
conflict and the used option value.  -fsources would also show which
options were enabled per source file.

Example:

MODULE foo <* compiler_flag: -fm2-whole-program -fpim2 -g -O0 *> ;
(* maybe the module uses division with the negative left value.  *)

VAR
   res: INTEGER ;
BEGIN
   res := -31 DIV 10  (* res = -3 *)
END foo.


IMPLEMENTATION MODULE bar <* compiler_flag: -fiso *> ;

BEGIN
END bar.


IMPLEMENTATION MODULE baz <* compiler_flag: -fcpp -fpim4 -fnil *> ;
(* maybe the module uses division with the negative left value or
   other specific pim4 features.  It also uses cpp and enables runtime
   pointer checking.  *)

VAR
   res: INTEGER ;
BEGIN
   res := -31 DIV 10  (* res = -4 *)
END baz.

$ gm2 foo.mod
$ ./a.out
$ gm2 -O3 foo.mod
foo.mod:1:Note: attribute and command line flag conflict between the command
line option -O3 and compiler_flag attribute -O0 (command line -O3 is used)
$ gm2 -fm2-attribute-override -O3 foo.mod
$ ./a.out


Module inline attribute
=======================

The proposal also includes an inline attribute for a definition
module, ie:

DEFINITION MODULE mat <* module_flag: inline *> ;

TYPE
   Matrix ;

PROCEDURE init () : Matrix ;
PROCEDURE set (VAR des: Matrix: ARRAY OF ARRAY OF REAL) : Matrix ;
PROCEDURE add (left, right: Matrix): Matrix ;
PROCEDURE get (VAR des: ARRAY OF ARRAY OF CHAR; m: Matrix) ;

END mat.

which forces the implementation module mat to be parsed and inlined into
the module performing the import.  This attribute will be used by the
runtime support to implement wide sets and also will be used to
re-implement runtime ordinal overflow checking (performed in modula-2
rather than in gcc trees internally).  Currently underway is the
re-implementation of wide sets using a packed array of boolean (as
opposed to the current record of bitset fields).  The wide set
implementation will be performed in modula-2 runtime libraries and the
inlining was partially motivated by the desire to minimise the
performance penalty.


regards,
Gaius



reply via email to

[Prev in Thread] Current Thread [Next in Thread]