Skip to content
Snippets Groups Projects
Commit bf4ba389 authored by Mark Hakansson's avatar Mark Hakansson
Browse files

Update HOME_EXAM.md

parent c3c9b48b
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment