Removed all opaque pointers

This commit is contained in:
Samuel Hammersberg 2023-01-23 16:17:54 +01:00
parent 157ff56301
commit 5524e1ec3e

View file

@ -23,7 +23,7 @@ define [21 x i8] @i64ToString(i64 %val_org) {
; allocate memory for the string, and store the temp variable into it
%string_ptr = alloca [21 x i8]
store [21 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", ptr %string_ptr
store [21 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [21 x i8]* %string_ptr
; create a pointer to the array
%array_index_ptr = alloca i32
@ -33,10 +33,10 @@ define [21 x i8] @i64ToString(i64 %val_org) {
while_point:
%val.tmp = load i64, i64* %val; load i64, i64* %val
%val.1 = call i64 @llvm.abs.i64(i64 %val.tmp, i1 true)
%tmp = load i32, ptr %array_index_ptr
%tmp = load i32, i32* %array_index_ptr
%array_pointer.1 = getelementptr [21 x i8], [21 x i8]* %string_ptr, i32 0, i32 %tmp
%array_index_ptr.1 = add i32 %tmp, 1
store i32 %array_index_ptr.1, ptr %array_index_ptr
store i32 %array_index_ptr.1, i32* %array_index_ptr
; this should not work, but it does
%remainder = srem i64 %val.1, 10
@ -76,10 +76,10 @@ define [21 x i8] @i64ToString(i64 %val_org) {
ret [21 x i8] %res
}
define void @reverseI64String(i8* %string, i64 %len) {
define void @reverseI64String([21 x i8]* %string) {
%new_string = alloca [21 x i8]
store [21 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", ptr %new_string
%reverse_index = alloca i32*
store [21 x i8] c"\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [21 x i8]* %new_string
%reverse_index = alloca i32
store i32 20, i32* %reverse_index
%new_index = alloca i32
@ -90,7 +90,7 @@ define void @reverseI64String(i8* %string, i64 %len) {
%reverse_index.0 = load i32, i32* %reverse_index
%reverse_ptr = getelementptr [21 x i8], [21 x i8]* %string, i32 0, i32 %reverse_index.0
%reverse_index.1 = sub i32 %reverse_index.0, 1
store i32 %reverse_index.1, ptr %reverse_index
store i32 %reverse_index.1, i32* %reverse_index
%new_index.0 = load i32, i32* %new_index
%new_ptr = getelementptr [21 x i8], [21 x i8]* %new_string, i32 0, i32 %new_index.0
@ -102,14 +102,14 @@ define void @reverseI64String(i8* %string, i64 %len) {
%condition = icmp eq i8 %value, 0
br i1 %condition, label %while_start, label %not_zero
not_zero:
store i8 %value, ptr %new_ptr
store i8 %value, i8* %new_ptr
%new_index.1 = add i32 %new_index.0, 1
store i32 %new_index.1, ptr %new_index
store i32 %new_index.1, i32* %new_index
br label %while_start
break:
%copy = load [21 x i8], [21 x i8]* %new_string
store [21 x i8] %copy, i8* %string
store [21 x i8] %copy, [21 x i8]* %string
; start iterating over the original string in reverse
; if i == '\00' ignore
; else put value into new_string at new i, then new i + 1
@ -119,13 +119,14 @@ define void @reverseI64String(i8* %string, i64 %len) {
; Definition of main function
define i32 @main() { ; i32()*
; %val = add i64 -123456789, 0
%val = add i64 -133769420, 0
%val = add i64 -133780085, 0
%print_res = call [21 x i8] @i64ToString(i64 %val)
%ptr = alloca [21 x i8]
store [21 x i8] %print_res, ptr %ptr
store [21 x i8] %print_res, [21 x i8]* %ptr
call i32 @puts(i8* %ptr)
%printable = bitcast [21 x i8]* %ptr to i8*
call i32 @puts(i8* %printable)
ret i32 0
}