Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
386490f6
Commit
386490f6
authored
Dec 14, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added takehome assignment 2 for compilerbouw.
parent
e074b980
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
196 additions
and
0 deletions
+196
-0
.gitignore
.gitignore
+1
-0
compiler-taddeus/takehome3.tex
compiler-taddeus/takehome3.tex
+195
-0
No files found.
.gitignore
View file @
386490f6
...
...
@@ -17,5 +17,6 @@ robotica/
*.cmi
*.cmo
*.exe
*.dvi
*#
*~
compiler-taddeus/takehome3.tex
0 → 100644
View file @
386490f6
\documentclass
[a4paper]
{
article
}
\usepackage
{
hyperref,color,float
}
\usepackage
[all]
{
xy
}
\title
{
Comilerbouw - Takehome opgave 2
}
\author
{
Tadde
\"
us Kroes (6054129)
}
% Paragraph indentation
\setlength
{
\parindent
}{
0pt
}
\setlength
{
\parskip
}{
1ex plus 0.5ex minus 0.2ex
}
\begin{document}
\maketitle
\setcounter
{
secnumdepth
}{
1
}
\section
{
1a
}
\begin{displaymath}
\xygraph
{
!
{
<0cm,0cm>;<2cm,0cm>:<0cm,2cm>::
}
!
{
(2,2)
}
*+
{
k
}
="k"
!
{
(1,2)
}
*+
{
j
}
="j"
!
{
(1,1)
}
*+
{
g
}
="g"
!
{
(2,1)
}
*+
{
h
}
="h"
!
{
(1,0)
}
*+
{
f
}
="f"
!
{
(2,0)
}
*+
{
e
}
="e"
!
{
(0,2)
}
*+
{
d
}
="d"
!
{
(3,1)
}
*+
{
c
}
="c"
"d"-"c" "d"-"j" "d"-"h" "d"-"g" "d"-"f"
"j"-"k" "j"-"c" "j"-"h" "j"-"g"
"k"-"g"
"g"-"h" "g"-"e" "g"-"f"
"h"-"c" "h"-"e" "h"-"f"
"c"-"f"
"f"-"e"
}
\end{displaymath}
\section
{
1b
}
We volgen het algoritme voor "Coloring by simplification":
\begin{enumerate}
\item
Find a node m with less than K neighbors
\item
Remove node m and its edges from G, resulting in G'.
Store m on a stack
\item
Color the graph G'
\item
Graph G can be colored since m has less than K neighbors
\end{enumerate}
In ons geval is K = 4 (er zijn immers 4 registers beschikbaar). We zoeken dus
eerst een node met minder dan 4 buren:
\begin{table}
[H]
\begin{tabular}
{
l|l
}
node
&
aantal buren
\\
\hline
k
&
2
$
\leftarrow
$
\\
j
&
5
\\
g
&
6
\\
h
&
6
\\
f
&
5
\\
e
&
3
\\
d
&
5
\\
c
&
4
\\
\end{tabular}
\end{table}
We verwijderen k en zetten hem op de stack. De overgebleven graaf is:
\begin{table}
[H]
\begin{tabular}
{
l|l
}
node
&
aantal buren
\\
\hline
j
&
4
\\
g
&
5
\\
h
&
6
\\
f
&
5
\\
e
&
3
$
\leftarrow
$
\\
d
&
5
\\
c
&
4
\\
\end{tabular}
\end{table}
We verwijderen e en zetten hem op de stack. De overgebleven graaf is:
\begin{table}
[H]
\begin{tabular}
{
l|l
}
node
&
aantal buren
\\
\hline
j
&
4
\\
g
&
4
\\
h
&
5
\\
f
&
4
\\
d
&
5
\\
c
&
4
\\
\end{tabular}
\end{table}
Er zijn geen nodes meer met minder dan 4 buren, maar er is een "redundant
move" (namelijk "j = f", omdat er geen kant in de graaf is tussen j en f).
We kunnen j en f, "coalesceren". Hierna hebben we de volgende graaf G'
(nodes k en e zijn al verwijderd):
\begin{displaymath}
\xygraph
{
!
{
<0cm,0cm>;<2cm,0cm>:<0cm,2cm>::
}
!
{
(1,2)
}
*+
{
j + f
}
="jf"
!
{
(1,1)
}
*+
{
g
}
="g"
!
{
(2,1)
}
*+
{
h
}
="h"
!
{
(0,2)
}
*+
{
d
}
="d"
!
{
(3,1)
}
*+
{
c
}
="c"
"d"-"c" "d"-"jf" "d"-"g" "d"-"h"
"jf"-"c" "jf"-"h" "jf"-"g"
"g"-"h"
"h"-"c"
}
\end{displaymath}
\begin{table}
[H]
\begin{tabular}
{
l|l
}
node
&
aantal buren
\\
\hline
j + f
&
4
\\
g
&
3
$
\leftarrow
$
\\
h
&
4
\\
d
&
4
\\
c
&
3
\\
\end{tabular}
\end{table}
We verwijderen g en zetten hem op de stack. De overgebleven graaf is:
\begin{table}
[H]
\begin{tabular}
{
l|l
}
node
&
aantal buren
\\
\hline
j + f
&
3
\\
h
&
3
\\
d
&
3
\\
c
&
3
\\
\end{tabular}
\end{table}
Alle nodes hebben nu minder dan 4 buren, dus volgens het algoritme worden ze
\'
e
\'
en voor
\'
e
\'
en op de stack gezet. De uiteindelijke stack is
\{
k, e, g,
j + f, h, d, c
\}
. Nu "poppen" we telkens een element van de stack en kleuren
hem met een kleur die niet wordt gebruikt door zijn buren:
\\
\{
k, e, g, j + f, h, d
\}
\textcolor
{
blue
}{
c
}
\\
\{
k, e, g, j + f, h
\}
\textcolor
{
red
}{
d
}
\\
\{
k, e, g, j + f
\}
\textcolor
{
green
}{
h
}
\\
\{
k, e, g
\}
\textcolor
{
cyan
}{
j + f
}
\\
\{
k, e
\}
\textcolor
{
blue
}{
g
}
\\
\{
k
\}
\textcolor
{
red
}{
e
}
\\
\{\}
\textcolor
{
red
}{
k
}
De kleurenindeling van G is dus als volgt:
\begin{displaymath}
\xygraph
{
!
{
<0cm,0cm>;<2cm,0cm>:<0cm,2cm>::
}
!
{
(2,2)
}
*+
{
\textcolor
{
red
}{
k
}}
="k"
!
{
(1,2)
}
*+
{
\textcolor
{
cyan
}{
j
}}
="j"
!
{
(1,1)
}
*+
{
\textcolor
{
blue
}{
g
}}
="g"
!
{
(2,1)
}
*+
{
\textcolor
{
green
}{
h
}}
="h"
!
{
(1,0)
}
*+
{
\textcolor
{
cyan
}{
f
}}
="f"
!
{
(2,0)
}
*+
{
\textcolor
{
red
}{
e
}}
="e"
!
{
(0,2)
}
*+
{
\textcolor
{
red
}{
d
}}
="d"
!
{
(3,1)
}
*+
{
\textcolor
{
blue
}{
c
}}
="c"
"d"-"c" "d"-"j" "d"-"h" "d"-"g" "d"-"f"
"j"-"k" "j"-"c" "j"-"h" "j"-"g"
"k"-"g"
"g"-"h" "g"-"e" "g"-"f"
"h"-"c" "h"-"e" "h"-"f"
"c"-"f"
"f"-"e"
}
\end{displaymath}
Dit komt neer op de volgende registerallocatie:
\begin{table}
[H]
\begin{tabular}
{
l|l
}
Register
&
Variabelen
\\
\hline
\textcolor
{
blue
}{
0
}
&
g, c
\\
\textcolor
{
red
}{
1
}
&
d, k, e
\\
\textcolor
{
green
}{
2
}
&
h
\\
\textcolor
{
cyan
}{
3
}
&
j, f
\\
\end{tabular}
\end{table}
\end{document}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment