shithub: spirva

ref: 0481916bfbc64666485d976d5b67e00dff5387ff
dir: /sym.c/

View raw version
#include <u.h>
#include <libc.h>
#include "sym.h"

Symbol* syms = nil;
uint id;

Symbol*
symfind(char *name)
{
	Symbol *s;
	
	if (!syms) {
		syms = malloc(sizeof(Symbol));
		syms->name = name;
		syms->next = nil;
		syms->id = id = 0;
		return syms;
	}
	
	s = syms;
	while (s) {
		if (strcmp(s->name, name) == 0) {
			return s;
		}
		if (!s->next) {
			s->next = malloc(sizeof(Symbol));
			s = s->next;
			s->next = nil;
			s->name = name;
			s->id = ++id;
			return s;
		}
		s = s->next;
	}
	return nil;
}

void
printsyms()
{
	Symbol *s;
	for (s = syms; s; s = s->next) {
		print("symbol: %s (%d)\n", s->name, s->id);
	}
}