void test_const() { test_exception e; boost::exception const & c(e); boost::exception & m(e); BOOST_TEST(is_const(boost::get_error_info<test_1>(c))); BOOST_TEST(!is_const(boost::get_error_info<test_1>(m))); }
// *change 1.2.3a 'do_strict' insists that the signatures match exactly; otherwise // we allow for looser matches (particularly method signatures) bool Signature::match(const Signature& sig, bool do_strict) const { // Comparing signatures // *fix 1.2.2b (Eric) Functions w/ no args can be incorrectly matched if (this == &sig) return true; if (size() != sig.size() || !class_ptr() != !sig.class_ptr()) return false; // *fix 1.2.3 Method signatures made tighter in 'exact match' mode if (class_ptr() != NULL && sig.class_ptr() != NULL) { if ((do_strict && class_ptr() != sig.class_ptr()) || !sig.class_ptr()->inherits_from(class_ptr())) return false; // *fix 1.2.1 Member function signatures are distinct! } if (is_const() != sig.is_const()) return false; // *fix 0.9.6 constness makes signatures distinct if (stdarg() != sig.stdarg()) return false; // *fix 1.2.3 (Eric) And so does whether this is stdarg or not Signature::iterator ti,tio; try { for(ti = begin(), tio = sig.begin(); ti != end(); ++ti,++tio) if (!(*ti == *tio)) return false; } catch(...) { return false; } //* return tio == sig.end() && ti == end(); //true; return true; }
/* Returns instantiate token list in a string (last argument) Uses CONNECTOR to connect the tokens together. if "failflag" is 0 then Return 1 if ok, 0 if failure. Otherwise, exit on failure. */ int instantiate_into_string(token_list l, instantiation_list inst,char str[], int failflag) { instantiation_list i; char *p; token_list t = l; for(p = str; t; t = t->next) { if (is_const(t->item)) /* just copy over */ { strcpy(p,t->item); p+=strlen(t->item); *p++ = CONNECTOR; } else { for(i=inst; i; i = i->next) if (strcmp(i->var_part, t->item) == SAME) { if (i->const_part == NULL) {i = NULL; break;} strcpy(p,i->const_part);p+=strlen(i->const_part);*p++ = CONNECTOR; break; } if (!i) { if (failflag) do_error("instantiation failed"); return 0; } } } *(--p) = '\0'; return 1; }
bool is_const(Expr e) { if (e.as<IntImm>()) return true; if (e.as<FloatImm>()) return true; if (const Cast *c = e.as<Cast>()) { return is_const(c->value); } if (const Ramp *r = e.as<Ramp>()) { return is_const(r->base) && is_const(r->stride); } if (const Broadcast *b = e.as<Broadcast>()) { return is_const(b->value); } return false; }
inline int get_repeat(struct ir_remote *remote) { if (!get_lead(remote)) return (0); if (is_biphase(remote)) { if (!expectspace(remote, remote->srepeat)) return (0); if (!expectpulse(remote, remote->prepeat)) return (0); } else { if (!expectpulse(remote, remote->prepeat)) return (0); set_pending_space(remote->srepeat); } if (!get_trail(remote)) return (0); if (!get_gap (remote, is_const(remote) ? (min_gap(remote) > rec_buffer.sum ? min_gap(remote) - rec_buffer.sum : 0) : (has_repeat_gap(remote) ? remote->repeat_gap : min_gap(remote)) )) return (0); return (1); }
Dimension Dimension::set_extent(Expr extent) { param.set_extent_constraint(d, extent); // Propagate constant bounds into estimates as well. if (is_const(extent)) { param.set_extent_constraint_estimate(d, extent); } return *this; }
Dimension Dimension::set_min(Expr min) { param.set_min_constraint(d, min); // Propagate constant bounds into estimates as well. if (is_const(min)) { param.set_min_constraint_estimate(d, min); } return *this; }
bool cmp_operand(Operand first, Operand second) { if (first == second) { return true; } else if (is_const(first) && is_const(second) && first->type == second->type) { switch (first->type) { case OPE_INTEGER: return first->integer == second->integer; case OPE_CHAR: return first->integer == second->integer; case OPE_FLOAT: return first->real == second->real; default: PANIC("Unexpected"); } return false; } else { return false; } }
void Lex_analyzer::addToken(int tokenType, QString tokenValue){ TokenType *t = new TokenType; Token *tok = new Token; switch(tokenType){ case 1: if(is_keyword(tokenValue,t)){ qDebug() <<"Token" <<tokenValue <<"found in keywords: id=" <<t->id <<"type=" <<t->type <<endl; tok->id=t->id; tok->tokclass = "keywords"; tok->toktype = t->type; tok->value = tokenValue; tokens->append(tok); }else if(is_type(tokenValue,t)){ qDebug() <<"Token" <<tokenValue <<"found in types: id=" <<t->id <<"type=" <<t->type <<endl; tok->id=t->id; tok->tokclass = "types"; tok->toktype = t->type; tok->value = tokenValue; tokens->append(tok); }else{ is_id(tokenValue, t); qDebug() <<"Token" <<tokenValue <<"found in/inserted to ids: id=" <<t->id <<"type=" <<t->type <<endl; tok->id=t->id; tok->tokclass = "ids"; tok->toktype = t->type; tok->value = tokenValue; tokens->append(tok); } break; case 2: is_const(tokenValue, t); qDebug() <<"Token" <<tokenValue <<"found in/inserted to constants: id=" <<t->id <<"type=" <<t->type <<endl; tok->id=t->id; tok->tokclass = "constants"; tok->toktype = t->type; tok->value = tokenValue; tokens->append(tok); break; case 3: case 4: if(is_operator(tokenValue, t)){ qDebug() <<"Token" <<tokenValue <<"found in operators/separators: id=" <<t->id <<"type=" <<t->type <<endl; tok->id=t->id; tok->tokclass = "separators"; tok->toktype = t->type; tok->value = tokenValue; tokens->append(tok); }else{ qDebug() <<"Error unknown token type: " <<tokenType <<endl; } break; default: qDebug() <<"Error unknown token type: " <<tokenType <<endl; } qDebug() <<"Adding token of type[" <<tokenType <<"] = " <<tokenValue <<endl; }
static int sanityChecks(struct ir_remote *rem) { struct ir_ncode *codes; struct ir_code_node *node; if (!rem->name) { logprintf(LOG_ERR,"you must specify a remote name"); return 0; } if(rem->gap == 0) { logprintf(LOG_WARNING, "you should specify a valid gap value"); } if(has_repeat_gap(rem) && is_const(rem)) { logprintf(LOG_WARNING, "repeat_gap will be ignored if " "CONST_LENGTH flag is set"); } if(is_raw(rem)) return 1; if((rem->pre_data&gen_mask(rem->pre_data_bits)) != rem->pre_data) { logprintf(LOG_WARNING, "invalid pre_data found for %s", rem->name); rem->pre_data &= gen_mask(rem->pre_data_bits); } if((rem->post_data&gen_mask(rem->post_data_bits)) != rem->post_data) { logprintf(LOG_WARNING, "invalid post_data found for %s", rem->name); rem->post_data &= gen_mask(rem->post_data_bits); } for(codes = rem->codes; codes->name != NULL; codes++) { if((codes->code&gen_mask(rem->bits)) != codes->code) { logprintf(LOG_WARNING, "invalid code found for %s: %s", rem->name, codes->name); codes->code &= gen_mask(rem->bits); } for(node = codes->next; node != NULL; node = node->next) { if((node->code&gen_mask(rem->bits)) != node->code) { logprintf(LOG_WARNING, "invalid code found " "for %s: %s", rem->name, codes->name); node->code &= gen_mask(rem->bits); } } } return 1; }
void match_types(Expr &a, Expr &b) { if (a.type() == b.type()) return; // First widen to match if (a.type().is_scalar() && b.type().is_vector()) { a = new Broadcast(a, b.type().width); } else if (a.type().is_vector() && b.type().is_scalar()) { b = new Broadcast(b, a.type().width); } else { assert(a.type().width == b.type().width && "Can't match types of differing widths"); } Type ta = a.type(), tb = b.type(); if (!ta.is_float() && tb.is_float()) { // int(a) * float(b) -> float(b) // uint(a) * float(b) -> float(b) a = cast(tb, a); } else if (ta.is_float() && !tb.is_float()) { b = cast(ta, b); } else if (ta.is_float() && tb.is_float()) { // float(a) * float(b) -> float(max(a, b)) if (ta.bits > tb.bits) b = cast(ta, b); else a = cast(tb, a); } else if (!ta.is_float() && !tb.is_float() && is_const(b)) { // (u)int(a) * (u)intImm(b) -> int(a) b = cast(ta, b); } else if (!tb.is_float() && !ta.is_float() && is_const(a)) { a = cast(tb, a); } else if (ta.is_uint() && tb.is_uint()) { // uint(a) * uint(b) -> uint(max(a, b)) if (ta.bits > tb.bits) b = cast(ta, b); else a = cast(tb, a); } else if (!ta.is_float() && !tb.is_float()) { // int(a) * (u)int(b) -> int(max(a, b)) int bits = std::max(ta.bits, tb.bits); a = cast(Int(bits), a); b = cast(Int(bits), b); } else { std::cerr << "Could not match types: " << ta << ", " << tb << std::endl; assert(false && "Failed type coercion"); } }
Expr Interval::make_min(Expr a, Expr b) { if (a.same_as(b)) return a; // Deal with infinities if (a.same_as(Interval::pos_inf)) return b; if (b.same_as(Interval::pos_inf)) return a; if (a.same_as(Interval::neg_inf)) return a; if (b.same_as(Interval::neg_inf)) return b; // Deep equality if (equal(a, b)) return a; // Constant fold const int64_t *ia = as_const_int(a); const int64_t *ib = as_const_int(b); const uint64_t *ua = as_const_uint(a); const uint64_t *ub = as_const_uint(b); const double *fa = as_const_float(a); const double *fb = as_const_float(b); if (ia && ib) return (*ia > *ib) ? b : a; if (ua && ub) return (*ua > *ub) ? b : a; if (fa && fb) return (*fa > *fb) ? b : a; // Balance trees to the left, with constants pushed rightwards const Min *ma = a.as<Min>(); const Min *mb = b.as<Min>(); if (mb && !ma && !(is_const(mb->a) && is_const(mb->b))) { std::swap(ma, mb); std::swap(a, b); } if (ma && is_const(ma->b) && is_const(b)) { return Interval::make_min(ma->a, Interval::make_min(ma->b, b)); } if (ma && (ma->a.same_as(b) || ma->b.same_as(b))) { // b is already represented in a return a; } return Min::make(a, b); }
void CodeGen_X86::visit(const Sub *op) { vector<Expr> matches; if (should_use_pmaddwd(op->a, op->b, matches)) { // Negate one of the factors in the second expression if (is_const(matches[2])) { matches[2] = -matches[2]; } else { matches[3] = -matches[3]; } codegen(Call::make(op->type, "pmaddwd", matches, Call::Extern)); } else { CodeGen_Posix::visit(op); } }
// 常量计算 Operand calc_const(IR_Type op, Operand left, Operand right) { assert(left->type == right->type && is_const(left)); assert(IR_ADD <= op && op <= IR_DIV); Operand rst = new_operand(left->type); switch (left->type) { case OPE_INTEGER: case OPE_CHAR:{ switch (op) { case IR_ADD: rst->integer = left->integer + right->integer; break; case IR_SUB: rst->integer = left->integer - right->integer; break; case IR_MUL: rst->integer = left->integer * right->integer; break; case IR_DIV: rst->integer = left->integer / right->integer; break; default: assert(0); } break; } case OPE_FLOAT: { switch (op) { case IR_ADD: rst->real = left->real + right->real; break; case IR_SUB: rst->real = left->real - right->real; break; case IR_MUL: rst->real = left->real * right->real; break; case IR_DIV: rst->real = left->real / right->real; break; default: assert(0); } break; } default: assert(0); } return rst; }
static int fold_unaryop(expr_ty node, PyArena *arena, int optimize) { expr_ty arg = node->v.UnaryOp.operand; if (!is_const(arg)) { /* Fold not into comparison */ if (node->v.UnaryOp.op == Not && arg->kind == Compare_kind && asdl_seq_LEN(arg->v.Compare.ops) == 1) { /* Eq and NotEq are often implemented in terms of one another, so folding not (self == other) into self != other breaks implementation of !=. Detecting such cases doesn't seem worthwhile. Python uses </> for 'is subset'/'is superset' operations on sets. They don't satisfy not folding laws. */ int op = asdl_seq_GET(arg->v.Compare.ops, 0); switch (op) { case Is: op = IsNot; break; case IsNot: op = Is; break; case In: op = NotIn; break; case NotIn: op = In; break; default: op = 0; } if (op) { asdl_seq_SET(arg->v.Compare.ops, 0, op); COPY_NODE(node, arg); return 1; } } return 1; } typedef PyObject *(*unary_op)(PyObject*); static const unary_op ops[] = { [Invert] = PyNumber_Invert, [Not] = unary_not, [UAdd] = PyNumber_Positive, [USub] = PyNumber_Negative, };
int pixelview_decode(struct ir_remote *remote, ir_code *prep,ir_code *codep,ir_code *postp, int *repeat_flagp,lirc_t *remaining_gapp) { #if 0 if(remote->pone!=0 || remote->sone!=833) return(0); if(remote->pzero!=833 || remote->szero!=0) return(0); #endif if(!map_code(remote,prep,codep,postp, 10,pre,20,code,0,0)) { return(0); } gap=0; if(start.tv_sec-last.tv_sec>=2) /* >1 sec */ { *repeat_flagp=0; } else { gap=(start.tv_sec-last.tv_sec)*1000000+ start.tv_usec-last.tv_usec; if(gap<remote->remaining_gap*(100+remote->eps)/100 || gap<=remote->remaining_gap+remote->aeps) *repeat_flagp=1; else *repeat_flagp=0; } *remaining_gapp=is_const(remote) ? (remote->gap>signal_length ? remote->gap-signal_length:0): remote->gap; LOGPRINTF(1,"pre: %llx",(unsigned long long) *prep); LOGPRINTF(1,"code: %llx",(unsigned long long) *codep); LOGPRINTF(1,"repeat_flag: %d",*repeat_flagp); LOGPRINTF(1,"gap: %lu",(unsigned long) gap); LOGPRINTF(1,"rem: %lu",(unsigned long) remote->remaining_gap); LOGPRINTF(1,"signal length: %lu",(unsigned long) signal_length); return(1); }
int pinsys_decode(struct ir_remote *remote, ir_code *prep,ir_code *codep,ir_code *postp, int *repeat_flagp,lirc_t *remaining_gapp) { if(!map_code(remote,prep,codep,postp, 0,0,8,code&(~REPEAT_FLAG),0,0)) { return(0); } gap=0; if(start.tv_sec-last.tv_sec>=2) /* >1 sec */ { *repeat_flagp=0; } else { gap=(start.tv_sec-last.tv_sec)*1000000+ start.tv_usec-last.tv_usec; if(gap<remote->remaining_gap*(100+remote->eps)/100 || gap<=remote->remaining_gap+remote->aeps) *repeat_flagp=1; else *repeat_flagp=0; /* let's believe the remote */ if(code&REPEAT_FLAG) { *repeat_flagp=1; } } *remaining_gapp=is_const(remote) ? (remote->gap>signal_length ? remote->gap-signal_length:0): remote->gap; LOGPRINTF(1,"code: %llx\n",(unsigned long long) *codep); LOGPRINTF(1,"repeat_flag: %d\n",*repeat_flagp); LOGPRINTF(1,"gap: %lu\n",(unsigned long) gap); LOGPRINTF(1,"rem: %lu\n",(unsigned long) remote->remaining_gap); LOGPRINTF(1,"signal length: %lu\n",(unsigned long) signal_length); return(1); }
Operand get_neg(Operand ope) { if (is_const(ope)) { Operand p = new_operand(ope->type); if (ope->type == OPE_INTEGER) { p->integer = -ope->integer; } else if (ope->type == OPE_FLOAT) { p->real = -ope->real; } else { LOG("Error"); assert(0); } return p; } else { LOG("Not const"); assert(0); } }
int mp3anywhere_decode(struct ir_remote *remote, ir_code *prep,ir_code *codep,ir_code *postp, int *repeat_flagp,lirc_t *remaining_gapp) { if(!map_code(remote,prep,codep,postp, 24,pre,8,code,0,0)) { return(0); } gap=0; if(start.tv_sec-last.tv_sec>=2) /* >1 sec */ { *repeat_flagp=0; } else { gap=(start.tv_sec-last.tv_sec)*1000000+ start.tv_usec-last.tv_usec; if(gap<remote->remaining_gap*(100+remote->eps)/100 || gap<=remote->remaining_gap+remote->aeps) *repeat_flagp=1; else *repeat_flagp=0; } *remaining_gapp=is_const(remote) ? (remote->gap>signal_length ? remote->gap-signal_length:0): remote->gap; LOGPRINTF(1,"pre: %llx",(unsigned long long) *prep); LOGPRINTF(1,"code: %llx",(unsigned long long) *codep); LOGPRINTF(1,"repeat_flag: %d",*repeat_flagp); LOGPRINTF(1,"gap: %lu",(unsigned long) gap); LOGPRINTF(1,"rem: %lu",(unsigned long) remote->remaining_gap); LOGPRINTF(1,"signal length: %lu",(unsigned long) signal_length); return(1); }
void to_string(Polynomial *poly){ Term *term; for (int i = 0; i < poly->num_terms; i++){ term = &(poly->terms[i]); if (term->coeff.den == 1){ if (is_const(*term, poly->num_vars)) { printf("%+d", term->coeff.num); } else if (i == 0 && term->coeff.num != 1) { printf("%d", term->coeff.num); } else if (i != 0 && term->coeff.num != 1){ printf("%+d", term->coeff.num); } else if (i != 0 && term->coeff.num == 1) { printf("+"); } } else if (i != 0){ printf("%+d/%d", term->coeff.num, term->coeff.den); } else { printf("%d/%d", term->coeff.num, term->coeff.den); } for (int j = 0; j < poly->num_vars; j++){ if (term->pow[j] != 0) { if (term->pow[j] == 1) { printf("%c", poly->vars[j]); } else { printf("%c^%d", poly->vars[j], term->pow[j]); } } } printf(" "); } printf("\n"); }
static std::string format_parameters(const std::vector<Boxed_Value> &t_parameters, bool t_dot_notation, const chaiscript::detail::Dispatch_Engine &t_ss) { std::stringstream ss; ss << "("; if (!t_parameters.empty()) { std::string paramstr; for (auto itr = t_parameters.begin(); itr != t_parameters.end(); ++itr) { paramstr += (itr->is_const()?"const ":""); paramstr += t_ss.type_name(*itr); if (itr == t_parameters.begin() && t_dot_notation) { paramstr += ").("; if (t_parameters.size() == 1) { paramstr += ", "; } } else { paramstr += ", "; } } ss << paramstr.substr(0, paramstr.size() - 2); } ss << ")"; return ss.str(); }
int receive_decode(struct ir_remote *remote, ir_code *prep,ir_code *codep,ir_code *postp, int *repeat_flagp,lirc_t *remaining_gapp) { ir_code pre,code,post,code_mask=0,post_mask=0; lirc_t sync; int header; struct timeval current; sync=0; /* make compiler happy */ code=pre=post=0; header=0; if(hw.rec_mode==LIRC_MODE_MODE2 || hw.rec_mode==LIRC_MODE_PULSE || hw.rec_mode==LIRC_MODE_RAW) { rewind_rec_buffer(); rec_buffer.is_biphase=is_biphase(remote) ? 1:0; /* we should get a long space first */ if(!(sync=sync_rec_buffer(remote))) { LOGPRINTF(1,"failed on sync"); return(0); } LOGPRINTF(1,"sync"); if(has_repeat(remote) && last_remote==remote) { if(remote->flags&REPEAT_HEADER && has_header(remote)) { if(!get_header(remote)) { LOGPRINTF(1,"failed on repeat " "header"); return(0); } LOGPRINTF(1,"repeat header"); } if(get_repeat(remote)) { if(remote->last_code==NULL) { logprintf(LOG_NOTICE,"repeat code " "without last_code " "received"); return(0); } *prep=remote->pre_data; *codep=remote->last_code->code; *postp=remote->post_data; *repeat_flagp=1; *remaining_gapp= is_const(remote) ? (remote->gap>rec_buffer.sum ? remote->gap-rec_buffer.sum:0): (has_repeat_gap(remote) ? remote->repeat_gap:remote->gap); return(1); } else { LOGPRINTF(1,"no repeat"); rewind_rec_buffer(); sync_rec_buffer(remote); } } if(has_header(remote)) { header=1; if(!get_header(remote)) { header=0; if(!(remote->flags&NO_HEAD_REP && (sync<=remote->gap+remote->gap*remote->eps/100 || sync<=remote->gap+remote->aeps))) { LOGPRINTF(1,"failed on header"); return(0); } } LOGPRINTF(1,"header"); } } if(is_raw(remote)) { struct ir_ncode *codes,*found; int i; if(hw.rec_mode==LIRC_MODE_CODE || hw.rec_mode==LIRC_MODE_LIRCCODE) return(0); codes=remote->codes; found=NULL; while(codes->name!=NULL && found==NULL) { found=codes; for(i=0;i<codes->length;) { if(!expectpulse(remote,codes->signals[i++])) { found=NULL; rewind_rec_buffer(); sync_rec_buffer(remote); break; } if(i<codes->length && !expectspace(remote,codes->signals[i++])) { found=NULL; rewind_rec_buffer(); sync_rec_buffer(remote); break; } } codes++; } if(found!=NULL) { if(!get_gap(remote, is_const(remote) ? remote->gap-rec_buffer.sum: remote->gap)) found=NULL; } if(found==NULL) return(0); code=found->code; } else { if(hw.rec_mode==LIRC_MODE_CODE || hw.rec_mode==LIRC_MODE_LIRCCODE) { int i; lirc_t sum; # ifdef LONG_IR_CODE LOGPRINTF(1,"decoded: %llx",rec_buffer.decoded); # else LOGPRINTF(1,"decoded: %lx",rec_buffer.decoded); # endif if((hw.rec_mode==LIRC_MODE_CODE && hw.code_length<remote->pre_data_bits +remote->bits+remote->post_data_bits) || (hw.rec_mode==LIRC_MODE_LIRCCODE && hw.code_length!=remote->pre_data_bits +remote->bits+remote->post_data_bits)) { return(0); } for(i=0;i<remote->post_data_bits;i++) { post_mask=(post_mask<<1)+1; } post=rec_buffer.decoded&post_mask; post_mask=0; rec_buffer.decoded= rec_buffer.decoded>>remote->post_data_bits; for(i=0;i<remote->bits;i++) { code_mask=(code_mask<<1)+1; } code=rec_buffer.decoded&code_mask; code_mask=0; pre=rec_buffer.decoded>>remote->bits; gettimeofday(¤t,NULL); sum=remote->phead+remote->shead+ lirc_t_max(remote->pone+remote->sone, remote->pzero+remote->szero)* (remote->bits+ remote->pre_data_bits+ remote->post_data_bits)+ remote->plead+ remote->ptrail+ remote->pfoot+remote->sfoot+ remote->pre_p+remote->pre_s+ remote->post_p+remote->post_s; rec_buffer.sum=sum>=remote->gap ? remote->gap-1:sum; sync=time_elapsed(&remote->last_send,¤t)- rec_buffer.sum; } else { if(!get_lead(remote))
int init_send(struct ir_remote *remote,struct ir_ncode *code) { int i, repeat=0; if(is_grundig(remote) || is_goldstar(remote) || is_serial(remote) || is_bo(remote)) { logprintf(LOG_ERR,"sorry, can't send this protocol yet"); return(0); } clear_send_buffer(); if(is_biphase(remote)) { send_buffer.is_biphase=1; } if(repeat_remote==NULL) { remote->repeat_countdown=remote->min_repeat; } else { repeat = 1; } init_send_loop: if(repeat && has_repeat(remote)) { if(remote->flags&REPEAT_HEADER && has_header(remote)) { send_header(remote); } send_repeat(remote); } else { if(!is_raw(remote)) { ir_code next_code; if(code->transmit_state == NULL) { next_code = code->code; } else { next_code = code->transmit_state->code; } send_code(remote, next_code, repeat); if(has_toggle_mask(remote)) { remote->toggle_mask_state++; if(remote->toggle_mask_state==4) { remote->toggle_mask_state=2; } } send_buffer.data=send_buffer._data; } else { if(code->signals==NULL) { logprintf(LOG_ERR, "no signals for raw send"); return 0; } if(send_buffer.wptr>0) { send_signals(code->signals, code->length); } else { send_buffer.data=code->signals; send_buffer.wptr=code->length; for(i=0; i<code->length; i++) { send_buffer.sum+=code->signals[i]; } } } } sync_send_buffer(); if(bad_send_buffer()) { logprintf(LOG_ERR,"buffer too small"); return(0); } if(has_repeat_gap(remote) && repeat && has_repeat(remote)) { remote->min_remaining_gap=remote->repeat_gap; remote->max_remaining_gap=remote->repeat_gap; } else if(is_const(remote)) { if(min_gap(remote)>send_buffer.sum) { remote->min_remaining_gap=min_gap(remote)-send_buffer.sum; remote->max_remaining_gap=max_gap(remote)-send_buffer.sum; } else { logprintf(LOG_ERR,"too short gap: %u",remote->gap); remote->min_remaining_gap=min_gap(remote); remote->max_remaining_gap=max_gap(remote); return(0); } } else { remote->min_remaining_gap=min_gap(remote); remote->max_remaining_gap=max_gap(remote); } /* update transmit state */ if(code->next != NULL) { if(code->transmit_state == NULL) { code->transmit_state = code->next; } else { code->transmit_state = code->transmit_state->next; } } if((remote->repeat_countdown>0 || code->transmit_state != NULL) && remote->min_remaining_gap<LIRCD_EXACT_GAP_THRESHOLD) { if(send_buffer.data!=send_buffer._data) { lirc_t *signals; int n; LOGPRINTF(1, "unrolling raw signal optimisation"); signals=send_buffer.data; n=send_buffer.wptr; send_buffer.data=send_buffer._data; send_buffer.wptr=0; send_signals(signals, n); } LOGPRINTF(1, "concatenating low gap signals"); if(code->next == NULL || code->transmit_state == NULL) { remote->repeat_countdown--; } send_space(remote->min_remaining_gap); flush_send_buffer(); send_buffer.sum=0; repeat = 1; goto init_send_loop; } LOGPRINTF(3, "transmit buffer ready"); return(1); }
/** * Fill `m_prologue_blocks` and return the register that we're "switching" on * (even if it's not a real switch statement) */ boost::optional<uint16_t> SwitchMethodPartitioning::compute_prologue_blocks( cfg::ControlFlowGraph* cfg, const cp::intraprocedural::FixpointIterator& fixpoint, bool verify_default_case) { for (const cfg::Block* b : cfg->blocks()) { always_assert_log(!b->is_catch(), "SwitchMethodPartitioning does not support methods with " "catch blocks. %d has a catch block in %s", b->id(), SHOW(*cfg)); } // First, add all the prologue blocks that forma a linear chain before the // case block selection blocks (a switch or an if-else tree) begin. for (cfg::Block* b = cfg->entry_block(); b != nullptr; b = b->follow_goto()) { m_prologue_blocks.push_back(b); } { auto last_prologue_block = m_prologue_blocks.back(); auto last_prologue_insn_it = last_prologue_block->get_last_insn(); always_assert(last_prologue_insn_it != last_prologue_block->end()); auto last_prologue_insn = last_prologue_insn_it->insn; // If this method was compiled from a default-case-only switch, there will // be no branch opcode -- the method will always throw an // IllegalArgumentException. auto op = last_prologue_insn->opcode(); always_assert(!verify_default_case || is_branch(op) || op == OPCODE_THROW); if (!is_branch(op)) { return boost::none; } else if (is_switch(op)) { // switch or if-else tree. Not both. return last_prologue_insn->src(0); } } // Handle a tree of if statements in the prologue. d8 emits this // when it would be smaller than a switch statement. The non-leaf nodes of the // tree are prologue blocks. The leaf nodes of the tree are case blocks. // // For example: // load-param v0 // const v1 1 // if-eq v0 v1 CASE_1 // goto EXIT_BLOCK ; or return // const v1 2 // if-eq v0 v1 CASE_2 // goto EXIT_BLOCK ; or return // ... // // Traverse the tree in starting at the end of the linear chain of prologue // blocks and stopping before we reach a leaf. boost::optional<uint16_t> determining_reg; std::queue<cfg::Block*> to_visit; to_visit.push(m_prologue_blocks.back()); while (!to_visit.empty()) { auto b = to_visit.front(); to_visit.pop(); // Leaf nodes have 0 or 1 successors (return or goto the epilogue blocks). // Throw edges are disallowed. if (b->succs().size() >= 2) { // The linear check above and this tree check both account for the // top-most node in the tree. Make sure we don't duplicate it if (b != m_prologue_blocks.back()) { m_prologue_blocks.push_back(b); // Verify there aren't extra instructions in here that we may lose track // of for (const auto& mie : InstructionIterable(b)) { auto insn = mie.insn; auto op = insn->opcode(); always_assert_log(is_const(op) || is_conditional_branch(op), "Unexpected instruction in if-else tree %s", SHOW(insn)); } } for (auto succ : b->succs()) { to_visit.push(succ->target()); } // Make sure all blocks agree on which register is the determiner uint16_t candidate_reg = ::find_determining_reg(b, fixpoint); if (determining_reg == boost::none) { determining_reg = candidate_reg; } else { always_assert_log( *determining_reg == candidate_reg, "Conflict: which register are we switching on? %d != %d in %s", *determining_reg, candidate_reg, SHOW(*cfg)); } } } always_assert_log(determining_reg != boost::none, "Couldn't find determining register in %s", SHOW(*cfg)); return determining_reg; }
void calculate_signal_lengths(struct ir_remote *remote) { if(is_const(remote)) { remote->min_total_signal_length = min_gap(remote); remote->max_total_signal_length = max_gap(remote); } else { remote->min_gap_length = min_gap(remote); remote->max_gap_length = max_gap(remote); } lirc_t min_signal_length = 0, max_signal_length = 0; lirc_t max_pulse = 0, max_space = 0; int first_sum = 1; struct ir_ncode *c = remote->codes; int i; while(c->name) { struct ir_ncode code = *c; struct ir_code_node *next = code.next; int first = 1; int repeat = 0; do{ if(first) { first = 0; } else { code.code = next->code; next = next->next; } for(repeat = 0; repeat < 2; repeat++) { if(init_sim(remote, &code, repeat)) { lirc_t sum = send_buffer.sum; if(sum) { if(first_sum || sum < min_signal_length) { min_signal_length = sum; } if(first_sum || sum > max_signal_length) { max_signal_length = sum; } first_sum = 0; } for(i=0; i<send_buffer.wptr; i++) { if(i&1) /* space */ { if(send_buffer.data[i] > max_space) { max_space = send_buffer.data[i]; } } else /* pulse */ { if(send_buffer.data[i] > max_pulse) { max_pulse = send_buffer.data[i]; } } } } } } while(next); c++; } if(first_sum) { /* no timing data, so assume gap is the actual total length */ remote->min_total_signal_length = min_gap(remote); remote->max_total_signal_length = max_gap(remote); remote->min_gap_length = min_gap(remote); remote->max_gap_length = max_gap(remote); } else if(is_const(remote)) { if(remote->min_total_signal_length > max_signal_length) { remote->min_gap_length = remote->min_total_signal_length - max_signal_length; } else { logprintf(LOG_WARNING, "min_gap_length is 0 for " "'%s' remote", remote->name); remote->min_gap_length = 0; } if(remote->max_total_signal_length > min_signal_length) { remote->max_gap_length = remote->max_total_signal_length - min_signal_length; } else { logprintf(LOG_WARNING, "max_gap_length is 0 for " "'%s' remote", remote->name); remote->max_gap_length = 0; } } else { remote->min_total_signal_length = min_signal_length + remote->min_gap_length; remote->max_total_signal_length = max_signal_length + remote->max_gap_length; } LOGPRINTF(1, "lengths: %lu %lu %lu %lu", remote->min_total_signal_length, remote->max_total_signal_length, remote->min_gap_length, remote->max_gap_length); }
bool optimize_block(GList** instructions, int opt_level) { if(opt_level == 0) // no optimization return true; for(GList *inst = *instructions; inst != NULL; inst = inst->next) { uint32_t *a = (uint32_t*) DATA(inst)->args; // pattern is LD A,HL+; LD (DE),A; INC DE -> LD DE+, HL+ if((*a & 0xffffff) == 0x13122a) { printf("optimizing block @%#x (3)\n", DATA(*instructions)->address); DATA(inst)->op1 = MEM_INC_DE; DATA(inst)->cycles = 6; DATA(inst)->bytes = 3; g_free(inst->next->data); *instructions = g_list_delete_link(*instructions, inst->next); g_free(inst->next->data); *instructions = g_list_delete_link(*instructions, inst->next); } //pattern f0 41 e6 03 20 fa -> wait for stat mode 3 if((*a) == 0x03e641f0 && (*(a+1) & 0xffff) == 0xfa20) { printf("optimizing block @%#x (4)\n", DATA(*instructions)->address); DATA(inst)->opcode = HALT; DATA(inst)->op1 = WAIT_STAT3; DATA(inst)->cycles = 0; DATA(inst)->bytes = 6; g_free(inst->next->data); *instructions = g_list_delete_link(*instructions, inst->next); g_free(inst->next->data); *instructions = g_list_delete_link(*instructions, inst->next); } //pattern f0 44 fe ?? 20 fa -> wait for ly if((*a & 0x00ffffff) == 0xfe44f0 && (*(a+1) & 0xffff) == 0xfa20) { printf("optimizing block @%#x (5)\n", DATA(*instructions)->address); DATA(inst)->opcode = HALT; DATA(inst)->op1 = WAIT_LY; DATA(inst)->cycles = 0; DATA(inst)->bytes = 6; g_free(inst->next->data); *instructions = g_list_delete_link(*instructions, inst->next); g_free(inst->next->data); *instructions = g_list_delete_link(*instructions, inst->next); } //pattern f0 00 f0 00 -> repeated read of jopad register if((*a) == 0x00f000f0) { printf("optimizing block @%#x (6)\n", DATA(*instructions)->address); DATA(inst)->cycles += 3; DATA(inst)->bytes += 2; DATA(inst)->args = DATA(inst->next)->args; g_free(inst->next->data); *instructions = g_list_delete_link(*instructions, inst->next); if(inst->prev) //apply pattern to this instruction again inst = inst->prev; } } int byte_offset = 0; for(GList *inst = *instructions; inst != NULL; inst = inst->next) { byte_offset += DATA(inst)->bytes; if(is_jump_to_start(DATA(inst), byte_offset)) { bool can_optimize1 = true; bool can_optimize2 = true; for(GList *inst2 = *instructions; inst2 != inst; inst2 = inst2->next) { if(!is_const(DATA(inst2), opt_level)) can_optimize1 = false; if(!is_no_mem_access(DATA(inst2), opt_level)) can_optimize2 = false; } if(can_optimize1) { printf("optimizing block @%#x (1)\n", DATA(*instructions)->address); // optimize 2: ... JP <2 // to JP >1 2: HALT 1: ... JP <2 // insert jump target at the position of the old start instruction gb_instruction *jp_target = g_new(gb_instruction, 1); *jp_target = (gb_instruction){JP_TARGET, TARGET_1, NONE, 0, DATA(*instructions)->address, 0, 0, 0, 0}; *instructions = g_list_prepend(*instructions, jp_target); // prepend halt, as the loop cannot change the break condition gb_instruction *halt_inst = g_new(gb_instruction, 1); *halt_inst = (gb_instruction){HALT, NONE, NONE, 0, DATA(*instructions)->address, 1, 1, 1, INST_FLAG_ENDS_BLOCK}; *instructions = g_list_prepend(*instructions, halt_inst); // prepend jump target before halt instruction gb_instruction *jp_target2 = g_new(gb_instruction, 1); *jp_target2 = (gb_instruction){JP_TARGET, TARGET_2, NONE, 0, DATA(*instructions)->address, 0, 0, 0, 0}; *instructions = g_list_prepend(*instructions, jp_target2); // prepend jp, to jump to the old start instruction gb_instruction *jp_inst = g_new(gb_instruction, 1); *jp_inst = (gb_instruction){JP_FWD, NONE, TARGET_1, 0, DATA(*instructions)->address, 0, 0, 0, 0}; *instructions = g_list_prepend(*instructions, jp_inst); // modify jump to point to the halt instruction DATA(inst)->opcode = JP_BWD; DATA(inst)->op2 = TARGET_2; DATA(inst)->flags &= ~INST_FLAG_ENDS_BLOCK; break; } else if(can_optimize2) { if(DATA(*instructions)->address < 0xff00) printf("optimizing block @%#x (2)\n", DATA(*instructions)->address); // insert jump target at the position of the old start instruction gb_instruction *jp_target = g_new(gb_instruction, 1); *jp_target = (gb_instruction){JP_TARGET, TARGET_1, NONE, 0, DATA(*instructions)->address, 0, 0, 0, 0}; *instructions = g_list_prepend(*instructions, jp_target); DATA(inst)->opcode = JP_BWD; DATA(inst)->op2 = TARGET_1; } else { printf("jp to start detected, could not optimize %#x\n", DATA(*instructions)->address); } } } return true; }
///////////////////////////////////// // Funkce get_token ///////////////////////////////////// int get_token(FILE *f, string *str) { int c; int ret; int state = start; char hex[] = "00"; bool must_be_next = false; if(del_string(str) == RET_ERR) return RET_ERR; while((c=fgetc(f)) != EOF) { switch(state) { case start: ////// identifikátor if(isalpha(c) || c == '_') { state = identificator; if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } ////// Proměnná else if(c == '$') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; state = variable; must_be_next = true; } ////// Řetězcový literál else if(c == '"') { state = string_literal; } ////// číslo else if(isdigit(c)) { state = int_num; if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } //////////////////////// ////// Rovno, nerovno ////// jedno nebo tři rovnítka else if(c == '=') { state = equal; if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } ////// nerovno else if(c == '!') { state = not_equal; if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } ////// konkatenace - další znaky netřeba else if(c == '.') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return concatenate; } ////////////////// ////// Logické ////// menší || menší nebo rovno else if(c == '<') { state = less; if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } ////// větší || větší nebo rovno else if(c == '>') { state = greater; if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } ////////////////// ////// Aritmetické ////// pouze znak plus - další znaky netřeba else if(c == '+') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return plus; } ////// pouze znak plus - další znaky netřeba else if(c == '*') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return multiply; } ////// pouze znak mínus - další znaky netřeba else if(c == '-') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return minus; } ////// znak děleno || začátek komentáře else if(c == '/') { if(first) return SYNT_ERR; else { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; state = comment; } } ////////////////// ////// Závorky ////// pouze znak ( - další znaky netřeba else if(c == '(') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return left_parent; } ////// pouze znak ) - další znaky netřeba else if(c == ')') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return right_parent; } ////// pouze znak { - další znaky netřeba else if(c == '{') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return left_braces; } ////// pouze znak } - další znaky netřeba else if(c == '}') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return right_braces; } ////// znak děleno || začátek komentáře else if(c == ',') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return comma; } ////// pouze středník - další znaky netřeba else if(c == ';') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return semicolon; } else if(isspace(c)==0) { return LEX_ERR; } else { if(first) return SYNT_ERR; } break; ////////////////// ////// Identifikátor case identificator: if(isalpha(c) || isdigit(c) || c == '_') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } else { ungetc(c,f); int id = 0; if((id = is_keyword(str->strg))!=RET_ERR) { return id; } else if((id = is_type(str->strg))!=RET_ERR) { return id; } else if((id = is_const(str->strg))!=RET_ERR) { return id; } else { return identificator; } } break; ////////////////// ////// Proměnná case variable: if(must_be_next) { if(isalpha(c) || c == '_') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; must_be_next = false; } else return LEX_ERR; } else { if(isalpha(c) || isdigit(c) || c == '_') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } else { ungetc(c,f); return variable; } } break; ////////////////// ////// Řetězcový literál case string_literal: if(c > 31) { if(c == '\\') { c=fgetc(f); if(c == '"') { if((ret = add_string(str,'\"')) == RET_ERR) return RET_ERR; } else if(c == 'n') { if((ret = add_string(str,'\n')) == RET_ERR) return RET_ERR; } else if(c == '$') { if((ret = add_string(str,'$')) == RET_ERR) return RET_ERR; } else if(c == 't') { if((ret = add_string(str,'\t')) == RET_ERR) return RET_ERR; } else if(c == '\\') { if((ret = add_string(str,'\\')) == RET_ERR) return RET_ERR; } else if(c == 'x') { hex[0]=fgetc(f); if(hex[0] == EOF) return LEX_ERR; else if(hex[0] == '\"') { if((ret = add_string(str,'\\')) == RET_ERR) return RET_ERR; if((ret = add_string(str,'x')) == RET_ERR) return RET_ERR; return string_literal; } else if(hex[0] > 31) { if(((hex[0]>'f') || (hex[0]<'a')) && ((hex[0]>'F') || (hex[0]<'A')) && ((hex[0]>'9') || (hex[0]<'0'))) { if((ret = add_string(str,'\\')) == RET_ERR) return RET_ERR; if((ret = add_string(str,'x')) == RET_ERR) return RET_ERR; ungetc(hex[0],f); } else { hex[1]=fgetc(f); if(hex[1] == EOF) return LEX_ERR; else if(hex[1] == '\"') { if((ret = add_string(str,'\\')) == RET_ERR) return RET_ERR; if((ret = add_string(str,'x')) == RET_ERR) return RET_ERR; if((ret = add_string(str,hex[0])) == RET_ERR) return RET_ERR; return string_literal; } else if(hex[1] > 31) { if(((hex[1]>'f') || (hex[1]<'a')) && ((hex[1]>'F') || (hex[1]<'A')) && ((hex[1]>'9') || (hex[1]<'0'))) { if((ret = add_string(str,'\\')) == RET_ERR) return RET_ERR; if((ret = add_string(str,'x')) == RET_ERR) return RET_ERR; ungetc(hex[0],f); ungetc(hex[1],f); } else { char* end = NULL; int pomoc = strtol(hex,&end,16); if(pomoc!=0 && *end == '\0') { if((ret = add_string(str,pomoc)) == RET_ERR) return RET_ERR; } } } else { return LEX_ERR; } } } else { return LEX_ERR; } } else if(c>31) { ungetc(c,f); c='\\'; if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } else return LEX_ERR; } else if(c == '"') { return string_literal; } else if(c == '$') { return LEX_ERR; } else { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } } else return LEX_ERR; break; ////////////////// ////// Číslo case int_num: if(isdigit(c)) { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } else if(c=='.') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; state = double_num; must_be_next = true; } else if(c=='e'||c=='E') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; must_be_next = true; state = double_num_exp; c=fgetc(f); if(c=='-' || c=='+') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } else ungetc(c,f); } else { ungetc(c,f); return int_num; } break; ////// desetinné číslo case double_num: if(must_be_next) { if(isdigit(c)) { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; must_be_next = false; } else { return LEX_ERR; } } else { if(isdigit(c)) { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; must_be_next = false; } else if(c=='e'||c=='E') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; state = double_num_exp; c=fgetc(f); must_be_next = true; if(c=='-' || c=='+') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } else ungetc(c,f); } else { ungetc(c,f); return double_num; } } break; ////// desetinné číslo case double_num_exp: if(must_be_next) { if(isdigit(c)) { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; must_be_next = false; } else { return LEX_ERR; } } else { if(isdigit(c)) { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; } else { ungetc(c,f); return double_num; } } break; ////////////////// ////// Rovno case equal: if(c == '=') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; c=fgetc(f); if(c == '=') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return equal; } else { ungetc(c,f); return LEX_ERR; } } else { ungetc(c,f); return assign; } break; ////////////////// ////// Nerovno case not_equal: if(c == '=') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; c=fgetc(f); if(c == '=') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return not_equal; } else { ungetc(c,f); return LEX_ERR; } } else { ungetc(c,f); return LEX_ERR; } break; ////////////////// ////// Větší či většíRovno case greater: if(c == '=') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return greater_equal; } else { ungetc(c,f); return greater; } break; ////////////////// ////// Menší či menšíRovno case less: if(c == '=') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; return less_equal; } else if(c == '?') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; state=php_entry; } else { ungetc(c,f); return less; } break; case php_entry: if(c == 'p') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; c=fgetc(f); if(c == 'h') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; c=fgetc(f); if(c == 'p') { if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; c=fgetc(f); if(c==EOF) { return php_entry_wrong; } else if(isspace(c)) { c=fgetc(f); if(c==EOF) { return php_entry_wrong; } ungetc(c,f); if((ret = add_string(str,c)) == RET_ERR) return RET_ERR; first = false; return php_entry; } else { first = false; return php_entry; } } else { return LEX_ERR; } } else { return LEX_ERR; } } else { ungetc(c,f); return LEX_ERR; } break; ////////////////// ////// Komentáře case comment: if(c == '/') { while((c=fgetc(f)) != EOF) { if(c=='\n') break; } del_string(str); state = start; } else if(c=='*') { while((c=fgetc(f)) != EOF) { if(c=='*') { if((c=fgetc(f)) == '/') { state = start; del_string(str); break; } else ungetc(c,f); } } if(c==EOF && state==comment) return LEX_ERR; } else { ungetc(c,f); return divide; } break; } } return EOF; }
void num_vars(void) /* Numeriert Variablen und erzeugt Indexliste */ { unsigned int i,j,done;struct IC *p;struct Var *v,*a[4],*vp; unsigned long heapsize=0; if(DEBUG&1024) printf("numerating variables loop1\n"); inr++; /* alle Indizes auf -1 */ a[0]=vl0; a[1]=vl1; a[2]=vl2; a[3]=vl3; #if 1 for(j=0;j<4;j++){ v=a[j]; while(v){ v->index=-1; /* Variablen von inline-Funktionen */ if(j==0&&v->fi&&v->fi->first_ic){ for(vp=v->fi->vars;vp;vp=vp->next) vp->index=-1; } v=v->next; } } /* variables that may be referenced in inter-proc. dflow-info */ for(p=first_ic;p;p=p->next){ if(p->code==CALL&&(p->q1.flags&VAR)&&p->q1.v->fi){ struct function_info *fi=p->q1.v->fi; if(fi->flags&ALL_USES){ for(i=0;i<fi->use_cnt;i++){ if(v=fi->use_list[i].v) fi->use_list[i].v->index=-1; } } if(fi->flags&ALL_MODS){ for(i=0;i<fi->change_cnt;i++){ if(v=fi->change_list[i].v) fi->change_list[i].v->index=-1; } } } /* const-lists */ if((p->q1.flags&VAR)) if(p->q1.v->clist&&is_const(p->q1.v->vtyp)) num_clist_refs(-1,p->q1.v->vtyp,p->q1.v->clist); if((p->q2.flags&VAR)) if(p->q2.v->clist&&is_const(p->q2.v->vtyp)) num_clist_refs(-1,p->q2.v->vtyp,p->q2.v->clist); if((p->z.flags&VAR)) if(p->z.v->clist&&is_const(p->z.v->vtyp)) num_clist_refs(-1,p->z.v->vtyp,p->z.v->clist); } #endif /* Do we need this? */ for(p=first_ic;p;p=p->next){ if(p->q1.flags&VAR) {p->q1.v->index=-1;p->q1.v->flags&=~USEDASADR;} if(p->q2.flags&VAR) {p->q2.v->index=-1;p->q2.v->flags&=~USEDASADR;} if(p->z.flags&VAR) {p->z.v->index=-1;p->z.v->flags&=~USEDASADR;} } /* erst alle Variablen, die als DREFOBJ benutzt werden */ if(DEBUG&1024) printf("numerating variables loop2\n"); i=0; do{ done=1; if(DEBUG&1024) printf("pass\n"); for(p=first_ic;p;p=p->next){ if(p->code<LABEL||p->code>BRA){ int c=p->code; /* mark variables ad USEDASADR */ if(c==ADDRESS) p->q1.v->flags|=USEDASADR; if(p->q1.flags&VARADR) p->q1.v->flags|=USEDASADR; if(p->q2.flags&VARADR) p->q2.v->flags|=USEDASADR; if(p->z.flags&VARADR) p->z.v->flags|=USEDASADR; j=(q1typ(p)&NQ); if((p->q1.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)){ v=p->q1.v; if(!v->vtyp->next||(v->vtyp->next->flags&NQ)!=j) v->flags|=DNOTTYPESAFE; if(v->index<0) {v->index=i++;v->inr=inr;done=0;} } j=(q2typ(p)&NQ); if((p->q2.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)){ v=p->q2.v; if(!v->vtyp->next||(v->vtyp->next->flags&NQ)!=j) v->flags|=DNOTTYPESAFE; if(v->index<0) {v->index=i++;v->inr=inr;done=0;} } j=(ztyp(p)&NQ); if((p->z.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)){ v=p->z.v; if(!v->vtyp->next||(v->vtyp->next->flags&NQ)!=j) v->flags|=DNOTTYPESAFE; if(v->index<0) {v->index=i++;v->inr=inr;done=0;} } /* mark copies from DREFs also as DREFs (necessary?) (check z for !DREFOBJ?) */ if((c==ASSIGN||c==ADDI2P||c==SUBIFP)&&(p->q1.flags&VAR)&&p->q1.v->index>=0&&(p->z.flags&VAR)&&p->z.v->index<0){ if(!(p->z.flags&VAR)) ierror(0); p->z.v->index=i++;p->z.v->inr=inr;done=0; } /* mark copies to DREFs as DREFs (because of copy-propagation */ /* and post-op reordering */ if((c==ASSIGN||c==ADDI2P||c==SUBIFP)&&(p->z.flags&VAR)&&p->z.v->index>=0&&(p->q1.flags&VAR)&&p->q1.v->index<0){ p->q1.v->index=i++;p->q1.v->inr=inr;done=0; } } } }while(!done); if(DEBUG&1024) printf("numerating variables loop3\n"); rcount=i; /* Anzahl der DREFOBJ-Variablen */ /* jetzt den Rest */ for(p=first_ic;p;p=p->next){ int c=p->code; if(1/*p->code<LABEL||p->code>BRA*/){ if((p->q1.flags&(VAR|DREFOBJ))==VAR){ j=(q1typ(p)&NQ); v=p->q1.v; if((v->vtyp->flags&NQ)!=j) v->flags|=NOTTYPESAFE; if(v->index<0) {v->index=i++;v->inr=inr;} } if((p->q2.flags&(VAR|DREFOBJ))==VAR){ j=(q2typ(p)&NQ); v=p->q2.v; if((v->vtyp->flags&NQ)!=j) v->flags|=NOTTYPESAFE; if(v->index<0) {v->index=i++;v->inr=inr;} } if((p->z.flags&(VAR|DREFOBJ))==VAR){ j=(ztyp(p)&NQ); v=p->z.v; if((v->vtyp->flags&NQ)!=j) v->flags|=NOTTYPESAFE; if(v->index<0) {v->index=i++;v->inr=inr;} } } /* const-lists */ if((p->q1.flags&VAR)) if(p->q1.v->clist&&is_const(p->q1.v->vtyp)) {clcnt=i;num_clist_refs(0,p->q1.v->vtyp,p->q1.v->clist);i=clcnt;} if((p->q2.flags&VAR)) if(p->q2.v->clist&&is_const(p->q2.v->vtyp)) {clcnt=i;num_clist_refs(0,p->q2.v->vtyp,p->q2.v->clist);i=clcnt;} if((p->z.flags&VAR)) if(p->z.v->clist&&is_const(p->z.v->vtyp)) {clcnt=i;num_clist_refs(0,p->z.v->vtyp,p->z.v->clist);i=clcnt;} } if(DEBUG&1024) printf("numerating variables loop4\n"); vcount=i+rcount; /* alle benutzten Variablen+Anzahl der DREFOBJs */ vilist=mymalloc(vcount*sizeof(struct Var *)); heapsize+=vcount*sizeof(struct Var *); #if 0 for(j=0;j<4;j++){ int i; v=a[j]; while(v){ i=v->index; /* printf("%s has index %d\n",v->identifier,i);*/ if(i>=0){ if(i>=vcount-rcount) ierror(0); vilist[i]=v; if(i<rcount) vilist[i+vcount-rcount]=v; } /* Variablen von inline-Funktionen */ if(j==0&&v->fi&&v->fi->first_ic){ for(vp=v->fi->vars;vp;vp=vp->next){ i=vp->index; if(i>=0){ if(i>=vcount-rcount) ierror(0); vilist[i]=vp; if(i<rcount) vilist[i+vcount-rcount]=vp; } } } v=v->next; } } #endif for(p=first_ic;p;p=p->next){ struct Var *v; if(p->q1.flags&VAR){ i=p->q1.v->index; vilist[i]=v=p->q1.v; if(v->clist&&is_const(v->vtyp)) num_clist_refs(1,v->vtyp,v->clist); } if(p->q2.flags&VAR){ i=p->q2.v->index; vilist[i]=v=p->q2.v; if(v->clist&&is_const(v->vtyp)) num_clist_refs(1,v->vtyp,v->clist); } if(p->z.flags&VAR){ i=p->z.v->index; vilist[i]=v=p->z.v; if(v->clist&&is_const(v->vtyp)) num_clist_refs(1,v->vtyp,v->clist); } } for(i=0;i<rcount;i++) vilist[i+vcount-rcount]=vilist[i]; /*vsize=(vcount+CHAR_BIT-1)/CHAR_BIT;*/ vsize=BVSIZE(vcount); if(DEBUG&(16384|1024)) printf("%lu variables (%lu DREFOBJs), vsize=%lu\n",(unsigned long)vcount,(unsigned long)rcount,(unsigned long)vsize); av_drefs=mymalloc(vsize); memset(av_drefs,0,vsize); /* alle DREFOBJs */ for(i=vcount-rcount;i<vcount;i++) BSET(av_drefs,i); /* av_globals enthaelt alle globalen Variablen und av_address */ /* zusaetzlich noch alle Variablen, deren Adressen genommen wurden */ av_globals=mymalloc(vsize); memset(av_globals,0,vsize); av_statics=mymalloc(vsize); memset(av_statics,0,vsize); av_address=mymalloc(vsize); memcpy(av_address,av_globals,vsize); heapsize+=4*vsize; for(i=0;i<vcount-rcount;i++){ if(vilist[i]->nesting==0||vilist[i]->storage_class==EXTERN) BSET(av_globals,i); if(vilist[i]->flags&USEDASADR) BSET(av_address,i); if(vilist[i]->storage_class==STATIC) BSET(av_statics,i); if(i<rcount){ /* if(!ISPOINTER(vilist[i]->vtyp->flags)){ printf("%s(%ld)\n",vilist[i]->identifier,zm2l(vilist[i]->offset));ierror(0);}*/ BSET(av_address,i+vcount-rcount); BSET(av_globals,i+vcount-rcount); } } if(DEBUG&16384) printf("num_vars heapsize=%lu\n",heapsize); }
lirc_t emulation_readdata(lirc_t timeout) { static lirc_t sum = 0; lirc_t data = 0; if(current_code == NULL) { data = 1000000; if(next_code) { current_code = next_code; } else { current_code = emulation_data->codes; } current_rep = 0; sum = 0; } else { if(current_code->name == NULL) { fprintf(stderr, "%s: %s no data found\n", progname, emulation_data->name); data = 0; } if(current_index >= current_code->length) { if(next_code) { current_code = next_code; } else { current_rep++; if(current_rep > 2) { current_code++; current_rep = 0; data = 1000000; } } current_index = 0; if(current_code->name == NULL) { current_code = NULL; return emulation_readdata(timeout); } if(data == 0) { if(is_const(emulation_data)) { data = emulation_data->gap - sum; } else { data = emulation_data->gap; } } sum = 0; } else { data = current_code->signals[current_index]; if((current_index % 2) == 0) { data |= PULSE_BIT; } current_index++; sum += data&PULSE_MASK; } } /* printf("delivering: %c%u\n", data&PULSE_BIT ? 'p':'s', data&PULSE_MASK); */ return data; }
char *get_token(char *lexeme , int mode){ char *token=(char*)calloc(strlen(lexeme)+50,sizeof(char)); //printf("Getting token\n"); if(is_long(lexeme)){ sprintf(token,"%d",LONG); } else if(is_static(lexeme)){ sprintf(token,"%d",STATIC); } else if(is_union(lexeme)){ sprintf(token,"%d",UNION); } else if(is_default(lexeme)){ sprintf(token,"%d",DEFAULT); } else if(is_break(lexeme)){ sprintf(token,"%d",BREAK); } else if(is_case(lexeme)){ sprintf(token,"%d",CASE); } else if(is_continue(lexeme)){ sprintf(token,"%d",CONTINUE); } else if(is_goto(lexeme)){ sprintf(token,"%d",GOTO); } else if(is_struct(lexeme)){ sprintf(token,"%d",STRUCT); } else if(is_const(lexeme)){ sprintf(token,"%d",CONST); } else if(is_void(lexeme)){ sprintf(token,"%d",VOID); } else if(is_switch(lexeme)){ sprintf(token,"%d",SWITCH); } else if(is_for(lexeme)){ sprintf(token,"%d",FOR); } else if(is_while(lexeme)){ sprintf(token,"%d",WHILE); } else if(is_do(lexeme)){ sprintf(token,"%d",DO); } else if(is_return(lexeme)){ sprintf(token,"%d",RETURN); } else if(is_bool(lexeme)){ sprintf(token,"%d",BOOL); } else if(is_char(lexeme)){ sprintf(token,"%d",CHAR); } else if(is_signed(lexeme)){ sprintf(token,"%d",SIGNED); } else if(is_unsigned(lexeme)){ sprintf(token,"%d",UNSIGNED); } else if(is_short(lexeme)){ sprintf(token,"%d",SHORT); } else if(is_int(lexeme)){ sprintf(token,"%d",INT); } else if(is_float(lexeme)){ sprintf(token,"%d",FLOAT); } else if(is_double(lexeme)){ sprintf(token,"%d",DOUBLE); } else if(is_l_square(lexeme)){ sprintf(token,"%d",L_SQUARE); } else if(is_r_square(lexeme)){ sprintf(token,"%d",R_SQUARE); } else if(is_l_paraen(lexeme)){ sprintf(token,"%d",L_PARAEN); } else if(is_r_paraen(lexeme)){ sprintf(token,"%d",R_PARAEN); } else if(is_l_cbrace(lexeme)){ sprintf(token,"%d",L_CBRACE); } else if(is_r_cbrace(lexeme)){ sprintf(token,"%d",R_CBRACE); } else if(is_comma(lexeme)){ sprintf(token,"%d",COMMA); } else if(is_semicol(lexeme)){ sprintf(token,"%d",SEMICOL); } else if(is_eq_eq(lexeme)){ sprintf(token,"%d",EQ_EQ); } else if(is_lesser(lexeme)){ sprintf(token,"%d",LESSER); } else if(is_less_eq(lexeme)){ sprintf(token,"%d",LESS_EQ); } else if(is_div(lexeme)){ sprintf(token,"%d",DIV); } else if(is_greater(lexeme)){ sprintf(token,"%d",GREATER); } else if(is_great_eq(lexeme)){ sprintf(token,"%d",GREAT_EQ); } else if(is_plus_eq(lexeme)){ sprintf(token,"%d",PLUS_EQ); } else if(is_minus_eq(lexeme)){ sprintf(token,"%d",MINUS_EQ); } else if(is_div_eq(lexeme)){ sprintf(token,"%d",DIV_EQ); } else if(is_mult_eq(lexeme)){ sprintf(token,"%d",MULT_EQ); } else if(is_minus_minus(lexeme)){ sprintf(token,"%d",MINUS_MINUS); } else if(is_plus_plus(lexeme)){ sprintf(token,"%d",PLUS_PLUS); } else if(is_percent(lexeme)){ sprintf(token,"%d",PERCENT); } else if(is_div(lexeme)){ sprintf(token,"%d",DIV); } else if(is_mult(lexeme)){ sprintf(token,"%d",MULT); } else if(is_minus(lexeme)){ sprintf(token,"%d",MINUS); } else if(is_plus(lexeme)){ sprintf(token,"%d",PLUS); } else if(is_int_const(lexeme)){ printf("int"); sprintf(token,"%d\t%s",INT_CONST,lexeme); } else if(is_flo_const(lexeme)){ printf("float"); sprintf(token,"%d\t%s",FLO_CONST,lexeme); } else if(is_comment_start(lexeme)){ sprintf(token,"$start"); } else if(is_comment_end(lexeme)){ sprintf(token,"$end"); } else if(is_identifier(lexeme)){ printf("Identifier"); if(mode==1) ht_set( symboltable, lexeme, "1"); sprintf(token,"%d\t%s",IDNTIFIER,lexeme); } else sprintf(token,"%d",NOTOK); return token; }