public CompilerParameters(IReflectionTypeSystemProvider reflectionProvider, bool loadDefaultReferences) { _libPaths = new List <string>(); _systemDir = Permissions.WithDiscoveryPermission(() => GetSystemDir()); if (_systemDir != null) { _libPaths.Add(_systemDir); _libPaths.Add(Directory.GetCurrentDirectory()); } _pipeline = null; _input = new CompilerInputCollection(); _resources = new CompilerResourceCollection(); _compilerReferences = new CompilerReferenceCollection(reflectionProvider); _maxExpansionIterations = 12; _outputAssembly = String.Empty; _outputType = CompilerOutputType.Auto; _outputWriter = Console.Out; _debug = true; _checked = true; _generateInMemory = true; _stdLib = true; _delaySign = false; Strict = false; TraceLevel = TraceLevel.Off; if (loadDefaultReferences) { LoadDefaultReferences(); } }
private static string UpdateOutputName(string outputName, CompilerOutputType outputType) { switch (outputType) { case CompilerOutputType.Executable: if (PlatformUtilities.IsWindows) { return(Path.ChangeExtension(outputName, "exe")); } else { return(outputName); } case CompilerOutputType.SharedLibrary: if (PlatformUtilities.IsWindows) { return(Path.ChangeExtension(outputName, "dll")); } else { return(Path.ChangeExtension(outputName, "so")); } default: throw new NotSupportedException("Support for output type '{0}' has not been implemented.".FormatInvariantWithArgs(outputType)); } }
public CompilerParameters(bool loadDefaultReferences) { _libpaths = new ArrayList(); _systemDir = GetSystemDir(); _libpaths.Add(_systemDir); _libpaths.Add(Directory.GetCurrentDirectory()); _pipeline = null; _input = new CompilerInputCollection(); _resources = new CompilerResourceCollection(); _assemblyReferences = new AssemblyCollection(); _maxAttributeSteps = 2; _outputAssembly = string.Empty; _outputType = CompilerOutputType.ConsoleApplication; _outputWriter = System.Console.Out; _debug = true; _checked = true; _generateInMemory = true; _StdLib = true; _delaySign = false; if (loadDefaultReferences) { LoadDefaultReferences(); } }
public void Compile( CompilerOutputType outputType, IEnumerable <string> libraries, IEnumerable <string> sourceFilePaths, string targetFilePath, CompilerOption options, IDictionary <string, string> defineConstants) { Parameter.ThrowIfNull(libraries, nameof(libraries)); Parameter.ThrowIfNull(sourceFilePaths, nameof(sourceFilePaths)); Parameter.ThrowIfNullOrWhiteSpace(targetFilePath, nameof(targetFilePath)); Parameter.ThrowIfNull(defineConstants, nameof(defineConstants)); bool result = this.CompileCore(outputType, this.Settings.DebuggeeArchitecture, libraries, sourceFilePaths, targetFilePath, options, defineConstants); Assert.True(result, "The compilation failed."); // If the output file was not created, then error Assert.True(File.Exists(targetFilePath), "The compiler did not create the expected output. " + targetFilePath); }
protected abstract bool CompileCore( CompilerOutputType outputType, SupportedArchitecture architecture, IEnumerable <string> libraries, IEnumerable <string> sourceFilePaths, string targetFilePath, CompilerOption options, IDictionary <string, string> defineConstants);
public CompilerParameters() { _pipeline = new CompilerPipeline(); _input = new CompilerInputCollection(); _assemblyReferences = new AssemblyCollection(); _assemblyReferences.Add(GetType().Assembly); _assemblyReferences.Add(typeof(string).Assembly); // corlib _assemblyReferences.Add(System.Reflection.Assembly.LoadWithPartialName("System")); // System _maxAttributeSteps = 2; _outputAssembly = string.Empty; _outputType = CompilerOutputType.ConsoleApplication; }
protected Assembly Compile(string filename, CompilerOutputType compilerOutputType) { BooCompiler compiler = new BooCompiler(); compiler.Parameters.OutputType = compilerOutputType; compiler.Parameters.GenerateInMemory = true; compiler.Parameters.Pipeline = new CompileToMemory(); AddCompilerSteps(compiler, filename, compiler.Parameters.Pipeline); compiler.Parameters.Input.Add(new FileInput(filename)); CompilerContext run = compiler.Run(); if (run.Errors.Count > 0) throw new CompilerError(run.Errors.ToString(true)); return run.GeneratedAssembly; }
public CompilerParameters() { _pipeline = null; _input = new CompilerInputCollection(); _resources = new CompilerResourceCollection(); _assemblyReferences = new AssemblyCollection(); _assemblyReferences.Add(typeof(Boo.Lang.Builtins).Assembly); _assemblyReferences.Add(GetType().Assembly); _assemblyReferences.Add(typeof(object).Assembly); // corlib _assemblyReferences.Add(System.Reflection.Assembly.LoadWithPartialName("System")); // System _maxAttributeSteps = 2; _outputAssembly = string.Empty; _outputType = CompilerOutputType.ConsoleApplication; _outputWriter = System.Console.Out; _debug = true; _generateInMemory = true; }
protected Assembly Compile(string filename, CompilerOutputType compilerOutputType) { BooCompiler compiler = new BooCompiler(); compiler.Parameters.OutputType = compilerOutputType; compiler.Parameters.GenerateInMemory = true; compiler.Parameters.Pipeline = new CompileToMemory(); AddCompilerSteps(compiler, filename, compiler.Parameters.Pipeline); compiler.Parameters.Input.Add(new FileInput(filename)); CompilerContext run = compiler.Run(); if (run.Errors.Count > 0) { throw new CompilerError(run.Errors.ToString(true)); } return(run.GeneratedAssembly); }
public CompilerParameters(IReflectionTypeSystemProvider reflectionProvider, bool loadDefaultReferences) { _libPaths = new List<string>(); _systemDir = Permissions.WithDiscoveryPermission(() => GetSystemDir()); if (_systemDir != null) { _libPaths.Add(_systemDir); _libPaths.Add(Directory.GetCurrentDirectory()); } _pipeline = null; _input = new CompilerInputCollection(); _resources = new CompilerResourceCollection(); _compilerReferences = new CompilerReferenceCollection(reflectionProvider); _maxExpansionIterations = 12; _outputAssembly = String.Empty; _outputType = CompilerOutputType.Auto; _outputWriter = Console.Out; _debug = true; _checked = true; _generateInMemory = true; _stdLib = true; _delaySign = false; Strict = false; TraceLevel = TraceLevel.Off; if (loadDefaultReferences) LoadDefaultReferences(); }
/// <summary> /// Creates a backend compiler for a specific architecture. /// </summary> internal AppxBackendCompiler(CompilerOutputType outputType) : base(CompilerOutputType.AppxPackage) { }
/// <summary> /// Creates a backend compiler for a specific architecture targeting a specific output. /// </summary> /// <param name="outputType">Type of output to generate.</param> internal WixBackendCompiler(CompilerOutputType outputType) : base(outputType) { }
public CompilerParameters(bool loadDefaultReferences) { _libpaths = new ArrayList(); _systemDir = GetSystemDir(); _libpaths.Add(_systemDir); _libpaths.Add(Directory.GetCurrentDirectory()); _pipeline = null; _input = new CompilerInputCollection(); _resources = new CompilerResourceCollection(); _assemblyReferences = new AssemblyCollection(); _maxAttributeSteps = 2; _outputAssembly = string.Empty; _outputType = CompilerOutputType.ConsoleApplication; _outputWriter = System.Console.Out; _debug = true; _checked = true; _generateInMemory = true; _StdLib = true; _delaySign = false; if (loadDefaultReferences) LoadDefaultReferences(); }
/// <summary> /// Creates a new debuggee instance. This will copy the debuggee into a new folder based on the debuggeeMoniker. /// This should only be called once per debuggee. /// </summary> public static IDebuggee Create(ILoggingComponent logger, ICompilerSettings settings, string debuggeeName, int debuggeeMoniker, string outputName = null, CompilerOutputType outputType = CompilerOutputType.Executable) { Debuggee newDebuggee = new Debuggee(logger, settings, debuggeeName, debuggeeMoniker, outputName, outputType); newDebuggee.CopySource(); return(newDebuggee); }
public CompilerParameters(bool loadDefaultReferences) { _libpaths = new ArrayList(); _systemDir = GetSystemDir(); _libpaths.Add(_systemDir); _libpaths.Add(Directory.GetCurrentDirectory()); _pipeline = null; _input = new CompilerInputCollection(); _resources = new CompilerResourceCollection(); _assemblyReferences = new AssemblyCollection(); _maxExpansionIterations = 4; _outputAssembly = string.Empty; _outputType = CompilerOutputType.ConsoleApplication; _outputWriter = System.Console.Out; _debug = true; _checked = true; _generateInMemory = true; _StdLib = true; if (null != Environment.GetEnvironmentVariable("TRACE")) EnableTraceSwitch(); _delaySign = false; if (loadDefaultReferences) LoadDefaultReferences(); }
/// <summary> /// Cannot create instance of this object. Use the <seealso cref="Create"/> method instead. /// </summary> /// <param name="outputType">Type of output to generate.</param> protected BackendCompiler(CompilerOutputType outputType) { this.TempPaths = new List <string>(); this.OutputType = outputType; }
/// <summary> /// Opens an existing debuggee instance. /// </summary> public static IDebuggee Open(ILoggingComponent logger, ICompilerSettings settings, string debuggeeName, int debuggeeMoniker, string outputName = null, CompilerOutputType outputType = CompilerOutputType.Executable) { return(new Debuggee(logger, settings, debuggeeName, debuggeeMoniker, outputName, outputType)); }
private Debuggee(ILoggingComponent logger, ICompilerSettings settings, string debuggeeName, int debuggeeMoniker, string outputName, CompilerOutputType outputType) { Parameter.ThrowIfNull(logger, nameof(logger)); Parameter.ThrowIfNullOrWhiteSpace(debuggeeName, nameof(debuggeeName)); Parameter.ThrowIfNegativeOrZero(debuggeeMoniker, nameof(debuggeeMoniker)); Parameter.ThrowIfNull(settings, nameof(settings)); this.OutputHelper = logger.OutputHelper; this.compilerDefineConstants = new Dictionary <string, string>(); this.debuggeeName = debuggeeName; this.debuggeeMoniker = debuggeeMoniker; this.CompilerOptions = CompilerOption.GenerateSymbols; this.libraries = new List <string>(); this.outputType = outputType; this.settings = settings; this.sourceFilePaths = new List <string>(); if (String.IsNullOrEmpty(outputName)) { // If the outputName was not provided, assume it is called "a.out" and update the extension outputName = Debuggee.UpdateOutputName("a.out", outputType); } else if (String.IsNullOrEmpty(Path.GetExtension(outputName))) { // If the outputName has no extension, add the appropriate extension outputName = Debuggee.UpdateOutputName(outputName, outputType); } this.outputName = outputName; }
protected override bool CompileCore( CompilerOutputType outputType, SupportedArchitecture architecture, IEnumerable <string> libraries, IEnumerable <string> sourceFilePaths, string targetFilePath, CompilerOption options, IDictionary <string, string> defineConstants) { ArgumentBuilder builder = new ArgumentBuilder("-", String.Empty); if (options.HasFlag(CompilerOption.GenerateSymbols)) { builder.AppendNamedArgument("g", null); } if (options.HasFlag(CompilerOption.OptimizeLevel1)) { builder.AppendNamedArgument("O1", null); } else if (options.HasFlag(CompilerOption.OptimizeLevel2)) { builder.AppendNamedArgument("O2", null); } else if (options.HasFlag(CompilerOption.OptimizeLevel3)) { builder.AppendNamedArgument("O3", null); } else { builder.AppendNamedArgument("O0", null); } // Enable pthreads if (options.HasFlag(CompilerOption.SupportThreading)) { builder.AppendNamedArgument("pthread", null); } // Just use C++ 11 builder.AppendNamedArgument("std", "c++11", "="); switch (outputType) { case CompilerOutputType.SharedLibrary: builder.AppendNamedArgument("shared", null); builder.AppendNamedArgument("fpic", null); break; case CompilerOutputType.ObjectFile: builder.AppendNamedArgument("c", null); builder.AppendNamedArgument("fpic", null); break; case CompilerOutputType.Unspecified: // Treat Unspecified as Executable, since executable is the default case CompilerOutputType.Executable: // Compiling an executable does not have a command line option, it's the default break; default: throw new ArgumentOutOfRangeException(nameof(outputType), "Unhandled output type: " + outputType); } switch (architecture) { case SupportedArchitecture.x64: builder.AppendNamedArgument("m", "64"); DefineConstant(builder, "DEBUGGEE_ARCH", "64"); break; case SupportedArchitecture.x86: builder.AppendNamedArgument("m", "32"); DefineConstant(builder, "DEBUGGEE_ARCH", "32"); break; case SupportedArchitecture.arm: builder.AppendNamedArgument("m", "arm"); DefineConstant(builder, "DEBUGGEE_ARCH", "ARM"); break; default: throw new ArgumentOutOfRangeException(nameof(architecture), "Unhandled target architecture: " + architecture); } // Define a constant for the platform name. DefineConstant(builder, "DEBUGGEE_PLATFORM", GetPlatformName()); this.SetAdditionalArguments(builder); builder.AppendNamedArgument("o", targetFilePath); foreach (string sourceFilePath in sourceFilePaths) { builder.AppendArgument(sourceFilePath); } foreach (string library in libraries) { builder.AppendNamedArgument("l", library); } foreach (var defineConstant in defineConstants) { DefineConstant(builder, defineConstant.Key, defineConstant.Value); } return(0 == this.RunCompiler(builder.ToString(), targetFilePath)); }
protected override bool CompileCore( CompilerOutputType outputType, SupportedArchitecture architecture, IEnumerable <string> libraries, IEnumerable <string> sourceFilePaths, string targetFilePath, CompilerOption options, IDictionary <string, string> defineConstants) { ArgumentBuilder clBuilder = new ArgumentBuilder("/", ":"); ArgumentBuilder linkBuilder = new ArgumentBuilder("/", ":"); foreach (var defineConstant in defineConstants) { DefineConstant(clBuilder, defineConstant.Key, defineConstant.Value); } DefineConstant(clBuilder, "_WIN32"); // Suppresses error C4996 for 'getenv' (in debuggees/kitchensink/src/environment.cpp) DefineConstant(clBuilder, "_CRT_SECURE_NO_WARNINGS"); if (options.HasFlag(CompilerOption.GenerateSymbols)) { clBuilder.AppendNamedArgument("ZI", null); clBuilder.AppendNamedArgument("Debug", null); } if (!options.HasFlag(CompilerOption.OptimizeLevel1) && !options.HasFlag(CompilerOption.OptimizeLevel2) && !options.HasFlag(CompilerOption.OptimizeLevel3)) { // Disable optimization clBuilder.AppendNamedArgument("Od", null); } // Add options that are set by default in VS AddDefaultOptions(clBuilder); if (this.Settings.Properties != null) { // Get the include folders from the compiler properties string rawIncludes; if (!this.Settings.Properties.TryGetValue("Include", out rawIncludes)) { rawIncludes = String.Empty; } IEnumerable <string> includes = rawIncludes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()); foreach (string include in includes) { clBuilder.AppendNamedArgumentQuoted("I", include, string.Empty); } // Get the lib folders from the compiler properties string rawLibs; if (!this.Settings.Properties.TryGetValue("Lib", out rawLibs)) { rawLibs = String.Empty; } IEnumerable <string> libs = rawLibs.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()); foreach (string lib in libs) { linkBuilder.AppendNamedArgumentQuoted("LIBPATH", lib); } } switch (outputType) { case CompilerOutputType.SharedLibrary: // Create.DLL clBuilder.AppendNamedArgument("LD", null); clBuilder.AppendNamedArgument("Fo", Path.GetDirectoryName(targetFilePath) + Path.DirectorySeparatorChar); clBuilder.AppendNamedArgument("Fe", targetFilePath); break; case CompilerOutputType.ObjectFile: // Name obj clBuilder.AppendNamedArgument("Fo", targetFilePath); break; case CompilerOutputType.Unspecified: // Treat Unspecified as Executable, since executable is the default case CompilerOutputType.Executable: // Compiling an executable does not have a command line option, it's the default // Name exe clBuilder.AppendNamedArgument("Fo", Path.GetDirectoryName(targetFilePath) + Path.DirectorySeparatorChar); clBuilder.AppendNamedArgument("Fe", targetFilePath); break; default: throw new ArgumentOutOfRangeException(nameof(outputType), "Unhandled output type: " + outputType); } // Specify the PDB name clBuilder.AppendNamedArgument("Fd", Path.ChangeExtension(targetFilePath, "pdb")); // Define a constant for the platform name. DefineConstant(clBuilder, "DEBUGGEE_PLATFORM", GetPlatformName()); DefineConstant(clBuilder, "DEBUGGEE_COMPILER", "Visual C++"); foreach (string sourceFilePath in sourceFilePaths) { clBuilder.AppendArgument(sourceFilePath); } foreach (string library in libraries) { clBuilder.AppendArgument(library); } switch (architecture) { case SupportedArchitecture.x64: DefineConstant(clBuilder, "DEBUGGEE_ARCH", "64"); linkBuilder.AppendNamedArgument("MACHINE", "X64"); break; case SupportedArchitecture.x86: DefineConstant(clBuilder, "DEBUGGEE_ARCH", "32"); linkBuilder.AppendNamedArgument("MACHINE", "X86"); break; default: throw new ArgumentOutOfRangeException(nameof(architecture), "Unhandled target architecture: " + architecture); } // Pass the linker arguments (Note, the link parameter doesn't use the ":" suffix) clBuilder.AppendNamedArgument("link", linkBuilder.ToString(), overrideSuffix: " "); return(0 == this.RunCompiler(clBuilder.ToString(), targetFilePath)); }