Closed esseks closed 9 years ago
My guess is that we could be able to do it by analyzing the AST built from Clang (cr #17) and emitting the dependencies of the module. The idea is that we begin by including everything, then we parse the dependencies and we remove what is unnecessary, unluckily we have to include everything first, otherwise the libclang will refuse to compile.
Otherwise we can just do something static and analyze the keywords emitted by the Nodes, easier to implement.
An easier strategy could be keeping a set of requirements at Program
level and pushing new Module
objects to it from semantic rules at parse time. For instance, every time an assert_stmt
is parsed, the semantic rule could contain:
program.addModule(Module("cassert"));
As per the title. For instance, if
assert()
is never used in the program, then:should not be emitted.