Skip to content

Commit d181b2e

Browse files
committed
Add bobbl/punycc
1 parent 37c83f5 commit d181b2e

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ endif
4747

4848
all:
4949
$(Q)$(MAKE) -C src/asm-hello BUILD_DIR="$(BUILD_DIR)" RV32_EXT=$(RV32_EXT) OPT_LEVEL="$(OPT_LEVEL)" all
50+
$(Q)$(MAKE) -C src/cc BUILD_DIR="$(BUILD_DIR)" RV32_EXT=$(RV32_EXT) OPT_LEVEL="$(OPT_LEVEL)" all
5051
$(Q)$(MAKE) -C src/ansibench/nbench BUILD_DIR="$(BUILD_DIR)" RV32_EXT=$(RV32_EXT) OPT_LEVEL="$(OPT_LEVEL)" all
5152

5253
include mk/common.mk

src/cc/Makefile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
RV32_EXT ?= rv32gc
2+
OPT_LEVEL ?= 0 1 2
3+
4+
CURDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
5+
SRC_DIR := $(CURDIR)
6+
7+
CFLAGS := -std=c99
8+
9+
# prevent lazy set
10+
ifeq ($(BUILD_DIR),)
11+
BUILD_DIR := $(CURDIR)/build
12+
endif
13+
14+
EXECUTABLES := cc.elf
15+
16+
SHELL_HACK := $(shell mkdir -p $(foreach LEVEL,$(OPT_LEVEL),$(BUILD_DIR)/$(RV32_EXT)/O$(LEVEL)/cc))
17+
18+
.PHONY: all clean build-O0 build-O1 build-O2
19+
20+
ifneq ($(filter $(OPT_LEVEL), 0),)
21+
all: build-O0
22+
endif
23+
24+
ifneq ($(filter $(OPT_LEVEL), 1),)
25+
all: build-O1
26+
endif
27+
28+
ifneq ($(filter $(OPT_LEVEL), 2),)
29+
all: build-O2
30+
endif
31+
32+
include ../../mk/common.mk
33+
include ../../mk/toolchain.mk
34+
35+
build-O0: $(addprefix $(BUILD_DIR)/$(RV32_EXT)/O0/cc/,$(EXECUTABLES))
36+
37+
$(BUILD_DIR)/$(RV32_EXT)/O0/cc/$(EXECUTABLES): $(SRC_DIR)/cc.c | build-toolchain
38+
$(VECHO) " RISCVCC\t$(patsubst $(abspath $(BUILD_DIR)/..)/%,%,$@)\n"
39+
$(Q)$(CROSS_COMPILE) -o $@ -O0 $(CFLAGS) $<
40+
41+
build-O1: $(addprefix $(BUILD_DIR)/$(RV32_EXT)/O1/cc/,$(EXECUTABLES))
42+
43+
$(BUILD_DIR)/$(RV32_EXT)/O1/cc/$(EXECUTABLES): $(SRC_DIR)/cc.c | build-toolchain
44+
$(VECHO) " RISCVCC\t$(patsubst $(abspath $(BUILD_DIR)/..)/%,%,$@)\n"
45+
$(Q)$(CROSS_COMPILE) -o $@ -O1 $(CFLAGS) $<
46+
47+
build-O2: $(addprefix $(BUILD_DIR)/$(RV32_EXT)/O2/cc/,$(EXECUTABLES))
48+
49+
$(BUILD_DIR)/$(RV32_EXT)/O2/cc/$(EXECUTABLES): $(SRC_DIR)/cc.c | build-toolchain
50+
$(VECHO) " RISCVCC\t$(patsubst $(abspath $(BUILD_DIR)/..)/%,%,$@)\n"
51+
$(Q)$(CROSS_COMPILE) -o $@ -O2 $(CFLAGS) $<
52+
53+
clean:
54+
$(RM) $(foreach LEVEL,$(OPT_LEVEL),$(BUILD_DIR)/$(RV32_EXT)/O$(LEVEL)/cc/*)

src/cc/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ Inspired by
2020
* [Compiler Construction](https://people.inf.ethz.ch/wirth/CompilerConstruction/index.html) -
2121
brief but comprehensive book by Niklaus Wirth.
2222

23-
Run the following command under top-level directory.
24-
```shell
25-
tests/cc-selfhost.sh
26-
```
27-
2823
## Language restrictions
2924

3025
* No linker.

src/cc/cc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
* 0Ah % 7Dh }
4545
*/
4646

47+
#include "emit.c"
48+
4749
/* Helper */
4850

4951
/* helper to write a 32 bit number to a char array */

src/cc/emit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1717
*/
1818

19+
#include "stdlib.c"
20+
1921
/* constants */
2022
unsigned buf_size;
2123

0 commit comments

Comments
 (0)