Skip to content

Instantly share code, notes, and snippets.

Dependencies
Recently I've been working on a cross-platform program. This program depends on LLVM/Clang, and currently targets Windows and Linux. Furthermore, the program runs both as a console application and library- for example, to support a VS addin. I wanted to share some of my stories depending on these libraries, and present some don'ts of creating a library. Some of them are more subtle than others.
Mutate global state of any form. This includes direct interaction with stdin/stdout/stderr, environment variables, filesystem, the works. It's one thing to provide helpers to make interaction with them simple, and another to simply interact with them regardless. LLVM keeps global mutable lists of things like loaded DLLs. Both libraries have a nasty habit of dumping things to stdout. Running tests on Linux produces 2MB of gunk that makes the real output unreadable. And if you're running as a VS addin, nobody is listening to stdout, so it's all wasted even if you wanted to read it.
Keep private state. Ser
struct Renderable { virtual ~Renderable() {} };
struct SelfRenderable : Renderable {
virtual void Render(Renderer& render) = 0;
};
class Renderer {
com_ptr<ID3D10Device> device;
public:
std::unordered_map<std::type_index, std::function<void(Renderer& renderer, const Renderable& renderable)>> rendering_functions;
void Render(Renderable& renderable) {
if (rendering_functions.find(typeid(renderable)) ! rendering_functions.end())
std::shared_ptr<Expression> ClangFunctionType::BuildCall(std::shared_ptr<Expression> val, std::vector<std::shared_ptr<Expression>> args, Context c) {
struct Call : Expression {
Call(Analyzer& an, std::shared_ptr<Expression> self, std::vector<std::shared_ptr<Expression>> args, Context c)
: a(an), args(std::move(args)), val(std::move(self))
{
if (GetType()->AlwaysKeepInMemory()) {
Ret = Wide::Memory::MakeUnique<ImplicitTemporaryExpr>(GetType(), c);
if (!GetType()->IsTriviallyDestructible())
Destructor = GetType()->BuildDestructorCall(Ret, c, true);