private static string ToPTX(this ControlFlowInstruction cfi, BasicBlock following) { JumpInstruction jump = cfi as JumpInstruction; JumpIfInstruction jumpif = cfi as JumpIfInstruction; switch (cfi.OpCode) { case IROpCodes.JMP: return(jump.Target == following ? "" : "bra.uni " + jump.Target.Label + ";\n"); case IROpCodes.JT: return("setp.ne." + jumpif.Flag.DataType.ToPTX() + " %p, 0, " + jumpif.Flag + ";\n" + "@%p bra.uni " + jump.Target.Label + ";\n" + (jumpif.Next == following ? "" : "bra.uni " + jumpif.Next.Label + ";\n")); case IROpCodes.JF: return("setp.eq." + jumpif.Flag.DataType.ToPTX() + " %p, 0, " + jumpif.Flag + ";\n" + "@%p bra.uni " + jump.Target.Label + ";\n" + (jumpif.Next == following ? "" : "bra.uni " + jumpif.Next.Label + ";\n")); case IROpCodes.RET: return("ret;\n"); default: throw new NotSupportedException(cfi.OpCode.ToString()); } }
public static ILabel MakeTreeChain( this IEnumerable <Node> nodes, ILabelFactory labelFactory, ControlFlowInstruction controlFlow) { var nodesList = nodes.Reverse().ToList(); return(MakeTreeChain(nodesList.Skip(1).Reverse(), labelFactory, labelFactory.GetLabel(new Tree(nodesList.First(), controlFlow)))); }
// Decodes two control-flow instructions from three uints. // (the uints must have endianness swapped so when ToString("X8") is used, they appear in // same order as raw hex) public static ControlFlowInstruction[] DecodeCF(uint dword0, uint dword1, uint dword2) { var cfi0 = new ControlFlowInstruction(); var cfi1 = new ControlFlowInstruction(); // necessary shifting/masking copied from xenia decodeCF(dword0, dword1 & 0xFFFF, ref cfi0); decodeCF((dword1 >> 16) | (dword2 << 16), dword2 >> 16, ref cfi1); return(new ControlFlowInstruction[] { cfi0, cfi1 }); }
internal static ILabel ConcatTrees(this IEnumerable <Node> trees, ILabelFactory labelFactory, ControlFlowInstruction next) { var treesReversed = trees.Reverse().ToList(); var resultTree = treesReversed .Skip(1) .Aggregate( new Tree(treesReversed.First(), next), (tree, node) => new Tree(node, new UnconditionalJump(labelFactory.GetLabel(tree)))); return(labelFactory.GetLabel(resultTree)); }
public Tree(Node root, ControlFlowInstruction controlFlow) { this.Root = root; this.ControlFlow = controlFlow; }
private static extern void decodeCF(uint dword0, uint dword1, ref ControlFlowInstruction cfi);
public static void Apply(ref ControlFlowInstruction instruction) { }
private ILabel GetLabel(ControlFlowInstruction controlFlow) { return(this.labelFactory.GetLabel(new Tree(null, controlFlow))); }