mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 05:18:38 +00:00
This commit is contained in:
parent
7bb985068f
commit
b9200d6e44
11 changed files with 57 additions and 57 deletions
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Indy.IL2CPU.Assembler {
|
||||
public abstract class Assembler : IDisposable {
|
||||
|
|
@ -167,58 +168,50 @@ namespace Indy.IL2CPU.Assembler {
|
|||
int xCurrentIdx = 0;
|
||||
int xIfLevelsToSkip = 0;
|
||||
var xDefines = new List<string>();
|
||||
while (xCurrentIdx < mAllAssemblerElements.Count) {
|
||||
var xCurrentInstruction = mAllAssemblerElements[xCurrentIdx];
|
||||
var xNewAssemblerElements = new List<BaseAssemblerElement>();
|
||||
foreach (var xCurrentInstruction in mAllAssemblerElements) {
|
||||
var xIfDefined = xCurrentInstruction as IIfDefined;
|
||||
var xEndIfDefined = xCurrentInstruction as IEndIfDefined;
|
||||
var xDefine = xCurrentInstruction as IDefine;
|
||||
var xIfNotDefined = xCurrentInstruction as IIfNotDefined;
|
||||
if (xCurrentInstruction is Comment) {
|
||||
mAllAssemblerElements.RemoveAt(xCurrentIdx);
|
||||
continue;
|
||||
}
|
||||
if(xIfDefined!=null){
|
||||
if(xIfLevelsToSkip>0){
|
||||
if (xIfDefined != null) {
|
||||
if (xIfLevelsToSkip > 0) {
|
||||
xIfLevelsToSkip++;
|
||||
} else if (!xDefines.Contains(xIfDefined.Symbol.ToLowerInvariant())) {
|
||||
xIfLevelsToSkip++;
|
||||
} else {
|
||||
if (!xDefines.Contains(xIfDefined.Symbol.ToLowerInvariant())) {
|
||||
xIfLevelsToSkip++;
|
||||
}
|
||||
}
|
||||
mAllAssemblerElements.RemoveAt(xCurrentIdx);
|
||||
continue;
|
||||
}
|
||||
if (xIfNotDefined != null) {
|
||||
if (xIfLevelsToSkip > 0) {
|
||||
xIfLevelsToSkip++;
|
||||
} else {
|
||||
if (xDefines.Contains(xIfNotDefined.Symbol.ToLower())) {
|
||||
xIfLevelsToSkip++;
|
||||
}
|
||||
} else if (xDefines.Contains(xIfNotDefined.Symbol.ToLower())) {
|
||||
xIfLevelsToSkip++;
|
||||
}
|
||||
mAllAssemblerElements.RemoveAt(xCurrentIdx);
|
||||
continue;
|
||||
}
|
||||
if (xEndIfDefined != null) {
|
||||
if (xIfLevelsToSkip > 0) {
|
||||
xIfLevelsToSkip--;
|
||||
xIfLevelsToSkip--;
|
||||
}
|
||||
mAllAssemblerElements.RemoveAt(xCurrentIdx);
|
||||
continue;
|
||||
}
|
||||
if (xIfLevelsToSkip > 0) {
|
||||
mAllAssemblerElements.RemoveAt(xCurrentIdx);
|
||||
continue;
|
||||
}
|
||||
if (xDefine != null) {
|
||||
if (!xDefines.Contains(xDefine.Symbol.ToLowerInvariant())) {
|
||||
xDefines.Add(xDefine.Symbol.ToLowerInvariant());
|
||||
var xSymbol = xDefine.Symbol.ToLowerInvariant();
|
||||
if (!xDefines.Contains(xSymbol)) {
|
||||
xDefines.Add(xSymbol);
|
||||
}
|
||||
mAllAssemblerElements.RemoveAt(xCurrentIdx);
|
||||
continue;
|
||||
}
|
||||
xCurrentIdx++;
|
||||
xNewAssemblerElements.Add(xCurrentInstruction);
|
||||
}
|
||||
mAllAssemblerElements = xNewAssemblerElements;
|
||||
}
|
||||
|
||||
internal List<BaseAssemblerElement> mAllAssemblerElements;
|
||||
|
|
@ -237,11 +230,7 @@ namespace Indy.IL2CPU.Assembler {
|
|||
var xCurrentAddresss = aBaseAddress;
|
||||
ulong xSize = 0;
|
||||
foreach (var xItem in mAllAssemblerElements) {
|
||||
xItem.StartAddress = xCurrentAddresss;
|
||||
if (!xItem.DetermineSize(this, out xSize)) {
|
||||
throw new Exception("Element of unknown size encountered.");
|
||||
}
|
||||
xCurrentAddresss += xSize;
|
||||
xItem.UpdateAddress(this, ref xCurrentAddresss);
|
||||
}
|
||||
|
||||
foreach (var xItem in mAllAssemblerElements) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ namespace Indy.IL2CPU.Assembler {
|
|||
get;
|
||||
}
|
||||
|
||||
public abstract bool DetermineSize(Assembler aAssembler, out ulong aSize);
|
||||
public virtual void UpdateAddress(Assembler aAssembler, ref ulong aAddress) {
|
||||
StartAddress = aAddress;
|
||||
}
|
||||
|
||||
public abstract bool IsComplete(Assembler aAssembler);
|
||||
public abstract byte[] GetData(Assembler aAssembler);
|
||||
|
|
|
|||
|
|
@ -16,9 +16,8 @@ namespace Indy.IL2CPU.Assembler {
|
|||
return "; " + Text;
|
||||
}
|
||||
|
||||
public override bool DetermineSize(Assembler aAssembler, out ulong aSize) {
|
||||
aSize = 0;
|
||||
return true;
|
||||
public override void UpdateAddress(Assembler aAssembler, ref ulong aAddress) {
|
||||
base.UpdateAddress(aAssembler, ref aAddress);
|
||||
}
|
||||
|
||||
public override bool IsComplete(Assembler aAssembler) {
|
||||
|
|
|
|||
|
|
@ -143,18 +143,15 @@ namespace Indy.IL2CPU.Assembler {
|
|||
}
|
||||
}
|
||||
|
||||
public override bool DetermineSize(Assembler aAssembler, out ulong aSize) {
|
||||
public override void UpdateAddress(Assembler aAssembler, ref ulong xAddress) {
|
||||
base.UpdateAddress(aAssembler, ref xAddress);
|
||||
if (RawDefaultValue != null) {
|
||||
aSize = (ulong)RawDefaultValue.LongLength;
|
||||
return true;
|
||||
xAddress += (ulong)RawDefaultValue.LongLength;
|
||||
}
|
||||
if (UntypedDefaultValue != null) {
|
||||
// TODO: what to do with 64bit target platforms? right now we only support 32bit
|
||||
aSize = (ulong)(UntypedDefaultValue.LongLength * 4);
|
||||
return true;
|
||||
xAddress += (ulong)(UntypedDefaultValue.LongLength * 4);
|
||||
}
|
||||
aSize = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsComplete(Assembler aAssembler) {
|
||||
|
|
@ -187,6 +184,9 @@ namespace Indy.IL2CPU.Assembler {
|
|||
if (xTheRef == null) {
|
||||
throw new Exception("Reference not found!");
|
||||
}
|
||||
if (!xTheRef.ActualAddress.HasValue) {
|
||||
Console.Write("");
|
||||
}
|
||||
xTemp = BitConverter.GetBytes(xTheRef.ActualAddress.Value);
|
||||
} else {
|
||||
if (UntypedDefaultValue[i] is int) {
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ namespace Indy.IL2CPU.Assembler {
|
|||
}
|
||||
}
|
||||
|
||||
public override bool DetermineSize(Assembler aAssembler, out ulong aSize) {
|
||||
throw new NotImplementedException("Method not implemented for instruction " + this.GetType().FullName.Substring(typeof(Instruction).Namespace.Length+1));
|
||||
public override void UpdateAddress(Assembler aAssembler, ref ulong aAddress) {
|
||||
base.UpdateAddress(aAssembler, ref aAddress);
|
||||
}
|
||||
|
||||
public override bool IsComplete(Assembler aAssembler) {
|
||||
|
|
|
|||
|
|
@ -101,9 +101,8 @@ namespace Indy.IL2CPU.Assembler {
|
|||
return true;
|
||||
}
|
||||
|
||||
public override bool DetermineSize(Assembler aAssembler, out ulong aSize) {
|
||||
aSize = 0;
|
||||
return true;
|
||||
public override void UpdateAddress(Assembler aAssembler, ref ulong aAddress) {
|
||||
base.UpdateAddress(aAssembler, ref aAddress);
|
||||
}
|
||||
|
||||
public override byte[] GetData(Assembler aAssembler) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Text;
|
|||
|
||||
namespace Indy.IL2CPU.Assembler.X86 {
|
||||
[OpCode("jmp")]
|
||||
public class JumpToSegment: Instruction {
|
||||
public class JumpToSegment: IL2CPU.Assembler.Instruction {
|
||||
public ElementReference DestinationRef {
|
||||
get;
|
||||
set;
|
||||
|
|
@ -41,9 +41,9 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
|||
return DestinationRef == null || DestinationRef.Resolve(aAssembler, out xAddress);
|
||||
}
|
||||
|
||||
public override bool DetermineSize(Indy.IL2CPU.Assembler.Assembler aAssembler, out ulong aSize) {
|
||||
aSize = 7;
|
||||
return true;
|
||||
public override void UpdateAddress(Indy.IL2CPU.Assembler.Assembler aAssembler, ref ulong aAddress) {
|
||||
base.UpdateAddress(aAssembler, ref aAddress);
|
||||
aAddress += 7;
|
||||
}
|
||||
|
||||
public override byte[] GetData(Indy.IL2CPU.Assembler.Assembler aAssembler) {
|
||||
|
|
|
|||
|
|
@ -615,18 +615,21 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
|||
return true;
|
||||
}
|
||||
|
||||
public override bool DetermineSize(Indy.IL2CPU.Assembler.Assembler aAssembler, out ulong aSize) {
|
||||
public override void UpdateAddress(Indy.IL2CPU.Assembler.Assembler aAssembler, ref ulong aAddress) {
|
||||
base.UpdateAddress(aAssembler, ref aAddress);
|
||||
var xInstructionWithDestination = this as IInstructionWithDestination;
|
||||
var xInstructionWithSource = this as IInstructionWithSource;
|
||||
var xInstructionWithSize = this as IInstructionWithSize;
|
||||
InstructionData xInstructionData = null;
|
||||
InstructionData.InstructionEncodingOption xEncodingOption = null;
|
||||
if (!GetEffectiveInstructionInfo(this, xInstructionWithDestination, xInstructionWithSize, xInstructionWithSource, out xInstructionData, out xEncodingOption)) {
|
||||
return base.DetermineSize(aAssembler, out aSize);
|
||||
return;
|
||||
}
|
||||
var xResult = DetermineSize(aAssembler, out aSize, this, xInstructionWithDestination, xInstructionWithSize, xInstructionWithSource, xInstructionData, xEncodingOption);
|
||||
mDataSize = aSize;
|
||||
return xResult;
|
||||
ulong aSize = 0;
|
||||
if (!DetermineSize(aAssembler, out aSize, this, xInstructionWithDestination, xInstructionWithSize, xInstructionWithSource, xInstructionData, xEncodingOption)) {
|
||||
throw new Exception("Unable to determine size");
|
||||
}
|
||||
aAddress += aSize;
|
||||
}
|
||||
|
||||
public override bool IsComplete(Indy.IL2CPU.Assembler.Assembler aAssembler) {
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
|||
return base.IsComplete(aAssembler);
|
||||
}
|
||||
|
||||
public override bool DetermineSize(Indy.IL2CPU.Assembler.Assembler aAssembler, out ulong aSize) {
|
||||
public override void UpdateAddress(Indy.IL2CPU.Assembler.Assembler aAssembler, ref ulong aAddresss) {
|
||||
if (DestinationRef != null) {
|
||||
DestinationValue = 0xFFFFFFFF;
|
||||
}
|
||||
return base.DetermineSize(aAssembler, out aSize);
|
||||
base.UpdateAddress(aAssembler, ref aAddresss);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
|||
return base.IsComplete(aAssembler);
|
||||
}
|
||||
|
||||
public override bool DetermineSize(Indy.IL2CPU.Assembler.Assembler aAssembler, out ulong aSize) {
|
||||
public override void UpdateAddress(Indy.IL2CPU.Assembler.Assembler aAssembler, ref ulong aAddress) {
|
||||
if (SourceRef != null) {
|
||||
SourceValue = 0xFFFFFFFF;
|
||||
}
|
||||
return base.DetermineSize(aAssembler, out aSize);
|
||||
base.UpdateAddress(aAssembler, ref aAddress);
|
||||
}
|
||||
|
||||
public override byte[] GetData(Indy.IL2CPU.Assembler.Assembler aAssembler) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ using System.Collections.ObjectModel;
|
|||
using System.Diagnostics.SymbolStore;
|
||||
using Microsoft.Samples.Debugging.CorSymbolStore;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Indy.IL2CPU {
|
||||
public enum DebugMode { None, IL, Source, MLUsingGDB }
|
||||
|
|
@ -324,7 +325,14 @@ namespace Indy.IL2CPU {
|
|||
} finally {
|
||||
if (aUseBinaryEmission) {
|
||||
using (Stream xOutStream = new FileStream(Path.Combine(aOutputDir, "output.bin"), FileMode.Create)) {
|
||||
mAssembler.FlushBinary(xOutStream, 0x200000);
|
||||
Stopwatch xSW = new Stopwatch();
|
||||
xSW.Start();
|
||||
try {
|
||||
mAssembler.FlushBinary(xOutStream, 0x200000);
|
||||
} finally {
|
||||
xSW.Stop();
|
||||
Debug.WriteLine(String.Format("Binary Emission took: {0}", xSW.Elapsed));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue