Skip to content

Commit e7318b5

Browse files
committed
Initial commit
0 parents  commit e7318b5

13 files changed

Lines changed: 938 additions & 0 deletions

File tree

.github/workflows/docs.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Deploy Docs
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-docs:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- uses: actions/setup-python@v5
19+
- name: Install dependencies
20+
run: |
21+
sudo apt-get install -y doxygen graphviz
22+
pip install sphinx breathe furo
23+
24+
- name: Build documentation
25+
working-directory: ./docs
26+
run: |
27+
sphinx-build -b html . _build
28+
29+
- name: Deploy to GitHub Pages
30+
uses: peaceiris/actions-gh-pages@v3
31+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
32+
with:
33+
publish_branch: gh-pages
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
publish_dir: ./docs/_build
36+
force_orphan: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(gate LANGUAGES C)
3+
4+
set(CMAKE_C_STANDARD 17)
5+
set(CMAKE_C_STANDARD_REQUIRED ON)
6+
set(CMAKE_C_EXTENSIONS ON)
7+
8+
include_directories(${PROJECT_SOURCE_DIR})
9+
10+
add_compile_options(
11+
-Wall
12+
-Wextra
13+
-Wno-implicit-fallthrough
14+
-fPIC
15+
)
16+
17+
if (CMAKE_BUILD_TYPE STREQUAL "Release")
18+
add_compile_options(-march=native -O3)
19+
else ()
20+
add_compile_options(-O2)
21+
endif()
22+
23+
add_library(gate SHARED src/gate.c src/vector.c src/gate.h src/vector.h)
24+
25+
add_executable(example example.c)
26+
target_link_libraries(example PRIVATE gate)

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Logic gates library
2+
3+
## Overview
4+
5+
A fast and space-efficient library for handling combinational Boolean circuits composed of the following types of gates:
6+
- NAND, AND, OR, NOR, XOR, XNOR
7+
8+
9+
## Gate implementation details
10+
11+
- A gate has a non-negative integer number of fan-ins (inputs) and one fan-out (output).
12+
- A gate with no fan-ins always outputs a signal with the value false.
13+
- For a positive n, the fan-ins of an n-input gate are numbered from 0 to n - 1.
14+
- A Boolean signal with values false or true can be supplied to the fan-ins of a gate.
15+
- The fan-out signal from a gate can be connected to multiple fan-ins of other gates.
16+
- Each fan-in of a gate can have only one signal source connected to it.
17+
18+
## API Reference
19+
20+
You can find the API reference for this library at the following link: [API Reference](link).
21+
22+
## Building and Running
23+
24+
### Prerequisites:
25+
To build and use this library, you need:
26+
27+
- CMake version 3.12 or higher.
28+
- A supported compiler, such as GCC or Clang, with support for the C17 standard.
29+
30+
### Compilation
31+
32+
1. Download or clone the repository.
33+
34+
2. Build the library and example program by executing the following commands in the root of the repository:
35+
36+
```bash
37+
cmake -B build/
38+
make -C build/
39+
```
40+
41+
This will create two binaries in `build/` directory:
42+
- `libgate.so` - the shared library file.
43+
- `example` - an example program demonstrating the usage of the library.
44+
45+
You can now link `libgate.so` to your own program.
46+
47+
#### Release Build
48+
For potentially better performance, build in Release mode to enable `-O3` and `-march=native`:
49+
```bash
50+
cmake -B build/ -DCMAKE_BUILD_TYPE=Release
51+
make -C build/
52+
```
53+
54+
55+
### Example
56+
For demonstration purposes, you can refer to and modify the `example.c` file. It showcases a sample usage of this library.
57+
58+
Gate from `example.c`:
59+
60+
![image info](./example_gate.svg)
61+
62+
63+
## License
64+
65+
This project is licensed under the **GNU General Public License v3.0**.
66+
See [LICENSE](LICENSE.md) for the full terms.

docs/Doxyfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
INPUT = ../src/gate.c ../src/gate.h ../src/vector.c ../src/vector.h
2+
OUTPUT_DIRECTORY = doxygen
3+
GENERATE_XML = YES
4+
PROJECT_NAME = "Logic gates library"
5+
PROJECT_BRIEF = "Logic gates library"

docs/conf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from datetime import datetime
2+
from subprocess import call
3+
4+
extensions = ["breathe"]
5+
html_theme = "furo"
6+
html_title = "Logic gates library"
7+
8+
call("doxygen", shell=True)
9+
10+
breathe_projects = {"Logic gates library": "doxygen/xml"}
11+
breathe_default_project = "Logic gates library"
12+
13+
copyright = f'{datetime.now().year} Iteron-dev. Licensed under the GNU GPLv3.'

docs/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
API Reference
2+
=============
3+
.. note::
4+
The full README is available on `GitHub <https://github.com/iteron-dev/logic-gates-library/blob/main/README.md>`_.
5+
6+
.. doxygenfile:: src/gate.h
7+
:project: Logic gates library

example.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifdef NDEBUG
2+
#undef NDEBUG
3+
#endif
4+
5+
#include "src/gate.h"
6+
#include <assert.h>
7+
#include <stdbool.h>
8+
9+
static int example(void) {
10+
gate_t *g0 = gate_new(AND, 2);
11+
gate_t *g1 = gate_new(NAND, 2);
12+
gate_t *g2 = gate_new(NAND, 2);
13+
14+
bool b0 = 0;
15+
bool b1 = 1;
16+
bool b = 1;
17+
18+
gate_connect_gate(g1, g0, 0);
19+
gate_connect_gate(g2, g0, 1);
20+
21+
gate_connect_signal(&b0, g1, 0);
22+
gate_connect_signal(&b0, g1, 1);
23+
gate_connect_signal(&b0, g2, 0);
24+
gate_connect_signal(&b1, g2, 1);
25+
26+
27+
assert(gate_evaluate(&g0, &b, 1) == 2);
28+
assert(b == 1);
29+
30+
gate_t *g4 = gate_new(XNOR, 2);
31+
gate_connect_gate(g1, g4, 0);
32+
gate_connect_gate(g0, g4, 1);
33+
assert(gate_evaluate(&g4, &b, 1) == 3);
34+
assert(b == 1);
35+
36+
gate_delete(g0);
37+
gate_delete(g1);
38+
gate_delete(g2);
39+
40+
return 0;
41+
}
42+
43+
int main(void) {
44+
return example();
45+
}

example_gate.svg

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)