Skip to content

Commit

Permalink
Squashed 'misc/packcc/' changes from 4a7dbab60..43934f352
Browse files Browse the repository at this point in the history
43934f352 Improve makefiles
29a2a1b06 Support gcc for IBM AIX
53aefcb47 Update README.md
6035daaba Change macro to check for size_t byte size
6015afca6 Fix universal-ctags#34
dfc33e6bf Merge pull request universal-ctags#33 from dolik-rce/test-improvements
8176c6492 fix uncrustify version check
fa144ef7c properly quote load statements
df95cbde7 refactor test utils
1ff5f9100 test --ascii option
e54a94c03 avoid copying calc.peg into test directories
a6a7ef719 test grammar dump (--debug option)
f1323e5ec display coverage
223b264fa allow options in CC environment variable

git-subtree-dir: misc/packcc
git-subtree-split: 43934f35254c08f0827801f80bbbec0e03c69fe0
  • Loading branch information
masatake committed Jun 10, 2021
1 parent 769d691 commit dd52f21
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 52 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview ##

**PackCC** is a packrat parser generator for C. Its main features are as follows:
**PackCC** is a parser generator for C. Its main features are as follows:

- Generates your parser in C from a grammar described in a **PEG**,
- Gives your parser great efficiency by **packrat parsing**,
Expand Down Expand Up @@ -34,6 +34,8 @@ For convenience, the build environments using GCC, Clang, and Microsoft Visual S

### Using GCC ###

#### Other than MinGW ####

`packcc` will be built in both directories `build/gcc/debug/bin` and `build/gcc/release/bin` using `gcc` by executing the following commands:

```
Expand All @@ -44,8 +46,22 @@ make check # bats-core and uncrustify are required (see tests/README.md)

`packcc` in the directory `build/gcc/release/bin` is suitable for practical use.

#### MinGW ####

`packcc` will be built in both directories `build/mingw-gcc/debug/bin` and `build/mingw-gcc/release/bin` using `gcc` by executing the following commands:

```
cd build/mingw-gcc
make
make check # bats-core and uncrustify are required (see tests/README.md)
```

`packcc` in the directory `build/mingw-gcc/release/bin` is suitable for practical use.

### Using Clang ###

#### Other than MinGW ####

`packcc` will be built in both directories `build/clang/debug/bin` and `build/clang/release/bin` using `clang` by executing the following commands:

```
Expand All @@ -56,6 +72,18 @@ make check # bats-core and uncrustify are required (see tests/README.md)

`packcc` in the directory `build/clang/release/bin` is suitable for practical use.

#### MinGW ####

`packcc` will be built in both directories `build/mingw-clang/debug/bin` and `build/mingw-clang/release/bin` using `clang` by executing the following commands:

```
cd build/mingw-clang
make
make check # bats-core and uncrustify are required (see tests/README.md)
```

`packcc` in the directory `build/mingw-clang/release/bin` is suitable for practical use.

### Using Microsoft Visual Studio ###

You have to install Microsoft Visual Studio 2019 in advance.
Expand Down
11 changes: 6 additions & 5 deletions build/clang/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC=clang
CFLAGS_D=-std=gnu89 -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O0 -g2
CFLAGS_R=-std=gnu89 -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O2 -DNDEBUG
CFLAGS_D=-std=gnu89 -fsigned-char -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O0 -g2
CFLAGS_R=-std=gnu89 -fsigned-char -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O2 -DNDEBUG
LDFLAGS_D=
LDFLAGS_R=

Expand All @@ -24,7 +24,7 @@ SRCS= \
$(patsubst %,$(TMPDIR_R)/%.c,$(EXAMPLES)) \
$(patsubst %,$(TMPDIR_R)/%.h,$(EXAMPLES))

.PHONY: all clean
.PHONY: all check clean

.SECONDARY: $(SRCS)

Expand All @@ -48,8 +48,9 @@ $(TMPDIR_D)/examples/%.c $(TMPDIR_D)/examples/%.h: $(SRCDIR)/examples/%.peg $(BI
$(TMPDIR_R)/examples/%.c $(TMPDIR_R)/examples/%.h: $(SRCDIR)/examples/%.peg $(BINDIR_R)/packcc
mkdir -p $(dir $@) && $(BINDIR_R)/packcc -o $(basename $@) $<

check: $(BINDIR_R)/packcc
PACKCC=$$PWD/$^ $(TESTDIR)/test.sh
check: $(BINDIR_D)/packcc $(BINDIR_R)/packcc
@echo "== Debug Version ==" && PACKCC=$$PWD/$(BINDIR_D)/packcc CC="$(CC) $(CFLAGS_D)" $(TESTDIR)/test.sh
@echo "== Release Version ==" && PACKCC=$$PWD/$(BINDIR_R)/packcc CC="$(CC) $(CFLAGS_R)" $(TESTDIR)/test.sh

clean:
rm -f $(BINS) $(SRCS)
11 changes: 6 additions & 5 deletions build/gcc/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC=gcc
CFLAGS_D=-std=gnu89 -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O0 -g2
CFLAGS_R=-std=gnu89 -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O2 -DNDEBUG
CFLAGS_D=-std=gnu89 -fsigned-char -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O0 -g2
CFLAGS_R=-std=gnu89 -fsigned-char -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O2 -DNDEBUG
LDFLAGS_D=
LDFLAGS_R=

Expand All @@ -24,7 +24,7 @@ SRCS= \
$(patsubst %,$(TMPDIR_R)/%.c,$(EXAMPLES)) \
$(patsubst %,$(TMPDIR_R)/%.h,$(EXAMPLES))

.PHONY: all clean
.PHONY: all check clean

.SECONDARY: $(SRCS)

Expand All @@ -48,8 +48,9 @@ $(TMPDIR_D)/examples/%.c $(TMPDIR_D)/examples/%.h: $(SRCDIR)/examples/%.peg $(BI
$(TMPDIR_R)/examples/%.c $(TMPDIR_R)/examples/%.h: $(SRCDIR)/examples/%.peg $(BINDIR_R)/packcc
mkdir -p $(dir $@) && $(BINDIR_R)/packcc -o $(basename $@) $<

check: $(BINDIR_R)/packcc
PACKCC=$$PWD/$^ $(TESTDIR)/test.sh
check: $(BINDIR_D)/packcc $(BINDIR_R)/packcc
@echo "== Debug Version ==" && PACKCC=$$PWD/$(BINDIR_D)/packcc CC="$(CC) $(CFLAGS_D)" $(TESTDIR)/test.sh
@echo "== Release Version ==" && PACKCC=$$PWD/$(BINDIR_R)/packcc CC="$(CC) $(CFLAGS_R)" $(TESTDIR)/test.sh

clean:
rm -f $(BINS) $(SRCS)
7 changes: 4 additions & 3 deletions build/mingw-clang/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SRCS= \
$(patsubst %,$(TMPDIR_R)/%.c,$(EXAMPLES)) \
$(patsubst %,$(TMPDIR_R)/%.h,$(EXAMPLES))

.PHONY: all clean
.PHONY: all check clean

.SECONDARY: $(SRCS)

Expand All @@ -48,8 +48,9 @@ $(TMPDIR_D)/examples/%.c $(TMPDIR_D)/examples/%.h: $(SRCDIR)/examples/%.peg $(BI
$(TMPDIR_R)/examples/%.c $(TMPDIR_R)/examples/%.h: $(SRCDIR)/examples/%.peg $(BINDIR_R)/packcc
mkdir -p $(dir $@) && $(BINDIR_R)/packcc -o $(basename $@) $<

check: $(BINDIR_R)/packcc
PACKCC=$$PWD/$^ $(TESTDIR)/test.sh
check: $(BINDIR_D)/packcc $(BINDIR_R)/packcc
@echo "== Debug Version ==" && PACKCC=$$PWD/$(BINDIR_D)/packcc CC="$(CC) $(CFLAGS_D)" $(TESTDIR)/test.sh
@echo "== Release Version ==" && PACKCC=$$PWD/$(BINDIR_R)/packcc CC="$(CC) $(CFLAGS_R)" $(TESTDIR)/test.sh

clean:
rm -f $(BINS) $(SRCS)
7 changes: 4 additions & 3 deletions build/mingw-gcc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SRCS= \
$(patsubst %,$(TMPDIR_R)/%.c,$(EXAMPLES)) \
$(patsubst %,$(TMPDIR_R)/%.h,$(EXAMPLES))

.PHONY: all clean
.PHONY: all check clean

.SECONDARY: $(SRCS)

Expand All @@ -48,8 +48,9 @@ $(TMPDIR_D)/examples/%.c $(TMPDIR_D)/examples/%.h: $(SRCDIR)/examples/%.peg $(BI
$(TMPDIR_R)/examples/%.c $(TMPDIR_R)/examples/%.h: $(SRCDIR)/examples/%.peg $(BINDIR_R)/packcc
mkdir -p $(dir $@) && $(BINDIR_R)/packcc -o $(basename $@) $<

check: $(BINDIR_R)/packcc
PACKCC=$$PWD/$^ $(TESTDIR)/test.sh
check: $(BINDIR_D)/packcc $(BINDIR_R)/packcc
@echo "== Debug Version ==" && PACKCC=$$PWD/$(BINDIR_D)/packcc CC="$(CC) $(CFLAGS_D)" $(TESTDIR)/test.sh
@echo "== Release Version ==" && PACKCC=$$PWD/$(BINDIR_R)/packcc CC="$(CC) $(CFLAGS_R)" $(TESTDIR)/test.sh

clean:
rm -f $(BINS) $(SRCS)
5 changes: 4 additions & 1 deletion src/packcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ static size_t strnlen_(const char *str, size_t maxlen) {
#define __attribute__(x)
#endif

#undef TRUE /* to avoid macro definition conflicts with the system header file of IBM AIX */
#undef FALSE

#define VERSION "1.5.0"

#ifndef BUFFER_INIT_SIZE
Expand Down Expand Up @@ -910,7 +913,7 @@ static size_t populate_bits(size_t x) {
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
#ifndef _M_IX86 /* not Windows for x86 (32-bit) */
#if (defined __SIZEOF_SIZE_T__ && __SIZEOF_SIZE_T__ == 8) /* gcc or clang */ || defined _WIN64 /* MSVC */
x |= x >> 32;
#endif
return x;
Expand Down
4 changes: 3 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
packcc
packcc.exe
*/parser.peg
packcc.gcda
packcc.gcno
packcc.c.gcov
*/parser.c
*/parser.h
*/parser
Expand Down
19 changes: 19 additions & 0 deletions tests/ascii.d/ascii.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bats

load "$TESTDIR/utils.sh"

@test "Testing ascii.d - generation" {
PACKCC_OPTS=("--ascii")
test_generate
}

@test "Testing ascii.d - check code" {
! in_source "pcc_get_char_as_utf32"
}

@test "Testing ascii.d - compilation" {
test_compile
}
@test "Testing ascii.d - run" {
run_for_input "ascii.d/input.txt"
}
4 changes: 4 additions & 0 deletions tests/ascii.d/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This
is
a
test
3 changes: 3 additions & 0 deletions tests/ascii.d/input.peg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FILE <- WORD / SPACE
WORD <- [^ \r\n\t]+ { PRINT($0); }
SPACE <- [ \r\n\t]+
1 change: 1 addition & 0 deletions tests/ascii.d/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test
7 changes: 3 additions & 4 deletions tests/calc.d/calc.bats
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env bats

load $TESTDIR/utils.sh
load "$TESTDIR/utils.sh"

@test "Testing calc.d - generation" {
cp -f ../src/examples/calc.peg calc.d/parser.peg ## NOTE: Copy is adopted instead of using a link, considering MinGW.
test_generate calc.d parser.peg
test_generate "$ROOTDIR/src/examples/calc.peg"
}

@test "Testing calc.d - compilation" {
"${CC:-cc}" calc.d/parser.c -o calc.d/parser
${CC:-cc} calc.d/parser.c -o calc.d/parser
}

@test "Testing calc.d - run" {
Expand Down
18 changes: 3 additions & 15 deletions tests/code_generation.d/generation.bats
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
#!/usr/bin/env bats

load $TESTDIR/utils.sh

in_header() {
grep -Fq "$1" "code_generation.d/parser.h"
}

in_source() {
grep -Fq "$1" "code_generation.d/parser.c"
}

get_line() {
sed -n "/$1/=" "code_generation.d/$2" | tail -n1
}
load "$TESTDIR/utils.sh"

@test "Testing code_generation.d - generation" {
test_generate "code_generation.d"
test_generate
}

@test "Testing code_generation.d - compilation" {
test_compile "code_generation.d" \
test_compile \
-D pcc_create=my_create \
-D pcc_destroy=my_destroy \
-D pcc_parse=my_parse \
Expand Down
8 changes: 8 additions & 0 deletions tests/dump.d/dump.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bats

load "$TESTDIR/utils.sh"

@test "Testing dump.d - generation" {
run "$PACKCC" --debug -o "dump.d/parser" "$ROOTDIR/src/examples/calc.peg" 2>&1
check_output "dump.d/expected.txt"
}
Loading

0 comments on commit dd52f21

Please sign in to comment.