Closed
Description
Related lfortran/lfortran#2042.
Example:
$ cat examples/expr_2.py
from lpython import i8, i16, i32, i64
def main0():
x: i8
y: i16
z: i32
w: i64
x = i8(97)
y = i16(47)
z = 56
w = i64(67)
print(chr(x), chr(y), chr(z), chr(w))
assert chr(x) == 'a'
assert chr(y) == '/'
assert chr(z) == '8'
assert chr(w) == 'C'
main0()
$ lpython examples/expr_2.py
; ModuleID = 'LFortran'
source_filename = "LFortran"
@0 = private unnamed_addr constant [2 x i8] c" \00", align 1
@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@2 = private unnamed_addr constant [17 x i8] c"%s%s%s%s%s%s%s%s\00", align 1
@3 = private unnamed_addr constant [2 x i8] c"a\00", align 1
@4 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1
@5 = private unnamed_addr constant [2 x i8] c"/\00", align 1
@6 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1
@7 = private unnamed_addr constant [2 x i8] c"8\00", align 1
@8 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1
@9 = private unnamed_addr constant [2 x i8] c"C\00", align 1
@10 = private unnamed_addr constant [16 x i8] c"AssertionError\0A\00", align 1
define void @__module__global_symbols__lpython_main_program() {
.entry:
call void @__module__global_symbols_main0()
br label %return
return: ; preds = %.entry
ret void
}
define void @__module__global_symbols_main0() {
.entry:
%w = alloca i64, align 8
%x = alloca i8, align 1
%y = alloca i16, align 2
%z = alloca i32, align 4
store i8 97, i8* %x, align 1
store i16 47, i16* %y, align 2
store i32 56, i32* %z, align 4
store i64 67, i64* %w, align 4
%0 = load i8, i8* %x, align 1
%1 = call i8* @_lfortran_str_chr(i8 %0)
%2 = load i16, i16* %y, align 2
%3 = call i8* @_lfortran_str_chr(i16 %2)
%4 = load i32, i32* %z, align 4
%5 = call i8* @_lfortran_str_chr(i32 %4)
%6 = load i64, i64* %w, align 4
%7 = call i8* @_lfortran_str_chr(i64 %6)
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @2, i32 0, i32 0), i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0))
%8 = load i8, i8* %x, align 1
%9 = call i8* @_lfortran_str_chr(i8 %8)
%10 = alloca i8*, align 8
store i8* %9, i8** %10, align 8
%11 = alloca i8*, align 8
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @3, i32 0, i32 0), i8** %11, align 8
%12 = call i1 @_lpython_str_compare_eq(i8** %10, i8** %11)
br i1 %12, label %then, label %else
then: ; preds = %.entry
br label %ifcont
else: ; preds = %.entry
call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @4, i32 0, i32 0))
call void @exit(i32 1)
br label %ifcont
ifcont: ; preds = %else, %then
%13 = load i16, i16* %y, align 2
%14 = call i8* @_lfortran_str_chr(i16 %13)
%15 = alloca i8*, align 8
store i8* %14, i8** %15, align 8
%16 = alloca i8*, align 8
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @5, i32 0, i32 0), i8** %16, align 8
%17 = call i1 @_lpython_str_compare_eq(i8** %15, i8** %16)
br i1 %17, label %then1, label %else2
then1: ; preds = %ifcont
br label %ifcont3
else2: ; preds = %ifcont
call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @6, i32 0, i32 0))
call void @exit(i32 1)
br label %ifcont3
ifcont3: ; preds = %else2, %then1
%18 = load i32, i32* %z, align 4
%19 = call i8* @_lfortran_str_chr(i32 %18)
%20 = alloca i8*, align 8
store i8* %19, i8** %20, align 8
%21 = alloca i8*, align 8
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @7, i32 0, i32 0), i8** %21, align 8
%22 = call i1 @_lpython_str_compare_eq(i8** %20, i8** %21)
br i1 %22, label %then4, label %else5
then4: ; preds = %ifcont3
br label %ifcont6
else5: ; preds = %ifcont3
call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @8, i32 0, i32 0))
call void @exit(i32 1)
br label %ifcont6
ifcont6: ; preds = %else5, %then4
%23 = load i64, i64* %w, align 4
%24 = call i8* @_lfortran_str_chr(i64 %23)
%25 = alloca i8*, align 8
store i8* %24, i8** %25, align 8
%26 = alloca i8*, align 8
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @9, i32 0, i32 0), i8** %26, align 8
%27 = call i1 @_lpython_str_compare_eq(i8** %25, i8** %26)
br i1 %27, label %then7, label %else8
then7: ; preds = %ifcont6
br label %ifcont9
else8: ; preds = %ifcont6
call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @10, i32 0, i32 0))
call void @exit(i32 1)
br label %ifcont9
ifcont9: ; preds = %else8, %then7
br label %return
return: ; preds = %ifcont9
ret void
}
declare i8* @_lfortran_str_chr(i32)
declare void @_lfortran_printf(i8*, ...)
declare i1 @_lpython_str_compare_eq(i8**, i8**)
declare void @_lcompilers_print_error(i8*, ...)
declare void @exit(i32)
define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @__module__global_symbols__lpython_main_program()
ret i32 0
}
declare void @_lpython_set_argv(i32, i8**)
code generation error: asr_to_llvm: module failed verification. Error:
Call parameter type does not match function signature!
%0 = load i8, i8* %x, align 1
i32 %1 = call i8* @_lfortran_str_chr(i8 %0)
Call parameter type does not match function signature!
%2 = load i16, i16* %y, align 2
i32 %3 = call i8* @_lfortran_str_chr(i16 %2)
Call parameter type does not match function signature!
%6 = load i64, i64* %w, align 4
i32 %7 = call i8* @_lfortran_str_chr(i64 %6)
Call parameter type does not match function signature!
%8 = load i8, i8* %x, align 1
i32 %9 = call i8* @_lfortran_str_chr(i8 %8)
Call parameter type does not match function signature!
%13 = load i16, i16* %y, align 2
i32 %14 = call i8* @_lfortran_str_chr(i16 %13)
Call parameter type does not match function signature!
%23 = load i64, i64* %w, align 4
i32 %24 = call i8* @_lfortran_str_chr(i64 %23)
Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that must be fixed).
Metadata
Metadata
Assignees
Labels
No labels