-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwasm_codegen.hpp
More file actions
35 lines (28 loc) · 1.28 KB
/
wasm_codegen.hpp
File metadata and controls
35 lines (28 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include "ast.hpp"
#include "semantic.hpp"
#include <ostream>
#include <string>
#include <unordered_map>
class WasmGenerator {
public:
WasmGenerator(AST::Program* prog, const SemanticResult& sem);
void generateToWat(std::ostream& os, const std::string& entryClass);
private:
AST::Program* program;
const SemanticResult& semantic;
std::unordered_map<std::string, AST::ClassDecl*> classes;
int labelCounter;
void indexClasses();
void emitModuleHeader(std::ostream& os);
void emitModuleFooter(std::ostream& os);
AST::ClassDecl* findClass(const std::string& name);
AST::CtorDecl* findDefaultCtor(AST::ClassDecl* c);
void emitCtorAsMain(std::ostream& os, AST::ClassDecl* c, AST::CtorDecl* ctor);
void collectLocals(AST::Stmt* s, std::unordered_map<std::string, bool>& locals);
void emitLocals(std::ostream& os, const std::unordered_map<std::string, bool>& locals);
void emitStmt(std::ostream& os, AST::Stmt* s, const std::unordered_map<std::string, bool>& locals);
void emitBlock(std::ostream& os, AST::Block* b, const std::unordered_map<std::string, bool>& locals);
void emitExpr(std::ostream& os, AST::Expr* e, const std::unordered_map<std::string, bool>& locals);
int nextLabelId();
};