From 32360071a075c24f1ce133c9566b7bbd32b12578 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Grang Date: Thu, 1 Dec 2016 18:42:04 +0000 Subject: [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 llvm-svn: 288396 --- llvm/lib/MC/MCContext.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'llvm/lib/MC/MCContext.cpp') diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 7932fe441e3..77fe015eefe 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -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 //===----------------------------------------------------------------------===// -- cgit v1.2.3