Skip to content

Commit

Permalink
Merge branch 'master' into devhawk/nefdbgnfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Pierson committed Jul 1, 2020
2 parents b0f58db + 40a7a76 commit 01d0c76
Show file tree
Hide file tree
Showing 38 changed files with 313 additions and 314 deletions.
13 changes: 2 additions & 11 deletions src/Neo.Compiler.MSIL/DebugExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using vmtool;

namespace Neo.Compiler
{
Expand Down Expand Up @@ -34,21 +33,13 @@ private static MyJson.JsonNode_Array GetSequencePoints(IEnumerable<NeoCode> code
return outjson;
}

private static string ConvertType(string type)
{
if (type == "System.Object")
return string.Empty;

return FuncExport.ConvType(type);
}

private static MyJson.JsonNode_Array ConvertParamList(IEnumerable<NeoParam> @params)
{
@params ??= Enumerable.Empty<NeoParam>();
var paramsJson = new MyJson.JsonNode_Array();
foreach (var param in @params)
{
var value = string.Format("{0},{1}", param.name, ConvertType(param.type));
var value = string.Format("{0},{1}", param.name, FuncExport.ConvType(param.type));
paramsJson.Add(new MyJson.JsonNode_ValueString(value));
}

Expand Down Expand Up @@ -78,7 +69,7 @@ private static MyJson.JsonNode_Array GetMethods(NeoModule module, IReadOnlyDicti
methodJson.SetDictValue("name", name);
methodJson.SetDictValue("range", range);
methodJson.SetDictValue("params", ConvertParamList(method.paramtypes));
methodJson.SetDictValue("return", ConvertType(method.returntype));
methodJson.SetDictValue("return", FuncExport.ConvType(method.returntype));
methodJson.SetDictValue("variables", ConvertParamList(method.method?.body_Variables));
methodJson.SetDictValue("sequence-points", GetSequencePoints(method.body_Codes.Values, docMap, addrConvTable));
outjson.Add(methodJson);
Expand Down
92 changes: 43 additions & 49 deletions src/Neo.Compiler.MSIL/FuncExport.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
using Neo.Compiler;
using Mono.Cecil;
using Neo.SmartContract.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace vmtool
namespace Neo.Compiler
{
public class FuncExport
{
public static string ConvType(string _type)
public static readonly TypeReference Void = new TypeReference("System", "Void", ModuleDefinition.ReadModule(typeof(object).Assembly.Location, new ReaderParameters(ReadingMode.Immediate)), null);

internal static string ConvType(TypeReference t)
{
switch (_type)
{
case "__Signature":
return "Signature";
if (t is null) return "Null";

var type = t.FullName;

case "System.Boolean":
return "Boolean";
TypeDefinition definition = t.Resolve();
if (definition != null)
foreach (var i in definition.Interfaces)
{
if (i.InterfaceType.Name == nameof(IApiInterface))
{
return "IInteropInterface";
}
}

switch (type)
{
case "System.Boolean": return "Boolean";
case "System.Char":
case "System.Byte":
case "System.SByte":
case "System.Int16":
Expand All @@ -26,43 +38,22 @@ public static string ConvType(string _type)
case "System.UInt32":
case "System.Int64":
case "System.UInt64":
case "System.Numerics.BigInteger":
return "Integer";

case "__Hash160":
return "Hash160";

case "__Hash256":
return "Hash256";

case "System.Byte[]":
return "ByteArray";

case "__PublicKey":
return "PublicKey";

case "System.String":
return "String";

case "System.Object[]":
return "Array";

case "__InteropInterface":
case "IInteropInterface":
return "InteropInterface";
case "System.Numerics.BigInteger": return "Integer";
case "System.Byte[]": return "ByteArray";
case "System.String": return "String";
case "IInteropInterface": return "InteropInterface";
case "System.Void": return "Void";
case "System.Object": return "Any";
}

case "System.Void":
return "Void";
if (t.IsArray) return "Array";

case "System.Object":
return "ByteArray";
}
if (_type?.Contains("[]") ?? false)
if (type.StartsWith("System.Action") || type.StartsWith("System.Func") || type.StartsWith("System.Delegate"))
return $"Unknown:Pointers are not allowed to be public '{type}'";
if (type.StartsWith("System.ValueTuple`") || type.StartsWith("System.Tuple`"))
return "Array";
if (_type?.Contains("Neo.SmartContract.Framework.Services.Neo.Enumerator") ?? false)
return "InteropInterface";

return "Unknown:" + _type;
return "Unknown:" + type;
}

public static string ComputeHash(byte[] script)
Expand All @@ -74,9 +65,9 @@ public static string ComputeHash(byte[] script)

StringBuilder sb = new StringBuilder();
sb.Append("0x");
foreach (var b in hash.Reverse().ToArray())
for (int i = hash.Length - 1; i >= 0; i--)
{
sb.Append(b.ToString("x02"));
sb.Append(hash[i].ToString("x02"));
}
return sb.ToString();
}
Expand Down Expand Up @@ -117,16 +108,20 @@ public static MyJson.JsonNode_Object Export(NeoModule module, byte[] script, Dic
{
foreach (var v in mm.paramtypes)
{
var ptype = ConvType(v.type);
var item = new MyJson.JsonNode_Object();
funcparams.Add(item);

item.SetDictValue("name", v.name);
item.SetDictValue("type", ptype);
item.SetDictValue("type", ConvType(v.type));
}
}

var rtype = ConvType(mm.returntype);
if (rtype.StartsWith("Unknown:"))
{
throw new Exception($"Unknown return type '{mm.returntype}' for method '{function.Value.name}'");
}

funcsign.SetDictValue("returnType", rtype);
}

Expand All @@ -146,12 +141,11 @@ public static MyJson.JsonNode_Object Export(NeoModule module, byte[] script, Dic
{
foreach (var v in mm.paramtypes)
{
var ptype = ConvType(v.type);
var item = new MyJson.JsonNode_Object();
funcparams.Add(item);

item.SetDictValue("name", v.name);
item.SetDictValue("type", ptype);
item.SetDictValue("type", ConvType(v.type));
}
}
//event do not have returntype in nep3
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,8 @@ private int ConvertNewObj(ILMethod from, OpCode src, NeoMethod to)
}

//ValueTuple
if (type.DeclaringType.FullName.StartsWith("System.ValueTuple`"))
if (type.DeclaringType.FullName.StartsWith("System.ValueTuple`") ||
type.DeclaringType.FullName.StartsWith("System.Tuple`"))
{
// Multiple returns
var count = type.DeclaringType.GenericParameters.Count;
Expand Down
17 changes: 1 addition & 16 deletions src/Neo.Compiler.MSIL/MSIL/Converter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
Expand Down Expand Up @@ -104,20 +103,6 @@ public NeoModule Convert(ILModule _in, ConvOption option = null)
//try
{
nm.returntype = m.Value.returntype;
try
{
var type = m.Value.method.ReturnType.Resolve();
foreach (var i in type.Interfaces)
{
if (i.InterfaceType.Name == "IApiInterface")
{
nm.returntype = "IInteropInterface";
}
}
}
catch
{
}

foreach (var src in m.Value.paramtypes)
{
Expand Down Expand Up @@ -173,7 +158,7 @@ private string InsertInitializeMethod()
displayName = "_initialize",
inSmartContract = true
};
initialize.returntype = "System.Void";
initialize.returntype = FuncExport.Void;
initialize.funcaddr = 0;
if (!FillInitializeMethod(initialize))
{
Expand Down
Loading

0 comments on commit 01d0c76

Please sign in to comment.