[llvm-commits] [llvm] r119972 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/MC/MCAsmStreamer.cpp lib/MC/MCParser/AsmParser.cpp lib/MC/MCStreamer.cpp

Rafael Espindola rafael.espindola at gmail.com
Mon Nov 22 06:27:24 PST 2010


Author: rafael
Date: Mon Nov 22 08:27:24 2010
New Revision: 119972

URL: http://llvm.org/viewvc/llvm-project?rev=119972&view=rev
Log:
Add basic CFI methods to the streamer interface.

Modified:
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/lib/MC/MCStreamer.cpp

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=119972&r1=119971&r2=119972&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Mon Nov 22 08:27:24 2010
@@ -352,6 +352,14 @@
                                        unsigned Isa,
                                        unsigned Discriminator);
 
+    virtual bool EmitCFIStartProc();
+    virtual bool EmitCFIEndProc();
+    virtual bool EmitCFIDefCfaOffset(int64_t Offset);
+    virtual bool EmitCFIDefCfaRegister(int64_t Register);
+    virtual bool EmitCFIOffset(int64_t Register, int64_t Offset);
+    virtual bool EmitCFIPersonality(const MCSymbol *Sym);
+    virtual bool EmitCFILsda(const MCSymbol *Sym);
+
     /// EmitInstruction - Emit the given @p Instruction into the current
     /// section.
     virtual void EmitInstruction(const MCInst &Inst) = 0;

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=119972&r1=119971&r2=119972&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Mon Nov 22 08:27:24 2010
@@ -177,6 +177,14 @@
                                      unsigned Column, unsigned Flags,
                                      unsigned Isa, unsigned Discriminator);
 
+  virtual bool EmitCFIStartProc();
+  virtual bool EmitCFIEndProc();
+  virtual bool EmitCFIDefCfaOffset(int64_t Offset);
+  virtual bool EmitCFIDefCfaRegister(int64_t Register);
+  virtual bool EmitCFIOffset(int64_t Register, int64_t Offset);
+  virtual bool EmitCFIPersonality(const MCSymbol *Sym);
+  virtual bool EmitCFILsda(const MCSymbol *Sym);
+
   virtual void EmitInstruction(const MCInst &Inst);
 
   /// EmitRawText - If this file is backed by an assembly streamer, this dumps
@@ -702,6 +710,76 @@
   EmitEOL();
 }
 
+bool MCAsmStreamer::EmitCFIStartProc() {
+  if (this->MCStreamer::EmitCFIStartProc())
+    return true;
+
+  OS << ".cfi_startproc";
+  EmitEOL();
+
+  return false;
+}
+
+bool MCAsmStreamer::EmitCFIEndProc() {
+  if (this->MCStreamer::EmitCFIEndProc())
+    return true;
+
+  OS << ".cfi_endproc";
+  EmitEOL();
+
+  return false;
+}
+
+bool MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
+  if (this->MCStreamer::EmitCFIDefCfaOffset(Offset))
+    return true;
+
+  OS << ".cfi_def_cfa_offset " << Offset;
+  EmitEOL();
+
+  return false;
+}
+
+bool MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
+  if (this->MCStreamer::EmitCFIDefCfaRegister(Register))
+    return true;
+
+  OS << ".cfi_def_cfa_register " << Register;
+  EmitEOL();
+
+  return false;
+}
+
+bool MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
+  if (this->MCStreamer::EmitCFIOffset(Register, Offset))
+    return true;
+
+  OS << ".cfi_offset " << Register << ", " << Offset;
+  EmitEOL();
+
+  return false;
+}
+
+bool MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym) {
+  if (this->MCStreamer::EmitCFIPersonality(Sym))
+    return true;
+
+  OS << ".cfi_personality 0, " << *Sym;
+  EmitEOL();
+
+  return false;
+}
+
+bool MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym) {
+  if (this->MCStreamer::EmitCFILsda(Sym))
+    return true;
+
+  OS << ".cfi_lsda 0, " << *Sym;
+  EmitEOL();
+
+  return false;
+}
+
 void MCAsmStreamer::AddEncodingComment(const MCInst &Inst) {
   raw_ostream &OS = GetCommentOS();
   SmallString<256> Code;

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=119972&r1=119971&r2=119972&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Mon Nov 22 08:27:24 2010
@@ -2151,13 +2151,13 @@
 /// ::= .cfi_startproc
 bool GenericAsmParser::ParseDirectiveCFIStartProc(StringRef,
                                                   SMLoc DirectiveLoc) {
-  return false;
+  return getStreamer().EmitCFIStartProc();
 }
 
 /// ParseDirectiveCFIEndProc
 /// ::= .cfi_endproc
 bool GenericAsmParser::ParseDirectiveCFIEndProc(StringRef, SMLoc DirectiveLoc) {
-  return false;
+  return getStreamer().EmitCFIEndProc();
 }
 
 /// ParseDirectiveCFIDefCfaOffset
@@ -2168,7 +2168,7 @@
   if (getParser().ParseAbsoluteExpression(Offset))
     return true;
 
-  return false;
+  return getStreamer().EmitCFIDefCfaOffset(Offset);
 }
 
 /// ParseDirectiveCFIDefCfaRegister
@@ -2178,7 +2178,8 @@
   int64_t Register = 0;
   if (getParser().ParseAbsoluteExpression(Register))
     return true;
-  return false;
+
+  return getStreamer().EmitCFIDefCfaRegister(Register);
 }
 
 /// ParseDirectiveCFIOffset
@@ -2196,13 +2197,13 @@
   if (getParser().ParseAbsoluteExpression(Offset))
     return true;
 
-  return false;
+  return getStreamer().EmitCFIOffset(Register, Offset);
 }
 
 /// ParseDirectiveCFIPersonalityOrLsda
 /// ::= .cfi_personality encoding, [symbol_name]
 /// ::= .cfi_lsda encoding, [symbol_name]
-bool GenericAsmParser::ParseDirectiveCFIPersonalityOrLsda(StringRef,
+bool GenericAsmParser::ParseDirectiveCFIPersonalityOrLsda(StringRef IDVal,
                                                     SMLoc DirectiveLoc) {
   int64_t Encoding = 0;
   if (getParser().ParseAbsoluteExpression(Encoding))
@@ -2210,6 +2211,9 @@
   if (Encoding == 255)
     return false;
 
+  if (Encoding != 0)
+    return TokError("unsupported encoding.");
+
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
   Lex();
@@ -2217,7 +2221,15 @@
   StringRef Name;
   if (getParser().ParseIdentifier(Name))
     return TokError("expected identifier in directive");
-  return false;
+
+  MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+
+  if (IDVal == ".cfi_personality")
+    return getStreamer().EmitCFIPersonality(Sym);
+  else {
+    assert(IDVal == ".cfi_lsda");
+    return getStreamer().EmitCFILsda(Sym);
+  }
 }
 
 /// ParseDirectiveMacrosOnOff

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=119972&r1=119971&r2=119972&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Mon Nov 22 08:27:24 2010
@@ -77,6 +77,34 @@
                                   Discriminator);
 }
 
+bool MCStreamer::EmitCFIStartProc() {
+  return false;
+}
+
+bool MCStreamer::EmitCFIEndProc() {
+  return false;
+}
+
+bool MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
+  return false;
+}
+
+bool MCStreamer::EmitCFIDefCfaRegister(int64_t Register) {
+  return false;
+}
+
+bool MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
+  return false;
+}
+
+bool MCStreamer::EmitCFIPersonality(const MCSymbol *Sym) {
+  return false;
+}
+
+bool MCStreamer::EmitCFILsda(const MCSymbol *Sym) {
+  return false;
+}
+
 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
 /// the specified string in the output .s file.  This capability is
 /// indicated by the hasRawTextSupport() predicate.





More information about the llvm-commits mailing list