Ejemplo n.º 1
0
Archivo: Engine.cs Proyecto: Sullux/tws
 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;
 }
Ejemplo n.º 2
0
 public static void Print(AssemblyDefinition assemblyDefinition, StringWriter xStringWriter)
 {
     using (var xOutputWriter = new OutputWriter(xStringWriter))
     {
         new Printer(xOutputWriter).Visit(assemblyDefinition);
     }
 }
Ejemplo n.º 3
0
 private void InitializeAssembly(AssemblyDefinition assembly)
 {
     foreach (var xRef in AssemblyReferences)
     {
         assembly.AssemblyReferences.Add(xRef);
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
 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);
     }
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 public virtual void Visit(AssemblyDefinition assemblyDefinition)
 {
     Visit(assemblyDefinition.AssemblyReferences);
     Visit(assemblyDefinition.RootNamespace);
 }
Ejemplo n.º 10
0
 public KeywordParsingContext(AssemblyDefinition assembly)
 {
     mAssembly = assembly;
 }
Ejemplo n.º 11
0
 public abstract void EmitOutput(string file, AssemblyDefinition asm);