#ifndef WONKY_INTEL_ASM_H
#define WONKY_INTEL_ASM_H WONKY_INTEL_ASM_H
#include <intel_asm.hh>
#include <intel_instruction.h>
#include <intel_location.h>
#include <intel_compile.h>
#include <stdio.h>
#include <stdlib.h>
#include <compile.h>
#include <program.h>
#include <queue.h>
#include <ast.h>
#include <value.h>
#include <constant.h>
#include <wonky_malloc.h>
#include <wonky_stream.h>
struct Compile_Data_Intel_Asm
{
enum Compilation_Type type;
struct Queue *errors;
struct Queue *data_block;
struct Queue *exports;
struct Queue *imports;
struct Queue *instructions;
int number_of_anon_labels;
_Bool in_main;
struct AST_Function_Definition *current_function;
int offset_from_stack_frame;
int stack_space_taken_for_current_block;
};
struct Compiled_Object_Intel_Asm
{
enum Compilation_Type type;
struct Queue *errors;
struct Queue *data_block;
struct Queue *exports;
struct Queue *imports;
struct Queue *instructions;
};
struct Compiled_Object_Intel_Asm* compile_program_to_intel_asm(struct Program *program);
void compile_program_static_objects(struct Compile_Data *obj,struct Program *program);
void save_compiled_intel_asm(struct Compiled_Object_Intel_Asm *object,struct wonky_stream *out);
void save_compiled_intel_asm_as_nasm(struct Compiled_Object_Intel_Asm *object,struct wonky_stream *out);
struct Compile_Data_Intel_Asm* get_compile_data_for_intel_asm();
void push_intel_asm_instruction(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Instruction *instruction);
void wonky_free_space_taken_for_value_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Memory_Location *location);
void memcpy_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Intel_Asm_Memory_Location *destination,struct Intel_Asm_Memory_Location *source);
void reserve_stack_space(struct Compile_Data_Intel_Asm *compile_data,int size);
void release_stack_space(struct Compile_Data_Intel_Asm *compile_data,int size);
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);
void release_stack_space_for_whole_block_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct Normal_Scope *scope);
void release_stack_frame_for_function(struct Compile_Data_Intel_Asm *compile_data);
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);
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);
struct Intel_Asm_Memory_Location* reserve_stack_space_for_function_argument(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);
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);
void import_object_definition(struct Compile_Data_Intel_Asm *compile_data,struct AST_Object_Declaration *object);
#endif