hashtbl.h

来自「< 虚拟机设计与实现> 的source code, linux版本」· C头文件 代码 · 共 74 行

H
74
字号
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+                                                                   +
+ hashtbl.h - the hash table                                      +
+                                                                   +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

/*
	The hash table is the gateway to the entire process of creating
	a symbol table and resolving indentifiers during assembly

	During Pass1 ( directives populate Proc and GlobVar arrays )
	------------
	
	1) encounter a identifier declaration
	2) take hash and query hash table
		2a) if exists ( query proc returns non-NULL ) 
			print error, redefinition
		2b) if does not exist ( query proc returns NULL )
			add entry to string table
			add entry to symbol table
			add entry to hash table

	During Pass2 ( gen. bytecode )
	------------
	
	1) encounter a identifier in an instruction
	2) take hash and query hash table
		2a) if exists ( query proc returns non-NULL ) 
			generate bytecode
		2b) if does not exist ( query proc returns NULL )
			print error, referencing non-existent identifier
*/

#ifndef _HASHTBL_H
#define _HASHTBL_H

#include "linux.h"

#define GLOBAL_VAR	0	
#define PROC		1
#define PROC_RET	2
#define PROC_ARG	3
#define PROC_LOC	4
#define PROC_LBL	5

struct HashTbl
{
	U1 empty;		/*indicates if entry is used or not*/
    U8 text;		/*index to strTbl*/
	U1 type;		/*GLOBAL_VAR -> PROC_LBL*/
	U4 index;		/*index to globVar, proc arrays in symbTbl*/
	U4 subIndex;	/*subindex for PROC_RET, ... , PROC_LBL*/
    struct HashTbl * left;
    struct HashTbl * right;
};

#define PRIME 547

extern char * SymTypeStr[];
extern struct HashTbl hashTbl[PRIME];

void HashTable_init();
void HashTable_free();

/*hash table routine calls corresponding BST rotuine*/
struct HashTbl * queryHashTbl(char * str);
int addHashTblEntry(char * val, U8 text, U1 type, U4 ind, U4 subInd, U4 line);
void printHashTbl();

void test_HashTbl();
void test_2();

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?