// the token stream is currently in a file, and must be completely loaded into RAM // -- either into the current workspace, or into a malloc int8_t ld_tokenstream() { int i, j; uint8_t *p; // open the file and read **the entire thing** in binary mode (size = num_toks) wrksp_top = wrksp + wrk_rem - idxidx * 4 - num_toks; infd = qcc_open_r("hi1", 1); // inf_infd = qcc_open_r(inout_fnames[??], 1); // HIHI! if num_toks will not fit in the wrksp with a little left for processing, then malloc it! // else p = wrksp_top; i = j = num_toks; // standard read loop while (i != 0) { i = read(infd, p, j); p += i; j -= i; } *p = TOK_ENDOFBUF; qcc_close (infd); outf_exists = 0; // reset the flag forever (unless I need to dump line_nums??) infd = outfd = -1; // HIHI!! if a buffer gets created -- store the pointer where? -- and return a 1 return 0; }
// compile a single C source file int do_c_compile(uint8_t *fname) { // open the source file (as text, for reading) int in = qcc_open_r ((char *) fname, 0); if (in < 0) return QCC_ERR_FNOTFOUND; // XXX: get a source file version number and timestamp, to include as extra info in the object file preprocess (in, fname); // preprocessing: includes, macros, #ifs, etc. // if (tccg_output_type == TCC_OUTPUT_PREPROCESS) // dump_cpp_output(); // return 0; tokenize(); // take the messy output from the preprocessor and tokenize it prettily prototypes(); // parse funct/struct/union/enum/typedef info at global scope syntax_check(); // hopefully a complete and final check on syntax, one function at a time? if (total_errs != 0) return 1; // expression_simplification(); -- do dead code elimination // tcg_frontend_conversion(); -- convert tokens into a superset of TCG frontend code // Note: tcg can only handle function returns in a single register, // but the C99 spec requires (??) functions to be able to return complete structs, long doubles, 64bit values, etc. // so this frontend conversion cannot be to pure tcg, I don't think -- unless there is a clever workaround for the return value thing. // XXX: -- some function needs to build the symtable/bss/data/rodata mem buffers? // emit_to_target needs to look up symbols -- what format of symbol is nicest for that? // this next function is a generic entrypoint for the config-selected specific target CPU emit_to_target(); // convert to binary -- create the .text mem buffer // XXX: then need a function that packs these mem buffers at the upper end of the workspace and lowers wrk_rem // (and stores info about where all of it is located, of course) return 0; }