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 likegdbcan 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-Iand-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-Isays. If-Iwasn'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 isStorage,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 aNILvalue pointer π-fno-nilβ doesn't generate thatNILpointer 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 aRETURNand don't just fall out at the end πͺ-fcaseβ turns on compile time checking for whether aCASEstatement needs anELSEclause 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 toNIL. Whenever a block is created, every pointer declared in that scope gets its address assigned toNILπ-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 generatingnopinstructions so single stepping stays precise over all code related keywords. For example, when a list of nestedIFstatements ends, multipleENDkeywords get mapped onto a sequence ofnopinstructions π§Έ-fm2-lower-caseβ renders keywords in error messages in lower case π€-fmakelistβ only applies when linking a program module. The compiler generates amodulename.lstfile, a list showing the initialisation order of all modules to be linked. The actual link does not happen. The GNU Modula-2 linker scans allIMPORTs, 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.lstfile is plain text, so you can edit it if needed βοΈ Once the.lstfile exists, the compiler can use it to link your project via the-fuselistoption. It has no effect if the-coption is present πfno-pthreadβ doesn't automatically link against the pthread library. This is likely useful ifgm2is 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β oncegm2has been told to link the program module, this uses the filemodulename.lstfor the initialisation order of modules π-fcppβ preprocesses the source withcpp -lang-asm -traditional-cpp. For further details about these options, see the reference the original page left off at π If-fcppis supplied, every definition module and implementation module that gets parsed will be preprocessed bycppπ§Ή-fisoβ turns on ISO standard features. Currently this enables the ISOSYSTEMmodule and changes the default library search path so the ISO libraries get searched before the PIM libraries. It also affects how theDIVandMODoperators behave. See the reference the original page left off at π-fpimβ turns on PIM standard features. Currently this enables the PIMSYSTEMmodule 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 removesSIZEfrom being a pervasive identifier, and placesSIZEin theSYSTEMmodule instead. It also affects howDIVandMODbehave. See the reference the original page left off at π-fpim3β turns on PIM-3 standard features. Currently this only affects howDIVandMODbehave. See the reference the original page left off at π’-fpim4β turns on PIM-4 standard features. Currently this only affects howDIVandMODbehave. See the reference the original page left off at π’-fpositive-mod-floor-divβ forcesDIVandMODto 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 arem2pim,m2iso,m2min,m2logandm2cor. 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=m2pimor-flibs=m2isoif you also specify-fpim,-fpim2,-fpim3,-fpim4or-fiso. Unless you're using-flibs=m2min, you should includem2pim, 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-coption. 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.modwhen 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 themodula-2application and skips compiling the program module beforehand π¦-funbounded-by-referenceβ an optimisation for unbounded parameters π It tries to pass nonVARunbounded 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
VARparameter. - 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.
- 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
Dangerous! Because of how risky this option is, it's not enabled when the -O option is specified π
-Wverbose-unboundedβ tells you which nonVARunbounded parameters will be passed by reference π It only shows output if-funbounded-by-referenceis 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 nestedWITHstatements 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
FORloop 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 useVALin these situations and saveCASTfor 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 β¨
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
- ubuntu jammy: gm2-12-riscv64-linux-gnu 12-20220302-1ubuntu1cross1
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms