Skip to content

Commit

Permalink
feat: add more statements (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
diohabara authored Jul 26, 2023
1 parent fcc625f commit 4cbd6ca
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 83 deletions.
55 changes: 55 additions & 0 deletions .gdb_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
run test
b main
run test
n
b gen
run test
c
n
s
q
r test
b main
r test
n
n
r
n
r
m
n
s
n
b function
r
c
n
s
n
b stmt
c
r
c
c
r
c
n
i
s
n
b stmt
r test
n
s cur
p cur
p sc
p *cur
n
p parse.c::cur
p 'parse.c'::cur
n
r
n
c
n
n
33 changes: 25 additions & 8 deletions ccc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef struct Var Var;
struct Var {
char *name; // Variable name
Type *ty; // Type
Token *tok; // for error message
bool is_local; // local or global
// local variable
int offset; // Offset from RBP
Expand Down Expand Up @@ -84,6 +85,12 @@ typedef enum {
ND_WHILE, // "while"
ND_FOR, // "for"
ND_BLOCK, // { ... }
ND_BREAK, // "break"
ND_CONTINUE, // "continue"
ND_GOTO, // "goto"
ND_LABEL, // Labeled statement
ND_SWITCH, // "switch"
ND_CASE, // "case"
ND_FUNCALL, // Function call
ND_EXPR_STMT, // Expression statement
ND_STMT_EXPR, // statement expression
Expand Down Expand Up @@ -132,6 +139,13 @@ struct Node {
// Function call
char *funcname;
Node *args;
// Goto or labeled statement
char *label_name;
// switch-cases
Node *case_next;
Node *default_case;
int case_label;
int case_end_label;
Var *var; // Used if kind == ND_VAR
long val; // Used if kind == ND_NUM
// Struct member access
Expand Down Expand Up @@ -173,19 +187,21 @@ typedef enum {
} TypeKind;
struct Type {
TypeKind kind;
bool is_typedef; // typedef
bool is_static; // static
int align; // alignment
Type *base; // pointer or array
int array_size; // array
Member *members; // struct
Type *return_ty; // function
bool is_typedef; // typedef
bool is_static; // static
bool is_incomplete; // incomplete array
int align; // alignment
Type *base; // pointer or array
int array_size; // array
Member *members; // struct
Type *return_ty; // function
};

// Struct member
struct Member {
Member *next;
Type *ty;
Token *tok;
char *name;
int offset;
};
Expand All @@ -197,10 +213,11 @@ Type *short_type();
Type *int_type();
Type *long_type();
Type *enum_type();
Type *struct_type();
Type *func_type(Type *return_ty);
Type *pointer_to(Type *base);
Type *array_of(Type *base, int size);
int size_of(Type *ty);
int size_of(Type *ty, Token *tok);
void add_type(Program *prog);

//
Expand Down
Loading

0 comments on commit 4cbd6ca

Please sign in to comment.