The Crystal Programming Language Forum

Adding semantic processing requires causes crash

Playing with https://github.com/catprintlabs/crow

which originally only parses into the AST tree, but does no semantic analysis.

I need to add the semantic analysis stuff, but when I try to require the appropriate files, i get this when I compile the app:

Showing last frame. Use --error-trace for full trace.

In /usr/local/Cellar/crystal/0.32.1/src/llvm/lib_llvm.cr:4:19

 4 | `[ -n "$LLVM_CONFIG" ] && command -v "$LLVM_CONFIG" || \
     ^
Error: error executing command: [ -n "$LLVM_CONFIG" ] && command -v "$LLVM_CONFIG" || command -v llvm-config-8 || command -v llvm-config-8.0 || command -v llvm-config80 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 8.0*) command -v llvm-config;; *) false;; esac)) || command -v llvm-config-7 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 7.1*) command -v llvm-config;; *) false;; esac)) || command -v llvm-config-7.0 || command -v llvm-config70 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 7.0*) command -v llvm-config;; *) false;; esac)) || command -v llvm-config-6.0 || command -v llvm-config60 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 6.0*) command -v llvm-config;; *) false;; esac)) || command -v llvm-config-5.0 || command -v llvm-config50 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 5.0*) command -v llvm-config;; *) false;; esac)) || command -v llvm-config-4.0 || command -v llvm-config40 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 4.0*) command -v llvm-config;; *) false;; esac)) || command -v llvm-config-3.9 || command -v llvm-config39 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.9*) command -v llvm-config;; *) false;; esac)) || command -v llvm-config-3.8 || command -v llvm-config38 || (command -v llvm-config > /dev/null && (case "$(llvm-config --version)" in 3.8*) command -v llvm-config;; *) false;; esac)) || command -v llvm-config

                  , got exit status 1

Here is the set of requires originally:

require “compiler/crystal/syntax/virtual_file.cr”
require “compiler/crystal/syntax/exception.cr”
require “compiler/crystal/syntax/parser.cr”
require “logger”

as soon as I add:

require “compiler/crystal/program.cr”

or (anything else to do with the require tree for semantic processing) I get the above error.

Hi!

You need to have LLVM installed to do semantic analysis.

The truth is, LLVM is used for code generation, but because we have macro run, which let’s you execute code at compile time, code generation is needed for semantic analysis.

Thanks for the prompt reply. I must have LLVM already installed, as I am able to compile and execute crystal code??? Anyway will poke along and see what I see.

The Crystal compiler has LLVM statically linked into the binary. And regular programs don’t need LLVM at runtime.

So you usually don’t need LLVM installed to build and run Crystal programs. Only if your code explicitly uses LLVM bindings, it needs to be available. require “compiler/crystal/program.cr” results in require "llvm", that’s why you need to have the library available.