public AssemblyDefinition Execute() { mResult = new AssemblyDefinition(Host); if (InitializeAssembly != null) { InitializeAssembly(mResult); } mParsingContexts.Push(mResult); mParsingContexts.Push(new KeywordParsingContext(mResult)); var xShouldLoop = true; while (xShouldLoop) { // todo: replace by pattern matching statement switch (mToken.TagValue) { case Tag.Identifier: var xWord = (Word)mToken; switch (mKeywords.IndexOf(xWord.Value)) { case Keywords.Namespace_Idx: ParseNamespace(mResult.RootNamespace); break; default: throw new Exception("Syntax error, Keyword not expected: " + xWord.Value); } break; case Tag.EndOfStream: xShouldLoop = false; break; } } return mResult; }
public static void Print(AssemblyDefinition assemblyDefinition, StringWriter xStringWriter) { using (var xOutputWriter = new OutputWriter(xStringWriter)) { new Printer(xOutputWriter).Visit(assemblyDefinition); } }
private void InitializeAssembly(AssemblyDefinition assembly) { foreach (var xRef in AssemblyReferences) { assembly.AssemblyReferences.Add(xRef); } }
public override void EmitOutput(string file, AssemblyDefinition asm) { mHostEnvironment = new CCIEnvironment(); mAssembly = new MCM.Assembly(); mAssembly.Name = mHostEnvironment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(file)); mAssembly.ModuleName = mHostEnvironment.NameTable.GetNameFor(Path.GetFileName(file)); RunVisitors(asm); mAssembly.Kind = ModuleKind.DynamicallyLinkedLibrary; // todo: add pdb writing using (var xOut = new FileStream(file, FileMode.Create)) { PeWriter.WritePeToStream(mAssembly, mHostEnvironment, xOut); } }
public void CompileSource(string source) { var xParser = new Engine(new Lexer.Lexer(source), Host); xParser.InitializeAssembly += InitializeAssembly; var xOutputAssembly = xParser.Execute(); if (OutputAssembly == null) { OutputAssembly = xOutputAssembly; } else { MergeAssembly(OutputAssembly, xOutputAssembly); } }
private void RunVisitors(AssemblyDefinition asm) { // create namespaces and types var xEmitter1 = new EmitVisitorPhase1(mAssembly, mHostEnvironment); xEmitter1.Visit(asm); var xTypes = xEmitter1.Types; // set basetypes var xEmitter2 = new EmitVisitorPhase2(mAssembly, mHostEnvironment); xEmitter2.Visit(asm); // create methods var xEmitter3 = new EmitVisitorPhase3(mAssembly, mHostEnvironment); xEmitter3.TypesMap = xTypes; xEmitter3.Visit(asm); var xMethods = xEmitter3.MethodsMap; // emit method bodies var xEmitter4 = new EmitVisitorPhase4(mAssembly, mHostEnvironment); xEmitter4.MethodsMap = xMethods; xEmitter4.TypesMap = xTypes; xEmitter4.Visit(asm); }
private static void MergeAssembly(AssemblyDefinition target, AssemblyDefinition source) { foreach (var xSourceAsmRef in source.AssemblyReferences) { bool xFound = false; foreach (var xTargetAsmRef in target.AssemblyReferences) { if (xTargetAsmRef.FullName == xSourceAsmRef.FullName) { xFound = true; break; } } if (!xFound) { target.AssemblyReferences.Add(xSourceAsmRef); } } MergeNamespace(target.RootNamespace, source.RootNamespace); }
public override void Visit(AssemblyDefinition assemblyDefinition) { foreach (var xAsmRef in assemblyDefinition.AssemblyReferences) { mAssembly.AssemblyReferences.Add(new MCM.AssemblyReference { Name = mHostEnvironment.NameTable.GetNameFor(xAsmRef.Name) }); } // root namespace mAssembly.UnitNamespaceRoot = new MCM.RootUnitNamespace() { Unit = mAssembly }; var xModClass = new MCM.NamespaceTypeDefinition { ContainingUnitNamespace = mAssembly.UnitNamespaceRoot, InternFactory = mHostEnvironment.InternFactory, IsClass = true, Name = mHostEnvironment.NameTable.GetNameFor("<Module>") }; mAssembly.AllTypes.Add(xModClass); mNamespaces.Push((MCM.UnitNamespace)mAssembly.UnitNamespaceRoot); base.Visit(assemblyDefinition); }
public virtual void Visit(AssemblyDefinition assemblyDefinition) { Visit(assemblyDefinition.AssemblyReferences); Visit(assemblyDefinition.RootNamespace); }
public KeywordParsingContext(AssemblyDefinition assembly) { mAssembly = assembly; }
public abstract void EmitOutput(string file, AssemblyDefinition asm);