aboutsummaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 21:39:48 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 21:40:25 +0000
commit75649381132924c4cb5e4fa215e200e2457a1434 (patch)
tree4abbb6ab858c2f8bb9003724bf4a8b0158aaeccc /asm
parent32c1bcb859426c73e3bc45fa537e932018346d07 (diff)
downloadovm-75649381132924c4cb5e4fa215e200e2457a1434.tar.gz
ovm-75649381132924c4cb5e4fa215e200e2457a1434.tar.bz2
ovm-75649381132924c4cb5e4fa215e200e2457a1434.zip
Implemented lexer and parser for new memory management instructions
Diffstat (limited to 'asm')
-rw-r--r--asm/lexer.c30
-rw-r--r--asm/lexer.h4
-rw-r--r--asm/parser.c12
3 files changed, 45 insertions, 1 deletions
diff --git a/asm/lexer.c b/asm/lexer.c
index f0408ad..ca467c5 100644
--- a/asm/lexer.c
+++ b/asm/lexer.c
@@ -42,6 +42,14 @@ const char *token_type_as_cstr(token_type_t type)
return "MOV";
case TOKEN_DUP:
return "DUP";
+ case TOKEN_MALLOC:
+ return "MALLOC";
+ case TOKEN_MSET:
+ return "MSET";
+ case TOKEN_MGET:
+ return "MGET";
+ case TOKEN_MDELETE:
+ return "MDELETE";
case TOKEN_NOT:
return "NOT";
case TOKEN_OR:
@@ -117,7 +125,7 @@ bool is_valid_hex_char(char c)
token_t tokenise_symbol(buffer_t *buffer, size_t *column)
{
- static_assert(NUMBER_OF_OPCODES == 73, "tokenise_buffer: Out of date!");
+ static_assert(NUMBER_OF_OPCODES == 83, "tokenise_buffer: Out of date!");
size_t sym_size = 0;
for (; sym_size < space_left(buffer) &&
@@ -168,6 +176,26 @@ token_t tokenise_symbol(buffer_t *buffer, size_t *column)
offset = 3;
type = TOKEN_DUP;
}
+ else if (sym_size >= 6 && strncmp(opcode, "MALLOC", 6) == 0)
+ {
+ offset = 6;
+ type = TOKEN_MALLOC;
+ }
+ else if (sym_size >= 4 && strncmp(opcode, "MSET", 4) == 0)
+ {
+ offset = 4;
+ type = TOKEN_MSET;
+ }
+ else if (sym_size >= 4 && strncmp(opcode, "MGET", 4) == 0)
+ {
+ offset = 4;
+ type = TOKEN_MGET;
+ }
+ else if (sym_size >= 7 && strncmp(opcode, "MDELETE", 7) == 0)
+ {
+ offset = 7;
+ type = TOKEN_MDELETE;
+ }
else if (sym_size >= 3 && strncmp(opcode, "NOT", 3) == 0)
{
offset = 3;
diff --git a/asm/lexer.h b/asm/lexer.h
index 9ae6fcf..c7d1f3d 100644
--- a/asm/lexer.h
+++ b/asm/lexer.h
@@ -26,6 +26,10 @@ typedef enum TokenType
TOKEN_PUSH_REG,
TOKEN_MOV,
TOKEN_DUP,
+ TOKEN_MALLOC,
+ TOKEN_MSET,
+ TOKEN_MGET,
+ TOKEN_MDELETE,
TOKEN_NOT,
TOKEN_OR,
TOKEN_AND,
diff --git a/asm/parser.c b/asm/parser.c
index 41ffdb9..a7340f9 100644
--- a/asm/parser.c
+++ b/asm/parser.c
@@ -221,6 +221,18 @@ perr_t parse_next_inst(token_stream_t *stream, inst_t *ret)
case TOKEN_DUP:
ret->opcode = OP_DUP_BYTE;
return parse_utype_inst_with_operand(stream, ret);
+ case TOKEN_MALLOC:
+ ret->opcode = OP_MALLOC_BYTE;
+ return parse_utype_inst_with_operand(stream, ret);
+ case TOKEN_MSET:
+ ret->opcode = OP_MSET_BYTE;
+ return parse_utype_inst_with_operand(stream, ret);
+ case TOKEN_MGET:
+ ret->opcode = OP_MGET_BYTE;
+ return parse_utype_inst_with_operand(stream, ret);
+ case TOKEN_MDELETE:
+ ret->opcode = OP_MDELETE;
+ break;
case TOKEN_NOT:
ret->opcode = OP_NOT_BYTE;
return parse_utype_inst(stream, ret);