From e0d17be3f5b5f0bb21af46942bd0e2df22c42366 Mon Sep 17 00:00:00 2001 From: Su Xing Date: Mon, 27 Mar 2023 00:16:53 +0800 Subject: [PATCH] Refine IR and Doxyfile --- Doxyfile => doc/Doxyfile | 18 ++++----- src/IR.h | 81 ++++++++-------------------------------- src/range.h | 61 ++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 74 deletions(-) rename Doxyfile => doc/Doxyfile (99%) create mode 100644 src/range.h diff --git a/Doxyfile b/doc/Doxyfile similarity index 99% rename from Doxyfile rename to doc/Doxyfile index 724fc10..8934973 100644 --- a/Doxyfile +++ b/doc/Doxyfile @@ -53,7 +53,7 @@ PROJECT_NUMBER = # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = +PROJECT_BRIEF = "Compiler for the SysY programming language" # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 @@ -378,7 +378,7 @@ AUTOLINK_SUPPORT = YES # diagrams that involve STL classes more complete and accurate. # The default value is: NO. -BUILTIN_STL_SUPPORT = NO +BUILTIN_STL_SUPPORT = YES # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. @@ -498,7 +498,7 @@ NUM_PROC_THREADS = 1 # normally produced when WARNINGS is set to YES. # The default value is: NO. -EXTRACT_ALL = NO +EXTRACT_ALL = YES # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. @@ -906,7 +906,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = src/IR.h +INPUT = src # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -986,7 +986,7 @@ FILE_PATTERNS = *.c \ # be searched for input files as well. # The default value is: NO. -RECURSIVE = NO +RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a @@ -1273,7 +1273,7 @@ HTML_OUTPUT = html # The default value is: .html. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_FILE_EXTENSION = .html +HTML_FILE_EXTENSION = .xhtml # The HTML_HEADER tag can be used to specify a user-defined HTML header file for # each generated HTML page. If the tag is left blank doxygen will generate a @@ -1889,7 +1889,7 @@ EXTRA_SEARCH_MAPPINGS = # If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. # The default value is: YES. -GENERATE_LATEX = YES +GENERATE_LATEX = NO # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of @@ -2610,7 +2610,7 @@ DIR_GRAPH_MAX_DEPTH = 1 # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_IMAGE_FORMAT = png +DOT_IMAGE_FORMAT = svg # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to # enable generation of interactive SVG images that allow zooming and panning. @@ -2622,7 +2622,7 @@ DOT_IMAGE_FORMAT = png # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -INTERACTIVE_SVG = NO +INTERACTIVE_SVG = YES # The DOT_PATH tag can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. diff --git a/src/IR.h b/src/IR.h index 794e7f7..abb84bc 100644 --- a/src/IR.h +++ b/src/IR.h @@ -1,9 +1,9 @@ #pragma once +#include "range.h" #include #include #include -#include #include #include #include @@ -13,60 +13,7 @@ namespace sysy { /*! - * \defgroup range Iterator range - * @{ - */ - -/*! - * \brief `range` is an simple wrapper of an iterator pair [begin, end) - * - * Example usage - * - * ```cpp - * vector v = {1,2,3}; - * auto rg = make_range(v); - * for (auto v : rg) - * cout << v << '\n'; - * ``` - */ -template struct range { - using iterator = IterT; - using value_type = typename std::iterator_traits::value_type; - using reference = typename std::iterator_traits::reference; - -private: - iterator b; - iterator e; - -public: - explicit range(iterator b, iterator e) : b(b), e(e) {} - iterator begin() { return b; } - iterator end() { return e; } - auto size() const { return std::distance(b, e); } - auto empty() const { return b == e; } -}; - -//! create `range` object from iterator pair [begin, end) -template range make_range(IterT b, IterT e) { - return range(b, e); -} -//! create `range` object from a container who has `begin()` and `end()` methods -template -range make_range(ContainerT &c) { - return make_range(c.begin(), c.end()); -} -//! create `range` object from a container who has `begin()` and `end()` methods -template -range make_range(const ContainerT &c) { - return make_range(c.begin(), c.end()); -} - -/*! - * @} - */ - -/*! - * \defgroup type Type system + * \defgroup type Types * The SysY type system is quite simple. * 1. The base class `Type` is used to represent all primitive scalar types, * include `int`, `float`, `void`, and the label type representing branch @@ -196,12 +143,6 @@ public: * @{ */ -//===----------------------------------------------------------------------===// -// Values -// -// description -//===----------------------------------------------------------------------===// - class User; class Value; @@ -363,7 +304,8 @@ public: }; // class BasicBlock //! User is the abstract base type of `Value` types which use other `Value` as -//! operands. Currently, there are two kinds of `User`s, `Instruction` and `GlobalValue`. +//! operands. Currently, there are two kinds of `User`s, `Instruction` and +//! `GlobalValue`. class User : public Value { protected: std::vector operands; @@ -403,10 +345,7 @@ public: /*! * Base of all concrete instruction types. - * - * Instruction */ - class Instruction : public User { public: enum Kind : uint64_t { @@ -508,6 +447,7 @@ public: }; // class Instruction class Function; +//! Function call. class CallInst : public Instruction { friend class IRBuilder; @@ -522,6 +462,7 @@ public: } }; // class CallInst +//! Unary instruction, includes '!', '-' and type conversion. class UnaryInst : public Instruction { friend class IRBuilder; @@ -536,6 +477,7 @@ public: Value *getOperand() const { return User::getOperand(0); } }; // class UnaryInst +//! Binary instruction, e.g., arithmatic, relation, logic, etc. class BinaryInst : public Instruction { friend class IRBuilder; @@ -552,6 +494,7 @@ public: Value *getRhs() const { return getOperand(1); } }; // class BinaryInst +//! The return statement class ReturnInst : public Instruction { friend class IRBuilder; @@ -569,6 +512,7 @@ public: } }; // class ReturnInst +//! Unconditional branch class UncondBrInst : public Instruction { friend class IRBuilder; @@ -590,6 +534,7 @@ public: } }; // class UncondBrInst +//! Conditional branch class CondBrInst : public Instruction { friend class IRBuilder; @@ -626,6 +571,7 @@ public: } }; // class CondBrInst +//! Allocate memory for stack variables, used for non-global variable declartion class AllocaInst : public Instruction { friend class IRBuilder; @@ -642,6 +588,7 @@ public: Value *getDim(int index) { return getOperand(index); } }; // class AllocaInst +//! Load a value from memory address specified by a pointer value class LoadInst : public Instruction { friend class IRBuilder; @@ -664,6 +611,7 @@ public: Value *getIndex(int index) const { return getOperand(index + 1); } }; // class LoadInst +//! Store a value to memory address specified by a pointer value class StoreInst : public Instruction { friend class IRBuilder; @@ -688,6 +636,7 @@ public: }; // class StoreInst class Module; +//! Function definition class Function : public Value { friend class Module; @@ -724,6 +673,7 @@ public: } }; // class Function +//! Global value declared at file scope class GlobalValue : public User { friend class Module; @@ -742,6 +692,7 @@ public: Value *getDim(int index) { return getOperand(index); } }; // class GlobalValue +//! IR unit for representing a SysY compile unit class Module { protected: std::map> functions; diff --git a/src/range.h b/src/range.h new file mode 100644 index 0000000..95bd520 --- /dev/null +++ b/src/range.h @@ -0,0 +1,61 @@ +#pragma once + +#include + +namespace sysy { + +/*! + * \defgroup utility Utilities + * @{ + */ + +/*! + * \brief `range` is an simple wrapper of an iterator pair [begin, end) + * + * Example usage + * + * ```cpp + * vector v = {1,2,3}; + * auto rg = make_range(v); + * for (auto v : rg) + * cout << v << '\n'; + * ``` + */ +template struct range { + using iterator = IterT; + using value_type = typename std::iterator_traits::value_type; + using reference = typename std::iterator_traits::reference; + +private: + iterator b; + iterator e; + +public: + explicit range(iterator b, iterator e) : b(b), e(e) {} + iterator begin() { return b; } + iterator end() { return e; } + auto size() const { return std::distance(b, e); } + auto empty() const { return b == e; } +}; + +//! create `range` object from iterator pair [begin, end) +template range make_range(IterT b, IterT e) { + return range(b, e); +} +//! create `range` object from a container who has `begin()` and `end()` methods +template +range make_range(ContainerT &c) { + return make_range(c.begin(), c.end()); +} +//! create `range` object from a container who has `begin()` and `end()` methods +template +range make_range(const ContainerT &c) { + return make_range(c.begin(), c.end()); +} + +/*! + * @} + */ + + +} // namespace sysy \ No newline at end of file