Headline/discord-compiler-bot

Enhance C/C++ preprocessor output

jeremy-rifkin opened this issue · 2 comments

It'd be great to take advantage of CE's preprocessor tool when -E is used during C/C++ compilation. The preprocessor tool automatically filters out headers, junk line directives which clutter even the most simple of preprocessor results, and can also automatically format the output. Demo: https://godbolt.org/z/bxoj4fzq7.

The API for this is undocumented but a simple request for the preprocessor tool looks like:

{
  source: '...',
  options: [  ],
  backendOptions: {
    producePp: { 'filter-headers': true, 'clang-format': true },
    produceGccDump: {},
    produceCfg: false,
    produceDevice: false
  },
  filters: {
    binary: false,
    execute: false,
    demangle: true,
    intel: true,
    commentOnly: true,
    directives: true,
    labels: true,
    optOutput: false,
    libraryCode: true,
    trim: false
  },
  bypassCache: false,
  tools: [],
  executionParameters: { args: [], stdin: undefined },
  libraries: []
}

Maybe this could be done for both ;compile and ;asm.

@jeremy-rifkin
I went ahead and started an implementation that allows for the filter-headers background option, but the following resulted in the same verbose output. Is something malformed with this request?

{
  "source": "...",
  "compiler": "g112",
  "options": {
    "userArguments": "-E",
    "compilerOptions": {
      "skipAsm": false,
      "executorRequest": false
    },
    "executeParameters": {
      "args": [],
      "stdin": ""
    },
    "filters": {
      "binary": false,
      "commentOnly": true,
      "demangle": true,
      "directives": true,
      "execute": false,
      "intel": true,
      "labels": true,
      "trim": false
    },
    "backendOptions": {
      "producePp": {
        "filter-headers": true
      }
    }
  }
}

My bad, it goes in compilerOptions. This should work

{
  "source": "...",
  "compiler": "g112",
  "options": {
    "userArguments": "-E",
    "compilerOptions": {
      "skipAsm": false,
      "executorRequest": false,
+     "producePp": {
+       "filter-headers": true
+     }
    },
    "executeParameters": {
      "args": [],
      "stdin": ""
    },
    "filters": {
      "binary": false,
      "commentOnly": true,
      "demangle": true,
      "directives": true,
      "execute": false,
      "intel": true,
      "labels": true,
      "trim": false
    },
-   "backendOptions": {
-     "producePp": {
-       "filter-headers": true
-     }
-   }
  }
}