| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
############################################################################### |
| 4 |
# # |
| 5 |
# qcc - Quantum Circuit Compiler for Unix # |
| 6 |
# J. Yamazaki, M. Suzuki and H. Watanabe # |
| 7 |
# Copyright (C) 2003 QCAD project, all rights reserved. # |
| 8 |
# # |
| 9 |
############################################################################### |
| 10 |
|
| 11 |
|
| 12 |
############################################################################### |
| 13 |
# Global valuables |
| 14 |
############################################################################### |
| 15 |
# ocppfile |
| 16 |
# ofile |
| 17 |
# ifile |
| 18 |
# qcpp_args |
| 19 |
# gcc_args |
| 20 |
|
| 21 |
er_str0="Try 'qcc --help' for more information." |
| 22 |
er_str1="No output file." |
| 23 |
er_str2=" is unexpected option." |
| 24 |
er_str3="'-o' option can be used only once." |
| 25 |
er_str4="Too many input files." |
| 26 |
er_str5="No input file." |
| 27 |
er_str6="File not found." |
| 28 |
er_str7="'-C' option can be used only once." |
| 29 |
|
| 30 |
version_str1="qcc version 0.2" |
| 31 |
version_str2="Copyright (C) 2003 QCAD project." |
| 32 |
|
| 33 |
opt_stop=0 |
| 34 |
opt_create=0 |
| 35 |
opt_input=0 |
| 36 |
opt_output=0 |
| 37 |
opt_verbose=0 |
| 38 |
|
| 39 |
inst_dir=../calcunits |
| 40 |
|
| 41 |
############################################################################### |
| 42 |
print_usage() |
| 43 |
{ |
| 44 |
echo "Usage: qcc [options] file" |
| 45 |
echo "Options:" |
| 46 |
echo " --help, -h ... Display this information" |
| 47 |
echo " -c ... Compile into c++, but do not link" |
| 48 |
echo " -C [36mfile[00m ... Create intermediate c++ file as [36mfile[00m" |
| 49 |
echo " (is effective only when '-c' is not selected)" |
| 50 |
echo " -o [36mfile[00m ... Place the output into [36mfile[00m" |
| 51 |
echo " (is effective for both c++ file and executables)" |
| 52 |
echo " -v ... Display the programs invoked by the compiler" |
| 53 |
echo " -V ... Display qcc version number" |
| 54 |
echo "Examples:" |
| 55 |
echo " qcc -c sample.mcd -o sample.cpp OK" |
| 56 |
echo " qcc sample.mcd -o a.out OK" |
| 57 |
echo " qcc sample.mcd -C sample.cpp -o a.out OK" |
| 58 |
echo " qcc -c sample.mcd -C sample.cpp -o a.out [31;01mERROR![00m" |
| 59 |
echo " [33mIn the last one, '-C' conflicts with '-o'," |
| 60 |
echo " then create a.out as c++ file.[00m" |
| 61 |
} |
| 62 |
|
| 63 |
############################################################################### |
| 64 |
option_create() |
| 65 |
{ |
| 66 |
if [ $opt_create -eq 0 ]; then |
| 67 |
if [ $1 ]; then |
| 68 |
ocppfile=$1 |
| 69 |
opt_create=1 |
| 70 |
else |
| 71 |
echo $er_str1 |
| 72 |
exit 1 |
| 73 |
fi |
| 74 |
else |
| 75 |
echo $er_str7 |
| 76 |
exit 1 |
| 77 |
fi |
| 78 |
} |
| 79 |
|
| 80 |
############################################################################### |
| 81 |
option_o() |
| 82 |
{ |
| 83 |
if [ $opt_output -eq 0 ]; then |
| 84 |
if [ $1 ]; then |
| 85 |
ofile=$1 |
| 86 |
opt_output=1 |
| 87 |
else |
| 88 |
echo $er_str1 |
| 89 |
exit 1 |
| 90 |
fi |
| 91 |
else |
| 92 |
echo $er_str3 |
| 93 |
exit 1 |
| 94 |
fi |
| 95 |
} |
| 96 |
|
| 97 |
############################################################################### |
| 98 |
############################################################################### |
| 99 |
############################################################################### |
| 100 |
############################################################################### |
| 101 |
# Analyze arguments... |
| 102 |
|
| 103 |
if [ $1 ]; then |
| 104 |
: |
| 105 |
else |
| 106 |
echo |
| 107 |
echo $version_str2 |
| 108 |
echo $version_str1 |
| 109 |
echo |
| 110 |
print_usage |
| 111 |
echo |
| 112 |
exit 0 |
| 113 |
fi |
| 114 |
|
| 115 |
while [ $1 ] |
| 116 |
do |
| 117 |
case $1 in |
| 118 |
--help | -h) |
| 119 |
echo |
| 120 |
print_usage |
| 121 |
echo |
| 122 |
exit 0 |
| 123 |
;; |
| 124 |
-c) |
| 125 |
opt_stop=1 |
| 126 |
;; |
| 127 |
-C) |
| 128 |
shift |
| 129 |
option_create $1 |
| 130 |
opt_create=1 |
| 131 |
;; |
| 132 |
-o) |
| 133 |
shift |
| 134 |
option_o $1 |
| 135 |
;; |
| 136 |
-v) |
| 137 |
opt_verbose=1 |
| 138 |
;; |
| 139 |
-V) |
| 140 |
echo |
| 141 |
echo $version_str2 |
| 142 |
echo $version_str1 |
| 143 |
echo |
| 144 |
exit 0 |
| 145 |
;; |
| 146 |
*) |
| 147 |
if [ $opt_input -eq 0 ]; then |
| 148 |
ifile=$1 |
| 149 |
opt_input=1 |
| 150 |
else |
| 151 |
echo "$er_str4 '$1'" |
| 152 |
exit 1 |
| 153 |
fi |
| 154 |
;; |
| 155 |
esac |
| 156 |
|
| 157 |
if [ $1 ]; then |
| 158 |
shift |
| 159 |
fi |
| 160 |
done |
| 161 |
|
| 162 |
############################################################################### |
| 163 |
# Check arguments... |
| 164 |
|
| 165 |
if [ $opt_input -eq 0 ]; then |
| 166 |
echo $er_str5 |
| 167 |
exit 1 |
| 168 |
fi |
| 169 |
|
| 170 |
if !([ -r $ifile ]); then |
| 171 |
echo $er_str6 |
| 172 |
exit 1 |
| 173 |
fi |
| 174 |
|
| 175 |
############################################################################### |
| 176 |
# Create qcpp args |
| 177 |
|
| 178 |
qcpp_args="" |
| 179 |
gcc_args="-I../qclib -I$inst_dir" |
| 180 |
|
| 181 |
#if [ $opt_verbose -eq 1 ]; then |
| 182 |
# qcpp_args="-v" |
| 183 |
#fi |
| 184 |
|
| 185 |
qcpp_args="$qcpp_args $ifile" |
| 186 |
|
| 187 |
if [ $opt_stop -eq 1 ]; then |
| 188 |
if [ $opt_output -eq 1 ]; then |
| 189 |
qcpp_args="$qcpp_args -o $ofile" |
| 190 |
fi |
| 191 |
else |
| 192 |
if [ $opt_create -eq 0 ]; then |
| 193 |
ocppfile="qcctmp.cpp" |
| 194 |
fi |
| 195 |
qcpp_args="$qcpp_args -o $ocppfile" |
| 196 |
#TODO: |
| 197 |
gcc_args="$ocppfile $gcc_args ../qclib/qclib.a -lm" |
| 198 |
if [ $opt_output -eq 1 ]; then |
| 199 |
gcc_args="$gcc_args -o $ofile" |
| 200 |
fi |
| 201 |
fi |
| 202 |
|
| 203 |
############################################################################### |
| 204 |
# For debug |
| 205 |
#echo "qcpp_args = $qcpp_args" |
| 206 |
#echo "gcc_args = $gcc_args" |
| 207 |
#echo "opt_stop = $opt_stop" |
| 208 |
#echo "opt_create = $opt_create" |
| 209 |
#echo "opt_verbose = $opt_verbose" |
| 210 |
#echo "opt_input = $opt_input" |
| 211 |
#echo "opt_output = $opt_output" |
| 212 |
#echo "ocppfile = $ocppfile" |
| 213 |
#echo "ofile = $ofile" |
| 214 |
#echo "ifile = $ifile" |
| 215 |
|
| 216 |
############################################################################### |
| 217 |
# Compile phase... |
| 218 |
|
| 219 |
if [ $opt_verbose -eq 1 ]; then |
| 220 |
echo "qcpp $qcpp_args" |
| 221 |
fi |
| 222 |
if !(qcpp $qcpp_args); then |
| 223 |
exit 1 |
| 224 |
fi |
| 225 |
|
| 226 |
if [ $opt_stop -eq 1 ]; then |
| 227 |
exit 0 |
| 228 |
fi |
| 229 |
|
| 230 |
############################################################################### |
| 231 |
|
| 232 |
if [ $opt_verbose -eq 1 ]; then |
| 233 |
echo g++ $gcc_args |
| 234 |
fi |
| 235 |
|
| 236 |
g++ $gcc_args |
| 237 |
|
| 238 |
if [ $opt_create -eq 0 ] && [ -e $ocppfile ]; then |
| 239 |
rm -f $ocppfile |
| 240 |
fi |
| 241 |
|
| 242 |
exit 0 |