WONKY



LOG | FILES | OVERVIEW


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
{
push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_NOP));
}
- void compile_logical_or_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data)
+ void compile_logical_or_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_logical_and_or_inner(compile_data,bin,INTEL_ASM_OP_JZ);
}
void compile_logical_and_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_logical_and_or_inner(compile_data,bin,INTEL_ASM_OP_JNZ);
}
- void compile_logical_not_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin)
+ void compile_logical_not_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary)
{
- push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_NOP));
+ enum Intel_Asm_Registers reg;
+ compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
+
+ reg=rvalue_to_ax(compile_data,unary->operand->value);
+
+ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(get_intel_asm_register(reg),get_intel_asm_register(reg),INTEL_ASM_OP_TEST));
+ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(INTEL_ASM_REGISTER_RAX,INTEL_ASM_OP_SETNE));
+
+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
}
- void compile_bitwise_or_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary)
+ void compile_bitwise_or_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_simple_bin_inner(compile_data,bin,INTEL_ASM_OP_OR);
}
void compile_bitwise_and_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_simple_bin_inner(compile_data,bin,INTEL_ASM_OP_AND);
}
void compile_bitwise_xor_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_simple_bin_inner(compile_data,bin,INTEL_ASM_OP_XOR);
}
void compile_bitwise_not_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary)
{
- push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_NOP));
+ enum Intel_Asm_Registers reg;
+ compile_ast_to_intel_asm(compile_data,(struct AST*)unary->operand);
+ reg=rvalue_to_ax(compile_data,unary->operand->value);
+ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(get_intel_asm_register(reg),INTEL_ASM_OP_NOT));
+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
+
}
void compile_get_address_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary)
{
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));
}
+ void compile_logical_and_or_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin,enum Intel_Asm_Instruction_Type cmp)
+ {
+ struct Intel_Asm_Label *first_is_true;
+ struct Intel_Asm_Label *end;
+ enum Intel_Asm_Registers reg;
+
+ end=(struct Intel_Asm_Label*)get_intel_asm_new_unique_label(compile_data);
+ first_is_true=(struct Intel_Asm_Label*)get_intel_asm_new_unique_label(compile_data);
+
+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->left);
+
+ reg=rvalue_to_ax(compile_data,bin->left->value);
+
+ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(
+ get_intel_asm_register(reg),
+ get_intel_asm_register(reg),
+ INTEL_ASM_OP_TEST));
+
+ push_intel_asm_instruction(compile_data,get_intel_asm_jump_instruction(first_is_true,cmp));
+ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(
+ get_intel_asm_register(INTEL_ASM_REGISTER_AL),
+ INTEL_ASM_OP_SETNE));
+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
+ push_intel_asm_instruction(compile_data,get_intel_asm_jump_instruction(end,INTEL_ASM_OP_JMP));
+
+ push_intel_asm_instruction(compile_data,(struct Intel_Asm_Instruction*)first_is_true);
+
+
+ compile_ast_to_intel_asm(compile_data,(struct AST*)bin->right);
+ rvalue_to_ax(compile_data,bin->right->value);
+ push_intel_asm_instruction(compile_data,get_intel_asm_binary_instruction(
+ get_intel_asm_register(reg),
+ get_intel_asm_register(reg),
+ INTEL_ASM_OP_TEST));
+ push_intel_asm_instruction(compile_data,get_intel_asm_unary_instruction(
+ get_intel_asm_register(INTEL_ASM_REGISTER_AL),
+ INTEL_ASM_OP_SETNE));
+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RAX));
+
+ push_intel_asm_instruction(compile_data,(struct Intel_Asm_Instruction*)end);
+ }
#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_xor_assign_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
void compile_pipe_assign_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
void compile_nop_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,void *dummy);
- void compile_logical_or_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data);
+ void compile_logical_or_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
void compile_logical_and_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
- void compile_logical_not_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
- void compile_bitwise_or_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary);
+ void compile_logical_not_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary);
+ void compile_bitwise_or_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
void compile_bitwise_and_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
void compile_bitwise_xor_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin);
void compile_bitwise_not_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Unary_Expression *unary);
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);
+ void compile_logical_and_or_inner(struct Compile_Data_Intel_Asm *compile_data,struct AST_Binary_Expression *bin,enum Intel_Asm_Instruction_Type cmp);
#endif
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_NEG]=(map_entry)save_intel_asm_unary_instruction,
[INTEL_ASM_OP_INC]=(map_entry)save_intel_asm_unary_instruction,
[INTEL_ASM_OP_DEC]=(map_entry)save_intel_asm_unary_instruction,
+ [INTEL_ASM_OP_NOT]=(map_entry)save_intel_asm_unary_instruction,
[INTEL_ASM_OP_DEFINE_BYTES]=(map_entry)save_intel_asm_define_bytes,
};
wonky_assert(map[instruction->type]!=NULL);
[INTEL_ASM_OP_NEG]="NEG",
[INTEL_ASM_OP_INC]="INC",
[INTEL_ASM_OP_DEC]="DEC",
+ [INTEL_ASM_OP_NOT]="NOT",
};
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.hh
INTEL_ASM_OP_NEG,
INTEL_ASM_OP_INC,
INTEL_ASM_OP_DEC,
+ INTEL_ASM_OP_NOT,
INTEL_ASM_OP_DEFINE_BYTES,
INTEL_ASM_OP_EXPORT,
INTEL_ASM_OP_IMPORT,