CoolFace
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes838downloads
AsmLib.txt177 linesDownload Raw Back to Compiler
1 2U0 AOTStoreCodeU8(CCmpCtrl *cc,U8 b)3{4  CAOTCtrl *aotc=cc->aotc;5  I64 i=aotc->rip>>AOT_BIN_BLK_BITS;6  CAOTBinBlk *tmpbin=aotc->bin;7  while (i--)8    if (!(tmpbin=tmpbin->next)) {9      i=aotc->rip>>AOT_BIN_BLK_BITS+1;10      tmpbin=&aotc->bin;11      while (i--) {12        if (!tmpbin->next)13          tmpbin->next=CAlloc(sizeof(CAOTBinBlk));14        tmpbin=tmpbin->next;15      }16      break;17    }18  tmpbin->body[aotc->rip++ & (AOT_BIN_BLK_SIZE-1)]=b;19  if (aotc->lst) {20    if (aotc->lst_col>=24) {21      '\n';22      aotc->lst_col=0;23    }24    "%02X ",b;25    aotc->lst_col+=3;26  }27  if (aotc->rip>aotc->num_bin_U8s)28    aotc->num_bin_U8s=aotc->rip;29}30 31U0 AOTStoreCodeU32(CCmpCtrl *cc,U32 d)32{33  CAOTCtrl *aotc=cc->aotc;34  I64 i=aotc->rip>>AOT_BIN_BLK_BITS,j=(aotc->rip+sizeof(U32))>>AOT_BIN_BLK_BITS;35  U32 *_d;36  CAOTBinBlk *tmpbin;37  if (i!=j)38    for (i=0;i<sizeof(U32);i++)39      AOTStoreCodeU8(cc,d.u8[i]);40  else {41    tmpbin=aotc->bin;42    while (i--)43      if (!(tmpbin=tmpbin->next)) {44        i=aotc->rip>>AOT_BIN_BLK_BITS+1;45        tmpbin=&aotc->bin;46        while (i--) {47          if (!tmpbin->next)48            tmpbin->next=CAlloc(sizeof(CAOTBinBlk));49          tmpbin=tmpbin->next;50        }51        break;52      }53    _d=tmpbin->body+ aotc->rip&(AOT_BIN_BLK_SIZE-1);54    *_d=d;55    aotc->rip+=sizeof(U32);56    if (aotc->lst) {57      if (aotc->lst_col>=24) {58        '\n';59        aotc->lst_col=0;60      }61      "%08X ",d;62      aotc->lst_col+=9;63    }64    if (aotc->rip>aotc->num_bin_U8s)65      aotc->num_bin_U8s=aotc->rip;66  }67}68 69U0 AOTStoreCodeU64(CCmpCtrl *cc,U64 q)70{71  CAOTCtrl *aotc=cc->aotc;72  I64   i=aotc->rip>>AOT_BIN_BLK_BITS,73        j=(aotc->rip+sizeof(I64))>>AOT_BIN_BLK_BITS, *_q;74  CAOTBinBlk *tmpbin;75  if (i!=j)76    for (i=0;i<sizeof(I64);i++)77      AOTStoreCodeU8(cc,q.u8[i]);78  else {79    tmpbin=aotc->bin;80    while (i--)81      if (!(tmpbin=tmpbin->next)) {82        i=aotc->rip>>AOT_BIN_BLK_BITS+1;83        tmpbin=&aotc->bin;84        while (i--) {85          if (!tmpbin->next)86            tmpbin->next=CAlloc(sizeof(CAOTBinBlk));87          tmpbin=tmpbin->next;88        }89        break;90      }91    _q=tmpbin->body+ aotc->rip&(AOT_BIN_BLK_SIZE-1);92    *_q=q;93    aotc->rip+=sizeof(I64);94    if (aotc->lst) {95      if (aotc->lst_col>=24) {96        '\n';97        aotc->lst_col=0;98      }99      "%016X ",q;100      aotc->lst_col+=17;101    }102    if (aotc->rip>aotc->num_bin_U8s)103      aotc->num_bin_U8s=aotc->rip;104  }105}106 107U0 AOTStoreCodeU8At(CCmpCtrl *cc,I64 rip,...)108{109  CAOTCtrl *aotc=cc->aotc;110  CAOTBinBlk *tmpbin;111  I64 i,j;112  for (j=0;j<argc;j++) {113    i=rip>>AOT_BIN_BLK_BITS+1;114    tmpbin=&aotc->bin;115    while (i--) {116      if (!tmpbin->next) {117        tmpbin->next=CAlloc(sizeof(CAOTBinBlk));118        tmpbin->next->next=NULL;119      }120      tmpbin=tmpbin->next;121    }122    tmpbin->body[rip++ & (AOT_BIN_BLK_SIZE-1)]=argv[j];123  }124  if (rip>aotc->num_bin_U8s)125    aotc->num_bin_U8s=rip;126}127 128I64 AsmLexExpression(CCmpCtrl *cc)129{130  U8 *machine_code;131  I64 res=0;132  cc->asm_undef_hash=NULL;133  cc->flags&=~(CCF_UNRESOLVED+CCF_LOCAL);134  cc->abs_cnts=0;135  if (!IsLexExpression2Bin(cc,&machine_code))136    LexSkipEol(cc);137  else {138    if (cc->abs_cnts.externs)139      LexExcept(cc,"Extern Not Allowed at ");140    if (cc->flags & CCF_UNRESOLVED)141      LexExcept(cc,"Undefined sym at ");142    res=Call(machine_code);143    Free(machine_code);144  }145  return res;146}147 148U0 AsmLineLst(CCmpCtrl *cc)149{150  CAOTCtrl *aotc=cc->aotc;151  CLexFile *tmpf=cc->lex_include_stk;152  CDocEntry *doc_e=tmpf->line_start,*doc_e2;153  if (aotc->lst && aotc->lst_last_lfn==tmpf && doc_e) {154    if (doc_e2=aotc->lst_last_line) {155      if (tmpf->flags& LFSF_DOC) {156        while (doc_e2->y<doc_e->y) {157          "%h*c%08X ",24-aotc->lst_col,CH_SPACE,aotc->lst_last_rip;158          aotc->lst_col=0;159          doc_e2=LexPutLine(cc,doc_e2);160        }161      } else {162        while (*doc_e2(U8 *) && doc_e2!=doc_e) {163          "%h*c%08X ",24-aotc->lst_col,CH_SPACE,aotc->lst_last_rip;164          aotc->lst_col=0;165          doc_e2=LexPutLine(cc,doc_e2);166        }167      }168      aotc->lst_last_line=doc_e2;169    } else170      aotc->lst_last_line=doc_e;171  } else {172    aotc->lst_last_line=NULL;173    aotc->lst_last_lfn=tmpf;174  }175  aotc->lst_last_rip=aotc->rip;176}177