-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from charles-rs/main
add fastbrili to repo
- Loading branch information
Showing
46 changed files
with
8,436 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
*~ | ||
\#*\# | ||
*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
TARGET_EXEC ?= fastbrili | ||
|
||
BUILD_DIR ?= ./build | ||
SRC_DIRS ?= ./src | ||
DOC_DIR ?= ./doc | ||
SHELL = /bin/sh | ||
|
||
CONFIGS := $(wildcard config/*.cf) | ||
GEN_HEAD := $(CONFIGS:config/%.cf=src/%.h) | ||
GEN_TEX := $(CONFIGS:config/%.cf=doc/%.tex) | ||
|
||
SRCS := $(wildcard $(SRC_DIRS)/*.c $(SRC_DIRS)/**/*.c) | ||
|
||
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) | ||
DEPS := $(OBJS:.o=.d) | ||
|
||
INC_DIRS := $(shell find $(SRC_DIRS) -type d) | ||
INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | ||
|
||
|
||
CFLAGS += $(INC_FLAGS) | ||
|
||
.PHONY: debug | ||
|
||
debug: CFLAGS += -g -Og | ||
debug: $(BUILD_DIR)/$(TARGET_EXEC) | ||
|
||
.PHONY: coverage | ||
|
||
coverage: CFLAGS += --coverage -DDEBUG -g3 | ||
coverage: $(GEN_HEAD) | ||
mkdir $(BUILD_DIR) && cd $(BUILD_DIR) && $(CC) $(CFLAGS) $(abspath $(SRCS)) -o $(TARGET_EXEC) | ||
|
||
.PHONY: cov-report | ||
|
||
cov-report: | ||
gcovr -r . --html --html-details -o cov-report/out.html | ||
|
||
.PHONY: release | ||
|
||
release: CFLAGS += -O3 | ||
release: $(BUILD_DIR)/$(TARGET_EXEC) | ||
|
||
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) lib/lib.o | ||
$(CC) $(OBJS) -o $@ $(LDFLAGS) | ||
|
||
# # assembly | ||
# $(BUILD_DIR)/%.s.o: %.s | ||
# $(MKDIR_P) $(dir $@) | ||
# $(AS) $(ASFLAGS) -c $< -o $@ | ||
|
||
# c source | ||
$(BUILD_DIR)/%.c.o: %.c | $(GEN_HEAD) | ||
$(MKDIR_P) $(dir $@) | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
# configured header files | ||
src/%.h: config/%.cf srcgen.awk | ||
./srcgen.awk < $< > $@ | ||
|
||
brb.pdf: $(GEN_TEX) $(DOC_DIR)/main.tex | ||
cd $(DOC_DIR) && latex -output-format=pdf main.tex && mv main.pdf brb.pdf | ||
|
||
lib/lib.o: lib/lib.c | ||
cd lib && $(CC) -O3 -c lib.c | ||
|
||
doc: brb.pdf | ||
|
||
$(GEN_TEX): $(configs) docgen.sh docgen.awk | ||
$(MKDIR_P) $(dir $@) | ||
./docgen.sh $@ | ||
|
||
.PHONY: clean | ||
|
||
clean: | ||
find . -name "*.aux" -o -name "*.log" -o -name "*.pdf" -o -name "*~" -o \ | ||
-name "*.gcda" -o -name "*.gcno" -o -name "*.o" | xargs rm || true | ||
$(RM) $(GEN_HEAD) | ||
$(RM) $(GEN_TEX) | ||
$(RM) -r $(BUILD_DIR) | ||
|
||
-include $(DEPS) | ||
|
||
MKDIR_P ?= mkdir -p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# The `fastbril` bytecode interpreter | ||
|
||
This is a bytecode spec/generator/interpreter for `bril`. It aims to | ||
be like the typescript or rust implementation, but faster. | ||
|
||
## To build | ||
|
||
+ binary: `make release` | ||
the binary will be `./build/fastbrili` | ||
+ doc: you need to have LaTeX installed. run `make doc` | ||
the doc will be `./doc/brb.pdf` | ||
there is a prebuilt pdf in case this is difficult | ||
|
||
|
||
|
||
### Features | ||
We support a superset of the behavior provided by `brili`, so options like `-p` | ||
work exactly the same. We also support the following: | ||
- `-b` will read in bytecode instead of the Bril json | ||
- `-bo <file>` will output the bytecode to `<file>` | ||
- `-pr` will print the program to standard out (probably more useful with the | ||
`-b` option) | ||
- `-ni` will NOT run the interpreter. | ||
- `-e <file>` will emit assembly to `<file>`. | ||
|
||
the current only supported assembly is armv8. sorry. | ||
|
||
the compiler to asm is probably the least trustworthy part of this | ||
whole project. The general interpreter should be pretty good, but it | ||
is always possible there are bugs. Please report bugs to | ||
`[email protected]`, and there's a chance that i will fix them :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Instructions are 64bit numbers | ||
1 bit to mark labelled, 15 bits of opcode, 16bits of destination, 16 bits of | ||
arg1, 16 bits of arg2 | ||
|
||
this is modified for other instructions | ||
|
||
Opcodes: | ||
nop: 0 | ||
const: 1 | ||
add: 2 | ||
mul: 3 | ||
sub: 4 | ||
div: 5 | ||
eq: 6 | ||
lt: 7 | ||
gt: 8 | ||
le: 9 | ||
ge: 10 | ||
not: 11 | ||
and: 12 | ||
or: 13 | ||
jmp: 14 | ||
br: 15 | ||
call: 16 | ||
ret: 17 | ||
print: 18 | ||
phi: 19 | ||
alloc: 20 | ||
free: 21 | ||
store: 22 | ||
load: 23 | ||
ptradd: 24 | ||
fadd: 25 | ||
fmul: 26 | ||
fsub: 27 | ||
fdiv: 28 | ||
feq: 29 | ||
flt: 30 | ||
fle: 31 | ||
fgt: 32 | ||
fge: 33 | ||
lconst: 34 | ||
|
||
|
||
types: | ||
bool: 0 | ||
int: 1 | ||
float: 2 | ||
ptr: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CONST 1 | ||
ADD 2 | ||
MUL 3 | ||
SUB 4 | ||
DIV 5 | ||
EQ 6 | ||
LT 7 | ||
GT 8 | ||
LE 9 | ||
GE 10 | ||
NOT 11 | ||
AND 12 | ||
OR 13 | ||
JMP 14 | ||
BR 15 | ||
CALL 16 | ||
RET 17 | ||
PRINT 18 | ||
LCONST 19 | ||
NOP 20 | ||
ID 21 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FADD 28 | ||
FMUL 29 | ||
FSUB 30 | ||
FDIV 31 | ||
FEQ 32 | ||
FLT 33 | ||
FLE 34 | ||
FGT 35 | ||
FGE 36 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALLOC 23 | ||
FREE 24 | ||
STORE 25 | ||
LOAD 26 | ||
PTRADD 27 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PHI 22 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
BRILINT 0 | ||
BRILBOOL 1 | ||
BRILFLOAT 2 | ||
BRILVOID 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.aux | ||
*.out | ||
*.log | ||
base.tex | ||
float.tex | ||
mem.tex | ||
ssa.tex | ||
types.tex | ||
brb.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(TeX-add-style-hook | ||
"main" | ||
(lambda () | ||
(TeX-add-to-alist 'LaTeX-provided-package-options | ||
'(("appendix" "toc" "page") ("geometry" "margin=3cm"))) | ||
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "href") | ||
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperref") | ||
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperimage") | ||
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperbaseurl") | ||
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "nolinkurl") | ||
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "url") | ||
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "path") | ||
(add-to-list 'LaTeX-verbatim-macros-with-delims-local "path") | ||
(TeX-run-style-hooks | ||
"latex2e" | ||
"base" | ||
"ssa" | ||
"mem" | ||
"float" | ||
"types" | ||
"article" | ||
"art10" | ||
"appendix" | ||
"hyperref" | ||
"geometry") | ||
(TeX-add-symbols | ||
"bril" | ||
"Bril" | ||
"refint") | ||
(LaTeX-add-labels | ||
"app:opcodes" | ||
"app:types")) | ||
:latex) | ||
|
Oops, something went wrong.