Merge remote-tracking branch 'origin/main' into mg/webpack5

This commit is contained in:
Matt Godbolt
2021-12-20 19:48:06 -06:00
19 changed files with 268 additions and 115 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
name: Compiler Explorer
on: [ push ]
on: [push, pull_request]
jobs:
build-and-test:
+1
View File
@@ -39,6 +39,7 @@ There are a number of videos that showcase some features of Compiler Explorer:
* [Presentation for CppCon 2019 about the project](https://www.youtube.com/watch?v=kIoZDUd5DKw)
* [Older 2 part series of videos](https://www.youtube.com/watch?v=4_HL3PH4wDg) which go into a bit more detail
into the more obscure features.
* [Just Enough Assembly for Compiler Explorer](https://youtu.be/QLolzolunJ4): Practical introduction to Assembly with a focus on usage on Compiler Explorer, from CppCon 2021.
* [Playlist: Compiler Explorer](https://www.youtube.com/playlist?list=PL2HVqYf7If8dNYVN6ayjB06FPyhHCcnhG): A collection of videos discussing Compiler Explorer; using it, installing it, what it's for, etc.
A [Road map](docs/Roadmap.md) is available which gives a little insight into
-1
View File
@@ -1867,7 +1867,6 @@ libs.mp-coro.name=mp-coro
libs.mp-coro.versions=trunk
libs.mp-coro.url=https://github.com/mpusz/mp-coro
libs.mp-coro.description=A C++20 coroutine support library
libs.mp-coro.examples=rYqW65rxr
libs.mp-coro.versions.trunk.version=trunk
libs.mp-coro.versions.trunk.path=/opt/compiler-explorer/libs/mp-coro/trunk/src/include
+66 -1
View File
@@ -515,7 +515,7 @@ compiler.cicx202112.options=--gcc-toolchain=/opt/compiler-explorer/gcc-10.1.0
###############################
# Cross GCC
group.ccross.compilers=&cppc:&cmips:&cmsp:&cgccarm:&cavr:&rvcgcc:&cplatspec:&ckalray
group.ccross.compilers=&cppc:&cmips:&cmsp:&cgccarm:&cavr:&rvcgcc:&cxtensaesp32:&cxtensaesp32s2:&cxtensaesp32s3:&cplatspec:&ckalray
group.ccross.supportsBinary=false
group.ccross.groupName=Cross GCC
@@ -848,6 +848,71 @@ compiler.rv32-cgcc1020.semver=10.2.0
compiler.rv32-cgcc1020.objdumper=/opt/compiler-explorer/riscv32/gcc-10.2.0/riscv32-unknown-elf/bin/riscv32-unknown-elf-objdump
compiler.rv32-cgcc1020.supportsBinary=true
################################
# GCC for Xtensa ESP32
group.cxtensaesp32.compilers=cesp32g2019r2:cesp32g2020r1:cesp32g2020r2:cesp32g2020r3:cesp32g2021r1:cesp32g2021r2
group.cxtensaesp32.groupName=Xtensa ESP32 GCC
group.cxtensaesp32.supportsBinary=false
compiler.cesp32g2019r2.exe=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_2_0-esp-2019r2/bin/xtensa-esp32-elf-gcc
compiler.cesp32g2019r2.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_2_0-esp-2019r2/bin/xtensa-esp32-elf-objdump
compiler.cesp32g2019r2.name=Xtensa ESP32 gcc 8.2.0 (2019r2)
compiler.cesp32g2020r1.exe=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_2_0-esp-2020r1/bin/xtensa-esp32-elf-gcc
compiler.cesp32g2020r1.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_2_0-esp-2020r1/bin/xtensa-esp32-elf-objdump
compiler.cesp32g2020r1.name=Xtensa ESP32 gcc 8.2.0 (2020r1)
compiler.cesp32g2020r2.exe=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_2_0-esp-2020r2/bin/xtensa-esp32-elf-gcc
compiler.cesp32g2020r2.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_2_0-esp-2020r2/bin/xtensa-esp32-elf-objdump
compiler.cesp32g2020r2.name=Xtensa ESP32 gcc 8.2.0 (2020r2)
compiler.cesp32g2020r3.exe=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_4_0-esp-2020r3/bin/xtensa-esp32-elf-gcc
compiler.cesp32g2020r3.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_4_0-esp-2020r3/bin/xtensa-esp32-elf-objdump
compiler.cesp32g2020r3.name=Xtensa ESP32 gcc 8.4.0 (2020r3)
compiler.cesp32g2021r1.exe=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_4_0-esp-2021r1/bin/xtensa-esp32-elf-gcc
compiler.cesp32g2021r1.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_4_0-esp-2021r1/bin/xtensa-esp32-elf-objdump
compiler.cesp32g2021r1.name=Xtensa ESP32 gcc 8.4.0 (2021r1)
compiler.cesp32g2021r2.exe=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_4_0-esp-2021r2/bin/xtensa-esp32-elf-gcc
compiler.cesp32g2021r2.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32-elf-gcc8_4_0-esp-2021r2/bin/xtensa-esp32-elf-objdump
compiler.cesp32g2021r2.name=Xtensa ESP32 gcc 8.4.0 (2021r2)
################################
# GCC for Xtensa ESP32-S2
group.cxtensaesp32s2.compilers=cesp32s2g2019r2:cesp32s2g2020r1:cesp32s2g2020r2:cesp32s2g2020r3:cesp32s2g2021r1:cesp32s2g2021r2
group.cxtensaesp32s2.groupName=Xtensa ESP32-S2 GCC
group.cxtensaesp32s2.supportsBinary=false
compiler.cesp32s2g2019r2.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_2_0-esp-2019r2/bin/xtensa-esp32s2-elf-gcc
compiler.cesp32s2g2019r2.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_2_0-esp-2019r2/bin/xtensa-esp32s2-elf-objdump
compiler.cesp32s2g2019r2.name=Xtensa ESP32-S2 gcc 8.2.0 (2019r2)
compiler.cesp32s2g2020r1.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_2_0-esp-2020r1/bin/xtensa-esp32s2-elf-gcc
compiler.cesp32s2g2020r1.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_2_0-esp-2020r1/bin/xtensa-esp32s2-elf-objdump
compiler.cesp32s2g2020r1.name=Xtensa ESP32-S2 gcc 8.2.0 (2020r1)
compiler.cesp32s2g2020r2.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_2_0-esp-2020r2/bin/xtensa-esp32s2-elf-gcc
compiler.cesp32s2g2020r2.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_2_0-esp-2020r2/bin/xtensa-esp32s2-elf-objdump
compiler.cesp32s2g2020r2.name=Xtensa ESP32-S2 gcc 8.2.0 (2020r2)
compiler.cesp32s2g2020r3.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_4_0-esp-2020r3/bin/xtensa-esp32s2-elf-gcc
compiler.cesp32s2g2020r3.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_4_0-esp-2020r3/bin/xtensa-esp32s2-elf-objdump
compiler.cesp32s2g2020r3.name=Xtensa ESP32-S2 gcc 8.4.0 (2020r3)
compiler.cesp32s2g2021r1.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r1/bin/xtensa-esp32s2-elf-gcc
compiler.cesp32s2g2021r1.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r1/bin/xtensa-esp32s2-elf-objdump
compiler.cesp32s2g2021r1.name=Xtensa ESP32-S2 gcc 8.4.0 (2021r1)
compiler.cesp32s2g2021r2.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2/bin/xtensa-esp32s2-elf-gcc
compiler.cesp32s2g2021r2.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r2/bin/xtensa-esp32s2-elf-objdump
compiler.cesp32s2g2021r2.name=Xtensa ESP32-S2 gcc 8.4.0 (2021r2)
################################
# GCC for Xtensa ESP32-S3
group.cxtensaesp32s3.compilers=cesp32s3g2020r3:cesp32s3g2021r1:cesp32s3g2021r2
group.cxtensaesp32s3.groupName=Xtensa ESP32-S3 GCC
group.cxtensaesp32s3.supportsBinary=false
compiler.cesp32s3g2020r3.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s3-elf-gcc8_4_0-esp-2020r3/bin/xtensa-esp32s3-elf-gcc
compiler.cesp32s3g2020r3.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s3-elf-gcc8_4_0-esp-2020r3/bin/xtensa-esp32s3-elf-objdump
compiler.cesp32s3g2020r3.name=Xtensa ESP32-S3 gcc 8.4.0 (2020r3)
compiler.cesp32s3g2021r1.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r1/bin/xtensa-esp32s3-elf-gcc
compiler.cesp32s3g2021r1.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r1/bin/xtensa-esp32s3-elf-objdump
compiler.cesp32s3g2021r1.name=Xtensa ESP32-S3 gcc 8.4.0 (2021r1)
compiler.cesp32s3g2021r2.exe=/opt/compiler-explorer/xtensa/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2/bin/xtensa-esp32s3-elf-gcc
compiler.cesp32s3g2021r2.objdumper=/opt/compiler-explorer/xtensa/xtensa-esp32s3-elf-gcc8_4_0-esp-2021r2/bin/xtensa-esp32s3-elf-objdump
compiler.cesp32s3g2021r2.name=Xtensa ESP32-S3 gcc 8.4.0 (2021r2)
###############################
# ARM HPC (disabled)
+6 -2
View File
@@ -3,7 +3,7 @@ compilerType=kotlin
versionFlag=-version
objdumper=/opt/compiler-explorer/jdk-17.0.0/bin/javap
instructionSet=java
defaultCompiler=kotlinc1600
defaultCompiler=kotlinc1610
demangler=
postProcess=
options=
@@ -12,7 +12,7 @@ needsMulti=false
supportsExecute=true
interpreted=true
group.kotlin.compilers=kotlinc1400:kotlinc1410:kotlinc1420:kotlinc1421:kotlinc1430:kotlinc1431:kotlinc1432:kotlinc1500:kotlinc1510:kotlinc1520:kotlinc1521:kotlinc1530:kotlinc1531:kotlinc1600
group.kotlin.compilers=kotlinc1400:kotlinc1410:kotlinc1420:kotlinc1421:kotlinc1430:kotlinc1431:kotlinc1432:kotlinc1500:kotlinc1510:kotlinc1520:kotlinc1521:kotlinc1530:kotlinc1531:kotlinc1600:kotlinc1610
group.kotlin.groupName=Kotlin
group.kotlin.baseName=kotlinc
group.kotlin.isSemVer=true
@@ -72,3 +72,7 @@ compiler.kotlinc1600.exe=/opt/compiler-explorer/kotlin-jvm-1.6.0/bin/kotlinc-jvm
compiler.kotlinc1600.semver=1.6.0
compiler.kotlinc1600.java_home=/opt/compiler-explorer/jdk-16.0.1
compiler.kotlinc1600.runtime=/opt/compiler-explorer/jdk-16.0.1/bin/java
compiler.kotlinc1610.exe=/opt/compiler-explorer/kotlin-jvm-1.6.10/bin/kotlinc-jvm
compiler.kotlinc1610.semver=1.6.10
compiler.kotlinc1610.java_home=/opt/compiler-explorer/jdk-16.0.1
compiler.kotlinc1610.runtime=/opt/compiler-explorer/jdk-16.0.1/bin/java
+65 -23
View File
@@ -789,10 +789,6 @@ export class BaseCompiler {
return inputFilename.replace(path.extname(inputFilename), '.ll');
}
getGnatDebugOutputFilename(inputFilename) {
return inputFilename + '.dg';
}
getOutputFilename(dirPath, outputFilebase, key) {
let filename;
if (key && key.backendOptions && key.backendOptions.customOutputFilename) {
@@ -812,30 +808,45 @@ export class BaseCompiler {
return this.getOutputFilename(dirPath, outputFilebase, key);
}
async processGnatDebugOutput(inputFilename, output) {
const gnatDebugPath = this.getGnatDebugOutputFilename(inputFilename);
async processGnatDebugOutput(inputFilename, result) {
const content = [];
const keep_stdout = [];
// Everything before this stays in stdout.
// Everything after is considered expanded code and is moved to the
// corresponding pane.
const startOfExpandedCode = /^Source recreated/;
let isInExpandedCode = false;
for (const obj of Object.values(result.stdout)) {
if (!isInExpandedCode && startOfExpandedCode.test(obj.text)) {
isInExpandedCode = true;
}
if (isInExpandedCode)
content.push(obj);
else
keep_stdout.push(obj);
}
// Do not check compiler result before looking for expanded code. The
// compiler may exit with an error after the emission. This file is also
// compiler may exit with an error after the emission. This dump is also
// very usefull to debug error message.
if (await fs.exists(gnatDebugPath)) {
const content = await fs.readFile(gnatDebugPath, 'utf-8');
return content.split('\n').map((line) => ({
text: line,
}));
} else {
// check for possible cause for missing file
if (output.code !== 0) {
if (content.length === 0)
if (result.code !== 0) {
return [{text: 'GNAT exited with an error and did not create the expanded code'}];
} else {
return [{text: 'GNAT exited successfully but the expanded code is missing, something is wrong'}];
}
}
result.stdout = keep_stdout;
return content;
}
/**
* @returns {{filename_suffix: string, name: string, command_prefix: string}}
* `filename_suffix`: dump file name suffix if GCC default dump names is used
* `filename_suffix`: dump file name suffix if GCC default dump name is used
*
* `name`: the name to be displayed in the UI
*
@@ -1735,24 +1746,55 @@ export class BaseCompiler {
currentPassOutput: '<No pass selected>',
syntaxHighlight: false,
};
const treeDumpsNotInPasses = [];
const selectedPasses = [];
if (opts.treeDump) selectedPasses.push('tree');
if (opts.treeDump) {
selectedPasses.push('tree');
// Fake 2 lines as coming from -fdump-passes
// This allows the insertion of 'gimple' and 'original'
// tree dumps that are not really part of a tree pass.
treeDumpsNotInPasses.push (
[ { text: 'tree-original: ON'},
{
filename_suffix: 't.original',
name: 'original (tree)',
command_prefix: '-fdump-tree-original',
},
],
[ { text: 'tree-gimple: ON'},
{
filename_suffix: 't.gimple',
name: 'gimple (tree)',
command_prefix: '-fdump-tree-gimple',
},
]);
}
if (opts.ipaDump) selectedPasses.push('ipa');
if (opts.rtlDump) selectedPasses.push('rtl');
// Defaults to a custom file derived from output file name. Works when
// using the -fdump-tree-foo=FILE variant (!removeEmptyPasses).
// Will be overriden later if not.
let dumpFileName = this.getGccDumpFileName(outputFilename);
let passFound = false;
const filtered_stderr = [];
const toRemoveFromStderr = /^\s*((ipa|tree|rtl)-)|(\*)([\w-]+).*(ON|OFF)$/;
for (const obj of Object.values(result.stderr)) {
const selectizeObject = this.fromInternalGccDumpName(obj.text, selectedPasses);
if (selectizeObject){
const dumpPassesLines = treeDumpsNotInPasses.concat(
Object.values(result.stderr).map(
x => [x, this.fromInternalGccDumpName(x.text, selectedPasses)]));
for (const [obj, selectizeObject] of dumpPassesLines) {
if (selectizeObject) {
if (opts.pass && opts.pass.name === selectizeObject.name)
passFound = true;
if (removeEmptyPasses){
if (removeEmptyPasses) {
const f = fs.readdirSync(rootDir).filter(fn => fn.endsWith(selectizeObject.filename_suffix));
// pass is enabled, but the dump hasn't produced anything:
@@ -1767,7 +1809,7 @@ export class BaseCompiler {
output.all.push(selectizeObject);
}
if (!toRemoveFromStderr.test(obj.text)){
if (!toRemoveFromStderr.test(obj.text)) {
filtered_stderr.push(obj);
}
}
+2 -1
View File
@@ -51,7 +51,8 @@ export class AdaCompiler extends BaseCompiler {
const opts = super.optionsForBackend (backendOptions, outputFilename);
if (backendOptions.produceGnatDebug && this.compiler.supportsGnatDebugView)
opts.push('-gnatDGL');
// This is using stdout
opts.push('-gnatGL');
return opts;
}
@@ -46,9 +46,10 @@ export const setup = (router) => router.get('/asm/:arch/:opcode', (req, res) =>
if (MAX_STATIC_AGE > 0) {
res.setHeader('Cache-Control', `public, max-age=${MAX_STATIC_AGE}`);
}
const handler = ASSEMBLY_DOCUMENTATION_HANDLERS[req.params.arch];
const architecture = req.params.arch;
const handler = ASSEMBLY_DOCUMENTATION_HANDLERS[architecture];
if (handler !== undefined) {
return handler.handle(req, res);
}
res.status(404).send({ error: 'Unknown architecture '});
res.status(404).json({ error: `No documentation for '${architecture}'` }).send();
});
@@ -57,7 +57,7 @@ export class BaseAssemblyDocumentationHandler {
const instruction = (request.params.opcode || '__UNKNOWN_OPCODE').toUpperCase();
const information = this.getInstructionInformation(instruction);
if (information === null) {
return response.status(404).send({ error: 'Unknown opcode' });
return response.status(404).send({ error: `Unknown opcode '${instruction}'` });
}
// Accept either JSON or Plaintext Content-Type
const requestedContentType = request.accepts(['text', 'json']);
+10 -10
View File
@@ -9135,9 +9135,9 @@
"dev": true
},
"moment": {
"version": "2.29.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
"version": "2.24.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
},
"monaco-editor": {
"version": "0.27.0",
@@ -11014,11 +11014,11 @@
"dev": true
},
"propagating-hammerjs": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/propagating-hammerjs/-/propagating-hammerjs-1.5.0.tgz",
"integrity": "sha512-3PUXWmomwutoZfydC+lJwK1bKCh6sK6jZGB31RUX6+4EXzsbkDZrK4/sVR7gBrvJaEIwpTVyxQUAd29FKkmVdw==",
"version": "1.4.6",
"resolved": "https://registry.npmjs.org/propagating-hammerjs/-/propagating-hammerjs-1.4.6.tgz",
"integrity": "sha1-/tAOmwB2f/1C0U9bUxvEk+tnLjc=",
"requires": {
"hammerjs": "^2.0.8"
"hammerjs": "^2.0.6"
}
},
"protobufjs": {
@@ -13391,9 +13391,9 @@
}
},
"vis": {
"version": "4.21.0-EOL",
"resolved": "https://registry.npmjs.org/vis/-/vis-4.21.0-EOL.tgz",
"integrity": "sha512-JVS1mywKg5S88XbkDJPfCb3n+vlg5fMA8Ae2hzs3KHAwD4ryM5qwlbFZ6ReDfY8te7I4NLCpuCoywJQEehvJlQ==",
"version": "4.20.1",
"resolved": "https://registry.npmjs.org/vis/-/vis-4.20.1.tgz",
"integrity": "sha1-Z+ku2v5y2mOxXJMCmRr57fL4Zhk=",
"requires": {
"emitter-component": "^1.1.1",
"hammerjs": "^2.0.8",
+1 -1
View File
@@ -75,7 +75,7 @@
"tslib": "^2.3.1",
"underscore": "^1.13.1",
"url-join": "^4.0.1",
"vis": "^4.21.0-EOL",
"vis": "4.20.1",
"whatwg-fetch": "^3.6.2",
"which": "^2.0.2",
"winston": "^3.3.3",
+25 -9
View File
@@ -22,25 +22,41 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import _ from 'underscore';
import { AssemblyDocumentationResponse, AssemblyDocumentationRequest } from './assemblydocumentation.interfaces';
import { FormattingRequest, FormattingResponse } from './formatting.interfaces';
/** Type wrapper allowing .json() to resolve to a concrete type */
type TypedResponse<R> = Response & {
json(): Promise<R>
interface TypedResponse<T> extends Response {
json(): Promise<T>;
}
/** Lightweight fetch() wrapper for CE API urls */
const request = async <R>(uri: string, options?: RequestInit): Promise<TypedResponse<R>> => fetch(
`${window.location.origin}${window.httpRoot}api${uri}`,
{
...options,
headers: {
...options?.headers,
'Accept': 'application/json',
}
...options,
credentials: 'include',
headers: {
...options?.headers,
'Accept': 'application/json',
},
},
);
/** GET /api/asm/:arch/:instruction */
export const getAssemblyDocumentation = async (
options: AssemblyDocumentationRequest
) => request<AssemblyDocumentationResponse>(`/asm/${options.instructionSet}/${options.opcode}`);
options: AssemblyDocumentationRequest,
) => await request<AssemblyDocumentationResponse>(`/asm/${options.instructionSet}/${options.opcode}`);
/** POST /api/format/:formatter */
export const getFormattedCode = async (
options: FormattingRequest,
) => await request<FormattingResponse>(`/format/${options.formatterId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(_.pick(options, 'source', 'base', 'tabWidth', 'useSpaces')),
});
@@ -22,9 +22,9 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import { FormatBase } from './settings.interfaces';
import { FormatBase } from '../settings.interfaces';
export interface FormatRequestOptions {
export interface FormattingRequest {
source: string;
formatterId: string;
/**
@@ -37,8 +37,8 @@ export interface FormatRequestOptions {
useSpaces: boolean;
}
export interface FormatResponse {
export interface FormattingResponse {
answer: string;
exit: number;
throw?: true;
}
}
+6 -13
View File
@@ -26,8 +26,9 @@ import * as monaco from 'monaco-editor';
import { Alert } from './alert';
import { getStoredSettings } from './settings';
import { FormatRequestOptions, FormatResponse } from './formatter-registry.interfaces';
import { SiteSettings } from './settings.interfaces';
import { FormattingRequest } from './api/formatting.interfaces';
import { getFormattedCode } from './api/api';
// Proxy function to emit the error to the alert system
const onFormatError = (cause: string, source: string) => {
@@ -39,17 +40,9 @@ const onFormatError = (cause: string, source: string) => {
return source;
};
const getFormattedCode = async ({ source, formatterId, base, tabWidth, useSpaces }: FormatRequestOptions) => {
const res = await fetch(`${window.location.origin}${window.httpRoot}api/format/${formatterId}`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({ source, base, tabWidth, useSpaces }),
});
const body = await res.json() as FormatResponse;
const doFormatRequest = async (options: FormattingRequest) => {
const res = await getFormattedCode(options);
const body = await res.json();
if (res.status === 200 && body.exit === 0) {
// API sent 200 and we have a valid response
return body.answer;
@@ -84,7 +77,7 @@ const getDocumentFormatter = (
const source = model.getValue();
// Request the formatted code. If that API call fails, we just back off
// and return the user's old code.
const formattedSource = await getFormattedCode({
const formattedSource = await doFormatRequest({
formatterId: formatter,
tabWidth: settings.tabWidth,
useSpaces: settings.useSpaces,
-12
View File
@@ -166,18 +166,6 @@ describe('API handling', () => {
throw err;
});
});
it('should respond to ASM doc requests', () => {
return chai.request(app)
.get('/api/asm/MOV')
.set('Accept', 'application/json')
.then(res => {
res.should.have.status(200);
res.should.be.json;
})
.catch(err => {
throw err;
});
});
it('should respond to JSON compilers requests with c++ filter', () => {
return chai.request(app)
.get('/api/compilers/c++')
@@ -40,7 +40,7 @@ describe('amd64 assembly documentation', () => {
.then(res => {
res.should.have.status(404);
res.should.be.json;
res.body.should.deep.equal({ error: 'Unknown opcode' });
res.body.should.deep.equal({ error: 'Unknown opcode \'MOV_OH_WAIT\'' });
}).catch(e => { throw e; });
});
@@ -65,16 +65,6 @@ describe('amd64 assembly documentation', () => {
}).catch(e => { throw e; });
});
it('should respond to json for unknown opcodes', () => {
return chai.request(app)
.get('/asm/NOANOPCODE')
.set('Accept', 'application/json')
.then(res => {
res.should.have.status(404);
res.should.be.json;
}).catch(e => { throw e; });
});
it('should return 406 on bad accept type', () => {
return chai.request(app).get('/asm/mov')
.set('Accept', 'application/pdf')
@@ -0,0 +1,73 @@
// Copyright (c) 2021, Compiler Explorer Authors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import express, { Router } from 'express';
import { setup } from '../../../lib/handlers/assembly-documentation/router';
import { chai } from '../../utils';
describe('Assembly Documentation API', () => {
let app;
before(() => {
app = express();
/** @type {e.Router} */
const router = Router();
setup(router);
app.use('/api', router);
});
it('should accept requests to the api', () => {
return chai.request(app)
.get('/api/asm/amd64/mov')
.set('Accept', 'application/json')
.then(res => {
res.should.have.status(200);
res.should.be.json;
})
.catch(err => {
throw err;
});
});
it('should return opcode not found', () => {
return chai.request(app).get('/api/asm/amd64/notexistingop')
.set('Accept', 'application/json')
.then((res) => {
res.should.have.status(404);
res.should.be.json;
res.body.should.deep.equals({ error: `Unknown opcode 'NOTEXISTINGOP'` });
}).catch(e => { throw e; });
});
it('should return architecture not found', () => {
return chai.request(app).get('/api/asm/notarch/mov')
.set('Accept', 'application/json')
.then((res) => {
res.should.have.status(404);
res.should.be.json;
res.body.should.deep.equals({ error: `No documentation for 'notarch'` });
}).catch(e => { throw e; });
});
});
@@ -40,7 +40,7 @@ describe('arm32 assembly documentation', () => {
.then(res => {
res.should.have.status(404);
res.should.be.json;
res.body.should.deep.equal({ error: 'Unknown opcode' });
res.body.should.deep.equal({ error: 'Unknown opcode \'MOV_OH_WAIT\'' });
}).catch(e => { throw e; });
});
@@ -65,16 +65,6 @@ describe('arm32 assembly documentation', () => {
}).catch(e => { throw e; });
});
it('should respond to json for unknown opcodes', () => {
return chai.request(app)
.get('/asm/NOANOPCODE')
.set('Accept', 'application/json')
.then(res => {
res.should.have.status(404);
res.should.be.json;
}).catch(e => { throw e; });
});
it('should return 406 on bad accept type', () => {
return chai.request(app).get('/asm/mov')
.set('Accept', 'application/pdf')
@@ -109,7 +99,7 @@ describe('arm32 assembly documentation', () => {
.then(res => {
res.should.have.status(404);
res.should.be.json;
res.body.should.deep.equal({ error: 'Unknown opcode' });
res.body.should.deep.equal({ error: 'Unknown opcode \'JNE\'' });
}).catch(e => { throw e; });
});
});
@@ -40,7 +40,7 @@ describe('jvm assembly documentation', () => {
.then(res => {
res.should.have.status(404);
res.should.be.json;
res.body.should.deep.equal({ error: 'Unknown opcode' });
res.body.should.deep.equal({ error: 'Unknown opcode \'MOV_OH_WAIT\'' });
}).catch(e => { throw e; });
});
@@ -65,16 +65,6 @@ describe('jvm assembly documentation', () => {
}).catch(e => { throw e; });
});
it('should respond to json for unknown opcodes', () => {
return chai.request(app)
.get('/asm/NOANOPCODE')
.set('Accept', 'application/json')
.then(res => {
res.should.have.status(404);
res.should.be.json;
}).catch(e => { throw e; });
});
it('should return 406 on bad accept type', () => {
return chai.request(app).get('/asm/iload_0')
.set('Accept', 'application/pdf')