change SysY to SysYF

master
15750821961 4 years ago
parent 1670909a3f
commit 34257e0942

@ -14,24 +14,24 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/ASTBuilder)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/ASTPrinter) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/ASTPrinter)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/ErrorReporter) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/ErrorReporter)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/Grammar) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/Grammar)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/SysYIR) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/SysYFIR)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/SysYBuilder) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/SysYFBuilder)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ASTBuilder) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ASTBuilder)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ASTPrinter) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ASTPrinter)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ErrorReporter) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ErrorReporter)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/Grammar) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/Grammar)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/SysYIR) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/SysYFIR)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/SysYBuilder) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/SysYFBuilder)
add_executable( add_executable(
SysYCompiler SysYFCompiler
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
) )
target_link_libraries( target_link_libraries(
SysYCompiler SysYFCompiler
SysYBuilder SysYFBuilder
IRLib IRLib
Driver Driver
ASTPrinter ASTPrinter

@ -10,8 +10,8 @@ set(SYSYF_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# include generated files in project environment # include generated files in project environment
include_directories(${SYSYF_SOURCE_DIR}include/SysYIR) include_directories(${SYSYF_SOURCE_DIR}include/SysYFIR)
add_subdirectory(${SYSYF_SOURCE_DIR}src/SysYIR src/SysYIR) add_subdirectory(${SYSYF_SOURCE_DIR}src/SysYFIR src/SysYFIR)
add_subdirectory(ta_demo) add_subdirectory(ta_demo)
add_subdirectory(student_cpp) add_subdirectory(student_cpp)

@ -1,5 +1,5 @@
#ifndef _SYSY_SYNTAX_TREE_H_ #ifndef _SYSYF_SYNTAX_TREE_H_
#define _SYSY_SYNTAX_TREE_H_ #define _SYSYF_SYNTAX_TREE_H_
#include <vector> #include <vector>
#include <memory> #include <memory>
@ -330,4 +330,4 @@ public:
} }
// end namespace SyntaxTree // end namespace SyntaxTree
#endif // _SYSY_SYNTAX_TREE_H_ #endif // _SYSYF_SYNTAX_TREE_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_SYNTAX_TREE_PRINTER_H_ #ifndef _SYSYF_SYNTAX_TREE_PRINTER_H_
#define _SYSY_SYNTAX_TREE_PRINTER_H_ #define _SYSYF_SYNTAX_TREE_PRINTER_H_
#include "SyntaxTree.h" #include "SyntaxTree.h"
@ -33,4 +33,4 @@ private:
int indent = 0; int indent = 0;
}; };
#endif // _SYSY_SYNTAX_TREE_PRINTER_H_ #endif // _SYSYF_SYNTAX_TREE_PRINTER_H_

@ -1,6 +1,5 @@
#ifndef _SYSYF_ERROR_REPORTER_H_
#ifndef _SYSY_ERROR_REPORTER_H_ #define _SYSYF_ERROR_REPORTER_H_
#define _SYSY_ERROR_REPORTER_H_
#include <iostream> #include <iostream>
#include <deque> #include <deque>
@ -24,4 +23,4 @@ private:
std::ostream &err; std::ostream &err;
}; };
#endif // _SYSY_ERROR_REPORTER_H_ #endif // _SYSYF_ERROR_REPORTER_H_

@ -1,32 +1,32 @@
#ifndef _SYSY_DRIVER_H_ #ifndef _SYSYF_DRIVER_H_
#define _SYSY_DRIVER_H_ #define _SYSYF_DRIVER_H_
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <map> #include <map>
// Generated by bison: // Generated by bison:
#include "SysYParser.h" #include "SysYFParser.h"
#include "SysYFlexLexer.h" #include "SysYFFlexLexer.h"
// Conducting the whole scanning and parsing of SysY. // Conducting the whole scanning and parsing of SysYF.
class SysYDriver class SysYFDriver
{ {
public: public:
SysYDriver(); SysYFDriver();
virtual ~SysYDriver(); virtual ~SysYFDriver();
std::map<std::string, int> variables; std::map<std::string, int> variables;
int result; int result;
// SysY lexer // SysYF lexer
SysYFlexLexer lexer; SysYFFlexLexer lexer;
std::ifstream instream; std::ifstream instream;
// Handling the SysY scanner. // Handling the SysYF scanner.
void scan_begin(); void scan_begin();
void scan_end(); void scan_end();
bool trace_scanning; bool trace_scanning;
@ -47,4 +47,4 @@ public:
SyntaxTree::Node* root = nullptr; SyntaxTree::Node* root = nullptr;
}; };
#endif // _SYSY_DRIVER_H_ #endif // _SYSYF_DRIVER_H_

@ -1,9 +1,9 @@
#ifndef _SYSY_FLEX_LEXER_H_ #ifndef _SYSYF_FLEX_LEXER_H_
#define _SYSY_FLEX_LEXER_H_ #define _SYSYF_FLEX_LEXER_H_
#ifndef YY_DECL #ifndef YY_DECL
#define YY_DECL \ #define YY_DECL \
yy::SysYParser::symbol_type SysYFlexLexer::yylex(SysYDriver& driver) yy::SysYFParser::symbol_type SysYFFlexLexer::yylex(SysYFDriver& driver)
#endif #endif
// We need this for yyFlexLexer. If we don't #undef yyFlexLexer, the // We need this for yyFlexLexer. If we don't #undef yyFlexLexer, the
@ -12,20 +12,20 @@
#undef yyFlexLexer #undef yyFlexLexer
#include <FlexLexer.h> #include <FlexLexer.h>
// We need this for the yy::SysYParser::symbol_type: // We need this for the yy::SysYFParser::symbol_type:
#include "SysYParser.h" #include "SysYFParser.h"
// We need this for the yy::location type: // We need this for the yy::location type:
#include "location.hh" #include "location.hh"
class SysYFlexLexer : public yyFlexLexer { class SysYFFlexLexer : public yyFlexLexer {
public: public:
// Use the superclass's constructor: // Use the superclass's constructor:
using yyFlexLexer::yyFlexLexer; using yyFlexLexer::yyFlexLexer;
// Provide the interface to `yylex`; `flex` will emit the // Provide the interface to `yylex`; `flex` will emit the
// definition into `SysYScanner.cpp`: // definition into `SysYFScanner.cpp`:
yy::SysYParser::symbol_type yylex(SysYDriver& driver); yy::SysYFParser::symbol_type yylex(SysYFDriver& driver);
// This seems like a reasonable place to put the location object // This seems like a reasonable place to put the location object
// rather than it being static (in the sense of having internal // rather than it being static (in the sense of having internal
@ -34,4 +34,4 @@ public:
yy::location loc; yy::location loc;
}; };
#endif // _SYSY_FLEX_LEXER_H_ #endif // _SYSYF_FLEX_LEXER_H_

@ -32,7 +32,7 @@
/** /**
** \file /home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYParser.h ** \file /home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFParser.h
** Define the yy::parser class. ** Define the yy::parser class.
*/ */
@ -42,16 +42,16 @@
// especially those whose name start with YY_ or yy_. They are // especially those whose name start with YY_ or yy_. They are
// private implementation details that can be changed or removed. // private implementation details that can be changed or removed.
#ifndef YY_YY_HOME_HZQ_SYSYF_IR_LAB_2021_SYSYCOMPILER_IR_LAB_BUILD_SYSYPARSER_H_INCLUDED #ifndef YY_YY_HOME_HZQ_SYSYF_IR_LAB_2021_SYSYCOMPILER_IR_LAB_BUILD_SYSYFPARSER_H_INCLUDED
# define YY_YY_HOME_HZQ_SYSYF_IR_LAB_2021_SYSYCOMPILER_IR_LAB_BUILD_SYSYPARSER_H_INCLUDED # define YY_YY_HOME_HZQ_SYSYF_IR_LAB_2021_SYSYCOMPILER_IR_LAB_BUILD_SYSYFPARSER_H_INCLUDED
// "%code requires" blocks. // "%code requires" blocks.
#line 12 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYParser.yy" #line 12 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFParser.yy"
#include <string> #include <string>
#include "SyntaxTree.h" #include "SyntaxTree.h"
class SysYDriver; class SysYFDriver;
#line 55 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYParser.h" #line 55 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFParser.h"
# include <cassert> # include <cassert>
# include <cstdlib> // std::abort # include <cstdlib> // std::abort
@ -185,13 +185,13 @@ class SysYDriver;
#endif #endif
namespace yy { namespace yy {
#line 189 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYParser.h" #line 189 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFParser.h"
/// A Bison parser. /// A Bison parser.
class SysYParser class SysYFParser
{ {
public: public:
#ifndef YYSTYPE #ifndef YYSTYPE
@ -1225,7 +1225,7 @@ switch (yykind)
/// The user-facing name of this symbol. /// The user-facing name of this symbol.
std::string name () const YY_NOEXCEPT std::string name () const YY_NOEXCEPT
{ {
return SysYParser::symbol_name (this->kind ()); return SysYFParser::symbol_name (this->kind ());
} }
/// Backward compatibility (Bison 3.6). /// Backward compatibility (Bison 3.6).
@ -1351,14 +1351,14 @@ switch (yykind)
}; };
/// Build a parser object. /// Build a parser object.
SysYParser (SysYDriver& driver_yyarg); SysYFParser (SysYFDriver& driver_yyarg);
virtual ~SysYParser (); virtual ~SysYFParser ();
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
/// Non copyable. /// Non copyable.
SysYParser (const SysYParser&) = delete; SysYFParser (const SysYFParser&) = delete;
/// Non copyable. /// Non copyable.
SysYParser& operator= (const SysYParser&) = delete; SysYFParser& operator= (const SysYFParser&) = delete;
#endif #endif
/// Parse. An alias for parse (). /// Parse. An alias for parse ().
@ -2196,7 +2196,7 @@ switch (yykind)
class context class context
{ {
public: public:
context (const SysYParser& yyparser, const symbol_type& yyla); context (const SysYFParser& yyparser, const symbol_type& yyla);
const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; } const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; }
symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); } symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }
const location_type& location () const YY_NOEXCEPT { return yyla_.location; } const location_type& location () const YY_NOEXCEPT { return yyla_.location; }
@ -2207,16 +2207,16 @@ switch (yykind)
int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; int expected_tokens (symbol_kind_type yyarg[], int yyargn) const;
private: private:
const SysYParser& yyparser_; const SysYFParser& yyparser_;
const symbol_type& yyla_; const symbol_type& yyla_;
}; };
private: private:
#if YY_CPLUSPLUS < 201103L #if YY_CPLUSPLUS < 201103L
/// Non copyable. /// Non copyable.
SysYParser (const SysYParser&); SysYFParser (const SysYFParser&);
/// Non copyable. /// Non copyable.
SysYParser& operator= (const SysYParser&); SysYFParser& operator= (const SysYFParser&);
#endif #endif
@ -2528,13 +2528,13 @@ switch (yykind)
// User arguments. // User arguments.
SysYDriver& driver; SysYFDriver& driver;
}; };
inline inline
SysYParser::symbol_kind_type SysYFParser::symbol_kind_type
SysYParser::yytranslate_ (int t) SysYFParser::yytranslate_ (int t)
{ {
// YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to
// TOKEN-NUM as returned by yylex. // TOKEN-NUM as returned by yylex.
@ -2587,7 +2587,7 @@ switch (yykind)
// basic_symbol. // basic_symbol.
template <typename Base> template <typename Base>
SysYParser::basic_symbol<Base>::basic_symbol (const basic_symbol& that) SysYFParser::basic_symbol<Base>::basic_symbol (const basic_symbol& that)
: Base (that) : Base (that)
, value () , value ()
, location (that.location) , location (that.location)
@ -2697,22 +2697,22 @@ switch (yykind)
template <typename Base> template <typename Base>
SysYParser::symbol_kind_type SysYFParser::symbol_kind_type
SysYParser::basic_symbol<Base>::type_get () const YY_NOEXCEPT SysYFParser::basic_symbol<Base>::type_get () const YY_NOEXCEPT
{ {
return this->kind (); return this->kind ();
} }
template <typename Base> template <typename Base>
bool bool
SysYParser::basic_symbol<Base>::empty () const YY_NOEXCEPT SysYFParser::basic_symbol<Base>::empty () const YY_NOEXCEPT
{ {
return this->kind () == symbol_kind::S_YYEMPTY; return this->kind () == symbol_kind::S_YYEMPTY;
} }
template <typename Base> template <typename Base>
void void
SysYParser::basic_symbol<Base>::move (basic_symbol& s) SysYFParser::basic_symbol<Base>::move (basic_symbol& s)
{ {
super_type::move (s); super_type::move (s);
switch (this->kind ()) switch (this->kind ())
@ -2820,13 +2820,13 @@ switch (yykind)
// by_kind. // by_kind.
inline inline
SysYParser::by_kind::by_kind () SysYFParser::by_kind::by_kind ()
: kind_ (symbol_kind::S_YYEMPTY) : kind_ (symbol_kind::S_YYEMPTY)
{} {}
#if 201103L <= YY_CPLUSPLUS #if 201103L <= YY_CPLUSPLUS
inline inline
SysYParser::by_kind::by_kind (by_kind&& that) SysYFParser::by_kind::by_kind (by_kind&& that)
: kind_ (that.kind_) : kind_ (that.kind_)
{ {
that.clear (); that.clear ();
@ -2834,48 +2834,48 @@ switch (yykind)
#endif #endif
inline inline
SysYParser::by_kind::by_kind (const by_kind& that) SysYFParser::by_kind::by_kind (const by_kind& that)
: kind_ (that.kind_) : kind_ (that.kind_)
{} {}
inline inline
SysYParser::by_kind::by_kind (token_kind_type t) SysYFParser::by_kind::by_kind (token_kind_type t)
: kind_ (yytranslate_ (t)) : kind_ (yytranslate_ (t))
{} {}
inline inline
void void
SysYParser::by_kind::clear () YY_NOEXCEPT SysYFParser::by_kind::clear () YY_NOEXCEPT
{ {
kind_ = symbol_kind::S_YYEMPTY; kind_ = symbol_kind::S_YYEMPTY;
} }
inline inline
void void
SysYParser::by_kind::move (by_kind& that) SysYFParser::by_kind::move (by_kind& that)
{ {
kind_ = that.kind_; kind_ = that.kind_;
that.clear (); that.clear ();
} }
inline inline
SysYParser::symbol_kind_type SysYFParser::symbol_kind_type
SysYParser::by_kind::kind () const YY_NOEXCEPT SysYFParser::by_kind::kind () const YY_NOEXCEPT
{ {
return kind_; return kind_;
} }
inline inline
SysYParser::symbol_kind_type SysYFParser::symbol_kind_type
SysYParser::by_kind::type_get () const YY_NOEXCEPT SysYFParser::by_kind::type_get () const YY_NOEXCEPT
{ {
return this->kind (); return this->kind ();
} }
} // yy } // yy
#line 2877 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYParser.h" #line 2877 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFParser.h"
#endif // !YY_YY_HOME_HZQ_SYSYF_IR_LAB_2021_SYSYCOMPILER_IR_LAB_BUILD_SYSYPARSER_H_INCLUDED #endif // !YY_YY_HOME_HZQ_SYSYF_IR_LAB_2021_SYSYCOMPILER_IR_LAB_BUILD_SYSYFPARSER_H_INCLUDED

@ -1,5 +1,5 @@
#ifndef _SYSY_IR_BUILDER_HPP_ #ifndef _SYSYF_IR_BUILDER_HPP_
#define _SYSY_IR_BUILDER_HPP_ #define _SYSYF_IR_BUILDER_HPP_
#include "BasicBlock.h" #include "BasicBlock.h"
#include "Constant.h" #include "Constant.h"
#include "Function.h" #include "Function.h"
@ -69,7 +69,7 @@ private:
std::vector<std::map<std::string, Value *>> name2func; std::vector<std::map<std::string, Value *>> name2func;
}; };
class SysYBuilder: public SyntaxTree::Visitor class SysYFBuilder: public SyntaxTree::Visitor
{ {
private: private:
virtual void visit(SyntaxTree::InitVal &) override final; virtual void visit(SyntaxTree::InitVal &) override final;
@ -99,8 +99,8 @@ private:
Scope scope; Scope scope;
std::unique_ptr<Module> module; std::unique_ptr<Module> module;
public: public:
SysYBuilder(){ SysYFBuilder(){
module = std::unique_ptr<Module>(new Module("SysY code")); module = std::unique_ptr<Module>(new Module("SysYF code"));
builder = new IRBuilder(nullptr, module.get()); builder = new IRBuilder(nullptr, module.get());
auto TyVoid = Type::get_void_type(module.get()); auto TyVoid = Type::get_void_type(module.get());
auto TyInt32 = Type::get_int32_type(module.get()); auto TyInt32 = Type::get_int32_type(module.get());
@ -214,4 +214,4 @@ public:
}; };
#endif // _SYSY_IR_BUILDER_HPP_ #endif // _SYSYF_IR_BUILDER_HPP_

@ -1,5 +1,5 @@
#ifndef _SYSY_BASICBLOCK_H_ #ifndef _SYSYF_BASICBLOCK_H_
#define _SYSY_BASICBLOCK_H_ #define _SYSYF_BASICBLOCK_H_
#include "Value.h" #include "Value.h"
#include "Instruction.h" #include "Instruction.h"
@ -74,4 +74,4 @@ private:
Function *parent_; Function *parent_;
}; };
#endif // _SYSY_BASICBLOCK_H_ #endif // _SYSYF_BASICBLOCK_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_CONSTANT_H_ #ifndef _SYSYF_CONSTANT_H_
#define _SYSY_CONSTANT_H_ #define _SYSYF_CONSTANT_H_
#include "User.h" #include "User.h"
#include "Value.h" #include "Value.h"
#include "Type.h" #include "Type.h"
@ -72,4 +72,4 @@ public:
virtual std::string print() override; virtual std::string print() override;
}; };
#endif //_SYSY_CONSTANT_H_ #endif //_SYSYF_CONSTANT_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_FUNCTION_H_ #ifndef _SYSYF_FUNCTION_H_
#define _SYSY_FUNCTION_H_ #define _SYSYF_FUNCTION_H_
#include <iterator> #include <iterator>
#include <list> #include <list>
@ -98,4 +98,4 @@ private:
unsigned arg_no_; // argument No. unsigned arg_no_; // argument No.
}; };
#endif // _SYSY_FUNCTION_H_ #endif // _SYSYF_FUNCTION_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_GLOBALVARIABLE_H_ #ifndef _SYSYF_GLOBALVARIABLE_H_
#define _SYSY_GLOBALVARIABLE_H_ #define _SYSYF_GLOBALVARIABLE_H_
#include "Module.h" #include "Module.h"
#include "User.h" #include "User.h"
@ -19,4 +19,4 @@ public:
bool is_const() { return is_const_; } bool is_const() { return is_const_; }
std::string print(); std::string print();
}; };
#endif //_SYSY_GLOBALVARIABLE_H_ #endif //_SYSYF_GLOBALVARIABLE_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_IRBUILDER_H_ #ifndef _SYSYF_IRBUILDER_H_
#define _SYSY_IRBUILDER_H_ #define _SYSYF_IRBUILDER_H_
#include "BasicBlock.h" #include "BasicBlock.h"
#include "Instruction.h" #include "Instruction.h"
@ -72,4 +72,4 @@ public:
SiToFpInst *create_sitofp(Value *val, Type *ty) { return SiToFpInst::create_sitofp(val, ty, this->BB_); } SiToFpInst *create_sitofp(Value *val, Type *ty) { return SiToFpInst::create_sitofp(val, ty, this->BB_); }
}; };
#endif // _SYSY_IRBUILDER_H_ #endif // _SYSYF_IRBUILDER_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_INSTRUCTION_H_ #ifndef _SYSYF_INSTRUCTION_H_
#define _SYSY_INSTRUCTION_H_ #define _SYSYF_INSTRUCTION_H_
#include "User.h" #include "User.h"
#include "Type.h" #include "Type.h"
@ -402,4 +402,4 @@ private:
}; };
#endif // _SYSY_INSTRUCTION_H_ #endif // _SYSYF_INSTRUCTION_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_MODULE_H_ #ifndef _SYSYF_MODULE_H_
#define _SYSY_MODULE_H_ #define _SYSYF_MODULE_H_
#include <string> #include <string>
#include <list> #include <list>
@ -58,4 +58,4 @@ private:
std::map<std::pair<Type *,int >, ArrayType *> array_map_; std::map<std::pair<Type *,int >, ArrayType *> array_map_;
}; };
#endif // _SYSY_MODULE_H_ #endif // _SYSYF_MODULE_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_TYPE_H_ #ifndef _SYSYF_TYPE_H_
#define _SYSY_TYPE_H_ #define _SYSYF_TYPE_H_
#include <vector> #include <vector>
#include <iostream> #include <iostream>
@ -143,4 +143,4 @@ private:
Type *contained_; // The element type of the ptr. Type *contained_; // The element type of the ptr.
}; };
#endif // _SYSY_TYPE_H_ #endif // _SYSYF_TYPE_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_USER_H_ #ifndef _SYSYF_USER_H_
#define _SYSY_USER_H_ #define _SYSYF_USER_H_
#include "Value.h" #include "Value.h"
#include <vector> #include <vector>
@ -31,4 +31,4 @@ private:
unsigned num_ops_; unsigned num_ops_;
}; };
#endif // _SYSY_USER_H_ #endif // _SYSYF_USER_H_

@ -1,5 +1,5 @@
#ifndef _SYSY_VALUE_H_ #ifndef _SYSYF_VALUE_H_
#define _SYSY_VALUE_H_ #define _SYSYF_VALUE_H_
#include <string> #include <string>
#include <list> #include <list>
@ -47,4 +47,4 @@ private:
std::string name_; // should we put name field here ? std::string name_; // should we put name field here ?
}; };
#endif // _SYSY_VALUE_H_ #endif // _SYSYF_VALUE_H_

@ -1,4 +1,3 @@
#include "SyntaxTree.h" #include "SyntaxTree.h"
using namespace SyntaxTree; using namespace SyntaxTree;

@ -1,7 +1,5 @@
#include "ErrorReporter.h" #include "ErrorReporter.h"
ErrorReporter::ErrorReporter(std::ostream &error_stream) : err(error_stream) {} ErrorReporter::ErrorReporter(std::ostream &error_stream) : err(error_stream) {}
void ErrorReporter::error(Position pos, const std::string &msg) void ErrorReporter::error(Position pos, const std::string &msg)

@ -1,16 +1,16 @@
add_library( add_library(
Driver STATIC Driver STATIC
SysYDriver.cpp SysYFDriver.cpp
) )
add_library( add_library(
Scanner STATIC Scanner STATIC
SysYScanner.cpp SysYFScanner.cpp
) )
add_library( add_library(
Parser STATIC Parser STATIC
SysYParser.cpp SysYFParser.cpp
) )
target_link_libraries( target_link_libraries(

@ -1,22 +1,22 @@
#include "SysYDriver.h" #include "SysYFDriver.h"
// #include "SysYParser.h" // #include "SysYFParser.h"
SysYDriver::SysYDriver() SysYFDriver::SysYFDriver()
: trace_scanning(false), trace_parsing(false) : trace_scanning(false), trace_parsing(false)
{ {
} }
SysYDriver::~SysYDriver() SysYFDriver::~SysYFDriver()
{ {
} }
SyntaxTree::Node* SysYDriver::parse(const std::string &f) SyntaxTree::Node* SysYFDriver::parse(const std::string &f)
{ {
file = f; file = f;
// lexer begin // lexer begin
scan_begin(); scan_begin();
yy::SysYParser parser(*this); yy::SysYFParser parser(*this);
parser.set_debug_level(trace_parsing); parser.set_debug_level(trace_parsing);
// parser begin // parser begin
parser.parse(); parser.parse();
@ -26,18 +26,18 @@ SyntaxTree::Node* SysYDriver::parse(const std::string &f)
return this->root; return this->root;
} }
void SysYDriver::error(const yy::location& l, const std::string& m) void SysYFDriver::error(const yy::location& l, const std::string& m)
{ {
std::cerr << l << ": " << m << std::endl; std::cerr << l << ": " << m << std::endl;
} }
void SysYDriver::error(const std::string& m) void SysYFDriver::error(const std::string& m)
{ {
std::cerr << m << std::endl; std::cerr << m << std::endl;
} }
void SysYDriver::scan_begin() void SysYFDriver::scan_begin()
{ {
lexer.set_debug(trace_scanning); lexer.set_debug(trace_scanning);
@ -56,7 +56,7 @@ void SysYDriver::scan_begin()
} }
} }
void SysYDriver::scan_end() void SysYFDriver::scan_end()
{ {
instream.close(); instream.close();
} }

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
#line 2 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYScanner.cpp" #line 2 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFScanner.cpp"
#line 4 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYScanner.cpp" #line 4 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFScanner.cpp"
#define YY_INT_ALIGNED short int #define YY_INT_ALIGNED short int
@ -597,8 +597,8 @@ static yyconst flex_int16_t yy_rule_linenum[45] =
#define yymore() yymore_used_but_not_detected #define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0 #define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET #define YY_RESTORE_YY_MORE_OFFSET
#line 1 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 1 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
#line 2 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 2 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
# include <cerrno> # include <cerrno>
# include <climits> # include <climits>
# include <cstdlib> # include <cstdlib>
@ -631,18 +631,18 @@ std::map<char,int> ch2int = {
{'E',14}, {'E',14},
{'F',15} {'F',15}
}; };
# include "SysYDriver.h" # include "SysYFDriver.h"
# include "SysYParser.h" # include "SysYFParser.h"
# define RET_NOTYPE_TOKEN(name) \ # define RET_NOTYPE_TOKEN(name) \
auto mytoken = yy::SysYParser::make_##name(loc);\ auto mytoken = yy::SysYFParser::make_##name(loc);\
loc.step();\ loc.step();\
return mytoken; return mytoken;
# define RET_TYPE_TOKEN(name, value) \ # define RET_TYPE_TOKEN(name, value) \
auto mytoken = yy::SysYParser::make_##name(value, loc);\ auto mytoken = yy::SysYFParser::make_##name(value, loc);\
loc.step();\ loc.step();\
return mytoken; return mytoken;
#line 48 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 48 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
#if defined __clang__ #if defined __clang__
# define CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) # define CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#endif #endif
@ -704,11 +704,11 @@ std::map<char,int> ch2int = {
# endif # endif
#endif #endif
#define YY_NO_INPUT 1 #define YY_NO_INPUT 1
#line 113 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 113 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
// Code run each time a pattern is matched. // Code run each time a pattern is matched.
# define YY_USER_ACTION loc.columns(yyleng); # define YY_USER_ACTION loc.columns(yyleng);
/* Regex abbreviations: */ /* Regex abbreviations: */
#line 712 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYScanner.cpp" #line 712 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFScanner.cpp"
#define INITIAL 0 #define INITIAL 0
@ -905,10 +905,10 @@ YY_DECL
{ {
/* %% [7.0] user's declarations go here */ /* %% [7.0] user's declarations go here */
#line 129 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 129 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
/* keyword */ /* keyword */
#line 912 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYScanner.cpp" #line 912 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFScanner.cpp"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{ {
@ -985,190 +985,190 @@ do_action: /* This label is used only to access EOF actions. */
case 1: case 1:
YY_RULE_SETUP YY_RULE_SETUP
#line 131 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 131 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(FLOAT);} {RET_NOTYPE_TOKEN(FLOAT);}
YY_BREAK YY_BREAK
case 2: case 2:
YY_RULE_SETUP YY_RULE_SETUP
#line 132 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 132 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(INT);} {RET_NOTYPE_TOKEN(INT);}
YY_BREAK YY_BREAK
case 3: case 3:
YY_RULE_SETUP YY_RULE_SETUP
#line 133 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 133 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(RETURN);} {RET_NOTYPE_TOKEN(RETURN);}
YY_BREAK YY_BREAK
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
#line 134 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 134 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(VOID);} {RET_NOTYPE_TOKEN(VOID);}
YY_BREAK YY_BREAK
case 5: case 5:
YY_RULE_SETUP YY_RULE_SETUP
#line 135 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 135 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(CONST);} {RET_NOTYPE_TOKEN(CONST);}
YY_BREAK YY_BREAK
case 6: case 6:
YY_RULE_SETUP YY_RULE_SETUP
#line 136 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 136 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(BREAK);} {RET_NOTYPE_TOKEN(BREAK);}
YY_BREAK YY_BREAK
case 7: case 7:
YY_RULE_SETUP YY_RULE_SETUP
#line 137 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 137 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(CONTINUE);} {RET_NOTYPE_TOKEN(CONTINUE);}
YY_BREAK YY_BREAK
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
#line 138 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 138 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(WHILE);} {RET_NOTYPE_TOKEN(WHILE);}
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
#line 139 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 139 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(IF);} {RET_NOTYPE_TOKEN(IF);}
YY_BREAK YY_BREAK
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
#line 140 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 140 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(ELSE);} {RET_NOTYPE_TOKEN(ELSE);}
YY_BREAK YY_BREAK
case 11: case 11:
YY_RULE_SETUP YY_RULE_SETUP
#line 142 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 142 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(LT);} {RET_NOTYPE_TOKEN(LT);}
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
#line 143 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 143 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(LTE);} {RET_NOTYPE_TOKEN(LTE);}
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
#line 144 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 144 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(GT);} {RET_NOTYPE_TOKEN(GT);}
YY_BREAK YY_BREAK
case 14: case 14:
YY_RULE_SETUP YY_RULE_SETUP
#line 145 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 145 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(GTE);} {RET_NOTYPE_TOKEN(GTE);}
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
#line 146 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 146 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(EQ);} {RET_NOTYPE_TOKEN(EQ);}
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
#line 147 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 147 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(NEQ);} {RET_NOTYPE_TOKEN(NEQ);}
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
#line 148 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 148 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(NOT);} {RET_NOTYPE_TOKEN(NOT);}
YY_BREAK YY_BREAK
case 18: case 18:
YY_RULE_SETUP YY_RULE_SETUP
#line 149 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 149 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(LOGICAND);} {RET_NOTYPE_TOKEN(LOGICAND);}
YY_BREAK YY_BREAK
case 19: case 19:
YY_RULE_SETUP YY_RULE_SETUP
#line 150 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 150 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(LOGICOR);} {RET_NOTYPE_TOKEN(LOGICOR);}
YY_BREAK YY_BREAK
case 20: case 20:
YY_RULE_SETUP YY_RULE_SETUP
#line 151 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 151 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(PLUS);} {RET_NOTYPE_TOKEN(PLUS);}
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
#line 152 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 152 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(MINUS);} {RET_NOTYPE_TOKEN(MINUS);}
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 153 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 153 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(MULTIPLY);} {RET_NOTYPE_TOKEN(MULTIPLY);}
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 154 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 154 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(DIVIDE);} {RET_NOTYPE_TOKEN(DIVIDE);}
YY_BREAK YY_BREAK
case 24: case 24:
YY_RULE_SETUP YY_RULE_SETUP
#line 155 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 155 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(MODULO);} {RET_NOTYPE_TOKEN(MODULO);}
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
#line 156 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 156 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(ASSIGN);} {RET_NOTYPE_TOKEN(ASSIGN);}
YY_BREAK YY_BREAK
case 26: case 26:
YY_RULE_SETUP YY_RULE_SETUP
#line 157 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 157 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(SEMICOLON);} {RET_NOTYPE_TOKEN(SEMICOLON);}
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
#line 158 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 158 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(COMMA);} {RET_NOTYPE_TOKEN(COMMA);}
YY_BREAK YY_BREAK
case 28: case 28:
YY_RULE_SETUP YY_RULE_SETUP
#line 159 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 159 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(LPARENTHESE);} {RET_NOTYPE_TOKEN(LPARENTHESE);}
YY_BREAK YY_BREAK
case 29: case 29:
YY_RULE_SETUP YY_RULE_SETUP
#line 160 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 160 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(RPARENTHESE);} {RET_NOTYPE_TOKEN(RPARENTHESE);}
YY_BREAK YY_BREAK
case 30: case 30:
YY_RULE_SETUP YY_RULE_SETUP
#line 161 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 161 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(LBRACKET);} {RET_NOTYPE_TOKEN(LBRACKET);}
YY_BREAK YY_BREAK
case 31: case 31:
YY_RULE_SETUP YY_RULE_SETUP
#line 162 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 162 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(RBRACKET);} {RET_NOTYPE_TOKEN(RBRACKET);}
YY_BREAK YY_BREAK
case 32: case 32:
YY_RULE_SETUP YY_RULE_SETUP
#line 163 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 163 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(LBRACE);} {RET_NOTYPE_TOKEN(LBRACE);}
YY_BREAK YY_BREAK
case 33: case 33:
YY_RULE_SETUP YY_RULE_SETUP
#line 164 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 164 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(RBRACE);} {RET_NOTYPE_TOKEN(RBRACE);}
YY_BREAK YY_BREAK
case 34: case 34:
/* rule 34 can match eol */ /* rule 34 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 167 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 167 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(LRBRACKET);} {RET_NOTYPE_TOKEN(LRBRACKET);}
YY_BREAK YY_BREAK
case 35: case 35:
YY_RULE_SETUP YY_RULE_SETUP
#line 168 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 168 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{loc.step();} {loc.step();}
YY_BREAK YY_BREAK
case 36: case 36:
/* rule 36 can match eol */ /* rule 36 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 169 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 169 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{loc.lines(yyleng); loc.step();} {loc.lines(yyleng); loc.step();}
YY_BREAK YY_BREAK
case 37: case 37:
/* rule 37 can match eol */ /* rule 37 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 170 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 170 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{std::string s = yytext; {std::string s = yytext;
size_t n = std::count(s.begin(), s.end(), '\n'); size_t n = std::count(s.begin(), s.end(), '\n');
for (size_t i = 0; i < n; i++) loc.lines(1);} for (size_t i = 0; i < n; i++) loc.lines(1);}
@ -1176,12 +1176,12 @@ YY_RULE_SETUP
case 38: case 38:
/* rule 38 can match eol */ /* rule 38 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 173 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 173 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{loc.lines(1);loc.step();} {loc.lines(1);loc.step();}
YY_BREAK YY_BREAK
case 39: case 39:
YY_RULE_SETUP YY_RULE_SETUP
#line 174 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 174 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{std::string dec = yytext; {std::string dec = yytext;
unsigned sum = 0; unsigned sum = 0;
int len = dec.size(); int len = dec.size();
@ -1193,7 +1193,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 40: case 40:
YY_RULE_SETUP YY_RULE_SETUP
#line 182 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 182 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{std::string hex = yytext; {std::string hex = yytext;
unsigned sum = 0; unsigned sum = 0;
int len = hex.size(); int len = hex.size();
@ -1205,7 +1205,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 41: case 41:
YY_RULE_SETUP YY_RULE_SETUP
#line 190 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 190 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{std::string oct = yytext; {std::string oct = yytext;
unsigned sum = 0; unsigned sum = 0;
int len = oct.size(); int len = oct.size();
@ -1217,29 +1217,29 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 42: case 42:
YY_RULE_SETUP YY_RULE_SETUP
#line 198 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 198 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_TYPE_TOKEN(IDENTIFIER, yytext);} {RET_TYPE_TOKEN(IDENTIFIER, yytext);}
YY_BREAK YY_BREAK
case 43: case 43:
YY_RULE_SETUP YY_RULE_SETUP
#line 199 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 199 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_TYPE_TOKEN(FLOATCONST, std::stod(yytext));} {RET_TYPE_TOKEN(FLOATCONST, std::stod(yytext));}
YY_BREAK YY_BREAK
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
#line 200 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 200 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{RET_NOTYPE_TOKEN(END);} {RET_NOTYPE_TOKEN(END);}
YY_BREAK YY_BREAK
case 44: case 44:
YY_RULE_SETUP YY_RULE_SETUP
#line 201 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 201 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
{std::cout << "Error in scanner!" << '\n'; exit(1);} {std::cout << "Error in scanner!" << '\n'; exit(1);}
YY_BREAK YY_BREAK
case 45: case 45:
YY_RULE_SETUP YY_RULE_SETUP
#line 202 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 202 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 1243 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYScanner.cpp" #line 1243 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/build/SysYFScanner.cpp"
case YY_END_OF_BUFFER: case YY_END_OF_BUFFER:
{ {
@ -2350,7 +2350,7 @@ void yyfree (void * ptr )
/* %ok-for-header */ /* %ok-for-header */
#line 202 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll" #line 202 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYFScanner.ll"

@ -1,4 +0,0 @@
add_library(
SysYBuilder STATIC
SysYBuilder.cpp
)

@ -1,74 +0,0 @@
#include "SysYBuilder.hpp"
#define CONST_INT(num) ConstantInt::get(num, module.get())
#define CONST_FLOAT(num) ConstantFloat::get(num, module.get())
// You can define global variables and functions here
// to store state
// store temporary value
Value *tmp_val = nullptr;
// types
Type *VOID_T;
Type *INT1_T;
Type *INT32_T;
Type *FLOAT_T;
Type *INT32PTR_T;
Type *FLOATPTR_T;
void SysYBuilder::visit(SyntaxTree::Assembly &node) {
VOID_T = Type::get_void_type(module.get());
INT1_T = Type::get_int1_type(module.get());
INT32_T = Type::get_int32_type(module.get());
FLOAT_T = Type::get_float_type(module.get());
INT32PTR_T = Type::get_int32_ptr_type(module.get());
FLOATPTR_T = Type::get_float_ptr_type(module.get());
for (const auto &def : node.global_defs) {
def->accept(*this);
}
}
// You need to fill them
void SysYBuilder::visit(SyntaxTree::InitVal &node) {}
void SysYBuilder::visit(SyntaxTree::FuncDef &node) {}
void SysYBuilder::visit(SyntaxTree::FuncFParamList &node) {}
void SysYBuilder::visit(SyntaxTree::FuncParam &node) {}
void SysYBuilder::visit(SyntaxTree::VarDef &node) {}
void SysYBuilder::visit(SyntaxTree::LVal &node) {}
void SysYBuilder::visit(SyntaxTree::AssignStmt &node) {}
void SysYBuilder::visit(SyntaxTree::Literal &node) {}
void SysYBuilder::visit(SyntaxTree::ReturnStmt &node) {}
void SysYBuilder::visit(SyntaxTree::BlockStmt &node) {}
void SysYBuilder::visit(SyntaxTree::EmptyStmt &node) {}
void SysYBuilder::visit(SyntaxTree::ExprStmt &node) {}
void SysYBuilder::visit(SyntaxTree::UnaryCondExpr &node) {}
void SysYBuilder::visit(SyntaxTree::BinaryCondExpr &node) {}
void SysYBuilder::visit(SyntaxTree::BinaryExpr &node) {}
void SysYBuilder::visit(SyntaxTree::UnaryExpr &node) {}
void SysYBuilder::visit(SyntaxTree::FuncCallStmt &node) {}
void SysYBuilder::visit(SyntaxTree::IfStmt &node) {}
void SysYBuilder::visit(SyntaxTree::WhileStmt &node) {}
void SysYBuilder::visit(SyntaxTree::BreakStmt &node) {}
void SysYBuilder::visit(SyntaxTree::ContinueStmt &node) {}

@ -0,0 +1,4 @@
add_library(
SysYFBuilder STATIC
SysYFBuilder.cpp
)

@ -0,0 +1,74 @@
#include "SysYFBuilder.hpp"
#define CONST_INT(num) ConstantInt::get(num, module.get())
#define CONST_FLOAT(num) ConstantFloat::get(num, module.get())
// You can define global variables and functions here
// to store state
// store temporary value
Value *tmp_val = nullptr;
// types
Type *VOID_T;
Type *INT1_T;
Type *INT32_T;
Type *FLOAT_T;
Type *INT32PTR_T;
Type *FLOATPTR_T;
void SysYFBuilder::visit(SyntaxTree::Assembly &node) {
VOID_T = Type::get_void_type(module.get());
INT1_T = Type::get_int1_type(module.get());
INT32_T = Type::get_int32_type(module.get());
FLOAT_T = Type::get_float_type(module.get());
INT32PTR_T = Type::get_int32_ptr_type(module.get());
FLOATPTR_T = Type::get_float_ptr_type(module.get());
for (const auto &def : node.global_defs) {
def->accept(*this);
}
}
// You need to fill them
void SysYFBuilder::visit(SyntaxTree::InitVal &node) {}
void SysYFBuilder::visit(SyntaxTree::FuncDef &node) {}
void SysYFBuilder::visit(SyntaxTree::FuncFParamList &node) {}
void SysYFBuilder::visit(SyntaxTree::FuncParam &node) {}
void SysYFBuilder::visit(SyntaxTree::VarDef &node) {}
void SysYFBuilder::visit(SyntaxTree::LVal &node) {}
void SysYFBuilder::visit(SyntaxTree::AssignStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::Literal &node) {}
void SysYFBuilder::visit(SyntaxTree::ReturnStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::BlockStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::EmptyStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::ExprStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::UnaryCondExpr &node) {}
void SysYFBuilder::visit(SyntaxTree::BinaryCondExpr &node) {}
void SysYFBuilder::visit(SyntaxTree::BinaryExpr &node) {}
void SysYFBuilder::visit(SyntaxTree::UnaryExpr &node) {}
void SysYFBuilder::visit(SyntaxTree::FuncCallStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::IfStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::WhileStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::BreakStmt &node) {}
void SysYFBuilder::visit(SyntaxTree::ContinueStmt &node) {}

@ -1,6 +1,6 @@
#include <iostream> #include <iostream>
#include "SysYBuilder.hpp" #include "SysYFBuilder.hpp"
#include "SysYDriver.h" #include "SysYFDriver.h"
#include "SyntaxTreePrinter.h" #include "SyntaxTreePrinter.h"
#include "ErrorReporter.h" #include "ErrorReporter.h"
@ -14,8 +14,8 @@ void print_help(const std::string& exe_name) {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
SysYBuilder builder; SysYFBuilder builder;
SysYDriver driver; SysYFDriver driver;
SyntaxTreePrinter printer; SyntaxTreePrinter printer;
ErrorReporter reporter(std::cerr); ErrorReporter reporter(std::cerr);

Loading…
Cancel
Save