int srec_read(FILE *pFile, unsigned char *buf, unsigned int start, unsigned int end) { fseek(pFile, 0, SEEK_SET); unsigned int chunk_len, chunk_addr, chunk_type, i, byte, line_no = 0, greatest_addr = 0; unsigned int number_of_records = 0; bool data_record = false; bool found_S5_rec = false; unsigned int expected_data_records = 0; unsigned int data_len = 0; unsigned char temp = ' '; while(fgets(line, sizeof(line), pFile)) { data_record = true; //Assume that the read data is a data record. Set to false if not. line_no++; // Reading chunk header if(sscanf(line, "S%01x%02x%08x", &chunk_type, &chunk_len, &chunk_addr) != 3) { sscanf(line, "%c",&temp); if(temp != 'S') { continue; } free(buf); ERROR2("Error while parsing SREC at line %d\n", line_no); } if(chunk_type == 0x00 || chunk_type == 0x04) //Header type record or reserved. Skip! { continue; } else if(chunk_type == 0x05) { //This will contain the total expected number of data records. Save for error checking later found_S5_rec = true; if (chunk_len != 3) { // Length field must contain a 3 to be a valid S5 record. ERROR2("Error while parsing S5 Record at line %d\n", line_no); } expected_data_records = chunk_addr; //The expected total number of data records is saved in S503<addr> field. } else if(is_data_type(chunk_type)) { chunk_addr = chunk_addr >> (8*(3-chunk_type)); data_len = chunk_len - chunk_type - 2; // See https://en.wikipedia.org/wiki/SREC_(file_format)#Record_types } else { continue; } // Reading chunk data for(i = 6 + 2*chunk_type; i < 2*data_len + 8; i +=2) { if(sscanf(&(line[i]), "%02x", &byte) != 1) { free(buf); ERROR2("Error while parsing SREC at line %d byte %d\n", line_no, i); } if(!is_data_type(chunk_type)) { // The only data records have to be processed data_record = false; continue; } if((i - 8) / 2 >= chunk_len) { // Respect chunk_len and do not capture checksum as data break; } if(chunk_addr < start) { free(buf); ERROR2("Address %08x is out of range at line %d\n", chunk_addr, line_no); } if(chunk_addr + data_len > end) { free(buf); ERROR2("Address %08x + %d is out of range at line %d\n", chunk_addr, data_len, line_no); } if(chunk_addr + data_len > greatest_addr) { greatest_addr = chunk_addr + data_len; } buf[chunk_addr - start + (i - 8) / 2] = byte; } if(data_record) { //We found a data record. Remember this. number_of_records++; } }
int check_entity(const ir_entity *entity) { bool fine = true; ir_linkage linkage = get_entity_linkage(entity); if (linkage & IR_LINKAGE_NO_CODEGEN) { if (!is_method_entity(entity)) { report_error("entity %+F has IR_LINKAGE_NO_CODEGEN but is not a function", entity); fine = false; } else if (get_entity_irg(entity) == NULL) { report_error("entity %+F has IR_LINKAGE_NO_CODEGEN but has no ir-graph anyway", entity); fine = false; } if (!is_externally_visible(entity)) { report_error("entity %+F has IR_LINKAGE_NO_CODEGEN but is not externally visible", entity); fine = false; } } check_external_linkage(entity, IR_LINKAGE_WEAK, "WEAK"); check_external_linkage(entity, IR_LINKAGE_GARBAGE_COLLECT, "GARBAGE_COLLECT"); check_external_linkage(entity, IR_LINKAGE_MERGE, "MERGE"); ir_type const *const type = get_entity_type(entity); ir_type const *const owner = get_entity_owner(entity); switch (get_entity_kind(entity)) { case IR_ENTITY_ALIAS: if (!is_segment_type(owner)) { report_error("alias entity %+F has non-segment owner %+F", entity, owner); fine = false; } break; case IR_ENTITY_NORMAL: { ir_initializer_t const *const init = get_entity_initializer(entity); if (init) fine &= check_initializer(init, type, entity); if (!is_data_type(type)) { report_error("normal entity %+F has non-data type %+F", entity, type); fine = false; } break; } case IR_ENTITY_COMPOUND_MEMBER: if (!is_compound_type(owner)) { report_error("compound member entity %+F has non-compound owner %+F", entity, owner); fine = false; } break; case IR_ENTITY_LABEL: if (type != get_code_type()) { report_error("label entity %+F has non-code type %+F", entity, type); fine = false; } break; case IR_ENTITY_METHOD: if (!is_Method_type(type)) { report_error("method entity %+F has non-method type %+F", entity, type); fine = false; } ir_graph *irg = get_entity_irg(entity); if (irg != NULL) { ir_entity *irg_entity = get_irg_entity(irg); if (irg_entity != entity) { report_error("entity(%+F)->irg->entity(%+F) relation invalid", entity, irg_entity); fine = false; } } break; case IR_ENTITY_PARAMETER: if (!is_frame_type(owner)) { report_error("parameter entity %+F has non-frame owner %+F", entity, owner); fine = false; } if (!is_data_type(type)) { report_error("parameter entity %+F has non-data type %+F", entity, type); fine = false; } break; case IR_ENTITY_UNKNOWN: break; case IR_ENTITY_SPILLSLOT: if (is_frame_type(owner)) { report_error("spillslot %+F must be on frame type", entity); fine = false; } break; } if (is_frame_type(owner) && entity_has_definition(entity)) { report_error("entity %+F on frame %+F has initialized", entity, owner); fine = false; } return fine; }