From e70b98545fc64cb0102641215ece82b6ac0599d4 Mon Sep 17 00:00:00 2001 From: Lai-YT <381xvmvbib@gmail.com> Date: Sat, 9 Sep 2023 23:25:04 +0800 Subject: [PATCH 1/4] Update Makefile to clean files in deeper directory --- test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index 2c9e48bd..d1a22497 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,4 +5,4 @@ test: qbe -o out.s test.ssa && cc out.s -o a.o && ./a.o clean: - rm -f *.s *o *.ssa + rm -f *.s **/*.s *.o **/*.o *.ssa **/*.ssa From f4e39383535305ed96623932a247110344f274b6 Mon Sep 17 00:00:00 2001 From: Lai-YT <381xvmvbib@gmail.com> Date: Sun, 10 Sep 2023 00:01:57 +0800 Subject: [PATCH 2/4] Separate implementation from header This allows incremental build. Also, implicit rules are used in the Makefile. --- Makefile | 33 ++++-- ast.cpp | 285 ++++++++++++++++++++++++++++++++++++++++++++++++++ ast.hpp | 299 ++++++++--------------------------------------------- symbol.cpp | 22 ++++ symbol.hpp | 18 +--- type.cpp | 11 ++ type.hpp | 12 +-- 7 files changed, 394 insertions(+), 286 deletions(-) create mode 100644 ast.cpp create mode 100644 symbol.cpp create mode 100644 type.cpp diff --git a/Makefile b/Makefile index 1ea5114f..04d6c2ee 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,20 @@ TARGET := vitaminc CXX := g++ -CXXFLAGS = -g3 -std=c++14 -Wall +CC = $(CXX) +CXXFLAGS = -g3 -std=c++14 -Wall -MMD +CFLAGS = $(CXXFLAGS) LEX = lex # C++ features are used, yacc doesn't suffice YACC = bison # -d: generate header with default name YFLAGS = --verbose --debug -d +# Note that lex.yy.c is excluded deliberately, as "lex.yy.c" is considered a +# header file (it's included by "y.tab.c"). +OBJS := $(shell find . -name "*.cpp") y.tab.o +OBJS := $(OBJS:.cpp=.o) +DEPS = $(OBJS:.o=.d) + .PHONY: all clean test all: $(TARGET) test @@ -14,15 +22,26 @@ all: $(TARGET) test test: $(TARGET) make -C test/ -$(TARGET): main.cpp lex.yy.c y.tab.c ast.hpp type.hpp scope.hpp symbol.hpp - $(CXX) $(CXXFLAGS) $< y.tab.c -o $@ +$(TARGET): $(OBJS) + $(CXX) $(CXXFLAGS) $(OBJS) -o $@ lex.yy.c: lexer.l - $(LEX) -o $@ $^ + $(LEX) -o $@ $< + +y.tab.h: y.tab.c +y.tab.c: parser.y lex.yy.c + $(YACC) $(YFLAGS) $< -o $@ -y.tab.c: parser.y - $(YACC) $(YFLAGS) $^ -o $@ +# +# Please note that although we're handling dependencies automatically with -MMD, +# files that includes Flex or Bison-generated files still have to make such +# dependency explicit to enforce the ordering. +# + +main.o: %.o: %.cpp y.tab.h clean: - rm -rf *.s *.o lex.yy.c y.tab.c y.tab.h *.output *.ssa $(TARGET) + rm -rf *.s *.o lex.yy.c y.tab.c y.tab.h *.output *.ssa $(TARGET) $(OBJS) $(DEPS) make -C test/ clean + +-include $(DEPS) diff --git a/ast.cpp b/ast.cpp new file mode 100644 index 00000000..490a3e71 --- /dev/null +++ b/ast.cpp @@ -0,0 +1,285 @@ +#include "ast.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#include "scope.hpp" +#include "symbol.hpp" +#include "type.hpp" + +// clang-format off +// Not to format the padding to emphasize the actual length. + +// 80 spaces for padding 01234567890123456789012345678901234567890123456789012345678901234567890123456789 +static const char* padding = " "; + +// clang-format on + +/// @param n The length of the padding, saturated on the boundary of [0, 80]. +static const char* Pad(int n); + +/// @brief qbe intermediate file +extern std::ofstream output; + +/// @brief Returns the next local number and increment it by 1. The first number +/// will be 1. +static int NextLocalNum() { + /// @brief temporary index under a scope + static int next_local_num = 1; + return next_local_num++; +} + +/// @note Use this as the return local number if the it's not expected to be +/// used, e.g., `StmtNode`. +static const int kDummyLocalNum = -1; + +/// @brief Returns the function-scope temporary with sigil (`%`). +static std::string PrefixSigil(int local_num) { + return "%." + std::to_string(local_num); +} + +static std::map id_to_num{}; + +int DeclNode::CodeGen() const { + int id_num = NextLocalNum(); + output << PrefixSigil(id_num) << " =l alloc4 4" << std::endl; + + if (init_) { + int init_num = init_->CodeGen(); + output << "storew " << PrefixSigil(init_num) << ", " << PrefixSigil(id_num) + << std::endl; + } + // Set up the number of the id so we know were to load it back. + id_to_num[id_] = id_num; + return kDummyLocalNum; +} + +void DeclNode::Dump(int pad) const { + std::cout << Pad(pad) << '(' << id_ << ": " << ExprTypeToCString(type_); + if (init_) { + std::cout << " =" << std::endl; + init_->Dump(pad + 2); + } + std::cout << ')' << std::endl; +} + +void DeclNode::CheckType(ScopeStack& env) { + if (init_) { + init_->CheckType(env); + if (init_->type != type_) { + // TODO: incompatible types when initializing type 'type_' using type + // 'init_->type' + } + } + + if (env.Probe(id_)) { + // TODO: redefinition of 'id_' + } else { + auto symbol = std::make_unique(id_); + symbol->expr_type = type_; + env.Add(std::move(symbol)); + } +} + +int BlockStmtNode::CodeGen() const { + output << "@start" << std::endl; + for (const auto& decl : decls_) { + decl->CodeGen(); + } + for (const auto& stmt : stmts_) { + stmt->CodeGen(); + } + + return kDummyLocalNum; +} + +void BlockStmtNode::Dump(int pad) const { + for (const auto& decl : decls_) { + decl->Dump(pad); + } + for (const auto& stmt : stmts_) { + stmt->Dump(pad); + } +} + +void BlockStmtNode::CheckType(ScopeStack& env) { + env.PushScope(); + for (auto& decl : decls_) { + decl->CheckType(env); + } + for (auto& stmt : stmts_) { + stmt->CheckType(env); + } + env.PopScope(); +} + +/// @brief Root of the entire program. + +int ProgramNode::CodeGen() const { + output << "export function w $main() {" << std::endl; + block_->CodeGen(); + output << "}"; + + return kDummyLocalNum; +} + +void ProgramNode::Dump(int pad) const { + block_->Dump(pad); +} + +void ProgramNode::CheckType(ScopeStack& env) { + block_->CheckType(env); +} + +int NullStmtNode::CodeGen() const { + return kDummyLocalNum; +} + +void NullStmtNode::Dump(int pad) const { + std::cout << Pad(pad) << "()" << std::endl; +} + +void NullStmtNode::CheckType(ScopeStack& env) {} + +int ReturnStmtNode::CodeGen() const { + int ret_num = expr_->CodeGen(); + output << " ret " << PrefixSigil(ret_num) << std::endl; + return kDummyLocalNum; +} + +void ReturnStmtNode::Dump(int pad) const { + std::cout << Pad(pad) << "(ret" << std::endl; + expr_->Dump(pad + 2); + std::cout << Pad(pad) << ')' << std::endl; +} + +void ReturnStmtNode::CheckType(ScopeStack& env) { + expr_->CheckType(env); + if (expr_->type != ExprType::kInt) { + // TODO: return value type does not match the function type + } +} + +int ExprStmtNode::CodeGen() const { + expr_->CodeGen(); + + return kDummyLocalNum; +} + +void ExprStmtNode::Dump(int pad) const { + expr_->Dump(pad); +} + +void ExprStmtNode::CheckType(ScopeStack& env) { + expr_->CheckType(env); +} + +int IdExprNode::CodeGen() const { + /// @brief Plays the role of a "pointer". Its value has to be loaded to + /// the register before use. + int id_num = id_to_num.at(id_); + int reg_num = NextLocalNum(); + output << PrefixSigil(reg_num) << " =w loadw " << PrefixSigil(id_num) + << std::endl; + return reg_num; +} + +void IdExprNode::Dump(int pad) const { + std::cout << Pad(pad) << id_ << ": " << ExprTypeToCString(type) << std::endl; +} + +void IdExprNode::CheckType(ScopeStack& env) { + if (auto symbol = env.LookUp(id_)) { + type = symbol->expr_type; + } else { + // TODO: 'id_' undeclared + } +} + +int IntConstExprNode::CodeGen() const { + int num = NextLocalNum(); + output << PrefixSigil(num) << " =w copy " << val_ << std::endl; + return num; +} + +void IntConstExprNode::Dump(int pad) const { + std::cout << Pad(pad) << val_ << ": " << ExprTypeToCString(type) << std::endl; +} + +void IntConstExprNode::CheckType(ScopeStack& env) { + type = ExprType::kInt; +} + +int BinaryExprNode::CodeGen() const { + int left_num = lhs_->CodeGen(); + int right_num = rhs_->CodeGen(); + int num = NextLocalNum(); + output << PrefixSigil(num) << " =w " << OpName_() << " " + << PrefixSigil(left_num) << ", " << PrefixSigil(right_num) + << std::endl; + + return num; +} + +void BinaryExprNode::Dump(int pad) const { + std::cout << Pad(pad) << '(' << Op_() << std::endl; + lhs_->Dump(pad + 2); + rhs_->Dump(pad + 2); + std::cout << Pad(pad) << ')' << ": " << ExprTypeToCString(type) << std::endl; +} + +void BinaryExprNode::CheckType(ScopeStack& env) { + lhs_->CheckType(env); + rhs_->CheckType(env); + if (lhs_->type != rhs_->type) { + // TODO: invalid operands to binary + + } else { + type = lhs_->type; + } +} + +std::string PlusExprNode::OpName_() const { + return "add"; +} + +char PlusExprNode::Op_() const { + return '+'; +} + +std::string SubExprNode::OpName_() const { + return "sub"; +} + +char SubExprNode::Op_() const { + return '-'; +} + +std::string MulExprNode::OpName_() const { + return "mul"; +} + +char MulExprNode::Op_() const { + return '*'; +} + +std::string DivExprNode::OpName_() const { + return "div"; +} + +char DivExprNode::Op_() const { + return '/'; +} + +static const char* Pad(int n) { + if (n > 80) { + n = 80; + } else if (n < 0) { + n = 0; + } + return padding + (80 - n); +} diff --git a/ast.hpp b/ast.hpp index 16dd10ee..c28cc845 100644 --- a/ast.hpp +++ b/ast.hpp @@ -1,51 +1,14 @@ #ifndef AST_HPP_ #define AST_HPP_ -#include -#include -#include #include #include #include #include #include "scope.hpp" -#include "symbol.hpp" #include "type.hpp" -// clang-format off -// Not to format the padding to emphasize the actual length. - -// 80 spaces for padding 01234567890123456789012345678901234567890123456789012345678901234567890123456789 -static const char* padding = " "; - -// clang-format on - -/// @param n The length of the padding, saturated on the boundary of [0, 80]. -static const char* Pad(int n); - -/// @brief qbe intermediate file -extern std::ofstream output; - -/// @brief Returns the next local number and increment it by 1. The first number -/// will be 1. -static int NextLocalNum() { - /// @brief temporary index under a scope - static int next_local_num = 1; - return next_local_num++; -} - -/// @note Use this as the return local number if the it's not expected to be -/// used, e.g., `StmtNode`. -static const int kDummyLocalNum = -1; - -/// @brief Returns the function-scope temporary with sigil (`%`). -static std::string PrefixSigil(int local_num) { - return "%." + std::to_string(local_num); -} - -static std::map id_to_num{}; - /// @brief The most general base node of the Abstract Syntax Tree. /// @note This is an abstract class. class AstNode { @@ -73,46 +36,11 @@ class DeclNode : public AstNode { std::unique_ptr init = {}) : id_{id}, type_{decl_type}, init_{std::move(init)} {} - int CodeGen() const override { - int id_num = NextLocalNum(); - output << PrefixSigil(id_num) << " =l alloc4 4" << std::endl; - - if (init_) { - int init_num = init_->CodeGen(); - output << "storew " << PrefixSigil(init_num) << ", " - << PrefixSigil(id_num) << std::endl; - } - // Set up the number of the id so we know were to load it back. - id_to_num[id_] = id_num; - return kDummyLocalNum; - } - - void Dump(int pad) const override { - std::cout << Pad(pad) << '(' << id_ << ": " << ExprTypeToCString(type_); - if (init_) { - std::cout << " =" << std::endl; - init_->Dump(pad + 2); - } - std::cout << ')' << std::endl; - } - - void CheckType(ScopeStack& env) override { - if (init_) { - init_->CheckType(env); - if (init_->type != type_) { - // TODO: incompatible types when initializing type 'type_' using type - // 'init_->type' - } - } - - if (env.Probe(id_)) { - // TODO: redefinition of 'id_' - } else { - auto symbol = std::make_unique(id_); - symbol->expr_type = type_; - env.Add(std::move(symbol)); - } - } + int CodeGen() const override; + + void Dump(int pad) const override; + + void CheckType(ScopeStack& env) override; protected: std::string id_; @@ -127,37 +55,11 @@ class BlockStmtNode : public StmtNode { std::vector>&& stmts) : decls_{std::move(decls)}, stmts_{std::move(stmts)} {} - int CodeGen() const override { - output << "@start" << std::endl; - for (const auto& decl : decls_) { - decl->CodeGen(); - } - for (const auto& stmt : stmts_) { - stmt->CodeGen(); - } - - return kDummyLocalNum; - } - - void Dump(int pad) const override { - for (const auto& decl : decls_) { - decl->Dump(pad); - } - for (const auto& stmt : stmts_) { - stmt->Dump(pad); - } - } - - void CheckType(ScopeStack& env) override { - env.PushScope(); - for (auto& decl : decls_) { - decl->CheckType(env); - } - for (auto& stmt : stmts_) { - stmt->CheckType(env); - } - env.PopScope(); - } + int CodeGen() const override; + + void Dump(int pad) const override; + + void CheckType(ScopeStack& env) override; protected: std::vector> decls_; @@ -171,21 +73,11 @@ class ProgramNode : public AstNode { ProgramNode(std::unique_ptr block) : block_{std::move(block)} {} - int CodeGen() const override { - output << "export function w $main() {" << std::endl; - block_->CodeGen(); - output << "}"; - - return kDummyLocalNum; - } + int CodeGen() const override; - void Dump(int pad) const override { - block_->Dump(pad); - } + void Dump(int pad) const override; - void CheckType(ScopeStack& env) override { - block_->CheckType(env); - } + void CheckType(ScopeStack& env) override; protected: std::unique_ptr block_; @@ -193,41 +85,22 @@ class ProgramNode : public AstNode { class NullStmtNode : public StmtNode { public: - NullStmtNode() = default; - - int CodeGen() const override { - return kDummyLocalNum; - } + int CodeGen() const override; - void Dump(int pad) const override { - std::cout << Pad(pad) << "()" << std::endl; - } + void Dump(int pad) const override; - void CheckType(ScopeStack& env) override {} + void CheckType(ScopeStack& env) override; }; class ReturnStmtNode : public StmtNode { public: ReturnStmtNode(std::unique_ptr expr) : expr_{std::move(expr)} {} - int CodeGen() const override { - int ret_num = expr_->CodeGen(); - output << " ret " << PrefixSigil(ret_num) << std::endl; - return kDummyLocalNum; - } - - void Dump(int pad) const override { - std::cout << Pad(pad) << "(ret" << std::endl; - expr_->Dump(pad + 2); - std::cout << Pad(pad) << ')' << std::endl; - } - - void CheckType(ScopeStack& env) override { - expr_->CheckType(env); - if (expr_->type != ExprType::kInt) { - // TODO: return value type does not match the function type - } - } + int CodeGen() const override; + + void Dump(int pad) const override; + + void CheckType(ScopeStack& env) override; protected: std::unique_ptr expr_; @@ -239,19 +112,11 @@ class ExprStmtNode : public StmtNode { public: ExprStmtNode(std::unique_ptr expr) : expr_{std::move(expr)} {} - int CodeGen() const override { - expr_->CodeGen(); - - return kDummyLocalNum; - } + int CodeGen() const override; - void Dump(int pad) const override { - expr_->Dump(pad); - } + void Dump(int pad) const override; - void CheckType(ScopeStack& env) override { - expr_->CheckType(env); - } + void CheckType(ScopeStack& env) override; protected: std::unique_ptr expr_; @@ -261,28 +126,11 @@ class IdExprNode : public ExprNode { public: IdExprNode(const std::string& id) : id_{id} {} - int CodeGen() const override { - /// @brief Plays the role of a "pointer". Its value has to be loaded to - /// the register before use. - int id_num = id_to_num.at(id_); - int reg_num = NextLocalNum(); - output << PrefixSigil(reg_num) << " =w loadw " << PrefixSigil(id_num) - << std::endl; - return reg_num; - } - - void Dump(int pad) const override { - std::cout << Pad(pad) << id_ << ": " << ExprTypeToCString(type) - << std::endl; - } - - void CheckType(ScopeStack& env) override { - if (auto symbol = env.LookUp(id_)) { - type = symbol->expr_type; - } else { - // TODO: 'id_' undeclared - } - } + int CodeGen() const override; + + void Dump(int pad) const override; + + void CheckType(ScopeStack& env) override; protected: std::string id_; @@ -292,20 +140,11 @@ class IntConstExprNode : public ExprNode { public: IntConstExprNode(int val) : val_{val} {} - int CodeGen() const override { - int num = NextLocalNum(); - output << PrefixSigil(num) << " =w copy " << val_ << std::endl; - return num; - } + int CodeGen() const override; - void Dump(int pad) const override { - std::cout << Pad(pad) << val_ << ": " << ExprTypeToCString(type) - << std::endl; - } + void Dump(int pad) const override; - void CheckType(ScopeStack& env) override { - type = ExprType::kInt; - } + void CheckType(ScopeStack& env) override; protected: int val_; @@ -317,34 +156,11 @@ class BinaryExprNode : public ExprNode { BinaryExprNode(std::unique_ptr lhs, std::unique_ptr rhs) : lhs_{std::move(lhs)}, rhs_{std::move(rhs)} {} - int CodeGen() const override { - int left_num = lhs_->CodeGen(); - int right_num = rhs_->CodeGen(); - int num = NextLocalNum(); - output << PrefixSigil(num) << " =w " << OpName_() << " " - << PrefixSigil(left_num) << ", " << PrefixSigil(right_num) - << std::endl; - - return num; - } - - void Dump(int pad) const override { - std::cout << Pad(pad) << '(' << Op_() << std::endl; - lhs_->Dump(pad + 2); - rhs_->Dump(pad + 2); - std::cout << Pad(pad) << ')' << ": " << ExprTypeToCString(type) - << std::endl; - } - - void CheckType(ScopeStack& env) override { - lhs_->CheckType(env); - rhs_->CheckType(env); - if (lhs_->type != rhs_->type) { - // TODO: invalid operands to binary + - } else { - type = lhs_->type; - } - } + int CodeGen() const override; + + void Dump(int pad) const override; + + void CheckType(ScopeStack& env) override; protected: std::unique_ptr lhs_; @@ -360,61 +176,36 @@ class PlusExprNode : public BinaryExprNode { using BinaryExprNode::BinaryExprNode; protected: - std::string OpName_() const override { - return "add"; - } + std::string OpName_() const override; - char Op_() const override { - return '+'; - } + char Op_() const override; }; class SubExprNode : public BinaryExprNode { using BinaryExprNode::BinaryExprNode; protected: - std::string OpName_() const override { - return "sub"; - } + std::string OpName_() const override; - char Op_() const override { - return '-'; - } + char Op_() const override; }; class MulExprNode : public BinaryExprNode { using BinaryExprNode::BinaryExprNode; protected: - std::string OpName_() const override { - return "mul"; - } + std::string OpName_() const override; - char Op_() const override { - return '*'; - } + char Op_() const override; }; class DivExprNode : public BinaryExprNode { using BinaryExprNode::BinaryExprNode; protected: - std::string OpName_() const override { - return "div"; - } + std::string OpName_() const override; - char Op_() const override { - return '/'; - } + char Op_() const override; }; -static const char* Pad(int n) { - if (n > 80) { - n = 80; - } else if (n < 0) { - n = 0; - } - return padding + (80 - n); -} - #endif // AST_HPP_ diff --git a/symbol.cpp b/symbol.cpp new file mode 100644 index 00000000..1762fc54 --- /dev/null +++ b/symbol.cpp @@ -0,0 +1,22 @@ +#include "symbol.hpp" + +#include +#include +#include +#include + +std::shared_ptr SymbolTable::Add( + std::unique_ptr entry) { + const std::string& id = entry->id; // to reference id after moved + if (!Probe(id)) { + entries_.insert({id, std::shared_ptr{std::move(entry)}}); + } + return entries_.at(id); +} + +std::shared_ptr SymbolTable::Probe(const std::string& id) const { + if (entries_.count(id)) { + return entries_.at(id); + } + return nullptr; +} diff --git a/symbol.hpp b/symbol.hpp index 287cccd5..940650dd 100644 --- a/symbol.hpp +++ b/symbol.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "type.hpp" @@ -21,20 +20,9 @@ class SymbolTable { /// already in the table. /// @returns The added entry if the `id` of the `entry` isn't /// already in the table; otherwise, the original entry. - std::shared_ptr Add(std::unique_ptr entry) { - const std::string& id = entry->id; // to reference id after moved - if (!Probe(id)) { - entries_.insert({id, std::shared_ptr{std::move(entry)}}); - } - return entries_.at(id); - } - - std::shared_ptr Probe(const std::string& id) const { - if (entries_.count(id)) { - return entries_.at(id); - } - return nullptr; - } + std::shared_ptr Add(std::unique_ptr entry); + + std::shared_ptr Probe(const std::string& id) const; private: std::map> entries_{}; diff --git a/type.cpp b/type.cpp new file mode 100644 index 00000000..2420f303 --- /dev/null +++ b/type.cpp @@ -0,0 +1,11 @@ +#include "type.hpp" + +const char* ExprTypeToCString(ExprType type) { + switch (type) { + case ExprType::kInt: + return "int"; + case ExprType::kUnknown: + default: + return "unknown"; + } +} diff --git a/type.hpp b/type.hpp index 8005aa1d..6837b0a4 100644 --- a/type.hpp +++ b/type.hpp @@ -8,14 +8,6 @@ enum class ExprType { kInt, }; -// FIXME: multiple definition error without inline -inline const char* ExprTypeToCString(ExprType type) { - switch (type) { - case ExprType::kInt: - return "int"; - case ExprType::kUnknown: - default: - return "unknown"; - } -} +const char* ExprTypeToCString(ExprType type); + #endif // TYPE_HPP_ From fdcd06edc4ff1852555a9a96c3d43f163bde4654 Mon Sep 17 00:00:00 2001 From: Lai-YT <381xvmvbib@gmail.com> Date: Sun, 10 Sep 2023 18:35:56 +0800 Subject: [PATCH 3/4] Separate header placement See also: https://api.csswg.org/bikeshed/?force=1&url=https://raw.githubusercontent.com/vector-of-bool/pitchfork/develop/data/spec.bs#src.header-placement.separate --- Makefile | 2 +- ast.hpp => include/ast.hpp | 0 scope.hpp => include/scope.hpp | 0 symbol.hpp => include/symbol.hpp | 0 type.hpp => include/type.hpp | 0 ast.cpp => src/ast.cpp | 0 symbol.cpp => src/symbol.cpp | 0 type.cpp => src/type.cpp | 0 8 files changed, 1 insertion(+), 1 deletion(-) rename ast.hpp => include/ast.hpp (100%) rename scope.hpp => include/scope.hpp (100%) rename symbol.hpp => include/symbol.hpp (100%) rename type.hpp => include/type.hpp (100%) rename ast.cpp => src/ast.cpp (100%) rename symbol.cpp => src/symbol.cpp (100%) rename type.cpp => src/type.cpp (100%) diff --git a/Makefile b/Makefile index 04d6c2ee..9a866aef 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ TARGET := vitaminc CXX := g++ CC = $(CXX) -CXXFLAGS = -g3 -std=c++14 -Wall -MMD +CXXFLAGS = -g3 -std=c++14 -Wall -MMD -Iinclude CFLAGS = $(CXXFLAGS) LEX = lex # C++ features are used, yacc doesn't suffice diff --git a/ast.hpp b/include/ast.hpp similarity index 100% rename from ast.hpp rename to include/ast.hpp diff --git a/scope.hpp b/include/scope.hpp similarity index 100% rename from scope.hpp rename to include/scope.hpp diff --git a/symbol.hpp b/include/symbol.hpp similarity index 100% rename from symbol.hpp rename to include/symbol.hpp diff --git a/type.hpp b/include/type.hpp similarity index 100% rename from type.hpp rename to include/type.hpp diff --git a/ast.cpp b/src/ast.cpp similarity index 100% rename from ast.cpp rename to src/ast.cpp diff --git a/symbol.cpp b/src/symbol.cpp similarity index 100% rename from symbol.cpp rename to src/symbol.cpp diff --git a/type.cpp b/src/type.cpp similarity index 100% rename from type.cpp rename to src/type.cpp From c0e734367afe05762c6b87394c1b42a2f0dea2d6 Mon Sep 17 00:00:00 2001 From: Lai-YT <381xvmvbib@gmail.com> Date: Mon, 11 Sep 2023 09:08:12 +0800 Subject: [PATCH 4/4] Fix CI script calling remove in wrong directory --- scripts/install-cxxopts.sh | 3 ++- scripts/install-qbe.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/install-cxxopts.sh b/scripts/install-cxxopts.sh index 59c6f06d..09954452 100755 --- a/scripts/install-cxxopts.sh +++ b/scripts/install-cxxopts.sh @@ -5,4 +5,5 @@ wget https://github.com/jarro2783/cxxopts/archive/refs/tags/v3.1.1.tar.gz -O - | mkdir build/ && cmake -B build/ . && sudo make -C build/ install && - rm -rf cxxopts-3.1.1/ + cd .. && + rm -r cxxopts-3.1.1/ diff --git a/scripts/install-qbe.sh b/scripts/install-qbe.sh index b6105b5e..6edbd4e4 100755 --- a/scripts/install-qbe.sh +++ b/scripts/install-qbe.sh @@ -4,4 +4,5 @@ wget https://c9x.me/compile/release/qbe-1.1.tar.xz -O - | tar Jxf - && cd qbe-1.1/ && make && sudo make install && - rm -rf qbe-1.1/ + cd .. && + rm -r qbe-1.1/