コード例 #1
0
ファイル: CodeForm.cs プロジェクト: GeroL/MOSA-Project
        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.None;

            CompilerSettings settings = new CompilerSettings();
            settings.CodeSource = SourceCode;
            settings.AddReference("mscorlib.dll");

            CompilerResults results = Mosa.Test.CodeDomCompiler.Compiler.ExecuteCompiler(settings);

            if (results.Errors.HasErrors)
            {
                tbErrors.Text = string.Empty;

                foreach (CompilerError error in results.Errors)
                {
                    tbErrors.AppendText(error.ToString());
                    tbErrors.AppendText("\n");
                }
            }
            else
            {
                Assembly = results.PathToAssembly;
                DialogResult = DialogResult.OK;
                Close();
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestCompilerSettings"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public CompilerSettings(CompilerSettings settings)
 {
     language = settings.language;
     unsafeCode = settings.unsafeCode;
     doNotReferenceMscorlib = settings.doNotReferenceMscorlib;
     codeSource = settings.codeSource;
     additionalSource = settings.additionalSource;
     references = new List<string>(settings.references);
 }
コード例 #3
0
ファイル: Compiler.cs プロジェクト: GeroL/MOSA-Project
        /// <summary>
        /// Initializes a new instance of the <see cref="Compiler"/> class.
        /// </summary>
        public static CompilerResults ExecuteCompiler(CompilerSettings settings)
        {
            CodeDomProvider provider;
            if (!providerCache.TryGetValue(settings.Language, out provider))
            {
                provider = CodeDomProvider.CreateProvider(settings.Language);
                if (provider == null)
                    throw new NotSupportedException("The language '" + settings.Language + "' is not supported on this machine.");
                providerCache.Add(settings.Language, provider);
            }

            string filename = Path.Combine(TempDirectory, Path.ChangeExtension(Path.GetRandomFileName(), "dll"));
            temps.AddFile(filename, false);

            string[] references = new string[settings.References.Count];
            settings.References.CopyTo(references, 0);

            CompilerParameters parameters = new CompilerParameters(references, filename, false);
            parameters.CompilerOptions = "/optimize-";

            if (settings.UnsafeCode)
            {
                if (settings.Language == "C#")
                    parameters.CompilerOptions = parameters.CompilerOptions + " /unsafe+";
                else
                    throw new NotSupportedException();
            }

            if (settings.DoNotReferenceMscorlib)
            {
                if (settings.Language == "C#")
                    parameters.CompilerOptions = parameters.CompilerOptions + " /nostdlib";
                else
                    throw new NotSupportedException();
            }

            parameters.GenerateInMemory = false;

            if (settings.CodeSource != null)
            {
                CompilerResults compileResults = provider.CompileAssemblyFromSource(parameters, settings.CodeSource + settings.AdditionalSource);

                return compileResults;
            }
            else
                throw new NotSupportedException();
        }
コード例 #4
0
        public bool IsEqual(CompilerSettings other)
        {
            if (other == null)
                return false;

            if (this.codeSource != other.codeSource)
                return false;

            if (this.additionalSource != other.additionalSource)
                return false;

            if (this.unsafeCode != other.unsafeCode)
                return false;

            if (this.language != other.language)
                return false;

            if (this.doNotReferenceMscorlib != other.doNotReferenceMscorlib)
                return false;

            if (this.references.Count != other.references.Count)
                return false;

            foreach (string file in this.references)
                if (!other.references.Contains(file))
                    return false;

            return true;
        }