discord-compiler-bot icon indicating copy to clipboard operation
discord-compiler-bot copied to clipboard

Enhance C/C++ preprocessor output

Open jeremy-rifkin opened this issue 3 years ago • 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 avatar Mar 02 '22 18:03 jeremy-rifkin

@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
      }
    }
  }
}

Headline avatar Apr 18 '22 00:04 Headline

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
-     }
-   }
  }
}

jeremy-rifkin avatar Apr 20 '22 18:04 jeremy-rifkin