2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "offline_compiler/offline_compiler.h"
|
2018-06-22 23:38:00 +08:00
|
|
|
#include "offline_compiler/utilities/safety_caller.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/os_library.h"
|
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "decoder/binary_decoder.h"
|
|
|
|
#include "decoder/binary_encoder.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <CL/cl.h>
|
|
|
|
|
|
|
|
using namespace OCLRT;
|
|
|
|
|
|
|
|
int main(int numArgs, const char *argv[]) {
|
2018-08-20 18:55:55 +08:00
|
|
|
try {
|
2018-10-25 22:30:10 +08:00
|
|
|
if (numArgs > 1 && !strcmp(argv[1], "disasm")) { // -file binary.bin -patch workspace/igc/inc -dump dump/folder
|
2018-08-20 18:55:55 +08:00
|
|
|
BinaryDecoder disasm;
|
|
|
|
int retVal = disasm.validateInput(numArgs, argv);
|
|
|
|
if (retVal == 0) {
|
|
|
|
return disasm.decode();
|
|
|
|
} else {
|
|
|
|
return retVal;
|
|
|
|
}
|
2018-10-25 22:30:10 +08:00
|
|
|
} else if (numArgs > 1 && !strcmp(argv[1], "asm")) { // -dump dump/folder -out new_elf.bin
|
2018-08-20 18:55:55 +08:00
|
|
|
BinaryEncoder assembler;
|
|
|
|
int retVal = assembler.validateInput(numArgs, argv);
|
|
|
|
if (retVal == 0) {
|
|
|
|
return assembler.encode();
|
|
|
|
} else {
|
|
|
|
return retVal;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
} else {
|
2018-08-20 18:55:55 +08:00
|
|
|
int retVal = CL_SUCCESS;
|
|
|
|
OfflineCompiler *pCompiler = OfflineCompiler::create(numArgs, argv, retVal);
|
|
|
|
|
|
|
|
if (retVal == CL_SUCCESS) {
|
|
|
|
retVal = buildWithSafetyGuard(pCompiler);
|
|
|
|
|
|
|
|
std::string buildLog = pCompiler->getBuildLog();
|
|
|
|
if (buildLog.empty() == false) {
|
|
|
|
printf("%s\n", buildLog.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retVal == CL_SUCCESS) {
|
|
|
|
if (!pCompiler->isQuiet())
|
|
|
|
printf("Build succeeded.\n");
|
|
|
|
} else {
|
|
|
|
printf("Build failed with error code: %d\n", retVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete pCompiler;
|
|
|
|
return retVal;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-08-20 18:55:55 +08:00
|
|
|
} catch (const std::exception &e) {
|
|
|
|
printf("%s\n", e.what());
|
|
|
|
return -1;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|