Compiler as dll
Yigal Chripun
yigal100 at gmail.com
Tue Jan 27 22:48:27 PST 2009
Benji Smith wrote:
> BCS wrote:
>> Hello Walter,
>>
>>>
>>> Instead, what you can do is simply dude up command line arguments,
>>> spawn the command line compiler, and collect the result.
>>>
>>
>> The one main thing I see not working there is memory-to-memory
>> compiles. I'd love to be able to build a function as a string, call
>> the compiler and get back a function pointer.
>
> I think also, with a compiler-as-dll, it'd have separate modules for
> lexing, parsing, optimizing, code-generation, and linking.
>
> As a user of that compiler DLL, I might like to write my own AST
> visitor, wrapping all function calls (or scope blocks) with tracing
> statements before sending them into the rest of the pipeline.
>
> Those are the kinds of things that I think would be especially cool with
> a CompilerServices module in the standard library.
>
> Also, consider this: someone could implement AST macros as a library!
>
> --benji
You've just described the design of clang - the new frontend for llvm
for compiling c/c++.
there are many tools used during development which need different
subsets of functionality of the compiler that will benefit from such a
design:
IDE - the IDE needs to use the lexing/parsing/semantic phases for
showing you errors on the fly, it's integrated build system needs to
know about dependencies, and it'll use the optimizer/code-gen phases to
build your projects.
lint tools - need the lexing/parsing/semantic phases.
stand alone build tool (like rebuild, bud, etc) - needs the lexer/parser
for automatically resolving dependencies.
doc system (built in IDE/ or stand alone) needs the semantic phases.
the compiler itself could (and should) use it - currently there's a
built in interpreter for CTFE which is limited to a subset of D.
instead of implementing a limited interpreter in addition to the
compiler, the compiler libs can easily be utilized for a JIT compiler
which will compile CTFE and run them during compilation using the same
code that is used to compile regular code.
More information about the Digitalmars-d
mailing list