Example #1
0
 public static SubscriptExpr Matches(SubscriptExpr expr, List <SubscriptExpr> exprs)
 {
     foreach (SubscriptExpr expr2 in exprs)
     {
         if (Matches(expr, expr2))
         {
             return(expr2);
         }
     }
     return(null);
 }
Example #2
0
        public void Store(string name, SubscriptExpr subscript, BitVector val)
        {
            if (!arrays.ContainsKey(name))
            {
                arrays[name] = new Dictionary <SubscriptExpr, BitVector>();
            }
            SubscriptExpr matchingSubscript = SubscriptExpr.Matches(subscript, arrays[name].Keys.ToList());

            if (matchingSubscript != null)
            {
                arrays[name].Remove(matchingSubscript);
            }
            arrays[name][subscript] = val;
        }
Example #3
0
 public static bool Matches(SubscriptExpr expr1, SubscriptExpr expr2)
 {
     if (expr1.indices.Count != expr2.indices.Count)
     {
         return(false);
     }
     foreach (var pair in expr1.indices.Zip(expr2.indices))
     {
         if (!pair.Item1.Equals(pair.Item2))
         {
             return(false);
         }
     }
     return(true);
 }
Example #4
0
 public bool Contains(string name, SubscriptExpr subscript)
 {
     if (arrays.ContainsKey(name))
     {
         Dictionary <SubscriptExpr, BitVector> arrayLocations = arrays[name];
         foreach (KeyValuePair <SubscriptExpr, BitVector> item in arrayLocations)
         {
             if (SubscriptExpr.Matches(item.Key, subscript))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #5
0
        public BitVector GetValue(string name, SubscriptExpr subscript)
        {
            Print.ConditionalExitMessage(arrays.ContainsKey(name), string.Format("Unable to find array '{0}' in memory", name));
            Dictionary <SubscriptExpr, BitVector> arrayLocations = arrays[name];

            foreach (KeyValuePair <SubscriptExpr, BitVector> item in arrayLocations)
            {
                if (SubscriptExpr.Matches(item.Key, subscript))
                {
                    return(arrays[name][item.Key]);
                }
            }
            Print.WarningMessage(string.Format("Location '{0}' in array '{1}' has not been initialised", subscript.ToString(), name));

            // Assign a random value
            BitVector val = new BitVector(Random.Next(int.MinValue, int.MaxValue));

            arrays[name][subscript] = val;
            return(val);
        }