This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to inline assembler into gcc-FORTRAN program?


David Livshin wrote:

> What I really need is to be able to specify portions of ( fortran ) code
> in such a way that it would be possible to determine their assembly code
> in the compiler-generated assembly output. For C it could be done by

If that's all you need then why not use the debug info?  Using objdump -dS and a binary
compiled with -g you get an output that has the source and generated assembly intermixed,
so it's simple to just search for marker comments.  e.g.

$ cat hello.f90
PROGRAM Hello_world
! marker-begin
        PRINT *,"Hello"
! marker-end
        PRINT *,"World"
END PROGRAM Hello_world

$ gfortran hello.f90 -O2 -g -o hello

$ objdump -dSw hello.exe | sed -ne '/! marker-begin/,/! marker-end/ p'
! marker-begin
        PRINT *,"Hello"
  40104a:       8d 9d d8 fe ff ff       lea    0xfffffed8(%ebp),%ebx
  401050:       c7 44 24 0c 00 00 00 00         movl   $0x0,0xc(%esp)
  401058:       c7 44 24 08 00 00 00 00         movl   $0x0,0x8(%esp)
  401060:       c7 44 24 04 7f 00 00 00         movl   $0x7f,0x4(%esp)
  401068:       c7 04 24 46 00 00 00    movl   $0x46,(%esp)
  40106f:       e8 fc 00 00 00          call   401170 <__gfortran_set_std>
  401074:       89 1c 24                mov    %ebx,(%esp)
  401077:       c7 85 e0 fe ff ff 00 60 41 00   movl   $0x416000,0xfffffee0(%ebp)
  401081:       c7 85 e4 fe ff ff 03 00 00 00   movl   $0x3,0xfffffee4(%ebp)
  40108b:       c7 85 dc fe ff ff 06 00 00 00   movl   $0x6,0xfffffedc(%ebp)
  401095:       c7 85 d8 fe ff ff 80 00 00 00   movl   $0x80,0xfffffed8(%ebp)
  40109f:       e8 4c 3e 00 00          call   404ef0 <__gfortran_st_write>
  4010a4:       89 1c 24                mov    %ebx,(%esp)
  4010a7:       c7 44 24 08 05 00 00 00         movl   $0x5,0x8(%esp)
  4010af:       c7 44 24 04 16 60 41 00         movl   $0x416016,0x4(%esp)
  4010b7:       e8 54 02 00 00          call   401310 <__gfortran_transfer_character>
  4010bc:       89 1c 24                mov    %ebx,(%esp)
  4010bf:       e8 8c 26 00 00          call   403750 <__gfortran_st_write_done>
! marker-end

(Note that I only split up the print into two parts as otherwise the marker-end would be
at the end of the program and have no line number associated with it in the debug info,
but in a non-trivial example this wouldn't be a problem.)

Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]