Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -341,6 +341,11 @@ LLVMDSNote } LLVMDiagnosticSeverity; +typedef enum { + LLVMInlineAsmDialectATT, + LLVMInlineAsmDialectIntel +} LLVMInlineAsmDialect; + /** * Attribute index are either LLVMAttributeReturnIndex, * LLVMAttributeFunctionIndex or a parameter number from 1 to N. @@ -649,12 +654,36 @@ */ char *LLVMPrintModuleToString(LLVMModuleRef M); +/** + * Get inline assembly for a module. + * + * @see Module::getModuleInlineAsm() + */ +const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len); + /** * Set inline assembly for a module. * * @see Module::setModuleInlineAsm() */ -void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm); +void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len); + +/** + * Append inline assembly to a module. + * + * @see Module::appendModuleInlineAsm() + */ +void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm); + +/** + * Create the specified uniqued inline asm string. + * + * @see InlineAsm::get() + */ +LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty, + char *AsmString, char *Constraints, + LLVMBool HasSideEffects, LLVMBool IsAlignStack, + LLVMInlineAsmDialect Dialect); /** * Obtain the context to which this module is associated. @@ -745,6 +774,9 @@ */ LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn); +/** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */ +void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm); + /** * @} */ @@ -1820,10 +1852,12 @@ LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, LLVMValueRef ElementValueConstant, unsigned *IdxList, unsigned NumIdx); +LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB); + +/** Deprecated: Use LLVMGetInlineAsm instead. */ LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, const char *Constraints, LLVMBool HasSideEffects, LLVMBool IsAlignStack); -LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB); /** * @} Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -304,10 +304,39 @@ } /*--.. Operations on inline assembler ......................................--*/ +void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len) { + unwrap(M)->setModuleInlineAsm(StringRef(Asm, Len)); +} + void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) { unwrap(M)->setModuleInlineAsm(StringRef(Asm)); } +void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm) { + unwrap(M)->appendModuleInlineAsm(StringRef(Asm)); +} + +const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len) { + auto &Str = unwrap(M)->getModuleInlineAsm(); + *Len = Str.length(); + return Str.c_str(); +} + +LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty, + char *AsmString, char *Constraints, + LLVMBool HasSideEffects, LLVMBool IsAlignStack, + LLVMInlineAsmDialect Dialect) { + InlineAsm::AsmDialect AD; + switch (Dialect) { + case LLVMInlineAsmDialectATT: + AD = InlineAsm::AD_ATT; + case LLVMInlineAsmDialectIntel: + AD = InlineAsm::AD_Intel; + } + return wrap(InlineAsm::get(unwrap(Ty), AsmString, Constraints, + HasSideEffects, IsAlignStack, AD)); +} + /*--.. Operations on module contexts ......................................--*/ LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M) { Index: test/Bindings/llvm-c/echo.ll =================================================================== --- test/Bindings/llvm-c/echo.ll +++ test/Bindings/llvm-c/echo.ll @@ -6,6 +6,8 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.11.0" +module asm "classical GAS" + %S = type { i64, %S* } @var = global i32 42 Index: tools/llvm-c-test/echo.cpp =================================================================== --- tools/llvm-c-test/echo.cpp +++ tools/llvm-c-test/echo.cpp @@ -1002,6 +1002,10 @@ if (strcmp(LLVMGetDataLayoutStr(M), LLVMGetDataLayoutStr(Src))) report_fatal_error("Inconsistent DataLayout string representation"); + size_t ModuleInlineAsmLen; + const char *ModuleAsm = LLVMGetModuleInlineAsm(Src, &ModuleInlineAsmLen); + LLVMSetModuleInlineAsm2(M, ModuleAsm, ModuleInlineAsmLen); + declare_symbols(Src, M); clone_symbols(Src, M); char *Str = LLVMPrintModuleToString(M);