Skip to content

Instantly share code, notes, and snippets.

@darach
Last active February 15, 2021 20:36
Show Gist options
  • Save darach/1b8bfade3f3b2488f6db to your computer and use it in GitHub Desktop.
Save darach/1b8bfade3f3b2488f6db to your computer and use it in GitHub Desktop.
Example showing how to compile pony executables via LLVM and clang from LLVM IR produced by 'ponyc -rir ...'
#!/bin/sh
LLVM_HOME=/usr/local/Cellar/llvm/3.6.2/bin
PONY_HOME=/path/to/pony/repo
PONY_LIBS=${PONY_HOME}/build/debug
TARGET_ARCH=x86-64
OUT_LL="$1.ll"
OUT_BC="$1.bc"
OUT_S="$1.s"
OUT_O="$1.o"
OUT="fony_$1"
# Compile pony in debug mode and generate LLVM IR human readable forms
${PONY_HOME}/build/debug/ponyc --debug -rir $1
# Translate LLVM IR human readable forms into LLVM bitcode
${LLVM_HOME}/llvm-as ${OUT_LL}
# Compile bitcode into assembly listing
${LLVM_HOME}/llc -march ${TARGET_ARCH} ${OUT_BC} -o ${OUT_S}
# Compile bitcode into object
${LLVM_HOME}/llc -march ${TARGET_ARCH} ${OUT_BC} -filetype=obj -o ${OUT_O}
# Link into executable
clang ${OUT_O} -o ${OUT} -L ${PONY_LIBS} -lponyrt -lSystem.B -e _main
# Run executable
./${OUT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment