Example #1
0
        protected override ExpressionNode Copy_WithoutLinkedNodes(CompilerState State, CodeString Code, Func <ExpressionNode, ExpressionNode> Func)
        {
            var Ch = new ExpressionNode[Children.Length];

            for (var i = 0; i < Children.Length; i++)
            {
                Ch[i] = Children[i].Copy(State, Code, Func);
                if (Ch[i] == null)
                {
                    return(null);
                }
            }

            if (!Code.IsValid)
            {
                Code = this.Code;
            }
            return(new OpExpressionNode(Operator, Ch, Code, Flags));
        }
Example #2
0
        public static bool GetIdAccess(CompilerState State, List <Modifier> Mods, out IdentifierAccess Ret)
        {
            var RetValue = true;

            Ret = IdentifierAccess.Unknown;

            for (var i = 0; i < Mods.Count; i++)
            {
                var Mod = Mods[i] as AccessModifier;
                if (Mod == null)
                {
                    State.Messages.Add(MessageId.NotExpected, Mods[i].Code);
                    RetValue = false;
                    continue;
                }

                Ret = Mod.Access;
            }

            return(RetValue);
        }
Example #3
0
        public static bool GetCallConv(CompilerState State, List <Modifier> Mods, out CallingConvention Ret)
        {
            var RetValue = true;

            Ret = CallingConvention.Unknown;

            for (var i = 0; i < Mods.Count; i++)
            {
                var Mod = Mods[i] as CallingConventionModifier;
                if (Mod == null)
                {
                    State.Messages.Add(MessageId.NotExpected, Mods[i].Code);
                    RetValue = false;
                    continue;
                }

                Ret = Mod.CallingConvention;
            }

            return(RetValue);
        }
Example #4
0
        public Assembly LoadAssemblyDesc(GlobalContainer Global, Stream Stream)
        {
            this.Global = Global;
            this.State  = Global.State;

            Reader       = new BinaryReader(Stream);
            BeginningPos = Stream.Position;
            var IdListPtr = Reader.ReadInt64() + BeginningPos;

            var Name     = ReadLEB128_String();
            var DescName = ReadLEB128_String();
            var Index    = Global.LoadedAssemblies.Count;

            CurrentAssembly        = new Assembly(State, Name, DescName, Index);
            CurrentAssembly.Random = Reader.ReadInt32();
            Global.LoadedAssemblies.Add(CurrentAssembly);
            ReadLEB128_Int();

            var Scope = new AssemblyScope(Global, CurrentAssembly);

            Global.GlobalNamespace.AddScope(Scope);
            Global.Children.Add(Scope);

            if (!ReadChildAssemblies(Global))
            {
                return(null);
            }

            var ContentPos = Stream.Position;

            Stream.Seek(IdListPtr, SeekOrigin.Begin);
            ReadIdRefs();

            Stream.Seek(ContentPos, SeekOrigin.Begin);
            ReadIdList(Scope, Global.GlobalNamespace);

            Dereference();
            UpdateIds();
            return(CurrentAssembly);
        }
Example #5
0
        public ExpressionNode Copy(CompilerState State, CodeString Code, Func <ExpressionNode, ExpressionNode> Func)
        {
            var Ret = Copy_WithoutLinkedNodes(State, Code, Func);

            if (Ret == null)
            {
                return(null);
            }

            for (var i = 0; i < LinkedNodes.Count; i++)
            {
                var Node = LinkedNodes[i].Node.Copy(State, Code, Func);
                if (Node == null)
                {
                    return(null);
                }

                Ret.LinkedNodes.Add(new LinkedExprNode(Node, LinkedNodes[i].Flags));
            }

            return(Func(Ret));
        }
Example #6
0
 public Preprocessor(IdContainer Container)
 {
     this.State     = Container.State;
     this.Container = Container;
 }
Example #7
0
 protected override ExpressionNode Copy_WithoutLinkedNodes(CompilerState State, CodeString Code, Func <ExpressionNode, ExpressionNode> Func)
 {
     throw new ApplicationException();
 }
Example #8
0
 protected override ExpressionNode Copy_WithoutLinkedNodes(CompilerState State, CodeString Code, Func <ExpressionNode, ExpressionNode> Func)
 {
     return(new StrExpressionNode(this.Code, Flags));
 }
Example #9
0
 protected abstract ExpressionNode Copy_WithoutLinkedNodes(CompilerState State,
                                                           CodeString Code, Func <ExpressionNode, ExpressionNode> Func);
Example #10
0
        public bool AdjustSettings()
        {
            if (Language == null)
            {
                Language = new Languages.Zinnia.ZinniaLanguage();
            }
            if (Arch == null)
            {
                Arch = new x86.x86Architecture();
            }
            if (Format == AssemblyFormat.Unknown)
            {
                Format = AssemblyFormat.Application;
            }
            if (Format == AssemblyFormat.Application && Entry == null)
            {
                Entry = "Main";
            }

            if (DefaultLibs)
            {
                Assemblies.Add(new AssemblyPath("ZinniaCore", true));
                Assemblies.Add(new AssemblyPath("BlitzMax", true));
            }

            if (Dir == null)
            {
                if (OutFile == null)
                {
                    Dir = Directory.GetCurrentDirectory();
                }
                else
                {
                    Dir = Path.GetDirectoryName(Path.GetFullPath(OutFile));
                }
            }

            if (State == null)
            {
                State = new CompilerState(this, Arch, Language);
            }
            else
            {
                State.Messages.Messages.Clear();
                State.Arch     = Arch;
                State.Language = Language;
            }

            State.Entry  = Entry;
            State.Format = ImageFormat.MSCoff;

            OutDir = Path.Combine(Dir, ".zinnia");
            if (!Directory.Exists(OutDir))
            {
                Directory.CreateDirectory(OutDir);
            }

            if (OutFile == null)
            {
                if (Format == AssemblyFormat.Object)
                {
                    OutFile = Path.Combine(OutDir, "Assembly.o");
                }
                else if (Format == AssemblyFormat.Archive)
                {
                    OutFile = Path.Combine(OutDir, "Assembly.a");
                }
                else if (Format == AssemblyFormat.Application)
                {
                    OutFile = Path.Combine(OutDir, "Assembly.exe");
                }
                else
                {
                    throw new ApplicationException();
                }
            }

            if (ZinniaLib == null)
            {
                ZinniaLib = Path.Combine(OutDir, "Assembly.zlib");
            }
            if (AsmFile == null)
            {
                AsmFile = Path.Combine(OutDir, "Assembly.s");
            }

            if (ObjFile == null)
            {
                if (Format == AssemblyFormat.Object)
                {
                    ObjFile = OutFile;
                }
                else
                {
                    ObjFile = Path.Combine(OutDir, "Assembly.o");
                }
            }

            return(true);
        }
Example #11
0
 public CodeGenerator(CompilerState State)
 {
     this.State        = State;
     this.InsContainer = new InstructionContainer();
 }
Example #12
0
 public ExpressionPlugin(PluginRoot Parent)
 {
     this.Parent    = Parent;
     this.Container = Parent.Container;
     this.State     = Parent.State;
 }
Example #13
0
 public PluginRoot(IdContainer Container)
 {
     this.Container = Container;
     this.State     = Container.State;
 }
Example #14
0
 public MTCompiler(CompilerState State, List <Identifier> Identifiers)
 {
     this.State       = State;
     this.Identifiers = Identifiers;
 }