LCOV - code coverage report
Current view: top level - lib/MC - MCWasmStreamer.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 98 0.0 %
Date: 2017-09-14 15:23:50 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- lib/MC/MCWasmStreamer.cpp - Wasm Object Output ---------------------===//
       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             : // This file assembles .s files and emits Wasm .o object files.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/MC/MCWasmStreamer.h"
      15             : #include "llvm/ADT/STLExtras.h"
      16             : #include "llvm/ADT/SmallPtrSet.h"
      17             : #include "llvm/MC/MCAsmBackend.h"
      18             : #include "llvm/MC/MCAsmInfo.h"
      19             : #include "llvm/MC/MCAsmLayout.h"
      20             : #include "llvm/MC/MCAssembler.h"
      21             : #include "llvm/MC/MCCodeEmitter.h"
      22             : #include "llvm/MC/MCContext.h"
      23             : #include "llvm/MC/MCExpr.h"
      24             : #include "llvm/MC/MCInst.h"
      25             : #include "llvm/MC/MCObjectFileInfo.h"
      26             : #include "llvm/MC/MCObjectStreamer.h"
      27             : #include "llvm/MC/MCObjectWriter.h"
      28             : #include "llvm/MC/MCSection.h"
      29             : #include "llvm/MC/MCSectionWasm.h"
      30             : #include "llvm/MC/MCSymbol.h"
      31             : #include "llvm/MC/MCSymbolWasm.h"
      32             : #include "llvm/MC/MCValue.h"
      33             : #include "llvm/Support/Casting.h"
      34             : #include "llvm/Support/Debug.h"
      35             : #include "llvm/Support/ErrorHandling.h"
      36             : #include "llvm/Support/TargetRegistry.h"
      37             : #include "llvm/Support/raw_ostream.h"
      38             : 
      39             : using namespace llvm;
      40             : 
      41           0 : MCWasmStreamer::~MCWasmStreamer() {}
      42             : 
      43           0 : void MCWasmStreamer::mergeFragment(MCDataFragment *DF, MCDataFragment *EF) {
      44           0 :   flushPendingLabels(DF, DF->getContents().size());
      45             : 
      46           0 :   for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
      47           0 :     EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
      48           0 :                                  DF->getContents().size());
      49           0 :     DF->getFixups().push_back(EF->getFixups()[i]);
      50             :   }
      51           0 :   DF->setHasInstructions(true);
      52           0 :   DF->getContents().append(EF->getContents().begin(), EF->getContents().end());
      53           0 : }
      54             : 
      55           0 : void MCWasmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
      56             :   // Let the target do whatever target specific stuff it needs to do.
      57           0 :   getAssembler().getBackend().handleAssemblerFlag(Flag);
      58             : 
      59             :   // Do any generic stuff we need to do.
      60           0 :   llvm_unreachable("invalid assembler flag!");
      61             : }
      62             : 
      63           0 : void MCWasmStreamer::ChangeSection(MCSection *Section,
      64             :                                    const MCExpr *Subsection) {
      65           0 :   MCAssembler &Asm = getAssembler();
      66           0 :   auto *SectionWasm = static_cast<const MCSectionWasm *>(Section);
      67           0 :   const MCSymbol *Grp = SectionWasm->getGroup();
      68           0 :   if (Grp)
      69           0 :     Asm.registerSymbol(*Grp);
      70             : 
      71           0 :   this->MCObjectStreamer::ChangeSection(Section, Subsection);
      72           0 : }
      73             : 
      74           0 : void MCWasmStreamer::EmitWeakReference(MCSymbol *Alias,
      75             :                                        const MCSymbol *Symbol) {
      76           0 :   getAssembler().registerSymbol(*Symbol);
      77           0 :   const MCExpr *Value = MCSymbolRefExpr::create(
      78           0 :       Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext());
      79           0 :   Alias->setVariableValue(Value);
      80           0 : }
      81             : 
      82           0 : bool MCWasmStreamer::EmitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
      83             :   assert(Attribute != MCSA_IndirectSymbol && "indirect symbols not supported");
      84             : 
      85           0 :   auto *Symbol = cast<MCSymbolWasm>(S);
      86             : 
      87             :   // Adding a symbol attribute always introduces the symbol, note that an
      88             :   // important side effect of calling registerSymbol here is to register
      89             :   // the symbol with the assembler.
      90           0 :   getAssembler().registerSymbol(*Symbol);
      91             : 
      92           0 :   switch (Attribute) {
      93             :   case MCSA_LazyReference:
      94             :   case MCSA_Reference:
      95             :   case MCSA_SymbolResolver:
      96             :   case MCSA_PrivateExtern:
      97             :   case MCSA_WeakDefinition:
      98             :   case MCSA_WeakDefAutoPrivate:
      99             :   case MCSA_Invalid:
     100             :   case MCSA_IndirectSymbol:
     101             :   case MCSA_Hidden:
     102             :     return false;
     103             : 
     104           0 :   case MCSA_Weak:
     105             :   case MCSA_WeakReference:
     106           0 :     Symbol->setWeak(true);
     107           0 :     Symbol->setExternal(true);
     108             :     break;
     109             : 
     110           0 :   case MCSA_Global:
     111           0 :     Symbol->setExternal(true);
     112             :     break;
     113             : 
     114           0 :   case MCSA_ELF_TypeFunction:
     115             :     Symbol->setIsFunction(true);
     116             :     break;
     117             : 
     118           0 :   case MCSA_ELF_TypeObject:
     119             :     Symbol->setIsFunction(false);
     120             :     break;
     121             : 
     122           0 :   default:
     123             :     // unrecognized directive
     124           0 :     llvm_unreachable("unexpected MCSymbolAttr");
     125             :     return false;
     126             :   }
     127             : 
     128             :   return true;
     129             : }
     130             : 
     131           0 : void MCWasmStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size,
     132             :                                       unsigned ByteAlignment) {
     133           0 :   llvm_unreachable("Common symbols are not yet implemented for Wasm");
     134             : }
     135             : 
     136           0 : void MCWasmStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
     137           0 :   cast<MCSymbolWasm>(Symbol)->setSize(Value);
     138           0 : }
     139             : 
     140           0 : void MCWasmStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
     141             :                                            unsigned ByteAlignment) {
     142           0 :   llvm_unreachable("Local common symbols are not yet implemented for Wasm");
     143             : }
     144             : 
     145           0 : void MCWasmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
     146             :                                    SMLoc Loc) {
     147           0 :   MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
     148           0 : }
     149             : 
     150           0 : void MCWasmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
     151             :                                           unsigned ValueSize,
     152             :                                           unsigned MaxBytesToEmit) {
     153           0 :   MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value, ValueSize,
     154             :                                          MaxBytesToEmit);
     155           0 : }
     156             : 
     157           0 : void MCWasmStreamer::EmitIdent(StringRef IdentString) {
     158           0 :   MCSection *Comment = getAssembler().getContext().getWasmSection(
     159           0 :       ".comment", 0, 0);
     160           0 :   PushSection();
     161           0 :   SwitchSection(Comment);
     162           0 :   if (!SeenIdent) {
     163           0 :     EmitIntValue(0, 1);
     164           0 :     SeenIdent = true;
     165             :   }
     166           0 :   EmitBytes(IdentString);
     167           0 :   EmitIntValue(0, 1);
     168           0 :   PopSection();
     169           0 : }
     170             : 
     171           0 : void MCWasmStreamer::EmitInstToFragment(const MCInst &Inst,
     172             :                                         const MCSubtargetInfo &STI) {
     173           0 :   this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
     174           0 : }
     175             : 
     176           0 : void MCWasmStreamer::EmitInstToData(const MCInst &Inst,
     177             :                                     const MCSubtargetInfo &STI) {
     178           0 :   MCAssembler &Assembler = getAssembler();
     179           0 :   SmallVector<MCFixup, 4> Fixups;
     180           0 :   SmallString<256> Code;
     181           0 :   raw_svector_ostream VecOS(Code);
     182           0 :   Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
     183             : 
     184             :   // Append the encoded instruction to the current data fragment (or create a
     185             :   // new such fragment if the current fragment is not a data fragment).
     186           0 :   MCDataFragment *DF = getOrCreateDataFragment();
     187             : 
     188             :   // Add the fixups and data.
     189           0 :   for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
     190           0 :     Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
     191           0 :     DF->getFixups().push_back(Fixups[i]);
     192             :   }
     193           0 :   DF->setHasInstructions(true);
     194           0 :   DF->getContents().append(Code.begin(), Code.end());
     195           0 : }
     196             : 
     197           0 : void MCWasmStreamer::FinishImpl() {
     198           0 :   EmitFrames(nullptr);
     199             : 
     200           0 :   this->MCObjectStreamer::FinishImpl();
     201           0 : }
     202             : 
     203           0 : MCStreamer *llvm::createWasmStreamer(MCContext &Context, MCAsmBackend &MAB,
     204             :                                      raw_pwrite_stream &OS, MCCodeEmitter *CE,
     205             :                                      bool RelaxAll) {
     206           0 :   MCWasmStreamer *S = new MCWasmStreamer(Context, MAB, OS, CE);
     207           0 :   if (RelaxAll)
     208           0 :     S->getAssembler().setRelaxAll(true);
     209           0 :   return S;
     210             : }
     211             : 
     212           0 : void MCWasmStreamer::EmitThumbFunc(MCSymbol *Func) {
     213           0 :   llvm_unreachable("Generic Wasm doesn't support this directive");
     214             : }
     215             : 
     216           0 : void MCWasmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
     217           0 :   llvm_unreachable("Wasm doesn't support this directive");
     218             : }
     219             : 
     220           0 : void MCWasmStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
     221             :                                   uint64_t Size, unsigned ByteAlignment) {
     222           0 :   llvm_unreachable("Wasm doesn't support this directive");
     223             : }
     224             : 
     225           0 : void MCWasmStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
     226             :                                     uint64_t Size, unsigned ByteAlignment) {
     227           0 :   llvm_unreachable("Wasm doesn't support this directive");
     228             : }

Generated by: LCOV version 1.13