Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zfx_script #405

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
166de9e
test zfx_script
sonicyouth98 Apr 27, 2022
7176db4
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 Apr 28, 2022
849cfc4
test2
sonicyouth98 Apr 28, 2022
e6b9850
test Lex
sonicyouth98 Apr 29, 2022
b711402
creat A test Project PiLeiFX
sonicyouth98 May 3, 2022
504ba12
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 May 4, 2022
7b10758
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 May 6, 2022
8d8cd0f
PiLeiFX
sonicyouth98 May 7, 2022
7e560ca
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 May 7, 2022
4f3eb6c
fix Lexical
sonicyouth98 May 8, 2022
302a043
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 May 9, 2022
9b91d72
continue cihou zfx
sonicyouth98 May 10, 2022
ab089e6
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 May 10, 2022
34354ba
cihouzfx
sonicyouth98 May 10, 2022
ea06fde
cihou ast parser
sonicyouth98 May 11, 2022
aff7d76
fix immature symbol table
sonicyouth98 May 12, 2022
063ef38
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 May 16, 2022
f2c0abc
want to add ctx Module
sonicyouth98 May 16, 2022
a29cb91
Merge branch 'zfx_script' of https://github.com/sonicyouth98/zeno int…
sonicyouth98 May 16, 2022
3da4fe7
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 May 23, 2022
36e90b0
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 May 24, 2022
844d323
next needs to be IRBuilder and some basic optimization
sonicyouth98 May 26, 2022
febc3d0
change code structure
sonicyouth98 May 31, 2022
54d5957
Merge branch 'zenustech:master' into zfx_script
sonicyouth98 Jun 7, 2022
eaf06e7
continue
sonicyouth98 Jun 11, 2022
10fcb91
add numericeval
sonicyouth98 Jun 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions projects/PiLeiFX/ZenoFX/Ast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// Created by admin on 2022/5/6.
//

#pragma once

#include "Lexical.h"
#include "Location.h"
#include <iostream>
#include <memory>
#include <string>
#include <any>
#include <memory>
#include <vector>
namespace zfx {

enum VarType {
Symbol,
Parameter
};

enum Op {

};
class AstVisitor {

};

class AstNode {
public:
Position beginPos;
Position endPos;
virtual void dump() = 0;
virtual std::any accept(AstVisitor &visitor, std::string additional = "") = 0;
virtual ~AstNode();
};
//语句
class Statement: AstNode {

};
//声明,子类为$ @
class Decl :public AstNode {
public:
VarType varType;//变量类型
std::string name;//变量名称
expilic Decl(VarType varType) : varType (varType) {

}
};

class VariableDecl : public Decl {
//变量类型
//变量初始化的形式,
public:
VarType varType;
//std::shared_ptr<AstNode> init;//变量初始化的语句
explicit VariableDecl(VarType varType , const std::string& name) : Decl(varType), name(name) {

}
std::any accept(AstVisitor& visitor) {

}

void dump(std::string prefix) {

}
};

class Statement : public AstNode {

};

class Expression:public AstNode {
public:
std::any constValue;//本表达式的常量值,用作后面的常量折叠等分析
};

class ExpressionStatement : public Statement {
public:
std::shared_ptr<AstNode> exp;


};
/*
* 二元表达式
* */
class Binary {
public:
Op op;
//左边表达式
//右边表达式
Binary() {

}

std::any accept(AstVisitor& visitor, const std::string &additional) {

}
};

class Unary {
public:
Op op;
//表达式
Unary() {

}

std::any accept(AstVisitor& visitor, const std::string &additional) {

}
};

}

40 changes: 40 additions & 0 deletions projects/PiLeiFX/ZenoFX/CodeGen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Created by admin on 2022/5/11.
//

#pragma once
#include <memory>
#include <map>
/*
* This class is an interface to complete a codegen in the Statement class
* */
namespace zfx {
Value* BinaryExprAst::codegen() {
if (op == '=') {
VariableExprAst* LHSE = static_cast<>
if (!LHSE) {
std::cout << "destination of '=' must be" << std::endl;

}
Value* Val = RHS->codegen();
if (!Val) {
return nullptr;
}
}
}

static AllocaInst *createEntryBlock(Function* function, std::string& VarName) {

}

Value* NumberExprAst::codegen() {

}

Value* UnaryExprAst::codegen() {
Value* OperandV = Operand->codegen();
if (!OperandV) {
return nullptr;
}
}
}
24 changes: 24 additions & 0 deletions projects/PiLeiFX/ZenoFX/ControlCheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by admin on 2022/5/14.
//

#include "Ast.h
#include <map>
#include <functional>
/*
* 这里我们用了一个最简单的bool 栈来判断if else 结构语句是否匹配成功
*
* */
namespace zfx {
struct ControlCheck {
using visit_emit_types = std::tuple<>;

void visit() {

}
};

void apply_control_check() {

}
}
13 changes: 13 additions & 0 deletions projects/PiLeiFX/ZenoFX/EmitAssembler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Created by admin on 2022/5/12.
//

#include <sstream>

namespace zfx {
struct EmitAssembly {

std::stringstream oss;

};
}
32 changes: 32 additions & 0 deletions projects/PiLeiFX/ZenoFX/Error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by admin on 2022/5/30.
//
#pragma once

#include <string>
namespace zfx {
struct Position{
uint32_t begin;
uint32_t end;
uint32_t line;
uint32_t col;

Position(){}
Position(uint32_t begin, uint32_t end, uint32_t line, uint32_t col) : begin(begin),
end(end), line(line), col(col) {

}

Position(const Position &rhs) {
this->begin = rhs.begin;
this->end = rhs.end;
this->line = rhs.line;
this->col = rhs.col;
}

std::string ToString() {
return "ln" + std::to_string(this->line) + ", col" + std::to_string(this->col) +
", Pos:" + std::to_string(this->pos);
}
};
}
45 changes: 45 additions & 0 deletions projects/PiLeiFX/ZenoFX/IR/BasicBlock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Created by admin on 2022/5/27.
//

#include "Module.h"
#include <list>
#include <set>
#include <string>
#include <vector>


namespace zfx {
class BasicBlock {
public:
static BasicBlock *create(Module *m, const std::string& name) {

return new BasicBlock(m, name);
}

BasicBlock(const BasicBlock& ) = delete;
BasicBlock& operator=(const BasicBlock&) = delete;
const Module* getModule() const {

}

Module* getModule() {

}

virtual std::string print() override;


//api for cfg
std::list<BasicBlock *> &get_pre_basic_blocks() {

}

//选一个迭代器遍历一遍
private:
explicit BasicBlock(Module *m, const std::string &name);
std::list<BasicBlock *> pre_bbs;
std::list<BasicBlock *> succ_bbs;

};
}
5 changes: 5 additions & 0 deletions projects/PiLeiFX/ZenoFX/IR/IR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by admin on 2022/6/13.
//
#include "IR.h

37 changes: 37 additions & 0 deletions projects/PiLeiFX/ZenoFX/IR/IR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Created by admin on 2022/5/7.
//
#pragma once
#include<memory>
#include <vector>
#include <unordered_set>
#include <unordered_map>
/*
* zfx中statement就相当于一条一条的Instruction
* */

namespace zfx {
class Stmt ;

class IRNode {
public:

virtual IRNode* get_parent() const = 0;

virtual IRNode* get_ir_root();

virtual ~IRNode() = default;

//获取一个编译选项,表示怎么处理IR
//
std::unique_ptr<IRNode> clone();//克隆IRNode节点
};
class Statement {
protected:
std::vector<>
};

class IRVisitor {

};
}
31 changes: 31 additions & 0 deletions projects/PiLeiFX/ZenoFX/IR/IRBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by admin on 2022/6/7.
//

#pragma once

#include "./BasicBlock.h"
#include "./Instruction.h"

namespace zfx {
class IRBuilder {
public:
IRBuilder() = default;
IRBuilder(BasicBlock *bb) : bb(bb) {}

void reset() ;
//把所有的指令清空

inline BasicBlock *getInsertBlock() {
return bb;
}

void setInsertPoint(BasicBlock *bb) const {
this->bb = bb;
}

//接下来是创建指令
private:
BasicBlock *bb;
};
}
Loading