MichaReiser / llvm-node

LLVM 9.0+ Node Bindings
MIT License
183 stars 29 forks source link

Expose JIT functions. #135

Closed metacritical closed 2 years ago

metacritical commented 2 years ago

An important use case for llvm-node is to implement small toy languages, thus JIT becomes a necessary function. Not all use requires writing a bitcode to file. Is exposing JIT functions in the pipeline?

MichaReiser commented 2 years ago

Hy @metacritical

Thanks for reaching out. I have no immediate plans to add new features to llvm-node but are willing to help new contributors on board and review/merge their PRs.

guncha commented 2 years ago

In case others find this helpful, I've been using lli to evaluate the IR which seems to work well for toy programs. The program below is the output from module.print():

import { spawnSync } from 'child_process';
const LLI_PATH = '/opt/homebrew/opt/llvm/bin/lli';

export function evalIR(program: string): string {
  const result = spawnSync(LLI_PATH, {
    input: program,
  });
  if (result.stderr.length) {
    console.warn('lli stderr:\n' + result.stderr.toString());
  }
  if (result.status !== 0) {
    throw new Error('lli failed with status: ' + result.status);
  }
  return result.stdout.toString();
}