summaryrefslogtreecommitdiff
path: root/directives.c
blob: 1e1d3020307e2790d49cb5fc61b5f04d0645920f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * This file is generated from directives.dat
 * by directives.pl; do not edit.
 */

#include "compiler.h"
#include <string.h>
#include "nasm.h"
#include "hashtbl.h"
#include "directives.h"

const char * const directives[24] = {
    NULL,
    "absolute",
    "bits",
    "common",
    "cpu",
    "debug",
    "default",
    "extern",
    "float",
    "global",
    "list",
    "section",
    "segment",
    "warning",
    "export",
    "group",
    "import",
    "library",
    "map",
    "module",
    "org",
    "osabi",
    "safeseh",
    "uppercase"
};

enum directives find_directive(const char *token)
{
#define UNUSED 16383
    static const int16_t hash1[32] = {
        0,
        UNUSED,
        UNUSED,
        UNUSED,
        UNUSED,
        0,
        0,
        10,
        0,
        9,
        UNUSED,
        UNUSED,
        UNUSED,
        0,
        0,
        UNUSED,
        UNUSED,
        UNUSED,
        UNUSED,
        0,
        UNUSED,
        22,
        16,
        UNUSED,
        -14,
        13,
        UNUSED,
        UNUSED,
        20,
        -17,
        13,
        3,
    };
    static const int16_t hash2[32] = {
        0,
        UNUSED,
        UNUSED,
        UNUSED,
        0,
        UNUSED,
        6,
        0,
        19,
        2,
        0,
        28,
        0,
        0,
        3,
        UNUSED,
        UNUSED,
        UNUSED,
        8,
        21,
        9,
        1,
        UNUSED,
        UNUSED,
        UNUSED,
        UNUSED,
        1,
        5,
        UNUSED,
        UNUSED,
        -4,
        UNUSED,
    };
    uint32_t k1, k2;
    uint64_t crc;
    uint16_t ix;

    crc = crc64i(UINT64_C(0x076259c3e291c26c), token);
    k1 = (uint32_t)crc;
    k2 = (uint32_t)(crc >> 32);

    ix = hash1[k1 & 0x1f] + hash2[k2 & 0x1f];
    if (ix >= 23)
        return D_NONE;

    ix++;
    if (nasm_stricmp(token, directives[ix]))
        return D_NONE;

    return ix;
}