Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline-Mode Feature #3

Open
TekuConcept opened this issue Mar 14, 2020 · 0 comments
Open

Offline-Mode Feature #3

TekuConcept opened this issue Mar 14, 2020 · 0 comments

Comments

@TekuConcept
Copy link

@TekuConcept TekuConcept commented Mar 14, 2020

Godbolt's Compiler-Explorer provides a great on-the-go convenience for side-by-side comparisons of C/C++ and assembly. However, it requires a network connection to work both in browser and in VSCode. What if you could add an offline mode that doesn't depend solely on the online Compiler-Explorer?

With any GCC or Clang toolchain, the commands are

gcc -S -o- ${filename} ${compileroptions}
clang -S -o- ${filename} ${compileroptions}
g++ and clang++ also work

For MSVC, I believe the command is cl /FAs /o - ${filename} ${compileroptions} but haven't confirmed.

You can use child_proc in place of node-fetch. The code looks something like:

export interface CompilerProperties {
    compiler: string
    flags: string
    includes: string[]
}

async compile(properties: CompilerProperties, file: string, lang: string) : Promise<string> {
    let vspath: string
    if (vscode.workspace.workspaceFolders == undefined) vspath = ''
    else vspath = vscode.workspace.workspaceFolders[0].uri.fsPath

    return new Promise((resolve, _reject) => {
        lang = lang.toUpperCase()
        if (lang !== 'C' && lang !== 'CXX' && lang !== 'C++' && lang !== 'CPP')
            resolve(`unsupported language ${lang}`)
        let command: string = `${properties.compiler} ${properties.flags} -S -o- ${file} `

        for (let i = 0; i < properties.includes.length; i++) {
            let include = properties.includes[i]
            if (include.startsWith('${workspaceFolder}'))
                include = include.replace('${workspaceFolder}', vspath)
            if (include.length === 0) continue
            command = command.concat(`-I${include} `)
        }

        // cp: child_proc
        cp.exec(command, (err:cp.ExecException | null, stdout:string, stderr:string) => {
            if (err) {
                console.log('error: ', err)
                resolve(`Error: ${err}`)
            }
            if (stderr.length > 0) resolve(`Command: ${command}\n\n${stderr}`)
            else resolve(`Command: ${command}\n\n${stdout}`)
        })
    })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.