# dmd.mars

Entry point for DMD.

#### Discussion

This modules defines the entry point (main) for DMD, as well as related utilities needed for arguments parsing, path manipulation, etc... This file is not shared with other compilers which use the DMD front-end.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: mars.d

Documentation: https://dlang.org/phobos/dmd_mars.html

Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/mars.d

- `parseCommandlineAndConfig`

  #### Declaration

  `bool `parseCommandlineAndConfig`(size_t `argc`, const(char)** `argv`, ref Param `params`, ref Strings `files`);`

  Parses the command line arguments and configuration `files`

  #### Parameters

  `size_t `argc`` | Number of arguments passed via command line
  `const(char)** `argv`` | Array of string arguments passed via command line
  `Param `params`` | parametes from `argv`
  `Strings `files`` | `files` from `argv`

  #### Return Value

  `true` on faiure

- `emitMakeDeps`

  #### Declaration

  `void `emitMakeDeps`(ref Param `params`);`

  Emit the makefile dependencies for the -makedeps switch

- `main`

  #### Declaration

  `int `main`(int `argc`, char** `argv`);`

  DMD's entry point, C `main`.

  #### Discussion

  Without `-lowmem`, we need to switch to the bump-pointer allocation scheme right from the start, before any module ctors are run, so we need this hook before druntime is initialized and `_Dmain` is called.

  #### Return Value

  Return code of the application

- `_Dmain`

  #### Declaration

  `int `_Dmain`(char[][]);`

  Manual D main (for druntime initialization), which forwards to `tryMain`.

  #### Return Value

  Return code of the application

- `getenv_setargv`

  #### Declaration

  `void `getenv_setargv`(const(char)* `envvalue`, Strings* `args`);`

  Parses an environment variable containing command-line flags and append them to ``args``.

  #### Discussion

  This function is used to read the content of DFLAGS. Flags are separated based on spaces and tabs.

  #### Parameters

  `const(char)* `envvalue`` | The content of an environment variable
  `Strings* `args`` | Array to append the flags to, if any.

- `parse_arch_arg`

  #### Declaration

  `const(char)[] `parse_arch_arg`(Strings* `args`, const(char)[] `arch`);`

  Parse command line arguments for the last instance of -m32, -m64, -m32mscoff or -m32omfobj to detect the desired architecture.

  #### Parameters

  `Strings* `args`` | Command line arguments
  `const(char)[] `arch`` | Default value to use for architecture. Should be "32" or "64"

  #### Return Value

  "32", "64" or "32omf" if the "-m32", "-m64", "-m32omf" flags were passed, respectively. If they weren't, return ``arch``.

- `parse_conf_arg`

  #### Declaration

  `const(char)[] `parse_conf_arg`(Strings* `args`);`

  Parse command line arguments for the last instance of -conf=path.

  #### Parameters

  `Strings* `args`` | Command line arguments

  #### Return Value

  The 'path' in -conf=path, which is the path to the config file to use

- `addDefaultVersionIdentifiers`

  #### Declaration

  `void `addDefaultVersionIdentifiers`(const ref Param `params`, const ref Target `tgt`);`

  Add default `version` identifier for dmd, and set the target platform in ``params``. https://dlang.org/spec/version.html#predefined-versions

  #### Discussion

  Needs to be run after all arguments parsing (command line, DFLAGS environment variable and config file) in order to add final flags (such as `X86_64` or the `CRuntime` used).

  #### Parameters

  `Param `params`` | which target to compile for (set by `setTarget()`)
  `Target `tgt`` | target

- `flushMixins`

  #### Declaration

  `void `flushMixins`();`

  we want to write the mixin expansion file also on error, but there are too many ways to terminate dmd (e.g. fatal() which calls exit(EXIT_FAILURE)), so we can't rely on scope(exit) ... in tryMain() actually being executed so we add atexit(&`flushMixins`); for those fatal exits (with the GC still valid)

- `parseCommandLine`

  #### Declaration

  `bool `parseCommandLine`(const ref Strings `arguments`, const size_t `argc`, ref Param `params`, ref Strings `files`, ref Target `target`);`

  Parse command line `arguments`.

  #### Discussion

  Prints message(s) if there are errors.

  #### Parameters

  `Strings `arguments`` | command line `arguments`
  `size_t `argc`` | argument count
  `Param `params`` | set to result of parsing ``arguments``
  `Strings `files`` | set to `files` pulled from ``arguments``
  `Target `target`` | more things set to result of parsing ``arguments``

  #### Return Value

  `true` if errors in command line

- `moduleWithEmptyMain`

  #### Declaration

  `Module `moduleWithEmptyMain`();`

  #### Return Value

  a compiled module (semantic3) containing an empty main() function, for the -main flag