summaryrefslogtreecommitdiff
path: root/contrib/llvm/tools/llvm-mc/llvm-mc.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-06-10 19:12:52 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-06-10 19:12:52 +0000
commit97bc6c731eabb6212f094302b94f3f0f9534ebdf (patch)
tree471dda8f5419bb81beedeeef3b8975938d7e7340 /contrib/llvm/tools/llvm-mc/llvm-mc.cpp
parent3adc74c768226112b373d0bcacee73521b0aed2a (diff)
parent85d8b2bbe386bcfe669575d05b61482d7be07e5d (diff)
Notes
Diffstat (limited to 'contrib/llvm/tools/llvm-mc/llvm-mc.cpp')
-rw-r--r--contrib/llvm/tools/llvm-mc/llvm-mc.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/contrib/llvm/tools/llvm-mc/llvm-mc.cpp b/contrib/llvm/tools/llvm-mc/llvm-mc.cpp
index 6a8b49373df5..9a9185c7523c 100644
--- a/contrib/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/contrib/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -70,6 +70,9 @@ static cl::opt<bool>
PrintImmHex("print-imm-hex", cl::init(false),
cl::desc("Prefer hex format for immediate values"));
+static cl::list<std::string>
+DefineSymbol("defsym", cl::desc("Defines a symbol to be an integer constant"));
+
enum OutputFileType {
OFT_Null,
OFT_AssemblyFile,
@@ -316,6 +319,26 @@ 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;
+ 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;
+}
+
static int AssembleInput(const char *ProgName, const Target *TheTarget,
SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str,
MCAsmInfo &MAI, MCSubtargetInfo &STI,
@@ -331,6 +354,9 @@ static int AssembleInput(const char *ProgName, const Target *TheTarget,
return 1;
}
+ int SymbolResult = fillCommandLineSymbols(*Parser);
+ if(SymbolResult)
+ return SymbolResult;
Parser->setShowParsedOperands(ShowInstOperands);
Parser->setTargetParser(*TAP);