├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── bliss.cpp ├── doc ├── bliss-article.pdf ├── bliss.xml ├── bliss2.xml ├── blsalphai64dif.md ├── blsalphai64dif.mem ├── blslref.pdf ├── blsvaxalphadif.md └── blsvaxalphadif.mem ├── include └── bliss │ ├── AST │ ├── AttributeAST.h │ ├── BaseAST.h │ ├── BindingAST.h │ ├── BlockAST.h │ ├── CompileTimeAST.h │ ├── ConditionHandlingAST.h │ ├── ConstantAST.h │ ├── ControlAST.h │ ├── DataAST.h │ ├── DeclarationAST.h │ ├── ExecutableFuncAST.h │ ├── ExprAST.h │ ├── IncludeAST.h │ ├── LexicalAST.h │ ├── LinkageAST.h │ ├── MacroAST.h │ ├── ModuleAST.h │ ├── OperatorAST.h │ ├── PrimaryAST.h │ ├── RoutineAST.h │ ├── SpecialAST.h │ └── StructureAST.h │ ├── Basic │ ├── CommonInclude.h │ ├── FileManager.h │ ├── InputChar.h │ ├── InputFile.h │ └── Lister.h │ ├── Driver │ └── Driver.h │ └── FrontEnd │ ├── Keyword.h │ ├── Lexer.h │ └── Parser.h ├── lib ├── Basic │ ├── CMakeLists.txt │ ├── FileManager.cpp │ └── InputFile.cpp ├── Driver │ ├── CMakeLists.txt │ └── Driver.cpp └── FrontEnd │ ├── CMakeLists.txt │ ├── Lexer.cpp │ └── Parser.cpp ├── nbproject ├── configurations.xml ├── private │ ├── c_standard_headers_indexer.c │ ├── configurations.xml │ ├── cpp_standard_headers_indexer.cpp │ ├── launcher.properties │ └── private.xml └── project.xml └── tests ├── AST └── module_test_01.b64 ├── expression ├── controlexp.bli ├── operators.bli └── structures.bli ├── lexical ├── lexfuncs1.bli ├── lexfuncs2.bli ├── literals.bli ├── macros.bli └── names.bli ├── runtests.py ├── testharness.c └── testharness.req /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/c++ 3 | # Edit at https://www.gitignore.io/?templates=c++ 4 | 5 | ### C++ ### 6 | # Prerequisites 7 | *.d 8 | 9 | # Compiled Object files 10 | *.slo 11 | *.lo 12 | *.o 13 | *.obj 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Compiled Dynamic libraries 20 | *.so 21 | *.dylib 22 | *.dll 23 | 24 | # Fortran module files 25 | *.mod 26 | *.smod 27 | 28 | # Compiled Static libraries 29 | *.lai 30 | *.la 31 | *.a 32 | *.lib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | 39 | # End of https://www.gitignore.io/api/c++ 40 | build/ 41 | 42 | # Netbeans project folder 43 | nbproject/ 44 | 45 | /doc/blsalphai64dif.pdf 46 | /doc/blsvaxalphadif.pdf 47 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.10) 2 | 3 | set(CMAKE_C_COMPILER clang) 4 | set(CMAKE_CXX_COMPILER clang++) 5 | 6 | project (bliss) 7 | 8 | set(CMAKE_CXX_FLAGS "-g -O0 -std=c++11") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE") 10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS") 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS") 12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_LIMIT_MACROS") 13 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${${CMAKE_PROJECT_NAME}_SOURCE_DIR}/include/bliss") 14 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/lib/llvm-8/include") 15 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") 16 | 17 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/lib/llvm-8/lib -lLLVM-8") 18 | 19 | add_subdirectory(lib/Basic) 20 | add_subdirectory(lib/FrontEnd) 21 | add_subdirectory(lib/Driver) 22 | 23 | add_executable(bliss bliss.cpp) 24 | 25 | add_dependencies(bliss 26 | Driver 27 | Basic 28 | FrontEnd 29 | ) 30 | 31 | target_link_libraries(bliss 32 | Driver 33 | Basic 34 | FrontEnd 35 | ) 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | README for the BLISS-LLVM Compiler 2 | ================================== 3 | 4 | This is the source package for the BLISS compiler, a portable 5 | cross-compiler for the BLISS programming language. 6 | Visit the [project website](http://github.com/JonathanBelanger/blisscpp) 7 | for more information about BLISS. 8 | 9 | Why a BLISS compiler 10 | -------------------- 11 | 12 | There are a number of reasons why I wanted to write a BLISS compiler. The 13 | top ones are: 14 | 15 | * When I worked at DEC on the IBM Interconnect product set, the OpenVMS versions 16 | of these products, all 14 of them, were written in BLISS. 17 | * I also wrote and SDL compiler, OpenSDL, that will eventually generate BLISS 18 | REQUIRE output files, and I wanted a way to be able to test them. 19 | * I love the BLISS way of defining MACROs. The fact that a MACRO can refer to 20 | itself, as well as other MACROs and vice versa, is incredibly powerful. 21 | * I have never written a compiler before and was recently introduced to LLVM, 22 | so it seems like a good place to start. 23 | 24 | Available BLISS compilers 25 | ------------------------- 26 | 27 | There are a few BLISS compilers out there: 28 | 29 | 1. The original, which only runs on OpenVMS (VAX, Alpha, and IA64), [OpenVMS Freeware CD V8.0](https://www.digiater.nl/openvms/freeware/v80/bliss/) 30 | 2. A FreeVMS Portable BLISS for GCC - ftp://freevms.nvg.org/pub/vms/freevms/bliss 31 | 3. One implemented by VMS Sofware - [VSI June 2019 OpenVMS Roadmap](http://vmssoftware.com/pdfs/VSI_Roadmap_20190722.pdf)). 32 | 4. One written by Matt Madison [The BLISS-M Compiler Project](http://madisongh.github.io/blissc) 33 | 34 | Current Status 35 | -------------- 36 | 37 | Work in progress. This is, in effect, a re-implementation of the BLISS-M compiler 38 | project for more information. BLISS-M was written in C and to LLVM 3.9-5.0. This 39 | implementation will be written in C++ and to LLVM 8.0-9.0 (and possibly 10.0) and 40 | support any available LLVM enhancements. 41 | 42 | Prerequisites 43 | ------------- 44 | 45 | Known to build Ubuntu 19.04 and later (64-bit). 46 | 47 | The code generator uses LLVM 8.0, 9.0 or 10.0, which you can download 48 | directly from llvm.org. On Ubuntu systems, you can install one 49 | of the llvm-dev packages using apt. 50 | 51 | The build system uses CMake 3.13 or later. 52 | 53 | Building the compiler 54 | --------------------- 55 | 56 | 1. Clone [the repository](https://github.com/JonathanBelanger/blisscpp.git). 57 | 2. cd to the top-level source directory and create a build directory. 58 | 3. cd to your build directory. 59 | 4. Run `cmake ..`. 60 | 5. Run `make` to build the compiler. 61 | 6. Run `make check` to test the built compiler. 62 | 63 | 64 | Running the compiler 65 | -------------------- 66 | 67 | The build will produce a program called **bliss** in your build 68 | directory. Run `./bliss --help` for a description of the arguments 69 | and options. 70 | 71 | 72 | Contributions 73 | ------------- 74 | 75 | There is a lot more yet to do on this project! If you are interested 76 | in contributing, contact me (JonathanBelanger on GitHub, or by e-mail at 77 | jbelanger _at_ rochester _dot_ rr _dot_ com). 78 | 79 | License 80 | ------- 81 | All sources are released under the GPL 3.0 license. See the 82 | [LICENSE](https://github.com/JonathanBelanger/blisscpp/blob/master/LICENSE) 83 | file for the license text. 84 | -------------------------------------------------------------------------------- /bliss.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: Reader.cpp 20 | * Author: Jonathan D. Belanger 21 | * 22 | * V01.000 Jonathan D. Belanger August 31, 2019, 3:02 PM 23 | * Initially created. 24 | * 25 | * V01.001 Jonathan D. Belanger September 1, 2019, 1:55 PM 26 | * Introduced the following classes: 27 | * InputChar - contains information about a single character, including 28 | * its character class. 29 | * InputFile - contains the code to read a single character from a file 30 | * and return it back to the caller. Also, handles character 31 | * classification and end of file detection. 32 | * FileManager - contains the code to be able to open multiple files and 33 | * close them in the reverse order in which they were opened. 34 | * The next step will be to move these into their own include and module 35 | * files. 36 | */ 37 | #include "Driver/Driver.h" 38 | 39 | using namespace std; 40 | using namespace bliss; 41 | 42 | Driver *Driver::driver = nullptr; 43 | 44 | /* 45 | * This function is called to test the input file processing and character 46 | * classification code. 47 | */ 48 | int main(int argc, char** argv) 49 | { 50 | Driver *driver = Driver::get(); 51 | vector files = {"/home/belanger/projects/bliss/tests/AST/module_test_01.b64"}; 52 | 53 | if (driver->setFiles(&files) == true) 54 | { 55 | driver->mainLoop(); 56 | } 57 | 58 | #if 0 59 | if (fileMgr->pushFile("/home/belanger/projects/bliss/tests/lexical/lexfuncs1.bli") == 60 | true) 61 | { 62 | while(lex->getNext()) 63 | { 64 | switch(lex->getType()) 65 | { 66 | case Lexer::LTUnknown: 67 | cout << "Got an unknown Lexeme:\n" << 68 | " c: " << lex->getChar() << "\n" << 69 | " string: " << lex->getString() << "\n" << 70 | " value: " << lex->getValue() << "\n"; 71 | break; 72 | 73 | case Lexer::LTKeyword: 74 | cout << "Got a keyword:\n" << 75 | " keyword: " << lex->getKeyword() << "\n" << 76 | " reserved: " << (lex->getReserved() ? "True\n" : "False\n") << 77 | " string: " << lex->getString() << "\n"; 78 | break; 79 | 80 | case Lexer::LTPredeclared: 81 | cout << "Got a predeclared keyword:\n" << 82 | " keyword: " << lex->getKeyword() << "\n" << 83 | " reserved: " << (lex->getReserved() ? "True\n" : "False\n") << 84 | " string: " << lex->getString() << "\n"; 85 | break; 86 | 87 | case Lexer::LTExplicitDeclared: 88 | cout << "Got an explicit declared keyword:\n" << 89 | " keyword: " << lex->getKeyword() << "\n" << 90 | " reserved: " << (lex->getReserved() ? "True\n" : "False\n") << 91 | " string: " << lex->getString() << "\n"; 92 | break; 93 | 94 | case Lexer::LTDecimalLiteral: 95 | cout << "Got a decimal literal:\n" << 96 | " value: " << lex->getValue() << "\n"; 97 | break; 98 | 99 | case Lexer::LTQuotedString: 100 | cout << "Got a quoted string:\n" << 101 | " value: " << lex->getString() << "\n"; 102 | break; 103 | 104 | case Lexer::LTOperator: 105 | cout << "Got an operator:\n" << 106 | " char: " << lex->getChar() << "\n"; 107 | break; 108 | 109 | case Lexer::LTPunctuation: 110 | cout << "Got a punctuation:\n" << 111 | " char: " << lex->getChar() << "\n"; 112 | break; 113 | 114 | case Lexer::LTLinemark: 115 | cout << "Got a line mark:\n"; 116 | break; 117 | 118 | case Lexer::LTTrailingComment: 119 | cout << "Got a trailing comment:\n" << 120 | " string: " << lex->getString() << "\n"; 121 | break; 122 | 123 | case Lexer::LTEmbeddedComment: 124 | cout << "Got a embedded comment:\n" << 125 | " string: " << lex->getString() << "\n"; 126 | break; 127 | 128 | case Lexer::LTPercentSign: 129 | cout << "Got a percent sign:\n" << 130 | " char: " << lex->getChar() << "\n"; 131 | break; 132 | } 133 | } 134 | fileMgr->popFile(); 135 | } 136 | #endif 137 | return 0; 138 | } 139 | -------------------------------------------------------------------------------- /doc/bliss-article.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JonathanBelanger/bliss/8ec1007fb4a4f5c815c9f7a7997e2aa9aeb684b0/doc/bliss-article.pdf -------------------------------------------------------------------------------- /doc/blslref.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JonathanBelanger/bliss/8ec1007fb4a4f5c815c9f7a7997e2aa9aeb684b0/doc/blslref.pdf -------------------------------------------------------------------------------- /include/bliss/AST/BaseAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: BaseAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 21, 2019, 3:43 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_BASEAST_H 26 | #define LLVM_BLISS_BASEAST_H 27 | 28 | using namespace std; 29 | 30 | namespace bliss 31 | { 32 | 33 | /* 34 | * This structure is to hold the starting and ending line and column 35 | * information associated with a particular AST node. 36 | */ 37 | typedef struct 38 | { 39 | uint32_t startLine; 40 | uint32_t startColumn; 41 | uint32_t endLine; 42 | uint32_t endColumn; 43 | } SourceLocation; 44 | 45 | /* 46 | * These structures define the various layouts of the descriptor structure. 47 | * The first one is the 32-bit version of the descriptor, and is used when 48 | * compiling for a 32-bit operating system. The second one is the 64-bit 49 | * version, and is used when compiling for a 64-bit operating system. 50 | */ 51 | typedef struct 52 | { 53 | uint16_t dsc_l_length; 54 | uint8_t dsc_w_type; 55 | uint8_t dsc_w_class; 56 | uint32_t dsc_a_pointer; 57 | } DSC32_DESCRIPTOR; 58 | typedef struct 59 | { 60 | uint32_t dsc_l_length; 61 | uint16_t dsc_w_dtype; 62 | uint16_t dsc_w_class; 63 | uint64_t dsc_a_pointer; 64 | } DSC64_DESCRIPTOR; 65 | 66 | /* 67 | * BaseAST - Base class for all other Abstract Syntax Tree classes (ASTs). 68 | */ 69 | class BaseAST 70 | { 71 | public: 72 | virtual ~BaseAST() {} 73 | 74 | /* 75 | * This function is called to return the line and column number ranges 76 | * associated with this AST node. 77 | * 78 | * @return - a pointer to a structure containing the starting/ending 79 | * line/column numbers associated with the current AST node. 80 | */ 81 | SourceLocation *getLocation() { return &Loc; } 82 | 83 | private: 84 | SourceLocation Loc; 85 | }; 86 | } 87 | 88 | #endif /* LLVM_BLISS_BASEAST_H */ 89 | -------------------------------------------------------------------------------- /include/bliss/AST/BindingAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: BindingAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 3:30 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_BINDINGAST_H 26 | #define LLVM_BLISS_BINDINGAST_H 27 | 28 | #include "AST/AttributeAST.h" 29 | #include "AST/DeclarationAST.h" 30 | #include "AST/ExprAST.h" 31 | 32 | using namespace std; 33 | 34 | namespace bliss 35 | { 36 | 37 | /* 38 | * +- literal-declaration 39 | * bound-declaration -+ external-literal-declaration 40 | * | bind-data-declaration 41 | * +- bind-routine-declaration 42 | */ 43 | class BindDeclAST : public DeclarationASt 44 | { 45 | }; 46 | 47 | /* 48 | * literal-declaration -+- LITERAL --------+- literal-item, ...; 49 | * +- GLOBAL LITERAL -+ 50 | * 51 | * literal-item --- literal-name = literal-value -+- : literal-attribute... 52 | * +- nothing 53 | * 54 | * literal-name --- name 55 | * 56 | * literal-value --- compile-time-constant-expression 57 | * 58 | * literal-attribute -+- range-attribute 59 | * +- weak-attribute 60 | * 61 | * Predeclared Literals 62 | * 63 | * ------- ------ ------ ---------------------------------- 64 | * 32-bit 64-bit 65 | * Name Value Value Significance 66 | * ------- ------ ------ ---------------------------------- 67 | * %BPVAL 32 64 Bits per BLISS value (fullword) 68 | * %BPUNIT 8 8 Bits per smallest addressable unit 69 | * %BPADDR 32 64 Bits per address value 70 | * %UPVAL 4 8 Addressable units per BLISS value 71 | * (%BPVAL / %BPUNIT) 72 | * ------- ------ ------ ---------------------------------- 73 | */ 74 | class LiteralDeclAST : public BindDeclAST 75 | { 76 | }; 77 | 78 | /* 79 | * external-literal-declaration --- EXTERNAL LITERAL external-literal-item, ...; 80 | * 81 | * external-literal-item --- literal-name -+- : literal-attribute 82 | * +- nothing 83 | */ 84 | class ExternLiteralDeclAST : public BindDeclAST 85 | { 86 | }; 87 | 88 | /* 89 | * bind-data-declaration -+- BIND -+- bind-data-item, ...; 90 | * 91 | * bind-data-item --- bind-data-name = data-name-value -+- : bind-data-attribute... 92 | * +- nothing 93 | * 94 | * bind-data-name --- name 95 | * 96 | * bind-data-value --- expression 97 | * 98 | * +- allocation-unit 99 | * | extension-attribute 100 | * bind-data-attribute -+ structure-attribute 101 | * | field-attribute 102 | * | volatile-attribute 103 | * +- weak-attribute 104 | */ 105 | class BindDataDeclAST : public BindDeclAST 106 | { 107 | }; 108 | 109 | /* 110 | * bind-routine-declaration -+- BIND ROUTINE --------+- bind-routine-item, ...; 111 | * +- GLOBAL BIND ROUTINE -+ 112 | * 113 | * bind-routine-item --- bind-routine-name = routine-name-value -+- : bind-routine-attribute... 114 | * +- nothing 115 | * 116 | * bind-routine-name --- name 117 | * 118 | * routine-name-value --- expression 119 | * 120 | * +- novalue-attribute 121 | * bind-routine-attribute -+ linkage-attribute 122 | * +- weak-attribute 123 | */ 124 | class BindRoutineDeclAST : public BindDeclAST 125 | { 126 | }; 127 | } 128 | 129 | #endif /* LLVM_BLISS_BINDINGAST_H */ 130 | -------------------------------------------------------------------------------- /include/bliss/AST/BlockAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: BlockAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 21, 2019, 5:00 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_BLOCKAST_H 26 | #define LLVM_BLISS_BLOCKAST_H 27 | 28 | #include "AST/BaseAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * block -+- labeled-block 37 | * +- unlabeled-block 38 | * 39 | * unlabeled-block -+- BEGIN block-body END 40 | * +- block-body 41 | * 42 | * block-body -+- declaration 43 | * +- nothing 44 | * -+- block-action ... 45 | * +- nothing 46 | * -+- block-value 47 | * +- nothing 48 | * 49 | * block-action -+- expression 50 | * block-value --+ 51 | */ 52 | class BlockAST : public BaseAST // AKA: The unlabeled-block 53 | { 54 | }; 55 | 56 | /* 57 | * labeled-block --- label:... unlabeled-block 58 | */ 59 | class LabeledBlockAST : public BlockAST 60 | { 61 | private: 62 | string label; // could be a vector of strings 63 | }; 64 | } 65 | 66 | #endif /* LLVM_BLISS_BLOCKAST_H */ 67 | -------------------------------------------------------------------------------- /include/bliss/AST/CompileTimeAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: CompileTimeAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 4:37 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_COMPILETIMEAST_H 26 | #define LLVM_BLISS_COMPILETIMEAST_H 27 | 28 | #include "AST/DeclarationAST.h" 29 | #include "AST/ExprAST.h" 30 | 31 | using namespace std; 32 | 33 | namespace bliss 34 | { 35 | 36 | /* 37 | * compile-time-declaration --- COMPILETIME compile-time-item, ...; 38 | * 39 | * compile-time-item --- compile-time-name = compile-time-value 40 | * 41 | * compile-time-name --- name 42 | * 43 | * compile-time-value --- compile-time-constant-expression 44 | */ 45 | class CompileTimeConstantAST : public DeclarationAST 46 | { 47 | }; 48 | } 49 | 50 | #endif /* LLVM_BLISS_COMPILETIMEAST_H */ 51 | -------------------------------------------------------------------------------- /include/bliss/AST/ConditionHandlingAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: ConditionHandlingAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 5:15 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_CONDITIONHANDLINGAST_H 26 | #define LLVM_BLISS_CONDITIONHANDLINGAST_H 27 | 28 | #include "AST/DeclarationAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * enable-declaration --- ENABLE routine-name -+- (enable-actual, ... ) 37 | * +- nothing 38 | * 39 | * +- own-name 40 | * enable-actual -+ global-name 41 | * | forward-name 42 | * +- local-name 43 | * 44 | * routine-name -+ 45 | * own-name | 46 | * global-name +- name 47 | * forward-name | 48 | * local-name ---+ 49 | */ 50 | class EnableDeclAST : public DeclarationAST 51 | { 52 | }; 53 | } 54 | 55 | #endif /* LLVM_BLISS_CONDITIONHANDLINGAST_H */ 56 | -------------------------------------------------------------------------------- /include/bliss/AST/ConstantAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: ConstantAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 21, 2019, 4:40 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_CONSTANTAST_H 26 | #define LLVM_BLISS_CONSTANTAST_H 27 | 28 | #include "AST/ExprAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | /* 35 | * compile-time-constant-expression --- expression 36 | * 37 | * Restrictions: 38 | * 39 | * A compile-time constant expression must be one of the following 40 | * expressions: 41 | * 1. A numeric-literal. 42 | * 2. A string-literal. 43 | * 3. A name that satisfies the following conditions: 44 | * a. It is declared in any bound-declaration except an EXTERNAL 45 | * literal-declaration (as described in Chapter 14). 46 | * b. It is bound to a value that is given by a compile-time 47 | * constant expression. 48 | * 4. A structure-reference that yields a compile-time constant 49 | * expression when it is expanded (as described in Chapter 11). 50 | * 5. A block that has a compile-time constant expression (and nothing 51 | * else) as its body. 52 | * 6. An operator-expression that satisfies the following conditions: 53 | * a. It is not a fetch-expression or an assignment-expression. 54 | * b. It has a compile-time constant expression as each of its 55 | * operands. 56 | * 7. An operator-expression that has the following form: 57 | * e1 -+- rela -+- e2 58 | * +- - --+ 59 | * In these forms, rela is one of the relational operators for 60 | * addresses (EQLA,NEQA, and so on). Both e1 and e2 must be 61 | * link-time constant expressions; furthermore, their values must 62 | * be addresses that are relative to the same program section, 63 | * external data segment, or external routine name. 64 | * 8. An executable-function that satisfies the following conditions: 65 | * a. It is the ABS function, the SIGN function, or one of the 66 | * max or min functions. 67 | * b. It has a compile-time constant expression as each of its 68 | * parameters. 69 | * 9. A supplementary-function that satisfies certain restrictions. 70 | * Those restrictions are not given here but instead appear as part 71 | * of the definition of each supplementary-function. (For example, 72 | * Section 20.2.1.1 states that the CH$ALLOCATION function is a 73 | * compile-time constant expression if its parameters are 74 | * compile-time constant expressions.) 75 | * 10. A conditional-expression that satisfies the following 76 | * conditions: 77 | * a. It has a test that is a compile-time constant expression. 78 | * b. It has a consequence or alternative that is a compile-time 79 | * constant expression, depending on whether the test is 80 | * satisfied or fails. 81 | * 11. A case-expression that satisfies the following conditions: 82 | * a. It has a case-index that is a compile-time constant 83 | * expression. 84 | * b. It has at least one case-action that is a compile-time 85 | * constant expression; namely, that case-action that is chosen 86 | * by the value of the case-ind 87 | */ 88 | class CompileTimeConstantExpr : public ExprAST 89 | { 90 | }; 91 | 92 | /* 93 | * compile-time-constant-expression --- expression 94 | * 95 | * Restrictions: 96 | * 97 | * These restrictions apply to an expression after any macro-calls in the 98 | * expression have been expanded. 99 | * 100 | * A link-time constant expression must be one of the following 101 | * expressions: 102 | * 1. A compile-time-constant-expression. 103 | * 2. A PLIT. 104 | * 3. A name that is declared as one of the following: 105 | * a. OWN, GLOBAL, EXTERNAL, or FORWARD. (These are used for names 106 | * of permanently allocated data segments.) 107 | * b. ROUTINE, GLOBAL ROUTINE, EXTERNAL ROUTINE, or FORWARD 108 | * ROUTINE. (These are used for names of routine segments.) 109 | * c. EXTERNAL LITERAL. (This is used for names of literals that 110 | * are bound in other modules.) 111 | * 4. A name that satisfies the following conditions: 112 | * a. It is declared by a bound-declaration (as described in 113 | * Chapter 14). 114 | * b. It is bound to a value that is given by a 115 | * link-time-constant-expression. 116 | * 5. A structure-reference that yields a link-time constant 117 | * expression when it is expanded (as described in Chapter 11). 118 | * 6. A block that has a link-time constant expression (and nothing 119 | * else) as its body. 120 | * 7. An operator-expression that has the following form: 121 | * e1 -+- + -+- e2 122 | * +- - -+ 123 | * In these forms, e1 must be a link-time constant expression and 124 | * e2 must be a compile-time constant expression. 125 | * 8. An operator-expression that has the following form: 126 | * e1 -+- rela -+- e2 127 | * +- - --+ 128 | * In these forms, rela is one of the relational operators for 129 | * addresses (EQLA, NEQA, and so on). Both e1 and e2 must be 130 | * link-time constant expressions; furthermore, their values must 131 | * be addresses that are relative to the same program section, 132 | * external data segment, or external routine name. 133 | * 9. A supplementary-function that satisfies certain restrictions. 134 | * Those restrictions are not given here but appear as part of the 135 | * definition of each supplementary function. (For example, Section 136 | * 20.2.2.1 states that the CH$PTR function is a link-time constant 137 | * expression if its first parameter is a link-time constant 138 | * expression and its remaining parameters are compile-time 139 | * constant expressions.) 140 | */ 141 | class LinkTimeConstantExpr : public ExprAST 142 | { 143 | }; 144 | } 145 | 146 | #endif /* LLVM_BLISS_CONSTANTAST_H */ 147 | -------------------------------------------------------------------------------- /include/bliss/AST/ControlAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: ControlAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 14, 2019, 5:28 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_CONTROLAST_H 26 | #define LLVM_BLISS_CONTROLAST_H 27 | 28 | #include "AST/ExprAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * +- conditional-expression 37 | * | case-expression 38 | * control-expression -+ select-expression 39 | * | loop-expression 40 | * | exit-expression 41 | * +- return-expression 42 | */ 43 | class ControlExprAST : public ExprAST 44 | { 45 | public: 46 | ControlExprAST(void *Val) : Val(Val) {} 47 | 48 | private: 49 | void* Val; 50 | }; 51 | 52 | /* 53 | * conditional-expression -+- IF test THEN consequence ELSE alternative 54 | * +- IF test THEN consequence 55 | * 56 | * test --------+ 57 | * consequence +- expression 58 | * alternative -+ 59 | */ 60 | class ConditionalExprAST : public ControlExprAST 61 | { 62 | }; 63 | 64 | /* 65 | * case-expression --- CASE case-index FROM low-bound TO high-bound 66 | * SET 67 | * case-line... 68 | * TES 69 | * 70 | * case-line --- [case-label, ...]: case-action; 71 | * 72 | * +- single-value 73 | * case-label -+ low-value TO high-value 74 | * | INRANGE 75 | * +- OUTRANGE 76 | * 77 | * case-index --+- expression 78 | * case-action -+ 79 | * 80 | * low-bound + 81 | * high-bound | 82 | * single-value +- compile-time-constant-expression 83 | * low-value | 84 | * high-value --+ 85 | */ 86 | class CaseExprAST : public ControlExprAST 87 | { 88 | }; 89 | 90 | /* 91 | * select-expression -+- SELECT | SELECTA | SELECTU ---------+- select-index OF 92 | * +- SELECTONE | SELECTONEA | SELECTONEU + 93 | * SET 94 | * select-line... 95 | * TES 96 | * 97 | * select-line --- [select-label, ...]: select-action; 98 | * 99 | * +- selector 100 | * select-label -+ low-selector TO high-selector 101 | * | OTHERWISE 102 | * + ALWAYS 103 | * 104 | * select-index --+ 105 | * select-action | 106 | * selector +- expression 107 | * low-selector | 108 | * high-selector -+ 109 | */ 110 | class SelectExprAST : public ControlExprAST 111 | { 112 | }; 113 | 114 | /* 115 | * loop-expression -+- indexed-loop-expression 116 | * +- tested-loop-expression 117 | * 118 | */ 119 | class LoopExprAST : public ControlExprAST 120 | { 121 | private: 122 | ExprAST LoopBody; 123 | }; 124 | 125 | /* 126 | * indexed-loop-expression -+- INCR | INCRA | INCRU -+- loop-index 127 | * +- DECR | DECRA | DESCU -+ 128 | * FROM initial -+--+- TO final -+--+- BY step 129 | * nothing ------+ +- nothing --+ +- nothing 130 | * DO loop-body 131 | * 132 | * loop-index --- name 133 | * 134 | * loop-body -+ 135 | * initial +- expression 136 | * final | 137 | * step ------+ 138 | */ 139 | class IndexLoopExprAST : public LoopExprAST 140 | { 141 | }; 142 | 143 | /* 144 | * tested-loop-expression -+- pre-tested-loop 145 | * +- post-tested-loop 146 | * 147 | * pre-tested-loop -+- WHILE -+- test DO loop-body 148 | * +- UNTIL -+ 149 | * 150 | * post-tested-loop --- DO loop-body -+- WHILE -+- test 151 | * +- UNTIL -+ 152 | */ 153 | class TestedLoopExprAST : public LoopExprAST 154 | { 155 | }; 156 | 157 | /* 158 | * exit-expression -+- leave-expression 159 | * +- exit-loop-expression 160 | * 161 | * leave-expression --- LEAVE label -+- WITH exit-value 162 | * +- nothing 163 | * 164 | * exit-loop-expression --- EXITLOOP -+- exit-value 165 | * +- nothing 166 | * 167 | * exit-value --- expression 168 | */ 169 | class ExitExprAST : public ControlExprAST 170 | { 171 | }; 172 | 173 | /* 174 | * return-expression --- RETURN -+- returned-value 175 | * +- nothing 176 | * 177 | * returned-value --- expression 178 | */ 179 | class ReturnExprAST : public ControlExprAST 180 | { 181 | }; 182 | } 183 | 184 | #endif /* LLVM_BLISS_CONTROLAST_H */ 185 | -------------------------------------------------------------------------------- /include/bliss/AST/DataAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: DataAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 22, 2019, 11:56 AM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_DATAAST_H 26 | #define LLVM_BLISS_DATAAST_H 27 | 28 | #include "AST/DeclarationAST.h" 29 | #include "AST/AttributeAST.h" 30 | 31 | using namespace std; 32 | 33 | namespace bliss 34 | { 35 | 36 | /* 37 | * +- own-declaration 38 | * | global-declaration 39 | * | forward-declaration 40 | * data-declaration -+ external-declaration 41 | * | local-declaration 42 | * | stack-local-declaration 43 | * | register-declaration 44 | * +- map-declaration 45 | */ 46 | class DataDeclarationAST : public DeclarationAST 47 | { 48 | }; 49 | 50 | /* 51 | * own-declaration --- OWN own-item, ... ; 52 | * 53 | * own-item --- own-name -+- : own-attribute... 54 | * +- nothing 55 | * 56 | * own-name --- name 57 | * 58 | * +- allocation-unit 59 | * | extension-attribute 60 | * | structure-attribute 61 | * | field-attribute 62 | * own-attribute -+ alignment-attribute 63 | * | initial-attribute 64 | * | preset-attribute 65 | * | psect-allocation 66 | * +- volatile-attribute 67 | */ 68 | class OwnDeclarationAST : public DataDeclarationAST 69 | { 70 | }; 71 | 72 | /* 73 | * global-declaration --- GLOBAL global-item, ... ; 74 | * 75 | * global-item --- global-name -+- : global-attribute... 76 | * +- nothing 77 | * 78 | * global-name --- name 79 | * 80 | * +- allocation-unit 81 | * | extension-attribute 82 | * | structure-attribute 83 | * | field-attribute 84 | * global-attribute-+ alignment-attribute 85 | * | initial-attribute 86 | * | preset-attribute 87 | * | psect-attribute 88 | * | volatile-attribute 89 | * +- weak-attribute 90 | */ 91 | class GlobalDeclarationAST : public DataDeclarationAST 92 | { 93 | }; 94 | 95 | /* 96 | * forward-declaration --- FORWARD forward-item, ... ; 97 | * 98 | * forward-item --- forward-name -+- : forward-attribute 99 | * +- nothing 100 | * 101 | * forward-name --- name 102 | * 103 | * +- allocation-unit 104 | * | extension-attribute 105 | * | structure-attribute 106 | * forward-attribute -+ field-attribute 107 | * | psect-attribute 108 | * | volatile-attribute 109 | * +- addressing-mode-attribute 110 | */ 111 | class ForwardDeclarationAST : public DataDeclarationAST 112 | { 113 | }; 114 | 115 | /* 116 | * external-declaration --- EXTERNAL external-item, ... ; 117 | * 118 | * external-item --- external-name -+- : external-attribute 119 | * +- nothing 120 | * 121 | * external-name --- name 122 | * 123 | * +- allocation-unit 124 | * | extension-attribute 125 | * | structure-attribute 126 | * external-attribute -+ field-attribute 127 | * | psect-attribute 128 | * | volatile-attribute 129 | * | addressing-mode-attribute 130 | * +- weak-attribute 131 | */ 132 | class ExternalDeclarationAST : public DataDeclarationAST 133 | { 134 | }; 135 | 136 | /* 137 | * local-declaration --- LOCAL local-item, ... ; 138 | * stack-local-declaration --- STACKLOCAL local-item, ... ; 139 | * 140 | * local-item --- local-name -+- : local-attribute... 141 | * +- nothing 142 | * 143 | * local-name --- name 144 | * 145 | * +- allocation-unit 146 | * | extension-attribute 147 | * | structure-attribute 148 | * local-attribute -+ field-attribute 149 | * | alignment-attribute 150 | * | initial-attribute 151 | * | preset-attribute 152 | * +- volatile-attribute 153 | */ 154 | class LocalDeclarationAST : public DataDeclarationAST 155 | { 156 | private: 157 | bool stack_local; 158 | }; 159 | 160 | /* 161 | * register-declaration --- REGISTER register-item, ... ; 162 | * external-register-declaration --- EXERNAL REGISTER register-item, ... ; 163 | * 164 | * register-item --- register-name -+- = register-number -+--+- : register-attribute 165 | * +- nothing -----------+ +- nothing 166 | * 167 | * register-name --- name 168 | * 169 | * register-number --- compile-time-constant-expression 170 | * 171 | * +- allocation-unit 172 | * | extension-attribute 173 | * register-attribute -+ structure-attribute 174 | * | field-attribute 175 | * | initial-attribute 176 | * +- preset-attribute 177 | */ 178 | class RegisterDeclarationAST : public DataDeclarationAST 179 | { 180 | private: 181 | bool external; 182 | }; 183 | 184 | /* 185 | * global-register-declaration --- GLOBAL REGISTER register-item, ... ; 186 | * 187 | * register-item --- register-name --- = register-number --+- : register-attribute 188 | * +- nothing 189 | */ 190 | class GlobalRegisterDeclarationAST : public RegisterDeclarationAST 191 | { 192 | }; 193 | 194 | /* 195 | * map-declaration --- MAP map-item, ... ; 196 | * 197 | * map-item --- map-name : map-attribute 198 | * 199 | * map-name --- name 200 | * 201 | * +- allocation-unit 202 | * | extension-attribute 203 | * map-attribute -+ structure-attribute 204 | * | field-attribute 205 | * +- volatile-attribute 206 | */ 207 | class MapDeclarationAST : public DataDeclarationAST 208 | { 209 | }; 210 | } 211 | 212 | #endif /* LLVM_BLISS_DATAAST_H */ 213 | -------------------------------------------------------------------------------- /include/bliss/AST/DeclarationAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: DeclarationAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 22, 2019, 10:31 AM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_DECLARATIONAST_H 26 | #define LLVM_BLISS_DECLARATIONAST_H 27 | 28 | #include "AST/AttributeAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * +- data-declaration 37 | * | structure-declaration 38 | * | field-declaration 39 | * | routine-declaration 40 | * | linkage-declaration 41 | * | enable-declaration 42 | * | bound-declaration 43 | * declaration -+ compile-time-declaration 44 | * | macro-declaration 45 | * | require-declaration 46 | * | library-declaration 47 | * | psect-declaration 48 | * | switches-declaration 49 | * | label-declaration 50 | * | builtin-declaration 51 | * +- undeclare-declaration 52 | */ 53 | class DeclarationAST : public BaseAST 54 | { 55 | }; 56 | 57 | } 58 | 59 | #endif /* LLVM_BLISS_DECLARATIONAST_H */ 60 | -------------------------------------------------------------------------------- /include/bliss/AST/ExecutableFuncAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: OperatorAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 14, 2019, 5:28 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_EXECUTABLEFUNCAST_H 26 | #define LLVM_BLISS_EXECUTABLEFUNCAST_H 27 | 28 | #include "AST/ExprAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * executable-function --- executable-function-name ( -+- actual-parameter, ... -+- ) 37 | * +- nothing ---------------+ 38 | * 39 | * executable-function-name -+- name 40 | * +- % name 41 | * 42 | * actual-parameter --- expression 43 | */ 44 | class ExecutableFuncAST : public ExprAST 45 | { 46 | public: 47 | ExecutableFuncAST(void *Val) : Val(Val) {} 48 | 49 | private: 50 | void *Val; 51 | }; 52 | } 53 | 54 | 55 | #endif /* LLVM_BLISS_EXECUTABLEFUNCAST_H */ 56 | -------------------------------------------------------------------------------- /include/bliss/AST/ExprAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: ExprAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 14, 2019, 2:42 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_EXPRAST_H 26 | #define LLVM_BLISS_EXPRAST_H 27 | 28 | #include "AST/BaseAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * ExprAST - Base class for all expression nodes. 37 | * 38 | * +- primary 39 | * expression -+ operator-expression 40 | * | executable-function 41 | * +- control-expression 42 | */ 43 | class ExprAST : public BaseAST 44 | { 45 | }; 46 | } 47 | 48 | #endif /* LLVM_BLISS_EXPRAST_H */ 49 | -------------------------------------------------------------------------------- /include/bliss/AST/IncludeAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: IncludeAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 5:10 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_INCLUDEAST_H 26 | #define LLVM_BLISS_INCLUDEAST_H 27 | 28 | #include "AST/BaseAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * require-declaration --- REQUIRE file-designator ; 37 | * 38 | * file-designator --- quoted-string 39 | */ 40 | class RequireAST 41 | { 42 | }; 43 | 44 | /* 45 | * library-declaration --- LIBRARY file-designator ; 46 | */ 47 | class LibraryAST 48 | { 49 | }; 50 | } 51 | 52 | #endif /* LLVM_BLISS_INCLUDEAST_H */ 53 | -------------------------------------------------------------------------------- /include/bliss/AST/LexicalAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: LexicalAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 4:09 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_LEXICALAST_H 26 | #define LLVM_BLISS_LEXICALAST_H 27 | 28 | #include "AST/ExprAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * lexical-expression -+- primitive 37 | * +- non-primitive 38 | */ 39 | class LexicalExprAST : public ExprAST 40 | { 41 | }; 42 | 43 | /* 44 | * +- delimiter 45 | * | keyword 46 | * primitive -+ name 47 | * | numeric-literal 48 | * +- string-literal 49 | */ 50 | class PrimitiveLexicalAST : public LexicalExprAST 51 | { 52 | }; 53 | 54 | /* +- lexical-function 55 | * | lexical-conditional 56 | * non-primitive -+ macro-call 57 | * | require-declaration 58 | * +- library-declaration 59 | * 60 | * +- ( lexical-actual-parameter, ... ) 61 | * lexical-function --- lexical-function-name -+ lexeme 62 | * +- nothing 63 | * 64 | * lexical-function-name --- % name 65 | * 66 | * lexical-actual-parameter -+- lexeme... 67 | * +- nothing 68 | * 69 | * Specific Lexical-Functions 70 | * 71 | * String-Functions: %STRING %EXACTSTRING %CHAR %CHARCOUNT 72 | * Delimiter-Functions: %EXPLODE %REMOVE 73 | * Name-Functions: %NAME %QUOTENAME 74 | * Sequence-Test-Functions: %NULL %IDENTICAL 75 | * Expression-Test-Functions: %ISSTRING %CTCE %LTCE 76 | * Bits-Functions: %NBITSU %NBITS 77 | * Allocation-Functions: %ALLOCATION %SIZE 78 | * FieldExpand-Function: %FIELDEXPAND 79 | * Calculation-Functions %ASSIGN %NUMBER 80 | * Compiler-State-Functions: %DECLARED %SWITCHES %BLISS %VARIANT 81 | * Advisory-Functions: %ERROR %WARN %INFORM %PRINT %MESSAGE %ERRORMACRO 82 | * Titling-Functions: %TITLE %SBTTL 83 | * Quote-Functions: %QUOTE %UNQUOTE %EXPAND 84 | * Macro-Functions: %REMAINING %LENGTH %COUNT %EXITITERATION %EXITMACRO 85 | * Require-Function: %REQUIRE 86 | */ 87 | class LexicalFunctionAST : public LexicalExprAST 88 | { 89 | }; 90 | 91 | /* 92 | * lexical-conditional --- %IF lexical-test %THEN lexical-consequence -+- %ELSE lexical-alternative -+- %FI 93 | * +- nothing -------------------+ 94 | * 95 | * lexical-test --- compile-time-constant-expression 96 | * 97 | * lexical-consequence -+--+- lexeme... 98 | * lexical-alternative -+ +- nothing 99 | */ 100 | class LexicalConditionalAST : public LexicalExprAST 101 | { 102 | }; 103 | } 104 | 105 | #endif /* LLVM_BLISS_LEXICALAST_H */ 106 | -------------------------------------------------------------------------------- /include/bliss/AST/LinkageAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: LinkageAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 11:40 AM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_LINKAGEAST_H 26 | #define LLVM_BLISS_LINKAGEAST_H 27 | 28 | #include "AST/DeclarationAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * linkage-declaration --- LINKAGE linkage-definition, ...; 37 | * 38 | * linkage-definition --- linkage-name = linkage-type -- 39 | * -- ( -+- input-parameter-location, ... -+--+- ; output-parameter-location, ... ) -+--+- : linkage-option, ... 40 | * +- nothing -----------------------+ +- nothing ----------------------------+ +- nothing 41 | * 42 | * +- CALL 43 | * linkage-type -+ JSB 44 | * +- INTERRUPT 45 | * 46 | * +- REGISTER = register-number 47 | * input-parameter-location -+ STANDARD 48 | * +- nothing 49 | * 50 | * output-parameter-location --- REGISTER = register-number 51 | * 52 | * +- GLOBAL ( global-register-segment, ...) 53 | * linkage-option -+ +- PRESERVE ---+ 54 | * +--+ NOPRESERVE -+- ( register-number, ... ) 55 | * +- NOTUSED ----+ 56 | * 57 | * global-register-segment --- global-register-name = register-number 58 | * 59 | * global-register-name -+- name 60 | * linkage-name ---------+ 61 | * 62 | * register-number --- compile-time-constant-expression 63 | */ 64 | class LinkageDeclAST : public DeclarationAST 65 | { 66 | }; 67 | 68 | /* 69 | * Predeclared linkage functions: 70 | * ACTUALCOUNT() 71 | * Restriction: Must be declared BUILTIN within the body of a routine whose linkage-attribute is defined with certain 72 | * linkage-types. 73 | * Value: Return the number of actual-parameters passed to the routine using STANDARD parameter-locations. Parameters 74 | * pass using REGISTER parameter-locations are not included in the returned value. 75 | * ACTUALPATAMETER(ii) 76 | * Restriction: The first restriction for ACTUALPARAMGER is the same as ACTUALCOUNT. The value of ii must be in the 77 | * range of 1 to ACTUALCOUNT(). 78 | * Value: Return the value of the ii-th actual-parameter that was passed using STANDARD parameter-locations; parameters 79 | * passed using REGISTER parameter-locations are not obtainable with this function. 80 | * ARGPTR() 81 | * Restriction: The restriction for ARGPTR is the same as for ACTUALCOUNT. 82 | * Value: Return the address of the argument block. 83 | * 84 | * NULLPARAMETER(ii) 85 | * Restriction: If ii is not a formal-name, then it is interpreted as an expression and the value of ii must then be 86 | * greater than or equal to 1. 87 | * Value: Returns true if the value of the ii-th actual-parameter was null or omitted. 88 | */ 89 | } 90 | 91 | #endif /* LLVM_BLISS_LINKAGEAST_H */ 92 | -------------------------------------------------------------------------------- /include/bliss/AST/MacroAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: MacroAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 4:41 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_MACROAST_H 26 | #define LLVM_BLISS_MACROAST_H 27 | 28 | #include "AST/DeclarationAST.h" 29 | #include "AST/ExprAST.h" 30 | 31 | using namespace std; 32 | 33 | namespace bliss 34 | { 35 | 36 | /* 37 | * macro-declaration -+- positional-macro-declaration 38 | * +- keyword-macro-declaration 39 | * 40 | * Pre-declared Macros 41 | * Name 32-bit 64-bit 42 | * %BLISS32[] = %REMAINING %; %; 43 | * %BLISS64[] = %; %REMAINING %; 44 | */ 45 | class MacroDeclAST : public DeclarationAST 46 | { 47 | }; 48 | 49 | /* 50 | * positional-macro-declaration --- MACRO positional-macro-definition, ...; 51 | * 52 | * +- simple-macro-definition 53 | * positional-macro-definition -+ conditional-macro-definition 54 | * +- iterative-macro-definition 55 | * 56 | * simple-macro-definition --- macro-name -+- ( macro-formal-name, ... ) -+- macro-body % 57 | * +- nothing --------------------+ 58 | * 59 | * conditional-macro-definition --- macro-name -+- ( macro-formal-name, ... ) -+- [] = macro-body % 60 | * +- nothing --------------------+ 61 | * 62 | * iterative-macro-definition --- macro-name -+- ( fixed-formal-name, ... ) -+- [ iterative-formal-name, ... ] = macro-body % 63 | * +- nothing --------------------+ 64 | * 65 | * macro-name ---=----+ 66 | * macro-formal-name +- name 67 | * fixed-formal-name -+ 68 | * 69 | * macro-body -+- lexeme... 70 | * +- nothing 71 | */ 72 | class PositionalMacroDeclAST : public MacroDeclAST 73 | { 74 | }; 75 | 76 | /* 77 | * keyword-macro-declaration --- KEYWORDMACRO keyword-macro-definition, ... ; 78 | * 79 | * keyword-macro-definition --- macro-name ( keyword-pair, ... ) = macro-body % 80 | * 81 | * keyword-pair --- keyword-formal-name -+- = default-actual 82 | * +- nothing 83 | * 84 | * keyword-formal-name --- name 85 | * 86 | * default-actual -+- lexeme... 87 | * +- nothing 88 | */ 89 | class KeywordMacroDeclAST : public MacroDeclAST 90 | { 91 | }; 92 | 93 | /* 94 | * macro-call -+- positional-macro-call 95 | * +- keyword-macro-call 96 | */ 97 | class MacroCallAST : public ExprAST 98 | { 99 | }; 100 | 101 | /* +- ( macro-actuals ) 102 | * positional-macro-call --- macro-name -+ [ macro-actuals ] 103 | * | < macro-actuals > 104 | * +- nothing 105 | * 106 | * macro-actuals -+- macro-actual-parameter, ... 107 | * +- nothing 108 | * 109 | * macro-actual-parameter -+- lexeme ... 110 | * +- nothing 111 | */ 112 | class PositionalMacroCallAST : public MacroCallAST 113 | { 114 | }; 115 | 116 | /* +- ( keyword-assignments ) 117 | * keyword-macro-call --- macro-name -+ [ keyword-assignments ] 118 | * + < keyword-assignments > 119 | * 120 | * keyword-assignments -+- keyword-assignment, ... 121 | * +- nothing 122 | * 123 | * keyword-assignment --- keyword-formal-name = macro-actual-parameter 124 | */ 125 | class KeywordMacroCallAST : public MacroCallAST 126 | { 127 | }; 128 | } 129 | 130 | #endif /* LLVM_BLISS_MACROAST_H */ 131 | -------------------------------------------------------------------------------- /include/bliss/AST/ModuleAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: ModuleAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 5:54 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_MODULEAST_H 26 | #define LLVM_BLISS_MODULEAST_H 27 | 28 | #include "AST/SpecialAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * module --- MODULE module-head = module-body ELUDOM 37 | * 38 | * module-head --- module-name -+- ( module-switch, ... ) 39 | * +- nothing 40 | * 41 | * module-name --- name 42 | * 43 | * module-body --- block 44 | * 45 | * module-switch -+- on-off-switch 46 | * +- special-switch 47 | * 48 | * +- CODE | NOCODE 49 | * | DEBUG | NODEBUG 50 | * | ERRS | NOERRS 51 | * on-off-switch -+ OPTIMIZE | NOOPTIMIZE 52 | * | SAFE | NOSAFE 53 | * | UNAMES | NOUNAMES 54 | * +- ZIP | NOZIP 55 | * 56 | * +- common-switch 57 | * special-switch -+ bliss-32-switch 58 | * +- bliss-64-switch 59 | * 60 | * +- IDENT = quoted-string 61 | * | LANGUAGE ( language-list, ... ) 62 | * | LINKAGE ( linkage-name) 63 | * common-switch -+ LIST ( list-options ) 64 | * | STRUCTURE -+- ( structure-attribute ) 65 | * | +- nothing 66 | * | MAIN = routine-name 67 | * | OPTLEVEL = 0 | 1 | 2 | 3 68 | * +- VERSION = quoted-string 69 | * 70 | */ 71 | class ModuleAST : public BaseAST 72 | { 73 | public: 74 | ModuleAST(const string &Name) : Name(Name) {} 75 | 76 | private: 77 | string Name; 78 | SwitchesDeclAST switches; 79 | }; 80 | } 81 | 82 | #endif /* LLVM_BLISS_MODULEAST_H */ 83 | -------------------------------------------------------------------------------- /include/bliss/AST/OperatorAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: OperatorAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 14, 2019, 5:28 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_OPERATORAST_H 26 | #define LLVM_BLISS_OPERATORAST_H 27 | 28 | #include "AST/ExprAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * Every operator has one of the following forms: 37 | * 38 | * prefix-operator rhs 39 | * lhs infix-operator rhs 40 | * 41 | * Direction of 42 | * Association 43 | * ------------ 44 | * +- . rhs <--- 45 | * | 46 | * | + -+- rhs <--- 47 | * | - -+ 48 | * | 49 | * | lhs ^ rhs ---> 50 | * | 51 | * | +- MOD -+ 52 | * | lhs -+ * +- rhs ---> 53 | * | +- / ---+ 54 | * | 55 | * operator-expression -+ lhs -+- + -+- rhs ---> 56 | * | +- - -+ 57 | * | 58 | * | +- EQL[ UA] -+ 59 | * | | NEQ[ UA] | 60 | * | lhs -+ LSS[ UA] +- rhs ---> 61 | * | | LEQ[ UA] | 62 | * | | GTR[ UA] | 63 | * | +- GEQ[ UA] -+ 64 | * | 65 | * | NOT rhs <--- 66 | * | 67 | * | lhs AND rhs ---> 68 | * | 69 | * | lhs OR rhs ---> 70 | * | 71 | * | lhs -+- EQV -+- rhs ---> 72 | * | +- XOR -+ 73 | * | 74 | * +- lhs = rhs <--- 75 | * 76 | * +- primary 77 | * lhs -+-+ operator-expression 78 | * rhs -+ +- executable-function 79 | */ 80 | class OperatorExprAST : public ExprAST 81 | { 82 | public: 83 | OperatorExprAST(void *Val) : Val(Val) {} 84 | 85 | private: 86 | void *Val; 87 | }; 88 | } 89 | 90 | #endif /* LLVM_BLISS_OPERATORAST_H */ 91 | -------------------------------------------------------------------------------- /include/bliss/AST/PrimaryAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: PrimaryAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 14, 2019, 4:42 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_PRIMARYAST_H 26 | #define LLVM_BLISS_PRIMARYAST_H 27 | 28 | #include "AST/ExprAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * +- numeric-literal 37 | * | string-literal 38 | * | plit 39 | * | name 40 | * primary -+ block 41 | * | structure-reference 42 | * | routine-call 43 | * | field-reference 44 | * +- code-comment 45 | */ 46 | class PrimaryExprAST : public ExprAST 47 | { 48 | public: 49 | virtual ~PrimaryExprAST() {} 50 | }; 51 | 52 | /* 53 | * +- decimal-literal 54 | * numeric-literal -+ integer-literal 55 | * | character-code-literal 56 | * +- float-literal 57 | * 58 | * decimal-literal --- decimal-digit... 59 | * 60 | * decimal-digit --- 0..9 61 | * 62 | * +- %B -------+ 63 | * integer-literal -+ %O +- ' opt-sign integer-digit... ' 64 | * | %DECIMAL | 65 | * +- %X -------+ 66 | * 67 | * +- + (positive) 68 | * opt-sign -+ - (negative) 69 | * +- nothing (positive) 70 | * 71 | * integer-digit --- 0..9 A..F 72 | * 73 | * character-coded-literal - %C ' quoted-character ' 74 | * 75 | * +- single-precision-float-literal 76 | * float-literal -+ double-precision-float-literal 77 | * | extended-exponent-double-precision-float-literal 78 | * +- extended-exponent-extended-precision-float-literal 79 | * 80 | * single-precision-float-literal -+- %E -+- ' mantissa -+- E exponent -+- ' 81 | * +- %T -+ +- nothing ----+ 82 | * 83 | * double-precision-float-literal -+- %D -+- ' mantissa -+- E exponent -+- ' 84 | * +- %S -+ +- nothing ----+ 85 | * 86 | * extended-exponent-double-precision-float-literal -+- %G -+- ' mantissa -+- Q exponent -+- ' 87 | * +- %? -+ +- nothing ----+ 88 | * 89 | * extended-exponent-extended-precision-float-literal -- %H ' mantissa -+- Q exponent -+- ' 90 | * +- nothing ----+ 91 | * 92 | * +- decimal-digits 93 | * mantissa --- opt-sign -+ decimal-digits . 94 | * | . decimal-digits 95 | * +- decimal-digits . decimal-digits 96 | * 97 | * exponent -- opt-sign decimal-digits 98 | */ 99 | class NumericLiteral : public PrimaryExprAST 100 | { 101 | public: 102 | NumericLiteral(float TVal) : TVal(TVal) {} 103 | NumericLiteral(double SVal) : SVal(SVal) {} 104 | NumericLiteral(long double XVal) : XVal(XVal) {} 105 | NumericLiteral(uint64_t IVal) : IVal(IVal) {} 106 | NumericLiteral(char CVal) : CVal(CVal) {} 107 | 108 | private: 109 | float TVal; 110 | double SVal; 111 | long double XVal; 112 | uint64_t IVal; // For both decimal- and integer-literals 113 | char CVal; 114 | }; 115 | 116 | /* 117 | * string-literal -+- string-type -+- quoted-string 118 | * +- nothing -+ 119 | * 120 | * +- %ASCII 121 | * | %ASCIZ 122 | * string-type -+ %ASCIC 123 | * | %ASCID 124 | * +- %P 125 | * 126 | * quoted-string --- ' quoted-character... ' 127 | * 128 | * +- printing-character-except-apostrophe 129 | * quoted-character -+ blank 130 | * | tab 131 | * +- '' (escape sequence for an apostrophe) 132 | * printing-character --- ASCII 33 through ASCII 126, inclusive 133 | * blank --- ASCII 32 134 | * tab --- ASCII 9 135 | * apostrophe --- ASCII 39 136 | */ 137 | class StringLiteral : public PrimaryExprAST 138 | { 139 | public: 140 | StringLiteral(string Str) : Str(Str) {} 141 | StringLiteral(DSC64_DESCRIPTOR StrDSC) : StrDSC(StrDSC) {} 142 | 143 | private: 144 | string Str; 145 | DSC64_DESCRIPTOR StrDSC; 146 | }; 147 | 148 | /* 149 | * +- allocation-unit ---------------- + 150 | * plit -+- PLIT --+-+ psect-allocation +- ( plit-item ) 151 | * +- UPLIT -+ | psect-allocation allocation-unit | 152 | * +- nothing -------------------------+ 153 | * 154 | * +- QUAD 155 | * | LONG 156 | * allocation-unit -+ WORD 157 | * +- BYTE 158 | * 159 | * psect-allocation --- PSECT ( psect-name ) 160 | * 161 | * psec-name --- name 162 | * 163 | * +- plit-group 164 | * plit-item -+ plit-expression 165 | * +- plit-string 166 | * 167 | * +- allocation-unit -------------------+ 168 | * plit-group -+ REP replicator OF +- ( plit-item, ... ) 169 | * +- REP replicator OF allocation-unit -+ 170 | * 171 | * replicator --- compile-time-constant-expression 172 | * 173 | * plit-expression --- link-time-constant-expression 174 | * 175 | * plit-string --- string-literal 176 | */ 177 | class Plit : public PrimaryExprAST 178 | { 179 | }; 180 | 181 | /* 182 | * +- + letter 183 | * +- letter -----+ | | digit 184 | * name -+ dollar +-+ -+ dollar 185 | * +- underscore -+ | + underscore 186 | * +- nothing 187 | * 188 | * letter --- A..Z a..Z 189 | * 190 | * digit --- 0..9 191 | * 192 | * dollar --- $ 193 | * 194 | * underscore --- _ 195 | */ 196 | class Name : public PrimaryExprAST 197 | { 198 | public: 199 | Name(string Str) : Str(Str) {} 200 | 201 | private: 202 | string Str; 203 | }; 204 | 205 | /* 206 | * block -+- labeled-block 207 | * +- unlabeled-block 208 | * 209 | * labeled-block --- {label:}... unlabeled-block 210 | * 211 | * label --- name 212 | * 213 | * unlabeled-block -+- BEGIN block-body END 214 | * +- ( block-body ) 215 | * 216 | * +-+- declaration ... 217 | * | +- nothing 218 | * | 219 | * block-body -+-+- block-action ... 220 | * | +- nothing 221 | * | 222 | * +-+- block-value 223 | * +- nothing 224 | * 225 | * block-action --- expression ; 226 | * 227 | * block-value --- expression 228 | */ 229 | class Block : public PrimaryExprAST 230 | { 231 | }; 232 | 233 | /* 234 | * +- ordinary-structure-reference 235 | * structure-reference -+ default-structure-reference 236 | * +- general-structure-reference 237 | * 238 | * ordinary-structure-reference --- segment-name [ access-actual, ... ] 239 | * 240 | * segment-name --- name 241 | * 242 | * +- field-name 243 | * access-actual -+ expression 244 | * +- nothing 245 | * 246 | * default-structure-reference --- address [ access-actual, ... ] 247 | * 248 | * address -+- primary 249 | * +- executable-function 250 | * 251 | * general-structure-reference --- structure-name [ access-part -+- ; allocation-actual, ... -+- ] 252 | * +- nothing ------------------+ 253 | * 254 | * access-part --- segment-expression -+- , access-actual 255 | * +- nothing 256 | * 257 | * segment-expression -+- expression 258 | * +- nothing 259 | */ 260 | class Structure : public PrimaryExprAST 261 | { 262 | }; 263 | 264 | /* 265 | * routine-call -+- ordinary-routine-call 266 | * +- general-routine-call 267 | */ 268 | class RoutineAST : public PrimaryExprAST 269 | { 270 | }; 271 | 272 | /* 273 | * ordinary-routine-call --- routine-designator ( -+- input-actual-parameter, ... -+--+- ; output-actual-parameter, ... -+- ) 274 | * +- nothing ---------------------+ +- nothing ------------------------+ 275 | * 276 | * routine-designator --- primary 277 | * 278 | * input-actual-parameter -+- expression 279 | * +- nothing 280 | * 281 | * output-actual-parameter -+- expression 282 | * +- nothing 283 | */ 284 | class OrdinaryRoutineAST : public RoutineAST 285 | { 286 | }; 287 | 288 | /* 289 | * general-routine-call --- linkage-name ( routine-address -- 290 | * -+- , input-actual-parameter, ... -+--+- ; output-actual-parameter, ... -+- ) 291 | * +- nothing -----------------------+ +- nothing ------------------------+ 292 | * 293 | * routine-address --- expression 294 | */ 295 | class GeneralRoutineAST : public RoutineAST 296 | { 297 | }; 298 | 299 | /* 300 | * field-reference --- address -+- field-selector 301 | * +- nothing 302 | * 303 | * field-selector --- < position, size -+- , sign-extension-flag -+- > 304 | * +- nothing ---------------+ 305 | * 306 | * position -+- expression 307 | * size -----+ 308 | * 309 | * sing-extension-flag --- compile-time-constant-expression 310 | */ 311 | class Field : public PrimaryExprAST 312 | { 313 | }; 314 | 315 | /* 316 | * code-comment --- CODECOMMENT quoted-string,... : block 317 | */ 318 | class CodeComment : public PrimaryExprAST 319 | { 320 | public: 321 | CodeComment(string Str) : Str(Str) {} 322 | 323 | private: 324 | string Str; 325 | }; 326 | } 327 | 328 | #endif /* LLVM_BLISS_PRIMARYAST_H */ 329 | -------------------------------------------------------------------------------- /include/bliss/AST/RoutineAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: RoutineAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 8:19 AM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_ROUTINEAST_H 26 | #define LLVM_BLISS_ROUTINEAST_H 27 | 28 | #include "AST/DeclarationAST.h" 29 | #include "AST/ExprAST.h" 30 | 31 | using namespace std; 32 | 33 | namespace bliss 34 | { 35 | 36 | /* 37 | * +- ordinary-routine-declaration 38 | * routine-declaration -+ global-routine-declaration 39 | * | forward-routine-declaration 40 | * +- external-routine-declaration 41 | * 42 | * ordinary-routine-declaration --- nothing -+- ROUTINE routine-definition, ...; 43 | * global-routine-declaration --- GLOBAL ----+ 44 | * 45 | * +- ( input-list ) ------------- -+ 46 | * routine-definition --- routine-name -+ ( ; output-list ) +--+- : routine-attribute... -+- = routine-body 47 | * | ( input-list ; output-list ) | +- nothing ----------------+ 48 | * +- nothing ----------------------+ 49 | * 50 | * routine-name --- name 51 | * 52 | * input-list --- input-formal-parameter, ... 53 | * 54 | * output-list --- output-formal-parameter, ... 55 | * 56 | * input-formal-parameter --+- formal-item 57 | * output-formal-parameter -+ 58 | * 59 | * formal-item --- formal-name -+- : formal-attribute-list 60 | * +- nothing 61 | * 62 | * formal-name --- name 63 | * 64 | * formal-attribute-list --- map-declaration-attribute ... 65 | * 66 | * +- allocation-unit 67 | * | extension-attribute 68 | * map-declaration-attribute -+ structure-attribute 69 | * | field-attribute 70 | * +- volatile-attribute 71 | * 72 | * +- novalue-attribute 73 | * | linkage-attribute 74 | * routine-attribute -+ psect-allocation 75 | * | addressing-mode-attribute 76 | * +- weak-attribute 77 | * 78 | * routine-body --- expression 79 | */ 80 | class RoutineDeclAST : public DeclarationAST 81 | { 82 | public: 83 | RoutineDeclAST(bool globalDeclaration = false); 84 | 85 | private: 86 | bool global; 87 | }; 88 | 89 | /* 90 | * forward-routine-declaration --- FORWARD ROUTINE forward-routine-item, ...; 91 | * 92 | * forward-routine-item --- routine-name -+- : fwd-routine-attribute ... 93 | * +- nothing 94 | * 95 | * +- novalue-attribute 96 | * fwd-routine-attribute -+ linkage-attribute 97 | * | psect-allocation 98 | * +- addressing-mode-attribute 99 | * 100 | * routine-name --- name 101 | */ 102 | class FwdRoutineDeclAST : public DeclarationAST 103 | { 104 | }; 105 | 106 | /* 107 | * external-routine-declaration --- EXTERNAL ROUTINE external-routine-item, ...; 108 | * 109 | * external-routine-item --- routine-name -+- : ext-routine-attribute ... 110 | * +- nothing 111 | * 112 | * +- novalue-attribute 113 | * | linkage-attribute 114 | * ext-routine-attribute -+ psect-allocation 115 | * | addressing-mode-attribute 116 | * +- weak-attribute 117 | * 118 | * routine-name --- name 119 | */ 120 | class ExtRoutineDeclAST : public DeclarationAST 121 | { 122 | }; 123 | } 124 | 125 | #endif /* LLVM_BLISS_ROUTINEAST_H */ 126 | -------------------------------------------------------------------------------- /include/bliss/AST/SpecialAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: SpecialAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 28, 2019, 5:46 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_SPECIALAST_H 26 | #define LLVM_BLISS_SPECIALAST_H 27 | 28 | #include "AST/DeclarationAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * psect-declaration --- PSECT psect-item, ... ; 37 | * 38 | * psect-item --- storage-class = psect-name -+- ( psect-attribute, ... ) 39 | * +- nothing 40 | * 41 | * +- OWN 42 | * | GLOBAL 43 | * storage-class -+ PLIT 44 | * | CODE 45 | * +- NODEFAULT 46 | * 47 | * psect-name --- name 48 | * 49 | * +- WRITE | NOWRITE 50 | * | EXECUTE | NOEXECUTE 51 | * | OVERLAY | NOOVERLAY 52 | * | READ | NOREAD 53 | * psect-attribute -+ SHARE | NOSHARE 54 | * | PIC | NOPIC 55 | * | LOCAL | GLOBAL 56 | * | VECTOR 57 | * | alignment-attribute 58 | * +- addressing-mode-attribute 59 | */ 60 | class PsectDeclAST : public DeclarationAST 61 | { 62 | }; 63 | 64 | /* 65 | * switches-declaration --- SWITCHES switch-item, ... ; 66 | * 67 | * switch-item -+- on-off-switch-item 68 | * +- special-switch-item 69 | * 70 | * +- ERRS | NOERRS 71 | * | OPTIMIZE | NOOPTIMIZE 72 | * on-off-switch-item -+ SAFE | NOSAFE 73 | * | UNAMES | NOUNAMES 74 | * +- ZIP | NOZIP 75 | * 76 | * +- ADDRESSING_MODE ( mode-spec, ... ) 77 | * | LANGUAGE ( language-list ) 78 | * special-switch-item -+ LINKAGE ( linkage-name ) 79 | * | LIST ( list-option, ... ) 80 | * +- STRUCTURE -+- ( structure-attribute ) 81 | * +- nothing 82 | * 83 | * +- COMMON 84 | * language-list -+ language-name 85 | * +- nothing 86 | * 87 | * language-name -+- BLISS32 88 | * +- BLISS64 89 | * 90 | * linkage-name --- name 91 | * 92 | * +- SOURCE | NOSOURCE 93 | * | REQUIRE | NOREQUIRE 94 | * | EXPAND | NOEXPAND 95 | * | TRACE | NOTRACE 96 | * list-option -+ LIBRARY | NOLIBRARY 97 | * | OBJECT | NOOBJECT 98 | * | ASSEMBLY | NOASSEMBLY 99 | * | SYMBOLIC | NOSYMBOLIC 100 | * | BINARY | NOBINARY 101 | * +- COMMENTARY | NOCOMMENTARY 102 | * 103 | * mode-spec -+- EXTERNAL ----+-- mode 104 | * +- NONEXTERNAL -+ 105 | * 106 | * +- GENERAL 107 | * mode -+ ABSOLUTE 108 | * | LONG_RELATIVE 109 | * +- WORD_RELATIVE 110 | */ 111 | class SwitchesDeclAST : public DeclarationAST 112 | { 113 | }; 114 | 115 | /* 116 | * built-in-declaration --- BUILTIN built-in-name, ... ; 117 | * 118 | * built-in-name --- name 119 | */ 120 | class BuiltInAST : public DeclarationAST 121 | { 122 | }; 123 | 124 | /* 125 | * label-declaration --- LABEL label-name, ... ; 126 | * 127 | * label-name --- name 128 | */ 129 | class LabelAST : public DeclarationAST 130 | { 131 | }; 132 | 133 | /* 134 | * undeclare-declaration --- UNDECLARE undeclare-name, ... ; 135 | * 136 | * undeclare-name --- name 137 | */ 138 | class UndeclareAST : public DeclarationAST 139 | { 140 | }; 141 | } 142 | 143 | #endif /* LLVM_BLISS_SPECIALINAST_H */ 144 | -------------------------------------------------------------------------------- /include/bliss/AST/StructureAST.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: StructureAST.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 22, 2019, 1:02 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_STRUCTUREAST_H 26 | #define LLVM_BLISS_STRUCTUREAST_H 27 | 28 | #include "AST/DeclarationAST.h" 29 | 30 | using namespace std; 31 | 32 | namespace bliss 33 | { 34 | 35 | /* 36 | * field-reference --- address -+- field-selector 37 | * +- nothing 38 | * 39 | * address -+- primary 40 | * +- executable-function 41 | * 42 | * field-selector --- < position , size -+- , sign-extension-flag -+- > 43 | * +- nothing ---------------+ 44 | * 45 | * position -+- expression 46 | * size -----+ 47 | * 48 | * sign-extension-flag --- compile-time-constant-expression 49 | */ 50 | class FieldReferenceAST : public DeclarationAST 51 | { 52 | }; 53 | 54 | /* 55 | * structure-declaration --- STRUCTURE structure-definition, ... ; 56 | * 57 | * structure-definition -- structure-name [ -+- access-formal -+--+- : allocation-formal -+- ] = 58 | * +- nothing -------+ +- nothing -------------+ 59 | * 60 | * -+- [ structure-size ] -+- structure-body 61 | * +- nothing ------------+ 62 | * 63 | * allocation-formal --- allocation-name -+- = allocation default 64 | * +- nothing 65 | * 66 | * structure-size -+- expression 67 | * structure-body -+ 68 | * 69 | * structure-name --+ 70 | * access-formal +- name 71 | * allocation-name -+ 72 | * 73 | * allocation-default -- compile-time-constant-expression 74 | */ 75 | class StructureDeclarationAST : public DeclarationAST 76 | { 77 | }; 78 | 79 | /* 80 | * field-declaration --- FIELD -+- field-set-definition -+- , ... ; 81 | * +- field-definition -----+ 82 | * 83 | * field-set-definition --- field-set-name = SET field-definition, ... TES 84 | * 85 | * field-definition --- field-name = [ field-component, ... ] 86 | * 87 | * field-set-name -+- name 88 | * field-name -----+ 89 | * 90 | * field-component --- compile-time-constant-expression 91 | */ 92 | class FieldDeclarationAST : public DeclarationAST 93 | { 94 | }; 95 | 96 | /* 97 | * +- ordinary-structure-reference 98 | * structure-reference -+ default-structure-reference 99 | * +- general-structure-reference 100 | * 101 | * ordinary-structure-reference --- segment-name [ access-actual, ... ] 102 | * 103 | * segment-name --- name 104 | * 105 | * +- field-name 106 | * access-actual -+ expression 107 | * +- nothing 108 | */ 109 | class OrdinaryStructReferenceAST : public DeclarationAST 110 | { 111 | }; 112 | 113 | /* 114 | * default-structure-reference --- address [ access-actual, ... ] 115 | */ 116 | class DefaultStructReferenceAST : public DeclarationAST 117 | { 118 | }; 119 | 120 | /* 121 | * general-structure-reference --- structure-name [ access-part -+- : allocation-actual, ... -+- ] 122 | * +- nothing ------------------+ 123 | * 124 | * access-part --- segment-expression -+- , access-actual, ... 125 | * +- nothing 126 | * 127 | * segment-expression -+- expression 128 | * +- nothing 129 | */ 130 | class GeneralStructReferenceAST : public DeclarationAST 131 | { 132 | }; 133 | 134 | /* 135 | * Predeclared Structures 136 | * 137 | * VECTOR - A vector of signed or unsigned elements of uniform size (BYTE, WORD, LONG, or QUAD) 138 | * BITVECTOR - A vector of 1 bit element 139 | * BLOCK - A sequence of varying-sized fields 140 | * BLOCKBYTE - This structure is functionally equivalent to BLOCK[,BYTE] 141 | * BLOCKVECTOR - A vector of BLOCKs 142 | */ 143 | class BlockDeclarationAST : public DeclarationAST 144 | { 145 | private: 146 | map<> fields; 147 | }; 148 | class VectorDeclarationAST : public DeclarationAST 149 | { 150 | private: 151 | vector<> elements; 152 | uint64_t element_size; 153 | }; 154 | class BitVectorDeclarationAST : public DeclarationAST 155 | { 156 | private: 157 | vector<> bits; 158 | uint64_t numberOfBits; 159 | uint64_t size; // in Bytes 160 | }; 161 | } 162 | 163 | #endif /* LLVM_BLISS_STRUCTUREAST_H */ 164 | -------------------------------------------------------------------------------- /include/bliss/Basic/CommonInclude.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: CommonInclude.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on August 25, 2019, 9:39 AM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_COMMONINCLUDE_H 26 | #define LLVM_BLISS_COMMONINCLUDE_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "llvm/ADT/STLExtras.h" 47 | #if 0 48 | #include "llvm/ADT/APFloat.h" 49 | #include "llvm/ADT/Optional.h" 50 | #include "llvm/IR/BasicBlock.h" 51 | #include "llvm/IR/Constants.h" 52 | #include "llvm/IR/DerivedTypes.h" 53 | #include "llvm/IR/Function.h" 54 | #include "llvm/IR/Instructions.h" 55 | #include "llvm/IR/IRBuilder.h" 56 | #include "llvm/IR/LLVMContext.h" 57 | #include "llvm/IR/LegacyPassManager.h" 58 | #include "llvm/IR/Module.h" 59 | #include "llvm/IR/Type.h" 60 | #include "llvm/IR/Verifier.h" 61 | #include "llvm/Target/TargetMachine.h" 62 | #include "llvm/Target/TargetOptions.h" 63 | #endif 64 | 65 | #define ALLOW_LISTER_INCLUDE 1 66 | #include "Basic/Lister.h" 67 | #undef ALLOW_LISTER_INCLUDE 68 | 69 | #endif /* LLVM_BLISS_COMMONINCLUDE_H */ 70 | -------------------------------------------------------------------------------- /include/bliss/Basic/FileManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: FileManager.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 1, 2019, 5:00 PM 23 | */ 24 | #ifndef LLVM_BLISS_FILEMANAGER_H 25 | #define LLVM_BLISS_FILEMANAGER_H 26 | 27 | #include "Basic/CommonInclude.h" 28 | #include "Basic/InputFile.h" 29 | 30 | namespace bliss 31 | { 32 | 33 | /* 34 | * This class is used to manage all the input files. As a file is processed, a language 35 | * keyword may cause another input file to be read in. This manages these files in 36 | * a file vector, which has files pushed on and popped off of it. 37 | * 38 | * This is a singleton class. Only one is ever created, and indirectly through the 39 | * get() method. 40 | */ 41 | class FileManager 42 | { 43 | public: 44 | 45 | /** 46 | * This function is called to return the address of the one and only FileManager. 47 | * If one has not been instantiated, this call will do so. 48 | * @return A pointer to the FileManager class. 49 | */ 50 | static FileManager *get() 51 | { 52 | if (fmp == nullptr) 53 | { 54 | fmp = new FileManager(); 55 | } 56 | return fmp; 57 | } 58 | 59 | /* SETTERS */ 60 | 61 | /** 62 | * This function is called to open a file and push it onto the stack. 63 | * 64 | * @param fileName - The file to be opened 65 | * @return - true if a file was successfully opened and pushed onto the stack 66 | * - false is there was an error opening the file. 67 | */ 68 | bool pushFile(std::string fileName); 69 | 70 | /** 71 | * This function is called to pop off a file from the stack and delete the 72 | * InputFile (closing the file). 73 | * @return - true if a file was successfully popped off and closed 74 | * - false is there are no more files on the stack. 75 | */ 76 | bool popFile(); 77 | 78 | /* GETTERS */ 79 | 80 | /** 81 | * Get the current file being processed off the top of the list. 82 | * 83 | * @return 84 | */ 85 | InputFile *getCurrentFile(); 86 | 87 | private: 88 | /* CONSTRUCTORS */ 89 | FileManager(){}; // Private constructor 90 | FileManager(FileManager const&) = delete; // Prevent copy constructor 91 | FileManager& operator=(FileManager const&) = delete; // Prevent assignment 92 | 93 | /* DESTRUCTORS */ 94 | ~FileManager(){}; 95 | 96 | /* CLASS DATA */ 97 | static FileManager *fmp; // A pointer to the File Manager 98 | vector files; // A vector of opened files. 99 | }; 100 | } 101 | 102 | #endif /* LLVM_BLISS_FILEMANAGER_H */ 103 | -------------------------------------------------------------------------------- /include/bliss/Basic/InputChar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: InputChar.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 1, 2019, 4:37 PM 23 | */ 24 | #ifndef LLVM_BLISS_INPUTCHAR_H 25 | #define LLVM_BLISS_INPUTCHAR_H 26 | 27 | #include "Basic/CommonInclude.h" 28 | 29 | namespace bliss 30 | { 31 | 32 | /* 33 | * This class is used to store information about a character read in from an input file. 34 | */ 35 | class InputChar 36 | { 37 | public: 38 | 39 | /* 40 | * This enumeration is used to classify the characters read in from the file. 41 | * This list is based on BLISS LRM Section 2.1.1 (pages 2-1 through 2-2). 42 | */ 43 | enum CharClass 44 | { 45 | CCUnknown, 46 | CCPrintLetter, 47 | CCPrintDigit, 48 | CCPrintDelim, 49 | CCPrintSpecial, 50 | CCPrintFree, 51 | CCNonprintSP, 52 | CCNonprintHT, 53 | CCLinemarkVT, 54 | CCLinemarkFF, 55 | CCLinemarkLF, 56 | CCLinemarkCR, 57 | CCEndOfFile 58 | }; 59 | 60 | /* GETTERS */ 61 | 62 | /** 63 | * This function is called to get the character read from the file. 64 | * 65 | * @return ASCII coded character 66 | */ 67 | char getChar() { return inChar; } 68 | 69 | /** 70 | * This function is called to get the line number from where the 71 | * character was read. 72 | * 73 | * @return ASCII coded character 74 | */ 75 | uint32_t getLine() { return inLine; } 76 | 77 | /** 78 | * This function is called to get the column number from where the 79 | * character was read. 80 | * 81 | * @return ASCII coded character 82 | */ 83 | uint32_t getColumn() { return inColumn; } 84 | 85 | /** 86 | * This function is called to get the offset from start of file 87 | * where the character was read. 88 | * 89 | * @return ASCII coded character 90 | */ 91 | uint32_t getOffset() { return inOffset; } 92 | 93 | /** 94 | * This function is called to get the character class associated with the 95 | * character read from the file. 96 | * 97 | * @return An enumeration specifying the character class 98 | */ 99 | CharClass getClass() { return inCharClass; } 100 | 101 | /* SETTERS */ 102 | 103 | /** 104 | * This function is called to save information about the character read 105 | * from the file. 106 | * 107 | * @param nextChar - ASCII coded character 108 | * @param nextCharClass - the Character Classification for nextChar 109 | * @param line - line in the file where nextChar was read 110 | * @param column - column (offset from start of line) in the file where 111 | * nextChar was read 112 | * @param offset - offset, from start of file, where the nextChar was read 113 | */ 114 | void setCharInfo(char nextChar, 115 | CharClass nextCharClass, 116 | uint32_t line, 117 | uint32_t column, 118 | uint32_t offset) 119 | { 120 | inChar = nextChar; 121 | inCharClass = nextCharClass; 122 | inLine = line; 123 | inColumn = column; 124 | inOffset = offset; 125 | } 126 | 127 | /* CONSTRUCTORS */ 128 | InputChar(){}; 129 | InputChar(InputChar const&) = delete; // Prevent copy constructor 130 | InputChar& operator=(InputChar const&) = delete; // Prevent assignment 131 | 132 | /* DESTRUCTORS */ 133 | ~InputChar(){}; 134 | 135 | private: 136 | /* CLASS DATA */ 137 | char inChar; // ASCII coded character read from the file. 138 | CharClass inCharClass; // Character classification enumeration 139 | uint32_t inLine; 140 | uint32_t inColumn; 141 | uint32_t inOffset; 142 | }; 143 | } 144 | 145 | #endif /* LLVM_BLISS_INPUTCHAR_H */ 146 | -------------------------------------------------------------------------------- /include/bliss/Basic/InputFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: InputFile.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 1, 2019, 4:48 PM 23 | */ 24 | #ifndef LLVM_BLISS_INPUTFILE_H 25 | #define LLVM_BLISS_INPUTFILE_H 26 | 27 | #include "Basic/CommonInclude.h" 28 | #include "Basic/InputChar.h" 29 | 30 | #define INPUT_CHAR_DEPTH 2 31 | 32 | using namespace std; 33 | 34 | namespace bliss 35 | { 36 | 37 | /* 38 | * This class is used to read characters from an input file and process them for 39 | * returning back to the caller (for further processing). 40 | */ 41 | class InputFile 42 | { 43 | public: 44 | /* CONSTRUCTORS */ 45 | InputFile(string fn); 46 | InputFile(InputFile const&) = delete; // Prevent copy constructor 47 | InputFile& operator=(InputFile const&) = delete; // Prevent assignment 48 | 49 | /* DESTRUCTOR */ 50 | ~InputFile(); 51 | 52 | /* GETTERS */ 53 | 54 | /** 55 | * Get the next character from the input file. This is actually the previous 56 | * character, as we always read one character ahead from the file. 57 | * 58 | * NOTE: This call is destructive, in that a read in character cannot be 59 | * unread. 60 | * 61 | * @return A pointer to an InputChar class. 62 | */ 63 | InputChar *getNextChar(); 64 | 65 | /** 66 | * Peak at the next character read from the input file that will be returned 67 | * on the next call to getNetChar(). 68 | * 69 | * NOTE: This call is non-destructive, in the successive calls without a 70 | * prior call to getNextChar() will return the same character information. 71 | * 72 | * @return A pointer to an InputChar class 73 | */ 74 | InputChar *peakNextChar(); 75 | 76 | /** 77 | * Push back the character just read from the input file that was returned 78 | * on the call to getNetChar(). 79 | * 80 | * NOTE: This call is destructive, in that the read in characters vector 81 | * is updated to point to the previously read character. The character is 82 | * already in the stack, we are just resetting the index. 83 | * 84 | * @return A pointer to an InputChar class 85 | */ 86 | void pushBackChar(); 87 | 88 | /** 89 | * The function is called to return an indicator that the input file was 90 | * successfully opened. 91 | * 92 | * @return A boolean value indicating that the file was successfully opened 93 | * (true) or not (false). 94 | */ 95 | bool getOpened() { return opened; } 96 | 97 | /** 98 | * This function is called to return an indicator that the end of file has 99 | * been read in and returned on a call to getNextChar(). 100 | * 101 | * @return A boolean value indicating that the EOF has been reached and 102 | * processed (true) or not (false). 103 | */ 104 | bool getEOF() { return atEOF; } 105 | 106 | /** 107 | * This function is called to return the filename string for the file. 108 | * 109 | * @return A string value for the file name. 110 | */ 111 | string getFilename() { return inputFilename; } 112 | 113 | private: 114 | /* SETTERS */ 115 | 116 | /** 117 | * This is a private function to read in a character from the input file and 118 | * determine its Character Classification. 119 | * 120 | * @param where - An integer value indicating where in the charVec the next 121 | * character information should be saved. 122 | */ 123 | void initChars(int where); 124 | 125 | /* CLASS DATA */ 126 | string inputFilename; // Input file name 127 | ifstream *inputStream; // Input file stream 128 | std::array charVec; // Character info vector 129 | bool atEOF; // EOF processed 130 | bool opened; // File opened 131 | bool nextLine; // Increment line counter on next read 132 | bool pushCalled; // A call to pushBackChar was made. 133 | int index; // Index for next character 134 | uint32_t line; // Current line in the file 135 | uint32_t column; // Current column in the file 136 | uint32_t offset; // Current offset in the file 137 | }; 138 | } 139 | 140 | #endif /* LLVM_BLISS_INPUTFILE_H */ 141 | -------------------------------------------------------------------------------- /include/bliss/Basic/Lister.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: Lister.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on October 6, 2019, 10:02 AM 23 | */ 24 | 25 | /* 26 | * This header file should not be included by itself. It should only be included 27 | * in CommonInclude. Check that this is the case. Otherwise, generate an error. 28 | */ 29 | #ifndef ALLOW_LISTER_INCLUDE 30 | #error "Lister.h should never be included directly." 31 | #endif 32 | 33 | #ifndef LLVM_BLISS_LISTER_H 34 | #define LLVM_BLISS_LISTER_H 35 | 36 | using namespace std; 37 | 38 | namespace bliss 39 | { 40 | class Lister 41 | { 42 | 43 | /** 44 | * This function is called to return the address of the one and only Lister. 45 | * If one has not been instantiated, this call will do so. If one has been 46 | * instantiated, then it is just returned. 47 | * 48 | * @return A pointer to the Parser class. 49 | */ 50 | static Lister *get() 51 | { 52 | if (list == nullptr) 53 | { 54 | list = new Lister(); 55 | } 56 | return list; 57 | } 58 | 59 | /** 60 | * Open a listing file. This must be done before any input files are read, 61 | * if we are generating a listing. There is only 1 listing file for each 62 | * input file specified on the command line. REQUIRE files may be output 63 | * in a listing file, but in the listed file for the top most parent input 64 | * file containing the REQUIRE statement. 65 | * 66 | * @param listingFile - a string specifying the listing file to be written. 67 | * @return true - the listing file has been successfully opened for write. 68 | * false - a failure occurred when attempting to open the listing 69 | * file for write. 70 | */ 71 | bool open(string listingFile); 72 | 73 | /** 74 | * This function is called to increment the depth. The depth is incremented 75 | * when starting a new block. 76 | */ 77 | void incrDepth() { depth++; return; }; 78 | 79 | /** 80 | * This function is called to decrement the depth. The depth is decremented 81 | * when ending a block. 82 | */ 83 | void decrDepth() { depth++; return; }; 84 | 85 | /** 86 | * This function is called to add a new character to the end of the current 87 | * listingLine. 88 | * 89 | * TODO: Need to determine when to move to the next line in the listing file. 90 | * 91 | * @param c - An ASCII character value to be added to the listing file. 92 | */ 93 | void addChar(char c); 94 | 95 | private: 96 | 97 | /* CONSTRUCTORS */ 98 | Lister() // Private constructor 99 | { 100 | depth = 0; 101 | currentLine = currentColumn = 0; 102 | listingLine.assign(""); 103 | return; 104 | }; 105 | Lister(Lister const&) = delete; // Prevent copy constructor 106 | Lister& operator=(Lister const&) = delete; // Prevent assignment 107 | 108 | /* DESTRUCTORS */ 109 | ~Lister(){}; 110 | 111 | /* CLASS DATA */ 112 | static Lister *list; 113 | ofstream listingStream; 114 | uint32_t depth; 115 | uint32_t currentLine; 116 | uint32_t currentColumn; 117 | string listingLine; 118 | }; 119 | } 120 | 121 | #endif /* LLVM_BLISS_LISTER_H */ 122 | -------------------------------------------------------------------------------- /include/bliss/Driver/Driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: Driver.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 29, 2019, 10:15 AM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_DRIVER_H 26 | #define LLVM_BLISS_DRIVER_H 27 | 28 | #include "Basic/CommonInclude.h" 29 | #include "Basic/FileManager.h" 30 | #include "FrontEnd/Lexer.h" 31 | #include "FrontEnd/Parser.h" 32 | 33 | using namespace std; 34 | 35 | namespace bliss 36 | { 37 | class Driver 38 | { 39 | public: 40 | 41 | /** 42 | * This function is called to return the address of the one and only Driver. 43 | * If one has not been instantiated, this call will do so. If one has been 44 | * instantiated, then the parameter is ignored. If the parameter is not 45 | * specified or a nullptr when instantiating the class, then the next call 46 | * will need to be to setFiles to supply the file names, one or more, to be 47 | * compiled. 48 | * 49 | * @param files - a vector of strings containing zero or more file names to 50 | * be compiled. 51 | * @return A pointer to the Driver class, if successfully created and 52 | * initialized. 53 | */ 54 | static Driver *get(vector *files = nullptr); 55 | 56 | /** 57 | * This function is called to set the file names to be processed, in order. 58 | * 59 | * @param files - the list of files to be compiled 60 | * @return true - if the files exist and can be read 61 | * false - if one or more files does not exist or cannot be read. 62 | */ 63 | bool setFiles(vector *files); 64 | 65 | /** 66 | * This function is the one that does all the work. It loops until it has 67 | * processed each of the files in the vector of filenames. 68 | */ 69 | void mainLoop(); 70 | 71 | private: 72 | 73 | /* CONSTRUCTORS */ 74 | Driver(); // Private constructor 75 | Driver(Driver const&) = delete; // Prevent copy constructor 76 | Driver& operator=(Driver const&) = delete; // Prevent assignment 77 | 78 | /* DESTRUCTORS */ 79 | ~Driver(); 80 | 81 | /* CLASS DATA */ 82 | static Driver *driver; 83 | FileManager *fileMgr; 84 | Lexer *lex; 85 | Parser *parse; 86 | vector fileNames; 87 | }; 88 | } 89 | 90 | #endif /* LLVM_BLISS_DRIVER_H */ 91 | -------------------------------------------------------------------------------- /include/bliss/FrontEnd/Keyword.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: Keyword.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 2, 2019, 1:04 PM 23 | */ 24 | #ifndef LLVM_BLISS_KEYWORD_H 25 | #define LLVM_BLISS_KEYWORD_H 26 | 27 | #include "Basic/CommonInclude.h" 28 | 29 | using namespace std; 30 | 31 | namespace bliss 32 | { 33 | class KWD 34 | { 35 | public: 36 | enum Keyword 37 | { 38 | _ALLOCATION, _ASCIC, _ASCID, _ASCII, _ASCIZ, 39 | _ASSIGN, _B, _BLISS, _BLISS32, _BLISS64, 40 | _BPADDR, _BPUNIT, _BPVAL, _C, _CHAR, 41 | _CHARCOUNT, _COUNT, _CTCE, _DECIMAL, _DECLARED, 42 | _ELSE, _ERROR, _ERRORMACRO, _EXACTSTRING, _EXITITERATION, 43 | _EXITMACRO, _EXPAND, _EXPLODE, _FI, _FIELDEXPAND, 44 | _IDENTICAL, _IF, _INFORM, _ISSTRING, _LENGTH, 45 | _LTCE, _MESSAGE, _NAME, _NBITS, _NBITSU, 46 | _NULL, _NUMBER, _O, _P, _PRINT, 47 | _QUOTE, _QUOTENAME, _REF, _REMAINING, _REMOVE, 48 | _REQUIRE, _S, _SBTTL, _SIZE, _STRING, 49 | _SWITCHES, _T, _THEN, _TITLE, _UNQUOTE, 50 | _UPVAL, _VARIANT, _WARN, _X, ABS, 51 | ABSOLUTE, ACTUALCOUNT, ACTUALPARAMETER, ADDRESSING_MODE, ALIGN, 52 | ALWAYS, AND, ARGPTR, ASSEMBLY, BEGIN, 53 | BINARY, BIND, BIT, BITVECTOR, BLISS, 54 | BLISS32, BLISS64, BLOCK, BLOCKVECTOR, BUILTIN, 55 | BY, BYTE, CALL, CASE, CH$A_RCHAR, 56 | CH$A_WCHAR, CH$ALLOCATION, CH$COMPARE, CH$COPY, CH$DIFF, 57 | CH$EQL, CH$FAIL, CH$FILL, CH$FIND_CH, CH$FIND_NOT_CH, 58 | CH$FIND_SUB, CH$GEQ, CH$GTR, CH$LEQ, CH$LSS, 59 | CH$MOVE, CH$NEQ, CH$PLUS, CH$PTR, CH$RCHAR, 60 | CH$RCHAR_A, CH$SIZE, CH$TRANSLATE, CH$TRANSTABLE, CH$WCHAR, 61 | CH$WCHAR_A, CODE, CODECOMMENT, COMMENTARY, COMPILETIME, 62 | CONCATENATE, DEBUG, DECR, DECRA, DECRU, 63 | DO, ELSE, ELUDOM, ENABLE, END, 64 | EQL, EQLA, EQLU, EQV, ERRS, 65 | EXECUTE, EXITLOOP, EXPAND, EXTERNAL, FIELD, 66 | FORWARD, FROM, GENERAL, GEQ, GEQA, 67 | GEQU, GLOBAL, GTR, GTRA, GTRU, 68 | IDENT, IF, INCR, INCRA, INCRU, 69 | INITIAL, INRANGE, INTERRUPT, IOPAGE, IOT, 70 | JSB, KEYWORDMACRO, LABEL, LANGUAGE, LEAVE, 71 | LEQ, LEQA, LEQU, LIBRARY, LINKAGE, 72 | LIST, LITERAL, LOCAL, LONG, LONG_RELATIVE, 73 | LSS, LSSA, LSSU, MACRO, MAIN, 74 | MAP, MAX, MAXA, MAXU, MIN, 75 | MINA, MINU, MOD, MODULE, NEQ, 76 | NEQA, NEQU, NOASSEMBLY, NOBINARY, NOCODE, 77 | NOCOMMENTARY, NODEBUG, NODEFAULT, NOERRS, NOEXECUTE, 78 | NOEXPAND, NOLIBRARY, NONEXTERNAL, NOOBJECT, NOOPTIMIZE, 79 | NOPIC, NOPRESERVE, NOREAD, NOREQUIRE, NOSAFE, 80 | NOSHARE, NOSOURCE, NOSYMBOLIC, NOT, NOTRACE, 81 | NOTUSED, NOUNAMES, NOVALUE, NOWRITE, NOZIP, 82 | NULLPARAMETER, OBJECT, OF, OPTIMIZE, OPTLEVEL, 83 | OR, OTHERWISE, OUTRANGE, OVERLAY, OWN, 84 | PIC, PLIT, PRESERVE, PRESET, PSECT, 85 | READ, RECORD, REF, REP, REQUIRE, 86 | RETURN, ROUTINE, SAFE, SELECT, SELECTA, 87 | SELECTONE, SELECTONEA, SELECTONEU, SELECTU, SET, 88 | SETUNWIND, SHARE, SHOW, SIGN, SIGNAL, 89 | SIGNAL_STOP, SIGNED, SOURCE, STACKLOCAL, STANDARD, 90 | STRUCTURE, SWITCHES, SYMBOLIC, TES, THEN, 91 | TO, TRACE, UNAMES, UNDECLARE, UNSIGNED, 92 | UNTIL, UPLIT, VECTOR, VERSION, VOLATILE, 93 | WEAK, WHILE, WITH, WORD, WORD_RELATIVE, 94 | XOR, ZIP, __MAX_ITEMS // Must be last one. 95 | }; 96 | }; 97 | #define KWD_MAX KWD::__MAX_ITEMS 98 | } 99 | 100 | #endif /* LLVM_BLISS_KEYWORD_H */ 101 | -------------------------------------------------------------------------------- /include/bliss/FrontEnd/Lexer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: Lexer.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 1, 2019, 5:37 PM 23 | */ 24 | #ifndef LLVM_BLISS_LEXEMES_H 25 | #define LLVM_BLISS_LEXEMES_H 26 | 27 | #include "Basic/CommonInclude.h" 28 | #include "Basic/FileManager.h" 29 | #include "FrontEnd/Keyword.h" 30 | 31 | using namespace std; 32 | 33 | namespace bliss 34 | { 35 | class Lexer 36 | { 37 | public: 38 | enum LexemeType 39 | { 40 | LTUnknown = 0, // 0 41 | LTKeyword, // 1 42 | LTPredeclared, // 2 43 | LTExplicitDeclared, // 3 44 | LTDecimalLiteral, // 4 45 | LTQuotedString, // 5 46 | LTOperator, // 6 47 | LTPunctuation, // 7 48 | LTLinemark, // 8 49 | LTTrailingComment, // 9 50 | LTEmbeddedComment, // 10 51 | LTPercentSign // 11 - This is not in the LRM, but used to terminate macros 52 | }; 53 | 54 | /** 55 | * This function is called to return the address of the one and only Lexer. 56 | * If one has not been instantiated, this call will do so. If one has been 57 | * instantiated, then it is just returned. 58 | * 59 | * @return A pointer to the Lexer class. 60 | */ 61 | static Lexer *get() 62 | { 63 | if (lex == nullptr) 64 | { 65 | lex = new Lexer(); 66 | } 67 | return lex; 68 | } 69 | 70 | /* GETTERS */ 71 | 72 | /** 73 | * This function is called to return the LexemeType of the current 74 | * lexeme being processed. 75 | * 76 | * @return One of the LexemeType enumerated values. 77 | */ 78 | LexemeType 79 | getType() { return type; } 80 | 81 | /** 82 | * This function is called to return the KWD::Keyword value for the 83 | * current lexeme. This is valid if the LexemeType is either 84 | * LTKeyword or LTPredeclared. 85 | * 86 | * @return One of the KWD::Keyword enumerate values. 87 | */ 88 | KWD::Keyword 89 | getKeyword() { return keyword; } 90 | 91 | /** 92 | * This function is called to return the boolean value for the 93 | * current keyword being reserved or not. 94 | * 95 | * @return true to indicate a reserved keyword 96 | * false to indicate not a reserved keyword 97 | */ 98 | bool 99 | getReserved() { return reserved; } 100 | 101 | /** 102 | * This function is called to get the string associated with the 103 | * current lexeme. This is valid if the LexemeType is either 104 | * LTExplicitDeclared Or LTQuotedString. 105 | * 106 | * @return A string value for the quoted string. 107 | */ 108 | string 109 | getString() { return valueStr; } 110 | 111 | /** 112 | * This function is called to get the value associated with the current 113 | * lexeme. This is valid if the LexemeType is LTDecimalLiteral. 114 | * 115 | * @return A 64-bit decimal value. 116 | */ 117 | uint64_t 118 | getValue() { return value; } 119 | 120 | /** 121 | * This function is called to get the character associated with the 122 | * current lexeme. This is valid if the LexemeType is either 123 | * LTOperator or LTPunctuation. 124 | * 125 | * @return An ASCII coded character. 126 | */ 127 | char 128 | getChar() { return valueChar; } 129 | 130 | /* SETTERS */ 131 | 132 | /** 133 | * This function is called to move to the next lexeme in the current 134 | * input file. The previous lexeme information is overwritten and 135 | * no longer available. 136 | * 137 | * NOTE: Calling this function may get to an end of file prior to 138 | * completely reading in the next lexeme. The function will 139 | * select a reasonable lexeme type and return with a true. 140 | * The next call will return the false value. 141 | * 142 | * @return true - if a lexeme was successfully read in 143 | * false - if an end of file was reached (file fully 144 | * processed). 145 | */ 146 | bool 147 | getNext(); 148 | 149 | /* MISCELLANEOUS */ 150 | 151 | /** 152 | * This function is called to dump the contents of the KeywordTable 153 | * to standard out. 154 | */ 155 | void 156 | dumpTable(); 157 | 158 | private: 159 | 160 | /* CONSTRUCTORS */ 161 | Lexer(); // Private constructor 162 | Lexer(Lexer const&) = delete; // Prevent copy constructor 163 | Lexer& operator=(Lexer const&) = delete; // Prevent assignment 164 | 165 | /* DESTRUCTORS */ 166 | ~Lexer(){}; 167 | 168 | /** 169 | * This function is called when a keyword Lexeme is being parsed. 170 | * 171 | * @param in - InputFile handle 172 | * @return true - if a lexeme was successfully read in 173 | * false - if an end of file was reached (file fully 174 | * processed). 175 | */ 176 | bool 177 | parseKeyword(InputFile *in); 178 | 179 | /** 180 | * This function is called when a Decimal Literal Lexeme is being 181 | * parsed. 182 | * 183 | * @param in - InputFile handle 184 | * @return true - if a lexeme was successfully read in 185 | * false - if an end of file was reached (file fully 186 | * processed). 187 | */ 188 | bool 189 | parseDecimalLiteral(InputFile *in); 190 | 191 | /** 192 | * This function is called when a Quoted String Lexeme is being parsed. 193 | * 194 | * @param in - InputFile handle 195 | * @return true - if a lexeme was successfully read in 196 | * false - if an end of file was reached (file fully 197 | * processed). 198 | */ 199 | bool 200 | parseQuotedString(InputFile *in); 201 | 202 | /** 203 | * This function is called when a Trailing Comment Lexeme is being 204 | * parsed. 205 | * 206 | * @param in - InputFile handle 207 | * @return true - if a lexeme was successfully read in 208 | * false - if an end of file was reached (file fully 209 | * processed). 210 | */ 211 | bool 212 | parseTrailingComment(InputFile *in); 213 | 214 | /** 215 | * This function is called when an Embedded Comment Lexeme is being 216 | * parsed. 217 | * 218 | * @param in - InputFile handle 219 | * @return true - if a lexeme was successfully read in 220 | * false - if an end of file was reached (file fully 221 | * processed). 222 | */ 223 | bool 224 | parseEmbeddedComment(InputFile *in); 225 | 226 | /* CLASS DATA */ 227 | static Lexer *lex; 228 | LexemeType type; 229 | KWD::Keyword keyword; 230 | string valueStr; 231 | uint64_t value; 232 | char valueChar; 233 | bool reserved; 234 | struct _keywordTable *table; 235 | size_t tableSize; 236 | }; 237 | typedef struct _keywordTable 238 | { 239 | string keywordStr; 240 | KWD::Keyword keyword; 241 | Lexer::LexemeType keywordVal; 242 | bool reserved_builtin; 243 | } KeywordTable; 244 | } 245 | 246 | /* 247 | * The following macros are used to file in the KeywordTable. The first 248 | * field is the name of the keyword, which will be converted to a string. 249 | * The second field is the KWD::Keyword enumeration associated with the 250 | * keyword. The final field is an indicator the a KWD::Keyword is reserved 251 | * or KWD::Predefined is for a builtin. 252 | */ 253 | #define KWD_TABLE(x, y, z) { #x, KWD::x, y, z } 254 | #define _KWD_TABLE(x, y, z) { string("%" #x), KWD::_##x, y, z } 255 | 256 | #endif /* LLVM_BLISS_LEXEMES_H */ 257 | -------------------------------------------------------------------------------- /include/bliss/FrontEnd/Parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * File: Parser.h 20 | * Author: Jonathan D. Belanger 21 | * 22 | * Created on September 14, 2019, 12:23 PM 23 | */ 24 | 25 | #ifndef LLVM_BLISS_PARSER_H 26 | #define LLVM_BLISS_PARSER_H 27 | 28 | #include "Basic/CommonInclude.h" 29 | #include "Basic/FileManager.h" 30 | #include "FrontEnd/Keyword.h" 31 | #include "FrontEnd/Lexer.h" 32 | #include "AST/ExprAST.h" 33 | #include "AST/PrimaryAST.h" 34 | #include "AST/OperatorAST.h" 35 | #include "AST/ExecutableFuncAST.h" 36 | #include "AST/ControlAST.h" 37 | #include "AST/ModuleAST.h" 38 | #include "AST/BlockAST.h" 39 | 40 | using namespace std; 41 | 42 | namespace bliss 43 | { 44 | class Parser 45 | { 46 | public: 47 | 48 | /** 49 | * This function is called to return the address of the one and only Parser. 50 | * If one has not been instantiated, this call will do so. If one has been 51 | * instantiated, then it is just returned. 52 | * 53 | * @param lex - A pointer to the lexer that will be used. 54 | * @return A pointer to the Parser class. 55 | */ 56 | static Parser *get(Lexer *lex) 57 | { 58 | if (parse == nullptr) 59 | { 60 | parse = new Parser(lex); 61 | } 62 | return parse; 63 | } 64 | 65 | /* 66 | * The top-level structure is the MODULE, which is terminated by ELUDOM. 67 | */ 68 | void handleModule(); 69 | std::unique_ptr handleModuleHead(); 70 | std::unique_ptr handleModuleBody(); 71 | std::unique_ptr handleBlock(); 72 | 73 | private: 74 | 75 | /* CONSTRUCTORS */ 76 | Parser(Lexer *lex) // Private constructor 77 | { 78 | lexer = lex; 79 | return; 80 | }; 81 | Parser(Parser const&) = delete; // Prevent copy constructor 82 | Parser& operator=(Parser const&) = delete; // Prevent assignment 83 | 84 | /* DESTRUCTORS */ 85 | ~Parser(){}; 86 | 87 | /* CLASS DATA */ 88 | static Parser *parse; 89 | Lexer *lexer; 90 | }; 91 | } 92 | 93 | #endif /* LLVM_BLISS_PARSER_H */ 94 | -------------------------------------------------------------------------------- /lib/Basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(Basic STATIC 2 | InputFile.cpp 3 | FileManager.cpp 4 | ) 5 | -------------------------------------------------------------------------------- /lib/Basic/FileManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | #include "Basic/FileManager.h" 18 | 19 | using namespace std; 20 | using namespace bliss; 21 | 22 | /** 23 | * This function is called to open a file and push it onto the stack. 24 | * 25 | * @param fileName - The file to be opened 26 | * @return - true if a file was successfully opened and pushed onto the stack 27 | * - false is there was an error opening the file. 28 | */ 29 | bool FileManager::pushFile(std::string fileName) 30 | { 31 | InputFile *in = new InputFile(fileName); 32 | bool retVal; 33 | 34 | if (in->getOpened()) 35 | { 36 | files.push_back(in); 37 | retVal = true; 38 | } 39 | else 40 | { 41 | delete in; 42 | in = nullptr; 43 | retVal = false; 44 | } 45 | 46 | return retVal; 47 | } 48 | 49 | /** 50 | * This function is called to pop off a file from the stack and delete the 51 | * InputFile (closing the file). 52 | * 53 | * @return - true if a file was successfully popped off the stack and closed. 54 | * - false if there were no more files to be popped off the stack. 55 | */ 56 | bool FileManager::popFile() 57 | { 58 | bool retVal = false; 59 | 60 | /* 61 | * If there is anything else on the stack, then pop it off and close it. 62 | * Set the return to true. 63 | */ 64 | if (files.size() > 0) 65 | { 66 | InputFile *file = files.back(); 67 | files.pop_back(); 68 | delete file; 69 | retVal = true; 70 | } 71 | 72 | return retVal; 73 | } 74 | 75 | /** 76 | * Get the current file being processed off the top of the list. 77 | * 78 | * @return 79 | */ 80 | InputFile *FileManager::getCurrentFile() 81 | { 82 | InputFile *file = files.back(); 83 | 84 | return file; 85 | } 86 | -------------------------------------------------------------------------------- /lib/Basic/InputFile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | #include "Basic/InputFile.h" 18 | 19 | using namespace std; 20 | using namespace bliss; 21 | 22 | /* 23 | * CONSTRUCTOR 24 | */ 25 | InputFile::InputFile(string fn) 26 | { 27 | inputFilename = fn; 28 | inputStream = new ifstream(fn.c_str()); 29 | opened = inputStream->is_open(); 30 | if (opened) 31 | { 32 | for(int ii = 0; ii < INPUT_CHAR_DEPTH; ii++) 33 | { 34 | charVec[ii] = new InputChar; 35 | } 36 | initChars(0); 37 | } 38 | return; 39 | } 40 | 41 | /* 42 | * DESTRUCTOR 43 | */ 44 | InputFile::~InputFile() 45 | { 46 | if (opened) 47 | { 48 | inputStream->close(); 49 | for(int ii = 0; ii < INPUT_CHAR_DEPTH; ii++) 50 | { 51 | delete charVec[ii]; 52 | } 53 | } 54 | return; 55 | } 56 | /** 57 | * This is a private function to read in a character from the input file and 58 | * determine its Character Classification. 59 | * 60 | * @param where - An integer value indicating where in the charVec the next 61 | * character information should be saved. 62 | */ 63 | void InputFile::initChars(int where) 64 | { 65 | char c = inputStream->get(); 66 | InputChar::CharClass cClass; 67 | 68 | if (inputStream->eof() == true) 69 | { 70 | c = '\0'; 71 | cClass = InputChar::CCEndOfFile; 72 | } 73 | else 74 | { 75 | offset++; // Count every character read, except EOF. 76 | 77 | /* 78 | * If this is the first character read, set the line and 79 | * column to 1. If the last character read was a LF, VT, 80 | * or FF and the current character is not CR, then increment 81 | * the line and set the column to 1. Otherwise, increment 82 | * the column. 83 | */ 84 | if (line == 0) 85 | { 86 | line = column = 1; 87 | } 88 | else if ((nextLine == true) && (c != 0x0d)) 89 | { 90 | line++; 91 | column = 1; 92 | nextLine = false; 93 | } 94 | else 95 | { 96 | column++; 97 | } 98 | nextLine = ((c >= 0x0a) && (c <= 0x0c)); 99 | switch(c) 100 | { 101 | /* (Horizontal) Tab */ 102 | case 0x09: 103 | cClass = InputChar::CCNonprintHT; 104 | break; 105 | 106 | /* Line Feed */ 107 | case 0x0a: 108 | cClass = InputChar::CCLinemarkLF; 109 | break; 110 | 111 | /* Virtical Tab */ 112 | case 0x0b: 113 | cClass = InputChar::CCLinemarkVT; 114 | break; 115 | 116 | /* Form Feed */ 117 | case 0x0c: 118 | cClass = InputChar::CCLinemarkFF; 119 | break; 120 | 121 | /* Carriage Return */ 122 | case 0x0d: 123 | cClass = InputChar::CCLinemarkCR; 124 | break; 125 | 126 | case ' ': 127 | cClass = InputChar::CCNonprintSP; 128 | break; 129 | 130 | /* $ _ % ! ' */ 131 | case '!': case '$': case '%': case '\'': case '_': 132 | cClass = InputChar::CCPrintSpecial; 133 | break; 134 | 135 | /* . ^ * / + - = , ; : ( ) [ ] < > */ 136 | case '(': case ')': case '*': case '+': case ',': 137 | case '-': case '.': case '/': case ':': case ';': 138 | case '<': case '=': case '>': case '[': case ']': 139 | case '^': 140 | cClass = InputChar::CCPrintDelim; 141 | break; 142 | 143 | /* " & ? @ \ ` { | } ~ */ 144 | case '"': case '&': case '?': case '@': case '\\': 145 | case '`': case '{': case '|': case '}': case '~': 146 | cClass = InputChar::CCPrintFree; 147 | break; 148 | 149 | /* A B C ... Z a b c ... z */ 150 | case 'A': case 'B': case 'C': case 'D': case 'E': 151 | case 'F': case 'G': case 'H': case 'I': case 'J': 152 | case 'K': case 'L': case 'M': case 'N': case 'O': 153 | case 'P': case 'Q': case 'R': case 'S': case 'T': 154 | case 'U': case 'V': case 'W': case 'X': case 'Y': 155 | case 'Z': case 'a': case 'b': case 'c': case 'd': 156 | case 'e': case 'f': case 'g': case 'h': case 'i': 157 | case 'j': case 'k': case 'l': case 'm': case 'n': 158 | case 'o': case 'p': case 'q': case 'r': case 's': 159 | case 't': case 'u': case 'v': case 'w': case 'x': 160 | case 'y': case 'z': 161 | cClass = InputChar::CCPrintLetter; 162 | break; 163 | 164 | /* 0 1 2 ... 9 */ 165 | case '0': case '1': case '2': case '3': case '4': 166 | case '5': case '6': case '7': case '8': case '9': 167 | cClass = InputChar::CCPrintDigit; 168 | break; 169 | 170 | default: 171 | cClass = InputChar::CCUnknown; 172 | break; 173 | } 174 | } 175 | charVec[where]->setCharInfo(c, cClass, line, column, offset); 176 | return; 177 | } 178 | 179 | /** 180 | * Get the next character from the input file. This is actually the previous 181 | * character, as we always read one character ahead from the file. 182 | * 183 | * NOTE: This call is destructive, in that a read in character cannot be 184 | * unread. 185 | * 186 | * @return A pointer to an InputChar class. 187 | */ 188 | InputChar *InputFile::getNextChar() 189 | { 190 | int retIndex = index; 191 | 192 | if ((opened == true) && (atEOF == false)) 193 | { 194 | if (charVec[retIndex]->getClass() != InputChar::CCEndOfFile) 195 | { 196 | index++; 197 | index %= INPUT_CHAR_DEPTH; 198 | 199 | /* 200 | * If pushBackChar() was called, then don't bother reading in the 201 | * next character from the file. We already have what we need. 202 | */ 203 | if (pushCalled == false) 204 | { 205 | initChars(index); 206 | } 207 | else 208 | { 209 | pushCalled = false; 210 | } 211 | } 212 | else 213 | { 214 | atEOF = true; 215 | } 216 | } 217 | return charVec[retIndex]; 218 | } 219 | 220 | /** 221 | * Peak at the next character read from the input file that will be returned 222 | * on the next call to getNetChar(). 223 | * 224 | * NOTE: This call is non-destructive, in the successive calls without a 225 | * prior call to getNextChar() will return the same character information. 226 | * 227 | * @return A pointer to an InputChar class 228 | */ 229 | InputChar *InputFile::peakNextChar() 230 | { 231 | return charVec[index]; 232 | } 233 | 234 | /** 235 | * Push back the character just read from the input file that was returned 236 | * on the call to getNetChar(). 237 | * 238 | * NOTE: This call is destructive, in that the read in characters vector 239 | * is updated to point to the previously read character. The character is 240 | * already in the stack, we are just resetting the index. 241 | * 242 | * @return A pointer to an InputChar class 243 | */ 244 | void InputFile::pushBackChar() 245 | { 246 | 247 | /* 248 | * If this function was previously called, or no characters have been read 249 | * in, then don't do anything and just return. 250 | */ 251 | if ((pushCalled == false) && (index != -1)) 252 | { 253 | 254 | /* 255 | * If the index is equal to 0, then set it to the maximum. Otherwise, 256 | * subtract one and set the pushCalled flag. 257 | */ 258 | index = (index == 0 ? INPUT_CHAR_DEPTH : index) - 1; 259 | pushCalled = true; 260 | } 261 | return; 262 | } 263 | -------------------------------------------------------------------------------- /lib/Driver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(Driver STATIC 2 | Driver.cpp 3 | ) 4 | -------------------------------------------------------------------------------- /lib/FrontEnd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(FrontEnd STATIC 2 | Lexer.cpp 3 | Parser.cpp 4 | ) 5 | -------------------------------------------------------------------------------- /lib/FrontEnd/Parser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Jonathan D. Belanger 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | #include "FrontEnd/Parser.h" 18 | 19 | using namespace std; 20 | using namespace bliss; 21 | 22 | /* 23 | * The top-level structure is the MODULE, which is terminated by ELUDOM. 24 | * 25 | * module --- MODULE module-head = module-body ELUDOM 26 | */ 27 | void Parser::handleModule() 28 | { 29 | if (lexer->getNext()) // eat the MODULE 30 | { 31 | if (lexer->getType() != Lexer::LTExplicitDeclared) 32 | { 33 | cerr << "Expected module-name\n"; 34 | return; 35 | } 36 | auto module = handleModuleHead(); 37 | 38 | if (module) 39 | { 40 | auto block = handleModuleBody(); 41 | cerr << "Parsed a MODULE...ELUDOM\n"; 42 | } 43 | else 44 | { 45 | cerr << "Failed to parse a MODULE\n"; 46 | } 47 | } 48 | else 49 | { 50 | cerr << "Unexpected end-of-file\n"; 51 | } 52 | return; 53 | } 54 | 55 | /* 56 | * This function is responsible for parsing the module-head. 57 | * 58 | * module-head --- module-name -+- ( module-switch, ... ) 59 | * +- nothing 60 | * 61 | * @return pointer to ModuleAST. 62 | */ 63 | std::unique_ptr Parser::handleModuleHead() 64 | { 65 | while (true) 66 | { 67 | Lexer::LexemeType type = lexer->getType(); 68 | 69 | if ((type == Lexer::LTTrailingComment) || 70 | (type == Lexer::LTEmbeddedComment)) 71 | { 72 | if (lexer->getNext()) 73 | { 74 | continue; 75 | } 76 | return nullptr; 77 | } 78 | else if (type == Lexer::LTExplicitDeclared) 79 | { 80 | auto module = llvm::make_unique(lexer->getString()); 81 | if (module) 82 | { 83 | 84 | /* 85 | * If moving on to the next lexeme returns an EOF 86 | * indicator, then there is nothing more to do here. 87 | * Return what we have back to the caller. 88 | */ 89 | if (lexer->getNext()) // eat the module name 90 | { 91 | if ((lexer->getType() == Lexer::LTOperator) && 92 | (lexer->getChar() == '=')) 93 | { 94 | lexer->getNext(); // eat the equal sign 95 | } 96 | else if ((lexer->getType() == Lexer::LTPunctuation) && 97 | (lexer->getChar() == '(')) 98 | { 99 | cout << "Need to process module switches\n"; 100 | } 101 | else 102 | { 103 | cerr << "Unexpected lexical, " << lexer->getType() << "\n"; 104 | } 105 | } 106 | return std::move(module); 107 | } 108 | else 109 | { 110 | cerr << "Failed to allocate a MODULE AST\n"; 111 | return nullptr; 112 | } 113 | } 114 | else 115 | { 116 | cerr << "Expected module-name\n"; 117 | return nullptr; 118 | } 119 | } 120 | } 121 | 122 | /* 123 | * This function is responsible for parsing the module-body 124 | * 125 | * module-body --- block 126 | * 127 | * @return pointer to BlockAST. 128 | */ 129 | std::unique_ptr Parser::handleModuleBody() 130 | { 131 | while(true) 132 | { 133 | switch (lexer->getType()) 134 | { 135 | case Lexer::LTEmbeddedComment: 136 | case Lexer::LTTrailingComment: 137 | break; 138 | 139 | case Lexer::LTPunctuation: 140 | if (lexer->getChar() == '(') 141 | { 142 | cout << "Got open parenthesis '('\n"; 143 | return handleBlock(); 144 | } 145 | else 146 | { 147 | cerr << "Got unexpected punctuation, " << lexer->getChar() << "\n"; 148 | } 149 | break; 150 | 151 | case Lexer::LTKeyword: 152 | switch (lexer->getKeyword()) 153 | { 154 | case KWD::BEGIN: 155 | cout << "Got BEGIN\n"; 156 | return handleBlock(); 157 | 158 | case KWD::ELUDOM: 159 | lexer->getNext(); // eat the ELUDOM 160 | return nullptr; 161 | 162 | default: 163 | cout << "Got an unexpected keyword, " << lexer->getString() << "\n"; 164 | return nullptr; 165 | } 166 | break; 167 | 168 | default: 169 | cout << "Got and unexpected lexical: " << lexer->getType() << "\n"; 170 | return nullptr; 171 | } 172 | if (lexer->getNext() == false) 173 | { 174 | return nullptr; 175 | } 176 | } 177 | } 178 | 179 | /* 180 | * This function is responsible for parsing the block. A block is either 181 | * labeled or unlabeled. 182 | * 183 | * block -+- labeled-block 184 | * +- unlabeled-block 185 | * 186 | * labeled-block --- {label: }... unlabeled-block 187 | * 188 | * unlabeled-block -+- BEGIN block-body END 189 | * +- ( block-body ) 190 | */ 191 | std::unique_ptr Parser::handleBlock() 192 | { 193 | bool beginFound = lexer->getType() == Lexer::LTKeyword; 194 | 195 | if (lexer->getNext()) 196 | { 197 | cout << "Got the start of the module block\n"; 198 | if (lexer->getType() == Lexer::LTKeyword) 199 | { 200 | cout << "Got keyword " << lexer->getString() << "\n"; 201 | if (lexer->getKeyword() == KWD::END) 202 | { 203 | lexer->getNext(); // eat the END 204 | if (beginFound) 205 | { 206 | return nullptr; 207 | } 208 | else 209 | { 210 | cerr << "module block started with ( terminated with END\n"; 211 | } 212 | } 213 | else 214 | { 215 | cerr << "unexpected keyword found, " << lexer->getString() << "\n"; 216 | } 217 | } 218 | else if (lexer->getType() == Lexer::LTPunctuation) 219 | { 220 | cout << "Got punctuation '" << lexer->getChar() << "'\n"; 221 | if (lexer->getChar() == ')') 222 | { 223 | lexer->getNext(); // eat the ')' 224 | if (beginFound) 225 | { 226 | cerr << "module block started with BEGIN terminated with ')'\n"; 227 | } 228 | else 229 | { 230 | return nullptr; 231 | } 232 | } 233 | else 234 | { 235 | cerr << "unexpected punctuation found, '" << lexer->getChar() << "'\n"; 236 | } 237 | } 238 | else 239 | { 240 | cerr << "unexpected lexeme in module block processing, " << lexer->getType() << "\n"; 241 | } 242 | } 243 | else 244 | { 245 | cerr << "Unexpected end-of-file detected\n"; 246 | } 247 | return nullptr; 248 | } 249 | -------------------------------------------------------------------------------- /nbproject/configurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | AttributeAST.h 9 | BaseAST.h 10 | BindingAST.h 11 | BlockAST.h 12 | CompileTimeAST.h 13 | ConditionHandlingAST.h 14 | ConstantAST.h 15 | ControlAST.h 16 | DataAST.h 17 | DeclarationAST.h 18 | ExecutableFuncAST.h 19 | ExprAST.h 20 | IncludeAST.h 21 | LexicalAST.h 22 | LinkageAST.h 23 | MacroAST.h 24 | ModuleAST.h 25 | OperatorAST.h 26 | PrimaryAST.h 27 | RoutineAST.h 28 | SpecialAST.h 29 | StructureAST.h 30 | 31 | 32 | Lister.h 33 | 34 | 35 | Driver.h 36 | 37 | 38 | Keyword.h 39 | Parser.h 40 | 41 | 42 | 43 | 44 | 45 | FileManager.cpp 46 | InputFile.cpp 47 | 48 | 49 | Driver.cpp 50 | 51 | 52 | Lexer.cpp 53 | Parser.cpp 54 | 55 | 56 | 57 | 58 | module_test_01.b64 59 | 60 | 61 | bliss.cpp 62 | 63 | 67 | CMakeLists.txt 68 | Makefile 69 | nbproject/private/launcher.properties 70 | 71 | 72 | ^(nbproject)$ 73 | 74 | . 75 | 76 | Makefile 77 | 78 | 79 | 80 | default 81 | false 82 | false 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | build 92 | ${MAKE} -f Makefile 93 | ${MAKE} -f Makefile clean 94 | 95 | 96 | 97 | /home/belanger/projects/bliss/include/bliss 98 | 99 | 100 | _GNU_SOURCE 101 | __STDC_CONSTANT_MACROS 102 | __STDC_FORMAT_MACROS 103 | __STDC_LIMIT_MACROS 104 | 105 | 106 | 107 | 108 | build 109 | ${CMAKE} -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${IDE_CC} -DCMAKE_CXX_COMPILER=${IDE_CXX} -DCMAKE_C_FLAGS_DEBUG="-g3 -gdwarf-2" -DCMAKE_CXX_FLAGS_DEBUG="-g3 -gdwarf-2" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. 110 | true 111 | 112 | 113 | 114 | 115 | 116 | include/bliss 117 | build 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | ../llvm-project/build/lib/clang/10.0.0/include 183 | ../llvm-project/build/include 184 | ../llvm-project/llvm/include 185 | include/bliss 186 | 187 | 188 | 189 | 190 | 191 | 192 | include/bliss 193 | build/lib/Basic 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /nbproject/private/c_standard_headers_indexer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * Oracle and Java are registered trademarks of Oracle and/or its affiliates. 7 | * Other names may be trademarks of their respective owners. 8 | * 9 | * The contents of this file are subject to the terms of either the GNU 10 | * General Public License Version 2 only ("GPL") or the Common 11 | * Development and Distribution License("CDDL") (collectively, the 12 | * "License"). You may not use this file except in compliance with the 13 | * License. You can obtain a copy of the License at 14 | * http://www.netbeans.org/cddl-gplv2.html 15 | * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the 16 | * specific language governing permissions and limitations under the 17 | * License. When distributing the software, include this License Header 18 | * Notice in each file and include the License file at 19 | * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this 20 | * particular file as subject to the "Classpath" exception as provided 21 | * by Oracle in the GPL Version 2 section of the License file that 22 | * accompanied this code. If applicable, add the following below the 23 | * License Header, with the fields enclosed by brackets [] replaced by 24 | * your own identifying information: 25 | * "Portions Copyrighted [year] [name of copyright owner]" 26 | * 27 | * If you wish your version of this file to be governed by only the CDDL 28 | * or only the GPL Version 2, indicate your decision by adding 29 | * "[Contributor] elects to include this software in this distribution 30 | * under the [CDDL or GPL Version 2] license." If you do not indicate a 31 | * single choice of license, a recipient has the option to distribute 32 | * your version of this file under either the CDDL, the GPL Version 2 or 33 | * to extend the choice of license to its licensees as provided above. 34 | * However, if you add GPL Version 2 code and therefore, elected the GPL 35 | * Version 2 license, then the option applies only if the new code is 36 | * made subject to such option by the copyright holder. 37 | * 38 | * Contributor(s): 39 | */ 40 | 41 | // List of standard headers was taken in http://en.cppreference.com/w/c/header 42 | 43 | #include // Conditionally compiled macro that compares its argument to zero 44 | #include // Functions to determine the type contained in character data 45 | #include // Macros reporting error conditions 46 | #include // Limits of float types 47 | #include // Sizes of basic types 48 | #include // Localization utilities 49 | #include // Common mathematics functions 50 | #include // Nonlocal jumps 51 | #include // Signal handling 52 | #include // Variable arguments 53 | #include // Common macro definitions 54 | #include // Input/output 55 | #include // String handling 56 | #include // General utilities: memory management, program utilities, string conversions, random numbers 57 | #include // Time/date utilities 58 | #include // (since C95) Alternative operator spellings 59 | #include // (since C95) Extended multibyte and wide character utilities 60 | #include // (since C95) Wide character classification and mapping utilities 61 | #ifdef _STDC_C99 62 | #include // (since C99) Complex number arithmetic 63 | #include // (since C99) Floating-point environment 64 | #include // (since C99) Format conversion of integer types 65 | #include // (since C99) Boolean type 66 | #include // (since C99) Fixed-width integer types 67 | #include // (since C99) Type-generic math (macros wrapping math.h and complex.h) 68 | #endif 69 | #ifdef _STDC_C11 70 | #include // (since C11) alignas and alignof convenience macros 71 | #include // (since C11) Atomic types 72 | #include // (since C11) noreturn convenience macros 73 | #include // (since C11) Thread library 74 | #include // (since C11) UTF-16 and UTF-32 character utilities 75 | #endif 76 | -------------------------------------------------------------------------------- /nbproject/private/configurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | CMakeCCompilerId.c 12 | 13 | 14 | 15 | 16 | CMakeCXXCompilerId.cpp 17 | 18 | 19 | 20 | 21 | 22 | testCXXCompiler.cxx 23 | 24 | 25 | 26 | feature_tests.c 27 | feature_tests.cxx 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | AttributeAST.h 56 | BaseAST.h 57 | BindingAST.h 58 | BlockAST.h 59 | CompileTimeAST.h 60 | ConditionHandlingAST.h 61 | ConstantAST.h 62 | ControlAST.h 63 | DataAST.h 64 | DeclarationAST.h 65 | ExecutableFuncAST.h 66 | ExprAST.h 67 | IncludeAST.h 68 | LexicalAST.h 69 | LinkageAST.h 70 | MacroAST.h 71 | ModuleAST.h 72 | OperatorAST.h 73 | PrimaryAST.h 74 | RoutineAST.h 75 | SpecialAST.h 76 | StructureAST.h 77 | 78 | 79 | CommonInclude.h 80 | FileManager.h 81 | InputChar.h 82 | InputFile.h 83 | Lister.h 84 | 85 | 86 | Driver.h 87 | 88 | 89 | Keyword.h 90 | Lexer.h 91 | Parser.h 92 | 93 | 94 | 95 | 96 | 97 | FileManager.cpp 98 | InputFile.cpp 99 | 100 | 101 | Driver.cpp 102 | 103 | 104 | Lexer.cpp 105 | Parser.cpp 106 | 107 | 108 | 109 | 110 | module_test_01.b64 111 | 112 | 113 | 114 | 115 | 116 | testharness.c 117 | 118 | bliss.cpp 119 | 120 | 121 | Makefile 122 | 123 | 124 | 125 | localhost 126 | 2 127 | 128 | 129 | 130 | . 131 | ${AUTO_FOLDER} 132 | 133 | ${AUTO_FOLDER} 134 | 135 | ${MAKE} ${ITEM_NAME}.o 136 | ${AUTO_COMPILE} 137 | 138 | ${AUTO_COMPILE} 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | gdb 154 | 155 | 156 | 157 | "${OUTPUT_PATH}" 158 | 159 | "${OUTPUT_PATH}" 160 | . 161 | false 162 | 0 163 | 0 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /nbproject/private/cpp_standard_headers_indexer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | * 4 | * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. 5 | * 6 | * Oracle and Java are registered trademarks of Oracle and/or its affiliates. 7 | * Other names may be trademarks of their respective owners. 8 | * 9 | * The contents of this file are subject to the terms of either the GNU 10 | * General Public License Version 2 only ("GPL") or the Common 11 | * Development and Distribution License("CDDL") (collectively, the 12 | * "License"). You may not use this file except in compliance with the 13 | * License. You can obtain a copy of the License at 14 | * http://www.netbeans.org/cddl-gplv2.html 15 | * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the 16 | * specific language governing permissions and limitations under the 17 | * License. When distributing the software, include this License Header 18 | * Notice in each file and include the License file at 19 | * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this 20 | * particular file as subject to the "Classpath" exception as provided 21 | * by Oracle in the GPL Version 2 section of the License file that 22 | * accompanied this code. If applicable, add the following below the 23 | * License Header, with the fields enclosed by brackets [] replaced by 24 | * your own identifying information: 25 | * "Portions Copyrighted [year] [name of copyright owner]" 26 | * 27 | * If you wish your version of this file to be governed by only the CDDL 28 | * or only the GPL Version 2, indicate your decision by adding 29 | * "[Contributor] elects to include this software in this distribution 30 | * under the [CDDL or GPL Version 2] license." If you do not indicate a 31 | * single choice of license, a recipient has the option to distribute 32 | * your version of this file under either the CDDL, the GPL Version 2 or 33 | * to extend the choice of license to its licensees as provided above. 34 | * However, if you add GPL Version 2 code and therefore, elected the GPL 35 | * Version 2 license, then the option applies only if the new code is 36 | * made subject to such option by the copyright holder. 37 | * 38 | * Contributor(s): 39 | */ 40 | 41 | // List of standard headers was taken in http://en.cppreference.com/w/cpp/header 42 | 43 | #include // General purpose utilities: program control, dynamic memory allocation, random numbers, sort and search 44 | #include // Functions and macro constants for signal management 45 | #include // Macro (and function) that saves (and jumps) to an execution context 46 | #include // Handling of variable length argument lists 47 | #include // Runtime type information utilities 48 | #include // std::bitset class template 49 | #include // Function objects, designed for use with the standard algorithms 50 | #include // Various utility components 51 | #include // C-style time/date utilites 52 | #include // typedefs for types such as size_t, NULL and others 53 | #include // Low-level memory management utilities 54 | #include // Higher level memory management utilities 55 | #include // limits of integral types 56 | #include // limits of float types 57 | #include // standardized way to query properties of arithmetic types 58 | #include // Exception handling utilities 59 | #include // Standard exception objects 60 | #include // Conditionally compiled macro that compares its argument to zero 61 | #include // Macro containing the last error number 62 | #include // functions to determine the type contained in character data 63 | #include // functions for determining the type of wide character data 64 | #include // various narrow character string handling functions 65 | #include // various wide and multibyte string handling functions 66 | #include // std::basic_string class template 67 | #include // std::vector container 68 | #include // std::deque container 69 | #include // std::list container 70 | #include // std::set and std::multiset associative containers 71 | #include // std::map and std::multimap associative containers 72 | #include // std::stack container adaptor 73 | #include // std::queue and std::priority_queue container adaptors 74 | #include // Algorithms that operate on containers 75 | #include // Container iterators 76 | #include // Common mathematics functions 77 | #include // Complex number type 78 | #include // Class for representing and manipulating arrays of values 79 | #include // Numeric operations on values in containers 80 | #include // forward declarations of all classes in the input/output library 81 | #include // std::ios_base class, std::basic_ios class template and several typedefs 82 | #include // std::basic_istream class template and several typedefs 83 | #include // std::basic_ostream, std::basic_iostream class templates and several typedefs 84 | #include // several standard stream objects 85 | #include // std::basic_fstream, std::basic_ifstream, std::basic_ofstream class templates and several typedefs 86 | #include // std::basic_stringstream, std::basic_istringstream, std::basic_ostringstream class templates and several typedefs 87 | #include // std::strstream, std::istrstream, std::ostrstream(deprecated) 88 | #include // Helper functions to control the format or input and output 89 | #include // std::basic_streambuf class template 90 | #include // C-style input-output functions 91 | #include // Localization utilities 92 | #include // C localization utilities 93 | #include // empty header. The macros that appear in iso646.h in C are keywords in C++ 94 | #if __cplusplus >= 201103L 95 | #include // (since C++11) std::type_index 96 | #include // (since C++11) Compile-time type information 97 | #include // (since C++11) C++ time utilites 98 | #include // (since C++11) std::initializer_list class template 99 | #include // (since C++11) std::tuple class template 100 | #include // (since C++11) Nested allocator class 101 | #include // (since C++11) fixed-size types and limits of other types 102 | #include // (since C++11) formatting macros , intmax_t and uintmax_t math and conversions 103 | #include // (since C++11) defines std::error_code, a platform-dependent error code 104 | #include // (since C++11) C-style Unicode character conversion functions 105 | #include // (since C++11) std::array container 106 | #include // (since C++11) std::forward_list container 107 | #include // (since C++11) std::unordered_set and std::unordered_multiset unordered associative containers 108 | #include // (since C++11) std::unordered_map and std::unordered_multimap unordered associative containers 109 | #include // (since C++11) Random number generators and distributions 110 | #include // (since C++11) Compile-time rational arithmetic 111 | #include // (since C++11) Floating-point environment access functions 112 | #include // (since C++11) Unicode conversion facilities 113 | #include // (since C++11) Classes, algorithms and iterators to support regular expression processing 114 | #include // (since C++11) Atomic operations library 115 | #include // (since C++11)(deprecated in C++17) simply includes the header 116 | #include // (since C++11)(deprecated in C++17) simply includes the headers (until C++17) (since C++17) and : the overloads equivalent to the contents of the C header tgmath.h are already provided by those headers 117 | #include // (since C++11)(deprecated in C++17) defines one compatibility macro constant 118 | #include // (since C++11)(deprecated in C++17) defines one compatibility macro constant 119 | #include // (since C++11) std::thread class and supporting functions 120 | #include // (since C++11) mutual exclusion primitives 121 | #include // (since C++11) primitives for asynchronous computations 122 | #include // (since C++11) thread waiting conditions 123 | #endif 124 | #if __cplusplus >= 201300L 125 | #include // (since C++14) shared mutual exclusion primitives 126 | #endif 127 | #if __cplusplus >= 201500L 128 | #include // (since C++17) std::any class template 129 | #include // (since C++17) std::optional class template 130 | #include // (since C++17) std::variant class template 131 | #include // (since C++17) Polymorphic allocators and memory resources 132 | #include // (since C++17) std::basic_string_view class template 133 | #include // (since C++17) Predefined execution policies for parallel versions of the algorithms 134 | #include // (since C++17) std::path class and supporting functions 135 | #endif 136 | -------------------------------------------------------------------------------- /nbproject/private/launcher.properties: -------------------------------------------------------------------------------- 1 | # Launchers File syntax: 2 | # 3 | # [Must-have property line] 4 | # launcher1.runCommand= 5 | # [Optional extra properties] 6 | # launcher1.displayName= 7 | # launcher1.hide= 8 | # launcher1.buildCommand= 9 | # launcher1.runDir= 10 | # launcher1.runInOwnTab= 11 | # launcher1.symbolFiles= 12 | # launcher1.env.= 13 | # (If this value is quoted with ` it is handled as a native command which execution result will become the value) 14 | # [Common launcher properties] 15 | # common.runDir= 16 | # (This value is overwritten by a launcher specific runDir value if the latter exists) 17 | # common.env.= 18 | # (Environment variables from common launcher are merged with launcher specific variables) 19 | # common.symbolFiles= 20 | # (This value is overwritten by a launcher specific symbolFiles value if the latter exists) 21 | # 22 | # In runDir, symbolFiles and env fields you can use these macroses: 23 | # ${PROJECT_DIR} - project directory absolute path 24 | # ${OUTPUT_PATH} - linker output path (relative to project directory path) 25 | # ${OUTPUT_BASENAME}- linker output filename 26 | # ${TESTDIR} - test files directory (relative to project directory path) 27 | # ${OBJECTDIR} - object files directory (relative to project directory path) 28 | # ${CND_DISTDIR} - distribution directory (relative to project directory path) 29 | # ${CND_BUILDDIR} - build directory (relative to project directory path) 30 | # ${CND_PLATFORM} - platform name 31 | # ${CND_CONF} - configuration name 32 | # ${CND_DLIB_EXT} - dynamic library extension 33 | # 34 | # All the project launchers must be listed in the file! 35 | # 36 | # launcher1.runCommand=... 37 | # launcher2.runCommand=... 38 | # ... 39 | # common.runDir=... 40 | # common.env.KEY=VALUE 41 | 42 | # launcher1.runCommand= -------------------------------------------------------------------------------- /nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | 7 | 0 8 | 0 9 | 10 | 11 | 12 | 13 | file:/home/belanger/projects/bliss/include/bliss/FrontEnd/Lexer.h 14 | file:/home/belanger/projects/bliss/include/bliss/Basic/InputChar.h 15 | file:/home/belanger/projects/bliss/include/bliss/FrontEnd/Keyword.h 16 | file:/home/belanger/projects/bliss/lib/Driver/Driver.cpp 17 | file:/home/belanger/projects/bliss/include/bliss/AST/BlockAST.h 18 | file:/home/belanger/projects/bliss/include/bliss/Basic/InputFile.h 19 | file:/home/belanger/projects/bliss/include/bliss/FrontEnd/Parser.h 20 | file:/home/belanger/projects/bliss/tests/AST/module_test_01.b64 21 | file:/home/belanger/projects/bliss/lib/FrontEnd/Parser.cpp 22 | file:/home/belanger/projects/bliss/lib/FrontEnd/Lexer.cpp 23 | file:/home/belanger/projects/bliss/CMakeLists.txt 24 | file:/home/belanger/projects/bliss/include/bliss/Driver/Driver.h 25 | file:/home/belanger/projects/bliss/include/bliss/Basic/Lister.h 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.cnd.makeproject 4 | 5 | 6 | bliss 7 | c 8 | cpp,cxx 9 | h 10 | UTF-8 11 | 12 | 13 | . 14 | 15 | 16 | 17 | Default 18 | 0 19 | 20 | 21 | 22 | false 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/AST/module_test_01.b64: -------------------------------------------------------------------------------- 1 | %( This is a trailing comment this is comprised of just one line )% 2 | ! This is a line comment all by itself 3 | %( This is a multi-line trailing comment 4 | 5 | Copyright (C) 2019 Jonathan D. Belanger 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | )% 20 | MODULE TEST_01 = ! This is a line comment at the end of an existing statement 21 | BEGIN 22 | END 23 | ELUDOM 24 | -------------------------------------------------------------------------------- /tests/expression/controlexp.bli: -------------------------------------------------------------------------------- 1 | MODULE test = 2 | BEGIN 3 | 4 | LIBRARY 'testharness.lib'; 5 | 6 | 7 | test_setup(numcases=10); 8 | 9 | GLOBAL ROUTINE runtest (caseno) : NOVALUE = 10 | BEGIN 11 | LOCAL 12 | val; 13 | 14 | IF .caseno GEQ 1 AND .caseno LEQ 3 THEN 15 | BEGIN 16 | val = (IF .caseno EQL 1 THEN 7654 17 | ELSE IF .caseno EQL 2 THEN 3210 18 | ELSE 9876); 19 | !! 1 7654 20 | !! 2 3210 21 | !! 3 9876 22 | END 23 | ELSE IF .caseno EQL 4 THEN 24 | BEGIN 25 | LOCAL n; 26 | n = 1; 27 | val = 0; 28 | WHILE .n LEQ 100 DO 29 | BEGIN 30 | val = .val + .n; 31 | n = .n * 10; 32 | END; 33 | !! 4 111 34 | END 35 | ELSE IF .caseno EQL 5 THEN 36 | BEGIN 37 | LOCAL n; 38 | n = 1000; 39 | val = 111; 40 | DO 41 | BEGIN 42 | n = .n / 10; 43 | val = .val - .n; 44 | END 45 | UNTIL .n LEQ 1; 46 | !! 5 0 47 | END 48 | ELSE IF .caseno EQL 6 THEN 49 | BEGIN 50 | val = 1; 51 | INCR i FROM 0 TO 100 BY 10 DO val = .val + .i; 52 | DECR i FROM 100 TO 0 BY 10 DO val = .val - .i; 53 | !! 6 1 54 | END 55 | ELSE IF .caseno EQL 7 THEN 56 | BEGIN 57 | LOCAL n; 58 | n = 0; 59 | val = (WHILE .n LSS 100 DO 60 | BEGIN 61 | n = .n + 20; 62 | IF .n GEQ 40 THEN EXITLOOP .n * 5; 63 | END); 64 | !! 7 200 65 | END 66 | ELSE IF .caseno EQL 8 THEN 67 | BEGIN 68 | SELECTONE .caseno OF 69 | SET 70 | [8] : val = 999; 71 | [OTHERWISE] : val = 0; 72 | TES; 73 | !! 8 999 74 | END 75 | ELSE IF .caseno EQL 9 THEN 76 | BEGIN 77 | SELECT .caseno OF 78 | SET 79 | [8] : val = 999; 80 | [OTHERWISE] : val = 0; 81 | [ALWAYS] : val = 333; 82 | TES; 83 | !! 9 333 84 | END 85 | ELSE IF .caseno EQL 10 THEN 86 | BEGIN 87 | LABEL outer; 88 | val = 0; 89 | outer: BEGIN 90 | INCR i FROM 1 TO 100 DO 91 | BEGIN 92 | val = .val + .i; 93 | IF .i GEQ 20 THEN LEAVE outer; 94 | END; 95 | END; ! outer 96 | !! 10 210 97 | END; 98 | test_output(.caseno, '%ld', .val); 99 | 100 | END; 101 | 102 | END 103 | ELUDOM 104 | -------------------------------------------------------------------------------- /tests/expression/operators.bli: -------------------------------------------------------------------------------- 1 | MODULE test = 2 | BEGIN 3 | 4 | LIBRARY 'testharness.lib'; 5 | 6 | 7 | OWN 8 | yesno : VECTOR [2] INITIAL(UPLIT(%ASCIZ'NO'),UPLIT(%ASCIZ'YES')); 9 | 10 | test_setup(numcases=29); 11 | 12 | GLOBAL ROUTINE runtest (caseno) : NOVALUE = 13 | BEGIN 14 | LOCAL 15 | a, b, val; 16 | 17 | a = 12; 18 | b = 6; 19 | 20 | CASE .caseno FROM 1 TO 29 OF 21 | SET 22 | [1] : val = +.a; 23 | !! 1 12 24 | [2] : val = -.a; 25 | !! 2 -12 26 | [3] : val = .a + .b; 27 | !! 3 18 28 | [4] : val = -.a + (-.b); 29 | !! 4 -18 30 | [5] : val = .a - .b; 31 | !! 5 6 32 | [6] : val = .a * .b; 33 | !! 6 72 34 | [7] : val = .a / .b; 35 | !! 7 2 36 | [8] : val = .a MOD .b; 37 | !! 8 0 38 | [9] : val = .a ^ .b; 39 | !! 9 768 40 | [10] : val = .a EQL .b; 41 | !! 10 0 42 | [11] : val = .a GTR .b; 43 | !! 11 1 44 | [12] : val = .a LSS .b; 45 | !! 12 0 46 | [13] : val = .a GEQ .b; 47 | !! 13 1 48 | [14] : val = .a LEQ .b; 49 | !! 14 0 50 | [15] : val = NOT .a; 51 | !! 15 -13 52 | [16] : val = .a AND .b; 53 | !! 16 4 54 | [17] : val = .a OR .b; 55 | !! 17 14 56 | [18] : val = .a XOR .b; 57 | !! 18 10 58 | [19] : val = .a EQV .b; 59 | !! 19 -11 60 | [20] : val = (a = .b); 61 | !! 20 6 62 | [21] : val = .a + .b * 2; 63 | !! 21 24 64 | [22] : val = .a * 2 + .b; 65 | !! 22 30 66 | [23] : val = a = .b EQLU 6; 67 | !! 23 1 68 | [24] : val = .a * (2 + .b); 69 | !! 24 96 70 | [25] : val = .a / .b + .a MOD .b; 71 | !! 25 2 72 | [26] : val = .a / 3 * .b + 5; 73 | !! 26 29 74 | [27] : val = .a * 1; 75 | !! 27 12 76 | [28] : val = .b * 0; 77 | !! 28 0 78 | [29] : val = .a + .b * 2 + .a / 3; 79 | !! 29 28 80 | TES; 81 | test_output(.caseno, '%ld', .val); 82 | 83 | END; 84 | 85 | END 86 | ELUDOM 87 | -------------------------------------------------------------------------------- /tests/expression/structures.bli: -------------------------------------------------------------------------------- 1 | MODULE test = 2 | BEGIN 3 | 4 | LIBRARY 'testharness.lib'; 5 | 6 | FIELD 7 | fld0 = [0,0,4,0], 8 | flds = SET 9 | fld1 = [0,4,4,0], 10 | fld2 = [1,0,4,0], 11 | fld3 = [1,4,4,0] 12 | TES; 13 | OWN 14 | blk : BLOCK [2,BYTE] FIELD (fld0,flds), 15 | vec : VECTOR [4] INITIAL (1,2,3,4), 16 | yesno : VECTOR [2] INITIAL(UPLIT(%ASCIZ'NO'),UPLIT(%ASCIZ'YES')); 17 | 18 | BIND 19 | gbword = blk : WORD, 20 | gbwarr = blk : VECTOR [,WORD]; 21 | 22 | test_setup(numcases=10); 23 | 24 | ROUTINE testref (caseno, v : REF VECTOR) = 25 | BEGIN 26 | IF .caseno EQL 1 THEN 27 | RETURN .v 28 | ELSE IF .caseno LEQ 5 THEN 29 | RETURN .v[.caseno-2] 30 | ELSE 31 | RETURN 0 32 | END; 33 | 34 | ROUTINE testbvec (idx, bvarg) = 35 | BEGIN 36 | LOCAL bv : BITVECTOR[%BPVAL] INITIAL(.bvarg); 37 | RETURN .bv[.idx]; 38 | END; 39 | 40 | GLOBAL ROUTINE runtest (caseno) : NOVALUE = 41 | BEGIN 42 | 43 | IF .caseno EQL 1 THEN 44 | test_output(.caseno, '%s', 45 | .yesno[vec EQLA testref(.caseno, vec)]) 46 | !! 1 YES 47 | ELSE IF .caseno LEQ 5 THEN 48 | test_output(.caseno, '%ld', testref(.caseno, vec)) 49 | !! 2 1 50 | !! 3 2 51 | !! 4 3 52 | !! 5 4 53 | ELSE IF .caseno LEQ 9 THEN 54 | test_output(.caseno, '%d', testbvec(.caseno-5, %B'1010')) 55 | !! 6 1 56 | !! 7 0 57 | !! 8 1 58 | !! 9 0 59 | ELSE 60 | BEGIN 61 | BIND 62 | bword = blk : WORD, 63 | bwarr = blk : VECTOR [,WORD]; 64 | blk [fld0] = .vec[0]; 65 | blk [fld1] = .vec[1]; 66 | blk [fld2] = .vec[2]; 67 | blk [fld3] = .vec[3]; 68 | test_output(.caseno, '%x,%x,%x,%x', 69 | .bword, .gbword, .bwarr[0], .gbwarr[0]); 70 | !! 10 4321,4321,4321,4321 71 | END; 72 | 73 | END; 74 | 75 | END 76 | ELUDOM 77 | -------------------------------------------------------------------------------- /tests/lexical/lexfuncs1.bli: -------------------------------------------------------------------------------- 1 | %TITLE'Test of %TITLE' 2 | %SBTTL'Test of %SBTTL' 3 | MODULE test = 4 | BEGIN 5 | 6 | LIBRARY 'testharness.lib'; 7 | 8 | OWN 9 | teststrings : VECTOR [4] INITIAL ( 10 | UPLIT(%STRING (%CHAR(65), %CHAR(66), %CHAR(67), %CHAR(0))), 11 | UPLIT(%EXACTSTRING (32, %C' ', 'Padded to 32'), %CHAR(0)), 12 | UPLIT(%STRING('CHARCOUNT = ', %NUMBER(%CHARCOUNT('abc')), %CHAR(0))), 13 | UPLIT(%STRING(%EXPLODE('An explosion'), %CHAR(0)))), 14 | yesno : VECTOR [2] INITIAL(UPLIT(%ASCIZ'NO'),UPLIT(%ASCIZ'YES')); 15 | 16 | test_setup(numcases=16); 17 | 18 | GLOBAL ROUTINE runtest (caseno) : NOVALUE = 19 | BEGIN 20 | CASE .caseno FROM 1 TO 16 OF 21 | SET 22 | [1 TO 4] : test_output(.caseno, '"%s"', .teststrings[.caseno-1]); 23 | !! 1 "ABC" 24 | !! 2 "Padded to 32 " 25 | !! 3 "CHARCOUNT = 3" 26 | !! 4 "An explosion" 27 | [5] : test_output(.caseno, '%%NBITS(7,5,2)=%d', %NBITS(7,5,2)); 28 | !! 5 %NBITS(7,5,2)=3 29 | [6] : test_output(.caseno, '%%NBITS(-7)=%d', %NBITS(-7)); 30 | !! 6 %NBITS(-7)=4 31 | [7] : test_output(.caseno, '%%NBITS(-8)=%d', %NBITS(-8)); 32 | !! 7 %NBITS(-8)=4 33 | [8] : test_output(.caseno, '%%NBITSU(7)=%d', %NBITSU(7)); 34 | !! 8 %NBITSU(7)=3 35 | [9] : test_output(.caseno, '%s', .yesno[%NBITSU(-8) EQLU %BPVAL]); 36 | !! 9 YES 37 | [10] : test_output(.caseno, '%s', .yesno[%IDENTICAL(A+B,a+b)]); 38 | !! 10 YES 39 | [11] : test_output(.caseno, '%s', 40 | .yesno[%IDENTICAL(A+B,%REMOVE((A+B)))]); 41 | !! 11 YES 42 | [12] : test_output(.caseno, '%s', 43 | .yesno[%IDENTICAL(A+B,%REMOVE([A+B]))]); 44 | !! 12 YES 45 | [13] : test_output(.caseno, '%s', 46 | .yesno[%IDENTICAL(A+B,%REMOVE())]); 47 | !! 13 YES 48 | [14] : test_output(.caseno, '%s', .yesno[%BLISS(BLISSM)]); 49 | !! 14 YES 50 | [15] : test_output(.caseno, '%d', %VARIANT); 51 | !! 15 0 52 | [16] : test_output(.caseno, '%s', .yesno[%DECLARED(teststrings)]); 53 | !! 16 YES 54 | TES; 55 | 56 | %MESSAGE('Test of %MESSAGE') 57 | !! cerr % Test of %MESSAGE 58 | %INFORM('Test of %INFORM') 59 | !! cerr %BLISS-I-INFORM, Test of %INFORM 60 | %WARN('Test of %WARN') 61 | !! cerr %BLISS-W-USRWARN, Test of %WARN 62 | %ERROR('Test of %ERROR') 63 | !! cerr %BLISS-E-USRERR, Test of %ERROR 64 | %PRINT('Test of %PRINT') 65 | END; 66 | 67 | END 68 | ELUDOM 69 | -------------------------------------------------------------------------------- /tests/lexical/lexfuncs2.bli: -------------------------------------------------------------------------------- 1 | MODULE test = 2 | BEGIN 3 | 4 | LIBRARY 'testharness.lib'; 5 | 6 | LITERAL 7 | z = 3 + 4, 8 | y = z + 2 * 5, 9 | bpvaltest1 = -7 : SIGNED(%BPVAL), 10 | bpvaltest2 = 255 : UNSIGNED(%BPVAL); 11 | 12 | FIELD 13 | testfield = [0,4,4,0]; 14 | 15 | GLOBAL 16 | testglob; 17 | 18 | OWN 19 | testown, 20 | yesno : VECTOR [2] INITIAL(UPLIT(%ASCIZ'NO'),UPLIT(%ASCIZ'YES')); 21 | 22 | test_setup(numcases=10); 23 | 24 | GLOBAL ROUTINE runtest (caseno) : NOVALUE = 25 | BEGIN 26 | LOCAL 27 | testlocal, 28 | testalloc : VECTOR [2]; 29 | 30 | testglob = 1; 31 | testown = 2; 32 | testlocal = 3; 33 | 34 | CASE .caseno FROM 1 TO 10 OF 35 | SET 36 | [1] : test_output(.caseno, '%s,%s', .yesno[%CTCE(z)],.yesno[%CTCE(y)]); 37 | !! 1 YES,YES 38 | [2] : test_output(.caseno, '%d,%d,%d,%d', %FIELDEXPAND(testfield)); 39 | !! 2 0,4,4,0 40 | [3] : test_output(.caseno, '%d,%d', bpvaltest1, bpvaltest2); 41 | !! 3 -7,255 42 | [4] : test_output(.caseno, '%s,%s', 43 | .yesno[%CTCE(testglob)], .yesno[%LTCE(testglob)]); 44 | !! 4 NO,YES 45 | [5] : test_output(.caseno, '%s,%s', 46 | .yesno[%CTCE(testown)], .yesno[%LTCE(testown)]); 47 | !! 5 NO,YES 48 | [6] : test_output(.caseno, '%s,%s', 49 | .yesno[%CTCE(testlocal)], .yesno[%LTCE(testlocal)]); 50 | !! 6 NO,NO 51 | [7] : test_output(.caseno, '%s,%s', 52 | .yesno[%CTCE(.testglob)], .yesno[%LTCE(.testglob)]); 53 | !! 7 NO,NO 54 | [8] : test_output(.caseno, '%s', 55 | .yesno[%ALLOCATION(testalloc) EQLU %UPVAL * 2]); 56 | !! 8 YES 57 | [9] : test_output(.caseno, 58 | %STRING(%NUMBER(y),'+',%NUMBER(z),'=',%NUMBER(y+z))); 59 | !! 9 17+7=24 60 | [10] : test_output(.caseno, '%s,%s', .yesno[%DECLARED(testglob)], 61 | .yesno[%DECLARED(nosuchname)]); 62 | !! 10 YES,NO 63 | TES; 64 | 65 | END; 66 | 67 | END 68 | ELUDOM 69 | -------------------------------------------------------------------------------- /tests/lexical/literals.bli: -------------------------------------------------------------------------------- 1 | MODULE test = 2 | BEGIN 3 | 4 | LIBRARY 'testharness.lib'; 5 | 6 | LITERAL 7 | a = 65535, 8 | b = -1, 9 | c = %DECIMAL'-10', 10 | d = %O'177', ! 127 decimal 11 | e = %B'1101', ! 13 decimal 12 | f = %X'7F', 13 | g = %C''''; 14 | 15 | BIND 16 | h = UPLIT('untyped string literal', %CHAR(0)), 17 | i = UPLIT(%ASCII'%ASCII string literal', %CHAR(0)), 18 | j = UPLIT(%ASCIC'counted string literal') : VECTOR [,BYTE], 19 | k = UPLIT(%ASCIZ'null-terminated string literal'); 20 | 21 | test_setup(numcases=11); 22 | 23 | GLOBAL ROUTINE runtest (caseno) : NOVALUE = 24 | BEGIN 25 | CASE .caseno FROM 1 TO 11 OF 26 | SET 27 | [1] : test_output(.caseno, 'a = [%d,0x%x]', a, a); 28 | !! 1 a = [65535,0xffff] 29 | [2] : test_output(.caseno, 'b = [%d,0x%x]', b, b); 30 | !! 2 b = [-1,0xffffffff] 31 | [3] : test_output(.caseno, 'c = [%d,0x%x]', c, c); 32 | !! 3 c = [-10,0xfffffff6] 33 | [4] : test_output(.caseno, 'd = [%d,0x%x]', d, d); 34 | !! 4 d = [127,0x7f] 35 | [5] : test_output(.caseno, 'e = [%d,0x%x]', e, e); 36 | !! 5 e = [13,0xd] 37 | [6] : test_output(.caseno, 'f = [%d,0x%x]', f, f); 38 | !! 6 f = [127,0x7f] 39 | [7] : test_output(.caseno, 'g = ["%c",0x%x]', g, g); 40 | !! 7 g = ["'",0x27] 41 | [8] : test_output(.caseno, 'h = "%s"', h); 42 | !! 8 h = "untyped string literal" 43 | [9] : test_output(.caseno, 'i = "%s"', i); 44 | !! 9 i = "%ASCII string literal" 45 | [10] : test_output(.caseno, 'j = "%-*.*s" (length=%d)', 46 | .j[0], .j[0], j[1], .j[0]); 47 | !!10 j = "counted string literal" (length=22) 48 | [11] : test_output(.caseno, 'k = "%s"', k); 49 | !!11 k = "null-terminated string literal" 50 | TES; 51 | END; 52 | 53 | END 54 | ELUDOM 55 | -------------------------------------------------------------------------------- /tests/lexical/macros.bli: -------------------------------------------------------------------------------- 1 | MODULE test = 2 | BEGIN 3 | 4 | LIBRARY 'testharness.lib'; 5 | 6 | COMPILETIME 7 | ctval = 0; 8 | 9 | MACRO 10 | nullmacro = %, 11 | macro_noparams = 1234 %, 12 | doswap(a, b) = (LOCAL tmp; tmp = .a; a = .b; b = .tmp)%, 13 | condmacro(x)[] = %STRING(x), condmacro(%REMAINING) %, 14 | test_cases(caseindex)[fmt, vals] = 15 | %ASSIGN(ctval, %COUNT+1) 16 | [ctval] : test_output(caseindex, fmt, %REMOVE(vals)) %, 17 | macro_argcount(x)[] = %LENGTH %, 18 | expandthis = %ASCIZ'expanded' %, 19 | expander(mname) = %EXPAND %QUOTE mname %, 20 | testlitname = hello%, 21 | test_exititer1[a] = %IF %COUNT EQL 2 %THEN a %EXITITERATION %FI '.' %, 22 | test_exititer[] = %ASCIZ %STRING(test_exititer1(%REMAINING)) %, 23 | test_exitmacro(x) = UPLIT(%ASCIZ %STRING( 'exit ', 24 | %IF x %THEN 'early')) %EXITMACRO %FI 'normally')) %, 25 | testunquote = %UNQUOTE testlitname %; 26 | 27 | KEYWORDMACRO 28 | copyvector(dest, src, n=1) = 29 | INCR i FROM 0 TO (n)-1 DO dest[.i] = .src[.i] %, 30 | test_errormacro(generror=0) = 31 | %IF generror %THEN %ERRORMACRO('%ERRORMACRO invoked') %FI %; 32 | 33 | LITERAL 34 | vecsize = 10, 35 | testunquote = 99; 36 | 37 | OWN 38 | vec1 : VECTOR [vecsize], 39 | vec2 : VECTOR [vecsize], 40 | yesno : VECTOR [2] INITIAL(UPLIT(%ASCIZ'NO'),UPLIT(%ASCIZ'YES')); 41 | 42 | test_setup(numcases=10); 43 | 44 | GLOBAL ROUTINE runtest (caseno) : NOVALUE = 45 | BEGIN 46 | LOCAL 47 | x, y, vecseql; 48 | 49 | IF .caseno EQL 1 THEN 50 | BEGIN 51 | x = 999; 52 | y = 888; 53 | doswap(x, y); 54 | test_output(.caseno, 'x=%d, y=%d', .x, .y); 55 | !! 1 x=888, y=999 56 | END 57 | ELSE IF .caseno EQL 2 THEN 58 | BEGIN 59 | INCR i FROM 0 TO vecsize-1 DO vec1[.i] = .i+1; 60 | copyvector(src=vec1, dest=vec2, n=vecsize); 61 | vecseql = (INCR i FROM 0 TO vecsize-1 DO 62 | IF .vec1[.i] NEQ .vec2[.i] THEN EXITLOOP 0; 1); 63 | test_output(.caseno, '%s', .yesno[.vecseql]); 64 | !! 2 YES 65 | END 66 | ELSE 67 | CASE .caseno-2 FROM 1 TO 8 OF 68 | test_cases(.caseno, 69 | 'nullmacro is null: %s', .yesno[%NULL(nullmacro)], 70 | !! 3 nullmacro is null: YES 71 | '%d', macro_noparams, 72 | !! 4 1234 73 | 'count=%d', macro_argcount(1,2,3,4,5), 74 | !! 5 count=5 75 | '%%EXPAND test: %s', UPLIT(expander(%QUOTE expandthis)), 76 | !! 6 %EXPAND test: expanded 77 | 'hello=%d', hello, 78 | !! 7 hello=99 79 | '"%s"', UPLIT(test_exititer(%EXPLODE('abcde'))), 80 | !! 8 "..c.." 81 | '"%s"', test_exitmacro(0), 82 | !! 9 "exit normally" 83 | '"%s"', test_exitmacro(1)); 84 | !! 10 "exit early" 85 | 86 | test_errormacro(generror=0) 87 | test_errormacro(generror=1) 88 | !! cerr %BLISS-E-USRERR, %ERRORMACRO invoked 89 | 90 | END; 91 | 92 | END 93 | ELUDOM 94 | -------------------------------------------------------------------------------- /tests/lexical/names.bli: -------------------------------------------------------------------------------- 1 | MODULE test = 2 | BEGIN 3 | 4 | LIBRARY 'testharness.lib'; 5 | 6 | LITERAL 7 | ABCDEFGHIJKLMNOPQRSTUVWXYZ12345 = 31, 8 | $_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$ = 666, 9 | $abcdefghijklmnopqrs_0123456789 = 999, 10 | %NAME ('This name can have any arbitrary sequence of characters') = 12345; 11 | !! cerr %BLISS-W-NAMETOOLON, 12 | 13 | test_setup(numcases=4); 14 | 15 | GLOBAL ROUTINE runtest (caseno) : NOVALUE = 16 | BEGIN 17 | CASE .caseno FROM 1 TO 4 OF 18 | SET 19 | [1] : test_output(.caseno, '%d', ABCDEFGHIJKLMNOPQRSTUVWXYZ12345); 20 | !! 1 31 21 | [2] : test_output(.caseno, '%d', $_$_$_$_$_$_$_$_$_$_$_$_$_$_$_$); 22 | !! 2 666 23 | [3] : test_output(.caseno, '%d', $abcdefghijklmnopqrs_0123456789); 24 | !! 3 999 25 | [4] : test_output(.caseno, '%d', 26 | %NAME ('This name can have any arbitrary sequence of characters')); 27 | ! will not trigger warning, just truncation 28 | !! 4 12345 29 | TES; 30 | END; 31 | 32 | END 33 | ELUDOM 34 | -------------------------------------------------------------------------------- /tests/runtests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # runtests 3 | # 4 | # Runs BLISS compiler tests. 5 | # 6 | # Tests are BLISS source files with comments embedded that 7 | # indicate the expected results. 8 | # 9 | # N.B.: requires Python 2.7 or later. 10 | # 11 | # Copyright (c) 2013, Matthew Madison 12 | # All rights reserved. 13 | # Distributed under license; see LICENSE.TXT for details. 14 | 15 | import sys 16 | import os 17 | import argparse 18 | import re 19 | import subprocess 20 | 21 | tests = [] 22 | skipped = 0 23 | tried = 0 24 | passed = 0 25 | failed = 0 26 | 27 | def process_test(testfile, blissc, cc, testharness, quiet=False, prefix='!!'): 28 | if not quiet: 29 | print "Processing: {}".format(testfile) 30 | compout = [] 31 | comperrs = [] 32 | runout = [] 33 | failures = 0 34 | cases = 0 35 | f = file(testfile, 'rU') 36 | for lraw in f.readlines(): 37 | l = lraw.strip() 38 | if l.startswith(prefix): 39 | s = l[len(prefix):].strip() 40 | (cmd, junk, result) = s.partition(' ') 41 | if cmd == 'cout': 42 | compout.append(result.strip()) 43 | elif cmd == 'cerr': 44 | comperrs.append(result.strip()) 45 | else: 46 | try: 47 | caseno = int(cmd) 48 | except ValueError: 49 | caseno = 0 50 | if caseno != 0: 51 | cases = cases + 1 52 | runout.append('TEST {:03d}: {}'.format(caseno,result.strip())) 53 | f.close() 54 | 55 | barename = os.path.splitext(os.path.basename(testfile))[0] 56 | docompile = subprocess.Popen([blissc, '-o', barename + '.o', 57 | '-I', '.', testfile], 58 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, 59 | universal_newlines=True) 60 | (oraw, eraw) = docompile.communicate() 61 | o = oraw.split('\n') 62 | e = [] 63 | for l in eraw.split('\n'): 64 | if l.startswith('%'): 65 | e.append(l) 66 | 67 | for s in compout: 68 | if s in o: 69 | o.remove(s) 70 | else: 71 | failures = failures + 1 72 | if not quiet: 73 | print " FAIL: compiler output [{}] not found".format(s) 74 | if len(e) != 0 and len(comperrs) == 0: 75 | failures = failures + 1 76 | if not quiet: 77 | print " FAIL: unexpected compilation errors:" 78 | for l in e: 79 | print " {}".format(l) 80 | else: 81 | for s in comperrs: 82 | if len(e) == 0: 83 | failures = failures + 1 84 | if not quiet: 85 | print " FAIL: expected compilation error(s) not found" 86 | break 87 | cur = e[0] 88 | e = e[1:] 89 | if not cur.startswith(s): 90 | failures = failures + 1 91 | if not quiet: 92 | print " FAIL: unmatched error: {}".format(s) 93 | print " actual: {}".format(cur) 94 | if not quiet and failures == 0: 95 | print " compilation phase passed" 96 | 97 | subprocess.call([cc, '-o', barename, testharness, barename + '.o']) 98 | dorun = subprocess.Popen(['./' + barename], stdout=subprocess.PIPE, 99 | universal_newlines=True) 100 | oraw = dorun.communicate()[0] 101 | o = oraw.split('\n') 102 | passes = 0 103 | for s in runout: 104 | if s in o: 105 | o.remove(s) 106 | passes = passes + 1 107 | else: 108 | failures = failures + 1 109 | pfx = s.partition(':') 110 | actual = "" 111 | for l in o: 112 | if l.startswith(pfx): 113 | actual = l 114 | break 115 | if actual == "": 116 | actual = "" 117 | else: 118 | o.remove(actual) 119 | if not quiet: 120 | print " FAIL: wanted: {}".format(s) 121 | print " actual: {}".format(actual) 122 | 123 | if not quiet: 124 | print " {:d} of {:d} test cases passed".format(passes,cases) 125 | return (cases, passes, failures) 126 | 127 | 128 | # begin main 129 | 130 | (mydir, myname) = os.path.split(sys.argv[0]) 131 | parser = argparse.ArgumentParser(description='Run blissc unit tests', prog=myname) 132 | parser.add_argument('testorsuite', help='test file name or test suite directory', nargs='*', default='.') 133 | parser.add_argument('--blissc', help='location of BLISS compiler', default='blissc') 134 | parser.add_argument('--harness', help='test harness C file', default=os.path.join(mydir, 'testharness.c')) 135 | parser.add_argument('--cc', help="C compiler", default='cc') 136 | parser.add_argument('--quiet', '-q', action='store_true') 137 | 138 | args = parser.parse_args() 139 | 140 | pat = re.compile('^.+\.bli$') 141 | for t_or_s in args.testorsuite: 142 | if os.path.exists(t_or_s): 143 | if os.path.isdir(t_or_s): 144 | for d, sdl, fl in os.walk(t_or_s): 145 | for f in fl: 146 | if pat.match(f): 147 | tests.append(os.path.join(d, f)) 148 | else: 149 | tests.append(t_or_s) 150 | else: 151 | if not args.quiet: 152 | print "Skipping non-existent test: {}".format(t_or_s) 153 | skipped = skipped + 1 154 | 155 | totcases = 0 156 | totpasses = 0 157 | for t in tests: 158 | tried = tried + 1 159 | (c, p, f) = process_test(t, args.blissc, args.cc, args.harness, args.quiet) 160 | totcases = totcases + c 161 | totpasses = totpasses + p 162 | if f == 0: 163 | passed = passed + 1 164 | else: 165 | failed = failed + 1 166 | 167 | if not args.quiet: 168 | print "-- Tried: {:d}; Skipped: {:d}; Passed: {:d}; Failed: {:d} --".format(tried, skipped, passed, failed) 169 | print "-- Total test cases: {:d} ({:d} passing) --".format(totcases, totpasses) 170 | if tried == 0 or failed != 0: 171 | sys.exit(1) 172 | sys.exit(0) 173 | -------------------------------------------------------------------------------- /tests/testharness.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | * testharness.c 3 | * 4 | * Simple test harness for running BLISS tests. 5 | * 6 | * Copyright © 2013, Matthew Madison. 7 | * All rights reserved. 8 | * Distributed under license. See LICENSE.TXT for details. 9 | *-- 10 | */ 11 | #include 12 | #include 13 | #include 14 | 15 | int TEST_INIT(void); 16 | void RUNTEST(int); 17 | 18 | void 19 | TEST_PRINTF (const char *fmt, ...) 20 | { 21 | va_list ap; 22 | 23 | va_start(ap, fmt); 24 | 25 | vprintf(fmt, ap); 26 | 27 | } 28 | 29 | int 30 | main (int argc, char *argv[]) 31 | { 32 | int i, numtests; 33 | 34 | numtests = TEST_INIT(); 35 | if (argc < 2) { 36 | for (i = 1; i <= numtests; i++) 37 | RUNTEST(i); 38 | return(0); 39 | } 40 | 41 | for (i = 1; i < argc; i++) { 42 | int tno = atoi(argv[i]); 43 | if (tno >= 1 && tno <= numtests) { 44 | RUNTEST(tno); 45 | } 46 | } 47 | 48 | return(0); 49 | } 50 | -------------------------------------------------------------------------------- /tests/testharness.req: -------------------------------------------------------------------------------- 1 | KEYWORDMACRO 2 | test_setup (numcases) = 3 | EXTERNAL ROUTINE test_printf; 4 | GLOBAL ROUTINE test_init = 5 | BEGIN 6 | RETURN numcases; 7 | END%; 8 | MACRO 9 | test_output (num, fmt)[] = 10 | test_printf(UPLIT(%STRING('TEST %03d: ', fmt, %CHAR(10), %CHAR(0))), 11 | num %IF NOT %NULL(%REMAINING) %THEN , %REMAINING %FI)%; 12 | --------------------------------------------------------------------------------