[llvm] r288396 - [llvm] Implement support for -defsym assembler option

Mandeep Singh Grang via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 10:42:04 PST 2016


Author: mgrang
Date: Thu Dec  1 12:42:04 2016
New Revision: 288396

URL: http://llvm.org/viewvc/llvm-project?rev=288396&view=rev
Log:
[llvm] Implement support for -defsym assembler option

Summary:
Changes to llvm-mc to move common logic to separate function.

Related clang patch: https://reviews.llvm.org/D26213

Reviewers: rafael, t.p.northover, colinl, echristo, rengolin

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D26214

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/lib/MC/MCContext.cpp
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=288396&r1=288395&r2=288396&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Thu Dec  1 12:42:04 2016
@@ -302,6 +302,9 @@ namespace llvm {
     /// Get the symbol for \p Name, or null.
     MCSymbol *lookupSymbol(const Twine &Name) const;
 
+    /// Set value for a symbol.
+    int setSymbolValue(MCStreamer &Streamer, std::string &I);
+
     /// getSymbols - Get a reference for the symbol table for clients that
     /// want to, for example, iterate over all symbols. 'const' because we
     /// still want any modifications to the table itself to use the MCContext

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=288396&r1=288395&r2=288396&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu Dec  1 12:42:04 2016
@@ -260,6 +260,22 @@ MCSymbol *MCContext::lookupSymbol(const
   return Symbols.lookup(NameRef);
 }
 
+int MCContext::setSymbolValue(MCStreamer &Streamer, std::string &I) {
+    auto Pair = StringRef(I).split('=');
+    if (Pair.second.empty()) {
+      errs() << "error: defsym must be of the form: sym=value: " << I << "\n";
+      return 1;
+    }
+    int64_t Value;
+    if (Pair.second.getAsInteger(0, Value)) {
+      errs() << "error: Value is not an integer: " << Pair.second << "\n";
+      return 1;
+    }
+    auto Symbol = getOrCreateSymbol(Pair.first);
+    Streamer.EmitAssignment(Symbol, MCConstantExpr::create(Value, *this));
+    return 0;
+}
+
 //===----------------------------------------------------------------------===//
 // Section Management
 //===----------------------------------------------------------------------===//

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=288396&r1=288395&r2=288396&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Thu Dec  1 12:42:04 2016
@@ -393,23 +393,10 @@ static int AsLexInput(SourceMgr &SrcMgr,
   return Error;
 }
 
-static int fillCommandLineSymbols(MCAsmParser &Parser){
-  for(auto &I: DefineSymbol){
-    auto Pair = StringRef(I).split('=');
-    if(Pair.second.empty()){
-      errs() << "error: defsym must be of the form: sym=value: " << I;
+static int fillCommandLineSymbols(MCAsmParser &Parser) {
+  for (auto &I: DefineSymbol)
+    if (Parser.getContext().setSymbolValue(Parser.getStreamer(), I))
       return 1;
-    }
-    int64_t Value;
-    if(Pair.second.getAsInteger(0, Value)){
-      errs() << "error: Value is not an integer: " << Pair.second;
-      return 1;
-    }
-    auto &Context = Parser.getContext();
-    auto Symbol = Context.getOrCreateSymbol(Pair.first);
-    Parser.getStreamer().EmitAssignment(Symbol,
-                                        MCConstantExpr::create(Value, Context));
-  }
   return 0;
 }
 




More information about the llvm-commits mailing list