Expected top-level entity

llvm

Solution

This error usually means that you copy-pasted part of some IR code which doesn't count as a top level entity. In other words, it's not a function, not a type, not a global variable, etc. The same error can happen in C, just for comparison:

x = 8;

Is not valid contents for a C file, because the assignment statement isn't a valid top level entity. To make it valid you put it in a function:

void foo() {
  x = 8;   /* assuming x is global and visible here */
}

The same error happens in LLVM IR.

Problem

How did you managed to pass through `expected top-level entity` error while executing `lli` in the `llvm` framework?

Original source