CoolFace
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes838downloads
CHash.txt143 linesDownload Raw Back to Compiler
1 2I64 HashEntrySize(CHashSrcSym *tmph)3{//Logical size of a std system hash entry.4  CDbgInfo *dbg_info;5  CBinFile *bfh;6  switch (HashTypeNum(tmph)) {7    case HTt_DEFINE_STR:8      return MSize(tmph(CHashDefineStr *)->data);9    case HTt_GLBL_VAR:10    case HTt_CLASS:11    case HTt_INTERNAL_TYPE:12      return tmph(CHashClass *)->size;13    case HTt_FUN:14      if (dbg_info=tmph->dbg_info)15        return dbg_info->body[dbg_info->max_line+1-dbg_info->min_line]16              -dbg_info->body[0];17      else18        return -1;19    case HTt_FILE:20      return MSize(tmph(CHashGeneric *)->user_data0);21    case HTt_MODULE:22      if (StrCmp(tmph->str,KERNEL_MODULE_NAME))23        return MSize(tmph(CHashGeneric *)->user_data0);24      else {25        bfh=mem_boot_base-sizeof(CBinFile);26        return bfh->file_size;27      }28    case HTt_WORD:29      return StrLen(tmph->str);30  }31  return -1;32}33 34I64 HashEntrySize2(CHashSrcSym *tmph)35{//Memory size of a std system hash entry.36  CDbgInfo *dbg_info;37  I64 res=MSize2(tmph);38  if (!(tmph->type&HTT_DICT_WORD))39    res+=MSize2(tmph->str);40  if (tmph->type & HTG_SRC_SYM) {41    res+=MSize2(tmph->src_link);42    res+=MSize2(tmph->idx);43    res+=MSize2(tmph->import_name);44    res+=LinkedLstSize(tmph->ie_lst);45    if (tmph->type & (HTT_FUN | HTT_EXPORT_SYS_SYM))46      res+=MSize2(tmph->dbg_info);47    if (tmph->type & HTT_CLASS)48      res+=MemberLstSize(tmph);49    else if (tmph->type & HTT_FUN) {50      res+=MemberLstSize(tmph);51      if (dbg_info=tmph->dbg_info)52//This should be MSize() but it would crash on AOT .BIN.Z file funs.53        res+=dbg_info->body[dbg_info->max_line+1-dbg_info->min_line]54              -dbg_info->body[0];55    } else if (tmph->type&HTT_DEFINE_STR)56      res+=MSize2(tmph(CHashDefineStr *)->data);57    else if (tmph->type & HTT_GLBL_VAR) {58      res+=LinkedLstSize(tmph(CHashGlblVar *)->dim.next);59      if (!(tmph(CHashGlblVar *)->flags&GVF_ALIAS))60        res+=MSize2(tmph(CHashGlblVar *)->data_addr);61      if (tmph(CHashGlblVar *)->fun_ptr)62        res+=HashEntrySize2(tmph(CHashGlblVar *)->fun_ptr63              -tmph(CHashGlblVar *)->fun_ptr->ptr_stars_cnt);64    }65  } else if (tmph->type & HTT_FILE)66    res+=MSize2(tmph(CHashGeneric *)->user_data0);67  else if (tmph->type & HTT_MODULE &&68        StrCmp(tmph->str,KERNEL_MODULE_NAME))69    res+=MSize2(tmph(CHashGeneric *)->user_data0);70  return res;71}72 73I64 HashTableSize2(CHashTable *table)74{//Memory size of std system hash table and all entries.75  I64 i,res=0;76  CHashSrcSym *tmph;77  if (!table)78    return 0;79  for (i=0;i<=table->mask;i++) {80    tmph=table->body[i];81    while (tmph) {82      res+=HashEntrySize2(tmph);83      tmph=tmph->next;84    }85  }86  res+=MSize2(table->body);87  res+=MSize2(table);88  return res;89}90 91U0 MapFileWrite(CHashTable *h,U8 *map_name,U8 drv_let)92{93  CHashSrcSym *tmph;94  I64 i,size;95  U8 *src_link;96  CDoc *doc;97  CDocBin *tmpb;98  CDbgInfo *dbg_info;99 100  doc=DocNew(map_name);101  doc->flags|=DOCF_NO_CURSOR;102  for (i=0;i<=h->mask;i++) {103    tmph=h->body[i];104    while (tmph) {105      if (tmph->src_link && !(tmph->type & (HTF_IMPORT | HTF_PRIVATE))) {106        src_link=StrNew(tmph->src_link);107        if (drv_let && StrLen(src_link)>=4)108          src_link[3]=drv_let;109        if (dbg_info=tmph->dbg_info) {110          size=offset(CDbgInfo.body)+111                sizeof(U32)*(dbg_info->max_line+2-dbg_info->min_line);112          if (size>MSize(dbg_info)) {113            "Corrupt Map Entry\n";114            dbg_info=NULL;115          } else {116            if (dbg_info->min_line<=dbg_info->max_line) {117              tmpb=CAlloc(sizeof(CDocBin));118              tmpb->size=size;119              tmpb->data=MAlloc(size);120              MemCpy(tmpb->data,dbg_info,size);121              tmpb->num=doc->cur_bin_num++;122              tmpb->use_cnt=1;123              QueIns(tmpb,doc->bin_head.last);124            } else125              dbg_info=NULL;126          }127        }128        if (dbg_info)129          DocPrint(doc,"$LK,\"%s\",A=\"%s\",BI=%d$\n",130                tmph->str,src_link,tmpb->num);131        else132          DocPrint(doc,"$LK,\"%s\",A=\"%s\"$\n",tmph->str,src_link);133 134        Free(src_link);135      }136      tmph=tmph->next;137    }138  }139  DocBinsValidate(doc);140  DocWrite(doc);141  DocDel(doc);142}143