diff --git a/apps/mwcompiler/main.cpp b/apps/mwcompiler/main.cpp index d55fe3a428..a19a50ab39 100644 --- a/apps/mwcompiler/main.cpp +++ b/apps/mwcompiler/main.cpp @@ -60,6 +60,10 @@ int main (int argc, char **argv) codeFile.write (reinterpret_cast (&code[0]), code.size()*sizeof (Interpreter::Type_Code)); + std::ofstream localFile ((filename + ".locals").c_str()); + + parser.getLocals().write (localFile); + return 0; } diff --git a/components/compiler/fileparser.cpp b/components/compiler/fileparser.cpp index 59ec90286b..caf44f749c 100644 --- a/components/compiler/fileparser.cpp +++ b/components/compiler/fileparser.cpp @@ -22,6 +22,11 @@ namespace Compiler { mScriptParser.getCode (code); } + + const Locals& FileParser::getLocals() const + { + return mLocals; + } bool FileParser::parseName (const std::string& name, const TokenLoc& loc, Scanner& scanner) diff --git a/components/compiler/fileparser.hpp b/components/compiler/fileparser.hpp index 55b5a15090..b9239841fe 100644 --- a/components/compiler/fileparser.hpp +++ b/components/compiler/fileparser.hpp @@ -31,6 +31,9 @@ namespace Compiler void getCode (std::vector& code) const; ///< store generated code in \æ code. + + const Locals& getLocals() const; + ///< get local variable declarations. virtual bool parseName (const std::string& name, const TokenLoc& loc, Scanner& scanner); diff --git a/components/compiler/locals.cpp b/components/compiler/locals.cpp index fe0974cf3c..eefe27a031 100644 --- a/components/compiler/locals.cpp +++ b/components/compiler/locals.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include namespace Compiler { @@ -52,6 +54,21 @@ namespace Compiler return ' '; } + void Locals::write (std::ostream& localFile) const + { + localFile + << get ('s').size() << ' ' + << get ('l').size() << ' ' + << get ('f').size() << std::endl; + + std::copy (get ('s').begin(), get ('s').end(), + std::ostream_iterator (localFile, " ")); + std::copy (get ('l').begin(), get ('l').end(), + std::ostream_iterator (localFile, " ")); + std::copy (get ('f').begin(), get ('f').end(), + std::ostream_iterator (localFile, " ")); + } + void Locals::declare (char type, const std::string& name) { get (type).push_back (name); diff --git a/components/compiler/locals.hpp b/components/compiler/locals.hpp index 4e4d5c7653..c12ba371a8 100644 --- a/components/compiler/locals.hpp +++ b/components/compiler/locals.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace Compiler { @@ -25,6 +26,9 @@ namespace Compiler char getType (const std::string& name) const; ///< 's': short, 'l': long, 'f': float, ' ': does not exist. + void write (std::ostream& localFile) const; + ///< write declarations to file. + void declare (char type, const std::string& name); ///< declares a variable.