summaryrefslogtreecommitdiff
path: root/asmmon.h
diff options
context:
space:
mode:
Diffstat (limited to 'asmmon.h')
-rw-r--r--asmmon.h79
1 files changed, 62 insertions, 17 deletions
diff --git a/asmmon.h b/asmmon.h
index 019be00..52315a9 100644
--- a/asmmon.h
+++ b/asmmon.h
@@ -28,9 +28,40 @@ struct line {
uint64_t addr;
};
+struct tok {
+ struct tok *next; /* Pointer to the next token. */
+ uint8_t id; /* Token ID. */
+ uint8_t type; /* Token type ID. */
+
+ /* Token value(s). */
+ union {
+ char *str;
+ uint8_t byte ;
+ uint16_t word ;
+ uint32_t dword;
+ uint64_t qword;
+ };
+};
+
+struct ln {
+ struct ln *next; /* Pointer to the next line. */
+ struct tok *tok; /* The token(s) for this line. */
+ uint16_t count; /* Total tokens for this line. */
+ uint16_t linenum; /* Line number. */
+ uint64_t addr; /* The address of this line. */
+ uint8_t stab; /* Number of starting tabs. */
+ uint8_t sspace; /* Number of starting spaces. */
+ uint8_t etab; /* Number of ending tabs. */
+ uint8_t espace; /* Number of ending spaces. */
+};
+
+typedef struct tok token;
+typedef struct ln line;
+
+
struct fixup {
struct symbol *s;
- uint16_t ln;
+ token *t;
uint64_t adr;
};
@@ -45,6 +76,10 @@ extern char lexeme[];
extern char *string[];
extern char *comment[];
extern uint16_t incl[];
+extern line *lines;
+extern line *last_line;
+extern token *tokens;
+extern token *last_tok;
extern struct line tokline[];
extern struct line tln[];
extern struct symbol *symbols[];
@@ -52,7 +87,7 @@ extern struct fixup *fixups[];
extern uint8_t lex_type;
-enum {
+enum dir {
DIR_ORG,
DIR_BYTE,
DIR_WORD,
@@ -61,12 +96,12 @@ enum {
DIR_INCLUDE
};
-enum {
+enum token {
TOK_DIR,
TOK_LABEL,
TOK_SYM,
- TOK_PLUS,
- TOK_MINUS,
+ TOK_EXPR,
+ TOK_COMMA,
TOK_STRING,
TOK_CHAR,
TOK_IMM,
@@ -79,11 +114,12 @@ enum {
TOK_INCLUDE
};
-enum {
- BASE_HEX,
- BASE_DEC,
- BASE_BIN,
- BASE_CHAR
+enum expr {
+ EXPR_PLUS,
+ EXPR_MINUS,
+ EXPR_LOW,
+ EXPR_HIGH,
+ EXPR_NONE
};
static const uint8_t opcodes[OPNUM][9] = {
@@ -200,8 +236,8 @@ static const char *lex_tok[15] = {
[0x0] = "TOK_DIR",
[0x1] = "TOK_LABEL",
[0x2] = "TOK_SYM",
- [0x3] = "TOK_PLUS",
- [0x4] = "TOK_MINUS",
+ [0x3] = "TOK_EXPR",
+ [0x4] = "TOK_COMMA",
[0x5] = "TOK_STRING",
[0x6] = "TOK_CHAR",
[0x7] = "TOK_IMM",
@@ -437,10 +473,12 @@ extern uint16_t stridx;
extern uint16_t comidx;
extern uint16_t inc_file; /* Number of included files. */
-typedef struct {
+struct bc {
uint64_t progsize;
uint64_t datasize;
-} bytecount;
+};
+
+typedef struct bc bytecount;
extern uint8_t defined;
extern uint8_t isfixup;
@@ -450,7 +488,14 @@ extern uint16_t mksymbol(const char *name, uint64_t val, uint8_t def, uint8_t us
extern uint64_t use_symbol(const char *name, uint16_t id, uint64_t val, uint8_t useid, uint8_t dbg);
extern uint8_t set_symval(const char *name, uint16_t id, uint64_t val, uint8_t useid, uint8_t dbg);
extern char *get_symname(uint16_t id, uint8_t dbg);
-extern uint16_t get_symid(const char *name, uint64_t val, uint16_t ln, uint8_t dbg);
+extern uint16_t get_symid(const char *name, uint64_t val, token *t, uint8_t dbg);
extern uint16_t get_comment(const char *cmnt, uint8_t dbg);
-extern uint16_t reslv_fixups(struct line *l, uint8_t dbg);
-extern uint64_t lex(char *str, struct line *l, uint64_t address, uint8_t dbg);
+extern uint16_t reslv_fixups(uint8_t dbg);
+extern line *find_line(uint16_t ln, uint8_t dbg);
+extern uint64_t lex(char *str, uint64_t address, uint8_t dbg);
+
+extern uint64_t parse_tokens(token *tm, bytecount *bc, uint8_t isasm, uint64_t address, uint8_t dbg);
+extern token *make_token(uint8_t id, uint8_t type, uint64_t value, char *str);
+extern void assemble(line *ln, bytecount *bc, uint8_t dbg);
+extern void free_tokens(token *t, uint16_t count);
+extern void free_lines();