diff options
author | terminaldweller <thabogre@gmail.com> | 2021-05-14 18:14:50 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2021-05-14 18:14:50 +0000 |
commit | 6e528248414e330c9e25e81596ab47b8b8a5b701 (patch) | |
tree | e1aa41a7f3198eeac187e6177ec7d4a33db229d3 /compiler-explorer | |
download | scripts-master.tar.gz scripts-master.zip |
first commitmaster
Diffstat (limited to '')
-rw-r--r-- | compiler-explorer/ceconfig.json | 14 | ||||
-rw-r--r-- | compiler-explorer/index.js | 21 | ||||
-rw-r--r-- | compiler-explorer/main.js | 45 | ||||
-rw-r--r-- | compiler-explorer/package.json | 14 |
4 files changed, 94 insertions, 0 deletions
diff --git a/compiler-explorer/ceconfig.json b/compiler-explorer/ceconfig.json new file mode 100644 index 0000000..386a2cc --- /dev/null +++ b/compiler-explorer/ceconfig.json @@ -0,0 +1,14 @@ +{"userArguments":"-O3", + "filters":{ + "binary":false, + "commentOnly":true, + "demangle":true, + "directives":true, + "execute":false, + "intel":true, + "labels":true, + "lables":true, + "libraryCode":false, + "trim":false + } +} diff --git a/compiler-explorer/index.js b/compiler-explorer/index.js new file mode 100644 index 0000000..fae05b7 --- /dev/null +++ b/compiler-explorer/index.js @@ -0,0 +1,21 @@ + +const fetch = require('node-fetch') +const fs = require("fs") +const util = require("util") +const readFile = util.promisify(fs.readFile) + +async function JSON_POST_req(data,options) { + var dummy = {"source": data.toString(), "options":"{}"} + return await {method:"POST", body:JSON.stringify(dummy), headers:{"Content-Type":"application/json"}} +} + +function compiler_explorer(data, options) { + JSON_POST_req(data, options).then(post_arg=> + fetch("https://godbolt.org/api/compiler/g92/compile?options=-O3", post_arg)).then(res=> + res.text()).then(body=> + console.log(body.split("\n").slice(1,body.split("\n").length).join("\n"))).catch(error=> + console.log(error)) +} + +const config = JSON.parse(fs.readFileSync("./ceconfig.json")) +compiler_explorer(process.argv[2], config) diff --git a/compiler-explorer/main.js b/compiler-explorer/main.js new file mode 100644 index 0000000..1b142c3 --- /dev/null +++ b/compiler-explorer/main.js @@ -0,0 +1,45 @@ + +const fetch = require('node-fetch') +const fs = require("fs") +const util = require("util") +const readFile = util.promisify(fs.readFile) +const path = require("path") +const defaultOpts = { +"userArguments":"-O3", "filters": + {"binary":false, + "commentOnly":true, + "demangle":true, + "directives":true, + "execute":false, + "intel":true, + "labels":true, + "lables":true, + "libraryCode":false, + "trim":false + } +} + +async function read_C_source(path) { + return await readFile(path, "utf-8") +} + +function JSON_POST_req(data, options) { + const config = fs.readFileSync(options, "utf-8") + var dummy = {"source": data, "options": JSON.parse(config)} + /* if no config found, then run default + var dummy = {"source": data, "options": defaultOpts} + */ + return {method:"POST", body:JSON.stringify(dummy), headers:{"Content-Type":"application/json"}} +} + +function compiler_explorer(path, options) { + read_C_source(path).then(data=> + JSON_POST_req(data, options)).then(post_arg=> + fetch("https://godbolt.org/api/compiler/g92/compile", post_arg)).then(res=> + res.text()).then(body=> + console.log(body.split("\n").slice(1,body.split("\n").length).join("\n"))).catch(error=> + console.log(error)) +} + +if (process.argv.length < 3) {console.log("you did not specify enough args. needs two. path to source code and path to options to pass to compiler explorer.")} +else {compiler_explorer(process.argv[2], process.argv[3])} diff --git a/compiler-explorer/package.json b/compiler-explorer/package.json new file mode 100644 index 0000000..1b60c79 --- /dev/null +++ b/compiler-explorer/package.json @@ -0,0 +1,14 @@ +{ + "name": "compiler-explorer", + "version": "1.0.0", + "description": "", + "main": "main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Farzad Sadeghi", + "license": "GPL-3.0-or-later", + "dependencies": { + "node-fetch": ">=2.1.2" + } +} |