mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-29 20:30:44 +00:00
147 lines
3.8 KiB
C#
147 lines
3.8 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace Indy.IL2CPU.Assembler {
|
|
public class Label: Instruction {
|
|
public static string GetFullName(MethodBase aMethod) {
|
|
var xBuilder = new StringBuilder();
|
|
string[] xParts = aMethod.ToString().Split(' ');
|
|
string[] xParts2 = xParts.Skip(1).ToArray();
|
|
var xMethodInfo = aMethod as MethodInfo;
|
|
if (xMethodInfo != null) {
|
|
xBuilder.Append(xMethodInfo.ReturnType.FullName);
|
|
} else {
|
|
ConstructorInfo xCtor = aMethod as ConstructorInfo;
|
|
if (xCtor != null) {
|
|
xBuilder.Append(typeof(void).FullName);
|
|
} else {
|
|
xBuilder.Append(xParts[0]);
|
|
}
|
|
}
|
|
xBuilder.Append(" ");
|
|
xBuilder.Append(aMethod.DeclaringType.FullName);
|
|
xBuilder.Append(".");
|
|
xBuilder.Append(aMethod.Name);
|
|
xBuilder.Append("(");
|
|
ParameterInfo[] xParams = aMethod.GetParameters();
|
|
for (int i = 0; i < xParams.Length; i++) {
|
|
if (xParams[i].Name == "aThis" && i == 0) {
|
|
continue;
|
|
}
|
|
xBuilder.Append(xParams[i].ParameterType.FullName);
|
|
if (i < (xParams.Length - 1)) {
|
|
xBuilder.Append(", ");
|
|
}
|
|
}
|
|
xBuilder.Append(")");
|
|
return String.Intern(xBuilder.ToString());
|
|
}
|
|
|
|
public static string FilterStringForIncorrectChars(string aName) {
|
|
return String.Intern(DataMember.FilterStringForIncorrectChars(aName.Replace(".", "__DOT__")));
|
|
}
|
|
|
|
|
|
public Label(MethodBase aMethod)
|
|
: this(MethodInfoLabelGenerator.GenerateLabelName(aMethod))
|
|
{
|
|
}
|
|
|
|
public Label(string aName)
|
|
{
|
|
mName = aName;
|
|
if (!aName.StartsWith("."))
|
|
{
|
|
LastFullLabel = aName;
|
|
QualifiedName = aName;
|
|
}
|
|
else
|
|
{
|
|
QualifiedName = LastFullLabel + 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;
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return mName; }
|
|
}
|
|
|
|
private string mName;
|
|
|
|
public override string ToString()
|
|
{
|
|
if (IsGlobal)
|
|
{
|
|
return "global " + Name + "\r\n" + Name + ":";
|
|
}
|
|
else
|
|
{
|
|
return Name + ":";
|
|
}
|
|
}
|
|
|
|
public static string GenerateLabelName(MethodBase aMethod) {
|
|
string xResult = DataMember.FilterStringForIncorrectChars(GetFullName(aMethod));
|
|
//if (xResult.Length > 245) {
|
|
using (var xHash = MD5.Create()) {
|
|
xResult = xHash.ComputeHash(Encoding.Default.GetBytes(xResult)).Aggregate("_",
|
|
(r,
|
|
x) => r + x.ToString("X2"));
|
|
}
|
|
//}
|
|
return String.Intern(xResult);
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
{
|
|
}
|
|
}
|
|
}
|