From bf4ba389c335f2a02b4a05a2b013ce05ca596da1 Mon Sep 17 00:00:00 2001
From: Mark Hakansson <marhak-6@student.ltu.se>
Date: Thu, 14 Nov 2019 08:35:57 +0000
Subject: [PATCH] Update HOME_EXAM.md

---
 HOME_EXAM.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/HOME_EXAM.md b/HOME_EXAM.md
index af30f68..fe46c98 100644
--- a/HOME_EXAM.md
+++ b/HOME_EXAM.md
@@ -344,6 +344,59 @@ The implemented type checker follows the rules above and should it find that the
 The borrow checker should check whether the variable is a mutable or unmutable borrow. If it's unmutable the program should not be able to change the value that the variable holds. If it's mutable the borrow checker should check that the mutable borrow does not occur somewhere else, so that the variable can't be written to at the same time.
 
 ## LLVM
+Very basic code generation was implemented, the compiler does not support all things in the SOS. Most of the LLVM code was inspired by Per's example, the Inkwell Kaleidoscope example as well as Gustav Hansson's work (https://github.com/97gushan/D7050E).
 
+Phi nodes have been added when compiling if branches. So that the compiler can understand which values to use after the branch.  IR code can be seen below
+```rust
+fn test() -> i32 {
+    return 5;
+}
+fn main() -> i32 {
+    let i: i32 = 300;
+    let b: bool = true;
+    let c: i32 = 0;
+    test();
+    while b {
+        c = 1;
+        b = false;
+    };
+    return i;
+}
+```
+
+```llvm
+; ModuleID = 'llvm-program'
+source_filename = "llvm-program"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define i32 @test() {
+entry:
+  ret i32 5
+}
+
+define i32 @main() {
+entry:
+  %c = alloca i32
+  %b = alloca i32
+  %i = alloca i32
+  store i32 300, i32* %i
+  store i1 true, i32* %b
+  store i32 0, i32* %c
+  %test = call i32 @test()
+  %b1 = load i32, i32* %b
+  br i32 %b1, label %do, label %cont
+
+do:                                               ; preds = %do, %entry
+  store i32 1, i32* %c
+  store i1 false, i32* %b
+  %b2 = load i32, i32* %b
+  br i32 %b2, label %do, label %cont
+
+cont:                                             ; preds = %do, %entry
+  %whiletmp = phi i32 [ 0, %do ], [ 0, %do ]
+  %i3 = load i32, i32* %i
+  ret i32 %i3
+}
+```
 ## Overal course goals and learning outcomes.
 I have improved my knowledge in Rust. As well as gained a basic understanding on how the Rust features such as borrows and type checks works. I've learnt how to create my own parser and then how to interpret an AST. 
\ No newline at end of file
-- 
GitLab