Joos1W Compiler Framework
All Classes Functions Typedefs Pages
CGClass.cc
1 #include "codegen/CodeGen.h"
2 
3 #include "ast/AstNode.h"
4 #include "ast/Type.h"
5 #include "tir/Type.h"
6 
7 namespace codegen {
8 
9 void CodeGenerator::emitClassDecl(ast::ClassDecl const* decl) {
10  // 1. Emit the function declarations
11  for(auto* method : decl->methods())
12  emitFunctionDecl(method);
13  // 2. Emit any static fields as globals
14  // 3. Construct the class struct type as well
15  std::vector<tir::Type*> fieldTypes{};
16  for(auto* field : decl->fields()) {
17  auto ty = emitType(field->type());
18  if(field->modifiers().isStatic()) {
19  gvMap[field] = cu.CreateGlobalVariable(ty, field->name());
20  } else {
21  fieldTypes.push_back(ty);
22  }
23  }
24  if(!fieldTypes.empty())
25  typeMap[decl] = tir::StructType::get(ctx, fieldTypes);
26 }
27 
28 void CodeGenerator::emitClass(ast::ClassDecl const* decl) {
29  for(auto* method : decl->methods()) {
30  if(method->modifiers().isStatic()) {
31  emitFunction(method);
32  }
33  }
34 }
35 
36 } // namespace codegen