private void GenLoadVariable(IL.Variable var) { if (var.Env != null) { // Load environment Gen(new I.LoadArgument { ArgNo = 0 }); Gen(new I.LoadField { Field = EnvMap[var.Env] }); Gen(new I.LoadField { Field = EnvMap[var.Env].Environment.VarMap[var] }); } else if (var is Optimization.LocalVariable loc) { // The entity is a (purely) local variable (used for optimization). GenLoadLoc(loc); } else { throw new NotImplementedException(); } }
private void GenStoreTemp(IL.Variable var) { if (var.Env != null) { Gen(new I.LoadArgument { ArgNo = 0 }); Gen(new I.LoadField { Field = EnvMap[var.Env] }); Gen(new I.Load { Loc = 0 }); Gen(new I.StoreField { Field = EnvMap[var.Env].Environment.VarMap[var] }); } else if (var is Optimization.LocalVariable loc) { Gen(new I.Load { Loc = 0 }); Gen(new I.Store { Loc = loc.LocSlot }); } else { throw new NotImplementedException(); } }
public void AddDef(IL.Variable var) { if (var != null) { Def.Add(var); } }
private static bool IsTailRecursion(Node node, IL.Variable var) { // If the instruction is return, and the returned value is the result of the recursion, // we can conclude that it is a tail recursion. if (node.Instruction is IL.ReturnInstruction ret) { if (ret.Value == var) { return(true); } } // If the current instruction is a label or unconditional jump, // find the path recursively. if (node.Instruction is IL.UnconditionalJumpInstruction || node.Instruction is IL.Label) { return(IsTailRecursion(node.Next.First(), var)); } return(false); }
private void GenPostStore(IL.Variable var) { if (var.Env != null) { // IL.Variable Gen(new I.StoreField { Field = EnvMap[var.Env].Environment.VarMap[var] }); } else if (var is Optimization.LocalVariable loc) { // Optimization.LocalVariable Gen(new I.Store { Loc = loc.LocSlot }); } else { throw new NotImplementedException(); } }
private void GenPreStore(IL.Variable var) { if (var.Env != null) { // IL.Variable Gen(new I.LoadArgument { ArgNo = 0 }); Gen(new I.LoadField { Field = EnvMap[var.Env] }); } else if (var is Optimization.LocalVariable) { // Optimization.LocalVariable // Do nothing. } else { throw new NotImplementedException(); } }
public Variable(IL.Variable var) { ILVariable = var; }