M2(1)

🌸 M2(1) · GNU Manual 🌸

Welcome to the GNU manual's M2(1) page, bestie πŸ’– Let's get into it ✨

✨ NAME ✨

gm2 - The GNU Modula-2 Compiler πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

Nothing's written in this section of the original page, so there's nothing to rewrite here πŸ«₯


πŸ’œ DESCRIPTION πŸ’œ

This section is also blank in the original page πŸ™ˆ


πŸ¦‹ OPTIONS πŸ¦‹

Okay so the file name suffix is the main character here πŸ‘‘ Whatever ending your input file has decides what kind of compilation gm2 does with it. These are the kinds it knows about:

  • file.mod β€” Modula-2 implementation or program source files. If your project uses a different source file extension, check out -fmod= 🌈
  • file.def β€” Modula-2 definition module source files. These don't get compiled on their own πŸ™… GNU Modula-2 parses them whenever a program or implementation module needs them. If your project uses a different extension, see -fdef= ✨

You can give gm2 more than one input file on the command line, bestie 🫢

  • -g β€” creates debugging info so debuggers like gdb can peek inside your executables and control them πŸ”
  • -I β€” sets the search path for definition and implementation modules. Example: gm2 -g -c -I.:../../libs foo.mod. If you don't set this, the default path is the current directory, followed by the appropriate language dialect library directories πŸ“‚
  • -fobject-path= β€” sets the path for objects during the linking stage. Example: gm2 -g -fobject-path=.:../../libs/O2 -I.:../../libs foo.mod. Using -I and -fobject-path= together lets projects keep different object styles separate from their source files. For instance, you could compile implementation modules with different optimisation levels, with or without debugging, and stash each set in its own directory πŸ—‚οΈ If -fobject-path= isn't set, it's built from whatever -I says. If -I wasn't set either, it uses the current directory. In every case, the language dialect library directories get tacked onto the end of the path 🧚
  • -fdebug-builtins β€” calls a real function instead of the builtin equivalent. This is super useful for debugging parameter values passed to a builtin, since it lets you single step your code right into a real function πŸ‘£
  • -fdump-system-exports β€” displays all inbuilt system items. This is an internal command line option, so it's more of a behind-the-scenes thing 🀫
  • -fswig β€” generates a swig interface file πŸ“
  • -fshared β€” generates a shared library from the module 🌸
  • -fmakeinit β€” generates the start up C++ code for the module, creating a file called _m2_modulename.cpp. This is also an internal command line option πŸ”§
  • -fruntime-modules= β€” takes a comma separated list naming the runtime modules and their order. These modules get initialised first, before any other modules in the application dependency. By default the list is Storage,SYSTEM,M2RTS,RTExceptions,IOLink. These modules only end up in your executable if they're actually required, so adding a long list of dependent modules won't change the executable's size. It just sets the initialisation order should they be needed πŸ“‹
  • -fnil β€” generates code to detect accessing data through a NIL value pointer πŸ™ˆ
  • -fno-nil β€” doesn't generate that NIL pointer detection code πŸ™…
  • -fwholediv β€” generates code to detect whole number division by zero, or modulus by zero βž—
  • -fno-wholediv β€” doesn't generate that division and modulus by zero detection code πŸ™…
  • -findex β€” generates code to check whether array index values are out of bounds πŸ“
  • -fno-index β€” doesn't generate that array bounds checking code πŸ™…
  • -frange β€” generates code to check the assignment range, return value range, set range and constructor range 🎯
  • -fno-range β€” doesn't generate code for those range checks πŸ™…
  • -freturn β€” generates code to check that 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 one wasn't specified πŸ’…
  • -fsoft-check-all β€” turns on all runtime checks. This is the same as invoking GNU Modula-2 with -fnil -frange -findex -fwholediv -fcase -freturn πŸ”₯
  • -fauto-init β€” turns on auto initialisation of pointers to NIL. Whenever a block is created, every pointer declared in that scope gets its address assigned to NIL πŸŒ™
  • -fno-exceptions β€” turns off all generation of exception handling code. No references get made to the runtime exception libraries 🚫
  • -v β€” displays all 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 remain after optimisation, and how many source lines were compiled πŸ“Š
  • -fm2-whole-program β€” compiles all implementation modules and the program module at once πŸš€
Heads up bestie: you need to take care if you're compiling different dialect modules, especially with negative operands to modulus πŸ’€ But when you pair this option with -O3, it can deliver huge performance improvements.
  • -fm2-g β€” makes debugging nicer for new programmers, at the cost of sometimes generating nop instructions so single stepping stays precise over all 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, a list showing the initialisation order of all modules to be linked. The actual link does not happen. The GNU Modula-2 linker scans all IMPORTs, generates 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 needed ✏️ Once the .lst file exists, the compiler can use it to link your project via the -fuselist option. It has no effect if the -c option is present πŸ“
  • fno-pthread β€” doesn't 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 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 the reference the original page left off at πŸ’€ If -fcpp is supplied, every definition module and implementation module that gets parsed will be preprocessed by cpp 🧹
  • -fiso β€” turns on ISO standard features. Currently this enables the ISO SYSTEM module and changes the default library search path so the ISO libraries get searched before the PIM libraries. It also affects how the DIV and MOD operators behave. See the reference the original page left off at 🌍
  • -fpim β€” turns on PIM standard features. Currently 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 behave as defined in PIM4. See the reference the original page left off at πŸ›οΈ
  • -fpim2 β€” turns on PIM-2 standard features. Currently this removes SIZE from being a pervasive identifier, and places SIZE in the SYSTEM module instead. It also affects how DIV and MOD behave. See the reference the original page left off at πŸ“
  • -fpim3 β€” turns on PIM-3 standard features. Currently this only affects how DIV and MOD behave. See the reference the original page left off at πŸ”’
  • -fpim4 β€” turns on PIM-4 standard features. Currently this only affects how DIV and MOD behave. See the reference the original page left off at πŸ”’
  • -fpositive-mod-floor-div β€” forces DIV and MOD to behave as defined by PIM4. All modulus results come out positive, and division results get rounded to the floor. See the reference the original page left off at ⬇️
  • -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, the ISO standard libraries, minimal library support, the Logitech compatible library, and Programming in Modula-2 with coroutines πŸ“š You can specify multiple libraries, comma separated, and precedence goes to the first one in the list. 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. It's used to see where objects are located when linking occurs πŸ“
  • -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 will still fall back to that default if a requested definition module can't be found πŸŽ€

✨ OPTIONS ✨

  • -fmod= β€” okay bestie, this one lets you pick your own suffix and tells GNU Modula-2 to treat it as the one for both implementation and module filenames πŸŽ€ The default is .mod, and if you use this option, the compiler will still fall back to .mod when it needs to read an implementation module and your suffixed filename doesn't exist 🫢
  • -fxcode β€” every error and warning comes out in the Xcode format πŸ“
  • -fonlylink β€” only links the modula-2 application and skips compiling the program module beforehand πŸ¦‹
  • -funbounded-by-reference β€” an optimisation for unbounded parameters πŸ’… It tries to pass non VAR unbounded parameters by reference, which avoids the implicit copy inside the callee procedure ✨
    • GNU Modula-2 only lets unbounded parameters go by reference if, inside the callee procedure, they aren't written to, no address is calculated on the array, and the array isn't passed as a VAR parameter.
    • It's possible to write code that breaks this optimisation, so use it carefully πŸ’€ For example, you could take the address of an array, pass the address and the array to a procedure, read from the array in that procedure, and write to the location using the address parameter.
Dangerous! Because of how risky this option is, it's not enabled when the -O option is specified 😭
  • -Wverbose-unbounded β€” tells you which non VAR unbounded parameters will be passed by reference πŸ‘€ It only shows output if -funbounded-by-reference is also on the command line.
  • -Wstudents β€” a style check for bad programming habits, aimed at new Modula-2 users 🌸 It looks for things that might cause confusion and mistakes, like variables with the same name declared in different scopes, and variables that look like keywords. Experienced users might find it a little too aggressive πŸ™ˆ
  • -Wpedantic β€” the strict one 🧚 It forces the compiler to reject nested WITH statements that reference the same record type, and it doesn't allow multiple imports of the same item from a module. It also checks that:
    • procedure variables are written to before they're read
    • variables aren't only written to, they're also read from
    • variables are declared and used
    • if the compiler spots a variable being read before it's written, it stops with a message
    • FOR loop indices aren't used outside the end of the loop without being reset
  • -Wpedantic-param-names β€” checks procedure parameter names in the definition module against their implementation module counterparts πŸ” This isn't needed in ISO or PIM versions of Modula-2, but it can be extremely useful, as long as you're writing code this way on purpose πŸ’–
  • -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 users prefer to use VAL in these situations and save CAST for type changes on objects that are the same size πŸ’œ
  • -Wunused-variable β€” warns if a variable has been declared but never used 🧹
  • -Wunused-parameter β€” warns if a parameter has been declared but never used 🧹
  • -Wall β€” turns on all Modula-2 warnings πŸ”₯

✨ ENVIRONMENT ✨

Nothing is documented under this heading on this page, so there's nothing to report here 🫢


✨ SEE ALSO ✨

gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entries for gm2 and gcc πŸ“š


Copyright (c) 1999-2021 Free Software Foundation, Inc. 🌈

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation, with 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) πŸ“–


Okay bestie, that's the whole page, and you're officially a M2 expert now πŸ‘‘ This one came from the gcc-12 crew and was dated 2022-03-02, so go be iconic and keep those warnings on πŸ’…πŸ¦‹

πŸ“¦ where this page comes from