xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AVR/MCTargetDesc/AVRELFStreamer.cpp (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 #include "AVRELFStreamer.h"
2 
3 #include "llvm/BinaryFormat/ELF.h"
4 #include "llvm/MC/MCAssembler.h"
5 #include "llvm/MC/MCSubtargetInfo.h"
6 #include "llvm/MC/SubtargetFeature.h"
7 #include "llvm/Support/FormattedStream.h"
8 
9 #include "AVRMCTargetDesc.h"
10 
11 namespace llvm {
12 
13 static unsigned getEFlagsForFeatureSet(const FeatureBitset &Features) {
14   unsigned EFlags = 0;
15 
16   // Set architecture
17   if (Features[AVR::ELFArchAVR1])
18     EFlags |= ELF::EF_AVR_ARCH_AVR1;
19   else if (Features[AVR::ELFArchAVR2])
20     EFlags |= ELF::EF_AVR_ARCH_AVR2;
21   else if (Features[AVR::ELFArchAVR25])
22     EFlags |= ELF::EF_AVR_ARCH_AVR25;
23   else if (Features[AVR::ELFArchAVR3])
24     EFlags |= ELF::EF_AVR_ARCH_AVR3;
25   else if (Features[AVR::ELFArchAVR31])
26     EFlags |= ELF::EF_AVR_ARCH_AVR31;
27   else if (Features[AVR::ELFArchAVR35])
28     EFlags |= ELF::EF_AVR_ARCH_AVR35;
29   else if (Features[AVR::ELFArchAVR4])
30     EFlags |= ELF::EF_AVR_ARCH_AVR4;
31   else if (Features[AVR::ELFArchAVR5])
32     EFlags |= ELF::EF_AVR_ARCH_AVR5;
33   else if (Features[AVR::ELFArchAVR51])
34     EFlags |= ELF::EF_AVR_ARCH_AVR51;
35   else if (Features[AVR::ELFArchAVR6])
36     EFlags |= ELF::EF_AVR_ARCH_AVR6;
37   else if (Features[AVR::ELFArchTiny])
38     EFlags |= ELF::EF_AVR_ARCH_AVRTINY;
39   else if (Features[AVR::ELFArchXMEGA1])
40     EFlags |= ELF::EF_AVR_ARCH_XMEGA1;
41   else if (Features[AVR::ELFArchXMEGA2])
42     EFlags |= ELF::EF_AVR_ARCH_XMEGA2;
43   else if (Features[AVR::ELFArchXMEGA3])
44     EFlags |= ELF::EF_AVR_ARCH_XMEGA3;
45   else if (Features[AVR::ELFArchXMEGA4])
46     EFlags |= ELF::EF_AVR_ARCH_XMEGA4;
47   else if (Features[AVR::ELFArchXMEGA5])
48     EFlags |= ELF::EF_AVR_ARCH_XMEGA5;
49   else if (Features[AVR::ELFArchXMEGA6])
50     EFlags |= ELF::EF_AVR_ARCH_XMEGA6;
51   else if (Features[AVR::ELFArchXMEGA7])
52     EFlags |= ELF::EF_AVR_ARCH_XMEGA7;
53 
54   return EFlags;
55 }
56 
57 AVRELFStreamer::AVRELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
58     : AVRTargetStreamer(S) {
59 
60   MCAssembler &MCA = getStreamer().getAssembler();
61   unsigned EFlags = MCA.getELFHeaderEFlags();
62 
63   EFlags |= getEFlagsForFeatureSet(STI.getFeatureBits());
64 
65   MCA.setELFHeaderEFlags(EFlags);
66 }
67 
68 } // end namespace llvm
69