Changes between Version 1 and Version 2 of Commentary/Compiler/CommandLineArgs


Ignore:
Timestamp:
Feb 21, 2014 5:08:57 PM (18 months ago)
Author:
spacepuppies
Comment:

/compiler/main/StaticFlagParser.hs was deleted in #7595. Also reworded/formatted some things.

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/CommandLineArgs

    v1 v2  
    11= Parsing of command line arguments =
    2 GHC's many flavours of command line flags make the code interpreting them rather involved. The following provides a brief overview of the processing of these options. Since the addition of the interactive front-end to GHC, there are two kinds of flags: static and dynamic. Static flags can only be set once on the command line. They remain the same throughout the whole GHC session (so for example you cannot change them within GHCi using `:set` or with `OPTIONS_GHC` pragma in the source code). Dynamic flags are the opposite: they can be changed in GHCi sessions using `:set` command or `OPTIONS_GHC` pragma in the source code. There are few static flags and it is likely that in the future there will be even less. Thus, you won't see to much static flag references in the source code, but you will see a lot of functions that use dynamic flags.
     2GHC's many flavours of command line flags make the code interpreting them rather involved. The following provides a brief overview of the processing of these options. Since the addition of the interactive front-end to GHC, there are two kinds of flags: static and dynamic. Static flags can only be set once on the command line. They remain the same throughout the whole GHC session (so for example you cannot change them within GHCi using `:set` or with `OPTIONS_GHC` pragma in the source code). Dynamic flags are the opposite: they can be changed in GHCi sessions using `:set` command or `OPTIONS_GHC` pragma in the source code. There are few static flags and it is likely that in the future there will be even less. Thus, you won't see many static flag references in the source code, but you will see a lot of functions that use dynamic flags.
    33
    44Command line flags are described by Flag data type defined in [[GhcFile(compiler/main/CmdLineParser.hs)]]:
     
    1515== Static flags  ==
    1616
    17 Files [[GhcFile(compiler/main/StaticFlagParser.hs)]] and [[GhcFile(compiler/main/StaticFlags.hs)]] contain functions responsible for parsing static flags. Two global IORefs are used in this process: `v_opt_C_ready` and `v_opt_C`. These are defined using `GLOBAL_VAR` macro from [[GhcFile(compiler/HsVersions.h)]]. First IORef is a flag that checks whether the static flags are parsed at the right time. It is initialized to `False` and after the parsing has been done it is set to `True`. `v_opt_C` is a `[String]` used to store parsed flags (see `addOpt` and `removeOpt` functions). `flagsStatic :: [Flag IO]` in [[GhcFile(compiler/main/StaticFlagParser.hs)]] defines a list of static flags and what actions should be taken when these flags are encountered (see `Flag` data type above). Function `parseStaticFlags ::` from the same file is an entry point for parsing static flags. It is called by the `main :: IO ()` function of GHC in [[GhcFile(ghc/Main.hs)]]. [[GhcFile(compiler/main/StaticFlags.hs)]] contains some helper functions to check whether particular flags have been set. `staticFlags :: [String]` and `packed_staticFlags :: [FastString]` return list of parsed command line static flags, provided that parsing has been done (checking the value of `v_opt_C_ready`).
     17Static flags are managed by functions in [[GhcFile(compiler/main/StaticFlags.hs)]].
     18
     19Function `parseStaticFlags ::` is an entry point for parsing static flags. It is called by the `main :: IO ()` function of GHC in [[GhcFile(ghc/Main.hs)]]. Two global IORefs are used to parse static flags: `v_opt_C_ready` and `v_opt_C`. These are defined using `GLOBAL_VAR` macro from [[GhcFile(compiler/HsVersions.h)]]. First IORef is a flag that checks whether the static flags are parsed at the right time. Initialized to `False`, it is set to `True` after the parsing is done. `v_opt_C` is a `[String]` used to store parsed flags (see `addOpt` and `removeOpt` functions).
     20
     21In [[GhcFile(compiler/main/StaticFlags.hs)]], `flagsStatic :: [Flag IO]` defines a list of static flags and what actions should be taken when these flags are encountered (see `Flag` data type above). It also contains some helper functions to check whether particular flags have been set. Functions `staticFlags :: [String]` and `packed_staticFlags :: [FastString]` return a list of parsed command line static flags, provided that parsing has been done (checking the value of `v_opt_C_ready`).
    1822
    1923== Dynamic flags ==