]> granicus.if.org Git - llvm/commitdiff
[llvm] Fix D26214: Move error handling out of MC and to the callers.
authorMandeep Singh Grang <mgrang@codeaurora.org>
Tue, 6 Dec 2016 02:49:17 +0000 (02:49 +0000)
committerMandeep Singh Grang <mgrang@codeaurora.org>
Tue, 6 Dec 2016 02:49:17 +0000 (02:49 +0000)
Summary: Related clang patch; https://reviews.llvm.org/D27360

Reviewers: t.p.northover, grosbach, compnerd, echristo

Subscribers: compnerd, mehdi_amini, llvm-commits

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

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

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

index 2ce2780d4f22e81f14b826f533e5d871d8bc71f1..aa302dbe0a218f168fd44614b44ac04de290c196 100644 (file)
@@ -303,7 +303,7 @@ namespace llvm {
     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 afe8ee84918e3218ec2667630b02bfb23306d10f..8298aff928ccf5accdc5fea983576d7902fe8f5e 100644 (file)
@@ -260,20 +260,11 @@ 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;
+void MCContext::setSymbolValue(MCStreamer &Streamer,
+                              StringRef Sym,
+                              uint64_t Val) {
+  auto Symbol = getOrCreateSymbol(Sym);
+  Streamer.EmitAssignment(Symbol, MCConstantExpr::create(Val, *this));
 }
 
 //===----------------------------------------------------------------------===//
index 8a904a8ad7cc9b656cb7f4cae7166422aac71044..497fb1987764e4a36f8ef2025b9769a55030923b 100644 (file)
@@ -394,9 +394,22 @@ static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI,
 }
 
 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;
 }