Line.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/DebugInfo/CodeView/TypeIndex.h"
  16. #include "llvm/Support/Endian.h"
  17. #include <cinttypes>
  18. namespace llvm {
  19. namespace codeview {
  20. using llvm::support::ulittle32_t;
  21. class LineInfo {
  22. public:
  23. enum : uint32_t {
  24. AlwaysStepIntoLineNumber = 0xfeefee,
  25. NeverStepIntoLineNumber = 0xf00f00
  26. };
  27. enum : int { EndLineDeltaShift = 24 };
  28. enum : uint32_t {
  29. StartLineMask = 0x00ffffff,
  30. EndLineDeltaMask = 0x7f000000,
  31. StatementFlag = 0x80000000u
  32. };
  33. LineInfo(uint32_t StartLine, uint32_t EndLine, bool IsStatement);
  34. LineInfo(uint32_t LineData) : LineData(LineData) {}
  35. uint32_t getStartLine() const { return LineData & StartLineMask; }
  36. uint32_t getLineDelta() const {
  37. return (LineData & EndLineDeltaMask) >> EndLineDeltaShift;
  38. }
  39. uint32_t getEndLine() const { return getStartLine() + getLineDelta(); }
  40. bool isStatement() const { return (LineData & StatementFlag) != 0; }
  41. uint32_t getRawData() const { return LineData; }
  42. bool isAlwaysStepInto() const {
  43. return getStartLine() == AlwaysStepIntoLineNumber;
  44. }
  45. bool isNeverStepInto() const {
  46. return getStartLine() == NeverStepIntoLineNumber;
  47. }
  48. private:
  49. uint32_t LineData;
  50. };
  51. class ColumnInfo {
  52. private:
  53. static const uint32_t StartColumnMask = 0x0000ffffu;
  54. static const uint32_t EndColumnMask = 0xffff0000u;
  55. static const int EndColumnShift = 16;
  56. public:
  57. ColumnInfo(uint16_t StartColumn, uint16_t EndColumn) {
  58. ColumnData =
  59. (static_cast<uint32_t>(StartColumn) & StartColumnMask) |
  60. ((static_cast<uint32_t>(EndColumn) << EndColumnShift) & EndColumnMask);
  61. }
  62. uint16_t getStartColumn() const {
  63. return static_cast<uint16_t>(ColumnData & StartColumnMask);
  64. }
  65. uint16_t getEndColumn() const {
  66. return static_cast<uint16_t>((ColumnData & EndColumnMask) >>
  67. EndColumnShift);
  68. }
  69. uint32_t getRawData() const { return ColumnData; }
  70. private:
  71. uint32_t ColumnData;
  72. };
  73. class Line {
  74. private:
  75. int32_t CodeOffset;
  76. LineInfo LineInf;
  77. ColumnInfo ColumnInf;
  78. public:
  79. Line(int32_t CodeOffset, uint32_t StartLine, uint32_t EndLine,
  80. uint16_t StartColumn, uint16_t EndColumn, bool IsStatement)
  81. : CodeOffset(CodeOffset), LineInf(StartLine, EndLine, IsStatement),
  82. ColumnInf(StartColumn, EndColumn) {}
  83. Line(int32_t CodeOffset, LineInfo LineInf, ColumnInfo ColumnInf)
  84. : CodeOffset(CodeOffset), LineInf(LineInf), ColumnInf(ColumnInf) {}
  85. LineInfo getLineInfo() const { return LineInf; }
  86. ColumnInfo getColumnInfo() const { return ColumnInf; }
  87. int32_t getCodeOffset() const { return CodeOffset; }
  88. uint32_t getStartLine() const { return LineInf.getStartLine(); }
  89. uint32_t getLineDelta() const { return LineInf.getLineDelta(); }
  90. uint32_t getEndLine() const { return LineInf.getEndLine(); }
  91. uint16_t getStartColumn() const { return ColumnInf.getStartColumn(); }
  92. uint16_t getEndColumn() const { return ColumnInf.getEndColumn(); }
  93. bool isStatement() const { return LineInf.isStatement(); }
  94. bool isAlwaysStepInto() const { return LineInf.isAlwaysStepInto(); }
  95. bool isNeverStepInto() const { return LineInf.isNeverStepInto(); }
  96. };
  97. } // namespace codeview
  98. } // namespace llvm
  99. #endif
  100. #ifdef __GNUC__
  101. #pragma GCC diagnostic pop
  102. #endif