public static void DebugOutput(string outpath, NeoModule module, byte[] avm, MyJson.JsonNode_Object abi) { if (System.IO.Directory.Exists(outpath) == false) { System.IO.Directory.CreateDirectory(outpath); } string mapInfo = null; string srcfile = null; {//gen debug info Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array(); foreach (var m in module.mapMethods) { Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object(); arr.Add(item); item.SetDictValue("name", m.Value.displayName); item.SetDictValue("addr", m.Value.funcaddr.ToString("X04")); Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array(); item.SetDictValue("map", infos); foreach (var c in m.Value.body_Codes) { if (c.Value.debugcode != null) { var debugcode = c.Value.debugcode.ToLower(); if (debugcode.Contains(".cs")) { srcfile = debugcode; infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString()); } } } } mapInfo = arr.ToString(); } var hash = abi["hash"].AsString(); var abistr = abi.ToString(); var outfile = System.IO.Path.Combine(outpath, hash); System.IO.File.WriteAllBytes(outfile + ".avm", avm); System.IO.File.WriteAllText(outfile + ".map.json", mapInfo); System.IO.File.WriteAllText(outfile + ".abi.json", abistr); if (srcfile != null) { var targetfilename = outfile + ".cs"; System.IO.File.Delete(targetfilename); System.IO.File.Copy(srcfile, targetfilename); } new DefLogger().Log("output to local succ"); DebugOutputToService(hash, avm, abistr, mapInfo, System.IO.File.ReadAllText(srcfile)); }
public static void DebugOutput(NeoModule module, byte[] avm, MyJson.JsonNode_Object abi) { string mapInfo = null; string srcfile = null; {//gen debug info Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array(); foreach (var m in module.mapMethods) { Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object(); arr.Add(item); item.SetDictValue("name", m.Value.displayName); item.SetDictValue("addr", m.Value.funcaddr.ToString("X04")); Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array(); item.SetDictValue("map", infos); foreach (var c in m.Value.body_Codes) { if (c.Value.debugcode != null) { var debugcode = c.Value.debugcode.ToLower(); if (debugcode.Contains(".cs")) { srcfile = debugcode; infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString()); } } } } mapInfo = arr.ToString(); } var hash = abi["hash"].AsString(); var abistr = abi.ToString(); System.IO.File.WriteAllBytes(hash + ".avm", avm); System.IO.File.WriteAllText(hash + ".map.json", mapInfo); System.IO.File.WriteAllText(hash + ".abi.json", abistr); if (srcfile != null) { var targetfilename = hash + ".cs"; System.IO.File.Delete(targetfilename); System.IO.File.Copy(srcfile, targetfilename); } }
void BuildNeon(byte[] dll, byte[] pdb, NeonResult result) { NeonResult nr = result; Neo.Compiler.MSIL.ModuleConverter convert = new Neo.Compiler.MSIL.ModuleConverter(nr); Neo.Compiler.MSIL.ILModule module = new Neo.Compiler.MSIL.ILModule(); System.IO.MemoryStream ms = new System.IO.MemoryStream(dll); System.IO.MemoryStream mspdb = new System.IO.MemoryStream(pdb); module.LoadModule(ms, mspdb); var mod = convert.Convert(module); var avm = mod.Build(); nr.avm = avm; var abijson = vmtool.FuncExport.Export(mod, avm); nr.hash = abijson["hash"].AsString(); nr.abi = abijson.ToString(); {//gen debug info Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array(); foreach (var m in convert.outModule.mapMethods) { Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object(); arr.Add(item); item.SetDictValue("name", m.Value.displayName); item.SetDictValue("addr", m.Value.funcaddr.ToString("X04")); Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array(); item.SetDictValue("map", infos); foreach (var c in m.Value.body_Codes) { if (c.Value.debugcode != null) { var debugcode = c.Value.debugcode.ToLower(); if (debugcode.Contains(".cs")) { infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString()); } } } } nr.map = arr.ToString(); } }
private static Result CompileDll(Neo.Compiler.ILogger logger, string name) { Result r = new Result(); var namepdb = name.Substring(0, name.Length - 4) + ".pdb"; if (System.IO.File.Exists(name) == false || System.IO.File.Exists(namepdb) == false) { throw new Exception("必须同时拥有dll 和 pdb 文件"); } var stream = System.IO.File.OpenRead(name); var streampdb = System.IO.File.OpenRead(namepdb); Neo.Compiler.MSIL.ILModule module = new Neo.Compiler.MSIL.ILModule(); module.LoadModule(stream, streampdb); Neo.Compiler.MSIL.ModuleConverter converter = new Neo.Compiler.MSIL.ModuleConverter(logger); converter.Convert(module); string srcfile = null; {//gen debug info Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array(); foreach (var m in converter.outModule.mapMethods) { Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object(); arr.Add(item); item.SetDictValue("name", m.Value.displayName); item.SetDictValue("addr", m.Value.funcaddr.ToString("X04")); Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array(); item.SetDictValue("map", infos); foreach (var c in m.Value.body_Codes) { if (c.Value.debugcode != null) { var debugcode = c.Value.debugcode.ToLower(); if (debugcode.Contains(".cs")) { if (srcfile == null) { srcfile = debugcode; } infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString()); } } } } r.debuginfo = arr.ToString(); } r.srcfile = srcfile; {//gen hexscript var bytes = converter.outModule.Build(); var hashstr = CalcScriptHashString(bytes); r.avm = bytes; r.script_hash = hashstr; } return(r); }
public static bool BuildNeon(System.IO.Stream ms, System.IO.Stream mspdb, List <string> errinfo) { string OutPath = ""; //loaddll Neo.Compiler.MSIL.ILModule module = null; //try { module = new Neo.Compiler.MSIL.ILModule(); module.LoadModule(ms, mspdb); } //catch (Exception err) //{ // errinfo.Add("LoadDll error:" + err.Message); // return false; //} //convert Neo.Compiler.MSIL.ModuleConverter converter = null; try { converter = new Neo.Compiler.MSIL.ModuleConverter(new Logger(errinfo)); converter.Convert(module); } catch (Exception err) { errinfo.Add("Convert error:" + err.Message); return(false); } //gen debug info string debuginfo = null; try { Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array(); foreach (var m in converter.outModule.mapMethods) { Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object(); arr.Add(item); item.SetDictValue("name", m.Value.displayName); item.SetDictValue("addr", m.Value.funcaddr.ToString("X04")); Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array(); item.SetDictValue("map", infos); foreach (var c in m.Value.body_Codes) { if (c.Value.debugcode != null) { var debugcode = c.Value.debugcode.ToLower(); if (debugcode.Contains(".cs")) { //if (srcfile == null) // srcfile = debugcode; infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString()); } } } } debuginfo = arr.ToString(); } catch (Exception err) { errinfo.Add("GenDebugInfo error:" + err.Message); return(false); } //save try { var bytes = converter.outModule.Build(); //avm var hashstr = CalcScriptHashString(bytes); //hash System.IO.File.WriteAllBytes(System.IO.Path.Combine(OutPath, hashstr + ".avm"), bytes); System.IO.File.WriteAllText(System.IO.Path.Combine(OutPath, hashstr + ".debug.json"), debuginfo, Encoding.UTF8); //System.IO.File.Copy(System.IO.Path.Combine(BuildPath, "Contract" + ".cs"), // System.IO.Path.Combine(OutPath, hashstr + ".cs")); return(true); } catch (Exception err) { errinfo.Add("Save error:" + err.Message); return(false); } }
public bool compile(string filename, string filetext, out byte[] avmtext, out string abitext, out string maptext, out string hash) { var tree = CSharpSyntaxTree.ParseText(filetext); var comp = CSharpCompilation.Create("aaa.dll", new[] { tree }, new[] { ref1, ref2, ref3, ref4 }, op); var fs = new MemoryStream(); var fspdb = new MemoryStream(); var result = comp.Emit(fs, fspdb); fs.Seek(0, SeekOrigin.Begin); fspdb.Seek(0, SeekOrigin.Begin); ILModule mod = new ILModule(); mod.LoadModule(fs, fspdb); NeoModule am = null; byte[] bytes = null; string jsonstr = null; string mapInfo = null; ConvOption option = new ConvOption() { useNep8 = false }; var conv = new ModuleConverter(new DefLogger()); am = conv.Convert(mod, option); // *.avm bytes = am.Build(); avmtext = bytes; // *.abi.json var outjson = vmtool.FuncExport.Export(am, bytes); jsonstr = outjson.ToString(); abitext = jsonstr; hash = outjson["hash"].ToString(); // *.map.json Neo.Compiler.MyJson.JsonNode_Array arr = new Neo.Compiler.MyJson.JsonNode_Array(); foreach (var m in am.mapMethods) { Neo.Compiler.MyJson.JsonNode_Object item = new Neo.Compiler.MyJson.JsonNode_Object(); arr.Add(item); item.SetDictValue("name", m.Value.displayName); item.SetDictValue("addr", m.Value.funcaddr.ToString("X04")); Neo.Compiler.MyJson.JsonNode_Array infos = new Neo.Compiler.MyJson.JsonNode_Array(); item.SetDictValue("map", infos); foreach (var c in m.Value.body_Codes) { if (c.Value.debugcode != null) { var debugcode = c.Value.debugcode.ToLower(); //if (debugcode.Contains(".cs")) { infos.AddArrayValue(c.Value.addr.ToString("X04") + "-" + c.Value.debugline.ToString()); } } } } mapInfo = arr.ToString(); maptext = mapInfo; try { fs.Dispose(); if (fspdb != null) { fspdb.Dispose(); } } catch { } return(true); }