ForCompile is a library to access the Compiler Explorer API.
Below is a test program that compiles the “Hello World” program:
program test_7
use forcompile, only: compiler_explorer
implicit none
type(compiler_explorer) :: ce
call ce%set_source("&
program hello;&
write(*,*) 'Hello World';&
end program hello&
")
call ce%set_compiler_id('gfortran132')
call ce%options%set_userArguments('-O3')
call ce%options%set_compilerOptions(skipAsm=.false., executorRequest=.false.)
call ce%options%set_filters(&
binary=.false.,&
binaryObject=.false.,&
commentOnly=.true.,&
demangle=.true.,&
directives=.true.,&
execute=.true.,&
intel=.true.,&
labels=.true.,&
libraryCode=.false.,&
trim=.false.,&
debugCalls=.false.)
call ce%set_lang('fortran')
call ce%set_allowStoreCodeDebug(.true.)
call ce%compile()
call ce%finalize()
end program test_7
Result:
# Compilation provided by Compiler Explorer at https://godbolt.org/
.LC0:
.string "/app/example.f90"
.LC2:
.string "Hello World"
MAIN__:
sub rsp, 536
mov rax, QWORD PTR .LC1[rip]
mov rdi, rsp
mov DWORD PTR [rsp+16], 1
mov QWORD PTR [rsp], rax
mov QWORD PTR [rsp+8], OFFSET FLAT:.LC0
call _gfortran_st_write
mov rdi, rsp
mov edx, 11
mov esi, OFFSET FLAT:.LC2
call _gfortran_transfer_character_write
mov rdi, rsp
call _gfortran_st_write_done
add rsp, 536
ret
main:
sub rsp, 8
call _gfortran_set_args
mov esi, OFFSET FLAT:options.1.0
mov edi, 7
call _gfortran_set_options
call MAIN__
xor eax, eax
add rsp, 8
ret
options.1.0:
.long 2116
.long 4095
.long 0
.long 1
.long 1
.long 0
.long 31
.LC1:
.long 128
.long 6
# Execution result with exit code 0
# Standard out:
Hello World