aboutsummaryrefslogtreecommitdiff
path: root/src/fasm/linker/linker.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/fasm/linker/linker.h')
-rw-r--r--src/fasm/linker/linker.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/fasm/linker/linker.h b/src/fasm/linker/linker.h
new file mode 100644
index 0000000..fd7813b
--- /dev/null
+++ b/src/fasm/linker/linker.h
@@ -0,0 +1,78 @@
+#pragma once
+
+#include <fasm/lexer/lexer.h>
+#include <stdint.h>
+
+typedef struct FasmLinkedLine {
+ char const *begin;
+ char const *end;
+ FasmToken instruction;
+ uint8_t *operands;
+ size_t operands_size;
+} FasmLinkedLine;
+
+typedef struct FasmVariable {
+ char const *begin;
+ char const *end;
+ uint64_t value;
+} FasmVariable;
+
+typedef struct FasmLinkedLines {
+ FasmLinkedLine *lines;
+ size_t lines_size;
+
+ FasmVariable *variables;
+ size_t variables_size;
+
+ uint8_t *data;
+ size_t data_size;
+} FasmLinkedLines;
+
+extern void fasmVariablePrint(FasmVariable variable);
+extern void fasmLinkedLinePrint(FasmLinkedLine line);
+extern void fasmLinkedLinesPrint(FasmLinkedLines lines);
+
+extern void fasmLinkedLineDeleteInner(FasmLinkedLine line);
+extern void fasmLinkedLinesDeleteInner(FasmLinkedLines lines);
+
+extern FasmLinkedLines fasmLinker(const FasmLines *lines,
+ SourceCode *sourceCode);
+
+extern void fasmLinesSetVariables(FasmLinkedLines *linkedLines,
+ const FasmLines *lines,
+ SourceCode *sourceCode);
+extern void fasmLinesSetLines(FasmLinkedLines *linkedLines,
+ const FasmLines *lines, SourceCode *sourceCode);
+extern void fasmLinesSetData(FasmLinkedLines *linkedLines,
+ const FasmLines *lines, SourceCode *sourceCode);
+
+extern FasmLinkedLine fasmLinesParseLine(FasmLinkedLines *linkedLines,
+ FasmLine line, SourceCode *sourceCode);
+
+extern bool fasmLinkerOperandSizeCorrect(FasmToken token, int size);
+
+extern size_t getSizeOfLine(const FasmLine line);
+extern size_t getSizeOfLineOperands(const FasmLine line);
+extern size_t getSizeOfLineOperandElementSize(const FasmLine line);
+
+extern void fasmLinesPushVariable(FasmLinkedLines *linkedLines,
+ FasmVariable variable);
+extern void fasmLinesPushLine(FasmLinkedLines *linkedLines,
+ FasmLinkedLine line);
+extern void fasmLinesPushData(FasmLinkedLines *linkedLines, uint8_t *data,
+ size_t size);
+extern FasmVariable fasmLinesGetVariable(const FasmLinkedLines *linkedLines,
+ char const *nameBegin,
+ char const *nameEnd);
+
+extern bool isOperandString(FasmOperand operand);
+
+extern uint64_t getOperandValue(FasmLinkedLines *linkedLines,
+ FasmOperand operand, SourceCode *sourceCode);
+
+extern uint64_t strToInt(const char *begin, const char *end,
+ SourceCode *sourceCode);
+extern uint64_t hexStrToInt(const char *begin, const char *end,
+ SourceCode *sourceCode);
+extern uint64_t binStrToInt(const char *begin, const char *end,
+ SourceCode *sourceCode);