コード例 #1
0
ファイル: codegen.c プロジェクト: bartgrantham/alice
int
output_parameters(NODE *node, int break_label, int continue_label)
{
    int stack_size;

    stack_size = 0;

    if (node != NULL) {
	if (node->op == FUNCTION_PARAM) {
	    stack_size += output_parameters(node->arg[1], break_label, continue_label);
	    stack_size += output_parameters(node->arg[0], break_label, continue_label);
	} else {
	    output_node(node, break_label, continue_label);
	    output_code("PUSH", "HL");
	    stack_size = 2;
	}
    }

    return stack_size;
}
コード例 #2
0
ファイル: darx_siso.hpp プロジェクト: sguazt/dcsxx-sysid
::std::basic_ostream<CharT,CharTraitsT>& operator<<(::std::basic_ostream<CharT,CharTraitsT>& os, darx_siso_model<VectorT,RealT,UIntT> const& model)
{
	::std::pair<UIntT,UIntT> ord = order(model);

	os << "<SISO ARX model y(k)+a_1*y(k-t_s)+...+a_{n_a}*y(k-n_a*t_s)=b_0*u(k-d)+...+b_{n_b}*u(k-d-n_b*t_s):"
		<<  " t_s=" << sampling_time(model)
		<< ", n_a=" << ord.first
		<< ", n_b=" << ord.second
		<< ", d=" << delay(model)
		<< ", a=" << output_parameters(model)
		<< ", b=" << input_parameters(model)
		<< ">";

	return os;
}
コード例 #3
0
void AMUReporter::after_run() {
    Model::DATA_COLLECTOR->update_after_run();

    //output parameter
    output_parameters();

    //output others indicators
    // NTF
    print_ntf_by_location();
    // EIR - 20x
    print_EIR_by_location();

    print_20x_by_location();

    // EAMU
    print_EAMU();

    // prevalance
    print_prevalence_by_location();

    // fraction of positive that are clinical
    print_fraction_of_positive_that_are_clinical_by_location();

    // mean immune
    print_mean_immune_by_location();

    // mean number of clones per positive Individual
    print_mean_number_of_clones_per_positive_individual();
    // LOI
    print_LOI();

    // mean number of clones per positive Individual by age group
    print_mean_number_of_clones_per_positive_individual_by_age_group();

    // death by age class
    print_death_by_age_group();

    // number of clinical episode by age class
    print_number_of_clinical_episode_by_age_class();

    // prevalance by age class
    print_prevalence_by_age_class();
    // clinical percentage by age class
    print_fraction_of_positive_that_are_clinical_by_location_age_class();

    print_mean_immune_by_location_age_class();

    //print moi distribution
    print_moi_distribution();

    // resistance tracker
    print_resistance_tracker();

    // number of treatment by therapy
    print_treatments_by_therapy();

    // current time
    std::cout << Model::SCHEDULER->current_time() << "\t";
    // utl
    print_total_utl();

    std::cout << Model::DATA_COLLECTOR->popsize_by_location()[0] << "\t";

    //
    //    print_popsize_by_age_class();

    //print phi value by 5-age-group
    print_fraction_of_positive_that_are_clinical_by_location_age_class_by_5();


    print_utl();

    std::cout << std::endl;

    //    PersonIndexByLocationStateAgeClass* pi = Model::POPULATION->get_person_index<PersonIndexByLocationStateAgeClass>();
    //    for (int loc = 0; loc < Model::CONFIG->number_of_locations(); loc++) {
    //
    //        for (int hs = 0; hs < Person::NUMBER_OF_STATE - 1; hs++) {
    //            for (int ac = 0; ac < Model::CONFIG->number_of_age_classes(); ac++) {
    //                int size = pi->vPerson()[loc][hs][ac].size();
    //
    //                for (int i = 0; i < size; i++) {
    //                    Person* p = pi->vPerson()[loc][hs][ac][i];
    //                    std::cout << p->age() << " \t" << p->age_class() << std::endl;
    //                    assert(p->age_class() == ac);
    //                }
    //            }
    //        }
    //    }
}
コード例 #4
0
ファイル: codegen.c プロジェクト: bartgrantham/alice
void output_node(NODE *node, int break_label, int continue_label)
{
    NODE *n;
    int top, cont, out, bottom, not, tmp1, imm, state;
    int stack_size;
    static int last_line = -1;

    if (node == NULL) {
	return;
    }

    // In case we call yyerror().
    yylineno = node->line;

    if (node->line != last_line && node->op != ';' && node->op != FOR) {
	last_line = node->line;

	/* fprintf(outf, "%d, %s\n", node->op, get_op_name(node->op)); */
	output_line(node->line);
    }

    switch (node->op) {
	case NUMBER:
	    output_code("LD", "HL, %d", node->data.value);
	    break;
	case STRING:
	    output_code("LD", "HL, %s", node->data.address);
	    break;
	case IDENT:
	    if (node->data.var->scope == SCOPE_GLOBAL) {
		if (node->lhs) {
		    output_code("LD", "IX, _%s", node->data.var->name);
		} else if (node->data.var->decl->decl_type == DECL_ARRAY) {
		    output_code("LD", "HL, _%s", node->data.var->name);
		} else {
		    output_code("LD", "HL, (_%s)", node->data.var->name);
		}
	    } else {
		if (node->lhs) {
		    output_code("PUSH", "IY");
		    output_code("POP", "IX");
		    output_code("LD", "BC, %d", node->data.var->offset);
		    output_code("ADD", "IX, BC");
		} else if (node->data.var->decl->decl_type == DECL_ARRAY) {
		    output_code("LD", "BC, %d", node->data.var->offset);
		    output_code("PUSH", "IY");
		    output_code("POP", "HL");
		    output_code("ADD", "HL, BC");
		} else {
		    output_code("LD", "L, (IY + %d)", node->data.var->offset);
		    output_code("LD", "H, (IY + %d)",
			node->data.var->offset + 1);
		}
	    }
	    break;
	case '(':
	    /* limited function call support */
	    stack_size = output_parameters(node->arg[1], break_label, continue_label);
	    output_code("CALL", "_%s", node->arg[0]->data.var->name);
	    while (stack_size-- > 0) {
		output_code("INC", "SP");
	    }
	    break;
	case INCR:
	    output_node(node->arg[0], break_label, continue_label); /* Address is in IX */
	    if (node->data.detail == -1) {  /* Preincrement */
		output_code("LD", "L, (IX + 0)");
		output_code("LD", "H, (IX + 1)");
		output_code("INC", "HL");
		output_code("LD", "(IX + 0), L");
		output_code("LD", "(IX + 1), H");
	    } else {  /* Postincrement */
		output_code("LD", "L, (IX + 0)");
		output_code("LD", "H, (IX + 1)");
		output_code("LD", "E, L");
		output_code("LD", "D, H");
		output_code("INC", "DE");
		output_code("LD", "(IX + 0), E");
		output_code("LD", "(IX + 1), D");
	    }
	    break;
	case DECR:
	    output_node(node->arg[0], break_label, continue_label); /* Address is in IX */
	    if (node->data.detail == -1) {  /* Predecrement */
		output_code("LD", "L, (IX + 0)");
		output_code("LD", "H, (IX + 1)");
		output_code("DEC", "HL");
		output_code("LD", "(IX + 0), L");
		output_code("LD", "(IX + 1), H");
	    } else {  /* Postdecrement */
		output_code("LD", "L, (IX + 0)");
		output_code("LD", "H, (IX + 1)");
		output_code("LD", "E, L");
		output_code("LD", "D, H");
		output_code("DEC", "DE");
		output_code("LD", "(IX + 0), E");
		output_code("LD", "(IX + 1), D");
	    }
	    break;
	case CAST:
	    output_node(node->arg[0], break_label, continue_label);
	    /*
	     * Use get_decl_size() to do the right thing here. Not
	     * necessary right now.
	     */
	    break;
	case SIZEOF:
	    output_code("LD", "HL, %d", get_decl_size(node->arg[0]->decl));
	    break;
	case '*':
	    if (node->numargs == 1) {
                // Pointer dereference.
		output_node(node->arg[0], break_label, continue_label);
		output_code("PUSH", "HL");
		output_code("POP", "IX");
		if (!node->lhs) {
                    // Actually dereference it.
		    output_code("LD", "H, (IX + 1)");
		    output_code("LD", "L, (IX)");
		}
	    } else {
                // Multiplication.
		if (node->arg[0]->op == NUMBER ||
		    node->arg[1]->op == NUMBER) {

		    if (node->arg[0]->op == NUMBER) {
			n = node->arg[0];
			node->arg[0] = node->arg[1];
			node->arg[1] = n;
		    }

		    output_node(node->arg[0], break_label, continue_label);

		    imm = node->arg[1]->data.value;
		    if (imm < 0) {
			imm = -imm;
			output_code("LD", "A, 255");
			output_code("XOR", "H");
			output_code("XOR", "L");
			output_code("INC", "HL");
		    }

		    if (imm == 0) {
			output_code("LD", "HL, 0");
		    } else if ((imm & (imm - 1)) == 0) { /* Power of two */
			while (imm != 1) {
			    output_code("ADD", "HL, HL");
			    imm >>= 1;
			}
		    } else {
			if ((imm & 1) != 0) {
			    output_code("LD", "D, H");
			    output_code("LD", "E, L");
			    imm &= ~1;
			} else {
			    output_code("LD", "DE, 0");
			}
			state = 0;  /* state = 1 when HL contains the output */
			while (imm != 1) {
			    if ((imm & 1) != 0) {
				if (!state) {
				    output_code("EX", "DE, HL");
				}
				state = 1;
				output_code("ADD", "HL, DE");
			    }
			    if (state) {
				output_code("EX", "DE, HL");
				state = 0;
			    }
			    output_code("ADD", "HL, HL");
			    imm >>= 1;
			}
			/* Doesn't matter what "state" is */
			output_code("ADD", "HL, DE");
		    }
		} else {
		    output_comment("Unsupported operands: %s.",
			get_op_name(node->op));
		    unsupported++;
		}
	    }