Skip to content

Commit e8e8887

Browse files
authored
[llvm-c] Add non-cstring versions of LLVMGetNamedFunction and LLVMGetNamedGlobal (llvm#103396)
Add `LLVMGetNamedFunctionWithLength` and `LLVMGetNamedGlobalWithLength` As far as i know, it isn't currently possible to use `LLVMGetNamedFunction` and `LLVMGetNamedGlobal` with non-null-terminated strings. These new functions are more convenient for C programs that use non-null-terminated strings or for languages like Rust that primarily use non-null-terminated strings.
1 parent 7e23a23 commit e8e8887

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ Changes to the C API
151151
* ``LLVMX86MMXTypeInContext``
152152
* ``LLVMX86MMXType``
153153

154+
* The following functions are added to further support non-null-terminated strings:
155+
156+
* ``LLVMGetNamedFunctionWithLength``
157+
* ``LLVMGetNamedGlobalWithLength``
158+
154159
Changes to the CodeGen infrastructure
155160
-------------------------------------
156161

llvm/include/llvm-c/Core.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,16 @@ LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
11791179
*/
11801180
LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
11811181

1182+
/**
1183+
* Obtain a Function value from a Module by its name.
1184+
*
1185+
* The returned value corresponds to a llvm::Function value.
1186+
*
1187+
* @see llvm::Module::getFunction()
1188+
*/
1189+
LLVMValueRef LLVMGetNamedFunctionWithLength(LLVMModuleRef M, const char *Name,
1190+
size_t Length);
1191+
11821192
/**
11831193
* Obtain an iterator to the first Function in a Module.
11841194
*
@@ -2633,6 +2643,8 @@ LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
26332643
const char *Name,
26342644
unsigned AddressSpace);
26352645
LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
2646+
LLVMValueRef LLVMGetNamedGlobalWithLength(LLVMModuleRef M, const char *Name,
2647+
size_t Length);
26362648
LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
26372649
LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
26382650
LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);

llvm/lib/IR/Core.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,11 @@ LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
22032203
return wrap(unwrap(M)->getNamedGlobal(Name));
22042204
}
22052205

2206+
LLVMValueRef LLVMGetNamedGlobalWithLength(LLVMModuleRef M, const char *Name,
2207+
size_t Length) {
2208+
return wrap(unwrap(M)->getNamedGlobal(StringRef(Name, Length)));
2209+
}
2210+
22062211
LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) {
22072212
Module *Mod = unwrap(M);
22082213
Module::global_iterator I = Mod->global_begin();
@@ -2381,6 +2386,11 @@ LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
23812386
return wrap(unwrap(M)->getFunction(Name));
23822387
}
23832388

2389+
LLVMValueRef LLVMGetNamedFunctionWithLength(LLVMModuleRef M, const char *Name,
2390+
size_t Length) {
2391+
return wrap(unwrap(M)->getFunction(StringRef(Name, Length)));
2392+
}
2393+
23842394
LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) {
23852395
Module *Mod = unwrap(M);
23862396
Module::iterator I = Mod->begin();

0 commit comments

Comments
 (0)