/// <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(); } }
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"); }
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"); }
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"); }
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"); }
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); } }
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); }
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); }
public Mul_Ovf(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public abstract bool IsComplete(Assembler aAssembler);
public Stelem_Ref(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Add_Ovf_Un(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public abstract void WriteText(Assembler aAssembler, TextWriter aOutput);
public override void WriteText(Assembler aAssembler, System.IO.TextWriter aOutput) { aOutput.Write(this.GetAsText()); }
public virtual void UpdateAddress(Assembler aAssembler, ref ulong aAddress) { StartAddress = aAddress; }
public abstract void WriteData(Assembler aAssembler, Stream aOutput);
public Ldc_R4(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public LdStr(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Localloc(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Shl(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Sizeof(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Conv_Ovf_I8(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Clt_Un(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Cgt(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public override void AssembleNew(XSharp.Assembler.Assembler aAssembler, object aMethodInfo) { new LiteralAssemblerCode("%ifdef DEBUGSTUB"); new LiteralAssemblerCode("mov dword [DebugStub_DebugBreakOnNextTrace], 1"); new LiteralAssemblerCode("%endif"); }
public Ldsfld(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
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); }
public Ldind_I(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
public Ldtoken(XSharp.Assembler.Assembler aAsmblr) : base(aAsmblr) { }
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); } }