static int init_trace_packet_header(struct bt_ctf_trace *trace) { int ret = 0; struct bt_ctf_field *magic = NULL, *uuid_array = NULL; struct bt_ctf_field_type *_uint32_t = get_field_type(FIELD_TYPE_ALIAS_UINT32_T); struct bt_ctf_field_type *_uint8_t = get_field_type(FIELD_TYPE_ALIAS_UINT8_T); struct bt_ctf_field_type *trace_packet_header_type = bt_ctf_field_type_structure_create(); struct bt_ctf_field_type *uuid_array_type = bt_ctf_field_type_array_create(_uint8_t, 16); if (!trace_packet_header_type || !uuid_array_type) { ret = -1; goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "magic"); if (ret) { goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, uuid_array_type, "uuid"); if (ret) { goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "stream_id"); if (ret) { goto end; } ret = bt_ctf_trace_set_packet_header_type(trace, trace_packet_header_type); if (ret) { goto end; } end: bt_put(uuid_array_type); bt_put(_uint32_t); bt_put(_uint8_t); bt_put(magic); bt_put(uuid_array); bt_put(trace_packet_header_type); return ret; }
static int bt_ctf_field_string_serialize(struct bt_ctf_field *field, struct ctf_stream_pos *pos) { size_t i; int ret = 0; struct bt_ctf_field_string *string = container_of(field, struct bt_ctf_field_string, parent); struct bt_ctf_field_type *character_type = get_field_type(FIELD_TYPE_ALIAS_UINT8_T); struct bt_ctf_field *character = bt_ctf_field_create(character_type); for (i = 0; i < string->payload->len + 1; i++) { ret = bt_ctf_field_unsigned_integer_set_value(character, (uint64_t) string->payload->str[i]); if (ret) { goto end; } ret = bt_ctf_field_integer_serialize(character, pos); if (ret) { goto end; } } end: bt_ctf_field_put(character); bt_ctf_field_type_put(character_type); return ret; }
tuple_type(type_id_t id, size_t size, const type *element_tp, bool variadic = false, uint32_t flags = type_flag_none) : base_type(id, 0, 1, flags | type_flag_indexable | (variadic ? type_flag_symbolic : 0), 0, 0, 0), m_field_count(size), m_field_types(size), m_arrmeta_offsets(size), m_variadic(variadic) { // Calculate the needed element alignment and arrmeta offsets size_t arrmeta_offset = get_field_count() * sizeof(size_t); this->m_data_alignment = 1; for (intptr_t i = 0; i < m_field_count; ++i) { m_field_types[i] = element_tp[i]; } for (intptr_t i = 0; i != m_field_count; ++i) { const type &ft = get_field_type(i); size_t field_alignment = ft.get_data_alignment(); // Accumulate the biggest field alignment as the type alignment if (field_alignment > this->m_data_alignment) { this->m_data_alignment = (uint8_t)field_alignment; } // Inherit any operand flags from the fields this->flags |= (ft.get_flags() & type_flags_operand_inherited); // Calculate the arrmeta offsets m_arrmeta_offsets[i] = arrmeta_offset; arrmeta_offset += ft.get_arrmeta_size(); } this->m_metadata_size = arrmeta_offset; }
void Class::printField() { for(int i=0;i<fields_count; i++) { printf("[%d] ", i); print_access(get_field_flags(i)); printf("%s:", get_field_name(i)); printf("%s\n", get_field_type(i)); } }
void flexible_type_registry::register_id_fields(flex_type_enum id_type) { if (!has_field("__id")) { register_field("__id", id_type); register_field("__src_id", id_type); register_field("__dst_id", id_type); } else { if (get_field_type("__id").second != id_type) { log_and_throw(std::string("ID field type mismatch")); } } }
void Class::putstatic(int index, u4 *in_data, u1 in_type) { u1 d_type; d_type = *( get_field_type(index) ); if(d_type != in_type) { printf("Error data type %c != %c: class.pustatic\n",d_type,in_type); exit(0); } if(static_fields_index[index] == -1) { printf("Error index value %d: class.pustatic\n" ,(short)static_fields_index[index]); exit(0); } static_fields[ static_fields_index[index] ] = in_data[0]; if( (d_type == TYPE_LONG) || (d_type == TYPE_DOUBLE) ) static_fields[ static_fields_index[index]+1 ] = in_data[1]; }
void Class::getstatic(int index, u4 *out_data, u1 out_type) { u1 d_type; d_type = *( get_field_type(index) ); if(d_type != out_type) { printf("Error data type %c != %c: class.gettatic\n",d_type,out_type); exit(0); } if(static_fields_index[index] == -1) { printf("Error index value %d: class.gettatic\n" ,(short)static_fields_index[index]); exit(0); } out_data[0] = static_fields[ static_fields_index[index] ]; if( (d_type == TYPE_LONG) || (d_type == TYPE_DOUBLE) ) out_data[1] = static_fields[ static_fields_index[index]+1 ]; }
void Class::print_statics() { //printf("Static Fields\n"); printf(" statics: %d\n", static_fields_count); printf(" "); for(u2 i=0;i<fields_count; i++) { if(static_fields_index[i] != -1) { printf("[%d] ",static_fields_index[i]); u1 d_type; d_type = *( get_field_type(i) ); printf("(%c)",d_type); printf("%08X ", static_fields[ static_fields_index[i] ]); if( (d_type == TYPE_LONG) || (d_type == TYPE_DOUBLE) ) { printf("[%d] ",static_fields_index[i]+1); printf("(%c)",d_type); printf("%08X ", static_fields[ static_fields_index[i]+1 ]); } } } printf("\n"); }
static int init_trace_packet_header(struct bt_ctf_writer *writer) { size_t i; int ret = 0; struct bt_ctf_field *trace_packet_header = NULL, *magic = NULL, *uuid_array = NULL; struct bt_ctf_field_type *_uint32_t = get_field_type(FIELD_TYPE_ALIAS_UINT32_T); struct bt_ctf_field_type *_uint8_t = get_field_type(FIELD_TYPE_ALIAS_UINT8_T); struct bt_ctf_field_type *trace_packet_header_type = bt_ctf_field_type_structure_create(); struct bt_ctf_field_type *uuid_array_type = bt_ctf_field_type_array_create(_uint8_t, 16); if (!trace_packet_header_type || !uuid_array_type) { ret = -1; goto end; } ret = bt_ctf_field_type_set_byte_order(_uint32_t, (writer->byte_order == LITTLE_ENDIAN ? BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN)); if (ret) { goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "magic"); if (ret) { goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, uuid_array_type, "uuid"); if (ret) { goto end; } ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "stream_id"); if (ret) { goto end; } trace_packet_header = bt_ctf_field_create(trace_packet_header_type); if (!trace_packet_header) { ret = -1; goto end; } magic = bt_ctf_field_structure_get_field(trace_packet_header, "magic"); ret = bt_ctf_field_unsigned_integer_set_value(magic, 0xC1FC1FC1); if (ret) { goto end; } uuid_array = bt_ctf_field_structure_get_field(trace_packet_header, "uuid"); for (i = 0; i < 16; i++) { struct bt_ctf_field *uuid_element = bt_ctf_field_array_get_field(uuid_array, i); ret = bt_ctf_field_unsigned_integer_set_value(uuid_element, writer->uuid[i]); bt_ctf_field_put(uuid_element); if (ret) { goto end; } } bt_ctf_field_type_put(writer->trace_packet_header_type); bt_ctf_field_put(writer->trace_packet_header); writer->trace_packet_header_type = trace_packet_header_type; writer->trace_packet_header = trace_packet_header; end: bt_ctf_field_type_put(uuid_array_type); bt_ctf_field_type_put(_uint32_t); bt_ctf_field_type_put(_uint8_t); bt_ctf_field_put(magic); bt_ctf_field_put(uuid_array); if (ret) { bt_ctf_field_type_put(trace_packet_header_type); bt_ctf_field_put(trace_packet_header); } return ret; }
/*=== parse_field =========================================================== * <Description Text> * * Assumes: ? * * Returns: (value) when X * (value) when Y * * Modifies: ? * * Calls: nothing * * Called By: ? * * History: MM/DD/YY MRH Created initial version based on function * 'func()' in motif/csr/file.c */ static PARSE_TABLE_TYPE parse_field(FILE *file, char *field_name, FIELD_TYPE *field_type, int *field_length, char *null_allowable) { char type_string[80]; char nullable[80]; char comment1[80]; char comment2[80]; char line[256]; char *p; int space_only; int num_args; fgets(line, sizeof(line), file); num_args = sscanf(line, "%s %s %s %s %s", field_name, type_string, nullable, comment1, comment2); if (num_args >= 2 && is_comment(field_name)) return TABLE_COMMENT; if (num_args == 1 && strchr(field_name, ')')) return TABLE_END; space_only = 1; for (p = &(line[0]); p < &(line[strlen(line)]); p++) if (*p != ' ' && *p != '\n') space_only = 0; if (space_only) return TABLE_COMMENT; if (num_args < 2) { fprintf(stderr, "Unable to scan line (args = %d) : '%s'.", num_args, line); return TABLE_PARSE_ERROR; } /* * OK - we have a valid field line. Get the type and length; * determine if it is null-allowable. */ *field_type = get_field_type(type_string); if (*field_type == FIELD_STRING_TYPE) *field_length = find_array_length(type_string); else *field_length = type_length[*field_type]; *null_allowable = is_nullable(nullable, comment1); /* * Finally, determine if the line contains a closing table parenthesis. * This is a bit tricky, since there may be pairs that we want to ignore. */ if (is_table_end(line)) return TABLE_DONE; return TABLE_OK; }