2 * Copyright (c) 2017 Rob Clark <robdclark@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * Intermediate representation for an instruction, before final encoding.
35 * This mostly exists because we need to resolve label offset's in a 2nd
36 * pass, but also so that parser.y doesn't really need to care so much
37 * about the different encodings for 2src regs vs 1src+immed, or mnemonics
39 struct asm_instruction
{
62 struct asm_instruction
*next_instr(int tok
);
63 void decl_label(const char *str
);
66 static inline uint32_t
67 parse_reg(const char *str
)
72 if (!strcmp(str
, "$rem"))
74 else if (!strcmp(str
, "$addr"))
76 else if (!strcmp(str
, "$addr2"))
78 else if (!strcmp(str
, "$data"))
81 ret
= strtol(str
+ 1, &retstr
, 16);
83 if (*retstr
!= '\0') {
84 printf("invalid register: %s\n", str
);
91 static inline uint32_t
92 parse_literal(const char *str
)
97 ret
= strtol(str
+ 1, &retstr
, 16);
100 printf("invalid literal: %s\n", str
);
107 static inline uint32_t
108 parse_bit(const char *str
)
110 return strtol(str
+ 1, NULL
, 10);
113 unsigned parse_control_reg(const char *name
);
115 /* string trailing ':' off label: */
116 static inline const char *
117 parse_label_decl(const char *str
)
119 char *s
= strdup(str
);
120 s
[strlen(s
) - 1] = '\0';
124 void yyset_in (FILE * _in_str
);