int main(int, char *[]) { std::fstream inf("tests/lexer-coverage.neon"); std::stringstream ss; ss << inf.rdbuf(); std::string source = ss.str(); time_t start = get_second(); time_t now; do { now = get_second(); } while (now == start); start = now; int count = 0; do { tokenize("", source); count++; now = get_second(); } while (now - start < 1); printf("count %d\n", count); }
struct arptab *arp_lookup(struct sk_buff *skb, __be32 daddr, unsigned char *mac) { struct arptab *entry; pthread_spin_lock(&arp_lock); entry = &arp_table[arp_hash(daddr)]; if (entry->status == ARP_STATUS_EMPTY) { arp_queue_try_insert(skb); entry->status = ARP_STATUS_REQUEST; pthread_spin_unlock(&arp_lock); arp_request(daddr); goto wait; } else if (entry->status == ARP_STATUS_REQUEST) { arp_queue_try_insert(skb); pthread_spin_unlock(&arp_lock); arp_request(daddr); goto wait; } else { if (get_second() > entry->time + ARP_MAX_LIFE) { arp_queue_try_insert(skb); entry->status = ARP_STATUS_REQUEST; pthread_spin_unlock(&arp_lock); arp_request(daddr); goto wait; } else { memcpy(mac, entry->mac, ETH_ALEN); pthread_spin_unlock(&arp_lock); return entry; } } wait: return NULL; }
InputIterator get( iter_type b, iter_type e, std::ios_base& iob, std::ios_base::iostate& err, std::tm* tm, char fmt, char) const { err = std::ios_base::goodbit; const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(iob.getloc()); switch (fmt) { case 'a': case 'A': { std::tm tm2; std::memset(&tm2, 0, sizeof(std::tm)); that_.get_weekday(b, e, iob, err, &tm2); //tm->tm_wday = tm2.tm_wday; } break; case 'b': case 'B': case 'h': { std::tm tm2; std::memset(&tm2, 0, sizeof(std::tm)); that_.get_monthname(b, e, iob, err, &tm2); //tm->tm_mon = tm2.tm_mon; } break; // case 'c': // { // const string_type& fm = c(); // b = get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size()); // } // break; case 'd': case 'e': get_day(tm->tm_mday, b, e, err, ct); break; case 'D': { const char_type fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'}; b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0])); } break; case 'F': { const char_type fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'}; b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0])); } break; case 'H': get_hour(tm->tm_hour, b, e, err, ct); break; case 'I': get_12_hour(tm->tm_hour, b, e, err, ct); break; case 'j': get_day_year_num(tm->tm_yday, b, e, err, ct); break; case 'm': get_month(tm->tm_mon, b, e, err, ct); break; case 'M': get_minute(tm->tm_min, b, e, err, ct); break; case 'n': case 't': get_white_space(b, e, err, ct); break; // case 'p': // get_am_pm(tm->tm_hour, b, e, err, ct); // break; case 'r': { const char_type fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'}; b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0])); } break; case 'R': { const char_type fm[] = {'%', 'H', ':', '%', 'M'}; b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0])); } break; case 'S': get_second(tm->tm_sec, b, e, err, ct); break; case 'T': { const char_type fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0])); } break; case 'w': { get_weekday(tm->tm_wday, b, e, err, ct); } break; case 'x': return that_.get_date(b, e, iob, err, tm); // case 'X': // return that_.get_time(b, e, iob, err, tm); // { // const string_type& fm = X(); // b = that_.get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size()); // } // break; // case 'y': // get_year(tm->tm_year, b, e, err, ct); break; case 'Y': get_year4(tm->tm_year, b, e, err, ct); break; case '%': get_percent(b, e, err, ct); break; default: err |= std::ios_base::failbit; } return b; }
ITime &Time::clone(void) const { return (*new Time(get_second(), get_nano())); }
int main() { print_time(get_second()); return 0; }
void arp_rcv(struct sk_buff *skb) { struct arppkt *ap; struct ethhdr *eh; unsigned int tip, sip; struct arptab *h; int hl; struct net_device *nic; hl = sizeof(struct ethhdr); skb->len -= hl; ap = (struct arppkt *) skb->data; skb->nh.arph = (struct arphdr *) skb->data; eh = (struct ethhdr *) (skb->data - hl); nic = skb->nic; /* skb->data += sizeof(struct arphdr); */ printf("--- ARP: packet received\n"); if (ap->ar_hrd != htons(ARPHRD_ETHER) || ap->ar_pro != htons(ETHERTYPE_IP) || ap->ar_hln != ETH_ALEN || ap->ar_pln != 4) goto bad; switch (ntohs(ap->ar_op)) { case ARPOP_REQUEST: tip = *(unsigned int *)ap->__ar_tip; sip = *(unsigned int *)ap->__ar_sip; if (tip != skb->nic->ip) goto drop; ap->ar_op = htons(ARPOP_REPLY); *(unsigned int *)ap->__ar_sip = skb->nic->ip; *(unsigned int *)ap->__ar_tip = sip; memcpy(ap->__ar_sha, skb->nic->dev_addr, ETH_ALEN); memcpy(ap->__ar_tha, eh->h_source, ETH_ALEN); memcpy(eh->h_dest, eh->h_source, ETH_ALEN); memcpy(eh->h_source, skb->nic->dev_addr, ETH_ALEN); skb->len +=14; skb->ip_summed = 0; skb->protocol = ETHERTYPE_ARP; dev_send(skb); goto reused; break; case ARPOP_REPLY: sip = *(unsigned int *)ap->__ar_sip; tip = *(unsigned int *)ap->__ar_tip; pthread_spin_lock(&arp_lock); h = &arp_table[arp_hash(sip)]; if (/* h->ip == sip && */ nic->ip == tip) { if (ap->__ar_sha[0] & 1) /* why? */ goto unlock_bad; memcpy(h->mac, ap->__ar_sha, ETH_ALEN); /* if (h->hold && (tv.tv_sec - h->time > ARP_MAX_HOLD)) */ /* { */ /* skb_free(h->hold); */ /* h->hold = NULL; */ /* } */ h->time = get_second(); if (h->status == ARP_STATUS_REQUEST) { h->status = ARP_STATUS_OK; pthread_spin_unlock(&arp_lock); pthread_cond_signal(&arp_queue_check); } else { /* received broadcast reply who was not requested */ h->status = ARP_STATUS_OK; pthread_spin_unlock(&arp_lock); } /* if ((skb = h->hold)) */ /* { */ /* h->hold = NULL; */ /* memcpy(eh->h_dest, h->mac, ETH_ALEN); */ /* pthread_spin_unlock(&arp_lock); */ /* /\* fragmentation? *\/ */ /* dev_send(skb); */ /* } */ /* else */ /* pthread_spin_unlock(&arp_lock); */ } else { goto unlock_bad; } break; default: goto bad; } reused: return; bad: printf("arp: packet invalid\n"); drop: skb_free(skb); return; unlock_bad: pthread_spin_unlock(&arp_lock); skb_free(skb); }
void Generator::optimize() { bool flag = true; std::list<std::pair<std::string, std::string>> label_list; std::list<std::pair<std::string, std::string>> var_list; do { auto first_instr = commands_.begin(); auto second_instr = ++commands_.begin(); auto decl_it = first_instr; flag = false; do { if (*first_instr == cmd_wrlab && first_instr->get_first() == op_null && first_instr->get_first()->get_name() == "\ninclude source\\end.inc\n") { decl_it = first_instr; ++first_instr; ++second_instr; } // push a // pop b if(*first_instr == cmd_push && *second_instr == cmd_pop) { // a != b -> mov b, a if (first_instr->get_first() != second_instr->get_first() && second_instr->get_first() == op_register) { commands_.insert(first_instr, Instruction(cmd_mov, second_instr->get_first(), first_instr->get_first())); delete_instr(first_instr, second_instr); flag = true; } if(first_instr->get_first() == second_instr->get_second()) { delete_instr(first_instr, second_instr); flag = true; } } // pop r // push r // -> delete pop && push if(*first_instr == cmd_pop && *second_instr == cmd_push && first_instr->get_first() == second_instr->get_first()) { delete_instr(first_instr, second_instr); flag = true; } // ... // label1: // label2: // ... // -> delete label1 if (*first_instr == cmd_wrlab && *second_instr == cmd_wrlab && first_instr->get_first() == op_label && second_instr->get_first() == op_label) { label_list.push_back(std::make_pair(first_instr->get_first()->get_name(), second_instr->get_first()->get_name())); delete_instr(first_instr); flag = true; } //change deleted labels in jumps if (is_jump(first_instr->get_cmd())) { for each(auto it in label_list) if (it.first == first_instr->get_first()->get_name()) { first_instr->get_first()->set_name(it.second); flag = true; break; } } // jmp label // label: // -> delete jmp if (*first_instr == cmd_jmp && *second_instr == cmd_wrlab && first_instr->get_first()->get_name() == second_instr->get_first()->get_name()) { delete_instr(first_instr); flag = true; } // jmp l1 // jmp l2 // -> delete l2 if (*first_instr == cmd_jmp && *second_instr == cmd_jmp) { second_instr = commands_.erase(second_instr); flag = true; } //mov r, 0 -> xor r, r if (*first_instr == cmd_mov && first_instr->get_first() == op_register && first_instr->get_second()->get_name() == "0") { commands_.insert(first_instr, Instruction(cmd_xor, first_instr->get_first(), first_instr->get_first())); delete_instr(first_instr); flag = true; } // mov r, r // -> delete if (*first_instr == cmd_mov && first_instr->get_first() == first_instr->get_second()) { delete_instr(first_instr); flag = true; } // add r, 0 || sub r, 0 // -> delete if ((*first_instr == cmd_add || *first_instr == cmd_sub) && first_instr->get_second() == "0") { delete_instr(first_instr); flag = true; } // add r, 1 // -> inc r if (*first_instr == cmd_add && first_instr->get_second()->get_name() == "1") { commands_.insert(first_instr, Instruction(cmd_inc, first_instr->get_first())); delete_instr(first_instr); flag = true; } // sub r, 1 // -> dec r if (*first_instr == cmd_sub && first_instr->get_second()->get_name() == "1") { commands_.insert(first_instr, Instruction(cmd_dec, first_instr->get_first())); delete_instr(first_instr); flag = true; } // mov r, 1 // dec r // -> xor r, r if (*first_instr == cmd_mov && *second_instr == cmd_dec && first_instr->get_first() == second_instr->get_first() && first_instr->get_second()->get_name() == "1") { commands_.insert(first_instr, Instruction(cmd_xor, first_instr->get_first(), first_instr->get_first())); delete_instr(first_instr, second_instr); flag = true; } // xor r, r // imul r, i || add a, r || sub a, r || div r, i // -> delete imul/add/sub if (*first_instr == cmd_xor && (((*second_instr == cmd_imul || *second_instr == cmd_idiv) && first_instr->get_first() == second_instr->get_first()) || ((*second_instr == cmd_add || *second_instr == cmd_sub) && first_instr->get_first() == second_instr->get_second()))) { second_instr = commands_.erase(second_instr); flag = true; } // val1 dq 1.2 // val2 dq 1.2 // -> delete val2, and use val1 instead val2 if (*first_instr == cmd_const_decl) { for (auto it = decl_it; it != commands_.end(); ++it) if (*it == cmd_const_decl && first_instr->get_first()->get_name() != (*it).get_first()->get_name() && first_instr->get_second()->get_name() == (*it).get_second()->get_name()) { var_list.push_back(std::make_pair(it->get_first()->get_name(), first_instr->get_first()->get_name())); if (second_instr == it) ++second_instr; it = commands_.erase(it); flag = true; } } if ((*first_instr == cmd_push && first_instr->get_first() == op_memory) || (*first_instr == cmd_mov && first_instr->get_first() == op_register && first_instr->get_second() == op_memory)) for each(auto it in var_list) { if ("qword ptr " + it.first == first_instr->get_first()->get_name()) { first_instr->get_first()->set_name("qword ptr " + it.second); flag = true; break; } else if ("offset " + it.first == first_instr->get_second()->get_name()) { first_instr->get_second()->set_name("offset " + it.second); flag = true; break; } } ++first_instr; ++second_instr; } while (second_instr != commands_.end()); } while(flag); }
int main(int argc,char **argv,char **environ) { unsigned int seconds = 0; int seconds_flag = 0; unsigned int wait_seconds; unsigned int proc_seconds; int wait_mode = 0; int proc_wait = 0; char **cmd_argv = NULL; int child_pid = 0; int job_count_flag = 0; int job_count_exit = 0; unsigned long job_counter = 1; int c; int first_do_flag = 0; int exitcode_flag = 0; int exitcode,exitcodewk; int init_sec_flag = 0; unsigned int init_seconds = 0; extern char *optarg; extern int optind, opterr, optopt; setvbuf(stdout,NULL,_IONBF,0); setvbuf(stdin,NULL,_IONBF,0); progname = *(argv + 0); seconds_flag = 0; first_do_flag = 0; exitcode_flag = 0; exitcode = exitcodewk = 0; job_counter = 1; init_sec_flag = 0; init_seconds = 0; while(1) { c = getopt(argc,argv,"ae:TWc:C:vhlLi:"); if(c == EOF) break; switch(c) { case 'a': first_do_flag = 1; init_sec_flag = 0; break; case 'e': exitcode_flag = 1; exitcode = strtoul(optarg, (char **)NULL, 10); break; case 'T': wait_mode = 1; break; case 'W': proc_wait = 1; break; case 'C': job_count_exit = 1; case 'c': job_count_flag = 1; job_counter = strtoul(optarg, (char **)NULL, 10); break; case 'v': printf("%s\n",RCSid); case 'h': print_help(); return 0; break; case 'l': print_time_flag = 1; break; case 'L': print_time_flag = 2; break; case 'i': init_sec_flag = 1; first_do_flag = 0; init_seconds = get_second(optarg); break; default : return 127; } } if (optind < argc) { seconds = get_second(argv[optind]); optind++; } if (optind < argc) { cmd_argv = argv + optind; } if((seconds == 0) || (cmd_argv == NULL)) { print_help(); exit(0); } #if 1 { int i; print_time(); printf("cron_job_start : %u %d %d %d\n",seconds,wait_mode,proc_wait,first_do_flag); print_time(); printf("cron_job_count : %u %d %d\n",job_counter,job_count_flag,job_count_exit); print_time(); printf("cron_job_exit : %d %d\n",exitcode_flag,exitcode); print_time(); printf("cron_job_args : "); for(i = 0;cmd_argv[i] != NULL;i++) { printf("[%s]",cmd_argv[i]); } printf("\n"); } #endif wait_seconds = seconds; /* main loop */ while((job_counter != 0) || (job_count_exit == 0)) { do_job = 0; do_job_force = 0; proc_seconds = 0; if(init_sec_flag != 0) { wait_seconds = time(NULL); if(init_seconds <= wait_seconds) wait_seconds = seconds; else wait_seconds = init_seconds - wait_seconds; print_time(); printf("cron_job_init_time : %u\n",wait_seconds); } init_sec_flag = 0; signal(SIGALRM, alarm_signal); signal(SIGHUP, hup_signal); if((first_do_flag != 0) || (timer_wait(wait_mode,wait_seconds) != 0)) { signal(SIGALRM, SIG_IGN); signal(SIGHUP, SIG_IGN); if(check_cronexec_do( ((do_job_force != 0) || (job_counter > 0)) ) != 0) { if((do_job_force != 0) || (job_counter > 0)) { child_pid = cron_job(cmd_argv,environ); if(child_pid > 0) proc_seconds = wait_proc(child_pid,exitcode_flag,exitcode,&exitcodewk); if((job_count_flag != 0) && (job_counter > 0)) job_counter--; } } } first_do_flag = 0; wait_seconds = seconds; if(proc_wait != 0) wait_seconds -= (clock_t2seconds(proc_seconds) % seconds); } print_time(); printf("cron_job_end\n"); return 0; }