diff options
Diffstat (limited to 'usr.bin/oasm/parse.c')
-rw-r--r-- | usr.bin/oasm/parse.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/usr.bin/oasm/parse.c b/usr.bin/oasm/parse.c new file mode 100644 index 0000000..45c697a --- /dev/null +++ b/usr.bin/oasm/parse.c @@ -0,0 +1,113 @@ +/* Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdint.h> +#include <stddef.h> +#include <stdlib.h> +#include <oasm/state.h> +#include <oasm/lex.h> +#include <oasm/parse.h> +#include <oasm/log.h> + +static const char *tokstr[] = { + [ TT_UNKNOWN] = "bad", + [ TT_ADD ] = "add", + [ TT_SUB ] = "sub", + [ TT_MUL ] = "mul", + [ TT_DIV ] = "div", + [ TT_COMMA ] = ",", + [ TT_INC ] = "inc", + [ TT_DEC ] = "dec", + [ TT_MOV ] = "mov", + + /* X<n> registers */ + [ TT_X0 ] = "x0", + [ TT_X1 ] = "x1", + [ TT_X2 ] = "x2", + [ TT_X3 ] = "x3", + [ TT_X4 ] = "x4", + [ TT_X5 ] = "x5", + [ TT_X6 ] = "x6", + [ TT_X7 ] = "x7", + [ TT_X8 ] = "x8", + [ TT_X9 ] = "x9", + [ TT_X10 ] = "x10", + [ TT_X11 ] = "x11", + [ TT_X12 ] = "x12", + [ TT_X13 ] = "x13", + [ TT_X14 ] = "x14", + [ TT_X15 ] = "x15", + + /* V<n> registers */ + [ TT_F0 ] = "v0", + [ TT_F1 ] = "v1", + [ TT_F2 ] = "v2", + [ TT_F3 ] = "v3", + [ TT_F4 ] = "v4", + [ TT_F5 ] = "v5", + [ TT_F6 ] = "v6", + [ TT_F7 ] = "v7", + + /* D<n> registers */ + [ TT_D0 ] = "d0", + [ TT_D1 ] = "d1", + [ TT_D2 ] = "d2", + [ TT_D3 ] = "d3", + [ TT_D4 ] = "d4", + [ TT_D5 ] = "d5", + [ TT_D6 ] = "d6", + [ TT_D7 ] = "d7", + + /* V<n> registers */ + [ TT_V0 ] = "v0", + [ TT_V1 ] = "v1", + [ TT_V2 ] = "v2", + [ TT_V3 ] = "v3", + [ TT_V4 ] = "v4", + [ TT_V5 ] = "v5", + [ TT_V6 ] = "v6", + [ TT_V7 ] = "v7", +}; + +void +parse_enter(struct oasm_state *state) +{ + struct oasm_token tok; + int error = 0; + + for (;;) { + error = lex_tok(state, &tok); + if (error < 0) { + break; + } + + if (tok.raw != NULL) { + free(tok.raw); + } + } +} |