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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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);
}
}
}
|