SML# Document Version 4.1.0
33 Control structure of the compiler

33.1 Compiler Start-up

The SML# compiler is an SML# program separately compiled and liked by the SML# compiler. the main function of an SML# program, initially called from the SML# runtime system, sequentially evaluets the top-level declarations of the set of source files in an order that respects the dependency among the source files. The set of source files of an SML# program consists of the source file corresponding to the root interface file specified as a command line argument to the link mode SML# command, and the source files correspondig to the interface files that are (directly and indirectly) referenced from the root interface file.

The SML# compiler command is linked by the following shell command written in Makefile file for the target src/compiler/smlsharp.

        $(SMLSHARP_ENV) $(SMLSHARP_STAGE1) -Bsrc -nostdpath $(SMLFLAGS) \
Ψ-filemap=filemap \
Ψ$(RDYNAMIC_LDFLAGS) $(LLVM_SMLSHARP_LDFLAGS) --link-all \
Ψ$(srcdir)/src/compiler/smlsharp.smi \
Ψ$(COMPILER_SUPPORT_OBJECTS) $(LLVM_LIBS) $(LLVM_SYSLIBS) -o $@

In the standard configuration, the shell variable SMLSHARP_STAGE1 is bound to minismlsharp commande, which is the same as smlsharp except that it links a minimal set of libraries. The top-lebel source file of the SML# compiler is

./src/compiler/smlsharp.sml

which corresponds to the root interface file ./src/compiler/smlsharp.smi specified in the avove shell command. This file consists of the following four lines.

  val commandLineName = CommandLine.name ()
  val commandArgs = CommandLine.arguments ()
  val status = Main.main (commandLineName, commandArgs)
  val () = OS.Process.exit status

Main.main is the following main function written in the file Main.sml in comiler/compilePhases/main/main directory.

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

This is the top-level function of the SML# compiler. This function takes a command name (smlsharp) string and command line parameter string list, and perform compilations and linking according to the parameter specification.