This commit is contained in:
Rose Apollo 2024-04-24 12:02:18 +00:00
parent 8a4e9539dd
commit 9d61e18339
3 changed files with 55 additions and 7 deletions

View File

@ -33,6 +33,12 @@ typedef struct
BinaryInstruction *instructions;
} BinaryInstructionArray;
typedef struct
{
uint16_t length;
uint16_t *values;
} BinaryDataValueArray;
typedef struct
{
char label[64];

View File

@ -88,15 +88,15 @@ AsmInstructionArray *InterpretAssembly(char *data)
{
char *d = data;
AsmInstructionArray *asmIA = malloc(sizeof(AsmInstructionArray));
uint32_t cSize = 0, mSize = 32;
asmIA->instruction = malloc(sizeof(AsmInstruction) * 32);
uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
asmIA->instruction = malloc(sizeof(AsmInstruction) * ARRAY_SNAP_SIZE);
while (true)
{
loopStart:
if (cSize == mSize)
{
mSize += 32;
mSize += ARRAY_SNAP_SIZE;
asmIA->instruction = realloc(asmIA->instruction, mSize);
}
@ -154,11 +154,42 @@ loopEnd:
}
final:
// TODO i think its mostly done, just need to make sure i free any rand temp
// shit used here
asmIA->instruction = realloc(asmIA->instruction, cSize);
asmIA->length = cSize;
return asmIA;
}
AsmLabelArray *GenerateLabels(AsmInstructionArray *assembly)
{
AsmLabelArray *labels = malloc(sizeof(AsmLabelArray));
uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
labels->labels = malloc(sizeof(AsmLabel) * ARRAY_SNAP_SIZE);
for (int i = 0; i < assembly->length; i++)
{
if (cSize == mSize)
{
mSize += ARRAY_SNAP_SIZE;
labels->labels = reallc(labels->labels, mSize);
}
if (assembly->instruction[0].label[0] == '\0')
continue;
labels->labels[cSize].location = i;
strcpy(&labels->labels[cSize].label, &assembly->instruction[0].label);
cSize++;
}
labels->labels = realloc(labels->labels, cSize);
labels->length = cSize;
return labels;
}
uint16_t *CompileAsembly(AsmInstructionArray *assembly, AsmLabelArray *labels)
{
}

View File

@ -1,6 +1,17 @@
#ifndef ASM_ASSEMBLER_H
#define ASM_ASSEMBLER_H
#include <stdbool.h>
#include "asm_const.h"
#define ARRAY_SNAP_SIZE 32
char *FindNextChar(char *data, char toFind, bool careAboutNull);
char *FindNextNonSpaceChar(char *data, bool careAboutNull);
char *FindNextSpaceChar(char *data, bool careAboutNull);
AsmInstructionArray *InterpretAssembly(char *data);
AsmLabelArray *GenerateLabels(AsmInstructionArray *assembly);
BinaryInstructionArray *CompileAsembly(AsmInstructionArray *assembly);
#endif