Skip to content

Commit

Permalink
Add an examples/project1 with multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed May 12, 2021
1 parent 3c205af commit 6eb58f1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/project1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(project1 C Fortran)

add_executable(project1
project1.f90
a.f90
b.f90
)
8 changes: 8 additions & 0 deletions examples/project1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
To compile with LFortran:

FC=lfortran cmake .

To choose a backend:

FC=lfortran FFLAGS="--backend=cpp" cmake .
FC=lfortran FFLAGS="--backend=llvm" cmake .
26 changes: 26 additions & 0 deletions examples/project1/a.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module a
use b, only: g
implicit none
private
public f, fib

contains

integer function f()
f = 3 + g()
end function

subroutine fib(n)
integer, intent(in) :: n
integer :: i, a, b, c
a = 1
b = 1
do i = 1, n-2
c = a+b
print *, "Fibonacci: ", i, " ", c
a = b;
b = c;
end do
end subroutine

end module
12 changes: 12 additions & 0 deletions examples/project1/b.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module b
implicit none
private
public g

contains

integer function g()
g = 5
end function

end module
11 changes: 11 additions & 0 deletions examples/project1/project1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
program project1
use a, only: f, fib
implicit none

if (f() /= 8) error stop

call fib(10)

print *, "OK"

end

0 comments on commit 6eb58f1

Please sign in to comment.