Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Confused, how is this related to C++ compilers?

Edit: Oh wow I didn't realize the website does other languages, thanks!



Why does it have to be related to C++ compilers? Compiler Explorer supports a number of languages, including C#:

  $ curl -sL https://godbolt.org/api/languages
  Id             | Name
  csharp         | C#
  fsharp         | F#
  vb             | Visual Basic
  go             | Go
  c              | C
  c++            | C++
  fortran        | Fortran
  assembly       | Assembly
  circle         | C++ (Circle)
  circt          | CIRCT
  hlsl           | HLSL
  cppx           | Cppx
  crystal        | Crystal
  dart           | Dart
  erlang         | Erlang
  carbon         | Carbon
  hook           | Hook
  cppx_blue      | Cppx-Blue
  cppx_gold      | Cppx-Gold
  mlir           | MLIR
  cuda           | CUDA C++
  analysis       | Analysis
  python         | Python
  racket         | Racket
  ruby           | Ruby
  typescript     | TypeScript Native
  d              | D
  ada            | Ada
  cpp_for_opencl | C++ for OpenCL
  openclc        | OpenCL C
  llvm           | LLVM IR
  cpp2_cppfront  | Cpp2-cppfront
  rust           | Rust
  ispc           | ispc
  java           | Java
  kotlin         | Kotlin
  nim            | Nim
  pony           | Pony
  scala          | Scala
  solidity       | Solidity
  clean          | Clean
  pascal         | Pascal
  haskell        | Haskell
  ocaml          | OCaml
  swift          | Swift
  zig            | Zig
  $


Since it's on topic and pretty cool, Common Lisp has built-in support for this with the disassemble function, (disassemble <function-name>):

    CL-USER> (defun do-something (a b)
               (format t "a: ~a~%b: ~a~%~%" a b))
    
    DO-SOMETHING
    CL-USER> (disassemble #'do-something)
    ; disassembly for DO-SOMETHING
    ; Size: 216 bytes. Origin: #x537D0F66                         ; DO-SOMETHING
    ; 0F66:       498B4510         MOV RAX, [R13+16]              ; thread.binding-stack-pointer
    ; 0F6A:       488945F8         MOV [RBP-8], RAX
    ; 0F6E:       840425F87F0050   TEST AL, [#x50007FF8]          ; safepoint
    ; 0F75:       498BB5E8050000   MOV RSI, [R13+1512]            ; tls: *STANDARD-OUTPUT*
    ; 0F7C:       4883FEFF         CMP RSI, -1
    ; 0F80:       480F443425B05B1450 CMOVEQ RSI, [#x50145BB0]     ; *STANDARD-OUTPUT*
    ; 0F89:       488975E0         MOV [RBP-32], RSI
    ; 0F8D:       4883EC10         SUB RSP, 16
    ; 0F91:       488B1570FFFFFF   MOV RDX, [RIP-144]             ; "a: "
    ; 0F98:       488B7DE0         MOV RDI, [RBP-32]
    ; ...

And of course it works for the functions that are defined by the standard, too:

    CL-USER> (disassemble #'format)
    ; disassembly for FORMAT
    ; Size: 581 bytes. Origin: #x52A12CCD                         ; FORMAT
    ; CCD:       840425F87F0050   TEST AL, [#x50007FF8]           ; safepoint
    ; CD4:       48817DF817810050 CMP QWORD PTR [RBP-8], #x50008117  ; NIL
    ; CDC:       0F85CB000000     JNE L4
    ; CE2:       4881EC90000000   SUB RSP, 144
    ; CE9:       4883E4F0         AND RSP, -16
    ; CED:       488D7C240F       LEA RDI, [RSP+15]
    ; CF2:       48C747F1E5000000 MOV QWORD PTR [RDI-15], 229
    ; CFA:       48C747F93E000000 MOV QWORD PTR [RDI-7], 62
    ; D02:       4881ECB0000000   SUB RSP, 176
    ; D09:       4883E4F0         AND RSP, -16
    ; D0D:       488BC4           MOV RAX, RSP
    ; ...

    CL-USER> (disassemble #'first)
    CL-USER> (disassemble #'+)


Godbolt does more than C++. I often share Java byte code snippets from there


I wish it could also do the machine code version like on .NET languages.

Maybe there is a way to plug hsdis into the workflow.

EDIT: Actually there is already a ticket discussing this, https://github.com/compiler-explorer/compiler-explorer/issue...



Naturally, :)




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: