[PATCH] D27359: [llvm] Fix D26214: Move error handling out of MC and to the callers.

Mandeep Singh Grang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 18:59:42 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL288763: [llvm] Fix D26214: Move error handling out of MC and to the callers. (authored by mgrang).

Changed prior to commit:
  https://reviews.llvm.org/D27359?vs=80113&id=80370#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27359

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


Index: llvm/trunk/include/llvm/MC/MCContext.h
===================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h
+++ llvm/trunk/include/llvm/MC/MCContext.h
@@ -303,7 +303,7 @@
     MCSymbol *lookupSymbol(const Twine &Name) const;
 
     /// Set value for a symbol.
-    int setSymbolValue(MCStreamer &Streamer, std::string &I);
+    void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val);
 
     /// getSymbols - Get a reference for the symbol table for clients that
     /// want to, for example, iterate over all symbols. 'const' because we
Index: llvm/trunk/lib/MC/MCContext.cpp
===================================================================
--- llvm/trunk/lib/MC/MCContext.cpp
+++ llvm/trunk/lib/MC/MCContext.cpp
@@ -260,20 +260,11 @@
   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;
+void MCContext::setSymbolValue(MCStreamer &Streamer,
+                              StringRef Sym,
+                              uint64_t Val) {
+  auto Symbol = getOrCreateSymbol(Sym);
+  Streamer.EmitAssignment(Symbol, MCConstantExpr::create(Val, *this));
 }
 
 //===----------------------------------------------------------------------===//
Index: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
===================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp
@@ -394,9 +394,22 @@
 }
 
 static int fillCommandLineSymbols(MCAsmParser &Parser) {
-  for (auto &I: DefineSymbol)
-    if (Parser.getContext().setSymbolValue(Parser.getStreamer(), I))
+  for (auto &I: DefineSymbol) {
+    auto Pair = StringRef(I).split('=');
+    auto Sym = Pair.first;
+    auto Val = Pair.second;
+
+    if (Sym.empty() || Val.empty()) {
+      errs() << "error: defsym must be of the form: sym=value: " << I << "\n";
+      return 1;
+    }
+    int64_t Value;
+    if (Val.getAsInteger(0, Value)) {
+      errs() << "error: Value is not an integer: " << Val << "\n";
       return 1;
+    }
+    Parser.getContext().setSymbolValue(Parser.getStreamer(), Sym, Value);
+  }
   return 0;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27359.80370.patch
Type: text/x-patch
Size: 2653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161206/1a82e3d8/attachment.bin>


More information about the llvm-commits mailing list