Changeset 5967
- Timestamp:
- 05/29/10 23:13:48 (3 years ago)
- Location:
- trunk/eda/fped
- Files:
-
- 4 added
- 19 edited
-
Makefile (modified) (1 diff)
-
README (modified) (3 diffs)
-
bitset.c (added)
-
bitset.h (added)
-
delete.c (modified) (2 diffs)
-
dump.c (modified) (3 diffs)
-
error.c (modified) (2 diffs)
-
error.h (modified) (2 diffs)
-
fpd.l (modified) (2 diffs)
-
fpd.y (modified) (15 diffs)
-
gui_meas.c (modified) (6 diffs)
-
inst.c (modified) (7 diffs)
-
inst.h (modified) (2 diffs)
-
meas.c (modified) (11 diffs)
-
meas.h (modified) (5 diffs)
-
obj.c (modified) (6 diffs)
-
obj.h (modified) (1 diff)
-
test/Common (modified) (1 diff)
-
test/dbg_meas (added)
-
test/del_frame (modified) (2 diffs)
-
test/del_vec (modified) (2 diffs)
-
test/meas_qual (added)
-
test/structure (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eda/fped/Makefile
r5944 r5967 17 17 OBJS = fped.o expr.o coord.o obj.o delete.o inst.o util.o error.o \ 18 18 unparse.o file.o dump.o kicad.o postscript.o meas.o \ 19 layer.o overlap.o hole.o tsort.o \19 layer.o overlap.o hole.o tsort.o bitset.o \ 20 20 cpp.o lex.yy.o y.tab.o \ 21 21 gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \ -
trunk/eda/fped/README
r5947 r5967 583 583 584 584 585 Additional qualifiers 586 - - - - - - - - - - - 587 588 When using frames as reusable building blocks, similar to functions or 589 macros in many programming languages, one may need finer control over 590 the points that are selected for measurements. 591 592 For example, let us consider a frame "square" that draws a square 593 centered at the frame's origin and with a side length given by the 594 variable "size". This variable be set in the frame referencing 595 "square". 596 597 frame square { 598 a: vec @(-size/2, -size/2) 599 b: vec @(size/2, size/2) 600 rect a b 601 } 602 603 frame small { 604 set size = 2mm 605 frame square @ 606 } 607 608 frame big { 609 set size = 5mm 610 frame square @ 611 } 612 613 frame small @ 614 vec @(5mm, 0mm) 615 frame big . 616 617 If we want to measure the size of each square, we could use 618 619 measx square.a -> square.b 620 621 Unfortunately, this only measures the small square. To reach the 622 big frame, we need to tell fped to use only those points in "square" 623 that have been placed when "square" was invoked from the big frame. 624 625 This is accomplished by prefixing the points in question with the 626 name(s) of the frames that need to be visited. The frame names are 627 separated by slashes (/). 628 629 measx big/square.a -> square.b 630 631 For clarity, it's better to qualify both points, e.g., 632 633 measx big/square.a -> big/square.b 634 635 If multiple frame names are given, they must be in the order in 636 which they are invoked. 637 638 585 639 Experimental: debugging directives 586 640 ---------------------------------- … … 593 647 %frame <identifier> <qualified-base> 594 648 %print <expression> 649 %meas <identifier> 595 650 %dump 596 651 %exit … … 623 678 output. %exit immediately exits fped, without invoking the GUI. 624 679 680 %print evaluates the expression and prints the result to standard output. 681 %meas performs an instantiation and prints the value of the labeled 682 measurement. 683 625 684 %tsort is used to test-drive the topological sort algorithm. The items 626 685 in the curly braces are declarations of nodes with (-<id>) or without -
trunk/eda/fped/delete.c
r5948 r5967 522 522 523 523 524 static int qual_ref(const struct frame_qual *qual, const struct frame *ref) 525 { 526 while (qual) { 527 if (qual->frame == ref) 528 return 1; 529 qual = qual->next; 530 } 531 return 0; 532 } 533 534 524 535 static void delete_references(const struct frame *ref) 525 536 { … … 536 547 case ot_meas: 537 548 if (obj->base->frame == ref || 538 obj->u.meas.high->frame == ref) 549 obj->u.meas.high->frame == ref || 550 qual_ref(obj->u.meas.low_qual, ref) || 551 qual_ref(obj->u.meas.high_qual, ref)) 539 552 do_delete_obj(obj); 540 553 break; -
trunk/eda/fped/dump.c
r5948 r5967 14 14 #include <stdlib.h> 15 15 #include <stdio.h> 16 #include <string.h> 17 #include <sys/types.h> 16 18 17 19 #include "util.h" … … 390 392 391 393 392 static char *print_meas_base(struct vec *base )394 static char *print_meas_base(struct vec *base, const struct frame_qual *qual) 393 395 { 394 396 const char *name; 397 size_t n; 398 const struct frame_qual *walk; 399 char *s, *p; 395 400 396 401 name = base_name(base, NULL); 397 if (base->frame == frames) 398 return stralloc(name); 399 return stralloc_printf("%s.%s", base->frame->name, name); 402 n = strlen(name)+1; /* vec\0 */ 403 for (walk = qual; walk; walk = walk->next) 404 n += strlen(walk->frame->name)+1; /* frame/ */ 405 if (base->frame != frames) 406 n += strlen(base->frame->name)+1; /* frame. */ 407 408 s = p = alloc_size(n); 409 for (walk = qual; walk; walk = walk->next) { 410 n = strlen(walk->frame->name); 411 memcpy(p, walk->frame->name, n); 412 p[n] = '/'; 413 p += n+1; 414 } 415 if (base->frame != frames) { 416 n = strlen(base->frame->name); 417 memcpy(p, base->frame->name, n); 418 p[n] = '.'; 419 p += n+1; 420 } 421 strcpy(p, name); 422 return s; 400 423 } 401 424 … … 414 437 s = t; 415 438 } 416 s1 = print_meas_base(obj->base );439 s1 = print_meas_base(obj->base, obj->u.meas.low_qual); 417 440 s2 = stralloc_printf(" %s ", 418 441 obj->u.meas.type < 3 ? obj->u.meas.inverted ? "<-" : "->" : 419 442 obj->u.meas.inverted ? "<<" : ">>"); 420 s3 = print_meas_base(obj->u.meas.high );443 s3 = print_meas_base(obj->u.meas.high, obj->u.meas.high_qual); 421 444 t = stralloc_printf("%s%s%s%s", s, s1, s2, s3); 422 445 free(s); -
trunk/eda/fped/error.c
r5461 r5967 2 2 * error.c - Error reporting 3 3 * 4 * Written 2009 by Werner Almesberger5 * Copyright 2009 by Werner Almesberger4 * Written 2009, 2010 by Werner Almesberger 5 * Copyright 2009, 2010 by Werner Almesberger 6 6 * 7 7 * This program is free software; you can redistribute it and/or modify … … 24 24 int lineno = 1; 25 25 void (*reporter)(const char *s) = report_to_stderr; 26 27 28 void yywarn(const char *s) 29 { 30 /* we use yywarn only when starting */ 31 fprintf(stderr, "%d: warning: %s near \"%s\"\n", lineno, s, yytext); 32 } 26 33 27 34 -
trunk/eda/fped/error.h
r5461 r5967 2 2 * error.h - Error reporting 3 3 * 4 * Written 2009 by Werner Almesberger5 * Copyright 2009 by Werner Almesberger4 * Written 2009, 2010 by Werner Almesberger 5 * Copyright 2009, 2010 by Werner Almesberger 6 6 * 7 7 * This program is free software; you can redistribute it and/or modify … … 21 21 22 22 23 void yywarn(const char *s); 24 23 25 void yyerrorf(const char *fmt, ...) 24 26 __attribute__((format(printf, 1, 2))); -
trunk/eda/fped/fpd.l
r5945 r5967 132 132 <INITIAL>"%print" { BEGIN(NOKEYWORD); 133 133 return TOK_DBG_PRINT; } 134 <INITIAL>"%meas" { BEGIN(NOKEYWORD); 135 return TOK_DBG_MEAS; } 134 136 <INITIAL>"%dump" { BEGIN(NOKEYWORD); 135 137 return TOK_DBG_DUMP; } … … 174 176 ; BEGIN(INITIAL); 175 177 176 "{" { BEGIN(NOKEYWORD); 177 disable_keywords = is_table; 178 "{" { disable_keywords = is_table; 179 BEGIN(disable_keywords ? 180 NOKEYWORD : INITIAL); 178 181 return '{'; } 179 182 "}" { disable_keywords = 0; 183 BEGIN(INITIAL); 180 184 return '}'; } 181 185 -
trunk/eda/fped/fpd.y
r5948 r5967 18 18 #include "util.h" 19 19 #include "error.h" 20 #include "coord.h" 20 21 #include "expr.h" 21 22 #include "obj.h" 22 23 #include "meas.h" 23 24 #include "gui_status.h" 25 #include "gui_inst.h" /* for %meas */ 24 26 #include "dump.h" 25 27 #include "tsort.h" 26 28 #include "fpd.h" 29 30 #include "y.tab.h" 27 31 28 32 … … 48 52 49 53 static struct tsort *tsort; 54 55 56 /* ----- lookup functions -------------------------------------------------- */ 50 57 51 58 … … 108 115 return NULL; 109 116 } 117 118 119 /* ----- item creation ----------------------------------------------------- */ 110 120 111 121 … … 178 188 179 189 190 /* ---- frame qualifiers --------------------------------------------------- */ 191 192 193 static int duplicate_qualifier(const struct frame_qual *a, 194 const struct frame_qual *b) 195 { 196 if (!b) 197 return 0; 198 if (a != b && a->frame == b->frame) { 199 yyerrorf("duplicate qualifier \"%s\"", a->frame->name); 200 return 1; 201 } 202 if (b && duplicate_qualifier(a, b->next)) 203 return 1; 204 return duplicate_qualifier(a->next, a->next); 205 } 206 207 208 static int can_reach(const struct frame *curr, const struct frame_qual *qual, 209 const struct frame *end) 210 { 211 const struct obj *obj; 212 213 if (curr == end) 214 return !qual; 215 216 /* 217 * Don't recurse for removing the qualifier alone. We require a frame 218 * reference step as well, so that things like foo.foo.foo.bar.vec 219 * aren't allowed. 220 * 221 * Since a duplicate qualifier can never work, we test for this error 222 * explicitly in "duplicate_qualifier". 223 */ 224 if (qual && curr == qual->frame) 225 qual = qual->next; 226 227 for (obj = curr->objs; obj; obj = obj->next) 228 if (obj->type == ot_frame) 229 if (can_reach(obj->u.frame.ref, qual, end)) 230 return 1; 231 return 0; 232 } 233 234 235 static int check_qbase(struct qbase *qbase) 236 { 237 if (duplicate_qualifier(qbase->qualifiers, qbase->qualifiers)) 238 return 0; 239 240 if (!can_reach(frames, qbase->qualifiers, qbase->vec->frame)) 241 yywarn("not all qualifiers can be reached"); 242 return 1; 243 } 244 245 246 /* ----- debugging directives ---------------------------------------------- */ 247 248 180 249 static int dbg_delete(const char *frame_name, const char *name) 181 250 { … … 311 380 return 0; 312 381 printf("%lg%s\n", num.n, str_unit(num)); 382 return 1; 383 } 384 385 386 static int dbg_meas(const char *name) 387 { 388 const struct obj *obj; 389 const struct inst *inst; 390 struct coord a1, b1; 391 char *s; 392 393 obj = find_obj(frames, name); 394 if (!obj) { 395 yyerrorf("unknown object \"%s\"", name); 396 return 0; 397 } 398 399 /* from fped.c:main */ 400 401 if (!pkg_name) 402 pkg_name = stralloc("_"); 403 reporter = report_to_stderr; 404 if (!instantiate()) 405 return 0; 406 407 inst = find_meas_hint(obj); 408 if (!inst) { 409 yyerrorf("measurement \"%s\" was not instantiated", name); 410 return 0; 411 } 412 413 project_meas(inst, &a1, &b1); 414 s = format_len(obj->u.meas.label ? obj->u.meas.label : "", 415 dist_point(a1, b1), curr_unit); 416 printf("%s\n", s); 417 free(s); 418 313 419 return 1; 314 420 } … … 340 446 struct vec *vec; 341 447 } qvec; 448 struct qbase { 449 struct vec *vec; 450 struct frame_qual *qualifiers; 451 } qbase; 342 452 }; 343 453 … … 349 459 %token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED 350 460 %token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_FRAME TOK_DBG_PRINT 351 %token TOK_DBG_DUMP TOK_DBG_EXIT TOK_DBG_TSORT 461 %token TOK_DBG_DUMP TOK_DBG_EXIT TOK_DBG_TSORT TOK_DBG_MEAS 352 462 353 463 %token <num> NUMBER … … 359 469 %type <row> rows 360 470 %type <value> row value opt_value_list 361 %type <vec> vec base qbase362 %type <obj> object obj meas 471 %type <vec> vec base 472 %type <obj> object obj meas unlabeled_meas 363 473 %type <expr> expr opt_expr add_expr mult_expr unary_expr primary_expr 364 474 %type <num> opt_num … … 369 479 %type <mo> meas_op 370 480 %type <qvec> qualified_base 481 %type <qbase> qbase qbase_unchecked 371 482 372 483 %% … … 537 648 { 538 649 if (!dbg_print($2)) 650 YYABORT; 651 } 652 | TOK_DBG_MEAS ID 653 { 654 if (!dbg_meas($2)) 539 655 YYABORT; 540 656 } … … 868 984 869 985 measurements: 870 meas986 unlabeled_meas /* @@@ hack */ 871 987 { 872 988 *next_obj = $1; … … 882 998 883 999 meas: 1000 unlabeled_meas 1001 { 1002 $$ = $1; 1003 } 1004 | LABEL unlabeled_meas 1005 { 1006 $$ = $2; 1007 if (find_label(curr_frame, $1)) { 1008 yyerrorf("duplicate label \"%s\"", $1); 1009 YYABORT; 1010 } 1011 $$->name = $1; 1012 } 1013 ; 1014 1015 unlabeled_meas: 884 1016 meas_type opt_string qbase meas_op qbase opt_expr 885 1017 { … … 890 1022 meas->type = $4.max ? $1+3 : $1; 891 1023 meas->label = $2; 892 $$->base = $3; 1024 $$->base = $3.vec; 1025 meas->low_qual = $3.qualifiers; 893 1026 meas->inverted = $4.inverted; 894 meas->high = $5; 1027 meas->high = $5.vec; 1028 meas->high_qual = $5.qualifiers; 895 1029 meas->offset = $6; 896 1030 $$->next = NULL; … … 899 1033 900 1034 qbase: 1035 qbase_unchecked 1036 { 1037 $$ = $1; 1038 if (!check_qbase(&$$)) 1039 YYABORT; 1040 } 1041 ; 1042 1043 qbase_unchecked: 901 1044 ID 902 1045 { 903 $$ = find_vec(frames, $1);904 if (!$$ ) {1046 $$.vec = find_vec(frames, $1); 1047 if (!$$.vec) { 905 1048 yyerrorf("unknown vector \"%s\"", $1); 906 1049 YYABORT; 907 1050 } 1051 $$.qualifiers = NULL; 908 1052 } 909 1053 | ID '.' ID … … 912 1056 913 1057 frame = find_frame($1); 914 $$ = frame ? find_vec(frame, $3) : NULL;915 if (!$$ ) {1058 $$.vec = frame ? find_vec(frame, $3) : NULL; 1059 if (!$$.vec) { 916 1060 yyerrorf("unknown vector \"%s.%s\"", $1, $3); 917 1061 YYABORT; 1062 } 1063 $$.qualifiers = NULL; 1064 } 1065 | ID '/' qbase 1066 { 1067 const struct frame *frame; 1068 struct frame_qual *qual; 1069 1070 $$ = $3; 1071 frame = find_frame($1); 1072 if (!frame) { 1073 yyerrorf("unknown frame \"%s\"", $1); 1074 YYABORT; 1075 } else { 1076 qual = alloc_type(struct frame_qual); 1077 qual->frame = frame; 1078 qual->next = $$.qualifiers; 1079 $$.qualifiers = qual; 918 1080 } 919 1081 } -
trunk/eda/fped/gui_meas.c
r5948 r5967 2 2 * gui_meas.c - GUI, measurements 3 3 * 4 * Written 2009 by Werner Almesberger5 * Copyright 2009by Werner Almesberger4 * Written 2009, 2010 by Werner Almesberger 5 * Copyright 2009, 2010 by Werner Almesberger 6 6 * 7 7 * This program is free software; you can redistribute it and/or modify … … 62 62 static int is_min(lt_op_type lt, const struct inst *inst) 63 63 { 64 struct coordmin;65 66 min = meas_find_min(lt, active_pkg->samples[inst->vec->n] );67 return coord_eq(inst->u.vec.end, min );64 const struct sample *min; 65 66 min = meas_find_min(lt, active_pkg->samples[inst->vec->n], NULL); 67 return coord_eq(inst->u.vec.end, min->pos); 68 68 } 69 69 … … 72 72 const struct inst *inst, const struct inst *ref) 73 73 { 74 struct coordnext;74 const struct sample *next; 75 75 76 76 next = meas_find_next(lt, active_pkg->samples[inst->vec->n], 77 ref->u.vec.end );78 return coord_eq(inst->u.vec.end, next );77 ref->u.vec.end, NULL); 78 return coord_eq(inst->u.vec.end, next->pos); 79 79 } 80 80 … … 82 82 static int is_max(lt_op_type lt, const struct inst *inst) 83 83 { 84 struct coordmax;85 86 max = meas_find_max(lt, active_pkg->samples[inst->vec->n] );87 return coord_eq(inst->u.vec.end, max );84 const struct sample *max; 85 86 max = meas_find_max(lt, active_pkg->samples[inst->vec->n], NULL); 87 return coord_eq(inst->u.vec.end, max->pos); 88 88 } 89 89 … … 92 92 { 93 93 struct inst *a; 94 struct coord min,next;94 const struct sample *min, *next; 95 95 96 96 for (a = insts_ip_vec(); a; a = a->next) { 97 min = meas_find_min(lt, active_pkg->samples[a->vec->n] );97 min = meas_find_min(lt, active_pkg->samples[a->vec->n], NULL); 98 98 next = meas_find_next(lt, active_pkg->samples[inst->vec->n], 99 min );100 if (coord_eq(next , inst->u.vec.end))99 min->pos, NULL); 100 if (coord_eq(next->pos, inst->u.vec.end)) 101 101 return 1; 102 102 } … … 310 310 meas->offset = NULL; 311 311 meas_dsc = NULL; 312 /* we don't support qualifiers through the GUI yet */ 313 meas->low_qual = NULL; 314 meas->high_qual = NULL; 312 315 return 1; 313 316 } -
trunk/eda/fped/inst.c
r5948 r5967 36 36 struct bbox active_frame_bbox; 37 37 struct pkg *pkgs, *active_pkg, *curr_pkg; 38 struct inst * curr_frame= NULL;38 struct inst *frame_instantiating = NULL; 39 39 40 40 static struct pkg *prev_pkgs; … … 575 575 static void propagate_bbox(const struct inst *inst) 576 576 { 577 struct inst *frame = 578 curr_frame ? curr_frame: curr_pkg->insts[ip_frame];577 struct inst *frame = frame_instantiating ? 578 frame_instantiating : curr_pkg->insts[ip_frame]; 579 579 580 580 update_bbox(&frame->bbox, inst->bbox.min); … … 603 603 inst->obj = NULL; 604 604 inst->base = inst->bbox.min = inst->bbox.max = base; 605 inst->outer = curr_frame;605 inst->outer = frame_instantiating; 606 606 inst->active = IS_ACTIVE; 607 607 inst->next = NULL; … … 1031 1031 1032 1032 1033 st atic struct inst *find_meas_hint(const struct obj *obj)1033 struct inst *find_meas_hint(const struct obj *obj) 1034 1034 { 1035 1035 struct inst *inst; … … 1152 1152 inst->active = active; 1153 1153 find_inst(inst); 1154 curr_frame= inst;1154 frame_instantiating = inst; 1155 1155 } 1156 1156 … … 1158 1158 void inst_end_frame(const struct frame *frame) 1159 1159 { 1160 struct inst *inst = curr_frame;1161 1162 curr_frame = curr_frame->outer;1163 if ( curr_frame)1160 struct inst *inst = frame_instantiating; 1161 1162 frame_instantiating = frame_instantiating->outer; 1163 if (frame_instantiating) 1164 1164 propagate_bbox(inst); 1165 1165 if (inst->u.frame.active && frame == active_frame) … … 1246 1246 inst_select_pkg(NULL); 1247 1247 curr_pkg = pkgs; 1248 curr_frame= NULL;1248 frame_instantiating = NULL; 1249 1249 } 1250 1250 -
trunk/eda/fped/inst.h
r5941 r5967 138 138 /* 139 139 * frame being instantiated - we need to export this one for meas.c, so that 140 * measurement scan update the root frame's bounding box.140 * measurements can update the root frame's bounding box. 141 141 */ 142 extern struct inst * curr_frame;142 extern struct inst *frame_instantiating; 143 143 144 144 /* … … 184 184 int inst_arc(struct obj *obj, struct coord center, struct coord start, 185 185 struct coord stop, unit_type width); 186 struct inst *find_meas_hint(const struct obj *obj); 186 187 int inst_meas(struct obj *obj, struct coord from, struct coord to); 187 188 void inst_meas_hint(struct obj *obj, unit_type offset); -
trunk/eda/fped/meas.c
r5948 r5967 2 2 * meas.c - Measurements 3 3 * 4 * Written 2009 by Werner Almesberger5 * Copyright 2009 by Werner Almesberger4 * Written 2009, 2010 by Werner Almesberger 5 * Copyright 2009, 2010 by Werner Almesberger 6 6 * 7 7 * This program is free software; you can redistribute it and/or modify … … 36 36 while (samples[i]) { 37 37 next = samples[i]->next; 38 bitset_free(samples[i]->frame_set); 38 39 free(samples[i]); 39 40 samples[i] = next; … … 54 55 55 56 56 void meas_post(const struct vec *vec, struct coord pos) 57 void meas_post(const struct vec *vec, struct coord pos, 58 const struct bitset *frame_set) 57 59 { 58 60 struct sample **walk, *new; … … 65 67 if (pos.x < (*walk)->pos.x) 66 68 break; 67 if (pos.x == (*walk)->pos.x) 69 if (pos.x != (*walk)->pos.x) 70 continue; 71 if (bitset_ge((*walk)->frame_set, frame_set)) 68 72 return; 73 if (bitset_ge(frame_set, (*walk)->frame_set)) { 74 bitset_or((*walk)->frame_set, frame_set); 75 return; 76 } 69 77 } 70 78 new = alloc_type(struct sample); 71 79 new->pos = pos; 80 new->frame_set = bitset_clone(frame_set); 72 81 new->next = *walk; 73 82 *walk = new; … … 178 187 */ 179 188 180 struct coord meas_find_min(lt_op_type lt, const struct sample *s) 181 { 182 struct coord min; 183 184 min = s->pos; 189 const struct sample *meas_find_min(lt_op_type lt, const struct sample *s, 190 const struct bitset *qual) 191 { 192 const struct sample *min = NULL; 193 185 194 while (s) { 186 if (lt(s->pos, min) || 187 (!lt(min, s->pos) && lt_xy(s->pos, min))) 188 min = s->pos; 195 if (!qual || bitset_ge(s->frame_set, qual)) 196 if (!min || lt(s->pos, min->pos) || 197 (!lt(min->pos, s->pos) && lt_xy(s->pos, min->pos))) 198 min = s; 189 199 s = s->next; 190 200 } … … 193 203 194 204 195 struct coord meas_find_next(lt_op_type lt, const struct sample *s, 196 struct coord ref) 197 { 198 struct coord next; 199 200 next = s->pos; 205 const struct sample *meas_find_next(lt_op_type lt, const struct sample *s, 206 struct coord ref, const struct bitset *qual) 207 { 208 const struct sample *next = NULL; 209 201 210 while (s) { 202 if (better_next(lt, ref, next, s->pos)) 203 next = s->pos; 211 if (!qual || bitset_ge(s->frame_set, qual)) 212 if (!next || better_next(lt, ref, next->pos, s->pos)) 213 next = s; 204 214 s = s->next; 205 215 } … … 208 218 209 219 210 struct coord meas_find_max(lt_op_type lt, const struct sample *s) 211 { 212 struct coord max; 213 214 max = s->pos; 220 const struct sample *meas_find_max(lt_op_type lt, const struct sample *s, 221 const struct bitset *qual) 222 { 223 const struct sample *max = NULL; 224 215 225 while (s) { 216 if (lt(max, s->pos) || 217 (!lt(s->pos, max) && lt_xy(max, s->pos))) 218 max = s->pos; 226 if (!qual || bitset_ge(s->frame_set, qual)) 227 if (!max || lt(max->pos, s->pos) || 228 (!lt(s->pos, max->pos) && lt_xy(max->pos, s->pos))) 229 max = s; 219 230 s = s->next; 220 231 } … … 226 237 227 238 228 static int instantiate_meas_pkg(void) 239 static struct bitset *make_frame_set(struct frame_qual *qual, int n_frames) 240 { 241 struct bitset *set; 242 243 set = bitset_new(n_frames); 244 while (qual) { 245 bitset_set(set, qual->frame->n); 246 qual = qual->next; 247 } 248 return set; 249 } 250 251 252 static int instantiate_meas_pkg(int n_frames) 229 253 { 230 254 struct obj *obj; 231 255 const struct meas *meas; 232 struct coord a0, b0; 256 struct bitset *set; 257 const struct sample *a0, *b0; 233 258 lt_op_type lt; 234 259 … … 237 262 continue; 238 263 meas = &obj->u.meas; 264 265 /* optimization. not really needed anymore. */ 239 266 if (!curr_pkg->samples[obj->base->n] || 240 267 !curr_pkg->samples[meas->high->n]) … … 242 269 243 270 lt = lt_op[meas->type]; 244 a0 = meas_find_min(lt, curr_pkg->samples[obj->base->n]); 271 272 set = make_frame_set(meas->low_qual, n_frames); 273 a0 = meas_find_min(lt, curr_pkg->samples[obj->base->n], set); 274 bitset_free(set); 275 if (!a0) 276 continue; 277 278 set = make_frame_set(meas->high_qual, n_frames); 245 279 if (is_next[meas->type]) 246 280 b0 = meas_find_next(lt, 247 curr_pkg->samples[meas->high->n], a0 );281 curr_pkg->samples[meas->high->n], a0->pos, set); 248 282 else 249 283 b0 = meas_find_max(lt, 250 curr_pkg->samples[meas->high->n]); 284 curr_pkg->samples[meas->high->n], set); 285 bitset_free(set); 286 if (!b0) 287 continue; 251 288 252 289 inst_meas(obj, 253 meas->inverted ? b0 : a0, meas->inverted ? a0 : b0); 290 meas->inverted ? b0->pos : a0->pos, 291 meas->inverted ? a0->pos : b0->pos); 254 292 } 255 293 return 1; … … 257 295 258 296 259 int instantiate_meas( void)297 int instantiate_meas(int n_frames) 260 298 { 261 299 struct pkg *pkg; 262 300 263 curr_frame= pkgs->insts[ip_frame];301 frame_instantiating = pkgs->insts[ip_frame]; 264 302 for (pkg = pkgs; pkg; pkg = pkg->next) 265 303 if (pkg->name) { 266 304 inst_select_pkg(pkg->name); 267 if (!instantiate_meas_pkg( ))305 if (!instantiate_meas_pkg(n_frames)) 268 306 return 0; 269 307 } -
trunk/eda/fped/meas.h
r5480 r5967 2 2 * meas.h - Measurements 3 3 * 4 * Written 2009 by Werner Almesberger5 * Copyright 2009 by Werner Almesberger4 * Written 2009, 2010 by Werner Almesberger 5 * Copyright 2009, 2010 by Werner Almesberger 6 6 * 7 7 * This program is free software; you can redistribute it and/or modify … … 18 18 #include "coord.h" 19 19 #include "expr.h" 20 #include "bitset.h" 20 21 21 22 … … 24 25 struct vec; 25 26 struct obj; 27 28 struct frame_qual { 29 const struct frame *frame; 30 struct frame_qual *next; 31 }; 26 32 27 33 struct meas { … … 40 46 struct vec *high; 41 47 struct expr *offset; 48 49 /* frame qualifiers */ 50 struct frame_qual *low_qual; 51 struct frame_qual *high_qual; 42 52 }; 43 53 44 54 struct sample { 45 55 struct coord pos; 56 struct bitset *frame_set; 46 57 struct sample *next; 47 58 }; … … 55 66 int lt_xy(struct coord a, struct coord b); 56 67 57 struct coord meas_find_min(lt_op_type lt, const struct sample *s); 58 struct coord meas_find_next(lt_op_type lt, const struct sample *s, 59 struct coord ref); 60 struct coord meas_find_max(lt_op_type lt, const struct sample *s); 68 const struct sample *meas_find_min(lt_op_type lt, const struct sample *s, 69 const struct bitset *qual); 70 const struct sample *meas_find_next(lt_op_type lt, const struct sample *s, 71 struct coord ref, const struct bitset *qual); 72 const struct sample *meas_find_max(lt_op_type lt, const struct sample *s, 73 const struct bitset *qual); 61 74 62 75 63 76 void reset_samples(struct sample **samples, int n); 64 77 void meas_start(void); 65 void meas_post(const struct vec *vec, struct coord pos); 66 int instantiate_meas(void); 78 void meas_post(const struct vec *vec, struct coord pos, 79 const struct bitset *frame_set); 80 int instantiate_meas(int n_frames); 67 81 68 82 #endif /* !MEAS_H */ -
trunk/eda/fped/obj.c
r5948 r5967 19 19 #include "error.h" 20 20 #include "expr.h" 21 #include "bitset.h" 21 22 #include "meas.h" 22 23 #include "inst.h" … … 37 38 struct frame *active_frame = NULL; 38 39 void *instantiation_error = NULL; 40 41 42 static struct bitset *frame_set; /* frames visited in "call chain" */ 39 43 40 44 … … 182 186 if (!inst_vec(vec, vec_base)) 183 187 goto error; 184 meas_post(vec, vec->pos );188 meas_post(vec, vec->pos, frame_set); 185 189 } 186 190 return 1; … … 400 404 active && parent == active_frame, 401 405 active && frame == active_frame); 406 bitset_set(frame_set, frame->n); 402 407 frame->curr_parent = parent; 403 408 ok = iterate_tables(frame, frame->tables, base, active); 404 409 inst_end_frame(frame); 410 bitset_clear(frame_set, frame->n); 405 411 frame->curr_parent = NULL; 406 412 return ok; … … 459 465 460 466 467 static int enumerate_frames(void) 468 { 469 struct frame *frame; 470 int n = 0; 471 472 for (frame = frames; frame; frame = frame->next) 473 frame->n = n++; 474 return n; 475 } 476 477 461 478 int instantiate(void) 462 479 { 463 480 struct coord zero = { 0, 0 }; 481 int n_frames; 464 482 int ok; 465 483 466 484 meas_start(); 467 485 inst_start(); 486 n_frames = enumerate_frames(); 487 frame_set = bitset_new(n_frames); 468 488 instantiation_error = NULL; 469 489 reset_all_loops(); … … 481 501 ok = refine_layers(); 482 502 if (ok) 483 ok = instantiate_meas( );503 ok = instantiate_meas(n_frames); 484 504 if (ok) 485 505 inst_commit(); 486 506 else 487 507 inst_revert(); 508 bitset_free(frame_set); 488 509 return ok; 489 510 } -
trunk/eda/fped/obj.h
r5948 r5967 164 164 struct obj *active_ref; 165 165 166 /* For searching */166 /* for searching */ 167 167 struct obj *found_ref; /* NULL if not found yet */ 168 169 /* index into bit vector in samples */ 170 int n; 168 171 169 172 /* for dumping */ -
trunk/eda/fped/test/Common
r5944 r5967 63 63 64 64 65 expect_grep() 66 { 67 grep "$1" <_out >_tmp || exit 1 68 mv _tmp _out 69 shift 70 expect "$@" 71 } 72 73 65 74 if [ ! -z "$CWD_PREFIX" -a ! -z "$FPED" -a "$FPED" = "${FPED#/}" ]; then 66 75 FPED="$CWD_PREFIX/$FPED" -
trunk/eda/fped/test/del_frame
r5947 r5967 54 54 } 55 55 56 frame f @ 56 57 meas f.v -> f.v 57 58 … … 65 66 EOF 66 67 68 #------------------------------------------------------------------------------ 69 70 fped_dump "delete frame: measurements with qualifiers disappear" <<EOF 71 frame f { 72 v: vec @(0mm, 0mm) 73 } 74 75 frame g { frame f @ } 76 77 frame g @ 78 meas g/f.v -> f.v 79 80 %del g 81 EOF 82 expect <<EOF 83 /* MACHINE-GENERATED ! */ 84 85 frame f { 86 v: vec @(0mm, 0mm) 87 } 88 89 package "_" 90 unit mm 91 EOF 92 67 93 ############################################################################### -
trunk/eda/fped/test/del_vec
r5947 r5967 49 49 v: vec @(0mm, 0mm) 50 50 } 51 frame f @ 51 52 meas f.v -> f.v 52 53 %del f.v … … 60 61 package "_" 61 62 unit mm 63 frame f @ 62 64 EOF 63 65 -
trunk/eda/fped/test/structure
r5944 r5967 73 73 b: vec @(1mm, 1mm) 74 74 } 75 frame f @ 75 76 meas f.a -> f.b 76 77 EOF … … 85 86 package "_" 86 87 unit mm 88 frame f @ 87 89 meas f.a -> f.b 88 90 EOF
Note: See TracChangeset
for help on using the changeset viewer.
