mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-15 08:19:51 +00:00
[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
This commit is contained in:
parent
ca7fd00a11
commit
e563ac372a
@ -341,6 +341,11 @@ typedef enum {
|
||||
LLVMDSNote
|
||||
} LLVMDiagnosticSeverity;
|
||||
|
||||
typedef enum {
|
||||
LLVMInlineAsmDialectATT,
|
||||
LLVMInlineAsmDialectIntel
|
||||
} LLVMInlineAsmDialect;
|
||||
|
||||
/**
|
||||
* Attribute index are either LLVMAttributeReturnIndex,
|
||||
* LLVMAttributeFunctionIndex or a parameter number from 1 to N.
|
||||
@ -649,12 +654,37 @@ LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
|
||||
*/
|
||||
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, size_t Len);
|
||||
|
||||
/**
|
||||
* Create the specified uniqued inline asm string.
|
||||
*
|
||||
* @see InlineAsm::get()
|
||||
*/
|
||||
LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty,
|
||||
char *AsmString, size_t AsmStringSize,
|
||||
char *Constraints, size_t ConstraintsSize,
|
||||
LLVMBool HasSideEffects, LLVMBool IsAlignStack,
|
||||
LLVMInlineAsmDialect Dialect);
|
||||
|
||||
/**
|
||||
* Obtain the context to which this module is associated.
|
||||
@ -745,6 +775,9 @@ LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
|
||||
*/
|
||||
LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
|
||||
|
||||
/** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */
|
||||
void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@ -1820,10 +1853,12 @@ LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
|
||||
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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -304,10 +304,42 @@ char *LLVMPrintModuleToString(LLVMModuleRef M) {
|
||||
}
|
||||
|
||||
/*--.. 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, size_t Len) {
|
||||
unwrap(M)->appendModuleInlineAsm(StringRef(Asm, Len));
|
||||
}
|
||||
|
||||
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, size_t AsmStringSize,
|
||||
char *Constraints, size_t ConstraintsSize,
|
||||
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<FunctionType>(Ty),
|
||||
StringRef(AsmString, AsmStringSize),
|
||||
StringRef(Constraints, ConstraintsSize),
|
||||
HasSideEffects, IsAlignStack, AD));
|
||||
}
|
||||
|
||||
|
||||
/*--.. Operations on module contexts ......................................--*/
|
||||
LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M) {
|
||||
|
@ -6,6 +6,8 @@ source_filename = "/test/Bindings/echo.ll"
|
||||
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
|
||||
|
@ -1002,6 +1002,10 @@ int llvm_echo(void) {
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user