Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ jobs:
steps:
- uses: actions/checkout@v5

- name: Get updated LLVM
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22

- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format
run: |
sudo apt-get install -y clang-format-22
sudo ln -sf $(which clang-format-22) /usr/local/bin/clang-format

- name: Check formatting
run: |
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ Currently PANNICC supports the following subset of C:
- Pointers (just int***... for now)
- Comments

Refer to the grammar in [parser.cpp](https://github.com/Golf0ned/PANNICC/blob/main/src/frontend/parser.cpp) for more specifics.
Refer to the grammar in [the parser](https://github.com/Golf0ned/PANNICC/tree/main/src/frontend/parser) for more specifics.

## Installation/Usage

This section assumes you are working in a unix environment.

Clone the repo:

```
Expand All @@ -36,12 +38,21 @@ To build and run tests, run:
make
```

To add to path, run:
```
source enable
```

To view the help message, run:

```
./build/bin/pannicc
pannicc
```

When writing programs for PANNICC, there are a few things to note:
- The subset of C supported is very limited (see [Language Support](https://github.com/Golf0ned/PANNICC/tree/main#language-support))
- Since the C standard library uses a lot of features not yet supported by PANNICC, use the [runtime library](https://github.com/Golf0ned/PANNICC/blob/main/include/runtime.h) instead.

## Contributing

The best way to support this project is by [sponsoring me](https://github.com/sponsors/Golf0ned).
Expand Down
2 changes: 2 additions & 0 deletions src/backend/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "backend/passes/legalize.h"

namespace backend {

void CodeGenVisitor::generateFilePreamble() { result += " .text"; }

void CodeGenVisitor::generateFilePostamble() {
Expand Down Expand Up @@ -49,4 +50,5 @@ std::string generateCode(lir::Program &lir) {

return cgv.getResult();
}

} // namespace backend
2 changes: 2 additions & 0 deletions src/backend/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "backend/lir/lir.h"

namespace backend {

class CodeGenVisitor : public lir::ToStringVisitor {
public:
void generateFilePreamble();
Expand All @@ -14,4 +15,5 @@ class CodeGenVisitor : public lir::ToStringVisitor {
};

std::string generateCode(lir::Program &lir);

} // namespace backend
6 changes: 4 additions & 2 deletions src/backend/lir/condition_code.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <utility>

#include "backend/lir/condition_code.h"

#include <utility>

namespace backend::lir {

ConditionCode invert(ConditionCode cc) {
switch (cc) {
case ConditionCode::EQ:
Expand All @@ -22,4 +23,5 @@ std::string toString(ConditionCode cc) {
}
std::unreachable();
}

} // namespace backend::lir
3 changes: 2 additions & 1 deletion src/backend/lir/condition_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#include <string>

namespace backend::lir {

enum class ConditionCode {
EQ,
NEQ,
};

ConditionCode invert(ConditionCode cc);

std::string toString(ConditionCode cc);

} // namespace backend::lir
6 changes: 4 additions & 2 deletions src/backend/lir/data_size.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <utility>

#include "backend/lir/data_size.h"

#include <utility>

namespace backend::lir {

char toChar(Extend extend) {
switch (extend) {
case Extend::NONE:
Expand Down Expand Up @@ -39,4 +40,5 @@ char toChar(DataSize size) {
}
std::unreachable();
}

} // namespace backend::lir
3 changes: 2 additions & 1 deletion src/backend/lir/data_size.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "middleend/mir/type.h"

namespace backend::lir {

enum class Extend {
NONE,
ZERO,
Expand All @@ -19,6 +20,6 @@ enum class DataSize {
};

DataSize fromMir(middleend::mir::Type type);

char toChar(DataSize size);

} // namespace backend::lir
6 changes: 4 additions & 2 deletions src/backend/lir/instruction.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <utility>

#include "backend/lir/instruction.h"

#include <utility>

namespace backend::lir {

Label::Label(std::string name) : name(name) {}

std::string Label::getName() { return name; }
Expand Down Expand Up @@ -206,4 +207,5 @@ void InstructionCall::accept(InstructionVisitor *v) { v->visit(this); }
void InstructionRet::accept(InstructionVisitor *v) { v->visit(this); }

void InstructionUnknown::accept(InstructionVisitor *v) { v->visit(this); }

} // namespace backend::lir
4 changes: 2 additions & 2 deletions src/backend/lir/instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "middleend/mir/operator.h"

namespace backend::lir {

class InstructionVisitor;

class Instruction {
Expand Down Expand Up @@ -97,7 +98,6 @@ enum class BinaryOp {
};

BinaryOp fromMir(middleend::mir::BinaryOp op);

std::string toString(BinaryOp op);

// TODO: div, inc, dec, neg, not
Expand Down Expand Up @@ -211,7 +211,6 @@ class InstructionRet : public Instruction {
void accept(InstructionVisitor *v) override;
};

// TODO: remove once tiling's implemented
class InstructionUnknown : public Instruction {
public:
void accept(InstructionVisitor *v) override;
Expand All @@ -235,4 +234,5 @@ class InstructionVisitor {
virtual void visit(InstructionRet *i) = 0;
virtual void visit(InstructionUnknown *i) = 0;
};

} // namespace backend::lir
2 changes: 2 additions & 0 deletions src/backend/lir/lir.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "backend/lir/lir.h"

namespace backend::lir {

Function::Function(std::string name, uint64_t num_params, uint64_t stack_bytes,
std::list<std::unique_ptr<Instruction>> instructions)
: name(name), num_params(num_params), stack_bytes(stack_bytes),
Expand Down Expand Up @@ -177,4 +178,5 @@ void ToStringVisitor::visit(InstructionUnknown *i) {
result += "\n ";
result += "unknown";
}

} // namespace backend::lir
6 changes: 4 additions & 2 deletions src/backend/lir/lir.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once

#include "backend/lir/instruction.h"

#include <list>
#include <memory>

#include "backend/lir/instruction.h"

namespace backend::lir {

class Function {
public:
Function(std::string name, uint64_t num_params, uint64_t stack_bytes,
Expand Down Expand Up @@ -60,4 +61,5 @@ class ToStringVisitor : public InstructionVisitor {
protected:
std::string result;
};

} // namespace backend::lir
6 changes: 4 additions & 2 deletions src/backend/lir/operand.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <stdexcept>

#include "backend/lir/operand.h"

#include <stdexcept>

namespace backend::lir {

static uint64_t cur_id = 0;

Immediate::Immediate(uint64_t value) : value(value) {}
Expand Down Expand Up @@ -140,4 +141,5 @@ StackArg *OperandManager::getStackArg(uint64_t arg_num) {
stack_args.insert({arg_num, std::make_unique<StackArg>(arg_num)});
return stack_args.at(arg_num).get();
}

} // namespace backend::lir
6 changes: 4 additions & 2 deletions src/backend/lir/operand.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once

#include "backend/lir/register_num.h"

#include <cstdint>
#include <memory>
#include <string>
#include <unordered_map>

#include "backend/lir/register_num.h"

namespace backend::lir {

class Operand {
public:
virtual std::string toString() = 0;
Expand Down Expand Up @@ -108,4 +109,5 @@ class OperandManager {
std::vector<std::unique_ptr<Address>> addresses;
std::unordered_map<uint64_t, std::unique_ptr<StackArg>> stack_args;
};

} // namespace backend::lir
6 changes: 4 additions & 2 deletions src/backend/lir/register_num.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <utility>

#include "backend/lir/register_num.h"

#include <utility>

namespace backend::lir {

DataSize getSize(RegisterNum rn) {
switch (rn) {
case RegisterNum::RAX:
Expand Down Expand Up @@ -331,4 +332,5 @@ const std::vector<RegisterNum> &getColoringPriority() {
};
return coloring_priority;
}

} // namespace backend::lir
8 changes: 4 additions & 4 deletions src/backend/lir/register_num.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <vector>

#include "backend/lir/data_size.h"

#include <vector>

namespace backend::lir {

enum class RegisterNum {
VIRTUAL,

Expand Down Expand Up @@ -46,14 +47,13 @@ enum class RegisterNum {
};

DataSize getSize(RegisterNum rn);

RegisterNum toSized(RegisterNum rn, DataSize size);

std::string toString(RegisterNum rn);

const std::vector<RegisterNum> &getAllRegisters();
const std::vector<RegisterNum> &getArgRegisters();
const std::vector<RegisterNum> &getCalleeSavedRegisters();
const std::vector<RegisterNum> &getCallerSavedRegisters();
const std::vector<RegisterNum> &getColoringPriority();

} // namespace backend::lir
2 changes: 2 additions & 0 deletions src/backend/lir_tree/function_info.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "function_info.h"

namespace backend::lir_tree {

FunctionInfo::FunctionInfo(std::string name, uint64_t num_params)
: name(name), num_params(num_params), stack_bytes(0) {}

Expand All @@ -16,4 +17,5 @@ uint64_t FunctionInfo::allocate(uint64_t num_bytes) {
stack_bytes += num_bytes;
return offset;
}

} // namespace backend::lir_tree
2 changes: 2 additions & 0 deletions src/backend/lir_tree/function_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>

namespace backend::lir_tree {

class FunctionInfo {
public:
FunctionInfo(std::string name, uint64_t num_params);
Expand All @@ -17,4 +18,5 @@ class FunctionInfo {
uint64_t num_params;
uint64_t stack_bytes;
};

} // namespace backend::lir_tree
8 changes: 5 additions & 3 deletions src/backend/lir_tree/gen_trees.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <unordered_set>

#include "backend/lir_tree/gen_trees.h"
#include "backend/lir/data_size.h"
#include "backend/lir/operand.h"
#include "backend/lir_tree/gen_trees.h"

#include <unordered_set>

namespace backend::lir_tree {

TreeGenVisitor::TreeGenVisitor(middleend::mir::Program &p,
lir::OperandManager *om)
: next_block(nullptr), om(om), tree_info(std::make_unique<TreeInfo>()) {
Expand Down Expand Up @@ -371,4 +372,5 @@ void TreeGenVisitor::visit(middleend::mir::TerminatorCondBranch *t) {
auto assembly = std::make_unique<AsmNode>(std::move(instructions));
function_trees.push_back(std::move(assembly));
}

} // namespace backend::lir_tree
1 change: 1 addition & 0 deletions src/backend/lir_tree/gen_trees.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ class TreeGenVisitor : public middleend::mir::InstructionVisitor {
std::vector<std::unique_ptr<FunctionInfo>> all_function_info;
std::unique_ptr<TreeInfo> tree_info;
};

} // namespace backend::lir_tree
Loading