Javier Lopez-Gomez 0f38c54c6f
[llvm-debuginfo-analyzer] Add support for parsing DWARF / CodeView SourceLanguage (#137223)
This pull request adds support for parsing the source language in both
DWARF and CodeView. Specifically,

- The `LVSourceLanguage` class is introduced to represent any supported
language by any of the debug info representations.

- Update `LVDWARFReader.cpp` and `LVCodeViewVisitor.cpp` to parse the
source language where it applies. Added a new `=Language` attribute;
`getAttributeLanguage()` is internally used to control whether this
information is being printed.
2025-06-06 15:03:07 +01:00

34 lines
1.1 KiB
C++

//===-- LVSourceLanguage.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements LVSourceLanguage.
//
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/LogicalView/Core/LVSourceLanguage.h"
#include "llvm/DebugInfo/CodeView/EnumTables.h"
#include "llvm/Support/ScopedPrinter.h"
using namespace llvm;
using namespace llvm::logicalview;
StringRef LVSourceLanguage::getName() const {
if (!isValid())
return {};
switch (getTag()) {
case LVSourceLanguage::TagDwarf:
return llvm::dwarf::LanguageString(getLang());
case LVSourceLanguage::TagCodeView: {
static auto LangNames = llvm::codeview::getSourceLanguageNames();
return LangNames[getLang()].Name;
}
default:
llvm_unreachable("Unsupported language");
}
}