-
-
Save unterumarmung/af0084a9bc68122d6f857d36bcd4929d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module foo | |
interface | |
integer function bar(A) | |
INTEGER :: A | |
end function | |
end interface | |
type baz | |
procedure(bar), pointer, nopass :: proc | |
end type baz | |
contains | |
integer function implement_bar(A) | |
integer :: A | |
print *, 'Hello, World!', A | |
implement_bar = 42 | |
end function | |
subroutine use_baz(b) | |
type(baz) :: b | |
call b%proc(42) | |
end subroutine | |
end module foo | |
program main | |
use foo | |
type(baz) :: obj | |
obj%proc => implement_bar | |
call use_baz(obj) | |
end program main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.target_triple = "x86_64-unknown-linux-gnu"} { | |
func.func @_QMfooPimplement_bar(%arg0: !fir.ref<i32> {fir.bindc_name = "a"}) -> i32 { | |
%0 = fir.alloca i32 {bindc_name = "implement_bar", uniq_name = "_QMfooFimplement_barEimplement_bar"} | |
%c-1_i32 = arith.constant -1 : i32 | |
%1 = fir.address_of(@_QQcl.2E2F612E66393000) : !fir.ref<!fir.char<1,8>> | |
%2 = fir.convert %1 : (!fir.ref<!fir.char<1,8>>) -> !fir.ref<i8> | |
%c14_i32 = arith.constant 14 : i32 | |
%3 = fir.call @_FortranAioBeginExternalListOutput(%c-1_i32, %2, %c14_i32) : (i32, !fir.ref<i8>, i32) -> !fir.ref<i8> | |
%4 = fir.address_of(@_QQcl.48656C6C6F2C20576F726C6421) : !fir.ref<!fir.char<1,13>> | |
%c13 = arith.constant 13 : index | |
%5 = fir.convert %4 : (!fir.ref<!fir.char<1,13>>) -> !fir.ref<i8> | |
%6 = fir.convert %c13 : (index) -> i64 | |
%7 = fir.call @_FortranAioOutputAscii(%3, %5, %6) : (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1 | |
%8 = fir.load %arg0 : !fir.ref<i32> | |
%9 = fir.call @_FortranAioOutputInteger32(%3, %8) : (!fir.ref<i8>, i32) -> i1 | |
%10 = fir.call @_FortranAioEndIoStatement(%3) : (!fir.ref<i8>) -> i32 | |
%c42_i32 = arith.constant 42 : i32 | |
fir.store %c42_i32 to %0 : !fir.ref<i32> | |
%11 = fir.load %0 : !fir.ref<i32> | |
return %11 : i32 | |
} | |
func.func @_QMfooPuse_baz(%arg0: !fir.ref<!fir.type<_QMfooTbaz{proc:!fir.boxproc<(!fir.ref<i32>) -> i32>}>> {fir.bindc_name = "b"}) { | |
return | |
} | |
func.func @_QQmain() { | |
%0 = fir.alloca !fir.type<_QMfooTbaz{proc:!fir.boxproc<(!fir.ref<i32>) -> i32>}> {bindc_name = "obj", uniq_name = "_QFEobj"} | |
%1 = fir.field_index proc, !fir.type<_QMfooTbaz{proc:!fir.boxproc<(!fir.ref<i32>) -> i32>}> | |
%2 = fir.coordinate_of %0, %1 : (!fir.ref<!fir.type<_QMfooTbaz{proc:!fir.boxproc<(!fir.ref<i32>) -> i32>}>>, !fir.field) -> !fir.ref<!fir.boxproc<(!fir.ref<i32>) -> i32>> | |
%3 = fir.address_of(@_QMfooPimplement_bar) : (!fir.ref<i32>) -> i32 | |
%4 = fir.emboxproc %3 : ((!fir.ref<i32>) -> i32) -> !fir.boxproc<(!fir.ref<i32>) -> i32> | |
fir.store %4 to %2 : !fir.ref<!fir.boxproc<(!fir.ref<i32>) -> i32>> | |
fir.call @_QMfooPuse_baz(%0) : (!fir.ref<!fir.type<_QMfooTbaz{proc:!fir.boxproc<(!fir.ref<i32>) -> i32>}>>) -> () | |
return | |
} | |
func.func private @_FortranAioBeginExternalListOutput(i32, !fir.ref<i8>, i32) -> !fir.ref<i8> attributes {fir.io, fir.runtime} | |
fir.global linkonce @_QQcl.2E2F612E66393000 constant : !fir.char<1,8> { | |
%0 = fir.string_lit "./a.f90\00"(8) : !fir.char<1,8> | |
fir.has_value %0 : !fir.char<1,8> | |
} | |
func.func private @_FortranAioOutputAscii(!fir.ref<i8>, !fir.ref<i8>, i64) -> i1 attributes {fir.io, fir.runtime} | |
fir.global linkonce @_QQcl.48656C6C6F2C20576F726C6421 constant : !fir.char<1,13> { | |
%0 = fir.string_lit "Hello, World!"(13) : !fir.char<1,13> | |
fir.has_value %0 : !fir.char<1,13> | |
} | |
func.func private @_FortranAioOutputInteger32(!fir.ref<i8>, i32) -> i1 attributes {fir.io, fir.runtime} | |
func.func private @_FortranAioEndIoStatement(!fir.ref<i8>) -> i32 attributes {fir.io, fir.runtime} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment