# ForCompile - A Fortran library to access the Compiler Explorer API

**URL:** <https://fortran-lang.discourse.group/t/forcompile-a-fortran-library-to-access-the-compiler-explorer-api/6559>\
**Category:** Announcements\
**Created:** [September 25, 2023, 5:35pm UTC](https://fortran-lang.discourse.group/t/forcompile-a-fortran-library-to-access-the-compiler-explorer-api/6559 "2023-09-25T17:35:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ali/32/751_2.png) [@Ali](https://fortran-lang.discourse.group/u/Ali)\
**Post date:** [September 25, 2023, 5:35pm UTC](https://fortran-lang.discourse.group/t/forcompile-a-fortran-library-to-access-the-compiler-explorer-api/6559/1 "2023-09-25T17:35:57Z")

</div>

[ForCompile](https://github.com/gha3mi/forcompile) is a library to access the [Compiler Explorer](https://godbolt.org/) API.

Below is a test program that compiles the “Hello World” program:

```fortran
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:**
>
> ```plaintext
> # 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
> 
> ```

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [September 26, 2023, 8:51am UTC](https://fortran-lang.discourse.group/t/forcompile-a-fortran-library-to-access-the-compiler-explorer-api/6559/2 "2023-09-26T08:51:46Z")

</div>

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

> **[Compiler Explorer DDoS 2023-09-22 | Matt Godbolt](https://www.patreon.com/posts/compiler-ddos-09-89840513?utm_medium=post_notification_email&utm_campaign=patron_engagement&utm_source=post_link)**
>
> Patreon is empowering a new generation of creators. 
> Support and engage with artists and creators as they live out their passions!

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. 🙈

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [September 26, 2023, 10:10am UTC](https://fortran-lang.discourse.group/t/forcompile-a-fortran-library-to-access-the-compiler-explorer-api/6559/3 "2023-09-26T10:10:48Z")

</div>

> [@ivanpribec](#):
>
> I hope it’s a coincidence that ForCompile was launched on the same day Compiler Explorer had a DDoS attack.

Probably as Matt Godbolt says:

> 200 million junk requests hit [godbolt.org](http://godbolt.org). Over 5000 hosts participated in the attack.

😵‍💫

and we are only 1242 registered users on the Discourse… 😅

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [September 30, 2023, 3:10am UTC](https://fortran-lang.discourse.group/t/forcompile-a-fortran-library-to-access-the-compiler-explorer-api/6559/4 "2023-09-30T03:10:44Z")

</div>

> [@ivanpribec](#):
>
> I hope it’s a coincidence that ForCompile was launched on the same day Compiler Explorer had a DDoS attack. 🙈

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. 🙂

---

<div class="post-metadata">

**Author:** ![Ali](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ali/32/751_2.png) [@Ali](https://fortran-lang.discourse.group/u/Ali)\
**Post date:** [September 30, 2023, 2:47pm UTC](https://fortran-lang.discourse.group/t/forcompile-a-fortran-library-to-access-the-compiler-explorer-api/6559/5 "2023-09-30T14:47:03Z")

</div>

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](https://github.com/compiler-explorer/compiler-explorer/blob/main/docs/API.md#implementations)

Enjoy your vacation! 🙂
