41 #define DEBUG_TYPE "asm-printer"
49 assert(DiagInfo &&
"Diagnostic context not passed down?");
53 const MDNode *LocInfo =
nullptr;
54 if (BufNum > 0 && BufNum <= DiagInfo->LocInfos.size())
55 LocInfo = DiagInfo->
LocInfos[BufNum-1];
59 unsigned LocCookie = 0;
67 mdconst::dyn_extract<ConstantInt>(LocInfo->
getOperand(ErrorLine)))
68 LocCookie = CI->getZExtValue();
79 assert(!Str.
empty() &&
"Can't emit empty inline asm block");
82 bool isNullTerminated = Str.
back() == 0;
92 assert(MCAI &&
"No MCAsmInfo");
102 DiagInfo = make_unique<SrcMgrDiagInfo>();
118 std::unique_ptr<MemoryBuffer> Buffer;
128 DiagInfo->LocInfos.resize(BufNum);
129 DiagInfo->LocInfos[BufNum-1] = LocMDNode;
132 std::unique_ptr<MCAsmParser> Parser(
141 STI, *Parser, *MII, MCOptions));
144 " we don't have an asm parser for this target\n");
145 Parser->setAssemblerDialect(Dialect);
146 Parser->setTargetParser(*TAP.get());
149 Parser->setParsingInlineAsm(
true);
157 int Res = Parser->Run(
true,
161 if (Res && !DiagInfo->DiagHandler)
170 OS <<
"\t.intel_syntax\n\t";
172 const char *LastEmitted = AsmStr;
175 while (*LastEmitted) {
176 switch (*LastEmitted) {
179 const char *LiteralEnd = LastEmitted+1;
180 while (*LiteralEnd && *LiteralEnd !=
'{' && *LiteralEnd !=
'|' &&
181 *LiteralEnd !=
'}' && *LiteralEnd !=
'$' && *LiteralEnd !=
'\n')
184 OS.
write(LastEmitted, LiteralEnd-LastEmitted);
185 LastEmitted = LiteralEnd;
197 switch (*LastEmitted) {
198 default: Done =
false;
break;
208 if (LastEmitted[0] ==
'{' && LastEmitted[1] ==
':') {
210 const char *StrStart = LastEmitted;
211 const char *StrEnd = strchr(StrStart,
'}');
214 " string: '" +
Twine(AsmStr) +
"'");
216 std::string Val(StrStart, StrEnd);
218 LastEmitted = StrEnd+1;
222 const char *IDStart = LastEmitted;
223 const char *IDEnd = IDStart;
224 while (*IDEnd >=
'0' && *IDEnd <=
'9') ++IDEnd;
229 Twine(AsmStr) +
"'");
232 if (Val >= NumOperands-1)
234 Twine(AsmStr) +
"'");
270 Msg <<
"invalid operand in inline asm: '" << AsmStr <<
"'";
277 OS <<
"\n\t.att_syntax\n" << (
char)0;
285 const char *LastEmitted = AsmStr;
290 while (*LastEmitted) {
291 switch (*LastEmitted) {
294 const char *LiteralEnd = LastEmitted+1;
295 while (*LiteralEnd && *LiteralEnd !=
'{' && *LiteralEnd !=
'|' &&
296 *LiteralEnd !=
'}' && *LiteralEnd !=
'$' && *LiteralEnd !=
'\n')
298 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
299 OS.
write(LastEmitted, LiteralEnd-LastEmitted);
300 LastEmitted = LiteralEnd;
312 switch (*LastEmitted) {
313 default: Done =
false;
break;
315 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
321 if (CurVariant != -1)
323 Twine(AsmStr) +
"'");
328 if (CurVariant == -1)
335 if (CurVariant == -1)
343 bool HasCurlyBraces =
false;
344 if (*LastEmitted ==
'{') {
346 HasCurlyBraces =
true;
352 if (HasCurlyBraces && *LastEmitted ==
':') {
354 const char *StrStart = LastEmitted;
355 const char *StrEnd = strchr(StrStart,
'}');
358 " string: '" +
Twine(AsmStr) +
"'");
360 std::string Val(StrStart, StrEnd);
362 LastEmitted = StrEnd+1;
366 const char *IDStart = LastEmitted;
367 const char *IDEnd = IDStart;
368 while (*IDEnd >=
'0' && *IDEnd <=
'9') ++IDEnd;
373 Twine(AsmStr) +
"'");
376 char Modifier[2] = { 0, 0 };
378 if (HasCurlyBraces) {
381 if (*LastEmitted ==
':') {
383 if (*LastEmitted == 0)
385 Twine(AsmStr) +
"'");
387 Modifier[0] = *LastEmitted;
391 if (*LastEmitted !=
'}')
393 Twine(AsmStr) +
"'");
397 if (Val >= NumOperands-1)
399 Twine(AsmStr) +
"'");
403 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
425 if (Modifier[0] ==
'l') {
432 Modifier[0] ? Modifier :
nullptr,
436 Modifier[0] ? Modifier :
nullptr, OS);
443 Msg <<
"invalid operand in inline asm: '" << AsmStr <<
"'";
451 OS <<
'\n' << (
char)0;
460 unsigned NumDefs = 0;
472 if (AsmStr[0] == 0) {
484 unsigned LocCookie = 0;
485 const MDNode *LocMD =
nullptr;
491 mdconst::dyn_extract<ConstantInt>(LocMD->
getOperand(0))) {
492 LocCookie = CI->getZExtValue();
534 const char *Code)
const {
535 if (!strcmp(Code,
"private")) {
538 }
else if (!strcmp(Code,
"comment")) {
540 }
else if (!strcmp(Code,
"uid")) {
554 Msg <<
"Unknown special formatter '" << Code
555 <<
"' for machine instr: " << *
MI;
564 unsigned AsmVariant,
const char *ExtraCode,
567 if (ExtraCode && ExtraCode[0]) {
568 if (ExtraCode[1] != 0)
return true;
571 switch (ExtraCode[0]) {
587 O << ((32 - MO.
getImm()) & 31);
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
A parsed version of the target data layout string in and methods for querying it. ...
unsigned getAssemblerDialect() const
StringRef getPrivateGlobalPrefix() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
MCTargetOptions MCOptions
Machine level options.
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
MachineBasicBlock * getMBB() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
InlineAsmDiagHandlerTy getInlineAsmDiagnosticHandler() const
getInlineAsmDiagnosticHandler - Return the diagnostic handler set by setInlineAsmDiagnosticHandler.
std::vector< std::string > IASSearchPaths
Additional paths to search for .include directives when using the integrated assembler.
MCContext & OutContext
This is the context for the output file that we are streaming.
unsigned getNumOperands() const
Return number of MDNode operands.
bool SanitizeAddress
Enables AddressSanitizer instrumentation at machine level.
const MachineFunction * MF
The current machine function.
A raw_ostream that writes to an SmallVector or SmallString.
unsigned getFunctionNumber() const
Return a unique ID for the current function.
const char * getSymbolName() const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
virtual void emitInlineAsmStart() const
Let the target do anything it needs to do before emitting inlineasm.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
LLVMContext::InlineAsmDiagHandlerTy DiagHandler
const MDNode * getMetadata() const
LLVM_NODISCARD char back() const
back - Get the last character in the string.
bool isMetadata() const
isMetadata - Tests if this is a MO_Metadata operand.
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance.
StringRef getCommentString() const
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const Module * getModule() const
virtual void PrintSpecial(const MachineInstr *MI, raw_ostream &OS, const char *Code) const
Print information related to the specified machine instr that is independent of the operand...
const char * getInlineAsmEnd() const
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Context object for machine code objects.
void emitError(unsigned LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
MCTargetAsmParser * createMCAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options) const
createMCAsmParser - Create a target specific assembly parser.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
This class is intended to be used as a base class for asm properties and features specific to the tar...
void setInlineSourceManager(SourceMgr *SM)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
const MCAsmInfo * MAI
Target Asm Printer information.
This is an important class for using LLVM in a threaded context.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const MachineOperand & getOperand(unsigned i) const
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
TargetMachine & TM
Target machine description.
This class is intended to be used as a driving class for all asm writers.
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag...
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo)
srcMgrDiagHandler - This callback is invoked when the SourceMgr for an inline asm has an error in it...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
static bool isMemKind(unsigned Flag)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo) const
Let the target do anything it needs to do after emitting inlineasm.
raw_ostream & write(unsigned char C)
const MDOperand & getOperand(unsigned I) const
This is the shared class of boolean and integer constants.
const MCContext & getContext() const
MachineOperand class - Representation of each machine instruction operand.
Module.h This file contains the declarations for the Module class.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
void * getInlineAsmDiagnosticContext() const
getInlineAsmDiagnosticContext - Return the diagnostic context set by setInlineAsmDiagnosticHandler.
Representation of each machine instruction.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
MCSubtargetInfo - Generic base class for all target subtargets.
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, int InlineAsmVariant, int AsmPrinterVariant, AsmPrinter *AP, unsigned LocCookie, raw_ostream &OS)
Lightweight error class with error context and mandatory checking.
bool useIntegratedAssembler() const
Return true if assembly (inline or otherwise) should be parsed.
This class implements an extremely fast bulk output stream that can only output to a stream...
const Target & getTarget() const
void setIncludeDirs(const std::vector< std::string > &Dirs)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, int InlineAsmVariant, AsmPrinter *AP, unsigned LocCookie, raw_ostream &OS)
const char * getInlineAsmStart() const
std::vector< const MDNode * > LocInfos
Represents a location in source code.
InlineAsm::AsmDialect getInlineAsmDialect() const
This class contains meta information specific to a module.
LLVMContext & getContext() const
Get the global data context.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...