Line.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- Line.h ---------------------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_CODEVIEW_LINE_H
  14. #define LLVM_DEBUGINFO_CODEVIEW_LINE_H
  15. #include "llvm/Support/Endian.h"
  16. #include <cinttypes>
  17. namespace llvm {
  18. namespace codeview {
  19. using llvm::support::ulittle32_t;
  20. class LineInfo {
  21. public:
  22. enum : uint32_t {
  23. AlwaysStepIntoLineNumber = 0xfeefee,
  24. NeverStepIntoLineNumber = 0xf00f00
  25. };
  26. enum : int { EndLineDeltaShift = 24 };
  27. enum : uint32_t {
  28. StartLineMask = 0x00ffffff,
  29. EndLineDeltaMask = 0x7f000000,
  30. StatementFlag = 0x80000000u
  31. };
  32. LineInfo(uint32_t StartLine, uint32_t EndLine, bool IsStatement);
  33. LineInfo(uint32_t LineData) : LineData(LineData) {}
  34. uint32_t getStartLine() const { return LineData & StartLineMask; }
  35. uint32_t getLineDelta() const {
  36. return (LineData & EndLineDeltaMask) >> EndLineDeltaShift;
  37. }
  38. uint32_t getEndLine() const { return getStartLine() + getLineDelta(); }
  39. bool isStatement() const { return (LineData & StatementFlag) != 0; }
  40. uint32_t getRawData() const { return LineData; }
  41. bool isAlwaysStepInto() const {
  42. return getStartLine() == AlwaysStepIntoLineNumber;
  43. }
  44. bool isNeverStepInto() const {
  45. return getStartLine() == NeverStepIntoLineNumber;
  46. }
  47. private:
  48. uint32_t LineData;
  49. };
  50. class ColumnInfo {
  51. private:
  52. static const uint32_t StartColumnMask = 0x0000ffffu;
  53. static const uint32_t EndColumnMask = 0xffff0000u;
  54. static const int EndColumnShift = 16;
  55. public:
  56. ColumnInfo(uint16_t StartColumn, uint16_t EndColumn) {
  57. ColumnData =
  58. (static_cast<uint32_t>(StartColumn) & StartColumnMask) |
  59. ((static_cast<uint32_t>(EndColumn) << EndColumnShift) & EndColumnMask);
  60. }
  61. uint16_t getStartColumn() const {
  62. return static_cast<uint16_t>(ColumnData & StartColumnMask);
  63. }
  64. uint16_t getEndColumn() const {
  65. return static_cast<uint16_t>((ColumnData & EndColumnMask) >>
  66. EndColumnShift);
  67. }
  68. uint32_t getRawData() const { return ColumnData; }
  69. private:
  70. uint32_t ColumnData;
  71. };
  72. class Line {
  73. private:
  74. int32_t CodeOffset;
  75. LineInfo LineInf;
  76. ColumnInfo ColumnInf;
  77. public:
  78. Line(int32_t CodeOffset, uint32_t StartLine, uint32_t EndLine,
  79. uint16_t StartColumn, uint16_t EndColumn, bool IsStatement)
  80. : CodeOffset(CodeOffset), LineInf(StartLine, EndLine, IsStatement),
  81. ColumnInf(StartColumn, EndColumn) {}
  82. Line(int32_t CodeOffset, LineInfo LineInf, ColumnInfo ColumnInf)
  83. : CodeOffset(CodeOffset), LineInf(LineInf), ColumnInf(ColumnInf) {}
  84. LineInfo getLineInfo() const { return LineInf; }
  85. ColumnInfo getColumnInfo() const { return ColumnInf; }
  86. int32_t getCodeOffset() const { return CodeOffset; }
  87. uint32_t getStartLine() const { return LineInf.getStartLine(); }
  88. uint32_t getLineDelta() const { return LineInf.getLineDelta(); }
  89. uint32_t getEndLine() const { return LineInf.getEndLine(); }
  90. uint16_t getStartColumn() const { return ColumnInf.getStartColumn(); }
  91. uint16_t getEndColumn() const { return ColumnInf.getEndColumn(); }
  92. bool isStatement() const { return LineInf.isStatement(); }
  93. bool isAlwaysStepInto() const { return LineInf.isAlwaysStepInto(); }
  94. bool isNeverStepInto() const { return LineInf.isNeverStepInto(); }
  95. };
  96. } // namespace codeview
  97. } // namespace llvm
  98. #endif
  99. #ifdef __GNUC__
  100. #pragma GCC diagnostic pop
  101. #endif