hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

gen-stdlib.sh (2315B)


      1 mod_path() {
      2 	printf '%s\n' "$1" | tr -s '::' '/'
      3 }
      4 mod_file() {
      5 	printf '%s\n' "$1" | tr -s '::' '_'
      6 }
      7 mod_var() {
      8 	printf '%s_%s_%s\n' "$stdlib" "$1" "$2" | tr -s '::' '_'
      9 }
     10 
     11 gen_srcs() {
     12 	platform=any
     13 	OPTIND=1
     14 	while getopts p: name
     15 	do
     16 		case $name in
     17 		p)
     18 			platform="$OPTARG"
     19 			;;
     20 		?)
     21 			printf 'Invalid use of gen_srcs' >&2
     22 			exit 1
     23 			;;
     24 		esac
     25 	done
     26 	shift $(($OPTIND - 1))
     27 
     28 	mod="$1"
     29 	shift
     30 
     31 	path="$(mod_path "$mod")"
     32 	var="$(mod_var "$mod" "$platform")"
     33 
     34 	printf '# %s (+%s)\n' "$mod" "$platform"
     35 	printf '%s_srcs = \\\n' "$var"
     36 	while [ $# -ne 0 ]
     37 	do
     38 		if [ $# -eq 1 ]
     39 		then
     40 			printf '\t$(STDLIB)/%s/%s\n\n' "$path" "$1"
     41 		else
     42 			printf '\t$(STDLIB)/%s/%s \\\n' "$path" "$1"
     43 		fi
     44 		shift
     45 	done
     46 }
     47 
     48 gen_ssa() {
     49 	platform=any
     50 	OPTIND=1
     51 	while getopts p: name
     52 	do
     53 		case $name in
     54 		p)
     55 			platform="$OPTARG"
     56 			;;
     57 		?)
     58 			printf 'Invalid use of gen_ssa' >&2
     59 			exit 1
     60 			;;
     61 		esac
     62 	done
     63 	shift $(($OPTIND - 1))
     64 
     65 	mod="$1"
     66 	shift
     67 
     68 	path=$(mod_path "$mod")
     69 	file=$(mod_file "$mod")
     70 	var=$(mod_var "$mod" "$platform")
     71 
     72 	printf "\$($cache)/$path/$file-$platform.ssa: \$(${var}_srcs) \$(${stdlib}_rt)"
     73 	for dep in $*
     74 	do
     75 		printf ' $(%s)' "$(mod_var "$dep" \$"(PLATFORM)")"
     76 	done
     77 	printf '\n'
     78 
     79 	cat <<EOF
     80 	@printf 'HAREC \t\$@\n'
     81 	@mkdir -p \$($cache)/$path
     82 	@\$(${stdlib}_env) \$(HAREC) \$($flags) -o \$@ -N$mod \\
     83 		-t\$($cache)/$path/$file.td \$(${var}_srcs)
     84 
     85 EOF
     86 }
     87 
     88 gen_lib() {
     89 	platform=any
     90 	OPTIND=1
     91 	while getopts p: name
     92 	do
     93 		case $name in
     94 		p)
     95 			platform="$OPTARG"
     96 			;;
     97 		?)
     98 			printf 'Invalid use of gen_lib' >&2
     99 			exit 1
    100 			;;
    101 		esac
    102 	done
    103 	shift $(($OPTIND - 1))
    104 
    105 	printf "# gen_lib $1 ($platform)\n"
    106 
    107 	mod="$1"
    108 	path=$(mod_path "$mod")
    109 	file=$(mod_file "$mod")
    110 	var=$(mod_var "$mod" "$platform")
    111 	printf "%s = \$(%s)/%s/%s-%s.o\n" "$var" "$cache" "$path" "$file" "$platform"
    112 	printf "%s_env += HARE_TD_%s=\$(%s)/%s/%s.td\n" "$stdlib" "$mod" "$cache" "$path" "$file"
    113 	printf '%s_deps_%s += $(%s)\n' "$stdlib" "$platform" "$var"
    114 	if [ "$platform" = "any" ]
    115 	then
    116 		for p in $all_platforms
    117 		do
    118 			printf '%s = $(%s)\n' "$(mod_var "$mod" "$p")" "$var"
    119 		done
    120 	fi
    121 	printf '\n'
    122 }
    123 
    124 genrules() {
    125 	if [ $# -gt 0 ] && [ "$1" = "test" ]
    126 	then
    127 		cache=TESTCACHE
    128 		flags=TESTHAREFLAGS
    129 		testing=1
    130 		stdlib=testlib
    131 	else
    132 		cache=HARECACHE
    133 		flags=HAREFLAGS
    134 		testing=0
    135 		stdlib=stdlib
    136 	fi
    137 	stdlib
    138 }