[PATCH] D26214: [llvm] Implement support for -defsym assembler option
Mandeep Singh Grang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 1 10:52:20 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288396: [llvm] Implement support for -defsym assembler option (authored by mgrang).
Changed prior to commit:
https://reviews.llvm.org/D26214?vs=77090&id=79948#toc
Repository:
rL LLVM
https://reviews.llvm.org/D26214
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/lib/MC/MCContext.cpp
===================================================================
--- llvm/trunk/lib/MC/MCContext.cpp
+++ llvm/trunk/lib/MC/MCContext.cpp
@@ -260,6 +260,22 @@
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: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
===================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp
@@ -393,23 +393,10 @@
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;
}
Index: llvm/trunk/include/llvm/MC/MCContext.h
===================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h
+++ llvm/trunk/include/llvm/MC/MCContext.h
@@ -302,6 +302,9 @@
/// 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26214.79948.patch
Type: text/x-patch
Size: 2704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161201/ddd98c9f/attachment.bin>
More information about the llvm-commits
mailing list