hschumann2/TempleOS-Source-Code
0838
1 2U8 *LexStmt2Bin(CCmpCtrl *cc,I64 *_type,I64 cmp_flags=0)3{//Compile one cc stmt to bin code.4 I64 size,i,j,k,*res=INVALID_PTR;5 CCodeCtrl *tmpcbh;6 if (_type) *_type=RT_I64;7 Btr(&cc->flags,CCf_PASS_TRACE_PRESENT);8 if (cc->aot_depth==2)9 COCPush(cc);10 COCInit(cc);11 if (!PrsStmt(cc,,,cmp_flags)) {12 if (cc->coc.coc_head.next!=&cc->coc.coc_head) {13 cc->coc.coc_head.last->ic_flags&=~ICF_RES_NOT_USED;14 ICAdd(cc,IC_RETURN_VAL2,0,0);15 ICAdd(cc,IC_RET,0,0);16 if (res=COCCompile(cc,&size,NULL,_type)) {17 if (cc->flags&CCF_AOT_COMPILE) {18 j=cc->aotc->rip;19 k=(size+7)>>3;20 for (i=0;i<k;i++)21 AOTStoreCodeU64(cc,res[i]);22 Free(res);23 res=j;24 }25 }26 } //TODO: else del misc?27 } else //TODO: too dangerous to del Misc?28 QueDel(&cc->coc.coc_head.next);29 if (cc->aot_depth==2) {30 tmpcbh=COCPopNoFree(cc);31 COCAppend(cc,tmpcbh);32 }33 return res;34}35 36CAOT *CmpJoin(CCmpCtrl *cc,I64 cmp_flags,U8 *map_name=NULL,U8 mapfile_drv_let=0)37{38 CAOTCtrl *aotc,*old_aot=cc->aotc;39 I64 i,j,l;40 U8 *buf;41 CAOTBinBlk *tmpbin;42 CAOTImportExport *tmpie;43 Bool okay=TRUE;44 CLexHashTableContext *htc=MAlloc(sizeof(CLexHashTableContext));45 CAOT *res=CAlloc(sizeof(CAOT)),*parent;46 if (parent=cc->aot) {47 res->parent_aot=parent;48 QueIns(res,parent->last);49 } else50 QueInit(res);51 cc->aot=res;52 53 res->next_ie=res->last_ie=&res->next_ie;54 cc->aotc=aotc=CAlloc(sizeof(CAOTCtrl));55 cc->aot_depth++;56 57 aotc->bin=CAlloc(sizeof(CAOTBinBlk));58 aotc->max_align_bits=0;59 aotc->org=INVALID_PTR;60 61 MemCpy(htc,&cc->htc,sizeof(CLexHashTableContext));62 if (cc->htc.fun)63 cc->htc.glbl_hash_table=HashTableNew(128);64 else65 cc->htc.glbl_hash_table=HashTableNew(1024);66 if (cc->flags&CCF_AOT_COMPILE) {67 cc->htc.define_hash_table=cc->htc.glbl_hash_table;68 if (cc->aot_depth<=1)69 cc->htc.glbl_hash_table->next=cmp.asm_hash;70 else71 cc->htc.glbl_hash_table->next=htc->glbl_hash_table;72 } else73 cc->htc.glbl_hash_table->next=Fs->hash_table;74 cc->htc.hash_table_lst=cc->htc.local_hash_table=HashTableNew(16);75 cc->htc.local_hash_table->next=cc->htc.glbl_hash_table;76 cc->htc.local_var_lst=cc->htc.fun; //HolyC local vars77 cc->htc.fun=NULL;78 try {79 if (cmp_flags&CMPF_LEX_FIRST)80 Lex(cc);81 if (!(cmp_flags&CMPF_ONE_ASM_INS))82 cmp_flags|=CMPF_PRS_SEMICOLON;83 if (cc->flags&CCF_AOT_COMPILE) {84 while (cc->token!=TK_EOF) {85 buf=LexStmt2Bin(cc,NULL,cmp_flags);86 if (buf!=INVALID_PTR) {87 tmpie=CAlloc(sizeof(CAOTImportExport));88 tmpie->type=IET_MAIN;89 tmpie->rip=buf;90 QueIns(tmpie,res->last_ie);91 }92 if (cmp_flags&CMPF_ASM_BLK)93 break;94 }95 } else96 PrsStmt(cc,,,cmp_flags);97 AOTGlblsResolve(cc,res);98 } catch {99 if (Fs->except_ch=='Compiler' && !(cmp_flags&CMPF_ASM_BLK)) {100 LexPutPos(cc);101 Fs->catch_except=TRUE;102 }103 okay=FALSE;104 }105 if (!okay) {106 if (cc->error_cnt<1)107 cc->error_cnt=1;108 cc->aot=res->parent_aot;109 Free(res);110 LinkedLstDel(aotc->bin);111 res=NULL;112 } else {113 if (map_name)114 MapFileWrite(cc->htc.glbl_hash_table,map_name,mapfile_drv_let);115 HashTableDel(cc->htc.local_hash_table);116 HashTableDel(cc->htc.glbl_hash_table);117 118 if (!aotc->num_bin_U8s)119 res->buf=NULL;120 else {121 if (cc->flags&CCF_AOT_COMPILE)122 res->buf=MAlloc(aotc->num_bin_U8s);123 else {124 if (aotc->org==INVALID_PTR)125 res->buf=MAlloc(aotc->num_bin_U8s,Fs->code_heap);126 else127 res->buf=aotc->org;128 }129 res->aot_U8s=aotc->num_bin_U8s;130 tmpbin=aotc->bin;131 j=0;132 l=aotc->num_bin_U8s;133 while (tmpbin) {134 i=l;135 if (i>AOT_BIN_BLK_SIZE)136 i=AOT_BIN_BLK_SIZE;137 MemCpy(res->buf+j,tmpbin->body,i);138 j+=i;139 l-=i;140 tmpbin=tmpbin->next;141 }142 }143 LinkedLstDel(aotc->bin);144 res->abss=aotc->abss;145 res->heap_glbls=aotc->heap_glbls;146 res->max_align_bits=aotc->max_align_bits;147 res->org=aotc->org;148 }149 cc->aot=parent;150 MemCpy(&cc->htc,htc,sizeof(CLexHashTableContext));151 Free(htc);152 Free(aotc);153 cc->aotc=old_aot;154 cc->aot_depth--;155 return res;156}157 158CAOT *CmpBuf(U8 *buf,U8 *map_name=NULL,159 I64 *error_cnt=NULL, I64 *warning_cnt=NULL,U8 mapfile_drv_let=0)160{161 CCmpCtrl *cc;162 CAOT *res=NULL;163 cc=CmpCtrlNew(buf,CCF_DONT_FREE_BUF);164 cc->flags|=CCF_AOT_COMPILE;165 QueIns(cc,Fs->last_cc);166 res=CmpJoin(cc,CMPF_LEX_FIRST,map_name,mapfile_drv_let);167 if (error_cnt) *error_cnt=cc->error_cnt;168 if (warning_cnt) *warning_cnt=cc->warning_cnt;169 QueRem(cc);170 if (res)171 CmpCtrlDel(cc);172 return res;173}174 175U0 CmpFixUpJITAsm(CCmpCtrl *cc,CAOT *tmpaot)176{177 I64 i,rip2=tmpaot->buf+tmpaot->rip,*str=NULL;178 U8 *ptr;179 CCodeMisc *g_lb;180 CAOTAbsAddr *tmpa,*tmpa1;181 CAOTImportExport *tmpie,*tmpie1;182 CHashExport *tmpex;183 184 tmpa=tmpaot->abss;185 while (tmpa) {186 tmpa1=tmpa->next;187 ptr=rip2+tmpa->rip;188 switch [tmpa->type] {189 case AAT_ADD_U8: *ptr(U8 *) +=rip2; break;190 case AAT_SUB_U8: *ptr(U8 *) -=rip2; break;191 case AAT_ADD_U16: *ptr(U16 *)+=rip2; break;192 case AAT_SUB_U16: *ptr(U16 *)-=rip2; break;193 case AAT_ADD_U32: *ptr(U32 *)+=rip2; break;194 case AAT_SUB_U32: *ptr(U32 *)-=rip2; break;195 case AAT_ADD_U64: *ptr(I64 *)+=rip2; break;196 case AAT_SUB_U64: *ptr(I64 *)-=rip2; break;197 }198 Free(tmpa);199 tmpa=tmpa1;200 }201 tmpie=tmpaot->next_ie;202 while (tmpie!=&tmpaot->next_ie) {203 tmpie1=tmpie->next;204 if (tmpie->str) {205 Free(str);206 str=tmpie->str;207 }208 switch (tmpie->type) {209 case IET_REL32_EXPORT:210 case IET_IMM32_EXPORT:211 case IET_REL64_EXPORT:212 case IET_IMM64_EXPORT:213 tmpex=CAlloc(sizeof(CHashExport));214 tmpex->str=str;215 str=NULL;216 tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;217 if (tmpie->type==IET_IMM32_EXPORT||tmpie->type==IET_IMM64_EXPORT)218 tmpex->val=tmpie->rip;219 else220 tmpex->val=tmpie->rip+rip2;221 tmpex->src_link=tmpie->src_link;222 tmpie->src_link=NULL;223 HashAdd(tmpex,Fs->hash_table);224 SysSymImportsResolve(tmpex->str);225 break;226 case IET_REL_I0...IET_IMM_I64:227 if (tmpie->str) {228 if (tmpie->flags&IEF_GOTO_LABEL) {229 if(!(g_lb=COCGoToLabelFind(cc,str)))230 "Unresolved Reference:%s\n",str;231 else {232 g_lb->use_cnt++;233 g_lb=OptLabelFwd(g_lb);234 i=g_lb->addr+tmpaot->buf;235 }236 tmpex=NULL;237 } else {238 if (!(tmpex=HashFind(str,Fs->hash_table,239 HTG_ALL-HTT_IMPORT_SYS_SYM)))240 "Unresolved Reference:%s\n",str;241 else {242 if (tmpex->type & HTT_FUN)243 i=tmpex(CHashFun *)->exe_addr;244 else if (tmpex->type & HTT_GLBL_VAR)245 i=tmpex(CHashGlblVar *)->data_addr;246 else247 i=tmpex->val;248 }249 g_lb=NULL;250 }251 }252 if (tmpex || g_lb) {253 ptr=tmpie->rip+rip2;254 switch [tmpie->type] {255 case IET_REL_I0:256 case IET_IMM_U0:257 break;258 case IET_REL_I8:259 if (!(I8_MIN<=i-ptr-1<=I8_MAX))260 LexExcept(cc,"Branch out of range at ");261 *ptr(U8 *) =i-ptr-1;262 break;263 case IET_IMM_U8:264 *ptr(U8 *) =i;265 break;266 case IET_REL_I16:267 if (!(I16_MIN<=i-ptr-2<=I16_MAX))268 LexExcept(cc,"Branch out of range at ");269 *ptr(U16 *)=i-ptr-2;270 break;271 case IET_IMM_U16:272 *ptr(U16 *)=i;273 break;274 case IET_REL_I32:275 if (!(I32_MIN<=i-ptr-4<=I32_MAX))276 LexExcept(cc,"Branch out of range at ");277 *ptr(U32 *)=i-ptr-4;278 break;279 case IET_IMM_U32:280 *ptr(U32 *)=i;281 break;282 case IET_REL_I64:283 *ptr(I64 *)=i-ptr-8;284 break;285 case IET_IMM_I64:286 *ptr(I64 *)=i;287 break;288 }289 }290 break;291 }292 Free(tmpie->src_link);293 Free(tmpie);294 tmpie=tmpie1;295 }296 Free(str);297 if (!cc->aot_depth && Bt(&cc->opts,OPTf_TRACE))298 Un(rip2,tmpaot->aot_U8s,64);299 QueRem(tmpaot);300 Free(tmpaot);301}302 303U0 CmpFixUpAOTAsm(CCmpCtrl *cc,CAOT *tmpaot)304{305 CAOTCtrl *aotc=cc->aotc;306 I64 i,rip2=tmpaot->rip+cc->aotc->rip;307 U8 *ptr;308 CCodeMisc *g_lb=NULL;309 CAOTAbsAddr *tmpa,*tmpa1;310 CAOTImportExport *tmpie,*tmpie1;311 312 tmpa=tmpaot->abss;313 while (tmpa) {314 tmpa1=tmpa->next;315 tmpa->next=aotc->abss;316 ptr=tmpaot->buf+tmpaot->rip+tmpa->rip;317 switch [tmpa->type] {318 case AAT_ADD_U8: *ptr(U8 *)+=rip2; break;319 case AAT_SUB_U8: *ptr(U8 *)-=rip2; break;320 case AAT_ADD_U16: *ptr(U16 *)+=rip2; break;321 case AAT_SUB_U16: *ptr(U16 *)-=rip2; break;322 case AAT_ADD_U32: *ptr(U32 *)+=rip2; break;323 case AAT_SUB_U32: *ptr(U32 *)-=rip2; break;324 case AAT_ADD_U64: *ptr(I64 *)+=rip2; break;325 case AAT_SUB_U64: *ptr(I64 *)-=rip2; break;326 }327 aotc->abss=tmpa;328 tmpa->rip+=rip2;329 tmpa=tmpa1;330 }331 332 tmpie=tmpaot->next_ie;333 while (tmpie!=&tmpaot->next_ie) {334 tmpie1=tmpie->next;335 QueRem(tmpie);336 if (IET_REL_I0<=tmpie->type<=IET_IMM_I64) {337 if (tmpie->str) {338 if (tmpie->flags&IEF_GOTO_LABEL) {339 if(!(g_lb=COCGoToLabelFind(cc,tmpie->str)))340 "Unresolved Reference:%s\n",tmpie->str;341 else {342 g_lb->use_cnt++;343 g_lb=OptLabelFwd(g_lb);344 }345 } else346 g_lb=NULL;347 }348 } else349 g_lb=NULL;350 351 ptr=tmpaot->buf+tmpaot->rip+tmpie->rip;352 if (g_lb) {353 i=g_lb->addr+tmpaot->buf;354 switch [tmpie->type] {355 case IET_REL_I0:356 case IET_IMM_U0:357 break;358 case IET_REL_I8:359 if (!(I8_MIN<=i-ptr-1<=I8_MAX))360 LexExcept(cc,"Branch out of range at ");361 *ptr(U8 *) =i-ptr-1;362 break;363 case IET_IMM_U8:364 *ptr(U8 *) =i;365 break;366 case IET_REL_I16:367 if (!(I16_MIN<=i-ptr-2<=I16_MAX))368 LexExcept(cc,"Branch out of range at ");369 *ptr(U16 *)=i-ptr-2;370 break;371 case IET_IMM_U16:372 *ptr(U16 *)=i;373 break;374 case IET_REL_I32:375 if (!(I32_MIN<=i-ptr-4<=I32_MAX))376 LexExcept(cc,"Branch out of range at ");377 *ptr(U32 *)=i-ptr-4;378 break;379 case IET_IMM_U32:380 *ptr(U32 *)=i;381 break;382 case IET_REL_I64:383 *ptr(I64 *)=i-ptr-8;384 break;385 case IET_IMM_I64:386 *ptr(I64 *)=i;387 break;388 }389 Free(tmpie->src_link);390 Free(tmpie);391 } else {392 switch (tmpie->type) {393 start:394 case IET_REL32_EXPORT:395 case IET_IMM32_EXPORT:396 case IET_REL64_EXPORT:397 case IET_IMM64_EXPORT:398 case IET_IMM_U0:399 case IET_IMM_U8:400 case IET_IMM_U16:401 case IET_IMM_U32:402 case IET_IMM_I64:403 case IET_REL_I0:404 break;405 case IET_REL_I8: *ptr(U8 *) -=rip2; break;406 case IET_REL_I16: *ptr(U16 *)-=rip2; break;407 case IET_REL_I32: *ptr(U32 *)-=rip2; break;408 case IET_REL_I64: *ptr(I64 *)-=rip2; break;409 end:410 tmpie->rip+=rip2;411 break;412 }413 tmpie->aot=NULL;414 QueIns(tmpie,tmpaot->parent_aot->last_ie);415 }416 tmpie=tmpie1;417 }418}419 420I64 Cmp(U8 *filename,U8 *map_name=NULL,U8 *out_name=NULL,U8 mapfile_drv_let=0)421{//AOT Compile HC or PRJ file a and output BIN file. Returns err_cnt.422 U8 *ptr,*fbuf=NULL,*fbuf2=NULL,*fbuf3=NULL,423 *patch_table=MAlloc(0x20000);424 CAOT *tmpaot;425 I64 i,cnt,size=0,error_cnt=0,warning_cnt=0,aot_U8s=0;426 CBinFile *bfh;427 CAOTImportExport *tmpie,*tmpie1;428 CAOTAbsAddr *tmpa,*tmpa1;429 CAOTHeapGlblRef *tmphgr,*tmphgr1;430 CAOTHeapGlbl *tmphg,*tmphg1;431 432 fbuf=ExtDft(filename,"PRJ.Z");433 fbuf2=MStrPrint("#include \"%s\"",fbuf);434 if (map_name)435 fbuf3=ExtDft(map_name,"MAP.Z");436 437 if (tmpaot=CmpBuf(fbuf2,fbuf3,&error_cnt,&warning_cnt,mapfile_drv_let)) {438 aot_U8s=tmpaot->aot_U8s;439 ptr=patch_table;440//See Load()441 cnt=0;442 tmpa=tmpaot->abss;443 while (tmpa) {444 if (!(tmpa->type&IEF_IMM_NOT_REL))445 cnt++;446 tmpa=tmpa->next;447 }448 if (cnt) {449 *ptr++=IET_ABS_ADDR;450 *ptr(U32 *)++=cnt;451 *ptr++=0;452 tmpa=tmpaot->abss;453 while (tmpa) {454 tmpa1=tmpa->next;455 if (!(tmpa->type&IEF_IMM_NOT_REL))456 *ptr(U32 *)++ =tmpa->rip;457 Free(tmpa);458 tmpa=tmpa1;459 }460 }461 tmphg=tmpaot->heap_glbls;462 while (tmphg) {463 tmphg1=tmphg->next;464 cnt=0;465 tmphgr=tmphg->references;466 while (tmphgr) {467 cnt++;468 tmphgr=tmphgr->next;469 }470 if (cnt) {471 *ptr++=IET_DATA_HEAP;472 *ptr(U32 *)++=cnt;473 if (tmphg->str) {474 i=StrLen(tmphg->str);475 MemCpy(ptr,tmphg->str,i+1);476 Free(tmphg->str);477 ptr+=i+1;478 } else479 *ptr++=0;480 *ptr(I64 *)++=tmphg->size;481 tmphgr=tmphg->references;482 while (tmphgr) {483 tmphgr1=tmphgr->next;484 *ptr(U32 *)++=tmphgr->rip;485 Free(tmphgr);486 tmphgr=tmphgr1;487 }488 }489 Free(tmphg);490 tmphg=tmphg1;491 }492 493 //Do exports first494 tmpie=tmpaot->next_ie;495 while (tmpie!=&tmpaot->next_ie) {496 tmpie1=tmpie->next;497 if (!tmpie->type || IET_REL32_EXPORT<=tmpie->type<=IET_IMM64_EXPORT) {498 QueRem(tmpie);499 *ptr++=tmpie->type;500 *ptr(U32 *)++=tmpie->rip;501 if (tmpie->str) {502 i=StrLen(tmpie->str);503 MemCpy(ptr,tmpie->str,i+1);504 Free(tmpie->str);505 ptr+=i+1;506 } else507 *ptr++=0;508 Free(tmpie->src_link);509 Free(tmpie);510 }511 tmpie=tmpie1;512 }513 514 //Do imports second515 tmpie=tmpaot->next_ie;516 while (tmpie!=&tmpaot->next_ie) {517 tmpie1=tmpie->next;518 QueRem(tmpie);519 *ptr++=tmpie->type;520 if (tmpie->aot)521 tmpie->rip+=tmpie->aot->rip2;522 *ptr(U32 *)++=tmpie->rip;523 if (tmpie->str) {524 i=StrLen(tmpie->str);525 MemCpy(ptr,tmpie->str,i+1);526 Free(tmpie->str);527 ptr+=i+1;528 } else529 *ptr++=0;530 Free(tmpie->src_link);531 Free(tmpie);532 tmpie=tmpie1;533 }534 535 *ptr++=IET_END;536 MemSet(ptr,0,16);537 i=ptr-patch_table;538//Needs 16 ALIGN539 size=(sizeof(CBinFile)+aot_U8s+i+15)&-16;540 bfh=MAlloc(size);541 bfh->jmp=0xEB+256*(sizeof(CBinFile)-2);542#assert sizeof(CBinFile)-2<=I8_MAX543 bfh->reserved=0;544 bfh->bin_signature=BIN_SIGNATURE_VAL;545 bfh->org=tmpaot->org;546 bfh->module_align_bits=tmpaot->max_align_bits;547 bfh->patch_table_offset=sizeof(CBinFile)+aot_U8s;548 bfh->file_size=size;549 MemCpy(bfh(U8 *)+sizeof(CBinFile),tmpaot->buf,aot_U8s);550 MemCpy(bfh(U8 *)+sizeof(CBinFile)+aot_U8s,patch_table,551 size-aot_U8s-sizeof(CBinFile));552 Free(fbuf2);553 if (out_name)554 fbuf2=ExtDft(out_name,"BIN.Z");555 else556 fbuf2=ExtChg(fbuf,"BIN.Z");557 FileWrite(fbuf2,bfh,size);558 Free(bfh);559 Free(tmpaot->buf);560 QueDel(tmpaot);561 Free(tmpaot);562 }563 Free(patch_table);564 Free(fbuf);565 Free(fbuf2);566 Free(fbuf3);567 Print("Errs:%d Warns:%d Code:%X Size:%X\n",568 error_cnt,warning_cnt,aot_U8s,size);569 return error_cnt;570}571 572I64 ExePutS(U8 *buf,U8 *filename=NULL,573 I64 ccf_flags=0,CLexHashTableContext *htc=NULL)574{//JIT Compile and execute text from a puts("").575 I64 res;576 Bool okay=TRUE;577 CCmpCtrl *cc;578 if (!filename)579 filename=blkdev.tmp_filename;580 cc=CmpCtrlNew(buf,ccf_flags|CCF_DONT_FREE_BUF,filename);581 if (Fs->last_cc!=&Fs->next_cc) {582 cc->opts=Fs->last_cc->opts;583 if (htc) {584 cc->flags=cc->flags &~CCF_ASM_EXPRESSIONS |585 htc->old_flags&CCF_ASM_EXPRESSIONS;586 MemCpy(&cc->htc,htc,sizeof(CLexHashTableContext));587 }588 }589 QueIns(cc,Fs->last_cc);590 try {591 Lex(cc);592 res=ExeCmdLine(cc);593 } catch {594 if (Fs->except_ch=='Compiler' || Fs->except_ch=='Break') {595 Fs->catch_except=TRUE;596 okay=FALSE;597 res=0;598 }599 }600 QueRem(cc);601 if (okay)602 CmpCtrlDel(cc); //TODO: can crash603 return res;604}605 606I64 ExePrint(U8 *fmt,...)607{//JIT Compile and execute text from a printf().608 I64 res;609 U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);610 res=ExePutS(buf);611 Free(buf);612 return res;613}614 615I64 ExeFile(U8 *name,I64 ccf_flags=0)616{//JIT Compile and execute a file.617 I64 res;618 U8 *name2=ExtDft(name,"HC.Z"),619 *st=MStrPrint("#include \"%s\";",name2);620 res=ExePutS(st,name,ccf_flags);621 Free(st);622 Free(name2);623 return res;624}625 626I64 RunFile(U8 *name,I64 ccf_flags=0,...)627{//ExeFile() with args using LastFun().628 ExeFile(name,ccf_flags);629 return LastFun(argc,argv);630}631 632I64 ExePutS2(U8 *buf,U8 *filename=NULL,I64 ccf_flags=0)633{//throws exceptions634 I64 res;635 CCmpCtrl *cc;636 if (!filename)637 filename=blkdev.tmp_filename;638 cc=CmpCtrlNew(buf,ccf_flags|CCF_DONT_FREE_BUF,filename);639 if (Fs->last_cc!=&Fs->next_cc)640 cc->opts=Fs->last_cc->opts;641 QueIns(cc,Fs->last_cc);642 Lex(cc);643 res=ExeCmdLine(cc);644 QueRem(cc);645 CmpCtrlDel(cc);646 return res;647}648 649I64 ExePrint2(U8 *fmt,...)650{//throws exceptions651 I64 res;652 U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);653 res=ExePutS2(buf);654 Free(buf);655 return res;656}657 658I64 ExeFile2(U8 *name,I64 ccf_flags=0)659{//throws exceptions660 I64 res;661 U8 *name2=ExtDft(name,"HC.Z"),*st=MStrPrint("#include \"%s\";",name2);662 res=ExePutS2(st,name,ccf_flags);663 Free(st);664 Free(name2);665 return res;666}667 668I64 RunFile2(U8 *name,I64 ccf_flags=0,...)669{//ExeFile2() with args using LastFun(). throws exceptions.670 ExeFile2(name,ccf_flags);671 return LastFun(argc,argv);672}673 674I64 StreamExePrint(U8 *fmt,...)675{//Causes value from stream to be used in an #exe{} block.676 U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);677 I64 res=0;678 CLexHashTableContext *htc;679 CCmpCtrl *cc=Fs->last_cc;680 if (cc==&Fs->next_cc)681 PrintErr("Not Compiling\n");682 else {683 if (!(cc->flags&CCF_EXE_BLK))684 LexExcept(cc,"StreamExePrint only allowed in AOT compiled #exe{} mode.");685 if (htc=cc->htc.next)686 res=ExePutS(buf,,,htc);687 }688 Free(buf);689 return res;690}691 692U0 CInit()693{694 CmpLoadDefines;695 CmpFillTables;696 QueInit(&cmp.ic_nop);697 cmp.ic_nop.ic_class=cmp.internal_types[RT_I64];698 cmp.ic_nop.ic_code=IC_NOP1;699 AsmHashLoad;700 UAsmHashLoad;701}702 703CInit;704 