private static bool ProcessStatement(Statement st, StatementBlock block)
 {
     if (st is AssignmentStatement) {
         var assign = (AssignmentStatement)st;
         if (assign.Value is BinOpExpression) {
             var exp = (BinOpExpression)assign.Value;
             if ((exp.Left is BinOpExpression || exp.Right is BinOpExpression) &&
                 exp.Left != assign.Target) {
                 block.Statements.Add(new AssignmentStatement {
                     Target = assign.Target,
                     Value = exp.Left
                 });
                 block.Statements.Add(new AssignmentStatement {
                     Target = assign.Target,
                     Value = new BinOpExpression {
                         Left = assign.Target,
                         Operation = exp.Operation,
                         Right = exp.Right
                     }
                 });
                 return true;
             }
         }
     }
     block.Statements.Add(st);
     return false;
 }
Example #2
0
		public CipherGenContext(RandomGenerator random, int dataVarCount) {
			this.random = random;
			Block = new StatementBlock(); // new LoopStatement() { Begin = 0, Limit = 4 };
			dataVars = new Variable[dataVarCount];
			for (int i = 0; i < dataVarCount; i++)
				dataVars[i] = new Variable("v" + i) { Tag = i };
		}
Example #3
0
		static int SearchDownwardKill(TransformContext context, Statement st, StatementBlock block, int startIndex) {
			Variable[] usage = context.Usages[st];
			Variable[] definition = context.Definitions[st];
			for (int i = startIndex + 1; i < block.Statements.Count; i++) {
				if (context.Usages[block.Statements[i]].Intersect(definition).Count() > 0 ||
				    context.Definitions[block.Statements[i]].Intersect(usage).Count() > 0)
					return i;
			}
			return block.Statements.Count - 1;
		}
		public static void Run(StatementBlock block) {
			bool workDone;
			do {
				workDone = false;
				Statement[] copy = block.Statements.ToArray();
				block.Statements.Clear();
				foreach (Statement st in copy)
					workDone |= ProcessStatement(st, block);
			} while (workDone);
		}
Example #5
0
        public static void Run(StatementBlock block, RandomGenerator random)
        {
            var context = new TransformContext {
                Statements = block.Statements.ToArray(),
                Usages = block.Statements.ToDictionary(s => s, s => GetVariableUsage(s).ToArray()),
                Definitions = block.Statements.ToDictionary(s => s, s => GetVariableDefinition(s).ToArray())
            };
            for (int i = 0; i < ITERATION; i++) {
                foreach (Statement st in context.Statements) {
                    int index = block.Statements.IndexOf(st);
                    Variable[] vars = GetVariableUsage(st).Concat(GetVariableDefinition(st)).ToArray();

                    // Statement can move between defIndex & useIndex without side effects
                    int defIndex = SearchUpwardKill(context, st, block, index);
                    int useIndex = SearchDownwardKill(context, st, block, index);

                    // Move to a random spot in the interval
                    int newIndex = defIndex + random.NextInt32(1, useIndex - defIndex);
                    if (newIndex > index) newIndex--;
                    block.Statements.RemoveAt(index);
                    block.Statements.Insert(newIndex, st);
                }
            }
        }
Example #6
0
 public void GenerateCipherPair(RandomGenerator random, out StatementBlock encrypt, out StatementBlock decrypt)
 {
     CipherGenerator.GeneratePair(random, out encrypt, out decrypt);
 }
		public static void Run(StatementBlock block) {
			foreach (Statement st in block.Statements)
				ProcessStatement(st);
		}
Example #8
0
 // Cannot go before the statements that use the variable defined at the statement
 // Cannot go further than the statements that override the variable used at the statement
 private static int SearchUpwardKill(TransformContext context, Statement st, StatementBlock block, int startIndex)
 {
     Variable[] usage = context.Usages[st];
     Variable[] definition = context.Definitions[st];
     for (int i = startIndex - 1; i >= 0; i--) {
         if (context.Usages[block.Statements[i]].Intersect(definition).Count() > 0 ||
             context.Definitions[block.Statements[i]].Intersect(usage).Count() > 0)
             return i;
     }
     return 0;
 }
Example #9
0
 public static void Run(StatementBlock block)
 {
     var mainBuff = new Variable("{BUFFER}");
     for (int i = 0; i < block.Statements.Count; i++)
         block.Statements[i] = ReplaceVar(block.Statements[i], mainBuff);
 }