MysoreScript
compiler.hh
Go to the documentation of this file.
1 #pragma once
2 #include "runtime.hh"
3 #include <llvm/IR/Module.h>
4 #include <llvm/IR/IRBuilder.h>
5 #include <llvm/IR/Value.h>
6 #include <llvm/IR/LLVMContext.h>
7 #include <unordered_map>
8 
9 namespace Compiler
10 {
11  using MysoreScript::Obj;
16  class Context
17  {
21  Interpreter::SymbolTable &globalSymbols;
22  public:
29  llvm::LLVMContext C;
33  std::unique_ptr<llvm::Module> M;
37  llvm::Function *F;
41  llvm::IRBuilder<> B;
47  std::unordered_map<std::string, llvm::Value*> symbols;
51  llvm::PointerType *ObjPtrTy;
55  llvm::Type *ObjIntTy;
59  llvm::Type *SelTy;
64  llvm::FunctionType *getClosureType(int bound, int args);
69  llvm::FunctionType *getMethodType(int ivars, int args);
73  llvm::Value *lookupSymbolAddr(const std::string &str);
83  };
84 };
Object * Obj
Object pointer.
Definition: runtime.hh:33
std::unique_ptr< llvm::Module > M
The current module.
Definition: compiler.hh:33
llvm::IRBuilder B
The IR builder, always set to the current insert point.
Definition: compiler.hh:41
std::unordered_map< std::string, llvm::Value * > symbols
Symbols within this compilation context.
Definition: compiler.hh:47
llvm::Value * lookupSymbolAddr(const std::string &str)
Returns the address of the specified symbol.
Definition: compiler.cc:89
std::unordered_map< std::string, Obj * > SymbolTable
A symbol table stores the address of each allocation.
Definition: interpreter.hh:103
llvm::FunctionType * getClosureType(int bound, int args)
Get the type of a closure invoke function, for a closure with the specified number of instance variab...
Definition: compiler.cc:174
The compiler context.
Definition: compiler.hh:16
Object *(* ClosureInvoke)(Closure *,...)
A compiled closure invoke function.
Definition: runtime.hh:80
Definition: ast.hh:7
llvm::Type * ObjIntTy
The type of an integer the same size as an object pointer.
Definition: compiler.hh:55
llvm::Type * SelTy
The type used for selectors.
Definition: compiler.hh:59
llvm::Function * F
The function being compiled.
Definition: compiler.hh:37
llvm::PointerType * ObjPtrTy
The type of a pointer to a MysoreScript object.
Definition: compiler.hh:51
llvm::LLVMContext C
The LLVM context.
Definition: compiler.hh:29
llvm::FunctionType * getMethodType(int ivars, int args)
Get the type of a method with the specified number of arguments, for an object with the specified num...
Definition: compiler.cc:151
MysoreScript::ClosureInvoke compile()
At the end of compilation, generate code and return a function pointer.
Definition: compiler.cc:107
Context(Interpreter::SymbolTable &g)
Construct a context, given a global symbol table from the interpreter.
Definition: compiler.cc:73