/// <summary> /// Renders a single ForStatement with the given indentation /// </summary> /// <returns>The VHDL lines in the statement.</returns> /// <param name="method">The method the statement belongs to.</param> /// <param name="s">The statement to render.</param> /// <param name="indentation">The indentation to use.</param> private IEnumerable <string> RenderStatement(AST.Method method, AST.ForStatement s, int indentation) { var edges = s.GetStaticForLoopValues(); var endval = edges.Item2; endval--; var indent = new string(' ', indentation); yield return($"{indent}for {s.LoopIndex.Name} in {edges.Item1} to {endval} loop"); var incr = edges.Item3; if (incr != 1) { throw new Exception($"Expected the for loop to have an increment of 1, it has {incr}"); } foreach (var n in RenderStatement(method, s.LoopBody, indentation + 4)) { yield return(n); } yield return($"{indent}end loop;"); }
/// <summary> /// Renders a single ForStatement with the given indentation /// </summary> /// <returns>The VHDL lines in the statement.</returns> /// <param name="method">The method the statement belongs to.</param> /// <param name="s">The statement to render.</param> /// <param name="indentation">The indentation to use.</param> private IEnumerable <string> RenderStatement(AST.Method method, AST.ForStatement s, int indentation) { var edges = s.GetStaticForLoopValues(); var endval = edges.Item2; var incr = edges.Item3; var indent = new string(' ', indentation); yield return($"{indent}for (size_t {s.LoopIndex.Name} = {edges.Item1}; {s.LoopIndex.Name} < {endval}; {s.LoopIndex.Name} += {incr}) {{"); foreach (var n in RenderStatement(method, s.LoopBody, indentation + 4)) { yield return(n); } yield return($"{indent}}}"); }