Added CFG

This commit is contained in:
Michael Chen 2022-05-18 21:05:23 +02:00
parent 8571c450c3
commit 18a1b3ad44
No known key found for this signature in database
GPG Key ID: 1CBC7AA5671437BB

View File

@ -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}