コード例 #1
0
ファイル: AsmGenerator.cs プロジェクト: uxrbk/XSharp
        /// <summary>Parse the input X# source code file and generate the matching target assembly
        /// language.</summary>
        /// <param name="aReader">X# source code reader.</param>
        /// <returns>The resulting target assembler content. The returned object contains
        /// a code and a data block.</returns>
        public Assembler.Assembler Generate(TextReader aReader)
        {
            if (aReader == null)
            {
                throw new ArgumentNullException(nameof(aReader));
            }
            mPatterns.EmitUserComments = EmitUserComments;
            mLineNo = 0;
            var xResult = new Assembler.Assembler();

            try {
                // Read one X# source code line at a time and process it.
                while (true)
                {
                    mLineNo++;
                    string xLine = aReader.ReadLine();
                    if (xLine == null)
                    {
                        break;
                    }

                    ProcessLine(xLine, mLineNo);
                }
                AssertLastFunctionComplete();
                return(xResult);
            } finally {
                Assembler.Assembler.ClearCurrentInstance();
            }
        }
コード例 #2
0
 public override void AssembleNew(XSharp.Assembler.Assembler aAssembler, object aMethodInfo)
 {
     new LiteralAssemblerCode("%ifdef DEBUGSTUB");
     new LiteralAssemblerCode("pushad");
     new LiteralAssemblerCode("Call DebugStub_SendPtr");
     new LiteralAssemblerCode("popad");
     new LiteralAssemblerCode("%endif");
 }
コード例 #3
0
 public override void AssembleNew(XSharp.Assembler.Assembler aAssembler, object aMethodInfo)
 {
     new LiteralAssemblerCode("%ifdef DEBUGSTUB");
     new LiteralAssemblerCode("push dword [EBP + 8]");
     new LiteralAssemblerCode("Call DebugStub_SendComplexNumber");
     new LiteralAssemblerCode("add ESP, 4");
     new LiteralAssemblerCode("%endif");
 }
コード例 #4
0
 public override void AssembleNew(XSharp.Assembler.Assembler aAssembler, object aMethodInfo)
 {
     new LiteralAssemblerCode("%ifdef DEBUGSTUB");
     new LiteralAssemblerCode("mov AL, [EBP + 12]");
     new LiteralAssemblerCode("mov BL, [EBP + 8]");
     new LiteralAssemblerCode("mov ECX, 0");
     new LiteralAssemblerCode("mov ESI, EBP");
     new LiteralAssemblerCode("call DebugStub_SendCommandOnChannel");
     new LiteralAssemblerCode("%endif");
 }
コード例 #5
0
 public override void AssembleNew(XSharp.Assembler.Assembler aAssembler, object aMethodInfo)
 {
     new LiteralAssemblerCode("%ifdef DEBUGSTUB");
     XS.Label(".BeforeArgumentsPrepare");
     new LiteralAssemblerCode("mov EBX, [EBP + 12]");
     new LiteralAssemblerCode("push dword [EBX + 12]");
     new LiteralAssemblerCode("add EBX, 16");
     new LiteralAssemblerCode("push dword EBX");
     XS.Label(".BeforeCall");
     new LiteralAssemblerCode("Call DebugStub_SendText");
     new LiteralAssemblerCode("add ESP, 8");
     new LiteralAssemblerCode("%endif");
 }
コード例 #6
0
        public static void Assemble(XSharp.Assembler.Assembler aAssembler, int aSize, bool debugEnabled)
        {
            int xAlignedSize = (int)Align((uint)aSize, 4);

            XS.Comment("address at: [esp]");
            DoNullReferenceCheck(aAssembler, debugEnabled, 0);

            XS.Pop(XSRegisters.EAX);
            for (int i = xAlignedSize - 4; i >= 0; i -= 4)
            {
                XS.Push(XSRegisters.EAX, isIndirect: true, displacement: i);
            }
        }
コード例 #7
0
        public static void Assemble(XSharp.Assembler.Assembler aAssembler, int aSize, bool debugEnabled)
        {
            int xAlignedSize = (int)Align((uint)aSize, 4);

            XS.Comment($"address at: [esp+{xAlignedSize}]");
            DoNullReferenceCheck(aAssembler, debugEnabled, xAlignedSize);

            XS.Set(XSRegisters.EAX, XSRegisters.ESP, sourceIsIndirect: true, sourceDisplacement: xAlignedSize);
            for (int i = 0; i < xAlignedSize; i += 4)
            {
                XS.Pop(XSRegisters.EBX);
                XS.Set(XSRegisters.EAX, XSRegisters.EBX, destinationIsIndirect: true, destinationDisplacement: i);
            }
            XS.Add(XSRegisters.ESP, 4);
        }
コード例 #8
0
        public static void DoExecute(XSharp.Assembler.Assembler assembler, _MethodInfo aMethod, string field, Type declaringType, ILOpCode aCurrentOpCode)
        {
            // call cctor:
            var xCctor = (declaringType.GetConstructors(BindingFlags.Static | BindingFlags.NonPublic) ?? new ConstructorInfo[0]).SingleOrDefault();

            if (xCctor != null)
            {
                XS.Call(LabelName.Get(xCctor));
                if (aCurrentOpCode != null)
                {
                    ILOp.EmitExceptionLogic(assembler, aMethod, aCurrentOpCode, true, null, ".AfterCCTorExceptionCheck");
                    XS.Label(".AfterCCTorExceptionCheck");
                }
            }
            string xDataName = field;

            XS.Push(xDataName);
        }
コード例 #9
0
 public Mul_Ovf(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #10
0
 public abstract bool IsComplete(Assembler aAssembler);
コード例 #11
0
ファイル: Stelem_Ref.cs プロジェクト: VatthanachaiW/IL2CPU
 public Stelem_Ref(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #12
0
 public Add_Ovf_Un(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #13
0
 public abstract void WriteText(Assembler aAssembler, TextWriter aOutput);
コード例 #14
0
ファイル: DataIfDefined.cs プロジェクト: tnsr1/XSharp
 public override void WriteText(Assembler aAssembler, System.IO.TextWriter aOutput)
 {
     aOutput.Write(this.GetAsText());
 }
コード例 #15
0
 public virtual void UpdateAddress(Assembler aAssembler, ref ulong aAddress)
 {
     StartAddress = aAddress;
 }
コード例 #16
0
 public abstract void WriteData(Assembler aAssembler, Stream aOutput);
コード例 #17
0
 public Ldc_R4(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #18
0
ファイル: Ldstr.cs プロジェクト: linhdh/IL2CPU
 public LdStr(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr)
 {
 }
コード例 #19
0
 public Localloc(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #20
0
 public Shl(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #21
0
 public Sizeof(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #22
0
 public Conv_Ovf_I8(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #23
0
 public Clt_Un(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #24
0
 public Cgt(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #25
0
 public override void AssembleNew(XSharp.Assembler.Assembler aAssembler, object aMethodInfo)
 {
     new LiteralAssemblerCode("%ifdef DEBUGSTUB");
     new LiteralAssemblerCode("mov dword [DebugStub_DebugBreakOnNextTrace], 1");
     new LiteralAssemblerCode("%endif");
 }
コード例 #26
0
ファイル: Ldsfld.cs プロジェクト: tgiphil/IL2CPU
 public Ldsfld(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #27
0
 public static void DoExecute(XSharp.Assembler.Assembler Assembler, _MethodInfo aCurrentMethod, MethodBase aTargetMethod, ILOpCode aCurrent, string currentLabel, bool debugEnabled)
 {
     DoExecute(Assembler, aCurrentMethod, aTargetMethod, aCurrent, currentLabel, ILOp.GetLabel(aCurrentMethod, aCurrent.NextPosition), debugEnabled);
 }
コード例 #28
0
 public Ldind_I(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #29
0
 public Ldtoken(XSharp.Assembler.Assembler aAsmblr)
     : base(aAsmblr)
 {
 }
コード例 #30
0
        public static void DoExecute(XSharp.Assembler.Assembler Assembler, _MethodInfo aCurrentMethod, MethodBase aTargetMethod, ILOpCode aOp, string currentLabel, string nextLabel, bool debugEnabled)
        {
            var    xMethodInfo    = aTargetMethod as MethodInfo;
            string xNormalAddress = LabelName.Get(aTargetMethod);
            var    xParameters    = aTargetMethod.GetParameters();

            // todo: implement exception support
            uint xExtraStackSize = GetStackSizeToReservate(aTargetMethod);

            if (!aTargetMethod.IsStatic)
            {
                uint xThisOffset = 0;
                foreach (var xItem in xParameters)
                {
                    xThisOffset += Align(SizeOfType(xItem.ParameterType), 4);
                }
                var stackOffsetToCheck = xThisOffset;
                if (IsReferenceType(aTargetMethod.DeclaringType))
                {
                    DoNullReferenceCheck(Assembler, debugEnabled, (int)stackOffsetToCheck + 4);
                }
                else
                {
                    DoNullReferenceCheck(Assembler, debugEnabled, (int)stackOffsetToCheck);
                }
            }

            if (xExtraStackSize > 0)
            {
                XS.Sub(XSRegisters.ESP, (uint)xExtraStackSize);
            }
            XS.Call(xNormalAddress);

            uint xReturnSize = 0;

            if (xMethodInfo != null)
            {
                xReturnSize = SizeOfType(xMethodInfo.ReturnType);
            }
            if (aCurrentMethod != null)
            {
                EmitExceptionLogic(Assembler, aCurrentMethod, aOp, true,
                                   delegate
                {
                    var xStackOffsetBefore = aOp.StackOffsetBeforeExecution.Value;

                    uint xPopSize = 0;
                    foreach (var type in aOp.StackPopTypes)
                    {
                        xPopSize += Align(SizeOfType(type), 4);
                    }

                    var xResultSize = xReturnSize;
                    if (xResultSize % 4 != 0)
                    {
                        xResultSize += 4 - (xResultSize % 4);
                    }

                    ILOp.EmitExceptionCleanupAfterCall(Assembler, xResultSize, xStackOffsetBefore, xPopSize);
                }, nextLabel);
            }
        }