summaryrefslogtreecommitdiff
path: root/masm/asm.h
blob: b8e6214d73c400069a34f0c02156a0e7389e971f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* Copyright (c) 2024 Freya Murphy */

#ifndef __ASM_H__
#define __ASM_H__

#include <stddef.h>

#include "lex.h"
#include "parse.h"

struct str_table {
	char *ptr;
	size_t size;
};

/* initalize a string table */
int strtbl_init(struct str_table *str_tbl);

/* free a string table */
void strtbl_free(struct str_table *str_tbl);

/* get a string form the string table */
int strtbl_get_str(struct str_table *str_tbl, const char *str, size_t *res);

/* get or append a string into the string table */
int strtbl_write_str(struct str_table *str_tbl, const char *str, size_t *res);

struct section_meta {
	void *reltbl;
	uint32_t reltbl_len;
	uint32_t reltbl_idx; // reltbl idx in shdr
	uint32_t shdr_idx; // sec idx in shdr
	uint32_t v_addr;
};

struct assembler {
	struct lexer lexer;
	struct parser parser;
	struct str_table shstr_tbl;
	struct str_table str_tbl;

	struct section_meta *meta;
	size_t shstrtbl_idx;
	size_t strtbl_idx;
	size_t symtbl_idx;
};

int assembler_init(struct assembler *asm, const char *path);
void assembler_free(struct assembler *asm);

/* assemble a mips32 file*/
int assemble_file_mips32(char *path);

#endif /* __ASM_H__ */