import { getCommand } from './command.js';
import { BuildCommandToCompileCModel, BuildCommandToCompileCppModel, BuildCommandToCompileSwiftModel, BuildCommandToFormatAssemblyModel, BuildCommandToFormatCModel, BuildCommandToFormatCodeWithClangModel, BuildCommandToFormatCppModel, BuildCommandToFormatJavaModel, BuildCommandToFormatKotlinModel, BuildCommandToFormatPythonModel, BuildCommandToFormatRubyModel, BuildCommandToFormatRustModel, BuildCommandToFormatSwiftModel, } from './type/index.js';
export function buildCommandToCompileSwift(source) {
    const { input, output, format } = BuildCommandToCompileSwiftModel.parse(source);
    const cmd = getCommand(`swiftc`);
    if (format === 'assembly') {
        cmd.list.push(`-emit-assembly`);
    }
    else if (format === 'llvm-ir') {
        cmd.list.push(`-emit-ir`);
    }
    cmd.list.push(`"${input.file.path}"`, '-o', `"${output.file.path}"`);
    return cmd;
}
// objdump disassembly
export function buildCommandToFormatKotlin(source) {
    const { input } = BuildCommandToFormatKotlinModel.parse(source);
    const cmd = getCommand('ktfmt');
    cmd.list.push(input.file.path);
    return cmd;
}
export function buildCommandToFormatSwift(source) {
    const { input } = BuildCommandToFormatSwiftModel.parse(source);
    const cmd = getCommand('swift-format');
    cmd.list.push(input.file.path);
    return cmd;
}
export function buildCommandToFormatRust(source) {
    const { input } = BuildCommandToFormatRustModel.parse(source);
    const cmd = getCommand('rustfmt');
    cmd.list.push(input.file.path);
    return cmd;
}
export function buildCommandToFormatPython(source) {
    const { input } = BuildCommandToFormatPythonModel.parse(source);
    const cmd = getCommand('black');
    cmd.list.push(input.file.path);
    return cmd;
}
export function buildCommandToFormatRuby(source) {
    const { input } = BuildCommandToFormatRubyModel.parse(source);
    const cmd = getCommand('rubocop');
    cmd.list.push(input.file.path);
    return cmd;
}
export function buildCommandToFormatAssembly(source) {
    const { input } = BuildCommandToFormatAssemblyModel.parse(source);
    const cmd = getCommand('asmfmt');
    cmd.list.push(input.file.path);
    return cmd;
}
export function buildCommandToFormatC(source) {
    const { input } = BuildCommandToFormatCModel.parse(source);
    const cmd = getCommand('clang-format');
    cmd.list.push(input.file.path);
    return cmd;
}
export function buildCommandToFormatCpp(source) {
    const { input } = BuildCommandToFormatCppModel.parse(source);
    const cmd = getCommand('clang-format');
    cmd.list.push(input.file.path);
    return cmd;
}
export function buildCommandToFormatJava(source) {
    const { input } = BuildCommandToFormatJavaModel.parse(source);
    const cmd = getCommand('clang-format');
    cmd.list.push(input.file.path);
    return cmd;
}
// ; ModuleID = 'tmp/c.c'
// source_filename = "tmp/c.c"
// target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
// target triple = "arm64-apple-macosx14.0.0"
// @.str = private unnamed_addr constant [14 x i8] c"Hello, World!\00", align 1
export async function buildCommandToCompileC(source) {
    const { optimizationLevel, fastMath, input, output, format, syntax } = BuildCommandToCompileCModel.parse(source);
    const cmd = getCommand(`clang`);
    cmd.list.push(`-O${optimizationLevel}`);
    if (format === 'llvm-ir') {
        cmd.list.push(`-S`, `-emit-llvm`);
    }
    else if (format === 'assembly') {
        cmd.list.push(`-S`);
    }
    if (syntax && format === 'assembly') {
        cmd.list.push(`-masm`, `${syntax}`);
    }
    if (fastMath) {
        cmd.list.push(`-ffast-math`);
    }
    cmd.list.push(`-o`, `"${output.file.path}"`, `"${input.file.path}"`);
    return cmd;
}
export async function buildCommandToCompileCpp(source) {
    const { optimizationLevel, fastMath, input, output, format, syntax } = BuildCommandToCompileCppModel.parse(source);
    const cmd = getCommand(`clang++`);
    cmd.list.push(`-O${optimizationLevel}`);
    if (format === 'llvm-ir') {
        cmd.list.push(`-S`, `-emit-llvm`);
    }
    else if (format === 'assembly') {
        cmd.list.push(`-S`);
    }
    if (syntax && format === 'assembly') {
        cmd.list.push(`-masm`, `${syntax}`);
    }
    if (fastMath) {
        cmd.list.push(`-ffast-math`);
    }
    cmd.list.push(`-o`, `"${output.file.path}"`, `"${input.file.path}"`);
    return cmd;
}
// rubocop --autocorrect file.rb
export async function buildCommandToDecompileBinary() {
    const cmd = getCommand(`objdump`);
    cmd.list.push(`-S`, 
    // `--x86-asm-syntax=intel`,
    `-M`, `intel`);
    return cmd;
}
// bash format
// shfmt -l -w script.sh
export function buildCommandToFormatCodeWithClang(source) {
    const input = BuildCommandToFormatCodeWithClangModel.parse(source);
    const cmd = getCommand(`clang-format`);
    cmd.list.push(`--style="${input.style}"`, `"${input.input.file.path}"`);
}
//# sourceMappingURL=code.js.map