Compiler :: Compiler (FILE* c_file, LogHTML& log, FILE* asm_file): code (), root ({ Block }) { log.setFontColor ("white"); log.setSize (100); log.setColor ("blue"); log.output ("========== Build started: DeerC %d.%d ==========\n", 1, 0); log.setColor ("red"); clock_t start = clock (); LexicialAnalyzer lexicial_analyzer (c_file, code); //Preprocessor preprocessor (code, log); SyntaxAnalyzer syntax_analyzer (root, code, log); //SemanticAnalyzer semantic_analyzer (root, log); //Optimizer optimizer (root); CodeGeneration code_generation (root, asm_file, 1); clock_t end = clock (); log.setColor ("blue"); RenderTree (root, "GCD.dot"); log.output ("Build started on: %f\n", (float) start / CLOCKS_PER_SEC); log.output ("Build ended on: %f\n\n", (float) end / CLOCKS_PER_SEC); log.output ("========== Build finished ==========\n"); log.out (); }
void code_generation(ast a, FILE *f) { int condn =0; Node temp_node; if(a->temp->children[0]==NULL) { while(!condn) { if(!strcmp(a->temp->info.token_name,"TK_STOP") && !remaining(a)) { return ; } if(a->temp->position_children+1<a->temp->parent->number_children) { a->temp=a->temp->parent->children[a->temp->position_children+1]; condn =1; } else { a->temp= a->temp->parent; } } code_generation(a,f); } else { if(!strcmp(a->temp->info.node_symbol,"program")) { temp_node=a->temp; statements(a,f); a->temp=temp_node; a->temp=a->temp->children[0]; } else { a->temp=a->temp->children[0]; } code_generation(a,f); } }
void assembly_code(ast a , SPTR s, FILE * f) { fprintf(f,".MODEL TINY\n.STACK\n.DATA\n"); printf(".MODEL TINY\n.STACK\n.DATA\n"); declaration_var (s,f); fseek(f,0,SEEK_END); fprintf(f,".CODE\n.STARTUP\n"); printf(".CODE\n.STARTUP\n"); code_generation(a,f); fprintf(f,".EXIT\nEND\n"); printf(".EXIT\nEND\n"); fclose(f); }