Compiler options#
This section describes the compiler options specific to GNU Modula-2 for generic flags details See GCC Command Options.
For any given input file, the file name suffix determines what kind of compilation is done. The following kinds of input file names are supported:
file.modModula-2 implementation or program source files. See the
-fmod=option if you wish to compile a project which uses a different source file extension.file.defModula-2 definition module source files. Definition modules are not compiled separately, in GNU Modula-2 definition modules are parsed as required when program or implementation modules are compiled. See the
-fdef=option if you wish to compile a project which uses a different source file extension.You can specify more than one input file on the gm2 command line,
-gcreate debugging information so that debuggers such as
gdbcan inspect and control executables.-Iused to specify the search path for definition and implementation modules. An example is:
gm2 -g -c -I.:../../libs foo.mod. If this option is not specified then the default path is added which consists of the current directory followed by the appropriate language dialect library directories.-fdebug-builtinscall a real function, rather than the builtin equivalent. This can be useful for debugging parameter values to a builtin function as it allows users to single step code into a real function.
-fdump-system-exportsdisplay all inbuilt system items. This is an internal command line option.
-fswiggenerate a swig interface file.
-fsharedgenerate a shared library from the module.
-fruntime-modules=specify, using a comma separated list, the runtime modules and their order. These modules will initialized first before any other modules in the application dependency. By default the runtime modules list is set to
Storage,SYSTEM,M2RTS,RTExceptions,IOLink. Note that these modules will only be linked into your executable if they are required. So adding a long list of dependant modules will not effect the size of the executable it merely states the initialization order should they be required.-fnilgenerate code to detect accessing data through a
NILvalue pointer.-fno-nildo not generate code to detect accessing data through a
NILvalue pointer.-fwholedivgenerate code to detect whole number division by zero or modulus by zero.
-fno-wholedivdo not generate code to detect whole number division by zero or modulus by zero.
-findexgenerate code to check whether array index values are out of bounds.
-fno-indexdo not generate code to check whether array index values are out of bounds.
-frangegenerate code to check the assignment range, return value range set range and constructor range.
-fno-rangedo not generate code to check the assignment range, return value range set range and constructor range.
-freturngenerate code to check that functions always exit with a
RETURNand do not fall out at the end.-fcaseturns on compile time checking to check whether a
CASEstatement requires anELSEclause when on was not specified.-fsoft-check-allturns on all runtime checks. This is the same as invoking GNU Modula-2 using the command options
-fnil-frange-findex-fwholediv-fcase-freturn.-fauto-initturns on auto initialization of pointers to NIL. Whenever a block is created all pointers declarated within this scope will have their addresses assigned to NIL.
-fno-exceptionsturns off all generation of exception handling code and no references are made to the runtime exception libraries.
-vdisplay all calls to subsidiary programs, such as the C preprocessor, the GNU Modula-2 linker and compiler.
-fm2-statisticsgenerates quadruple information: number of quadruples generated, number of quadruples remaining after optimisation and number of source lines compiled.
-fm2-whole-programcompile all implementation modules and program module at once. Notice that you need to take care if you are compiling different dialect modules (particularly with the negative operands to modulus). But this option, when coupled together with
-O3, can deliver huge performance improvements.-fm2-gimprove the debugging experience for new programmers at the expense of generating
nopinstructions if necessary to ensure single stepping precision over all code related keywords. An example of this is in termination of a list of nestedIFstatements where multipleENDkeywords are mapped onto a sequence ofnopinstructions.-fm2-lower-caserender keywords in error messages using lower case.
fno-pthreaddo not automatically link against the pthread library. This option is likely useful if gm2 is configured as a cross compiler targetting embedded systems. By default GNU Modula-2 uses the GCC pthread libraries to implement coroutines (see the SYSTEM implementation module).
-fuse-list=filenameif
-fscaffold-staticis enabled then use the filefilenamefor the initialization order of modules. Whereas if-fscaffold-dynamicis enabled then use this file to force linking of all module ctors. This option cannot be used if-fgen-module-list=is enabled.-fgen-module-list=filenameattempt to find all modules when linking and generate a module list. If the
filenameis-then the contents are not written and only used to force the linking of all module ctors. This option cannot be used if-fuse-list=is enabled.-fscaffold-staticthe option ensures that
gm2will generate a static scaffold within the program module. The static scaffold is useful for debugging and single stepping the initialization blocks of implementation modules.-fscaffold-dynamicthe option ensures that
gm2will generate a dynamic scaffold infastructure when compiling implementation and program modules. By default this option is on. Use-fno-scaffold-dynamicto turn it off or select-fno-scaffold-dynamic.-fcpppreprocess the source with
cpp -lang-asm -traditional-cppFor further details about these options See Invocation. If-fcppis supplied then all definition modules and implementation modules which are parsed will be preprocessed bycpp.-fisoturn on ISO standard features. Currently this enables the ISO
SYSTEMmodule and alters the default library search path so that the ISO libraries are searched before the PIM libraries. It also effects the behaviour ofDIVandMODoperators. See GNU Modula-2 supported dialects.-fpimturn on PIM standard features. Currently this enables the PIM
SYSTEMmodule and determines which identifiers are pervasive (declared in the base module). If no other-fpim[234]switch is used then division and modulus operators behave as defined in PIM4. See GNU Modula-2 supported dialects.-fpim2turn on PIM-2 standard features. Currently this removes
SIZEfrom being a pervasive identifier (declared in the base module). It placesSIZEin theSYSTEMmodule. It also effects the behaviour ofDIVandMODoperators. See GNU Modula-2 supported dialects.-fpim3turn on PIM-3 standard features. Currently this only effects the behaviour of
DIVandMODoperators. See GNU Modula-2 supported dialects.-fpim4turn on PIM-4 standard features. Currently this only effects the behaviour of
DIVandMODoperators. See GNU Modula-2 supported dialects.-fpositive-mod-floor-divforces the
DIVandMODoperators to behave as defined by PIM4. All modulus results are positive and the results from the division are rounded to the floor. See GNU Modula-2 supported dialects.-flibs=modifies the default library search path. The libraries supplied are: m2pim, m2iso, m2min, m2log and m2cor. These map onto the Programming in Modula-2 base libraries, ISO standard libraries, minimal library support, Logitech compatible library and Programming in Modula-2 with coroutines. Multiple libraries can be specified and are comma separated with precidence going to the first in the list. It is not necessary to use -flibs=m2pim or -flibs=m2iso if you also specify -fpim, -fpim2, -fpim3, -fpim4 or -fiso. Unless you are using -flibs=m2min you should include m2pim as the they provide the base modules which all other dialects utilize. The option
-fno-libs=-disables thegm2driver from modifying the search and library paths.-fextended-opaqueallows opaque types to be implemented as any type. This is a GNU Modula-2 extension and it requires that the implementation module defining the opaque type is available so that it can be resolved when compiling the module which imports the opaque type.
-fsourcesdisplays the path to the source of each module. This option can be used at compile time to check the correct definition module is being used.
-fdef=recognise the specified suffix as a definition module filename. The default implmentation and module filename suffix is
.def. If this option is used GNU Modula-2 will still fall back to this default if a requested definition module is not found.-fmod=recognise the specified suffix as implementation and module filenames. The default implmentation and module filename suffix is
.mod. If this option is used GNU Modula-2 will still fall back to this default if it needs to read an implmentation module and the specified suffixed filename does not exist.-fxcodeissues all errors and warnings in the
Xcodeformat.-funbounded-by-referenceenable optimization of unbounded parameters by attempting to pass non
VARunbounded parameters by reference. This optimization avoids the implicit copy inside the callee procedure. GNU Modula-2 will only allow unbounded parameters to be passed by reference if, inside the callee procedure, they are not written to, no address is calculated on the array and it is not passed as aVARparameter. Note that it is possible to write code to break this optimization, therefore this option should be used carefully. For example it would be possible to take the address of an array, pass the address and the array to a procedure, read from the array in the procedure and write to the location using the address parameter.Due to the dangerous nature of this option it is not enabled when the -O option is specified.
-Wverbose-unboundedinform the user which non
VARunbounded parameters will be passed by reference. This only produces output if the option-funbounded-by-referenceis also supplied on the command line.-Wstylechecks for poor programming style. This option is aimed at new users of Modula-2 in that it checks for situations which might cause confusion and thus mistakes. It checks whether variables of the same name are declared in different scopes and whether variables look like keywords. Experienced users might find this option too aggressive.
-Wpedanticforces the compiler to reject nested
WITHstatements referencing the same record type. Does not allow multiple imports of the same item from a module. It also checks that: procedure variables are written to before being read; variables are not only written to but read from; variables are declared and used. If the compiler encounters a variable being read before written it will terminate with a message. It will check thatFORloop indices are not used outside the end of this loop without being reset.-Wpedantic-param-namesprocedure parameter names are checked in the definition module against their implementation module counterpart. This is not necessary in ISO or PIM versions of Modula-2.
-Wpedantic-castwarns if the ISO system function is used and if the size of the variable is different from that of the type. This is legal in ISO Modula-2, however it can be dangerous. Some users may prefer to use
VALinstead in these situations and useCASTexclusively for changes in type on objects which have the same size.-Wunused-variablewarns if a variable has been declared and it not used.
-Wunused-parameterwarns if a parameter has been declared and it not used.
-Wallturn on all Modula-2 warnings.