Re: [hackers] [sbase][patches] sort makefile and add getconf guard file
On Mon, 3 Oct 2016 15:59:10 -0700 Evan Gateswrote: Hey Evan, > After discussion on IRC, a patch that changes getconf.sh and creates a > single header. I have pushed your patch and one little tweak for the heredocs to the 2f30 staging repository. They'll hit mainline soon. Cheers FRIGN -- FRIGN
Re: [hackers] [sbase][patches] sort makefile and add getconf guard file
On Mon, Oct 3, 2016 at 11:19 AM, FRIGNwrote: > On Thu, 29 Sep 2016 08:54:30 -0700 > Evan Gates wrote: >> sbase-getconf_guard.diff adds a guard file to the getconf rules so >> that getconf.sh doesn't get run multiple times in parallel. > > This could be solved a bit more elegantly. You can see that getconf.sh > generates the files confstr_l.h, limits_l.h, sysconf_l.h and > pathconf_l.h. Maybe you can work something out. :) After discussion on IRC, a patch that changes getconf.sh and creates a single header. From 0ef723e6c448f555c52b156a8abf488b4dd6f368 Mon Sep 17 00:00:00 2001 From: Evan Gates Date: Mon, 3 Oct 2016 15:55:22 -0700 Subject: [PATCH] use only one getconf header this simplifies the getconf.sh script and handling parallel make --- Makefile | 10 +- getconf.c | 17 + getconf.sh | 18 -- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 6b2bfdf..25bab70 100644 --- a/Makefile +++ b/Makefile @@ -205,10 +205,10 @@ $(LIBUTIL): $(LIBUTILOBJ) $(AR) rc $@ $? $(RANLIB) $@ -getconf.c: confstr_l.h limits_l.h sysconf_l.h pathconf_l.h +getconf.o: getconf.h -confstr_l.h limits_l.h sysconf_l.h pathconf_l.h: getconf.sh - ./getconf.sh +getconf.h: getconf.sh + ./getconf.sh > $@ install: all mkdir -p $(DESTDIR)$(PREFIX)/bin @@ -234,7 +234,7 @@ dist: clean sbase-box: $(LIB) $(SRC) mkdir -p build cp $(HDR) build - cp confstr_l.h limits_l.h sysconf_l.h pathconf_l.h build + cp getconf.h build for f in $(SRC); do sed "s/^main(/$$(echo "$${f%.c}" | sed s/-/_/g)_&/" < $$f > build/$$f; done echo '#include ' > build/$@.c echo '#include ' >> build/$@.c @@ -270,7 +270,7 @@ sbase-box-uninstall: uninstall clean: rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz - rm -f confstr_l.h limits_l.h sysconf_l.h pathconf_l.h + rm -f getconf.h .PHONY: all install uninstall dist sbase-box sbase-box-install sbase-box-uninstall clean diff --git a/getconf.c b/getconf.c index 94bff80..e611659 100644 --- a/getconf.c +++ b/getconf.c @@ -12,22 +12,7 @@ struct var { long v; }; -static const struct var pathconf_l[] = { -#include "pathconf_l.h" -}; - -static const struct var sysconf_l[] = { -#include "sysconf_l.h" -}; - -static const struct var confstr_l[] = { -#include "confstr_l.h" -}; - -static const struct var limits_l[] = { -#include "limits_l.h" -}; - +#include "getconf.h" void usage(void) diff --git a/getconf.sh b/getconf.sh index cca5873..e826385 100755 --- a/getconf.sh +++ b/getconf.sh @@ -1,14 +1,12 @@ #!/bin/sh -ifdef() -{ - awk '{printf("#ifdef %s\n"\ - "\t{\"%s\",\t%s},\n"\ - "#endif\n", $2, $1, $2)}' > $1 +ifdef() { + printf 'static const struct var %s[] = {\n' "$1" + awk '{printf("#ifdef %s\n\t{\"%s\",\t%s},\n#endif\n", $2, $1, $2)}' + echo '};' } - -cat <
Re: [hackers] [sbase][patch]find: copy path before using basename
On Mon, 3 Oct 2016 15:04:16 -0700 Evan Gateswrote: > "The basename() function may modify the string pointed to by path..." > Thanks POSIX. > + char path[strlen(arg->path)+1]; > + strcpy(path, arg->path); > + return !fnmatch((char *)arg->extra.p, path, 0); Please don't use VLA's. Use estrdup() in this case. Cheers FRIGN -- FRIGN
Re: [hackers] [sbase][patches] sort makefile and add getconf guard file
On Thu, 29 Sep 2016 08:54:30 -0700 Evan Gateswrote: Hey Evan, > sbase-sort_makefile.diff sorts all the lists in the Makefile. Sorry > that was bugging me. this looks good. :) > sbase-getconf_guard.diff adds a guard file to the getconf rules so > that getconf.sh doesn't get run multiple times in parallel. This could be solved a bit more elegantly. You can see that getconf.sh generates the files confstr_l.h, limits_l.h, sysconf_l.h and pathconf_l.h. Maybe you can work something out. :) Cheers FRIGN -- FRIGN
[hackers] [scc] [cc2] Assign curfun only in functions || Roberto E. Vargas Caballero
commit 4c6c01a90ba930f89907cc16efc1a3b2d2f2db6c Author: Roberto E. Vargas CaballeroAuthorDate: Mon Oct 3 16:11:37 2016 +0200 Commit: Roberto E. Vargas Caballero CommitDate: Mon Oct 3 16:11:37 2016 +0200 [cc2] Assign curfun only in functions Curfun was changed in every prototype, and it meant that the current function could be changed when a prototype was declared in the body of a function. diff --git a/cc2/parser.c b/cc2/parser.c index 496b900..34f35c3 100644 --- a/cc2/parser.c +++ b/cc2/parser.c @@ -37,6 +37,7 @@ struct swtch { }; static struct swtch swtbl[NR_BLOCK], *swp = swtbl; +static Symbol *lastfun; typedef void parsefun(char *, union tokenop); static parsefun type, symbol, getname, unary, binary, ternary, call, @@ -543,7 +544,7 @@ decl(Symbol *sym) Type *tp = >type; if (tp->flags & FUNF) { - curfun = sym; + lastfun = sym; } else { switch (sym->kind) { case SEXTRN: @@ -653,6 +654,7 @@ stmt(void) static void beginfun(void) { + curfun = lastfun; inpars = 1; pushctx(); addstmt(newnode(OBFUN), SETCUR);
[hackers] [scc] [tests] Add new test about call functions || Roberto E. Vargas Caballero
commit e1f34328f525289ed96ef82a644ce1abd6916c4e Author: Roberto E. Vargas CaballeroAuthorDate: Mon Oct 3 16:16:48 2016 +0200 Commit: Roberto E. Vargas Caballero CommitDate: Mon Oct 3 16:16:48 2016 +0200 [tests] Add new test about call functions diff --git a/tests/0081-calls.c b/tests/0081-calls.c new file mode 100644 index 000..64425f5 --- /dev/null +++ b/tests/0081-calls.c @@ -0,0 +1,18 @@ + +int +f1(char *p) +{ + return *p+1; +} + +int +main() +{ + char s = 1; + int v[1000]; + int f1(char *); + + if (f1() != 2) + return 1; + return 0; +} diff --git a/tests/scc-tests.lst b/tests/scc-tests.lst index 1782198..9728e79 100644 --- a/tests/scc-tests.lst +++ b/tests/scc-tests.lst @@ -76,3 +76,4 @@ 0078-dirifexpr.c 0079-cond.c 0080-arrays.c +0081-calls.c
[hackers] [scc] [cc2-qbe] Fix lhs() and OADDR || Roberto E. Vargas Caballero
commit d9b9cf2c66cd52605ddbac816cd204daf3f4a4cf Author: Roberto E. Vargas CaballeroAuthorDate: Mon Oct 3 16:05:03 2016 +0200 Commit: Roberto E. Vargas Caballero CommitDate: Mon Oct 3 16:05:03 2016 +0200 [cc2-qbe] Fix lhs() and OADDR lhs was returning the source node instead of returning the destination node, and it was hidden the error because the correct type of the lhs expression is the type of the parent when we are in a OADDR expression. Without this patch pointers passed as parameters had the same type that the base type instead of having pointer type. diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c index 425fd74..3deb1e4 100644 --- a/cc2/arch/qbe/cgen.c +++ b/cc2/arch/qbe/cgen.c @@ -326,7 +326,7 @@ lhs(Node *np, Node *new) case OMEM: case OAUTO: *new = *np; - return np; + return new; case OPTR: return rhs(np->left, new); case OFIELD: @@ -590,7 +590,9 @@ rhs(Node *np, Node *ret) case OPTR: return load(tp, rhs(l, ), ret); case OADDR: - return lhs(l, ret); + lhs(l, ret); + ret->type = *tp; + return ret; case OFIELD: return field(np, ret, 0); default:
[hackers] [scc] [cc1] Fix cc1 tests after 9761a80 || Roberto E. Vargas Caballero
commit 204960d4e839953472c11204ea6b2e893019cc0e Author: Roberto E. Vargas CaballeroAuthorDate: Mon Oct 3 13:42:10 2016 +0200 Commit: Roberto E. Vargas Caballero CommitDate: Mon Oct 3 13:42:10 2016 +0200 [cc1] Fix cc1 tests after 9761a80 diff --git a/cc1/tests/test002.c b/cc1/tests/test002.c index 3696fb7..015c63a 100644 --- a/cc1/tests/test002.c +++ b/cc1/tests/test002.c @@ -9,7 +9,7 @@ G4 P "x G8 I F "main { \ -S2 "S #NC #N2 +S2 "S #N8 #N2 M5 I "i #N0 M6 P "next #N2 A9 S2 "y diff --git a/cc1/tests/test030.c b/cc1/tests/test030.c index b09d6bd..c3180ba 100644 --- a/cc1/tests/test030.c +++ b/cc1/tests/test030.c @@ -7,12 +7,12 @@ error: output: G14I F "f1 { -S2 "foo#N24#N2 +S2 "foo#N18#N2 M3 I "i #N0 M4 I "j #N2 M5 I "k #N4 M7 P "p #N6 -M8 J "v #NE +M8 J "v #N8 A9 S2 "f A11P "p A12I "n diff --git a/cc1/tests/test040.c b/cc1/tests/test040.c index 2c1aae4..516a6fa 100644 --- a/cc1/tests/test040.c +++ b/cc1/tests/test040.c @@ -8,10 +8,10 @@ output: G9 I F "main { \ -S2 "List #N1C#N2 +S2 "List #NC #N2 M4 I "len#N0 M6 P "head #N2 -M7 P "back #N6 +M7 P "back #N4 A10S2 "List h A10 M4 .I } diff --git a/cc1/tests/test043.c b/cc1/tests/test043.c index 1b41f3b..2c1d71b 100644 --- a/cc1/tests/test043.c +++ b/cc1/tests/test043.c @@ -5,7 +5,7 @@ name: TEST043 description: Test for double typedef (taken from plan9 kernel) error: output: -S2 "Clock0link #NC #N2 +S2 "Clock0link #N8 #N2 M6 P "clock #N0 M8 P "link #N2 G9 S2 "cl0
[hackers] [scc] [cc2-qbe] Improve generation of or/and || Roberto E. Vargas Caballero
commit 6c048208cdea11ad20bb09c24363cf7065bdc217 Author: Roberto E. Vargas CaballeroAuthorDate: Mon Oct 3 13:39:43 2016 +0200 Commit: Roberto E. Vargas Caballero CommitDate: Mon Oct 3 13:39:43 2016 +0200 [cc2-qbe] Improve generation of or/and Cgen() was calling rhs() to generate the code of the conditions in branches, but it is better to call to log(), because it already handles the case of having an expression. diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c index 39ee9ec..425fd74 100644 --- a/cc2/arch/qbe/cgen.c +++ b/cc2/arch/qbe/cgen.c @@ -602,34 +602,30 @@ rhs(Node *np, Node *ret) Node * cgen(Node *np) { - Node ret, aux1, aux2, *p, *next, ifyes, ifno; + Node aux, *p, *next; setlabel(np->label); switch (np->op) { case OJMP: - label2node(, np->u.sym); - code(ASJMP, NULL, , NULL); + label2node(, np->u.sym); + code(ASJMP, NULL, , NULL); break; case OBRANCH: next = np->next; if (!next->label) next->label = newlabel(); - - label2node(, np->u.sym); - label2node(, next->label); - rhs(np->left, ); - code(ASBRANCH, , , ); + bool(np->left, np->u.sym, next->label); break; case ORET: - p = (np->left) ? rhs(np->left, ) : NULL; + p = (np->left) ? rhs(np->left, ) : NULL; code(ASRET, NULL, p, NULL); break; case OBSWITCH: - p = rhs(np->left, ); + p = rhs(np->left, ); swtch_if(p); break; default: - rhs(np, ); + rhs(np, ); break; } return NULL;