GM2(1)

๐Ÿ“ฆ
version 10.5.0 ยท 3 versions
, in ubuntu jammy

๐Ÿ’– gm2: GM2(1) from the GNU manual ๐Ÿ’–

manual name: GM2(1) ๐ŸŒธ


โœจ NAME โœจ

okay bestie, the whole NAME section is just gm2 - The GNU Modula-2 Compiler ๐ŸŽ€. that's it, that's the compiler, and it's iconic ๐Ÿ‘‘


โœจ SYNOPSIS โœจ

this section is blank on this page ๐Ÿ™ˆ so the heading is all you get for now.


โœจ DESCRIPTION โœจ

also blank here ๐Ÿ™ˆ nothing to see, moving on bestie.


โœจ OPTIONS โœจ

so the file name suffix you give gm2 decides what kind of compilation it does ๐Ÿ’… these are the input file kinds it supports:

๐Ÿ“ Input files

  • file.mod โ€” Modula-2 implementation or program source files. if your project uses a different source file extension, check out the -fmod= option ๐Ÿฆ‹
  • file.def โ€” Modula-2 definition module source files. these aren't compiled on their own ๐Ÿ™…โ€โ™€๏ธ in GNU Modula-2, definition modules get parsed whenever a program or implementation module needs them. if your project uses a different source extension, see the -fdef= option ๐ŸŒˆ

you can throw more than one input file on the gm2 command line too โœจ

๐ŸŽ›๏ธ Options

  • -g โ€” debug info time! ๐Ÿ” it creates debugging information so debuggers like gdb can inspect and control your executables ๐Ÿงš
  • -I โ€” sets the search path for definition and implementation modules ๐Ÿ—บ๏ธ for example:
gm2 -g -c -I.:../../libs foo.mod

if you don't pass -I, the default path is added: the current directory first, then the right language dialect library directories ๐Ÿ’–

  • -fobject-path= โ€” sets the path for objects during the linking stage ๐Ÿงฑ for example:
gm2 -g -fobject-path=.:../../libs/O2 -I.:../../libs foo.mod

mixing -I and -fobject-path= keeps your objects separate from your source files, which is so organised ๐Ÿซถ like you could compile implementation modules with different optimisation levels, with or without debugging, and stash each set in its own folder. if you skip -fobject-path=, it's set internally from whatever path -I gave. no -I either? then it uses the current directory. either way, the right language dialect library directories get tacked onto the end of the path ๐Ÿ“‚

  • -fdebug-builtins โ€” calls a real function instead of the builtin equivalent ๐Ÿ”ง super handy for debugging parameter values passed to a builtin, since you can single step your code right into a real function ๐Ÿชœ
  • -fdump-system-exports โ€” displays all inbuilt system items ๐Ÿงพ heads up, this is an internal command line option ๐Ÿ™ˆ
  • -fswig โ€” generates a swig interface file ๐Ÿ
  • -fshared โ€” generates a shared library from the module ๐Ÿ“š
  • -fmakeinit โ€” generates the start-up C++ code for the module, and a file called _m2_modulename.cpp gets created ๐Ÿ› ๏ธ also internal, so don't worry about it too much ๐Ÿ’…
  • -fruntime-modules= โ€” takes a comma separated list of the runtime modules and their order ๐Ÿ“‹ those modules get initialised first, before any other modules in the application dependency. the default list is Storage,SYSTEM,M2RTS,RTExceptions,IOLink ๐Ÿ’œ and here's the tea: these modules only get linked into your executable if they're actually needed. so a super long list won't make your executable bigger. it just sets the initialisation order, if they're needed ๐Ÿซ 
  • -fnil โ€” generates code that detects accessing data through a NIL value pointer ๐Ÿšจ
  • -fno-nil โ€” does NOT generate that NIL pointer check ๐Ÿ™…โ€โ™€๏ธ
  • -fwholediv โ€” generates code that detects whole number division by zero or modulus by zero ๐Ÿงฎ
  • -fno-wholediv โ€” does NOT generate that division or modulus by zero check ๐Ÿ™…โ€โ™€๏ธ
  • -findex โ€” generates code that checks whether array index values are out of bounds ๐Ÿ“
  • -fno-index โ€” does NOT generate that array bounds check ๐Ÿ™…โ€โ™€๏ธ
  • -frange โ€” generates code that checks the assignment range, return value range, set range and constructor range ๐ŸŽฏ
  • -fno-range โ€” does NOT check the assignment range, return value range, set range or constructor range ๐Ÿ™…โ€โ™€๏ธ
  • -freturn โ€” generates code that checks functions always exit with a RETURN and don't just fall out at the end ๐Ÿ
  • -fcase โ€” turns on compile time checking for whether a CASE statement needs an ELSE clause when you didn't specify one ๐Ÿ”
  • -fsoft-check-all โ€” turns on all the runtime checks ๐Ÿ”ฅ it's the same as using -fnil -frange -findex -fwholediv -fcase -freturn all together ๐Ÿ’ฏ
  • -fauto-init โ€” turns on auto initialisation of pointers to NIL ๐ŸŒ™ whenever a block gets created, every pointer declared in that scope has its address set to NIL ๐Ÿซถ
  • -fno-exceptions โ€” turns off all generation of exception handling code ๐Ÿšซ and nothing references the runtime exception libraries ๐Ÿ’€
  • -v โ€” displays all the calls to subsidiary programs, like the C preprocessor and the GNU Modula-2 linker and compiler ๐Ÿ•ต๏ธโ€โ™€๏ธ
  • -fm2-statistics โ€” generates quadruple information: how many quadruples were generated, how many are left after optimisation, and how many source lines got compiled ๐Ÿ“Š
  • -fm2-whole-program โ€” compiles all implementation modules and the program module at once ๐Ÿš€ ngl be careful if you're compiling different dialect modules, especially with negative operands to modulus ๐Ÿ˜ฌ but paired with -O3, this can deliver huge performance improvements โšก
  • -fm2-g โ€” makes debugging way nicer for new programmers ๐ŸŽ€ the cost is that it may generate nop instructions to keep single stepping precise over all the code related keywords. for example, when a list of nested IF statements ends, multiple END keywords get mapped onto a sequence of nop instructions ๐Ÿซ 
  • -fm2-lower-case โ€” renders keywords in error messages in lower case ๐Ÿ”ค
  • -fmakelist โ€” only applies when linking a program module ๐Ÿงพ the compiler generates a modulename.lst file that lists the initialisation order of all the modules being linked, and the actual link does NOT happen ๐Ÿ™…โ€โ™€๏ธ the GNU Modula-2 linker scans all IMPORTs, builds a list of dependencies, and produces an ordered list for initialisation. it'll probably get the order wrong if your project has cyclic dependencies ๐Ÿ˜ญ but the .lst file is plain text, so you can edit it if you need to ๐Ÿ“ once the .lst file exists, the compiler can use it to link your project via the -fuselist option. it has no effect if -c is present ๐Ÿ™ˆ
  • fno-pthread โ€” does not automatically link against the pthread library ๐Ÿงต this is likely useful if gm2 is configured as a cross compiler targeting embedded systems ๐Ÿค– by default, GNU Modula-2 uses the GCC pthread libraries to implement coroutines (see the SYSTEM implementation module) ๐Ÿฆ‹
  • -fuselist โ€” once gm2 has been told to link the program module, this option uses the file modulename.lst for the initialisation order of modules ๐Ÿ“œ
  • -fcpp โ€” preprocesses the source with cpp -lang-asm -traditional-cpp. for further details about these options, see. if -fcpp is supplied, then every definition module and implementation module that gets parsed will be preprocessed by cpp ๐Ÿงš
  • -fiso โ€” turns on ISO standard features ๐ŸŒ right now this enables the ISO SYSTEM module, and it changes the default library search path so the ISO libraries are searched before the PIM libraries. it also affects the behaviour of DIV and MOD operators. See
  • -fpim โ€” turns on PIM standard features ๐Ÿ“˜ right now this enables the PIM SYSTEM module and decides which identifiers are pervasive (declared in the base module). if no other -fpim[234] switch is used, division and modulus operators behave as defined in PIM4. See
  • -fpim2 โ€” turns on PIM-2 standard features ๐Ÿ“— right now this removes SIZE from being a pervasive identifier (declared in the base module) and places SIZE in the SYSTEM module instead. it also affects the behaviour of DIV and MOD operators. See
  • -fpim3 โ€” turns on PIM-3 standard features ๐Ÿ“™ right now this only affects the behaviour of DIV and MOD operators. See
  • -fpim4 โ€” turns on PIM-4 standard features ๐Ÿ“• right now this only affects the behaviour of DIV and MOD operators. See
  • -fpositive-mod-floor-div โ€” forces the DIV and MOD operators to behave as defined by PIM4 ๐Ÿ’– all modulus results come out positive, and division results are rounded to the floor. See
  • -flibs= โ€” modifies the default library search path ๐Ÿ“š the libraries you can supply are m2pim, m2iso, m2min, m2log and m2cor. those map onto: the Programming in Modula-2 base libraries, the ISO standard libraries, minimal library support, the Logitech compatible library, and Programming in Modula-2 with coroutines. you can list multiple libraries, comma separated, and the first one in the list gets precedence ๐Ÿฅ‡ you don't need -flibs=m2pim or -flibs=m2iso if you also specify -fpim, -fpim2, -fpim3, -fpim4 or -fiso. unless you're using -flibs=m2min, you should include m2pim, because it provides the base modules that all the other dialects use ๐Ÿซถ
  • -fextended-opaque โ€” allows 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 it can be resolved when compiling the module that imports the opaque type ๐Ÿ”—
  • -fsources โ€” displays the path to the source of each module ๐Ÿ—‚๏ธ you can use this at compile time to check that the correct definition module is being used ๐Ÿ‘€
  • -fmodules โ€” displays the path to each module's object file ๐Ÿงฑ this option can only be invoked with the -c option, and it's used to see where the objects are when linking happens ๐Ÿ”Ž
  • -fdef= โ€” recognises the specified suffix as a definition module filename ๐Ÿ“ the default implementation and module filename suffix is .def. if you use this option, GNU Modula-2 still falls back to that default when a requested definition module isn't found ๐Ÿฆ‹
  • -fmod= โ€” okay so this one lets you pick your own suffix ๐Ÿ’… for implementation and module filenames. The default is .mod, and if you use this flag, GNU Modula-2 will still fall back to .mod when it needs an implementation module and your suffixed filename isn't there ๐ŸŽ€
  • -fxcode โ€” makes every error and warning come out in the Xcode format ๐Ÿ’ปโœจ
  • -fonlylink โ€” only links your Modula-2 app. It skips compiling the program module first ๐Ÿ”—๐ŸŒธ
  • -funbounded-by-reference โ€” this one is a whole vibe ๐Ÿ”ฅ It turns on optimisation for unbounded parameters by trying to pass non VAR unbounded parameters by reference, which means the implicit copy inside the callee procedure gets skipped. GNU Modula-2 only lets an unbounded parameter go by reference if, inside the callee, it's never written to, no address gets calculated on the array, and it isn't passed as a VAR parameter. You can still write code that breaks this optimisation, so be careful. For example, you could take the address of an array, pass both the address and the array into a procedure, read from the array in there, and then write to the location through the address parameter ๐Ÿ™ˆ
Heads up, bestie: this option is seriously risky ๐Ÿ’€ Because of that, it is not enabled when the -O option is specified.
  • -Wverbose-unbounded โ€” tells you which non VAR unbounded parameters are going to be passed by reference ๐Ÿ‘€ It only shows anything if -funbounded-by-reference is also on your command line.
  • -Wstudents โ€” a style check for bad programming habits ๐Ÿ“š It's made for new Modula-2 users, since it catches stuff that could cause confusion and then mistakes. It flags variables with the same name declared in different scopes, and variables that look like keywords. Experienced users might find it a bit too aggressive ๐Ÿ˜ญ
  • -Wpedantic โ€” forces the compiler to reject nested WITH statements that reference the same record type ๐Ÿ™…โ€โ™€๏ธ It also won't allow multiple imports of the same item from a module. On top of that, it checks that procedure variables are written to before they're read, that variables aren't only written to but also read from, and that variables are declared and used. If the compiler spots a variable being read before it's written, it stops and prints a message. It also checks that FOR loop indices aren't used outside the end of the loop without being reset first ๐Ÿ”
  • -Wpedantic-param-names โ€” checks procedure parameter names in the definition module against their counterparts in the implementation module ๐Ÿง This isn't required in ISO or PIM versions of Modula-2, but it can be super useful, as long as your code is intentionally written that way โœจ
  • -Wpedantic-cast โ€” warns if the ISO system function is used and the size of the variable is different from the size of the type ๐Ÿซฃ It's legal in ISO Modula-2, but it can be dangerous. Some people prefer using VAL in these situations, and only using CAST for type changes on objects that are the same size ๐Ÿ’œ
  • -Wunused-variable โ€” warns you if a variable is declared but never used ๐Ÿ—‘๏ธ
  • -Wunused-parameter โ€” warns you if a parameter is declared but never used ๐Ÿ—‘๏ธ
  • -Wall โ€” turns on all Modula-2 warnings at once ๐Ÿ”ฅ๐Ÿ‘‘

๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

This page doesn't list any environment variables, so there's nothing to see here, bestie ๐Ÿซถ

๐ŸŒธ SEE ALSO ๐ŸŒธ

Copyright (c) 1999-2020 Free Software Foundation, Inc. ๐Ÿ’–

Okay, so you're allowed to copy, distribute, and/or modify this document under the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation โœจ There are no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the man page gfdl(7) ๐Ÿ“œ


Bestie, that's the whole page ๐Ÿ’… This one's from gcc-10 and was last dated 2023-07-07. Go be a Modula-2 main character ๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from