rers2go.sh 1.32 KB
Newer Older
Etienne Renault's avatar
Etienne Renault committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! /bin/bash
# 1er  arg : file.c
# Script dedicated to work on RERS challenge. Takes a C file in
# parameter and convert it into a go program that can then be processed
# by the Go2Pins tool.

filename=$(basename -- "$1")
filename="${filename%.*}"

echo Converting $filename

cat $1 | sed 's/#include <stdio.h>//g'                                          | \
    sed 's/#include <assert.h>//g'                                              | \
    sed 's/#include <math.h>//g'                                                | \
    sed 's/#include <stdlib.h>//g'                                              | \
    sed 's/extern void __VERIFIER_error(int);/void __VERIFIER_error(int n){}/g' | \
    sed 's/int input;/int __RERS__;/g' | sed 's/(input !=/(__RERS__ !=/g'       | \
    sed 's/calculate_output(input);/calculate_output(__RERS__);/g'              | \
    sed "s/scanf(\"%d\", &input);/__RERS__ = __RERS__ + 1;/g"                   | \
    sed "s/return -2;/break;/g"| sed "s#fprintf#;//fprintf#g"                   | \
    sed "s#printf#;//printf#g">/tmp/$filename.c

# Requires C to Go transpiler https://github.com/Konstantin8105/c4go
./c4go transpile /tmp/$filename.c

# This last step is mandatory to handle the tranduction of the C instruction
# "a ? b : c" which is translated using closure.
sed -i 's/int32/int/g' $filename.go