static void installGlobals(ModulePtr m) { m->env = new Env(m); vector<TopLevelItemPtr>::iterator i, end; for (i = m->topLevelItems.begin(), end = m->topLevelItems.end(); i != end; ++i) { TopLevelItem *x = i->ptr(); x->env = m->env; switch (x->objKind) { case ENUMERATION : { Enumeration *enumer = (Enumeration *)x; TypePtr t = enumType(enumer); addGlobal(m, enumer->name, enumer->visibility, t.ptr()); for (unsigned i = 0 ; i < enumer->members.size(); ++i) { EnumMember *member = enumer->members[i].ptr(); member->index = (int)i; member->type = t; addGlobal(m, member->name, enumer->visibility, member); } break; } case PROCEDURE : { Procedure *proc = (Procedure *)x; if (proc->interface != NULL) proc->interface->env = m->env; // fallthrough } default : if (x->name.ptr()) addGlobal(m, x->name, x->visibility, x); break; } } }
void addGlobals(ModulePtr m, llvm::ArrayRef<TopLevelItemPtr> toplevels) { TopLevelItemPtr const *i, *end; for (i = toplevels.begin(), end = toplevels.end(); i != end; ++i) { m->topLevelItems.push_back(*i); TopLevelItem *x = i->ptr(); x->env = m->env; switch (x->objKind) { case ENUM_DECL : { EnumDecl *enumer = (EnumDecl *)x; TypePtr t = enumType(enumer); addGlobal(m, enumer->name, enumer->visibility, t.ptr()); for (unsigned i = 0 ; i < enumer->members.size(); ++i) { EnumMember *member = enumer->members[i].ptr(); member->index = (int)i; member->type = t; addGlobal(m, member->name, enumer->visibility, member); } break; } case PROCEDURE : { Procedure *proc = (Procedure *)x; if (proc->interface != NULL) proc->interface->env = m->env; // fallthrough } default : if (x->name.ptr()) addGlobal(m, x->name, x->visibility, x); break; } } llvm::ArrayRef<TopLevelItemPtr> items = m->topLevelItems; for (size_t i = items.size() - toplevels.size(); i < items.size(); ++i) { Object *obj = items[i].ptr(); switch (obj->objKind) { case OVERLOAD : initOverload((Overload *)obj); break; case INSTANCE_DECL : initVariantInstance((InstanceDecl *)obj); break; case STATIC_ASSERT_TOP_LEVEL: checkStaticAssert((StaticAssertTopLevel *)obj); break; default: break; } } }
int main(int argc, char const *argv[]) { printf("%d\n", x); addGlobal(); printf("%d\n", x); return 0; }
llvm::GlobalVariable* addGlobal(T* object, bool isConstant, std::string name = "") { llvm::Type* type = llvm::TypeBuilder<T, false>::get( m_module->getContext()); return addGlobal(type, (void*)object, isConstant, name); }
Info & Block::setDefaultData(const symbol::Symbol & sym) { Info & i = addSym(sym, new Data(false, sym)); i.local = Info::Local::INFO_FALSE; i.type = DataManager::getSymInScilabContext(getGVN(), sym, i.exists); addGlobal(sym); dm->registerData(i.data);//, __LINE__, __FILE__); return i; }
int open () { if (StdAwk::open () <= -1) return -1; idLastSleep = addGlobal (QSE_T("LAST_SLEEP")); if (idLastSleep <= -1) goto oops; /* this is for demonstration only. * you can use sys::sleep() instead */ if (addFunction (QSE_T("sleep"), 1, 1, QSE_NULL, (FunctionHandler)&MyAwk::sleep) <= -1) goto oops; if (addFunction (QSE_T("sumintarray"), 1, 1, QSE_NULL, (FunctionHandler)&MyAwk::sumintarray) <= -1) goto oops; if (addFunction (QSE_T("arrayindices"), 1, 1, QSE_NULL, (FunctionHandler)&MyAwk::arrayindices) <= -1) goto oops; return 0; oops: StdAwk::close (); return -1; }
static void addOperator(ModulePtr module, llvm::StringRef name) { IdentifierPtr ident = Identifier::get(name); ProcedurePtr opProc = new Procedure(module.ptr(), ident, PUBLIC, false); opProc->env = new Env(module); addGlobal(module, ident, PUBLIC, opProc.ptr()); }
static void addOperator(ModulePtr module, const string &name) { IdentifierPtr ident = new Identifier(name); ProcedurePtr opProc = new Procedure(ident, PUBLIC); opProc->env = new Env(module); addGlobal(module, ident, PUBLIC, opProc.ptr()); }