├── include └── Elite │ ├── Model │ ├── BlockNode.h │ ├── ListNode.h │ ├── SeqNode.h │ ├── nodes.h │ ├── ByteNode.h │ ├── CharNode.h │ ├── IntNode.h │ ├── FloatNode.h │ ├── IDNode.h │ ├── ModelException.h │ ├── StringNode.h │ └── TypeNode.h │ ├── CodeGen │ ├── ICodeGenFunction.h │ ├── CodeGen.h │ ├── RedCodeGen.h │ ├── CodeGenFunction.h │ ├── ICodeGenContext.h │ └── CodeGenContext.h │ ├── MetaModel │ ├── MapModel.h │ ├── MacroModel.h │ ├── MetaModel.h │ ├── StructModel.h │ └── FunctionModel.h │ ├── LLCG │ ├── lvalue.h │ ├── llcg.h │ └── llcg_l.h │ └── Translater │ ├── PassManager.h │ └── Pass.h ├── README.md ├── src ├── main.cpp ├── Model │ ├── CharNode.cpp │ ├── ByteNode.cpp │ ├── IntNode.cpp │ ├── FloatNode.cpp │ ├── IDNode.cpp │ ├── StringNode.cpp │ ├── ModelCodeGen.cpp │ ├── TypeNode.cpp │ └── Node.cpp ├── LLCG │ ├── llcg.cpp │ └── LLVMLIB │ │ ├── llvm_value.cpp │ │ ├── llvm_value.h │ │ ├── llvm_type.cpp │ │ ├── llvm_type.h │ │ └── llvm_libs.cpp ├── Parser │ ├── GrammarParser.h │ ├── GrammarParser.cpp │ └── scanner.l ├── MetaModel │ ├── MapModel.cpp │ ├── MetaModel.cpp │ ├── MacroModel.cpp │ ├── StructModel.cpp │ └── FunctionModel.cpp ├── Utils │ ├── StringEscape.h │ ├── string_formatter.h │ └── StringEscape.cpp ├── Translater │ ├── idmap.cpp │ ├── MacroTranslate.h │ ├── idtable.cpp │ ├── idtable.h │ ├── idmap.h │ ├── Pass.cpp │ ├── MacroTranslate.cpp │ └── PassManager.cpp ├── CodeGen │ ├── CodeGenFunction.cpp │ └── RedCodeGen.cpp └── Macro │ ├── Classes.cpp │ └── Prescan.cpp ├── doc ├── misc │ ├── github_logo.png │ ├── footer.html │ └── header.html ├── Makefile ├── index.cn.md ├── CMakeLists.txt ├── index.po ├── Doxyfile.in ├── Doxyfile.zh-cn.in └── 设计文档.md ├── .gitignore ├── CHANGELOG.md ├── .travis ├── run.sh └── install.sh ├── runtime └── CMakeLists.txt ├── .clang-format ├── appveyor.yml ├── test ├── apptest.cpp └── CMakeLists.txt ├── cmake ├── ClangConf.cmake ├── CombineHeader.cmake └── Install.cmake ├── Authors ├── .travis.yml ├── header_libs ├── cereal │ ├── external │ │ ├── rapidjson │ │ │ ├── internal │ │ │ │ ├── strfunc.h │ │ │ │ ├── stack.h │ │ │ │ └── pow10.h │ │ │ ├── license.txt │ │ │ ├── filestream.h │ │ │ ├── stringbuffer.h │ │ │ └── genericstream.h │ │ ├── rapidxml │ │ │ ├── license.txt │ │ │ ├── rapidxml_utils.hpp │ │ │ └── rapidxml_iterators.hpp │ │ └── base64.hpp │ ├── types │ │ ├── utility.hpp │ │ ├── complex.hpp │ │ ├── list.hpp │ │ ├── deque.hpp │ │ ├── forward_list.hpp │ │ ├── string.hpp │ │ ├── chrono.hpp │ │ ├── stack.hpp │ │ ├── array.hpp │ │ ├── set.hpp │ │ ├── bitset.hpp │ │ ├── unordered_set.hpp │ │ ├── valarray.hpp │ │ ├── unordered_map.hpp │ │ ├── map.hpp │ │ ├── boost_variant.hpp │ │ └── tuple.hpp │ ├── details │ │ ├── util.hpp │ │ └── static_object.hpp │ └── macros.hpp ├── elegantlist.hpp └── sptr │ ├── sptr.hpp │ └── memheap.hpp ├── LICENSE ├── conanfile.py └── CMakeLists.txt /include/Elite/Model/BlockNode.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/Elite/Model/ListNode.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Elite 2 | ================= 3 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | int main(int argc, char *argv[]) 3 | { 4 | 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /doc/misc/github_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/Elite/HEAD/doc/misc/github_logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.*~ 2 | *.bc 3 | .fuse* 4 | *.sublime-* 5 | .clang_complete 6 | bin/ 7 | build/ 8 | build-doc/ 9 | .vscode/ 10 | -------------------------------------------------------------------------------- /src/Model/CharNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #include "Elite/Model/CharNode.h" 7 | 8 | /** 9 | * CharNode implementation 10 | */ 11 | -------------------------------------------------------------------------------- /src/Model/ByteNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #include "Elite/Model/ByteNode.h" 7 | 8 | /** 9 | * ByteNode implementation 10 | */ 11 | 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | =============== 3 | 4 | ### V0.1.1 5 | 6 | 7 | ------------------------ 8 | 9 | ### V0.1.0 2015-11-02 10 | 11 | The first commit 12 | 这是本项目的第一个版本 13 | 14 | -------------------------------------------------------------------------------- /include/Elite/Model/SeqNode.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SEQ_NODE_H 3 | #define SEQ_NODE_H 4 | 5 | #include "Elite/Model/Node.h" 6 | 7 | namespace Elite { 8 | class SeqNode : public Node { 9 | 10 | }; 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /.travis/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if [[ "$(uname -s)" == 'Darwin' ]]; then 7 | if which pyenv > /dev/null; then 8 | eval "$(pyenv init -)" 9 | fi 10 | pyenv activate conan 11 | fi 12 | 13 | codef build -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | po: index.po 2 | 3 | english: index.en.md 4 | 5 | %.en.md: %.po %.cn.md 6 | po4a-translate -M UTF-8 -f text -o markdown -m $(@:%.en.md=%.cn.md) -p $< -l $@ 7 | 8 | %.po: %.cn.md 9 | po4a-gettextize -M UTF-8 -f text -m $< -p $@ 10 | 11 | 12 | -------------------------------------------------------------------------------- /include/Elite/Model/nodes.h: -------------------------------------------------------------------------------- 1 | #include "Elite/Model/Node.h" 2 | #include "Elite/Model/CharNode.h" 3 | #include "Elite/Model/FloatNode.h" 4 | #include "Elite/Model/IDNode.h" 5 | #include "Elite/Model/IntNode.h" 6 | #include "Elite/Model/StringNode.h" 7 | #include "Elite/Model/TypeNode.h" 8 | -------------------------------------------------------------------------------- /runtime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET (CMAKE_CXX_FLAGS "-std=c++11") 2 | include_directories(src lib/dyncall) 3 | file(GLOB_RECURSE runtime_source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 4 | 5 | add_library(runtime STATIC ${runtime_source_files} ) 6 | install(TARGETS runtime ARCHIVE DESTINATION runtime) 7 | -------------------------------------------------------------------------------- /src/LLCG/llcg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-23 21:43:28 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-24 11:01:39 6 | */ 7 | 8 | #include "Elite/LLCG/llcg.h" 9 | #include "LLCG/LLVMLIB/llcg_llvm.h" 10 | 11 | llcg* llcg::CreateLLVM() { 12 | return new llcg_llvm(); 13 | } 14 | -------------------------------------------------------------------------------- /src/Parser/GrammarParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Elite/Model/nodes.h" 4 | #include 5 | 6 | namespace Elite 7 | { 8 | 9 | class GrammarParser { 10 | public: 11 | Node* Parse(const std::string& data); 12 | Node* ParseFile(const std::string& file_path); 13 | 14 | 15 | }; 16 | 17 | } -------------------------------------------------------------------------------- /doc/misc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /include/Elite/Model/ByteNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #ifndef _BYTENODE_H 7 | #define _BYTENODE_H 8 | 9 | #include "Elite/Model/Node.h" 10 | 11 | namespace Elite 12 | { 13 | 14 | class ByteNode: public Node { 15 | public: 16 | char value; 17 | 18 | // virtual Value* codeGen(CodeGenContext* context); 19 | }; 20 | 21 | } 22 | #endif //_BYTENODE_H -------------------------------------------------------------------------------- /src/MetaModel/MapModel.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Elite/MetaModel/MapModel.h" 3 | #include "Translater/idmap.h" 4 | 5 | MapModel::MapModel (const string& name) 6 | : MetaModel(name) { 7 | 8 | } 9 | 10 | MapModel::~MapModel () { 11 | 12 | } 13 | 14 | 15 | id* MapModel::find(const string& name) { 16 | auto p = data.find(name); 17 | if (p != data.end()) return p->second; 18 | return NULL; 19 | } 20 | -------------------------------------------------------------------------------- /include/Elite/Model/CharNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #ifndef _CHARNODE_H 7 | #define _CHARNODE_H 8 | 9 | #include "Elite/Model/Node.h" 10 | 11 | namespace Elite 12 | { 13 | class CharNode: public Node { 14 | public: 15 | char value; 16 | 17 | CharNode(char* v) { 18 | value = *v; 19 | } 20 | 21 | // virtual Value* codeGen(CodeGenContext* context); 22 | }; 23 | 24 | } 25 | #endif //_CHARNODE_H -------------------------------------------------------------------------------- /src/Parser/GrammarParser.cpp: -------------------------------------------------------------------------------- 1 | #include "GrammarParser.h" 2 | 3 | namespace Elite 4 | { 5 | 6 | Node* GrammarParser::Parse(const std::string& data) { 7 | yyscan_t sc; 8 | int res; 9 | yylex_init(&sc); 10 | yyset_in(src, sc); 11 | res = yyparse(sc, this); 12 | yylex_destroy(sc); 13 | return model; 14 | } 15 | } 16 | 17 | Node* GrammarParser::ParseFile(const std::string& file_path) { 18 | 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: WebKit 2 | IndentWidth: 4 3 | 4 | AllowShortCaseLabelsOnASingleLine: true 5 | AllowShortFunctionsOnASingleLine: true 6 | AccessModifierOffset: -4 7 | 8 | BraceWrapping: 9 | AfterEnum: false 10 | AfterStruct: false 11 | AfterClass: false 12 | AfterFunction: false 13 | AfterNamespace: false 14 | AfterUnion: false 15 | BeforeCatch: false 16 | BeforeElse: false 17 | 18 | CompactNamespaces: false -------------------------------------------------------------------------------- /src/Utils/StringEscape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-10-25 09:21:30 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-14 17:16:11 6 | */ 7 | 8 | 9 | #ifndef STRING_ESCAPE_H 10 | #define STRING_ESCAPE_H 11 | 12 | #include 13 | using namespace std; 14 | 15 | /** 16 | * @brief 字符串转义函数 17 | */ 18 | char* CharEscape(const char* str); 19 | string StringEscape(const string& str); 20 | 21 | #endif // STRING_ESCAPE_H 22 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | build: false 2 | clone_depth: 3 3 | 4 | environment: 5 | PYTHON: "C:\\Python27" 6 | PYTHON_VERSION: "2.7.11" 7 | PYTHON_ARCH: "32" 8 | 9 | install: 10 | # - git submodule update --init --recursive 11 | - set PATH=%PATH%;%PYTHON%/Scripts/ 12 | - pip.exe install conan_package_tools # It install conan too 13 | - conan user sunxfancy # It creates the conan data directory 14 | 15 | build_script: 16 | - codef build 17 | -------------------------------------------------------------------------------- /test/apptest.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @Author: Sun Xiaofan 3 | * @Date: 2016-11-14 4 | * @Email: sunxfancy@gmail.com 5 | * @Last modified by: sxf 6 | * @Last modified time: 2016-11-14 7 | * @License: MIT License 8 | */ 9 | 10 | #include 11 | #include "Elite/Model/nodes.h" 12 | 13 | using namespace Elite; 14 | 15 | TEST(ModelTest, Basic) { 16 | Node* node = FloatNode::Create("3.1415926"); 17 | EXPECT_NE(node, nullptr); 18 | } -------------------------------------------------------------------------------- /include/Elite/CodeGen/ICodeGenFunction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-24 08:56:30 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 08:58:15 6 | */ 7 | 8 | #ifndef I_CODE_GEN_FUNCTION_H 9 | #define I_CODE_GEN_FUNCTION_H 10 | 11 | #include "Elite/Model/Node.h" 12 | #include "Elite/LLCG/llcg.h" 13 | class CodeGenContext; 14 | 15 | class ICodeGenFunction 16 | { 17 | public: 18 | virtual LValue call(CodeGenContext*, Node*) = 0; 19 | }; 20 | 21 | 22 | #endif // I_CODE_GEN_FUNCTION_H 23 | -------------------------------------------------------------------------------- /include/Elite/MetaModel/MapModel.h: -------------------------------------------------------------------------------- 1 | #ifndef MAP_MODEL_H 2 | #define MAP_MODEL_H 3 | 4 | #include "Elite/MetaModel/MetaModel.h" 5 | #include 6 | #include 7 | 8 | class MapModel : public MetaModel { 9 | public: 10 | MapModel (const string& name); 11 | virtual ~MapModel (); 12 | 13 | struct id* find(const string& name); 14 | 15 | protected: 16 | /* data */ 17 | std::map< std::string, struct id* > data; 18 | 19 | }; 20 | 21 | 22 | 23 | 24 | #endif /* end of include guard: MAP_MODEL_H */ 25 | -------------------------------------------------------------------------------- /src/Model/IntNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #include "Elite/Model/IntNode.h" 7 | #include 8 | #include "Utils/string_formatter.h" 9 | /** 10 | * IntNode implementation 11 | */ 12 | 13 | namespace Elite { 14 | 15 | IntNode* IntNode::Create(const char* num) { 16 | return new IntNode(num); 17 | } 18 | 19 | IntNode::IntNode(const char* num) { 20 | value = atoi(num); 21 | } 22 | 23 | void IntNode::printSelf() { 24 | } 25 | 26 | NodeType IntNode::getType() { 27 | return int_node_t; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /src/MetaModel/MetaModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-14 14:33:49 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 09:46:33 6 | */ 7 | 8 | #include "Elite/MetaModel/MetaModel.h" 9 | #include "Elite/CodeGen/CodeGenContext.h" 10 | 11 | MetaModel::MetaModel(std::string name) { 12 | this->name = name; 13 | } 14 | 15 | MetaModel::~MetaModel() { 16 | 17 | } 18 | 19 | MetaModel* MetaModel::readJson() { 20 | return NULL; 21 | } 22 | 23 | MetaModel* MetaModel::readMetaCode() { 24 | return NULL; 25 | } 26 | -------------------------------------------------------------------------------- /doc/index.cn.md: -------------------------------------------------------------------------------- 1 | Elite 2 | ================== 3 | 4 | ## 其他语言文档 5 | 6 | - [English Documents](../index.html) 7 | - [中文文档](#) 8 | 9 | ## 加入我们 10 | 11 | 希望和我们交流非常容易,可以选择发邮件或在github上直接和我们联系,都可以。 12 | 13 | - github: 14 | - 邮箱: 15 | 16 | ## 开源协议 17 | 18 | MIT协议,允许任何人基于该项目开发其他项目,无论是开源的还是商业的,仅仅需要您在使用时,附带我们的版权声明即可。 19 | 20 | ## 关于本文档 21 | 22 | 本文档分为三部分,其一是用户帮助文档,其二是开发者文档,最后还包括全部代码的注释文档。本文档也属于开源项目的一部分,欢迎大家帮助我们完善和改进本文档。本文档使用Markdown格式编写,使用doxygen工具生成。 23 | 24 | 关于文档的构建与使用:[文件构建参考](md-doc.html) 25 | -------------------------------------------------------------------------------- /.travis/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if [[ "$(uname -s)" == 'Darwin' ]]; then 7 | brew update || brew update 8 | brew outdated pyenv || brew upgrade pyenv 9 | brew install pyenv-virtualenv 10 | 11 | if which pyenv > /dev/null; then 12 | eval "$(pyenv init -)" 13 | fi 14 | 15 | pyenv install 2.7.10 16 | pyenv virtualenv 2.7.10 conan 17 | pyenv rehash 18 | pyenv activate conan 19 | fi 20 | 21 | sudo pip install conan 22 | sudo pip install codefactory 23 | conan user sunxfancy -------------------------------------------------------------------------------- /cmake/ClangConf.cmake: -------------------------------------------------------------------------------- 1 | SET (CMAKE_CXX_COMPILER_ENV_VAR "clang++ ") 2 | SET (CMAKE_CXX_FLAGS_DEBUG "-g") 3 | SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 4 | SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG") 5 | SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") 6 | if (APPLE) 7 | SET (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") 8 | elseif(COVERAGE_FLAG) 9 | SET (CMAKE_CXX_FLAGS "-std=c++11 -coverage") 10 | else() 11 | SET (CMAKE_CXX_FLAGS "-std=c++11") 12 | endif() 13 | # SET (CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") 14 | # SET (CMAKE_SHARED_LINKER_FLAGS "-static-libgcc -static-libstdc++") 15 | -------------------------------------------------------------------------------- /src/LLCG/LLVMLIB/llvm_value.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-24 15:39:17 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-25 16:55:59 6 | */ 7 | 8 | #include "LLCG/LLVMLIB/llvm_value.h" 9 | #include "llvm/IR/DerivedTypes.h" 10 | #include "llvm/IR/Module.h" 11 | 12 | using namespace llvm; 13 | 14 | llvm_value::llvm_value(llvm::Value* v) { 15 | data = v; 16 | } 17 | 18 | llvm_value::~llvm_value() { 19 | 20 | } 21 | 22 | string llvm_value::getTypeName() { 23 | Type* t = data->getType(); 24 | StructType* st = (StructType*)(t->getPointerElementType()); 25 | return st->getName().str(); 26 | } -------------------------------------------------------------------------------- /include/Elite/Model/IntNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #ifndef _INTNODE_H 7 | #define _INTNODE_H 8 | 9 | #include "Elite/Model/Node.h" 10 | 11 | namespace Elite 12 | { 13 | class IntNode: public Node { 14 | public: 15 | static IntNode* Create(const char* num); 16 | // virtual LValue codeGen(CodeGenContext* context); 17 | virtual void printSelf(); 18 | virtual NodeType getType(); 19 | virtual std::string getTypeName(); 20 | virtual Node* copy() { 21 | return new IntNode(*this); 22 | } 23 | protected: 24 | IntNode(const char* num); 25 | int value; 26 | }; 27 | } // Elite 28 | 29 | #endif //_INTNODE_H -------------------------------------------------------------------------------- /Authors: -------------------------------------------------------------------------------- 1 | ## 请贡献者将自己添加到作者列表中,您的一点一滴贡献,都值得我们永远记忆 ## 2 | ## 我们也会定期检查并更新该列表,以确认是否全部贡献都得到记录 ## 3 | ## 以下列表按照字母序排列,母语非英语的贡献者可以将自己的母语名字添加到英文名后 ## 4 | 5 | ## Please contribute to the list of authors, your little bit of contribution, are worthy of our memory forever ## 6 | ## We also periodically check and update the list to see if all contributions have been recorded ## 7 | ## The following list is in alphabetical order, and contributors who are not native English speakers can add their native language names to English names ## 8 | 9 | 10 | Creator 11 | ------------- 12 | 13 | 14 | 15 | 16 | 17 | Contributor 18 | ------------- 19 | 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | git: 2 | depth: 3 3 | 4 | language: cpp 5 | 6 | compiler: 7 | - clang 8 | 9 | matrix: 10 | include: 11 | - os: linux 12 | dist: trusty 13 | sudo: required 14 | 15 | - os: osx 16 | osx_image: xcode7.3 17 | sudo: required 18 | 19 | addons: 20 | apt: 21 | packages: 22 | - clang 23 | - ninja-build 24 | 25 | before_install: 26 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi 27 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ninja; fi 28 | 29 | install: 30 | - bash ./.travis/install.sh 31 | 32 | script: 33 | - bash ./.travis/run.sh 34 | -------------------------------------------------------------------------------- /src/Model/FloatNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #include "Elite/Model/FloatNode.h" 7 | #include 8 | /** 9 | * FloatNode implementation 10 | */ 11 | 12 | namespace Elite{ 13 | 14 | FloatNode::FloatNode(const char* num) { 15 | value = atof(num); 16 | } 17 | 18 | FloatNode* FloatNode::Create(const char* num) { 19 | return new FloatNode(num); 20 | } 21 | 22 | NodeType FloatNode::getType() { 23 | return float_node_t; 24 | } 25 | 26 | std::string FloatNode::getTypeName() { 27 | return "float_node"; 28 | } 29 | 30 | float FloatNode::getFloat() { 31 | return value; 32 | } 33 | 34 | void FloatNode::printSelf() { 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/Model/IDNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #include "Elite/Model/IDNode.h" 7 | 8 | /** 9 | * IDNode implementation 10 | */ 11 | 12 | namespace Elite{ 13 | 14 | IDNode* IDNode::Create(const char* _value) { 15 | return new IDNode(_value); 16 | } 17 | 18 | IDNode* IDNode::Create(char _value) { 19 | return new IDNode(_value); 20 | } 21 | 22 | IDNode::IDNode(const char* _value){ 23 | this->value = _value; 24 | } 25 | IDNode::IDNode(char _value){ 26 | this->value = _value; 27 | } 28 | 29 | void IDNode::printSelf() { 30 | // printf("ID %s", value.c_str()); 31 | } 32 | 33 | NodeType IDNode::getType() { 34 | return id_node_t; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /include/Elite/Model/FloatNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #ifndef _FLOATNODE_H 7 | #define _FLOATNODE_H 8 | 9 | #include "Elite/Model/Node.h" 10 | #include 11 | 12 | namespace Elite 13 | { 14 | class FloatNode: public Node { 15 | public: 16 | static FloatNode* Create(const char* num); 17 | // virtual LValue codeGen(CodeGenContext* context); 18 | virtual NodeType getType(); 19 | virtual std::string getTypeName(); 20 | 21 | float getFloat(); 22 | virtual Node* copy() { 23 | return new FloatNode(*this); 24 | } 25 | protected: 26 | void printSelf(); 27 | float value; 28 | FloatNode(const char* num); 29 | }; 30 | 31 | } 32 | #endif //_FLOATNODE_H 33 | -------------------------------------------------------------------------------- /src/Translater/idmap.cpp: -------------------------------------------------------------------------------- 1 | #include "Translater/idmap.h" 2 | 3 | IDMap::IDMap() 4 | { 5 | } 6 | 7 | IDMap::~IDMap() 8 | { 9 | for (auto p : ID_map) { 10 | id* pid = p.second; 11 | delete pid; 12 | } 13 | } 14 | 15 | id* IDMap::find(const string& str) const { 16 | auto p = ID_map.find(str); 17 | if (p != ID_map.end()) 18 | return (*p).second; 19 | return NULL; 20 | } 21 | 22 | map& IDMap::getAll() { 23 | return ID_map; 24 | } 25 | 26 | void IDMap::insert(const string& str, int level, SymbolType type, LValue data) { 27 | id* i = new id(); 28 | i->level = level; 29 | i->type = type; 30 | i->data = data; 31 | ID_map[str] = i; 32 | } 33 | -------------------------------------------------------------------------------- /src/MetaModel/MacroModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-25 15:02:32 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 09:46:30 6 | */ 7 | 8 | #include "Elite/MetaModel/MacroModel.h" 9 | 10 | MacroModel::MacroModel(const std::string& name, Node* node) : MetaModel(name) { 11 | this->node = node; 12 | } 13 | 14 | MacroModel::~MacroModel() { 15 | 16 | } 17 | 18 | 19 | void MacroModel::insertToST(CodeGenContext* context) { 20 | 21 | } 22 | 23 | void MacroModel::genCode(CodeGenContext* context) { 24 | 25 | } 26 | 27 | 28 | void MacroModel::genMetaCode(CodeGenContext* context) { 29 | 30 | } 31 | 32 | MetaType MacroModel::getMetaType() { 33 | return macro_meta_t; 34 | } 35 | -------------------------------------------------------------------------------- /src/Translater/MacroTranslate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-17 17:11:42 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-14 17:09:06 6 | */ 7 | 8 | #ifndef MACRO_TRANSLATE_H 9 | #define MACRO_TRANSLATE_H 10 | 11 | #include 12 | #include 13 | #include "Elite/Model/Node.h" 14 | 15 | using namespace std; 16 | 17 | /** 18 | * @brief 宏翻译器, 可以支持用户自定义宏 19 | * @details 宏翻译器, 应该说是宏展开器, 能够根据用户的定义, 20 | * 将宏转换为真正的形式, 支持递归 21 | */ 22 | class MacroTranslate 23 | { 24 | public: 25 | Node* Marco(Node* node_template, Node* args); 26 | private: 27 | void marcoReplace(Node* node); 28 | Node* findArg(const string& name); 29 | map< string, Node* > args_map; 30 | }; 31 | 32 | 33 | 34 | #endif // MACRO_TRANSLATE_H 35 | -------------------------------------------------------------------------------- /src/LLCG/LLVMLIB/llvm_value.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-23 22:03:33 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-25 16:42:19 6 | */ 7 | 8 | #ifndef LLVM_VALUE_H 9 | #define LLVM_VALUE_H 10 | 11 | #include "Elite/LLCG/lvalue.h" 12 | 13 | class llvm_value; 14 | 15 | typedef shared_ptr LLVMValue; 16 | #define LLVALUE(T) dynamic_pointer_cast(T) 17 | 18 | namespace llvm { 19 | class Value; 20 | } // llvm 21 | 22 | class llvm_value : public lvalue 23 | { 24 | public: 25 | llvm_value(llvm::Value* v); 26 | virtual ~llvm_value(); 27 | 28 | operator llvm::Value* () const { return data; } 29 | virtual string getTypeName(); 30 | 31 | private: 32 | llvm::Value* data; 33 | }; 34 | 35 | 36 | 37 | #endif // LLVM_VALUE_H 38 | -------------------------------------------------------------------------------- /include/Elite/Model/IDNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Project Untitled 3 | */ 4 | 5 | 6 | #ifndef _IDNODE_H 7 | #define _IDNODE_H 8 | 9 | #include "Elite/Model/Node.h" 10 | #include 11 | 12 | namespace Elite 13 | { 14 | 15 | class IDNode: public Node { 16 | public: 17 | static IDNode* Create(const char* _value); 18 | static IDNode* Create(char _value); 19 | std::string& getStr() { return value; } 20 | // virtual LValue codeGen(CodeGenContext* context); 21 | virtual NodeType getType(); 22 | virtual std::string getTypeName(); 23 | virtual Node* copy() { 24 | return new IDNode(*this); 25 | } 26 | protected: 27 | IDNode(const char* _value); 28 | IDNode(char _value); 29 | virtual void printSelf(); 30 | private: 31 | std::string value; 32 | }; 33 | 34 | } // Elite 35 | 36 | #endif //_IDNODE_H -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 2 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | //! Custom strlen() which works on different character types. 8 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 9 | \param s Null-terminated input string. 10 | \return Number of characters in the string. 11 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 12 | */ 13 | template 14 | inline SizeType StrLen(const Ch* s) { 15 | const Ch* p = s; 16 | while (*p != '\0') 17 | ++p; 18 | return SizeType(p - s); 19 | } 20 | 21 | } // namespace internal 22 | } // namespace rapidjson 23 | 24 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 25 | -------------------------------------------------------------------------------- /include/Elite/MetaModel/MacroModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-25 15:01:05 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-21 16:52:50 6 | */ 7 | 8 | 9 | #ifndef MACRO_MODEL_H 10 | #define MACRO_MODEL_H 11 | 12 | #include "Elite/Model/Node.h" 13 | #include "Elite/MetaModel/MetaModel.h" 14 | 15 | /** 16 | * @brief 宏模型元类型 17 | */ 18 | class MacroModel : public MetaModel 19 | { 20 | public: 21 | MacroModel(const std::string& name, Node* node); 22 | ~MacroModel(); 23 | 24 | virtual void insertToST(CodeGenContext* context); 25 | virtual void genCode(CodeGenContext* context); 26 | virtual void genMetaCode(CodeGenContext* context); 27 | virtual MetaType getMetaType(); 28 | 29 | Node* getData() { return node; } 30 | private: 31 | Node* node; 32 | }; 33 | 34 | 35 | #endif // MACRO_MODEL_H 36 | -------------------------------------------------------------------------------- /src/LLCG/LLVMLIB/llvm_type.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-24 15:40:26 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-21 17:08:13 6 | */ 7 | 8 | #include "LLCG/LLVMLIB/llvm_type.h" 9 | #include "llvm/IR/DerivedTypes.h" 10 | #include "llvm/Support/raw_ostream.h" 11 | using namespace llvm; 12 | 13 | llvm_type::llvm_type(llvm::Type* v) { 14 | data = v; 15 | } 16 | 17 | llvm_type::~llvm_type() { 18 | 19 | } 20 | 21 | bool llvm_type::isStructType() { 22 | return data->isStructTy(); 23 | } 24 | 25 | 26 | string llvm_type::getTypeName() { 27 | if (data->isStructTy()) { 28 | StructType* st = (StructType*) data; 29 | return st->getName().str(); 30 | } 31 | return ""; 32 | } 33 | 34 | LValue llvm_type::getPointerTo() { 35 | Type* t = data->getPointerTo(); 36 | return LValue(new llvm_type(t)); 37 | } -------------------------------------------------------------------------------- /src/LLCG/LLVMLIB/llvm_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-24 08:43:52 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-21 16:44:22 6 | */ 7 | 8 | 9 | #ifndef LLVM_TYPE_H 10 | #define LLVM_TYPE_H 11 | 12 | #include "Elite/LLCG/lvalue.h" 13 | 14 | class llvm_type; 15 | 16 | typedef shared_ptr LLVMType; 17 | #define LLTYPE(T) dynamic_pointer_cast(T) 18 | 19 | namespace llvm { 20 | class Type; 21 | } // llvm 22 | 23 | class llvm_type : public lvalue 24 | { 25 | public: 26 | llvm_type(llvm::Type* v); 27 | virtual ~llvm_type(); 28 | 29 | operator llvm::Type* () const { return data; } 30 | virtual bool isStructType(); 31 | virtual string getTypeName(); 32 | virtual LValue getPointerTo(); 33 | private: 34 | llvm::Type* data; 35 | }; 36 | 37 | 38 | 39 | #endif // LLVM_TYPE_H 40 | -------------------------------------------------------------------------------- /header_libs/elegantlist.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ELEGANT_LIST_H 2 | #define ELEGANT_LIST_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | class ElegantList { 11 | public: 12 | ElegantList() : os(std::cout) {} 13 | ElegantList(ostream& out_stream) : os(out_stream) {} 14 | 15 | void print(const string& data) { 16 | if (data == "(") { 17 | os << endl; 18 | ++level; 19 | printTab(); 20 | } 21 | os << data << ' '; 22 | if (data == ")") { 23 | --level; 24 | } 25 | } 26 | private: 27 | void printTab() { 28 | for (int i = 1; i < level; ++i) 29 | os << " "; 30 | } 31 | ostream& os; 32 | int level; 33 | }; 34 | 35 | 36 | 37 | #endif /* end of include guard: ELEGANT_LIST_H */ 38 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | enable_testing() 2 | find_package(GTest REQUIRED) 3 | 4 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}) 5 | include_directories (${GTEST_INCLUDE_DIRS}) 6 | file(GLOB_RECURSE test_source_files ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 7 | 8 | add_executable (all_test ${test_source_files}) 9 | 10 | if (WIN32) 11 | set(PTHREAD "") 12 | else() 13 | set(PTHREAD pthread) 14 | endif() 15 | 16 | target_link_libraries(all_test 17 | ${PROJECT_NAME} 18 | ${GTEST_BOTH_LIBRARIES} 19 | ${PTHREAD}) 20 | 21 | add_test(AllTest all_test) 22 | 23 | add_custom_target( runtest ALL 24 | DEPENDS all_test) 25 | 26 | add_custom_command(TARGET runtest 27 | POST_BUILD 28 | COMMAND all_test) 29 | -------------------------------------------------------------------------------- /include/Elite/LLCG/lvalue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-23 10:54:27 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-18 23:05:26 6 | */ 7 | 8 | 9 | #ifndef LVALUE_H 10 | #define LVALUE_H 11 | 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | class lvalue; 18 | typedef shared_ptr LValue; 19 | 20 | /** 21 | * @brief 代替LLVM中Value的类,可供返回部分自定义数据,例如整数有无符号等信息 22 | */ 23 | class lvalue 24 | { 25 | public: 26 | virtual bool isStructType() { 27 | return false; 28 | } 29 | 30 | // 当前为值时,获取当前的类型 31 | virtual LValue getType() { 32 | return NULL; 33 | } 34 | 35 | // 当前为值或类型,都能获得对应的名称 36 | virtual string getTypeName() { 37 | return ""; 38 | } 39 | 40 | // 当前为类型时, 返回一个新的指针类型 41 | virtual LValue getPointerTo() { 42 | return NULL; 43 | } 44 | 45 | }; 46 | 47 | 48 | 49 | #endif // LVALUE_H 50 | -------------------------------------------------------------------------------- /include/Elite/Model/ModelException.h: -------------------------------------------------------------------------------- 1 | #ifndef MODEL_EXCEPTION_H 2 | #define MODEL_EXCEPTION_H 3 | 4 | #include 5 | #include 6 | namespace Elite { 7 | 8 | class InvalidMethod : public std::exception { 9 | public: 10 | InvalidMethod(const char* func_name, const char* msg) : std::exception() { 11 | this->func_name = func_name; 12 | this->msg += msg; 13 | this->msg += " ("; 14 | this->msg += func_name; 15 | this->msg += ")\n"; 16 | } 17 | virtual const char* what() const noexcept { 18 | return msg.c_str(); 19 | } 20 | std::string msg; 21 | const char* func_name; 22 | }; 23 | 24 | class FunctionNotImplement : public std::exception { 25 | virtual const char* what() const noexcept { 26 | return "You have called an unimplemented function."; 27 | } 28 | }; 29 | 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /include/Elite/CodeGen/CodeGen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-11 13:57:49 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-14 16:56:32 6 | */ 7 | 8 | 9 | #ifndef CODE_GEN_H 10 | #define CODE_GEN_H 11 | 12 | #include 13 | 14 | class Node; 15 | 16 | 17 | /** 18 | * @brief 代码生成器的接口类 19 | * @details 代码生成器的接口 20 | * 使用RedApple后端代码生成器时,核心功能可以通过该接口调用 21 | * 首先调用Init初始化该生成器, 之后对全部定义头文件进行Prescan 22 | * 接着对每一个要编译的目标文件调用Make, 23 | * 最后调用MakeMeta 24 | */ 25 | class CodeGen 26 | { 27 | public: 28 | virtual void Init() = 0; 29 | virtual void PreScan(Node* node) = 0; 30 | virtual void PreScan(std::set& nodes) = 0; 31 | virtual void Make(Node* node, const char* outfile_name, const char* module_name = "") = 0; 32 | virtual void MakeMeta(const char* outfile_name, const char* module_name = "") = 0; 33 | }; 34 | 35 | #endif // CODE_GEN_H 36 | -------------------------------------------------------------------------------- /include/Elite/Model/StringNode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-09-22 22:00:32 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-25 15:46:49 6 | */ 7 | 8 | #ifndef STRING_NODE_H 9 | #define STRING_NODE_H 10 | 11 | #include "Elite/Model/Node.h" 12 | 13 | namespace Elite { 14 | class StringNode : public Node 15 | { 16 | public: 17 | static StringNode* Create(const char* _value); 18 | static StringNode* Create(char _value); 19 | std::string& getStr() { return value; } 20 | // virtual LValue codeGen(CodeGenContext* context); 21 | virtual NodeType getType(); 22 | virtual std::string getTypeName(); 23 | virtual Node* copy() { 24 | return new StringNode(*this); 25 | } 26 | protected: 27 | virtual void printSelf(); 28 | StringNode(const char* _value); 29 | StringNode(char _value); 30 | private: 31 | std::string value; 32 | }; 33 | 34 | } 35 | 36 | 37 | #endif // STRING_NODE_H 38 | -------------------------------------------------------------------------------- /src/Translater/idtable.cpp: -------------------------------------------------------------------------------- 1 | #include "Translater/idtable.h" 2 | 3 | IDTable::IDTable() 4 | { 5 | ID_stack.push_back(IDMap()); 6 | } 7 | 8 | id* IDTable::find(const string& idname) const { 9 | for (auto p = ID_stack.rbegin(); p != ID_stack.rend(); ++p) { 10 | const IDMap& imap = *p; 11 | id* pid = imap.find(idname); 12 | if (pid != NULL) return pid; 13 | } 14 | return NULL; 15 | } 16 | 17 | map& IDTable::getAll(int level) { 18 | return ID_stack[level].getAll(); 19 | } 20 | 21 | void IDTable::insert(const string& str,SymbolType type, LValue data) { 22 | IDMap& imap = ID_stack.back(); 23 | imap.insert(str,getLevel(), type, data); 24 | } 25 | 26 | void IDTable::push() { 27 | ID_stack.push_back(IDMap()); 28 | } 29 | 30 | void IDTable::pop() { 31 | ID_stack.pop_back(); 32 | } 33 | 34 | int IDTable::getLevel() { 35 | return ID_stack.size()-1; 36 | } 37 | -------------------------------------------------------------------------------- /src/Utils/string_formatter.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_FORMATTER 2 | #define STRING_FORMATTER 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // TODO: 这里有Windows和Linux下snprintf功能不同的隐藏bug 11 | // linux下 sprintf会自动在后面加'/0',同时copy的长度也包含了‘/0’, 12 | // 但windows下的_snprintf并未按照该规则,就是简单的copy指定长度的字符,不自动加0,并且长度也不包含0。 13 | 14 | #ifdef __GNUC__ 15 | #define _snprintf snprintf 16 | #endif 17 | 18 | 19 | template 20 | std::string string_format( const std::string& format, Args ... args ) 21 | { 22 | size_t size = _snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0' 23 | std::unique_ptr buf( new char[ size ] ); 24 | _snprintf(buf.get(), size, format.c_str(), args ...); 25 | return std::string( buf.get(), buf.get() + size - 1 ); // We don't want the '\0' inside 26 | } 27 | 28 | 29 | #endif /* end of include guard: STRING_FORMATTER */ 30 | -------------------------------------------------------------------------------- /src/CodeGen/CodeGenFunction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-19 10:44:37 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 09:10:42 6 | */ 7 | 8 | #include "Elite/CodeGen/CodeGenFunction.h" 9 | #include "Elite/CodeGen/CodeGenContext.h" 10 | 11 | CodeGenFunction::CodeGenFunction() { 12 | } 13 | 14 | CodeGenFunction::CodeGenFunction(CodeGenCFunction _cfunc) { 15 | *this = _cfunc; 16 | } 17 | 18 | const CodeGenFunction& CodeGenFunction::operator= (const CodeGenFunction& obj) { 19 | this->cfunc = obj.cfunc; 20 | return *this; 21 | } 22 | 23 | const CodeGenFunction& CodeGenFunction::operator= (CodeGenCFunction _cfunc) { 24 | this->cfunc = _cfunc; 25 | return *this; 26 | } 27 | 28 | LValue CodeGenFunction::call(CodeGenContext* ctx, Node* n) { 29 | CodeGenCFunction f = getCFunc(); 30 | return f(ctx, n); 31 | } 32 | 33 | CodeGenCFunction CodeGenFunction::getCFunc() { 34 | return this->cfunc; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/Model/StringNode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-09-22 22:00:32 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-16 22:42:02 6 | */ 7 | 8 | 9 | #include "Elite/Model/StringNode.h" 10 | #include "Utils/StringEscape.h" 11 | 12 | namespace Elite { 13 | StringNode::StringNode(const char* _value){ 14 | string data = _value; 15 | if (data[0] == '@') 16 | this->value = data.substr(2, data.length()-3); 17 | else 18 | this->value = StringEscape(data.substr(1, data.length()-2)); 19 | } 20 | 21 | StringNode::StringNode(char _value){ 22 | this->value = _value; 23 | } 24 | 25 | StringNode* StringNode::Create(const char* _value) { 26 | return new StringNode(_value); 27 | } 28 | 29 | StringNode* StringNode::Create(char _value) { 30 | return new StringNode(_value); 31 | } 32 | 33 | 34 | void StringNode::printSelf() { 35 | // printf("String %s", value.c_str()); 36 | } 37 | 38 | NodeType StringNode::getType() { 39 | return string_node_t; 40 | } 41 | } -------------------------------------------------------------------------------- /src/Utils/StringEscape.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Utils/StringEscape.h" 3 | #include 4 | #include 5 | 6 | char StringEscapeGetChar(const char*& p) { 7 | ++p; char c; 8 | switch(*p) { 9 | case 'a': c = '\a'; break; 10 | case 'b': c = '\b'; break; 11 | case 'f': c = '\f'; break; 12 | case 'n': c = '\n'; break; 13 | case 'r': c = '\r'; break; 14 | case 't': c = '\t'; break; 15 | case 'v': c = '\v'; break; 16 | case '0': c = '\0'; break; 17 | default: c = *p; 18 | } 19 | return c; 20 | } 21 | 22 | char* CharEscape(const char* str) { 23 | int len = strlen(str); 24 | char* ret = new char[len+1]; 25 | char* ans = ret; 26 | for (const char* p = str; *p != 0; ++p, ++ans) { 27 | if (*p != '\\') 28 | *ans = *p; 29 | else 30 | *ans = StringEscapeGetChar(p); 31 | } 32 | *ans = 0; 33 | return ret; 34 | } 35 | 36 | string StringEscape(const string& str) { 37 | char* c = CharEscape(str.c_str()); 38 | string s = c; 39 | delete[] c; 40 | return s; 41 | } 42 | -------------------------------------------------------------------------------- /include/Elite/MetaModel/MetaModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-13 17:08:01 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-18 23:05:21 6 | */ 7 | 8 | 9 | #ifndef META_MODEL_H 10 | #define META_MODEL_H 11 | 12 | #include 13 | #include "Elite/LLCG/lvalue.h" 14 | 15 | 16 | 17 | enum MetaType 18 | { 19 | struct_meta_t, function_meta_t, macro_meta_t, map_meta_t 20 | }; 21 | 22 | class CodeGenContext; 23 | 24 | /** 25 | * @brief 元数据模型基类 26 | */ 27 | class MetaModel : public lvalue 28 | { 29 | public: 30 | MetaModel(std::string); 31 | virtual ~MetaModel(); 32 | 33 | virtual void insertToST(CodeGenContext* context) = 0; 34 | virtual void genCode(CodeGenContext* context) = 0; 35 | virtual void genMetaCode(CodeGenContext* context) = 0; 36 | virtual MetaType getMetaType() = 0; 37 | 38 | static MetaModel* readJson(); 39 | static MetaModel* readMetaCode(); 40 | protected: 41 | std::string name; 42 | }; 43 | 44 | 45 | 46 | #endif // META_MODEL_H 47 | -------------------------------------------------------------------------------- /include/Elite/CodeGen/RedCodeGen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-09-23 22:55:30 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-26 14:28:25 6 | * 7 | * 代码生成部分的引导类 8 | */ 9 | 10 | #ifndef RED_CODE_GEN_H 11 | #define RED_CODE_GEN_H 12 | 13 | #include "Elite/Model/Node.h" 14 | #include "Elite/CodeGen/CodeGen.h" 15 | #include "Elite/Translater/PassManager.h" 16 | 17 | 18 | class CodeGenContext; 19 | class RedCodeGen : public CodeGen 20 | { 21 | public: 22 | virtual void Init(); 23 | virtual void PreScan(Node* node); 24 | virtual void PreScan(std::set& nodes); 25 | virtual void Make(Node* node, const char* outfile_name, const char* module_name); 26 | virtual void MakeMeta(const char* outfile_name, const char* module_name); 27 | 28 | static RedCodeGen* Create(); 29 | 30 | CodeGenContext* getContext() { return context; } 31 | private: 32 | RedCodeGen(); 33 | ~RedCodeGen(); 34 | CodeGenContext* context = NULL; 35 | PassManager pm; 36 | }; 37 | 38 | 39 | 40 | #endif // RED_CODE_GEN_H 41 | -------------------------------------------------------------------------------- /include/Elite/Translater/PassManager.h: -------------------------------------------------------------------------------- 1 | #ifndef PASS_MANAGER_H 2 | #define PASS_MANAGER_H 3 | 4 | #include "Elite/Translater/Pass.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | class ICodeGenContext; 12 | 13 | class PassManager { 14 | public: 15 | PassManager (); 16 | virtual ~PassManager (); 17 | 18 | void NewPassList(const string& name, const vector& vec); 19 | 20 | void NewPassList(const string& name, const list& lst); 21 | 22 | list* getPassList(const string& name); 23 | 24 | void RunPassList(const string& name, Node* node, ICodeGenContext* ctx); 25 | 26 | void RunPassListWithSet(const string& name, set& nodes, ICodeGenContext* ctx); 27 | 28 | void LoadDefaultLists(); 29 | 30 | protected: 31 | /* data */ 32 | 33 | /** 34 | * 所有PassList的存储位置 35 | */ 36 | map > pass_lists; 37 | }; 38 | 39 | 40 | #endif /* end of include guard: PASS_MANAGER_H */ 41 | -------------------------------------------------------------------------------- /include/Elite/MetaModel/StructModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-10-29 10:47:04 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-14 17:17:28 6 | */ 7 | 8 | #ifndef STRUCT_MODEL_H 9 | #define STRUCT_MODEL_H 10 | 11 | #include "Elite/MetaModel/MetaModel.h" 12 | #include 13 | #include 14 | 15 | /** 16 | * @brief 结构体类型元类型 17 | */ 18 | class StructModel : public MetaModel 19 | { 20 | public: 21 | StructModel(std::string& name, 22 | std::vector& type_list, 23 | std::vector& name_list); 24 | 25 | int find(std::string& name); 26 | 27 | std::vector type_list; 28 | std::vector name_list; 29 | LValue getStruct(CodeGenContext* context); 30 | 31 | virtual void insertToST(CodeGenContext* context); 32 | virtual void genCode(CodeGenContext* context); 33 | virtual void genMetaCode(CodeGenContext* context); 34 | virtual MetaType getMetaType(); 35 | private: 36 | LValue struct_type; 37 | }; 38 | 39 | 40 | 41 | #endif // STRUCT_MODEL_H 42 | -------------------------------------------------------------------------------- /cmake/CombineHeader.cmake: -------------------------------------------------------------------------------- 1 | 2 | 3 | ADD_CUSTOM_TARGET(header 4 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../ExIconv/include header 5 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../Lex/include header 6 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../LR_Scanner/includes header 7 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../RedApple/includes header 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../Builder/include header 9 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../MetaScriptRunner/include header 10 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 11 | COMMENT "Generating headers" 12 | VERBATIM) 13 | 14 | install(DIRECTORY 15 | ${CMAKE_CURRENT_SOURCE_DIR}/build/header 16 | DESTINATION . 17 | FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 18 | GROUP_EXECUTE GROUP_READ WORLD_READ 19 | DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 20 | GROUP_EXECUTE GROUP_READ WORLD_READ 21 | COMPONENT header 22 | PATTERN ".git" EXCLUDE) 23 | -------------------------------------------------------------------------------- /include/Elite/CodeGen/CodeGenFunction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-19 10:43:27 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 09:10:10 6 | */ 7 | 8 | 9 | #ifndef CODE_GEN_FUNCTION_H 10 | #define CODE_GEN_FUNCTION_H 11 | 12 | 13 | #include "Elite/CodeGen/ICodeGenFunction.h" 14 | 15 | /** 16 | * @brief 定义宏翻译函数指针 17 | */ 18 | typedef LValue (*CodeGenCFunction)(CodeGenContext*, Node*); 19 | 20 | class CodeGenFunction : public ICodeGenFunction 21 | { 22 | public: 23 | CodeGenFunction(); 24 | CodeGenFunction(CodeGenCFunction _cfunc); 25 | const CodeGenFunction& operator=(const CodeGenFunction& obj); 26 | const CodeGenFunction& operator=(CodeGenCFunction _cfunc); 27 | 28 | virtual LValue call(CodeGenContext*, Node*); 29 | CodeGenCFunction getCFunc(); 30 | 31 | private: 32 | CodeGenCFunction cfunc; 33 | }; 34 | 35 | /** 36 | * @brief 宏翻译函数注册结构体 37 | * @details name 为宏名, func 为函数指针 38 | */ 39 | typedef struct _funcReg 40 | { 41 | const char* name; 42 | CodeGenCFunction func; 43 | } FuncReg; 44 | 45 | 46 | 47 | #endif // CODE_GEN_FUNCTION_H 48 | -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidjson/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011 Milo Yip 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Xiaofan Sun 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /include/Elite/Model/TypeNode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-19 11:22:12 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-25 15:47:07 6 | */ 7 | 8 | #ifndef TYPE_NODE_H 9 | #define TYPE_NODE_H 10 | 11 | #include "Elite/Model/Node.h" 12 | 13 | // namespace llvm { 14 | // class Type; 15 | // } // llvm 16 | 17 | namespace Elite { 18 | class TypeNode: public Node { 19 | public: 20 | static TypeNode* Create(const char* name, bool is_const = false, bool is_source = false); 21 | // LValue typeGen(CodeGenContext* context); 22 | void addDimension(); 23 | bool isArray() { 24 | return dimension == 0; 25 | } 26 | 27 | virtual NodeType getType(); 28 | virtual std::string& getStr(); 29 | virtual std::string getTypeName(); 30 | 31 | virtual Node* copy() { 32 | return new TypeNode(*this); 33 | } 34 | protected: 35 | virtual void printSelf(); 36 | std::string str; 37 | std::string name; 38 | bool is_const = false; 39 | bool is_source = false; // 这个只在函数是结构体时有用,来设置真正的原型类型 40 | int dimension = 0; 41 | TypeNode(const char* name, bool is_const = false, bool is_source = false); 42 | }; 43 | 44 | } 45 | 46 | #endif // TYPE_NODE_H 47 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FIND_PACKAGE(Doxygen) 2 | OPTION(BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND}) 3 | 4 | IF(BUILD_DOCUMENTATION) 5 | IF(NOT DOXYGEN_FOUND) 6 | MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.") 7 | ENDIF() 8 | 9 | CONFIGURE_FILE(Doxyfile.in Doxyfile @ONLY) 10 | CONFIGURE_FILE(Doxyfile.zh-cn.in Doxyfile.zh-cn @ONLY) 11 | 12 | file(GLOB_RECURSE MARKDOWN_DOC ${PROJECT_SOURCE_DIR}/doc/*.md) 13 | 14 | add_custom_command(OUTPUT html 15 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile 16 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.zh-cn 17 | DEPENDS ${MARKDOWN_DOC} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.zh-cn 18 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 19 | ) 20 | 21 | ADD_CUSTOM_TARGET(doc 22 | DEPENDS html 23 | COMMENT "Generating API documentation with Doxygen" 24 | VERBATIM) 25 | 26 | INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/build-doc/html DESTINATION doc COMPONENT doc) 27 | ENDIF() 28 | -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidjson/filestream.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_FILESTREAM_H_ 2 | #define RAPIDJSON_FILESTREAM_H_ 3 | 4 | #include 5 | 6 | namespace rapidjson { 7 | 8 | //! Wrapper of C file stream for input or output. 9 | /*! 10 | This simple wrapper does not check the validity of the stream. 11 | \implements Stream 12 | */ 13 | class FileStream { 14 | public: 15 | typedef char Ch; //!< Character type. Only support char. 16 | 17 | FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); } 18 | 19 | char Peek() const { return current_; } 20 | char Take() { char c = current_; Read(); return c; } 21 | size_t Tell() const { return count_; } 22 | void Put(char c) { fputc(c, fp_); } 23 | 24 | // Not implemented 25 | char* PutBegin() { return 0; } 26 | size_t PutEnd(char*) { return 0; } 27 | 28 | private: 29 | void Read() { 30 | RAPIDJSON_ASSERT(fp_ != 0); 31 | int c = fgetc(fp_); 32 | if (c != EOF) { 33 | current_ = (char)c; 34 | count_++; 35 | } 36 | else 37 | current_ = '\0'; 38 | } 39 | 40 | FILE* fp_; 41 | char current_; 42 | size_t count_; 43 | }; 44 | 45 | } // namespace rapidjson 46 | 47 | #endif // RAPIDJSON_FILESTREAM_H_ 48 | -------------------------------------------------------------------------------- /include/Elite/MetaModel/FunctionModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-13 12:07:03 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-14 17:16:42 6 | */ 7 | 8 | 9 | #ifndef FUNCTION_MODEL_H 10 | #define FUNCTION_MODEL_H 11 | 12 | #include "Elite/MetaModel/MetaModel.h" 13 | #include 14 | #include 15 | 16 | /** 17 | * @brief 函数模型元类型 18 | */ 19 | class FunctionModel : public MetaModel 20 | { 21 | public: 22 | FunctionModel( 23 | std::string& name, 24 | std::string& ret_type, 25 | std::vector& type_list, 26 | std::vector& name_list 27 | ); 28 | 29 | int find(std::string& name); 30 | 31 | std::string return_type; 32 | std::vector type_list; 33 | std::vector name_list; 34 | 35 | LValue getFunction(CodeGenContext* context); 36 | LValue getFunctionType() { return func_type; } 37 | 38 | virtual void insertToST(CodeGenContext* context); 39 | virtual void genCode(CodeGenContext* context); 40 | virtual void genMetaCode(CodeGenContext* context); 41 | virtual MetaType getMetaType(); 42 | private: 43 | LValue func_type; 44 | }; 45 | 46 | 47 | 48 | #endif // FUNCTION_MODEL_H 49 | -------------------------------------------------------------------------------- /src/Model/ModelCodeGen.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-10-12 19:21:50 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-25 21:58:03 6 | */ 7 | 8 | // #include "Elite/CodeGen/CodeGenContext.h" 9 | #include "Elite/Model/nodes.h" 10 | 11 | #include 12 | using namespace std; 13 | 14 | namespace Elite { 15 | 16 | // LValue Node::codeGen(CodeGenContext* context) { 17 | // return context->MacroMake(this); 18 | // } 19 | 20 | // LValue IntNode::codeGen(CodeGenContext* context) { 21 | // return context->getLLCG()->ConstInt(value); 22 | // } 23 | 24 | // LValue FloatNode::codeGen(CodeGenContext* context) { 25 | // return context->getLLCG()->ConstDouble(value); 26 | // } 27 | 28 | 29 | // LValue StringNode::codeGen(CodeGenContext* context) { 30 | // return context->getLLCG()->ConstString(value); 31 | // } 32 | 33 | // LValue IDNode::codeGen(CodeGenContext* context) { 34 | // LValue v = context->FindVar(value); 35 | // if (v == NULL) { 36 | // cerr << "未定义的变量: " << value << endl; 37 | // return NULL; 38 | // } 39 | // if (context->isSave()) return v; 40 | // return context->getLLCG()->Load(v); 41 | // } 42 | 43 | 44 | } -------------------------------------------------------------------------------- /conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake, tools 2 | 3 | class EliteConan(ConanFile): 4 | name = "Elite" 5 | version = "0.1.0" 6 | license = "" 7 | url = "" 8 | settings = "os", "compiler", "build_type", "arch" 9 | options = {"shared": [True, False]} 10 | default_options = "shared=False", "gtest:shared=False" 11 | generators = "cmake" 12 | build_policy = "missing" 13 | requires = 'gtest/1.8.0@sunxfancy/stable' #, 'llvm/7.0.0@sunxfancy/stable' 14 | exports = "*" 15 | 16 | def build(self): 17 | cmake = CMake(self) 18 | cmake.configure() 19 | cmake.build() 20 | 21 | def package(self): 22 | self.copy("*.h", dst="include", src="include") 23 | self.copy("*.lib", dst="lib", keep_path=False) 24 | self.copy("*.dll", dst="bin", keep_path=False) 25 | self.copy("*.so", dst="lib", keep_path=False) 26 | self.copy("*.dylib", dst="lib", keep_path=False) 27 | self.copy("*.a", dst="lib", keep_path=False) 28 | self.copy("LICENSE", dst=".", keep_path=False) 29 | 30 | def package_info(self): 31 | self.cpp_info.libs = [self.name] 32 | -------------------------------------------------------------------------------- /doc/misc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 |
22 | $searchbox 23 | 24 | 25 | -------------------------------------------------------------------------------- /doc/index.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE 2 | # Copyright (C) YEAR Free Software Foundation, Inc. 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "POT-Creation-Date: 2016-11-15 22:33+0800\n" 11 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 12 | "Last-Translator: FULL NAME \n" 13 | "Language-Team: LANGUAGE \n" 14 | "Language: \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=UTF-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | 19 | #. type: Plain text 20 | #: index.cn.md:47 21 | msgid "## 开源协议" 22 | msgstr "" 23 | 24 | #. type: Plain text 25 | #: index.cn.md:49 26 | msgid "MIT协议,允许任何人基于该项目开发其他项目,无论是开源的还是商业的,仅仅需要您在使用时,附带我们的版权声明即可。" 27 | msgstr "" 28 | 29 | #. type: Plain text 30 | #: index.cn.md:51 31 | msgid "## 关于本文档" 32 | msgstr "" 33 | 34 | #. type: Plain text 35 | #: index.cn.md:53 36 | msgid "本文档分为三部分,其一是用户帮助文档,其二是开发者文档,最后还包括全部代码的注释文档。本文档也属于开源项目的一部分,欢迎大家帮助我们完善和改进本文档。本文档使用Markdown格式编写,使用doxygen工具生成。" 37 | msgstr "" 38 | 39 | #. type: Plain text 40 | #: index.cn.md:54 41 | msgid "关于文档的构建与使用:[文件构建参考](md-doc.html)" 42 | msgstr "" 43 | -------------------------------------------------------------------------------- /src/Translater/idtable.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef IDTABLE_H 3 | #define IDTABLE_H 4 | 5 | 6 | #include "Translater/idmap.h" 7 | #include 8 | 9 | using namespace std; 10 | 11 | /** 12 | * @brief 简易栈式符号表,需要在进入函数后手动压栈等操作 13 | */ 14 | class IDTable 15 | { 16 | public: 17 | IDTable(); 18 | 19 | /** 20 | * @brief 查找元素是否在符号表中 21 | * @details 查找元素是否在当前符号表中,若当前符号栈不只一层,还好向上层符号表进行查找 22 | * 23 | * @param str 要查找的符号名 24 | * @return 若找到,返回id结构体的指针,无需释放内存。未找到返回NULL 25 | */ 26 | id* find(const string& str) const; 27 | 28 | /** 29 | * @brief 返回一层的全部元素 30 | * 31 | * @param level 返回一层的全部元素,level是传入的层级 32 | * @return 返回的元素map 33 | */ 34 | map& getAll(int level); 35 | 36 | /** 37 | * @brief 插入一个元素 38 | * 39 | * @param str 要插入的名称 40 | * @param type 类型的枚举 41 | * @param data 数据指针 42 | */ 43 | void insert(const string& str,SymbolType type, LValue data); 44 | 45 | /** 46 | * @brief 压栈,一般在进入新的符号区域,例如函数体中 47 | */ 48 | void push(); 49 | 50 | /** 51 | * @brief 弹栈,在离开一个符号区域时需要手动调用 52 | */ 53 | void pop(); 54 | 55 | /** 56 | * @brief 获取当前层级 57 | */ 58 | int getLevel(); 59 | 60 | private: 61 | deque ID_stack; 62 | }; 63 | 64 | #endif // IDTABLE_H 65 | -------------------------------------------------------------------------------- /src/Translater/idmap.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef IDMAP_H 3 | #define IDMAP_H 4 | 5 | #include "Elite/LLCG/lvalue.h" 6 | #include 7 | 8 | using namespace std; 9 | 10 | 11 | /** 12 | * 符号表中符号的基本类型 13 | */ 14 | enum SymbolType 15 | { 16 | var_t, type_t, struct_t, enum_t, delegate_t, function_t, macro_t, map_t, conditions_t 17 | }; 18 | 19 | /** 20 | * @brief 栈式符号表返回的临时对象, 用来打包类型信息和值等, 无需释放资源 21 | */ 22 | struct id { 23 | int level; 24 | SymbolType type; 25 | LValue data; 26 | }; 27 | 28 | 29 | /** 30 | * @brief 一款简单的栈式符号表,代表栈的一层 31 | * @details 简单的栈式符号表,负责一层局部符号,用Map构建,而存储的内容则是void*,使用时必须强制类型转换 32 | */ 33 | class IDMap 34 | { 35 | public: 36 | IDMap(); 37 | ~IDMap(); 38 | 39 | /** 40 | * @brief 查找一个符号,若不存在返回空 41 | * 42 | * @param str 符号名 43 | * @return 返回对应的id结构体指针,未找到返回NULL 44 | */ 45 | id* find(const string& str) const; 46 | 47 | /** 48 | * @brief 返回当前表中全部元素 49 | */ 50 | map& getAll(); 51 | 52 | /** 53 | * @brief 插入一个符号 54 | * 55 | * @param str 名字 56 | * @param level 当前层次 57 | * @param type 枚举类型 58 | * @param data 数据指针 59 | */ 60 | void insert(const string& str, int level, SymbolType type, LValue data); 61 | private: 62 | map ID_map; 63 | }; 64 | 65 | #endif // IDMAP_H 66 | -------------------------------------------------------------------------------- /src/Translater/Pass.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Elite/Translater/Pass.h" 3 | 4 | Pass::Pass (const FuncReg* macro_funcs) { 5 | AddOrReplaceMacros(macro_funcs); 6 | } 7 | 8 | Pass::Pass (const FuncReg* macro_funcs, const FuncReg* macro_funcs2) { 9 | AddOrReplaceMacros(macro_funcs); 10 | AddOrReplaceMacros(macro_funcs2); 11 | } 12 | 13 | Pass::~Pass () { 14 | 15 | } 16 | 17 | void Pass::Init() { 18 | 19 | } 20 | 21 | ICodeGenFunction* Pass::getMacro(const string& str) { 22 | auto func = macro_map.find(str); 23 | if (func != macro_map.end()) return func->second; 24 | else return NULL; 25 | } 26 | 27 | 28 | void Pass::AddOrReplaceMacros(const FuncReg* macro_funcs) { 29 | while (true) { 30 | const char* name = macro_funcs->name; 31 | CodeGenCFunction func = macro_funcs->func; 32 | if (name == 0) return; 33 | string fname = name; 34 | auto p = macro_map.find(fname); 35 | if (p != macro_map.end()) 36 | p->second = new CodeGenFunction(func); 37 | else 38 | macro_map[fname] = new CodeGenFunction(func); 39 | ++macro_funcs; 40 | } 41 | } 42 | 43 | void Pass::AddOrReplaceMacros(const string& name, ICodeGenFunction* func) { 44 | macro_map[name] = func; 45 | } 46 | 47 | void Pass::RemoveAllMacros() { 48 | macro_map.clear(); 49 | } 50 | 51 | 52 | void Pass::SaveMacros() { 53 | macro_save_stack.push(macro_map); 54 | } 55 | 56 | void Pass::RecoverMacros() { 57 | macro_map = macro_save_stack.top(); 58 | macro_save_stack.pop(); 59 | } 60 | -------------------------------------------------------------------------------- /src/Macro/Classes.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-10-26 14:05:30 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-25 15:35:28 6 | */ 7 | 8 | #include "Elite/CodeGen/CodeGenContext.h" 9 | #include "Elite/Model/StringNode.h" 10 | #include "Elite/Model/IDNode.h" 11 | #include 12 | #include "Elite/Translater/Pass.h" 13 | 14 | extern const FuncReg macro_classes_replace[]; 15 | 16 | static LValue class_macro(CodeGenContext* context, Node* node) { 17 | auto pass = context->getNowPass(); 18 | pass->SaveMacros(); 19 | pass->AddOrReplaceMacros(macro_classes_replace); 20 | 21 | 22 | pass->RecoverMacros(); 23 | return NULL; 24 | } 25 | 26 | static LValue module_macro(CodeGenContext* context, Node* node) { 27 | 28 | 29 | return NULL; 30 | } 31 | 32 | extern const FuncReg macro_funcs[]; 33 | 34 | static LValue function_macro(CodeGenContext* context, Node* node) { 35 | auto pass = context->getNowPass(); 36 | pass->SaveMacros(); 37 | pass->AddOrReplaceMacros(macro_funcs); 38 | 39 | pass->RecoverMacros(); 40 | return NULL; 41 | } 42 | 43 | static LValue set_macro(CodeGenContext* context, Node* node) { 44 | return NULL; 45 | } 46 | 47 | 48 | extern const FuncReg macro_classes_replace[] = { 49 | {"function", function_macro}, 50 | {"set", set_macro}, 51 | {NULL, NULL} 52 | }; 53 | 54 | 55 | extern const FuncReg macro_classes[] = { 56 | {"class", class_macro}, 57 | {"module", module_macro}, 58 | {NULL, NULL} 59 | }; 60 | -------------------------------------------------------------------------------- /src/Translater/MacroTranslate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-17 18:33:42 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-17 20:51:34 6 | */ 7 | 8 | #include "Translater/MacroTranslate.h" 9 | 10 | Node* MacroTranslate::Marco(Node* node_template, Node* args) { 11 | // 第一个参数 宏参数表 12 | Node* node = node_template->getChild(); 13 | for (Node* p = node; p != NULL; p = p->getNext(), args = args->getNext()) { 14 | string name = p->getStr(); 15 | args_map[name] = args; 16 | } 17 | 18 | // 第二个参数 模板部分 19 | node_template = node_template->getNext(); 20 | Node* copied_temp = node_template->copyChild(); 21 | marcoReplace(copied_temp); 22 | return copied_temp; 23 | } 24 | 25 | void MacroTranslate::marcoReplace(Node* node) { 26 | if (node == NULL) return; 27 | for (Node* p = node; p != NULL; p = p->getNext()) { 28 | Node* n = p->getNext(); 29 | if (n != NULL && n->isIDNode()) { 30 | Node* arg = findArg(n->getStr()); 31 | if (arg != NULL) { 32 | p->replaceNext(arg->copyChild()); 33 | } 34 | } 35 | n = p->getChild(); 36 | if (n != NULL) { 37 | if (n->isIDNode()) { 38 | Node* arg = findArg(n->getStr()); 39 | if (arg != NULL) { 40 | p->replaceChild(arg->copyChild()); 41 | continue; 42 | } 43 | } 44 | marcoReplace(n); 45 | } 46 | } 47 | } 48 | 49 | Node* MacroTranslate::findArg(const string& name) { 50 | auto p = args_map.find(name); 51 | if (p == args_map.end()) return NULL; 52 | return p->second; 53 | } 54 | -------------------------------------------------------------------------------- /src/Model/TypeNode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-19 13:40:13 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-21 17:12:32 6 | */ 7 | 8 | #include "Elite/Model/TypeNode.h" 9 | // #include "Elite/CodeGen/CodeGenContext.h" 10 | #include 11 | using namespace std; 12 | 13 | namespace Elite { 14 | TypeNode* TypeNode::Create(const char* name, bool is_const, bool is_source) { 15 | return new TypeNode(name, is_const, is_source); 16 | } 17 | 18 | // LValue TypeNode::typeGen(CodeGenContext* context) { 19 | // LValue t = context->FindType(str); 20 | // if (t == NULL) { 21 | // cerr << "找不到该类型的定义:"; 22 | // cerr << str.c_str() << endl; 23 | // exit(1); 24 | // } 25 | // return t; 26 | // } 27 | 28 | void TypeNode::addDimension() { 29 | ++dimension; 30 | str += "[]"; 31 | } 32 | 33 | 34 | NodeType TypeNode::getType() { 35 | return type_node_t; 36 | } 37 | 38 | string& TypeNode::getStr() { 39 | return str; 40 | } 41 | 42 | string TypeNode::getTypeName() { 43 | return "type_node"; 44 | } 45 | 46 | void TypeNode::printSelf() { 47 | // printf("Type "); 48 | // if (is_const) Node::el.print("const"); 49 | // printf("%s", str.c_str()); 50 | // Node::el.print(str); 51 | } 52 | 53 | TypeNode::TypeNode(const char* name, bool is_const, bool is_source) { 54 | this->str = name; 55 | this->name = name; 56 | this->is_const = is_const; 57 | this->is_source = is_source; 58 | if (is_source) { 59 | this->str.insert(str.begin(), '*'); 60 | } 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_STRINGBUFFER_H_ 2 | #define RAPIDJSON_STRINGBUFFER_H_ 3 | 4 | #include "rapidjson.h" 5 | #include "internal/stack.h" 6 | 7 | namespace rapidjson { 8 | 9 | //! Represents an in-memory output stream. 10 | /*! 11 | \tparam Encoding Encoding of the stream. 12 | \tparam Allocator type for allocating memory buffer. 13 | \implements Stream 14 | */ 15 | template 16 | struct GenericStringBuffer { 17 | typedef typename Encoding::Ch Ch; 18 | 19 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 20 | 21 | void Put(Ch c) { *stack_.template Push() = c; } 22 | 23 | void Clear() { stack_.Clear(); } 24 | 25 | const char* GetString() const { 26 | // Push and pop a null terminator. This is safe. 27 | *stack_.template Push() = '\0'; 28 | stack_.template Pop(1); 29 | 30 | return stack_.template Bottom(); 31 | } 32 | 33 | size_t Size() const { return stack_.GetSize(); } 34 | 35 | static const size_t kDefaultCapacity = 256; 36 | mutable internal::Stack stack_; 37 | }; 38 | 39 | typedef GenericStringBuffer > StringBuffer; 40 | 41 | //! Implement specialized version of PutN() with memset() for better performance. 42 | template<> 43 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 44 | memset(stream.stack_.Push(n), c, n * sizeof(c)); 45 | } 46 | 47 | } // namespace rapidjson 48 | 49 | #endif // RAPIDJSON_STRINGBUFFER_H_ 50 | -------------------------------------------------------------------------------- /doc/Doxyfile.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "@CMAKE_PROJECT_NAME@" 2 | PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_RELEASE@ 3 | STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ 4 | INPUT = @doxy_main_page@ \ 5 | @PROJECT_SOURCE_DIR@ 6 | OUTPUT_DIRECTORY = @PROJECT_SOURCE_DIR@/build-doc 7 | FILE_PATTERNS = *.h \ 8 | *.cpp \ 9 | *.en.md 10 | IMAGE_PATH = ./doc 11 | OUTPUT_LANGUAGE = English 12 | RECURSIVE = YES 13 | EXTRACT_ALL = YES 14 | EXTRACT_PRIVATE = YES 15 | EXTRACT_STATIC = YES 16 | BRIEF_MEMBER_DESC = YES 17 | REPEAT_BRIEF = YES 18 | EXCLUDE_PATTERNS = extlib build bin third_party cmake example lib header_libs 19 | USE_MDFILE_AS_MAINPAGE = index.en.md 20 | SEARCHENGINE = YES 21 | SERVER_BASED_SEARCH = NO 22 | REFERENCED_BY_RELATION = YES 23 | REFERENCES_RELATION = YES 24 | 25 | #--------------------------------------------------------------------------- 26 | # Configuration options related to the HTML output 27 | #--------------------------------------------------------------------------- 28 | 29 | GENERATE_HTML = YES 30 | HTML_OUTPUT = html 31 | HTML_FILE_EXTENSION = .html 32 | HTML_HEADER = ./doc/misc/header.html 33 | HTML_FOOTER = ./doc/misc/footer.html 34 | HTML_EXTRA_STYLESHEET = ./doc/misc/doxygenextra.css 35 | HTML_TIMESTAMP = YES 36 | DISABLE_INDEX = YES 37 | GENERATE_TREEVIEW = YES 38 | TREEVIEW_WIDTH = 250 39 | 40 | GENERATE_LATEX = NO 41 | GENERATE_RTF = NO 42 | GENERATE_MAN = NO 43 | GENERATE_XML = NO 44 | -------------------------------------------------------------------------------- /src/MetaModel/StructModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-10-31 18:24:33 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 09:46:46 6 | */ 7 | 8 | #include "Elite/MetaModel/StructModel.h" 9 | #include "Elite/CodeGen/CodeGenContext.h" 10 | #include "Translater/idtable.h" 11 | 12 | 13 | 14 | StructModel::StructModel(std::string& name, 15 | std::vector& type_list, 16 | std::vector& name_list) 17 | : MetaModel(name) 18 | { 19 | this->type_list = type_list; 20 | this->name_list = name_list; 21 | } 22 | 23 | int StructModel::find(std::string& name) 24 | { 25 | int i = 0; 26 | if (name_list.size() == 0) return -1; 27 | for (auto& p : name_list) { 28 | if (name == p) return i; 29 | ++i; 30 | } 31 | return -1; 32 | } 33 | 34 | void StructModel::insertToST(CodeGenContext* context) { 35 | context->st->insert(name, struct_t, LValue(this)); // 插入符号表中 36 | } 37 | 38 | LValue StructModel::getStruct(CodeGenContext* context) { 39 | if (struct_type == NULL) 40 | struct_type = context->getLLCG()->DeclareStruct(name); 41 | return struct_type; 42 | } 43 | 44 | void StructModel::genCode(CodeGenContext* context) { 45 | std::vector type_vec; 46 | for (auto& s : type_list) { 47 | LValue t = context->FindType(s); 48 | type_vec.push_back(t); 49 | } 50 | struct_type = context->getLLCG()->Struct(getStruct(context), type_vec); 51 | } 52 | 53 | 54 | void StructModel::genMetaCode(CodeGenContext* context) { 55 | vector data; 56 | data.push_back("struct"); 57 | data.push_back(name); 58 | for (int i = 0; i < name_list.size(); ++i) { 59 | data.push_back(type_list[i]); 60 | data.push_back(name_list[i]); 61 | } 62 | context->getLLCG()->MakeMetaList(data); 63 | } 64 | 65 | MetaType StructModel::getMetaType() { 66 | return struct_meta_t; 67 | } 68 | -------------------------------------------------------------------------------- /doc/Doxyfile.zh-cn.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "@CMAKE_PROJECT_NAME@" 2 | PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_RELEASE@ 3 | STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ 4 | INPUT = @doxy_main_page@ \ 5 | @PROJECT_SOURCE_DIR@ 6 | OUTPUT_DIRECTORY = @PROJECT_SOURCE_DIR@/build-doc 7 | FILE_PATTERNS = *.h \ 8 | *.cpp \ 9 | *.cn.md 10 | 11 | IMAGE_PATH = ./doc 12 | OUTPUT_LANGUAGE = Chinese 13 | RECURSIVE = YES 14 | EXTRACT_ALL = YES 15 | EXTRACT_PRIVATE = YES 16 | EXTRACT_STATIC = YES 17 | BRIEF_MEMBER_DESC = YES 18 | REPEAT_BRIEF = YES 19 | BUILTIN_STL_SUPPORT = YES 20 | EXCLUDE_PATTERNS = extlib build bin third_party cmake example lib header_libs 21 | USE_MDFILE_AS_MAINPAGE = index.zh-cn.md 22 | SEARCHENGINE = YES 23 | SERVER_BASED_SEARCH = NO 24 | REFERENCED_BY_RELATION = YES 25 | REFERENCES_RELATION = YES 26 | 27 | #--------------------------------------------------------------------------- 28 | # Configuration options related to the HTML output 29 | #--------------------------------------------------------------------------- 30 | 31 | GENERATE_HTML = YES 32 | HTML_OUTPUT = html/zh-cn 33 | HTML_FILE_EXTENSION = .html 34 | HTML_HEADER = ./doc/misc/header.html 35 | HTML_FOOTER = ./doc/misc/footer.html 36 | HTML_EXTRA_STYLESHEET = ./doc/misc/doxygenextra.css 37 | HTML_TIMESTAMP = YES 38 | DISABLE_INDEX = YES 39 | GENERATE_TREEVIEW = YES 40 | TREEVIEW_WIDTH = 250 41 | 42 | GENERATE_LATEX = NO 43 | GENERATE_RTF = NO 44 | GENERATE_MAN = NO 45 | GENERATE_XML = NO 46 | -------------------------------------------------------------------------------- /src/CodeGen/RedCodeGen.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-09-23 22:57:41 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-25 22:03:20 6 | */ 7 | 8 | #include "Elite/CodeGen/RedCodeGen.h" 9 | #include "Translater/idtable.h" 10 | #include "Elite/CodeGen/CodeGenContext.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | 17 | 18 | RedCodeGen::RedCodeGen() { 19 | 20 | } 21 | 22 | RedCodeGen* RedCodeGen::Create() { 23 | return new RedCodeGen(); 24 | } 25 | 26 | void RedCodeGen::Init() { 27 | if (this->context != NULL) { 28 | delete context; 29 | context = NULL; 30 | } 31 | this->context = new CodeGenContext(); 32 | pm.LoadDefaultLists(); 33 | this->context->setPassManager(&pm); 34 | } 35 | 36 | RedCodeGen::~RedCodeGen() { 37 | if (context != NULL) delete context; 38 | } 39 | 40 | 41 | void RedCodeGen::PreScan(Node* node) { 42 | pm.RunPassList("prescan", node, context); 43 | } 44 | 45 | void RedCodeGen::PreScan(std::set& nodes) { 46 | pm.RunPassListWithSet("prescan", nodes, context); 47 | } 48 | 49 | 50 | void RedCodeGen::MakeMeta(const char* outfile_name, const char* module_name) { 51 | string out_name = outfile_name; 52 | string mod_name = module_name; 53 | context->getLLCG()->MakeMetaModule(out_name, mod_name); 54 | } 55 | 56 | 57 | void RedCodeGen::Make(Node* node, const char* outfile_name, const char* module_name) { 58 | string mod_name = module_name; 59 | context->st->push(); // 进入文件局部符号表 60 | context->Init(); 61 | context->getLLCG()->BeginModule(mod_name); 62 | // 正式流程 63 | pm.RunPassList("main", node, context); 64 | string out_name = outfile_name; 65 | context->getLLCG()->VerifyAndWrite(out_name); 66 | context->st->pop(); // 离开该文件符号表 67 | } 68 | -------------------------------------------------------------------------------- /include/Elite/Translater/Pass.h: -------------------------------------------------------------------------------- 1 | #ifndef PASS_H 2 | #define PASS_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | #include "Elite/CodeGen/CodeGenFunction.h" 11 | 12 | 13 | class Pass { 14 | public: 15 | Pass (const FuncReg* macro_funcs); 16 | Pass (const FuncReg* macro_funcs, const FuncReg* macro_funcs2); 17 | virtual ~Pass (); 18 | 19 | /** 20 | * @brief 正式扫描前的初始化 21 | */ 22 | virtual void Init(); 23 | 24 | 25 | /** 26 | * @brief 查找一个名称是否为一个C宏 27 | * @details 查找一个名称是否为一个C宏 28 | * 29 | * @param str 宏的名字 30 | * @return 如果有,则返回函数指针,否则返回NULL 31 | */ 32 | virtual ICodeGenFunction* getMacro(const string& str); 33 | 34 | // C++注册宏 35 | // void AddMacros(const FuncReg* macro_funcs); // 为只添加不替换保留 36 | 37 | /** 38 | * @brief 添加或替换一条宏 39 | * @details 添加或替换一条宏,如果当前名称存在则替换,没有则添加 40 | * 41 | * @param macro_funcs 一组宏定义数组,类似Lua中函数的定义方式 42 | */ 43 | virtual void AddOrReplaceMacros(const FuncReg* macro_funcs); 44 | 45 | virtual void AddOrReplaceMacros(const string& name, ICodeGenFunction* func); 46 | 47 | 48 | /** 49 | * @brief 移除全部宏指令 50 | * @details 移除全部宏指令 51 | */ 52 | virtual void RemoveAllMacros(); 53 | 54 | /** 55 | * 临时保存当前宏到堆栈中,还可以恢复 56 | * @method SaveMacros 57 | */ 58 | virtual void SaveMacros(); 59 | 60 | /** 61 | * 恢复之前保存的堆栈 62 | * @method RecoverMacros 63 | */ 64 | virtual void RecoverMacros(); 65 | 66 | 67 | protected: 68 | 69 | /** 70 | * @brief 宏定义表,用来查找是否有该宏定义的 71 | * @details 宏定义表,里面存放有对应名称的C语言宏处理函数 72 | */ 73 | map macro_map; 74 | 75 | /** 76 | * @brief 这个栈是用来临时保存上面的查询表的 77 | * @details 某些情况,可能会对宏处理的函数进行临时的变更,就需要保存和恢复全部的状态,这个栈是用来记录宏表的 78 | */ 79 | stack > macro_save_stack; 80 | 81 | 82 | }; 83 | 84 | 85 | #endif /* end of include guard: PASS_H */ 86 | -------------------------------------------------------------------------------- /src/MetaModel/FunctionModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-13 16:45:51 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 09:46:12 6 | */ 7 | 8 | #include "Elite/MetaModel/FunctionModel.h" 9 | #include "Elite/CodeGen/CodeGenContext.h" 10 | #include "Translater/idtable.h" 11 | 12 | FunctionModel::FunctionModel( 13 | std::string& name, 14 | std::string& ret_type, 15 | std::vector& type_list, 16 | std::vector& name_list 17 | ) : MetaModel(name) 18 | { 19 | this->return_type = ret_type; 20 | this->type_list = type_list; 21 | this->name_list = name_list; 22 | } 23 | 24 | int FunctionModel::find(std::string& name) 25 | { 26 | int i = 0; 27 | if (name_list.size() == 0) return -1; 28 | for (auto& p : name_list) { 29 | if (name == p) return i; 30 | ++i; 31 | } 32 | return -1; 33 | } 34 | 35 | void FunctionModel::insertToST(CodeGenContext* context) { 36 | context->st->insert(name, function_t, LValue(this)); // 插入符号表中 37 | } 38 | 39 | LValue FunctionModel::getFunction(CodeGenContext* context) { 40 | return context->getLLCG()->GetOrInsertFunction(name, func_type); 41 | } 42 | 43 | 44 | void FunctionModel::genCode(CodeGenContext* context) { 45 | LValue ret_type = context->FindType(return_type); 46 | std::vector type_vec; 47 | for (auto& s : type_list) { 48 | LValue t = context->FindType(s); 49 | type_vec.push_back(t); 50 | } 51 | // 先合成一个函数 52 | func_type = context->getLLCG()->FuncType(ret_type, type_vec, 53 | /*not vararg*/false); 54 | } 55 | 56 | 57 | void FunctionModel::genMetaCode(CodeGenContext* context) { 58 | vector data; 59 | data.push_back(return_type); // 参数表1, 返回类型 60 | for (int i = 0; i < name_list.size(); ++i) { 61 | data.push_back(type_list[i]); // 类型 62 | data.push_back(name_list[i]); // 名称 63 | } 64 | context->getLLCG()->MakeMetaList(name, data, func_type); 65 | } 66 | 67 | MetaType FunctionModel::getMetaType() { 68 | return function_meta_t; 69 | } 70 | -------------------------------------------------------------------------------- /src/Translater/PassManager.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Elite/Translater/PassManager.h" 3 | #include "Elite/CodeGen/ICodeGenContext.h" 4 | 5 | 6 | PassManager::PassManager () { 7 | 8 | } 9 | 10 | PassManager::~PassManager () { 11 | 12 | } 13 | 14 | 15 | void PassManager::NewPassList(const string& name, const vector& vec) { 16 | NewPassList(name, list(vec.begin(), vec.end())); 17 | } 18 | 19 | 20 | void PassManager::NewPassList(const string& name, const list& lst) { 21 | pass_lists[name] = lst; 22 | } 23 | 24 | 25 | list* PassManager::getPassList(const string& name) { 26 | auto idx = pass_lists.find(name); 27 | if (idx != pass_lists.end()) return &(idx->second); 28 | return NULL; 29 | } 30 | 31 | 32 | void PassManager::RunPassList(const string& name, Node* node, ICodeGenContext* ctx) { 33 | auto idx = pass_lists.find(name); 34 | if (idx != pass_lists.end()) { 35 | for (auto i : idx->second) { 36 | // 设置i为活动pass 37 | ctx->setNowPass(i); 38 | ctx->MacroMake(node); 39 | } 40 | } 41 | } 42 | 43 | void PassManager::RunPassListWithSet(const string& name, set& nodes, ICodeGenContext* ctx) { 44 | auto idx = pass_lists.find(name); 45 | if (idx != pass_lists.end()) { 46 | for (auto i : idx->second) { 47 | // 设置i为活动pass 48 | ctx->setNowPass(i); 49 | for (auto node : nodes) 50 | ctx->MacroMake(node); 51 | } 52 | } 53 | } 54 | 55 | 56 | extern const FuncReg macro_funcs[]; 57 | extern const FuncReg macro_classes[]; 58 | extern const FuncReg macro_prescan[]; 59 | extern const FuncReg macro_pretype[]; 60 | extern const FuncReg macro_defmacro[]; 61 | 62 | 63 | void PassManager::LoadDefaultLists() { 64 | list prescan = { new Pass(macro_defmacro), new Pass(macro_prescan), new Pass(macro_pretype) }; 65 | list main = { new Pass(macro_funcs, macro_classes) }; 66 | NewPassList("prescan", prescan); 67 | NewPassList("main", main); 68 | } 69 | -------------------------------------------------------------------------------- /header_libs/cereal/types/utility.hpp: -------------------------------------------------------------------------------- 1 | /*! \file utility.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UTILITY_HPP_ 31 | #define CEREAL_TYPES_UTILITY_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serializing for std::pair 39 | template inline 40 | void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, std::pair & pair ) 41 | { 42 | ar( CEREAL_NVP_("first", pair.first), 43 | CEREAL_NVP_("second", pair.second) ); 44 | } 45 | } // namespace cereal 46 | 47 | #endif // CEREAL_TYPES_UTILITY_HPP_ 48 | -------------------------------------------------------------------------------- /doc/设计文档.md: -------------------------------------------------------------------------------- 1 | 2 | 目标: 制作一款能够自由扩展语法, 对语法元素拥有绝对控制能力的语言 3 | 4 | 语言类别: 静态, 强类型, 安全性高, 适合超大型工程, 极其高效 5 | 6 | 语言主要任务: 7 | 实现自举的静态语言, 作为C++的替代品, 需要能够完全实现面向对象, 同时提供兼容底层C库的操作 8 | 制作一款安全易用的多范式编程语言, 并且各个范式间可以混合使用 9 | 可以对代码进行多个层级的建模 10 | 11 | 主要语言特性: 12 | 13 | 1. 函数的多返回值和重载 14 | 15 | ``` 16 | public func hello(int a, int b) -> int { 17 | 18 | } 19 | 20 | // 支持重载, 多返回, 在导出成C函数时, 可以用attrbute设定名称, 否则将自动添加新的后缀用于重命名 21 | @attr(name='hello2') 22 | public func hello(int a, int b, int c) -> int, int { 23 | 24 | } 25 | 26 | func main() { 27 | int a, b = hello(12, 3) 28 | } 29 | 30 | ``` 31 | 32 | 33 | 2. 基本变量类型 34 | 35 | 小写的内置类型均为值类型 36 | 整数 37 | int(定义为int32), int8, int16, int32, int64 38 | 无符号整数 39 | uint(定义为uint32), uint8, uint16, uint32, uint64 40 | 字符, 字符串 (这部分实际上是库扩展的) 41 | char, string 42 | 布尔 (库扩展的) 43 | bool 44 | 浮点 45 | float, double 46 | 通用变量 (库扩展的) 47 | var 48 | 自动推断 (库扩展的) 49 | auto 50 | 51 | 实际上, 在不引用任何库的情况下, 只有 52 | int8, int16, int32, int64, 53 | uint8, uint16, uint32, uint64 54 | 和 float, double 55 | 56 | 57 | 3. 符合标准LLVM格式的二进制库 58 | 59 | 语言的库符合LLVM IR标准, 使用metadata存储额外的编译信息 60 | 这样一个文件在载入后, 完全等同于载入源代码, 只不过具体的函数都被编译成了二进制, 丢失了这些函数的源代码信息而已 61 | 但包名, 文件名, 符号名, 以及宏和所有需要的符号类型信息都得以保留. 62 | 63 | 而且, 该文件可以和其他库链接, 形成一个库 64 | 65 | 66 | 4. 最小编译单元 67 | 68 | 文件是最小编译单元, 包是最小组织单元. 69 | 每个文件可以视为一个独立的编译环境, 其他文件import的符号和宏不会作用于当前文件. 70 | 但包是最小的组织单元, 每次编译, 最少应编译一整个包, 因为包内符号是互相能够看到的, 而且包内符号没有顺序之分, 一个包编译后整体作为一个LLVM IR文件, 71 | 并以包名作为输出 72 | 当然单个文件可以作为一个包, 几个文件也可以, 一个或多个目录也可以, 甚至是一个递归搜索的目录也可以 73 | 74 | 包同时也是一个命名空间, 故包也是可以嵌套存在的 75 | 76 | 77 | 5. 宏翻译模型 78 | 79 | 每次匹配一段语法序列中的内容, 尝试去匹配最接近的内容, 并以此结构作为匹配上的语法进行宏翻译, 翻译出新的内容后就按照普通代码来处理 80 | 宏翻译能够动态扩展语法, 而且根据宏定义的位置不同(或引用位置不同) 该定义存在生存周期 81 | 82 | 例如: 83 | ``` 84 | func hello() { 85 | import 'string' 86 | // this import will only available in this scope 87 | } 88 | ``` 89 | 90 | 同时, 宏翻译模型还可以用于语法检查的扩展 91 | 例如, 我们可以对未初始化变量进行检查, 这部分扩展可以用宏来实现, 通过向回调链注册这个宏, 实现在特定语法处理的时候, 用该宏进行前处理和后处理 92 | 93 | 94 | 宏翻译的方式其实就是将一段匹配上的内容根据语法格式进行提取和转换, 例如: 95 | ``` 96 | int a, b 97 | 98 | 99 | defmacro (Type type, ID[] ids) { 100 | return (settype type ids) 101 | } 102 | 103 | or 104 | 105 | defmacro (Type type, ID[] ids[]) { 106 | for id in ids: 107 | yield (settype type id) 108 | } 109 | 110 | ``` 111 | 112 | 113 | 114 | 6. 安全的内存模型 115 | -------------------------------------------------------------------------------- /include/Elite/CodeGen/ICodeGenContext.h: -------------------------------------------------------------------------------- 1 | #ifndef ICODE_GEN_CONTEXT_H 2 | #define ICODE_GEN_CONTEXT_H 3 | 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | #include "Elite/LLCG/llcg.h" 10 | #include "Elite/MetaModel/StructModel.h" 11 | #include "Elite/MetaModel/FunctionModel.h" 12 | #include "Elite/MetaModel/MacroModel.h" 13 | #include "Elite/CodeGen/CodeGenFunction.h" 14 | 15 | class Node; 16 | class Pass; 17 | class PassManager; 18 | class IDTable; 19 | struct id; 20 | 21 | class ICodeGenContext 22 | { 23 | public: 24 | 25 | /** 26 | * @brief 这个函数是用来一条条翻译Node宏的 27 | * @details 这个函数是用来一条条翻译Node宏的 28 | * 29 | * @param node 要翻译的语法节点 30 | * @return 翻译后的后端变量,往往是一个表达式或一个语句返回的值 31 | */ 32 | virtual LValue MacroMake(Node* node) = 0; 33 | 34 | 35 | // 获取当前模块中已注册的函数 36 | virtual LValue getFunction(Node* node) = 0; 37 | virtual LValue getFunction(const std::string& name) = 0; 38 | 39 | 40 | // 用户宏的查找与声明设置 41 | virtual shared_ptr getUserMacro(const std::string& name) = 0; 42 | virtual void setUserMacro(const std::string& name, Node* node) = 0; 43 | 44 | virtual shared_ptr getFunctionModel(const std::string& name) = 0; 45 | virtual shared_ptr getStructModel(const std::string& name) = 0; 46 | 47 | 48 | // 类型的定义和查找 49 | virtual void DefType(string name, LValue t) = 0; 50 | virtual LValue FindType(const string& name) = 0; 51 | virtual LValue FindType(Node*) = 0; 52 | virtual LValue FindSrcType(const string& name) = 0; 53 | virtual LValue FindSrcType(Node*) = 0; 54 | 55 | /** 56 | * @brief 定义一个变量 有可能是全局变量 57 | * 58 | * @param name 变量名 59 | * @param addr 存储地址 60 | */ 61 | virtual void DefVar(const string& name, LValue addr) = 0; 62 | 63 | /** 64 | * @brief 在符号表中查找一个变量 65 | * 66 | * @param name 变量名 67 | * @return 变量的存储地址 68 | */ 69 | virtual LValue FindVar(const string& name) = 0; 70 | 71 | 72 | virtual bool isSave() = 0; 73 | virtual void setIsSave(bool save) = 0; 74 | 75 | virtual id* FindST(Node* node) const = 0; 76 | virtual id* FindST(const string& str) const = 0; 77 | 78 | /** 79 | * @brief 获取低层次代码生成器,目前只有llvm 80 | * @return 生成器指针 81 | */ 82 | virtual llcg* getLLCG() = 0; 83 | 84 | virtual void setNowPass(Pass* pass) = 0; 85 | 86 | virtual Pass* getNowPass() = 0; 87 | 88 | virtual PassManager* getPassManager() = 0; 89 | }; 90 | 91 | 92 | #endif /* end of include guard: ICODE_GEN_CONTEXT_H */ 93 | -------------------------------------------------------------------------------- /src/Model/Node.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-09-22 19:21:40 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-10 18:19:23 6 | */ 7 | 8 | #include "Elite/Model/ModelException.h" 9 | #include "Elite/Model/nodes.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Elite { 16 | 17 | Node::Node() 18 | { 19 | next = nullptr; 20 | } 21 | 22 | Node::Node(const Node& other) 23 | { 24 | next = other.next; 25 | } 26 | 27 | Node::~Node() 28 | { 29 | } 30 | 31 | Node* Node::copyAll() 32 | { 33 | Node* n = copyAll(); 34 | if (n->next) 35 | n->next = next->copyAll(); 36 | return n; 37 | } 38 | 39 | void Node::print(int k) 40 | { 41 | } 42 | 43 | void Node::printSelf() 44 | { 45 | } 46 | 47 | bool Node::hasNext() 48 | { 49 | return next != nullptr; 50 | } 51 | 52 | bool Node::isSeq() 53 | { 54 | return getType() == seq_node_t; 55 | } 56 | 57 | bool Node::isBlock() 58 | { 59 | return getType() == block_node_t; 60 | } 61 | 62 | bool Node::isList() 63 | { 64 | return getType() == list_node_t; 65 | } 66 | 67 | bool Node::isIntNode() 68 | { 69 | return getType() == int_node_t; 70 | } 71 | 72 | bool Node::isFloatNode() 73 | { 74 | return getType() == float_node_t; 75 | } 76 | 77 | bool Node::isIDNode() 78 | { 79 | return getType() == id_node_t; 80 | } 81 | 82 | bool Node::isStringNode() 83 | { 84 | return getType() == string_node_t; 85 | } 86 | 87 | bool Node::isCharNode() 88 | { 89 | return getType() == char_node_t; 90 | } 91 | 92 | bool Node::isTypeNode() 93 | { 94 | return getType() == type_node_t; 95 | } 96 | 97 | Node* Node::getChild() { throw InvalidMethod("getChild", "Element didn't have children."); } 98 | 99 | std::string& Node::getStr() 100 | { 101 | throw InvalidMethod("getStr", "Can not get string since the wrong type."); 102 | } 103 | 104 | Node* Node::make_linked(...) 105 | { 106 | return nullptr; 107 | } 108 | 109 | Node* Node::makeLinked(int num, Node* plist[]) 110 | { 111 | 112 | return nullptr; 113 | } 114 | 115 | Node* Node::CreateList(Node* n) 116 | { 117 | return nullptr; 118 | } 119 | 120 | Node* Node::CreateBlock(Node* n) 121 | { 122 | 123 | return nullptr; 124 | } 125 | 126 | void Node::Free(Node*& p) 127 | { 128 | } 129 | 130 | void Node::FreeAll(Node*& p) 131 | { 132 | } 133 | 134 | } // Elite 135 | -------------------------------------------------------------------------------- /header_libs/cereal/types/complex.hpp: -------------------------------------------------------------------------------- 1 | /*! \file complex.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_COMPLEX_HPP_ 31 | #define CEREAL_TYPES_COMPLEX_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Serializing (save) for std::complex 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::complex const & comp ) 40 | { 41 | ar( CEREAL_NVP_("real", comp.real()), 42 | CEREAL_NVP_("imag", comp.imag()) ); 43 | } 44 | 45 | //! Serializing (load) for std::complex 46 | template inline 47 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::complex & bits ) 48 | { 49 | T real, imag; 50 | ar( CEREAL_NVP_("real", real), 51 | CEREAL_NVP_("imag", imag) ); 52 | bits = {real, imag}; 53 | } 54 | } // namespace cereal 55 | 56 | #endif // CEREAL_TYPES_COMPLEX_HPP_ 57 | -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidjson/internal/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_INTERNAL_STACK_H_ 2 | #define RAPIDJSON_INTERNAL_STACK_H_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | /////////////////////////////////////////////////////////////////////////////// 8 | // Stack 9 | 10 | //! A type-unsafe stack for storing different types of data. 11 | /*! \tparam Allocator Allocator for allocating stack memory. 12 | */ 13 | template 14 | class Stack { 15 | public: 16 | Stack(Allocator* allocator, size_t stack_capacity) : allocator_(allocator), own_allocator_(0), stack_(0), stack_top_(0), stack_end_(0), stack_capacity_(stack_capacity) { 17 | RAPIDJSON_ASSERT(stack_capacity_ > 0); 18 | if (!allocator_) 19 | own_allocator_ = allocator_ = new Allocator(); 20 | stack_top_ = stack_ = (char*)allocator_->Malloc(stack_capacity_); 21 | stack_end_ = stack_ + stack_capacity_; 22 | } 23 | 24 | ~Stack() { 25 | Allocator::Free(stack_); 26 | delete own_allocator_; // Only delete if it is owned by the stack 27 | } 28 | 29 | void Clear() { /*stack_top_ = 0;*/ stack_top_ = stack_; } 30 | 31 | template 32 | T* Push(size_t count = 1) { 33 | // Expand the stack if needed 34 | if (stack_top_ + sizeof(T) * count >= stack_end_) { 35 | size_t new_capacity = stack_capacity_ * 2; 36 | size_t size = GetSize(); 37 | size_t new_size = GetSize() + sizeof(T) * count; 38 | if (new_capacity < new_size) 39 | new_capacity = new_size; 40 | stack_ = (char*)allocator_->Realloc(stack_, stack_capacity_, new_capacity); 41 | stack_capacity_ = new_capacity; 42 | stack_top_ = stack_ + size; 43 | stack_end_ = stack_ + stack_capacity_; 44 | } 45 | T* ret = (T*)stack_top_; 46 | stack_top_ += sizeof(T) * count; 47 | return ret; 48 | } 49 | 50 | template 51 | T* Pop(size_t count) { 52 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); 53 | stack_top_ -= count * sizeof(T); 54 | return (T*)stack_top_; 55 | } 56 | 57 | template 58 | T* Top() { 59 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 60 | return (T*)(stack_top_ - sizeof(T)); 61 | } 62 | 63 | template 64 | T* Bottom() { return (T*)stack_; } 65 | 66 | Allocator& GetAllocator() { return *allocator_; } 67 | size_t GetSize() const { return stack_top_ - stack_; } 68 | size_t GetCapacity() const { return stack_capacity_; } 69 | 70 | private: 71 | Allocator* allocator_; 72 | Allocator* own_allocator_; 73 | char *stack_; 74 | char *stack_top_; 75 | char *stack_end_; 76 | size_t stack_capacity_; 77 | }; 78 | 79 | } // namespace internal 80 | } // namespace rapidjson 81 | 82 | #endif // RAPIDJSON_STACK_H_ 83 | -------------------------------------------------------------------------------- /header_libs/sptr/sptr.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SPTR_HPP 2 | #define SPTR_HPP 3 | 4 | #include "memheap.hpp" 5 | 6 | void* operator new (size_t size, MemHeap* ptr) { 7 | if (ptr) return ptr->allocate(size); 8 | static MemHeap* p = MemHeap::getInstance(); 9 | return p->allocate(size); 10 | } 11 | 12 | 13 | inline void sptr_ref(void* p) { 14 | MemHeap::ref(p); 15 | } 16 | 17 | inline void sptr_unref(void* p) { 18 | MemHeap::unref(p); 19 | } 20 | 21 | 22 | template 23 | class sptr { 24 | public: 25 | sptr() { 26 | ptr = NULL; 27 | } 28 | 29 | sptr(T* p) { 30 | ptr = p; 31 | } 32 | 33 | sptr(const sptr& p) { 34 | ptr = p.ptr; 35 | ref(); 36 | } 37 | 38 | sptr& operator=(T* p) { 39 | unref(); 40 | ptr = p; 41 | return *this; 42 | } 43 | 44 | sptr& operator=(const sptr& p) { 45 | unref(); 46 | ptr = p.ptr; 47 | ref(); 48 | return *this; 49 | } 50 | 51 | virtual ~sptr() { 52 | unref(); 53 | } 54 | 55 | inline T* get() { 56 | return ptr; 57 | } 58 | 59 | inline void wrapper(T* p) { 60 | ptr = p; 61 | } 62 | inline T* unwrapper() { 63 | ref(); 64 | return ptr; 65 | } 66 | 67 | inline T* operator -> () { 68 | return ptr; 69 | } 70 | inline T& operator * () { 71 | return *ptr; 72 | } 73 | 74 | protected: 75 | inline void ref() { 76 | if (ptr) MemHeap::ref(ptr); 77 | } 78 | inline void unref() { 79 | if (ptr) MemHeap::unref(ptr); 80 | } 81 | 82 | T* ptr; 83 | }; 84 | 85 | template 86 | class sptr_stack : public sptr { 87 | public: 88 | sptr_stack() : sptr() { 89 | MemHeap::push_stack(this->ptr); 90 | } 91 | 92 | sptr_stack(T* p) : sptr(p) { 93 | MemHeap::push_stack(this->ptr); 94 | } 95 | 96 | sptr_stack(const sptr& p) : sptr(p) { 97 | MemHeap::push_stack(this->ptr); 98 | } 99 | 100 | 101 | sptr& operator=(T* p) { 102 | pop(); 103 | sptr::operator=(p); 104 | return *this; 105 | } 106 | 107 | sptr& operator=(const sptr& p) { 108 | pop(); 109 | sptr::operator=(p); 110 | return *this; 111 | } 112 | 113 | virtual ~sptr_stack() { 114 | pop(); 115 | } 116 | 117 | protected: 118 | inline void pop() { 119 | if (this->ptr) MemHeap::pop_stack(this->ptr); 120 | } 121 | }; 122 | 123 | 124 | #endif /* end of include guard: SPTR_HPP */ 125 | -------------------------------------------------------------------------------- /header_libs/cereal/types/list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_LIST_HPP_ 31 | #define CEREAL_TYPES_LIST_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::list 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::list const & list ) 41 | { 42 | ar( make_size_tag( static_cast(list.size()) ) ); 43 | 44 | for( auto const & i : list ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::list 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::list & list ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | list.resize( static_cast( size ) ); 56 | 57 | for( auto & i : list ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_LIST_HPP_ 63 | -------------------------------------------------------------------------------- /header_libs/cereal/types/deque.hpp: -------------------------------------------------------------------------------- 1 | /*! \file deque.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_DEQUE_HPP_ 31 | #define CEREAL_TYPES_DEQUE_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::deque 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::deque const & deque ) 41 | { 42 | ar( make_size_tag( static_cast(deque.size()) ) ); 43 | 44 | for( auto const & i : deque ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::deque 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::deque & deque ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | deque.resize( static_cast( size ) ); 56 | 57 | for( auto & i : deque ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_DEQUE_HPP_ 63 | -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidxml/license.txt: -------------------------------------------------------------------------------- 1 | Use of this software is granted under one of the following two licenses, 2 | to be chosen freely by the user. 3 | 4 | 1. Boost Software License - Version 1.0 - August 17th, 2003 5 | =============================================================================== 6 | 7 | Copyright (c) 2006, 2007 Marcin Kalicinski 8 | 9 | Permission is hereby granted, free of charge, to any person or organization 10 | obtaining a copy of the software and accompanying documentation covered by 11 | this license (the "Software") to use, reproduce, display, distribute, 12 | execute, and transmit the Software, and to prepare derivative works of the 13 | Software, and to permit third-parties to whom the Software is furnished to 14 | do so, all subject to the following: 15 | 16 | The copyright notices in the Software and this entire statement, including 17 | the above license grant, this restriction and the following disclaimer, 18 | must be included in all copies of the Software, in whole or in part, and 19 | all derivative works of the Software, unless such copies or derivative 20 | works are solely in the form of machine-executable object code generated by 21 | a source language processor. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | DEALINGS IN THE SOFTWARE. 30 | 31 | 2. The MIT License 32 | =============================================================================== 33 | 34 | Copyright (c) 2006, 2007 Marcin Kalicinski 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | of the Software, and to permit persons to whom the Software is furnished to do so, 41 | subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 52 | IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidjson/genericstream.h: -------------------------------------------------------------------------------- 1 | // Generic*Stream code from https://code.google.com/p/rapidjson/issues/detail?id=20 2 | #ifndef RAPIDJSON_GENERICSTREAM_H_ 3 | #define RAPIDJSON_GENERICSTREAM_H_ 4 | 5 | #include "rapidjson.h" 6 | #include 7 | 8 | #ifdef _MSC_VER 9 | #pragma warning(push) 10 | #pragma warning(disable: 4127) // conditional expression is constant 11 | #pragma warning(disable: 4512) // assignment operator could not be generated 12 | #pragma warning(disable: 4100) // unreferenced formal parameter 13 | #endif 14 | 15 | namespace rapidjson { 16 | 17 | //! Wrapper of std::istream for input. 18 | class GenericReadStream { 19 | public: 20 | typedef char Ch; //!< Character type (byte). 21 | 22 | //! Constructor. 23 | /*! 24 | \param is Input stream. 25 | */ 26 | GenericReadStream(std::istream & is) : is_(&is) { 27 | } 28 | 29 | 30 | Ch Peek() const { 31 | if(is_->eof()) return '\0'; 32 | return static_cast(is_->peek()); 33 | } 34 | 35 | Ch Take() { 36 | if(is_->eof()) return '\0'; 37 | return static_cast(is_->get()); 38 | } 39 | 40 | size_t Tell() const { 41 | return (int)is_->tellg(); 42 | } 43 | 44 | // Not implemented 45 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 46 | void Flush() { RAPIDJSON_ASSERT(false); } 47 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 48 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 49 | 50 | std::istream * is_; 51 | }; 52 | 53 | 54 | //! Wrapper of std::ostream for output. 55 | class GenericWriteStream { 56 | public: 57 | typedef char Ch; //!< Character type. Only support char. 58 | 59 | //! Constructor 60 | /*! 61 | \param os Output stream. 62 | */ 63 | GenericWriteStream(std::ostream& os) : os_(os) { 64 | } 65 | 66 | void Put(char c) { 67 | os_.put(c); 68 | } 69 | 70 | void PutN(char c, size_t n) { 71 | for (size_t i = 0; i < n; ++i) { 72 | Put(c); 73 | } 74 | } 75 | 76 | void Flush() { 77 | os_.flush(); 78 | } 79 | 80 | size_t Tell() const { 81 | return (int)os_.tellp(); 82 | } 83 | 84 | // Not implemented 85 | char Peek() const { RAPIDJSON_ASSERT(false); } 86 | char Take() { RAPIDJSON_ASSERT(false); } 87 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 88 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 89 | 90 | private: 91 | std::ostream& os_; 92 | }; 93 | 94 | template<> 95 | inline void PutN(GenericWriteStream& stream, char c, size_t n) { 96 | stream.PutN(c, n); 97 | } 98 | 99 | } // namespace rapidjson 100 | 101 | // On MSVC, restore warnings state 102 | #ifdef _MSC_VER 103 | #pragma warning(pop) 104 | #endif 105 | #endif // RAPIDJSON_GENERICSTREAM_H_ 106 | -------------------------------------------------------------------------------- /include/Elite/CodeGen/CodeGenContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-10-10 18:44:44 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-26 15:10:36 6 | * 7 | * 代码生成的上下文类, 是C实现宏的最核心功能类 8 | */ 9 | 10 | #ifndef CODE_GEN_CONTENT_H 11 | #define CODE_GEN_CONTENT_H 12 | 13 | #include "Elite/CodeGen/ICodeGenContext.h" 14 | 15 | 16 | /** 17 | * @brief 代码生成上下文, 是代码生成中的关键信息存储类 18 | * @details 存储最关键的数据, 例如符号栈, LLVM生成器对象. 19 | * 在宏翻译过程中, 该上下文指针将会传入翻译函数中.\n 20 | * 该上下文在编译器中, 同一时刻应该仅存在一份, 21 | * 生存周期为一个包的编译开始到包内全部代码翻译完毕.\n 22 | * 切换上下文时, 相当于清空符号栈, 释放资源, 重启LLVM后端 23 | * 会导致之前分析的符号全部消失 24 | */ 25 | class CodeGenContext : public ICodeGenContext 26 | { 27 | public: 28 | CodeGenContext(); 29 | virtual ~CodeGenContext(); 30 | 31 | void Init(); 32 | 33 | /** 34 | * @brief 这个函数是用来一条条翻译Node宏的 35 | * @details 这个函数是用来一条条翻译Node宏的 36 | * 37 | * @param node 要翻译的语法节点 38 | * @return 翻译后的后端变量,往往是一个表达式或一个语句返回的值 39 | */ 40 | virtual LValue MacroMake(Node* node); 41 | 42 | 43 | // 获取当前模块中已注册的函数 44 | virtual LValue getFunction(Node* node); 45 | virtual LValue getFunction(const std::string& name); 46 | 47 | 48 | // 用户宏的查找与声明设置 49 | virtual shared_ptr getUserMacro(const std::string& name); 50 | virtual void setUserMacro(const std::string& name, Node* node); 51 | 52 | virtual shared_ptr getFunctionModel(const std::string& name); 53 | virtual shared_ptr getStructModel(const std::string& name); 54 | 55 | // 类型的定义和查找 56 | virtual void DefType(string name, LValue t); 57 | virtual LValue FindType(const string& name); 58 | virtual LValue FindType(Node*); 59 | virtual LValue FindSrcType(const string& name); 60 | virtual LValue FindSrcType(Node*); 61 | 62 | /** 63 | * @brief 定义一个变量 有可能是全局变量 64 | * 65 | * @param name 变量名 66 | * @param addr 存储地址 67 | */ 68 | virtual void DefVar(const string& name, LValue addr); 69 | 70 | /** 71 | * @brief 在符号表中查找一个变量 72 | * 73 | * @param name 变量名 74 | * @return 变量的存储地址 75 | */ 76 | virtual LValue FindVar(const string& name); 77 | 78 | virtual bool isSave() { return _save; } 79 | virtual void setIsSave(bool save) { _save = save; } 80 | 81 | virtual id* FindST(Node* node) const; 82 | virtual id* FindST(const string& str) const; 83 | IDTable* st; 84 | 85 | /** 86 | * @brief 获取低层次代码生成器,目前只有llvm 87 | * @return 生成器指针 88 | */ 89 | virtual llcg* getLLCG() { return codeGenerator; } 90 | 91 | virtual void setNowPass(Pass* pass) { 92 | now_pass = pass; 93 | } 94 | 95 | virtual Pass* getNowPass() { 96 | return now_pass; 97 | } 98 | 99 | virtual PassManager* getPassManager() { 100 | return pm; 101 | } 102 | 103 | virtual void setPassManager(PassManager* pm) { 104 | this->pm = pm; 105 | } 106 | 107 | private: 108 | 109 | llcg* codeGenerator; 110 | 111 | Pass* now_pass; 112 | PassManager* pm; 113 | 114 | void setNormalType(); 115 | 116 | /** 117 | * 用来记录当前是读取还是存入状态 118 | */ 119 | bool _save; 120 | }; 121 | 122 | 123 | #endif // CODE_GEN_CONTENT_H 124 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project("Elite") 3 | 4 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/conanbuildinfo.cmake) 5 | include(${CMAKE_CURRENT_SOURCE_DIR}/build/conanbuildinfo.cmake) 6 | else() 7 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 8 | endif() 9 | conan_basic_setup() 10 | 11 | SET(VERSION_MAJOR "0") 12 | SET(VERSION_MINOR "10") 13 | SET(VERSION_PATCH "0") 14 | 15 | # SET (CMAKE_BUILD_TYPE Release) # 默认构建Debug模式 16 | 17 | # 寻找依赖项 18 | # include(${CONAN_LLVM_ROOT}/lib/cmake/llvm/LLVMConfig.cmake) 19 | 20 | # if(NOT LLVM_INSTALL_PREFIX) 21 | # message(FATAL_ERROR "ERROR! LLVM NOT FOUND!") 22 | # endif() 23 | 24 | # message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") 25 | # message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") 26 | 27 | # include_directories(${LLVM_INCLUDE_DIRS}) 28 | # add_definitions(${LLVM_DEFINITIONS}) 29 | # llvm_map_components_to_libnames(llvm_libs 30 | # support core irreader mc mcjit bitwriter x86codegen target) 31 | 32 | 33 | ## Flex/Bison configuration 34 | find_package(BISON REQUIRED) 35 | find_package(FLEX REQUIRED) 36 | 37 | if (WIN32) 38 | set (ADDITIONAL_FLEX_FLAGS "--wincompat") 39 | else() 40 | set (ADDITIONAL_FLEX_FLAGS "") 41 | endif() 42 | FLEX_TARGET(SCANNER ${CMAKE_CURRENT_SOURCE_DIR}/src/Parser/scanner.l 43 | ${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/scanner.h COMPILE_FLAGS ${ADDITIONAL_FLEX_FLAGS}) 44 | BISON_TARGET(PARSER ${CMAKE_CURRENT_SOURCE_DIR}/src/Parser/parser.y 45 | ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp COMPILE_FLAGS "-d -v") 46 | ADD_FLEX_BISON_DEPENDENCY(SCANNER PARSER) 47 | 48 | # 设定编译器版本和相关目录 49 | 50 | set (CMAKE_CXX_STANDARD 14) 51 | add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) ## It's important for gtest 52 | 53 | SET (CMAKE_CXX_FLAGS_DEBUG "-g -D_GLIBCXX_DEBUG") 54 | SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 55 | SET (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") 56 | SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") 57 | 58 | include_directories(src include header_libs) 59 | 60 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) 61 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) 62 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) 63 | 64 | 65 | # file(GLOB_RECURSE source_files 66 | # ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp 67 | # ) 68 | file(GLOB source_files 69 | ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp 70 | ${CMAKE_CURRENT_SOURCE_DIR}/src/Model/*.cpp 71 | ) 72 | list(REMOVE_ITEM source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) 73 | 74 | # 生成库目标 75 | add_library(${PROJECT_NAME} ${source_files} ${BISON_PARSER_OUTPUTS} ${FLEX_SCANNER_OUTPUTS}) 76 | add_executable(${PROJECT_NAME}_exe ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) 77 | # 链接库 78 | target_link_libraries(${PROJECT_NAME}_exe ${PROJECT_NAME} ${llvm_libs}) 79 | 80 | # 指定动态库版本 81 | # VERSION 动态库版本 82 | # SOVERSION API版本 83 | if (BUILD_SHARED_LIBS) 84 | set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} SOVERSION ${VERSION_MAJOR}) 85 | endif() 86 | 87 | add_subdirectory(doc) 88 | add_subdirectory(test) 89 | add_subdirectory(runtime) -------------------------------------------------------------------------------- /header_libs/sptr/memheap.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MEM_HEAP_HPP 2 | #define MEM_HEAP_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | class MemHeap { 12 | 13 | // 内部使用的节点类型 14 | struct MemObjNode { 15 | size_t size; 16 | int count; 17 | void* data[]; 18 | }; 19 | 20 | public: 21 | MemHeap() { 22 | 23 | } 24 | 25 | inline static void ref (void* ptr) { 26 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 27 | ++(p->count); 28 | } 29 | 30 | inline static void unref (void* ptr) { 31 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 32 | --(p->count); 33 | if (p->count == 0) getInstance()->release(ptr); 34 | } 35 | 36 | void* allocate(size_t size) { 37 | MemObjNode* p = (MemObjNode*) malloc(size + sizeof(MemObjNode)); 38 | if (p == NULL) return NULL; 39 | p->size = size; 40 | p->count = 1; 41 | all.insert(&(p->data)); 42 | printf("allocate %p\n", &(p->data)); 43 | return &(p->data); 44 | } 45 | 46 | void release(void* ptr) { 47 | if (ptr == NULL) return; 48 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 49 | all.erase(ptr); 50 | free(p); 51 | printf("release %p\n", ptr); 52 | } 53 | 54 | inline static MemHeap* getInstance() { 55 | static MemHeap instance; 56 | return &instance; 57 | } 58 | 59 | inline static void push_stack(void* ptr) { 60 | getInstance()->stack.insert(ptr); 61 | } 62 | 63 | inline static void pop_stack(void* ptr) { 64 | getInstance()->stack.erase(ptr); 65 | } 66 | 67 | 68 | static void runGC() { 69 | auto inst = getInstance(); 70 | for (void* p : inst->stack) { 71 | inst->markChildren(p); 72 | } 73 | 74 | vector v; 75 | for (void* ptr : inst->all) { 76 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 77 | if (p->count < 0) p->count = -(p->count); 78 | else v.push_back(ptr); 79 | } 80 | for (void* p : v) inst->release(p); 81 | } 82 | 83 | protected: 84 | 85 | unordered_set stack; 86 | unordered_set all; 87 | void* heap; 88 | 89 | void markChildren(void* ptr) { 90 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 91 | 92 | // 如果打了标记则退出, 否则设置标记, 标记方式则是改变符号位 93 | if (p->count < 0) return; 94 | p->count = -(p->count); 95 | printf("tag %p\n", ptr); 96 | 97 | size_t size = (p->size) / sizeof(char*); 98 | char** end = (char**)ptr + size; 99 | for (char** i = (char**)ptr; i < end; ++i) { 100 | if (all.find(*i) != all.end()) { 101 | markChildren(*i); 102 | } 103 | } 104 | } 105 | 106 | }; 107 | 108 | 109 | 110 | #endif /* end of include guard: MEM_HEAP_HPP */ 111 | -------------------------------------------------------------------------------- /header_libs/cereal/types/forward_list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file forward_list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_FORWARD_LIST_HPP_ 31 | #define CEREAL_TYPES_FORWARD_LIST_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::forward_list all other types 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::forward_list const & forward_list ) 41 | { 42 | // write the size - note that this is slow because we need to traverse 43 | // the entire list. there are ways we could avoid this but this was chosen 44 | // since it works in the most general fashion with any archive type 45 | size_type const size = std::distance( forward_list.begin(), forward_list.end() ); 46 | 47 | ar( make_size_tag( size ) ); 48 | 49 | // write the list 50 | for( const auto & i : forward_list ) 51 | ar( i ); 52 | } 53 | 54 | //! Loading for std::forward_list all other types from 55 | template 56 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::forward_list & forward_list ) 57 | { 58 | size_type size; 59 | ar( make_size_tag( size ) ); 60 | 61 | forward_list.resize( static_cast( size ) ); 62 | 63 | for( auto & i : forward_list ) 64 | ar( i ); 65 | } 66 | } // namespace cereal 67 | 68 | #endif // CEREAL_TYPES_FORWARD_LIST_HPP_ 69 | -------------------------------------------------------------------------------- /header_libs/cereal/types/string.hpp: -------------------------------------------------------------------------------- 1 | /*! \file string.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STRING_HPP_ 31 | #define CEREAL_TYPES_STRING_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serialization for basic_string types, if binary data is supported 39 | template inline 40 | typename std::enable_if, Archive>::value, void>::type 41 | CEREAL_SAVE_FUNCTION_NAME(Archive & ar, std::basic_string const & str) 42 | { 43 | // Save number of chars + the data 44 | ar( make_size_tag( static_cast(str.size()) ) ); 45 | ar( binary_data( str.data(), str.size() * sizeof(CharT) ) ); 46 | } 47 | 48 | //! Serialization for basic_string types, if binary data is supported 49 | template inline 50 | typename std::enable_if, Archive>::value, void>::type 51 | CEREAL_LOAD_FUNCTION_NAME(Archive & ar, std::basic_string & str) 52 | { 53 | size_type size; 54 | ar( make_size_tag( size ) ); 55 | str.resize(static_cast(size)); 56 | ar( binary_data( const_cast( str.data() ), static_cast(size) * sizeof(CharT) ) ); 57 | } 58 | } // namespace cereal 59 | 60 | #endif // CEREAL_TYPES_STRING_HPP_ 61 | 62 | -------------------------------------------------------------------------------- /header_libs/cereal/types/chrono.hpp: -------------------------------------------------------------------------------- 1 | /*! \file chrono.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_CHRONO_HPP_ 31 | #define CEREAL_TYPES_CHRONO_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Saving std::chrono::duration 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::duration const & dur ) 40 | { 41 | ar( CEREAL_NVP_("count", dur.count()) ); 42 | } 43 | 44 | //! Loading std::chrono::duration 45 | template inline 46 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::duration & dur ) 47 | { 48 | R count; 49 | ar( CEREAL_NVP_("count", count) ); 50 | 51 | dur = std::chrono::duration{count}; 52 | } 53 | 54 | //! Saving std::chrono::time_point 55 | template inline 56 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::time_point const & dur ) 57 | { 58 | ar( CEREAL_NVP_("time_since_epoch", dur.time_since_epoch()) ); 59 | } 60 | 61 | //! Loading std::chrono::time_point 62 | template inline 63 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::time_point & dur ) 64 | { 65 | D elapsed; 66 | ar( CEREAL_NVP_("time_since_epoch", elapsed) ); 67 | 68 | dur = std::chrono::time_point{elapsed}; 69 | } 70 | } // namespace cereal 71 | 72 | #endif // CEREAL_TYPES_CHRONO_HPP_ 73 | -------------------------------------------------------------------------------- /header_libs/cereal/types/stack.hpp: -------------------------------------------------------------------------------- 1 | /*! \file stack.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STACK_HPP_ 31 | #define CEREAL_TYPES_STACK_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | // The default container for stack is deque, so let's include that too 37 | #include 38 | 39 | namespace cereal 40 | { 41 | namespace stack_detail 42 | { 43 | //! Allows access to the protected container in stack 44 | template inline 45 | C const & container( std::stack const & stack ) 46 | { 47 | struct H : public std::stack 48 | { 49 | static C const & get( std::stack const & s ) 50 | { 51 | return s.*(&H::c); 52 | } 53 | }; 54 | 55 | return H::get( stack ); 56 | } 57 | } 58 | 59 | //! Saving for std::stack 60 | template inline 61 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::stack const & stack ) 62 | { 63 | ar( CEREAL_NVP_("container", stack_detail::container( stack )) ); 64 | } 65 | 66 | //! Loading for std::stack 67 | template inline 68 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::stack & stack ) 69 | { 70 | C container; 71 | ar( CEREAL_NVP_("container", container) ); 72 | stack = std::stack( std::move( container ) ); 73 | } 74 | } // namespace cereal 75 | 76 | #endif // CEREAL_TYPES_STACK_HPP_ 77 | -------------------------------------------------------------------------------- /header_libs/cereal/details/util.hpp: -------------------------------------------------------------------------------- 1 | /*! \file util.hpp 2 | \brief Internal misc utilities 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_DETAILS_UTIL_HPP_ 31 | #define CEREAL_DETAILS_UTIL_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | #ifdef _MSC_VER 37 | namespace cereal 38 | { 39 | namespace util 40 | { 41 | //! Demangles the type encoded in a string 42 | /*! @internal */ 43 | inline std::string demangle( std::string const & name ) 44 | { return name; } 45 | 46 | //! Gets the demangled name of a type 47 | /*! @internal */ 48 | template inline 49 | std::string demangledName() 50 | { return typeid( T ).name(); } 51 | } // namespace util 52 | } // namespace cereal 53 | #else // clang or gcc 54 | #include 55 | #include 56 | namespace cereal 57 | { 58 | namespace util 59 | { 60 | //! Demangles the type encoded in a string 61 | /*! @internal */ 62 | inline std::string demangle(std::string mangledName) 63 | { 64 | int status = 0; 65 | char *demangledName = nullptr; 66 | std::size_t len; 67 | 68 | demangledName = abi::__cxa_demangle(mangledName.c_str(), 0, &len, &status); 69 | 70 | std::string retName(demangledName); 71 | free(demangledName); 72 | 73 | return retName; 74 | } 75 | 76 | //! Gets the demangled name of a type 77 | /*! @internal */ 78 | template inline 79 | std::string demangledName() 80 | { return demangle(typeid(T).name()); } 81 | } 82 | } // namespace cereal 83 | #endif // clang or gcc branch of _MSC_VER 84 | #endif // CEREAL_DETAILS_UTIL_HPP_ 85 | -------------------------------------------------------------------------------- /src/Macro/Prescan.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-10-29 11:05:42 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 09:41:18 6 | */ 7 | 8 | #include "Elite/CodeGen/CodeGenContext.h" 9 | #include "Elite/Model/StringNode.h" 10 | #include "Elite/MetaModel/StructModel.h" 11 | #include "Elite/MetaModel/FunctionModel.h" 12 | #include "Elite/Model/IDNode.h" 13 | #include "Translater/idtable.h" 14 | #include 15 | 16 | static LValue function_macro(CodeGenContext* context, Node* node) { 17 | // 第一个参数, 返回类型 18 | std::string ret_type = node->getStr(); 19 | 20 | // 第二个参数, 函数名 21 | node = node->getNext(); 22 | std::string function_name = node->getStr(); 23 | 24 | // 第三个参数, 参数表 25 | Node* args_node = node = node->getNext(); 26 | std::vector type_vec; 27 | std::vector arg_name; 28 | if (args_node->getChild() != NULL) { 29 | for (Node* pC = args_node->getChild(); 30 | pC != NULL; pC = pC->getNext() ) 31 | { 32 | Node* pSec = pC->getChild()->getNext(); 33 | type_vec.push_back(pSec->getStr()); 34 | pSec = pSec->getNext(); 35 | arg_name.push_back(pSec->getStr()); 36 | pSec = pSec->getNext(); 37 | if (pSec != NULL) 38 | { 39 | LValue v = pSec->getNext()->codeGen(context); 40 | } else { 41 | } 42 | } 43 | } 44 | FunctionModel* fm = new FunctionModel(function_name, ret_type, type_vec, arg_name); 45 | fm->insertToST(context); 46 | return NULL; 47 | } 48 | 49 | static LValue struct_macro(CodeGenContext* context, Node* node) { 50 | // 第一个参数, 结构体名 51 | std::string struct_name = node->getStr(); 52 | Node* args_node = node->getNext(); 53 | std::vector type_vec; 54 | std::vector arg_name; 55 | if (args_node->getChild() != NULL) { 56 | for (Node* pC = args_node->getChild(); 57 | pC != NULL; pC = pC->getNext() ) 58 | { 59 | Node* pSec = pC->getChild()->getNext(); 60 | type_vec.push_back(pSec->getStr()); 61 | arg_name.push_back(pSec->getNext()->getStr()); 62 | } 63 | } 64 | StructModel* sm = new StructModel(struct_name, type_vec, arg_name); 65 | sm->insertToST(context); 66 | return NULL; 67 | } 68 | 69 | static LValue struct_type_macro(CodeGenContext* context, Node* node) { 70 | // 第一个参数, 结构体名 71 | std::string struct_name = node->getStr(); 72 | id* i = context->st->find(struct_name); 73 | if (i->type != struct_t) return NULL; 74 | auto sm = dynamic_pointer_cast(i->data); 75 | sm->genCode(context); 76 | return NULL; 77 | } 78 | 79 | 80 | static LValue function_type_macro(CodeGenContext* context, Node* node) { 81 | // 第二个参数, 函数名 82 | node = node->getNext(); 83 | std::string function_name = node->getStr(); 84 | id* i = context->st->find(function_name); 85 | if (i == NULL || i->type != function_t) return NULL; 86 | auto fm = dynamic_pointer_cast(i->data); 87 | fm->genCode(context); 88 | return NULL; 89 | } 90 | 91 | static LValue defmacro_macro(CodeGenContext* context, Node* node) { 92 | context->setUserMacro(node->getStr(), node->getNext()); 93 | return NULL; 94 | } 95 | 96 | extern const FuncReg macro_prescan[] = { 97 | {"function", function_macro}, 98 | {"struct", struct_macro}, 99 | {NULL, NULL} 100 | }; 101 | 102 | extern const FuncReg macro_pretype[] = { 103 | {"function", function_type_macro}, 104 | {"struct", struct_type_macro}, 105 | {NULL, NULL} 106 | }; 107 | 108 | extern const FuncReg macro_defmacro[] = { 109 | {"defmacro", defmacro_macro}, 110 | {NULL, NULL} 111 | }; 112 | -------------------------------------------------------------------------------- /src/Parser/scanner.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include "Model/nodes.h" 4 | #include 5 | using namespace std; 6 | 7 | #include "redapple_parser.hpp" 8 | 9 | #define SAVE_TOKEN yylval.str = maketoken(yytext, yyleng) 10 | #define SAVE_STRING yylval.str = maketoken(yytext, yyleng) 11 | #define SAVE_STRING_NC yylval.str = maketoken(yytext, yyleng) 12 | extern "C" int yywrap() { return 1; } 13 | char* maketoken(const char* data, int len); 14 | %} 15 | 16 | %option yylineno 17 | %option reentrant noyywrap 18 | %option bison-bridge bison-locations 19 | 20 | %% 21 | 22 | "/*"([^\*]|(\*)*[^\*/])*(\*)*"*/" ; /* 就是这种注释 */ 23 | "//"[^\n]*\n ; /* 双线注释 */ 24 | 25 | [ \t\v\n\f]+ ; /* 过滤空白字符 */ 26 | 27 | "++" return PP; 28 | "--" return SS; 29 | "!" return '!'; 30 | 31 | /* 一些双元运算符 */ 32 | "<-" return LF; 33 | "->" return RF; 34 | "&&" return AND; 35 | "||" return OR; 36 | "::" return NSP; 37 | 38 | "+=" return PE; 39 | "-=" return SE; 40 | "*=" return ME; 41 | "/=" return DE; 42 | "&=" return AE; 43 | "|=" return OE; 44 | "^=" return XE; 45 | "%=" return MODE; 46 | "<<=" return FLE; 47 | ">>=" return FRE; 48 | 49 | 50 | /* 比较运算符 */ 51 | "==" return CEQ; 52 | "<=" return CLE; 53 | ">=" return CGE; 54 | "!=" return CNE; 55 | "<" return '<'; 56 | ">" return '>'; 57 | 58 | 59 | /* 界符 */ 60 | "(" return '('; 61 | ")" return ')'; 62 | "[" return '['; 63 | "]" return ']'; 64 | "{" return '{'; 65 | "}" return '}'; 66 | "." return '.'; 67 | "," return ','; 68 | "?" return '?'; 69 | ":" return ':'; 70 | ";" return ';'; 71 | "[]" return SZ; 72 | 73 | 74 | /* 基本运算符 */ 75 | "=" return '='; 76 | "+" return '+'; 77 | "-" return '-'; 78 | "*" return '*'; 79 | "/" return '/'; 80 | "%" return '%'; 81 | "^" return '^'; 82 | "&" return '&'; 83 | "|" return '|'; 84 | "~" return '~'; 85 | 86 | /* 宏运算符 */ 87 | "@" return '@'; 88 | ",@" return MBK; 89 | "`" return '`'; 90 | 91 | [a-zA-Z_][a-zA-Z0-9_]* SAVE_TOKEN; return ID; /* 标识符 */ 92 | 93 | -?[0-9]*\.[0-9]* SAVE_TOKEN; return DOUBLE; 94 | -?[0-9]+ SAVE_TOKEN; return INTEGER; 95 | 0x[0-9A-Fa-f]+ SAVE_TOKEN; return INTEGER; 96 | 97 | \"(\\.|[^\\"])*\" SAVE_STRING; return STRING; /* 字符串 */ 98 | @\"(\\.|[^\\"])*\" SAVE_STRING_NC; return STRING; /* 无转义字符串 */ 99 | \'(\\.|.)\' SAVE_STRING; return CHAR; /* 字符 */ 100 | 101 | . printf("Unknown Token!\n"); yyterminate(); 102 | 103 | %% 104 | 105 | 106 | char* maketoken(const char* data, int len) { 107 | char* str = new char[len+1]; 108 | strncpy(str, data, len); 109 | str[len] = 0; 110 | return str; 111 | } 112 | -------------------------------------------------------------------------------- /header_libs/cereal/types/array.hpp: -------------------------------------------------------------------------------- 1 | /*! \file array.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_ARRAY_HPP_ 31 | #define CEREAL_TYPES_ARRAY_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::array primitive types 39 | //! using binary serialization, if supported 40 | template inline 41 | typename std::enable_if, Archive>::value 42 | && std::is_arithmetic::value, void>::type 43 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 44 | { 45 | ar( binary_data( array.data(), sizeof(array) ) ); 46 | } 47 | 48 | //! Loading for std::array primitive types 49 | //! using binary serialization, if supported 50 | template inline 51 | typename std::enable_if, Archive>::value 52 | && std::is_arithmetic::value, void>::type 53 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 54 | { 55 | ar( binary_data( array.data(), sizeof(array) ) ); 56 | } 57 | 58 | //! Saving for std::array all other types 59 | template inline 60 | typename std::enable_if, Archive>::value 61 | || !std::is_arithmetic::value, void>::type 62 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 63 | { 64 | for( auto const & i : array ) 65 | ar( i ); 66 | } 67 | 68 | //! Loading for std::array all other types 69 | template inline 70 | typename std::enable_if, Archive>::value 71 | || !std::is_arithmetic::value, void>::type 72 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 73 | { 74 | for( auto & i : array ) 75 | ar( i ); 76 | } 77 | } // namespace cereal 78 | 79 | #endif // CEREAL_TYPES_ARRAY_HPP_ 80 | -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidxml/rapidxml_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDXML_UTILS_HPP_INCLUDED 2 | #define RAPIDXML_UTILS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective. 8 | 9 | #include "rapidxml.hpp" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace rapidxml 16 | { 17 | 18 | //! Represents data loaded from a file 19 | template 20 | class file 21 | { 22 | 23 | public: 24 | 25 | //! Loads file into the memory. Data will be automatically destroyed by the destructor. 26 | //! \param filename Filename to load. 27 | file(const char *filename) 28 | { 29 | using namespace std; 30 | 31 | // Open stream 32 | basic_ifstream stream(filename, ios::binary); 33 | if (!stream) 34 | throw runtime_error(string("cannot open file ") + filename); 35 | stream.unsetf(ios::skipws); 36 | 37 | // Determine stream size 38 | stream.seekg(0, ios::end); 39 | size_t size = stream.tellg(); 40 | stream.seekg(0); 41 | 42 | // Load data and add terminating 0 43 | m_data.resize(size + 1); 44 | stream.read(&m_data.front(), static_cast(size)); 45 | m_data[size] = 0; 46 | } 47 | 48 | //! Loads file into the memory. Data will be automatically destroyed by the destructor 49 | //! \param stream Stream to load from 50 | file(std::basic_istream &stream) 51 | { 52 | using namespace std; 53 | 54 | // Load data and add terminating 0 55 | stream.unsetf(ios::skipws); 56 | m_data.assign(istreambuf_iterator(stream), istreambuf_iterator()); 57 | if (stream.fail() || stream.bad()) 58 | throw runtime_error("error reading stream"); 59 | m_data.push_back(0); 60 | } 61 | 62 | //! Gets file data. 63 | //! \return Pointer to data of file. 64 | Ch *data() 65 | { 66 | return &m_data.front(); 67 | } 68 | 69 | //! Gets file data. 70 | //! \return Pointer to data of file. 71 | const Ch *data() const 72 | { 73 | return &m_data.front(); 74 | } 75 | 76 | //! Gets file data size. 77 | //! \return Size of file data, in characters. 78 | std::size_t size() const 79 | { 80 | return m_data.size(); 81 | } 82 | 83 | private: 84 | 85 | std::vector m_data; // File data 86 | 87 | }; 88 | 89 | //! Counts children of node. Time complexity is O(n). 90 | //! \return Number of children of node 91 | template 92 | inline std::size_t count_children(xml_node *node) 93 | { 94 | xml_node *child = node->first_node(); 95 | std::size_t count = 0; 96 | while (child) 97 | { 98 | ++count; 99 | child = child->next_sibling(); 100 | } 101 | return count; 102 | } 103 | 104 | //! Counts attributes of node. Time complexity is O(n). 105 | //! \return Number of attributes of node 106 | template 107 | inline std::size_t count_attributes(xml_node *node) 108 | { 109 | xml_attribute *attr = node->first_attribute(); 110 | std::size_t count = 0; 111 | while (attr) 112 | { 113 | ++count; 114 | attr = attr->next_attribute(); 115 | } 116 | return count; 117 | } 118 | 119 | } 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /header_libs/cereal/types/set.hpp: -------------------------------------------------------------------------------- 1 | /*! \file set.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_SET_HPP_ 31 | #define CEREAL_TYPES_SET_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace set_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, SetT const & set ) 43 | { 44 | ar( make_size_tag( static_cast(set.size()) ) ); 45 | 46 | for( const auto & i : set ) 47 | ar( i ); 48 | } 49 | 50 | //! @internal 51 | template inline 52 | void load( Archive & ar, SetT & set ) 53 | { 54 | size_type size; 55 | ar( make_size_tag( size ) ); 56 | 57 | set.clear(); 58 | 59 | auto hint = set.begin(); 60 | for( size_type i = 0; i < size; ++i ) 61 | { 62 | typename SetT::key_type key; 63 | 64 | ar( key ); 65 | #ifdef CEREAL_OLDER_GCC 66 | hint = set.insert( hint, std::move( key ) ); 67 | #else // NOT CEREAL_OLDER_GCC 68 | hint = set.emplace_hint( hint, std::move( key ) ); 69 | #endif // NOT CEREAL_OLDER_GCC 70 | } 71 | } 72 | } 73 | 74 | //! Saving for std::set 75 | template inline 76 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::set const & set ) 77 | { 78 | set_detail::save( ar, set ); 79 | } 80 | 81 | //! Loading for std::set 82 | template inline 83 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::set & set ) 84 | { 85 | set_detail::load( ar, set ); 86 | } 87 | 88 | //! Saving for std::multiset 89 | template inline 90 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::multiset const & multiset ) 91 | { 92 | set_detail::save( ar, multiset ); 93 | } 94 | 95 | //! Loading for std::multiset 96 | template inline 97 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::multiset & multiset ) 98 | { 99 | set_detail::load( ar, multiset ); 100 | } 101 | } // namespace cereal 102 | 103 | #endif // CEREAL_TYPES_SET_HPP_ 104 | -------------------------------------------------------------------------------- /header_libs/cereal/details/static_object.hpp: -------------------------------------------------------------------------------- 1 | /*! \file static_object.hpp 2 | \brief Internal polymorphism static object support 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of cereal nor the 15 | names of its contributors may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | #ifndef CEREAL_DETAILS_STATIC_OBJECT_HPP_ 29 | #define CEREAL_DETAILS_STATIC_OBJECT_HPP_ 30 | 31 | //! Prevent link optimization from removing non-referenced static objects 32 | /*! Especially for polymorphic support, we create static objects which 33 | may not ever be explicitly referenced. Most linkers will detect this 34 | and remove the code causing various unpleasant runtime errors. These 35 | macros, adopted from Boost (see force_include.hpp) prevent this 36 | (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 37 | Use, modification and distribution is subject to the Boost Software 38 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 39 | http://www.boost.org/LICENSE_1_0.txt) */ 40 | 41 | #ifdef _MSC_VER 42 | # define CEREAL_DLL_EXPORT __declspec(dllexport) 43 | # define CEREAL_USED 44 | #else // clang or gcc 45 | # define CEREAL_DLL_EXPORT 46 | # define CEREAL_USED __attribute__ ((__used__)) 47 | #endif 48 | 49 | namespace cereal 50 | { 51 | namespace detail 52 | { 53 | //! A static, pre-execution object 54 | /*! This class will create a single copy (singleton) of some 55 | type and ensures that merely referencing this type will 56 | cause it to be instantiated and initialized pre-execution. 57 | For example, this is used heavily in the polymorphic pointer 58 | serialization mechanisms to bind various archive types with 59 | different polymorphic classes */ 60 | template 61 | class CEREAL_DLL_EXPORT StaticObject 62 | { 63 | private: 64 | //! Forces instantiation at pre-execution time 65 | static void instantiate( T const & ) {} 66 | 67 | static T & create() 68 | { 69 | static T t; 70 | instantiate(instance); 71 | return t; 72 | } 73 | 74 | StaticObject( StaticObject const & /*other*/ ) {} 75 | 76 | public: 77 | static T & getInstance() 78 | { 79 | return create(); 80 | } 81 | 82 | private: 83 | static T & instance; 84 | }; 85 | 86 | template T & StaticObject::instance = StaticObject::create(); 87 | } // namespace detail 88 | } // namespace cereal 89 | 90 | #endif // CEREAL_DETAILS_STATIC_OBJECT_HPP_ -------------------------------------------------------------------------------- /header_libs/cereal/types/bitset.hpp: -------------------------------------------------------------------------------- 1 | /*! \file bitset.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_BITSET_HPP_ 31 | #define CEREAL_TYPES_BITSET_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace bitset_detail 39 | { 40 | //! The type the bitset is encoded with 41 | /*! @internal */ 42 | enum class type : uint8_t 43 | { 44 | ulong, 45 | ullong, 46 | string 47 | }; 48 | } 49 | 50 | //! Serializing (save) for std::bitset 51 | template inline 52 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::bitset const & bits ) 53 | { 54 | try 55 | { 56 | auto const b = bits.to_ulong(); 57 | ar( CEREAL_NVP_("type", bitset_detail::type::ulong) ); 58 | ar( CEREAL_NVP_("data", b) ); 59 | } 60 | catch( std::overflow_error const & ) 61 | { 62 | try 63 | { 64 | auto const b = bits.to_ullong(); 65 | ar( CEREAL_NVP_("type", bitset_detail::type::ullong) ); 66 | ar( CEREAL_NVP_("data", b) ); 67 | } 68 | catch( std::overflow_error const & ) 69 | { 70 | ar( CEREAL_NVP_("type", bitset_detail::type::string) ); 71 | ar( CEREAL_NVP_("data", bits.to_string()) ); 72 | } 73 | } 74 | } 75 | 76 | //! Serializing (load) for std::bitset 77 | template inline 78 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::bitset & bits ) 79 | { 80 | bitset_detail::type t; 81 | ar( CEREAL_NVP_("type", t) ); 82 | 83 | switch( t ) 84 | { 85 | case bitset_detail::type::ulong: 86 | { 87 | unsigned long b; 88 | ar( CEREAL_NVP_("data", b) ); 89 | bits = std::bitset( b ); 90 | break; 91 | } 92 | case bitset_detail::type::ullong: 93 | { 94 | unsigned long long b; 95 | ar( CEREAL_NVP_("data", b) ); 96 | bits = std::bitset( b ); 97 | break; 98 | } 99 | case bitset_detail::type::string: 100 | { 101 | std::string b; 102 | ar( CEREAL_NVP_("data", b) ); 103 | bits = std::bitset( b ); 104 | break; 105 | } 106 | default: 107 | throw Exception("Invalid bitset data representation"); 108 | } 109 | } 110 | } // namespace cereal 111 | 112 | #endif // CEREAL_TYPES_BITSET_HPP_ 113 | -------------------------------------------------------------------------------- /header_libs/cereal/macros.hpp: -------------------------------------------------------------------------------- 1 | /*! \file macros.hpp 2 | \brief Preprocessor macros that can customise the cereal library 3 | 4 | By default, cereal looks for serialization functions with very 5 | specific names, that is: serialize, load, save, load_minimal, 6 | or save_minimal. 7 | 8 | This file allows an advanced user to change these names to conform 9 | to some other style or preference. This is implemented using 10 | preprocessor macros. 11 | 12 | As a result of this, in internal cereal code you will see macros 13 | used for these function names. In user code, you should name 14 | the functions like you normally would and not use the macros 15 | to improve readability. 16 | \ingroup utility */ 17 | /* 18 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 19 | All rights reserved. 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions are met: 23 | * Redistributions of source code must retain the above copyright 24 | notice, this list of conditions and the following disclaimer. 25 | * Redistributions in binary form must reproduce the above copyright 26 | notice, this list of conditions and the following disclaimer in the 27 | documentation and/or other materials provided with the distribution. 28 | * Neither the name of cereal nor the 29 | names of its contributors may be used to endorse or promote products 30 | derived from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 33 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 34 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 35 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 36 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 37 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 38 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 39 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 41 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | */ 43 | 44 | #ifndef CEREAL_MACROS_HPP_ 45 | #define CEREAL_MACROS_HPP_ 46 | 47 | #ifndef CEREAL_SERIALIZE_FUNCTION_NAME 48 | //! The serialization/deserialization function name to search for. 49 | /*! You can define @c CEREAL_SERIALIZE_FUNCTION_NAME to be different assuming 50 | you do so before this file is included. */ 51 | #define CEREAL_SERIALIZE_FUNCTION_NAME serialize 52 | #endif // CEREAL_SERIALIZE_FUNCTION_NAME 53 | 54 | #ifndef CEREAL_LOAD_FUNCTION_NAME 55 | //! The deserialization (load) function name to search for. 56 | /*! You can define @c CEREAL_LOAD_FUNCTION_NAME to be different assuming you do so 57 | before this file is included. */ 58 | #define CEREAL_LOAD_FUNCTION_NAME load 59 | #endif // CEREAL_LOAD_FUNCTION_NAME 60 | 61 | #ifndef CEREAL_SAVE_FUNCTION_NAME 62 | //! The serialization (save) function name to search for. 63 | /*! You can define @c CEREAL_SAVE_FUNCTION_NAME to be different assuming you do so 64 | before this file is included. */ 65 | #define CEREAL_SAVE_FUNCTION_NAME save 66 | #endif // CEREAL_SAVE_FUNCTION_NAME 67 | 68 | #ifndef CEREAL_LOAD_MINIMAL_FUNCTION_NAME 69 | //! The deserialization (load_minimal) function name to search for. 70 | /*! You can define @c CEREAL_LOAD_MINIMAL_FUNCTION_NAME to be different assuming you do so 71 | before this file is included. */ 72 | #define CEREAL_LOAD_MINIMAL_FUNCTION_NAME load_minimal 73 | #endif // CEREAL_LOAD_MINIMAL_FUNCTION_NAME 74 | 75 | #ifndef CEREAL_SAVE_MINIMAL_FUNCTION_NAME 76 | //! The serialization (save_minimal) function name to search for. 77 | /*! You can define @c CEREAL_SAVE_MINIMAL_FUNCTION_NAME to be different assuming you do so 78 | before this file is included. */ 79 | #define CEREAL_SAVE_MINIMAL_FUNCTION_NAME save_minimal 80 | #endif // CEREAL_SAVE_MINIMAL_FUNCTION_NAME 81 | 82 | #endif // CEREAL_MACROS_HPP_ 83 | -------------------------------------------------------------------------------- /header_libs/cereal/types/unordered_set.hpp: -------------------------------------------------------------------------------- 1 | /*! \file unordered_set.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UNORDERED_SET_HPP_ 31 | #define CEREAL_TYPES_UNORDERED_SET_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace unordered_set_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, SetT const & set ) 43 | { 44 | ar( make_size_tag( static_cast(set.size()) ) ); 45 | 46 | for( const auto & i : set ) 47 | ar( i ); 48 | } 49 | 50 | //! @internal 51 | template inline 52 | void load( Archive & ar, SetT & set ) 53 | { 54 | size_type size; 55 | ar( make_size_tag( size ) ); 56 | 57 | set.clear(); 58 | set.reserve( static_cast( size ) ); 59 | 60 | for( size_type i = 0; i < size; ++i ) 61 | { 62 | typename SetT::key_type key; 63 | 64 | ar( key ); 65 | set.emplace( std::move( key ) ); 66 | } 67 | } 68 | } 69 | 70 | //! Saving for std::unordered_set 71 | template inline 72 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unordered_set const & unordered_set ) 73 | { 74 | unordered_set_detail::save( ar, unordered_set ); 75 | } 76 | 77 | //! Loading for std::unordered_set 78 | template inline 79 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unordered_set & unordered_set ) 80 | { 81 | unordered_set_detail::load( ar, unordered_set ); 82 | } 83 | 84 | //! Saving for std::unordered_multiset 85 | template inline 86 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unordered_multiset const & unordered_multiset ) 87 | { 88 | unordered_set_detail::save( ar, unordered_multiset ); 89 | } 90 | 91 | //! Loading for std::unordered_multiset 92 | template inline 93 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unordered_multiset & unordered_multiset ) 94 | { 95 | unordered_set_detail::load( ar, unordered_multiset ); 96 | } 97 | } // namespace cereal 98 | 99 | #endif // CEREAL_TYPES_UNORDERED_SET_HPP_ 100 | -------------------------------------------------------------------------------- /header_libs/cereal/types/valarray.hpp: -------------------------------------------------------------------------------- 1 | /*! \file valarray.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | 5 | /* 6 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of cereal nor the 17 | names of its contributors may be used to endorse or promote products 18 | derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 24 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef CEREAL_TYPES_VALARRAY_HPP_ 33 | #define CEREAL_TYPES_VALARRAY_HPP_ 34 | 35 | #include 36 | #include 37 | 38 | namespace cereal 39 | { 40 | //! Saving for std::valarray arithmetic types, using binary serialization, if supported 41 | template inline 42 | typename std::enable_if, Archive>::value 43 | && std::is_arithmetic::value, void>::type 44 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray const & valarray ) 45 | { 46 | ar( make_size_tag( static_cast(valarray.size()) ) ); // number of elements 47 | ar( binary_data( &valarray[0], valarray.size() * sizeof(T) ) ); // &valarray[0] ok since guaranteed contiguous 48 | } 49 | 50 | //! Loading for std::valarray arithmetic types, using binary serialization, if supported 51 | template inline 52 | typename std::enable_if, Archive>::value 53 | && std::is_arithmetic::value, void>::type 54 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray & valarray ) 55 | { 56 | size_type valarraySize; 57 | ar( make_size_tag( valarraySize ) ); 58 | 59 | valarray.resize( static_cast( valarraySize ) ); 60 | ar( binary_data( &valarray[0], static_cast( valarraySize ) * sizeof(T) ) ); 61 | } 62 | 63 | //! Saving for std::valarray all other types 64 | template inline 65 | typename std::enable_if, Archive>::value 66 | || !std::is_arithmetic::value, void>::type 67 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray const & valarray ) 68 | { 69 | ar( make_size_tag( static_cast(valarray.size()) ) ); // number of elements 70 | for(auto && v : valarray) 71 | ar(v); 72 | } 73 | 74 | //! Loading for std::valarray all other types 75 | template inline 76 | typename std::enable_if, Archive>::value 77 | || !std::is_arithmetic::value, void>::type 78 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray & valarray ) 79 | { 80 | size_type valarraySize; 81 | ar( make_size_tag( valarraySize ) ); 82 | 83 | valarray.resize( static_cast( valarraySize ) ); 84 | for(auto && v : valarray) 85 | ar(v); 86 | } 87 | } // namespace cereal 88 | 89 | #endif // CEREAL_TYPES_VALARRAY_HPP_ 90 | -------------------------------------------------------------------------------- /src/LLCG/LLVMLIB/llvm_libs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-24 10:21:35 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-16 22:22:28 6 | */ 7 | 8 | #include "LLCG/LLVMLIB/llcg_llvm.h" 9 | 10 | 11 | static void register_printf(llvm::Module *module) { 12 | std::vector printf_arg_types; 13 | printf_arg_types.push_back(llvm::Type::getInt8PtrTy(module->getContext())); 14 | 15 | llvm::FunctionType* printf_type = 16 | llvm::FunctionType::get( 17 | llvm::Type::getInt32Ty(module->getContext()), printf_arg_types, true); 18 | 19 | llvm::Function *func = llvm::Function::Create( 20 | printf_type, llvm::Function::ExternalLinkage, 21 | llvm::Twine("printf"), 22 | module 23 | ); 24 | func->setCallingConv(llvm::CallingConv::C); 25 | } 26 | 27 | static void register_functioncall(llvm::Module *module) { 28 | std::vector arg_types; 29 | arg_types.push_back(llvm::Type::getInt8PtrTy(module->getContext())); 30 | 31 | llvm::FunctionType* func_type = 32 | llvm::FunctionType::get( 33 | llvm::Type::getInt8PtrTy(module->getContext()), arg_types, true); 34 | 35 | llvm::Function *func = llvm::Function::Create( 36 | func_type, llvm::Function::ExternalLinkage, 37 | llvm::Twine("FunctionCall"), 38 | module 39 | ); 40 | func->setCallingConv(llvm::CallingConv::C); 41 | } 42 | 43 | 44 | static void register_elite_meta_function(Module *module) { 45 | std::vector arg_types; 46 | arg_types.push_back(Type::getInt8PtrTy(module->getContext())); 47 | arg_types.push_back(Type::getInt8PtrTy(module->getContext())->getPointerTo()); 48 | arg_types.push_back(Type::getInt8PtrTy(module->getContext())); 49 | 50 | FunctionType* meta_type = 51 | FunctionType::get( 52 | Type::getVoidTy(module->getContext()), arg_types, false); 53 | 54 | Function *func = Function::Create( 55 | meta_type, Function::ExternalLinkage, 56 | Twine("elite_meta_function"), 57 | module 58 | ); 59 | func->setCallingConv(CallingConv::C); 60 | } 61 | 62 | static void register_elite_meta_list(Module *module) { 63 | std::vector arg_types; 64 | arg_types.push_back(Type::getInt8PtrTy(module->getContext())->getPointerTo()); 65 | 66 | FunctionType* meta_type = 67 | FunctionType::get( 68 | Type::getVoidTy(module->getContext()), arg_types, true); 69 | 70 | Function *func = Function::Create( 71 | meta_type, Function::ExternalLinkage, 72 | Twine("elite_meta_list"), 73 | module 74 | ); 75 | func->setCallingConv(CallingConv::C); 76 | } 77 | 78 | 79 | static void register_elite_meta_init(Module *module) { 80 | std::vector arg_types; 81 | 82 | FunctionType* meta_type = 83 | FunctionType::get( 84 | Type::getVoidTy(module->getContext()), arg_types, false); 85 | 86 | Function *func = Function::Create( 87 | meta_type, Function::InternalLinkage, 88 | Twine("elite_meta_init"), 89 | module 90 | ); 91 | func->setCallingConv(CallingConv::C); 92 | 93 | BasicBlock::Create(module->getContext(), "entry", func); 94 | } 95 | 96 | static void register_malloc_array(Module *module) { 97 | std::vector arg_types; 98 | arg_types.push_back(Type::getInt64Ty(module->getContext())); 99 | 100 | FunctionType* meta_type = 101 | FunctionType::get( 102 | Type::getInt8PtrTy(module->getContext()), arg_types, true); 103 | 104 | Function *func = Function::Create( 105 | meta_type, Function::ExternalLinkage, 106 | Twine("malloc_array"), 107 | module 108 | ); 109 | func->setCallingConv(CallingConv::C); 110 | } 111 | 112 | extern const LibFunc stdlibs[] = { 113 | register_printf, 114 | register_functioncall, 115 | register_malloc_array, 116 | NULL 117 | }; 118 | 119 | extern const LibFunc metalibs[] = { 120 | register_elite_meta_function, 121 | register_elite_meta_list, 122 | register_elite_meta_init, 123 | NULL 124 | }; 125 | -------------------------------------------------------------------------------- /header_libs/cereal/types/unordered_map.hpp: -------------------------------------------------------------------------------- 1 | /*! \file unordered_map.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UNORDERED_MAP_HPP_ 31 | #define CEREAL_TYPES_UNORDERED_MAP_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace unordered_map_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, MapT const & map ) 43 | { 44 | ar( make_size_tag( static_cast(map.size()) ) ); 45 | 46 | for( const auto & i : map ) 47 | ar( make_map_item(i.first, i.second) ); 48 | } 49 | 50 | //! @internal 51 | template inline 52 | void load( Archive & ar, MapT & map ) 53 | { 54 | size_type size; 55 | ar( make_size_tag( size ) ); 56 | 57 | map.clear(); 58 | map.reserve( static_cast( size ) ); 59 | 60 | for( size_type i = 0; i < size; ++i ) 61 | { 62 | typename MapT::key_type key; 63 | typename MapT::mapped_type value; 64 | 65 | ar( make_map_item(key, value) ); 66 | map.emplace( std::move( key ), std::move( value ) ); 67 | } 68 | } 69 | } 70 | 71 | //! Saving for std::unordered_map 72 | template inline 73 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unordered_map const & unordered_map ) 74 | { 75 | unordered_map_detail::save( ar, unordered_map ); 76 | } 77 | 78 | //! Loading for std::unordered_map 79 | template inline 80 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unordered_map & unordered_map ) 81 | { 82 | unordered_map_detail::load( ar, unordered_map ); 83 | } 84 | 85 | //! Saving for std::unordered_multimap 86 | template inline 87 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::unordered_multimap const & unordered_multimap ) 88 | { 89 | unordered_map_detail::save( ar, unordered_multimap ); 90 | } 91 | 92 | //! Loading for std::unordered_multimap 93 | template inline 94 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::unordered_multimap & unordered_multimap ) 95 | { 96 | unordered_map_detail::load( ar, unordered_multimap ); 97 | } 98 | } // namespace cereal 99 | 100 | #endif // CEREAL_TYPES_UNORDERED_MAP_HPP_ 101 | -------------------------------------------------------------------------------- /header_libs/cereal/types/map.hpp: -------------------------------------------------------------------------------- 1 | /*! \file map.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_MAP_HPP_ 31 | #define CEREAL_TYPES_MAP_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace map_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, MapT const & map ) 43 | { 44 | ar( make_size_tag( static_cast(map.size()) ) ); 45 | 46 | for( const auto & i : map ) 47 | { 48 | ar( make_map_item(i.first, i.second) ); 49 | } 50 | } 51 | 52 | //! @internal 53 | template inline 54 | void load( Archive & ar, MapT & map ) 55 | { 56 | size_type size; 57 | ar( make_size_tag( size ) ); 58 | 59 | map.clear(); 60 | 61 | auto hint = map.begin(); 62 | for( size_t i = 0; i < size; ++i ) 63 | { 64 | typename MapT::key_type key; 65 | typename MapT::mapped_type value; 66 | 67 | ar( make_map_item(key, value) ); 68 | #ifdef CEREAL_OLDER_GCC 69 | hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) ); 70 | #else // NOT CEREAL_OLDER_GCC 71 | hint = map.emplace_hint( hint, std::move( key ), std::move( value ) ); 72 | #endif // NOT CEREAL_OLDER_GCC 73 | } 74 | } 75 | } 76 | 77 | //! Saving for std::map 78 | template inline 79 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::map const & map ) 80 | { 81 | map_detail::save( ar, map ); 82 | } 83 | 84 | //! Loading for std::map 85 | template inline 86 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::map & map ) 87 | { 88 | map_detail::load( ar, map ); 89 | } 90 | 91 | //! Saving for std::multimap 92 | /*! @note serialization for this type is not guaranteed to preserve ordering */ 93 | template inline 94 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::multimap const & multimap ) 95 | { 96 | map_detail::save( ar, multimap ); 97 | } 98 | 99 | //! Loading for std::multimap 100 | /*! @note serialization for this type is not guaranteed to preserve ordering */ 101 | template inline 102 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::multimap & multimap ) 103 | { 104 | map_detail::load( ar, multimap ); 105 | } 106 | } // namespace cereal 107 | 108 | #endif // CEREAL_TYPES_MAP_HPP_ 109 | -------------------------------------------------------------------------------- /cmake/Install.cmake: -------------------------------------------------------------------------------- 1 | set(InstallLocation /opt/Elite) 2 | 3 | SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) 4 | SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) 5 | SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}) 6 | 7 | 8 | SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY ON) 9 | SET(CPACK_PACKAGE_NAME "Elite") 10 | SET(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") 11 | SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") 12 | SET(CPACK_PACKAGE_CONTACT "sunxfancy@gmail.com") 13 | SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "short description") 14 | 15 | IF(WIN32 AND NOT UNIX) 16 | SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}\\\\doc\\\\icon.ico") 17 | set(CPACK_GENERATOR NSIS) 18 | set(CPACK_NSIS_INSTALLED_ICON_NAME "${CMAKE_CURRENT_SOURCE_DIR}\\\\bin\\\\Elite") 19 | set (CPACK_NSIS_MODIFY_PATH "ON") 20 | ELSEIF(LINUX) 21 | SET(CPACK_GENERATOR "STGZ;TGZ;DEB") 22 | ENDIF() 23 | 24 | install(DIRECTORY 25 | ${CMAKE_CURRENT_SOURCE_DIR}/bin 26 | ${CMAKE_CURRENT_SOURCE_DIR}/conf 27 | DESTINATION . 28 | FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 29 | GROUP_EXECUTE GROUP_READ WORLD_READ 30 | DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 31 | GROUP_EXECUTE GROUP_READ WORLD_READ 32 | COMPONENT core 33 | PATTERN ".git" EXCLUDE) 34 | 35 | install(DIRECTORY 36 | ${CMAKE_CURRENT_SOURCE_DIR}/tools 37 | DESTINATION . 38 | FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 39 | GROUP_EXECUTE GROUP_READ WORLD_READ 40 | DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 41 | GROUP_EXECUTE GROUP_READ WORLD_READ 42 | COMPONENT toolchain 43 | PATTERN ".git" EXCLUDE) 44 | 45 | 46 | install(DIRECTORY 47 | ${CMAKE_CURRENT_SOURCE_DIR}/packages 48 | DESTINATION . 49 | FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 50 | GROUP_EXECUTE GROUP_READ WORLD_READ 51 | DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 52 | GROUP_EXECUTE GROUP_READ WORLD_READ 53 | COMPONENT plugins 54 | PATTERN ".git" EXCLUDE) 55 | 56 | install(DIRECTORY 57 | ${CMAKE_CURRENT_SOURCE_DIR}/lib 58 | DESTINATION . 59 | FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 60 | GROUP_EXECUTE GROUP_READ WORLD_READ 61 | DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 62 | GROUP_EXECUTE GROUP_READ WORLD_READ 63 | COMPONENT lib 64 | PATTERN ".git" EXCLUDE) 65 | 66 | 67 | 68 | install(DIRECTORY 69 | ${CMAKE_CURRENT_SOURCE_DIR}/runtime 70 | DESTINATION . 71 | FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 72 | GROUP_EXECUTE GROUP_READ WORLD_READ 73 | DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 74 | GROUP_EXECUTE GROUP_READ WORLD_READ 75 | COMPONENT runtime 76 | PATTERN ".git" EXCLUDE) 77 | 78 | 79 | set(CPACK_COMPONENT_CORE_DISPLAY_NAME "Elite Core") 80 | set(CPACK_COMPONENT_CORE_DESCRIPTION "Elite core system") 81 | set(CPACK_COMPONENT_CORE_GROUP "Application") 82 | 83 | set(CPACK_COMPONENT_TOOLCHAIN_DISPLAY_NAME "Toolchain") 84 | set(CPACK_COMPONENT_TOOLCHAIN_DESCRIPTION "The toolchain of Elite") 85 | set(CPACK_COMPONENT_TOOLCHAIN_GROUP "Application") 86 | 87 | set(CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "Runtime") 88 | set(CPACK_COMPONENT_RUNTIME_DESCRIPTION "The runtime libraries for built program") 89 | set(CPACK_COMPONENT_RUNTIME_GROUP "Application") 90 | 91 | set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "C++ Headers") 92 | set(CPACK_COMPONENT_HEADER_DESCRIPTION "The header files of Cpp") 93 | set(CPACK_COMPONENT_HEADER_GROUP "Development") 94 | 95 | set(CPACK_COMPONENT_LIB_DISPLAY_NAME "Libraries") 96 | set(CPACK_COMPONENT_LIB_DESCRIPTION "Elite libraries") 97 | set(CPACK_COMPONENT_LIB_GROUP "Development") 98 | 99 | set(CPACK_COMPONENT_DOC_DISPLAY_NAME "User Manual") 100 | set(CPACK_COMPONENT_DOC_DESCRIPTION "The Documentation of Elite") 101 | set(CPACK_COMPONENT_DOC_GROUP "Documentation") 102 | 103 | set(CPACK_COMPONENT_GROUP_APPLICATION_DESCRIPTION 104 | "The major part of the Elite system") 105 | set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION 106 | "All of the libraries you'll ever need to develop with Elite") 107 | set(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION 108 | "The documentation of Elite") 109 | 110 | set(CPACK_COMPONENTS_ALL core doc header runtime toolchain lib) 111 | 112 | INCLUDE(CPack) 113 | -------------------------------------------------------------------------------- /include/Elite/LLCG/llcg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-23 10:53:22 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 17:15:54 6 | */ 7 | 8 | #ifndef LLCG_H 9 | #define LLCG_H 10 | 11 | #include "Elite/LLCG/lvalue.h" 12 | 13 | #include "Elite/MetaModel/FunctionModel.h" 14 | #include "Elite/MetaModel/StructModel.h" 15 | 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | 22 | /** 23 | * @brief 核心接口类 底层代码生成器 Low-Level Code Generator 24 | * 整个底层的聚合接口 25 | */ 26 | class llcg 27 | { 28 | public: 29 | virtual LValue FuncType(FunctionModel* fmodel) = 0; // 返回FunctionType 30 | virtual LValue FuncType(LValue ret_type, vector& types, bool isNotSure = false) = 0; 31 | virtual LValue GetOrInsertFunction(FunctionModel* fmodel) = 0; // 返回Function 32 | virtual LValue GetOrInsertFunction(const string& name, LValue func_type) = 0; 33 | virtual LValue GetOrInsertFunction(const string& name, LValue ret_type, vector& types, bool isNotSure = false) = 0; 34 | virtual void FunctionBodyBegin(LValue func, vector& name_list) = 0; // 设置当前BasicBlock 35 | virtual void FunctionBodyEnd() = 0; // 处理函数结束 36 | virtual LValue getFunction(const string& name) = 0; // 从当前模块中获取一个函数 37 | virtual LValue Call(FunctionModel* fmodel, vector& args) = 0; // 返回CallInst 38 | virtual LValue Call(LValue func, vector& args) = 0; 39 | virtual LValue Struct(StructModel* smodel) = 0; // 返回StructType 40 | virtual LValue Struct(LValue _struct, vector& types) = 0; 41 | virtual LValue DeclareStruct(const string& name) = 0; 42 | virtual LValue DefVar(LValue var_type, const string& name) = 0; // 返回分配的地址 43 | virtual LValue DefVar(LValue var_type, const string& name, LValue init) = 0; 44 | virtual LValue DefGlobalVar(LValue var_type, const string& name) = 0; 45 | virtual LValue DefGlobalVar(LValue var_type, const string& name, LValue init) = 0; 46 | virtual LValue Load(LValue var_addr) = 0; 47 | virtual LValue Store(LValue var_addr, LValue value) = 0; 48 | virtual LValue Opt1(const string& opt, LValue value) = 0; 49 | virtual LValue Opt2(const string& opt, LValue value1, LValue value2) = 0; 50 | virtual LValue Cmp(const string& opt, LValue value1, LValue value2) = 0; 51 | virtual LValue Assignment(const string& opt, LValue value1, LValue value2) = 0; 52 | virtual LValue Dot(LValue value, int num) = 0; 53 | virtual LValue Select(LValue value, vector& args) = 0; 54 | virtual void If(LValue cond, LValue father, LValue true_block, LValue true_block_end, 55 | LValue false_block, LValue false_block_end, bool isElseWork) = 0; 56 | virtual void For(LValue cond, LValue init, LValue pd, LValue work, LValue statement, LValue statement_end, LValue end) = 0; 57 | virtual void While(LValue cond, LValue father, LValue pd, LValue statement, LValue statement_end, LValue end) = 0; 58 | virtual void DoWhile(LValue statement, LValue pd) = 0; 59 | virtual void DoUntil(LValue statement, LValue pd) = 0; 60 | virtual void Goto(LValue target) = 0; 61 | virtual LValue New(LValue var_type, vector& args, const string& funcname = "") = 0; 62 | virtual LValue NewArray(LValue var_type, vector& wd, const string& funcname = "") = 0; 63 | virtual LValue Delete(LValue pointer, const string& funcname = "") = 0; 64 | virtual LValue DeleteArray(LValue pointer, const string& funcname = "") = 0; 65 | virtual LValue Return() = 0; 66 | virtual LValue Return(LValue var) = 0; 67 | 68 | virtual LValue Int8() = 0; 69 | virtual LValue Int16() = 0; 70 | virtual LValue Int32() = 0; 71 | virtual LValue Int64() = 0; 72 | virtual LValue Float() = 0; 73 | virtual LValue Double() = 0; 74 | virtual LValue Void() = 0; 75 | 76 | virtual LValue ConstString(const string& str) = 0; 77 | virtual LValue ConstInt(int num) = 0; 78 | virtual LValue ConstDouble(double num) = 0; 79 | 80 | virtual void BeginModule(const string& name) = 0; 81 | virtual void VerifyAndWrite(const string& outfile_name) = 0; 82 | virtual void MakeMetaModule(const string& outfile_name, const string& module_name) = 0; 83 | 84 | virtual LValue GetNowBasicBlock() = 0; 85 | virtual LValue CreateBasicBlock() = 0; 86 | virtual LValue CreateBasicBlock(LValue func) = 0; 87 | 88 | virtual void MakeMetaList(vector& list) = 0; 89 | virtual void MakeMetaList(const string& name, vector& list, LValue fp) = 0; 90 | virtual void CloseTerminator(LValue basicblock, LValue target) = 0; 91 | virtual void SetNowBasicBlock(LValue nowBlock) = 0; 92 | static llcg* CreateLLVM(); 93 | 94 | }; 95 | 96 | 97 | #endif // LLCG_H 98 | -------------------------------------------------------------------------------- /header_libs/cereal/types/boost_variant.hpp: -------------------------------------------------------------------------------- 1 | /*! \file boost_variant.hpp 2 | \brief Support for boost::variant 3 | \ingroup OtherTypes */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_BOOST_VARIANT_HPP_ 31 | #define CEREAL_TYPES_BOOST_VARIANT_HPP_ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | namespace cereal 38 | { 39 | namespace variant_detail 40 | { 41 | //! @internal 42 | template 43 | struct variant_save_visitor : boost::static_visitor<> 44 | { 45 | variant_save_visitor(Archive & ar_) : ar(ar_) {} 46 | 47 | template 48 | void operator()(T const & value) const 49 | { 50 | ar( CEREAL_NVP_("data", value) ); 51 | } 52 | 53 | Archive & ar; 54 | }; 55 | 56 | //! @internal 57 | template 58 | typename std::enable_if::value, void>::type 59 | load_variant(Archive & /*ar*/, int /*target*/, Variant & /*variant*/) 60 | { 61 | throw ::cereal::Exception("Error traversing variant during load"); 62 | } 63 | 64 | //! @internal 65 | template 66 | typename std::enable_if::value, void>::type 67 | load_variant(Archive & ar, int target, Variant & variant) 68 | { 69 | if(N == target) 70 | { 71 | H value; 72 | ar( CEREAL_NVP_("data", value) ); 73 | variant = value; 74 | } 75 | else 76 | load_variant(ar, target, variant); 77 | } 78 | 79 | } // namespace variant_detail 80 | 81 | //! Saving for boost::variant 82 | template inline 83 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, boost::variant const & variant ) 84 | { 85 | int32_t which = variant.which(); 86 | ar( CEREAL_NVP_("which", which) ); 87 | variant_detail::variant_save_visitor visitor(ar); 88 | variant.apply_visitor(visitor); 89 | } 90 | 91 | //! Loading for boost::variant 92 | template inline 93 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, boost::variant & variant ) 94 | { 95 | typedef typename boost::variant::types types; 96 | 97 | int32_t which; 98 | ar( CEREAL_NVP_("which", which) ); 99 | if(which >= boost::mpl::size::value) 100 | throw Exception("Invalid 'which' selector when deserializing boost::variant"); 101 | 102 | variant_detail::load_variant<0, boost::variant, VariantTypes...>(ar, which, variant); 103 | } 104 | } // namespace cereal 105 | 106 | #endif // CEREAL_TYPES_BOOST_VARIANT_HPP_ 107 | -------------------------------------------------------------------------------- /header_libs/cereal/external/base64.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2004-2008 René Nyffenegger 3 | 4 | This source code is provided 'as-is', without any express or implied 5 | warranty. In no event will the author be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this source code must not be misrepresented; you must not 13 | claim that you wrote the original source code. If you use this source code 14 | in a product, an acknowledgment in the product documentation would be 15 | appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original source code. 19 | 20 | 3. This notice may not be removed or altered from any source distribution. 21 | 22 | René Nyffenegger rene.nyffenegger@adp-gmbh.ch 23 | */ 24 | 25 | #ifndef CEREAL_EXTERNAL_BASE64_HPP_ 26 | #define CEREAL_EXTERNAL_BASE64_HPP_ 27 | 28 | #include 29 | 30 | namespace base64 31 | { 32 | static const std::string chars = 33 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 34 | "abcdefghijklmnopqrstuvwxyz" 35 | "0123456789+/"; 36 | 37 | static inline bool is_base64(unsigned char c) { 38 | return (isalnum(c) || (c == '+') || (c == '/')); 39 | } 40 | 41 | inline std::string encode(unsigned char const* bytes_to_encode, size_t in_len) { 42 | std::string ret; 43 | int i = 0; 44 | int j = 0; 45 | unsigned char char_array_3[3]; 46 | unsigned char char_array_4[4]; 47 | 48 | while (in_len--) { 49 | char_array_3[i++] = *(bytes_to_encode++); 50 | if (i == 3) { 51 | char_array_4[0] = (unsigned char) ((char_array_3[0] & 0xfc) >> 2); 52 | char_array_4[1] = (unsigned char) ( ( ( char_array_3[0] & 0x03 ) << 4 ) + ( ( char_array_3[1] & 0xf0 ) >> 4 ) ); 53 | char_array_4[2] = (unsigned char) ( ( ( char_array_3[1] & 0x0f ) << 2 ) + ( ( char_array_3[2] & 0xc0 ) >> 6 ) ); 54 | char_array_4[3] = (unsigned char) ( char_array_3[2] & 0x3f ); 55 | 56 | for(i = 0; (i <4) ; i++) 57 | ret += chars[char_array_4[i]]; 58 | i = 0; 59 | } 60 | } 61 | 62 | if (i) 63 | { 64 | for(j = i; j < 3; j++) 65 | char_array_3[j] = '\0'; 66 | 67 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 68 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 69 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 70 | char_array_4[3] = char_array_3[2] & 0x3f; 71 | 72 | for (j = 0; (j < i + 1); j++) 73 | ret += chars[char_array_4[j]]; 74 | 75 | while((i++ < 3)) 76 | ret += '='; 77 | 78 | } 79 | 80 | return ret; 81 | 82 | } 83 | 84 | inline std::string decode(std::string const& encoded_string) { 85 | size_t in_len = encoded_string.size(); 86 | size_t i = 0; 87 | size_t j = 0; 88 | int in_ = 0; 89 | unsigned char char_array_4[4], char_array_3[3]; 90 | std::string ret; 91 | 92 | while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { 93 | char_array_4[i++] = encoded_string[in_]; in_++; 94 | if (i ==4) { 95 | for (i = 0; i <4; i++) 96 | char_array_4[i] = (unsigned char) chars.find( char_array_4[i] ); 97 | 98 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 99 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 100 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 101 | 102 | for (i = 0; (i < 3); i++) 103 | ret += char_array_3[i]; 104 | i = 0; 105 | } 106 | } 107 | 108 | if (i) { 109 | for (j = i; j <4; j++) 110 | char_array_4[j] = 0; 111 | 112 | for (j = 0; j <4; j++) 113 | char_array_4[j] = (unsigned char) chars.find( char_array_4[j] ); 114 | 115 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 116 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 117 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 118 | 119 | for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; 120 | } 121 | 122 | return ret; 123 | } 124 | } // base64 125 | #endif // CEREAL_EXTERNAL_BASE64_HPP_ 126 | -------------------------------------------------------------------------------- /include/Elite/LLCG/llcg_l.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-19 10:15:48 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 17:16:05 6 | */ 7 | #ifndef LLVG_L_H 8 | #define LLVG_L_H 9 | 10 | 11 | #include "Elite/LLCG/lvalue.h" 12 | 13 | #include "Elite/MetaModel/FunctionModel.h" 14 | #include "Elite/MetaModel/StructModel.h" 15 | 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | 22 | /** 23 | * @brief 核心接口类 底层代码生成器 Low-Level Code Generator 24 | * 整个底层的聚合接口 25 | */ 26 | class llcg_l 27 | { 28 | public: 29 | virtual lvalue* l_FuncType(FunctionModel* fmodel) = 0; // 返回FunctionType 30 | virtual lvalue* l_FuncType(lvalue* ret_type, vector& types, bool isNotSure = false) = 0; 31 | virtual lvalue* l_GetOrInsertFunction(FunctionModel* fmodel) = 0; // 返回Function 32 | virtual lvalue* l_GetOrInsertFunction(const string& name, lvalue* func_type) = 0; 33 | virtual lvalue* l_GetOrInsertFunction(const string& name, lvalue* ret_type, vector& types, bool isNotSure = false) = 0; 34 | virtual void l_FunctionBodyBegin(lvalue* func, vector& name_list) = 0; // 设置当前BasicBlock 35 | virtual void l_FunctionBodyEnd() = 0; // 处理函数结束 36 | virtual lvalue* l_getFunction(const string& name) = 0; // 从当前模块中获取一个函数 37 | virtual lvalue* l_Call(FunctionModel* fmodel, vector& args) = 0; // 返回CallInst 38 | virtual lvalue* l_Call(lvalue* func, vector& args) = 0; 39 | virtual lvalue* l_Struct(StructModel* smodel) = 0; // 返回StructType 40 | virtual lvalue* l_Struct(lvalue* _struct, vector& types) = 0; 41 | virtual lvalue* l_DeclareStruct(const string& name) = 0; 42 | virtual lvalue* l_DefVar(lvalue* var_type, const string& name) = 0; // 返回分配的地址 43 | virtual lvalue* l_DefVar(lvalue* var_type, const string& name, lvalue* init) = 0; 44 | virtual lvalue* l_DefGlobalVar(lvalue* var_type, const string& name) = 0; 45 | virtual lvalue* l_DefGlobalVar(lvalue* var_type, const string& name, lvalue* init) = 0; 46 | virtual lvalue* l_Load(lvalue* var_addr) = 0; 47 | virtual lvalue* l_Store(lvalue* var_addr, lvalue* value) = 0; 48 | virtual lvalue* l_Opt1(const string& opt, lvalue* value) = 0; 49 | virtual lvalue* l_Opt2(const string& opt, lvalue* value1, lvalue* value2) = 0; 50 | virtual lvalue* l_Cmp(const string& opt, lvalue* value1, lvalue* value2) = 0; 51 | virtual lvalue* l_Assignment(const string& opt, lvalue* value1, lvalue* value2) = 0; 52 | virtual lvalue* l_Dot(lvalue* value, int num) = 0; 53 | virtual lvalue* l_Select(lvalue* value, vector& args) = 0; 54 | virtual void l_If(lvalue* cond, lvalue* father, lvalue* true_block, lvalue* true_block_end, 55 | lvalue* false_block, lvalue* false_block_end, bool isElseWork) = 0; 56 | virtual void l_For(lvalue* cond, lvalue* init, lvalue* pd, lvalue* work, lvalue* statement, lvalue* statement_end, lvalue* end) = 0; 57 | virtual void l_While(lvalue* cond, lvalue* father, lvalue* pd, lvalue* statement, lvalue* statement_end, lvalue* end) = 0; 58 | virtual void l_DoWhile(lvalue* statement, lvalue* pd) = 0; 59 | virtual void l_DoUntil(lvalue* statement, lvalue* pd) = 0; 60 | virtual lvalue* l_New(lvalue* var_type, vector& args, const string& funcname = "") = 0; 61 | virtual lvalue* l_NewArray(lvalue* var_type, vector& wd, const string& funcname = "") = 0; 62 | virtual lvalue* l_Delete(lvalue* pointer, const string& funcname = "") = 0; 63 | virtual lvalue* l_DeleteArray(lvalue* pointer, const string& funcname = "") = 0; 64 | virtual lvalue* l_Return() = 0; 65 | virtual lvalue* l_Return(lvalue* var) = 0; 66 | 67 | virtual lvalue* l_Int8() = 0; 68 | virtual lvalue* l_Int16() = 0; 69 | virtual lvalue* l_Int32() = 0; 70 | virtual lvalue* l_Int64() = 0; 71 | virtual lvalue* l_Float() = 0; 72 | virtual lvalue* l_Double() = 0; 73 | virtual lvalue* l_Void() = 0; 74 | 75 | virtual lvalue* l_ConstString(const string& str) = 0; 76 | virtual lvalue* l_ConstInt(int num) = 0; 77 | virtual lvalue* l_ConstDouble(double num) = 0; 78 | 79 | virtual void l_BeginModule(const string& name) = 0; 80 | virtual void l_VerifyAndWrite(const string& outfile_name) = 0; 81 | virtual void l_MakeMetaModule(const string& outfile_name, const string& module_name) = 0; 82 | 83 | virtual lvalue* l_GetNowBasicBlock() = 0; 84 | virtual lvalue* l_CreateBasicBlock() = 0; 85 | virtual lvalue* l_CreateBasicBlock(lvalue* func) = 0; 86 | 87 | virtual void l_MakeMetaList(vector& list) = 0; 88 | virtual void l_MakeMetaList(const string& name, vector& list, lvalue* fp) = 0; 89 | virtual void l_CloseTerminator(lvalue* basicblock, lvalue* target) = 0; 90 | 91 | }; 92 | 93 | 94 | 95 | 96 | 97 | #endif // LLVG_L_H 98 | -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidxml/rapidxml_iterators.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDXML_ITERATORS_HPP_INCLUDED 2 | #define RAPIDXML_ITERATORS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | 8 | #include "rapidxml.hpp" 9 | 10 | namespace rapidxml 11 | { 12 | 13 | //! Iterator of child nodes of xml_node 14 | template 15 | class node_iterator 16 | { 17 | 18 | public: 19 | 20 | typedef typename xml_node value_type; 21 | typedef typename xml_node &reference; 22 | typedef typename xml_node *pointer; 23 | typedef std::ptrdiff_t difference_type; 24 | typedef std::bidirectional_iterator_tag iterator_category; 25 | 26 | node_iterator() 27 | : m_node(0) 28 | { 29 | } 30 | 31 | node_iterator(xml_node *node) 32 | : m_node(node->first_node()) 33 | { 34 | } 35 | 36 | reference operator *() const 37 | { 38 | assert(m_node); 39 | return *m_node; 40 | } 41 | 42 | pointer operator->() const 43 | { 44 | assert(m_node); 45 | return m_node; 46 | } 47 | 48 | node_iterator& operator++() 49 | { 50 | assert(m_node); 51 | m_node = m_node->next_sibling(); 52 | return *this; 53 | } 54 | 55 | node_iterator operator++(int) 56 | { 57 | node_iterator tmp = *this; 58 | ++this; 59 | return tmp; 60 | } 61 | 62 | node_iterator& operator--() 63 | { 64 | assert(m_node && m_node->previous_sibling()); 65 | m_node = m_node->previous_sibling(); 66 | return *this; 67 | } 68 | 69 | node_iterator operator--(int) 70 | { 71 | node_iterator tmp = *this; 72 | ++this; 73 | return tmp; 74 | } 75 | 76 | bool operator ==(const node_iterator &rhs) 77 | { 78 | return m_node == rhs.m_node; 79 | } 80 | 81 | bool operator !=(const node_iterator &rhs) 82 | { 83 | return m_node != rhs.m_node; 84 | } 85 | 86 | private: 87 | 88 | xml_node *m_node; 89 | 90 | }; 91 | 92 | //! Iterator of child attributes of xml_node 93 | template 94 | class attribute_iterator 95 | { 96 | 97 | public: 98 | 99 | typedef typename xml_attribute value_type; 100 | typedef typename xml_attribute &reference; 101 | typedef typename xml_attribute *pointer; 102 | typedef std::ptrdiff_t difference_type; 103 | typedef std::bidirectional_iterator_tag iterator_category; 104 | 105 | attribute_iterator() 106 | : m_attribute(0) 107 | { 108 | } 109 | 110 | attribute_iterator(xml_node *node) 111 | : m_attribute(node->first_attribute()) 112 | { 113 | } 114 | 115 | reference operator *() const 116 | { 117 | assert(m_attribute); 118 | return *m_attribute; 119 | } 120 | 121 | pointer operator->() const 122 | { 123 | assert(m_attribute); 124 | return m_attribute; 125 | } 126 | 127 | attribute_iterator& operator++() 128 | { 129 | assert(m_attribute); 130 | m_attribute = m_attribute->next_attribute(); 131 | return *this; 132 | } 133 | 134 | attribute_iterator operator++(int) 135 | { 136 | attribute_iterator tmp = *this; 137 | ++this; 138 | return tmp; 139 | } 140 | 141 | attribute_iterator& operator--() 142 | { 143 | assert(m_attribute && m_attribute->previous_attribute()); 144 | m_attribute = m_attribute->previous_attribute(); 145 | return *this; 146 | } 147 | 148 | attribute_iterator operator--(int) 149 | { 150 | attribute_iterator tmp = *this; 151 | ++this; 152 | return tmp; 153 | } 154 | 155 | bool operator ==(const attribute_iterator &rhs) 156 | { 157 | return m_attribute == rhs.m_attribute; 158 | } 159 | 160 | bool operator !=(const attribute_iterator &rhs) 161 | { 162 | return m_attribute != rhs.m_attribute; 163 | } 164 | 165 | private: 166 | 167 | xml_attribute *m_attribute; 168 | 169 | }; 170 | 171 | } 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /header_libs/cereal/external/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_POW10_ 2 | #define RAPIDJSON_POW10_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | //! Computes integer powers of 10 in double (10.0^n). 8 | /*! This function uses lookup table for fast and accurate results. 9 | \param n positive/negative exponent. Must <= 308. 10 | \return 10.0^n 11 | */ 12 | inline double Pow10(int n) { 13 | static const double e[] = { // 1e-308...1e308: 617 * 8 bytes = 4936 bytes 14 | 1e-308,1e-307,1e-306,1e-305,1e-304,1e-303,1e-302,1e-301,1e-300, 15 | 1e-299,1e-298,1e-297,1e-296,1e-295,1e-294,1e-293,1e-292,1e-291,1e-290,1e-289,1e-288,1e-287,1e-286,1e-285,1e-284,1e-283,1e-282,1e-281,1e-280, 16 | 1e-279,1e-278,1e-277,1e-276,1e-275,1e-274,1e-273,1e-272,1e-271,1e-270,1e-269,1e-268,1e-267,1e-266,1e-265,1e-264,1e-263,1e-262,1e-261,1e-260, 17 | 1e-259,1e-258,1e-257,1e-256,1e-255,1e-254,1e-253,1e-252,1e-251,1e-250,1e-249,1e-248,1e-247,1e-246,1e-245,1e-244,1e-243,1e-242,1e-241,1e-240, 18 | 1e-239,1e-238,1e-237,1e-236,1e-235,1e-234,1e-233,1e-232,1e-231,1e-230,1e-229,1e-228,1e-227,1e-226,1e-225,1e-224,1e-223,1e-222,1e-221,1e-220, 19 | 1e-219,1e-218,1e-217,1e-216,1e-215,1e-214,1e-213,1e-212,1e-211,1e-210,1e-209,1e-208,1e-207,1e-206,1e-205,1e-204,1e-203,1e-202,1e-201,1e-200, 20 | 1e-199,1e-198,1e-197,1e-196,1e-195,1e-194,1e-193,1e-192,1e-191,1e-190,1e-189,1e-188,1e-187,1e-186,1e-185,1e-184,1e-183,1e-182,1e-181,1e-180, 21 | 1e-179,1e-178,1e-177,1e-176,1e-175,1e-174,1e-173,1e-172,1e-171,1e-170,1e-169,1e-168,1e-167,1e-166,1e-165,1e-164,1e-163,1e-162,1e-161,1e-160, 22 | 1e-159,1e-158,1e-157,1e-156,1e-155,1e-154,1e-153,1e-152,1e-151,1e-150,1e-149,1e-148,1e-147,1e-146,1e-145,1e-144,1e-143,1e-142,1e-141,1e-140, 23 | 1e-139,1e-138,1e-137,1e-136,1e-135,1e-134,1e-133,1e-132,1e-131,1e-130,1e-129,1e-128,1e-127,1e-126,1e-125,1e-124,1e-123,1e-122,1e-121,1e-120, 24 | 1e-119,1e-118,1e-117,1e-116,1e-115,1e-114,1e-113,1e-112,1e-111,1e-110,1e-109,1e-108,1e-107,1e-106,1e-105,1e-104,1e-103,1e-102,1e-101,1e-100, 25 | 1e-99, 1e-98, 1e-97, 1e-96, 1e-95, 1e-94, 1e-93, 1e-92, 1e-91, 1e-90, 1e-89, 1e-88, 1e-87, 1e-86, 1e-85, 1e-84, 1e-83, 1e-82, 1e-81, 1e-80, 26 | 1e-79, 1e-78, 1e-77, 1e-76, 1e-75, 1e-74, 1e-73, 1e-72, 1e-71, 1e-70, 1e-69, 1e-68, 1e-67, 1e-66, 1e-65, 1e-64, 1e-63, 1e-62, 1e-61, 1e-60, 27 | 1e-59, 1e-58, 1e-57, 1e-56, 1e-55, 1e-54, 1e-53, 1e-52, 1e-51, 1e-50, 1e-49, 1e-48, 1e-47, 1e-46, 1e-45, 1e-44, 1e-43, 1e-42, 1e-41, 1e-40, 28 | 1e-39, 1e-38, 1e-37, 1e-36, 1e-35, 1e-34, 1e-33, 1e-32, 1e-31, 1e-30, 1e-29, 1e-28, 1e-27, 1e-26, 1e-25, 1e-24, 1e-23, 1e-22, 1e-21, 1e-20, 29 | 1e-19, 1e-18, 1e-17, 1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e+0, 30 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 31 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 32 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 33 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 34 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 35 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 36 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 37 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 38 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 39 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 40 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 41 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 42 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 43 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 44 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 45 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 46 | }; 47 | RAPIDJSON_ASSERT(n <= 308); 48 | return n < -308 ? 0.0 : e[n + 308]; 49 | } 50 | 51 | } // namespace internal 52 | } // namespace rapidjson 53 | 54 | #endif // RAPIDJSON_POW10_ 55 | -------------------------------------------------------------------------------- /header_libs/cereal/types/tuple.hpp: -------------------------------------------------------------------------------- 1 | /*! \file tuple.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_TUPLE_HPP_ 31 | #define CEREAL_TYPES_TUPLE_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace tuple_detail 39 | { 40 | //! Creates a c string from a sequence of characters 41 | /*! The c string created will alwas be prefixed by "tuple_element" 42 | Based on code from: http://stackoverflow/a/20973438/710791 43 | @internal */ 44 | template 45 | struct char_seq_to_c_str 46 | { 47 | static const int size = 14;// Size of array for the word: tuple_element 48 | typedef const char (&arr_type)[sizeof...(Cs) + size]; 49 | static const char str[sizeof...(Cs) + size]; 50 | }; 51 | 52 | // the word tuple_element plus a number 53 | //! @internal 54 | template 55 | const char char_seq_to_c_str::str[sizeof...(Cs) + size] = 56 | {'t','u','p','l','e','_','e','l','e','m','e','n','t', Cs..., '\0'}; 57 | 58 | //! Converts a number into a sequence of characters 59 | /*! @tparam Q The quotient of dividing the original number by 10 60 | @tparam R The remainder of dividing the original number by 10 61 | @tparam C The sequence built so far 62 | @internal */ 63 | template 64 | struct to_string_impl 65 | { 66 | using type = typename to_string_impl::type; 67 | }; 68 | 69 | //! Base case with no quotient 70 | /*! @internal */ 71 | template 72 | struct to_string_impl<0, R, C...> 73 | { 74 | using type = char_seq_to_c_str; 75 | }; 76 | 77 | //! Generates a c string for a given index of a tuple 78 | /*! Example use: 79 | @code{cpp} 80 | tuple_element_name<3>::c_str();// returns "tuple_element3" 81 | @endcode 82 | @internal */ 83 | template 84 | struct tuple_element_name 85 | { 86 | using type = typename to_string_impl::type; 87 | static const typename type::arr_type c_str(){ return type::str; }; 88 | }; 89 | 90 | // unwinds a tuple to save it 91 | //! @internal 92 | template 93 | struct serialize 94 | { 95 | template inline 96 | static void apply( Archive & ar, std::tuple & tuple ) 97 | { 98 | serialize::template apply( ar, tuple ); 99 | ar( CEREAL_NVP_(tuple_element_name::c_str(), 100 | std::get( tuple )) ); 101 | } 102 | }; 103 | 104 | // Zero height specialization - nothing to do here 105 | //! @internal 106 | template <> 107 | struct serialize<0> 108 | { 109 | template inline 110 | static void apply( Archive &, std::tuple & ) 111 | { } 112 | }; 113 | } 114 | 115 | //! Serializing for std::tuple 116 | template inline 117 | void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, std::tuple & tuple ) 118 | { 119 | tuple_detail::serialize>::value>::template apply( ar, tuple ); 120 | } 121 | } // namespace cereal 122 | 123 | #endif // CEREAL_TYPES_TUPLE_HPP_ 124 | --------------------------------------------------------------------------------