int* BinaryPath(TreeNode *t, List *l,char *input, int size_S, int* size_R){ int i=0, j=0, k=0, size=0; int *R_Path=(int*)malloc(sizeof(int)*MAX_LENGTH); while(i<size_S){ size = 0; int *code=code_return(l, input[i++], &size); if(code!=NULL){ for(j=0;j<=size;j++){ R_Path[k++] = code[j]; } } } *size_R=k; return R_Path; }
void code_tac(FILE *file, RegDesc *registers, Tac *current) { switch (current->op) { case TAC_BEGINPROGRAM: code_main(file); code_begin_function(file, current->result); break; case TAC_BEGINFUNCTION: code_begin_function(file, current->result); break; case TAC_ENDFUNCTION: code_end_function(file, registers); break; case TAC_RETURN: code_return(file, registers, current->result); break; case TAC_ENDPROGRAM: code_end_function(file, registers); break; case TAC_GOTO: code_jump(file, registers, JUMP, current->location->result, NULL); break; case TAC_IFZ: code_jump(file, registers, JUMP_NE, current->location->result, current->condition); break; case TAC_IFNZ: code_jump(file, registers, JUMP_E, current->location->result, current->condition); break; case TAC_ADD: code_binary(file, registers, ADD, current->result, current->operand1, current->operand2); break; case TAC_SUBTRACT: code_binary(file, registers, SUBTRACT, current->result, current->operand1, current->operand2); break; case TAC_MULTIPLY: code_binary(file, registers, MULTIPLY, current->result, current->operand1, current->operand2); break; case TAC_DIVIDE: code_binary(file, registers, DIVIDE, current->result, current->operand1, current->operand2); break; case TAC_NOT: //FIX 5-19-2011 - INVERT is not what we want - thats a bit wise invert //Since we are using booleans, just xor them //code_unary(file, registers, INVERT, current->result, current->operand1); code_binary(file, registers, LOGIC_XOR, current->result, current->operand1, symbol_one); break; case TAC_NEGATIVE: code_unary(file, registers, NEGATE, current->result, current->operand1); break; case TAC_AND: code_binary(file, registers, LOGIC_AND, current->result, current->operand1, current->operand2); break; case TAC_OR: code_binary(file, registers, LOGIC_OR, current->result, current->operand1, current->operand2); break; case TAC_MOD: code_binary(file, registers, ATT_MOD, current->result, current->operand1, current->operand2); break; case TAC_COPY: code_copy(file, registers, current->result, current->operand1); break; case TAC_ARG: code_arg(file, registers, current->result); break; case TAC_CALL://On a TAC call, the function is the operand, and the return is the result code_call(file, registers, current->operand1, current->result); break; case TAC_LABEL: debug("Code_Label - Symbol: %s", symbol_to_string(current->result)); code_flush_all(file, registers); fprintf(file, "%s:\n", current->result->name); break; case TAC_GT: code_compare(file, registers, IS_GREATER, current->result, current->operand1, current->operand2); break; case TAC_LT: code_compare(file, registers, IS_LESS, current->result, current->operand1, current->operand2); break; case TAC_GTE: code_compare(file, registers, IS_GREATER_EQUAL, current->result, current->operand1, current->operand2); break; case TAC_LTE: code_compare(file, registers, IS_LESS_EQUAL, current->result, current->operand1, current->operand2); break; case TAC_EQUAL: code_compare(file, registers, IS_EQUAL, current->result, current->operand1, current->operand2); break; case TAC_NOTEQUAL: code_compare(file, registers, IS_NOT_EQUAL, current->result, current->operand1, current->operand2); break; case TAC_VARIABLE: //do nothing break; case TAC_NOP: //Do nothing break; default: die("Unrecognized TAC: %d", current->op); break; } }