[triton/ast] renamed ast -> lang in namespace and file structure
This commit is contained in:
@@ -6,8 +6,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|||||||
# FLEX/YACC
|
# FLEX/YACC
|
||||||
find_package(BISON)
|
find_package(BISON)
|
||||||
find_package(FLEX)
|
find_package(FLEX)
|
||||||
BISON_TARGET(Parser ${CMAKE_CURRENT_SOURCE_DIR}/include/triton/ast/parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
|
BISON_TARGET(Parser ${CMAKE_CURRENT_SOURCE_DIR}/include/triton/lang/parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
|
||||||
FLEX_TARGET(Lexer ${CMAKE_CURRENT_SOURCE_DIR}/include/triton/ast/scanner.l ${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp)
|
FLEX_TARGET(Lexer ${CMAKE_CURRENT_SOURCE_DIR}/include/triton/lang/scanner.l ${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp)
|
||||||
get_filename_component(BISON_Parser_INCLUDE_DIRECTORIES ${BISON_Parser_OUTPUT_HEADER} DIRECTORY)
|
get_filename_component(BISON_Parser_INCLUDE_DIRECTORIES ${BISON_Parser_OUTPUT_HEADER} DIRECTORY)
|
||||||
include_directories(${BISON_Parser_INCLUDE_DIRECTORIES})
|
include_directories(${BISON_Parser_INCLUDE_DIRECTORIES})
|
||||||
|
|
||||||
|
@@ -1,62 +0,0 @@
|
|||||||
#ifndef TRITON_INCLUDE_AST_ERROR_H
|
|
||||||
#define TRITON_INCLUDE_AST_ERROR_H
|
|
||||||
|
|
||||||
#include "ops.h"
|
|
||||||
#include "parser.hpp"
|
|
||||||
#include "node.h"
|
|
||||||
#include <cassert>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace triton{
|
|
||||||
|
|
||||||
|
|
||||||
namespace ir{
|
|
||||||
class function;
|
|
||||||
class value;
|
|
||||||
class type;
|
|
||||||
class builder;
|
|
||||||
class module;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ast{
|
|
||||||
|
|
||||||
class expression;
|
|
||||||
class pointer;
|
|
||||||
class identifier;
|
|
||||||
class constant;
|
|
||||||
class compound_statement;
|
|
||||||
class initializer;
|
|
||||||
class declaration_specifier;
|
|
||||||
class function;
|
|
||||||
|
|
||||||
/* Translation Unit */
|
|
||||||
class translation_unit: public node{
|
|
||||||
public:
|
|
||||||
translation_unit(node *item)
|
|
||||||
: decls_(item) { }
|
|
||||||
|
|
||||||
translation_unit *add(node *item) {
|
|
||||||
decls_.append(item);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
ir::value* codegen(ir::module * mod) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
list<node*> decls_;
|
|
||||||
};
|
|
||||||
|
|
||||||
void update_location(const char *t);
|
|
||||||
void print_error(const char *error);
|
|
||||||
char return_impl(char t, const char * yytext);
|
|
||||||
yytokentype return_impl(yytokentype t, const char * yytext);
|
|
||||||
void return_void(const char * yytext);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
class iteration_statement;
|
class iteration_statement;
|
||||||
class compound_statement;
|
class compound_statement;
|
||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
typedef std::map<std::string, global_value*> symbols_map_t;
|
typedef std::map<std::string, global_value*> symbols_map_t;
|
||||||
typedef std::vector<function*> functions_list_t;
|
typedef std::vector<function*> functions_list_t;
|
||||||
struct current_iteration_info_t{
|
struct current_iteration_info_t{
|
||||||
ast::iteration_statement *statement;
|
lang::iteration_statement *statement;
|
||||||
basic_block *block;
|
basic_block *block;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,12 +1,8 @@
|
|||||||
#ifndef TRITON_INCLUDE_AST_DECLARATION_H
|
#ifndef TRITON_INCLUDE_LANG_DECLARATION_H
|
||||||
#define TRITON_INCLUDE_AST_DECLARATION_H
|
#define TRITON_INCLUDE_LANG_DECLARATION_H
|
||||||
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "parser.hpp"
|
|
||||||
#include <cassert>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
@@ -20,7 +16,7 @@ namespace ir{
|
|||||||
class module;
|
class module;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
class expression;
|
class expression;
|
||||||
class pointer;
|
class pointer;
|
20
include/triton/lang/error.h
Normal file
20
include/triton/lang/error.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef TRITON_INCLUDE_LANG_ERROR_H
|
||||||
|
#define TRITON_INCLUDE_LANG_ERROR_H
|
||||||
|
|
||||||
|
#include "parser.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace triton{
|
||||||
|
namespace lang{
|
||||||
|
|
||||||
|
|
||||||
|
void update_location(const char *t);
|
||||||
|
void print_error(const char *error);
|
||||||
|
char return_impl(char t, const char * yytext);
|
||||||
|
yytokentype return_impl(yytokentype t, const char * yytext);
|
||||||
|
void return_void(const char * yytext);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@@ -1,8 +1,7 @@
|
|||||||
#ifndef TDL_INCLUDE_AST_EXPRESSION_H
|
#ifndef TDL_INCLUDE_LANG_EXPRESSION_H
|
||||||
#define TDL_INCLUDE_AST_EXPRESSION_H
|
#define TDL_INCLUDE_LANG_EXPRESSION_H
|
||||||
|
|
||||||
#include "parser.hpp"
|
#include "lang.h"
|
||||||
#include "ast.h"
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -20,7 +19,7 @@ namespace ir{
|
|||||||
class module;
|
class module;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
|
|
||||||
enum slice_enum_t{
|
enum slice_enum_t{
|
@@ -1,12 +1,13 @@
|
|||||||
#ifndef TRITON_INCLUDE_AST_AST_H
|
#ifndef TRITON_INCLUDE_LANG_LANG_H
|
||||||
#define TRITON_INCLUDE_AST_AST_H
|
#define TRITON_INCLUDE_LANG_LANG_H
|
||||||
|
|
||||||
#include "ops.h"
|
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
#include "declaration.h"
|
#include "declaration.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "expression.h"
|
#include "expression.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "ops.h"
|
#include "ops.h"
|
||||||
|
#include "module.h"
|
||||||
|
#include "statement.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -1,17 +1,10 @@
|
|||||||
#ifndef TRITON_INCLUDE_AST_MODULE_H
|
#ifndef TRITON_INCLUDE_LANG_MODULE_H
|
||||||
#define TRITON_INCLUDE_AST_MODULE_H
|
#define TRITON_INCLUDE_LANG_MODULE_H
|
||||||
|
|
||||||
#include "ops.h"
|
|
||||||
#include "parser.hpp"
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include <cassert>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
/* Translation Unit */
|
/* Translation Unit */
|
||||||
class translation_unit: public node{
|
class translation_unit: public node{
|
@@ -1,13 +1,8 @@
|
|||||||
#ifndef TRITON_INCLUDE_AST_NODE_H
|
#ifndef TRITON_INCLUDE_LANG_NODE_H
|
||||||
#define TRITON_INCLUDE_AST_NODE_H
|
#define TRITON_INCLUDE_LANG_NODE_H
|
||||||
|
|
||||||
#include "ops.h"
|
|
||||||
#include "parser.hpp"
|
|
||||||
#include <cassert>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include "ops.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
@@ -20,7 +15,7 @@ namespace ir{
|
|||||||
class module;
|
class module;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
class expression;
|
class expression;
|
||||||
class pointer;
|
class pointer;
|
@@ -1,14 +1,8 @@
|
|||||||
#ifndef TRITON_INCLUDE_AST_OPS_H
|
#ifndef TRITON_INCLUDE_LANG_OPS_H
|
||||||
#define TRITON_INCLUDE_AST_OPS_H
|
#define TRITON_INCLUDE_LANG_OPS_H
|
||||||
|
|
||||||
#include "parser.hpp"
|
|
||||||
#include <cassert>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
enum ASSIGN_OP_T{
|
enum ASSIGN_OP_T{
|
||||||
ASSIGN,
|
ASSIGN,
|
@@ -2,16 +2,13 @@
|
|||||||
|
|
||||||
%{
|
%{
|
||||||
namespace triton{
|
namespace triton{
|
||||||
namespace ast{
|
namespace lang{
|
||||||
class node;
|
class node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using namespace triton::ast;
|
using namespace triton::lang;
|
||||||
#define YYSTYPE node*
|
#define YYSTYPE node*
|
||||||
#include "../include/triton/ast/ast.h"
|
#include "../include/triton/lang/lang.h"
|
||||||
#include "../include/triton/ast/expression.h"
|
|
||||||
#include "../include/triton/ast/statement.h"
|
|
||||||
#include "../include/triton/ast/declaration.h"
|
|
||||||
|
|
||||||
extern char* yytext;
|
extern char* yytext;
|
||||||
void yyerror(const char *s);
|
void yyerror(const char *s);
|
||||||
@@ -150,8 +147,8 @@ primary_expression_list
|
|||||||
|
|
||||||
/* Postfix */
|
/* Postfix */
|
||||||
slice
|
slice
|
||||||
: ':' { $$ = new slice(triton::ast::ALL); }
|
: ':' { $$ = new slice(triton::lang::ALL); }
|
||||||
| NEWAXIS { $$ = new slice(triton::ast::NEWAXIS); }
|
| NEWAXIS { $$ = new slice(triton::lang::NEWAXIS); }
|
||||||
|
|
||||||
slice_list
|
slice_list
|
||||||
: slice { $$ = new list<slice*>((slice*)$1); }
|
: slice { $$ = new list<slice*>((slice*)$1); }
|
||||||
@@ -387,6 +384,15 @@ storage_class_specifier
|
|||||||
| CONSTANT_SPACE { $$ = new token(CONSTANT_SPACE_T); }
|
| CONSTANT_SPACE { $$ = new token(CONSTANT_SPACE_T); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
external_declaration
|
||||||
|
: function_definition { $$ = $1; }
|
||||||
|
| declaration { $$ = $1; }
|
||||||
|
;
|
||||||
|
|
||||||
|
function_definition
|
||||||
|
: declaration_specifiers declarator compound_statement { $$ = new function_definition($1, $2, $3); }
|
||||||
|
;
|
||||||
|
|
||||||
/* -------------------------- */
|
/* -------------------------- */
|
||||||
/* Translation Unit */
|
/* Translation Unit */
|
||||||
/* -------------------------- */
|
/* -------------------------- */
|
||||||
@@ -395,15 +401,7 @@ translation_unit
|
|||||||
: external_declaration { ast_root = new translation_unit($1); $$ = ast_root; }
|
: external_declaration { ast_root = new translation_unit($1); $$ = ast_root; }
|
||||||
| translation_unit external_declaration { $$ = ((translation_unit*)($1))->add($2); }
|
| translation_unit external_declaration { $$ = ((translation_unit*)($1))->add($2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
external_declaration
|
|
||||||
: function_definition { $$ = $1; }
|
|
||||||
| declaration { $$ = $1; }
|
|
||||||
;
|
|
||||||
|
|
||||||
function_definition
|
|
||||||
: declaration_specifiers declarator compound_statement { $$ = new function_definition($1, $2, $3); }
|
|
||||||
;
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
void yyerror (const char *s){
|
void yyerror (const char *s){
|
@@ -8,9 +8,9 @@ IS (u|U|l|L)*
|
|||||||
%{
|
%{
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
#include "../include/triton/ast/ast.h"
|
#include "../include/triton/lang/lang.h"
|
||||||
using triton::ast::return_impl;
|
using triton::lang::return_impl;
|
||||||
using triton::ast::return_void;
|
using triton::lang::return_void;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%
|
%%
|
@@ -1,13 +1,7 @@
|
|||||||
#ifndef TRITON_INCLUDE_AST_STATEMENT_H
|
#ifndef TRITON_INCLUDE_LANG_STATEMENT_H
|
||||||
#define TRITON_INCLUDE_AST_STATEMENT_H
|
#define TRITON_INCLUDE_LANG_STATEMENT_H
|
||||||
|
|
||||||
#include "parser.hpp"
|
|
||||||
#include "triton/ast/ast.h"
|
|
||||||
#include <cassert>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
#include "expression.h"
|
||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
@@ -20,7 +14,7 @@ namespace ir{
|
|||||||
class module;
|
class module;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
class declaration;
|
class declaration;
|
||||||
|
|
@@ -1,5 +1,5 @@
|
|||||||
#include "triton/ast/statement.h"
|
#include "triton/lang/statement.h"
|
||||||
#include "triton/ast/declaration.h"
|
#include "triton/lang/declaration.h"
|
||||||
#include "triton/ir/function.h"
|
#include "triton/ir/function.h"
|
||||||
#include "triton/ir/module.h"
|
#include "triton/ir/module.h"
|
||||||
#include "triton/ir/basic_block.h"
|
#include "triton/ir/basic_block.h"
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
/* Declaration specifier */
|
/* Declaration specifier */
|
||||||
ir::type* typed_declaration_specifier::type(ir::module *mod) const {
|
ir::type* typed_declaration_specifier::type(ir::module *mod) const {
|
@@ -1,9 +1,10 @@
|
|||||||
#include "triton/ast/error.h"
|
#include <iostream>
|
||||||
|
#include "triton/lang/error.h"
|
||||||
|
|
||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
static int current_line = 0;
|
static int current_line = 0;
|
||||||
static int current_column = 0;
|
static int current_column = 0;
|
@@ -1,5 +1,5 @@
|
|||||||
#include "triton/ast/expression.h"
|
#include "triton/lang/expression.h"
|
||||||
#include "triton/ast/declaration.h"
|
#include "triton/lang/declaration.h"
|
||||||
#include "triton/ir/constant.h"
|
#include "triton/ir/constant.h"
|
||||||
#include "triton/ir/module.h"
|
#include "triton/ir/module.h"
|
||||||
#include "triton/ir/builder.h"
|
#include "triton/ir/builder.h"
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
|
|
||||||
/* Binary operator */
|
/* Binary operator */
|
@@ -1,10 +1,10 @@
|
|||||||
#include "triton/ast/module.h"
|
#include "triton/lang/module.h"
|
||||||
#include "triton/ir/module.h"
|
#include "triton/ir/module.h"
|
||||||
|
|
||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
/* Translation unit */
|
/* Translation unit */
|
||||||
ir::value* translation_unit::codegen(ir::module *mod) const{
|
ir::value* translation_unit::codegen(ir::module *mod) const{
|
@@ -1,11 +1,11 @@
|
|||||||
#include "triton/ast/node.h"
|
#include "triton/lang/node.h"
|
||||||
#include "triton/ir/builder.h"
|
#include "triton/ir/builder.h"
|
||||||
#include "triton/ir/module.h"
|
#include "triton/ir/module.h"
|
||||||
#include "triton/ir/constant.h"
|
#include "triton/ir/constant.h"
|
||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
/* node */
|
/* node */
|
||||||
ir::value *node::explicit_cast(ir::builder &builder, ir::value *src, ir::type *dst_ty){
|
ir::value *node::explicit_cast(ir::builder &builder, ir::value *src, ir::type *dst_ty){
|
@@ -1,6 +1,6 @@
|
|||||||
#include "triton/ast/expression.h"
|
#include "triton/lang/expression.h"
|
||||||
#include "triton/ast/statement.h"
|
#include "triton/lang/statement.h"
|
||||||
#include "triton/ast/declaration.h"
|
#include "triton/lang/declaration.h"
|
||||||
#include "triton/ir/constant.h"
|
#include "triton/ir/constant.h"
|
||||||
#include "triton/ir/module.h"
|
#include "triton/ir/module.h"
|
||||||
#include "triton/ir/basic_block.h"
|
#include "triton/ir/basic_block.h"
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace triton{
|
namespace triton{
|
||||||
|
|
||||||
namespace ast{
|
namespace lang{
|
||||||
|
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
inline bool is_terminator(ir::value* x) {
|
inline bool is_terminator(ir::value* x) {
|
@@ -1,5 +1,5 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "triton/ast/ast.h"
|
#include "triton/lang/lang.h"
|
||||||
#include "triton/codegen/target.h"
|
#include "triton/codegen/target.h"
|
||||||
#include "triton/ir/context.h"
|
#include "triton/ir/context.h"
|
||||||
#include "triton/ir/context_impl.h"
|
#include "triton/ir/context_impl.h"
|
||||||
@@ -24,8 +24,7 @@ typedef struct yy_buffer_state * YY_BUFFER_STATE;
|
|||||||
extern int yyparse();
|
extern int yyparse();
|
||||||
extern YY_BUFFER_STATE yy_scan_string(const char * str);
|
extern YY_BUFFER_STATE yy_scan_string(const char * str);
|
||||||
extern void yy_delete_buffer(YY_BUFFER_STATE buffer);
|
extern void yy_delete_buffer(YY_BUFFER_STATE buffer);
|
||||||
using triton::ast::translation_unit;
|
extern triton::lang::translation_unit *ast_root;
|
||||||
extern translation_unit *ast_root;
|
|
||||||
|
|
||||||
namespace triton {
|
namespace triton {
|
||||||
|
|
||||||
@@ -84,7 +83,7 @@ std::unique_ptr<ir::module> jit::make_triton_module(const char *name, const char
|
|||||||
YY_BUFFER_STATE buffer = yy_scan_string(src);
|
YY_BUFFER_STATE buffer = yy_scan_string(src);
|
||||||
yyparse();
|
yyparse();
|
||||||
yy_delete_buffer(buffer);
|
yy_delete_buffer(buffer);
|
||||||
translation_unit *program = ast_root;
|
triton::lang::translation_unit *program = ast_root;
|
||||||
// create Triton-IR from AST
|
// create Triton-IR from AST
|
||||||
ir::module* module = new ir::module(name, triton_context_);
|
ir::module* module = new ir::module(name, triton_context_);
|
||||||
program->codegen(module);
|
program->codegen(module);
|
||||||
|
Reference in New Issue
Block a user