---
# System prepended metadata

title: LLVM IR Notes
tags: [Lucid Dreams, Development]

---

{%hackmd theme-dark %}
# LLVM IR Notes
###### tags: `Lucid Dreams` `Development` 
## Basic Constructs

### Variables

Register/Temp Var

```llvm
; Define symbols with %
%reg = add i32 4, 2
```
Stack

`%stack` isn't actually stack ptr or anything, use `alloca` to get the stack ptr for the variable

```
%stack = alloca i32
```
### Structs

accessed by index, not by name, using the GEP ~~gun~~ instruction

Definition

```llvm
%Foo = type {
    i32,
    i8*,
    double
}
```

Getting attribs

```llvm
%foo = alloca %Foo
%fooptr.1 = getelementptr %Foo, %Foo %foo, i32 0, i32 1
```

