Switched directories for the test program, added some example LL programs, and gave the Funky programs a temporary extension.

This commit is contained in:
Samuel Hammersberg 2023-01-22 19:42:51 +01:00
parent df3bf7c6ab
commit 0ae5a9cee0
4 changed files with 87 additions and 0 deletions

20
test/helloworld.ll Normal file
View file

@ -0,0 +1,20 @@
; Copied directly from the documentation
; Declare the string constant as a global constant.
@.hello = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
; External declaration of the puts function
declare i32 @puts(i8* nocapture) nounwind
; Definition of main function
define i32 @main() { ; i32()*
; Convert [13 x i8]* to i8 *...
%cast210 = getelementptr [13 x i8],[13 x i8]* @.hello, i64 0, i64 0
; Call puts function to write out the string to stdout.
call i32 @puts(i8* %cast210)
ret i32 0
}
; Named metadata
!0 = !{i32 42, null, !"string"}
!foo = !{!0}

5
test/simple.sf Normal file
View file

@ -0,0 +1,5 @@
main = 2

62
test/simple_goal.ll Normal file
View file

@ -0,0 +1,62 @@
; External declaration of the puts function
declare i32 @puts(i8* nocapture) nounwind
define [22 x i8] @i64ToString(i64 %val) {
; https://stackoverflow.com/a/7123710
; an algorithm for translating ints to strings
; s = ''
; sign = ''
; if i < 0:
; sign = '-'
; i = -i
; while True:
; remainder = i % 10
; i = i / 10
; s = chr(ord('0') + remainder) + s
; if i == 0:
; break
; return sign + s
; allocate memory for the string, and store the temp variable into it
%string_ptr = alloca [22 x i8]
store [22 x i8] c"Tjena banane hellosa\0A\00", ptr %string_ptr
; create a pointer to the array
%array_index_ptr = alloca i32
store i32 0, ptr %array_index_ptr
; get the value of the first element in the array
%array_index_ptr.0 = load i32, i32* %array_index_ptr
%p = getelementptr [22 x i8], [22 x i8]* %string_ptr, i32 0, i32 %array_index_ptr.0
; check if p is below 0
%condition = icmp slt i64 %val, 0
br i1 %condition, label %negative_check_true, label %negative_check_false
negative_check_true:
store i8 45, i8* %p
br label %negative_check_done
negative_check_false:
store i8 43, i8* %p
br label %negative_check_done
negative_check_done:
; iterate over the next nums
; load the result and return it
%res = load [22 x i8],[22 x i8]* %string_ptr
ret [22 x i8] %res
}
; Definition of main function
define i32 @main() { ; i32()*
%val = add i64 1, 0
%print_res = call [22 x i8] @i64ToString(i64 %val)
%ptr = alloca [22 x i8]
store [22 x i8] %print_res, ptr %ptr
call i32 @puts(i8* %ptr)
ret i32 0
}

5
test/test_program.sf Normal file
View file

@ -0,0 +1,5 @@
main = (\x -> x + x + 3) ((\x -> x) 2)