compiler-explorer-directives v3.3.0
compiler-explorer-directives
Interact with Compiler Explorer links using inline code directives.
Base'd on Matt Godbolt's code which can be found at here.
Example
const {parseCode, displayURL} = require('compiler-explorer-directives');
const info = parseCode(`
///compiler=g83
///options+=-O0
#include <iostream>
int main() {
std::cout << "Hello CE!";
}`, cpp);
const url = displayURL(info);
API
parseCode
parseCode(code, language, config)
Parses code according to directives and generates an info object which can then be passed to displayUrl
and compile
.
language
should be one of CE's support languages.
config
is optional, and should be an object with fields listed under Configuration.
displayUrl
displayUrl(info)
Generates a URL which opens CE with the code parsed by parseCode
.
compile
compile(info)
Calls CE's Rest API to compile the code parsed by parseCode
.
Returns output from compiling and running the code (if enabled) on success, otherwise throws CompileError
with code
being the exit code and message
being the compiler's error message.
Directives
Use ///
directives to configure a specific code snippet. Every line starting with ///
, which is not mapped to one of the supported directives, is ignored.
///compiler=<compiler>
Override default compiler.
///options=<options>
Override default options.
///options+=<options>
Add to default options.
///libs=<lib:version>[,lib:version...]
Use libraries in snippet.
///execute
Run the compiled output.
///noexecute
Disable execution in case runMain
is set, this snippet contains a main
function but execution is not wanted.
///external
Always open on godbolt.com
even if useLocal
is set.
Configuration
To configure the plugin pass a compilerExplorer
object to Reveal.initialize
with any of the following options:
compiler
Compiler to use when there's no compiler
directive. Defaults to g102
.
options
Compiler options to pass when there's no options
directive. Defaults to -O2 -march=haswell -Wall -Wextra -pedantic -Wno-unused-variable -Wno-unused-parameter
.
runMain
Whether to always run code with main
functions. Defaults to false
.
useLocal
Whether to use a local running instance of Compiler Explorer (might speed up processing).
localPort
Port of local running Compiler Explorer, in case useLocal
is true
. Defaults to 10240
.
directives
User defined directives. Needs to be an array of [regex, action]
pairs where action
is a function accepting matches
and info
with the regex
's matches and current info instance, respectively.
12 days ago
18 days ago
1 year ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago