SML# Document Version 3.7.1
33 Control structure of the compiler

33.3 The compiler toplevel

The toplevel function of the SML# compiler is function Top.compile definde in comiler/compilePhases/toplevel/main/Top.sml file. Its has the following type.

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

It takes LLVM code generation options, compile options, compile context, input stream of the source file, compiles the source and returns the set of dependent interface files and the result object file. This function is called from compileSML function in Main.sml file. It compiles the source file by calling the funtions of the compilation phases as shown in the following table.

Compile step Compile Phase Function Source Language Target Language
1 Parser.parse (input stream) Absyn.absyn
2 LoadFile.load Absyn.absyn AbsynInterface.compile_unit
3 Elaborator.elaborate AbsynInterface.compile_unit PatternCalcInterface.compile_unit
4 NameEval.nameEval PatternCalcInterface.compile_unit IDCalc.topdecl
5 TypedElaboration.elaborate IDCalc.topdecl IDCalc.topdecl
6 VALREC_Optimizer.optimize IDCalc.topdecl IDCalc.topdecl
7 InferTypes.typeinf IDCalc.topdecl TypedCalc.tpdecl list
8 UncurryFundecl.optimize TypedCalc.tpdecl list TypedCalc.tpdecl list
9 PolyTyElimination.compile TypedCalc.tpdecl list TypedCalc.tpdecl list
10 TPOptimize.optimize TypedCalc.tpdecl list TypedCalc.tpdecl list
11 MatchCompiler.compile TypedCalc.tpdecl list RecordCalc.rcdecl list
12 FFICompilation.compile RecordCalc.rcdecl list RecordCalc.rcdecl list
13 RecordCompilation.compile RecordCalc.rcdecl list RecordCalc.rcdecl list
13 DatatypeCompilation.compile RecordCalc.rcdecl list TypedLambda.tldecl list
14 BitmapCompilation2.compile TypedCalc.tpdecl list BitmapCalc2.bcdecl list
15 ClosureConversion2.convert BitmapCalc2.bcdecl list ClosureCalc.program
16 CallingConventionCompile.compile ClosureCalc.program RuntimeCalc.program
17 ANormalize.compile RuntimeCalc.program ANormal.program
18 MachineCodeGen.compile ANormal.program MachineCode.program
18 ConcurrencySupport.insertCheckGC MachineCode.program MachineCode.program
19 StackAllocation.compile MachineCode.program MachineCode.program
19 LLVMGen.compile MachineCode.program LLVMIR.program
20 LLVMEmit.emit LLVMIR.program LLVM.LLVMModuleRef