labels
This commit is contained in:
parent
8a4e9539dd
commit
9d61e18339
@ -33,6 +33,12 @@ typedef struct
|
|||||||
BinaryInstruction *instructions;
|
BinaryInstruction *instructions;
|
||||||
} BinaryInstructionArray;
|
} BinaryInstructionArray;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t length;
|
||||||
|
uint16_t *values;
|
||||||
|
} BinaryDataValueArray;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char label[64];
|
char label[64];
|
||||||
|
@ -88,15 +88,15 @@ AsmInstructionArray *InterpretAssembly(char *data)
|
|||||||
{
|
{
|
||||||
char *d = data;
|
char *d = data;
|
||||||
AsmInstructionArray *asmIA = malloc(sizeof(AsmInstructionArray));
|
AsmInstructionArray *asmIA = malloc(sizeof(AsmInstructionArray));
|
||||||
uint32_t cSize = 0, mSize = 32;
|
uint32_t cSize = 0, mSize = ARRAY_SNAP_SIZE;
|
||||||
asmIA->instruction = malloc(sizeof(AsmInstruction) * 32);
|
asmIA->instruction = malloc(sizeof(AsmInstruction) * ARRAY_SNAP_SIZE);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
loopStart:
|
loopStart:
|
||||||
if (cSize == mSize)
|
if (cSize == mSize)
|
||||||
{
|
{
|
||||||
mSize += 32;
|
mSize += ARRAY_SNAP_SIZE;
|
||||||
asmIA->instruction = realloc(asmIA->instruction, mSize);
|
asmIA->instruction = realloc(asmIA->instruction, mSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,11 +154,42 @@ loopEnd:
|
|||||||
}
|
}
|
||||||
|
|
||||||
final:
|
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->instruction = realloc(asmIA->instruction, cSize);
|
||||||
asmIA->length = cSize;
|
asmIA->length = cSize;
|
||||||
|
|
||||||
return asmIA;
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
#ifndef ASM_ASSEMBLER_H
|
#ifndef ASM_ASSEMBLER_H
|
||||||
#define 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
|
#endif
|
Loading…
Reference in New Issue
Block a user