public static string HashString(string s) { var knuthHash = KnuthHash.Create(); knuthHash.Add(s); return(knuthHash.Value.ToString()); }
private static void VisitMethods(TypeDefinition type) { foreach (var type2 in type.NestedTypes) { VisitMethods(type2); } foreach (var method in type.Methods) { if (!method.HasCustomAttributes || !method.CustomAttributes.Any(a => a.AttributeType.ToString().Contains("BurstCompile")) || method.IsConstructor) { continue; } var hash = new KnuthHash(); var sb = new StringBuilder(); sb.Append("--method="); var methodDeclaringType = method.DeclaringType; hash.Add(methodDeclaringType.FullName); sb.Append($"{methodDeclaringType.FullName.Replace('/', '+')}, {methodDeclaringType.Module.Assembly}"); sb.Append("::"); sb.Append(method.Name); hash.Add(method.Name); sb.Append("("); var ps = method.Parameters.ToArray(); if (ps.Length > 0) { for (int i = 0; i < ps.Length - 1; i++) { var p = ps[i]; var paramString = $"{p.ParameterType.FullName}, {p.ParameterType.Scope}|"; sb.Append(paramString); hash.Add(paramString); } var lastParamString = $"{ps[ps.Length - 1].ParameterType.FullName}, {ps[ps.Length - 1].ParameterType.Scope}"; hash.Add(lastParamString); sb.Append(lastParamString); } sb.Append(")"); sb.Append("--"); // if you don't add a letter then cpp can't parse it if it's all decimals var hashvalue = "burstedmethod_" + hash.Value; sb.Append(hashvalue); burstargs.Add(sb.ToString()); ModuleReference internalModuleRef = null; var mainModuleModuleReferences = type.Module.Assembly.MainModule.ModuleReferences; if (mainModuleModuleReferences.Any(m => m.Name == "__Internal")) { internalModuleRef = type.Module; } else { internalModuleRef = new ModuleReference("__Internal"); mainModuleModuleReferences.Add(internalModuleRef); } method.Body = null; method.Attributes |= MethodAttributes.PInvokeImpl; method.PInvokeInfo = new PInvokeInfo( PInvokeAttributes.CallConvCdecl, hashvalue, internalModuleRef); } }
private static string GetKey(string fieldsKey, string fieldName) { return(KnuthHash.CalculateHash(fieldsKey + fieldName).ToString()); }