]> granicus.if.org Git - llvm/commitdiff
[llvm] Implement support for -defsym assembler option
authorMandeep Singh Grang <mgrang@codeaurora.org>
Thu, 1 Dec 2016 18:42:04 +0000 (18:42 +0000)
committerMandeep Singh Grang <mgrang@codeaurora.org>
Thu, 1 Dec 2016 18:42:04 +0000 (18:42 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288396 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e637afb9871c8a9fb6175f2559059b0abb8927c4..4c1367343dbfb6c46bedcb836ead8f2ee0119a26 100644 (file)
@@ -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
index 7932fe441e3e84e8583a10ac7c072ed8cbb9d799..77fe015eefeec71e7bb78b4d20bb957a1e31c8c3 100644 (file)
@@ -260,6 +260,22 @@ MCSymbol *MCContext::lookupSymbol(const Twine &Name) 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
 //===----------------------------------------------------------------------===//
index 452777b05c58baf4bcf7aa26a7da1b10a0531804..8a904a8ad7cc9b656cb7f4cae7166422aac71044 100644 (file)
@@ -393,23 +393,10 @@ static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI,
   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;
 }