llvm.org GIT mirror llvm / e563ac3
[LLVM-C] Audit Inline Assembly APIs for Consistency Summary: - Add a missing getter for module-level inline assembly - Add a missing append function for module-level inline assembly - Deprecate LLVMSetModuleInlineAsm and replace it with LLVMSetModuleInlineAsm2 which takes an explicit length parameter - Deprecate LLVMConstInlineAsm and replace it with LLVMGetInlineAsm, a function that allows passing a dialect and is not mis-classified as a constant operation Reviewers: whitequark, deadalnix Reviewed By: whitequark Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45346 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329369 91177308-0d34-0410-b5e6-96231b3b80d8 Robert Widmann 2 years ago
4 changed file(s) with 75 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
340340 LLVMDSNote
341341 } LLVMDiagnosticSeverity;
342342
343 typedef enum {
344 LLVMInlineAsmDialectATT,
345 LLVMInlineAsmDialectIntel
346 } LLVMInlineAsmDialect;
347
343348 /**
344349 * Attribute index are either LLVMAttributeReturnIndex,
345350 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
649654 char *LLVMPrintModuleToString(LLVMModuleRef M);
650655
651656 /**
657 * Get inline assembly for a module.
658 *
659 * @see Module::getModuleInlineAsm()
660 */
661 const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len);
662
663 /**
652664 * Set inline assembly for a module.
653665 *
654666 * @see Module::setModuleInlineAsm()
655667 */
656 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
668 void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len);
669
670 /**
671 * Append inline assembly to a module.
672 *
673 * @see Module::appendModuleInlineAsm()
674 */
675 void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len);
676
677 /**
678 * Create the specified uniqued inline asm string.
679 *
680 * @see InlineAsm::get()
681 */
682 LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty,
683 char *AsmString, size_t AsmStringSize,
684 char *Constraints, size_t ConstraintsSize,
685 LLVMBool HasSideEffects, LLVMBool IsAlignStack,
686 LLVMInlineAsmDialect Dialect);
657687
658688 /**
659689 * Obtain the context to which this module is associated.
743773 * no previous functions.
744774 */
745775 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
776
777 /** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */
778 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
746779
747780 /**
748781 * @}
18191852 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
18201853 LLVMValueRef ElementValueConstant,
18211854 unsigned *IdxList, unsigned NumIdx);
1855 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1856
1857 /** Deprecated: Use LLVMGetInlineAsm instead. */
18221858 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
18231859 const char *AsmString, const char *Constraints,
18241860 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1825 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
18261861
18271862 /**
18281863 * @}
303303 }
304304
305305 /*--.. Operations on inline assembler ......................................--*/
306 void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len) {
307 unwrap(M)->setModuleInlineAsm(StringRef(Asm, Len));
308 }
309
306310 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
307311 unwrap(M)->setModuleInlineAsm(StringRef(Asm));
312 }
313
314 void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len) {
315 unwrap(M)->appendModuleInlineAsm(StringRef(Asm, Len));
316 }
317
318 const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len) {
319 auto &Str = unwrap(M)->getModuleInlineAsm();
320 *Len = Str.length();
321 return Str.c_str();
322 }
323
324 LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty,
325 char *AsmString, size_t AsmStringSize,
326 char *Constraints, size_t ConstraintsSize,
327 LLVMBool HasSideEffects, LLVMBool IsAlignStack,
328 LLVMInlineAsmDialect Dialect) {
329 InlineAsm::AsmDialect AD;
330 switch (Dialect) {
331 case LLVMInlineAsmDialectATT:
332 AD = InlineAsm::AD_ATT;
333 case LLVMInlineAsmDialectIntel:
334 AD = InlineAsm::AD_Intel;
335 }
336 return wrap(InlineAsm::get(unwrap(Ty),
337 StringRef(AsmString, AsmStringSize),
338 StringRef(Constraints, ConstraintsSize),
339 HasSideEffects, IsAlignStack, AD));
308340 }
309341
310342
44 source_filename = "/test/Bindings/echo.ll"
55 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
66 target triple = "x86_64-apple-macosx10.11.0"
7
8 module asm "classical GAS"
79
810 %S = type { i64, %S* }
911
10011001 if (strcmp(LLVMGetDataLayoutStr(M), LLVMGetDataLayoutStr(Src)))
10021002 report_fatal_error("Inconsistent DataLayout string representation");
10031003
1004 size_t ModuleInlineAsmLen;
1005 const char *ModuleAsm = LLVMGetModuleInlineAsm(Src, &ModuleInlineAsmLen);
1006 LLVMSetModuleInlineAsm2(M, ModuleAsm, ModuleInlineAsmLen);
1007
10041008 declare_symbols(Src, M);
10051009 clone_symbols(Src, M);
10061010 char *Str = LLVMPrintModuleToString(M);