@@ -31,6 +31,7 @@ void Module::Init(Napi::Env env, Napi::Object &exports) {
31
31
InstanceMethod (" getFunction" , &Module::getFunction),
32
32
InstanceMethod (" getOrInsertFunction" , &Module::getOrInsertFunction),
33
33
InstanceMethod (" getGlobalVariable" , &Module::getGlobalVariable),
34
+ InstanceMethod (" getOrInsertGlobal" , &Module::getOrInsertGlobal),
34
35
InstanceMethod (" addModuleFlag" , &Module::addModuleFlag),
35
36
InstanceMethod (" empty" , &Module::empty),
36
37
InstanceMethod (" print" , &Module::print)
@@ -198,6 +199,17 @@ Napi::Value Module::getGlobalVariable(const Napi::CallbackInfo &info) {
198
199
throw Napi::TypeError::New (env, ErrMsg::Class::Module::getGlobalVariable);
199
200
}
200
201
202
+ Napi::Value Module::getOrInsertGlobal (const Napi::CallbackInfo &info) {
203
+ Napi::Env env = info.Env ();
204
+ if (info.Length () == 2 && info[0 ].IsString () && Type::IsClassOf (info[1 ])) {
205
+ std::string functionName = info[0 ].As <Napi::String>();
206
+ llvm::Type *type = Type::Extract (info[1 ]);
207
+ llvm::Constant* glob = module->getOrInsertGlobal (functionName, type);
208
+ return GlobalVariable::New (env, dyn_cast_or_null<llvm::GlobalVariable>(glob));
209
+ }
210
+ throw Napi::TypeError::New (env, ErrMsg::Class::Module::getOrInsertGlobal);
211
+ }
212
+
201
213
void Module::addModuleFlag (const Napi::CallbackInfo &info) {
202
214
Napi::Env env = info.Env ();
203
215
if (info.Length () == 3 && info[0 ].IsNumber () && info[1 ].IsString () && info[2 ].IsNumber ()) {
0 commit comments