Commit e3f7f8a769534ba879c06192a44f65b245112578

Authored by Austin Sun
Exists in master

Merge branch 'master' of git.ucsd.edu:acs008/cse131-pa4

Showing 5 changed files Side-by-side Diff

... ... @@ -131,4 +131,16 @@
131 131 if (field) field->Print(indentLevel+1);
132 132 if (actuals) actuals->PrintAll(indentLevel+1, "(actuals) ");
133 133 }
  134 +
  135 +llvm::Value* IntConstant::Emit() {
  136 + return llvm::ConstantInt::get(llvm::Type::getInt32Ty(*irgen.GetContext()), value, true);
  137 +}
  138 +
  139 +llvm::Value* FloatConstant::Emit() {
  140 + return llvm::ConstantInt::get(llvm::Type::getFloatTy(*irgen.GetContext()), value, true);
  141 +}
  142 +
  143 +llvm::Value* BoolConstant::Emit() {
  144 + return llvm::ConstantInt::get(llvm::Type::getInt1Ty(*irgen.GetContext()), value, false);
  145 +}
... ... @@ -56,6 +56,7 @@
56 56 IntConstant(yyltype loc, int val);
57 57 const char *GetPrintNameForNode() { return "IntConstant"; }
58 58 void PrintChildren(int indentLevel);
  59 + llvm::Value* Emit();
59 60 };
60 61  
61 62 class FloatConstant: public Expr
... ... @@ -67,6 +68,7 @@
67 68 FloatConstant(yyltype loc, double val);
68 69 const char *GetPrintNameForNode() { return "FloatConstant"; }
69 70 void PrintChildren(int indentLevel);
  71 + llvm::Value* Emit();
70 72 };
71 73  
72 74 class BoolConstant : public Expr
... ... @@ -78,6 +80,7 @@
78 80 BoolConstant(yyltype loc, bool val);
79 81 const char *GetPrintNameForNode() { return "BoolConstant"; }
80 82 void PrintChildren(int indentLevel);
  83 + llvm::Value* Emit();
81 84 };
82 85  
83 86 class VarExpr : public Expr
... ... @@ -30,7 +30,7 @@
30 30 // You can use this as a template and create Emit() function
31 31 // for individual node to fill in the module structure and instructions.
32 32 //
33   - IRGenerator irgen;
  33 + //IRGenerator irgen;
34 34 llvm::Module *mod = irgen.GetOrCreateModule("Name_the_Module.bc");
35 35  
36 36 // create a function signature
... ... @@ -5,6 +5,8 @@
5 5  
6 6 #include "irgen.h"
7 7  
  8 +IRGenerator irgen;
  9 +
8 10 IRGenerator::IRGenerator() :
9 11 context(NULL),
10 12 module(NULL),
... ... @@ -48,5 +48,7 @@
48 48 static const char *TargetLayout;
49 49 };
50 50  
  51 +extern IRGenerator irgen;
  52 +
51 53 #endif