Example #1
0
 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;
 }
Example #2
0
        public Node GenRoot(Arg dst, int depth)
        {
            Node root = GenInst(dst, depth == 0 || dstPool.Count == 0);
            root.children = new List<Node>();
            if(depth == 0 || dstPool.Count==0)
            {
                return root;
            }
            if (depth != 0)
            {
                foreach(var ar in root.args)
                {
                    if(ar.Type == "reg")
                    {
                        root.children.Add(GenRoot(ar, depth - 1));
                        dstPool.Remove(ar.Value);
                    }
                }
                foreach(var ar in root.args)
                {
                    if (ar.Type == "reg")
                    {
                        dstPool.Add(ar.Value);
                    }
                }
                if (root.readFlag && root.children.Last() != null && !root.children.Last().setFlag && r.Next(2)==1)
                {
                    root.children.Add(GenRoot(new Arg() { Type = "zero", Value = 0}, depth -1));
                }
            }

            return root;
        }
Example #3
0
 Arg GenArg(string type, bool leaf)
 {
     Arg ar = new Arg() { Type = type };
     if(type == "reg" && !leaf)
     {
         ar.Value = dstPool[r.Next(dstPool.Count())];
     }
     if (type == "reg" && leaf)
     {
         ar.Value = srcPool[r.Next(srcPool.Count())];
     }
     if (type == "int")
     {
         ar.Value = r.Next();
     }
     return ar;
 }
Example #4
0
        public Node GenRoot(Arg dst, int depth)
        {
            Node root = GenInst(dst, false, depth == 0);
            if(depth == 0 || dstPool.Count==0)
            {
                return root;
            }
            if (depth != 0)
            {
                foreach(var ar in root.args)
                {
                    if(ar.Type == "reg")
                    {
                        root.children.Add(GenRoot(ar, depth - 1));
                        dstPool.Remove(ar.Value);
                    }
                }
                foreach(var ar in root.args)
                {
                    if (ar.Type == "reg")
                    {
                        dstPool.Add(ar.Value);
                    }
                }
                if (root.readFlag && root.children.Last() != null && !root.children.Last().setFlag)
                {
                    root.children.Add(GenRoot(null, depth));
                }
            }

            return root;
        }