hschumann2/TempleOS-Source-Code
0838
1 2U0 LexPutToken(CCmpCtrl *cc)3{//Print cur token to StdOut. (Crude)4 '"';5 if (cc->token==TK_IDENT || cc->token==TK_STR)6 "%s",cc->cur_str;7 else if (cc->token==TK_I64)8 "INT:%X",cc->cur_i64;9 else if (cc->token==TK_CHAR_CONST)10 "U8:%X",cc->cur_i64;11 else if (cc->token==TK_F64)12 "FLOAT:%e",cc->cur_f64;13 else if (cc->token=='\n')14 "<NEW_LINE>";15 else if (Bt(char_bmp_displayable,cc->token))16 '' cc->token;17 else {18 "T:%X",cc->token;19 }20 "\" ";21}22 23U8 *LexPutLine(CCmpCtrl *cc,U8 *start)24{//Print cur pos to end of line to StdOut.25 I64 ch;26 U8 *ptr;27 if (!start) return NULL;28 if (cc->lex_include_stk->flags&LFSF_DOC)29 return DocPutLine(cc->lex_include_stk->doc,start);30 else {31 ptr=start;32 while (ch=*ptr++) {33 if (ch=='\n') {34 if (*ptr=='\r')35 ptr++;36 break;37 } else if (ch=='\r') {38 if (*ptr=='\n')39 ptr++;40 break;41 }42 '' ch;43 }44 if (!ch) ptr--;45 '\n';46 return ptr;47 }48 return NULL;49}50 51U0 LexPutPos(CCmpCtrl *cc)52{//Print token, line link and, then, LexPutLine().53 LexPutToken(cc);54 FixSet(cc->lex_include_stk->full_name,cc->lex_include_stk->line_num);55 if (IsRaw)56 "%s,%d ",cc->lex_include_stk->full_name,cc->lex_include_stk->line_num;57 else {58 PutFileLink(cc->lex_include_stk->full_name,,cc->lex_include_stk->line_num);59 AdamErr("%s,%d\n",60 cc->lex_include_stk->full_name,cc->lex_include_stk->line_num);61 '' CH_SPACE;62 }63 LexPutLine(cc,cc->lex_include_stk->line_start);64}65 66U0 LexWarn(CCmpCtrl *cc,U8 *str=NULL)67{//Print warn msg, then, LexPutPos().68 if (str) PrintWarn(str);69 if (cc->htc.fun) {70 "in fun '%s'.\n",cc->htc.fun->str;71 if (IsRaw)72 "%s\n",cc->htc.fun->src_link;73 else {74 "$LK,\"%s\"$\n",cc->htc.fun->src_link;75 AdamErr("%s\n",cc->htc.fun->src_link);76 }77 } else78 LexPutPos(cc);79 cc->warning_cnt++;80}81 82U0 LexExcept(CCmpCtrl *cc,U8 *str=NULL)83{//Print err msg, LexPutPos() and throw exception.84 if (!Bt(&sys_run_level,RLf_ADAM_SERVER)) {85 Raw(ON);86 "Note: Still in boot phase.\n";87 }88 if (str) PrintErr(str);89 if (!IsRaw)90 AdamErr("Task:%08X %s\n",Fs,str);91 LexPutPos(cc);92 cc->error_cnt++;93 FlushMsgs;94 if (!Bt(&sys_run_level,RLf_ADAM_SERVER))95 Dbg("Type \"Fix;\"");96 throw('Compiler');97}98 99U0 UndefinedExtern()100{101 PrintErr("Undefined Extern\nat %P\n",Caller);102 throw('UndefExt');103}104 105U0 UnusedExternWarning(CCmpCtrl *cc,CHashClass *tmpc)106{107 PrintWarn("Unused extern '%s'\n",tmpc->str);108 cc->warning_cnt++;109}110 111U0 ParenWarning(CCmpCtrl *cc)112{113 if (Bt(&cc->opts,OPTf_WARN_PAREN) &&114 !(cc->lex_include_stk->flags&LFSF_DEFINE))115 LexWarn(cc,"Unnecessary parenthesis ");116}117 118U0 ICClassPut(CHashClass *c)119{120 I64 i;121 if (!c) return;122 if (c->ptr_stars_cnt>4) {123 PrintErr("put_class ptrcnt=%d\n",c->ptr_stars_cnt);124 while (TRUE)125//TODO:126 Yield;127 }128 for (i=0;i<c->ptr_stars_cnt;i++)129 '*';130 c-=c->ptr_stars_cnt;131 if (c->str)132 "%s",c->str;133 else {134 PrintErr("put_class str=NULL\n");135 while (TRUE)136//TODO:137 Yield;138 }139 '' CH_SPACE;140}141 142U0 ICArgPut(CICArg *a,I64 type_pointed_to)143{144 if (type_pointed_to)145 "[%Z](%Z) %Z ",a->type.raw_type,"ST_RAW_TYPES",146 type_pointed_to,"ST_RAW_TYPES",Bsr(a->type>>8)+1,"ST_TY_TYPES";147 else148 "%Z %Z ",a->type.raw_type,"ST_RAW_TYPES",149 Bsr(a->type>>8)+1,"ST_TY_TYPES";150 switch (Bsr(a->type)) {151 case MDf_STK:152 "STK";153 break;154 case MDf_IMM:155 "#%X",a->disp;156 break;157 case MDf_REG:158 "%Z",a->reg,"ST_U64_REGS";159 break;160 case MDf_DISP:161 "%X[%Z]",a->disp,a->reg,"ST_U64_REGS";162 break;163 case MDf_RIP_DISP32:164 "[%X]",a->disp;165 break;166 case MDf_SIB:167 if (a->disp)168 "%X",a->disp;169 if (a->reg==REG_RIP)170 '[';171 else172 "[%Z+",a->reg&15,"ST_U64_REGS";173 "%Z",a->reg>>8&15,"ST_U64_REGS";174 switch (a->reg>>14) {175 case 0: "]"; break;176 case 1: "*2]"; break;177 case 2: "*4]"; break;178 case 3: "*8]"; break;179 }180 break;181 }182 '' CH_SPACE;183}184 185U0 ICPut(CCmpCtrl *cc,CIntermediateCode *tmpi)186{187 I64 opcode=tmpi->ic_code,i;188 if (opcode>=IC_END_EXP && opcode!=IC_NOP2) {189 "%15ts %016X ",intermediate_code_table[opcode].name,tmpi->ic_data;190 if (cc->pass) {191 if (tmpi->res.type.mode) {192 "$PURPLE$RES:$FG$";193 ICArgPut(&tmpi->res,0);194 }195 if (tmpi->arg1.type.mode) {196 "$PURPLE$ARG1:$FG$";197 if (intermediate_code_table[tmpi->ic_code].type==IST_DEREF ||198 intermediate_code_table[tmpi->ic_code].type==IST_ASSIGN)199 ICArgPut(&tmpi->arg1,tmpi->arg1_type_pointed_to);200 else201 ICArgPut(&tmpi->arg1,0);202 }203 if (tmpi->arg2.type.mode) {204 "$PURPLE$ARG2:$FG$";205 ICArgPut(&tmpi->arg2,0);206 }207 "$PURPLE$:$FG$";208 }209 ICClassPut(tmpi->ic_class);210 if (tmpi->ic_flags & ICF_LOCK)211 "$BROWN$lock$FG$ ";212 if (tmpi->ic_flags & ICF_ARG2_TO_F64)213 "$LTBLUE$a2d$FG$ ";214 if (tmpi->ic_flags & ICF_ARG2_TO_INT)215 "$GREEN$a2i$FG$ ";216 if (tmpi->ic_flags & ICF_ARG1_TO_F64)217 "$LTBLUE$a1d$FG$ ";218 if (tmpi->ic_flags & ICF_ARG1_TO_INT)219 "$GREEN$a1i$FG$ ";220 if (tmpi->ic_flags & ICF_RES_TO_F64)221 "$LTBLUE$rd$FG$ ";222 if (tmpi->ic_flags & ICF_RES_TO_INT)223 "$GREEN$ri$FG$ ";224 if (tmpi->ic_flags & ICF_USE_F64)225 "[F64] ";226 if (tmpi->ic_flags & ICF_USE_UNSIGNED)227 "[unsigned] ";228 if (tmpi->ic_flags & ICF_USE_INT)229 "[int] ";230 if (tmpi->ic_flags & ICF_RES_NOT_USED)231 "NO_RES ";232 if (tmpi->ic_flags & ICF_BY_VAL)233 "BY_VAL ";234 if (tmpi->ic_flags & ICF_PUSH_RES)235 "PUSH ";236 if (tmpi->ic_flags & ICF_PUSH_CMP)237 "PUSH_CMP ";238 if (tmpi->ic_flags & ICF_POP_CMP)239 "POP_CMP ";240 if (tmpi->ic_flags & ICF_DEL_PREV_INS)241 "DEL_PREV ";242 if (tmpi->ic_flags & ICF_PREV_DELETED)243 "PREV_DEL ";244 for (i=0;i<3;i++) {245 if (Bt(&tmpi->ic_flags,ICf_DONT_PUSH_FLOAT0+i))246 "DONT_PUSH#%d ",i;247 if (Bt(&tmpi->ic_flags,ICf_DONT_POP_FLOAT0+i))248 "DONT_POP#%d ",i;249 }250 if (tmpi->ic_flags & ICF_ALT_TEMPLATE)251 "ALT_TMP ";252 '\n';253 }254}255 