Debian Codegraph @

visa/iga/IGALibrary/IR/Loc.hpp

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2017-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #ifndef IGA_LOC
10 #define IGA_LOC
11 // WARNING: the IR is subject to change without any notice. External tools
12 // should use the official interfaces in the external API. Those interfaces
13 // are tested between releases and maintained even with changes to the IR.
14
15 #include <cstdint>
16
17 namespace iga {
18 typedef int32_t PC;
19
20 // a source location (can also be binary for things like decoding)
21 struct Loc {
22 // int file; // an optional file index
23 PC offset = 0; // file offset or binary offset (PC)
24 uint32_t line = 0;
25 uint32_t col = 0;
26 uint32_t extent = 0; // length (in characters/bytes)
27
28 Loc() {}
29 Loc(PC pc) : offset(pc) {}
30
31 Loc(uint32_t ln, uint32_t cl, uint32_t off, uint32_t len)
32 : offset((PC)off), line(ln), col(cl), extent(len) {}
33
34 Loc endOfToken() const {
35 Loc l = *this;
36 l.col += extent;
37 l.offset += extent;
38 l.extent = 1;
39 return l;
40 }
41
42 bool isValid() const { return line != INVALID.line && col != INVALID.col; }
43 // tells if the offset value is a PC or text offset
44 bool isBinary() const { return line == 0 && col == 0; }
45 bool isText() const { return !isBinary(); }
46
47 // bool operator==(const Loc &rhs) const {
48 // return this->line == rhs.line &&
49 // this->col == rhs.col &&
50 // this->offset == rhs.offset &&
51 // this->extent == rhs.extent;
52 // }
53
54 const static Loc INVALID;
55 };
56
57 } // namespace iga
58
59 #endif