static void write_const_vector(Context* ctx, const WasmConstVector* consts) { wasm_writef(&ctx->json_stream, "["); size_t i; for (i = 0; i < consts->size; ++i) { const WasmConst* const_ = &consts->data[i]; write_const(ctx, const_); if (i != consts->size - 1) write_separator(ctx); } wasm_writef(&ctx->json_stream, "]"); }
static int alldiagrams(FILE * fd, int nsub) { marktp bh; varptr totnum, totdenum, rnum; long pos_c1,pos_c2; int deg1,deg2,tmpn1,tmpn2, nC; catrec cr; deninforec dendescript; mark_(&bh); tmpNameMax=0; initinfo(); initdegnames(); writeF("{\n"); writeF("REAL N,D,R; COMPLEX Prop;\n"); pos_c1= ftell(outFile); writeF("%70s\n",""); writeF("if(CalcConst) C%d(C);\n",nsub); while(FREAD1(dendescript,fd) == 1) { fseek(catalog,dendescript.cr_pos,SEEK_SET); FREAD1(cr,catalog); ++(diagrcount); if(!noPict)writpict(cr.ndiagr_ + inftmp->firstdiagpos - 1); whichArchive(cr.nFile,'r'); fseek(archiv,cr.factpos,SEEK_SET); readvardef(archiv); readpolynom(&totnum); readpolynom(&totdenum); clearvardef(); fseek(archiv,cr.rnumpos,SEEK_SET); readvardef(archiv); readpolynom(&rnum); clearvardef(); fortwriter("N",totnum); fortwriter("D",totdenum); fortwriter("R",rnum); writeF("R*=(N/D);\n"); if(nin+nout>3) { writeF("Prop=1"); writeDenominators(&dendescript); writeF("R*=creal(Prop);\n"); writeF(" if(R>Fmax) Fmax=R; else if(R<-Fmax) Fmax=-R;\n"); } else writeF(";\n"); if(!noCChain)calcColor(cr.ndiagr_+inftmp->firstdiagpos); writeF("ans+=R;\n"); } whichArchive(0,0); writeF("\n}\nreturn ans;\n}\n"); deg1=cleardegnames(); tmpn1=tmpNameMax; tmpNameMax=0; initdegnames(); writeF("\nstatic void C%d(REAL*C)\n{\n",nsub); writeF(" REAL* V=va_ext;\n"); pos_c2= ftell(outFile); writeF("%70s\n",""); nC=write_const(); if(nC==0) nC=1; writeF("}\n"); fseek(outFile,pos_c1,SEEK_SET); writeF("static REAL C[%d];",nC); if(deg1) writeF("REAL S[%d];",deg1); if(tmpn1) writeF("REAL tmp[%d];",tmpn1); fseek(outFile,pos_c2,SEEK_SET); deg2=cleardegnames(); tmpn2=tmpNameMax; if(deg2) writeF("REAL S[%d];",deg2) ; if(tmpn2) writeF("REAL tmp[%d];",tmpn2 ); fseek(outFile,0,SEEK_END); release_(&bh); if( escpressed()) return 1; else return 0; }
static void onediagram(deninforec* dendescript) { catrec cr; marktp bh; varptr totnum, totdenum, rnum; long pos_c; int deg1,nConst; mark_(&bh); tmpNameMax=0; initinfo(); initdegnames(); fseek(catalog,dendescript->cr_pos,SEEK_SET); FREAD1(cr,catalog); ++(diagrcount); whichArchive(cr.nFile,'r'); fseek(archiv,cr.factpos,SEEK_SET); readvardef(archiv); readpolynom(&totnum); readpolynom(&totdenum); clearvardef(); fseek(archiv,cr.rnumpos,SEEK_SET); readvardef(archiv); readpolynom(&rnum); clearvardef(); { outFileOpen("%sresults%cf%d.c",pathtouser,f_slash,diagrcount); labl(); writeF("#include\"num_out.h\"\n"); writeF("#include\"num_in.h\"\n"); } writeF("extern FNN F%d_ext;\n",diagrcount); writeF("static void C%d(REAL * C)\n{\n",diagrcount); writeF("REAL* V=va_ext;\n"); pos_c= ftell(outFile); writeF("%80s\n",""); nConst=write_const(); deg1=cleardegnames(); writeF("}\n"); fseek(outFile,pos_c,SEEK_SET); if(deg1) writeF("REAL S[%d];",deg1); if(tmpNameMax) writeF("REAL tmp[%d];",tmpNameMax ); fseek(outFile,0,SEEK_END); tmpNameMax=0; initdegnames(); writeF("REAL F%d_ext(double GG,REAL*DP,REAL*Q0,COMPLEX*Q1,REAL*Q2)\n{\n",diagrcount); if(!noPict) writpict(cr.ndiagr_ + inftmp->firstdiagpos - 1); writeF("REAL N,D,R; COMPLEX Prop;\n"); writeF("REAL * V=va_ext;\n"); pos_c= ftell(outFile); writeF("%80s\n",""); writeF("if(CalcConst) C%d(C);\n",diagrcount); fortwriter("N",totnum); fortwriter("D",totdenum); fortwriter("R",rnum); writeF("R*=(N/D);\n"); writeF("Prop=1"); writeDenominators(dendescript); writeF("R*=creal(Prop);\n"); if(!noCChain)calcColor(cr.ndiagr_+inftmp->firstdiagpos); writeF(" return R;\n"); writeF("}\n"); deg1=cleardegnames(); if(nConst==0) nConst=1; fseek(outFile,pos_c,SEEK_SET); writeF("static REAL C[%d];",nConst); if(deg1) writeF("REAL S[%d];",deg1); if(tmpNameMax) writeF("REAL tmp[%d];",tmpNameMax ); fseek(outFile,0,SEEK_END); outFileClose(); release_(&bh); }
static void write_inst(CTX *ctx, struct ir_inst *in, bool inner) { if (in->comment) P(ctx, " /* COMMENT: %s */ ", in->comment); // @ALL ir_opcode switch (in->op) { case IR_OP_NOP: break; case IR_OP_COPY: P(ctx, "%s", R0); break; case IR_OP_GOTO: P(ctx, "goto B%d", BR(in, 0)); break; case IR_OP_BRANCH: P(ctx, "if (%s) goto B%d; else goto B%d", R0, BR(in, 1), BR(in, 0)); break; case IR_OP_RET: if (type_is_void(inst_getuse(in, 0)->result_type)) { P(ctx, "return"); } else { P(ctx, "return %s", R0); } break; case IR_OP_ABORT: P(ctx, "abort()"); break; case IR_OP_GETARG: P(ctx, "A%d", in->struct_member->index); break; case IR_OP_READ_VAR: P(ctx, "V%d", in->var->index); break; case IR_OP_WRITE_VAR: P(ctx, "V%d = %s", in->var->index, R0); break; case IR_OP_VAR_PTR: P(ctx, "&V%d", in->var->index); break; case IR_OP_GET_STRUCT_MEMBER_PTR: { struct name_temp t; P(ctx, "&(%s->%s)", R0, member_name(in->struct_member, &t)); break; } case IR_OP_CONSTRUCT_STRUCT: { if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); P(ctx, "{"); print_reads(ctx, in, 0); P(ctx, "}"); break; } case IR_OP_GET_STRUCT_MEMBER: { struct name_temp t; P(ctx, "%s.%s", R0, member_name(in->struct_member, &t)); break; } case IR_OP_SET_STRUCT_MEMBER: { //struct name_temp t; //bstr name = member_name(in->struct_member, &t); //P(ctx, "%s; %s.%.*s = %s", R0, in->write, BSTR_P(name), R1); abort(); break; } case IR_OP_MAKE_CLOSURE: if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); P(ctx, "{ (void*)%s, %s }", R0, R1); break; case IR_OP_GET_CLOSURE_FN: P(ctx, "(%s) %s.fn", type(ctx, in->result_type), R0); break; case IR_OP_GET_CLOSURE_CTX: P(ctx, "%s.ctx", R0); break; case IR_OP_CONSTRUCT_SLICE: case IR_OP_SLICE: case IR_OP_SLICE_COPY: case IR_OP_SLICE_SET: assert(false); //TODO case IR_OP_GET_SLICE_LENGTH: P(ctx, "%s.len", R0); break; case IR_OP_GET_SLICE_PTR: P(ctx, "(%s)%s.ptr", type(ctx, in->result_type), R0); break; case IR_OP_GET_SLICE_ITEM_PTR: P(ctx, "(assert(%s < %s.len), ((%s)%s.ptr) + %s)", R1, R0, type(ctx, in->result_type), R0, R1); break; case IR_OP_CONSTRUCT_ARRAY: if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); P(ctx, "{ {"); print_reads(ctx, in, 0); P(ctx, "} }"); break; case IR_OP_ARRAY_TO_SLICE: if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); P(ctx, "{ &%s->a[0], %d }", R0, type_array_get_dimension (type_unptr(inst_getuse(in, 0)->result_type))); break; case IR_OP_READ_PTR: P(ctx, "*%s", R0); break; case IR_OP_WRITE_PTR: P(ctx, "*%s = %s", R0, R1); break; case IR_OP_LOAD_CONST: if (inner) P(ctx, "(%s)", type(ctx, in->result_type)); write_const(ctx, *in->const_value); break; case IR_OP_FN_PTR: P(ctx, "%s", def_fn(ctx, in->fn)); break; case IR_OP_CALL: { P(ctx, "%s(", def_fn(ctx, in->fn)); print_reads(ctx, in, 0); P(ctx, ")"); break; } case IR_OP_CALL_PTR: { P(ctx, "%s(", R0); print_reads(ctx, in, 1); P(ctx, ")"); break; } case IR_OP_NEG: P(ctx, "-%s", R0); break; case IR_OP_NOT: if (in->result_type.type == IR_TYPE_tbool) { // C promotes the bool to a larger integer, "~" won't work. P(ctx, "!%s", R0); } else { P(ctx, "~%s", R0); } break; case IR_OP_CONV_INT_SIGN: case IR_OP_CONV_INT_EXT: case IR_OP_CONV_INT_TRUNC: case IR_OP_CONV_TO_G_PTR: case IR_OP_CONV_FROM_G_PTR: P(ctx, "(%s)%s", type(ctx, in->result_type), R0); break; case IR_OP_ADD: case IR_OP_SUB: case IR_OP_MUL: case IR_OP_DIV: case IR_OP_MOD: case IR_OP_AND: case IR_OP_OR: case IR_OP_XOR: case IR_OP_SHIFT_R: case IR_OP_SHIFT_L: case IR_OP_EQ: case IR_OP_NOT_EQ: case IR_OP_CMP_LT: case IR_OP_CMP_GT: case IR_OP_CMP_LT_EQ: case IR_OP_CMP_GT_EQ: { // C integer promotion makes it hard to avoid the cast here. P(ctx, "(%s)(%s %s %s)", type(ctx, in->result_type), R0, optable[in->op], R1); break; } // not applicable case IR_OP_UPVAL_PTR: case IR_OP_UPVAL_CONTEXT: case IR_OP_PHI: assert(false); default: assert(false); } }
static void write_colored(int fd, const char *buffer, size_t length) { if (length < 16) { write_fully(fd, buffer, length); return; } size_t space_offsets[3]; int o = find_space_offsets(buffer, length, space_offsets); if (o == 3) { // Log date and device name write_const(fd, COLOR_DARK_WHITE); write_fully(fd, buffer, space_offsets[0]); // Log process name int pos = 0; for (int i = space_offsets[0]; i < space_offsets[0]; i++) { if (buffer[i] == '[') { pos = i; break; } } write_const(fd, COLOR_CYAN); if (pos && buffer[space_offsets[1]-1] == ']') { write_fully(fd, buffer + space_offsets[0], pos - space_offsets[0]); write_const(fd, COLOR_DARK_CYAN); write_fully(fd, buffer + pos, space_offsets[1] - pos); } else { write_fully(fd, buffer + space_offsets[0], space_offsets[1] - space_offsets[0]); } // Log level size_t levelLength = space_offsets[2] - space_offsets[1]; if (levelLength > 4) { const char *normalColor; const char *darkColor; if (levelLength == 9 && memcmp(buffer + space_offsets[1], " <Debug>:", 9) == 0){ normalColor = COLOR_MAGENTA; darkColor = COLOR_DARK_MAGENTA; } else if (levelLength == 11 && memcmp(buffer + space_offsets[1], " <Warning>:", 11) == 0){ normalColor = COLOR_YELLOW; darkColor = COLOR_DARK_YELLOW; } else if (levelLength == 9 && memcmp(buffer + space_offsets[1], " <Error>:", 9) == 0){ normalColor = COLOR_RED; darkColor = COLOR_DARK_RED; } else if (levelLength == 10 && memcmp(buffer + space_offsets[1], " <Notice>:", 10) == 0) { normalColor = COLOR_GREEN; darkColor = COLOR_DARK_GREEN; } else { goto level_unformatted; } write_string(fd, darkColor); write_fully(fd, buffer + space_offsets[1], 2); write_string(fd, normalColor); write_fully(fd, buffer + space_offsets[1] + 2, levelLength - 4); write_string(fd, darkColor); write_fully(fd, buffer + space_offsets[1] + levelLength - 2, 1); write_const(fd, COLOR_DARK_WHITE); write_fully(fd, buffer + space_offsets[1] + levelLength - 1, 1); } else { level_unformatted: write_const(fd, COLOR_RESET); write_fully(fd, buffer + space_offsets[1], levelLength); } write_const(fd, COLOR_RESET); write_fully(fd, buffer + space_offsets[2], length - space_offsets[2]); } else { write_fully(fd, buffer, length); } }
static void color_separator(int fd) { write_const(fd, COLOR_DARK_WHITE "--" COLOR_RESET "\n"); }
static void plain_separator(int fd) { write_const(fd, "--\n"); }