mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-07-05 13:29:22 +00:00
Teaching llvm-mc how to understand the defsym command line option. This allows integer-constant symbols to be defined on the command line and used during assembly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239240 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
86a28d87b1
commit
4514db2bfb
20
test/MC/AsmParser/defsym.s
Normal file
20
test/MC/AsmParser/defsym.s
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# RUN: llvm-mc -filetype=obj -triple=i386-unknown-elf -defsym a=7 -defsym b=11 %s | llvm-objdump -t - | FileCheck %s
|
||||||
|
|
||||||
|
.ifndef a
|
||||||
|
.err
|
||||||
|
.endif
|
||||||
|
|
||||||
|
.if a<>7
|
||||||
|
.err
|
||||||
|
.endif
|
||||||
|
|
||||||
|
.ifndef b
|
||||||
|
.err
|
||||||
|
.endif
|
||||||
|
|
||||||
|
.if b<>11
|
||||||
|
.err
|
||||||
|
.endif
|
||||||
|
|
||||||
|
# CHECK: 00000007 *ABS* 00000000 a
|
||||||
|
# CHECK: 0000000b *ABS* 00000000 b
|
2
test/MC/AsmParser/defsym_error1.s
Normal file
2
test/MC/AsmParser/defsym_error1.s
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# RUN: not llvm-mc -filetype=obj -triple=i386-unknown-elf -defsym aaoeuaoeu %s 2>&1 | FileCheck %s
|
||||||
|
# CHECK: defsym must be of the form: sym=value
|
2
test/MC/AsmParser/defsym_error2.s
Normal file
2
test/MC/AsmParser/defsym_error2.s
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# RUN: not llvm-mc -filetype=obj -triple=i386-unknown-elf -defsym a=a %s 2>&1 | FileCheck %s
|
||||||
|
# CHECK: error: Value is not an integer: a
|
@ -70,6 +70,9 @@ static cl::opt<bool>
|
|||||||
PrintImmHex("print-imm-hex", cl::init(false),
|
PrintImmHex("print-imm-hex", cl::init(false),
|
||||||
cl::desc("Prefer hex format for immediate values"));
|
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 {
|
enum OutputFileType {
|
||||||
OFT_Null,
|
OFT_Null,
|
||||||
OFT_AssemblyFile,
|
OFT_AssemblyFile,
|
||||||
@ -316,6 +319,26 @@ static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI,
|
|||||||
return Error;
|
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,
|
static int AssembleInput(const char *ProgName, const Target *TheTarget,
|
||||||
SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str,
|
SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str,
|
||||||
MCAsmInfo &MAI, MCSubtargetInfo &STI,
|
MCAsmInfo &MAI, MCSubtargetInfo &STI,
|
||||||
@ -331,6 +354,9 @@ static int AssembleInput(const char *ProgName, const Target *TheTarget,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SymbolResult = fillCommandLineSymbols(*Parser);
|
||||||
|
if(SymbolResult)
|
||||||
|
return SymbolResult;
|
||||||
Parser->setShowParsedOperands(ShowInstOperands);
|
Parser->setShowParsedOperands(ShowInstOperands);
|
||||||
Parser->setTargetParser(*TAP);
|
Parser->setTargetParser(*TAP);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user