le compilateur super performant
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

yacc_util.c 1.4KB

123456789101112131415161718192021222324252627282930
  1. #include "yacc_util.h"
  2. void write_affectation(SymbolTable* symbol_table, InstructionTable *instruction_table, char* symbol_dest, SymbolItem* src) {
  3. mark_symbol_initialized(symbol_table, symbol_dest);
  4. SymbolItem *dest = get_symbol_item(symbol_table, symbol_dest);
  5. add_instruction(instruction_table, COP, src->address, dest->address, 0);
  6. }
  7. const SymbolItem* write_op(SymbolTable* symbol_table, InstructionTable *instruction_table, Instruction instruction, SymbolItem *op1, SymbolItem *op2) {
  8. const SymbolItem* dest = add_temp_symbol(symbol_table, TYPE_INT);
  9. add_instruction(instruction_table, instruction, dest->address, op1->address, op2->address);
  10. return dest;
  11. }
  12. const SymbolItem* write_negation(SymbolTable* symbol_table, InstructionTable *instruction_table, SymbolItem *op2) {
  13. // Create temp variable with 0
  14. const SymbolItem* op1 = init_temp_symbol(symbol_table, instruction_table, 0);
  15. const SymbolItem* dest = add_temp_symbol(symbol_table, TYPE_INT);
  16. // Make the 0 - variable operation
  17. add_instruction(instruction_table, SOU, dest->address, op1->address, op2->address);
  18. return dest;
  19. }
  20. const SymbolItem* init_temp_symbol(SymbolTable* symbol_table, InstructionTable *instruction_table, int constant) {
  21. const SymbolItem* dest = add_temp_symbol(symbol_table, TYPE_INT);
  22. add_instruction(instruction_table, AFC, dest->address, constant, 0);
  23. return dest;
  24. }