diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/llvm12/tools/llvm-ml | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/tools/llvm-ml')
-rw-r--r-- | contrib/libs/llvm12/tools/llvm-ml/Disassembler.cpp | 406 | ||||
-rw-r--r-- | contrib/libs/llvm12/tools/llvm-ml/Disassembler.h | 74 | ||||
-rw-r--r-- | contrib/libs/llvm12/tools/llvm-ml/llvm-ml.cpp | 414 | ||||
-rw-r--r-- | contrib/libs/llvm12/tools/llvm-ml/ya.make | 44 |
4 files changed, 469 insertions, 469 deletions
diff --git a/contrib/libs/llvm12/tools/llvm-ml/Disassembler.cpp b/contrib/libs/llvm12/tools/llvm-ml/Disassembler.cpp index 8eeddb7179..a7fec3c35d 100644 --- a/contrib/libs/llvm12/tools/llvm-ml/Disassembler.cpp +++ b/contrib/libs/llvm12/tools/llvm-ml/Disassembler.cpp @@ -1,203 +1,203 @@ -//===- Disassembler.cpp - Disassembler for hex strings --------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This class implements the disassembler of strings of bytes written in -// hexadecimal, from standard input or from a file. -// -//===----------------------------------------------------------------------===// - -#include "Disassembler.h" -#include "llvm/ADT/Triple.h" -#include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCContext.h" -#include "llvm/MC/MCDisassembler/MCDisassembler.h" -#include "llvm/MC/MCInst.h" -#include "llvm/MC/MCRegisterInfo.h" -#include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSubtargetInfo.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/raw_ostream.h" - -using namespace llvm; - -typedef std::pair<std::vector<unsigned char>, std::vector<const char *>> - ByteArrayTy; - -static bool PrintInsts(const MCDisassembler &DisAsm, const ByteArrayTy &Bytes, - SourceMgr &SM, raw_ostream &Out, MCStreamer &Streamer, - bool InAtomicBlock, const MCSubtargetInfo &STI) { - ArrayRef<uint8_t> Data(Bytes.first.data(), Bytes.first.size()); - - // Disassemble it to strings. - uint64_t Size; - uint64_t Index; - - for (Index = 0; Index < Bytes.first.size(); Index += Size) { - MCInst Inst; - - MCDisassembler::DecodeStatus S; - S = DisAsm.getInstruction(Inst, Size, Data.slice(Index), Index, nulls()); - switch (S) { - case MCDisassembler::Fail: - SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]), - SourceMgr::DK_Warning, "invalid instruction encoding"); - // Don't try to resynchronise the stream in a block - if (InAtomicBlock) - return true; - - if (Size == 0) - Size = 1; // skip illegible bytes - - break; - - case MCDisassembler::SoftFail: - SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]), - SourceMgr::DK_Warning, - "potentially undefined instruction encoding"); - LLVM_FALLTHROUGH; - - case MCDisassembler::Success: - Streamer.emitInstruction(Inst, STI); - break; - } - } - - return false; -} - -static bool SkipToToken(StringRef &Str) { - for (;;) { - if (Str.empty()) - return false; - - // Strip horizontal whitespace and commas. - if (size_t Pos = Str.find_first_not_of(" \t\r\n,")) { - Str = Str.substr(Pos); - continue; - } - - // If this is the start of a comment, remove the rest of the line. - if (Str[0] == '#') { - Str = Str.substr(Str.find_first_of('\n')); - continue; - } - return true; - } -} - -static bool ByteArrayFromString(ByteArrayTy &ByteArray, StringRef &Str, - SourceMgr &SM) { - while (SkipToToken(Str)) { - // Handled by higher level - if (Str[0] == '[' || Str[0] == ']') - return false; - - // Get the current token. - size_t Next = Str.find_first_of(" \t\n\r,#[]"); - StringRef Value = Str.substr(0, Next); - - // Convert to a byte and add to the byte vector. - unsigned ByteVal; - if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) { - // If we have an error, print it and skip to the end of line. - SM.PrintMessage(SMLoc::getFromPointer(Value.data()), SourceMgr::DK_Error, - "invalid input token"); - Str = Str.substr(Str.find('\n')); - ByteArray.first.clear(); - ByteArray.second.clear(); - continue; - } - - ByteArray.first.push_back(ByteVal); - ByteArray.second.push_back(Value.data()); - Str = Str.substr(Next); - } - - return false; -} - -int Disassembler::disassemble(const Target &T, const std::string &Triple, - MCSubtargetInfo &STI, MCStreamer &Streamer, - MemoryBuffer &Buffer, SourceMgr &SM, - raw_ostream &Out) { - std::unique_ptr<const MCRegisterInfo> MRI(T.createMCRegInfo(Triple)); - if (!MRI) { - errs() << "error: no register info for target " << Triple << "\n"; - return -1; - } - - MCTargetOptions MCOptions; - std::unique_ptr<const MCAsmInfo> MAI( - T.createMCAsmInfo(*MRI, Triple, MCOptions)); - if (!MAI) { - errs() << "error: no assembly info for target " << Triple << "\n"; - return -1; - } - - // Set up the MCContext for creating symbols and MCExpr's. - MCContext Ctx(MAI.get(), MRI.get(), nullptr); - - std::unique_ptr<const MCDisassembler> DisAsm( - T.createMCDisassembler(STI, Ctx)); - if (!DisAsm) { - errs() << "error: no disassembler for target " << Triple << "\n"; - return -1; - } - - // Set up initial section manually here - Streamer.InitSections(false); - - bool ErrorOccurred = false; - - // Convert the input to a vector for disassembly. - ByteArrayTy ByteArray; - StringRef Str = Buffer.getBuffer(); - bool InAtomicBlock = false; - - while (SkipToToken(Str)) { - ByteArray.first.clear(); - ByteArray.second.clear(); - - if (Str[0] == '[') { - if (InAtomicBlock) { - SM.PrintMessage(SMLoc::getFromPointer(Str.data()), SourceMgr::DK_Error, - "nested atomic blocks make no sense"); - ErrorOccurred = true; - } - InAtomicBlock = true; - Str = Str.drop_front(); - continue; - } else if (Str[0] == ']') { - if (!InAtomicBlock) { - SM.PrintMessage(SMLoc::getFromPointer(Str.data()), SourceMgr::DK_Error, - "attempt to close atomic block without opening"); - ErrorOccurred = true; - } - InAtomicBlock = false; - Str = Str.drop_front(); - continue; - } - - // It's a real token, get the bytes and emit them - ErrorOccurred |= ByteArrayFromString(ByteArray, Str, SM); - - if (!ByteArray.first.empty()) - ErrorOccurred |= - PrintInsts(*DisAsm, ByteArray, SM, Out, Streamer, InAtomicBlock, STI); - } - - if (InAtomicBlock) { - SM.PrintMessage(SMLoc::getFromPointer(Str.data()), SourceMgr::DK_Error, - "unclosed atomic block"); - ErrorOccurred = true; - } - - return ErrorOccurred; -} +//===- Disassembler.cpp - Disassembler for hex strings --------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This class implements the disassembler of strings of bytes written in +// hexadecimal, from standard input or from a file. +// +//===----------------------------------------------------------------------===// + +#include "Disassembler.h" +#include "llvm/ADT/Triple.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCDisassembler/MCDisassembler.h" +#include "llvm/MC/MCInst.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +typedef std::pair<std::vector<unsigned char>, std::vector<const char *>> + ByteArrayTy; + +static bool PrintInsts(const MCDisassembler &DisAsm, const ByteArrayTy &Bytes, + SourceMgr &SM, raw_ostream &Out, MCStreamer &Streamer, + bool InAtomicBlock, const MCSubtargetInfo &STI) { + ArrayRef<uint8_t> Data(Bytes.first.data(), Bytes.first.size()); + + // Disassemble it to strings. + uint64_t Size; + uint64_t Index; + + for (Index = 0; Index < Bytes.first.size(); Index += Size) { + MCInst Inst; + + MCDisassembler::DecodeStatus S; + S = DisAsm.getInstruction(Inst, Size, Data.slice(Index), Index, nulls()); + switch (S) { + case MCDisassembler::Fail: + SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]), + SourceMgr::DK_Warning, "invalid instruction encoding"); + // Don't try to resynchronise the stream in a block + if (InAtomicBlock) + return true; + + if (Size == 0) + Size = 1; // skip illegible bytes + + break; + + case MCDisassembler::SoftFail: + SM.PrintMessage(SMLoc::getFromPointer(Bytes.second[Index]), + SourceMgr::DK_Warning, + "potentially undefined instruction encoding"); + LLVM_FALLTHROUGH; + + case MCDisassembler::Success: + Streamer.emitInstruction(Inst, STI); + break; + } + } + + return false; +} + +static bool SkipToToken(StringRef &Str) { + for (;;) { + if (Str.empty()) + return false; + + // Strip horizontal whitespace and commas. + if (size_t Pos = Str.find_first_not_of(" \t\r\n,")) { + Str = Str.substr(Pos); + continue; + } + + // If this is the start of a comment, remove the rest of the line. + if (Str[0] == '#') { + Str = Str.substr(Str.find_first_of('\n')); + continue; + } + return true; + } +} + +static bool ByteArrayFromString(ByteArrayTy &ByteArray, StringRef &Str, + SourceMgr &SM) { + while (SkipToToken(Str)) { + // Handled by higher level + if (Str[0] == '[' || Str[0] == ']') + return false; + + // Get the current token. + size_t Next = Str.find_first_of(" \t\n\r,#[]"); + StringRef Value = Str.substr(0, Next); + + // Convert to a byte and add to the byte vector. + unsigned ByteVal; + if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) { + // If we have an error, print it and skip to the end of line. + SM.PrintMessage(SMLoc::getFromPointer(Value.data()), SourceMgr::DK_Error, + "invalid input token"); + Str = Str.substr(Str.find('\n')); + ByteArray.first.clear(); + ByteArray.second.clear(); + continue; + } + + ByteArray.first.push_back(ByteVal); + ByteArray.second.push_back(Value.data()); + Str = Str.substr(Next); + } + + return false; +} + +int Disassembler::disassemble(const Target &T, const std::string &Triple, + MCSubtargetInfo &STI, MCStreamer &Streamer, + MemoryBuffer &Buffer, SourceMgr &SM, + raw_ostream &Out) { + std::unique_ptr<const MCRegisterInfo> MRI(T.createMCRegInfo(Triple)); + if (!MRI) { + errs() << "error: no register info for target " << Triple << "\n"; + return -1; + } + + MCTargetOptions MCOptions; + std::unique_ptr<const MCAsmInfo> MAI( + T.createMCAsmInfo(*MRI, Triple, MCOptions)); + if (!MAI) { + errs() << "error: no assembly info for target " << Triple << "\n"; + return -1; + } + + // Set up the MCContext for creating symbols and MCExpr's. + MCContext Ctx(MAI.get(), MRI.get(), nullptr); + + std::unique_ptr<const MCDisassembler> DisAsm( + T.createMCDisassembler(STI, Ctx)); + if (!DisAsm) { + errs() << "error: no disassembler for target " << Triple << "\n"; + return -1; + } + + // Set up initial section manually here + Streamer.InitSections(false); + + bool ErrorOccurred = false; + + // Convert the input to a vector for disassembly. + ByteArrayTy ByteArray; + StringRef Str = Buffer.getBuffer(); + bool InAtomicBlock = false; + + while (SkipToToken(Str)) { + ByteArray.first.clear(); + ByteArray.second.clear(); + + if (Str[0] == '[') { + if (InAtomicBlock) { + SM.PrintMessage(SMLoc::getFromPointer(Str.data()), SourceMgr::DK_Error, + "nested atomic blocks make no sense"); + ErrorOccurred = true; + } + InAtomicBlock = true; + Str = Str.drop_front(); + continue; + } else if (Str[0] == ']') { + if (!InAtomicBlock) { + SM.PrintMessage(SMLoc::getFromPointer(Str.data()), SourceMgr::DK_Error, + "attempt to close atomic block without opening"); + ErrorOccurred = true; + } + InAtomicBlock = false; + Str = Str.drop_front(); + continue; + } + + // It's a real token, get the bytes and emit them + ErrorOccurred |= ByteArrayFromString(ByteArray, Str, SM); + + if (!ByteArray.first.empty()) + ErrorOccurred |= + PrintInsts(*DisAsm, ByteArray, SM, Out, Streamer, InAtomicBlock, STI); + } + + if (InAtomicBlock) { + SM.PrintMessage(SMLoc::getFromPointer(Str.data()), SourceMgr::DK_Error, + "unclosed atomic block"); + ErrorOccurred = true; + } + + return ErrorOccurred; +} diff --git a/contrib/libs/llvm12/tools/llvm-ml/Disassembler.h b/contrib/libs/llvm12/tools/llvm-ml/Disassembler.h index d3565089e2..f54bab3239 100644 --- a/contrib/libs/llvm12/tools/llvm-ml/Disassembler.h +++ b/contrib/libs/llvm12/tools/llvm-ml/Disassembler.h @@ -1,37 +1,37 @@ -//===- Disassembler.h - Text File Disassembler ----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This class implements the disassembler of strings of bytes written in -// hexadecimal, from standard input or from a file. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_LLVM_MC_DISASSEMBLER_H -#define LLVM_TOOLS_LLVM_MC_DISASSEMBLER_H - -#include <string> - -namespace llvm { - -class MemoryBuffer; -class Target; -class raw_ostream; -class SourceMgr; -class MCSubtargetInfo; -class MCStreamer; - -class Disassembler { -public: - static int disassemble(const Target &T, const std::string &Triple, - MCSubtargetInfo &STI, MCStreamer &Streamer, - MemoryBuffer &Buffer, SourceMgr &SM, raw_ostream &Out); -}; - -} // namespace llvm - -#endif +//===- Disassembler.h - Text File Disassembler ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This class implements the disassembler of strings of bytes written in +// hexadecimal, from standard input or from a file. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVM_MC_DISASSEMBLER_H +#define LLVM_TOOLS_LLVM_MC_DISASSEMBLER_H + +#include <string> + +namespace llvm { + +class MemoryBuffer; +class Target; +class raw_ostream; +class SourceMgr; +class MCSubtargetInfo; +class MCStreamer; + +class Disassembler { +public: + static int disassemble(const Target &T, const std::string &Triple, + MCSubtargetInfo &STI, MCStreamer &Streamer, + MemoryBuffer &Buffer, SourceMgr &SM, raw_ostream &Out); +}; + +} // namespace llvm + +#endif diff --git a/contrib/libs/llvm12/tools/llvm-ml/llvm-ml.cpp b/contrib/libs/llvm12/tools/llvm-ml/llvm-ml.cpp index 1733dcd472..8ac253723e 100644 --- a/contrib/libs/llvm12/tools/llvm-ml/llvm-ml.cpp +++ b/contrib/libs/llvm12/tools/llvm-ml/llvm-ml.cpp @@ -1,52 +1,52 @@ -//===-- llvm-ml.cpp - masm-compatible assembler -----------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// A simple driver around MasmParser; based on llvm-mc. -// -//===----------------------------------------------------------------------===// - +//===-- llvm-ml.cpp - masm-compatible assembler -----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// A simple driver around MasmParser; based on llvm-mc. +// +//===----------------------------------------------------------------------===// + #include "llvm/ADT/StringSwitch.h" -#include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCCodeEmitter.h" -#include "llvm/MC/MCContext.h" -#include "llvm/MC/MCInstPrinter.h" -#include "llvm/MC/MCInstrInfo.h" -#include "llvm/MC/MCObjectFileInfo.h" -#include "llvm/MC/MCObjectWriter.h" -#include "llvm/MC/MCParser/AsmLexer.h" -#include "llvm/MC/MCParser/MCTargetAsmParser.h" -#include "llvm/MC/MCRegisterInfo.h" -#include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSubtargetInfo.h" -#include "llvm/MC/MCTargetOptionsCommandFlags.h" +#include "llvm/MC/MCAsmBackend.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCCodeEmitter.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCObjectFileInfo.h" +#include "llvm/MC/MCObjectWriter.h" +#include "llvm/MC/MCParser/AsmLexer.h" +#include "llvm/MC/MCParser/MCTargetAsmParser.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/MC/MCTargetOptionsCommandFlags.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" -#include "llvm/Support/Compression.h" -#include "llvm/Support/FileUtilities.h" +#include "llvm/Support/Compression.h" +#include "llvm/Support/FileUtilities.h" #include "llvm/Support/FormatVariadic.h" -#include "llvm/Support/FormattedStream.h" -#include "llvm/Support/Host.h" -#include "llvm/Support/InitLLVM.h" -#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/FormattedStream.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Support/ToolOutputFile.h" -#include "llvm/Support/WithColor.h" - -using namespace llvm; +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/WithColor.h" + +using namespace llvm; using namespace llvm::opt; - + namespace { - + enum ID { OPT_INVALID = 0, // This is not an option ID. #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ @@ -54,12 +54,12 @@ enum ID { OPT_##ID, #include "Opts.inc" #undef OPTION -}; - +}; + #define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; #include "Opts.inc" #undef PREFIX - + static const opt::OptTable::Info InfoTable[] = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR, VALUES) \ @@ -70,83 +70,83 @@ static const opt::OptTable::Info InfoTable[] = { OPT_##ALIAS, ALIASARGS, VALUES}, #include "Opts.inc" #undef OPTION -}; - +}; + class MLOptTable : public opt::OptTable { public: MLOptTable() : OptTable(InfoTable, /*IgnoreCase=*/false) {} -}; +}; } // namespace - + static Triple GetTriple(StringRef ProgName, opt::InputArgList &Args) { - // Figure out the target triple. + // Figure out the target triple. StringRef DefaultBitness = "32"; SmallString<255> Program = ProgName; sys::path::replace_extension(Program, ""); if (Program.endswith("ml64")) DefaultBitness = "64"; - + StringRef TripleName = StringSwitch<StringRef>(Args.getLastArgValue(OPT_bitness, DefaultBitness)) .Case("32", "i386-pc-windows") .Case("64", "x86_64-pc-windows") .Default(""); return Triple(Triple::normalize(TripleName)); -} - -static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path) { - std::error_code EC; - auto Out = std::make_unique<ToolOutputFile>(Path, EC, sys::fs::F_None); - if (EC) { - WithColor::error() << EC.message() << '\n'; - return nullptr; - } - - return Out; -} - -static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI, raw_ostream &OS) { - AsmLexer Lexer(MAI); - Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())->getBuffer()); +} + +static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path) { + std::error_code EC; + auto Out = std::make_unique<ToolOutputFile>(Path, EC, sys::fs::F_None); + if (EC) { + WithColor::error() << EC.message() << '\n'; + return nullptr; + } + + return Out; +} + +static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI, raw_ostream &OS) { + AsmLexer Lexer(MAI); + Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())->getBuffer()); Lexer.setLexMasmIntegers(true); Lexer.useMasmDefaultRadix(true); Lexer.setLexMasmHexFloats(true); Lexer.setLexMasmStrings(true); - - bool Error = false; - while (Lexer.Lex().isNot(AsmToken::Eof)) { - Lexer.getTok().dump(OS); - OS << "\n"; - if (Lexer.getTok().getKind() == AsmToken::Error) - Error = true; - } - - return Error; -} - + + bool Error = false; + while (Lexer.Lex().isNot(AsmToken::Eof)) { + Lexer.getTok().dump(OS); + OS << "\n"; + if (Lexer.getTok().getKind() == AsmToken::Error) + Error = true; + } + + return Error; +} + static int AssembleInput(StringRef ProgName, const Target *TheTarget, - SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str, - MCAsmInfo &MAI, MCSubtargetInfo &STI, + SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str, + MCAsmInfo &MAI, MCSubtargetInfo &STI, MCInstrInfo &MCII, MCTargetOptions &MCOptions, const opt::ArgList &InputArgs) { - std::unique_ptr<MCAsmParser> Parser( + std::unique_ptr<MCAsmParser> Parser( createMCMasmParser(SrcMgr, Ctx, Str, MAI, 0)); - std::unique_ptr<MCTargetAsmParser> TAP( - TheTarget->createMCAsmParser(STI, *Parser, MCII, MCOptions)); - - if (!TAP) { - WithColor::error(errs(), ProgName) - << "this target does not support assembly parsing.\n"; - return 1; - } - + std::unique_ptr<MCTargetAsmParser> TAP( + TheTarget->createMCAsmParser(STI, *Parser, MCII, MCOptions)); + + if (!TAP) { + WithColor::error(errs(), ProgName) + << "this target does not support assembly parsing.\n"; + return 1; + } + Parser->setShowParsedOperands(InputArgs.hasArg(OPT_show_inst_operands)); - Parser->setTargetParser(*TAP); - Parser->getLexer().setLexMasmIntegers(true); + Parser->setTargetParser(*TAP); + Parser->getLexer().setLexMasmIntegers(true); Parser->getLexer().useMasmDefaultRadix(true); Parser->getLexer().setLexMasmHexFloats(true); Parser->getLexer().setLexMasmStrings(true); - + auto Defines = InputArgs.getAllArgValues(OPT_define); for (StringRef Define : Defines) { const auto NameValue = Define.split('='); @@ -158,27 +158,27 @@ static int AssembleInput(StringRef ProgName, const Target *TheTarget, } } - int Res = Parser->Run(/*NoInitialTextSection=*/true); - - return Res; -} - + int Res = Parser->Run(/*NoInitialTextSection=*/true); + + return Res; +} + int main(int Argc, char **Argv) { InitLLVM X(Argc, Argv); StringRef ProgName = sys::path::filename(Argv[0]); - - // Initialize targets and assembly printers/parsers. - llvm::InitializeAllTargetInfos(); - llvm::InitializeAllTargetMCs(); - llvm::InitializeAllAsmParsers(); - llvm::InitializeAllDisassemblers(); - + + // Initialize targets and assembly printers/parsers. + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + MLOptTable T; unsigned MissingArgIndex, MissingArgCount; ArrayRef<const char *> ArgsArr = makeArrayRef(Argv + 1, Argc - 1); opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MissingArgIndex, MissingArgCount); - + std::string InputFilename; for (auto *Arg : InputArgs.filtered(OPT_INPUT)) { std::string ArgString = Arg->getAsString(InputArgs); @@ -230,17 +230,17 @@ int main(int Argc, char **Argv) { } MCTargetOptions MCOptions; - MCOptions.AssemblyLanguage = "masm"; - + MCOptions.AssemblyLanguage = "masm"; + Triple TheTriple = GetTriple(ProgName, InputArgs); std::string Error; const Target *TheTarget = TargetRegistry::lookupTarget("", TheTriple, Error); if (!TheTarget) { WithColor::error(errs(), ProgName) << Error; - return 1; + return 1; } const std::string &TripleName = TheTriple.getTriple(); - + bool SafeSEH = InputArgs.hasArg(OPT_safeseh); if (SafeSEH && !(TheTriple.isArch32Bit() && TheTriple.isX86())) { WithColor::warning() @@ -248,42 +248,42 @@ int main(int Argc, char **Argv) { SafeSEH = false; } - ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr = - MemoryBuffer::getFileOrSTDIN(InputFilename); - if (std::error_code EC = BufferPtr.getError()) { - WithColor::error(errs(), ProgName) - << InputFilename << ": " << EC.message() << '\n'; - return 1; - } - - SourceMgr SrcMgr; - - // Tell SrcMgr about this buffer, which is what the parser will pick up. - SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); - - // Record the location of the include directories so that the lexer can find - // it later. + ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr = + MemoryBuffer::getFileOrSTDIN(InputFilename); + if (std::error_code EC = BufferPtr.getError()) { + WithColor::error(errs(), ProgName) + << InputFilename << ": " << EC.message() << '\n'; + return 1; + } + + SourceMgr SrcMgr; + + // Tell SrcMgr about this buffer, which is what the parser will pick up. + SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); + + // Record the location of the include directories so that the lexer can find + // it later. SrcMgr.setIncludeDirs(InputArgs.getAllArgValues(OPT_include_path)); - - std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName)); - assert(MRI && "Unable to create target register info!"); - - std::unique_ptr<MCAsmInfo> MAI( - TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions)); - assert(MAI && "Unable to create target asm info!"); - + + std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName)); + assert(MRI && "Unable to create target register info!"); + + std::unique_ptr<MCAsmInfo> MAI( + TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions)); + assert(MAI && "Unable to create target asm info!"); + MAI->setPreserveAsmComments(InputArgs.hasArg(OPT_preserve_comments)); - - // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and - // MCObjectFileInfo needs a MCContext reference in order to initialize itself. - MCObjectFileInfo MOFI; - MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); - MOFI.InitMCObjectFileInfo(TheTriple, /*PIC=*/false, Ctx, - /*LargeCodeModel=*/true); - + + // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and + // MCObjectFileInfo needs a MCContext reference in order to initialize itself. + MCObjectFileInfo MOFI; + MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr); + MOFI.InitMCObjectFileInfo(TheTriple, /*PIC=*/false, Ctx, + /*LargeCodeModel=*/true); + if (InputArgs.hasArg(OPT_save_temp_labels)) - Ctx.setAllowTemporaryLabels(false); - + Ctx.setAllowTemporaryLabels(false); + // Set compilation information. SmallString<128> CWD; if (!sys::fs::current_path(CWD)) @@ -294,78 +294,78 @@ int main(int Argc, char **Argv) { SmallString<255> DefaultOutputFilename; if (InputArgs.hasArg(OPT_as_lex)) { DefaultOutputFilename = "-"; - } else { + } else { DefaultOutputFilename = InputFilename; sys::path::replace_extension(DefaultOutputFilename, FileType); - } + } const StringRef OutputFilename = InputArgs.getLastArgValue(OPT_output_file, DefaultOutputFilename); - std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename); - if (!Out) - return 1; - - std::unique_ptr<buffer_ostream> BOS; - raw_pwrite_stream *OS = &Out->os(); - std::unique_ptr<MCStreamer> Str; - - std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo()); + std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename); + if (!Out) + return 1; + + std::unique_ptr<buffer_ostream> BOS; + raw_pwrite_stream *OS = &Out->os(); + std::unique_ptr<MCStreamer> Str; + + std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo()); assert(MCII && "Unable to create instruction info!"); - std::unique_ptr<MCSubtargetInfo> STI(TheTarget->createMCSubtargetInfo( - TripleName, /*CPU=*/"", /*Features=*/"")); + std::unique_ptr<MCSubtargetInfo> STI(TheTarget->createMCSubtargetInfo( + TripleName, /*CPU=*/"", /*Features=*/"")); assert(STI && "Unable to create subtarget info!"); - - MCInstPrinter *IP = nullptr; + + MCInstPrinter *IP = nullptr; if (FileType == "s") { const bool OutputATTAsm = InputArgs.hasArg(OPT_output_att_asm); - const unsigned OutputAsmVariant = OutputATTAsm ? 0U // ATT dialect - : 1U; // Intel dialect + const unsigned OutputAsmVariant = OutputATTAsm ? 0U // ATT dialect + : 1U; // Intel dialect IP = TheTarget->createMCInstPrinter(TheTriple, OutputAsmVariant, *MAI, *MCII, *MRI); - - if (!IP) { - WithColor::error() - << "unable to create instruction printer for target triple '" - << TheTriple.normalize() << "' with " - << (OutputATTAsm ? "ATT" : "Intel") << " assembly variant.\n"; - return 1; - } - - // Set the display preference for hex vs. decimal immediates. + + if (!IP) { + WithColor::error() + << "unable to create instruction printer for target triple '" + << TheTriple.normalize() << "' with " + << (OutputATTAsm ? "ATT" : "Intel") << " assembly variant.\n"; + return 1; + } + + // Set the display preference for hex vs. decimal immediates. IP->setPrintImmHex(InputArgs.hasArg(OPT_print_imm_hex)); - - // Set up the AsmStreamer. - std::unique_ptr<MCCodeEmitter> CE; + + // Set up the AsmStreamer. + std::unique_ptr<MCCodeEmitter> CE; if (InputArgs.hasArg(OPT_show_encoding)) - CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); - - std::unique_ptr<MCAsmBackend> MAB( - TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); - auto FOut = std::make_unique<formatted_raw_ostream>(*OS); + CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); + + std::unique_ptr<MCAsmBackend> MAB( + TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); + auto FOut = std::make_unique<formatted_raw_ostream>(*OS); Str.reset(TheTarget->createAsmStreamer( Ctx, std::move(FOut), /*asmverbose*/ true, /*useDwarfDirectory*/ true, IP, std::move(CE), std::move(MAB), InputArgs.hasArg(OPT_show_inst))); - + } else if (FileType == "null") { - Str.reset(TheTarget->createNullStreamer(Ctx)); + Str.reset(TheTarget->createNullStreamer(Ctx)); } else if (FileType == "obj") { - if (!Out->os().supportsSeeking()) { - BOS = std::make_unique<buffer_ostream>(Out->os()); - OS = BOS.get(); - } - - MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx); - MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions); - Str.reset(TheTarget->createMCObjectStreamer( - TheTriple, Ctx, std::unique_ptr<MCAsmBackend>(MAB), - MAB->createObjectWriter(*OS), std::unique_ptr<MCCodeEmitter>(CE), *STI, - MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, - /*DWARFMustBeAtTheEnd*/ false)); + if (!Out->os().supportsSeeking()) { + BOS = std::make_unique<buffer_ostream>(Out->os()); + OS = BOS.get(); + } + + MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx); + MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions); + Str.reset(TheTarget->createMCObjectStreamer( + TheTriple, Ctx, std::unique_ptr<MCAsmBackend>(MAB), + MAB->createObjectWriter(*OS), std::unique_ptr<MCCodeEmitter>(CE), *STI, + MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, + /*DWARFMustBeAtTheEnd*/ false)); } else { llvm_unreachable("Invalid file type!"); - } - + } + if (TheTriple.isOSBinFormatCOFF()) { // Emit an absolute @feat.00 symbol. This is a features bitfield read by // link.exe. @@ -383,20 +383,20 @@ int main(int Argc, char **Argv) { Str->emitAssignment(Feat00Sym, MCConstantExpr::create(Feat00Flags, Ctx)); } - // Use Assembler information for parsing. - Str->setUseAssemblerInfoForParsing(true); - - int Res = 1; + // Use Assembler information for parsing. + Str->setUseAssemblerInfoForParsing(true); + + int Res = 1; if (InputArgs.hasArg(OPT_as_lex)) { // -as-lex; Lex only, and output a stream of tokens - Res = AsLexInput(SrcMgr, *MAI, Out->os()); + Res = AsLexInput(SrcMgr, *MAI, Out->os()); } else { - Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, *Str, *MAI, *STI, + Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, *Str, *MAI, *STI, *MCII, MCOptions, InputArgs); - } - - // Keep output if no errors. - if (Res == 0) - Out->keep(); - return Res; -} + } + + // Keep output if no errors. + if (Res == 0) + Out->keep(); + return Res; +} diff --git a/contrib/libs/llvm12/tools/llvm-ml/ya.make b/contrib/libs/llvm12/tools/llvm-ml/ya.make index 5371cfd851..8566abf283 100644 --- a/contrib/libs/llvm12/tools/llvm-ml/ya.make +++ b/contrib/libs/llvm12/tools/llvm-ml/ya.make @@ -1,17 +1,17 @@ -# Generated by devtools/yamaker. - -PROGRAM() - +# Generated by devtools/yamaker. + +PROGRAM() + OWNER( orivej g:cpp-contrib ) - + LICENSE(Apache-2.0 WITH LLVM-exception) - + LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -PEERDIR( +PEERDIR( contrib/libs/llvm12 contrib/libs/llvm12/include contrib/libs/llvm12/lib/BinaryFormat @@ -45,20 +45,20 @@ PEERDIR( contrib/libs/llvm12/lib/Target/X86/Disassembler contrib/libs/llvm12/lib/Target/X86/MCTargetDesc contrib/libs/llvm12/lib/Target/X86/TargetInfo -) - -ADDINCL( +) + +ADDINCL( ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm12/tools/llvm-ml contrib/libs/llvm12/tools/llvm-ml -) - -NO_COMPILER_WARNINGS() - -NO_UTIL() - -SRCS( - Disassembler.cpp - llvm-ml.cpp -) - -END() +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + Disassembler.cpp + llvm-ml.cpp +) + +END() |