void llvm_codegen_visit_call (struct _Visitor *visitor, struct AstNode *node) { /* int index = -1; struct AstNode *temp, *child = node->children; index = _process_expression(child, visitor); temp= child->sibling; if (temp != NULL) { for (temp = temp->children; temp != NULL; temp = temp->sibling) { PRINT_TYPE(child->type); printf(" "); ast_node_accept(child, visitor); if (child->sibling != NULL) printf(", "); } } printf(TAB"call "); PRINT_TYPE(child->symbol->type); printf(" "); ast_node_accept(child, visitor); printf("( "); printf(" )\n"); stack_size++; */ struct AstNode *child = node->children; printf(TAB"call "); PRINT_TYPE(child->symbol->type); printf(" "); ast_node_accept(child, visitor); printf("( "); child = child->sibling; if (child != NULL) { for (child = child->children; child != NULL; child = child->sibling) { PRINT_TYPE(child->type); printf(" "); ast_node_accept(child, visitor); if (child->sibling != NULL) printf(", "); } } printf(" )\n"); stack_size++; }
void llvm_codegen_visit_assignment_stmt (struct _Visitor *visitor, struct AstNode *node) { int rindex = -1; struct AstNode *lnode = node->children; struct AstNode *rnode = lnode->sibling; /* FIXME * */printf("; [Assignment][%s] %s(%d/%d) = %d\n", rnode->name, lnode->symbol->name, lnode->symbol->stack_index, stack_size, ast_node_get_value_as_int(rnode)); /**/ /* rnode */ rindex = _process_expression(rnode, visitor); /* lnode */ if (lnode->symbol->is_global && !symbol_is_procfunc(lnode->symbol)) { printf(TAB"store "); PRINT_TYPE(lnode->type); printf(" "); PRINT_VALUE(rnode, rindex); printf(", "); PRINT_TYPE(lnode->type); printf("* "); ast_node_accept(lnode, visitor); printf(", align 4\n"); } else if (rindex == -1) { /*lnode->symbol->stack_index = -1; lnode->symbol->value.integer = rnode->value.integer; lnode->value.integer = rnode->value.integer;*/ printf(TAB"add "); PRINT_TYPE(lnode->type); printf(" "); PRINT_VALUE(rnode, rindex); printf(", 0\n"); stack_size++; lnode->symbol->stack_index = stack_size; } else lnode->symbol->stack_index = rindex; /* FIXME */ printf("; [Assignment][%s] %s(%d/%d) = %d\n", rnode->name, lnode->symbol->name, lnode->symbol->stack_index, stack_size, ast_node_get_value_as_int(rnode)); /**/ }
void llvm_codegen_visit_parameter (struct _Visitor *visitor, struct AstNode *node) { PRINT_TYPE(node->type); printf(" "); ast_node_accept(node->children, visitor); }
static void _print_load(struct AstNode *node, Visitor *visitor) { printf(TAB"load "); PRINT_TYPE(node->type); printf("* "); ast_node_accept(node, visitor); printf(", align 4\n"); stack_size++; }
void llvm_codegen_visit_procfunc (struct _Visitor *visitor, struct AstNode *node) { struct AstNode *child; printf("define "); PRINT_TYPE(node->type); printf(" "); child = node->children; // Identifier ast_node_accept(child, visitor); printf(" ( "); child = child->sibling; if (child->kind == PARAM_LIST) { ast_node_accept(child, visitor); child = child->sibling; } printf(" ) {\n"); printf("entry:\n"); if (child->kind == VARDECL_LIST) { ast_node_accept(child, visitor); child = child->sibling; } ast_node_accept(child, visitor); printf(TAB"ret "); PRINT_TYPE(node->type); if (node->kind == FUNCTION) { printf(" "); PRINT_VALUE(node->children, node->children->symbol->stack_index); } printf("\n}\n\n"); }
TEST_P(AddArray, Accuracy) { PRINT_PARAM(devInfo); PRINT_TYPE(type); PRINT_PARAM(size); cv::Mat dst_gold; cv::add(mat1, mat2, dst_gold); cv::Mat dst; ASSERT_NO_THROW( cv::gpu::GpuMat gpuRes; cv::gpu::add(cv::gpu::GpuMat(mat1), cv::gpu::GpuMat(mat2), gpuRes); gpuRes.download(dst); );
TEST_P(Merge, Accuracy) { if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::gpu::NATIVE_DOUBLE)) return; PRINT_PARAM(devInfo); PRINT_TYPE(type); PRINT_PARAM(size); cv::Mat dst; ASSERT_NO_THROW( std::vector<cv::gpu::GpuMat> dev_src; cv::gpu::GpuMat dev_dst; for (size_t i = 0; i < src.size(); ++i) dev_src.push_back(cv::gpu::GpuMat(src[i])); cv::gpu::merge(dev_src, dev_dst); dev_dst.download(dst); );
/* parse an array initialiser and assign to a variable */ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable, int DoAssignment) { int ArrayIndex = 0; enum LexToken Token; struct Value *CValue; /* count the number of elements in the array */ if (DoAssignment && Parser->Mode == RunModeRun) { struct ParseState CountParser; int NumElements; ParserCopy(&CountParser, Parser); NumElements = ParseArrayInitialiser(&CountParser, NewVariable, FALSE); if (NewVariable->Typ->Base != TypeArray) AssignFail(Parser, "%t from array initializer", NewVariable->Typ, NULL, 0, 0, NULL, 0); if (NewVariable->Typ->ArraySize == 0) { NewVariable->Typ = TypeGetMatching(Parser->pc, Parser, NewVariable->Typ->FromType, NewVariable->Typ->Base, NumElements, NewVariable->Typ->Identifier, TRUE); VariableRealloc(Parser, NewVariable, TypeSizeValue(NewVariable, FALSE)); } #ifdef DEBUG_ARRAY_INITIALIZER PRINT_SOURCE_POS; printf("array size: %d \n", NewVariable->Typ->ArraySize); #endif } /* parse the array initialiser */ Token = LexGetToken(Parser, NULL, FALSE); while (Token != TokenRightBrace) { if (LexGetToken(Parser, NULL, FALSE) == TokenLeftBrace) { /* this is a sub-array initialiser */ int SubArraySize = 0; struct Value *SubArray = NewVariable; if (Parser->Mode == RunModeRun && DoAssignment) { SubArraySize = TypeSize(NewVariable->Typ->FromType, NewVariable->Typ->FromType->ArraySize, TRUE); SubArray = VariableAllocValueFromExistingData(Parser, NewVariable->Typ->FromType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + SubArraySize * ArrayIndex), TRUE, NewVariable); #ifdef DEBUG_ARRAY_INITIALIZER int FullArraySize = TypeSize(NewVariable->Typ, NewVariable->Typ->ArraySize, TRUE); PRINT_SOURCE_POS; PRINT_TYPE(NewVariable->Typ) printf("[%d] subarray size: %d (full: %d,%d) \n", ArrayIndex, SubArraySize, FullArraySize, NewVariable->Typ->ArraySize); #endif if (ArrayIndex >= NewVariable->Typ->ArraySize) ProgramFail(Parser, "too many array elements"); } LexGetToken(Parser, NULL, TRUE); ParseArrayInitialiser(Parser, SubArray, DoAssignment); } else { struct Value *ArrayElement = NULL; if (Parser->Mode == RunModeRun && DoAssignment) { struct ValueType * ElementType = NewVariable->Typ; int TotalSize = 1; int ElementSize = 0; /* int x[3][3] = {1,2,3,4} => handle it just like int x[9] = {1,2,3,4} */ while (ElementType->Base == TypeArray) { TotalSize *= ElementType->ArraySize; ElementType = ElementType->FromType; /* char x[10][10] = {"abc", "def"} => assign "abc" to x[0], "def" to x[1] etc */ if (LexGetToken(Parser, NULL, FALSE) == TokenStringConstant && ElementType->FromType->Base == TypeChar) break; } ElementSize = TypeSize(ElementType, ElementType->ArraySize, TRUE); #ifdef DEBUG_ARRAY_INITIALIZER PRINT_SOURCE_POS; printf("[%d/%d] element size: %d (x%d) \n", ArrayIndex, TotalSize, ElementSize, ElementType->ArraySize); #endif if (ArrayIndex >= TotalSize) ProgramFail(Parser, "too many array elements"); ArrayElement = VariableAllocValueFromExistingData(Parser, ElementType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + ElementSize * ArrayIndex), TRUE, NewVariable); } /* this is a normal expression initialiser */ if (!ExpressionParse(Parser, &CValue)) ProgramFail(Parser, "expression expected"); if (Parser->Mode == RunModeRun && DoAssignment) { ExpressionAssign(Parser, ArrayElement, CValue, FALSE, NULL, 0, FALSE); VariableStackPop(Parser, CValue); VariableStackPop(Parser, ArrayElement); } } ArrayIndex++; Token = LexGetToken(Parser, NULL, FALSE); if (Token == TokenComma) { LexGetToken(Parser, NULL, TRUE); Token = LexGetToken(Parser, NULL, FALSE); } else if (Token != TokenRightBrace) ProgramFail(Parser, "comma expected"); } if (Token == TokenRightBrace) LexGetToken(Parser, NULL, TRUE); else ProgramFail(Parser, "'}' expected"); return ArrayIndex; }
int main( int i_argc, char **ppsz_argv ) { char *client_socket_tmpl = "dvblastctl.clientsock.XXXXXX"; char *psz_srv_socket = NULL; int i; char *p_cmd, *p_arg1 = NULL, *p_arg2 = NULL; ssize_t i_size; struct sockaddr_un sun_client, sun_server; uint8_t p_buffer[COMM_BUFFER_SIZE]; uint8_t *p_data = p_buffer + COMM_HEADER_SIZE; uint16_t i_pid = 0; struct dvblastctl_option opt = { 0, 0, 0 }; for ( ; ; ) { int c; static const struct option long_options[] = { {"remote-socket", required_argument, NULL, 'r'}, {"print", required_argument, NULL, 'x'}, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; if ( (c = getopt_long(i_argc, ppsz_argv, "r:x:h", long_options, NULL)) == -1 ) break; switch ( c ) { case 'r': psz_srv_socket = optarg; break; case 'x': if ( !strcmp(optarg, "text") ) i_print_type = PRINT_TEXT; else if ( !strcmp(optarg, "xml") ) i_print_type = PRINT_XML; else msg_Warn( NULL, "unrecognized print type %s", optarg ); /* Make stdout line-buffered */ setvbuf(stdout, NULL, _IOLBF, 0); break; case 'h': default: usage(); } } /* Validate commands */ #define usage_error(msg, ...) \ do { \ msg_Err( NULL, msg, ##__VA_ARGS__ ); \ usage(); \ } while(0) p_cmd = ppsz_argv[optind]; p_arg1 = ppsz_argv[optind + 1]; p_arg2 = ppsz_argv[optind + 2]; if ( !psz_srv_socket ) usage_error( "Remote socket is not set.\n" ); if ( !p_cmd ) usage_error( "Command is not set.\n" ); i = 0; do { if ( streq(ppsz_argv[optind], options[i].opt) ) { opt = options[i]; break; } } while ( options[++i].opt ); if ( !opt.opt ) usage_error( "Unknown command: %s\n", p_cmd ); if ( opt.nparams == 1 && !p_arg1 ) usage_error( "%s option needs parameter.\n", opt.opt ); if ( opt.nparams == 2 && (!p_arg1 || !p_arg2) ) usage_error( "%s option needs two parameters.\n", opt.opt ); #undef usage_error /* Create client socket name */ char *tmpdir = getenv("TMPDIR"); snprintf( psz_client_socket, PATH_MAX - 1, "%s/%s", tmpdir ? tmpdir : "/tmp", client_socket_tmpl ); psz_client_socket[PATH_MAX - 1] = '\0'; int tmp_fd = mkstemp(psz_client_socket); if ( tmp_fd > -1 ) { close(tmp_fd); unlink(psz_client_socket); } else { return_error( "Cannot build UNIX socket %s (%s)", psz_client_socket, strerror(errno) ); } if ( (i_fd = socket( AF_UNIX, SOCK_DGRAM, 0 )) < 0 ) return_error( "Cannot create UNIX socket (%s)", strerror(errno) ); i = COMM_MAX_MSG_CHUNK; setsockopt( i_fd, SOL_SOCKET, SO_RCVBUF, &i, sizeof(i) ); memset( &sun_client, 0, sizeof(sun_client) ); sun_client.sun_family = AF_UNIX; strncpy( sun_client.sun_path, psz_client_socket, sizeof(sun_client.sun_path) ); sun_client.sun_path[sizeof(sun_client.sun_path) - 1] = '\0'; if ( bind( i_fd, (struct sockaddr *)&sun_client, SUN_LEN(&sun_client) ) < 0 ) return_error( "Cannot bind (%s)", strerror(errno) ); memset( &sun_server, 0, sizeof(sun_server) ); sun_server.sun_family = AF_UNIX; strncpy( sun_server.sun_path, psz_srv_socket, sizeof(sun_server.sun_path) ); sun_server.sun_path[sizeof(sun_server.sun_path) - 1] = '\0'; p_buffer[0] = COMM_HEADER_MAGIC; p_buffer[1] = opt.cmd; memset( p_buffer + 2, 0, COMM_HEADER_SIZE - 2 ); i_size = COMM_HEADER_SIZE; /* Handle commands that send parameters */ switch ( opt.cmd ) { case CMD_INVALID: case CMD_RELOAD: case CMD_SHUTDOWN: case CMD_FRONTEND_STATUS: case CMD_MMI_STATUS: case CMD_GET_PAT: case CMD_GET_CAT: case CMD_GET_NIT: case CMD_GET_SDT: case CMD_GET_PIDS: /* These commands need no special handling because they have no parameters */ break; case CMD_GET_PMT: { uint16_t i_sid = atoi(p_arg1); i_size = COMM_HEADER_SIZE + 2; p_data[0] = (uint8_t)((i_sid >> 8) & 0xff); p_data[1] = (uint8_t)(i_sid & 0xff); break; } case CMD_GET_PID: { i_pid = (uint16_t)atoi(p_arg1); i_size = COMM_HEADER_SIZE + 2; p_data[0] = (uint8_t)((i_pid >> 8) & 0xff); p_data[1] = (uint8_t)(i_pid & 0xff); break; } case CMD_MMI_SEND_TEXT: { struct cmd_mmi_send *p_cmd = (struct cmd_mmi_send *)p_data; p_cmd->i_slot = atoi(p_arg1); en50221_mmi_object_t object; object.i_object_type = EN50221_MMI_ANSW; if ( !p_arg2 || p_arg2[0] == '\0' ) { object.u.answ.b_ok = 0; object.u.answ.psz_answ = ""; } else { object.u.answ.b_ok = 1; object.u.answ.psz_answ = p_arg2; } i_size = COMM_BUFFER_SIZE - COMM_HEADER_SIZE - ((void *)&p_cmd->object - (void *)p_cmd); if ( en50221_SerializeMMIObject( (uint8_t *)&p_cmd->object, &i_size, &object ) == -1 ) return_error( "Comm buffer is too small" ); i_size += COMM_HEADER_SIZE + ((void *)&p_cmd->object - (void *)p_cmd); break; } case CMD_MMI_SEND_CHOICE: { struct cmd_mmi_send *p_cmd = (struct cmd_mmi_send *)p_data; p_cmd->i_slot = atoi(p_arg1); i_size = COMM_HEADER_SIZE + sizeof(struct cmd_mmi_send); p_cmd->object.i_object_type = EN50221_MMI_MENU_ANSW; p_cmd->object.u.menu_answ.i_choice = atoi(p_arg2); break; } case CMD_MMI_SLOT_STATUS: case CMD_MMI_OPEN: case CMD_MMI_CLOSE: case CMD_MMI_RECV: { p_data[0] = atoi(p_arg1); i_size = COMM_HEADER_SIZE + 1; break; } default: /* This should not happen */ return_error( "Unhandled option (%d)", opt.cmd ); } /* Send command and receive answer */ if ( sendto( i_fd, p_buffer, i_size, 0, (struct sockaddr *)&sun_server, SUN_LEN(&sun_server) ) < 0 ) return_error( "Cannot send comm socket (%s)", strerror(errno) ); uint32_t i_packet_size = 0, i_received = 0; do { i_size = recv( i_fd, p_buffer + i_received, COMM_MAX_MSG_CHUNK, 0 ); if ( i_size == -1 ) break; if ( !i_packet_size ) { uint32_t *p_packet_size = (uint32_t *)&p_buffer[4]; i_packet_size = *p_packet_size; if ( i_packet_size > COMM_BUFFER_SIZE ) { i_size = -1; break; } } i_received += i_size; } while ( i_received < i_packet_size ); clean_client_socket(); if ( i_size < COMM_HEADER_SIZE ) return_error( "Cannot recv from comm socket, size:%zd (%s)", i_size, strerror(errno) ); /* Process answer */ if ( p_buffer[0] != COMM_HEADER_MAGIC ) return_error( "Wrong protocol version 0x%x", p_buffer[0] ); now = mdate(); ctl_cmd_answer_t c_answer = p_buffer[1]; switch ( c_answer ) { case RET_OK: break; case RET_MMI_WAIT: exit(252); break; case RET_ERR: return_error( "Request failed" ); break; case RET_HUH: return_error( "Internal error" ); break; case RET_NODATA: return_error( "No data" ); break; case RET_PAT: case RET_CAT: case RET_NIT: case RET_SDT: { uint8_t *p_flat_data = p_buffer + COMM_HEADER_SIZE; unsigned int i_flat_data_size = i_size - COMM_HEADER_SIZE; uint8_t **pp_sections = psi_unpack_sections( p_flat_data, i_flat_data_size ); switch( c_answer ) { case RET_PAT: pat_table_print( pp_sections, psi_print, NULL, i_print_type ); break; case RET_CAT: cat_table_print( pp_sections, psi_print, NULL, i_print_type ); break; case RET_NIT: nit_table_print( pp_sections, psi_print, NULL, psi_iconv, NULL, i_print_type ); break; case RET_SDT: sdt_table_print( pp_sections, psi_print, NULL, psi_iconv, NULL, i_print_type ); break; default: break; /* Can't happen */ } psi_table_free( pp_sections ); free( pp_sections ); break; } case RET_PMT: { pmt_print( p_data, psi_print, NULL, psi_iconv, NULL, i_print_type ); break; } case RET_PID: { print_pids_header(); print_pid( i_pid, (ts_pid_info_t *)p_data ); print_pids_footer(); break; } case RET_PIDS: { print_pids( p_data ); break; } case RET_FRONTEND_STATUS: { int ret = 1; struct ret_frontend_status *p_ret = (struct ret_frontend_status *)&p_buffer[COMM_HEADER_SIZE]; if ( i_size != COMM_HEADER_SIZE + sizeof(struct ret_frontend_status) ) return_error( "Bad frontend status" ); if ( i_print_type == PRINT_XML ) printf("<FRONTEND>\n"); #define PRINT_TYPE( x ) \ do { \ if ( i_print_type == PRINT_XML ) \ printf( " <TYPE type=\"%s\"/>\n", STRINGIFY(x) ); \ else \ printf( "type: %s\n", STRINGIFY(x) ); \ } while(0) switch ( p_ret->info.type ) { case FE_QPSK: PRINT_TYPE(QPSK); break; case FE_QAM : PRINT_TYPE(QAM); break; case FE_OFDM: PRINT_TYPE(OFDM); break; case FE_ATSC: PRINT_TYPE(ATSC); break; default : PRINT_TYPE(UNKNOWN); break; } #undef PRINT_TYPE #define PRINT_INFO( x ) \ do { \ if ( i_print_type == PRINT_XML ) \ printf( " <SETTING %s=\"%u\"/>\n", STRINGIFY(x), p_ret->info.x ); \ else \ printf( "%s: %u\n", STRINGIFY(x), p_ret->info.x ); \ } while(0) PRINT_INFO( frequency_min ); PRINT_INFO( frequency_max ); PRINT_INFO( frequency_stepsize ); PRINT_INFO( frequency_tolerance ); PRINT_INFO( symbol_rate_min ); PRINT_INFO( symbol_rate_max ); PRINT_INFO( symbol_rate_tolerance ); PRINT_INFO( notifier_delay ); #undef PRINT_INFO if ( i_print_type == PRINT_TEXT ) printf("\ncapability list:\n"); #define PRINT_CAPS( x ) \ do { \ if ( p_ret->info.caps & (FE_##x) ) { \ if ( i_print_type == PRINT_XML ) { \ printf( " <CAPABILITY %s=\"1\"/>\n", STRINGIFY(x) ); \ } else { \ printf( "%s\n", STRINGIFY(x) ); \ } \ } \ } while(0) PRINT_CAPS( IS_STUPID ); PRINT_CAPS( CAN_INVERSION_AUTO ); PRINT_CAPS( CAN_FEC_1_2 ); PRINT_CAPS( CAN_FEC_2_3 ); PRINT_CAPS( CAN_FEC_3_4 ); PRINT_CAPS( CAN_FEC_4_5 ); PRINT_CAPS( CAN_FEC_5_6 ); PRINT_CAPS( CAN_FEC_6_7 ); PRINT_CAPS( CAN_FEC_7_8 ); PRINT_CAPS( CAN_FEC_8_9 ); PRINT_CAPS( CAN_FEC_AUTO ); PRINT_CAPS( CAN_QPSK ); PRINT_CAPS( CAN_QAM_16 ); PRINT_CAPS( CAN_QAM_32 ); PRINT_CAPS( CAN_QAM_64 ); PRINT_CAPS( CAN_QAM_128 ); PRINT_CAPS( CAN_QAM_256 ); PRINT_CAPS( CAN_QAM_AUTO ); PRINT_CAPS( CAN_TRANSMISSION_MODE_AUTO ); PRINT_CAPS( CAN_BANDWIDTH_AUTO ); PRINT_CAPS( CAN_GUARD_INTERVAL_AUTO ); PRINT_CAPS( CAN_HIERARCHY_AUTO ); PRINT_CAPS( CAN_MUTE_TS ); #define DVBAPI_VERSION ((DVB_API_VERSION)*100+(DVB_API_VERSION_MINOR)) #if DVBAPI_VERSION >= 301 PRINT_CAPS( CAN_8VSB ); PRINT_CAPS( CAN_16VSB ); PRINT_CAPS( NEEDS_BENDING ); PRINT_CAPS( CAN_RECOVER ); #endif #if DVBAPI_VERSION >= 500 PRINT_CAPS( HAS_EXTENDED_CAPS ); #endif #if DVBAPI_VERSION >= 501 PRINT_CAPS( CAN_2G_MODULATION ); #endif #undef PRINT_CAPS if ( i_print_type == PRINT_TEXT ) printf("\nstatus:\n"); #define PRINT_STATUS( x ) \ do { \ if ( p_ret->i_status & (FE_##x) ) { \ if ( i_print_type == PRINT_XML ) { \ printf( " <STATUS status=\"%s\"/>\n", STRINGIFY(x) ); \ } else { \ printf( "%s\n", STRINGIFY(x) ); \ } \ } \ } while(0) PRINT_STATUS( HAS_SIGNAL ); PRINT_STATUS( HAS_CARRIER ); PRINT_STATUS( HAS_VITERBI ); PRINT_STATUS( HAS_SYNC ); PRINT_STATUS( HAS_LOCK ); PRINT_STATUS( REINIT ); #undef PRINT_STATUS if ( p_ret->i_status & FE_HAS_LOCK ) { if ( i_print_type == PRINT_XML ) { printf(" <VALUE bit_error_rate=\"%d\"/>\n", p_ret->i_ber); printf(" <VALUE signal_strength=\"%d\"/>\n", p_ret->i_strength); printf(" <VALUE SNR=\"%d\"/>\n", p_ret->i_snr); } else { printf("\nBit error rate: %d\n", p_ret->i_ber); printf("Signal strength: %d\n", p_ret->i_strength); printf("SNR: %d\n", p_ret->i_snr); } ret = 0; } if ( i_print_type == PRINT_XML ) printf("</FRONTEND>\n" ); exit(ret); break; } case RET_MMI_STATUS: { struct ret_mmi_status *p_ret = (struct ret_mmi_status *)&p_buffer[COMM_HEADER_SIZE]; if ( i_size != COMM_HEADER_SIZE + sizeof(struct ret_mmi_status) ) return_error( "Bad MMI status" ); printf("CA interface with %d %s, type:\n", p_ret->caps.slot_num, p_ret->caps.slot_num == 1 ? "slot" : "slots"); #define PRINT_CAPS( x, s ) \ if ( p_ret->caps.slot_type & (CA_##x) ) \ printf(s "\n"); PRINT_CAPS( CI, "CI high level interface" ); PRINT_CAPS( CI_LINK, "CI link layer level interface" ); PRINT_CAPS( CI_PHYS, "CI physical layer level interface (not supported)" ); PRINT_CAPS( DESCR, "built-in descrambler" ); PRINT_CAPS( SC, "simple smartcard interface" ); #undef PRINT_CAPS printf("\n%d available %s\n", p_ret->caps.descr_num, p_ret->caps.descr_num == 1 ? "descrambler (key)" : "descramblers (keys)"); #define PRINT_DESC( x ) \ if ( p_ret->caps.descr_type & (CA_##x) ) \ printf( STRINGIFY(x) "\n" ); PRINT_DESC( ECD ); PRINT_DESC( NDS ); PRINT_DESC( DSS ); #undef PRINT_DESC exit( p_ret->caps.slot_num ); break; } case RET_MMI_SLOT_STATUS: { struct ret_mmi_slot_status *p_ret = (struct ret_mmi_slot_status *)&p_buffer[COMM_HEADER_SIZE]; if ( i_size < COMM_HEADER_SIZE + sizeof(struct ret_mmi_slot_status) ) return_error( "Bad MMI slot status" ); printf("CA slot #%u: ", p_ret->sinfo.num); #define PRINT_TYPE( x, s ) \ if ( p_ret->sinfo.type & (CA_##x) ) \ printf(s); PRINT_TYPE( CI, "high level, " ); PRINT_TYPE( CI_LINK, "link layer level, " ); PRINT_TYPE( CI_PHYS, "physical layer level, " ); #undef PRINT_TYPE if ( p_ret->sinfo.flags & CA_CI_MODULE_READY ) { printf("module present and ready\n"); exit(0); } if ( p_ret->sinfo.flags & CA_CI_MODULE_PRESENT ) printf("module present, not ready\n"); else printf("module not present\n"); exit(1); break; } case RET_MMI_RECV: { struct ret_mmi_recv *p_ret = (struct ret_mmi_recv *)&p_buffer[COMM_HEADER_SIZE]; if ( i_size < COMM_HEADER_SIZE + sizeof(struct ret_mmi_recv) ) return_error( "Bad MMI recv" ); en50221_UnserializeMMIObject( &p_ret->object, i_size - COMM_HEADER_SIZE - ((void *)&p_ret->object - (void *)p_ret) ); switch ( p_ret->object.i_object_type ) { case EN50221_MMI_ENQ: printf("%s\n", p_ret->object.u.enq.psz_text); printf("(empty to cancel)\n"); exit(p_ret->object.u.enq.b_blind ? 253 : 254); break; case EN50221_MMI_MENU: printf("%s\n", p_ret->object.u.menu.psz_title); printf("%s\n", p_ret->object.u.menu.psz_subtitle); printf("0 - Cancel\n"); for ( i = 0; i < p_ret->object.u.menu.i_choices; i++ ) printf("%d - %s\n", i + 1, p_ret->object.u.menu.ppsz_choices[i]); printf("%s\n", p_ret->object.u.menu.psz_bottom); exit(p_ret->object.u.menu.i_choices); break; case EN50221_MMI_LIST: printf("%s\n", p_ret->object.u.menu.psz_title); printf("%s\n", p_ret->object.u.menu.psz_subtitle); for ( i = 0; i < p_ret->object.u.menu.i_choices; i++ ) printf("%s\n", p_ret->object.u.menu.ppsz_choices[i]); printf("%s\n", p_ret->object.u.menu.psz_bottom); printf("(0 to cancel)\n"); exit(0); break; default: return_error( "Unknown MMI object" ); break; } exit(255); break; } default: return_error( "Unknown command answer: %u", c_answer ); } return 0; }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); osgViewer::Viewer viewer(arguments); #if 0 typedef std::list< osg::ref_ptr<osg::Script> > Scripts; Scripts scripts; osg::ref_ptr<osg::Group> model = new osg::Group; std::string filename; while(arguments.read("--script",filename)) { osg::ref_ptr<osg::Script> script = osgDB::readScriptFile(filename); if (script.valid()) scripts.push_back(script.get()); } // assgin script engine to scene graphs model->getOrCreateUserDataContainer()->addUserObject(osgDB::readFile<osg::ScriptEngine>("ScriptEngine.lua")); model->getOrCreateUserDataContainer()->addUserObject(osgDB::readFile<osg::ScriptEngine>("ScriptEngine.python")); model->getOrCreateUserDataContainer()->addUserObject(osgDB::readFile<osg::ScriptEngine>("ScriptEngine.js")); // assign scripts to scene graph for(Scripts::iterator itr = scripts.begin(); itr != scripts.end(); ++itr) { model->addUpdateCallback(new osg::ScriptNodeCallback(itr->get())); } std::string str; osg::ref_ptr<osg::ScriptEngine> luaScriptEngine = osgDB::readFile<osg::ScriptEngine>("ScriptEngine.lua"); if (luaScriptEngine.valid()) { while (arguments.read("--lua", str)) { osg::ref_ptr<osg::Script> script = osgDB::readScriptFile(str); if (script.valid()) { luaScriptEngine->run(script.get()); } } } osg::ref_ptr<osg::ScriptEngine> v8ScriptEngine = osgDB::readFile<osg::ScriptEngine>("ScriptEngine.V8"); if (v8ScriptEngine.valid()) { while (arguments.read("--js",str)) { osg::ref_ptr<osg::Script> script = osgDB::readScriptFile(str); if (script.valid()) { v8ScriptEngine->run(script.get()); } } } osg::ref_ptr<osg::ScriptEngine> pythonScriptEngine = osgDB::readFile<osg::ScriptEngine>("ScriptEngine.python"); if (pythonScriptEngine.valid()) { while (arguments.read("--python",str)) { osg::ref_ptr<osg::Script> script = osgDB::readScriptFile(str); if (script.valid()) { pythonScriptEngine->run(script.get()); } } } return 0; #endif #if 1 osg::ref_ptr<osgPresentation::Presentation> presentation = new osgPresentation::Presentation; osg::ref_ptr<osgPresentation::Slide> slide = new osgPresentation::Slide; osg::ref_ptr<osgPresentation::Layer> layer = new osgPresentation::Layer; osg::ref_ptr<osgPresentation::Group> group = new osgPresentation::Group; osg::ref_ptr<osgPresentation::Element> element = new osgPresentation::Element; osg::ref_ptr<osgPresentation::Text> text = new osgPresentation::Text; osg::ref_ptr<osgPresentation::Model> model = new osgPresentation::Model; osg::ref_ptr<osgPresentation::Audio> audio = new osgPresentation::Audio; osg::ref_ptr<osgPresentation::Image> image = new osgPresentation::Image; osg::ref_ptr<osgPresentation::Movie> movie = new osgPresentation::Movie; osg::ref_ptr<osgPresentation::Volume> volume = new osgPresentation::Volume; presentation->addChild(slide.get()); slide->addChild(layer.get()); //layer->addChild(element.get()); //layer->addChild(group.get()); layer->addChild(element.get()); // layer->addChild(model.get()); layer->addChild(text.get()); layer->addChild(audio.get()); layer->addChild(image.get()); layer->addChild(movie.get()); layer->addChild(volume.get()); text->setProperty("string",std::string("This is a first test")); text->setProperty("font",std::string("times.ttf")); text->setProperty("character_size",2.2); text->setProperty("width",std::string("103.2")); model->setProperty("filename", std::string("dumptruck.osgt")); image->setProperty("filename", std::string("Images/lz.rgb")); image->setProperty("scale",0.75); movie->setProperty("filename", std::string("/home/robert/Data/Movie/big_buck_bunny_1080p_stereo.ogg")); movie->setProperty("scale",0.75); volume->setProperty("filename", std::string("/home/robert/Data/MaleVisibleHumanHead")); volume->setProperty("scale",0.75); volume->setProperty("technique",std::string("iso-surface")); presentation->setProperty("scale",1.0); #if 0 osgPresentation::PrintSupportedProperties psp(std::cout); presentation->accept(psp); osgPresentation::PrintProperties pp(std::cout); presentation->accept(pp); #endif osgPresentation::LoadAction load; presentation->accept( load ); viewer.setSceneData( presentation.get() ); osgDB::writeNodeFile(*presentation, "pres.osgt"); osgDB::ClassInterface pi; pi.getWhiteList()["osgPresentation::Presentation"]["filename"]=osgDB::BaseSerializer::RW_STRING; pi.getBlackList()["osgPresentation::Presentation"]["Children"]; pi.getBlackList()["osgPresentation::Presentation"]["UserDataContainer"]; pi.getBlackList()["osgPresentation::Presentation"]["UserData"]; pi.getBlackList()["osgPresentation::Presentation"]["CullCallback"]; pi.getBlackList()["osgPresentation::Presentation"]["ComputeBoundingSphereCallback"]; #if 0 osgDB::ObjectWrapperManager* owm = osgDB::Registry::instance()->getObjectWrapperManager(); if (owm) { const osgDB::ObjectWrapperManager::WrapperMap& wrapperMap = owm->getWrapperMap(); for(osgDB::ObjectWrapperManager::WrapperMap::const_iterator itr = wrapperMap.begin(); itr != wrapperMap.end(); ++itr) { osgDB::ObjectWrapper* ow = itr->second.get(); OSG_NOTICE<<std::endl<<"Wrapper : "<<itr->first<<", Domain="<<ow->getDomain()<<", Name="<<ow->getName()<<std::endl; const osgDB::StringList& associates = ow->getAssociates(); for(osgDB::StringList::const_iterator aitr = associates.begin(); aitr != associates.end(); ++aitr) { OSG_NOTICE<<" associate = "<<*aitr<<std::endl; } osgDB::StringList properties; osgDB::ObjectWrapper::TypeList types; ow->writeSchema(properties, types); OSG_NOTICE<<" properties.size() = "<<properties.size()<<", types.size() = "<<types.size()<<std::endl; unsigned int numProperties = std::min(properties.size(), types.size()); for(unsigned int i=0; i<numProperties; ++i) { OSG_NOTICE<<" property = "<<properties[i]<<", type = "<<types[i]<<", typeName = "<<pi.getTypeName(types[i])<<std::endl; } } #if 1 osgDB::ObjectWrapperManager::IntLookupMap& intLookupMap = owm->getLookupMap(); for(osgDB::ObjectWrapperManager::IntLookupMap::iterator itr = intLookupMap.begin(); itr != intLookupMap.end(); ++itr) { OSG_NOTICE<<std::endl<<"IntLookMap["<<itr->first<<"]"<<std::endl; osgDB::IntLookup::StringToValue& stv = itr->second.getStringToValue(); for(osgDB::IntLookup::StringToValue::iterator sitr = stv.begin(); sitr != stv.end(); ++sitr) { OSG_NOTICE<<" "<<sitr->first<<", "<<sitr->second<<std::endl; } } #endif } #endif presentation->setName("[this is a test]"); #if 0 if (pi.setProperty(presentation.get(), "Name", std::string("[this is new improved test]"))) { OSG_NOTICE<<"setProperty(presentation.get(), Name) succeeded."<<std::endl; } else { OSG_NOTICE<<"setProperty(presentation.get(), Name) failed."<<std::endl; } std::string name; if (pi.getProperty(presentation.get(), "Name", name)) { OSG_NOTICE<<"getProperty(presentation.get(), Name) succeeded, Name = "<<name<<std::endl; } else { OSG_NOTICE<<"getProperty(presentation.get(), Name) failed."<<std::endl; } OSG_NOTICE<<std::endl; // presentation->setDataVariance(osg::Object::DYNAMIC); int variance = 1234; if (pi.getProperty(presentation.get(), "DataVariance", variance)) { OSG_NOTICE<<"getProperty(presentation.get(), DataVariance) succeeded, variance = "<<variance<<std::endl; } else { OSG_NOTICE<<"getProperty(presentation.get(), DataVariance) failed."<<std::endl; } OSG_NOTICE<<std::endl; if (pi.setProperty(presentation.get(), "DataVariance", 1)) { OSG_NOTICE<<"setProperty(presentation.get(), DataVariance) succeeded."<<std::endl; } else { OSG_NOTICE<<"setProperty(presentation.get(), DataVariance) failed."<<std::endl; } OSG_NOTICE<<std::endl; if (pi.getProperty(presentation.get(), "DataVariance", variance)) { OSG_NOTICE<<"2nd getProperty(presentation.get(), DataVariance) succeeded, variance = "<<variance<<std::endl; } else { OSG_NOTICE<<"2nd getProperty(presentation.get(), DataVariance) failed."<<std::endl; } OSG_NOTICE<<std::endl; presentation->setMatrix(osg::Matrixd::translate(osg::Vec3d(1.0,2.0,3.0))); // if (pi.setProperty(presentation.get(), "Matrix", osg::Matrixd::scale(1.0,2.0,2.0))) if (pi.setProperty(presentation.get(), "Matrix", osg::Matrixd::scale(2.0,2.0,2.0))) { OSG_NOTICE<<"setProperty(..,Matrix) succeeded."<<std::endl; } else { OSG_NOTICE<<"setProperty(..,Matrix) failed."<<std::endl; } osg::Matrixd matrix; if (pi.getProperty(presentation.get(), "Matrix", matrix)) { OSG_NOTICE<<"getProperty(presentation.get(), ...) succeeded, Matrix = "<<matrix<<std::endl; } else { OSG_NOTICE<<"getProperty(presentation.get(), ...) failed."<<std::endl; } #if 1 osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; osg::ref_ptr<osg::Node> node = new osg::Node; osgDB::ClassInterface::PropertyMap properties; if (pi.getSupportedProperties(presentation.get(), properties, true)) { OSG_NOTICE<<"Have supported properites found."<<std::endl; for(osgDB::ClassInterface::PropertyMap::iterator itr = properties.begin(); itr != properties.end(); ++itr) { OSG_NOTICE<<" Property "<<itr->first<<", "<<pi.getTypeName(itr->second)<<std::endl; } } else { OSG_NOTICE<<"No supported properites found."<<std::endl; } OSG_NOTICE<<"Type(float) = "<<osgDB::getTypeEnum<float>()<<", "<<osgDB::getTypeString<float>()<<std::endl; OSG_NOTICE<<"Type(bool) = "<<osgDB::getTypeEnum<bool>()<<", "<<osgDB::getTypeString<bool>()<<std::endl; OSG_NOTICE<<"Type(osg::Vec3) = "<<osgDB::getTypeEnum<osg::Vec3>()<<", "<<osgDB::getTypeString<osg::Vec3>()<<std::endl; OSG_NOTICE<<"Type(osg::Matrixd) = "<<osgDB::getTypeEnum<osg::Matrixd>()<<", "<<osgDB::getTypeString<osg::Matrixd>()<<std::endl; OSG_NOTICE<<"Type(osg::Vec2ui) = "<<osgDB::getTypeEnum<osg::Vec2ui>()<<", "<<osgDB::getTypeString<osg::Vec2ui>()<<std::endl; OSG_NOTICE<<"Type(GLenum) = "<<osgDB::getTypeEnum<GLenum>()<<", "<<osgDB::getTypeString<GLenum>()<<std::endl; OSG_NOTICE<<"Type(int) = "<<osgDB::getTypeEnum<int>()<<", "<<osgDB::getTypeString<int>()<<std::endl; OSG_NOTICE<<"Type(osg::Image*) = "<<osgDB::getTypeEnum<osg::Image*>()<<", "<<osgDB::getTypeString<osg::Image*>()<<std::endl; OSG_NOTICE<<"Type(osg::Object*) = "<<osgDB::getTypeEnum<osg::Object*>()<<", "<<osgDB::getTypeString<osg::Object*>()<<std::endl; OSG_NOTICE<<"Type(osg::Referenced*) = "<<osgDB::getTypeEnum<osg::Referenced*>()<<", "<<osgDB::getTypeString<osg::Referenced*>()<<std::endl; osg::Object* ptr = presentation.get(); OSG_NOTICE<<"Type(ptr) = "<<osgDB::getTypeEnumFromPtr(ptr)<<", "<<osgDB::getTypeStringFromPtr(ptr)<<std::endl; OSG_NOTICE<<"Type(presentation) = "<<osgDB::getTypeEnumFromPtr(presentation.get())<<", "<<osgDB::getTypeStringFromPtr(presentation.get())<<std::endl; osg::Image* image2 = 0; OSG_NOTICE<<"Type(image) = "<<osgDB::getTypeEnumFromPtr(image2)<<", "<<osgDB::getTypeStringFromPtr(image2)<<std::endl; osg::Vec3 pos; OSG_NOTICE<<"Type(pos) = "<<osgDB::getTypeEnumFrom(pos)<<", "<<osgDB::getTypeStringFrom(pos)<<std::endl; OSG_NOTICE<<"Type(std::string) = "<<osgDB::getTypeEnum<std::string>()<<", "<<osgDB::getTypeString<std::string>()<<std::endl; osgDB::BaseSerializer::Type type; if (pi.getPropertyType(presentation.get(), "Name", type)) { OSG_NOTICE<<"Property Type, Name = "<< type<<std::endl; } #endif osg::Matrixd mymatrix = osg::Matrix::translate(-1,2,3); pi.setProperty(presentation.get(), "mymatrix", mymatrix); osg::Matrixd copyofmatrix; if (pi.getProperty(presentation.get(), "mymatrix", copyofmatrix)) { OSG_NOTICE<<"mymatrix = "<<copyofmatrix<<std::endl; } if (pi.getProperty(presentation.get(), "Matrix", copyofmatrix)) { OSG_NOTICE<<"Matrix = "<<copyofmatrix<<std::endl; } std::string teststring="Another test"; pi.setProperty(presentation.get(),"mystring",teststring); std::string astring; if (pi.getProperty(presentation.get(),"mystring",astring)) { OSG_NOTICE<<"mystring = "<<astring<<std::endl; } else { OSG_NOTICE<<"failed to get mystring"<<std::endl; } #define PRINT_TYPE(O,PN) \ { \ osgDB::BaseSerializer::Type type; \ if (pi.getPropertyType(O, #PN, type)) \ { \ OSG_NOTICE<<#PN<<" : type "<<type<<", "<<pi.getTypeName(type)<<std::endl; \ } \ else \ { \ OSG_NOTICE<<#PN<<" : failed to get type"<<std::endl; \ } \ } PRINT_TYPE(presentation.get(), Name) PRINT_TYPE(presentation.get(), Matrix) PRINT_TYPE(presentation.get(), DataVariance) PRINT_TYPE(presentation.get(), mystring) PRINT_TYPE(presentation.get(), mymatrix) osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter; if (pi.getSupportedProperties(event.get(), properties, true)) { OSG_NOTICE<<"Have supported properites found."<<std::endl; for(osgDB::ClassInterface::PropertyMap::iterator itr = properties.begin(); itr != properties.end(); ++itr) { OSG_NOTICE<<" Property "<<itr->first<<", "<<pi.getTypeName(itr->second)<<std::endl; } } else { OSG_NOTICE<<"No supported properites found."<<std::endl; } #endif osg::Vec3f pos(1.5,3.0,4.5); presentation->setProperty("position",pos); osg::Vec2f texcoord(0.5f,0.20f); presentation->setProperty("texcoord",texcoord); osg::ref_ptr<osg::ScriptEngine> luaScriptEngine = osgDB::readFile<osg::ScriptEngine>("ScriptEngine.lua"); if (luaScriptEngine.valid()) { presentation->getOrCreateUserDataContainer()->addUserObject(luaScriptEngine.get()); std::string str; while (arguments.read("--lua", str)) { osg::ref_ptr<osg::Script> script = osgDB::readScriptFile(str); if (script.valid()) { presentation->addUpdateCallback(new osg::ScriptNodeCallback(script.get(),"update")); } } if (arguments.read("--test", str)) { osg::ref_ptr<osg::Script> script = osgDB::readScriptFile(str); if (script.valid()) { osg::Parameters inputParameters; osg::Parameters outputParameters; inputParameters.push_back(new osg::StringValueObject("string","my very first string input")); inputParameters.push_back(new osg::DoubleValueObject("double",1.234)); inputParameters.push_back(new osg::MatrixfValueObject("matrix",osg::Matrixf())); osg::ref_ptr<osg::MatrixdValueObject> svo = new osg::MatrixdValueObject("return", osg::Matrixd()); outputParameters.push_back(svo.get()); if (luaScriptEngine->run(script.get(), "test", inputParameters, outputParameters)) { OSG_NOTICE<<"Successfully ran script : return value = "<<svo->getValue()<<std::endl; } else { OSG_NOTICE<<"script run failed"<<std::endl; } } } } osg::ref_ptr<osg::Object> obj = pi.createObject("osgVolume::VolumeTile"); if (obj.valid()) { OSG_NOTICE<<"obj created "<<obj->getCompoundClassName()<<std::endl; } else { OSG_NOTICE<<"obj creation failed "<<std::endl; } osgDB::ClassInterface::PropertyMap properties; if (pi.getSupportedProperties(obj.get(), properties, true)) { OSG_NOTICE<<"Have supported properites found."<<std::endl; for(osgDB::ClassInterface::PropertyMap::iterator itr = properties.begin(); itr != properties.end(); ++itr) { OSG_NOTICE<<" Property "<<itr->first<<", "<<pi.getTypeName(itr->second)<<std::endl; } } else { OSG_NOTICE<<"No supported properites found."<<std::endl; } //return 0; return viewer.run(); #endif }
void llvm_codegen_visit_binary_expr (struct _Visitor *visitor, struct AstNode *node) { int lindex = -1; int rindex = -1; struct AstNode *lnode = node->children; struct AstNode *op = lnode->sibling; struct AstNode *rnode = op->sibling; int __process_binexpr_node(struct AstNode *node) { if (node->kind == IDENTIFIER) { if (node->symbol->is_global) { if (symbol_is_procfunc(node->symbol)) return node->symbol->stack_index; _print_load(node, visitor); return stack_size; } } else if (!IS_LITERAL(node->kind)) { ast_node_accept(node, visitor); return stack_size; } return -1; } void __print_operand(struct AstNode *node, int index) { if (index > -1) printf("%%%d", index); else if (node->symbol != NULL && symbol_is_procfunc(node->symbol)) printf("0"); else ast_node_accept(node, visitor); } /* Construcao mais simples */ if (IS_LITERAL(lnode->kind) && IS_LITERAL(rnode->kind)) { ast_node_accept(op, visitor); printf(" "); PRINT_TYPE(lnode->type); printf(" "); ast_node_accept(lnode, visitor); printf(", "); ast_node_accept(rnode, visitor); printf("\n"); /* Construcoes complexas */ } else { lindex = __process_binexpr_node(lnode); rindex = __process_binexpr_node(rnode); ast_node_accept(op, visitor); printf(" "); PRINT_TYPE(lnode->type); printf(" "); __print_operand(lnode, lindex); printf(", "); __print_operand(rnode, rindex); printf("\n"); } stack_size++; }