3.3.0 • Published 12 days ago

compiler-explorer-directives v3.3.0

Weekly downloads
56
License
MIT
Repository
github
Last release
12 days ago

compiler-explorer-directives

npm version npm publish

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.

3.3.0

12 days ago

3.2.1

18 days ago

3.1.0

1 year ago

3.0.0

2 years ago

2.0.0

2 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.4

3 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago