Skip to content
Snippets Groups Projects
Commit ff196e06 authored by Clemens Paumgarten's avatar Clemens Paumgarten
Browse files

fixed warnings

parent 95cc7f06
No related branches found
No related tags found
No related merge requests found
......@@ -111,7 +111,9 @@ int main(int argc, char *argv[]) {
}
struct mcc_tac *tac = mcc_tac_build(prog,symbol_table);
tac_print(tac, stdout);
mcc_tac_print(tac, out);
mcc_symbol_table_delete_table(symbol_table);
mcc_symbol_table_delete_error_collector(ec);
......
......@@ -6,8 +6,6 @@
#include "mcc/symbol_table_print.h"
#include "mcc/tac.h"
static const char *tac_type(enum mcc_tac_operation type);
void tac_print(struct mcc_tac *tac, FILE *out);
void mcc_tac_print(struct mcc_tac *tac, FILE *out);
#endif
......@@ -671,7 +671,7 @@ int mcc_symbol_table_validate_statement_return(
}else{
if(symbol_table->parent != NULL){
struct mcc_symbol_table *parent = symbol_table->parent;
int result = mcc_symbol_table_validate_statement_return(
mcc_symbol_table_validate_statement_return(
func_def -> statement,
return_type,
parent,
......
......@@ -85,10 +85,31 @@ int mcc_tac_add_entry(struct mcc_tac *tac, struct mcc_tac_entry *te) {
int mcc_tac_create_and_add_new_entry(
enum mcc_tac_operation tac_op,
char *arg1,
char *arg2,
char *result,
char *arg1_temp,
char *arg2_temp,
char *result_temp,
struct mcc_tac *tac) {
// this way every string is stored in heap, easier to free
char *arg1 = NULL;
char *arg2 = NULL;
char *result = NULL;
if (arg1_temp != NULL) {
arg1 = malloc(sizeof(arg1_temp));
*arg1 = *arg1_temp;
}
if (arg2_temp != NULL) {
arg2 = malloc(sizeof(arg2_temp));
*arg2 = *arg2_temp;
}
if (result_temp != NULL) {
result = malloc(sizeof(result));
*result = *result;
}
struct mcc_tac_entry *te = mcc_tac_new_entry(tac_op, arg1, arg2, result);
return mcc_tac_add_entry(tac, te);
......@@ -195,13 +216,12 @@ enum mcc_tac_operation mcc_convert_ast_type_to_tac_unary(enum mcc_ast_data_type
case MCC_AST_DATA_TYPE_INT:
return MCC_TAC_MINUS_INT_UN;
case MCC_AST_DATA_TYPE_BOOL:
return MCC_TAC_PARAM_BOOL;
case MCC_TAC_MINUS_FLOAT_UN:
return MCC_TAC_NOT;
case MCC_AST_DATA_TYPE_FLOAT:
return MCC_TAC_MINUS_FLOAT_UN;
default:
break;
return MCC_TAC_UNKNOWN;
}
return MCC_TAC_UNKNOWN;
}
......
......@@ -89,7 +89,7 @@ void mcc_tac_parse_expression(struct mcc_ast_expression *expression, struct mcc_
tac->current_symbol_table);
enum mcc_tac_operation op = mcc_convert_ast_type_to_tac_ident(type);
if(type != MCC_TAC_UNKNOWN) {
if(op != MCC_TAC_UNKNOWN) {
char *arg1 = mcc_tac_new_return_function_name(result);
mcc_tac_create_and_add_new_entry_temp(op, arg1, NULL, tac);
}
......@@ -122,7 +122,7 @@ void mcc_tac_parse_expression(struct mcc_ast_expression *expression, struct mcc_
if (is_array) {
int number_of_digits = mcc_get_number_of_digits(array_size);
char *arg1 = malloc(sizeof(char) * number_of_digits + 1);
sprintf(arg1, "%d", array_size);
sprintf(arg1, "%ld", array_size);
}
// char *arg1 = tac->last_temporary;
......
......@@ -24,6 +24,7 @@ static const char *tac_type(enum mcc_tac_operation type)
case MCC_TAC_INT:
case MCC_TAC_INT_LITERAL:
case MCC_TAC_MINUS_INT_BIN:
case MCC_TAC_MINUS_INT_UN:
case MCC_TAC_PLUS_INT:
case MCC_TAC_MUL_INT:
case MCC_TAC_DIV_INT:
......@@ -78,11 +79,11 @@ static const char *tac_type(enum mcc_tac_operation type)
case MCC_TAC_PARAM_STRING_ARR: return "string_array";
case MCC_TAC_PARAM_POP_FLOAT_ARR:
case MCC_TAC_PARAM_FLOAT_ARR: return "float_arr";
default: return "ERROR";
}
return "ERROR";
}
void tac_print(struct mcc_tac *tac, FILE *out)
void mcc_tac_print(struct mcc_tac *tac, FILE *out)
{
fprintf(out,"------------------------------\n");
fprintf(out,"- TAC -\n");
......@@ -243,4 +244,4 @@ void tac_print(struct mcc_tac *tac, FILE *out)
fprintf(out,"ERROR\n");
}
}
}
\ No newline at end of file
}
int mcc_get_number_of_digits(int input) {
int digits = 0;
......@@ -9,4 +7,4 @@ int mcc_get_number_of_digits(int input) {
}
return digits;
}
\ No newline at end of file
}
......@@ -4,10 +4,8 @@ int main() {
int max;
a = (1 + 1);
a = -a;
b = func_a(2);
a = 2;
b = 5;
if (a < b) {
max = b;
......@@ -15,17 +13,5 @@ int main() {
max = a;
}
while (a < b) {
a = a + 1;
}
return 0;
}
int func_a (int a) {
int b;
b = 3;
return b;
return max;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment