// To generate the if-then // You need to introduce the void Generator::gen(If_then_stmt const* s) { llvm::Value* cond = gen(s->condition()); cond = build.CreateICmpEQ(cond, build.getTrue(), "ifcond"); llvm::Function* fn = build.GetInsertBlock()->getParent(); // create then block llvm::BasicBlock* then = llvm::BasicBlock::Create(cxt, "then", fn); // create an empty else block llvm::BasicBlock* merge = llvm::BasicBlock::Create(cxt, "cont", fn); // create the branch build.CreateCondBr(cond, then, merge); // emit the 'then' block build.SetInsertPoint(then); gen(s->body()); make_branch(build.GetInsertBlock(), merge); // reset the block back to where it should be then = build.GetInsertBlock(); // set the insertion point to the merge block build.SetInsertPoint(merge); merge = build.GetInsertBlock(); }
struct branch *branch_get(const char *name) { struct branch *ret; read_config(); if (!name || !*name || !strcmp(name, "HEAD")) ret = current_branch; else ret = make_branch(name, 0); if (ret && ret->remote_name) { ret->remote = remote_get(ret->remote_name); if (ret->merge_nr) { int i; ret->merge = xcalloc(sizeof(*ret->merge), ret->merge_nr); for (i = 0; i < ret->merge_nr; i++) { ret->merge[i] = xcalloc(1, sizeof(**ret->merge)); ret->merge[i]->src = xstrdup(ret->merge_name[i]); remote_find_tracking(ret->remote, ret->merge[i]); } } } return ret; }
void Generator::gen(Continue_stmt const* s) { if (!loop_entry_stack.empty()) { llvm::BasicBlock* reentry = loop_entry_stack.top(); make_branch(build.GetInsertBlock(), reentry); } }
void Generator::gen(Break_stmt const* s) { if (!loop_entry_stack.empty()) { llvm::BasicBlock* exit_ = loop_exit_stack.top(); make_branch(build.GetInsertBlock(), exit_); } }
SipMOByeTU::SipMOByeTU(SipDialog *wDialog, string wReasonHeader) // : SipClientTrLayer(wDialog->dsPeer(), make_branch(),wDialog) { LOG(INFO) << "SIP term info SipMOByeTU"; // SVGDBG string branch = make_branch(); SipMessage *bye = new SipMessageRequestWithinDialog(stGetMethodNameV(),wDialog,branch); bye->msmReasonHeader = wReasonHeader; sctInitInDialogClientTransaction(wDialog, bye, branch); delete bye; }
SipMOCancelTU::SipMOCancelTU(SipDialog *wDialog,string wReasonHeader) { // : SipClientTrLayer(wDialog->dsPeer(), make_branch(),wDialog LOG(INFO) << "SIP term info SipMOCancelTU"; // Mobile originate string branch = make_branch(); SipMessage *cancelMsg = new SipMessageRequestWithinDialog(this->stGetMethodNameV(),wDialog,branch); cancelMsg->msmReasonHeader = wReasonHeader; //wDialog->getTermList().copyEntireList(cancelMsg->getTermList()); // SVGDBG SipMOCancelTU this->sctInitInDialogClientTransaction(wDialog, cancelMsg, branch); // Message gets copied in here delete cancelMsg; }
void Generator::gen(While_stmt const* s) { llvm::Function* fn = build.GetInsertBlock()->getParent(); // create while block llvm::BasicBlock* before_while = llvm::BasicBlock::Create(cxt, "before_while", fn); llvm::BasicBlock* while_ = llvm::BasicBlock::Create(cxt, "while", fn); llvm::BasicBlock* after_while = llvm::BasicBlock::Create(cxt, "after_while", fn); // push the entry and exit loop_entry_stack.push(before_while); loop_exit_stack.push(after_while); // emit a branch to the loop entry make_branch(build.GetInsertBlock(), before_while); // emit the block which evaluates the condition build.SetInsertPoint(before_while); // generate the value for the cond llvm::Value* cond = gen(s->condition()); // convert cond to boolean i1 cond = build.CreateICmpEQ(cond, build.getTrue(), "whilecond"); build.CreateCondBr(cond, while_, after_while); // emit the 'while' block build.SetInsertPoint(while_); gen(s->body()); // generate branch back to condition testing block make_branch(build.GetInsertBlock(), before_while); // apparently codegen of 'while' can change the current block, update then for the PHI while_ = build.GetInsertBlock(); // emit the rest of the code in after_while build.SetInsertPoint(after_while); after_while = build.GetInsertBlock(); // pop the entry and exit loop_entry_stack.pop(); loop_exit_stack.pop(); }
// A request inside an invite is ACK, CANCEL, BYE, INFO, or re-INVITE. // The only target-refresh-request is re-INVITE, which can change the "Dialog State". // For ACK sec 17.1.1.3 the To must equal the To of the response being acked, which specifically contains a tag. // ACK contains only one via == top via of original request with matching branch. // TODO: ACK must copy route header fields from INVITE. // sec 9.1 For CANCEL, all fields must == INVITE except the method. Note CSeq must match too. Must have single via // matching the [invite] request being cancelled, with matching branch. TODO: Must copy route header from request. // 15.1.1: BYE is a new request within a dialog as per section 12.2. // transaction constructed as per with a new tag, branch, etc. // It should not include CONTACT because it is non-target-refresh. // // TODO: // 12.2.1.1 The request-URI must be set as follows: // 1. If there is a non-empty route-set and the first route-set URI contains "lr" param, request-URI = remote-target-URI // and must include a Route Header field including all params. // 2. If there is a non-empty route-set and the first UR does not contain "lr" param, // request-URI = first route-route URI with params stripped, and generate new route set with first route removed, // andn then add the remote-target-URI at the end of the route header. // 3. If no route-set, request-URI = remote-target-URI // The remote-target-URI is set by the Contact header only from a INVITE or re-INVITE. SipMessageRequestWithinDialog::SipMessageRequestWithinDialog(string reqMethod, SipBase *dialog, string branch) { this->msmCallId = dialog->callId(); this->msmReqMethod = reqMethod; this->msmCSeqMethod = reqMethod; //this->msmReqUri = dialog->mInvite->msmReqUri; // TODO: WRONG! see comments above. this->msmReqUri = dialog->dsInDialogRequestURI(); // TODO: WRONG! see comments above. this->msmTo = *dialog->dsRequestToHeader(); this->msmFrom = *dialog->dsRequestFromHeader(); this->msmCSeqNum = dialog->dsNextCSeq(); // The BYE seq number must be incremental within the enclosing INVITE dialog. if (branch.empty()) { branch = make_branch(reqMethod.c_str()); } this->smAddViaBranch(dialog,branch); }
// When we hit a return stmt we // 1. generate the code for the return value // 2. store the temp value into the return variable // 3. branch to the return block void Generator::gen(Return_stmt const* s) { // get the current block auto curr_block = build.GetInsertBlock(); // check that this will be the only branch // in the block llvm::Value* v = gen(s->value()); build.CreateStore(v, ret_var); make_branch(curr_block, ret_block); }
SipDtmfTU::SipDtmfTU(SipDialog *wDialog, unsigned wInfo) //: SipClientTrLayer(wDialog->dsPeer(), make_branch(),wDialog) { string branch = make_branch(); SipMessage *msg = new SipMessageRequestWithinDialog(stGetMethodNameV(),wDialog,branch); static const string applicationDtmf("application/dtmf-relay"); string body; switch (wInfo) { case 11: body = string("Signal=*\nDuration=200"); break; case 12: body = string("Signal=#\nDuration=200"); break; default: body = format("Signal=%i\nDuration=200",wInfo); break; } msg->smAddBody(applicationDtmf,body); sctInitInDialogClientTransaction(wDialog, msg, branch); delete msg; }
void Generator::gen(If_else_stmt const* s) { llvm::Value* cond = gen(s->condition()); cond = build.CreateICmpEQ(cond, build.getTrue(), "ifcond"); llvm::Function* fn = build.GetInsertBlock()->getParent(); // create then block llvm::BasicBlock* then = llvm::BasicBlock::Create(cxt, "then", fn); // create an empty else block llvm::BasicBlock* el = llvm::BasicBlock::Create(cxt, "else", fn); // create a merge block llvm::BasicBlock* merge = llvm::BasicBlock::Create(cxt, "ifcont", fn); // create the branch build.CreateCondBr(cond, then, el); // emit the 'then' block build.SetInsertPoint(then); gen(s->true_branch()); make_branch(build.GetInsertBlock(), merge); // apparently codegen of 'then' can change the current block, update then for the PHI then = build.GetInsertBlock(); // emit the else block build.SetInsertPoint(el); gen(s->false_branch()); make_branch(build.GetInsertBlock(), merge); // branch back to merge el = build.GetInsertBlock(); // emit the merge block build.SetInsertPoint(merge); merge = build.GetInsertBlock(); }
static void read_config(void) { unsigned char sha1[20]; const char *head_ref; int flag; if (default_remote_name) // did this already return; default_remote_name = xstrdup("origin"); current_branch = NULL; head_ref = resolve_ref("HEAD", sha1, 0, &flag); if (head_ref && (flag & REF_ISSYMREF) && !prefixcmp(head_ref, "refs/heads/")) { current_branch = make_branch(head_ref + strlen("refs/heads/"), 0); } git_config(handle_config, NULL); alias_all_urls(); }
// A request inside an invite is ACK, CANCEL, BYE, INFO, or re-INVITE. // The only target-refresh-request is re-INVITE, which can change the "Dialog State". // For ACK sec 17.1.1.3 the To must equal the To of the response being acked, which specifically contains a tag. // ACK contains only one via == top via of original request with matching branch. // TODO: ACK must copy route header fields from INVITE. // sec 9.1 For CANCEL, all fields must == INVITE except the method. Note CSeq must match too. Must have single via // matching the [invite] request being cancelled, with matching branch. TODO: Must copy route header from request. // 15.1.1: BYE is a new request within a dialog as per section 12.2. // transaction constructed as per with a new tag, branch, etc. // It should not include CONTACT because it is non-target-refresh. // // TODO: // 12.2.1.1 The request-URI must be set as follows: // 1. If there is a non-empty route-set and the first route-set URI contains "lr" param, request-URI = remote-target-URI // and must include a Route Header field including all params. // 2. If there is a non-empty route-set and the first UR does not contain "lr" param, // request-URI = first route-route URI with params stripped, and generate new route set with first route removed, // andn then add the remote-target-URI at the end of the route header. // 3. If no route-set, request-URI = remote-target-URI // The remote-target-URI is set by the Contact header only from a INVITE or re-INVITE. SipMessageRequestWithinDialog::SipMessageRequestWithinDialog(string reqMethod, SipBase *dialog, bool incrementCSeq, string branch) { this->smInit(); this->msmCallId = dialog->callId(); this->msmReqMethod = reqMethod; this->msmCSeqMethod = reqMethod; //this->msmReqUri = dialog->mInvite->msmReqUri; // TODO: WRONG! see comments above. this->msmReqUri = dialog->dsInDialogRequestURI(); // TODO: WRONG! see comments above. this->msmTo = *dialog->dsRequestToHeader(); this->msmFrom = *dialog->dsRequestFromHeader(); if (incrementCSeq){ //NBYE and Dtmf increment, CANCEL does not -kurtis this->msmCSeqNum = dialog->dsNextCSeq(); // The BYE seq number must be incremental within the enclosing INVITE dialog. } else{ this->msmCSeqNum = dialog->mLocalCSeq; } if (branch.empty()) { branch = make_branch(reqMethod.c_str()); } //this->smAddViaBranch(dialog,branch); // SHOULD NOT CREATE NEW VIA HEADER, USE OLD ONE -kurtis this->smCopyTopVia(dialog->getInvite()); }
static int handle_config(const char *key, const char *value, void *cb) { const char *name; const char *subkey; struct remote *remote; struct branch *branch; if (!prefixcmp(key, "branch.")) { name = key + 7; subkey = strrchr(name, '.'); if (!subkey) return 0; branch = make_branch(name, subkey - name); if (!strcmp(subkey, ".remote")) { if (!value) return config_error_nonbool(key); branch->remote_name = xstrdup(value); if (branch == current_branch) default_remote_name = branch->remote_name; } else if (!strcmp(subkey, ".merge")) { if (!value) return config_error_nonbool(key); add_merge(branch, xstrdup(value)); } return 0; } if (!prefixcmp(key, "url.")) { struct rewrite *rewrite; name = key + 4; subkey = strrchr(name, '.'); if (!subkey) return 0; rewrite = make_rewrite(name, subkey - name); if (!strcmp(subkey, ".insteadof")) { if (!value) return config_error_nonbool(key); add_instead_of(rewrite, xstrdup(value)); } } if (prefixcmp(key, "remote.")) return 0; name = key + 7; if (*name == '/') { warning("Config remote shorthand cannot begin with '/': %s", name); return 0; } subkey = strrchr(name, '.'); if (!subkey) return error("Config with no key for remote %s", name); remote = make_remote(name, subkey - name); remote->origin = REMOTE_CONFIG; if (!strcmp(subkey, ".mirror")) remote->mirror = git_config_bool(key, value); else if (!strcmp(subkey, ".skipdefaultupdate")) remote->skip_default_update = git_config_bool(key, value); else if (!strcmp(subkey, ".url")) { const char *v; if (git_config_string(&v, key, value)) return -1; add_url(remote, v); } else if (!strcmp(subkey, ".push")) { const char *v; if (git_config_string(&v, key, value)) return -1; add_push_refspec(remote, v); } else if (!strcmp(subkey, ".fetch")) { const char *v; if (git_config_string(&v, key, value)) return -1; add_fetch_refspec(remote, v); } else if (!strcmp(subkey, ".receivepack")) { const char *v; if (git_config_string(&v, key, value)) return -1; if (!remote->receivepack) remote->receivepack = v; else error("more than one receivepack given, using the first"); } else if (!strcmp(subkey, ".uploadpack")) { const char *v; if (git_config_string(&v, key, value)) return -1; if (!remote->uploadpack) remote->uploadpack = v; else error("more than one uploadpack given, using the first"); } else if (!strcmp(subkey, ".tagopt")) { if (!strcmp(value, "--no-tags")) remote->fetch_tags = -1; } else if (!strcmp(subkey, ".proxy")) { return git_config_string((const char **)&remote->http_proxy, key, value); } return 0; }
int main ( int narg, char **argv ) { // parse command line ---------------------------------------------- po::options_description general_opt ( "Allowed options are: " ); general_opt.add_options() ( "help,h", "display this message." ) ( "initial,i", po::value< std::string >(), "Initial skeleton pgm filename." ) ( "reduced,r", po::value< std::string >(), "Reduced skeleton pgm filename." ) ( "label,l", po::value< std::string >(), "(part of the) Reduced skeleton being labeled pgm filename." ) ( "selection,s", po::value< std::string >()->multitoken(), "Catch branch touching the given components\' labels of the reduced skeleton.") ( "output,o", po::value< std::string >(), "Extended labeled skeleton pgm filename."); bool parseOK = true ; po::variables_map vm; try { po::store(po::parse_command_line(narg, argv, general_opt), vm); } catch ( const std::exception& ex ) { parseOK = false ; std::cerr<< "Error checking program options: "<< ex.what()<< endl; return -1 ; } po::notify ( vm ); if (!parseOK || vm.count ( "help" ) ||narg<=1 ) { errorAndHelp( general_opt ) ; return -1 ; } if ( ! vm.count("initial") ) missingParam( "initial" ) ; if ( ! vm.count("label") ) missingParam( "label" ) ; if ( ! vm.count("reduced") ) missingParam( "reduced" ) ; if ( ! vm.count("output") ) missingParam( "output" ) ; std::string initialSkelFile = vm["initial"].as<std::string>() ; std::string reducedSkelFile = vm["reduced"].as<std::string>() ; std::string reducedLabelSkelFile = vm["label"].as<std::string>() ; std::string outputSkelFile = vm["output"].as<std::string>() ; QList< tlabel > Labels ; if ( vm.count( "selection" ) ) { QStringList selectedLabels = QString( "%1").arg( vm["selection"].as< std::string >().c_str() ).split( " ", QString::SkipEmptyParts) ; while ( !selectedLabels.isEmpty() ) Labels.append( (tlabel)selectedLabels.takeAt(0).toInt() ) ; qSort( Labels.begin(), Labels.end(), qLess<tlabel>() ) ; std::cout<<"Selection : "; for ( QList< tlabel >::ConstIterator lbl = Labels.begin() ; lbl != Labels.end() ; lbl++ ) std::cout<<"["<<(int) *lbl<<"] " ; std::cout<<std::endl; } BillonTpl< tlabel > *labelReducedSkel ; BillonTpl< arma::u8 > *initialSkel, *reducedSkel ; { Pgm3dFactory< tlabel > factory ; labelReducedSkel = factory.read( QString(reducedLabelSkelFile.c_str()) ) ; } { Pgm3dFactory< arma::u8 > factory ; initialSkel = factory.read( QString(initialSkelFile.c_str()) ) ; if ( initialSkel->max() > 1 ) *initialSkel /= initialSkel->max() ; reducedSkel = factory.read( QString(reducedSkelFile.c_str()) ) ; if ( reducedSkel->max() > 1 ) *reducedSkel /= reducedSkel->max() ; } QList< uint * > touching ; make_branch( initialSkel, reducedSkel, labelReducedSkel, touching ) ; delete reducedSkel ; ConnexComponentExtractor< arma::u8, tlabelbranch > CCE ; BillonTpl< tlabelbranch > * labelBranch = CCE.run( *initialSkel ) ; IOPgm3d< tlabelbranch, qtlabelbranch, false >::write( *labelBranch, "/tmp/whois429.pgm3d" ) ; delete initialSkel ; QMap< tlabelbranch, tlabel > NewLabelBranch ; QMap< tlabel, QList<tlabel> > edges ; set_branch( touching, labelReducedSkel, labelBranch, NewLabelBranch, Labels,edges ) ; attach_branch( labelReducedSkel, labelBranch, NewLabelBranch, Labels ) ; IOPgm3d< tlabel, qtlabel, false >::write( *labelReducedSkel, QString(outputSkelFile.c_str() ) ) ; while ( !touching.isEmpty() ) { delete [] touching.takeFirst() ; } delete labelReducedSkel ; delete labelBranch ; return 0 ; }