Labels use # instead of ., hopefully GDB will like them better.

This commit is contained in:
kudzu_cp 2011-07-19 23:32:55 +00:00
parent 09dd37f7e5
commit 32e5c353fb
5 changed files with 205 additions and 258 deletions

View file

@ -25,8 +25,7 @@ namespace Cosmos.Compiler.Assembler.X86 {
} }
} }
public override void WriteData( Cosmos.Compiler.Assembler.Assembler aAssembler, Stream aOutput ) public override void WriteData(Cosmos.Compiler.Assembler.Assembler aAssembler, Stream aOutput) {
{
if (mCorrectAddress) { if (mCorrectAddress) {
if (IsRelativeJump) { if (IsRelativeJump) {
if (DestinationValue.HasValue && !DestinationIsIndirect) { if (DestinationValue.HasValue && !DestinationIsIndirect) {
@ -44,16 +43,6 @@ namespace Cosmos.Compiler.Assembler.X86 {
} }
base.WriteData(aAssembler, aOutput); base.WriteData(aAssembler, aOutput);
} }
//public override string ToString() {
// var xResult = base.ToString();
// if (mNear) {
// if (!xResult.StartsWith(Mnemonic + " near", StringComparison.InvariantCultureIgnoreCase)) {
// if (xResult.StartsWith(Mnemonic)) {
// return Mnemonic + " near " + xResult.Substring(Mnemonic.Length + 1);
// }
// }
// }
// return xResult;
//}
} }
} }

View file

@ -4,64 +4,49 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
namespace Cosmos.Compiler.Assembler namespace Cosmos.Compiler.Assembler {
{ public class ElementReference {
public class ElementReference
{
private static Dictionary<string, ElementReference> mLookup = new Dictionary<string, ElementReference>(StringComparer.InvariantCultureIgnoreCase); private static Dictionary<string, ElementReference> mLookup = new Dictionary<string, ElementReference>(StringComparer.InvariantCultureIgnoreCase);
public static ElementReference New( string aName, int aOffset ) public static ElementReference New(string aName, int aOffset) {
{
ElementReference xResult; ElementReference xResult;
if( aName.StartsWith( "." ) ) aName = aName.Replace('.', '#');
{ if (aName.StartsWith("#")) {
aName = Label.LastFullLabel + aName; aName = Label.LastFullLabel + aName;
} }
string xId = String.Intern(aName + "@@" + aOffset); string xId = String.Intern(aName + "@@" + aOffset);
if( mLookup.TryGetValue( xId, out xResult ) ) if (mLookup.TryGetValue(xId, out xResult)) {
{
return xResult; return xResult;
} }
if( aOffset == 0 ) if (aOffset == 0) {
{
xResult = new ElementReference(aName); xResult = new ElementReference(aName);
} } else {
else
{
xResult = new ElementReference(aName, aOffset); xResult = new ElementReference(aName, aOffset);
} }
mLookup.Add(xId, xResult); mLookup.Add(xId, xResult);
return xResult; return xResult;
} }
public static ElementReference New( string aName ) public static ElementReference New(string aName) {
{
return New(aName, 0); return New(aName, 0);
} }
private ElementReference(string aName, int aOffset) private ElementReference(string aName, int aOffset)
: this( aName ) : this(aName) {
{
Offset = aOffset; Offset = aOffset;
} }
private ElementReference( string aName ) private ElementReference(string aName) {
{ aName = aName.Replace('.', '#');
if( String.IsNullOrEmpty( aName ) ) if (String.IsNullOrEmpty(aName)) {
{
throw new ArgumentNullException("aName"); throw new ArgumentNullException("aName");
} } else if (aName == "00h") {
if( aName == "00h" )
{
Console.Write(""); Console.Write("");
} } else if (aName.StartsWith("#")) {
if( aName.StartsWith( "." ) )
{
Name = Label.LastFullLabel + aName; Name = Label.LastFullLabel + aName;
} } else {
else
{
Name = aName; Name = aName;
} }
// Some older code still passes in full labels, so we search and replace
} }
private ulong? mActualAddress; private ulong? mActualAddress;
@ -70,55 +55,39 @@ namespace Cosmos.Compiler.Assembler
private static Dictionary<string, BaseAssemblerElement> mCache;// = new SortedList<string, BaseAssemblerElement>(StringComparer.InvariantCultureIgnoreCase); private static Dictionary<string, BaseAssemblerElement> mCache;// = new SortedList<string, BaseAssemblerElement>(StringComparer.InvariantCultureIgnoreCase);
private static int? mThreadId = null; private static int? mThreadId = null;
private static BaseAssemblerElement DoResolve( Assembler aAssembler, string aName ) private static BaseAssemblerElement DoResolve(Assembler aAssembler, string aName) {
{ if (!mThreadId.HasValue) {
if( !mThreadId.HasValue )
{
mThreadId = Thread.CurrentThread.ManagedThreadId; mThreadId = Thread.CurrentThread.ManagedThreadId;
} } else {
else if (mThreadId.Value != Thread.CurrentThread.ManagedThreadId) {
{
if( mThreadId.Value != Thread.CurrentThread.ManagedThreadId )
{
throw new Exception("Called from multiple threads"); throw new Exception("Called from multiple threads");
} }
} }
mCacheLocker.EnterReadLock(); mCacheLocker.EnterReadLock();
try try {
{ if (mCache != null) {
if( mCache != null )
{
BaseAssemblerElement xTempResult; BaseAssemblerElement xTempResult;
if( mCache.TryGetValue( aName, out xTempResult ) ) if (mCache.TryGetValue(aName, out xTempResult)) {
{
return xTempResult; return xTempResult;
} }
} }
} } finally {
finally
{
mCacheLocker.ExitReadLock(); mCacheLocker.ExitReadLock();
} }
mCacheLocker.EnterWriteLock(); mCacheLocker.EnterWriteLock();
try try {
{ if (mCache == null) {
if( mCache == null )
{
mCache = new Dictionary<string, BaseAssemblerElement>(StringComparer.InvariantCultureIgnoreCase); mCache = new Dictionary<string, BaseAssemblerElement>(StringComparer.InvariantCultureIgnoreCase);
int xMax = aAssembler.AllAssemblerElementCount; int xMax = aAssembler.AllAssemblerElementCount;
for( int i = 0; i < xMax; i++ ) for (int i = 0; i < xMax; i++) {
{
var xInstruction = aAssembler.GetAssemblerElement(i); var xInstruction = aAssembler.GetAssemblerElement(i);
var xLabel = xInstruction as Label; var xLabel = xInstruction as Label;
if( xLabel != null ) if (xLabel != null) {
{
mCache.Add(xLabel.QualifiedName, xLabel); mCache.Add(xLabel.QualifiedName, xLabel);
} }
var xDataMember = xInstruction as DataMember; var xDataMember = xInstruction as DataMember;
if( xDataMember != null ) if (xDataMember != null) {
{ if (mCache.ContainsKey(xDataMember.Name)) {
if( mCache.ContainsKey( xDataMember.Name ) )
{
Console.Write(""); Console.Write("");
} }
mCache.Add(xDataMember.Name, xDataMember); mCache.Add(xDataMember.Name, xDataMember);
@ -126,8 +95,7 @@ namespace Cosmos.Compiler.Assembler
} }
} }
BaseAssemblerElement xTempResult; BaseAssemblerElement xTempResult;
if( mCache.TryGetValue( aName, out xTempResult ) ) if (mCache.TryGetValue(aName, out xTempResult)) {
{
return xTempResult; return xTempResult;
} }
throw new Exception("Cannot resolve ElementReference to '" + aName + "'!"); throw new Exception("Cannot resolve ElementReference to '" + aName + "'!");
@ -148,26 +116,20 @@ namespace Cosmos.Compiler.Assembler
// } // }
// } // }
//} //}
} } finally {
finally
{
mCacheLocker.ExitWriteLock(); mCacheLocker.ExitWriteLock();
} }
} }
public bool Resolve( Assembler aAssembler, out ulong aAddress ) public bool Resolve(Assembler aAssembler, out ulong aAddress) {
{
// //
if( mActualAddress != null ) if (mActualAddress != null) {
{
aAddress = mActualAddress.Value; aAddress = mActualAddress.Value;
return true; return true;
} }
var xElement = DoResolve(aAssembler, Name); var xElement = DoResolve(aAssembler, Name);
if( xElement != null ) if (xElement != null) {
{ if (xElement.ActualAddress.HasValue) {
if( xElement.ActualAddress.HasValue )
{
mActualAddress = (ulong)((long)xElement.ActualAddress.Value + Offset); mActualAddress = (ulong)((long)xElement.ActualAddress.Value + Offset);
aAddress = mActualAddress.Value; aAddress = mActualAddress.Value;
return true; return true;
@ -178,26 +140,20 @@ namespace Cosmos.Compiler.Assembler
return false; return false;
} }
public int Offset public int Offset {
{
get; get;
set; set;
} }
public string Name public string Name {
{
get; get;
set; set;
} }
public override string ToString() public override string ToString() {
{ if (Offset != 0) {
if( Offset != 0 )
{
return Name + " + " + Offset; return Name + " + " + Offset;
} } else {
else
{
return Name; return Name;
} }
} }

View file

@ -18,18 +18,19 @@ namespace Cosmos.Compiler.Assembler {
} }
public Label(string aName, string aComment) { public Label(string aName, string aComment) {
mName = aName; // Dont use . in labels. Although they are legal in NASM, GDB cannot handle them in labels while debugging.
if (aName.StartsWith(".")) { // Some older code still passes in full dotted labels, so we replace.
QualifiedName = LastFullLabel + aName; mName = aName.Replace('.', '#');
if (mName.StartsWith("#")) {
QualifiedName = LastFullLabel + mName;
} else { } else {
QualifiedName = aName; QualifiedName = mName;
// Some older code passes the whole label in the argument, so we check for any . in it. // Some older code passes the whole label in the argument, so we check for any ./# in it.
// That assumes that the main prefix can never have a . in it. // That assumes that the main prefix can never have a # in it.
// This code isnt perfect and doenst label X# code properly, but we don't care about // This code isnt perfect and doenst always label X# code properly.
// auto emitted X# labels for now. var xParts = mName.Split('#');
var xParts = aName.Split('.');
if (xParts.Length < 3) { if (xParts.Length < 3) {
LastFullLabel = aName; LastFullLabel = mName;
} }
} }
Comment = aComment; Comment = aComment;
@ -37,8 +38,9 @@ namespace Cosmos.Compiler.Assembler {
public static string GetLabel(object aObject) { public static string GetLabel(object aObject) {
Label xLabel = aObject as Label; Label xLabel = aObject as Label;
if (xLabel == null) if (xLabel == null) {
return ""; return "";
}
return xLabel.Name; return xLabel.Name;
} }

View file

@ -13,8 +13,8 @@ namespace Cosmos.IL2CPU.X86
{ {
public abstract class AppAssembler: IL2CPU.AppAssembler public abstract class AppAssembler: IL2CPU.AppAssembler
{ {
public const string EndOfMethodLabelNameNormal = ".END__OF__METHOD_NORMAL"; public const string EndOfMethodLabelNameNormal = "#END__OF__METHOD_NORMAL";
public const string EndOfMethodLabelNameException = ".END__OF__METHOD_EXCEPTION"; public const string EndOfMethodLabelNameException = "#END__OF__METHOD_EXCEPTION";
public AppAssembler(byte comportNumber) public AppAssembler(byte comportNumber)

View file

@ -48,7 +48,7 @@ namespace Cosmos.IL2CPU {
} }
public static string GetLabel(MethodInfo aMethod, int aPos) { public static string GetLabel(MethodInfo aMethod, int aPos) {
return GetMethodLabel(aMethod) + "." + aPos.ToString("X4"); return GetMethodLabel(aMethod) + "#" + aPos.ToString("X4");
} }
public override string ToString() { public override string ToString() {