lc3bid.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. /* Generated by re2c
  2. */
  3. /*
  4. * LC-3b identifier recognition and instruction handling
  5. *
  6. * Copyright (C) 2003-2007 Peter Johnson
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  21. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. * POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include <util.h>
  30. #include <libyasm.h>
  31. #include "modules/arch/lc3b/lc3barch.h"
  32. /* Opcode modifiers. The opcode bytes are in "reverse" order because the
  33. * parameters are read from the arch-specific data in LSB->MSB order.
  34. * (only for asthetic reasons in the lexer code below, no practical reason).
  35. */
  36. #define MOD_OpHAdd (1UL<<0) /* Parameter adds to upper 8 bits of insn */
  37. #define MOD_OpLAdd (1UL<<1) /* Parameter adds to lower 8 bits of insn */
  38. /* Operand types. These are more detailed than the "general" types for all
  39. * architectures, as they include the size, for instance.
  40. * Bit Breakdown (from LSB to MSB):
  41. * - 1 bit = general type (must be exact match, except for =3):
  42. * 0 = immediate
  43. * 1 = register
  44. *
  45. * MSBs than the above are actions: what to do with the operand if the
  46. * instruction matches. Essentially describes what part of the output bytecode
  47. * gets the operand. This may require conversion (e.g. a register going into
  48. * an ea field). Naturally, only one of each of these may be contained in the
  49. * operands of a single insn_info structure.
  50. * - 2 bits = action:
  51. * 0 = does nothing (operand data is discarded)
  52. * 1 = DR field
  53. * 2 = SR field
  54. * 3 = immediate
  55. *
  56. * Immediate operands can have different sizes.
  57. * - 3 bits = size:
  58. * 0 = no immediate
  59. * 1 = 4-bit immediate
  60. * 2 = 5-bit immediate
  61. * 3 = 6-bit index, word (16 bit)-multiple
  62. * 4 = 6-bit index, byte-multiple
  63. * 5 = 8-bit immediate, word-multiple
  64. * 6 = 9-bit signed immediate, word-multiple
  65. * 7 = 9-bit signed offset from next PC ($+2), word-multiple
  66. */
  67. #define OPT_Imm 0x0
  68. #define OPT_Reg 0x1
  69. #define OPT_MASK 0x1
  70. #define OPA_None (0<<1)
  71. #define OPA_DR (1<<1)
  72. #define OPA_SR (2<<1)
  73. #define OPA_Imm (3<<1)
  74. #define OPA_MASK (3<<1)
  75. #define OPI_None (LC3B_IMM_NONE<<3)
  76. #define OPI_4 (LC3B_IMM_4<<3)
  77. #define OPI_5 (LC3B_IMM_5<<3)
  78. #define OPI_6W (LC3B_IMM_6_WORD<<3)
  79. #define OPI_6B (LC3B_IMM_6_BYTE<<3)
  80. #define OPI_8 (LC3B_IMM_8<<3)
  81. #define OPI_9 (LC3B_IMM_9<<3)
  82. #define OPI_9PC (LC3B_IMM_9_PC<<3)
  83. #define OPI_MASK (7<<3)
  84. typedef struct lc3b_insn_info {
  85. /* Opcode modifiers for variations of instruction. As each modifier reads
  86. * its parameter in LSB->MSB order from the arch-specific data[1] from the
  87. * lexer data, and the LSB of the arch-specific data[1] is reserved for the
  88. * count of insn_info structures in the instruction grouping, there can
  89. * only be a maximum of 3 modifiers.
  90. */
  91. unsigned int modifiers;
  92. /* The basic 2 byte opcode */
  93. unsigned int opcode;
  94. /* The number of operands this form of the instruction takes */
  95. unsigned char num_operands;
  96. /* The types of each operand, see above */
  97. unsigned int operands[3];
  98. } lc3b_insn_info;
  99. typedef struct lc3b_id_insn {
  100. yasm_insn insn; /* base structure */
  101. /* instruction parse group - NULL if empty instruction (just prefixes) */
  102. /*@null@*/ const lc3b_insn_info *group;
  103. /* Modifier data */
  104. unsigned long mod_data;
  105. /* Number of elements in the instruction parse group */
  106. unsigned int num_info:8;
  107. } lc3b_id_insn;
  108. static void lc3b_id_insn_destroy(void *contents);
  109. static void lc3b_id_insn_print(const void *contents, FILE *f, int indent_level);
  110. static void lc3b_id_insn_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc);
  111. static const yasm_bytecode_callback lc3b_id_insn_callback = {
  112. lc3b_id_insn_destroy,
  113. lc3b_id_insn_print,
  114. lc3b_id_insn_finalize,
  115. NULL,
  116. yasm_bc_calc_len_common,
  117. yasm_bc_expand_common,
  118. yasm_bc_tobytes_common,
  119. YASM_BC_SPECIAL_INSN
  120. };
  121. /*
  122. * Instruction groupings
  123. */
  124. static const lc3b_insn_info empty_insn[] = {
  125. { 0, 0, 0, {0, 0, 0} }
  126. };
  127. static const lc3b_insn_info addand_insn[] = {
  128. { MOD_OpHAdd, 0x1000, 3,
  129. {OPT_Reg|OPA_DR, OPT_Reg|OPA_SR, OPT_Reg|OPA_Imm|OPI_5} },
  130. { MOD_OpHAdd, 0x1020, 3,
  131. {OPT_Reg|OPA_DR, OPT_Reg|OPA_SR, OPT_Imm|OPA_Imm|OPI_5} }
  132. };
  133. static const lc3b_insn_info br_insn[] = {
  134. { MOD_OpHAdd, 0x0000, 1, {OPT_Imm|OPA_Imm|OPI_9PC, 0, 0} }
  135. };
  136. static const lc3b_insn_info jmp_insn[] = {
  137. { 0, 0xC000, 2, {OPT_Reg|OPA_DR, OPT_Imm|OPA_Imm|OPI_9, 0} }
  138. };
  139. static const lc3b_insn_info lea_insn[] = {
  140. { 0, 0xE000, 2, {OPT_Reg|OPA_DR, OPT_Imm|OPA_Imm|OPI_9PC, 0} }
  141. };
  142. static const lc3b_insn_info ldst_insn[] = {
  143. { MOD_OpHAdd, 0x0000, 3,
  144. {OPT_Reg|OPA_DR, OPT_Reg|OPA_SR, OPT_Imm|OPA_Imm|OPI_6W} }
  145. };
  146. static const lc3b_insn_info ldstb_insn[] = {
  147. { MOD_OpHAdd, 0x0000, 3,
  148. {OPT_Reg|OPA_DR, OPT_Reg|OPA_SR, OPT_Imm|OPA_Imm|OPI_6B} }
  149. };
  150. static const lc3b_insn_info not_insn[] = {
  151. { 0, 0x903F, 2, {OPT_Reg|OPA_DR, OPT_Reg|OPA_SR, 0} }
  152. };
  153. static const lc3b_insn_info nooperand_insn[] = {
  154. { MOD_OpHAdd, 0x0000, 0, {0, 0, 0} }
  155. };
  156. static const lc3b_insn_info shift_insn[] = {
  157. { MOD_OpLAdd, 0xD000, 3,
  158. {OPT_Reg|OPA_DR, OPT_Reg|OPA_SR, OPT_Imm|OPA_Imm|OPI_4} }
  159. };
  160. static const lc3b_insn_info trap_insn[] = {
  161. { 0, 0xF000, 1, {OPT_Imm|OPA_Imm|OPI_8, 0, 0} }
  162. };
  163. static void
  164. lc3b_id_insn_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc)
  165. {
  166. lc3b_id_insn *id_insn = (lc3b_id_insn *)bc->contents;
  167. lc3b_insn *insn;
  168. int num_info = id_insn->num_info;
  169. const lc3b_insn_info *info = id_insn->group;
  170. unsigned long mod_data = id_insn->mod_data;
  171. int found = 0;
  172. yasm_insn_operand *op;
  173. int i;
  174. yasm_insn_finalize(&id_insn->insn);
  175. /* Just do a simple linear search through the info array for a match.
  176. * First match wins.
  177. */
  178. for (; num_info>0 && !found; num_info--, info++) {
  179. int mismatch = 0;
  180. /* Match # of operands */
  181. if (id_insn->insn.num_operands != info->num_operands)
  182. continue;
  183. if (id_insn->insn.num_operands == 0) {
  184. found = 1; /* no operands -> must have a match here. */
  185. break;
  186. }
  187. /* Match each operand type and size */
  188. for(i = 0, op = yasm_insn_ops_first(&id_insn->insn);
  189. op && i<info->num_operands && !mismatch;
  190. op = yasm_insn_op_next(op), i++) {
  191. /* Check operand type */
  192. switch ((int)(info->operands[i] & OPT_MASK)) {
  193. case OPT_Imm:
  194. if (op->type != YASM_INSN__OPERAND_IMM)
  195. mismatch = 1;
  196. break;
  197. case OPT_Reg:
  198. if (op->type != YASM_INSN__OPERAND_REG)
  199. mismatch = 1;
  200. break;
  201. default:
  202. yasm_internal_error(N_("invalid operand type"));
  203. }
  204. if (mismatch)
  205. break;
  206. }
  207. if (!mismatch) {
  208. found = 1;
  209. break;
  210. }
  211. }
  212. if (!found) {
  213. /* Didn't find a matching one */
  214. yasm_error_set(YASM_ERROR_TYPE,
  215. N_("invalid combination of opcode and operands"));
  216. return;
  217. }
  218. /* Copy what we can from info */
  219. insn = yasm_xmalloc(sizeof(lc3b_insn));
  220. yasm_value_initialize(&insn->imm, NULL, 0);
  221. insn->imm_type = LC3B_IMM_NONE;
  222. insn->opcode = info->opcode;
  223. /* Apply modifiers */
  224. if (info->modifiers & MOD_OpHAdd) {
  225. insn->opcode += ((unsigned int)(mod_data & 0xFF))<<8;
  226. mod_data >>= 8;
  227. }
  228. if (info->modifiers & MOD_OpLAdd) {
  229. insn->opcode += (unsigned int)(mod_data & 0xFF);
  230. /*mod_data >>= 8;*/
  231. }
  232. /* Go through operands and assign */
  233. if (id_insn->insn.num_operands > 0) {
  234. for(i = 0, op = yasm_insn_ops_first(&id_insn->insn);
  235. op && i<info->num_operands; op = yasm_insn_op_next(op), i++) {
  236. switch ((int)(info->operands[i] & OPA_MASK)) {
  237. case OPA_None:
  238. /* Throw away the operand contents */
  239. if (op->type == YASM_INSN__OPERAND_IMM)
  240. yasm_expr_destroy(op->data.val);
  241. break;
  242. case OPA_DR:
  243. if (op->type != YASM_INSN__OPERAND_REG)
  244. yasm_internal_error(N_("invalid operand conversion"));
  245. insn->opcode |= ((unsigned int)(op->data.reg & 0x7)) << 9;
  246. break;
  247. case OPA_SR:
  248. if (op->type != YASM_INSN__OPERAND_REG)
  249. yasm_internal_error(N_("invalid operand conversion"));
  250. insn->opcode |= ((unsigned int)(op->data.reg & 0x7)) << 6;
  251. break;
  252. case OPA_Imm:
  253. insn->imm_type = (info->operands[i] & OPI_MASK)>>3;
  254. switch (op->type) {
  255. case YASM_INSN__OPERAND_IMM:
  256. if (insn->imm_type == LC3B_IMM_6_WORD
  257. || insn->imm_type == LC3B_IMM_8
  258. || insn->imm_type == LC3B_IMM_9
  259. || insn->imm_type == LC3B_IMM_9_PC)
  260. op->data.val = yasm_expr_create(YASM_EXPR_SHR,
  261. yasm_expr_expr(op->data.val),
  262. yasm_expr_int(yasm_intnum_create_uint(1)),
  263. op->data.val->line);
  264. if (yasm_value_finalize_expr(&insn->imm,
  265. op->data.val,
  266. prev_bc, 0))
  267. yasm_error_set(YASM_ERROR_TOO_COMPLEX,
  268. N_("immediate expression too complex"));
  269. break;
  270. case YASM_INSN__OPERAND_REG:
  271. if (yasm_value_finalize_expr(&insn->imm,
  272. yasm_expr_create_ident(yasm_expr_int(
  273. yasm_intnum_create_uint(op->data.reg & 0x7)),
  274. bc->line), prev_bc, 0))
  275. yasm_internal_error(N_("reg expr too complex?"));
  276. break;
  277. default:
  278. yasm_internal_error(N_("invalid operand conversion"));
  279. }
  280. break;
  281. default:
  282. yasm_internal_error(N_("unknown operand action"));
  283. }
  284. /* Clear so it doesn't get destroyed */
  285. op->type = YASM_INSN__OPERAND_REG;
  286. }
  287. if (insn->imm_type == LC3B_IMM_9_PC) {
  288. if (insn->imm.seg_of || insn->imm.rshift > 1
  289. || insn->imm.curpos_rel)
  290. yasm_error_set(YASM_ERROR_VALUE, N_("invalid jump target"));
  291. insn->imm.curpos_rel = 1;
  292. }
  293. }
  294. /* Transform the bytecode */
  295. yasm_lc3b__bc_transform_insn(bc, insn);
  296. }
  297. #define YYCTYPE unsigned char
  298. #define YYCURSOR id
  299. #define YYLIMIT id
  300. #define YYMARKER marker
  301. #define YYFILL(n) (void)(n)
  302. yasm_arch_regtmod
  303. yasm_lc3b__parse_check_regtmod(yasm_arch *arch, const char *oid, size_t id_len,
  304. uintptr_t *data)
  305. {
  306. const YYCTYPE *id = (const YYCTYPE *)oid;
  307. /*const char *marker;*/
  308. {
  309. YYCTYPE yych;
  310. goto yy0;
  311. ++YYCURSOR;
  312. yy0:
  313. if((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
  314. yych = *YYCURSOR;
  315. if(yych <= 'R'){
  316. if(yych <= '\000') goto yy6;
  317. if(yych <= 'Q') goto yy4;
  318. goto yy2;
  319. } else {
  320. if(yych != 'r') goto yy4;
  321. goto yy2;
  322. }
  323. yy2: yych = *++YYCURSOR;
  324. if(yych <= '/') goto yy5;
  325. if(yych <= '7') goto yy8;
  326. goto yy5;
  327. yy3:
  328. {
  329. return YASM_ARCH_NOTREGTMOD;
  330. }
  331. yy4: ++YYCURSOR;
  332. if(YYLIMIT == YYCURSOR) YYFILL(1);
  333. yych = *YYCURSOR;
  334. goto yy5;
  335. yy5: if(yych <= '\000') goto yy3;
  336. goto yy4;
  337. yy6: yych = *++YYCURSOR;
  338. goto yy7;
  339. yy7:
  340. {
  341. return YASM_ARCH_NOTREGTMOD;
  342. }
  343. yy8: yych = *++YYCURSOR;
  344. if(yych >= '\001') goto yy4;
  345. goto yy9;
  346. yy9:
  347. {
  348. *data = (oid[1]-'0');
  349. return YASM_ARCH_REG;
  350. }
  351. }
  352. }
  353. #define RET_INSN(g, m) \
  354. do { \
  355. group = g##_insn; \
  356. mod = m; \
  357. nelems = NELEMS(g##_insn); \
  358. goto done; \
  359. } while(0)
  360. yasm_arch_insnprefix
  361. yasm_lc3b__parse_check_insnprefix(yasm_arch *arch, const char *oid,
  362. size_t id_len, unsigned long line,
  363. yasm_bytecode **bc, uintptr_t *prefix)
  364. {
  365. const YYCTYPE *id = (const YYCTYPE *)oid;
  366. const lc3b_insn_info *group = empty_insn;
  367. unsigned long mod = 0;
  368. unsigned int nelems = NELEMS(empty_insn);
  369. lc3b_id_insn *id_insn;
  370. *bc = (yasm_bytecode *)NULL;
  371. *prefix = 0;
  372. /*const char *marker;*/
  373. {
  374. YYCTYPE yych;
  375. goto yy10;
  376. ++YYCURSOR;
  377. yy10:
  378. if((YYLIMIT - YYCURSOR) < 6) YYFILL(6);
  379. yych = *YYCURSOR;
  380. if(yych <= 'T'){
  381. if(yych <= 'K'){
  382. if(yych <= 'A'){
  383. if(yych <= '\000') goto yy23;
  384. if(yych <= '@') goto yy21;
  385. goto yy12;
  386. } else {
  387. if(yych <= 'B') goto yy14;
  388. if(yych == 'J') goto yy15;
  389. goto yy21;
  390. }
  391. } else {
  392. if(yych <= 'N'){
  393. if(yych <= 'L') goto yy16;
  394. if(yych <= 'M') goto yy21;
  395. goto yy18;
  396. } else {
  397. if(yych <= 'Q') goto yy21;
  398. if(yych <= 'R') goto yy19;
  399. if(yych <= 'S') goto yy17;
  400. goto yy20;
  401. }
  402. }
  403. } else {
  404. if(yych <= 'l'){
  405. if(yych <= 'b'){
  406. if(yych <= '`') goto yy21;
  407. if(yych >= 'b') goto yy14;
  408. goto yy12;
  409. } else {
  410. if(yych == 'j') goto yy15;
  411. if(yych <= 'k') goto yy21;
  412. goto yy16;
  413. }
  414. } else {
  415. if(yych <= 'q'){
  416. if(yych == 'n') goto yy18;
  417. goto yy21;
  418. } else {
  419. if(yych <= 'r') goto yy19;
  420. if(yych <= 's') goto yy17;
  421. if(yych <= 't') goto yy20;
  422. goto yy21;
  423. }
  424. }
  425. }
  426. yy12: yych = *++YYCURSOR;
  427. if(yych <= 'N'){
  428. if(yych == 'D') goto yy88;
  429. if(yych <= 'M') goto yy22;
  430. goto yy89;
  431. } else {
  432. if(yych <= 'd'){
  433. if(yych <= 'c') goto yy22;
  434. goto yy88;
  435. } else {
  436. if(yych == 'n') goto yy89;
  437. goto yy22;
  438. }
  439. }
  440. yy13:
  441. {
  442. return YASM_ARCH_NOTINSNPREFIX;
  443. }
  444. yy14: yych = *++YYCURSOR;
  445. if(yych == 'R') goto yy72;
  446. if(yych == 'r') goto yy72;
  447. goto yy22;
  448. yy15: yych = *++YYCURSOR;
  449. if(yych <= 'S'){
  450. if(yych == 'M') goto yy66;
  451. if(yych <= 'R') goto yy22;
  452. goto yy67;
  453. } else {
  454. if(yych <= 'm'){
  455. if(yych <= 'l') goto yy22;
  456. goto yy66;
  457. } else {
  458. if(yych == 's') goto yy67;
  459. goto yy22;
  460. }
  461. }
  462. yy16: yych = *++YYCURSOR;
  463. if(yych <= 'S'){
  464. if(yych <= 'D'){
  465. if(yych <= 'C') goto yy22;
  466. goto yy53;
  467. } else {
  468. if(yych <= 'E') goto yy55;
  469. if(yych <= 'R') goto yy22;
  470. goto yy56;
  471. }
  472. } else {
  473. if(yych <= 'e'){
  474. if(yych <= 'c') goto yy22;
  475. if(yych <= 'd') goto yy53;
  476. goto yy55;
  477. } else {
  478. if(yych == 's') goto yy56;
  479. goto yy22;
  480. }
  481. }
  482. yy17: yych = *++YYCURSOR;
  483. if(yych == 'T') goto yy47;
  484. if(yych == 't') goto yy47;
  485. goto yy22;
  486. yy18: yych = *++YYCURSOR;
  487. if(yych == 'O') goto yy42;
  488. if(yych == 'o') goto yy42;
  489. goto yy22;
  490. yy19: yych = *++YYCURSOR;
  491. if(yych <= 'T'){
  492. if(yych <= 'E'){
  493. if(yych <= 'D') goto yy22;
  494. goto yy29;
  495. } else {
  496. if(yych <= 'R') goto yy22;
  497. if(yych <= 'S') goto yy30;
  498. goto yy31;
  499. }
  500. } else {
  501. if(yych <= 'r'){
  502. if(yych == 'e') goto yy29;
  503. goto yy22;
  504. } else {
  505. if(yych <= 's') goto yy30;
  506. if(yych <= 't') goto yy31;
  507. goto yy22;
  508. }
  509. }
  510. yy20: yych = *++YYCURSOR;
  511. if(yych == 'R') goto yy25;
  512. if(yych == 'r') goto yy25;
  513. goto yy22;
  514. yy21: ++YYCURSOR;
  515. if(YYLIMIT == YYCURSOR) YYFILL(1);
  516. yych = *YYCURSOR;
  517. goto yy22;
  518. yy22: if(yych <= '\000') goto yy13;
  519. goto yy21;
  520. yy23: yych = *++YYCURSOR;
  521. goto yy24;
  522. yy24:
  523. {
  524. return YASM_ARCH_NOTINSNPREFIX;
  525. }
  526. yy25: yych = *++YYCURSOR;
  527. if(yych == 'A') goto yy26;
  528. if(yych != 'a') goto yy22;
  529. goto yy26;
  530. yy26: yych = *++YYCURSOR;
  531. if(yych == 'P') goto yy27;
  532. if(yych != 'p') goto yy22;
  533. goto yy27;
  534. yy27: yych = *++YYCURSOR;
  535. if(yych >= '\001') goto yy21;
  536. goto yy28;
  537. yy28:
  538. { RET_INSN(trap, 0); }
  539. yy29: yych = *++YYCURSOR;
  540. if(yych == 'T') goto yy40;
  541. if(yych == 't') goto yy40;
  542. goto yy22;
  543. yy30: yych = *++YYCURSOR;
  544. if(yych == 'H') goto yy34;
  545. if(yych == 'h') goto yy34;
  546. goto yy22;
  547. yy31: yych = *++YYCURSOR;
  548. if(yych == 'I') goto yy32;
  549. if(yych != 'i') goto yy22;
  550. goto yy32;
  551. yy32: yych = *++YYCURSOR;
  552. if(yych >= '\001') goto yy21;
  553. goto yy33;
  554. yy33:
  555. { RET_INSN(nooperand, 0x80); }
  556. yy34: yych = *++YYCURSOR;
  557. if(yych == 'F') goto yy35;
  558. if(yych != 'f') goto yy22;
  559. goto yy35;
  560. yy35: yych = *++YYCURSOR;
  561. if(yych <= 'L'){
  562. if(yych == 'A') goto yy38;
  563. if(yych <= 'K') goto yy22;
  564. goto yy36;
  565. } else {
  566. if(yych <= 'a'){
  567. if(yych <= '`') goto yy22;
  568. goto yy38;
  569. } else {
  570. if(yych != 'l') goto yy22;
  571. goto yy36;
  572. }
  573. }
  574. yy36: yych = *++YYCURSOR;
  575. if(yych >= '\001') goto yy21;
  576. goto yy37;
  577. yy37:
  578. { RET_INSN(shift, 0x10); }
  579. yy38: yych = *++YYCURSOR;
  580. if(yych >= '\001') goto yy21;
  581. goto yy39;
  582. yy39:
  583. { RET_INSN(shift, 0x30); }
  584. yy40: yych = *++YYCURSOR;
  585. if(yych >= '\001') goto yy21;
  586. goto yy41;
  587. yy41:
  588. { RET_INSN(nooperand, 0xCE); }
  589. yy42: yych = *++YYCURSOR;
  590. if(yych <= 'T'){
  591. if(yych == 'P') goto yy45;
  592. if(yych <= 'S') goto yy22;
  593. goto yy43;
  594. } else {
  595. if(yych <= 'p'){
  596. if(yych <= 'o') goto yy22;
  597. goto yy45;
  598. } else {
  599. if(yych != 't') goto yy22;
  600. goto yy43;
  601. }
  602. }
  603. yy43: yych = *++YYCURSOR;
  604. if(yych >= '\001') goto yy21;
  605. goto yy44;
  606. yy44:
  607. { RET_INSN(not, 0); }
  608. yy45: yych = *++YYCURSOR;
  609. if(yych >= '\001') goto yy21;
  610. goto yy46;
  611. yy46:
  612. { RET_INSN(nooperand, 0); }
  613. yy47: yych = *++YYCURSOR;
  614. if(yych <= 'I'){
  615. if(yych <= 'A'){
  616. if(yych >= '\001') goto yy21;
  617. goto yy48;
  618. } else {
  619. if(yych <= 'B') goto yy51;
  620. if(yych <= 'H') goto yy21;
  621. goto yy49;
  622. }
  623. } else {
  624. if(yych <= 'b'){
  625. if(yych <= 'a') goto yy21;
  626. goto yy51;
  627. } else {
  628. if(yych == 'i') goto yy49;
  629. goto yy21;
  630. }
  631. }
  632. yy48:
  633. { RET_INSN(ldst, 0x30); }
  634. yy49: yych = *++YYCURSOR;
  635. if(yych >= '\001') goto yy21;
  636. goto yy50;
  637. yy50:
  638. { RET_INSN(ldst, 0xB0); }
  639. yy51: yych = *++YYCURSOR;
  640. if(yych >= '\001') goto yy21;
  641. goto yy52;
  642. yy52:
  643. { RET_INSN(ldstb, 0x70); }
  644. yy53: yych = *++YYCURSOR;
  645. if(yych <= 'I'){
  646. if(yych <= 'A'){
  647. if(yych >= '\001') goto yy21;
  648. goto yy54;
  649. } else {
  650. if(yych <= 'B') goto yy64;
  651. if(yych <= 'H') goto yy21;
  652. goto yy62;
  653. }
  654. } else {
  655. if(yych <= 'b'){
  656. if(yych <= 'a') goto yy21;
  657. goto yy64;
  658. } else {
  659. if(yych == 'i') goto yy62;
  660. goto yy21;
  661. }
  662. }
  663. yy54:
  664. { RET_INSN(ldst, 0x20); }
  665. yy55: yych = *++YYCURSOR;
  666. if(yych == 'A') goto yy60;
  667. if(yych == 'a') goto yy60;
  668. goto yy22;
  669. yy56: yych = *++YYCURSOR;
  670. if(yych == 'H') goto yy57;
  671. if(yych != 'h') goto yy22;
  672. goto yy57;
  673. yy57: yych = *++YYCURSOR;
  674. if(yych == 'F') goto yy58;
  675. if(yych != 'f') goto yy22;
  676. goto yy58;
  677. yy58: yych = *++YYCURSOR;
  678. if(yych >= '\001') goto yy21;
  679. goto yy59;
  680. yy59:
  681. { RET_INSN(shift, 0x00); }
  682. yy60: yych = *++YYCURSOR;
  683. if(yych >= '\001') goto yy21;
  684. goto yy61;
  685. yy61:
  686. { RET_INSN(lea, 0); }
  687. yy62: yych = *++YYCURSOR;
  688. if(yych >= '\001') goto yy21;
  689. goto yy63;
  690. yy63:
  691. { RET_INSN(ldst, 0xA0); }
  692. yy64: yych = *++YYCURSOR;
  693. if(yych >= '\001') goto yy21;
  694. goto yy65;
  695. yy65:
  696. { RET_INSN(ldstb, 0x60); }
  697. yy66: yych = *++YYCURSOR;
  698. if(yych == 'P') goto yy70;
  699. if(yych == 'p') goto yy70;
  700. goto yy22;
  701. yy67: yych = *++YYCURSOR;
  702. if(yych == 'R') goto yy68;
  703. if(yych != 'r') goto yy22;
  704. goto yy68;
  705. yy68: yych = *++YYCURSOR;
  706. if(yych >= '\001') goto yy21;
  707. goto yy69;
  708. yy69:
  709. { RET_INSN(br, 0x40); }
  710. yy70: yych = *++YYCURSOR;
  711. if(yych >= '\001') goto yy21;
  712. goto yy71;
  713. yy71:
  714. { RET_INSN(jmp, 0); }
  715. yy72: yych = *++YYCURSOR;
  716. if(yych <= 'Z'){
  717. if(yych <= 'N'){
  718. if(yych <= '\000') goto yy73;
  719. if(yych <= 'M') goto yy21;
  720. goto yy74;
  721. } else {
  722. if(yych == 'P') goto yy78;
  723. if(yych <= 'Y') goto yy21;
  724. goto yy76;
  725. }
  726. } else {
  727. if(yych <= 'o'){
  728. if(yych == 'n') goto yy74;
  729. goto yy21;
  730. } else {
  731. if(yych <= 'p') goto yy78;
  732. if(yych == 'z') goto yy76;
  733. goto yy21;
  734. }
  735. }
  736. yy73:
  737. { RET_INSN(br, 0x00); }
  738. yy74: yych = *++YYCURSOR;
  739. if(yych <= 'Z'){
  740. if(yych <= 'O'){
  741. if(yych >= '\001') goto yy21;
  742. goto yy75;
  743. } else {
  744. if(yych <= 'P') goto yy82;
  745. if(yych <= 'Y') goto yy21;
  746. goto yy84;
  747. }
  748. } else {
  749. if(yych <= 'p'){
  750. if(yych <= 'o') goto yy21;
  751. goto yy82;
  752. } else {
  753. if(yych == 'z') goto yy84;
  754. goto yy21;
  755. }
  756. }
  757. yy75:
  758. { RET_INSN(br, 0x08); }
  759. yy76: yych = *++YYCURSOR;
  760. if(yych <= 'P'){
  761. if(yych <= '\000') goto yy77;
  762. if(yych <= 'O') goto yy21;
  763. goto yy80;
  764. } else {
  765. if(yych == 'p') goto yy80;
  766. goto yy21;
  767. }
  768. yy77:
  769. { RET_INSN(br, 0x04); }
  770. yy78: yych = *++YYCURSOR;
  771. if(yych >= '\001') goto yy21;
  772. goto yy79;
  773. yy79:
  774. { RET_INSN(br, 0x02); }
  775. yy80: yych = *++YYCURSOR;
  776. if(yych >= '\001') goto yy21;
  777. goto yy81;
  778. yy81:
  779. { RET_INSN(br, 0x06); }
  780. yy82: yych = *++YYCURSOR;
  781. if(yych >= '\001') goto yy21;
  782. goto yy83;
  783. yy83:
  784. { RET_INSN(br, 0x0A); }
  785. yy84: yych = *++YYCURSOR;
  786. if(yych <= 'P'){
  787. if(yych <= '\000') goto yy85;
  788. if(yych <= 'O') goto yy21;
  789. goto yy86;
  790. } else {
  791. if(yych == 'p') goto yy86;
  792. goto yy21;
  793. }
  794. yy85:
  795. { RET_INSN(br, 0x0C); }
  796. yy86: yych = *++YYCURSOR;
  797. if(yych >= '\001') goto yy21;
  798. goto yy87;
  799. yy87:
  800. { RET_INSN(br, 0x0E); }
  801. yy88: yych = *++YYCURSOR;
  802. if(yych == 'D') goto yy92;
  803. if(yych == 'd') goto yy92;
  804. goto yy22;
  805. yy89: yych = *++YYCURSOR;
  806. if(yych == 'D') goto yy90;
  807. if(yych != 'd') goto yy22;
  808. goto yy90;
  809. yy90: yych = *++YYCURSOR;
  810. if(yych >= '\001') goto yy21;
  811. goto yy91;
  812. yy91:
  813. { RET_INSN(addand, 0x40); }
  814. yy92: yych = *++YYCURSOR;
  815. if(yych >= '\001') goto yy21;
  816. goto yy93;
  817. yy93:
  818. { RET_INSN(addand, 0x00); }
  819. }
  820. done:
  821. id_insn = yasm_xmalloc(sizeof(lc3b_id_insn));
  822. yasm_insn_initialize(&id_insn->insn);
  823. id_insn->group = group;
  824. id_insn->mod_data = mod;
  825. id_insn->num_info = nelems;
  826. *bc = yasm_bc_create_common(&lc3b_id_insn_callback, id_insn, line);
  827. return YASM_ARCH_INSN;
  828. }
  829. static void
  830. lc3b_id_insn_destroy(void *contents)
  831. {
  832. lc3b_id_insn *id_insn = (lc3b_id_insn *)contents;
  833. yasm_insn_delete(&id_insn->insn, yasm_lc3b__ea_destroy);
  834. yasm_xfree(contents);
  835. }
  836. static void
  837. lc3b_id_insn_print(const void *contents, FILE *f, int indent_level)
  838. {
  839. const lc3b_id_insn *id_insn = (const lc3b_id_insn *)contents;
  840. yasm_insn_print(&id_insn->insn, f, indent_level);
  841. /*TODO*/
  842. }
  843. /*@only@*/ yasm_bytecode *
  844. yasm_lc3b__create_empty_insn(yasm_arch *arch, unsigned long line)
  845. {
  846. lc3b_id_insn *id_insn = yasm_xmalloc(sizeof(lc3b_id_insn));
  847. yasm_insn_initialize(&id_insn->insn);
  848. id_insn->group = empty_insn;
  849. id_insn->mod_data = 0;
  850. id_insn->num_info = NELEMS(empty_insn);
  851. return yasm_bc_create_common(&lc3b_id_insn_callback, id_insn, line);
  852. }