@@ -569,7 +569,40 @@ void CodeViewDebug::emitCodeViewMagicVersion() {
569
569
OS.emitInt32 (COFF::DEBUG_SECTION_MAGIC);
570
570
}
571
571
572
- static SourceLanguage MapDWLangToCVLang (unsigned DWLang) {
572
+ static SourceLanguage
573
+ MapDWARFLanguageToCVLang (dwarf::SourceLanguageName DWLName) {
574
+ switch (DWLName) {
575
+ case dwarf::DW_LNAME_C:
576
+ return SourceLanguage::C;
577
+ case dwarf::DW_LNAME_C_plus_plus:
578
+ return SourceLanguage::Cpp;
579
+ case dwarf::DW_LNAME_Fortran:
580
+ return SourceLanguage::Fortran;
581
+ case dwarf::DW_LNAME_Pascal:
582
+ return SourceLanguage::Pascal;
583
+ case dwarf::DW_LNAME_Cobol:
584
+ return SourceLanguage::Cobol;
585
+ case dwarf::DW_LNAME_Java:
586
+ return SourceLanguage::Java;
587
+ case dwarf::DW_LNAME_D:
588
+ return SourceLanguage::D;
589
+ case dwarf::DW_LNAME_Swift:
590
+ return SourceLanguage::Swift;
591
+ case dwarf::DW_LNAME_Rust:
592
+ return SourceLanguage::Rust;
593
+ case dwarf::DW_LNAME_ObjC:
594
+ return SourceLanguage::ObjC;
595
+ case dwarf::DW_LNAME_ObjC_plus_plus:
596
+ return SourceLanguage::ObjCpp;
597
+ default :
598
+ // There's no CodeView representation for this language, and CV doesn't
599
+ // have an "unknown" option for the language field, so we'll use MASM,
600
+ // as it's very low level.
601
+ return SourceLanguage::Masm;
602
+ }
603
+ }
604
+
605
+ static SourceLanguage MapDWARFLanguageToCVLang (dwarf::SourceLanguage DWLang) {
573
606
switch (DWLang) {
574
607
case dwarf::DW_LANG_C:
575
608
case dwarf::DW_LANG_C89:
@@ -633,8 +666,13 @@ void CodeViewDebug::beginModule(Module *M) {
633
666
Node = *CUs->operands ().begin ();
634
667
}
635
668
const auto *CU = cast<DICompileUnit>(Node);
669
+ DISourceLanguageName Lang = CU->getSourceLanguage ();
636
670
CurrentSourceLanguage =
637
- MapDWLangToCVLang (CU->getSourceLanguage ().getUnversionedName ());
671
+ Lang.hasVersionedName ()
672
+ ? MapDWARFLanguageToCVLang (
673
+ static_cast <dwarf::SourceLanguageName>(Lang.getName ()))
674
+ : MapDWARFLanguageToCVLang (
675
+ static_cast <dwarf::SourceLanguage>(Lang.getName ()));
638
676
if (!M->getCodeViewFlag () ||
639
677
CU->getEmissionKind () == DICompileUnit::NoDebug) {
640
678
Asm = nullptr ;
0 commit comments