WONKY



LOG | FILES | OVERVIEW


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
Queue_Init(ret->instructions);
ret->number_of_anon_labels=0;
+ ret->offset_from_stack_frame=0;
return ret;
}
{
push_intel_asm_instruction(compile_data,
get_intel_asm_binary_instruction(
- get_intel_asm_register(INTEL_ASM_REGISTER_SP),
+ get_intel_asm_register(INTEL_ASM_REGISTER_RSP),
get_intel_asm_in_instruction_number(size),
INTEL_ASM_OP_SUB
)
{
push_intel_asm_instruction(compile_data,
get_intel_asm_binary_instruction(
- get_intel_asm_register(INTEL_ASM_REGISTER_SP),
+ get_intel_asm_register(INTEL_ASM_REGISTER_RSP),
get_intel_asm_in_instruction_number(size),
INTEL_ASM_OP_ADD
)
return get_intel_asm_label_location((struct Intel_Asm_Label*)label);
}
- struct Intel_Asm_Memory_Location* push_declaration_on_stack_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Object_Declaration *declaration)
- {
- int size;
- size=get_type_size(declaration->object->object->type);
- reserve_stack_space(compile_data,size);
- return get_intel_asm_stack_offset(size);
- }
void release_stack_space_for_whole_block_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Normal_Scope *scope)
{
int whole_size=0;
case INTEL_ASM_MEMORY_LOCATION_BY_LABEL:
case INTEL_ASM_MEMORY_LOCATION_BY_REGISTER:
case INTEL_ASM_MEMORY_LOCATION_IN_INSTRUCTION_NUMBER:
+ case INTEL_ASM_MEMORY_LOCATION_BY_STACK_OFFSET:
push_intel_asm_instruction(
compile_data,
get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RAX),location,INTEL_ASM_OP_MOV)
);
break;
- case INTEL_ASM_MEMORY_LOCATION_BY_STACK_OFFSET:
+ /*case INTEL_ASM_MEMORY_LOCATION_BY_STACK_OFFSET:*/
push_intel_asm_instruction(
compile_data,
get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_RAX),location,INTEL_ASM_OP_MOV)
{
release_stack_space(compile_data,get_expression_value_size(value));
}
+ struct Intel_Asm_Memory_Location* reserve_stack_space_for_object(struct Compile_Data_Intel_Asm *compile_data,struct Object *object)
+ {
+ int size;
+ struct Intel_Asm_Memory_Location *ret;
+ 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;
+
+ object->location=(struct Location*)ret;
+ return ret;
+ }
+ void release_object_from_stack(struct Compile_Data_Intel_Asm *compile_data,struct Object *object)
+ {
+ release_stack_space(compile_data,get_type_size(object->type));
+ }
struct Intel_Asm_Memory_Location* get_location_of_value(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value)
{
switch(value->type)
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
int number_of_anon_labels;
_Bool in_main;
+ int offset_from_stack_frame;
+ int stack_space_taken_for_current_block;
};
struct Compiled_Object_Intel_Asm
{
struct Intel_Asm_Memory_Location* reserve_static_space_for_object(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Label *label,int size);
struct Intel_Asm_Memory_Location* reserve_static_space_for_string(struct Compile_Data_Intel_Asm *compile_data,struct Constant *string);
- struct Intel_Asm_Memory_Location* push_declaration_on_stack_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Object_Declaration *declaration);
void release_stack_space_for_whole_block_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Normal_Scope *scope);
struct Intel_Asm_Memory_Location* reserve_space_for_value_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value);
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 release_object_from_stack(struct Compile_Data_Intel_Asm *compile_data,struct Object *object);
+
struct Intel_Asm_Memory_Location* get_location_of_value(struct Compile_Data_Intel_Asm *compile_data,struct Expression_Value *value);
struct Intel_Asm_Memory_Location* get_location_of_constant(struct Compile_Data_Intel_Asm *compile_data,struct Constant *constant);
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,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_push(INTEL_ASM_REGISTER_RAX));
}
void compile_constant_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Constant *constant)
{
if(is_expression[((struct AST*)it->data)->type])
push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));
}
+ release_stack_space_for_whole_block_intel_asm(compile_data,(struct Normal_Scope*)statement->scope);
}
void compile_for_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_For_Statement *statement)
{
}
void compile_return_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Return_Statement *ret)
{
+ compile_ast_to_intel_asm(compile_data,ret->return_expression);
push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));
if(!compile_data->in_main)
push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RBP));
}
void compile_object_declaration_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Object_Declaration *objd)
{
+ /*
push_intel_asm_instruction(compile_data,
get_intel_asm_binary_instruction(get_intel_asm_register(INTEL_ASM_REGISTER_SP),
get_intel_asm_in_instruction_number(4),
INTEL_ASM_OP_SUB));
-
- push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_NOP));
+ */
+ reserve_stack_space_for_object(compile_data,objd->object->object);
}
void compile_function_definition_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Function_Definition *def)
{
+ compile_data->offset_from_stack_frame=0;
+ compile_data->stack_space_taken_for_current_block=0;
+
export_function_definition(compile_data,def);
+
if(!gstrn_cmp(def->function->id->data,"main",sizeof("main")-1))
compile_data->in_main=0;
else
{
def->function->location=(struct Location*)
get_intel_asm_label_location(
- (struct Intel_Asm_Label*)get_intel_asm_label(gstr_dup(def->function->id->data,def->function->id->data+def->function->id->data_size,1024))
+ (struct Intel_Asm_Label*)get_intel_asm_label(
+ gstr_dup(
+ def->function->id->data,
+ def->function->id->data+def->function->id->data_size,
+ 1024
+ )
+ )
);
}
+
push_intel_asm_instruction(compile_data,(struct Intel_Asm_Instruction*)((struct Intel_Asm_Memory_Location_By_Label*)def->function->location)->label);
push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RBP));
+
+ push_intel_asm_instruction(compile_data,
+ get_intel_asm_binary_instruction(
+ get_intel_asm_register(INTEL_ASM_REGISTER_RBP),
+ get_intel_asm_register(INTEL_ASM_REGISTER_RSP),
+ INTEL_ASM_OP_MOV
+ )
+ );
+
compile_compound_statement_to_intel_asm(compile_data,def->body);
- if(!compile_data->in_main)
- push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RBP));
+ push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RBP));
/*if there are no returns we return jiberrish*/
push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_RET));
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_DI]="DI",
[INTEL_ASM_REGISTER_SI]="SI",
[INTEL_ASM_REGISTER_CX]="CX",
- [INTEL_ASM_REGISTER_SP]="SP",
+ [INTEL_ASM_REGISTER_RSP]="RSP",
[INTEL_ASM_REGISTER_RDI]="RDI",
[INTEL_ASM_REGISTER_RSI]="RSI",
[INTEL_ASM_REGISTER_RDX]="RDX",
}
void save_intel_asm_stack_offset_location(struct Intel_Asm_Memory_Location_By_Stack_Offset *sp,FILE *out)
{
- fprintf(out,"[SP+%d]",sp->offset);
+ fprintf(out,"[RBP-%d]",sp->offset);
}
void save_intel_asm_by_register_location(struct Intel_Asm_Memory_Location_By_Register *reg,FILE *out)
{
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
INTEL_ASM_REGISTER_DI,
INTEL_ASM_REGISTER_SI,
INTEL_ASM_REGISTER_CX,
- INTEL_ASM_REGISTER_SP,
+ INTEL_ASM_REGISTER_RSP,
INTEL_ASM_REGISTER_RDI,
INTEL_ASM_REGISTER_RSI,
F diff --git a/src/semantics/identifiers/scope.c b/src/semantics/identifiers/scope.c --- a/src/semantics/identifiers/scope.c +++ b/src/semantics/identifiers/scope.c
hold_previous=check_and_push_id(denoted_object,AS_NORMAL_SCOPE(current)->ordinary,denoted_object->id,translation_data);
+ Queue_Push(AS_NORMAL_SCOPE(current)->object_order,denoted_object);
+
if(has_new_errors(translation_data) || !constraint_check_object_linkage(denoted_object,hold_previous,current,translation_data) )
{