F diff --git a/src/backend/asm/intel/intel_asm.c b/src/backend/asm/intel/intel_asm.c --- a/src/backend/asm/intel/intel_asm.c +++ b/src/backend/asm/intel/intel_asm.c}void reserve_stack_space(struct Compile_Data_Intel_Asm *compile_data,int size){+ compile_data->offset_from_stack_frame+=size;push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RSP),}void release_stack_space(struct Compile_Data_Intel_Asm *compile_data,int size){+ compile_data->offset_from_stack_frame-=size;push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RSP),size=(int)get_type_size(object->type);reserve_stack_space(compile_data,size);- compile_data->offset_from_stack_frame+=size;+ //compile_data->offset_from_stack_frame+=size;ret=get_intel_asm_stack_offset(compile_data->offset_from_stack_frame);object->location=(struct Location*)ret;struct Intel_Asm_Memory_Location *ret;size=(int)get_type_size(object->type);- compile_data->offset_from_stack_frame+=size;- ret=get_intel_asm_stack_offset(compile_data->offset_from_stack_frame);+ ret=get_intel_asm_stack_offset(-size);object->location=(struct Location*)ret;return ret;F diff --git a/src/backend/asm/intel/intel_compile.c b/src/backend/asm/intel/intel_compile.c --- a/src/backend/asm/intel/intel_compile.c +++ b/src/backend/asm/intel/intel_compile.c[OP_COMMA]=(map_entry)compile_comma_expression_to_intel_asm,[OP_ADDITION]=(map_entry)compile_addition_to_intel_asm,[OP_POINTER_ADDITION]=(map_entry)compile_pointer_addition_to_intel_asm,- [OP_SUBTRACTION]=(map_entry)compile_subscript_to_intel_asm,- [OP_MUL]=(map_entry)compile_mul_assign_to_intel_asm,+ [OP_SUBTRACTION]=(map_entry)compile_subtraction_to_intel_asm,+ [OP_MUL]=(map_entry)compile_multiplication_to_intel_asm,[OP_DIV]=(map_entry)compile_div_assign_to_intel_asm,[OP_REMAINDER]=(map_entry)compile_remainder_to_intel_asm,[OP_COND]=(map_entry)compile_conditional_expression_to_intel_asm,{int current_register;ssize_t i;+ int size_on_stack_for_arguments=0;+ int size_of_stack_padding=0;- /*at first pass we store the memory class stuff on the stack*/+ /*stack must be aligned to 16 bytes*/+ for(i=call->number_of_arguments-1,current_register=0;i>=0;--i)+ {+ if(get_expression_value_size(call->arg_list[i]->value)<=8 && current_register<6)+ {+ ++current_register;+ }else+ {+ size_on_stack_for_arguments+=get_expression_value_size(call->arg_list[i]->value);+ }+ }++ size_of_stack_padding=(16-(compile_data->offset_from_stack_frame+size_on_stack_for_arguments)%16)%16;+ if(size_of_stack_padding != 0)+ reserve_stack_space(compile_data,size_of_stack_padding);+++ /*at second pass we store the memory class stuff on the stack*/for(i=call->number_of_arguments-1,current_register=0;i>=0;--i){if(get_expression_value_size(call->arg_list[i]->value)<=8 && current_register<6)compile_ast_to_intel_asm(compile_data,(struct AST*)call->id);- push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));-- push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_CALL));+ push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RDX));++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(+ get_intel_asm_register(INTEL_ASM_REGISTER_EAX),+ get_intel_asm_register(INTEL_ASM_REGISTER_EAX),+ INTEL_ASM_OP_XOR));++ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),INTEL_ASM_OP_CALL));+push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));+++ /*'unalign' the stack*/+ if(size_of_stack_padding != 0)+ release_stack_space(compile_data,size_of_stack_padding);++ release_stack_space(compile_data,size_on_stack_for_arguments);}void compile_constant_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Constant *constant){ssize_t i;struct Type_Function *type;enum Intel_Asm_Registers reg;+ int size_on_stack_for_arguments=0;type=(struct Type_Function*)def->function->type;/*anotate the function args*/+++ /*memory class stuff*/for(i=type->number_of_arguments-1,current_register=0;i>=0;--i){if(get_type_size(type->arguments[i]->object->type)<=8 && current_register<6)++current_register;}else{+ size_on_stack_for_arguments+=get_type_size(type->arguments[i]->object->type);reserve_stack_space_for_function_argument(compile_data,type->arguments[i]->object);}}+ /*push the things on the registers to stack*/for(i=type->number_of_arguments-1,current_register=0;i>=0;--i){if(get_type_size(type->arguments[i]->object->type)<=8 && current_register<6)}void compile_addition_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin){- enum Intel_Asm_Registers ax;- enum Intel_Asm_Registers dx;-- compile_ast_to_intel_asm(compile_data,(struct AST*)bin->left);- compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);-- ax=rvalue_to_ax(compile_data,bin->right->value);- dx=rvalue_to_dx(compile_data,bin->left->value);-- push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(ax),get_intel_asm_register(dx),INTEL_ASM_OP_ADD));- push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));+ compile_simple_bin_inner(compile_data,bin,INTEL_ASM_OP_ADD);+ }+ void compile_subtraction_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin)+ {+ compile_simple_bin_inner(compile_data,bin,INTEL_ASM_OP_SUB);}void compile_pointer_addition_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin){}void compile_multiplication_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin){- push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_NOP));+ compile_mul_div_inner(compile_data,bin,INTEL_ASM_OP_MUL);}void compile_division_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin){- push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_NOP));+ compile_mul_div_inner(compile_data,bin,INTEL_ASM_OP_DIV);}void compile_remainder_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin){push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(ax),get_intel_asm_register(INTEL_ASM_REGISTER_CL),op));push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));}+ void compile_simple_bin_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin,enum Intel_Asm_Instruction_Type op)+ {+ enum Intel_Asm_Registers ax;+ enum Intel_Asm_Registers dx;++ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->left);+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);++ dx=rvalue_to_dx(compile_data,bin->right->value);+ ax=rvalue_to_ax(compile_data,bin->left->value);++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(ax),get_intel_asm_register(dx),op));+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));++ }+ void compile_mul_div_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin,enum Intel_Asm_Instruction_Type op)+ {+ enum Intel_Asm_Registers ax;+ enum Intel_Asm_Registers dx;++ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->left);+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);++ ax=rvalue_to_ax(compile_data,bin->right->value);+ dx=rvalue_to_dx(compile_data,bin->left->value);++ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_register(dx),op));+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));+ }#endifF diff --git a/src/backend/asm/intel/intel_compile.h b/src/backend/asm/intel/intel_compile.h --- a/src/backend/asm/intel/intel_compile.h +++ b/src/backend/asm/intel/intel_compile.hvoid compile_comma_expression_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);void compile_addition_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);+ void compile_subtraction_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);void compile_pointer_addition_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);void compile_multiplication_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);void compile_division_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);void compile_postfix_inc_dec_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary,enum Intel_Asm_Instruction_Type op);void compile_comparison_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin,enum Intel_Asm_Instruction_Type op);void compile_shift_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin,enum Intel_Asm_Instruction_Type op);+ void compile_simple_bin_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin,enum Intel_Asm_Instruction_Type op);+ void compile_mul_div_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin,enum Intel_Asm_Instruction_Type op);#endifF diff --git a/src/backend/asm/intel/intel_instruction.c b/src/backend/asm/intel/intel_instruction.c --- a/src/backend/asm/intel/intel_instruction.c +++ b/src/backend/asm/intel/intel_instruction.c[INTEL_ASM_OP_ADD]=(map_entry)save_intel_asm_binary_instruction,[INTEL_ASM_OP_SUB]=(map_entry)save_intel_asm_binary_instruction,[INTEL_ASM_OP_MOV]=(map_entry)save_intel_asm_binary_instruction,- [INTEL_ASM_OP_MUL]=(map_entry)save_intel_asm_binary_instruction,+ [INTEL_ASM_OP_MUL]=(map_entry)save_intel_asm_unary_instruction,+ [INTEL_ASM_OP_DIV]=(map_entry)save_intel_asm_unary_instruction,[INTEL_ASM_OP_JMP]=(map_entry)save_intel_asm_jump_instruction,[INTEL_ASM_OP_TEST]=(map_entry)save_intel_asm_binary_instruction,[INTEL_ASM_OP_CMP]=(map_entry)save_intel_asm_binary_instruction,[INTEL_ASM_OP_ADD]="ADD",[INTEL_ASM_OP_SUB]="SUB",[INTEL_ASM_OP_MOV]="MOV",- [INTEL_ASM_OP_MUL]="MOV",[INTEL_ASM_OP_TEST]="TEST",[INTEL_ASM_OP_AND]="AND",[INTEL_ASM_OP_XOR]="XOR",[INTEL_ASM_OP_POP]="POP",[INTEL_ASM_OP_PUSH]="PUSH",[INTEL_ASM_OP_CALL]="CALL",+ [INTEL_ASM_OP_MUL]="MUL",+ [INTEL_ASM_OP_DIV]="DIV",[INTEL_ASM_OP_SETL]="SETL",[INTEL_ASM_OP_SETE]="SETE",[INTEL_ASM_OP_SETNE]="SETNE",F diff --git a/src/backend/asm/intel/intel_instruction.hh b/src/backend/asm/intel/intel_instruction.hh --- a/src/backend/asm/intel/intel_instruction.hh +++ b/src/backend/asm/intel/intel_instruction.hhINTEL_ASM_OP_SUB,INTEL_ASM_OP_MOV,INTEL_ASM_OP_MUL,+ INTEL_ASM_OP_DIV,INTEL_ASM_OP_JMP,INTEL_ASM_OP_TEST,INTEL_ASM_OP_CMP,F diff --git a/src/backend/asm/intel/intel_location.c b/src/backend/asm/intel/intel_location.c --- a/src/backend/asm/intel/intel_location.c +++ b/src/backend/asm/intel/intel_location.c}void save_intel_asm_by_stack_offset_location(struct Intel_Asm_Memory_Location_By_Stack_Offset *sp,FILE *out){- fprintf(out,"%s [RBP-%d]",memory_size_map[sp->size],sp->offset);+ if(sp->offset>=0)+ fprintf(out,"%s [RBP-%d]",memory_size_map[sp->size],sp->offset);+ else+ fprintf(out,"%s [RBP+%d]",memory_size_map[sp->size],sp->offset);}void save_intel_asm_stack_offset_location(struct Intel_Asm_Memory_Location_Stack_Offset *sp,FILE *out){- fprintf(out,"RBP-%d",sp->offset);+ if(sp->offset>=0)+ fprintf(out,"RBP-%d",sp->offset);+ else+ fprintf(out,"RBP+%d",sp->offset);}void save_intel_asm_by_register_location(struct Intel_Asm_Memory_Location_By_Register *reg,FILE *out){