2018-08-20 18:55:55 +08:00
|
|
|
/*
|
2020-01-23 22:00:33 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-08-20 18:55:55 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-01-26 02:18:48 +08:00
|
|
|
#include "offline_compiler/decoder/helper.h"
|
|
|
|
#include "offline_compiler/decoder/iga_wrapper.h"
|
2020-02-07 21:06:50 +08:00
|
|
|
#include "offline_compiler/ocloc_arg_helper.h"
|
2019-03-26 22:11:49 +08:00
|
|
|
|
2018-08-20 18:55:55 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
struct PTField {
|
2019-07-05 20:47:53 +08:00
|
|
|
uint8_t size = 0U;
|
2018-08-20 18:55:55 +08:00
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BinaryHeader {
|
2019-06-27 03:19:34 +08:00
|
|
|
std::vector<PTField> fields;
|
2019-07-05 20:47:53 +08:00
|
|
|
uint32_t size = 0U;
|
2018-08-20 18:55:55 +08:00
|
|
|
};
|
|
|
|
struct PatchToken : BinaryHeader {
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
|
|
|
using PTMap = std::unordered_map<uint8_t, std::unique_ptr<PatchToken>>;
|
|
|
|
|
|
|
|
class BinaryDecoder {
|
|
|
|
public:
|
2019-06-27 03:19:34 +08:00
|
|
|
BinaryDecoder() : iga(new IgaWrapper) {
|
|
|
|
iga->setMessagePrinter(messagePrinter);
|
2020-02-07 21:06:50 +08:00
|
|
|
if (nullptr == argHelper) {
|
|
|
|
argHelper = std::make_unique<OclocArgHelper>();
|
|
|
|
}
|
2019-06-27 03:19:34 +08:00
|
|
|
}
|
2018-08-20 18:55:55 +08:00
|
|
|
BinaryDecoder(const std::string &file, const std::string &patch, const std::string &dump)
|
|
|
|
: binaryFile(file), pathToPatch(patch), pathToDump(dump){};
|
2020-02-07 21:06:50 +08:00
|
|
|
BinaryDecoder(std::unique_ptr<OclocArgHelper> helper) : argHelper(std::move(helper)), iga(new IgaWrapper) {
|
|
|
|
iga->setMessagePrinter(messagePrinter);
|
|
|
|
};
|
2018-08-20 18:55:55 +08:00
|
|
|
int decode();
|
2020-02-07 21:06:50 +08:00
|
|
|
int validateInput(const std::vector<std::string> &args);
|
2019-03-26 22:11:49 +08:00
|
|
|
void setMessagePrinter(const MessagePrinter &messagePrinter);
|
|
|
|
|
2018-08-20 18:55:55 +08:00
|
|
|
protected:
|
2020-02-07 21:06:50 +08:00
|
|
|
std::unique_ptr<OclocArgHelper> argHelper = nullptr;
|
2020-01-23 22:00:33 +08:00
|
|
|
bool ignoreIsaPadding = false;
|
2018-08-20 18:55:55 +08:00
|
|
|
BinaryHeader programHeader, kernelHeader;
|
2020-01-26 02:18:48 +08:00
|
|
|
std::vector<char> binary;
|
2019-06-27 03:19:34 +08:00
|
|
|
std::unique_ptr<IgaWrapper> iga;
|
2018-08-20 18:55:55 +08:00
|
|
|
PTMap patchTokens;
|
|
|
|
std::string binaryFile, pathToPatch, pathToDump;
|
2019-03-26 22:11:49 +08:00
|
|
|
MessagePrinter messagePrinter;
|
|
|
|
|
2020-01-26 02:18:48 +08:00
|
|
|
void dumpField(const void *&binaryPtr, const PTField &field, std::ostream &ptmFile);
|
2018-08-20 18:55:55 +08:00
|
|
|
uint8_t getSize(const std::string &typeStr);
|
2020-01-26 02:18:48 +08:00
|
|
|
const void *getDevBinary();
|
2020-02-07 21:06:50 +08:00
|
|
|
std::vector<std::string> loadPatchList();
|
2018-08-20 18:55:55 +08:00
|
|
|
void parseTokens();
|
|
|
|
void printHelp();
|
2020-01-26 02:18:48 +08: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 18:55:55 +08:00
|
|
|
uint32_t readStructFields(const std::vector<std::string> &patchList,
|
|
|
|
const size_t &structPos, std::vector<PTField> &fields);
|
|
|
|
};
|