TCPU/src/compiler/Binary.h
2025-03-12 12:57:16 +05:00

67 lines
1.7 KiB
C

#pragma once
#include "../std.h"
#include "../string/str.h"
#include "../instructions/instructions.h"
#include "../instructions/registers.h"
#include "../collections/List.h"
#include "../collections/HashMap.h"
#include "AST.h"
typedef struct CompiledSection CompiledSection;
typedef struct ConstDataProps {
str name;
u32 size; // size in bytes
u32 offset; // offset in bytes from section start
} ConstDataProps;
#define ConstDataProps_construct(NAME, SIZE, OFFSET) ((ConstDataProps){ .name = NAME, .size = SIZE, .offset = OFFSET})
List_declare(ConstDataProps);
HashMap_declare(ConstDataProps);
typedef enum NamedRefType {
NamedRefType_Unset,
NamedRefType_Ptr,
NamedRefType_Size,
} NamedRefType;
typedef struct NamedRef {
str name;
NamedRefType type;
u32 offset; // offset in bytes from section start
} NamedRef;
#define NamedRef_construct(NAME, TYPE, OFFSET) ((NamedRef){ .name = NAME, .type = TYPE, .offset = OFFSET})
List_declare(NamedRef);
typedef struct CompiledSection {
str name;
CompiledSection* next;
u32 offset;
List_ConstDataProps const_data_props_list;
List_NamedRef named_refs;
List_u8 bytes;
} CompiledSection;
void CompiledSection_construct(CompiledSection* ptr, str name);
void CompiledSection_free(CompiledSection* ptr);
List_declare(CompiledSection);
typedef CompiledSection* CompiledSectionPtr;
HashMap_declare(CompiledSectionPtr);
typedef struct BinaryObject {
List_CompiledSection section_list;
HashMap_CompiledSectionPtr section_map;
NULLABLE(CompiledSection*) main_section;
HashMap_ConstDataProps const_data_map;
u32 total_size;
} BinaryObject;
void BinaryObject_construct(BinaryObject* ptr);
void BinaryObject_free(BinaryObject* ptr);