2
* $Id: vhdl.c,v 1.0 2005/11/05
4
* Copyright (c) 2005, Klaus Dannecker
6
* This source code is released for free distribution under the terms of the
7
* GNU General Public License.
9
* This module contains functions for generating tags for the Vhdl HDL
10
* (Hardware Description Language).
17
#include "general.h" /* must always come first */
30
typedef enum eException { ExceptionNone, ExceptionEOF } exception_t;
59
static jmp_buf Exception;
60
static vString* Name=NULL;
61
static vString* Lastname=NULL;
62
static vString* Keyword=NULL;
63
static vString* TagName=NULL;
65
static kindOption VhdlKinds [] = {
66
{ TRUE, 'c', "constant", "constants" },
67
{ TRUE, 't', "type", "types" },
68
{ TRUE, 'v', "variable", "variables" },
69
{ TRUE, 'a', "atribute", "atributes" },
70
{ TRUE, 's', "signal", "signals" },
71
{ TRUE, 'f', "function", "functions" },
72
{ TRUE, 'p', "procedure", "procedure" },
73
{ TRUE, 'k', "component", "components" },
74
{ TRUE, 'l', "package", "packages" },
75
{ TRUE, 'm', "process", "process" },
76
{ TRUE, 'n', "entity", "entity" },
77
{ TRUE, 'o', "architecture", "architecture" },
78
{ TRUE, 'u', "port", "ports" }
81
static keywordAssoc VhdlKeywordTable [] = {
82
{ "variable", K_VARIABLE },
83
{ "constant", K_CONSTANT },
84
{ "variable", K_VARIABLE },
86
{ "subtype", K_TYPE },
87
{ "signal", K_SIGNAL },
88
{ "function", K_FUNCTION },
89
{ "procedure", K_PROCEDURE },
90
{ "component", K_COMPONENT },
91
{ "package", K_PACKAGE },
92
{ "process", K_PROCESS },
93
{ "entity", K_ENTITY },
94
{ "architecture", K_ARCHITECTURE },
102
* FUNCTION DEFINITIONS
105
static void initialize (const langType language)
108
const size_t count = sizeof (VhdlKeywordTable) /
109
sizeof (VhdlKeywordTable [0]);
110
Lang_vhdl = language;
111
for (i = 0 ; i < count ; ++i)
113
const keywordAssoc* const p = &VhdlKeywordTable [i];
114
addKeyword (p->keyword, language, (int) p->kind);
118
static void vUngetc (int c)
120
Assert (Ungetc == '\0');
124
static int vGetc (void)
136
int c2 = fileGetc ();
138
longjmp (Exception, (int) ExceptionEOF);
139
else if (c2 == '-') /* strip comment until end-of-line */
143
while (c != '\n' && c != EOF);
149
longjmp (Exception, (int) ExceptionEOF);
153
static boolean isIdentifierCharacter (const int c)
155
return (boolean)(isalnum (c) || c == '_' || c == '`');
158
static int skipWhite (int c)
165
static boolean readIdentifier (vString *const name, int c)
168
if (isIdentifierCharacter (c))
170
while (isIdentifierCharacter (c))
172
vStringPut (name, c);
176
vStringTerminate (name);
178
return (boolean)(name->length > 0);
181
static void tagNameList (const vhdlKind kind, int c)
183
Assert (isIdentifierCharacter (c));
184
if (isIdentifierCharacter (c))
186
readIdentifier (TagName, c);
187
makeSimpleTag (TagName, VhdlKinds, kind);
192
static void findTag (vString *const name)
196
vStringCopyToLower (Keyword, name);
197
kind = (vhdlKind)lookupKeyword (vStringValue (Keyword), Lang_vhdl);
198
if (kind == K_UNDEFINED)
200
c = skipWhite (vGetc ());
201
vStringCopyS(Lastname,vStringValue(name));
204
c = skipWhite (vGetc ());
205
if (isIdentifierCharacter (c))
207
readIdentifier (name, c);
208
vStringCopyToLower (Keyword, name);
209
lookupKeyword (vStringValue (Keyword), Lang_vhdl);
210
kind = (vhdlKind)lookupKeyword (vStringValue (Keyword), Lang_vhdl);
211
if (kind == K_PROCESS || kind == K_PORT)
213
makeSimpleTag (Lastname, VhdlKinds, kind);
222
if (kind == K_SIGNAL) {
224
c = skipWhite (vGetc ());
227
if (isIdentifierCharacter (c))
228
tagNameList (kind, c);
234
else if (kind == K_PROCESS) {
235
vStringCopyS(TagName,"unnamed");
236
makeSimpleTag (TagName, VhdlKinds, kind);
238
c = skipWhite (vGetc ());
241
if (isIdentifierCharacter (c))
242
tagNameList (kind, c);
247
static void findVhdlTags (void)
249
volatile boolean newStatement = TRUE;
250
volatile int c = '\0';
251
exception_t exception = (exception_t) setjmp (Exception);
252
Name = vStringNew ();
253
Lastname = vStringNew ();
254
Keyword = vStringNew ();
255
TagName = vStringNew ();
257
if (exception == ExceptionNone) while (c != EOF)
272
if (newStatement && readIdentifier (Name, c)) {
275
newStatement = FALSE;
279
vStringDelete (Name);
280
vStringDelete (Lastname);
281
vStringDelete (Keyword);
282
vStringDelete (TagName);
285
extern parserDefinition* VhdlParser (void)
287
static const char *const extensions [] = { "vhdl", "vhd", NULL };
288
parserDefinition* def = parserNew ("Vhdl");
289
def->kinds = VhdlKinds;
290
def->kindCount = KIND_COUNT (VhdlKinds);
291
def->extensions = extensions;
292
def->parser = findVhdlTags;
293
def->initialize = initialize;
297
/* vi:set tabstop=8 shiftwidth=4: */