BOOST_AUTO_TEST_CASE_TEMPLATE (test_map_move_constructor_1, parameters, test_map_parameters) { COMMON_MAP_TEST_SETUP; map_type map (std::move (map_type (RANGE (value_data::values1 ())))); BOOST_CHECK_EQUAL (map, map_type (RANGE (value_data::values1 ()))); }
static std::vector<char> create_npy_header(const cnpy::Type dtype, const size_t elementSize, const std::vector<size_t>& shape) { size_t ndims = shape.size(); std::string dict; dict += "{'descr': '"; dict += BigEndianTest(); dict += map_type(dtype); dict += tostring(elementSize); dict += "', 'fortran_order': False, 'shape': ("; dict += tostring(shape[0]); for(int i=1; i<ndims; i++) dict += ", " + tostring(shape[i]); if(ndims == 1) dict += ","; dict += "), }"; //pad with spaces so that preamble+dict is modulo 16 bytes. preamble is 10 bytes. dict needs to end with \n int remainder = 16 - (10 + dict.size()) % 16; //dict.insert(dict.end(), remainder, ' '); for(int i=0; i<remainder-1; ++i) dict += ' '; dict += '\n'; NpHeader header; header.dictSize = dict.size(); std::vector<char> bytes; bytes.resize(sizeof(NpHeader) + dict.size()); std::memcpy(bytes.data(), &header, sizeof(NpHeader)); std::memcpy(bytes.data()+sizeof(NpHeader), dict.data(), dict.size()); return bytes; }
ERROR_CODE _bencoding_dictionary_start_callback(struct bencoding_engine_t *bencoding_engine) { /* allocates space for the hash map and for the type structure that will encapsulate it */ struct hash_map_t *hash_map; struct sort_map_t *sort_map; struct type_t *type; /* retrieves the bencoding handler from the template engine context then uses it to store the (current) value */ struct bencoding_handler_t *bencoding_handler = (struct bencoding_handler_t *) bencoding_engine->context; /* switchs over the "target" map type to be used to store conceptual maps in the bencoding structure */ switch(bencoding_engine->map_type) { case MAP_TYPE: /* creates a new hash map for the new structure (sequence) context and then creates the respective type for the map */ create_hash_map(&hash_map, 0); create_type(&type, MAP_TYPE); *type = map_type(hash_map); case SORT_MAP_TYPE: /* creates a new sort map for the new structure (sequence) context and then creates the respective type for the map */ create_sort_map(&sort_map, 0); create_type(&type, SORT_MAP_TYPE); *type = sort_map_type(sort_map); default: /* creates a new sort map for the new structure (sequence) context and then creates the respective type for the map */ create_sort_map(&sort_map, 0); create_type(&type, SORT_MAP_TYPE); *type = sort_map_type(sort_map); } /* adds the sequence type to the sequence stack and then adds the current handler key to the key stack, then updates the current sequence reference and the current key in the handler */ append_value_linked_list(bencoding_handler->sequence_stack, (void *) type); append_value_linked_list(bencoding_handler->key_stack, (void *) bencoding_handler->key); bencoding_handler->sequence = type; bencoding_handler->key = NULL; /* in case there is no top type defined for the handler sets the current type as the top type (base type) */ if(bencoding_handler->top == NULL) { bencoding_handler->top = type; } /* sets the next key flag so that in the next iteration the string is "accepted" as the current key value */ bencoding_handler->next_key = 1; /* raises no error */ RAISE_NO_ERROR; }
static inline int is_compatible(struct tcf_meta_val *what, struct tcf_meta_val *needed) { char *p; struct meta_entry *entry; entry = lookup_meta_entry_byid(TCF_META_ID(what->kind)); if (entry == NULL) return 0; for (p = entry->mask; p; p++) if (map_type(*p) == TCF_META_TYPE(needed->kind)) return 1; return 0; }
static void list_meta_ids(FILE *fd) { int i; fprintf(fd, "--------------------------------------------------------\n" \ " ID Type Description\n" \ "--------------------------------------------------------"); for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++) { if (meta_table[i].id == TCF_META_ID_SECTION) { fprintf(fd, "\n%s:\n", meta_table[i].kind); } else { char *p = meta_table[i].mask; char buf[64] = {0}; fprintf(fd, " %-16s ", meta_table[i].kind); while (*p) { int type = map_type(*p); switch (type) { case TCF_META_TYPE_INT: strcat(buf, "INT"); break; case TCF_META_TYPE_VAR: strcat(buf, "VAR"); break; } if (*(++p)) strcat(buf, ","); } fprintf(fd, "%-10s %s\n", buf, meta_table[i].desc); } } fprintf(fd, "--------------------------------------------------------\n"); }
int main() { map_type(); map_select(); return 0; }
int parse_i2c_devs(const struct HDIF_common_hdr *hdr, int idata_index, struct dt_node *xscom) { struct dt_node *i2cm, *bus, *node; const struct hdat_i2c_type *type; const struct hdat_i2c_info *info; const struct i2c_dev *dev; const char *name, *compat; const struct host_i2c_hdr *ahdr; uint32_t dev_addr; uint32_t version; uint32_t size; uint32_t purpose; int i, count; /* * This code makes a few assumptions about XSCOM addrs, etc * and will need updating for new processors */ assert(proc_gen == proc_gen_p9); /* * Emit an error if we get a newer version. This is an interim measure * until the new version format is finalised. */ ahdr = HDIF_get_idata(hdr, idata_index, &size); if (!ahdr || !size) return -1; /* * Some hostboots don't correctly fill the version field. On these * the offset from the start of the header to the start of the array * is 16 bytes. */ if (be32_to_cpu(ahdr->hdr.offset) == 16) { version = 1; prerror("I2C: HDAT device array has no version! Assuming v1\n"); } else { version = be32_to_cpu(ahdr->version); } if (version == 2) { prlog(PR_INFO, "I2C: v%d found, but not supported. Parsing as v1\n", version); } else if (version > 2) { prerror("I2C: v%d found, but not supported! THIS IS A BUG\n", version); return -1; } count = HDIF_get_iarray_size(hdr, idata_index); for (i = 0; i < count; i++) { dev = HDIF_get_iarray_item(hdr, idata_index, i, &size); /* * XXX: Some broken hostboots populate i2c devs with zeros. * Workaround them for now. */ if (is_zeros(dev, size)) { prerror("I2C: Ignoring broken i2c dev %d\n", i); continue; } /* * On some systems the CFAM I2C master is represented in the * host I2C table as engine 6. There are only 4 (0, 1, 2, 3) * engines accessible to the host via XSCOM so filter out * engines outside this range so we don't create bogus * i2cm@<addr> nodes. */ if (dev->i2cm_engine >= 4 && proc_gen == proc_gen_p9) continue; i2cm = get_i2cm_node(xscom, dev->i2cm_engine); bus = get_bus_node(i2cm, dev->i2cm_port, be16_to_cpu(dev->i2c_bus_freq)); /* * Looks like hostboot gives the address as an 8 bit, left * justified quantity (i.e it includes the R/W bit). So we need * to strip it off to get an address linux can use. */ dev_addr = dev->dev_addr >> 1; purpose = be32_to_cpu(dev->purpose); type = map_type(dev->type); info = get_info(purpose); /* HACK: Hostboot doesn't export the correct type information * for the DIMM SPD EEPROMs. This is a problem because SPD * EEPROMs have a different wire protocol to the atmel,24XXXX * series. The main difference being that SPD EEPROMs have an * 8bit offset rather than a 16bit offset. This means that the * driver will send 2 bytes when doing a random read, * potentially overwriting part of the SPD information. * * Just to make things interested the FSP also gets the device * type wrong. To work around both just set the device-type to * "spd" for anything in the 0x50 to 0x57 range since that's the * SPD eeprom range. * * XXX: Future chips might not use engine 3 for the DIMM buses. */ if (dev->i2cm_engine == 3 && dev_addr >= 0x50 && dev_addr < 0x58) { compat = "spd"; name = "eeprom"; } else if (type) { compat = type->compat; name = type->name; } else { name = "unknown"; compat = NULL; } /* * An i2c device is unknown if either the i2c device list is * outdated or the device is marked as unknown (0xFF) in the * hdat. Log both cases to see what/where/why. */ if (!type || dev->type == 0xFF) { prlog(PR_NOTICE, "HDAT I2C: found e%dp%d - %s@%x dp:%02x (%#x:%s)\n", dev->i2cm_engine, dev->i2cm_port, name, dev_addr, dev->dev_port, purpose, info->label); continue; } prlog(PR_DEBUG, "HDAT I2C: found e%dp%d - %s@%x dp:%02x (%#x:%s)\n", dev->i2cm_engine, dev->i2cm_port, name, dev_addr, dev->dev_port, purpose, info->label); /* * Multi-port device require special handling since we need to * generate the device-specific DT bindings. For now we're just * going to ignore them since these devices are owned by FW * any way. */ if (dev->dev_port != 0xff) continue; node = dt_new_addr(bus, name, dev_addr); if (!node) continue; dt_add_property_cells(node, "reg", dev_addr); dt_add_property_cells(node, "link-id", be32_to_cpu(dev->i2c_link)); if (compat) dt_add_property_string(node, "compatible", compat); if (info->label) dt_add_property_string(node, "label", info->label); if (!info->whitelist) dt_add_property_string(node, "status", "reserved"); /* * Set a default timeout of 2s on the ports with a TPM. This is * to work around a bug with certain TPM firmwares that can * clock stretch for long periods of time and will lock up * until they are power cycled if a STOP condition is sent * during this period. */ if (dev->type == 0x3) dt_add_property_cells(bus, "timeout-ms", 2000); /* XXX: SLCA index? */ } return 0; }
int map_select() // 맵 선택 { int menu=0,key; map_type(); while(1) { if(kbhit()) { key = getch(); if(key == P1_LEFT ||key == P2_LEFT) { menu = menu? menu-1 : 2; } else if(key == P1_RIGHT || key == P2_RIGHT) { menu = (menu + 1) % 3; } else if(key == SPACE || key == ENTER) { return menu + 1; } if(menu == 0) { gotoxy(33,26); printf(" "); gotoxy(43,26); printf(" "); gotoxy(23,26); printf("◈"); gotoxy(41,26); printf(" "); gotoxy(51,26); printf(" "); gotoxy(31,26); printf("◈"); } else if(menu == 1) { gotoxy(23,26); printf(" "); gotoxy(43,26); printf(" "); gotoxy(33,26); printf("◈"); gotoxy(31,26); printf(" "); gotoxy(51,26); printf(" "); gotoxy(41,26); printf("◈"); } else if(menu == 2) { gotoxy(23,26); printf(" "); gotoxy(33,26); printf(" "); gotoxy(43,26); printf("◈"); gotoxy(31,26); printf(" "); gotoxy(41,26); printf(" "); gotoxy(51,26); printf("◈"); } } } }
// This functions saves all the 'projection-worthy' system vectors for // future use void MemorySolutionHistory::store() { this->find_stored_entry(); // In an empty history we create the first entry if (stored_solutions.begin() == stored_solutions.end()) { stored_solutions.push_back(std::make_pair(_system.time, map_type())); stored_sols = stored_solutions.begin(); } // If we're past the end we can create a new entry if (_system.time - stored_sols->first > TOLERANCE ) { #ifndef NDEBUG ++stored_sols; libmesh_assert (stored_sols == stored_solutions.end()); #endif stored_solutions.push_back(std::make_pair(_system.time, map_type())); stored_sols = stored_solutions.end(); --stored_sols; } // If we're before the beginning we can create a new entry else if (stored_sols->first - _system.time > TOLERANCE) { libmesh_assert (stored_sols == stored_solutions.begin()); stored_solutions.push_front(std::make_pair(_system.time, map_type())); stored_sols = stored_solutions.begin(); } // We don't support inserting entries elsewhere libmesh_assert(std::abs(stored_sols->first - _system.time) < TOLERANCE); // Map of stored vectors for this solution step std::map<std::string, std::unique_ptr<NumericVector<Number>>> & saved_vectors = stored_sols->second; // Loop over all the system vectors for (System::vectors_iterator vec = _system.vectors_begin(); vec != _system.vectors_end(); ++vec) { // The name of this vector const std::string & vec_name = vec->first; // If we haven't seen this vector before or if we have and // want to overwrite it if ((overwrite_previously_stored || !saved_vectors.count(vec_name)) && // and if we think it's worth preserving _system.vector_preservation(vec_name)) { // Then we save it. saved_vectors[vec_name] = vec->second->clone(); } } // Of course, we will usually save the actual solution std::string _solution("_solution"); if ((overwrite_previously_stored || !saved_vectors.count(_solution)) && // and if we think it's worth preserving _system.project_solution_on_reinit()) saved_vectors[_solution] = _system.solution->clone(); }
nodes_info_t(type_t type = type_t::none) : type(map_type(type)), nodes("_all") {}
static inline struct bstr * parse_object(struct bstr *args, struct bstr *arg, struct tcf_meta_val *obj, unsigned long *dst, struct tcf_meta_val *left) { struct meta_entry *entry; unsigned long num; struct bstr *a; if (arg->quoted) { obj->kind = TCF_META_TYPE_VAR << 12; obj->kind |= TCF_META_ID_VALUE; *dst = (unsigned long) arg; return bstr_next(arg); } num = bstrtoul(arg); if (num != ULONG_MAX) { obj->kind = TCF_META_TYPE_INT << 12; obj->kind |= TCF_META_ID_VALUE; *dst = (unsigned long) num; return bstr_next(arg); } entry = lookup_meta_entry(arg); if (entry == NULL) { PARSE_ERR(arg, "meta: unknown meta id\n"); return PARSE_FAILURE; } obj->kind = entry->id | (map_type(entry->mask[0]) << 12); if (left) { struct tcf_meta_val *right = obj; if (TCF_META_TYPE(right->kind) == TCF_META_TYPE(left->kind)) goto compatible; if (can_adopt(left) && !can_adopt(right)) { if (is_compatible(left, right)) left->kind = overwrite_type(left, right); else goto not_compatible; } else if (can_adopt(right) && !can_adopt(left)) { if (is_compatible(right, left)) right->kind = overwrite_type(right, left); else goto not_compatible; } else if (can_adopt(left) && can_adopt(right)) { if (is_compatible(left, right)) left->kind = overwrite_type(left, right); else if (is_compatible(right, left)) right->kind = overwrite_type(right, left); else goto not_compatible; } else goto not_compatible; } compatible: a = bstr_next(arg); while(a) { if (!bstrcmp(a, "shift")) { unsigned long shift; if (a->next == NULL) { PARSE_ERR(a, "meta: missing argument"); return PARSE_FAILURE; } a = bstr_next(a); shift = bstrtoul(a); if (shift == ULONG_MAX) { PARSE_ERR(a, "meta: invalid shift, must " \ "be numeric"); return PARSE_FAILURE; } obj->shift = (__u8) shift; a = bstr_next(a); } else if (!bstrcmp(a, "mask")) { unsigned long mask; if (a->next == NULL) { PARSE_ERR(a, "meta: missing argument"); return PARSE_FAILURE; } a = bstr_next(a); mask = bstrtoul(a); if (mask == ULONG_MAX) { PARSE_ERR(a, "meta: invalid mask, must be " \ "numeric"); return PARSE_FAILURE; } *dst = (unsigned long) mask; a = bstr_next(a); } else break; } return a; not_compatible: PARSE_ERR(arg, "lvalue and rvalue are not compatible."); return PARSE_FAILURE; }
map_t map_add(gpt_t gpt, off_t start, off_t size, int type, void *data, int alloc) { map_t m, n, p; #ifdef DEBUG printf("add: %s %#jx %#jx\n", map_type(type), (uintmax_t)start, (uintmax_t)size); for (n = gpt->mediamap; n; n = n->map_next) printf("have: %s %#jx %#jx\n", map_type(n->map_type), (uintmax_t)n->map_start, (uintmax_t)n->map_size); #endif n = gpt->mediamap; while (n != NULL && n->map_start + n->map_size <= start) n = n->map_next; if (n == NULL) { if (!(gpt->flags & GPT_QUIET)) gpt_warnx(gpt, "Can't find map"); return NULL; } if (n->map_start + n->map_size < start + size) { if (!(gpt->flags & GPT_QUIET)) gpt_warnx(gpt, "map entry doesn't fit media"); return NULL; } if (n->map_start == start && n->map_size == size) { if (n->map_type != MAP_TYPE_UNUSED) { if (n->map_type != MAP_TYPE_MBR_PART || type != MAP_TYPE_GPT_PART) { if (!(gpt->flags & GPT_QUIET)) gpt_warnx(gpt, "partition(%ju,%ju) mirrored", (uintmax_t)start, (uintmax_t)size); } } n->map_type = type; n->map_data = data; n->map_alloc = alloc; return n; } if (n->map_type != MAP_TYPE_UNUSED) { if (n->map_type != MAP_TYPE_MBR_PART || type != MAP_TYPE_GPT_PART) { gpt_warnx(gpt, "bogus map current=%s new=%s", map_type(n->map_type), map_type(type)); return NULL; } n->map_type = MAP_TYPE_UNUSED; } m = map_create(start, size, type); if (m == NULL) goto oomem; m->map_data = data; m->map_alloc = alloc; if (start == n->map_start) { m->map_prev = n->map_prev; m->map_next = n; if (m->map_prev != NULL) m->map_prev->map_next = m; else gpt->mediamap = m; n->map_prev = m; n->map_start += size; n->map_size -= size; } else if (start + size == n->map_start + n->map_size) { p = n; m->map_next = p->map_next; m->map_prev = p; if (m->map_next != NULL) m->map_next->map_prev = m; p->map_next = m; p->map_size -= size; } else { p = map_create(n->map_start, start - n->map_start, n->map_type); if (p == NULL) goto oomem; n->map_start += p->map_size + m->map_size; n->map_size -= (p->map_size + m->map_size); p->map_prev = n->map_prev; m->map_prev = p; n->map_prev = m; m->map_next = n; p->map_next = m; if (p->map_prev != NULL) p->map_prev->map_next = p; else gpt->mediamap = p; } return m; oomem: map_destroy(m); gpt_warn(gpt, "Can't create map"); return NULL; }
int map_struct(ctf_type type, void* _arg) { ctf_member target_member; ctf_struct_union target_su; ctf_struct_union local_su; size_t local_su_size; ctf_member local_member; char* local_member_name; struct m_elem* member_runner; int find_status; struct map_arg member_arg; struct map_arg* arg; char* member_addr; (void)type; printf(" Mapping a struct\n"); arg = _arg; local_su_size = size_type(arg->local_type); ctf_struct_union_init(arg->local_type, &local_su); ctf_struct_union_init(arg->target_type, &target_su); /* arg->output = malloc(local_su_size); */ /* printf("Allocated %u bytes at address %p for 'struct %s'\n", local_su_size, arg->output, local_su->name); */ m_list_first(&local_su->members, &member_runner); while (member_runner != NULL) { m_elem_data(member_runner, (void**)&local_member); ctf_member_get_name(local_member, &local_member_name); printf("Examining member '%s' ... ", local_member_name); find_status = m_list_find(&target_su->members, compare_member_name, local_member_name, (void**)&target_member); if (find_status == M_LIST_OK) { printf("pairing exists\n"); member_arg.target_type = target_member->type; member_arg.local_type = local_member->type; member_arg.t = arg->t; member_arg.pointer_db = arg->pointer_db; member_arg.addr = arg->addr + (target_member->offset/8); member_addr = (char*)(*arg->output); printf("member_addr = %p\n", member_addr); member_addr += local_member->offset/8; printf("member_addr = %p\n", member_addr); member_arg.output = (void**)&member_addr; map_type(&member_arg); } else printf("No '%s' member in target!\n", local_member_name); m_elem_next(member_runner, &member_runner); } return CTF_OK; }
int map_array(ctf_type type, void* _arg) { struct map_arg* in_arg; struct map_arg out_arg; ctf_array_length idx; char* output_addr; ctf_array local_array; ctf_type local_array_type; ctf_array_length local_array_length; size_t local_array_type_size; ctf_array target_array; ctf_type target_array_type; ctf_array_length target_array_length; size_t target_array_type_size; (void)type; in_arg = _arg; printf("Mapping an array!\n"); ctf_array_init(in_arg->local_type, &local_array); ctf_array_init(in_arg->target_type, &target_array); ctf_array_get_length(local_array, &local_array_length); ctf_array_get_length(target_array, &target_array_length); if (local_array_length != target_array_length) { printf("Different array lengths!\n"); return 1; } ctf_array_get_content_type(local_array, &local_array_type); ctf_array_get_content_type(target_array, &target_array_type); local_array_type_size = size_type(local_array_type); target_array_type_size = size_type(target_array_type); out_arg.local_type = local_array_type; out_arg.target_type = target_array_type; out_arg.addr = in_arg->addr; out_arg.output = in_arg->output; out_arg.t = in_arg->t; out_arg.pointer_db = in_arg->pointer_db; for (idx = 0; idx < local_array_length; idx++) { printf("Array idx %d\n", idx); map_type(&out_arg); out_arg.addr += target_array_type_size; output_addr = (char*)(*out_arg.output); output_addr += local_array_type_size; out_arg.output = (void**)&output_addr; } return CTF_OK; /* get the local array length get the target array length compare lengths return error if not the same local array memory is already allocated for element in array.elements: map_type if (map_type) failed return failure too increment address increment output */ }
const llvm::Type* to_arrayType(BasicType type) const { return map_type(_to_arrayType, type); }
const llvm::Type* to_stackType(BasicType type) const { return map_type(_to_stackType, type); }