progs/sqr.ll
author Christian Urban <urbanc@in.tum.de>
Wed, 06 Nov 2019 23:17:05 +0000
changeset 683 c6c79d21f8a8
parent 678 ff3b48da282c
child 701 681c36b2af27
permissions -rw-r--r--
updated

@.str = private constant [4 x i8] c"%d\0A\00"

declare i32 @printf(i8*, ...)

; prints out an integer
define i32 @printInt(i32 %x) {
   %t0 = getelementptr [4 x i8], [4 x i8]* @.str, i32 0, i32 0
   call i32 (i8*, ...) @printf(i8* %t0, i32 %x) 
   ret i32 %x
}

; square function
define i32 @sqr(i32 %x) {
   %tmp = mul i32 %x, %x
   ret i32 %tmp
}

; main 
define i32 @main() {
  %1 = call i32 @sqr(i32 5)
  %2 = call i32 @printInt (i32 %1)
  ret i32 %1
}