OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [Instruction.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2012-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// CC64 - 'C' derived language compiler
9
//  - 64 bit CPU
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
// ============================================================================
25
//
26
#include "stdafx.h"
27
 
28
// brk and rti ???
29
bool Instruction::IsFlowControl()
30
{
31
        if (opcode == op_jal ||
32
                opcode == op_jmp ||
33
                opcode == op_ret ||
34
                opcode == op_call ||
35
                opcode == op_bra ||
36
                opcode == op_beq ||
37
                opcode == op_bne ||
38
                opcode == op_blt ||
39
                opcode == op_ble ||
40
                opcode == op_bgt ||
41
                opcode == op_bge ||
42
                opcode == op_bltu ||
43
                opcode == op_bleu ||
44
                opcode == op_bgtu ||
45
                opcode == op_bgeu ||
46
                opcode == op_beqi ||
47
                opcode == op_bbs ||
48
                opcode == op_bbc ||
49
                opcode == op_ibne ||
50
                opcode == op_dbnz ||
51
                opcode == op_bchk
52
                )
53
                return (true);
54
        return (false);
55
}
56
 
57
static int fbmcmp(const void *a, const void *b)
58
{
59
        Instruction *ib;
60
 
61
        ib = (Instruction *)b;
62
        return (strcmp((char *)a, ib->mnem));
63
}
64
 
65
Instruction *Instruction::FindByMnem(std::string& mn)
66
{
67
        return ((Instruction *)bsearch(mn.c_str(), &opl[1], 222, sizeof(Instruction), fbmcmp));
68
}
69
 
70
Instruction *Instruction::Get(int op)
71
{
72
        int i;
73
 
74
        for (i = 0; opl[i].mnem; i++)
75
                if (opl[i].opcode == op)
76
                        return (&opl[i]);
77
        return (nullptr);
78
}
79
 
80
int Instruction::store(txtoStream& ofs)
81
{
82
        ofs.write(mnem);
83
        return (strlen(mnem));
84
}
85
 
86
int Instruction::storeHRR(txtoStream& ofs)
87
{
88
        ofs.write(mnem);
89
        return (strlen(mnem));
90
}
91
 
92
int Instruction::storeHex(txtoStream& ofs)
93
{
94
        char buf[20];
95
 
96
        sprintf_s(buf, sizeof(buf), "I%03X", opcode);
97
        ofs.write(buf);
98
        return (0);
99
}
100
 
101
Instruction *Instruction::loadHex(std::ifstream& ifs)
102
{
103
        char buf[10];
104
        int op;
105
 
106
        ifs.read(buf, 3);
107
        buf[4] = '\0';
108
        op = atoi(buf);
109
        return (GetInsn(op));
110
}
111
 
112
int Instruction::load(std::ifstream& ifs, Instruction **p)
113
{
114
        int nn;
115
        char buf[20];
116
        std::streampos pos;
117
 
118
        do {
119
                ifs.read(buf, 1);
120
        } while (isspace(buf[0]));
121
        pos = ifs.tellg();
122
        for (nn = 0; nn < sizeof(buf); nn++) {
123
                ifs.read(&buf[nn], 1);
124
                if (isspace(buf[nn]))
125
                        break;
126
        }
127
        // If too long, can't be an instruction
128
        if (nn >= sizeof(buf)) {
129
                ifs.seekg(pos);
130
                return (0);
131
        }
132
        // Given the mnemonic figure out the opcode
133
        *p = FindByMnem(std::string(buf));
134
        return (nn);
135
}
136
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.