Would llvm be a good fit for writing a DSL interpreter to work with a C code base?

Hello all,

This is my first post on the forum so please bear with me.

The question that brings me here is if I could use llvm to write a simple DSL interpreter on top of a large C code base.

(Part of) The aforementioned C program is a simple in memory database of numeric arrays, and the idea of the DSL would be to run simple calculations on those arrays (akin to vector programming).

Please imagine the following example, where “X” represents a numeric array in memory, and whatever computation should be done to every element of “X”.

$ ./interpreter

access X // “I want to use the vector called X that you - C program - have in memory”
sin( X ) // This is easy to implement with a switch statement inside the C program, however,
sin( cos( X ) ) + 2 // this is much more difficult, involving multiple function pointers.

What I would like then is to have this very simple language that could parse mathematical expressions and delegate them to the respective math.h functions in the C library, or other functions that are already part of the C code base.

With this said, I would welcome any thoughts from your side regarding if llvm would be a good fit, or if I should for example just adopt an embedded language like lua, or any other ideas that come to mind.

Much appreciated.
F.