Skip to content
Open
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
3 changes: 3 additions & 0 deletions .clang-format-include
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/**/*
lib/env_args.cpp
lib/env_args.h
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ General programming language for low-level performant program.
- `src/kapuc/{lex,parse}.{c,h}` for syntax/parser
- (TODO) `src/kapu/` for the main package manager/build system
- Before making pr, make sure
- You run `clang-format` with all of the files you modified (or simpler, ```git clang-format --staged``` for staged changes)
- You run `clang-format` with all of the files you modified (or simpler, ```git clang-format --staged``` for staged changes or ```ninja -C build clang-format``` for full project)
- You make sure the build is successful
- (TODO) check clang-tidy with `clang-tidy --warnings-as-errors=* ./src/kapuc/*.{c,h} ./lib/env_args.{cpp,h}`

Expand Down
2 changes: 1 addition & 1 deletion compile_commands.json
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ log_headers = files('lib/log.h')
env_args_sources = files('lib/env_args.cpp')
env_args_headers = files('lib/env_args.h')

kapuc_sources = files('src/kapuc/helper.h', 'src/kapuc/lex.c', 'src/kapuc/lex.h', 'src/kapuc/main.c', 'src/kapuc/parse.c', 'src/kapuc/parse.h')
kapuc_sources = files('src/kapuc/helper.h', 'src/kapuc/lex.c', 'src/kapuc/lex.h', 'src/kapuc/main.c', 'src/kapuc/parse.c', 'src/kapuc/parse.h', 'src/kapuc/analyzer/analysis.c', 'src/kapuc/analyzer/analysis.h', 'src/kapuc/analyzer/scope_analysis.h', 'src/kapuc/PIR/generator.c', 'src/kapuc/PIR/generator.h', 'src/kapuc/PIR/compiler.c', 'src/kapuc/PIR/compiler.h', 'src/kapuc/PIR/PIR.h')

# Define the libraries
sds_lib = static_library('sds', sds_sources, include_directories: include_directories('.'))
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [meson llvmPackages_17.libllvm ninja];
nativeBuildInputs = with pkgs; [meson llvmPackages_17.libllvm clang-tools_17 ninja];
}
176 changes: 176 additions & 0 deletions src/kapuc/PIR/PIR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#include "lib/sds.h"

#include <stdbool.h>
#include <stdint.h>

#ifndef PIR_H
#define PIR_H

enum expr_type
{
// operation (all are non-checked operation on LLVM)
// TODO: add flag to change this
Add,
Mul,
Del,
Div,
Func_val,
Val,
};

typedef struct
{
bool is_default_type;
bool is_ptr;
union
{
uint8_t
default_type; // 0: int8, 1: int16, 2: int32, 3: int64, 4: bool (int1)
// FIXME: add type trail for custom type
};
} typing;

typedef struct
{
typing t;
union
{
int int__val;
// FIXME: add value for custom type (struct, etc)
};
} val;

typedef struct expr_
{
enum expr_type t;
union
{
struct
{
struct expr_* lhs;
struct expr_* rhs;
} b;
val v;
size_t func_val;
};
} expr;

#define T expr
void
expr_free(T* v);
T
expr_copy(T* v);
#include "lib/ctl/vec.h"
#undef T

struct assignment
{
int id;
expr e;
};

typedef enum
{
assignment,
ret,
call,
ic,
} stmt_type;

typedef struct
{
size_t call_ids; // the main_blocks index
vec_expr value;
} call_expr;

typedef struct
{
int jmp_case;
int jmp_result;
} int_case;

#define T int_case
void
int_case_free(T*);
T
int_case_copy(T*);
#include "lib/ctl/vec.h"

typedef struct
{
expr to_switch;
vec_int_case ics;
} int_switch;

typedef struct
{
stmt_type t;
union
{
struct assignment assignment;
expr ret_val;
call_expr call_ca;
int_switch ics;
};
} stmt;
#define T stmt
void
stmt_free(T*);
T
stmt_copy(T*);
#include "lib/ctl/vec.h"

typedef typing FUNC_VAR;
#define T FUNC_VAR
void
FUNC_VAR_free(T*);
T
FUNC_VAR_copy(T*);
#include "lib/ctl/vec.h"

typedef vec_stmt BLOCK;
#define T BLOCK
void
BLOCK_free(T*);
T
BLOCK_copy(T*);
#include "lib/ctl/vec.h"

struct FUNC
{
sds name;
vec_FUNC_VAR vv;
vec_BLOCK bs;
typing t;
bool is_external;
bool is_variadic;
};

typedef enum
{
func
} main_type;

typedef struct
{
main_type type;
union
{
struct FUNC func;
};
} MAIN_BLOCK;

#define T MAIN_BLOCK
void
MAIN_BLOCK_free(T*);
T
MAIN_BLOCK_copy(T*);
#include "lib/ctl/vec.h"

// entire PIR for the file generation
struct PIR
{
vec_MAIN_BLOCK main_blocks;
};

#endif
Loading