GM2(1)
β¨ GM2(1) β¨
Okay bestie, this one is from the GNU manual crew π and it's all about the GNU Modula-2 compiler π (part 1 of 2)
π NAME
gm2 - The GNU Modula-2 Compiler. Yes, this is the whole compiler, and it's giving main character energy π
π§ SYNOPSIS
πΈ DESCRIPTION
π¦ OPTIONS
okay so for any input file, the file name suffix decides what kind of compilation happens. These are the input file name kinds that are supported:
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 aren't compiled on their own. Instead, definition modules get parsed whenever a program or implementation module gets compiled π«Ά If your project uses a different source file extension, see-fdef=.
You can specify more than one input file on the gm2 command line, π
-gβ creates debugging info so debuggers likegdbcan 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 specify this, the default path is the current directory, followed by 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. Pairing-Iwith-fobject-path=lets projects keep different styles of objects separate from their source. You could compile implementation modules with different levels of optimization, with or without debugging, and stash each in its own directory β¨ If you skip-fobject-path=, it gets set from whatever-Isays. If-Iwasn't specified either, 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. This is super useful for debugging the parameter values passed to a builtin function, because you can single step your code right into a real function π-fdump-system-exportsβ displays all inbuilt system items. This one is an internal command line option, so it's more for the compiler people π€-fswigβ generates a swig interface file π¦-fsharedβ generates a shared library from the module π-fmakeinitβ generates the start up C++ code for the module. It creates a file called_m2_modulename.cpp. This is also an internal command line option π§-fruntime-modules=β lets you list the runtime modules and their order, separated by commas. These modules get initialized first, before any other modules in the application dependency chain. By default the list isStorage,SYSTEM,M2RTS,RTExceptions,IOLink. These modules only get linked into your executable if they're actually required. So adding a long list of dependent modules won't change your executable's size. It just sets the initialization order, should they be needed π-fnilβ generates code that detects accessing data through aNILvalue pointer π¨-fno-nilβ does not generate thatNILpointer detection code π ββοΈ-fwholedivβ generates code that detects whole number division by zero, or modulus by zero β-fno-wholedivβ does not generate that division by zero detection code π ββοΈ-findexβ generates code that checks whether array index values are out of bounds π-fno-indexβ does not generate those array bounds checks π ββοΈ-frangeβ generates code that checks the assignment range, the return value range, the set range and the constructor range π―-fno-rangeβ does not generate those range checks π ββοΈ-freturnβ generates code that checks functions always exit with aRETURNand never just fall out the end π-fcaseβ turns on compile time checking for whether aCASEstatement needs anELSEclause when you didn't write one π§-fsoft-check-allβ turns on all runtime checks. It's the same as invoking GNU Modula-2 with-fnil-frange-findex-fwholediv-fcase-freturnπ―-fauto-initβ turns on auto initialization of pointers to NIL. Whenever a block is created, every pointer declared within that scope gets its address assigned to NIL πΈ-fno-exceptionsβ turns off all generation of exception handling code, and nothing references the runtime exception libraries π«-vβ displays every call 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 were compiled π-fm2-whole-programβ compiles all implementation modules and the program module all at once. Heads up, you need to take care if you're compiling different dialect modules (especially with negative operands to modulus) π But this option, paired with-O3, can deliver huge performance improvements π-fm2-gβ makes debugging easier for new programmers, at the cost of generatingnopinstructions when needed. This makes sure single stepping is precise over all the code-related keywords. For example, when a list of nestedIFstatements ends, the 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 that lists the initialization order of all the modules that are going to be linked. The actual link does not happen. The GNU Modula-2 linker scans allIMPORTs, builds a list of dependencies, and produces an ordered list for initialization.
It will probably get the order wrong if your project has cyclic dependencies. The good news is the.lstfile is plain text, so you can edit it if you need to π Once the.lstfile exists, the compiler can use it to link your project through the-fuselistoption. This has no effect if-cis present.
fno-pthreadβ does not 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β as long asgm2has been told to link the program module, this option uses the filemodulename.lstfor the initialization order of modules π-fcppβ preprocesses the source withcpp -lang-asm -traditional-cpp. For further details about these options see If-fcppis supplied then all definition modules and implementation modules which are parsed will be preprocessed bycppπ§Ή-fisoβ turns on ISO standard features. Right now 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-fpimβ turns on PIM standard features. Right now this enables the PIMSYSTEMmodule and decides which identifiers are pervasive (declared in the base module). If no other-fpim[234]switch is used, the division and modulus operators behave as defined in PIM4 π See-fpim2β turns on PIM-2 standard features. Right now this takesSIZEout of the pervasive identifiers (declared in the base module) and puts it in theSYSTEMmodule instead. It also affects howDIVandMODbehave. See-fpim3β turns on PIM-3 standard features. Right now this only affects howDIVandMODbehave. See-fpim4β turns on PIM-4 standard features. Right now this only affects howDIVandMODbehave. See-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-flibs=β modifies the default library search path. The libraries you can supply 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 several, separated by commas, and the first one in the list gets precedence. 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, since it provides the base modules that all the other dialects use π-fextended-opaqueβ lets opaque types 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 the module importing the opaque type gets compiled π-fsourcesβ displays the path to the source of each module. You can use this at compile time to double check the correct definition module is being used π-fmodulesβ displays the path to each module's object file. This option can only be invoked with-c. It's used to see where objects are located 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 will still fall back to that default if a requested definition module can't be found π¦-fmod=β okay so this one lets you pick your own suffix for implementation and module filenames π¦ The default is.mod. Even with this set, GNU Modula-2 will still fall back to.modif it needs to read an implementation module and your suffixed filename isn't there π«Ά-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β this one is a main character optimization π It tries to pass nonVARunbounded parameters by reference, which skips the implicit copy inside the callee procedure. GNU Modula-2 only does this if, inside the callee, the parameters aren't written to, no address is calculated on the array, and it isn't passed as aVARparameter. You can still write code that breaks it, so use it carefully π
This option is dangerous, bestie π Because of that, it is not enabled when the -O option is specified. For example, you could take the address of an array, pass both the address and the array to a procedure, read from the array in the procedure, and write to the location using the address parameter. Yikes.
-Wverbose-unboundedβ tells you which nonVARunbounded parameters will be passed by reference π’ It only shows anything if-funbounded-by-referenceis also on the command line-Wstudentsβ a style check for new Modula-2 users π± It catches stuff that could cause confusion and mistakes, like variables with the same name declared in different scopes, or 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 won't allow multiple imports of the same item from a module. It also checks that procedure variables are written to before being read, that variables aren't only written to but also read from, and that variables are declared and used. If the compiler finds a variable being read before it's written, it stops with a message. It also checks thatFORloop indices aren't used outside the end of the loop without being reset π-Wpedantic-param-namesβ checks that procedure parameter names in the definition module match their implementation module counterparts π This isn't required in ISO or PIM versions of Modula-2, but it can be super useful, as long as you're doing it 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 β οΈ This is legal in ISO Modula-2, but it can be dangerous. Some folks preferVALin these situations and only useCASTfor type changes on objects that are the same size π«Ά-Wunused-variableβ warns if a variable has been declared and never used π-Wunused-parameterβ warns if a parameter has been declared and never used πΈ-Wallβ turns on all the Modula-2 warnings ππ₯
β¨ ENVIRONMENT β¨
Nothing is documented in this section, so there's no environment variable tea to spill 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.
You're totally 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) π
That's a wrap on GM2(1) for the gcc-11 crowd, dated 2024-07-19 ππ Go be iconic with your Modula-2 code, bestie πβ¨
π¦ where this page comes from
- ubuntu noble: gm2-11-mipsisa32r6el-linux-gnu 11.5.0-1ubuntu1~24.04cross1
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms