File: ocloc_api.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (89 lines) | stat: -rw-r--r-- 3,247 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright (C) 2020-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "ocloc_api.h"

#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_interface.h"

#include <iostream>

using namespace Ocloc;

int oclocInvokeWithHelper(
    OclocArgHelper *argHelper,
    unsigned int numArgs, const char *argv[]) {

    std::vector<std::string> args(argv, argv + numArgs);

    try {
        if (numArgs <= 1 || NEO::ConstStringRef("-h") == args[1] || NEO::ConstStringRef("--help") == args[1]) {
            printHelp(*argHelper);
            return OCLOC_SUCCESS;
        }
        auto &command = args[1];
        int retVal = -0;
        if (command == CommandNames::disassemble) {
            retVal = Commands::disassemble(argHelper, args);
        } else if (command == CommandNames::assemble) {
            retVal = Commands::assemble(argHelper, args);
        } else if (command == CommandNames::multi) {
            retVal = Commands::multi(argHelper, args);
        } else if (command == CommandNames::validate) {
            retVal = Commands::validate(argHelper, args);
        } else if (command == CommandNames::query) {
            retVal = Commands::query(argHelper, args);
        } else if (command == CommandNames::ids) {
            retVal = Commands::ids(argHelper, args);
        } else if (command == CommandNames::link) {
            retVal = Commands::link(argHelper, args);
        } else if (command == CommandNames::concat) {
            retVal = Commands::concat(argHelper, args);
        } else {
            retVal = Commands::compile(argHelper, args);
        }

        if (retVal != OCLOC_SUCCESS) {
            printOclocCmdLine(*argHelper, args);
        } else if (argHelper->isVerbose()) {
            printOclocCmdLine(*argHelper, args);
        }
        return retVal;
    } catch (const std::exception &e) {
        argHelper->printf("%s\n", e.what());
        printOclocCmdLine(*argHelper, args);
        return -1;
    }
}

extern "C" {
int oclocInvoke(unsigned int numArgs, const char *argv[],
                const uint32_t numSources, const uint8_t **dataSources, const uint64_t *lenSources, const char **nameSources,
                const uint32_t numInputHeaders, const uint8_t **dataInputHeaders, const uint64_t *lenInputHeaders, const char **nameInputHeaders,
                uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **lenOutputs, char ***nameOutputs) {
    auto argHelper = std::make_unique<OclocArgHelper>(
        numSources, dataSources, lenSources, nameSources,
        numInputHeaders, dataInputHeaders, lenInputHeaders, nameInputHeaders,
        numOutputs, dataOutputs, lenOutputs, nameOutputs);
    return oclocInvokeWithHelper(argHelper.get(), numArgs, argv);
}

int oclocFreeOutput(uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **lenOutputs, char ***nameOutputs) {
    for (uint32_t i = 0; i < *numOutputs; i++) {
        delete[] (*dataOutputs)[i];
        delete[] (*nameOutputs)[i];
    }
    delete[] (*dataOutputs);
    delete[] (*lenOutputs);
    delete[] (*nameOutputs);
    return 0;
}

int oclocVersion() {
    return static_cast<int>(ocloc_version_t::OCLOC_VERSION_CURRENT);
}
}