1 //===- MipsABIFlagsSection.cpp - Mips ELF ABI Flags Section ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "MCTargetDesc/MipsABIFlagsSection.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/MC/MCStreamer.h"
13 #include "llvm/Support/ErrorHandling.h"
14 #include "llvm/Support/MipsABIFlags.h"
15 
16 using namespace llvm;
17 
getFpABIValue()18 uint8_t MipsABIFlagsSection::getFpABIValue() {
19   switch (FpABI) {
20   case FpABIKind::ANY:
21     return Mips::Val_GNU_MIPS_ABI_FP_ANY;
22   case FpABIKind::SOFT:
23     return Mips::Val_GNU_MIPS_ABI_FP_SOFT;
24   case FpABIKind::XX:
25     return Mips::Val_GNU_MIPS_ABI_FP_XX;
26   case FpABIKind::S32:
27     return Mips::Val_GNU_MIPS_ABI_FP_DOUBLE;
28   case FpABIKind::S64:
29     if (Is32BitABI)
30       return OddSPReg ? Mips::Val_GNU_MIPS_ABI_FP_64
31                       : Mips::Val_GNU_MIPS_ABI_FP_64A;
32     return Mips::Val_GNU_MIPS_ABI_FP_DOUBLE;
33   }
34 
35   llvm_unreachable("unexpected fp abi value");
36 }
37 
getFpABIString(FpABIKind Value)38 StringRef MipsABIFlagsSection::getFpABIString(FpABIKind Value) {
39   switch (Value) {
40   case FpABIKind::XX:
41     return "xx";
42   case FpABIKind::S32:
43     return "32";
44   case FpABIKind::S64:
45     return "64";
46   default:
47     llvm_unreachable("unsupported fp abi value");
48   }
49 }
50 
getCPR1SizeValue()51 uint8_t MipsABIFlagsSection::getCPR1SizeValue() {
52   if (FpABI == FpABIKind::XX)
53     return (uint8_t)Mips::AFL_REG_32;
54   return (uint8_t)CPR1Size;
55 }
56 
57 namespace llvm {
58 
operator <<(MCStreamer & OS,MipsABIFlagsSection & ABIFlagsSection)59 MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection) {
60   // Write out a Elf_Internal_ABIFlags_v0 struct
61   OS.EmitIntValue(ABIFlagsSection.getVersionValue(), 2);      // version
62   OS.EmitIntValue(ABIFlagsSection.getISALevelValue(), 1);     // isa_level
63   OS.EmitIntValue(ABIFlagsSection.getISARevisionValue(), 1);  // isa_rev
64   OS.EmitIntValue(ABIFlagsSection.getGPRSizeValue(), 1);      // gpr_size
65   OS.EmitIntValue(ABIFlagsSection.getCPR1SizeValue(), 1);     // cpr1_size
66   OS.EmitIntValue(ABIFlagsSection.getCPR2SizeValue(), 1);     // cpr2_size
67   OS.EmitIntValue(ABIFlagsSection.getFpABIValue(), 1);        // fp_abi
68   OS.EmitIntValue(ABIFlagsSection.getISAExtensionValue(), 4); // isa_ext
69   OS.EmitIntValue(ABIFlagsSection.getASESetValue(), 4);       // ases
70   OS.EmitIntValue(ABIFlagsSection.getFlags1Value(), 4);       // flags1
71   OS.EmitIntValue(ABIFlagsSection.getFlags2Value(), 4);       // flags2
72   return OS;
73 }
74 
75 } // end namespace llvm
76