Skip to content

Commit

Permalink
Added tests for BinOp:Complex and more rules to .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Feb 26, 2021
1 parent 330d2a6 commit d6d49c3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ MANIFEST
## Build Files
*/bin/lfortran
output
*.o
*.out
10 changes: 5 additions & 5 deletions src/lfortran/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
* _lfortran_complex_div
* _lfortran_complex_mul
*/
llvm::Value* lfortran_complex_bin_op(llvm::Value* left_arg, llvm::Value* righ_arg,
llvm::Value* lfortran_complex_bin_op(llvm::Value* left_arg, llvm::Value* right_arg,
std::string runtime_func_name)
{
llvm::Function *fn = module->getFunction(func_name);
llvm::Function *fn = module->getFunction(runtime_func_name);
if (!fn) {
llvm::FunctionType *function_type = llvm::FunctionType::get(
llvm::Type::getVoidTy(context), {
Expand All @@ -137,15 +137,15 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
complex_type->getPointerTo()
}, true);
fn = llvm::Function::Create(function_type,
llvm::Function::ExternalLinkage, func_name, *module);
llvm::Function::ExternalLinkage, runtime_func_name, *module);
}

llvm::AllocaInst *pleft_arg = builder->CreateAlloca(complex_type,
nullptr);
builder->CreateStore(left_arg, pa);
builder->CreateStore(left_arg, pleft_arg);
llvm::AllocaInst *pright_arg = builder->CreateAlloca(complex_type,
nullptr);
builder->CreateStore(right_arg, pb);
builder->CreateStore(right_arg, pright_arg);
llvm::AllocaInst *presult = builder->CreateAlloca(complex_type,
nullptr);
std::vector<llvm::Value*> args = {pleft_arg, pright_arg, presult};
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/complex_mul_test.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
program complex2
complex :: x
x = (3.0, 4.0)
x = x * 4.0
print *, x
x = 2 * x
print *, x
x = (x * (0.0, 3.0))
print *, x
end program
11 changes: 11 additions & 0 deletions tests/complex_sub_test.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
program complex2
complex :: x
x = (3.0, 4.0)
x = x - 4.0
x = 4.0 - x
print *, x
x = 2 - x
print *, x
x = (x - (0.0, 3.0))
print *, x
end program

0 comments on commit d6d49c3

Please sign in to comment.