Index: include/llvm-c/Target.h =================================================================== --- include/llvm-c/Target.h +++ include/llvm-c/Target.h @@ -183,6 +183,20 @@ /*===-- Target Data -------------------------------------------------------===*/ +/** + * Obtain the data layout for a module. + * + * @see Module::getDataLayout() + */ +LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M); + +/** + * Obtain 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); Index: include/llvm-c/TargetMachine.h =================================================================== --- include/llvm-c/TargetMachine.h +++ include/llvm-c/TargetMachine.h @@ -115,6 +115,9 @@ LLVMDisposeMessage. */ char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T); +/** Create a DataLayout based on the targetMachine. */ +LLVMTargetDataRef LLVMCreateTargetMachineData(LLVMTargetMachineRef T); + /** Set the target machine's ASM verbosity. */ void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, LLVMBool VerboseAsm); Index: lib/Target/Target.cpp =================================================================== --- lib/Target/Target.cpp +++ lib/Target/Target.cpp @@ -42,6 +42,14 @@ 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)); } Index: lib/Target/TargetMachineC.cpp =================================================================== --- lib/Target/TargetMachineC.cpp +++ lib/Target/TargetMachineC.cpp @@ -171,6 +171,10 @@ unwrap(T)->Options.MCOptions.AsmVerbose = VerboseAsm; } +LLVMTargetDataRef LLVMCreateTargetMachineData(LLVMTargetMachineRef T) { + return wrap(new DataLayout(unwrap(T)->createDataLayout())); +} + static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, raw_pwrite_stream &OS, LLVMCodeGenFileType codegen,