Skip to main content

Compile wires "from, to" list to working C code

Project description

📦 LSC — Logic Scheme to C compiler

forthebadge

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

Also you can run

python -m lsc --help

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


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.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lsc_mentalblood-1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file lsc-mentalblood-1.1.tar.gz.

File metadata

  • Download URL: lsc-mentalblood-1.1.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

Hashes for lsc-mentalblood-1.1.tar.gz
Algorithm Hash digest
SHA256 c1580075ea011ab181f325b66843778319ce1c041b1b0c07f20ca4879a830ed9
MD5 19dd273c02e062e1bd5b3feea599af80
BLAKE2b-256 f29b264f747d1744667b5e1b93ab46cea235d16656942ab86013d1eddcc0addb

See more details on using hashes here.

File details

Details for the file lsc_mentalblood-1.1-py3-none-any.whl.

File metadata

  • Download URL: lsc_mentalblood-1.1-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

Hashes for lsc_mentalblood-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb8f5e993fe0bc3142065460f3f4317697fd6b7058f52e8d3c54d275f85ba03d
MD5 7f50e15ec912d088deb786396fa25769
BLAKE2b-256 67e1dfb645c38cc324d01c655b3529ffe9f46b4ad3923942bad8b0bd4a320724

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page