# Run Smart Contract Compiler

# Download the Summoner Project

git clone https://github.com/Bytom/summoner

# Confirm the Environment

make sure that you have installed bison,byacc,flex

if not , install them

yum -y install bison 
yum -y install bycc
yum -y install flex

# Install cmake and Configure Environment Variable

make sure your cmake version is not below 3.22.0

you can download it from the offical website:https://cmake.org/download/ (opens new window)

unzip the package to your user path

tar -zxvf cmake-3.22.0-rc1-linux-x86_64.tar.gz

edit environment variable, open /etc/profile,add cmake path to the end

PATH=/usr/local/cmake/bin:$PATH
export PATH

set the environment variable by source

source /etc/profile

check cmake

cmake -version

cmake version 3.22.0-rc1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

# Compile Summoner Project

create a new folder in Summoner project

mkdir buid
cd build

Compile Summoner

# cmake ..

-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/summoner/build

Build Summoner

# cmake --build .

[  4%] Building C object builtin/CMakeFiles/BUILTIN.dir/builtin.c.o
[  9%] Linking C static library libBUILTIN.a
[  9%] Built target BUILTIN
[ 13%] Building C object compiler/CMakeFiles/COMPILER.dir/lex.yy.c.o
[ 18%] Building C object compiler/CMakeFiles/COMPILER.dir/y.tab.c.o
[ 22%] Building C object compiler/CMakeFiles/COMPILER.dir/codegen.c.o
[ 27%] Building C object compiler/CMakeFiles/COMPILER.dir/disassemble.c.o
[ 31%] Building C object compiler/CMakeFiles/COMPILER.dir/create.c.o
[ 36%] Building C object compiler/CMakeFiles/COMPILER.dir/error.c.o
[ 40%] Building C object compiler/CMakeFiles/COMPILER.dir/fix_tree.c.o
[ 45%] Building C object compiler/CMakeFiles/COMPILER.dir/opcode.c.o
[ 50%] Building C object compiler/CMakeFiles/COMPILER.dir/string.c.o
[ 54%] Building C object compiler/CMakeFiles/COMPILER.dir/compiler.c.o
[ 59%] Building C object compiler/CMakeFiles/COMPILER.dir/util.c.o
[ 63%] Linking C static library libCOMPILER.a
[ 72%] Built target COMPILER
[ 77%] Building C object debug/CMakeFiles/DEBUG.dir/debug.c.o
[ 81%] Linking C static library libDEBUG.a
[ 81%] Built target DEBUG
[ 86%] Building C object share/CMakeFiles/SHARE.dir/wchar.c.o
[ 90%] Linking C static library libSHARE.a
[ 90%] Built target SHARE
[ 95%] Building C object CMakeFiles/summoner.dir/main/main.c.o
[100%] Linking C executable summoner
[100%] Built target summoner

now you can use Summoner

# Compile Summoner Smart Contract

write a smart contract

func IfLocal(b int64, c int64) {
	var a int64 = 12345678
	if b > c {
		a = b
	} else {
		a = c
	}
	a = a + 6
}

named the smart contract file as 'a', then compile the file

./summoner a

** global variable section *********************************
** function section ****************************************
*** [0] IfLocal ***
void  IfLocal ( b,  c)
   0 DATA_4
   1 12345678
   5 2
   6 PICK
   7 2
   8 PICK
   9 GREATERTHAN
  10 NOT
  11 NOP
  12 JUMPIF
  13 24
  17 DROP
  18 DUP
  19 JUMP
  20 24
  24 DROP
  25 OVER
  26 DUP
  27 6
  28 ADD
*** line number ***
*** assemble opcodes ***
044e61bc0052795279a091616400000018757663000000187578765693
*** end of IfLocal ***
** type section ********************************************
** toplevel ********************
*** line number ***

finishing compile and get the opcodes and machine codes

Last Updated: 11/2/2021, 6:32:36 PM