/*-------------------------------------------------------------------------- * (function: depth_first_traverse) *------------------------------------------------------------------------*/ void depth_traverse_output_blif(nnode_t *node, int traverse_mark_number, FILE *fp) { int i, j; nnode_t *next_node; nnet_t *next_net; if (node->traverse_visited == traverse_mark_number) { return; } else { /* ELSE - this is a new node so depth visit it */ /* POST traverse map the node since you might delete */ output_node(node, traverse_mark_number, fp); /* mark that we have visitied this node now */ node->traverse_visited = traverse_mark_number; for (i = 0; i < node->num_output_pins; i++) { if (node->output_pins[i]->net == NULL) continue; next_net = node->output_pins[i]->net; for (j = 0; j < next_net->num_fanout_pins; j++) { if (next_net->fanout_pins[j] == NULL) continue; next_node = next_net->fanout_pins[j]->node; if (next_node == NULL) continue; /* recursive call point */ depth_traverse_output_blif(next_node, traverse_mark_number, fp); } } } }
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; }
static void add_nodes(Scene *scene, BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNodeTree b_ntree, const ProxyMap &proxy_input_map, const ProxyMap &proxy_output_map) { /* add nodes */ BL::ShaderNodeTree::nodes_iterator b_node; PtrInputMap input_map; PtrOutputMap output_map; BL::Node::inputs_iterator b_input; BL::Node::outputs_iterator b_output; /* find the node to use for output if there are multiple */ bool found_active_output = false; BL::ShaderNode output_node(PointerRNA_NULL); for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) { if (is_output_node(*b_node)) { BL::ShaderNodeOutputMaterial b_output_node(*b_node); if(b_output_node.is_active_output()) { output_node = b_output_node; found_active_output = true; break; } else if(!output_node.ptr.data && !found_active_output) { output_node = b_output_node; } } } /* add nodes */ for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) { if (b_node->mute() || b_node->is_a(&RNA_NodeReroute)) { /* replace muted node with internal links */ BL::Node::internal_links_iterator b_link; for (b_node->internal_links.begin(b_link); b_link != b_node->internal_links.end(); ++b_link) { ProxyNode *proxy = new ProxyNode(convert_socket_type(b_link->to_socket())); input_map[b_link->from_socket().ptr.data] = proxy->inputs[0]; output_map[b_link->to_socket().ptr.data] = proxy->outputs[0]; graph->add(proxy); } } else if (b_node->is_a(&RNA_ShaderNodeGroup) || b_node->is_a(&RNA_NodeCustomGroup)) { BL::ShaderNodeTree b_group_ntree(PointerRNA_NULL); if (b_node->is_a(&RNA_ShaderNodeGroup)) b_group_ntree = BL::ShaderNodeTree(((BL::NodeGroup)(*b_node)).node_tree()); else b_group_ntree = BL::ShaderNodeTree(((BL::NodeCustomGroup)(*b_node)).node_tree()); ProxyMap group_proxy_input_map, group_proxy_output_map; /* Add a proxy node for each socket * Do this even if the node group has no internal tree, * so that links have something to connect to and assert won't fail. */ for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) { ProxyNode *proxy = new ProxyNode(convert_socket_type(*b_input)); graph->add(proxy); /* register the proxy node for internal binding */ group_proxy_input_map[b_input->identifier()] = proxy; input_map[b_input->ptr.data] = proxy->inputs[0]; set_default_value(proxy->inputs[0], *b_node, *b_input, b_data, b_ntree); } for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) { ProxyNode *proxy = new ProxyNode(convert_socket_type(*b_output)); graph->add(proxy); /* register the proxy node for internal binding */ group_proxy_output_map[b_output->identifier()] = proxy; output_map[b_output->ptr.data] = proxy->outputs[0]; } if (b_group_ntree) add_nodes(scene, b_data, b_scene, graph, b_group_ntree, group_proxy_input_map, group_proxy_output_map); } else if (b_node->is_a(&RNA_NodeGroupInput)) { /* map each socket to a proxy node */ for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) { ProxyMap::const_iterator proxy_it = proxy_input_map.find(b_output->identifier()); if (proxy_it != proxy_input_map.end()) { ProxyNode *proxy = proxy_it->second; output_map[b_output->ptr.data] = proxy->outputs[0]; } } } else if (b_node->is_a(&RNA_NodeGroupOutput)) { BL::NodeGroupOutput b_output_node(*b_node); /* only the active group output is used */ if (b_output_node.is_active_output()) { /* map each socket to a proxy node */ for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) { ProxyMap::const_iterator proxy_it = proxy_output_map.find(b_input->identifier()); if (proxy_it != proxy_output_map.end()) { ProxyNode *proxy = proxy_it->second; input_map[b_input->ptr.data] = proxy->inputs[0]; set_default_value(proxy->inputs[0], *b_node, *b_input, b_data, b_ntree); } } } } else { ShaderNode *node = NULL; if (is_output_node(*b_node)) { if (b_node->ptr.data == output_node.ptr.data) { node = graph->output(); } } else { node = add_node(scene, b_data, b_scene, graph, b_ntree, BL::ShaderNode(*b_node)); } if(node) { /* map node sockets for linking */ for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) { ShaderInput *input = node_find_input_by_name(node, *b_node, *b_input); input_map[b_input->ptr.data] = input; set_default_value(input, *b_node, *b_input, b_data, b_ntree); } for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) { ShaderOutput *output = node_find_output_by_name(node, *b_node, *b_output); output_map[b_output->ptr.data] = output; } } } } /* connect nodes */ BL::NodeTree::links_iterator b_link; for(b_ntree.links.begin(b_link); b_link != b_ntree.links.end(); ++b_link) { /* get blender link data */ BL::NodeSocket b_from_sock = b_link->from_socket(); BL::NodeSocket b_to_sock = b_link->to_socket(); ShaderOutput *output = 0; ShaderInput *input = 0; PtrOutputMap::iterator output_it = output_map.find(b_from_sock.ptr.data); if (output_it != output_map.end()) output = output_it->second; PtrInputMap::iterator input_it = input_map.find(b_to_sock.ptr.data); if (input_it != input_map.end()) input = input_it->second; /* either node may be NULL when the node was not exported, typically * because the node type is not supported */ if(output && input) graph->connect(output, input); } }
// ============================================================================ int CFormatGuessApp::Run(void) // ============================================================================ { const CArgs& args = GetArgs(); CNcbiIstream & input_stream = args["i"].AsInputFile(CArgValue::fBinary); string name_of_input_stream = args["i"].AsString(); if( name_of_input_stream.empty() || name_of_input_stream == "-" ) { name_of_input_stream = "stdin"; } CFormatGuess guesser( input_stream ); CFormatGuess::EFormat uFormat = guesser.GuessFormat(); string format_name; if( args["canonical-name"] ) { // caller wants to always use the format-guesser's name format_name = CFormatGuess::GetFormatName(uFormat); } else { // caller wants special names for some types FormatMap FormatStrings; FormatStrings[ CFormatGuess::eUnknown ] = "Format not recognized"; FormatStrings[ CFormatGuess::eBinaryASN ] = "Binary ASN.1"; FormatStrings[ CFormatGuess::eTextASN ] = "Text ASN.1"; FormatStrings[ CFormatGuess::eFasta ] = "FASTA sequence record"; FormatStrings[ CFormatGuess::eXml ] = "XML"; FormatStrings[ CFormatGuess::eRmo ] = "RepeatMasker Out"; FormatStrings[ CFormatGuess::eGlimmer3 ] = "Glimmer3 prediction"; FormatStrings[ CFormatGuess::ePhrapAce ] = "Phrap ACE assembly file"; FormatStrings[ CFormatGuess::eGtf ] = "GFF/GTF style annotation"; FormatStrings[ CFormatGuess::eAgp ] = "AGP format assembly"; FormatStrings[ CFormatGuess::eNewick ] = "Newick tree"; FormatStrings[ CFormatGuess::eDistanceMatrix ] = "Distance matrix"; FormatStrings[ CFormatGuess::eFiveColFeatureTable ] = "Five column feature table"; FormatStrings[ CFormatGuess::eTaxplot ] = "Tax plot"; FormatStrings[ CFormatGuess::eTable ] = "Generic table"; FormatStrings[ CFormatGuess::eAlignment ] = "Text alignment"; FormatStrings[ CFormatGuess::eFlatFileSequence ] = "Flat file sequence portion"; FormatStrings[ CFormatGuess::eSnpMarkers ] = "SNP marker flat file"; FormatStrings[ CFormatGuess::eWiggle ] = "UCSC Wiggle file"; FormatStrings[ CFormatGuess::eBed ] = "UCSC BED file"; FormatStrings[ CFormatGuess::eBed15 ] = "UCSC microarray file"; FormatStrings[ CFormatGuess::eHgvs ] = "HGVS Variation file"; FormatStrings[ CFormatGuess::eGff2 ] = "GFF2 feature table"; FormatStrings[ CFormatGuess::eGff3 ] = "GFF3 feature table"; FormatStrings[ CFormatGuess::eGvf ] = "GVF gene variation data"; FormatStrings[ CFormatGuess::eVcf ] = "VCF Variant Call Format"; FormatIter it = FormatStrings.find( uFormat ); if ( it == FormatStrings.end() ) { // cout << "Unmapped format [" << uFormat << "]"; format_name = CFormatGuess::GetFormatName(uFormat); } else { format_name = it->second; } } string object_type_to_show; if( args["show-object-type"] ) { AutoPtr<CObjectIStream> obj_istrm; switch( uFormat ) { case CFormatGuess::eBinaryASN: obj_istrm.reset( new CObjectIStreamAsnBinary(input_stream, eNoOwnership)); break; case CFormatGuess::eTextASN: obj_istrm.reset( new CObjectIStreamAsn(input_stream, eNoOwnership)); break; case CFormatGuess::eXml: obj_istrm.reset( new CObjectIStreamXml(input_stream, eNoOwnership)); break; case CFormatGuess::eJSON: obj_istrm.reset( new CObjectIStreamJson(input_stream, eNoOwnership)); break; default: // obj_istrm will be unset break; } if( obj_istrm.get() ) { object_type_to_show = guess_object_type(*obj_istrm); } else { object_type_to_show = "unknown"; } // If caller requested the object type then it should be set // even if it's unknown _ASSERT( ! object_type_to_show.empty() ); } const string output_format = args["output-format"].AsString(); if( output_format == "text" ) { cout << name_of_input_stream << " : "; _ASSERT( ! format_name.empty() ); // should be non-empty even if unknown cout << format_name; // second line is object type line, if applicable. if( ! object_type_to_show.empty() ) { cout << ", object type: " << object_type_to_show; } cout << endl; } else if( output_format == "XML" ) { xml::node output_node("formatguess"); // input_stream_node for each input specified. // However, there's currently only one so no loop here yet. xml::node input_stream_node("input_stream"); xml::attributes & stream_attribs = input_stream_node.get_attributes(); stream_attribs.insert("name", name_of_input_stream.c_str()); stream_attribs.insert("format_name", format_name.c_str()); if( ! object_type_to_show.empty() ) { stream_attribs.insert("object_type", object_type_to_show.c_str()); } output_node.push_back(input_stream_node); xml::document output_doc(output_node); output_doc.save_to_stream(cout); } else { _TROUBLE; } return 0; }
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++; } }
void run_query2(librdf_world* world, librdf_model* model, const std::string& q) { librdf_stream* strm; std::cout << "** Query: " << q << std::endl; librdf_uri* uri1 = librdf_new_uri(world, (const unsigned char*) "http://bunchy.org"); if (uri1 == 0) throw std::runtime_error("Couldn't parse URI"); librdf_uri* uri2 = librdf_new_uri(world, (const unsigned char*) "http://bunchy.org"); if (uri2 == 0) throw std::runtime_error("Couldn't parse URI"); librdf_query* qry = librdf_new_query(world, "sparql", uri1, (const unsigned char*) q.c_str(), uri2); librdf_free_uri(uri1); librdf_free_uri(uri2); if (qry == 0) throw std::runtime_error("Couldn't parse query."); librdf_query_results* results = librdf_query_execute(qry, model); if (results == 0) throw std::runtime_error("Couldn't execute query"); librdf_free_query(qry); std::cout << "--------------------------------------------------------" << std::endl; while (true) { if (librdf_query_results_finished(results)) break; int bcount = librdf_query_results_get_bindings_count(results); if (bcount < 0) throw std::runtime_error("Couldn't get query bindings count"); for(int i = 0; i < bcount; i++) { if (i != 0) std::cout << " "; librdf_node* value = librdf_query_results_get_binding_value(results, i); if (value == 0) throw std::runtime_error("Couldn't get results binding"); output_node(value); librdf_free_node(value); } std::cout << std::endl; librdf_query_results_next(results); } std::cout << "--------------------------------------------------------" << std::endl; librdf_free_query_results(results); }