hschumann2/TempleOS-Source-Code
0838
1 2Bool Option(I64 num,Bool val)3{//Set compiler Option to val.4 return BEqu(&Fs->last_cc->opts,num,val);5}6 7Bool GetOption(I64 num)8{//Get state of compiler option.9 return Bt(&Fs->last_cc->opts,num);10}11 12asm {13_LAST_FUN:: //See _CALL_IND14 PUSH RBP15 MOV RBP,RSP16 PUSH RSI17 PUSH RDI18 19 XOR RAX,RAX20 MOV RAX,FS:CTask.last_fun[RAX]21 TEST RAX,RAX22 JZ @@1023 MOV RDX,U64 CHashFun.exe_addr[RAX]24 25 MOV RCX,U64 SF_ARG1[RBP] //argc26 MOV RSI,U64 SF_ARG2[RBP] //argv27 SHL RCX,328 SUB RSP,RCX29 MOV RDI,RSP30 REP_MOVSB31 TEST RDX,RDX32 JZ @@0533 34 CALL RDX35 POP RDI36 POP RSI37 POP RBP38 RET1 1639 40@@05: MOV RCX,U64 SF_ARG1[RBP] //argc41 SHL RCX,342 ADD RSP,RCX43 XOR RAX,RAX44@@10: POP RDI45 POP RSI46 POP RBP47 RET1 1648}49_extern _LAST_FUN I64 LastFun(I64 argc,I64 *argv); //Execute last fun with args.50 51I64 PassTrace(I64 i=0b10001111101)52{//Ctrls which optimizer passes are displayed.53 I64 old=Fs->last_cc->pass_trace;54 if (i) Fs->last_cc->saved_pass_trace=i;55 Fs->last_cc->pass_trace=i;56 return old;57}58 59Bool Trace(Bool val=ON)60{//Displays assembly code output from compiler.61 return Option(OPTf_TRACE,val);62}63 64Bool Echo(Bool val)65{//Displays text as it is being compiled.66 return Option(OPTf_ECHO,val);67}68 69U0 StreamPrint(U8 *fmt,...)70{//Injects text into the compile stream. Used in #exe{} blocks.71 U8 *buf=StrPrintJoin(NULL,fmt,argc,argv),*st;72 CCmpCtrl *cc=Fs->last_cc;73 CStreamBlk *tmpe=cc->last_stream_blk;74 if (tmpe!=&cc->next_stream_blk) {75 st=MStrPrint("%s%s",tmpe->body,buf);76 Free(tmpe->body);77 tmpe->body=st;78 } else79 PrintErr("No exe{} blk\n");80 Free(buf);81}82 83U0 StreamDir()84{85 U8 *dirname;86 if (dirname=DirFile(Fs->last_cc->lex_include_stk->full_name)) {87 StreamPrint("\"%s\"",dirname);88 Free(dirname);89 }90}91 92CD2I32 *LexD2I32(CCmpCtrl *cc,CD2I32 *p)93{//Not HolyC. Sprite-like lex 2D point.94 if (cc->token!='(')95 LexExcept(cc,"Expecting '(' at ");96 Lex(cc); //Skip (97 p->x=LexExpressionI64(cc);98 if (cc->token!=',')99 LexExcept(cc,"Expecting ',' at ");100 Lex(cc); //Skip ,101 p->y=LexExpressionI64(cc);102 if (cc->token!=')')103 LexExcept(cc,"Expecting ')' at ");104 Lex(cc); //Skip )105 return p;106}107 108CD3I32 *LexD3I32(CCmpCtrl *cc,CD3I32 *p)109{//Not HolyC. Sprite-like lex 3D point.110 if (cc->token!='(')111 LexExcept(cc,"Expecting '(' at ");112 Lex(cc); //Skip (113 p->x=LexExpressionI64(cc);114 if (cc->token!=',')115 LexExcept(cc,"Expecting ',' at ");116 Lex(cc); //Skip ,117 p->y=LexExpressionI64(cc);118 if (cc->token!=',')119 LexExcept(cc,"Expecting ',' at ");120 Lex(cc); //Skip ,121 p->z=LexExpressionI64(cc);122 if (cc->token!=')')123 LexExcept(cc,"Expecting ')' at ");124 Lex(cc); //Skip )125 return p;126}127 128U8 *CmdLinePmt()129{130 I64 i;131 U8 *res,*st;132 if (Fs->new_answer) {133 if (Fs->answer_type&~1!=RT_I0) {134 if (Fs->answer_type==RT_F64)135 "%8.6fs ansf=%15.7g\n",Fs->answer_time,Fs->answer;136 else137 "%8.6fs ans=0x%08X=%d\n",Fs->answer_time,Fs->answer,Fs->answer;138 } else {139 "%8.6fs\n",Fs->answer_time;140 Fs->answer=0;141 }142 Fs->new_answer=FALSE;143 }144 if (st=DirCur) {145 "%s",st;146 Free(st);147 }148 '>';149 if (IsDbgMode&&IsRaw)150 RawDr;151 152 LBts(&Fs->task_flags,TASKf_CMD_LINE_PMT);153 st=GetStr(,,GSF_SHIFT_ESC_EXIT);154 LBtr(&Fs->task_flags,TASKf_CMD_LINE_PMT);155 156 i=StrLen(st);157 res=MAlloc(i+1+2);158 MemCpy(res,st,i+1);159 i--;160 while (i>=0 && Bt(char_bmp_white_space,res[i]))161 i--;162 i++;163 if (i>0 && res[i-1]==';')164 res[i++]=';'; //The Lex goes one beyond165 res[i++]='\n';//#define goes to '\n'166 res[i]=0;167 168 Free(st);169 return res;170}171 