Skip to content

Commit

Permalink
feat: Classes and Enums can now be imported properly from other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
alinalihassan committed May 25, 2022
1 parent 8931484 commit dd78333
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/liblesma/Backend/Codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ void Codegen::CompileModule(llvm::SMRange span, const std::string &filepath, boo
codegen->TheModule->setModuleIdentifier(filepath);

if (isJIT) {
// Add classes and enums
for (auto sym: codegen->Scope->getSymbols()) {
if (sym.second->getType()->isOneOf({TY_ENUM, TY_CLASS})) {
// TODO: We have to reconstruct classes and enums, fix me
auto struct_ty = dyn_cast<llvm::StructType>(sym.second->getLLVMType());
llvm::StructType *structType = llvm::StructType::create(*TheContext, struct_ty->elements(), sym.first);

auto *structSymbol = new SymbolTableEntry(sym.first, sym.second->getType());
structSymbol->setLLVMType(structType);
Scope->insertType(sym.first, sym.second->getType());
Scope->insertSymbol(structSymbol);
}
}

// Link modules together
if (Linker::linkModules(*TheModule, std::move(codegen->TheModule), (1 << 0)))
throw CodegenError({}, "Error linking modules together");
Expand Down
3 changes: 3 additions & 0 deletions src/liblesma/Symbol/SymbolTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace lesma {
void insertType(const std::string &name, SymbolType *type);
SymbolTable *createChildBlock(const std::string &blockName);
SymbolTable *getParent();
std::map<std::string, SymbolTableEntry *> getSymbols() { return symbols; }
std::map<std::string, SymbolType *> getTypes() { return types; }

SymbolTable *getChild(const std::string &tableName);

std::string toString(int ind) {
Expand Down

0 comments on commit dd78333

Please sign in to comment.