Cosmos/source2/Compiler/Cosmos.Compiler.Assembler/Label.cs
2011-07-16 20:19:57 +00:00

68 lines
1.7 KiB
C#

using System;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
namespace Cosmos.Compiler.Assembler {
public class Label : Instruction {
public static string GetFullName(MethodBase aMethod) {
return MethodInfoLabelGenerator.GenerateLabelName(aMethod);
}
public Label(MethodBase aMethod) : this(MethodInfoLabelGenerator.GenerateLabelName(aMethod)) { }
public Label(string aName) {
mName = aName;
if (aName.StartsWith(".")) {
QualifiedName = LastFullLabel + aName;
} else {
LastFullLabel = aName;
QualifiedName = aName;
}
}
public static string GetLabel(object aObject) {
Label xLabel = aObject as Label;
if (xLabel == null)
return "";
return xLabel.Name;
}
public static string LastFullLabel { get; set; }
public string QualifiedName {
get;
private set;
}
public bool IsGlobal {
get;
set;
}
private string mName;
public string Name {
get { return mName; }
}
public override void WriteText(Assembler aAssembler, System.IO.TextWriter aOutput) {
if (IsGlobal) {
aOutput.Write("global ");
aOutput.WriteLine(QualifiedName);
}
aOutput.Write(QualifiedName);
aOutput.Write(":");
}
public override bool IsComplete(Assembler aAssembler) {
return true;
}
public override void UpdateAddress(Assembler aAssembler, ref ulong aAddress) {
base.UpdateAddress(aAssembler, ref aAddress);
}
public override void WriteData(Assembler aAssembler, System.IO.Stream aOutput) { }
}
}