summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-10-15 12:23:23 -0700
committerJulian Blake Kongslie2022-10-15 12:26:13 -0700
commitf06ab846e3e297007afe65d9f815afff4638af0d (patch)
tree9e84c022a17afae0c1a292deb9b0ad2c8fa8acec
parentImplement most of the OPR instructions. (diff)
downloadbiggolf-f06ab846e3e297007afe65d9f815afff4638af0d.tar.xz
Automatically discover programs and incorporate into the binary
Diffstat (limited to '')
-rw-r--r--Makefile10
-rw-r--r--main.cpp10
-rw-r--r--programs/programs.h7
-rwxr-xr-xscripts/mkprograms39
4 files changed, 56 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index b6a5e0d..18d889f 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ clean:
33.SECONDARY: 33.SECONDARY:
34.SUFFIXES: 34.SUFFIXES:
35 35
36override SOURCES := $(shell find -\( -name build -prune -\) -o -\( -\( -name \*.bin -o -name \*.cpp -o -name \*.pal -\) -print -\)) 36override SOURCES := $(shell find -\( -name build -prune -\) -o -\( -\( -name \*.bin -o -name \*.cpp -o -name \*.pal -\) -print -\)) $(BUILD)/programs/programs.cpp
37 37
38override OBJECTS := $(addprefix $(BUILD)/, $(addsuffix .o, $(basename $(SOURCES)))) 38override OBJECTS := $(addprefix $(BUILD)/, $(addsuffix .o, $(basename $(SOURCES))))
39override DEPENDS := $(addprefix $(BUILD)/, $(addsuffix .d, $(basename $(SOURCES)))) 39override DEPENDS := $(addprefix $(BUILD)/, $(addsuffix .d, $(basename $(SOURCES))))
@@ -56,6 +56,14 @@ $(BUILD)/%.o: %.cpp
56 @mkdir -p $(dir $@) 56 @mkdir -p $(dir $@)
57 $(CXX) $(CXXFLAGS) $(COMPILE_FLAGS) -c -o $@ $< 57 $(CXX) $(CXXFLAGS) $(COMPILE_FLAGS) -c -o $@ $<
58 58
59$(BUILD)/%.o: $(BUILD)/%.cpp
60 $(CXX) $(CXXFLAGS) $(COMPILE_FLAGS) -c -o $@ $<
61
62$(BUILD)/programs/programs.cpp:
63 @mkdir -p $(dir $@)
64 scripts/mkprograms > $@
65.PHONY: $(BUILD)/programs/programs.cpp
66
59$(BUILD)/minigolf: $(OBJECTS) 67$(BUILD)/minigolf: $(OBJECTS)
60 @mkdir -p $(dir $@) 68 @mkdir -p $(dir $@)
61 $(CXX) $(CXXFLAGS) -o $@ -Wl,--start-group $+ -Wl,--end-group $(LINK_FLAGS) 69 $(CXX) $(CXXFLAGS) -o $@ -Wl,--start-group $+ -Wl,--end-group $(LINK_FLAGS)
diff --git a/main.cpp b/main.cpp
index 63dcb50..28dcbf7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,19 +2,11 @@
2#include <cstdint> 2#include <cstdint>
3#include <fmt/format.h> 3#include <fmt/format.h>
4#include <iostream> 4#include <iostream>
5#include <map>
6#include <optional> 5#include <optional>
7#include <utility> 6#include <utility>
8 7
9#include "isa/checker.h" 8#include "isa/checker.h"
10 9#include "programs/programs.h"
11extern std::uint8_t _binary_count_bin_start[];
12extern std::uint8_t _binary_fib_bin_start[];
13
14static const std::map<std::string, std::uint8_t *> programs = {
15 { "count", _binary_count_bin_start },
16 { "fib", _binary_fib_bin_start },
17};
18 10
19int load_program(checker &checker, const std::uint8_t *program) { 11int load_program(checker &checker, const std::uint8_t *program) {
20 bool seen_non_leader = false; 12 bool seen_non_leader = false;
diff --git a/programs/programs.h b/programs/programs.h
new file mode 100644
index 0000000..dbe14e2
--- /dev/null
+++ b/programs/programs.h
@@ -0,0 +1,7 @@
1#pragma once
2
3#include <cstdint>
4#include <map>
5#include <string>
6
7extern const std::map<std::string, std::uint8_t *> programs;
diff --git a/scripts/mkprograms b/scripts/mkprograms
new file mode 100755
index 0000000..0529e63
--- /dev/null
+++ b/scripts/mkprograms
@@ -0,0 +1,39 @@
1#!/bin/bash
2
3cd programs
4
5cat <<END
6#include <cstdint>
7#include <map>
8#include <string>
9
10#include "programs/programs.h"
11
12extern "C" {
13END
14
15for f in *; do
16 if [[ "$f" == "programs.h" ]]; then
17 continue
18 fi
19 b="${f%.*}"
20 echo " extern std::uint8_t _binary_${b}_bin_start[];"
21done
22
23cat <<END
24}
25
26const std::map<std::string, std::uint8_t *> programs = {
27END
28
29for f in *; do
30 if [[ "$f" == "programs.h" ]]; then
31 continue
32 fi
33 b="${f%.*}"
34 echo " { \"$b\", _binary_${b}_bin_start },"
35done
36
37cat <<END
38};
39END