void test_vector() { vector *v = vector_make_size(1, sizeof(int)); int a[] = {1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15,16}; *(int *) vector_in(v, 0) = 12; int i = 0; for (; i < 15; i++) { vector_push(v, a + i); printf("-- %d %d\n",a[i], v->len); } for (i = 0; i < 15; i++) { vector_push(v, &i); } printf("%d\n",v->len); for (i = 0; i < (int)v->len; i++) { printf("%d\n", *((int *) vector_in(v, i))); } for (i = 0; i < 50; i++) { vector_pop(v); } for (i = 0; i < (int)v->len; i++) { printf("%d\n", *((int *) vector_in(v, i))); } char c[] = "123456789"; string b; b.str = c; b.len = 7; vector *v2 = vector_make(sizeof(string)); memcpy(v2->array, &b, v2->size); printf("%s", ((string *) vector_in(v2, 0))->str); }
bool TransformComponentWithUse(Module& M, ComponentInterfaceTransform& T) { bool modified = false; for (ComponentInterfaceTransform::FMap::const_iterator i = T.rewrites.begin(), e = T.rewrites.end(); i != e; ++i) { errs() << "Looking for calls to " << i->first << "\n"; Function* f = M.getFunction(i->first); if (f == NULL) continue; for (Function::use_iterator ui = f->use_begin(), ue = f->use_end(); ui != ue; ++ui) { Use* use = &(*ui); User* user = ui->getUser(); if (isa<CallInst>(user) || isa<InvokeInst>(user)) { // The instruction is a call site CallSite cs(cast<Instruction>(user)); // If we are not the callee we should bail if( ! cs.isCallee(use)) { continue; } const CallRewrite* const rw = T.lookupRewrite(i->first, cs.arg_begin(), cs.arg_end()); if (rw == NULL) { continue; } #if DUMP BasicBlock* owner = cs.getInstruction()->getParent(); errs() << "Specializing (inter-module) call to '" << cs.getCalledFunction()->getName() << "' in function '" << (owner == NULL ? "??" : owner->getParent()->getName()) << "' on arguments ["; for (unsigned int i = 0, cnt = 0; i < cs.arg_size(); ++i) { if (!vector_in(rw->args, i)) { if (cnt++ != 0) errs() << ","; errs() << i << "=(" << *cs.getArgument(i) << ")"; } } errs() << "]\n"; #endif Instruction* newInst = applyRewriteToCall(M, rw, cs); llvm::ReplaceInstWithInst(cs.getInstruction(), newInst); modified = true; } } } return modified; }