Compile wires "from, to" list to working C code
Project description
📦 LSC — Logic Scheme to C compiler
Why use LSC?
- You can use this web-based editor to create and export schemes ✏️
- Super-easy to integrate with any other logic schemes editor 🔌
- Results in logic expressions, so C compiler can easily optimize them 🎯
- Supports nesting 📁
Features
- Written in Python 🐍
- Takes JSON logic schemes representations 👀
- Checks JSON representation for errors 🧐
- Requires only wires "from, to" description ➡️
- Works with nested schemes (i.e defined scheme can be used in other schemes in file as element) 📁
- Scheme tests can be provided ✔️
- High full (JSON - C - executable) compilation speed 🚀
Installation
pip install lsc-mentalblood
Usage
python -m lsc [-h] -i INPUT [-t TARGET] -l [LINK ...] -o OUTPUT
arguments:
-i INPUT,--input INPUT-- path to file with target function-t TARGET,--target TARGET-- name of function to compile-l LINK,-link LINK-- paths to (input files) / (directories containing input files) with required functions descriptions-o OUTPUT,-output OUTPUT-- path to output file
Examples
XOR
{
"xor": {
"wires": [
{
"from": "INPUT_2[1]",
"to": "NOT_2[1]"
},
{
"from": "INPUT_1[1]",
"to": "NOT_1[1]"
},
{
"from": "INPUT_1[1]",
"to": "OR_1[1]"
},
{
"from": "INPUT_2[1]",
"to": "OR_1[2]"
},
{
"from": "NOT_1[1]",
"to": "OR_2[1]"
},
{
"from": "NOT_2[1]",
"to": "OR_2[2]"
},
{
"from": "OR_1[1]",
"to": "AND_1[2]"
},
{
"from": "AND_1[1]",
"to": "OUTPUT_1[1]"
},
{
"from": "OR_2[1]",
"to": "AND_1[1]"
}
],
"tests": [
{
"inputs": [
0,
0
],
"outputs": [
0
]
},
{
"inputs": [
1,
1
],
"outputs": [
0
]
},
{
"inputs": [
1,
0
],
"outputs": [
1
]
},
{
"inputs": [
0,
1
],
"outputs": [
1
]
}
]
}
}
command for compile:
python -m lsc --input lib\xor.json --target xor --link lib --output example.c
output code: godbolt 📜
Full bit adder
{
"sum": {
"wires": [
{
"from": "INPUT_1[1]",
"to": "AND_1[1]"
},
{
"from": "INPUT_1[1]",
"to": "AND_2[1]"
},
{
"from": "INPUT_1[1]",
"to": "OR_3_1[1]"
},
{
"from": "INPUT_1[1]",
"to": "AND_3_1[1]"
},
{
"from": "INPUT_2[1]",
"to": "AND_1[2]"
},
{
"from": "INPUT_2[1]",
"to": "AND_3[1]"
},
{
"from": "INPUT_2[1]",
"to": "OR_3_1[2]"
},
{
"from": "INPUT_2[1]",
"to": "AND_3_1[2]"
},
{
"from": "INPUT_3[1]",
"to": "AND_2[2]"
},
{
"from": "INPUT_3[1]",
"to": "AND_3[2]"
},
{
"from": "INPUT_3[1]",
"to": "OR_3_1[3]"
},
{
"from": "INPUT_3[1]",
"to": "AND_3_1[3]"
},
{
"from": "AND_1[1]",
"to": "OR_3_2[1]"
},
{
"from": "AND_2[1]",
"to": "OR_3_2[2]"
},
{
"from": "AND_3[1]",
"to": "OR_3_2[3]"
},
{
"from": "OR_3_2[1]",
"to": "OUTPUT_1[1]"
},
{
"from": "OR_3_2[1]",
"to": "NOT_1[1]"
},
{
"from": "NOT_1[1]",
"to": "AND_4[1]"
},
{
"from": "OR_3_1[1]",
"to": "AND_4[2]"
},
{
"from": "AND_4[1]",
"to": "OR_1[1]"
},
{
"from": "AND_3_1[1]",
"to": "OR_1[2]"
},
{
"from": "OR_1[1]",
"to": "OUTPUT_2[1]"
}
],
"tests": [
{
"inputs": [
0,
0,
0
],
"outputs": [
0,
0
]
},
{
"inputs": [
0,
0,
1
],
"outputs": [
0,
1
]
},
{
"inputs": [
0,
1,
0
],
"outputs": [
0,
1
]
},
{
"inputs": [
1,
0,
0
],
"outputs": [
0,
1
]
},
{
"inputs": [
0,
1,
1
],
"outputs": [
1,
0
]
},
{
"inputs": [
1,
1,
0
],
"outputs": [
1,
0
]
},
{
"inputs": [
1,
0,
1
],
"outputs": [
1,
0
]
},
{
"inputs": [
1,
1,
1
],
"outputs": [
1,
1
]
}
]
}
}
command for compile:
python -m lsc --input lib\sum.json --target sum --link lib --output example.c
output code: godbolt 📜
Full 8bit adder (cascade)
{
"sum_8": {
"wires": [
{
"from": "INPUT_16[1]",
"to": "sum_1[1]"
},
{
"from": "INPUT_8[1]",
"to": "sum_1[2]"
},
{
"from": "INPUT_7[1]",
"to": "sum_2[2]"
},
{
"from": "INPUT_15[1]",
"to": "sum_2[1]"
},
{
"from": "INPUT_17[1]",
"to": "sum_1[3]"
},
{
"from": "sum_1[1]",
"to": "sum_2[3]"
},
{
"from": "INPUT_6[1]",
"to": "sum_3[2]"
},
{
"from": "INPUT_14[1]",
"to": "sum_3[1]"
},
{
"from": "sum_2[1]",
"to": "sum_3[3]"
},
{
"from": "INPUT_5[1]",
"to": "sum_4[2]"
},
{
"from": "sum_3[1]",
"to": "sum_4[3]"
},
{
"from": "INPUT_1[1]",
"to": "sum_8[2]"
},
{
"from": "INPUT_9[1]",
"to": "sum_8[1]"
},
{
"from": "INPUT_2[1]",
"to": "sum_7[2]"
},
{
"from": "INPUT_10[1]",
"to": "sum_7[1]"
},
{
"from": "INPUT_11[1]",
"to": "sum_6[1]"
},
{
"from": "INPUT_3[1]",
"to": "sum_6[2]"
},
{
"from": "INPUT_12[1]",
"to": "sum_5[1]"
},
{
"from": "INPUT_4[1]",
"to": "sum_5[2]"
},
{
"from": "sum_4[1]",
"to": "sum_5[3]"
},
{
"from": "sum_5[1]",
"to": "sum_6[3]"
},
{
"from": "sum_6[1]",
"to": "sum_7[3]"
},
{
"from": "sum_7[1]",
"to": "sum_8[3]"
},
{
"from": "INPUT_13[1]",
"to": "sum_4[1]"
},
{
"from": "sum_8[1]",
"to": "OUTPUT_1[1]"
},
{
"from": "sum_8[2]",
"to": "OUTPUT_2[1]"
},
{
"from": "sum_1[2]",
"to": "OUTPUT_9[1]"
},
{
"from": "sum_2[2]",
"to": "OUTPUT_8[1]"
},
{
"from": "sum_3[2]",
"to": "OUTPUT_7[1]"
},
{
"from": "sum_4[2]",
"to": "OUTPUT_6[1]"
},
{
"from": "sum_5[2]",
"to": "OUTPUT_5[1]"
},
{
"from": "sum_6[2]",
"to": "OUTPUT_4[1]"
},
{
"from": "sum_7[2]",
"to": "OUTPUT_3[1]"
}
],
"tests": [
{
"inputs": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"outputs": [
0,
0,
0,
0,
0,
0,
0,
0,
0
]
},
{
"inputs": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
],
"outputs": [
0,
0,
0,
0,
0,
0,
0,
0,
1
]
},
{
"inputs": [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"outputs": [
0,
0,
0,
0,
0,
0,
0,
0,
1
]
},
{
"inputs": [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
1,
0
],
"outputs": [
0,
0,
0,
0,
0,
0,
0,
1,
0
]
},
{
"inputs": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
],
"outputs": [
0,
0,
0,
0,
0,
0,
0,
1,
0
]
},
{
"inputs": [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"outputs": [
0,
0,
0,
0,
0,
0,
0,
1,
0
]
},
{
"inputs": [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
],
"outputs": [
0,
0,
0,
0,
0,
0,
1,
0,
0
]
}
]
}
}
command for compile:
python -m lsc --input lib\sum_8.json --target sum_8 --link lib --output example.c
output code: godbolt 📜
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lsc-mentalblood-1.0.tar.gz
(9.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lsc-mentalblood-1.0.tar.gz.
File metadata
- Download URL: lsc-mentalblood-1.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6914c2a1f2b1d47de126151195987c5b766a179cba6a34ea8a77b884f68d3099
|
|
| MD5 |
59ca5e4d6a9b4c719a38e35681779a31
|
|
| BLAKE2b-256 |
654fbd090fa06cdacecfa457cdf43d16426ec5e8bee94ffe144f39acc613c3e1
|
File details
Details for the file lsc_mentalblood-1.0-py3-none-any.whl.
File metadata
- Download URL: lsc_mentalblood-1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff0f191e886dc828bf5e2c00587f0d6f8cb5d0fac3cf94443163631c51ea7579
|
|
| MD5 |
e110f8343b254e0e43aeb45d1f7c4227
|
|
| BLAKE2b-256 |
fc4bc584ffdbde1af34390d3b7a70a95adbbce6989f8de31523dd1e85e31c26e
|