int main (int argc, char** argv) { if (argc != 2) { puts("Usage: cc <file>"); return 1; } output = fopen("a.s", "w"); lex_init(argv[1], 256); sym_init(256); //No arrays? Fine! A 0xFFFFFF terminated string of null terminated strings will do. //A negative-terminated null-terminated strings string, if you will char* std_fns = "malloc\0calloc\0free\0atoi\0fopen\0fclose\0fgetc\0ungetc\0feof\0fputs\0fprintf\0puts\0printf\0" "isalpha\0isdigit\0isalnum\0strlen\0strcmp\0strchr\0strcpy\0strdup\0\xFF\xFF\xFF\xFF"; //Remember that mini-c is typeless, so this is both a byte read and a 4 byte read. //(char) 0xFF == -1, (int) 0xFFFFFF == -1 while (std_fns[0] != -1) { new_fn(strdup(std_fns)); std_fns = std_fns+strlen(std_fns)+1; } program(); return errors != 0; }
driver(boost::filesystem::path const& path) : name_{path.stem().string()} , library_{path.string()} { new_fn_t new_fn; library_.require("k_driver_new", new_fn); library_.require("k_driver_free", free_fn); impl_ = new_fn(); }
ot_u8 vl_new(vlFILE** fp_new, vlBLOCK block_id, ot_u8 data_id, ot_u8 mod, ot_uint max_length, id_tmpl* user_id) { #if (OT_FEATURE(VLNEW) == ENABLED) vaddr header; sub_vaddr search_fn; sub_new new_fn; /// 1. Authenticate, when it's not a su call if (user_id != NULL) { if ( auth_check(VL_ACCESS_USER, VL_ACCESS_W, user_id) == 0 ) { return 0x04; } } /// 2. Make sure the file is not already there block_id--; switch (block_id) { case 0: search_fn = &sub_gfb_search; new_fn = &sub_gfb_new; break; case 1: search_fn = &sub_isfs_search; new_fn = &sub_isfs_new; break; case 2: search_fn = &sub_isf_search; new_fn = &sub_isf_new; break; default: return 0xFF; } header = search_fn(data_id); if (header != NULL_vaddr) { return 0x02; } *fp_new = new_fn(data_id, mod, max_length); if (*fp_new == NULL) { return 0x06; } return 0; #else return 255; #endif }
void decl (int kind) { //A C declaration comes in three forms: // - Local decls, which end in a semicolon and can have an initializer. // - Parameter decls, which do not and cannot. // - Module decls, which end in a semicolon unless there is a function body. bool fn = false; bool fn_impl = false; int local; next(); while (try_match("*")) ; //Owned (freed) by the symbol table char* ident = strdup(buffer); next(); //Functions if (try_match("(")) { if (kind == decl_module) new_scope(); //Params if (waiting_for(")")) do { decl(decl_param); } while (try_match(",")); match(")"); new_fn(ident); fn = true; //Body if (see("{")) { require(kind == decl_module, "a function implementation is illegal here\n"); fn_impl = true; function(ident); } //Add it to the symbol table } else { if (kind == decl_local) { local = new_local(ident); } else (kind == decl_module ? new_global : new_param)(ident); } //Initialization if (see("=")) require(!fn && kind != decl_param, fn ? "cannot initialize a function\n" : "cannot initialize a parameter\n"); if (kind == decl_module) { fputs(".section .data\n", output); if (try_match("=")) { if (token == token_int) fprintf(output, "%s: .quad %d\n", ident, atoi(buffer)); else error("expected a constant expression, found '%s'\n"); next(); //Static data defaults to zero if no initializer } else if (!fn) fprintf(output, "%s: .quad 0\n", ident); fputs(".section .text\n", output); } else if (try_match("=")) { expr(0); fprintf(output, "mov dword ptr [ebp%+d], eax\n", offsets[local]); } if (!fn_impl && kind != decl_param) match(";"); }