shithub: spirva

ref: cbbb6280961fd5a120d2a5a765bd483fbfc86af7
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);
	}
}