private static CSharpCompilation CreateCompilation(string cmdLine, params CSharpSyntaxTree[] sources) { MetadataReference[] refs = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location) }; var args = CSharpCommandLineParser.SplitCommandLineIntoArguments(cmdLine, false); var cmdParser = new CSharpCommandLineParser(); var parsedArgs = cmdParser.Parse(args, ".", null); if (sources.Contains(VulcanRuntime)) { sources = sources.Where(s => s != VulcanRuntime).ToArray(); refs = refs.Concat(new[] { LoadVulcanRuntime() }).ToArray(); } return(CSharpCompilation.Create( System.IO.Path.GetRandomFileName(), syntaxTrees: sources, references: refs, options: parsedArgs.CompilationOptions.WithOutputKind(OutputKind.DynamicallyLinkedLibrary) )); }
private static MetadataReference LoadVulcanRuntime() { if (_vrt == null) { MetadataReference[] refs = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location) }; var args = CSharpCommandLineParser.SplitCommandLineIntoArguments("/dialect:vulcan /r:VulcanRTFuncs.dll /r:VulcanRT.dll /unsafe", false); var cmdParser = new CSharpCommandLineParser(); var parsedArgs = cmdParser.Parse(args, ".", null); var c = CSharpCompilation.Create( "VulcanRTdummy.dll", syntaxTrees: new[] { VulcanRuntime }, references: refs, options: parsedArgs.CompilationOptions.WithOutputKind(OutputKind.DynamicallyLinkedLibrary) ); var ms = new System.IO.MemoryStream(); EmitResult r = c.Emit(ms); if (!r.Success) { string err = ""; r.Diagnostics.Where(d => d.IsWarningAsError || d.Severity == DiagnosticSeverity.Error).ToList().ForEach(d => err += d.ToString() + "\r\n"); throw new Exception(err); } ms.Seek(0, System.IO.SeekOrigin.Begin); _vrt = ms.ToArray(); _vrta = System.Reflection.Assembly.Load(_vrt); System.AppDomain.CurrentDomain.AssemblyResolve += currentDomain_AssemblyResolve; } return(MetadataReference.CreateFromStream(new System.IO.MemoryStream(_vrt))); }
public static CSharpSyntaxTree ParseStartFunction(string cmdLine, string body) { var args = CSharpCommandLineParser.SplitCommandLineIntoArguments(cmdLine, false); var cmdParser = new CSharpCommandLineParser(); var parsedArgs = cmdParser.Parse(args, ".", null); return((CSharpSyntaxTree)CSharpSyntaxTree.ParseText( "FUNCTION Start() AS VOID\r\n" + body, options: parsedArgs.ParseOptions )); }
public static CSharpSyntaxTree ParseSource(string cmdLine, string source) { var args = CSharpCommandLineParser.SplitCommandLineIntoArguments(cmdLine, false); var cmdParser = new CSharpCommandLineParser(); var parsedArgs = cmdParser.Parse(args, ".", null); return((CSharpSyntaxTree)CSharpSyntaxTree.ParseText( source, options: parsedArgs.ParseOptions )); }
private static CSharpCommandLineArguments BuildCommandLineArguments(CompilerParameters parameters, TextWriter outputWriter) { IEnumerable <string> enumerable = CSharpCompilationArguments.BuildCommandLineArgArray(parameters); outputWriter.Write(Res.Compilation_Arguments); foreach (string current in enumerable) { outputWriter.Write(current + " "); } outputWriter.WriteLine(); enumerable = enumerable.Concat(new string[] { "SuppressNoSourceFileSpecifiedWarning" }); string currentDirectory = Environment.CurrentDirectory; string environmentVariable = Environment.GetEnvironmentVariable("LIB"); CSharpCommandLineParser @default = CSharpCommandLineParser.Default; return(@default.Parse(enumerable, currentDirectory, environmentVariable)); }