Example #1
0
 public Emitter(EmitterOptions options)
 {
     _options = options;
     _assemblyName = new AssemblyName(_options.AssemblyName);
     _assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave);// TODO: temp for debugging .RunAndCollect);
     if (_options.DebugOn)
         _assembly.SetCustomAttribute
         (
             new CustomAttributeBuilder
             (
                 typeof(DebuggableAttribute).GetConstructor
                 (
                     new System.Type[] { typeof(DebuggableAttribute.DebuggingModes) }
                 ),
                 new object[]
                 {
                     DebuggableAttribute.DebuggingModes.DisableOptimizations |
                     DebuggableAttribute.DebuggingModes.Default
                 }
             )
         );
     _module = _assembly.DefineDynamicModule(_assemblyName.Name, _assemblyName.Name + ".dll", _options.DebugOn);
     if (_options.DebugOn)
         _symbolWriter = _module.DefineDocument(_options.SourceFileName, Guid.Empty, Guid.Empty, Guid.Empty);
     _tupleToNative = new Dictionary<Type.TupleType, System.Type>();
 }
 public ILDynamicMethodDebugImpl(string name, Type delegateType, Type thisType)
 {
     _delegateType = delegateType;
     _expectedLength = 64;
     var mi = delegateType.GetMethod("Invoke");
     var uniqueName = ILDynamicTypeDebugImpl.UniqueName(name);
     _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(uniqueName), AssemblyBuilderAccess.RunAndSave, DynamicILDirectoryPath.DynamicIL);
     _moduleBuilder = _assemblyBuilder.DefineDynamicModule(uniqueName + ".dll", true);
     var sourceCodeFileName = Path.Combine(DynamicILDirectoryPath.DynamicIL, uniqueName + ".il");
     _symbolDocumentWriter = _moduleBuilder.DefineDocument(sourceCodeFileName, SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft);
     _sourceCodeWriter = new SourceCodeWriter(sourceCodeFileName, _symbolDocumentWriter);
     Type[] parameterTypes;
     if (thisType != null)
     {
         parameterTypes = new[] { thisType }.Concat(mi.GetParameters().Select(pi => pi.ParameterType)).ToArray();
     }
     else
     {
         parameterTypes = mi.GetParameters().Select(pi => pi.ParameterType).ToArray();
     }
     _sourceCodeWriter.StartMethod(name, mi.ReturnType, parameterTypes, MethodAttributes.Static);
     _typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, typeof(object), Type.EmptyTypes);
     _forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
     _dynamicMethod = _typeBuilder.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Static, mi.ReturnType, parameterTypes);
     for (int i = 0; i < parameterTypes.Length; i++)
     {
         _dynamicMethod.DefineParameter(i + 1, ParameterAttributes.In, string.Format("arg{0}", i));
     }
 }
Example #3
0
File: exe.cs Project: master/plil
 public void BeginModule(string ifile)
 {
     appdomain	= System.Threading.Thread.GetDomain();
     appname		= getAssemblyName(filename);
     appbuild	= appdomain.DefineDynamicAssembly(appname, AssemblyBuilderAccess.Save, ".");
     emodule		= appbuild.DefineDynamicModule(filename + "_module", io.GetOutputFilename(), io.getGenDebug());
     Guid g 		= System.Guid.Empty;
     if (io.getGenDebug()) srcdoc = emodule.DefineDocument(ifile, g, g, g);
 }
Example #4
0
 public ILDynamicTypeDebugImpl(string name, Type baseType, Type[] interfaces)
 {
     _name = name;
     var uniqueName = UniqueName(name);
     _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(uniqueName), AssemblyBuilderAccess.RunAndSave, "dynamicIL");
     _moduleBuilder = _assemblyBuilder.DefineDynamicModule(uniqueName + ".dll", true);
     var sourceCodeFileName = Path.GetFullPath("dynamicIL/" + uniqueName + ".il");
     _symbolDocumentWriter = _moduleBuilder.DefineDocument(sourceCodeFileName, SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft);
     _sourceCodeWriter = new SourceCodeWriter(sourceCodeFileName, _symbolDocumentWriter);
     _sourceCodeWriter.WriteLine(string.Format("class {0} : {1}{2}", name, baseType.ToSimpleName(), string.Concat(interfaces.Select(i => ", " + i.ToSimpleName()))));
     _sourceCodeWriter.OpenScope();
     _typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, baseType, interfaces);
     _forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
 }
Example #5
0
 public ILDynamicTypeDebugImpl(string name, Type baseType, Type[] interfaces)
 {
     _name = name;
     var uniqueName = UniqueName(name, 259 - (DynamicILDirectoryPath.DynamicIL.Length + 1 + 4));
     _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(uniqueName), AssemblyBuilderAccess.RunAndSave, DynamicILDirectoryPath.DynamicIL);
     _moduleBuilder = _assemblyBuilder.DefineDynamicModule(uniqueName + ".dll", true);
     var sourceCodeFileName = Path.Combine(DynamicILDirectoryPath.DynamicIL, uniqueName + ".il");
     _symbolDocumentWriter = _moduleBuilder.DefineDocument(sourceCodeFileName, SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft);
     _sourceCodeWriter = new SourceCodeWriter(sourceCodeFileName, _symbolDocumentWriter);
     _sourceCodeWriter.WriteLine(
         $"class {name} : {baseType.ToSimpleName()}{string.Concat(interfaces.Select(i => ", " + i.ToSimpleName()))}");
     _sourceCodeWriter.OpenScope();
     _typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, baseType, interfaces);
     _forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
 }
Example #6
0
        public static Parser GetParser(ModuleBuilder mb, LOLProgram prog, string filename, Stream s, CompilerResults cr) {
            Parser p = new Parser(new Scanner(s));
            p.filename = Path.GetFileName(filename);
            if (prog.compileropts.IncludeDebugInformation)
            {
                p.doc = mb.DefineDocument(p.filename, Guid.Empty, Guid.Empty, Guid.Empty);
            }
            else
            {
                //Not a debug build
                p.doc = null;
            }

            p.program = prog;
            p.errors = new Errors(cr.Errors);
            p.main = prog.methods["Main"];

            return p;
        }
Example #7
0
        public Emitter(EmitterOptions options)
        {
            _options = options;

            //// TODO: setup separate app domain with appropriate cache path, shadow copying etc.
            //var domainName = "plan" + DateTime.Now.Ticks.ToString();
            //var domain = AppDomain.CreateDomain(domainName);

            _assemblyName = new AssemblyName(_options.AssemblyName);
            _assembly =
                AppDomain.CurrentDomain.DefineDynamicAssembly
                (
                    _assemblyName,
                    _options.DebugOn ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.RunAndCollect
                );
            if (_options.DebugOn)
                _assembly.SetCustomAttribute
                (
                    new CustomAttributeBuilder
                    (
                        typeof(DebuggableAttribute).GetConstructor
                        (
                            new System.Type[] { typeof(DebuggableAttribute.DebuggingModes) }
                        ),
                        new object[]
                        {
                            DebuggableAttribute.DebuggingModes.DisableOptimizations |
                            DebuggableAttribute.DebuggingModes.Default
                        }
                    )
                );

            _module = _assembly.DefineDynamicModule(_assemblyName.Name, _assemblyName.Name + ".dll", _options.DebugOn);
            if (_options.DebugOn)
                _symbolWriter = _module.DefineDocument(_options.SourceFileName, Guid.Empty, Guid.Empty, Guid.Empty);
            _tupleToNative = new Dictionary<TupleType, System.Type>();
        }
Example #8
0
		internal void DefineSymbolDocument(ModuleBuilder module, string url, Guid language, Guid languageVendor, Guid documentType)
		{
			symbols = module.DefineDocument(url, language, languageVendor, documentType);
		}
Example #9
0
 ISymbolDocumentWriter GetDocumentWriterFor(ISymbolDocument doc, ModuleBuilder moduleBuilder)
 {
     return moduleBuilder.DefineDocument(doc.URL, doc.Language, doc.LanguageVendor, doc.DocumentType);
 }
Example #10
0
        /// <summary>
        /// set program name and creates AssemblyBuilder, ModuleBuilder and debug Document
        /// </summary>
        /// <param name="n">N.</param>
        public void DefineProgram(string n)
        {
            this.ProgramName = n.ToUpper();

            // create AssemblyBuilder for RunAndSave
            AssemblyName aName = new AssemblyName(this.ProgramName);
            ab = AppDomain.CurrentDomain.DefineDynamicAssembly( aName,
                                                               AssemblyBuilderAccess.RunAndSave );

            // mark generated code as debuggable
            System.Type daType = typeof(DebuggableAttribute);
            ConstructorInfo daCtor = daType.GetConstructor(new System.Type[] { typeof(DebuggableAttribute.DebuggingModes) });
            CustomAttributeBuilder daBuilder = new CustomAttributeBuilder(daCtor, new object[] {
                DebuggableAttribute.DebuggingModes.DisableOptimizations |
                DebuggableAttribute.DebuggingModes.Default });
            ab.SetCustomAttribute(daBuilder);

            // For a single-module assembly, the module name is usually
            // the assembly name plus an extension.
            module = ab.DefineDynamicModule(this.ProgramName, this.ProgramName + ".dll", true);

            // Tell Emit about the source file that we want to associate this with.
            FileInfo info = new FileInfo(this.ProgramName + ".abap");
            doc = module.DefineDocument(info.FullName, Guid.Empty, Guid.Empty, Guid.Empty);
        }