[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
|
||||
find_package(BISON)
|
||||
find_package(FLEX)
|
||||
BISON_TARGET(Parser ${CMAKE_CURRENT_SOURCE_DIR}/include/triton/ast/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)
|
||||
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/lang/scanner.l ${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp)
|
||||
get_filename_component(BISON_Parser_INCLUDE_DIRECTORIES ${BISON_Parser_OUTPUT_HEADER} DIRECTORY)
|
||||
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 ast{
|
||||
namespace lang{
|
||||
|
||||
class iteration_statement;
|
||||
class compound_statement;
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
typedef std::map<std::string, global_value*> symbols_map_t;
|
||||
typedef std::vector<function*> functions_list_t;
|
||||
struct current_iteration_info_t{
|
||||
ast::iteration_statement *statement;
|
||||
lang::iteration_statement *statement;
|
||||
basic_block *block;
|
||||
};
|
||||
|
||||
|
@@ -1,12 +1,8 @@
|
||||
#ifndef TRITON_INCLUDE_AST_DECLARATION_H
|
||||
#define TRITON_INCLUDE_AST_DECLARATION_H
|
||||
#ifndef TRITON_INCLUDE_LANG_DECLARATION_H
|
||||
#define TRITON_INCLUDE_LANG_DECLARATION_H
|
||||
|
||||
#include "node.h"
|
||||
#include "parser.hpp"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace triton{
|
||||
@@ -20,7 +16,7 @@ namespace ir{
|
||||
class module;
|
||||
}
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
class expression;
|
||||
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
|
||||
#define TDL_INCLUDE_AST_EXPRESSION_H
|
||||
#ifndef TDL_INCLUDE_LANG_EXPRESSION_H
|
||||
#define TDL_INCLUDE_LANG_EXPRESSION_H
|
||||
|
||||
#include "parser.hpp"
|
||||
#include "ast.h"
|
||||
#include "lang.h"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -20,7 +19,7 @@ namespace ir{
|
||||
class module;
|
||||
}
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
|
||||
enum slice_enum_t{
|
@@ -1,12 +1,13 @@
|
||||
#ifndef TRITON_INCLUDE_AST_AST_H
|
||||
#define TRITON_INCLUDE_AST_AST_H
|
||||
#ifndef TRITON_INCLUDE_LANG_LANG_H
|
||||
#define TRITON_INCLUDE_LANG_LANG_H
|
||||
|
||||
#include "ops.h"
|
||||
#include "parser.hpp"
|
||||
#include "declaration.h"
|
||||
#include "error.h"
|
||||
#include "expression.h"
|
||||
#include "node.h"
|
||||
#include "ops.h"
|
||||
#include "module.h"
|
||||
#include "statement.h"
|
||||
|
||||
#endif
|
@@ -1,17 +1,10 @@
|
||||
#ifndef TRITON_INCLUDE_AST_MODULE_H
|
||||
#define TRITON_INCLUDE_AST_MODULE_H
|
||||
#ifndef TRITON_INCLUDE_LANG_MODULE_H
|
||||
#define TRITON_INCLUDE_LANG_MODULE_H
|
||||
|
||||
#include "ops.h"
|
||||
#include "parser.hpp"
|
||||
#include "node.h"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace triton{
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
/* Translation Unit */
|
||||
class translation_unit: public node{
|
@@ -1,13 +1,8 @@
|
||||
#ifndef TRITON_INCLUDE_AST_NODE_H
|
||||
#define TRITON_INCLUDE_AST_NODE_H
|
||||
#ifndef TRITON_INCLUDE_LANG_NODE_H
|
||||
#define TRITON_INCLUDE_LANG_NODE_H
|
||||
|
||||
#include "ops.h"
|
||||
#include "parser.hpp"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "ops.h"
|
||||
|
||||
namespace triton{
|
||||
|
||||
@@ -20,7 +15,7 @@ namespace ir{
|
||||
class module;
|
||||
}
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
class expression;
|
||||
class pointer;
|
@@ -1,14 +1,8 @@
|
||||
#ifndef TRITON_INCLUDE_AST_OPS_H
|
||||
#define TRITON_INCLUDE_AST_OPS_H
|
||||
|
||||
#include "parser.hpp"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#ifndef TRITON_INCLUDE_LANG_OPS_H
|
||||
#define TRITON_INCLUDE_LANG_OPS_H
|
||||
|
||||
namespace triton{
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
enum ASSIGN_OP_T{
|
||||
ASSIGN,
|
@@ -2,16 +2,13 @@
|
||||
|
||||
%{
|
||||
namespace triton{
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
class node;
|
||||
}
|
||||
}
|
||||
using namespace triton::ast;
|
||||
using namespace triton::lang;
|
||||
#define YYSTYPE node*
|
||||
#include "../include/triton/ast/ast.h"
|
||||
#include "../include/triton/ast/expression.h"
|
||||
#include "../include/triton/ast/statement.h"
|
||||
#include "../include/triton/ast/declaration.h"
|
||||
#include "../include/triton/lang/lang.h"
|
||||
|
||||
extern char* yytext;
|
||||
void yyerror(const char *s);
|
||||
@@ -150,8 +147,8 @@ primary_expression_list
|
||||
|
||||
/* Postfix */
|
||||
slice
|
||||
: ':' { $$ = new slice(triton::ast::ALL); }
|
||||
| NEWAXIS { $$ = new slice(triton::ast::NEWAXIS); }
|
||||
: ':' { $$ = new slice(triton::lang::ALL); }
|
||||
| NEWAXIS { $$ = new slice(triton::lang::NEWAXIS); }
|
||||
|
||||
slice_list
|
||||
: slice { $$ = new list<slice*>((slice*)$1); }
|
||||
@@ -387,6 +384,15 @@ storage_class_specifier
|
||||
| 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 */
|
||||
/* -------------------------- */
|
||||
@@ -395,15 +401,7 @@ translation_unit
|
||||
: external_declaration { ast_root = new translation_unit($1); $$ = ast_root; }
|
||||
| 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){
|
@@ -8,9 +8,9 @@ IS (u|U|l|L)*
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#include "parser.hpp"
|
||||
#include "../include/triton/ast/ast.h"
|
||||
using triton::ast::return_impl;
|
||||
using triton::ast::return_void;
|
||||
#include "../include/triton/lang/lang.h"
|
||||
using triton::lang::return_impl;
|
||||
using triton::lang::return_void;
|
||||
%}
|
||||
|
||||
%%
|
@@ -1,13 +1,7 @@
|
||||
#ifndef TRITON_INCLUDE_AST_STATEMENT_H
|
||||
#define TRITON_INCLUDE_AST_STATEMENT_H
|
||||
|
||||
#include "parser.hpp"
|
||||
#include "triton/ast/ast.h"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#ifndef TRITON_INCLUDE_LANG_STATEMENT_H
|
||||
#define TRITON_INCLUDE_LANG_STATEMENT_H
|
||||
|
||||
#include "expression.h"
|
||||
|
||||
namespace triton{
|
||||
|
||||
@@ -20,7 +14,7 @@ namespace ir{
|
||||
class module;
|
||||
}
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
class declaration;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include "triton/ast/statement.h"
|
||||
#include "triton/ast/declaration.h"
|
||||
#include "triton/lang/statement.h"
|
||||
#include "triton/lang/declaration.h"
|
||||
#include "triton/ir/function.h"
|
||||
#include "triton/ir/module.h"
|
||||
#include "triton/ir/basic_block.h"
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace triton{
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
/* Declaration specifier */
|
||||
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 ast{
|
||||
namespace lang{
|
||||
|
||||
static int current_line = 0;
|
||||
static int current_column = 0;
|
@@ -1,5 +1,5 @@
|
||||
#include "triton/ast/expression.h"
|
||||
#include "triton/ast/declaration.h"
|
||||
#include "triton/lang/expression.h"
|
||||
#include "triton/lang/declaration.h"
|
||||
#include "triton/ir/constant.h"
|
||||
#include "triton/ir/module.h"
|
||||
#include "triton/ir/builder.h"
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace triton{
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
|
||||
/* Binary operator */
|
@@ -1,10 +1,10 @@
|
||||
#include "triton/ast/module.h"
|
||||
#include "triton/lang/module.h"
|
||||
#include "triton/ir/module.h"
|
||||
|
||||
|
||||
namespace triton{
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
/* Translation unit */
|
||||
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/module.h"
|
||||
#include "triton/ir/constant.h"
|
||||
|
||||
namespace triton{
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
/* node */
|
||||
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/ast/statement.h"
|
||||
#include "triton/ast/declaration.h"
|
||||
#include "triton/lang/expression.h"
|
||||
#include "triton/lang/statement.h"
|
||||
#include "triton/lang/declaration.h"
|
||||
#include "triton/ir/constant.h"
|
||||
#include "triton/ir/module.h"
|
||||
#include "triton/ir/basic_block.h"
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace triton{
|
||||
|
||||
namespace ast{
|
||||
namespace lang{
|
||||
|
||||
/* Helpers */
|
||||
inline bool is_terminator(ir::value* x) {
|
@@ -1,5 +1,5 @@
|
||||
#include <string>
|
||||
#include "triton/ast/ast.h"
|
||||
#include "triton/lang/lang.h"
|
||||
#include "triton/codegen/target.h"
|
||||
#include "triton/ir/context.h"
|
||||
#include "triton/ir/context_impl.h"
|
||||
@@ -24,8 +24,7 @@ typedef struct yy_buffer_state * YY_BUFFER_STATE;
|
||||
extern int yyparse();
|
||||
extern YY_BUFFER_STATE yy_scan_string(const char * str);
|
||||
extern void yy_delete_buffer(YY_BUFFER_STATE buffer);
|
||||
using triton::ast::translation_unit;
|
||||
extern translation_unit *ast_root;
|
||||
extern triton::lang::translation_unit *ast_root;
|
||||
|
||||
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);
|
||||
yyparse();
|
||||
yy_delete_buffer(buffer);
|
||||
translation_unit *program = ast_root;
|
||||
triton::lang::translation_unit *program = ast_root;
|
||||
// create Triton-IR from AST
|
||||
ir::module* module = new ir::module(name, triton_context_);
|
||||
program->codegen(module);
|
||||
|
Reference in New Issue
Block a user