Skip to content

Commit 10625b0

Browse files
eigenhombremewmew
authored andcommitted
Apply changes suggested by maintainer. llir#228 / llir#227.
1 parent 5d437a7 commit 10625b0

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

README.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,21 @@ import (
8989
func main() {
9090
// Create a new LLVM IR module.
9191
m := ir.NewModule()
92-
arr := constant.NewCharArrayFromString("Hello, world!\n\x00")
93-
gd := m.NewGlobalDef("str", arr)
94-
// link to external function puts
92+
hello := constant.NewCharArrayFromString("Hello, world!\n\x00")
93+
str := m.NewGlobalDef("str", hello)
94+
// Add external function declaration of puts.
9595
puts := m.NewFunc("puts", types.I32, ir.NewParam("", types.NewPointer(types.I8)))
9696
main := m.NewFunc("main", types.I32)
9797
entry := main.NewBlock("")
98-
99-
// Perform cast per [1]:
100-
gep := constant.NewGetElementPtr(types.NewArray(15, types.I8),
101-
gd,
102-
constant.NewInt(types.I8, 0),
103-
constant.NewInt(types.I8, 0))
98+
// Cast *[15]i8 to *i8; c.f.: [1]
99+
zero := constant.NewInt(types.I64, 0)
100+
gep := constant.NewGetElementPtr(hello.Typ, str, zero, zero)
104101
entry.NewCall(puts, gep)
105102
entry.NewRet(constant.NewInt(types.I32, 0))
106103
fmt.Println(m)
107104
}
108-
109-
// See also:
105+
// [1] See also:
110106
// https://github.com/anoopsarkar/compilers-class-hw/blob/master/llvm-practice/helloworld.ll
111-
112107
```
113108

114109
#### Pseudo Random-Number Generator

0 commit comments

Comments
 (0)