예제 #1
0
        public CompilerState(ZinniaBuilder Builder, MessageStrings Strings, IArchitecture Arch, Language Language)
        {
            Messages = new MessageList(Strings);

            this.Builder  = Builder;
            this.Arch     = Arch;
            this.Language = Language;
            this.Strings  = Strings;
        }
예제 #2
0
        public static bool BuildAndRun(string[] Args)
        {
            var Builder = new ZinniaBuilder();

            if (!Builder.BuildAndRun(Args))
            {
                return(false);
            }
            return(true);
        }
예제 #3
0
        public static void PerfTest()
        {
            MakePerfTestFile();
            var Arch  = new x86.x86Architecture();
            var Lang  = new Languages.Zinnia.ZinniaLanguage();
            var State = new CompilerState(null, Arch, Lang);

            State.SetOutput(new MemoryStream(), new MemoryStream());
            State.Entry  = "Main";
            State.Format = ImageFormat.MSCoff;

            var Times      = 10;
            var Files      = new[] { PerfTestFile };
            var Lines      = ZinniaBuilder.ReadLines(Files, State.TabSize);
            var Assemblies = new List <AssemblyPath>()
            {
                new AssemblyPath("ZinniaCore", true),
            };

            Console.WriteLine("Start");
            var Average = Environment.TickCount;
            var Minimum = int.MaxValue;

            for (var i = 0; i < Times; i++)
            {
                var Ms = Environment.TickCount;
                State.CodeOut.Seek(0, SeekOrigin.Begin);
                State.LibOut.Seek(0, SeekOrigin.Begin);

                if (State.Compile(Lines, Assemblies))
                {
                    Console.WriteLine(i + ": " + State.Strings["CompilingSucceded"]);
                }
                else
                {
                    Console.WriteLine(i + ": " + State.Strings["CompilingFailed"]);
                    State.Messages.WriteToConsole();
                    break;
                }

                Ms = Environment.TickCount - Ms;
                if (Ms < Minimum)
                {
                    Minimum = Ms;
                }
            }

            Average = Environment.TickCount - Average;
            Console.WriteLine("Minimum: {0}", Minimum);
            Console.WriteLine("Average: {0}", Average / Times);
            State.DisposeOutput();
        }
예제 #4
0
 public CompilerState(ZinniaBuilder Builder, IArchitecture Arch, Language Language)
     : this(Builder, new MessageStrings(), Arch, Language)
 {
 }
예제 #5
0
        public Assembly LoadAssembly(AssemblyPath AssemblyPath)
        {
            string ZinniaLib;

            if (AssemblyPath.BuiltIn)
            {
                var Name = AssemblyPath.Name;
                var Dir  = ZinniaBuilder.GetDirectory(ZinniaDirectory.Libraries);
                if (Dir == null || !Directory.Exists(Dir = Path.Combine(Dir, Name)))
                {
                    State.Messages.Add(MessageId.AssemblyNotFound, new CodeString(Name));
                    return(null);
                }

                ZinniaLib = Path.Combine(Dir, Name + ".zlib");
                if (!File.Exists(ZinniaLib))
                {
                    State.Messages.Add(MessageId.FileDoesntExists, new CodeString(ZinniaLib));
                    return(null);
                }

                var Arc = Path.Combine(Dir, Name + ".a");
                if (!File.Exists(Arc))
                {
                    State.Messages.Add(MessageId.FileDoesntExists, new CodeString(Arc));
                    return(null);
                }

                if (State.Builder != null)
                {
                    State.Builder.Archives.Add(Arc);
                }

                var Additional = Path.Combine(Dir, Name + ".link.txt");
                if (File.Exists(Additional))
                {
                    var RetValue = true;
                    foreach (var Line in File.ReadAllLines(Additional))
                    {
                        var NewLine = State.Builder.GetFilePath(Line, Dir);
                        if (!File.Exists(NewLine))
                        {
                            State.Messages.Add(MessageId.FileDoesntExists, new CodeString(Line));
                            RetValue = false;
                        }

                        var Ext = Path.GetExtension(NewLine);
                        if (Ext == ".o" || Ext == ".obj")
                        {
                            State.Builder.ObjectFiles.Add(NewLine);
                        }
                        else if (Ext == ".a")
                        {
                            State.Builder.Archives.Add(NewLine);
                        }
                        else
                        {
                            State.Messages.Add(MessageId.CantLoadFile, new CodeString(NewLine));
                            return(null);
                        }
                    }

                    if (!RetValue)
                    {
                        return(null);
                    }
                }
            }
            else
            {
                ZinniaLib = AssemblyPath.Name;
            }

#if !DEBUG
            try
            {
#endif
            var Stream = File.OpenRead(ZinniaLib);
            var ADL    = new AssemblyDescLoader();

            var Ret = ADL.LoadAssemblyDesc(this, Stream);
            if (Ret == null)
            {
                State.Messages.Add(MessageId.CantLoadFile, new CodeString(ZinniaLib));
            }
            return(Ret);

#if !DEBUG
        }

        catch (Exception)
        {
            State.Messages.Add(MessageId.CantLoadFile, new CodeString(ZinniaLib));
            return(null);
        }
#endif
        }