private void AddKnownTrue(Expr e) { if (VisitorFindVars.V(e).Any()) { this.knownTrue.Peek().Add(e); } }
protected override ICode VisitIf(StmtIf s) { var ctx = s.Ctx; var condition = (Expr)this.Visit(s.Condition); this.stack.Push(new List <ExprVar>()); var then = (Stmt)this.Visit(s.Then); var thenDA = this.stack.Pop(); this.stack.Push(new List <ExprVar>()); var @else = (Stmt)this.Visit(s.Else); var elseDA = this.stack.Pop(); var intersection = thenDA.Intersect(elseDA, (IEqualityComparer <ExprVar>) this.phiComparer).ToArray(); this.stack.Peek().AddRange(intersection); var conditionVars = VisitorFindVars.V(condition); var needAssigning = conditionVars.Except(this.stack.SelectMany(x => x), (IEqualityComparer <ExprVar>) this.phiComparer).ToArray(); if (needAssigning.Any()) { var replacements = needAssigning.Select(x => { var newExpr = ctx.Local(x.Type); var phi = new ExprVarPhi(ctx) { Exprs = new[] { x, newExpr } }; return(new { orgExpr = x, newExpr, phi }); }).ToArray(); foreach (var replace in replacements) { this.stack.Peek().Add(replace.newExpr); this.stack.Peek().Add(replace.phi); condition = (Expr)VisitorReplace.V(condition, replace.orgExpr, replace.phi); } this.ensureAssigned.Add(s, replacements.Select(x => x.newExpr).ToArray()); } if (condition != s.Condition || then != s.Then || @else != s.Else) { var newS = new StmtIf(ctx, condition, then, @else); this.stmtMap.Add(newS, s); return(newS); } else { return(s); } }
protected override ICode VisitDoLoop(StmtDoLoop s) { var ctx = s.Ctx; var body = (Stmt)this.Visit(s.Body); var @while = (Expr)this.Visit(s.While); var conditionVars = VisitorFindVars.V(@while); var needAssigning = conditionVars.Except(this.stack.SelectMany(x => x), (IEqualityComparer <ExprVar>) this.phiComparer).ToArray(); if (needAssigning.Any()) { var replacements = needAssigning.Select(x => { var newExpr = ctx.Local(x.Type); var phi = new ExprVarPhi(ctx) { Exprs = new[] { x, newExpr } }; return(new { orgExpr = x, newExpr, phi }); }).ToArray(); foreach (var replace in replacements) { this.stack.Peek().Add(replace.newExpr); this.stack.Peek().Add(replace.phi); @while = (Expr)VisitorReplace.V(@while, replace.orgExpr, replace.phi); } var assignmentStmts = replacements .Select(x => new StmtAssignment(ctx, x.newExpr, new ExprDefaultValue(ctx, x.newExpr.Type))) .ToArray(); body = new StmtBlock(ctx, assignmentStmts.Concat(body)); } if (body != s.Body || @while != s.While) { return(new StmtDoLoop(ctx, body, @while)); } else { return(s); } }
private void AddKnownTrue(IEnumerable <Expr> es) { this.knownTrue.Peek().AddRange(es.Where(x => VisitorFindVars.V(x).Any())); }