Changeset 4504


Ignore:
Timestamp:
06/30/08 02:55:00 (5 years ago)
Author:
werner
Message:
  • use unique() also when looking up identifiers from the command line
  • added regression tests for split lines, values given by formulas
Location:
developers/werner/greg
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • developers/werner/greg/Makefile

    r4502 r4504  
    66LDLIBS=-lfl 
    77 
    8 OBJS=greg.o lex.yy.o y.tab.o cpp.o 
     8OBJS=greg.o lex.yy.o y.tab.o cpp.o id.o 
    99 
    1010.PHONY:         all dep depend clean spotless test tests 
  • developers/werner/greg/README

    r4502 r4504  
    1515------------ 
    1616 
    17 - output format should be easier to read 
    1817- value names in pcf50633.greg are often unsuitable for identifier generation 
    1918  (should align them properly with what we use in u-boot and kernel) 
    2019- "pretty-print" is hard to read 
    2120- unique() should use rb-trees 
    22 - greg.c should use unique(), to accelerate lookups 
    2321 
    2422 
  • developers/werner/greg/greg.c

    r4502 r4504  
    1515#include <stdlib.h> 
    1616#include <stdio.h> 
    17 #include <string.h> 
    1817 
    1918#include "reg.h" 
    2019#include "cpp.h" 
     20#include "id.h" 
    2121#include "greg.h" 
    2222 
     
    8282        const struct field *field; 
    8383 
     84        id = unique(id); 
    8485        for (reg = regs; reg; reg = reg->next) 
    85                 if (!strcmp(reg->id, id)) 
     86                if (reg->id == id) 
    8687                        break; 
    8788        if (!reg) { 
  • developers/werner/greg/lang.l

    r4502 r4504  
    2222 
    2323#include "greg.h" 
     24#include "id.h" 
    2425 
    2526 
     
    2728static int col0 = 1; /* token starts in the first column */ 
    2829 
    29  
    30 static char *unique(const char *s) 
    31 { 
    32         static struct node { 
    33                 char *s; 
    34                 struct node *left, *right; 
    35         } *root = NULL; 
    36         struct node **n = &root; 
    37         int cmp; 
    38  
    39         while (*n) { 
    40                 cmp = strcmp((*n)->s, s); 
    41                 if (!cmp) 
    42                         return (*n)->s; 
    43                 n = cmp < 0 ? &(*n)->left : &(*n)->right; 
    44         } 
    45         *n = malloc(sizeof(struct node)); 
    46         if (!*n) { 
    47                 perror("malloc"); 
    48                 exit(1); 
    49         } 
    50         (*n)->s = strdup(s); 
    51         if (!(*n)->s) { 
    52                 perror("strdup"); 
    53                 exit(1); 
    54         } 
    55         (*n)->left = (*n)->right = NULL; 
    56         return (*n)->s; 
    57 } 
    58  
    5930%} 
    6031 
     32 
    6133%% 
     34 
    6235 
    6336"%"[0-9]+               { yylval.num = strtoul(yytext+1, NULL, 10); 
Note: See TracChangeset for help on using the changeset viewer.