File: ar_decoder.h

package info (click to toggle)
intel-compute-runtime 20.44.18297-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,780 kB
  • sloc: cpp: 379,729; lisp: 4,931; python: 299; sh: 196; makefile: 8
file content (86 lines) | stat: -rw-r--r-- 2,259 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (C) 2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/compiler_interface/intermediate_representations.h"
#include "shared/source/device_binary_format/ar/ar.h"
#include "shared/source/utilities/arrayref.h"
#include "shared/source/utilities/stackvec.h"

namespace NEO {
namespace Ar {

struct ArFileEntryHeaderAndData {
    ConstStringRef fileName;
    ArrayRef<const uint8_t> fileData;

    const ArFileEntryHeader *fullHeader = nullptr;
};

struct Ar {
    const char *magic = nullptr;
    StackVec<ArFileEntryHeaderAndData, 32> files;
    ArFileEntryHeaderAndData longFileNamesEntry;
};

inline bool isAr(const ArrayRef<const uint8_t> binary) {
    return NEO::hasSameMagic(arMagic, binary);
}

template <uint32_t MaxLength>
inline uint64_t readDecimal(const char *decimalAsString) {
    uint64_t ret = 0U;
    for (uint32_t i = 0; i < MaxLength; ++i) {
        if (('\0' == decimalAsString[i]) || (' ' == decimalAsString[i])) {
            break;
        }
        ret = ret * 10 + (decimalAsString[i] - '0');
    }
    return ret;
}

inline bool isStringPadding(char character) {
    switch (character) {
    default:
        return false;
    case ' ':
        return true;
    case '\0':
        return true;
    case '/':
        return true;
    }
}

template <uint32_t MaxLength>
inline ConstStringRef readUnpaddedString(const char *paddedString) {
    uint32_t unpaddedSize = MaxLength - 1;
    for (; unpaddedSize > 0U; --unpaddedSize) {
        if (false == isStringPadding(paddedString[unpaddedSize])) {
            break;
        }
    }
    if (false == isStringPadding(paddedString[unpaddedSize])) {
        ++unpaddedSize;
    }
    return ConstStringRef(paddedString, unpaddedSize);
}

inline ConstStringRef readLongFileName(ConstStringRef longFileNamesSection, size_t offset) {
    size_t end = offset;
    while ((end < longFileNamesSection.size()) && (longFileNamesSection[end] != SpecialFileNames::fileNameTerminator)) {
        ++end;
    }
    return ConstStringRef(longFileNamesSection.begin() + offset, end - offset);
}

Ar decodeAr(const ArrayRef<const uint8_t> binary, std::string &outErrReason, std::string &outWarnings);

} // namespace Ar

} // namespace NEO