public void Visit(Instruction instruction, MethodTranslateContextCXX methodContext) { var fld = instruction.Operand as FieldReference; var Type = fld.DeclaringType.Resolve(); methodContext.AddStaticReference(Type); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var fld = instruction.Operand as FieldReference; var Type = fld.DeclaringType.Resolve(); return($"{Type.CXXTypeName()}::{Utilities.GetCXXValidTokenString(fld.Name)} = {methodContext.CmptStackPopObject};"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var type = instruction.Operand as TypeReference; var arg = methodContext.CmptStackPopObject; return($"auto {methodContext.CmptStackPushObject} = RTCLI::UnBox<{type.CXXTypeName()}_V>({arg});"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var Type = instruction.Operand as TypeReference; return($"auto {methodContext.CmptStackPushObject} = \n" + $"\t\tRTCLI::Isinst<{Type.CXXTypeName()}>({methodContext.CmptStackPopObject});"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var op1 = methodContext.CmptStackPopObject; return($"auto {methodContext.CmptStackPushObject}" + $" = RTCLI::Ckfinite({op1});"); }
public static string Convert(Instruction instruction, MethodTranslateContextCXX methodContext, string type) { var op1 = methodContext.CmptStackPopObject; var op2 = methodContext.CmptStackPopObject; return($"RTCLI::Deref<{type}>({op2}) = {op1};"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var op2 = methodContext.CmptStackPopObject; var op1 = methodContext.CmptStackPopObject; return($"RTCLI::i32 {methodContext.CmptStackPushObject}" + $" = RTCLI::Cgt_Un({op1}, {op2});"); }
private static void IterateILInstruction( Instruction inst, MethodTranslateContextCXX methodContext) { if (Constants.CXXILConverters.TryGetValue(inst.OpCode, out ICXXILConverter targetConverter)) { targetConverter.Visit(inst, methodContext); } }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var obj = methodContext.CmptStackPopObject; var fld = instruction.Operand as FieldReference; var name = methodContext.CmptStackPushObject; return($"auto& {name} = {obj}.{Utilities.GetCXXValidTokenString(fld.Name)};"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var method = instruction.Operand as MethodReference; var methodDef = method.Resolve(); var Type = method.DeclaringType.Resolve(); return($"auto {methodContext.CmptStackPushObject} = &{methodDef.CXXMethodCallName(Type)};"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var Type = instruction.Operand as TypeReference; var op2 = methodContext.CmptStackPopObject; var op1 = methodContext.CmptStackPopObject; return($"RTCLI::stobj<{Type.CXXTypeName()}>({op1}, {op2});"); }
private static string NoteILInstruction(Instruction inst, MethodTranslateContextCXX methodContext) { if (Constants.CXXILConverters.TryGetValue(inst.OpCode, out ICXXILConverter targetConverter)) { return(targetConverter.Note(inst, methodContext)); } return($"//{inst.ToString().HoldEscape()}"); }
public static string Convert(Instruction instruction, MethodTranslateContextCXX methodContext, string type) { var op2 = methodContext.CmptStackPopObject; var op1 = methodContext.CmptStackPopObject; return($"auto {methodContext.CmptStackPushObject}" + $" = RTCLI::ArrayGet<{type}>({op1}, {op2});"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var Type = instruction.Operand as TypeReference; var len = methodContext.CmptStackPopObject; return($"RTCLI::System::ElementArray<{Type.CXXTypeName()}>& {methodContext.CmptStackPushObject} = \n" + $"\t\tRTCLI::new_array<{Type.CXXTypeName()}>({len});"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var op3 = methodContext.CmptStackPopObject; var op2 = methodContext.CmptStackPopObject; var op1 = methodContext.CmptStackPopObject; return($"RTCLI::cpblk({op1}, {op2}, {op3});"); }
private string ParseParams(Instruction instruction, MethodTranslateContextCXX methodContext) { MethodReference calledMethod = instruction.Operand as MethodReference; var Type = calledMethod.DeclaringType; string paramSequenceCXX = string.Join(',', calledMethod.Parameters.Select(_ => methodContext.CmptStackPopObject).Reverse() ); return($"{Type.CXXTypeName()}& {methodContext.CmptStackPushObject} = \n\t\tRTCLI::new_object<{Type.CXXTypeName()}>({paramSequenceCXX});"); }
public static void Visit(Instruction instruction, MethodTranslateContextCXX methodContext) { var mtd = instruction.Operand as MethodReference; var mtdDef = mtd.Resolve(); if (mtdDef.IsStatic) { var type = mtd.DeclaringType.Resolve(); methodContext.AddStaticReference(type); } }
private static string TranslateILInstruction( Instruction inst, MethodTranslateContextCXX methodContext, bool StaticAssertOnUnimplementatedILs = false) { if (Constants.CXXILConverters.TryGetValue(inst.OpCode, out ICXXILConverter targetConverter)) { return(targetConverter.Convert(inst, methodContext)); } return(StaticAssertOnUnimplementatedILs ? $"static_assert(0, \"[{inst.ToString()}] Has No Converter Implementation!\");" : $"RTCLI::unimplemented_il(\"{ inst.ToString()}\"); //{inst.ToString()}"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var val = methodContext.CmptStackPopObject; var obj = methodContext.CmptStackPopObject; var op = instruction.Operand; if (op is PropertyReference prop) { return("RTCLI::unimplemented_il(\"stfld prop\");"); } else if (op is FieldReference fld) { return($"{obj}.{Utilities.GetCXXValidTokenString(fld.Name)} = {val};"); } return(""); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var obj = methodContext.CmptStackPopObject; var op = instruction.Operand; if (op is PropertyReference prop) { return("RTCLI::unimplemented_il(\"ldfld prop\");"); } else if (op is FieldReference fld) { var name = methodContext.CmptStackPushObject; return($"auto& {name} = {obj}.{Utilities.GetCXXValidTokenString(fld.Name)}{(fld.FieldType.IsValueType ? "" : ".Get()")};"); } return(""); }
public static string Convert(MethodTranslateContextCXX methodContext, int index) { if (!methodContext.Method.IsStatic) { index -= 1; } if (index < 0) { return($"auto& {methodContext.CmptStackPushObject} = *this;"); } else { var param = methodContext.Method.Parameters[index]; return($"auto& {methodContext.CmptStackPushObject} = {param.Name}{(param.ParameterType.IsValueType?"" : ".Get()")};"); } }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var op = instruction.Operand; if (op is TypeDefinition Type) { return("RTCLI::unimplemented_il(\"sizeof typedef\");"); } else if (op is TypeReference TypeR) { return($"auto {methodContext.CmptStackPushObject} = RTCLI_SIZEOF({TypeR.CXXTypeName()});"); } else { return(""); } }
public static void WriteMethodBody(CodeTextWriter Writer, MethodDefinition Method, bool ValueType) { MethodTranslateContextCXX methodContext = new MethodTranslateContextCXX(Method); Writer.WriteLine("{"); Writer.indent(); Writer.WriteLine("// [S2000] Method Body"); if (Method.IsConstructor && Method.IsStatic) { Writer.WriteLine("// [S2000-2] Static Constructor Body"); Writer.WriteLine("static std::once_flag flag;"); Writer.WriteLine("std::call_once(flag,[&]()"); Writer.WriteLine("{"); Writer.indent(); } if (Method.Body.HasVariables) { Writer.WriteLine("// [S2000-0] Local Varaiables"); foreach (var localVar in Method.Body.Variables) { if (Method.Body.InitLocals) { Writer.WriteLine($"{localVar.CXXVarDeclaration()} v{localVar.Index} = {localVar.CXXVarInitVal()};"); } else { Writer.WriteLine($"{localVar.CXXVarDeclaration()} v{localVar.Index};"); } } } Writer.WriteLine("// [S2000-1] Code Body"); foreach (var instruction in Method.Body.Instructions) { IterateILInstruction(instruction, methodContext); } foreach (var sr in methodContext.StaticReference) { var constructor = sr.GetStaticConstructor(); if (constructor == null) { continue; } Writer.WriteLine($"{constructor.CXXMethodCallName(sr)}();"); } foreach (var instruction in Method.Body.Instructions) { Writer.WriteLine(NoteILInstruction(instruction, methodContext)); var Lable = instruction.GetLabel(); if (methodContext.LableReference.Contains(Lable)) { Writer.WriteLineRaw(Lable + " :"); } Writer.WriteLine(TranslateILInstruction(instruction, methodContext)); } if (Method.IsConstructor && Method.IsStatic) { Writer.unindent(); Writer.WriteLine("});"); Writer.WriteLine("// [S2000-2] Static Constructor Body End"); } Writer.unindent(); Writer.WriteLine("}"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) => StelemConvert.Convert(instruction, methodContext, "int");
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) { var typeReference = instruction.Operand as TypeReference; return(StelemConvert.Convert(instruction, methodContext, typeReference.CXXTypeName())); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) => Ldc_Convert.I4Convert(instruction, methodContext, 7);
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) => Ldc_Convert.I4Convert(instruction, methodContext, Int32.Parse(instruction.Operand.ToString()));
public static string R8Convert(Instruction instruction, MethodTranslateContextCXX ctx, Double val) { return($"RTCLI::System::Double {ctx.CmptStackPushObject} = RTCLI::StaticCast<{/*ctx.MetadataContext.UInt32Type.CXXTypeName*/"RTCLI::System::Double"}>({val});"); }
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) => LdindConvert.Convert(instruction, methodContext, "RTCLI::u32");
public string Convert(Instruction instruction, MethodTranslateContextCXX methodContext) => StelemConvert.Convert(instruction, methodContext, "RTCLI::System::Double");