From 18a1b3ad4489c874df7383dc89af10408a0f3c03 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Wed, 18 May 2022 21:05:23 +0200 Subject: [PATCH] Added CFG --- .../Solution_Phase03_MichaelChen.tex | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex index e889bda..3166bd3 100644 --- a/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex +++ b/project_task_sheets/phase_03/project_phase03_tasks/Solution_Phase03_MichaelChen.tex @@ -132,23 +132,33 @@ \begin{enumerate}[topsep=0pt, leftmargin=*] \item Create the control flow graph for the given constructor. \begin{answer} - [TODO: Add answer here] - - % Example graph using tikz \begin{center} \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick] \tikzstyle{every state}=[fill=gray,draw=none,text=white] - \node[initial,state] (A) {$A$}; - \node[state] (B) [above right of=A] {$B$}; - \node[state] (D) [below right of=A] {$C$}; - \node[state] (C) [below right of=B] {$D$}; + \node[initial,state] (s0) {\texttt{.ctor}}; + \node[state] (s1) [below of=s0] {$s_1$}; + \node[state] (s2) [right of=s1] {$s_2$}; + \node[state] (s3) [below of=s1] {$s_3$}; + \node[state] (s4p) [below of=s3] {$s_{4,p}$}; + \node[state] (s4) [right of=s4p] {$s_4$}; + \node[state] (s5) [right of=s4] {$s_5$}; + \node[state] (s6) [below of=s4] {\texttt{.ret}}; + \node[state] (throw) [right of=s2] {\texttt{throw}}; - \path (A) edge node {Dummy Label 1} (B) - (B) edge [loop above] node {Dummy Label 2} (B) - edge node {Dummy Label 3} (C) - (C) edge node {Dummy Label 4} (D) - (D) edge node {Dummy Label 5} (A); + \path + (s0) edge [bend left] node {$\texttt{iC} < 0$} (throw) + (s0) edge node {$\texttt{iC} \geq 0$} (s1) + (s1) edge node {$\texttt{iC} > \texttt{MAX}$} (s2) + (s1) edge node {$\texttt{iC} \leq \texttt{MAX}$} (s3) + (s2) edge [bend left] node {} (s3) + (s3) edge node {} (s4p) + (s3) edge [bend right] node [right] {$\texttt{lF} \leq 0 \lor \texttt{lF} \equiv \texttt{NaN}$} (throw) + (s4p) edge node {} (s4) + (s4) edge [bend left] node {$\texttt{c} < \texttt{iC}$} (s5) + (s4) edge node {$\texttt{c} \geq \texttt{iC}$} (s6) + (s5) edge [bend left] node {} (s4) + ; \end{tikzpicture} \end{center} \end{answer}