////////////////////////////////////////////////////////////////////////// // EXPORTED FUNCTIONS ////////////////////////////////////////////////////////////////////////// __declspec(dllexport) BYTE* CompileBuffer(BYTE* Buffer, char* Source, DWORD BufferSize, DWORD* CompiledSize){ YY_BUFFER_STATE state; BYTE* ret = NULL; if(Buffer==NULL){ if(CompiledSize)*CompiledSize = 0; return NULL; } state = yy_scan_bytes(Buffer, BufferSize); lineno=1; yyparse(); yy_delete_buffer(state); if(errorCheck()) goto finish_error; weedSCRIPTCOLLECTION(thescriptcollection); if(errorCheck()) goto finish_error; symSCRIPTCOLLECTION(thescriptcollection); if(errorCheck()) goto finish_error; ret = opcodeSCRIPTCOLLECTION(thescriptcollection, Source, CompiledSize); if(errorCheck()) goto finish_error; FinalCleanup(); return ret; finish_error: if(ret!=NULL) free(ret); *CompiledSize = 0; FinalCleanup(); return NULL; }
int main(int argc, char **argv) { /* debugging */ setbuf(stdout, NULL); setbuf(stderr, NULL); if(argc < 3){ printf("Usage: u1comp <infile> <outfile>\n"); //exit(1); printf("Interactive mode!\n"); interactiveMode = 1; // make yyparse() abort after '\n' while (1) { printf("> "); yyparse(); #if 1 printf("// Prettyprinting...\n"); prettySCRIPTCOLLECTION(thescriptcollection); errorCheck(); #endif } } else { if(freopen(argv[1],"r",stdin) != NULL){ printf("// Parsing...\n"); lineno=1; yyparse(); /* Build AST */ } else { printf("Couldn't open file %s\n",argv[1]); exit(1); } } errorCheck(); printf("// Weeding...\n"); weedSCRIPTCOLLECTION(thescriptcollection); errorCheck(); printf("// Symbolchecking...\n"); symSCRIPTCOLLECTION(thescriptcollection); errorCheck(); printf("// Typechecking...\n"); typeSCRIPTCOLLECTION(thescriptcollection); errorCheck(); #if 0 printf("// Prettyprinting...\n"); prettySCRIPTCOLLECTION(thescriptcollection); errorCheck(); #endif printf("// Resource calculations...\n"); resSCRIPTCOLLECTION(thescriptcollection); errorCheck(); printf("// Coding...\n"); codeSCRIPTCOLLECTION(thescriptcollection); errorCheck(); printf("// Emitting (asm)...\n"); emitSCRIPTCOLLECTION(thescriptcollection); errorCheck(); printf("// Assembling...\n"); AssembleFile(argv[2]); return 0; }