This repository has been archived by the owner. It is now read-only.
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (29 sloc) 1.35 KB
module MiniC.Compiler.Compiler
open System
open System.IO
open System.Reflection
open System.Reflection.Emit
let compile (assemblyBuilder : AssemblyBuilder) code =
let assemblyName = assemblyBuilder.GetName()
let moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name, assemblyName.Name + ".exe", true)
let program = Parser.parse code
let semanticAnalysisResult = SemanticAnalysis.analyze program
let ilBuilder = new ILBuilder(semanticAnalysisResult)
let ilClass = ilBuilder.BuildClass program
let codeGenerator = new CodeGenerator(moduleBuilder, ilClass, assemblyName.Name)
let (compiledType, entryPoint) = codeGenerator.GenerateType()
assemblyBuilder.SetEntryPoint entryPoint
(compiledType, entryPoint)
let compileToMemory assemblyName code =
let assemblyBuilder =
assemblyName, AssemblyBuilderAccess.RunAndSave)
compile assemblyBuilder code
let compileToFile fileName code =
let assemblyName = new AssemblyName (Path.GetFileNameWithoutExtension fileName)
let assemblyBuilder =
assemblyName, AssemblyBuilderAccess.RunAndSave,
let (_, _) = compile assemblyBuilder code
assemblyBuilder.Save (Path.GetFileName fileName)