2018-08-20 12:55:55 +02:00
|
|
|
/*
|
2022-04-01 16:37:48 +00:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2018-08-20 12:55:55 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-27 16:17:08 +01:00
|
|
|
#include "shared/offline_compiler/source/decoder/helper.h"
|
|
|
|
|
#include "shared/offline_compiler/source/decoder/iga_wrapper.h"
|
|
|
|
|
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
|
2019-03-26 15:11:49 +01:00
|
|
|
|
2018-08-20 12:55:55 +02:00
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
struct PTField {
|
2019-07-05 14:47:53 +02:00
|
|
|
uint8_t size = 0U;
|
2018-08-20 12:55:55 +02:00
|
|
|
std::string name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct BinaryHeader {
|
2019-06-26 21:19:34 +02:00
|
|
|
std::vector<PTField> fields;
|
2019-07-05 14:47:53 +02:00
|
|
|
uint32_t size = 0U;
|
2018-08-20 12:55:55 +02:00
|
|
|
};
|
|
|
|
|
struct PatchToken : BinaryHeader {
|
|
|
|
|
std::string name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using PTMap = std::unordered_map<uint8_t, std::unique_ptr<PatchToken>>;
|
|
|
|
|
|
|
|
|
|
class BinaryDecoder {
|
|
|
|
|
public:
|
|
|
|
|
BinaryDecoder(const std::string &file, const std::string &patch, const std::string &dump)
|
|
|
|
|
: binaryFile(file), pathToPatch(patch), pathToDump(dump){};
|
2022-04-01 16:37:48 +00:00
|
|
|
|
2020-03-10 14:02:09 +01:00
|
|
|
BinaryDecoder(OclocArgHelper *helper) : argHelper(helper), iga(new IgaWrapper) {
|
2020-03-05 11:49:46 +01:00
|
|
|
iga->setMessagePrinter(argHelper->getPrinterRef());
|
2022-04-01 16:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOCKABLE_VIRTUAL ~BinaryDecoder() = default;
|
|
|
|
|
|
2018-08-20 12:55:55 +02:00
|
|
|
int decode();
|
2020-02-07 14:06:50 +01:00
|
|
|
int validateInput(const std::vector<std::string> &args);
|
2019-03-26 15:11:49 +01:00
|
|
|
|
2021-08-06 14:44:04 +00:00
|
|
|
bool showHelp = false;
|
|
|
|
|
void printHelp();
|
|
|
|
|
|
2018-08-20 12:55:55 +02:00
|
|
|
protected:
|
2020-03-10 14:02:09 +01:00
|
|
|
OclocArgHelper *argHelper = nullptr;
|
2020-01-23 15:00:33 +01:00
|
|
|
bool ignoreIsaPadding = false;
|
2018-08-20 12:55:55 +02:00
|
|
|
BinaryHeader programHeader, kernelHeader;
|
2020-01-25 19:18:48 +01:00
|
|
|
std::vector<char> binary;
|
2019-06-26 21:19:34 +02:00
|
|
|
std::unique_ptr<IgaWrapper> iga;
|
2018-08-20 12:55:55 +02:00
|
|
|
PTMap patchTokens;
|
|
|
|
|
std::string binaryFile, pathToPatch, pathToDump;
|
2019-03-26 15:11:49 +01:00
|
|
|
|
2020-01-25 19:18:48 +01:00
|
|
|
void dumpField(const void *&binaryPtr, const PTField &field, std::ostream &ptmFile);
|
2018-08-20 12:55:55 +02:00
|
|
|
uint8_t getSize(const std::string &typeStr);
|
2020-01-25 19:18:48 +01:00
|
|
|
const void *getDevBinary();
|
2020-02-07 14:06:50 +01:00
|
|
|
std::vector<std::string> loadPatchList();
|
2018-08-20 12:55:55 +02:00
|
|
|
void parseTokens();
|
2020-01-25 19:18:48 +01:00
|
|
|
int processBinary(const void *&ptr, std::ostream &ptmFile);
|
|
|
|
|
void processKernel(const void *&ptr, std::ostream &ptmFile);
|
|
|
|
|
void readPatchTokens(const void *&patchListPtr, uint32_t patchListSize, std::ostream &ptmFile);
|
2018-08-20 12:55:55 +02:00
|
|
|
uint32_t readStructFields(const std::vector<std::string> &patchList,
|
|
|
|
|
const size_t &structPos, std::vector<PTField> &fields);
|
|
|
|
|
};
|