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
int size;
size=get_expression_value_size(value);
reserve_stack_space(compile_data,size);
- return get_intel_asm_stack_offset(size);
+ return get_intel_asm_stack_offset(compile_data->offset_from_stack_frame);
}
- void rvalue_to_register(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value,enum Intel_Asm_Registers reg)
+ enum Intel_Asm_Registers rvalue_to_ax(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value)
{
size_t value_size;
+ enum Intel_Asm_Registers reg;
+
value_size=get_expression_value_size(value);
- wonky_assert(value_size<=8);
+ reg=get_ax_with_size(value_size);
- 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
- )
- );
+ push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));
+ push_intel_asm_instruction(
+ compile_data,
+ get_intel_asm_binary_instruction(
+ get_intel_asm_register(reg),
+ get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX,value_size),
+ INTEL_ASM_OP_MOV
+ )
+ );
+ }else
+ {
+ push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));
}
-
+ return reg;
}
- void lvalue_to_register(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value,enum Intel_Asm_Registers reg)
+ void lvalue_to_rax(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value)
{
size_t value_size;
+
value_size=get_expression_value_size(value);
- wonky_assert(value_size<=8 && value->type==VALUE_LVALUE);
+ wonky_assert(value->type==VALUE_LVALUE);
- push_intel_asm_instruction(compile_data,intel_asm_get_pop(reg));
+ push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));
+ }
+ enum Intel_Asm_Registers rvalue_to_dx(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value)
+ {
+ size_t value_size;
+ enum Intel_Asm_Registers reg;
+
+ value_size=get_expression_value_size(value);
+
+ reg=get_dx_with_size(value_size);
+
+ if(value->type==VALUE_LVALUE)
+ {
+ 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(reg),
+ get_intel_asm_by_register(INTEL_ASM_REGISTER_RDX,value_size),
+ INTEL_ASM_OP_MOV
+ )
+ );
+ }else
+ {
+ push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RDX));
+ }
+
+ return reg;
+ }
+ enum Intel_Asm_Registers get_ax_with_size(size_t size)
+ {
+ switch(size)
+ {
+ case 1:
+ return INTEL_ASM_REGISTER_AL;
+ case 2:
+ return INTEL_ASM_REGISTER_AX;
+ case 4:
+ return INTEL_ASM_REGISTER_EAX;
+ case 8:
+ return INTEL_ASM_REGISTER_RAX;
+ default:
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ }
+
+ }
+ enum Intel_Asm_Registers get_dx_with_size(size_t size)
+ {
+ switch(size)
+ {
+ case 1:
+ return INTEL_ASM_REGISTER_DL;
+ case 2:
+ return INTEL_ASM_REGISTER_DX;
+ case 4:
+ return INTEL_ASM_REGISTER_EDX;
+ case 8:
+ return INTEL_ASM_REGISTER_RDX;
+ default:
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ }
}
void release_value_from_stack(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value)
{
size=(int)get_type_size(object->type);
reserve_stack_space(compile_data,size);
- ret=get_intel_asm_stack_offset(compile_data->offset_from_stack_frame);
compile_data->offset_from_stack_frame+=size;
+ ret=get_intel_asm_stack_offset(compile_data->offset_from_stack_frame);
object->location=(struct Location*)ret;
return ret;
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));
+ //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_AL),INTEL_ASM_OP_MOV));
}
void export_function_definition(struct Compile_Data_Intel_Asm *compile_data,struct AST_Function_Definition *function)
{
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.h
void 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 lvalue_to_register(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value,enum Intel_Asm_Registers reg);
+
+ enum Intel_Asm_Registers rvalue_to_ax(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value);
+ void lvalue_to_rax(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value);
+ enum Intel_Asm_Registers rvalue_to_dx(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value);
+
+ enum Intel_Asm_Registers get_ax_with_size(size_t size);
+ enum Intel_Asm_Registers get_dx_with_size(size_t size);
+
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);
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
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);
+ rvalue_to_ax(compile_data,((struct AST_Expression*)ret->return_expression)->value);
}
}
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);
- 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));
+
+ 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));
}
void compile_pointer_addition_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin)
{
if(type_is_scalar(extract_expresion_value_type(bin->left->value)))
{
+ 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);
- 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));
+ dx=rvalue_to_dx(compile_data,bin->right->value);
+ lvalue_to_rax(compile_data,bin->left->value);
+
+ ax=get_ax_with_size(get_expression_value_size(bin->left->value));
push_intel_asm_instruction(compile_data,
get_intel_asm_binary_instruction(
- get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX),
- get_intel_asm_register(INTEL_ASM_REGISTER_RDX),
+ get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX,get_expression_value_size(bin->left->value)),
+ get_intel_asm_register(dx),
INTEL_ASM_OP_MOV)
);
}
void compile_get_address_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary)
{
- intel_asm_memory_location_to_rax(compile_data,get_location_of_value(compile_data,unary->operand->value));
- push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
+ compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
}
void compile_dereference_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary)
{
- intel_asm_memory_location_to_rax(compile_data,get_location_of_value(compile_data,unary->operand->value));
+ enum Intel_Asm_Registers ax;
+ compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
+ lvalue_to_rax(compile_data,unary->operand->value);
+ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RAX),get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX,8),INTEL_ASM_OP_MOV));
push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
}
void compile_member_from_ptr_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin)
}
void compile_unary_minus_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary)
{
+ enum Intel_Asm_Registers ax;
+
compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
- rvalue_to_register(compile_data,unary->operand->value,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_NEG));
+ ax=rvalue_to_ax(compile_data,unary->operand->value);
+ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_register(ax),INTEL_ASM_OP_NEG));
push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
}
void compile_cast_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary)
}
void compile_shift_left_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);
-
- rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RDX);
- rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RAX);
-
- push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_CL),get_intel_asm_register(INTEL_ASM_REGISTER_DL),INTEL_ASM_OP_MOV));
-
- 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_CL),INTEL_ASM_OP_SAL));
- push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
+ compile_shift_inner(compile_data,bin,INTEL_ASM_OP_SAL);
}
void compile_shift_right_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);
-
- rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RDX);
- rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RAX);
-
- push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_CL),get_intel_asm_register(INTEL_ASM_REGISTER_DL),INTEL_ASM_OP_MOV));
-
- 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_CL),INTEL_ASM_OP_SAR));
- push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
+ compile_shift_inner(compile_data,bin,INTEL_ASM_OP_SAR);
}
void compile_less_eq_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);
-
- 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));
+ compile_comparison_inner(compile_data,bin,INTEL_ASM_OP_SETBE);
}
void compile_greater_eq_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);
-
- 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));
+ compile_comparison_inner(compile_data,bin,INTEL_ASM_OP_SETAE);
}
void compile_less_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);
-
- 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));
+ compile_comparison_inner(compile_data,bin,INTEL_ASM_OP_SETL);
}
void compile_greater_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);
+ compile_comparison_inner(compile_data,bin,INTEL_ASM_OP_SETG);
+ }
+ void compile_equal_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin)
+ {
+ compile_comparison_inner(compile_data,bin,INTEL_ASM_OP_SETE);
+ }
+ void compile_not_equal_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin)
+ {
+ compile_comparison_inner(compile_data,bin,INTEL_ASM_OP_SETNE);
+ }
- rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);
- rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);
+ void compile_prefix_inc_dec_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary,enum Intel_Asm_Instruction_Type op)
+ {
+ enum Intel_Asm_Registers reg;
+
+ compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
+ lvalue_to_rax(compile_data,unary->operand->value);
+ reg=get_dx_with_size(get_expression_value_size(unary->operand->value));
- 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,get_intel_asm_unary_instruction(get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX,get_expression_value_size(unary->operand->value)),op));
+
+ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(reg),get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX,get_expression_value_size(unary->operand->value)),INTEL_ASM_OP_MOV));
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)
+
+ void compile_postfix_inc_dec_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary,enum Intel_Asm_Instruction_Type op)
{
- compile_ast_to_intel_asm(compile_data,(struct AST*)bin->left);
- compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);
+ enum Intel_Asm_Registers reg;
+
+ compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
- rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);
- rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);
+ reg=get_dx_with_size(get_expression_value_size(unary->operand->value));
- 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);
+ lvalue_to_rax(compile_data,unary->operand->value);
+
+ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(reg),get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX,get_expression_value_size(unary->operand->value)),INTEL_ASM_OP_MOV));
+ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX,get_expression_value_size(unary->operand->value)),op));
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)
+ void compile_comparison_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);
- rvalue_to_register(compile_data,bin->right->value,INTEL_ASM_REGISTER_RAX);
- rvalue_to_register(compile_data,bin->left->value,INTEL_ASM_REGISTER_RDX);
+ 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(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,get_intel_asm_binary_instruction(get_intel_asm_register(ax),get_intel_asm_register(dx),INTEL_ASM_OP_CMP));
+ intel_asm_finish_comparison(compile_data,op);
push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
}
-
- void compile_prefix_inc_dec_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary,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)
{
- compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
- lvalue_to_register(compile_data,unary->operand->value,INTEL_ASM_REGISTER_RAX);
- push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX),op));
- push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_MOV));
- push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RDX));
+ 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);
- void compile_postfix_inc_dec_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary,enum Intel_Asm_Instruction_Type op)
- {
- compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
- lvalue_to_register(compile_data,unary->operand->value,INTEL_ASM_REGISTER_RAX);
- push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RDX),get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX),INTEL_ASM_OP_MOV));
- push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_by_register(INTEL_ASM_REGISTER_RAX),op));
- push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RDX));
+ 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(INTEL_ASM_REGISTER_CL),get_intel_asm_register(INTEL_ASM_REGISTER_DL),INTEL_ASM_OP_MOV));
+
+ 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));
}
#endif
F 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.h
void compile_prefix_inc_dec_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary,enum Intel_Asm_Instruction_Type op);
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);
#endif
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
static const char *register_map[INTEL_ASM_REGISTER_END]
=
{
+ [INTEL_ASM_REGISTER_EAX]="EAX",
[INTEL_ASM_REGISTER_AX]="AX",
[INTEL_ASM_REGISTER_AL]="AL",
[INTEL_ASM_REGISTER_AH]="AH",
[INTEL_ASM_REGISTER_BX]="BX",
+ [INTEL_ASM_REGISTER_EDX]="EDX",
[INTEL_ASM_REGISTER_DX]="DX",
[INTEL_ASM_REGISTER_DL]="DL",
[INTEL_ASM_REGISTER_DH]="DH",
[INTEL_ASM_REGISTER_RAX]="RAX",
[INTEL_ASM_REGISTER_RBP]="RBP",
};
+ static const char *memory_size_map[INTEL_ASM_MEMORY_SIZE_END]
+ =
+ {
+ [INTEL_ASM_MEMORY_SIZE_BYTE]="BYTE",
+ [INTEL_ASM_MEMORY_SIZE_WORD]="WORD",
+ [INTEL_ASM_MEMORY_SIZE_DWORD]="DWORD",
+ [INTEL_ASM_MEMORY_SIZE_QWORD]="QWORD",
- struct Intel_Asm_Memory_Location* get_intel_by_asm_register(enum Intel_Asm_Registers reg)
+ };
+ struct Intel_Asm_Memory_Location* get_intel_asm_by_register(enum Intel_Asm_Registers reg,size_t size)
{
struct Intel_Asm_Memory_Location_By_Register *ret;
ret=wonky_malloc(sizeof(struct Intel_Asm_Memory_Location_By_Register));
ret->type=INTEL_ASM_MEMORY_LOCATION_BY_REGISTER;
ret->reg=reg;
+ switch(size)
+ {
+ case 1:
+ ret->size=INTEL_ASM_MEMORY_SIZE_BYTE;
+ break;
+ case 2:
+ ret->size=INTEL_ASM_MEMORY_SIZE_WORD;
+ break;
+ case 4:
+ ret->size=INTEL_ASM_MEMORY_SIZE_DWORD;
+ break;
+ case 8:
+ ret->size=INTEL_ASM_MEMORY_SIZE_QWORD;
+ break;
+ default:
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ }
return (struct Intel_Asm_Memory_Location*)ret;
}
return (struct Intel_Asm_Memory_Location*)ret;
}
- struct Intel_Asm_Memory_Location* get_intel_asm_by_register(enum Intel_Asm_Registers reg)
- {
- struct Intel_Asm_Memory_Location_Register *ret;
- ret=wonky_malloc(sizeof(struct Intel_Asm_Memory_Location_Register));
- ret->type=INTEL_ASM_MEMORY_LOCATION_BY_REGISTER;
- ret->reg=reg;
-
- return (struct Intel_Asm_Memory_Location*)ret;
- }
struct Intel_Asm_Memory_Location* get_intel_asm_label_location(struct Intel_Asm_Label *label)
{
struct Intel_Asm_Memory_Location_By_Label *ret;
return (struct Intel_Asm_Memory_Location*)ret;
}
- struct Intel_Asm_Memory_Location* get_intel_by_asm_stack_offset(int offset)
+ struct Intel_Asm_Memory_Location* get_intel_by_asm_stack_offset(int offset,size_t size)
{
struct Intel_Asm_Memory_Location_By_Stack_Offset *ret;
ret=wonky_malloc(sizeof(struct Intel_Asm_Memory_Location_By_Stack_Offset));
ret->type=INTEL_ASM_MEMORY_LOCATION_BY_STACK_OFFSET;
ret->offset=offset;
+ switch(size)
+ {
+ case 1:
+ ret->size=INTEL_ASM_MEMORY_SIZE_BYTE;
+ break;
+ case 2:
+ ret->size=INTEL_ASM_MEMORY_SIZE_WORD;
+ break;
+ case 4:
+ ret->size=INTEL_ASM_MEMORY_SIZE_DWORD;
+ break;
+ case 8:
+ ret->size=INTEL_ASM_MEMORY_SIZE_QWORD;
+ break;
+ default:
+ wonky_assert(SHOULD_NOT_REACH_HERE);
+ }
+
return (struct Intel_Asm_Memory_Location*)ret;
}
struct Intel_Asm_Memory_Location* get_intel_asm_in_instruction_number(int number)
}
void save_intel_asm_by_stack_offset_location(struct Intel_Asm_Memory_Location_By_Stack_Offset *sp,FILE *out)
{
- fprintf(out,"QWORD [RBP-%d]",sp->offset);
+ fprintf(out,"%s [RBP-%d]",memory_size_map[sp->size],sp->offset);
}
void save_intel_asm_stack_offset_location(struct Intel_Asm_Memory_Location_By_Stack_Offset *sp,FILE *out)
{
- fprintf(out,"QWORD [RBP-%d]",sp->offset);
+ fprintf(out,"%s [RBP-%d]",memory_size_map[sp->size],sp->offset);
}
void save_intel_asm_by_register_location(struct Intel_Asm_Memory_Location_By_Register *reg,FILE *out)
{
wonky_assert(register_map[reg->reg]!=NULL);
- fprintf(out,"QWORD[%s]",register_map[reg->reg]);
+ fprintf(out,"%s [%s]",memory_size_map[reg->size],register_map[reg->reg]);
}
void save_intel_asm_register_location(struct Intel_Asm_Memory_Location_Register *reg,FILE *out)
{
F diff --git a/src/backend/asm/intel/intel_location.h b/src/backend/asm/intel/intel_location.h
--- a/src/backend/asm/intel/intel_location.h
+++ b/src/backend/asm/intel/intel_location.h
{
enum Intel_Asm_Memory_Location_Type type;
enum Intel_Asm_Registers reg;
+ enum Intel_Asm_Memory_Size_Type size;
};
struct Intel_Asm_Memory_Location_Register
{
{
enum Intel_Asm_Memory_Location_Type type;
int offset;
+ enum Intel_Asm_Memory_Size_Type size;
};
struct Intel_Asm_Memory_Location_Stack_Offset
{
void save_intel_asm_number_in_instruction(struct Intel_Asm_Memory_Location_In_Instruction_Number *num,FILE *out);
struct Intel_Asm_Memory_Location* get_intel_asm_register(enum Intel_Asm_Registers reg);
- struct Intel_Asm_Memory_Location* get_intel_asm_by_register(enum Intel_Asm_Registers reg);
+ struct Intel_Asm_Memory_Location* get_intel_asm_by_register(enum Intel_Asm_Registers reg,size_t size);
struct Intel_Asm_Memory_Location* get_intel_asm_label_location(struct Intel_Asm_Label *label);
struct Intel_Asm_Memory_Location* get_intel_asm_stack_offset(int offset);
- struct Intel_Asm_Memory_Location* get_intel_asm_by_stack_offset(int offset);
+ struct Intel_Asm_Memory_Location* get_intel_asm_by_stack_offset(int offset,size_t size);
struct Intel_Asm_Memory_Location* get_intel_asm_in_instruction_number(int number);
struct Intel_Asm_Memory_Location* intel_asm_get_ax_register();
struct Intel_Asm_Memory_Location* intel_asm_get_dx_register();
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.hh
enum Intel_Asm_Registers
{
+ INTEL_ASM_REGISTER_RAX,
+ INTEL_ASM_REGISTER_EAX,
INTEL_ASM_REGISTER_AX,
INTEL_ASM_REGISTER_AL,
INTEL_ASM_REGISTER_AH,
INTEL_ASM_REGISTER_BX,
+ INTEL_ASM_REGISTER_RDX,
+ INTEL_ASM_REGISTER_EDX,
INTEL_ASM_REGISTER_DX,
INTEL_ASM_REGISTER_DH,
INTEL_ASM_REGISTER_DL,
INTEL_ASM_REGISTER_RDI,
INTEL_ASM_REGISTER_RSI,
- INTEL_ASM_REGISTER_RDX,
INTEL_ASM_REGISTER_RCX,
INTEL_ASM_REGISTER_R8,
INTEL_ASM_REGISTER_R9,
- INTEL_ASM_REGISTER_RAX,
INTEL_ASM_REGISTER_RBP,
INTEL_ASM_REGISTER_END
INTEL_ASM_MEMORY_LOCATION_END
};
+ enum Intel_Asm_Memory_Size_Type
+ {
+ INTEL_ASM_MEMORY_SIZE_BYTE,
+ INTEL_ASM_MEMORY_SIZE_WORD,
+ INTEL_ASM_MEMORY_SIZE_DWORD,
+ INTEL_ASM_MEMORY_SIZE_QWORD,
+ INTEL_ASM_MEMORY_SIZE_END
+ };
+
struct Intel_Asm_Memory_Location;
struct Intel_Asm_Memory_Location_By_Register;
struct Intel_Asm_Memory_Location_Register;