<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style id="owaParaStyle" type="text/css">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1" style="word-wrap:break-word">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">This time with the patch.<br>
<br>
Jack<br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF606967"><font size="2" color="#000000" face="Tahoma"><b>From:</b> Vladimir Medic<br>
<b>Sent:</b> Tuesday, September 10, 2013 12:52 AM<br>
<b>To:</b> llvm-commits@cs.uiuc.edu<br>
<b>Cc:</b> Jack Carter; Jim Grosbach<br>
<b>Subject:</b> RE: [PATCH][AsmParser][MC] Allow asm parser to emit elf header flags<br>
</font><br>
</div>
<div></div>
<div>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">
<pre class="bz_comment_text" id="comment_text_30">Hi all,<br>This patch handles LLVM standalone assembler (llvm-mc) ELF flag setting based on input file
directive processing.

Mips assembly requires processing inline directives that directly and
indirectly affect the output ELF header flags. This patch handles one
".abicalls".

To process these directives we are following the model the code generator
uses by storing state in a container as we go through processing and when
we detect the end of input file processing, AsmParser is notified and we
update the ELF header flags through a MipsELFStreamer method with a call from
MCTargetAsmParser::emitEndOfAsmFile(MCStreamer &OutStreamer).

It has been suggested that we use AsmPrinter::EmitEndOfAsmFile() to
trigger the updating of the ELF header flags, but as far as we can tell
MipsAsmPrinter is not available for the AsmParser.

Also, the location of the call to emitEndOfAsmFile() is our best guess for when
the input assembler file processing is at an end. If there is a better location
for this please be specific and we will make the change.

We have separate enum values for the relocation models than are in the ELF
defines for Mips because static (non-shared) model is an active state, but is
represented by 0 in the flags. Also we want to have a "default" state.<br><br>Kind regards<br><br>Vladimir<br></pre>
<div style="font-family:Times New Roman; color:#000000; font-size:16px">
<hr tabindex="-1">
<div id="divRpF185999" style="direction:ltr"><font size="2" color="#000000" face="Tahoma"><b>From:</b> Jim Grosbach [grosbach@apple.com]<br>
<b>Sent:</b> Monday, August 26, 2013 11:08 PM<br>
<b>To:</b> Vladimir Medic<br>
<b>Cc:</b> llvm-commits@cs.uiuc.edu; Jack Carter<br>
<b>Subject:</b> Re: [PATCH][AsmParser][MC] Allow asm parser to emit elf header flags<br>
</font><br>
</div>
<div></div>
<div>
<div>Hi Vladimir,</div>
<div><br>
</div>
<div>Detailed comments inline below.</div>
<div><br>
</div>
<div>Generally speaking, please run new code through clang-format. There are lots of small formatting problems here and there that tool will help clean up without having to fuss about the details.</div>
<div><br>
</div>
<div>I don’t have much to comment on regarding the Mips specific side of things. You guys know that stuff better than I do.</div>
<div><br>
</div>
<br>
<blockquote type="cite">
<div>Index: test/MC/Mips/mips_directives.s</div>
<div>===================================================================</div>
<div>--- test/MC/Mips/mips_directives.s<span class="Apple-tab-span" style="white-space:pre">
</span>(revision 188764)</div>
<div>+++ test/MC/Mips/mips_directives.s<span class="Apple-tab-span" style="white-space:pre">
</span>(working copy)</div>
<div>@@ -3,7 +3,10 @@</div>
<div> # CHECK:  .text</div>
<div> # CHECK:  $BB0_2:</div>
<div> $BB0_2:</div>
<div>-  .ent directives_test</div>
<div>+    .ent directives_test</div>
<div>+    .abicalls</div>
<div>+    .option pic0</div>
<div>+    .set mips16</div>
<div>     .frame    $sp,0,$ra</div>
<div>     .mask     0x00000000,0</div>
<div>     .fmask    0x00000000,0</div>
<div>Index: include/llvm/MC/MCTargetAsmParser.h</div>
<div>===================================================================</div>
<div>--- include/llvm/MC/MCTargetAsmParser.h<span class="Apple-tab-span" style="white-space:pre">
</span>(revision 188764)</div>
<div>+++ include/llvm/MC/MCTargetAsmParser.h<span class="Apple-tab-span" style="white-space:pre">
</span>(working copy)</div>
<div>@@ -174,6 +174,10 @@</div>
<div> </div>
<div>   virtual void convertToMapAndConstraints(unsigned Kind,</div>
<div>                       const SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;</div>
<div>+</div>
<div>+  /// setAssemblerDialect - Target specific cleanup such as Ehdr flag setting.</div>
<div>+  /// Analogous to MipsAsmPrinter::EmitEndOfAsmFile().</div>
<div>+  virtual void emitEndOfObjFile(MCStreamer &Out) { }</div>
</blockquote>
<div><br>
</div>
<div>The comment doesn’t match the function.</div>
<div><br>
</div>
<div>Relatedly, please refer to <a href="http://llvm.org/docs/CodingStandards.html#doxygen-use-in-documentation-comments" target="_blank">http://llvm.org/docs/CodingStandards.html#doxygen-use-in-documentation-comments</a> for the latest style preferences for
 these comments. I wouldn’t trust that the surrounding code is up-to-date.</div>
<div><br>
</div>
<div>That said, why is this function necessary at all? EmitEndOfAsmFile() is called even for object files.</div>
<br>
<blockquote type="cite">
<div> };</div>
<div> </div>
<div> } // End llvm namespace</div>
<div>Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp</div>
<div>===================================================================</div>
<div>--- lib/Target/Mips/AsmParser/MipsAsmParser.cpp<span class="Apple-tab-span" style="white-space:pre">
</span>(revision 188764)</div>
<div>+++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp<span class="Apple-tab-span" style="white-space:pre">
</span>(working copy)</div>
<div>@@ -7,6 +7,8 @@</div>
<div> //</div>
<div> //===----------------------------------------------------------------------===//</div>
<div> </div>
<div>+#include "AsmParser/MipsAsmFlags.h"</div>
<div>+#include "MCTargetDesc/MipsELFStreamer.h"</div>
<div> #include "MCTargetDesc/MipsMCTargetDesc.h"</div>
<div> #include "MipsRegisterInfo.h"</div>
<div> #include "llvm/ADT/StringSwitch.h"</div>
<div>@@ -63,6 +65,7 @@</div>
<div>   MCSubtargetInfo &STI;</div>
<div>   MCAsmParser &Parser;</div>
<div>   MipsAssemblerOptions Options;</div>
<div>+  MipsMCAsmFlags Flags;</div>
<div>   bool hasConsumedDollar;</div>
<div> </div>
<div> #define GET_ASSEMBLER_HEADER</div>
<div>@@ -166,6 +169,8 @@</div>
<div> </div>
<div>   bool parseDirectiveWord(unsigned Size, SMLoc L);</div>
<div> </div>
<div>+  bool parseDirectiveOption();</div>
<div>+</div>
<div>   MCSymbolRefExpr::VariantKind getVariantKind(StringRef Symbol);</div>
<div> </div>
<div>   bool isMips64() const {</div>
<div>@@ -198,11 +203,20 @@</div>
<div> </div>
<div>   bool processInstruction(MCInst &Inst, SMLoc IDLoc,</div>
<div>                         SmallVectorImpl<MCInst> &Instructions);</div>
<div>+  void emitEndOfObjFile(MCStreamer &Out);</div>
<div>+</div>
<div>+  void setAbiTy();</div>
<div>+  void setArchTy();</div>
<div>+  void setAseTy();</div>
</blockquote>
<div><br>
</div>
<div>
<div>setXXX() is the usual name for the setter of a getter/setter pair. These are a different sort of thing, and should be named differently. Comments about what they do would be good.</div>
<br>
<blockquote type="cite"></blockquote>
</div>
<br>
<blockquote type="cite">
<div>+</div>
<div> public:</div>
<div>   MipsAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser)</div>
<div>     : MCTargetAsmParser(), STI(sti), Parser(parser), hasConsumedDollar(false) {</div>
<div>     // Initialize the set of available features.</div>
<div>     setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));</div>
<div>+    setAbiTy();</div>
<div>+    setArchTy();</div>
<div>+    setAseTy();</div>
</blockquote>
<div><br>
</div>
<div>Since these are just called once, and all in order, why have three separate functions at all?</div>
<br>
<blockquote type="cite">
<div>   }</div>
<div> </div>
<div>   MCAsmParser &getParser() const { return Parser; }</div>
<div>@@ -446,6 +460,43 @@</div>
<div>   return MipsInsts[Opcode];</div>
<div> }</div>
<div> </div>
<div>+void MipsAsmParser::setAbiTy() {</div>
<div>+  uint64_t FeatureBits = STI.getFeatureBits();</div>
<div>+  unsigned AbiType = MipsMCAsmFlags::MAF_ABI_DEFAULT;</div>
<div>+  if (FeatureBits & Mips::FeatureN32)</div>
<div>+    AbiType = MipsMCAsmFlags::MAF_ABI_N32;</div>
<div>+  else if (FeatureBits & Mips::FeatureO32)</div>
<div>+    AbiType = MipsMCAsmFlags::MAF_ABI_O32;</div>
<div>+  else if (FeatureBits & Mips::FeatureN64)</div>
<div>+    AbiType = MipsMCAsmFlags::MAF_ABI_N64;</div>
<div>+</div>
<div>+  Flags.setAbi(AbiType);</div>
<div>+}</div>
<div>+void MipsAsmParser::setArchTy() {</div>
<div>+    uint64_t FeatureBits = STI.getFeatureBits();</div>
<div>+  unsigned ArchType = MipsMCAsmFlags::MAF_ARCH_DEFAULT;</div>
<div>+  if (FeatureBits & Mips::FeatureMips64r2)</div>
<div>+    ArchType = MipsMCAsmFlags::MAF_ARCH_64R2;</div>
<div>+  else if (FeatureBits & Mips::FeatureMips64)</div>
<div>+    ArchType = MipsMCAsmFlags::MAF_ARCH_64R1;</div>
<div>+  else if (FeatureBits & Mips::FeatureMips32r2)</div>
<div>+    ArchType = MipsMCAsmFlags::MAF_ARCH_32R2;</div>
<div>+  else if (FeatureBits & Mips::FeatureMips32)</div>
<div>+    ArchType = MipsMCAsmFlags::MAF_ARCH_32R1;</div>
<div>+</div>
<div>+  Flags.setArch(ArchType);</div>
<div>+</div>
<div>+}</div>
<div>+void MipsAsmParser::setAseTy() {</div>
<div>+  uint64_t FeatureBits = STI.getFeatureBits();</div>
<div>+  unsigned AseType = MipsMCAsmFlags::MAF_ASE_DEFAULT;</div>
<div>+  if (FeatureBits & Mips::FeatureMips16)</div>
<div>+    AseType = MipsMCAsmFlags::MAF_ASE_MIPS16;</div>
<div>+  else if (FeatureBits & Mips::FeatureMicroMips)</div>
<div>+    AseType = MipsMCAsmFlags::MAF_ASE_MICROMIPS;</div>
<div>+  Flags.setAse(AseType);</div>
<div>+}</div>
<div>+</div>
<div> bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,</div>
<div>                                        SmallVectorImpl<MCInst> &Instructions) {</div>
<div>   const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());</div>
<div>@@ -1807,14 +1858,30 @@</div>
<div>   } else if (Tok.getString() == "nomacro") {</div>
<div>     return parseSetNoMacroDirective();</div>
<div>   } else if (Tok.getString() == "nomips16") {</div>
<div>-    // Ignore this directive for now.</div>
<div>-    Parser.eatToEndOfStatement();</div>
<div>+    if ((STI.getFeatureBits() & Mips::FeatureMips16))</div>
<div>+      STI.ToggleFeature(Mips::FeatureMips16);</div>
<div>+    Flags.setAse(MipsMCAsmFlags::MAF_ASE_DEFAULT);</div>
<div>+    Parser.Lex();</div>
<div>     return false;</div>
<div>-  } else if (Tok.getString() == "nomicromips") {</div>
<div>-    // Ignore this directive for now.</div>
<div>-    Parser.eatToEndOfStatement();</div>
<div>+  } else if (Tok.getString() == "mips16") {</div>
<div>+    if (!(STI.getFeatureBits() & Mips::FeatureMips16))</div>
<div>+      STI.ToggleFeature(Mips::FeatureMips16);</div>
<div>+    Flags.setAse(MipsMCAsmFlags::MAF_ASE_MIPS16);</div>
<div>+    Parser.Lex();</div>
<div>     return false;</div>
<div>-  } else {</div>
<div>+  }else if (Tok.getString() == "nomicromips") {</div>
<div>+    if (STI.getFeatureBits() & Mips::FeatureMicroMips)</div>
<div>+      STI.ToggleFeature(Mips::FeatureMicroMips);</div>
<div>+    Flags.setAse(MipsMCAsmFlags::MAF_ASE_DEFAULT);</div>
<div>+    Parser.Lex();</div>
<div>+    return false;</div>
<div>+  } else if (Tok.getString() == "micromips") {</div>
<div>+    if (!(STI.getFeatureBits() & Mips::FeatureMicroMips))</div>
<div>+      STI.ToggleFeature(Mips::FeatureMicroMips);</div>
<div>+    Flags.setAse(MipsMCAsmFlags::MAF_ASE_MICROMIPS);</div>
<div>+    Parser.Lex();</div>
<div>+    return false;</div>
<div>+  }else {</div>
<div>     // It is just an identifier, look for an assignment.</div>
<div>     parseSetAssignment();</div>
<div>     return false;</div>
<div>@@ -1848,6 +1915,36 @@</div>
<div>   return false;</div>
<div> }</div>
<div> </div>
<div>+bool MipsAsmParser::parseDirectiveOption() {</div>
<div>+  // Get the option token</div>
<div>+  AsmToken Tok = Parser.getTok();</div>
<div>+  // At the moment only identifiers are supported</div>
<div>+  if (Tok.isNot(AsmToken::Identifier)) {</div>
<div>+    // Clear line</div>
<div>+    Parser.eatToEndOfStatement();</div>
<div>+    return Error(Tok.getLoc(), "unexpected token in directive");</div>
<div>+  }</div>
<div>+  StringRef Option = Tok.getIdentifier();</div>
<div>+  if (Option == "pic0") {</div>
<div>+    Flags.setRelocationModel(MipsMCAsmFlags::MAF_RM_STATIC);</div>
<div>+    Parser.Lex();</div>
<div>+    if (Parser.getTok().isNot(AsmToken::EndOfStatement))</div>
<div>+      return Error(Parser.getTok().getLoc(), "unexpected token in directive");</div>
<div>+    return false;</div>
<div>+  }</div>
<div>+</div>
<div>+   if (Option == "pic2") {</div>
<div>+    Flags.setRelocationModel(MipsMCAsmFlags::MAF_RM_PIC);</div>
<div>+    Parser.Lex();</div>
<div>+    if (Parser.getTok().isNot(AsmToken::EndOfStatement))</div>
<div>+      return Error(Parser.getTok().getLoc(), "unexpected token in directive");</div>
<div>+    return false;</div>
<div>+  }</div>
<div>+  // Unknown option</div>
<div>+   Parser.eatToEndOfStatement();</div>
<div>+   return Warning(Parser.getTok().getLoc(), "unknown option in directive");</div>
<div>+}</div>
<div>+</div>
<div> bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {</div>
<div> </div>
<div>   StringRef IDVal = DirectiveID.getString();</div>
<div>@@ -1897,9 +1994,29 @@</div>
<div>     return false;</div>
<div>   }</div>
<div> </div>
<div>+  if (IDVal == ".abicalls") {</div>
<div>+    // TODO: Set the Reloc::PIC_</div>
<div>+    Flags.setRelocationModel(MipsMCAsmFlags::MAF_RM_PIC);</div>
<div>+    if (Parser.getTok().isNot(AsmToken::EndOfStatement))</div>
<div>+      return Error(Parser.getTok().getLoc(), "unexpected token in directive");</div>
<div>+    return false;</div>
<div>+  }</div>
<div>+  if (IDVal == ".option") {</div>
<div>+    return parseDirectiveOption();</div>
<div>+  }</div>
<div>+</div>
<div>   return true;</div>
<div> }</div>
<div> </div>
<div>+/// setAssemblerDialect -</div>
<div>+/// Analogous to MipsAsmPrinter::EmitEndOfAsmFile().</div>
</blockquote>
<div><br>
</div>
Incorrect comment again.<br>
<blockquote type="cite">
<div>+void MipsAsmParser::emitEndOfObjFile(MCStreamer &OutStreamer)</div>
<div>+{</div>
<div>+  if (MipsELFStreamer *MES = dyn_cast<MipsELFStreamer>(&OutStreamer))</div>
<div>+    MES->emitELFHeaderFlagsAsm(Flags);</div>
<div>+  MCTargetAsmParser::emitEndOfObjFile(OutStreamer);</div>
<div>+}</div>
</blockquote>
<div><br>
</div>
This can definitely be done without this function being added. See how ARM handles the EHDR flags.<br>
<br>
<blockquote type="cite">
<div>+</div>
<div> extern "C" void LLVMInitializeMipsAsmParser() {</div>
<div>   RegisterMCAsmParser<MipsAsmParser> X(TheMipsTarget);</div>
<div>   RegisterMCAsmParser<MipsAsmParser> Y(TheMipselTarget);</div>
<div>Index: lib/Target/Mips/AsmParser/MipsAsmFlags.h</div>
<div>===================================================================</div>
<div>--- lib/Target/Mips/AsmParser/MipsAsmFlags.h<span class="Apple-tab-span" style="white-space:pre">
</span>(revision 0)</div>
<div>+++ lib/Target/Mips/AsmParser/MipsAsmFlags.h<span class="Apple-tab-span" style="white-space:pre">
</span>(revision 0)</div>
<div>@@ -0,0 +1,93 @@</div>
<div>+//=== MipsMCAsmFlags.h - MipsMCAsmFlags --------------------------------===//</div>
<div>+//</div>
<div>+//                    The LLVM Compiler Infrastructure</div>
<div>+//</div>
<div>+// This file is distributed under the University of Illinois Open Source</div>
<div>+// License. See LICENCE.TXT for details.</div>
<div>+//</div>
<div>+//===-------------------------------------------------------------------===//</div>
<div>+#ifndef MIPSMCASMFLAGS_H_</div>
<div>+#define MIPSMCASMFLAGS_H_</div>
<div>+</div>
<div>+namespace llvm {</div>
<div>+class MipsMCAsmFlags;</div>
<div>+</div>
<div>+class MipsMCAsmFlags {</div>
<div>+public:</div>
<div>+  enum MAFAbiTy {</div>
<div>+    MAF_ABI_DEFAULT,</div>
<div>+    MAF_ABI_O32,</div>
<div>+    MAF_ABI_N32,</div>
<div>+    MAF_ABI_N64</div>
<div>+  } MAFAbi;</div>
<div>+</div>
<div>+  // These act as bit flags because more that one can be</div>
<div>+  // active at the same time, sometimes ;-)</div>
<div>+  enum MAFRelocationModelTy {</div>
<div>+    MAF_RM_DEFAULT = 0,</div>
<div>+    MAF_RM_STATIC = 1,</div>
<div>+    MAF_RM_CPIC = 2,</div>
<div>+    MAF_RM_PIC = 4</div>
<div>+  } MAFRelocationModel;</div>
<div>+</div>
<div>+  enum MAFArchTy {</div>
<div>+    MAF_ARCH_DEFAULT,</div>
<div>+    MAF_ARCH_32R1,</div>
<div>+    MAF_ARCH_32R2,</div>
<div>+    MAF_ARCH_64R1,</div>
<div>+    MAF_ARCH_64R2</div>
<div>+  } MAFArch;</div>
<div>+</div>
<div>+  enum MAFAseTy {</div>
<div>+    MAF_ASE_DEFAULT,</div>
<div>+    MAF_ASE_MIPS16,</div>
<div>+    MAF_ASE_MICROMIPS</div>
<div>+  } MAFAse;</div>
<div>+</div>
</blockquote>
<div><br>
</div>
<div>Shouldn’t these be part of the MIPS ELF object file information if they’re not already? They’re not really internal to the MIPS AsmParser, right?</div>
<br>
<blockquote type="cite">
<div>+public:</div>
<div>+  MipsMCAsmFlags()</div>
<div>+    : abi(MAF_ABI_DEFAULT),</div>
<div>+      model(MAF_RM_DEFAULT),</div>
<div>+      arch(MAF_ARCH_DEFAULT),</div>
<div>+      ase(MAF_ASE_DEFAULT) {}</div>
<div>+</div>
<div>+  ~MipsMCAsmFlags() {}</div>
<div>+</div>
<div>+  // This is simplistic. Mips16 may need on off switches.</div>
<div>+  void setAbi(unsigned Abi) {(abi = Abi);}</div>
<div>+  void setRelocationModel(unsigned RM) {(model |= RM);}</div>
<div>+  void setArch(unsigned Arch) {(arch = Arch);}</div>
<div>+  void setAse(unsigned Ase) {(ase = Ase);}</div>
<div>+</div>
<div>+  bool isAbiO32() const {return (abi == MAF_ABI_O32);}</div>
<div>+  bool isAbiN32() const {return (abi == MAF_ABI_N32);}</div>
<div>+  bool isAbiN64() const {return (abi == MAF_ABI_N64);}</div>
<div>+  bool isAbiDefault() const {return (abi == MAF_ABI_DEFAULT);}</div>
<div>+</div>
<div>+  bool isModelCpic() const {return (model & MAF_RM_CPIC) == MAF_RM_CPIC;}</div>
<div>+  bool isModelPic() const {return (model & MAF_RM_PIC) == MAF_RM_PIC;}</div>
<div>+  bool isModelStatic() const {return (model & MAF_RM_STATIC) == MAF_RM_STATIC;}</div>
<div>+  bool isModelDefault() const {</div>
<div>+    return (model & MAF_RM_DEFAULT) == MAF_RM_DEFAULT;</div>
<div>+  }</div>
<div>+</div>
<div>+  bool isArch32r1() const {return (arch == MAF_ARCH_32R1);}</div>
<div>+  bool isArch32r2() const {return (arch == MAF_ARCH_32R2);}</div>
<div>+  bool isArch64r1() const {return (arch == MAF_ARCH_64R1);}</div>
<div>+  bool isArch64r2() const {return (arch == MAF_ARCH_64R2);}</div>
<div>+  bool isArchDefault() const {return (arch == MAF_ARCH_DEFAULT);}</div>
<div>+</div>
<div>+  bool isAseMips16() const {return (ase == MAF_ASE_MIPS16);}</div>
<div>+  bool isAseMicroMips() const {return (ase == MAF_ASE_MICROMIPS);}</div>
<div>+  bool isAseDefault() const {return (ase == MAF_ASE_DEFAULT);}</div>
<div>+</div>
<div>+private:</div>
<div>+  unsigned abi;  // o32, n32, n64, etc.</div>
<div>+  unsigned model; // pic, cpic, etc.</div>
<div>+  unsigned arch; // 32, 32r2, 64,etc.</div>
<div>+  unsigned ase;  // 16, MicroMips, etc.</div>
</blockquote>
<div><br>
</div>
<div>Class member variables shouldn’t be all-lower-case. See <a href="http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly" target="_blank">http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly</a></div>
<br>
<blockquote type="cite">
<div>+};</div>
<div>+</div>
<div>+}</div>
<div>+</div>
<div>+#endif /* MIPSMCASMFLAGS_H_ */</div>
<div>Index: lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp</div>
<div>===================================================================</div>
<div>--- lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp<span class="Apple-tab-span" style="white-space:pre">
</span>(revision 188764)</div>
<div>+++ lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp<span class="Apple-tab-span" style="white-space:pre">
</span>(working copy)</div>
<div>@@ -6,6 +6,7 @@</div>
<div> // License. See LICENSE.TXT for details.</div>
<div> //</div>
<div> //===-------------------------------------------------------------------===//</div>
<div>+#include "AsmParser/MipsAsmFlags.h"</div>
<div> #include "MCTargetDesc/MipsELFStreamer.h"</div>
<div> #include "MipsSubtarget.h"</div>
<div> #include "llvm/MC/MCAssembler.h"</div>
<div>@@ -74,6 +75,59 @@</div>
<div>     MCA.setELFHeaderEFlags(EFlags);</div>
<div>   }</div>
<div> </div>
<div>+  // For llvm-mc. Set a group of ELF header flags</div>
<div>+  void</div>
<div>+  MipsELFStreamer::emitELFHeaderFlagsAsm(const MipsMCAsmFlags &Flags) {</div>
<div>+</div>
<div>+    // Update e_header flags</div>
<div>+    MCAssembler& MCA = getAssembler();</div>
<div>+    unsigned EFlags = MCA.getELFHeaderEFlags();</div>
<div>+</div>
<div>+    if (Flags.isAseMips16())</div>
<div>+      EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;</div>
<div>+    else if (Flags.isAseMicroMips())</div>
<div>+      EFlags |= ELF::EF_MIPS_ARCH_ASE_M16;</div>
<div>+    else</div>
<div>+      EFlags |= ELF::EF_MIPS_NOREORDER;</div>
<div>+</div>
<div>+    // Architecture</div>
<div>+    if (Flags.isArch64r2())</div>
<div>+      EFlags |= ELF::EF_MIPS_ARCH_64R2;</div>
<div>+    else if (Flags.isArch64r1())</div>
<div>+      EFlags |= ELF::EF_MIPS_ARCH_64;</div>
<div>+    else if (Flags.isArch32r2())</div>
<div>+      EFlags |= ELF::EF_MIPS_ARCH_32R2;</div>
<div>+    else</div>
<div>+      EFlags |= ELF::EF_MIPS_ARCH_32;</div>
<div>+</div>
<div>+    if (Flags.isAseMicroMips())</div>
<div>+      EFlags |= ELF::EF_MIPS_MICROMIPS;</div>
<div>+</div>
<div>+    // ABI</div>
<div>+    if (Flags.isAbiO32() || Flags.isAbiDefault())</div>
<div>+      EFlags |= ELF::EF_MIPS_ABI_O32;</div>
<div>+//    else if (Flags.isAbiN32())</div>
<div>+//      EFlags |= ELF::EF_MIPS_ABI2;</div>
<div>+//    else if (Flags.isAbiN64())</div>
<div>+//      EFlags |= ELF::EF_MIPS_ABI2;</div>
</blockquote>
<div><br>
</div>
<div>Please remove commented out code.</div>
<br>
<blockquote type="cite">
<div>+    else</div>
<div>+      llvm_unreachable("Unsupported ABI for e_flags");</div>
<div>+</div>
<div>+    // Relocation Model</div>
<div>+    // TODO: Need to add -mabicalls and -mno-abicalls flags.</div>
<div>+    // Currently we assume that -mabicalls is the default.</div>
<div>+    if (Flags.isModelCpic() || Flags.isModelDefault())</div>
<div>+      EFlags |= ELF::EF_MIPS_CPIC;</div>
<div>+    if (Flags.isModelPic() || Flags.isModelDefault())</div>
<div>+      EFlags |= ELF::EF_MIPS_PIC;</div>
<div>+    else if (Flags.isModelStatic())</div>
<div>+      ; // Do nothing for Reloc::Static</div>
<div>+    else</div>
<div>+      llvm_unreachable("Unsupported relocation model for e_flags");</div>
<div>+</div>
<div>+    MCA.setELFHeaderEFlags(EFlags);</div>
<div>+  }</div>
<div>+</div>
<div>   // For llc. Set a symbol's STO flags</div>
<div>   void</div>
<div>   MipsELFStreamer::emitMipsSTOCG(const MipsSubtarget &Subtarget,</div>
<div>Index: lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h</div>
<div>===================================================================</div>
<div>--- lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h<span class="Apple-tab-span" style="white-space:pre">
</span>(revision 188764)</div>
<div>+++ lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h<span class="Apple-tab-span" style="white-space:pre">
</span>(working copy)</div>
<div>@@ -13,6 +13,7 @@</div>
<div> </div>
<div> namespace llvm {</div>
<div> class MipsAsmPrinter;</div>
<div>+class MipsMCAsmFlags;</div>
<div> class MipsSubtarget;</div>
<div> class MCSymbol;</div>
<div> </div>
<div>@@ -26,6 +27,7 @@</div>
<div> </div>
<div>   ~MipsELFStreamer() {}</div>
<div>   void emitELFHeaderFlagsCG(const MipsSubtarget &Subtarget);</div>
<div>+  void emitELFHeaderFlagsAsm(const MipsMCAsmFlags &MAFlags);</div>
<div>   void emitMipsSTOCG(const MipsSubtarget &Subtarget,</div>
<div>                      MCSymbol *Sym,</div>
<div>                      unsigned Val);</div>
</blockquote>
<div>
<div><br>
</div>
</div>
<div>
<div>On Aug 20, 2013, at 7:28 AM, Vladimir Medic <<a href="mailto:Vladimir.Medic@imgtec.com" target="_blank">Vladimir.Medic@imgtec.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<div style="direction:ltr; font-family:Tahoma; font-size:10pt">
<pre style="margin-top:14pt; margin-bottom:14pt"><font face="Tahoma">The assembler effects changes to the ELF environment through commandline
options and inline directives. These need to be written out into the ELF
header's eflags.

The mechanism for this is through the MCELFStreamer. We have modeled the
assembler's version after the previously implemented codegen one.<br><br>I'm looking forward to your comments and remarks<br><br>Vladimir</font><br></pre>
</div>
<span><MipsElfFlags.patch></span>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>