// Copyright (c) Ivan Bondarev, Stanislav Mihalkovich (for details please see \doc\copyright.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; using PascalABCCompiler.SemanticTree; using System.Threading; using System.Reflection; using System.Reflection.Emit; using System.Collections; using System.Collections.Generic; using System.IO; using System.Diagnostics.SymbolStore; using System.Runtime.InteropServices; using System.Runtime.Remoting; using System.Security; using System.Runtime.Versioning; namespace PascalABCCompiler.NETGenerator { public enum TargetType { Exe, Dll, WinExe } public enum DebugAttributes { Debug, ForDebbuging, Release } //compiler options class public class CompilerOptions { public enum PlatformTarget { x64, x86, AnyCPU }; public TargetType target = TargetType.Exe; public DebugAttributes dbg_attrs = DebugAttributes.Release; public bool optimize = false; public bool ForRunningWithEnvironment = false; public bool GenerateDebugInfoForInitalValue = true; public bool NeedDefineVersionInfo = false; private string _Product = ""; private PlatformTarget _platformtarget = PlatformTarget.AnyCPU; public PlatformTarget platformtarget { get { return _platformtarget; } set { _platformtarget = value; } } public string Product { get { return _Product; } set { _Product = value; NeedDefineVersionInfo = true; } } private string _ProductVersion = ""; public string ProductVersion { get { return _ProductVersion; } set { _ProductVersion = value; NeedDefineVersionInfo = true; } } private string _Company = ""; public string Company { get { return _Company; } set { _Company = value; NeedDefineVersionInfo = true; } } private string _Copyright = ""; public string Copyright { get { return _Copyright; } set { _Copyright = value; NeedDefineVersionInfo = true; } } private string _TradeMark = ""; public string TradeMark { get { return _TradeMark; } set { _TradeMark = value; NeedDefineVersionInfo = true; } } public string MainResourceFileName = null; public byte[] MainResourceData = null; public CompilerOptions() { } } /// /// Класс, переводящий сем. дерево в сборку .NET /// public class ILConverter : AbstractVisitor { protected AppDomain ad;//домен приложения (в нем будет генерироваться сборка) protected AssemblyName an;//имя сборки protected AssemblyBuilder ab;//билдер для сборки protected ModuleBuilder mb;//билдер для модуля protected TypeBuilder entry_type;//тип-обертка над осн. программой protected TypeBuilder cur_type;//текущий компилируемый тип protected MethodBuilder entry_meth;//входная точка в приложение protected MethodBuilder cur_meth;//текущий билдер для метода protected MethodBuilder init_variables_mb; protected ILGenerator il;//стандартный класс для генерации IL-кода protected ISymbolDocumentWriter doc;//класс для генерации отладочной информации protected ISymbolDocumentWriter first_doc;//класс для генерации отладочной информации protected Stack