def write_transition_forward(builder, tr): if tr.code is not None: write_vars_struct(builder, tr) write_transition_user_function(builder, tr, forward=True) write_tokens_struct(builder, tr) class_name = "Transition_{0.id}".format(tr) builder.write_class_head(class_name, "ca::TransitionDef") builder.write_constructor(class_name, "", [ "ca::TransitionDef({0}, {1}, {2}, {3})".format( tr.id, const_string(tr.name), const_boolean(not tr.has_code()), tr.priority) ]) builder.write_method_end() builder.line("ca::FireResult full_fire(ca::ThreadBase *thread, ca::NetBase *net);") builder.line("void* fire_phase1(ca::ThreadBase *thread, ca::NetBase *net);") builder.line("void fire_phase2(ca::ThreadBase *thread, ca::NetBase *net, void *data);") builder.line("void fire_phase2_ro_binding" "(ca::ThreadBase *thread, ca::NetBase *net, void *data);") builder.line("void cleanup_binding(void *data);") builder.line("bool is_enable(ca::ThreadBase *thread, ca::NetBase *net);") if builder.pack_bindings: builder.line("void pack_binding(ca::Packer &packer, void *data);") builder.line("ca::FireResult full_fire_with_binding(ca::ThreadBase *thread, ca::NetBase *net, ca::Packer &$packer);") builder.write_class_end() builder.line("static Transition_{0.id} transition_{0.id};", tr, const_boolean(not tr.has_code())) builder.emptyline();
def write_main_setup(builder, init_function="ca::init", start_process=True): builder.line("ca::project_description({0});", const_string(builder.project.description)) builder.line("std::vector<ca::Parameter*> parameters;") for p in builder.project.get_parameters(): builder.line("parameters.push_back(¶m::{0});", p.get_name()) builder.emptyline() builder.line("{0}(argc, argv, parameters, {1});", init_function, writer.const_boolean(builder.project.tracing)) builder.emptyline() for net in builder.project.nets: write_register_net(builder, net) defs = ["def_{0.id}".format(net) for net in builder.project.nets] builder.line("ca::NetDef *defs[] = {{{0}}};", ",".join(defs)) builder.line("ca::setup({0}, defs, {1});", len(defs), const_boolean(start_process))
def write_register_net(builder, net): builder.line("ca::NetDef *def_{0.id} = new ca::NetDef({1}, {0.id}, spawn_{0.id}, {2});", net, net.get_index(), const_boolean(net.is_local())) for i, tr in enumerate(net.transitions): builder.line("def_{0.id}->register_transition(&transition_{1.id});", net, tr)
def write_transition_forward(builder, tr): if tr.code is not None: write_vars_struct(builder, tr) write_transition_user_function(builder, tr, forward=True) write_tokens_struct(builder, tr) class_name = "Transition_{0.id}".format(tr) builder.write_class_head(class_name, "ca::TransitionDef") if tr.collective: transition_type = "ca::TRANSITION_COLLECTIVE" elif tr.has_code(): transition_type = "ca::TRANSITION_NORMAL" else: transition_type = "ca::TRANSITION_IMMEDIATE" builder.write_constructor(class_name, "", [ "ca::TransitionDef({0}, {1}, {2}, {3})".format( tr.id, const_string(tr.name), transition_type, tr.priority) ]) builder.write_method_end() builder.line( "ca::FireResult full_fire(ca::ThreadBase *thread, ca::NetBase *net);") builder.line( "ca::Binding* fire_phase1(ca::ThreadBase *thread, ca::NetBase *net);") builder.line( "void fire_phase2(ca::ThreadBase *thread, ca::NetBase *net, ca::Binding *data);" ) builder.line("bool is_enable(ca::ThreadBase *thread, ca::NetBase *net);") if tr.collective: builder.line("bool is_blocked(ca::Binding *data);") if builder.pack_bindings: builder.line( "void pack_binding(ca::Packer &packer, ca::Binding *data);") builder.line( "ca::FireResult full_fire_with_binding(ca::ThreadBase *thread, ca::NetBase *net, ca::Packer &$packer);" ) builder.write_class_end() builder.line("static Transition_{0.id} transition_{0.id};", tr, const_boolean(not tr.has_code())) builder.emptyline()
def write_transition_forward(builder, tr): if tr.code is not None: write_vars_struct(builder, tr) write_transition_user_function(builder, tr, forward=True) write_tokens_struct(builder, tr) class_name = "Transition_{0.id}".format(tr) builder.write_class_head(class_name, "ca::TransitionDef") if tr.collective: transition_type = "ca::TRANSITION_COLLECTIVE" elif tr.has_code(): transition_type = "ca::TRANSITION_NORMAL" else: transition_type = "ca::TRANSITION_IMMEDIATE" builder.write_constructor(class_name, "", [ "ca::TransitionDef({0}, {1}, {2}, {3})".format( tr.id, const_string(tr.name), transition_type, tr.priority) ]) builder.write_method_end() builder.line("ca::FireResult full_fire(ca::ThreadBase *thread, ca::NetBase *net);") builder.line("ca::Binding* fire_phase1(ca::ThreadBase *thread, ca::NetBase *net);") builder.line("void fire_phase2(ca::ThreadBase *thread, ca::NetBase *net, ca::Binding *data);") builder.line("bool is_enable(ca::ThreadBase *thread, ca::NetBase *net);") if tr.collective: builder.line("bool is_blocked(ca::Binding *data);") if builder.pack_bindings: builder.line("void pack_binding(ca::Packer &packer, ca::Binding *data);") builder.line("ca::Binding* unpack_binding(ca::Unpacker &unpacker);") builder.line("ca::FireResult full_fire_with_binding(ca::ThreadBase *thread, ca::NetBase *net, ca::Packer &$packer);") builder.write_class_end() builder.line("static Transition_{0.id} transition_{0.id};", tr, const_boolean(not tr.has_code())) builder.emptyline();