B2Program
This is the code generator B2Program for generating code from B to other programming languages.
A subset of B is supported for Java and C++ now. The work for code generation for Python, Clojure and C has begun but not continued.
Note:
- The implementation of the B types in C++ uses persistent set from: https://github.com/arximboldi/immer
- The library must first be installed before the generated C++ code can be used.
- The generated code in Python is not supported as the implementations of needed B Types are missed.
- The generated code for C works for a subset of the generated code that works for Java and C++.
- Sets and couples are not supported for C. Including other machines is not supported in C, too. The only types that are implemented for C are BInteger and BBoolean. An example where code generation for C works is the machine Lift.
Usage
Starting the code generator
# Java
./gradlew run -Planguage="java" -Pbig_integer="true/false" -Pfile="de/hhu/stups/codegenerator/testfiles/Lift.mch"
# Python
./gradlew run -Planguage="python" -Pbig_integer="true/false" -Pfile="de/hhu/stups/codegenerator/testfiles/Lift.mch"
# C
./gradlew run -Planguage="c" -Pbig_integer="true/false" -Pfile="de/hhu/stups/codegenerator/testfiles/Lift.mch"
# C++
./gradlew run -Planguage="cpp" -Pbig_integer="true/false" -Pfile="de/hhu/stups/codegenerator/testfiles/Lift.mch"
Compile the generated code in Java
- Run
./gradlew build
in project btypes_persistent or btypes_big_integer - Move
btypes-all-2.9.12-SNAPSHOT.jar
to same folder as the generated classes javac -cp btypes-all-2.9.12-SNAPSHOT.jar <files....>
- Example:
javac -cp btypes-all-2.9.12-SNAPSHOT.jar TrafficLightExec.java TrafficLight.java
(Code generated from TrafficLightExec.mch which includes TrafficLight.mch)
Compile the generated code in C++
- Move all B types (see btypes_persistent or btypes_big_integer folder) files to same folder as the generated classes
g++ -std=c++14 -O2 -march=native -g -DIMMER_NO_THREAD_SAFETY -o <executable> <main class>
- Example:
g++ -std=c++14 -O2 -march=native -g -DIMMER_NO_THREAD_SAFETY -o TrafficLightExec.exec TrafficLightExec.cpp
(TrafficLightExec.mch includes TrafficLight.mch, this command automatically compiles TrafficLight.cpp)
Compile the generated code in C
- Move BInteger and BBoolean to same folder as generated code (see btypes/src/main/c)
gcc <input file> -o <output file>
- Example:
gcc Lift.c -o Lift
Execute the generated code in Java
- Write a main function in the generated main class
java -cp :btypes-all-2.9.12-SNAPSHOT.jar <main file>
- Example:
java -cp :btypes-all-2.9.12-SNAPSHOT.jar TrafficLightExec
Execute the generated code in C++
- Write a main function in the generated main class
./<main file>
- Example:
./TrafficLightExec.exec
Execute the generated code in C
- Write a main function in the generated main file
./main.c
- Example:
./Lift
Performance
Analysis of the Performance is described in benchmarks/README.md.