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=*] \begin{enumerate}[topsep=0pt, leftmargin=*]
\item Create the control flow graph for the given constructor. \item Create the control flow graph for the given constructor.
\begin{answer} \begin{answer}
[TODO: Add answer here]
% Example graph using tikz
\begin{center} \begin{center}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick] \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,semithick]
\tikzstyle{every state}=[fill=gray,draw=none,text=white] \tikzstyle{every state}=[fill=gray,draw=none,text=white]
\node[initial,state] (A) {$A$}; \node[initial,state] (s0) {\texttt{.ctor}};
\node[state] (B) [above right of=A] {$B$}; \node[state] (s1) [below of=s0] {$s_1$};
\node[state] (D) [below right of=A] {$C$}; \node[state] (s2) [right of=s1] {$s_2$};
\node[state] (C) [below right of=B] {$D$}; \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) \path
(B) edge [loop above] node {Dummy Label 2} (B) (s0) edge [bend left] node {$\texttt{iC} < 0$} (throw)
edge node {Dummy Label 3} (C) (s0) edge node {$\texttt{iC} \geq 0$} (s1)
(C) edge node {Dummy Label 4} (D) (s1) edge node {$\texttt{iC} > \texttt{MAX}$} (s2)
(D) edge node {Dummy Label 5} (A); (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{tikzpicture}
\end{center} \end{center}
\end{answer} \end{answer}