# Compiler Explorer

> Compile code with thousands of compilers on Compiler Explorer (godbolt.org) and see the assembly, build and run programs with input, run analysis tools such as clang-tidy, format code, share it as a short link, and look up what an instruction does. No account or API key required.

App · 12 actions. Web page: https://docs.lodol.com/docs/integrations/compiler-explorer

## Actions

### Compile and run code

Build a program and run it once on Compiler Explorer, with the input and command-line arguments you give, and get what it printed and its exit code. A build that fails comes back with the compiler's errors and 'ran' false.

**Inputs**

- Language (`language`, text, required): The programming language of the code.
- Compiler (`compiler`, text, required): The compiler to use, such as x86-64 gcc 16.2. Choose the language first to list its compilers.
- Code (`source`, text, required): The code, as you would paste it into Compiler Explorer.
- Compiler flags (`options`, text): Flags for the compiler, such as -O2 -Wall -std=c++20.
- Program input (`stdin`, text): Text the program reads from standard input.
- Program arguments (`arguments`, text): Command-line arguments, separated by spaces. Quote one that contains spaces, as in --name "Jo Bloggs".
- Libraries (`libraries`, list): Libraries the code includes, such as {fmt} or Boost. Choose the language first to list them.

**Outputs**

- `build` (object): How the build went
- `compiler` (text): The compiler ID used
- `exit_code` (number): The program's exit code; empty when it did not run
- `language` (text): The language ID used
- `ran` (true/false): True when the program ran; false when the build failed
- `run_time_ms` (number): How long the program ran, in milliseconds
- `stderr` (text): What the program printed to standard error
- `stdout` (text): What the program printed to standard output
- `summary` (text): One line saying what came back
- `timed_out` (true/false): True when the program ran out of time and was stopped
- `truncated` (true/false): True when the output was too long and was cut short

**Example output**

```json
{
  "build": {
    "diagnostics": [],
    "error_count": 0,
    "exit_code": 0,
    "stderr": "",
    "stdout": "",
    "success": true,
    "warning_count": 0
  },
  "compiler": "g162",
  "exit_code": 0,
  "language": "c++",
  "ran": true,
  "run_time_ms": 24,
  "stderr": "",
  "stdout": "hello world",
  "summary": "The program ran and exited with code 0, printing 1 line.",
  "timed_out": false,
  "truncated": false
}
```

### Compile code

Compile code with the compiler and flags you choose and get the assembly it produces, with the compiler's errors and warnings line by line. Code that fails to compile comes back with 'success' false rather than failing the step.

**Inputs**

- Language (`language`, text, required): The programming language of the code.
- Compiler (`compiler`, text, required): The compiler to use, such as x86-64 gcc 16.2. Choose the language first to list its compilers.
- Code (`source`, text, required): The code, as you would paste it into Compiler Explorer.
- Compiler flags (`options`, text): Flags for the compiler, such as -O2 -Wall -std=c++20.
- Output filters (`filters`, list): Which of Compiler Explorer's output filters to turn on. Leave empty for its defaults: Intel syntax and demangled names, with unused labels, directives and comment-only lines hidden. One or more of: `intel` (Intel syntax (x86)), `demangle` (Demangle names), `labels` (Hide unused labels), `directives` (Hide directives), `commentOnly` (Hide comment-only lines), `libraryCode` (Hide library functions), `trim` (Trim extra whitespace), `debugCalls` (Hide debug intrinsics), `binaryObject` (Compile to an object file and disassemble it), `binary` (Link to a binary and disassemble it).
- Libraries (`libraries`, list): Libraries the code includes, such as {fmt} or Boost. Choose the language first to list them.

**Outputs**

- `assembly` (text): The assembly the compiler produced, one line per line
- `assembly_line_count` (number): How many lines of assembly
- `compile_time_ms` (number): How long compiling took, in milliseconds
- `compiler` (text): The compiler ID used
- `diagnostics` (list): Each error, warning and note, with its line
- `error_count` (number): How many errors
- `exit_code` (number): The compiler's exit code: 0 when it succeeded
- `instruction_set` (text): What the assembly is for, such as amd64
- `language` (text): The language ID used
- `stderr` (text): What the compiler printed to standard error: its messages
- `stdout` (text): What the compiler printed to standard output
- `success` (true/false): True when the code compiled
- `summary` (text): One line saying what came back
- `timed_out` (true/false): True when the compiler ran out of time
- `truncated` (true/false): True when the output was too long and was cut short
- `warning_count` (number): How many warnings

**Example output**

```json
{
  "assembly": "\"square(int)\":\n        imul    edi, edi\n        mov     eax, edi\n        ret",
  "assembly_line_count": 4,
  "compile_time_ms": 40,
  "compiler": "g162",
  "diagnostics": [],
  "error_count": 0,
  "exit_code": 0,
  "instruction_set": "amd64",
  "language": "c++",
  "stderr": "",
  "stdout": "",
  "success": true,
  "summary": "g162 compiled the code, no warnings; 4 lines of assembly.",
  "timed_out": false,
  "truncated": false,
  "warning_count": 0
}
```

### Create short link

Save code with its compiler, flags and libraries as a godbolt.org/z/ link that opens it in Compiler Explorer, optionally with the program running. Links are permanent and anyone who has one can see the code.

**Inputs**

- Language (`language`, text, required): The programming language of the code.
- Compiler (`compiler`, text, required): The compiler to use, such as x86-64 gcc 16.2. Choose the language first to list its compilers.
- Code (`source`, text, required): The code, as you would paste it into Compiler Explorer.
- Compiler flags (`options`, text): Flags for the compiler, such as -O2 -Wall -std=c++20.
- Libraries (`libraries`, list): Libraries the code includes, such as {fmt} or Boost. Choose the language first to list them.
- Show the program running (`run_program`, true/false): Add a pane that runs the program, with the input and arguments below.
- Program input (`stdin`, text): Text the program reads from standard input.
- Program arguments (`arguments`, text): Command-line arguments, separated by spaces. Quote one that contains spaces, as in --name "Jo Bloggs".

**Outputs**

- `id` (text): The link's ID, the part after /z/
- `summary` (text): One line saying what came back
- `url` (text): The link, such as https://godbolt.org/z/E9Escj1EY

**Example output**

```json
{
  "id": "E9Escj1EY",
  "summary": "Saved as https://godbolt.org/z/E9Escj1EY.",
  "url": "https://godbolt.org/z/E9Escj1EY"
}
```

### Format code

Reformat code with clang-format (in the Google, LLVM or another style), rustfmt, gofmt or another formatter, choosing spaces or tabs and the indent width.

**Inputs**

- Formatter (`formatter`, text, required): The formatter: clangformat for C and C++, rustfmt, gofmt...
- Code (`source`, text, required): The code, as you would paste it into Compiler Explorer.
- Style (`style`, text): The base style, for formatters that have them (clang-format: Google, LLVM, Mozilla...). Defaults to the formatter's first.
- Indent with spaces (`use_spaces`, true/false): Indent with spaces rather than tabs. Defaults to on.
- Indent width (`tab_width`, number): How many columns one indent is, 1 to 16. Defaults to 4. From 1 to 16.

**Outputs**

- `changed` (true/false): True when formatting changed the code
- `formatted` (text): The formatted code
- `formatter` (text): The formatter used
- `style` (text): The base style used, if the formatter has styles
- `summary` (text): One line saying what came back

**Example output**

```json
{
  "changed": true,
  "formatted": "int main() { int x = 1; }",
  "formatter": "clangformat",
  "style": "Google",
  "summary": "clangformat reformatted the code."
}
```

### Get instruction documentation

Look up what an assembly instruction does, such as imul on x86-64 or ldr on ARM, from the vendor's reference, with a link to the full entry.

**Inputs**

- Instruction set (`instruction_set`, text, required): The processor family, or bytecode, the instruction is for. One of: `amd64` (x86-64 (amd64)), `aarch64` (ARM 64-bit (AArch64)), `arm32` (ARM 32-bit), `riscv64` (RISC-V 64-bit), `powerpc`, `avr`, `6502` (MOS 6502), `llvm` (LLVM IR), `ptx` (NVIDIA PTX), `sass` (NVIDIA SASS), and 3 more.
- Instruction (`opcode`, text, required): The instruction's mnemonic, such as imul, ldr or addi.

**Outputs**

- `description` (text): The full explanation, as plain text
- `html` (text): The full explanation as the reference's HTML
- `instruction_set` (text): The instruction set it is from
- `opcode` (text): The instruction looked up
- `summary` (text): A one-paragraph explanation
- `url` (text): A link to the reference's entry

**Example output**

```json
{
  "description": "Performs a signed multiplication of two operands. This instruction has three forms, depending on the number of operands.",
  "html": "<p>Performs a signed multiplication of two operands. This instruction has three forms, depending on the number of operands.</p>",
  "instruction_set": "amd64",
  "opcode": "imul",
  "summary": "Performs a signed multiplication of two operands. This instruction has three forms, depending on the number of operands.",
  "url": "https://www.felixcloutier.com/x86/imul"
}
```

### Get short link

Read the code, language, compilers, flags and libraries saved in a godbolt.org/z/ short link.

**Inputs**

- Short link (`link`, text, required): The link, such as https://godbolt.org/z/E9Escj1EY, or just its ID.

**Outputs**

- `compiler` (text): The first compiler's ID
- `id` (text): The link's ID
- `language` (text): The first editor's language ID
- `options` (text): The first compiler's flags
- `session_count` (number): How many editors
- `sessions` (list): Every editor in the link, with its compilers
- `source` (text): The first editor's code
- `summary` (text): One line saying what came back
- `url` (text): The link

**Example output**

```json
{
  "compiler": "g162",
  "id": "E9Escj1EY",
  "language": "c++",
  "options": "-O2",
  "session_count": 1,
  "sessions": [
    {
      "compilers": [
        {
          "compiler": "g162",
          "libraries": [],
          "options": "-O2"
        }
      ],
      "executors": [
        {
          "arguments": "",
          "compiler": "g162",
          "libraries": [],
          "options": "-O2",
          "stdin": ""
        }
      ],
      "language": "c++",
      "source": "int square(int n) { return n * n; }\n"
    }
  ],
  "source": "int square(int n) { return n * n; }\n",
  "summary": "1 editor of c++ code with 1 compiler.",
  "url": "https://godbolt.org/z/E9Escj1EY"
}
```

### List code formatters

List the code formatters Compiler Explorer runs, such as clang-format, rustfmt and gofmt, with their versions and the styles each offers.

**Inputs**: None.

**Outputs**

- `count` (number): How many are listed
- `formatters` (list): The formatters
- `summary` (text): One line saying what came back

**Example output**

```json
{
  "count": 1,
  "formatters": [
    {
      "name": "clangformat",
      "styles": [
        "Google",
        "LLVM",
        "Mozilla",
        "Chromium",
        "WebKit"
      ],
      "type": "clangformat",
      "version": "clang-format version 24.0.0git"
    }
  ],
  "summary": "1 formatter: clangformat."
}
```

### List compilers

List compilers, for one language or all, with each one's ID, version, target instruction set and release track. Narrow it by name (clang, x86-64 gcc), to stable or nightly builds, or to compilers whose programs can be run.

**Inputs**

- Language (`language`, text): Only compilers for this language. Leave empty for all.
- Name contains (`name_contains`, text): Only compilers whose name or ID contains this, such as clang.
- Release track (`release_track`, text): Only stable releases, nightly builds and so on. One of: `stable` (Stable releases), `nightly` (Nightly builds (trunk)), `prerelease` (Pre-releases), `experimental`.
- Only those that can run programs (`runnable_only`, true/false): Only compilers whose programs Compiler Explorer can run.
- Most to return (`limit`, number): How many compilers to return, 1 to 1000. Defaults to 100. From 1 to 1000.

**Outputs**

- `compilers` (list): The compilers that matched
- `count` (number): How many are listed
- `summary` (text): One line saying what came back
- `total_count` (number): How many matched in all, before the limit

**Example output**

```json
{
  "compilers": [
    {
      "can_run_programs": true,
      "compiler_type": null,
      "group": "GCC x86-64",
      "id": "g162",
      "instruction_set": "amd64",
      "language": "c++",
      "name": "x86-64 gcc 16.2",
      "release_track": "stable",
      "version": "16.2"
    }
  ],
  "count": 1,
  "summary": "1 compiler for c++ matched.",
  "total_count": 1
}
```

### List languages

List the programming languages Compiler Explorer supports, with each one's ID, file extensions, default compiler, formatter, and whether its programs can be run.

**Inputs**: None.

**Outputs**

- `count` (number): How many are listed
- `languages` (list): The languages, by name
- `summary` (text): One line saying what came back

**Example output**

```json
{
  "count": 1,
  "languages": [
    {
      "can_run_programs": true,
      "default_compiler": "g162",
      "example": "int square(int num) {\n    return num * num;\n}",
      "extensions": [
        ".cpp",
        ".cxx",
        ".h",
        ".hpp",
        ".cc"
      ],
      "formatter": "clangformat",
      "id": "c++",
      "name": "C++"
    }
  ],
  "summary": "Compiler Explorer supports 1 language."
}
```

### List libraries

List the libraries code in a language can include on Compiler Explorer, such as {fmt} or Boost for C++, with their versions.

**Inputs**

- Language (`language`, text, required): The programming language.
- Name contains (`name_contains`, text): Only libraries whose name, ID or description contains this.

**Outputs**

- `count` (number): How many are listed
- `libraries` (list): The libraries
- `summary` (text): One line saying what came back

**Example output**

```json
{
  "count": 1,
  "libraries": [
    {
      "description": "A modern formatting library",
      "id": "fmt",
      "latest_value": "fmt@1200",
      "latest_version": "12.0.0",
      "name": "{fmt}",
      "url": "https://fmt.dev/",
      "versions": [
        {
          "id": "1100",
          "version": "11.0.0"
        },
        {
          "id": "1200",
          "version": "12.0.0"
        },
        {
          "id": "trunk",
          "version": "trunk"
        }
      ]
    }
  ],
  "summary": "1 library for c++."
}
```

### List tools

List the analysis tools that can run over a language's code, such as clang-tidy, llvm-mca, pahole or readelf for C++, and whether each reads input.

**Inputs**

- Language (`language`, text, required): The programming language.

**Outputs**

- `count` (number): How many are listed
- `summary` (text): One line saying what came back
- `tools` (list): The tools

**Example output**

```json
{
  "count": 1,
  "summary": "1 tool for c++.",
  "tools": [
    {
      "accepts_input": false,
      "id": "clangtidytrunk",
      "name": "clang-tidy (trunk)",
      "type": "independent"
    }
  ]
}
```

### Run analysis tool

Compile code and run one analysis tool over it, such as clang-tidy to find likely bugs, llvm-mca to estimate cycles or include-what-you-use to tidy includes. Returns the tool's output and the messages it tied to lines of the code.

**Inputs**

- Language (`language`, text, required): The programming language of the code.
- Compiler (`compiler`, text, required): The compiler to use, such as x86-64 gcc 16.2. Choose the language first to list its compilers.
- Tool (`tool`, text, required): The tool to run, such as clang-tidy, llvm-mca or include-what-you-use. Choose the language first to list them.
- Code (`source`, text, required): The code, as you would paste it into Compiler Explorer.
- Tool arguments (`tool_arguments`, text): Arguments for the tool. clang-tidy needs checks to run, such as -checks=bugprone-*.
- Tool input (`tool_input`, text): Text for tools that read input, such as a clang-query query. 'List tools' says which accept it.
- Compiler flags (`options`, text): Flags for the compiler, such as -O2 -Wall -std=c++20.
- Libraries (`libraries`, list): Libraries the code includes, such as {fmt} or Boost. Choose the language first to list them.

**Outputs**

- `build` (object): How the build went
- `compiler` (text): The compiler ID used
- `diagnostics` (list): Each error, warning and note, with its line
- `errors` (text): What the tool printed to standard error
- `exit_code` (number): The tool's exit code
- `language` (text): The language ID used
- `output` (text): What the tool printed to standard output
- `summary` (text): One line saying what came back
- `tool` (text): The tool ID run
- `tool_name` (text): The tool's name

**Example output**

```json
{
  "build": {
    "diagnostics": [],
    "error_count": 0,
    "exit_code": 0,
    "stderr": "",
    "stdout": "",
    "success": true,
    "warning_count": 0
  },
  "compiler": "clang_trunk",
  "diagnostics": [
    {
      "column": 23,
      "line": 1,
      "message": "an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]",
      "severity": "warning"
    }
  ],
  "errors": "1 warning generated.",
  "exit_code": 0,
  "language": "c++",
  "output": "<source>:1:23: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]",
  "summary": "clang-tidy (trunk) exited with code 0 and reported 1 message about the code.",
  "tool": "clangtidytrunk",
  "tool_name": "clang-tidy (trunk)"
}
```
