Skip to content

Commit

Permalink
Register the test
Browse files Browse the repository at this point in the history
  • Loading branch information
namannimmo10 committed Jul 19, 2022
1 parent 3f3bfdd commit fc35d31
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4371,15 +4371,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
fmt.push_back("%s");
args.push_back(tmp);
} else if (ASRUtils::is_logical(*t)) {
// check if value is 0 or 1 in LLVM
llvm::Value *zero = llvm::ConstantInt::get(getIntType(8, false), 0);
llvm::Value *one = llvm::ConstantInt::get(getIntType(8, false), 1);
llvm::Value *cmp = builder->CreateICmpEQ(tmp, zero);
llvm::Value *cmp = builder->CreateICmpEQ(tmp, builder->getInt1(0));
llvm::Value *zero_str = builder->CreateGlobalStringPtr("False");
llvm::Value *one_str = builder->CreateGlobalStringPtr("True");
llvm::Value *str = builder->CreateSelect(cmp, zero_str, one_str);
fmt.push_back("%s");
args.push_back(str);
printf(context, *module, *builder, {str});
} else if (ASRUtils::is_complex(*t)) {
llvm::Type *type, *complex_type;
switch( a_kind ) {
Expand Down
10 changes: 10 additions & 0 deletions tests/bool1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test_bool():
print(True)
print(False)
b: bool
b = True
print(b)
b = False
print(b)

test_bool()
13 changes: 13 additions & 0 deletions tests/reference/llvm-bool1-af4376b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "llvm-bool1-af4376b",
"cmd": "lpython --no-color --show-llvm {infile} -o {outfile}",
"infile": "tests/bool1.py",
"infile_hash": "963bf5fcc3706fab6a0b5d415caa90048a33ce28b946ce65359204e4",
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-bool1-af4376b.stdout",
"stdout_hash": "eb08319c96550e3b6bc07ec0612f6102a31e24ac39cb85ea9a4e397c",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
26 changes: 26 additions & 0 deletions tests/reference/llvm-bool1-af4376b.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; ModuleID = 'LFortran'
source_filename = "LFortran"

@0 = private unnamed_addr constant [5 x i8] c"True\00", align 1
@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@2 = private unnamed_addr constant [6 x i8] c"False\00", align 1
@3 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1

define void @constant_bool() {
.entry:
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0))
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0))
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @2, i32 0, i32 0))
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @3, i32 0, i32 0))
br label %return

return: ; preds = %.entry
ret void
}

declare void @_lfortran_printf(i8*, ...)

define i32 @main() {
.entry:
ret i32 0
}
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ filename = "set1.py"
ast = true
asr = true

[[test]]
filename = "bool1.py"
llvm = true

[[test]]
filename = "global_scope1.py"
ast = true
Expand Down

0 comments on commit fc35d31

Please sign in to comment.