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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [AS64/] [source/] [NameTable.hpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2014  Robert Finch, Stratford
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// A64 - Assembler
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
#ifndef NAMETABLE_HPP
27
#define NAMETABLE_HPP
28
 
29
#include <string.h>
30
 
31
class NameTable {
32
public:
33
    char text[1000000];
34
    int length;
35
 
36
public:
37
    NameTable() {
38
        text[0] = 0;
39
        text[1] = 0;
40
        length = 1;
41
    };
42
    void Clear() {
43
        text[0] = 0;
44
        text[1] = 0;
45
        length = 1;
46
    };
47
    char *GetName(int ndx) {
48
         return &text[ndx];
49
    };
50
 
51
    int FindName(char *nm) {
52
        int nn, mm;
53
 
54
        for (nn = 1; nn < length; nn++) {
55
            if (text[nn] == nm[0]) {
56
                for(mm = 1; nm[mm] == text[nn+mm] && nm[mm]; mm++);
57
                if (nm[mm]=='\0')
58
                   return nn;
59
            }
60
            else {
61
                while(text[nn]!=0 && nn < length) nn++;
62
                nn++;
63
            }
64
        }
65
        return -1;
66
    };
67
 
68
    int AddName(char *nm) {
69
        int ret;
70
        int olen;
71
 
72
        if ((ret = FindName(nm)) > 0)
73
           return ret;
74
        olen = length;
75
        strcpy_s(&text[length], sizeof(text)-length, nm);
76
        length += strlen(nm) + 1;
77
        return olen;
78
    };
79
 
80
    void write(FILE *fp) {
81
         fwrite((void *)text, 1, length, fp);
82
    };
83
};
84
 
85
#endif

powered by: WebSVN 2.1.0

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