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.creserve_stack_space(compile_data,size);return get_intel_asm_stack_offset(size);}+ void rvalue_to_register(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value,enum Intel_Asm_Registers reg)+ {+ size_t value_size;+ value_size=get_expression_value_size(value);+ wonky_assert(value_size<=8);++ push_intel_asm_instruction(compile_data,intel_asm_get_pop(reg));+ if(value->type==VALUE_LVALUE)+ {+ push_intel_asm_instruction(+ compile_data,+ get_intel_asm_binary_instruction(+ get_intel_asm_register(reg),+ get_intel_asm_by_register(reg),+ INTEL_ASM_OP_MOV+ )+ );+ }++ }void release_value_from_stack(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value){release_stack_space(compile_data,get_expression_value_size(value));function->location=(struct Location*)location;}+ void intel_asm_finish_comparison(struct Compile_Data_Intel_Asm *compile_data,enum Intel_Asm_Instruction_Type op)+ {+ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_AL),op));++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_AH),get_intel_asm_register(INTEL_ASM_REGISTER_AH),INTEL_ASM_OP_XOR));+ }void export_function_definition(struct Compile_Data_Intel_Asm *compile_data,struct AST_Function_Definition *function){wonky_assert(function!=NULL && function->type==ST_FUNCTION_DEFINITION);F diff --git a/src/backend/asm/intel/intel_asm.h b/src/backend/asm/intel/intel_asm.h --- a/src/backend/asm/intel/intel_asm.h +++ b/src/backend/asm/intel/intel_asm.hvoid intel_asm_memory_location_to_rax(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Memory_Location *location);struct Intel_Asm_Memory_Location* reserve_space_for_value_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value);+ void rvalue_to_register(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value,enum Intel_Asm_Registers reg);void release_value_from_stack(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value);struct Intel_Asm_Memory_Location* reserve_stack_space_for_object(struct Compile_Data_Intel_Asm *compile_data,struct Object *object);void intel_asm_anotate_denoted(struct Denoted *denoted,struct Compile_Data_Intel_Asm *compile_data);void intel_asm_anotate_function(struct Compile_Data_Intel_Asm *compile_data,struct Denoted_Function *func);++ void intel_asm_finish_comparison(struct Compile_Data_Intel_Asm *compile_data,enum Intel_Asm_Instruction_Type op);+void export_function_definition(struct Compile_Data_Intel_Asm *compile_data,struct AST_Function_Definition *function);void export_object_definition(struct Compile_Data_Intel_Asm *compile_data,struct AST_Object_Declaration *object);void import_function_definition(struct Compile_Data_Intel_Asm *compile_data,struct AST_Function_Declaration *function);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{struct Scope *current_scope;- compile_ast_to_intel_asm(compile_data,ret->return_expression);++ if(ret->return_expression!=NULL)+ {+ compile_ast_to_intel_asm(compile_data,ret->return_expression);+ rvalue_to_register(compile_data,((struct AST_Expression*)ret->return_expression)->value,INTEL_ASM_REGISTER_RAX);+ }for(current_scope=ret->checkpoint;current_scope!=NULL;current_scope=current_scope->parent)if(current_scope->type==BLOCK_SCOPE)release_stack_space_for_whole_block_intel_asm(compile_data,(struct Normal_Scope*)ret->checkpoint);}- push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));+push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RBP));push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_RET));{compile_ast_to_intel_asm(compile_data,(struct AST*)bin->left);compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);- push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));- push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_DX));- push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(intel_asm_get_ax_register(),intel_asm_get_dx_register(),INTEL_ASM_OP_ADD));- push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));+ rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);+ rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);+ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RAX),get_intel_asm_register(INTEL_ASM_REGISTER_RDX),INTEL_ASM_OP_ADD));+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));}void compile_pointer_addition_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin){compile_ast_to_intel_asm(compile_data,(struct AST*)bin->left);compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);- push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RDX));+ rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RDX);push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));push_intel_asm_instruction(compile_data,}void compile_less_eq_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_ast_to_intel_asm(compile_data,(struct AST*)bin->left);+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);++ rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);+ rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),get_intel_asm_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_CMP));+ intel_asm_finish_comparison(compile_data,INTEL_ASM_OP_SETBE);+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));}void compile_greater_eq_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_ast_to_intel_asm(compile_data,(struct AST*)bin->left);+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);++ rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);+ rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),get_intel_asm_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_CMP));+ intel_asm_finish_comparison(compile_data,INTEL_ASM_OP_SETAE);+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));}void compile_less_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_ast_to_intel_asm(compile_data,(struct AST*)bin->left);+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);++ rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);+ rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),get_intel_asm_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_CMP));+ intel_asm_finish_comparison(compile_data,INTEL_ASM_OP_SETL);+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));}void compile_greater_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_ast_to_intel_asm(compile_data,(struct AST*)bin->left);+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);++ rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);+ rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),get_intel_asm_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_CMP));+ intel_asm_finish_comparison(compile_data,INTEL_ASM_OP_SETG);+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));}void compile_equal_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_ast_to_intel_asm(compile_data,(struct AST*)bin->left);+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);++ rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);+ rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),get_intel_asm_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_CMP));+ intel_asm_finish_comparison(compile_data,INTEL_ASM_OP_SETE);+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));}void compile_not_equal_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_ast_to_intel_asm(compile_data,(struct AST*)bin->left);+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);++ rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);+ rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);++ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),get_intel_asm_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_CMP));+ intel_asm_finish_comparison(compile_data,INTEL_ASM_OP_SETNE);+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));}F 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_MUL]=(map_entry)save_intel_asm_binary_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_SETL]=(map_entry)save_intel_asm_unary_instruction,+ [INTEL_ASM_OP_SETE]=(map_entry)save_intel_asm_unary_instruction,+ [INTEL_ASM_OP_SETNE]=(map_entry)save_intel_asm_unary_instruction,+ [INTEL_ASM_OP_SETG]=(map_entry)save_intel_asm_unary_instruction,+ [INTEL_ASM_OP_SETAE]=(map_entry)save_intel_asm_unary_instruction,+ [INTEL_ASM_OP_SETBE]=(map_entry)save_intel_asm_unary_instruction,[INTEL_ASM_OP_JE]=(map_entry)save_intel_asm_jump_instruction,[INTEL_ASM_OP_JL]=(map_entry)save_intel_asm_jump_instruction,[INTEL_ASM_OP_JNZ]=(map_entry)save_intel_asm_jump_instruction,[INTEL_ASM_OP_AND]="AND",[INTEL_ASM_OP_XOR]="XOR",[INTEL_ASM_OP_OR]="OR",+ [INTEL_ASM_OP_CMP]="CMP",};wonky_assert(map[bin->type]!=NULL);fprintf(out,"%s ",map[bin->type]);[INTEL_ASM_OP_POP]="POP",[INTEL_ASM_OP_PUSH]="PUSH",[INTEL_ASM_OP_CALL]="CALL",+ [INTEL_ASM_OP_SETL]="SETL",+ [INTEL_ASM_OP_SETE]="SETE",+ [INTEL_ASM_OP_SETNE]="SETNE",+ [INTEL_ASM_OP_SETG]="SETG",+ [INTEL_ASM_OP_SETAE]="SETAE",+ [INTEL_ASM_OP_SETBE]="SETBE",};wonky_assert(map[unary->type]!=NULL);fprintf(out,"%s ",map[unary->type]);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_MUL,INTEL_ASM_OP_JMP,INTEL_ASM_OP_TEST,+ INTEL_ASM_OP_CMP,+ INTEL_ASM_OP_SETL,+ INTEL_ASM_OP_SETE,+ INTEL_ASM_OP_SETNE,+ INTEL_ASM_OP_SETG,+ INTEL_ASM_OP_SETAE,+ INTEL_ASM_OP_SETBE,INTEL_ASM_OP_JE,INTEL_ASM_OP_JL,INTEL_ASM_OP_JNZ,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={[INTEL_ASM_REGISTER_AX]="AX",+ [INTEL_ASM_REGISTER_AL]="AL",+ [INTEL_ASM_REGISTER_AH]="AH",[INTEL_ASM_REGISTER_BX]="BX",[INTEL_ASM_REGISTER_DX]="DX",[INTEL_ASM_REGISTER_DI]="DI",F diff --git a/src/backend/asm/intel/intel_location.hh b/src/backend/asm/intel/intel_location.hh --- a/src/backend/asm/intel/intel_location.hh +++ b/src/backend/asm/intel/intel_location.hhenum Intel_Asm_Registers{INTEL_ASM_REGISTER_AX,+ INTEL_ASM_REGISTER_AL,+ INTEL_ASM_REGISTER_AH,+INTEL_ASM_REGISTER_BX,INTEL_ASM_REGISTER_DX,INTEL_ASM_REGISTER_DI,