SML# Document Version 4.0.0
33 Control structure of the compiler

33.2 The compiler command main function

The main function of the SML# command is the follwing function in the directory comiler/compilePhases/main/main/.

  val main : string * string list -> OS.Process.status

The argument pair consists of the command name (smlsharp or minismlsharp ) and the command line argument kist. This function invokes command function to do the following.

  1. 1.

    Parse the arugment list and determine the command mode and the set of command options.

  2. 2.

    Perfoms one of the following depending on the command mode.

    1. (a)

      Compile source files.

    2. (b)

      Compile and link one soruce file.

    3. (c)

      Link a system specified by a root .smi file.

    4. (d)

      Generate dependency and Makefile for a soure file.

    5. (e)

      Print various information.

    Compiling a source file is done by compileSMLFile function in the following steps.

    • Open the source file.

    • Generate a compile ontext (topContext) prepared by the command function.

    • Compile the source file by the Top.compile function in comiler/compilePhases/top/main/, which has the following type.

        val compile
            : LLVMUtils.compile_options
              -> options
              -> toplevelContext
              -> Parser.input
              -> InterfaceName.dependency * result
      

      The return value type InterfacceName.dependency represent the set of interface files used by the source file, and result denotes the generated object file.

    Compile and link is done by link function in the following steps.

    1. (a)

      If the input is a soruce file (.sml file), then compile it to obtain an object file and the set of dependent interface files. If the input file is an interface file (.smi file), determine the root object file, and obtain the set of dependent interface files by calling loadSMI function.

    2. (b)

      Link the root object file, the set of dependent object files and the referenced library files by calling the system linker.