backburn 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/Makefile +50 -0
  4. data/README.md +520 -0
  5. data/docs/cli-and-outputs.md +226 -0
  6. data/docs/technical-spec.md +656 -0
  7. data/exe/backburn +8 -0
  8. data/ext/backburn/extconf.rb +31 -0
  9. data/ext/backburn/prism/COMMIT +1 -0
  10. data/ext/backburn/prism/LICENSE.md +7 -0
  11. data/ext/backburn/prism/Makefile +213 -0
  12. data/ext/backburn/prism/include/prism/arena.h +45 -0
  13. data/ext/backburn/prism/include/prism/arena.hpp +42 -0
  14. data/ext/backburn/prism/include/prism/ast.h +10395 -0
  15. data/ext/backburn/prism/include/prism/ast.hpp +641 -0
  16. data/ext/backburn/prism/include/prism/buffer.h +60 -0
  17. data/ext/backburn/prism/include/prism/buffer.hpp +55 -0
  18. data/ext/backburn/prism/include/prism/comments.h +72 -0
  19. data/ext/backburn/prism/include/prism/compiler/accel.h +26 -0
  20. data/ext/backburn/prism/include/prism/compiler/align.h +36 -0
  21. data/ext/backburn/prism/include/prism/compiler/assume.h +25 -0
  22. data/ext/backburn/prism/include/prism/compiler/branch.h +26 -0
  23. data/ext/backburn/prism/include/prism/compiler/bswap.h +46 -0
  24. data/ext/backburn/prism/include/prism/compiler/cplusplus.hpp +16 -0
  25. data/ext/backburn/prism/include/prism/compiler/endianness.h +34 -0
  26. data/ext/backburn/prism/include/prism/compiler/exceptions.hpp +17 -0
  27. data/ext/backburn/prism/include/prism/compiler/exported.h +24 -0
  28. data/ext/backburn/prism/include/prism/compiler/fallthrough.h +22 -0
  29. data/ext/backburn/prism/include/prism/compiler/filesystem.h +32 -0
  30. data/ext/backburn/prism/include/prism/compiler/flex_array.h +19 -0
  31. data/ext/backburn/prism/include/prism/compiler/force_inline.h +21 -0
  32. data/ext/backburn/prism/include/prism/compiler/format.h +27 -0
  33. data/ext/backburn/prism/include/prism/compiler/inline.h +17 -0
  34. data/ext/backburn/prism/include/prism/compiler/lifetimebound.hpp +25 -0
  35. data/ext/backburn/prism/include/prism/compiler/nodiscard.h +22 -0
  36. data/ext/backburn/prism/include/prism/compiler/nonnull.h +18 -0
  37. data/ext/backburn/prism/include/prism/compiler/noreturn.h +24 -0
  38. data/ext/backburn/prism/include/prism/compiler/stack.h +60 -0
  39. data/ext/backburn/prism/include/prism/compiler/unused.h +18 -0
  40. data/ext/backburn/prism/include/prism/constant_pool.h +112 -0
  41. data/ext/backburn/prism/include/prism/diagnostic.h +121 -0
  42. data/ext/backburn/prism/include/prism/errors_format.h +63 -0
  43. data/ext/backburn/prism/include/prism/excludes.h +29 -0
  44. data/ext/backburn/prism/include/prism/integer.h +79 -0
  45. data/ext/backburn/prism/include/prism/internal/allocator.h +68 -0
  46. data/ext/backburn/prism/include/prism/internal/allocator_debug.h +88 -0
  47. data/ext/backburn/prism/include/prism/internal/arena.h +223 -0
  48. data/ext/backburn/prism/include/prism/internal/assert.h +14 -0
  49. data/ext/backburn/prism/include/prism/internal/bignum.h +239 -0
  50. data/ext/backburn/prism/include/prism/internal/bit.h +66 -0
  51. data/ext/backburn/prism/include/prism/internal/buffer.h +104 -0
  52. data/ext/backburn/prism/include/prism/internal/char.h +145 -0
  53. data/ext/backburn/prism/include/prism/internal/comments.h +54 -0
  54. data/ext/backburn/prism/include/prism/internal/constant_pool.h +155 -0
  55. data/ext/backburn/prism/include/prism/internal/diagnostic.h +392 -0
  56. data/ext/backburn/prism/include/prism/internal/double.h +19 -0
  57. data/ext/backburn/prism/include/prism/internal/encoding.h +326 -0
  58. data/ext/backburn/prism/include/prism/internal/integer.h +66 -0
  59. data/ext/backburn/prism/include/prism/internal/isinf.h +16 -0
  60. data/ext/backburn/prism/include/prism/internal/line_offset_list.h +50 -0
  61. data/ext/backburn/prism/include/prism/internal/list.h +62 -0
  62. data/ext/backburn/prism/include/prism/internal/magic_comments.h +23 -0
  63. data/ext/backburn/prism/include/prism/internal/memchr.h +15 -0
  64. data/ext/backburn/prism/include/prism/internal/node.h +197 -0
  65. data/ext/backburn/prism/include/prism/internal/oom.h +16 -0
  66. data/ext/backburn/prism/include/prism/internal/options.h +248 -0
  67. data/ext/backburn/prism/include/prism/internal/parser.h +1170 -0
  68. data/ext/backburn/prism/include/prism/internal/regexp.h +70 -0
  69. data/ext/backburn/prism/include/prism/internal/serialize.h +39 -0
  70. data/ext/backburn/prism/include/prism/internal/source.h +72 -0
  71. data/ext/backburn/prism/include/prism/internal/static_literals.h +60 -0
  72. data/ext/backburn/prism/include/prism/internal/stringy.h +37 -0
  73. data/ext/backburn/prism/include/prism/internal/strncasecmp.h +18 -0
  74. data/ext/backburn/prism/include/prism/internal/strpbrk.h +61 -0
  75. data/ext/backburn/prism/include/prism/internal/tokens.h +11 -0
  76. data/ext/backburn/prism/include/prism/internal/xxh3.h +16 -0
  77. data/ext/backburn/prism/include/prism/json.h +40 -0
  78. data/ext/backburn/prism/include/prism/line_offset_list.h +69 -0
  79. data/ext/backburn/prism/include/prism/magic_comments.h +53 -0
  80. data/ext/backburn/prism/include/prism/node.h +139 -0
  81. data/ext/backburn/prism/include/prism/node.hpp +272 -0
  82. data/ext/backburn/prism/include/prism/node_type.hpp +38 -0
  83. data/ext/backburn/prism/include/prism/options.h +393 -0
  84. data/ext/backburn/prism/include/prism/options.hpp +43 -0
  85. data/ext/backburn/prism/include/prism/parser.h +433 -0
  86. data/ext/backburn/prism/include/prism/parser.hpp +274 -0
  87. data/ext/backburn/prism/include/prism/prettyprint.h +39 -0
  88. data/ext/backburn/prism/include/prism/serialize.h +123 -0
  89. data/ext/backburn/prism/include/prism/source.h +163 -0
  90. data/ext/backburn/prism/include/prism/stream.h +36 -0
  91. data/ext/backburn/prism/include/prism/string_query.h +97 -0
  92. data/ext/backburn/prism/include/prism/stringy.h +61 -0
  93. data/ext/backburn/prism/include/prism/stringy.hpp +31 -0
  94. data/ext/backburn/prism/include/prism/version.h +46 -0
  95. data/ext/backburn/prism/include/prism.h +123 -0
  96. data/ext/backburn/prism/include/prism.hpp +24 -0
  97. data/ext/backburn/prism/src/arena.c +200 -0
  98. data/ext/backburn/prism/src/bignum.c +399 -0
  99. data/ext/backburn/prism/src/buffer.c +405 -0
  100. data/ext/backburn/prism/src/char.c +289 -0
  101. data/ext/backburn/prism/src/comments.c +455 -0
  102. data/ext/backburn/prism/src/constant_pool.c +410 -0
  103. data/ext/backburn/prism/src/diagnostic.c +918 -0
  104. data/ext/backburn/prism/src/double.c +394 -0
  105. data/ext/backburn/prism/src/encoding.c +1701 -0
  106. data/ext/backburn/prism/src/errors_format.c +650 -0
  107. data/ext/backburn/prism/src/integer.c +675 -0
  108. data/ext/backburn/prism/src/json.c +5745 -0
  109. data/ext/backburn/prism/src/line_offset_list.c +99 -0
  110. data/ext/backburn/prism/src/list.c +24 -0
  111. data/ext/backburn/prism/src/memchr.c +37 -0
  112. data/ext/backburn/prism/src/node.c +4464 -0
  113. data/ext/backburn/prism/src/options.c +475 -0
  114. data/ext/backburn/prism/src/parser.c +371 -0
  115. data/ext/backburn/prism/src/prettyprint.c +9038 -0
  116. data/ext/backburn/prism/src/prism.c +23615 -0
  117. data/ext/backburn/prism/src/regexp.c +3833 -0
  118. data/ext/backburn/prism/src/serialize.c +2656 -0
  119. data/ext/backburn/prism/src/source.c +525 -0
  120. data/ext/backburn/prism/src/static_literals.c +562 -0
  121. data/ext/backburn/prism/src/string_query.c +195 -0
  122. data/ext/backburn/prism/src/stringy.c +77 -0
  123. data/ext/backburn/prism/src/strncasecmp.c +37 -0
  124. data/ext/backburn/prism/src/strpbrk.c +465 -0
  125. data/ext/backburn/prism/src/tokens.c +724 -0
  126. data/ext/backburn/prism/src/xxh3.c +292 -0
  127. data/lib/backburn/version.rb +7 -0
  128. data/presets/devise.roots +11 -0
  129. data/presets/fast-mcp.roots +5 -0
  130. data/presets/graphql.roots +6 -0
  131. data/presets/phlex.roots +7 -0
  132. data/presets/pundit.roots +3 -0
  133. data/presets/rails-framework.roots +10 -0
  134. data/presets/rails.roots +83 -0
  135. data/presets/sidekiq.roots +4 -0
  136. data/presets/thor.roots +3 -0
  137. data/rails.roots +99 -0
  138. data/scripts/embed-presets.sh +13 -0
  139. data/scripts/version-h.sh +7 -0
  140. data/src/analysis/analysis.c +95 -0
  141. data/src/analysis/analysis.h +24 -0
  142. data/src/analysis/batches.c +127 -0
  143. data/src/analysis/batches.h +17 -0
  144. data/src/analysis/graph.c +238 -0
  145. data/src/analysis/graph.h +34 -0
  146. data/src/analysis/mark.c +300 -0
  147. data/src/analysis/mark.h +21 -0
  148. data/src/analysis/roots.c +229 -0
  149. data/src/analysis/roots.h +29 -0
  150. data/src/cli/cli.c +237 -0
  151. data/src/cli/cli.h +9 -0
  152. data/src/cli/config.c +112 -0
  153. data/src/cli/config.h +14 -0
  154. data/src/cli/options.c +17 -0
  155. data/src/cli/options.h +35 -0
  156. data/src/commands/commands.h +11 -0
  157. data/src/commands/explain.c +255 -0
  158. data/src/commands/gemfile.c +126 -0
  159. data/src/commands/gemfile.h +27 -0
  160. data/src/commands/gems.c +408 -0
  161. data/src/commands/init.c +92 -0
  162. data/src/commands/roots.c +82 -0
  163. data/src/commands/scan.c +91 -0
  164. data/src/core/intern.c +94 -0
  165. data/src/core/intern.h +40 -0
  166. data/src/core/json.c +17 -0
  167. data/src/core/json.h +9 -0
  168. data/src/core/model.c +25 -0
  169. data/src/core/model.h +85 -0
  170. data/src/core/util.c +116 -0
  171. data/src/core/util.h +48 -0
  172. data/src/index/erb.c +40 -0
  173. data/src/index/erb.h +9 -0
  174. data/src/index/haml.c +334 -0
  175. data/src/index/haml.h +10 -0
  176. data/src/index/indexer.c +702 -0
  177. data/src/index/indexer.h +19 -0
  178. data/src/index/walk.c +144 -0
  179. data/src/index/walk.h +14 -0
  180. data/src/main.c +81 -0
  181. data/src/output/baseline.c +101 -0
  182. data/src/output/baseline.h +15 -0
  183. data/src/output/report.c +440 -0
  184. data/src/output/report.h +28 -0
  185. metadata +231 -0
data/exe/backburn ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # RubyGems binstubs `load` this file, so it has to be Ruby. It hands over to the
5
+ # native binary, which the gem installs as libexec/backburn.
6
+ bin = File.expand_path("../libexec/backburn", __dir__)
7
+ abort "backburn: no native binary for #{RUBY_PLATFORM}" unless File.executable?(bin)
8
+ exec [bin, "backburn"], *ARGV
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # `gem install backburn` runs this, then `make clean`, `make` and `make install`
4
+ # in this directory. The Makefile it writes builds the backburn binary with the
5
+ # gem's top-level Makefile, from the Prism sources vendored in ext/backburn/prism,
6
+ # and installs it as libexec/backburn, where exe/backburn runs it. A C compiler
7
+ # and make are the only requirements: no git, no network.
8
+ require "shellwords"
9
+
10
+ root = File.expand_path("../..", __dir__)
11
+ abort "extconf.rb: #{root}/Makefile not found" unless File.exist?(File.join(root, "Makefile"))
12
+ # Quoted for the shell, with `$` doubled for make.
13
+ dir = Shellwords.escape(root).gsub("$", "$$")
14
+
15
+ File.write("Makefile", <<~MAKE)
16
+ ROOT = #{dir}
17
+
18
+ all:
19
+ \t$(MAKE) -C $(ROOT) backburn
20
+
21
+ install: all
22
+ \tmkdir -p $(ROOT)/libexec
23
+ \tmv -f $(ROOT)/backburn $(ROOT)/libexec/backburn
24
+ \t$(MAKE) -C $(ROOT) clean
25
+ \trm -rf $(ROOT)/ext/backburn/prism/build
26
+
27
+ clean:
28
+ \t$(MAKE) -C $(ROOT) clean
29
+
30
+ .PHONY: all install clean
31
+ MAKE
@@ -0,0 +1 @@
1
+ a1d1d96c368d49b752d06e361823a098b54f9a9d
@@ -0,0 +1,7 @@
1
+ Copyright 2022-present, Ruby developers
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,213 @@
1
+
2
+ # V=0 quiet, V=1 verbose. other values don't work.
3
+ V = 0
4
+ V0 = $(V:0=)
5
+ Q1 = $(V:1=)
6
+ Q = $(Q1:0=@)
7
+ ECHO1 = $(V:1=@ :)
8
+ ECHO = $(ECHO1:0=@ echo)
9
+ FUZZ_OUTPUT_DIR = $(CURDIR)/test/fuzz/output
10
+
11
+ SOEXT ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
12
+
13
+ CPPFLAGS := -Iinclude $(CPPFLAGS)
14
+
15
+ # The build variants. Each is on when its variable is set, even to an empty
16
+ # value, in the environment or on the command line. ext/prism/extconf.rb reads
17
+ # the same variables the same way, so one variable selects the same variant of
18
+ # libprism and of the C extension.
19
+ ifneq ($(origin PRISM_BUILD_DEBUG),undefined)
20
+ CPPFLAGS += -DPRISM_BUILD_DEBUG
21
+ endif
22
+ ifneq ($(origin PRISM_BUILD_MINIMAL),undefined)
23
+ CPPFLAGS += -DPRISM_BUILD_MINIMAL
24
+ endif
25
+ ifneq ($(origin PRISM_BUILD_NDEBUG),undefined)
26
+ CPPFLAGS += -DNDEBUG=1
27
+ endif
28
+ ifneq ($(origin PRISM_BUILD_ASAN),undefined)
29
+ CFLAGS += -fsanitize=address -fno-omit-frame-pointer
30
+ endif
31
+ ifneq ($(origin PRISM_BUILD_UBSAN),undefined)
32
+ CFLAGS += -fsanitize=undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer
33
+ endif
34
+
35
+ CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden -Wimplicit-fallthrough $(CFLAGS)
36
+ JAVA_WASM_CFLAGS := -g0 -O2 -Oz -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fno-sanitize=all -fno-stack-protector -fPIC -fvisibility=hidden -Wimplicit-fallthrough $(JAVA_WASM_CFLAGS)
37
+ CC ?= cc
38
+ AR ?= ar
39
+ ARFLAGS ?= -r$(V0:1=v)
40
+ WASI_SDK_PATH := /opt/wasi-sdk
41
+
42
+ # Exporting a symbol makes it a GC root, so the JavaScript module exports only
43
+ # the symbols javascript/src/parsePrism.js calls. That lets --gc-sections drop
44
+ # the rest of the C API along with the wasi-libc code reachable from it.
45
+ WASM_EXPORTS := -Wl,--export=malloc,--export=free,--export=pm_buffer_new,--export=pm_buffer_value,--export=pm_buffer_length,--export=pm_buffer_free,--export=pm_serialize_parse
46
+
47
+ # Bind the library's own references to its own definitions at link time, so
48
+ # that the functions exported for FFI cannot be interposed by another copy of
49
+ # libprism loaded in the same process (for example the copy built into the
50
+ # interpreter next to the one built by a prism gem, when either copy was loaded
51
+ # with RTLD_GLOBAL). Mach-O and PE do this by default; only ELF needs the flag.
52
+ ifeq ($(SOEXT),so)
53
+ SHARED_LDFLAGS := -Wl,-Bsymbolic
54
+ endif
55
+
56
+ MAKEDIRS ?= mkdir -p
57
+ RMALL ?= rm -f -r
58
+
59
+ HEADERS := $(wildcard include/*.h include/*/*.h include/*/*/*.h)
60
+ SOURCES := $(wildcard src/*.c src/*/*.c)
61
+ SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
62
+ STATIC_OBJECTS := $(subst src/,build/static/,$(SOURCES:.c=.o))
63
+
64
+ # The objects depend on the flags they are compiled with as well as on their
65
+ # sources. Make only compares timestamps, so build/.flags records the flags and
66
+ # is rewritten whenever they differ from what it holds. Its timestamp then moves
67
+ # only when the flags change, which makes the objects out of date exactly then.
68
+ # Target-specific flags, such as those of `minimal`, reach it as a prerequisite.
69
+ # In the same way, build/.sources records the list of sources, so that the
70
+ # libraries are linked again when a source is removed.
71
+ #
72
+ # Separate stamps track shared-library linker flags and the archive command,
73
+ # so changing those settings rebuilds only the affected library, not its objects.
74
+ # Each Wasm target also tracks its own flags and the shared source list.
75
+ #
76
+ # Some makes compare timestamps to the second, such as the GNU Make 3.81 that
77
+ # ships with macOS. A stamp written in the same second as the last objects of
78
+ # the previous build would not be newer than them, so a changed stamp is written
79
+ # a second after it is found to differ.
80
+ BUILD_FLAGS = $(CC) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(OPTFLAGS)
81
+ WASM_BUILD_FLAGS = $(WASI_SDK_PATH) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(WASM_EXPORTS)
82
+ JAVA_WASM_BUILD_FLAGS = $(WASI_SDK_PATH) $(DEBUG_FLAGS) $(CPPFLAGS) $(JAVA_WASM_CFLAGS)
83
+
84
+ all: shared static
85
+
86
+ shared: build/libprism.$(SOEXT)
87
+ static: build/libprism.a
88
+ wasm: javascript/src/prism.wasm
89
+ java-wasm: java/wasm/src/main/wasm/prism.wasm
90
+ playground: doc/playground
91
+
92
+ build/.flags: FORCE
93
+ $(Q) $(MAKEDIRS) $(@D)
94
+ $(Q) printf '%s\n' '$(BUILD_FLAGS)' | cmp -s - $@ || { sleep 1; printf '%s\n' '$(BUILD_FLAGS)' > $@; }
95
+
96
+ build/.sources: FORCE
97
+ $(Q) $(MAKEDIRS) $(@D)
98
+ $(Q) printf '%s\n' '$(SOURCES)' | cmp -s - $@ || { sleep 1; printf '%s\n' '$(SOURCES)' > $@; }
99
+
100
+ build/.ldflags: FORCE
101
+ $(Q) $(MAKEDIRS) $(@D)
102
+ $(Q) printf '%s\n' '$(SHARED_LDFLAGS)' | cmp -s - $@ || { sleep 1; printf '%s\n' '$(SHARED_LDFLAGS)' > $@; }
103
+
104
+ build/.arflags: FORCE
105
+ $(Q) $(MAKEDIRS) $(@D)
106
+ $(Q) printf '%s\n' '$(AR) $(ARFLAGS)' | cmp -s - $@ || { sleep 1; printf '%s\n' '$(AR) $(ARFLAGS)' > $@; }
107
+
108
+ build/.wasm.flags: FORCE
109
+ $(Q) $(MAKEDIRS) $(@D)
110
+ $(Q) printf '%s\n' '$(WASM_BUILD_FLAGS)' | cmp -s - $@ || { sleep 1; printf '%s\n' '$(WASM_BUILD_FLAGS)' > $@; }
111
+
112
+ build/.java-wasm.flags: FORCE
113
+ $(Q) $(MAKEDIRS) $(@D)
114
+ $(Q) printf '%s\n' '$(JAVA_WASM_BUILD_FLAGS)' | cmp -s - $@ || { sleep 1; printf '%s\n' '$(JAVA_WASM_BUILD_FLAGS)' > $@; }
115
+
116
+ build/libprism.$(SOEXT): $(SHARED_OBJECTS) build/.flags build/.sources build/.ldflags
117
+ $(ECHO) "linking $@ with $(CC)"
118
+ $(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) $(OPTFLAGS) -shared $(SHARED_LDFLAGS) -o $@ $(SHARED_OBJECTS)
119
+
120
+ # `ar -r` only adds and replaces members, so the archive is created afresh to
121
+ # hold exactly the current objects.
122
+ build/libprism.a: $(STATIC_OBJECTS) build/.flags build/.sources build/.arflags
123
+ $(ECHO) "building $@ with $(AR)"
124
+ $(Q) $(RMALL) $@
125
+ $(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS)
126
+
127
+ javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS) build/.sources build/.wasm.flags
128
+ $(ECHO) "building $@"
129
+ $(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ \
130
+ $(DEBUG_FLAGS) \
131
+ -DPRISM_EXPORT_SYMBOLS -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXCLUDE_JSON \
132
+ -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) \
133
+ $(WASM_EXPORTS) -Wl,--gc-sections -Wl,--strip-all -Wl,--lto-O3 -Wl,--no-entry -mexec-model=reactor \
134
+ -Oz -g0 -flto -fdata-sections -ffunction-sections \
135
+ -o $@ $(SOURCES)
136
+
137
+ # The playground parses with the JavaScript package built from this checkout, so
138
+ # the page is served the parser the rest of the site was generated from. The
139
+ # JavaScript half of the package is generated by `rake templates`.
140
+ doc/playground: javascript/src/prism.wasm
141
+ $(ECHO) "building $@"
142
+ $(Q) $(MAKEDIRS) $@
143
+ $(Q) cp javascript/src/*.js javascript/src/prism.wasm javascript/package.json $@
144
+
145
+ java/wasm/src/main/wasm/prism.wasm: Makefile $(SOURCES) $(HEADERS) build/.sources build/.java-wasm.flags
146
+ $(ECHO) "building $@"
147
+ $(Q) $(MAKEDIRS) $(@D)
148
+ $(Q) $(WASI_SDK_PATH)/bin/clang \
149
+ $(DEBUG_FLAGS) \
150
+ -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN \
151
+ -lwasi-emulated-mman $(CPPFLAGS) $(JAVA_WASM_CFLAGS) \
152
+ -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -lc++ -lc++abi \
153
+ -o $@ $(SOURCES)
154
+
155
+ build/shared/%.o: src/%.c Makefile $(HEADERS) build/.flags
156
+ $(ECHO) "compiling $@"
157
+ $(Q) $(MAKEDIRS) $(@D)
158
+ $(Q) $(CC) $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS $(CPPFLAGS) $(CFLAGS) $(OPTFLAGS) -c -o $@ $<
159
+
160
+ build/static/%.o: src/%.c Makefile $(HEADERS) build/.flags
161
+ $(ECHO) "compiling $@"
162
+ $(Q) $(MAKEDIRS) $(@D)
163
+ $(Q) $(CC) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(OPTFLAGS) -c -o $@ $<
164
+
165
+ build/fuzz.%: $(SOURCES) test/fuzz/%.c test/fuzz/fuzz.c
166
+ $(ECHO) "building $* fuzzer"
167
+ $(Q) $(MAKEDIRS) $(@D)
168
+ $(ECHO) "building main fuzz binary"
169
+ $(Q) afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@ $^
170
+ $(ECHO) "building cmplog binary"
171
+ $(Q) AFL_LLVM_CMPLOG=1 afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@.cmplog $^
172
+
173
+ build/fuzz.heisenbug.%: $(SOURCES) test/fuzz/%.c test/fuzz/heisenbug.c
174
+ $(Q) afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@ $^
175
+
176
+ fuzz-debug:
177
+ $(ECHO) "entering debug shell"
178
+ $(Q) docker run -it --rm -e HISTFILE=/prism/test/fuzz/output/.bash_history -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz
179
+
180
+ fuzz-docker-build: test/fuzz/docker/Dockerfile
181
+ $(ECHO) "building docker image"
182
+ $(Q) docker build -t prism/fuzz test/fuzz/docker/
183
+
184
+ fuzz-run-%: FORCE fuzz-docker-build
185
+ $(ECHO) "generating templates"
186
+ $(Q) bundle exec rake templates
187
+ $(ECHO) "running $* fuzzer"
188
+ $(Q) docker run --rm -v $(CURDIR):/prism prism/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
189
+ $(ECHO) "starting AFL++ run"
190
+ $(Q) $(MAKEDIRS) $(FUZZ_OUTPUT_DIR)/$*
191
+ $(Q) docker run -it --rm -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz /bin/bash -c "./test/fuzz/$*.sh /fuzz_output/$*"
192
+ FORCE:
193
+
194
+ fuzz-clean:
195
+ $(Q) $(RMALL) test/fuzz/output
196
+
197
+ clean:
198
+ $(Q) $(RMALL) build
199
+
200
+ .PHONY: clean doc/playground fuzz-clean
201
+
202
+ all-no-debug: DEBUG_FLAGS := -DNDEBUG=1
203
+ all-no-debug: OPTFLAGS := -O3
204
+ all-no-debug: all
205
+
206
+ minimal: CFLAGS := $(CFLAGS) -DPRISM_BUILD_MINIMAL
207
+ minimal: all
208
+
209
+ run: Makefile $(STATIC_OBJECTS) $(HEADERS) test.c
210
+ $(ECHO) "compiling test.c"
211
+ $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) $(STATIC_OBJECTS) test.c
212
+ $(ECHO) "running test.c"
213
+ $(Q) ./a.out
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @file arena.h
3
+ *
4
+ * A bump allocator for the prism parser.
5
+ */
6
+ #ifndef PRISM_ARENA_H
7
+ #define PRISM_ARENA_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nodiscard.h"
11
+ #include "prism/compiler/nonnull.h"
12
+
13
+ #include <stddef.h>
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
19
+ /**
20
+ * An opaque pointer to an arena that is used for allocations.
21
+ */
22
+ typedef struct pm_arena_t pm_arena_t;
23
+
24
+ /**
25
+ * Returns a newly allocated and initialized arena. If the arena cannot be
26
+ * allocated, this function aborts the process.
27
+ *
28
+ * @returns A pointer to the newly allocated arena. It is the responsibility of
29
+ * the caller to free the arena using pm_arena_free when it is no longer
30
+ * needed.
31
+ */
32
+ PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_arena_t * pm_arena_new(void);
33
+
34
+ /**
35
+ * Frees both the held memory and the arena itself.
36
+ *
37
+ * @param arena The arena to free.
38
+ */
39
+ PRISM_EXPORTED_FUNCTION void pm_arena_free(pm_arena_t *arena) PRISM_NONNULL(1);
40
+
41
+ #ifdef __cplusplus
42
+ }
43
+ #endif
44
+
45
+ #endif
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @file arena.hpp
3
+ *
4
+ * Ownership of arenas from C++.
5
+ */
6
+ #ifndef PRISM_ARENA_HPP
7
+ #define PRISM_ARENA_HPP
8
+
9
+ #include "prism/compiler/cplusplus.hpp"
10
+
11
+ #include "prism/arena.h"
12
+
13
+ #include <memory>
14
+
15
+ namespace prism {
16
+
17
+ /** Frees an arena with pm_arena_free. */
18
+ struct arena_deleter {
19
+ /**
20
+ * Frees the given arena.
21
+ *
22
+ * @param arena The arena to free.
23
+ */
24
+ void operator()(pm_arena_t *arena) const noexcept { pm_arena_free(arena); }
25
+ };
26
+
27
+ /** An owned arena. */
28
+ using unique_arena = std::unique_ptr<pm_arena_t, arena_deleter>;
29
+
30
+ /**
31
+ * Allocate a new arena. Allocation failure aborts, so this never throws.
32
+ *
33
+ * @return A unique_arena managing the newly allocated arena.
34
+ */
35
+ [[nodiscard]] inline unique_arena
36
+ make_arena() noexcept {
37
+ return unique_arena(pm_arena_new());
38
+ }
39
+
40
+ }
41
+
42
+ #endif