Changeset 739
- Timestamp:
- 11/21/08 13:12:06 (7 weeks ago)
- Location:
- trunk/rphp
- Files:
-
- 12 modified
-
compiler/CMakeLists.txt (modified) (1 diff)
-
compiler/pAST.h (modified) (4 diffs)
-
compiler/pDriver.cpp (modified) (1 diff)
-
compiler/pGenSupport.cpp (modified) (4 diffs)
-
compiler/pGenSupport.h (modified) (1 diff)
-
compiler/pGenerator.cpp (modified) (4 diffs)
-
compiler/pGenerator.h (modified) (1 diff)
-
compiler/pModule.cpp (modified) (2 diffs)
-
compiler/pModule.h (modified) (1 diff)
-
compiler/pSourceFile.cpp (modified) (3 diffs)
-
compiler/pStandAloneTargets.cpp (modified) (3 diffs)
-
frontend/cli/main.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/rphp/compiler/CMakeLists.txt
r729 r739 81 81 pLinkTarget.cpp 82 82 pLibTargets.cpp 83 pCompileError.cpp 83 84 ${RPHP_LLVM_DEP_FILES} 84 85 ${LLVM_LIBS_INTERPRETER_OBJECTS} -
trunk/rphp/compiler/pAST.h
r734 r739 168 168 class var: public expr { 169 169 170 const pSourceRangename_;171 172 public: 173 var(const pSourceRange& name): expr(varKind), name_(name ) { }170 pIdentString name_; 171 172 public: 173 var(const pSourceRange& name): expr(varKind), name_(name.begin(), name.end()) { } 174 174 175 175 pIdentString name(void) const { 176 return pIdentString(name_.begin(), name_.end());176 return name_; 177 177 } 178 178 … … 200 200 class functionInvoke: public expr { 201 201 202 const pSourceRangename_;202 pIdentString name_; 203 203 expressionList argList_; 204 204 … … 206 206 functionInvoke(const pSourceRange& name, expressionList* argList): 207 207 expr(functionInvokeKind), 208 name_(name ),208 name_(name.begin(), name.end()), 209 209 argList_(*argList) 210 210 { … … 220 220 221 221 pIdentString name(void) const { 222 return pIdentString(name_.begin(), name_.end());222 return name_; 223 223 } 224 224 expressionList& argList(void) { return argList_; } -
trunk/rphp/compiler/pDriver.cpp
r732 r739 152 152 l.dumpTokens(); 153 153 delete source; 154 154 155 155 } 156 156 -
trunk/rphp/compiler/pGenSupport.cpp
r735 r739 28 28 #include <fstream> 29 29 30 #include "pCompileError.h" 30 31 #include "pGenSupport.h" 31 32 … … 39 40 } 40 41 41 boolpGenSupport::writeBitcode(llvm::Module* m, std::string outFile) {42 void pGenSupport::writeBitcode(llvm::Module* m, std::string outFile) { 42 43 43 44 assert(m != NULL); 44 45 assert(outFile.length() > 0); 45 46 46 // TODO: real error handling47 47 std::ofstream OS(outFile.c_str(), std::ios_base::out|std::ios::trunc|std::ios::binary); 48 48 if (!OS.fail()) { 49 49 llvm::WriteBitcodeToFile(m, OS); 50 return true;51 50 } 52 51 else { 53 return false;52 throw pCompileError("unable to write bitcode file ["+outFile+"]"); 54 53 } 55 54 … … 62 61 llvm::MemoryBuffer* mb = llvm::MemoryBuffer::getFile(fileName.c_str(), &errMsg); 63 62 if (errMsg.length()) { 64 // TODO: errors 65 std::cerr << "error loading runtime IR file [" << fileName << "]: " << errMsg << std::endl; 66 exit(1); 63 throw pCompileError("error loading runtime IR file [" + fileName + "]: " + errMsg); 67 64 } 68 65 69 66 llvm::ModuleProvider* mp = llvm::getBitcodeModuleProvider(mb, &errMsg); 70 67 if (errMsg.length()) { 71 // TODO: errors 72 std::cerr << "error parsing bitcode file [" << fileName << "]: " << errMsg << std::endl; 73 exit(1); 68 throw pCompileError("error parsing bitcode file [" + fileName + "]: " + errMsg); 74 69 } 75 70 … … 86 81 llvm::Module* pGenSupport::getRuntimeIR() { 87 82 88 // TODO: ouch!83 // TODO: needs to be a command line option with a good default 89 84 return readBitcode("../runtime-ir/irRuntime.ir"); 90 85 -
trunk/rphp/compiler/pGenSupport.h
r680 r739 35 35 public: 36 36 static std::string mangleModuleName(std::string moduleName); 37 static boolwriteBitcode(llvm::Module* m, std::string outFile);37 static void writeBitcode(llvm::Module* m, std::string outFile); 38 38 static llvm::Module* readBitcode(std::string fileName); 39 39 static llvm::Module* getRuntimeIR(); -
trunk/rphp/compiler/pGenerator.cpp
r734 r739 31 31 #include <llvm/Linker.h> 32 32 33 #include "pCompileError.h" 33 34 #include "pGenerator.h" 34 35 #include "pCompileTarget.h" … … 65 66 l.LinkInModule(irMod, &errMsg); 66 67 if (errMsg.length()) { 67 // TODO: errors 68 std::cerr << "error linking in runtime ir: " << errMsg << std::endl; 69 exit(1); 68 throw pCompileError("error linking in runtime IR [" + errMsg + "]"); 70 69 } 71 70 … … 261 260 262 261 // gen lval 262 pIdentString name("lVal"); 263 if (n->lVal()->getKind() == AST::varKind) { 264 AST::var* l = static_cast<AST::var*>(n->lVal()); 265 name = l->name(); 266 } 263 267 visit(n->lVal()); 264 268 Value* lVal = valueStack_.back(); … … 268 272 assert(f != NULL); 269 273 270 currentBlock_.CreateCall2(f, lVal, rVal );274 currentBlock_.CreateCall2(f, lVal, rVal, name.c_str()); 271 275 272 276 } -
trunk/rphp/compiler/pGenerator.h
r722 r739 40 40 namespace rphp { 41 41 42 // TODO: llvm has structures for this. use those? 42 43 typedef boost::unordered_map<pIdentString, llvm::Value*> symbolTableType; 43 44 -
trunk/rphp/compiler/pModule.cpp
r738 r739 43 43 { 44 44 45 // TODO: error handling46 45 source_ = new pSourceFile(file); 47 46 parser::parseSourceFile(this); … … 115 114 } 116 115 117 boolpModule::writeBitcode(pFileNameString fileName) {116 void pModule::writeBitcode(pFileNameString fileName) { 118 117 119 returnpGenSupport::writeBitcode(llvmModule_, source_->fileName());118 pGenSupport::writeBitcode(llvmModule_, source_->fileName()); 120 119 121 120 } -
trunk/rphp/compiler/pModule.h
r732 r739 71 71 void applyVisitor(AST::baseVisitor* v); 72 72 bool lowerToIR(pCompileTarget* target); 73 boolwriteBitcode(pFileNameString fileName);73 void writeBitcode(pFileNameString fileName); 74 74 void setLLVMModuleOwnership(bool v) { llvmModuleOwner_ = v; } 75 75 llvm::Module* getLLVMModule() { return llvmModule_; } -
trunk/rphp/compiler/pSourceFile.cpp
r738 r739 30 30 #include <stdio.h> 31 31 32 #include "pCompileError.h" 32 33 #include "pSourceFile.h" 33 34 … … 40 41 std::ifstream instream(file_.get<0>().c_str()); 41 42 if (!instream.is_open()) { 42 std::cerr << "Couldn't open file: " << file_.get<0>() << std::endl; 43 exit(-1); 43 throw pCompileError("couldn't open file [" + file_.get<0>() + "]"); 44 44 } 45 45 instream.unsetf(std::ios::skipws); … … 66 66 UnicodeString ubuffer(rawBuffer.data(), rawBuffer.length(), file_.get<1>().c_str()); 67 67 if (ubuffer.isBogus()) { 68 std::cerr << "Could not perform character conversion in file: " << file_.get<0>() << " from charset: " << file_.get<1>() << std::endl; 69 exit(-1); 68 throw pCompileError("could not perform character conversion in file [" + file_.get<0>() + "] from charset [" + file_.get<1>() + "]"); 70 69 } 71 70 -
trunk/rphp/compiler/pStandAloneTargets.cpp
r722 r739 34 34 #include <llvm/System/Program.h> 35 35 36 #include "pCompileError.h" 36 37 #include "pGenSupport.h" 37 38 #include "pStandAloneTargets.h" … … 123 124 sys::Path ld = sys::Program::FindProgramByName("llvm-ld"); 124 125 if (ld.isEmpty()) { 125 // TODO: error handling 126 std::cerr << "unable to link: llvm-ld not found" << std::endl; 127 return; 126 throw pCompileError("unable to link: llvm-ld not found"); 128 127 } 129 128 … … 163 162 164 163 if (R != 0) { 165 // TODO: error handling 166 std::cerr << errMsg << std::endl; 167 return; 164 throw pCompileError(errMsg); 168 165 } 169 166 -
trunk/rphp/frontend/cli/main.cpp
r732 r739 72 72 } 73 73 else if (dumpToks) { 74 driver.dumpTokens(boost::make_tuple(inputFile, encoding)); 74 try { 75 driver.dumpTokens(boost::make_tuple(inputFile, encoding)); 76 } 77 catch (std::exception& e) { 78 std::cerr << e.what() << std::endl; 79 return 1; 80 } 81 return 0; 75 82 } 76 83 else if (dumpAST) { 77 driver.dumpAST(boost::make_tuple(inputFile, encoding)); 84 try { 85 driver.dumpAST(boost::make_tuple(inputFile, encoding)); 86 } 87 catch (std::exception& e) { 88 std::cerr << e.what() << std::endl; 89 return 1; 90 } 91 return 0; 78 92 } 79 93 else if (dumpIR) { 80 driver.dumpIR(boost::make_tuple(inputFile, encoding)); 94 try { 95 driver.dumpIR(boost::make_tuple(inputFile, encoding)); 96 } 97 catch (std::exception& e) { 98 std::cerr << e.what() << std::endl; 99 return 1; 100 } 101 return 0; 81 102 } 82 103 else if (dumpPre) { 83 driver.dumpPre(boost::make_tuple(inputFile, encoding)); 104 try { 105 driver.dumpPre(boost::make_tuple(inputFile, encoding)); 106 } 107 catch (std::exception& e) { 108 std::cerr << e.what() << std::endl; 109 return 1; 110 } 111 return 0; 84 112 } 85 113 else {
