TDL [codegen]: improving class structure
This commit is contained in:
@@ -6,6 +6,12 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
namespace llvm{
|
||||
|
||||
class LLVMType;
|
||||
|
||||
}
|
||||
|
||||
namespace tdl{
|
||||
|
||||
class module;
|
||||
@@ -197,7 +203,8 @@ class no_op: public statement { };
|
||||
|
||||
// Types
|
||||
class declarator: public node{
|
||||
|
||||
public:
|
||||
virtual llvm::LLVMType llvm_type(TYPE_T spec) const = 0;
|
||||
};
|
||||
|
||||
class pointer_declarator: public declarator{
|
||||
@@ -210,35 +217,33 @@ public:
|
||||
return this;
|
||||
}
|
||||
|
||||
llvm::LLVMType llvm_type(TYPE_T spec) const;
|
||||
|
||||
private:
|
||||
unsigned order_;
|
||||
};
|
||||
|
||||
class tile_declarator: public declarator{
|
||||
public:
|
||||
tile_declarator(node *shapes)
|
||||
: shapes_((list<constant*>*)(shapes)) { }
|
||||
tile_declarator(node *decl, node *shapes)
|
||||
: decl_(decl), shapes_((list<constant*>*)(shapes)) { }
|
||||
|
||||
llvm::LLVMType llvm_type(TYPE_T spec) const;
|
||||
|
||||
public:
|
||||
const node* decl_;
|
||||
const list<constant*>* shapes_;
|
||||
};
|
||||
|
||||
class parameter: public declarator {
|
||||
public:
|
||||
parameter(TYPE_T spec, node *decl)
|
||||
: spec_(spec), decl_(decl) { }
|
||||
|
||||
public:
|
||||
const TYPE_T spec_;
|
||||
const node *decl_;
|
||||
};
|
||||
|
||||
class function_declarator: public declarator{
|
||||
public:
|
||||
function_declarator(node *args)
|
||||
: args_((list<node*>*)args) { }
|
||||
function_declarator(node *decl, node *args)
|
||||
: decl_(decl), args_((list<node*>*)args) { }
|
||||
|
||||
llvm::LLVMType llvm_type(TYPE_T spec) const;
|
||||
|
||||
public:
|
||||
const node* decl_;
|
||||
const list<node*>* args_;
|
||||
};
|
||||
|
||||
@@ -247,6 +252,8 @@ public:
|
||||
compound_declarator(node *ptr, node *tile)
|
||||
: ptr_(ptr), tile_(tile) { }
|
||||
|
||||
llvm::LLVMType llvm_type(TYPE_T spec) const;
|
||||
|
||||
public:
|
||||
const node *ptr_;
|
||||
const node *tile_;
|
||||
@@ -257,11 +264,24 @@ public:
|
||||
init_declarator(node *decl, node *initializer)
|
||||
: decl_(decl), initializer_(initializer){ }
|
||||
|
||||
llvm::LLVMType llvm_type(TYPE_T spec) const;
|
||||
|
||||
public:
|
||||
const node *decl_;
|
||||
const node *initializer_;
|
||||
};
|
||||
|
||||
class parameter: public node {
|
||||
public:
|
||||
parameter(TYPE_T spec, node *decl)
|
||||
: spec_(spec), decl_(decl) { }
|
||||
|
||||
llvm::LLVMType* llvm_type() const;
|
||||
|
||||
public:
|
||||
const TYPE_T spec_;
|
||||
const node *decl_;
|
||||
};
|
||||
|
||||
class type: public node{
|
||||
public:
|
||||
@@ -276,10 +296,11 @@ public:
|
||||
/* Function definition */
|
||||
class function_definition: public node{
|
||||
public:
|
||||
function_definition(node *header, node *body)
|
||||
: header_((function_declarator *)header), body_((compound_statement*)body) { }
|
||||
function_definition(TYPE_T spec, node *header, node *body)
|
||||
: spec_(spec), header_((function_declarator *)header), body_((compound_statement*)body) { }
|
||||
|
||||
public:
|
||||
const TYPE_T spec_;
|
||||
const function_declarator *header_;
|
||||
const compound_statement *body_;
|
||||
};
|
||||
|
@@ -84,7 +84,7 @@ abstract_declarator
|
||||
;
|
||||
|
||||
direct_abstract_declarator
|
||||
: '[' constant_list ']' { $$ = new tile_declarator($1); }
|
||||
: '[' constant_list ']' { $$ = new tile_declarator(nullptr, $1); }
|
||||
|
||||
constant :
|
||||
CONSTANT { $$ = new constant(atoi(yytext)); }
|
||||
@@ -279,16 +279,11 @@ iteration_statement
|
||||
|
||||
direct_declarator
|
||||
: identifier { $$ = $1; }
|
||||
| direct_declarator '[' constant_list ']' { $$ = new tile_declarator($2); }
|
||||
| direct_declarator '(' parameter_list ')' { $$ = new function_declarator($2); }
|
||||
| direct_declarator '(' identifier_list ')' { $$ = new function_declarator($2); }
|
||||
| direct_declarator '(' ')' { $$ = new function_declarator(nullptr); }
|
||||
| identifier '[' constant_list ']' { $$ = new tile_declarator($1, $2); }
|
||||
| identifier '(' parameter_list ')' { $$ = new function_declarator($1, $2); }
|
||||
| identifier '(' ')' { $$ = new function_declarator($1, nullptr); }
|
||||
;
|
||||
|
||||
identifier_list
|
||||
: identifier { $$ = new list<identifier*>((identifier*)$1); }
|
||||
| identifier_list ',' identifier { $$ = append_ptr_list<identifier>($1, $2); }
|
||||
;
|
||||
|
||||
parameter_list
|
||||
: parameter_declaration { $$ = new list<parameter*>((parameter*)$1); }
|
||||
@@ -298,7 +293,6 @@ parameter_list
|
||||
parameter_declaration
|
||||
: declaration_specifiers declarator { $$ = new parameter(get_type_spec($1), $2); }
|
||||
| declaration_specifiers abstract_declarator { $$ = new parameter(get_type_spec($1), $2); }
|
||||
| declaration_specifiers { $$ = new parameter(get_type_spec($1), nullptr); }
|
||||
;
|
||||
|
||||
|
||||
@@ -346,7 +340,6 @@ external_declaration
|
||||
;
|
||||
|
||||
function_definition
|
||||
: declaration_specifiers declarator compound_statement
|
||||
| declarator compound_statement { $$ = new function_definition($1, $2); }
|
||||
: type_specifier declarator compound_statement { $$ = new function_definition(get_type_spec($1), $2, $3); }
|
||||
;
|
||||
|
||||
|
@@ -1,4 +1,3 @@
|
||||
#include "codegen.h"
|
||||
#include "ast.h"
|
||||
|
||||
namespace tdl{
|
||||
|
Reference in New Issue
Block a user