elemental impure subroutine compile(this)
use http, only: response_type, request, HTTP_POST, pair_type
use json_module, only: json_file
class(compiler_explorer), intent(inout) :: this
character(len=:), allocatable :: jsonstr
type(pair_type), allocatable :: req_header(:)
type(response_type) :: response
type(json_file) :: json
integer :: i
character(len=10) :: i_str
req_header = [pair_type('Content-Type', 'application/json')]
call json%initialize()
call json%add('source', this%source)
call json%add('options.userArguments', this%options%userArguments)
call json%add('options.compilerOptions.skipAsm', this%options%compilerOptions%skipAsm)
call json%add('options.compilerOptions.executorRequest', this%options%compilerOptions%executorRequest)
call json%add('options.filters.binary', this%options%filters%binary)
call json%add('options.filters.binaryObject', this%options%filters%binaryObject)
call json%add('options.filters.commentOnly', this%options%filters%commentOnly)
call json%add('options.filters.demangle', this%options%filters%demangle)
call json%add('options.filters.directives', this%options%filters%directives)
call json%add('options.filters.execute', this%options%filters%execute)
call json%add('options.filters.intel', this%options%filters%intel)
call json%add('options.filters.labels', this%options%filters%labels)
call json%add('options.filters.libraryCode', this%options%filters%libraryCode)
call json%add('options.filters.trim', this%options%filters%trim)
call json%add('options.filters.debugCalls', this%options%filters%debugCalls)
if (allocated(this%options%tools)) then
do i = 1, size(this%options%tools)
write(i_str, '(I2)') i
call json%add('options.tools('//trim(i_str)//').id', trim(this%options%tools(i)%id_args(1)))
call json%add('options.tools('//trim(i_str)//').args', trim(this%options%tools(i)%id_args(2)))
end do
end if
if (allocated(this%options%libraries)) then
do i = 1, size(this%options%libraries)
write(i_str, '(I2)') i
call json%add('options.libraries('//trim(i_str)//').id', trim(this%options%libraries(i)%id_version(1)))
call json%add('options.libraries('//trim(i_str)//').version', trim(this%options%libraries(i)%id_version(2)))
end do
end if
call json%add('lang', this%lang)
call json%add('allowStoreCodeDebug', this%allowStoreCodeDebug)
call json%print_to_string(jsonstr)
call json%destroy()
response = request(url=this%api_url//'/api/compiler/'//trim(this%compiler_id)//'/compile',&
method=HTTP_POST, data=jsonstr, header=req_header)
if (response%ok) then
print*, response%content
else
print '(A)', 'Sorry, an error occurred while processing your request.'
print '(A)', 'Error message:', response%err_msg
end if
end subroutine compile