change SysY to SysYF

master
15750821961 3 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/ErrorReporter)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/Grammar)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/SysYIR)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/SysYBuilder)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/SysYFIR)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/SysYFBuilder)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ASTBuilder)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ASTPrinter)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ErrorReporter)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/Grammar)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/SysYIR)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/SysYBuilder)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/SysYFIR)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/SysYFBuilder)
add_executable(
SysYCompiler
SysYFCompiler
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
)
target_link_libraries(
SysYCompiler
SysYBuilder
SysYFCompiler
SysYFBuilder
IRLib
Driver
ASTPrinter

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

@ -1,6 +1,6 @@
add_executable(
assign_generator
assign_gen.cpp
assign_generator
assign_gen.cpp
)
target_link_libraries(
assign_generator
@ -30,7 +30,7 @@ add_executable(
while_gen.cpp
)
target_link_libraries(
while_generator
while_generator
IRLib
)

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

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

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

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

@ -1,9 +1,9 @@
#ifndef _SYSY_FLEX_LEXER_H_
#define _SYSY_FLEX_LEXER_H_
#ifndef _SYSYF_FLEX_LEXER_H_
#define _SYSYF_FLEX_LEXER_H_
#ifndef YY_DECL
#define YY_DECL \
yy::SysYParser::symbol_type SysYFlexLexer::yylex(SysYDriver& driver)
yy::SysYFParser::symbol_type SysYFFlexLexer::yylex(SysYFDriver& driver)
#endif
// We need this for yyFlexLexer. If we don't #undef yyFlexLexer, the
@ -12,20 +12,20 @@
#undef yyFlexLexer
#include <FlexLexer.h>
// We need this for the yy::SysYParser::symbol_type:
#include "SysYParser.h"
// We need this for the yy::SysYFParser::symbol_type:
#include "SysYFParser.h"
// We need this for the yy::location type:
#include "location.hh"
class SysYFlexLexer : public yyFlexLexer {
class SysYFFlexLexer : public yyFlexLexer {
public:
// Use the superclass's constructor:
using yyFlexLexer::yyFlexLexer;
// Provide the interface to `yylex`; `flex` will emit the
// definition into `SysYScanner.cpp`:
yy::SysYParser::symbol_type yylex(SysYDriver& driver);
// definition into `SysYFScanner.cpp`:
yy::SysYFParser::symbol_type yylex(SysYFDriver& driver);
// This seems like a reasonable place to put the location object
// rather than it being static (in the sense of having internal
@ -34,4 +34,4 @@ public:
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.
*/
@ -42,16 +42,16 @@
// especially those whose name start with YY_ or yy_. They are
// 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
# define 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_SYSYFPARSER_H_INCLUDED
// "%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 "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 <cstdlib> // std::abort
@ -185,13 +185,13 @@ class SysYDriver;
#endif
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.
class SysYParser
class SysYFParser
{
public:
#ifndef YYSTYPE
@ -1225,7 +1225,7 @@ switch (yykind)
/// The user-facing name of this symbol.
std::string name () const YY_NOEXCEPT
{
return SysYParser::symbol_name (this->kind ());
return SysYFParser::symbol_name (this->kind ());
}
/// Backward compatibility (Bison 3.6).
@ -1351,14 +1351,14 @@ switch (yykind)
};
/// Build a parser object.
SysYParser (SysYDriver& driver_yyarg);
virtual ~SysYParser ();
SysYFParser (SysYFDriver& driver_yyarg);
virtual ~SysYFParser ();
#if 201103L <= YY_CPLUSPLUS
/// Non copyable.
SysYParser (const SysYParser&) = delete;
SysYFParser (const SysYFParser&) = delete;
/// Non copyable.
SysYParser& operator= (const SysYParser&) = delete;
SysYFParser& operator= (const SysYFParser&) = delete;
#endif
/// Parse. An alias for parse ().
@ -2196,7 +2196,7 @@ switch (yykind)
class context
{
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_; }
symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }
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;
private:
const SysYParser& yyparser_;
const SysYFParser& yyparser_;
const symbol_type& yyla_;
};
private:
#if YY_CPLUSPLUS < 201103L
/// Non copyable.
SysYParser (const SysYParser&);
SysYFParser (const SysYFParser&);
/// Non copyable.
SysYParser& operator= (const SysYParser&);
SysYFParser& operator= (const SysYFParser&);
#endif
@ -2528,13 +2528,13 @@ switch (yykind)
// User arguments.
SysYDriver& driver;
SysYFDriver& driver;
};
inline
SysYParser::symbol_kind_type
SysYParser::yytranslate_ (int t)
SysYFParser::symbol_kind_type
SysYFParser::yytranslate_ (int t)
{
// YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to
// TOKEN-NUM as returned by yylex.
@ -2587,7 +2587,7 @@ switch (yykind)
// basic_symbol.
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)
, value ()
, location (that.location)
@ -2697,22 +2697,22 @@ switch (yykind)
template <typename Base>
SysYParser::symbol_kind_type
SysYParser::basic_symbol<Base>::type_get () const YY_NOEXCEPT
SysYFParser::symbol_kind_type
SysYFParser::basic_symbol<Base>::type_get () const YY_NOEXCEPT
{
return this->kind ();
}
template <typename Base>
bool
SysYParser::basic_symbol<Base>::empty () const YY_NOEXCEPT
SysYFParser::basic_symbol<Base>::empty () const YY_NOEXCEPT
{
return this->kind () == symbol_kind::S_YYEMPTY;
}
template <typename Base>
void
SysYParser::basic_symbol<Base>::move (basic_symbol& s)
SysYFParser::basic_symbol<Base>::move (basic_symbol& s)
{
super_type::move (s);
switch (this->kind ())
@ -2820,13 +2820,13 @@ switch (yykind)
// by_kind.
inline
SysYParser::by_kind::by_kind ()
SysYFParser::by_kind::by_kind ()
: kind_ (symbol_kind::S_YYEMPTY)
{}
#if 201103L <= YY_CPLUSPLUS
inline
SysYParser::by_kind::by_kind (by_kind&& that)
SysYFParser::by_kind::by_kind (by_kind&& that)
: kind_ (that.kind_)
{
that.clear ();
@ -2834,48 +2834,48 @@ switch (yykind)
#endif
inline
SysYParser::by_kind::by_kind (const by_kind& that)
SysYFParser::by_kind::by_kind (const by_kind& that)
: kind_ (that.kind_)
{}
inline
SysYParser::by_kind::by_kind (token_kind_type t)
SysYFParser::by_kind::by_kind (token_kind_type t)
: kind_ (yytranslate_ (t))
{}
inline
void
SysYParser::by_kind::clear () YY_NOEXCEPT
SysYFParser::by_kind::clear () YY_NOEXCEPT
{
kind_ = symbol_kind::S_YYEMPTY;
}
inline
void
SysYParser::by_kind::move (by_kind& that)
SysYFParser::by_kind::move (by_kind& that)
{
kind_ = that.kind_;
that.clear ();
}
inline
SysYParser::symbol_kind_type
SysYParser::by_kind::kind () const YY_NOEXCEPT
SysYFParser::symbol_kind_type
SysYFParser::by_kind::kind () const YY_NOEXCEPT
{
return kind_;
}
inline
SysYParser::symbol_kind_type
SysYParser::by_kind::type_get () const YY_NOEXCEPT
SysYFParser::symbol_kind_type
SysYFParser::by_kind::type_get () const YY_NOEXCEPT
{
return this->kind ();
}
} // 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_
#define _SYSY_IR_BUILDER_HPP_
#ifndef _SYSYF_IR_BUILDER_HPP_
#define _SYSYF_IR_BUILDER_HPP_
#include "BasicBlock.h"
#include "Constant.h"
#include "Function.h"
@ -69,7 +69,7 @@ private:
std::vector<std::map<std::string, Value *>> name2func;
};
class SysYBuilder: public SyntaxTree::Visitor
class SysYFBuilder: public SyntaxTree::Visitor
{
private:
virtual void visit(SyntaxTree::InitVal &) override final;
@ -99,8 +99,8 @@ private:
Scope scope;
std::unique_ptr<Module> module;
public:
SysYBuilder(){
module = std::unique_ptr<Module>(new Module("SysY code"));
SysYFBuilder(){
module = std::unique_ptr<Module>(new Module("SysYF code"));
builder = new IRBuilder(nullptr, module.get());
auto TyVoid = Type::get_void_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_
#define _SYSY_BASICBLOCK_H_
#ifndef _SYSYF_BASICBLOCK_H_
#define _SYSYF_BASICBLOCK_H_
#include "Value.h"
#include "Instruction.h"
@ -74,4 +74,4 @@ private:
Function *parent_;
};
#endif // _SYSY_BASICBLOCK_H_
#endif // _SYSYF_BASICBLOCK_H_

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

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

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

@ -1,5 +1,5 @@
#ifndef _SYSY_IRBUILDER_H_
#define _SYSY_IRBUILDER_H_
#ifndef _SYSYF_IRBUILDER_H_
#define _SYSYF_IRBUILDER_H_
#include "BasicBlock.h"
#include "Instruction.h"
@ -72,4 +72,4 @@ public:
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_
#define _SYSY_INSTRUCTION_H_
#ifndef _SYSYF_INSTRUCTION_H_
#define _SYSYF_INSTRUCTION_H_
#include "User.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_
#define _SYSY_MODULE_H_
#ifndef _SYSYF_MODULE_H_
#define _SYSYF_MODULE_H_
#include <string>
#include <list>
@ -58,4 +58,4 @@ private:
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_
#define _SYSY_TYPE_H_
#ifndef _SYSYF_TYPE_H_
#define _SYSYF_TYPE_H_
#include <vector>
#include <iostream>
@ -143,4 +143,4 @@ private:
Type *contained_; // The element type of the ptr.
};
#endif // _SYSY_TYPE_H_
#endif // _SYSYF_TYPE_H_

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

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

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

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

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

@ -1,22 +1,22 @@
#include "SysYDriver.h"
// #include "SysYParser.h"
#include "SysYFDriver.h"
// #include "SysYFParser.h"
SysYDriver::SysYDriver()
SysYFDriver::SysYFDriver()
: 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;
// lexer begin
scan_begin();
yy::SysYParser parser(*this);
yy::SysYFParser parser(*this);
parser.set_debug_level(trace_parsing);
// parser begin
parser.parse();
@ -26,18 +26,18 @@ SyntaxTree::Node* SysYDriver::parse(const std::string &f)
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;
}
void SysYDriver::error(const std::string& m)
void SysYFDriver::error(const std::string& m)
{
std::cerr << m << std::endl;
}
void SysYDriver::scan_begin()
void SysYFDriver::scan_begin()
{
lexer.set_debug(trace_scanning);
@ -56,7 +56,7 @@ void SysYDriver::scan_begin()
}
}
void SysYDriver::scan_end()
void SysYFDriver::scan_end()
{
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
@ -597,8 +597,8 @@ static yyconst flex_int16_t yy_rule_linenum[45] =
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
#line 1 "/home/hzq/SysYF_IR_Lab/2021_sysycompiler_ir_lab/grammar/SysYScanner.ll"
#line 2 "/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/SysYFScanner.ll"
# include <cerrno>
# include <climits>
# include <cstdlib>
@ -631,18 +631,18 @@ std::map<char,int> ch2int = {
{'E',14},
{'F',15}
};
# include "SysYDriver.h"
# include "SysYParser.h"
# include "SysYFDriver.h"
# include "SysYFParser.h"
# define RET_NOTYPE_TOKEN(name) \
auto mytoken = yy::SysYParser::make_##name(loc);\
auto mytoken = yy::SysYFParser::make_##name(loc);\
loc.step();\
return mytoken;
# define RET_TYPE_TOKEN(name, value) \
auto mytoken = yy::SysYParser::make_##name(value, loc);\
auto mytoken = yy::SysYFParser::make_##name(value, loc);\
loc.step();\
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__
# define CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#endif
@ -704,11 +704,11 @@ std::map<char,int> ch2int = {
# endif
#endif
#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.
# define YY_USER_ACTION loc.columns(yyleng);
/* 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
@ -905,10 +905,10 @@ YY_DECL
{
/* %% [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 */
#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 */
{
@ -985,190 +985,190 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
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);}
YY_BREAK
case 2:
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);}
YY_BREAK
case 3:
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);}
YY_BREAK
case 4:
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);}
YY_BREAK
case 5:
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);}
YY_BREAK
case 6:
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);}
YY_BREAK
case 7:
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);}
YY_BREAK
case 8:
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);}
YY_BREAK
case 9:
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);}
YY_BREAK
case 10:
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);}
YY_BREAK
case 11:
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);}
YY_BREAK
case 12:
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);}
YY_BREAK
case 13:
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);}
YY_BREAK
case 14:
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);}
YY_BREAK
case 15:
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);}
YY_BREAK
case 16:
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);}
YY_BREAK
case 17:
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);}
YY_BREAK
case 18:
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);}
YY_BREAK
case 19:
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);}
YY_BREAK
case 20:
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);}
YY_BREAK
case 21:
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);}
YY_BREAK
case 22:
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);}
YY_BREAK
case 23:
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);}
YY_BREAK
case 24:
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);}
YY_BREAK
case 25:
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);}
YY_BREAK
case 26:
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);}
YY_BREAK
case 27:
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);}
YY_BREAK
case 28:
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);}
YY_BREAK
case 29:
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);}
YY_BREAK
case 30:
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);}
YY_BREAK
case 31:
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);}
YY_BREAK
case 32:
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);}
YY_BREAK
case 33:
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);}
YY_BREAK
case 34:
/* rule 34 can match eol */
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);}
YY_BREAK
case 35:
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();}
YY_BREAK
case 36:
/* rule 36 can match eol */
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();}
YY_BREAK
case 37:
/* rule 37 can match eol */
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;
size_t n = std::count(s.begin(), s.end(), '\n');
for (size_t i = 0; i < n; i++) loc.lines(1);}
@ -1176,12 +1176,12 @@ YY_RULE_SETUP
case 38:
/* rule 38 can match eol */
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();}
YY_BREAK
case 39:
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;
unsigned sum = 0;
int len = dec.size();
@ -1193,7 +1193,7 @@ YY_RULE_SETUP
YY_BREAK
case 40:
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;
unsigned sum = 0;
int len = hex.size();
@ -1205,7 +1205,7 @@ YY_RULE_SETUP
YY_BREAK
case 41:
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;
unsigned sum = 0;
int len = oct.size();
@ -1217,29 +1217,29 @@ YY_RULE_SETUP
YY_BREAK
case 42:
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);}
YY_BREAK
case 43:
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));}
YY_BREAK
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);}
YY_BREAK
case 44:
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);}
YY_BREAK
case 45:
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;
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:
{
@ -2350,7 +2350,7 @@ void yyfree (void * ptr )
/* %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 "SysYBuilder.hpp"
#include "SysYDriver.h"
#include "SysYFBuilder.hpp"
#include "SysYFDriver.h"
#include "SyntaxTreePrinter.h"
#include "ErrorReporter.h"
@ -14,8 +14,8 @@ void print_help(const std::string& exe_name) {
int main(int argc, char *argv[])
{
SysYBuilder builder;
SysYDriver driver;
SysYFBuilder builder;
SysYFDriver driver;
SyntaxTreePrinter printer;
ErrorReporter reporter(std::cerr);

Loading…
Cancel
Save