/* * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/offline_compiler/source/ocloc_arg_helper.h" #include "helper.h" #include "iga_wrapper.h" #include #include #include class BinaryEncoder { public: BinaryEncoder() : iga(new IgaWrapper) { iga->setMessagePrinter(messagePrinter); argHelper = std::make_unique(); } BinaryEncoder(const std::string &dump, const std::string &elf) : pathToDump(dump), elfName(elf){}; BinaryEncoder(std::unique_ptr helper) : argHelper(std::move(helper)), iga(new IgaWrapper) { iga->setMessagePrinter(messagePrinter); } int encode(); int validateInput(const std::vector &args); void setMessagePrinter(const MessagePrinter &messagePrinter); protected: std::unique_ptr argHelper = nullptr; bool ignoreIsaPadding = false; std::string pathToDump, elfName; MessagePrinter messagePrinter; std::unique_ptr iga; void calculatePatchListSizes(std::vector &ptmFile); MOCKABLE_VIRTUAL bool copyBinaryToBinary(const std::string &srcFileName, std::ostream &outBinary, uint32_t *binaryLength); bool copyBinaryToBinary(const std::string &srcFileName, std::ostream &outBinary) { return copyBinaryToBinary(srcFileName, outBinary, nullptr); } int createElf(std::stringstream &deviceBinary); void printHelp(); int processBinary(const std::vector &ptmFile, std::ostream &deviceBinary); int processKernel(size_t &i, const std::vector &ptmFileLines, std::ostream &deviceBinary); template void write(std::stringstream &in, std::ostream &deviceBinary); int writeDeviceBinary(const std::string &line, std::ostream &deviceBinary); void addPadding(std::ostream &out, size_t numBytes); };