|
| 1 | +//===-- LVSourceLanguage.h --------------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +// |
| 9 | +// This file defines the LVSourceLanguage struct, a unified representation of |
| 10 | +// the source language used in a compile unit. |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSOURCELANGUAGE_H |
| 15 | +#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSOURCELANGUAGE_H |
| 16 | + |
| 17 | +#include "llvm/ADT/StringRef.h" |
| 18 | +#include "llvm/BinaryFormat/Dwarf.h" |
| 19 | +#include "llvm/DebugInfo/CodeView/CodeView.h" |
| 20 | + |
| 21 | +namespace llvm { |
| 22 | +namespace logicalview { |
| 23 | + |
| 24 | +/// A source language supported by any of the debug info representations. |
| 25 | +struct LVSourceLanguage { |
| 26 | + static constexpr unsigned TagDwarf = 0x00; |
| 27 | + static constexpr unsigned TagCodeView = 0x01; |
| 28 | + |
| 29 | + enum TaggedLanguage : uint32_t { |
| 30 | + Invalid = -1U, |
| 31 | + |
| 32 | + // DWARF |
| 33 | +#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ |
| 34 | + DW_LANG_##NAME = (TagDwarf << 16) | ID, |
| 35 | +#include "llvm/BinaryFormat/Dwarf.def" |
| 36 | + // CodeView |
| 37 | +#define CV_LANGUAGE(NAME, ID) CV_LANG_##NAME = (TagCodeView << 16) | ID, |
| 38 | +#include "llvm/DebugInfo/CodeView/CodeViewLanguages.def" |
| 39 | + }; |
| 40 | + |
| 41 | + LVSourceLanguage() = default; |
| 42 | + LVSourceLanguage(llvm::dwarf::SourceLanguage SL) |
| 43 | + : LVSourceLanguage(TagDwarf, SL) {} |
| 44 | + LVSourceLanguage(llvm::codeview::SourceLanguage SL) |
| 45 | + : LVSourceLanguage(TagCodeView, SL) {} |
| 46 | + bool operator==(const LVSourceLanguage &SL) const { |
| 47 | + return get() == SL.get(); |
| 48 | + } |
| 49 | + bool operator==(const LVSourceLanguage::TaggedLanguage &TL) const { |
| 50 | + return get() == TL; |
| 51 | + } |
| 52 | + |
| 53 | + bool isValid() const { return Language != Invalid; } |
| 54 | + TaggedLanguage get() const { return Language; } |
| 55 | + StringRef getName() const; |
| 56 | + |
| 57 | +private: |
| 58 | + TaggedLanguage Language = Invalid; |
| 59 | + |
| 60 | + LVSourceLanguage(unsigned Tag, unsigned Lang) |
| 61 | + : Language(static_cast<TaggedLanguage>((Tag << 16) | Lang)) {} |
| 62 | + unsigned getTag() const { return Language >> 16; } |
| 63 | + unsigned getLang() const { return Language & 0xffff; } |
| 64 | +}; |
| 65 | + |
| 66 | +} // end namespace logicalview |
| 67 | +} // end namespace llvm |
| 68 | + |
| 69 | +#endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSOURCELANGUAGE_H |
0 commit comments