Node GenInst(Arg dst, bool leaf) { bool zero = dst.Type == "zero"; Node res = new Node(); res.args = new List<Arg>(); Instruction inst; List<Instruction> insts; if (zero) { insts = instPool.Where(x => x.setFlag).Where(x => x.Dst.Contains("zero")).ToList(); } else { insts = instPool.Where(x => x.Dst.Contains("reg")).ToList(); } inst = insts[r.Next(insts.Count)]; res.name = inst.Name; res.readFlag = inst.readFlag; res.setFlag = inst.setFlag; if (zero) { res.dst = new Arg() { Type = "zero", Value = 0 }; } else { res.dst = dst; } foreach(var ar in inst.Args) { res.args.Add(GenArg(ar, leaf)); } return res; }
public static string PrintTree(Node root) { string res = ""; if(root.children.Count != 0) { foreach(var ch in root.children) { res += PrintTree(ch); } } res += root.name + " "; res += root.dst.ToString() + ", "; for (int i = 0; i < root.args.Count; i++ ) { res += root.args[i].ToString(); res += i == root.args.Count - 1 ? "" : ", "; } res += "\n"; return res; }