URL
https://opencores.org/ocsvn/zipcpu/zipcpu/trunk
Subversion Repositories zipcpu
[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zparser.h] - Rev 18
Go to most recent revision | Compare with Previous | Blame | View Log
//////////////////////////////////////////////////////////////////////////////// // // Filename: zparser.h // // Project: Zip CPU -- a small, lightweight, RISC CPU core // // Purpose: This file is really mis-named. At one time it was going to // be header file for the parser for the Zip Assembler, zasm. // Since then, I discovered Flex and Bison and have written a // parser using those tools. The true parser may therefore be // found in zasm.y. This file, however, still declares some // very valuable tools. In particular, all of the routines used // to build instructions from the appropriate fields are declared // in this file. // // Creator: Dan Gisselquist, Ph.D. // Gisselquist Tecnology, LLC // //////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2015, Gisselquist Technology, LLC // // This program is free software (firmware): you can redistribute it and/or // modify it under the terms of the GNU General Public License as published // by the Free Software Foundation, either version 3 of the License, or (at // your option) any later version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License along // with this program. (It's in the $(ROOT)/doc directory, run make with no // target there if the PDF file isn't present.) If not, see // <http://www.gnu.org/licenses/> for a copy. // // License: GPL, v3, as defined and found on www.gnu.org, // http://www.gnu.org/licenses/gpl.html // // //////////////////////////////////////////////////////////////////////////////// #ifndef ZPARSER_H #define ZPARSER_H class ZPARSER { public: typedef unsigned int ZIPI, ZIPA; typedef int ZIPIMM; typedef enum { ZIP_R0, ZIP_R1, ZIP_R2, ZIP_R3, ZIP_R4, ZIP_R5, ZIP_R6, ZIP_R7, ZIP_R8, ZIP_R9, ZIP_R10, ZIP_R11, ZIP_R12, ZIP_SP, ZIP_CC, ZIP_PC, ZIP_uR0, ZIP_uR1, ZIP_uR2, ZIP_uR3, ZIP_uR4, ZIP_uR5, ZIP_uR6, ZIP_uR7, ZIP_uR8, ZIP_uR9, ZIP_uR10, ZIP_uR11, ZIP_uR12, ZIP_uSP, ZIP_uCC, ZIP_uPC, ZIP_Rnone } ZIPREG; typedef enum { ZIPC_ALWAYS, ZIPC_Z, ZIPC_NZ, ZIPC_GE, ZIPC_GT, ZIPC_LT, ZIPC_C, ZIPC_V } ZIPCOND; ZIPI op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_cmp(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_cmp(ZIPC_ALWAYS, imm, b, a); } ZIPI op_cmp(ZIPIMM imm, ZIPREG a) const { return op_cmp(ZIPC_ALWAYS, imm, a); } ZIPI op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_tst(ZIPIMM imm, ZIPREG a) const { return op_tst(ZIPC_ALWAYS, imm, a); } ZIPI op_tst(ZIPCOND cnd, ZIPREG a) const { return op_tst(cnd, -1, a); } ZIPI op_mov(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_mov(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_mov(ZIPC_ALWAYS, imm, b, a); } ZIPI op_mov(ZIPREG b, ZIPREG a) const { return op_mov(ZIPC_ALWAYS, 0, b, a); } ZIPI op_ldi(ZIPIMM imm, ZIPREG a) const; ZIPI op_trap(ZIPCOND cnd, ZIPIMM imm) const; ZIPI op_trap(ZIPIMM imm) const { return op_trap(ZIPC_ALWAYS, imm); } ZIPI op_clr(ZIPREG a) const { return op_ldi(0, a); } ZIPI op_noop(void) const; ZIPI op_break(void) const; ZIPI op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_ldilo(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_ldihi(ZIPIMM imm, ZIPREG a) const { return op_ldihi(ZIPC_ALWAYS, imm, a); } ZIPI op_ldilo(ZIPIMM imm, ZIPREG a) const { return op_ldilo(ZIPC_ALWAYS, imm, a); } ZIPI op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_mpy(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_mpy(ZIPC_ALWAYS, imm, b, a); } ZIPI op_mpy(ZIPIMM imm, ZIPREG a) const { return op_mpy(ZIPC_ALWAYS, imm, a); } ZIPI op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_rol(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_rol(ZIPC_ALWAYS, imm, b, a); } ZIPI op_rol(ZIPIMM imm, ZIPREG a) const { return op_rol(ZIPC_ALWAYS, imm, a); } ZIPI op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_lod(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_lod(ZIPC_ALWAYS, imm, b, a); } ZIPI op_lod(ZIPIMM imm, ZIPREG a) const { return op_lod(ZIPC_ALWAYS, imm, a); } ZIPI op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm, ZIPREG b) const; ZIPI op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm) const; ZIPI op_sto(ZIPREG v, ZIPIMM imm, ZIPREG b) const { return op_sto(ZIPC_ALWAYS, v, imm, b); } ZIPI op_sto(ZIPREG v, ZIPIMM imm) const { return op_sto(ZIPC_ALWAYS, v, imm); } ZIPI op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_sub(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_sub(ZIPC_ALWAYS, imm, b, a); } ZIPI op_sub(ZIPIMM imm, ZIPREG a) const { return op_sub(ZIPC_ALWAYS, imm, a); } ZIPI op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_and(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_and(ZIPC_ALWAYS, imm, b, a); } ZIPI op_and(ZIPIMM imm, ZIPREG a) const { return op_and(ZIPC_ALWAYS, imm, a); } ZIPI op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_add(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_add(ZIPC_ALWAYS, imm, b, a); } ZIPI op_add(ZIPIMM imm, ZIPREG a) const // GOOD { return op_add(ZIPC_ALWAYS, imm, a); } ZIPI op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_or(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_or(ZIPC_ALWAYS, imm, b, a); } ZIPI op_or(ZIPIMM imm, ZIPREG a) const { return op_or(ZIPC_ALWAYS, imm, a); } ZIPI op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_xor(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_xor(ZIPC_ALWAYS, imm, b, a); } ZIPI op_xor(ZIPIMM imm, ZIPREG a) const { return op_xor(ZIPC_ALWAYS, imm, a); } ZIPI op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_lsl(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_lsl(ZIPC_ALWAYS, imm, b, a); } ZIPI op_lsl(ZIPIMM imm, ZIPREG a) const { return op_lsl(ZIPC_ALWAYS, imm, a); } ZIPI op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_lsl(cnd, imm, b, a); } ZIPI op_asl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const { return op_lsl(cnd, imm, a); } ZIPI op_asl(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_lsl(ZIPC_ALWAYS, imm, b, a); } ZIPI op_asl(ZIPIMM imm, ZIPREG a) const { return op_lsl(ZIPC_ALWAYS, imm, a); } ZIPI op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_asr(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_asr(ZIPC_ALWAYS, imm, b, a); } ZIPI op_asr(ZIPIMM imm, ZIPREG a) const { return op_asr(ZIPC_ALWAYS, imm, a); } ZIPI op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const; ZIPI op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const; ZIPI op_lsr(ZIPIMM imm, ZIPREG b, ZIPREG a) const { return op_lsr(ZIPC_ALWAYS, imm, b, a); } ZIPI op_lsr(ZIPIMM imm, ZIPREG a) const { return op_lsr(ZIPC_ALWAYS, imm, a); } ZIPI op_bra(ZIPCOND cnd, ZIPIMM imm) const { return op_mov(cnd, imm, ZIP_PC, ZIP_PC); } ZIPI op_bra(ZIPIMM imm) const { return op_mov(ZIPC_ALWAYS, imm, ZIP_PC, ZIP_PC); } ZIPI op_brz(ZIPIMM imm) const { return op_mov(ZIPC_Z, imm, ZIP_PC, ZIP_PC); } ZIPI op_bnz(ZIPIMM imm) const { return op_mov(ZIPC_NZ, imm, ZIP_PC, ZIP_PC); } ZIPI op_bge(ZIPIMM imm) const { return op_mov(ZIPC_GE, imm, ZIP_PC, ZIP_PC); } ZIPI op_bgt(ZIPIMM imm) const { return op_mov(ZIPC_GT, imm, ZIP_PC, ZIP_PC); } ZIPI op_blt(ZIPIMM imm) const { return op_mov(ZIPC_LT, imm, ZIP_PC, ZIP_PC); } ZIPI op_brc(ZIPIMM imm) const { return op_mov(ZIPC_C, imm, ZIP_PC, ZIP_PC); } ZIPI op_brv(ZIPIMM imm) const { return op_mov(ZIPC_V, imm, ZIP_PC, ZIP_PC); } ZIPI op_bv(ZIPIMM imm) const { return op_brv(imm); } ZIPI op_clrf(ZIPCOND cnd, ZIPREG a) const { return op_xor(cnd, 0, a, a); } ZIPI op_clrf(ZIPREG a) const { return op_xor(ZIPC_ALWAYS, 0, a, a); } ZIPI op_halt(ZIPCOND c) const { return op_or(c, 0x10, ZIP_CC); } ZIPI op_wait(ZIPCOND c) const { return op_or(c, 0x10, ZIP_CC); } ZIPI op_halt(void) const { return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); } ZIPI op_wait(void) const { return op_or(ZIPC_ALWAYS, 0x10, ZIP_CC); } ZIPI op_busy(ZIPCOND c) const { return op_mov(c, -1, ZIP_PC, ZIP_PC); } ZIPI op_busy(void) const { return op_mov(ZIPC_ALWAYS, -1, ZIP_PC, ZIP_PC); } ZIPI op_rtu(void) const { return op_or(ZIPC_ALWAYS, 0x20, ZIP_CC); } ZIPI op_rtu(ZIPCOND cnd) const { return op_or(cnd, 0x20, ZIP_CC); } ZIPI op_jmp(ZIPCOND c, ZIPIMM imm, ZIPREG r) const { return op_mov(ZIPC_ALWAYS, imm, r, ZIP_PC); } ZIPI op_ljmp(ZIPCOND c, ZIPIMM imm) const { return op_add(ZIPC_ALWAYS, imm, ZIP_PC); } ZIPI op_not(ZIPCOND c, ZIPREG r) const { return op_xor(c, -1, r); } ZIPI op_not(ZIPREG r) const { return op_xor(ZIPC_ALWAYS, -1, r); } }; #endif
Go to most recent revision | Compare with Previous | Blame | View Log