I am implementing the support library for my toy Python implementation in C. Is there a recommended way to import types/functions defined in my C library as LLVM type objects into my compiler? I am currently doing this: - Create a "null" C file that references the important types - Load the bytecode of this file when initializing the compiler - Load the types and functions out of this "null" module I'm thinking that a better solution would be to write some tool that takes the "null" bytecode and outputs a C++ file so I don't need to link my compiler with the bytecode reader, or be able to find the "nullmodule.bc" file. Are there any better ways to do this? Thanks, Evan Jones -- Evan Jones http://evanjones.ca/
On Sun, 30 Oct 2005, Evan Jones wrote:> I am implementing the support library for my toy Python implementation in C. > Is there a recommended way to import types/functions defined in my C library > as LLVM type objects into my compiler? I am currently doing this: > > - Create a "null" C file that references the important types > - Load the bytecode of this file when initializing the compiler > - Load the types and functions out of this "null" module > > I'm thinking that a better solution would be to write some tool that takes > the "null" bytecode and outputs a C++ file so I don't need to link my > compiler with the bytecode reader, or be able to find the "nullmodule.bc" > file. Are there any better ways to do this?Unfortunately, I'm not aware of a better way to do this. If you care about a few specific functions, you can hard code them into the compiler. If you care about general functions or a large number of them, this is a reasonable approach. -Chris -- http://nondot.org/sabre/ http://llvm.org/
On Mon, 31 Oct 2005, Chris Lattner wrote:>> I'm thinking that a better solution would be to write some tool that takes >> the "null" bytecode and outputs a C++ file so I don't need to link my >> compiler with the bytecode reader, or be able to find the "nullmodule.bc" >> file. Are there any better ways to do this? > > Unfortunately, I'm not aware of a better way to do this. If you care about a > few specific functions, you can hard code them into the compiler. If you care > about general functions or a large number of them, this is a reasonable > approach.One thing I should mention: this is only if you REALLY care about the types that a function takes (e.g. what FILE is on the system). For most uses, you can just prototype a function as taking an 'sbyte*' and cast pointer values to sbyte* before calling the function. This could simplify things enough that you can do simple things instead of grand and complicated ones. -Chris -- http://nondot.org/sabre/ http://llvm.org/