Skip to content

Commit 5add860

Browse files
jtpaaschphilzook58
authored andcommitted
Adding vibes-tools scaffolding
1 parent e447b5a commit 5add860

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+8490
-0
lines changed

vibes-tools/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
_build
2+
*~
3+
*.swp
4+
.DS_Store

vibes-tools/Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
TOOLS_SRC := tools
2+
VIBES_PLAYGROUND := vibes-playground
3+
VIBES_PARSE := vibes-parse
4+
VIBES_OPT := vibes-opt
5+
6+
7+
###################################
8+
# DEFAULT
9+
###################################
10+
11+
.DEFAULT_GOAL := all
12+
13+
14+
###################################
15+
# ALL
16+
###################################
17+
18+
all:
19+
$(MAKE) $(VIBES_PLAYGROUND)
20+
$(MAKE) $(VIBES_PARSE)
21+
$(MAKE) $(VIBES_OPT)
22+
23+
.PHONY: clean
24+
clean:
25+
$(MAKE) clean.$(VIBES_PLAYGROUND)
26+
$(MAKE) clean.$(VIBES_PARSE)
27+
$(MAKE) clean.$(VIBES_OPT)
28+
29+
build:
30+
$(MAKE) build.$(VIBES_PLAYGROUND)
31+
$(MAKE) build.$(VIBES_PARSE)
32+
$(MAKE) build.$(VIBES_OPT)
33+
34+
install:
35+
$(MAKE) install.$(VIBES_PLAYGROUND)
36+
$(MAKE) install.$(VIBES_PARSE)
37+
$(MAKE) install.$(VIBES_OPT)
38+
39+
uninstall:
40+
$(MAKE) uninstall.$(VIBES_PLAYGROUND)
41+
$(MAKE) uninstall.$(VIBES_PARSE)
42+
$(MAKE) uninstall.$(VIBES_OPT)
43+
44+
45+
###################################
46+
# vibes-playground
47+
###################################
48+
49+
.PHONY: clean.$(VIBES_PLAYGROUND)
50+
clean.$(VIBES_PLAYGROUND):
51+
$(MAKE) clean -C $(TOOLS_SRC)/$(VIBES_PLAYGROUND)
52+
53+
build.$(VIBES_PLAYGROUND):
54+
$(MAKE) build -C $(TOOLS_SRC)/$(VIBES_PLAYGROUND)
55+
56+
install.$(VIBES_PLAYGROUND):
57+
$(MAKE) install -C $(TOOLS_SRC)/$(VIBES_PLAYGROUND)
58+
59+
uninstall.$(VIBES_PLAYGROUND):
60+
$(MAKE) uninstall -C $(TOOLS_SRC)/$(VIBES_PLAYGROUND)
61+
62+
$(VIBES_PLAYGROUND):
63+
$(MAKE) clean.$(VIBES_PLAYGROUND)
64+
$(MAKE) build.$(VIBES_PLAYGROUND)
65+
$(MAKE) install.$(VIBES_PLAYGROUND)
66+
67+
68+
###################################
69+
# vibes-parse
70+
###################################
71+
72+
.PHONY: clean.$(VIBES_PARSE)
73+
clean.$(VIBES_PARSE):
74+
$(MAKE) clean -C $(TOOLS_SRC)/$(VIBES_PARSE)
75+
76+
build.$(VIBES_PARSE):
77+
$(MAKE) build -C $(TOOLS_SRC)/$(VIBES_PARSE)
78+
79+
install.$(VIBES_PARSE):
80+
$(MAKE) install -C $(TOOLS_SRC)/$(VIBES_PARSE)
81+
82+
uninstall.$(VIBES_PARSE):
83+
$(MAKE) uninstall -C $(TOOLS_SRC)/$(VIBES_PARSE)
84+
85+
$(VIBES_PARSE):
86+
$(MAKE) clean.$(VIBES_PARSE)
87+
$(MAKE) build.$(VIBES_PARSE)
88+
$(MAKE) install.$(VIBES_PARSE)
89+
90+
91+
###################################
92+
# vibes-opt
93+
###################################
94+
95+
.PHONY: clean.$(VIBES_OPT)
96+
clean.$(VIBES_OPT):
97+
$(MAKE) clean -C $(TOOLS_SRC)/$(VIBES_OPT)
98+
99+
build.$(VIBES_OPT):
100+
$(MAKE) build -C $(TOOLS_SRC)/$(VIBES_OPT)
101+
102+
install.$(VIBES_OPT):
103+
$(MAKE) install -C $(TOOLS_SRC)/$(VIBES_OPT)
104+
105+
uninstall.$(VIBES_OPT):
106+
$(MAKE) uninstall -C $(TOOLS_SRC)/$(VIBES_OPT)
107+
108+
$(VIBES_OPT):
109+
$(MAKE) clean.$(VIBES_OPT)
110+
$(MAKE) build.$(VIBES_OPT)
111+
$(MAKE) install.$(VIBES_OPT)
112+

vibes-tools/README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# The VIBES Tool Suite
2+
3+
A suite of tools for the VIBES project.
4+
5+
6+
## The Tools
7+
8+
In progress. So far, the tools that are under development are these:
9+
10+
* `vibes-parse` ([README.md](tools/vibes-parse)) - Takes a `patch.c` file (containing C code), and produces a `patch.bir` file (containing serialized BAP IR).
11+
* `vibes-opt` ([README.md](tools/vibes-opt)) - Takes a `patch.bir` file, and produces a `patch.bir.opt` file (containing optimized BAP IR).
12+
13+
14+
## Building/Installing everything
15+
16+
To build and install the entire suite:
17+
18+
```
19+
make
20+
```
21+
22+
Check that all tools are installed:
23+
24+
```
25+
vibes-parse --help
26+
vibes-opt --help
27+
```
28+
29+
or:
30+
31+
```
32+
vibes-parse --version
33+
vibes-opt --version
34+
```
35+
36+
To just build the suite:
37+
38+
```
39+
make build
40+
```
41+
42+
To install the suite:
43+
44+
```
45+
make install
46+
```
47+
48+
To uninstall and clean:
49+
50+
```
51+
make uninstall
52+
make clean
53+
```
54+
55+
56+
## Building/installing one tool
57+
58+
To build, install, uninstall, or clean a single tool, use `make tool-name`, e.g.:
59+
60+
```
61+
make vibes-parse
62+
```
63+
64+
To build, install, uninstall, or clean the tool, append `.tool-name` to the `build`, `install`, `uninstall`, and `clean` targets. E.g.,
65+
66+
```
67+
make build.vibes-parse
68+
make install.vibes-parse
69+
make uninstall.vibes-parse
70+
make clean.vibes-parse
71+
```
72+
73+
74+
## Toy/sample CLI
75+
76+
There is a toy/dummy command line tool that can be used a a playground or as a template for your own tool.
77+
78+
It lives here:
79+
80+
* [tools/vibes-playground](tools/vibes-playground)
81+
82+
To use it, go to [tools/vibes-playground/bin/main.ml#L21](tools/vibes-playground/bin/main.ml#L21) and start modifying/playing. Then build/install:
83+
84+
```
85+
make vibes-playground
86+
```
87+
88+
And try it out from the command line:
89+
90+
```
91+
vibes-playground --help
92+
vibes-playground
93+
```
94+
95+
96+
## Tool scaffolding
97+
98+
The repo root of this tool suite currently lives at [VIBES-internal/experiments/vibes-tools](https://github.com/draperlaboratory/VIBES-internal/tree/main/experiments/vibes-tools).
99+
100+
The tool suite is then contained in the [tools/](tools/) subdirectory, where each tool has its own folder, like this:
101+
102+
```
103+
|-- <repo root>/
104+
|
105+
|-- "README.md" (top level README)
106+
|-- "Makefile" (top level makefile)
107+
|-- ...
108+
|-- "tools/"
109+
|
110+
|-- ...
111+
|-- "vibes-parse/" (folder containing the vibes-parse tool)
112+
|-- "vibes-opt/" (folder containing the vibes-opt tool)
113+
|-- "vibes-log/" (folder containing a shared logging library)
114+
|-- "vibes-error/" (folder containing a shared error handling library)
115+
|-- ...
116+
```
117+
118+
Some tools are command line tools. Other tools are just libraries that can be used by other tools. Each tool has a similar scaffolding. It's folder contains:
119+
120+
* A `README.md` describing the tool/library and how to build/install it
121+
* A `Makefile` for building the tool
122+
* A possible `lib` folder, containing local library files just for this tool
123+
* A possible `bin` folder, containing files that define the CLI just for this tool
124+
125+
For instance, consider a command line tool called `vibes-foo`. It would live in its own folder called `vibes-foo/`, which would look like this:
126+
127+
```
128+
|-- <repo root>/
129+
|
130+
|-- ...
131+
|-- "tools/"
132+
|
133+
|-- "vibes-foo/"
134+
|
135+
|-- "README.md"
136+
|-- "Makefile"
137+
|-- "lib/"
138+
| |
139+
| |-- "dune" (defines "vibes_foo_lib", a non-public library)
140+
| |-- "runner.ml" (contains a "run" method, to run the library)
141+
| |-- "types.ml" (contains type definitions for this library)
142+
| |-- "module_a.ml"
143+
| |-- "module_b.ml"
144+
| |-- ...
145+
|-- "bin/"
146+
|
147+
|-- "dune" (defines a "main.exe" executable)
148+
|-- "main.ml" (defines the Cmdliner CLI)
149+
```
150+
151+
Note that a non-public library is defined in the `lib/` folder. Regarding this `lib/` folder, note the following:
152+
153+
* These 'lib/' files make up a library that is not public (no `.opam` file). It is not meant to be installed separately as an opam package. Rather, it is just a library to be used locally by the tool `vibes-foo`.
154+
* Although this local library does not need an `.opam` file, it does need a `dune` file. In that file, we name this local library `vibes_foo_lib`. The convention is to append `_lib` to the end of the tool name (hence, if the tool were called `vibes-bar`, then this library would be named `vibes_bar_lib`).
155+
* If the library can be "run" (as an application), then there should be a `Runner` module that contains a `run` function, so that a CLI frontend can directly "run" it by calling `Vibes_foo_lib.Runner.run`.
156+
* If the library uses any shared types, they should be declared in a `types.ml` module.
157+
158+
Note that a `main.exe` executable is defined in the `bin/` folder. Regarding this `bin/` folder, note the following:
159+
160+
* The `bin/` folder is for housing the binary executable `vibes-foo` (a command line tool).
161+
* The CLI should be defined (using `Cmdliner`) in a file called `main.ml`.
162+
* There should be a `dune` file, defining the executable as `main.exe`.
163+
* The `install` target in `<repo root>/tools/vibes-foo/Makefile` should take the built executable `main.exe`, and install it on your system at `${OPAM_SWITCH_PREFIX}/bin`, under the name `vibes-foo`. That way, once the user has installed the tool, they can find the tool by the name `vibes-foo`.
164+
165+
If a tool is just a library meant to be used by other tools (hence it has no CLI frontend of its own), then it should not have a `bin/` folder. Conversely, if a tool is just a CLI frontend that relies entirely on other shared libraries, then it need not have a `lib/` folder.
166+
167+
Other conventions:
168+
169+
* Functionality shared by more than one tool should be moved into its own library.
170+
* Other tools can import shared libraries by listing them in the `libraries` stanza of their local `dune` files.
171+
* The `<repo root>/tools/vibes-log` library provides a common logger that other tools should use for logging. Messages can be sent from any application by invoking the `Vibes_log.Stream.send` function.
172+
* The `<repo root>/tools/vibes-error` library provides a common error type that other tools should use. The type is extensible, so every tool can add its own custom errors and custom error printers. Such custom errors and printers should be declared in the tools `lib/types.ml` module. In general, any public function from a library should return a `(_, Vibes_error.Std.t) result` type. That way, consumers (i.e., CLI frontends) can automatically handle errors and print them out for the user with an appropriate exit code.
173+
* The `<repo root>/tools/vibes-common-cli-options` library provides various command line options that multiple tools share. For instance, it provides verbosity options that other tools can import into their own CLI.
174+
* The `<repo root>/tools/vibes-constants` library provides constant values that other applications can use. For instance, it specifies the version numbers for the various command line tools. Those CLIs simply import their version number from this `vibes-constants` library.
175+
176+
When in doubt about a convention, look at some of the tools (e.g., `vibes-parse` or `vibes-opt`) and copy what you see there.

vibes-tools/dune-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 3.0)

vibes-tools/resources/empty_patch.c

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let () =
2+
let foo x = x * x in
3+
print_endline "Hello world"

vibes-tools/resources/patch.bir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(%00000009 block(data((%00000005 set(var x)(int 3:32u))))(ctrl()))

vibes-tools/resources/patch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int x;
2+
x = 3;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# vibes-c-toolkit
2+
3+
A library of utilities for working with C code.
4+
5+
6+
## Building and installing
7+
8+
This library cannot be built and installed on its own. It is a private library that is automatically built and included in other tools when they are built.

0 commit comments

Comments
 (0)