ForCompile - A Fortran library to access the Compiler Explorer API

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
17 Likes

Please be careful with such programs. It’s easy to incur high costs for the provider of a service:

Quoting,

This post is open to all, not just my Patrons. Earlier this week - 22nd September - Compiler Explorer experienced a brief DDoS attack from an unknown assailant.
[…]
I have no real idea why this happened: I’ve not had anyone contact me about it. I wonder if it was someone showing off or briefly testing their newly-acquired botnet. If it was you, and it was a mistake…just, please be careful. We’re fortunate to be able to absorb a one off cost of this magnitude, but we couldn’t take more than this without bringing the service down.

I hope it’s a coincidence that ForCompile was launched on the same day Compiler Explorer had a DDoS attack. :see_no_evil:

4 Likes

Probably as Matt Godbolt says:

200 million junk requests hit godbolt.org. Over 5000 hosts participated in the attack.

:face_with_spiral_eyes:

and we are only 1242 registered users on the Discourse… :sweat_smile:

1 Like

I think you’re merely pointing out a funny coincidence. However, it has occurred to me that this may not be obvious to everybody reading Fortran Discourse.

We’re all on the same page here that ForCompile has nothing to do with the attack on the Compiler Explorer. If anyone has a doubt about it, ask the service owner about the attackers’ User-Agent fields (these can be easily changed, of course). There are 100 easier ways to make HTTP requests to Compiler Explorer’s API than using ForCompile.

I look forward to ForCompiling next week when I get back from my vacation. Thanks, Ali. :slight_smile:

5 Likes

Thanks for clarifying! Obviously, this tool wasn’t developed for that purpose.

I’m happy to see Fortran in the list of projects on Compiler Explorer’s documentation: https://github.com/compiler-explorer/compiler-explorer/blob/main/docs/API.md#implementations

Enjoy your vacation! :slight_smile:

5 Likes