1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

Restore the capability to manipulate datalayout from the C API

Summary:
This consist in variosu addition to the C API:

  LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
  void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
  LLVMTargetDataRef LLVMCreateTargetMachineData(LLVMTargetMachineRef T);

Reviewers: joker.eph, Wallbraker, echristo

Subscribers: axw

Differential Revision: http://reviews.llvm.org/D17255

llvm-svn: 260936
This commit is contained in:
Amaury Sechet 2016-02-16 05:11:24 +00:00
parent aecb941958
commit 34464e942c
6 changed files with 38 additions and 0 deletions

View File

@ -183,6 +183,20 @@ static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
/*===-- Target Data -------------------------------------------------------===*/
/**
* Obtain the data layout for a module.
*
* @see Module::getDataLayout()
*/
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
/**
* Set the data layout for a module.
*
* @see Module::setDataLayout()
*/
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
/** Creates target data from a target layout string.
See the constructor llvm::DataLayout::DataLayout. */
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);

View File

@ -115,6 +115,9 @@ char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
LLVMDisposeMessage. */
char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
/** Create a DataLayout based on the targetMachine. */
LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);
/** Set the target machine's ASM verbosity. */
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
LLVMBool VerboseAsm);

View File

@ -42,6 +42,14 @@ void LLVMInitializeTarget(LLVMPassRegistryRef R) {
initializeTarget(*unwrap(R));
}
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M) {
return wrap(&unwrap(M)->getDataLayout());
}
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL) {
unwrap(M)->setDataLayout(*unwrap(DL));
}
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
return wrap(new DataLayout(StringRep));
}

View File

@ -171,6 +171,10 @@ void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
unwrap(T)->Options.MCOptions.AsmVerbose = VerboseAsm;
}
LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T) {
return wrap(new DataLayout(unwrap(T)->createDataLayout()));
}
static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
raw_pwrite_stream &OS,
LLVMCodeGenFileType codegen,

View File

@ -2,6 +2,9 @@
; RUN: llvm-as < %s | llvm-c-test --echo > %t.echo
; RUN: diff -w %t.orig %t.echo
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"
%S = type { i64, %S* }
define { i64, %S* } @unpackrepack(%S %s) {

View File

@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//
#include "llvm-c-test.h"
#include "llvm-c/Target.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/ErrorHandling.h"
@ -629,6 +630,11 @@ int llvm_echo(void) {
LLVMContextRef Ctx = LLVMContextCreate();
LLVMModuleRef M = LLVMModuleCreateWithNameInContext("<stdin>", Ctx);
LLVMSetTarget(M, LLVMGetTarget(Src));
LLVMSetModuleDataLayout(M, LLVMGetModuleDataLayout(Src));
if (strcmp(LLVMGetDataLayoutStr(M), LLVMGetDataLayoutStr(Src)))
report_fatal_error("Inconsistent DataLayout string representation");
clone_functions(Src, M);
char *Str = LLVMPrintModuleToString(M);
fputs(Str, stdout);