Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate default manifest file when compiling #109

Merged
merged 3 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/Neo.Compiler.MSIL/FuncExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,35 @@ public static MyJson.JsonNode_Object Export(NeoModule module, byte[] script)
outjson.SetDictValue("hash", sb.ToString());

//entrypoint
outjson.SetDictValue("entrypoint", "Main");
var entryPoint = "Main";
var mainmethod = module.mapMethods[module.mainMethod];
if (mainmethod != null)
{
var name = mainmethod.displayName;
outjson.SetDictValue("entrypoint", name);
entryPoint = mainmethod.displayName;
}

//functions
var funcsigns = new MyJson.JsonNode_Array();
outjson["functions"] = funcsigns;
var methods = new MyJson.JsonNode_Array();
outjson["methods"] = methods;

List<string> names = new List<string>();

foreach (var function in module.mapMethods)
{
var mm = function.Value;
if (mm.inSmartContract == false)
continue;
if (mm.isPublic == false)
continue;
var ps = mm.name.Split(new char[] { ' ', '(' }, StringSplitOptions.RemoveEmptyEntries);
var funcsign = new MyJson.JsonNode_Object();

funcsigns.Add(funcsign);
var funcname = ps[1];
if (funcname.IndexOf("::") > 0)
var funcsign = new MyJson.JsonNode_Object();
if (function.Value.displayName == entryPoint)
{
var sps = funcname.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries);
funcname = sps.Last();
// This is the entryPoint
outjson.SetDictValue("entryPoint", funcsign);
}
else
{
methods.Add(funcsign);
}
funcsign.SetDictValue("name", function.Value.displayName);
if (names.Contains(function.Value.displayName))
Expand All @@ -133,7 +133,7 @@ public static MyJson.JsonNode_Object Export(NeoModule module, byte[] script)
}

var rtype = ConvType(mm.returntype);
funcsign.SetDictValue("returntype", rtype);
funcsign.SetDictValue("returnType", rtype);
}

//events
Expand All @@ -142,10 +142,7 @@ public static MyJson.JsonNode_Object Export(NeoModule module, byte[] script)
foreach (var events in module.mapEvents)
{
var mm = events.Value;

var ps = mm.name.Split(new char[] { ' ', '(' }, StringSplitOptions.RemoveEmptyEntries);
var funcsign = new MyJson.JsonNode_Object();

eventsigns.Add(funcsign);

funcsign.SetDictValue("name", events.Value.displayName);
Expand Down
17 changes: 2 additions & 15 deletions src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ private bool TryInsertMethod(NeoModule outModule, Mono.Cecil.MethodDefinition me
var _method = type.methods[method.FullName];
try
{
NeoMethod nm = new NeoMethod();
if (method.Is_cctor())
{
CctorSubVM.Parse(_method, this.outModule);
Expand All @@ -996,22 +995,10 @@ private bool TryInsertMethod(NeoModule outModule, Mono.Cecil.MethodDefinition me
return false;
//continue;
}
nm._namespace = method.DeclaringType.FullName;
nm.name = method.FullName;
nm.displayName = method.Name;
Mono.Collections.Generic.Collection<Mono.Cecil.CustomAttribute> ca = method.CustomAttributes;
foreach (var attr in ca)
{
if (attr.AttributeType.Name == "DisplayNameAttribute")
{
nm.displayName = (string)attr.ConstructorArguments[0].Value;
}
}
nm.inSmartContract = method.DeclaringType.BaseType.Name == "SmartContract";
nm.isPublic = method.IsPublic;

NeoMethod nm = new NeoMethod(method);
this.methodLink[_method] = nm;
outModule.mapMethods[nm.name] = nm;

ConvertMethod(_method, nm);
return true;
}
Expand Down
25 changes: 2 additions & 23 deletions src/Neo.Compiler.MSIL/MSIL/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,13 @@ public NeoModule Convert(ILModule _in, ConvOption option = null)
if (m.Value.method == null) continue;
if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
continue;//event 自动生成的代码,不要
NeoMethod nm = new NeoMethod();
if (m.Value.method.Is_cctor())
{
CctorSubVM.Parse(m.Value, this.outModule);
continue;
}
if (m.Value.method.Is_ctor()) continue;
nm._namespace = m.Value.method.DeclaringType.FullName;
nm.name = m.Value.method.FullName;
nm.displayName = m.Value.method.Name;

Mono.Collections.Generic.Collection<Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes;
foreach (var attr in ca)
{
if (attr.AttributeType.Name == "DisplayNameAttribute")
{
nm.displayName = (string)attr.ConstructorArguments[0].Value;
}
}
nm.inSmartContract = m.Value.method.DeclaringType.BaseType.Name == "SmartContract";
nm.isPublic = m.Value.method.IsPublic;
NeoMethod nm = new NeoMethod(m.Value.method);
this.methodLink[m.Value] = nm;
outModule.mapMethods[nm.name] = nm;
}
Expand All @@ -114,14 +100,7 @@ public NeoModule Convert(ILModule _in, ConvOption option = null)
{
if (e.Value.isEvent)
{
NeoEvent ae = new NeoEvent
{
_namespace = e.Value.field.DeclaringType.FullName,
name = e.Value.field.DeclaringType.FullName + "::" + e.Key,
displayName = e.Value.displayName,
returntype = e.Value.returntype,
paramtypes = e.Value.paramtypes
};
NeoEvent ae = new NeoEvent(e.Value);
outModule.mapEvents[ae.name] = ae;
}
else if (e.Value.field.IsStatic)
Expand Down
73 changes: 38 additions & 35 deletions src/Neo.Compiler.MSIL/MSIL/ILModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ public void LoadModule(System.IO.Stream dllStream, System.IO.Stream pdbStream)

}
}

}
}
}

}

public class ILType
{
public Dictionary<string, ILField> fields = new Dictionary<string, ILField>();
Expand Down Expand Up @@ -91,11 +90,18 @@ public ILType(ILModule module, Mono.Cecil.TypeDefinition type, ILogger logger)
}
}
}

}

public class ILField
{
public bool isEvent = false;
public string type;
public string name;
public string displayName;
public string returntype;
public List<NeoParam> paramtypes = new List<NeoParam>();
public Mono.Cecil.FieldDefinition field;

public ILField(ILType type, Mono.Cecil.FieldDefinition field)
{
this.type = field.FieldType.FullName;
Expand Down Expand Up @@ -173,7 +179,6 @@ public ILField(ILType type, Mono.Cecil.FieldDefinition field)
}
}
this.paramtypes.Add(new NeoParam(src.Name, paramtype));

}
}
}
Expand All @@ -182,21 +187,23 @@ public ILField(ILType type, Mono.Cecil.FieldDefinition field)
}
}
}
public bool isEvent = false;
public string type;
public string name;
public string displayName;
public string returntype;
public List<NeoParam> paramtypes = new List<NeoParam>();

public override string ToString()
{
return type;
}
public Mono.Cecil.FieldDefinition field;
}

public class ILMethod
{
public string returntype;
public List<NeoParam> paramtypes = new List<NeoParam>();
public bool hasParam = false;
public Mono.Cecil.MethodDefinition method;
public List<NeoParam> body_Variables = new List<NeoParam>();
public SortedDictionary<int, OpCode> body_Codes = new SortedDictionary<int, OpCode>();
public string fail = null;

public ILMethod(ILType type, Mono.Cecil.MethodDefinition method, ILogger logger = null)
{
this.method = method;
Expand Down Expand Up @@ -259,13 +266,6 @@ public ILMethod(ILType type, Mono.Cecil.MethodDefinition method, ILogger logger
}
}

public string returntype;
public List<NeoParam> paramtypes = new List<NeoParam>();
public bool hasParam = false;
public Mono.Cecil.MethodDefinition method;
public List<NeoParam> body_Variables = new List<NeoParam>();
public SortedDictionary<int, OpCode> body_Codes = new SortedDictionary<int, OpCode>();
public string fail = null;
public int GetNextCodeAddr(int srcaddr)
{
bool bskip = false;
Expand Down Expand Up @@ -511,6 +511,24 @@ public enum CodeEx

public class OpCode
{
public TokenValueType tokenValueType = TokenValueType.Nothing;
public int addr;
public CodeEx code;
public int debugline = -1;
public string debugcode;
public object tokenUnknown;
public int tokenAddr_Index;
//public int tokenAddr;
public int[] tokenAddr_Switch;
public string tokenType;
public string tokenField;
public string tokenMethod;
public int tokenI32;
public Int64 tokenI64;
public float tokenR32;
public double tokenR64;
public string tokenStr;

public override string ToString()
{
var info = "IL_" + addr.ToString("X04") + " " + code + " ";
Expand All @@ -525,6 +543,7 @@ public override string ToString()
}
return info;
}

public enum TokenValueType
{
Nothing,
Expand All @@ -538,23 +557,7 @@ public enum TokenValueType
I64,
OTher,
}
public TokenValueType tokenValueType = TokenValueType.Nothing;
public int addr;
public CodeEx code;
public int debugline = -1;
public string debugcode;
public object tokenUnknown;
public int tokenAddr_Index;
//public int tokenAddr;
public int[] tokenAddr_Switch;
public string tokenType;
public string tokenField;
public string tokenMethod;
public int tokenI32;
public Int64 tokenI64;
public float tokenR32;
public double tokenR64;
public string tokenStr;

public void InitToken(object _p)
{
this.tokenUnknown = _p;
Expand Down
Loading