diff options
Diffstat (limited to 'contrib/llvm/tools/llvm-mc/llvm-mc.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-mc/llvm-mc.cpp | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/contrib/llvm/tools/llvm-mc/llvm-mc.cpp b/contrib/llvm/tools/llvm-mc/llvm-mc.cpp index 78fe9b7..9a9185c 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); @@ -357,6 +383,7 @@ int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); TripleName = Triple::normalize(TripleName); + Triple TheTriple(TripleName); setDwarfDebugFlags(argc, argv); setDwarfDebugProducer(); @@ -438,7 +465,8 @@ int main(int argc, char **argv) { if (!Out) return 1; - formatted_raw_ostream FOS(Out->os()); + std::unique_ptr<buffer_ostream> BOS; + raw_pwrite_stream *OS = &Out->os(); std::unique_ptr<MCStreamer> Str; std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo()); @@ -447,8 +475,8 @@ int main(int argc, char **argv) { MCInstPrinter *IP = nullptr; if (FileType == OFT_AssemblyFile) { - IP = - TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MCII, *MRI, *STI); + IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant, + *MAI, *MCII, *MRI); // Set the display preference for hex vs. decimal immediates. IP->setPrintImmHex(PrintImmHex); @@ -457,21 +485,29 @@ int main(int argc, char **argv) { MCCodeEmitter *CE = nullptr; MCAsmBackend *MAB = nullptr; if (ShowEncoding) { - CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx); + CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx); MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU); } - Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, /*asmverbose*/ true, - /*useDwarfDirectory*/ true, IP, CE, - MAB, ShowInst)); + auto FOut = llvm::make_unique<formatted_raw_ostream>(*OS); + Str.reset(TheTarget->createAsmStreamer( + Ctx, std::move(FOut), /*asmverbose*/ true, + /*useDwarfDirectory*/ true, IP, CE, MAB, ShowInst)); } else if (FileType == OFT_Null) { - Str.reset(createNullStreamer(Ctx)); + Str.reset(TheTarget->createNullStreamer(Ctx)); } else { assert(FileType == OFT_ObjectFile && "Invalid file type!"); - MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx); + + if (!Out->os().supportsSeeking()) { + BOS = make_unique<buffer_ostream>(Out->os()); + OS = BOS.get(); + } + + MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx); MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU); - Str.reset(TheTarget->createMCObjectStreamer(TripleName, Ctx, *MAB, FOS, CE, - *STI, RelaxAll)); + Str.reset(TheTarget->createMCObjectStreamer(TheTriple, Ctx, *MAB, *OS, CE, + *STI, RelaxAll, + /*DWARFMustBeAtTheEnd*/ false)); if (NoExecStack) Str->InitSections(true); } |