├── src ├── algorithms │ ├── yield_setter.cpp │ ├── yield_setter.h │ ├── reuse_setter.h │ ├── stall_setter.h │ ├── reuse_setter.cpp │ ├── cfg.h │ └── register_allocator.h ├── core │ ├── module.cpp │ ├── module.h │ └── kernel.h ├── arch │ ├── arch-common.h │ ├── arch-common.cpp │ ├── base_arch.h │ └── arch_sm7x.h ├── CMakeLists.txt └── dada-common.h ├── thirdparty ├── antlr4-runtime │ ├── VERSION │ ├── src │ │ ├── misc │ │ │ ├── Predicate.cpp │ │ │ ├── Predicate.h │ │ │ └── InterpreterDataReader.h │ │ ├── tree │ │ │ ├── xpath │ │ │ │ ├── XPathLexer.tokens │ │ │ │ ├── XPathLexerErrorListener.cpp │ │ │ │ ├── XPathWildcardElement.h │ │ │ │ ├── XPathWildcardAnywhereElement.h │ │ │ │ ├── XPathWildcardElement.cpp │ │ │ │ ├── XPathLexerErrorListener.h │ │ │ │ ├── XPathRuleElement.h │ │ │ │ ├── XPathRuleAnywhereElement.cpp │ │ │ │ ├── XPathTokenAnywhereElement.cpp │ │ │ │ ├── XPathTokenElement.h │ │ │ │ ├── XPathTokenAnywhereElement.h │ │ │ │ ├── XPathWildcardAnywhereElement.cpp │ │ │ │ ├── XPathRuleAnywhereElement.h │ │ │ │ ├── XPathElement.cpp │ │ │ │ ├── XPathRuleElement.cpp │ │ │ │ ├── XPathTokenElement.cpp │ │ │ │ ├── XPathElement.h │ │ │ │ ├── XPathLexer.g4 │ │ │ │ └── XPathLexer.h │ │ │ ├── ErrorNode.cpp │ │ │ ├── pattern │ │ │ │ ├── Chunk.cpp │ │ │ │ ├── TextChunk.cpp │ │ │ │ ├── TagChunk.cpp │ │ │ │ ├── TokenTagToken.cpp │ │ │ │ ├── Chunk.h │ │ │ │ ├── TextChunk.h │ │ │ │ └── ParseTreePattern.cpp │ │ │ ├── TerminalNode.cpp │ │ │ ├── ParseTreeVisitor.cpp │ │ │ ├── ParseTreeListener.cpp │ │ │ ├── ParseTree.cpp │ │ │ ├── ErrorNode.h │ │ │ ├── ErrorNodeImpl.cpp │ │ │ ├── TerminalNode.h │ │ │ ├── TerminalNodeImpl.h │ │ │ ├── ParseTreeWalker.h │ │ │ ├── ErrorNodeImpl.h │ │ │ ├── ParseTreeListener.h │ │ │ ├── TerminalNodeImpl.cpp │ │ │ ├── ParseTreeProperty.h │ │ │ └── ParseTreeWalker.cpp │ │ ├── Token.cpp │ │ ├── TokenSource.cpp │ │ ├── WritableToken.cpp │ │ ├── atn │ │ │ ├── LexerAction.cpp │ │ │ ├── BlockStartState.cpp │ │ │ ├── BasicState.cpp │ │ │ ├── LoopEndState.cpp │ │ │ ├── RuleStopState.cpp │ │ │ ├── TokensStartState.cpp │ │ │ ├── PlusLoopbackState.cpp │ │ │ ├── BasicBlockStartState.cpp │ │ │ ├── PlusBlockStartState.cpp │ │ │ ├── StarBlockStartState.cpp │ │ │ ├── OrderedATNConfigSet.cpp │ │ │ ├── BlockEndState.cpp │ │ │ ├── RuleStartState.cpp │ │ │ ├── StarLoopEntryState.cpp │ │ │ ├── AbstractPredicateTransition.cpp │ │ │ ├── ATNType.h │ │ │ ├── DecisionState.cpp │ │ │ ├── BasicState.h │ │ │ ├── OrderedATNConfigSet.h │ │ │ ├── ContextSensitivityInfo.cpp │ │ │ ├── ErrorInfo.cpp │ │ │ ├── StarLoopbackState.h │ │ │ ├── BasicBlockStartState.h │ │ │ ├── StarBlockStartState.h │ │ │ ├── BlockStartState.h │ │ │ ├── LoopEndState.h │ │ │ ├── StarLoopbackState.cpp │ │ │ ├── DecisionEventInfo.cpp │ │ │ ├── TokensStartState.h │ │ │ ├── AbstractPredicateTransition.h │ │ │ ├── LookaheadEventInfo.cpp │ │ │ ├── RuleStartState.h │ │ │ ├── BlockEndState.h │ │ │ ├── AmbiguityInfo.cpp │ │ │ ├── PlusLoopbackState.h │ │ │ ├── DecisionState.h │ │ │ ├── PredicateEvalInfo.cpp │ │ │ ├── WildcardTransition.h │ │ │ ├── RuleStopState.h │ │ │ ├── NotSetTransition.h │ │ │ ├── WildcardTransition.cpp │ │ │ ├── PlusBlockStartState.h │ │ │ ├── RangeTransition.h │ │ │ ├── EmptyPredictionContext.h │ │ │ ├── SetTransition.h │ │ │ ├── AtomTransition.h │ │ │ ├── DecisionInfo.cpp │ │ │ ├── AtomTransition.cpp │ │ │ ├── EmptyPredictionContext.cpp │ │ │ ├── NotSetTransition.cpp │ │ │ ├── PrecedencePredicateTransition.h │ │ │ ├── SetTransition.cpp │ │ │ ├── StarLoopEntryState.h │ │ │ ├── ActionTransition.h │ │ │ ├── RangeTransition.cpp │ │ │ ├── EpsilonTransition.cpp │ │ │ ├── Transition.cpp │ │ │ ├── PrecedencePredicateTransition.cpp │ │ │ ├── LexerMoreAction.cpp │ │ │ ├── LexerSkipAction.cpp │ │ │ ├── RuleTransition.cpp │ │ │ ├── ActionTransition.cpp │ │ │ ├── EpsilonTransition.h │ │ │ ├── LexerPopModeAction.cpp │ │ │ ├── PredicateTransition.cpp │ │ │ ├── ATNDeserializationOptions.h │ │ │ ├── RuleTransition.h │ │ │ ├── PredicateTransition.h │ │ │ ├── LexerModeAction.cpp │ │ │ ├── LexerTypeAction.cpp │ │ │ ├── LexerChannelAction.cpp │ │ │ ├── LexerPushModeAction.cpp │ │ │ ├── LexerActionType.h │ │ │ ├── SingletonPredictionContext.h │ │ │ ├── ArrayPredictionContext.h │ │ │ ├── LexerATNConfig.h │ │ │ ├── Makefile │ │ │ ├── LexerCustomAction.cpp │ │ │ ├── ATNDeserializationOptions.cpp │ │ │ ├── LexerIndexedCustomAction.cpp │ │ │ ├── LexerSkipAction.h │ │ │ ├── ErrorInfo.h │ │ │ ├── LexerMoreAction.h │ │ │ ├── LexerPopModeAction.h │ │ │ ├── LexerTypeAction.h │ │ │ └── LookaheadEventInfo.h │ │ ├── CharStream.cpp │ │ ├── TokenStream.cpp │ │ ├── ANTLRErrorListener.cpp │ │ ├── ANTLRErrorStrategy.cpp │ │ ├── support │ │ │ ├── Any.cpp │ │ │ ├── Arrays.cpp │ │ │ ├── StringUtils.cpp │ │ │ ├── StringUtils.h │ │ │ └── BitSet.h │ │ ├── IntStream.cpp │ │ ├── InputMismatchException.cpp │ │ ├── dfa │ │ │ ├── LexerDFASerializer.cpp │ │ │ ├── LexerDFASerializer.h │ │ │ └── DFASerializer.h │ │ ├── ConsoleErrorListener.cpp │ │ ├── InterpreterRuleContext.cpp │ │ ├── WritableToken.h │ │ ├── RuleContextWithAltNum.cpp │ │ ├── InputMismatchException.h │ │ ├── ANTLRFileStream.cpp │ │ ├── ANTLRFileStream.h │ │ ├── LexerNoViableAltException.h │ │ ├── RuleContextWithAltNum.h │ │ ├── ConsoleErrorListener.h │ │ ├── FailedPredicateException.h │ │ ├── BaseErrorListener.cpp │ │ ├── TokenFactory.h │ │ ├── NoViableAltException.cpp │ │ ├── LexerNoViableAltException.cpp │ │ ├── CommonTokenFactory.cpp │ │ ├── BaseErrorListener.h │ │ ├── CharStream.h │ │ ├── InterpreterRuleContext.h │ │ ├── ProxyErrorListener.h │ │ ├── NoViableAltException.h │ │ ├── FailedPredicateException.cpp │ │ ├── BailErrorStrategy.cpp │ │ └── CommonTokenStream.cpp │ ├── cmake │ │ └── antlr4-runtime.cmake.in │ └── CMakeLists.txt └── CMakeLists.txt ├── bin └── antlr-4.7.2-complete.jar ├── examples ├── hgemm │ ├── results │ │ ├── rtx2070-result-origin.csv │ │ └── rtx2070-result.csv │ ├── rtx2070-result.csv │ ├── run.sh │ └── Makefile ├── sgemm │ ├── results │ │ ├── rtx2070-result-cuda10.1.csv │ │ ├── rtx2070-result-cuda11.0.csv │ │ ├── v100-result-wo-yield.csv │ │ ├── rtx2070-result.csv │ │ └── v100-result.csv │ ├── run.sh │ └── Makefile ├── benchmark │ ├── cpi │ │ └── Makefile │ ├── L0-i-cache │ │ ├── Makefile │ │ ├── codgen.py │ │ └── main.cu │ └── L1-i-cache │ │ ├── Makefile │ │ ├── codegen.py │ │ └── main.cu └── copy │ └── copy.gas ├── .gitignore ├── grammar └── CMakeLists.txt ├── CMakeLists.txt └── README.md /src/algorithms/yield_setter.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/algorithms/yield_setter.h: -------------------------------------------------------------------------------- 1 | #pragma once -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/VERSION: -------------------------------------------------------------------------------- 1 | 4.7.2 2 | -------------------------------------------------------------------------------- /bin/antlr-4.7.2-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daadaada/gas/HEAD/bin/antlr-4.7.2-complete.jar -------------------------------------------------------------------------------- /thirdparty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | add_subdirectory(antlr4-runtime) 4 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/misc/Predicate.cpp: -------------------------------------------------------------------------------- 1 | #include "misc/Predicate.h" 2 | 3 | antlr4::misc::Predicate::~Predicate() { 4 | } 5 | -------------------------------------------------------------------------------- /examples/hgemm/results/rtx2070-result-origin.csv: -------------------------------------------------------------------------------- 1 | m,n,k,cuBLAS,GAS,Speedup 2 | 16384,16384,16384,24.8,30.1,0 3 | 8192,8192,8192,40.9,50.9,0 4 | 4096,4096,4096,40.1,35.3,0 -------------------------------------------------------------------------------- /src/core/module.cpp: -------------------------------------------------------------------------------- 1 | #include "module.h" 2 | 3 | namespace dada { 4 | void Module::addKernel(Kernel* kernel){ 5 | kernels_.emplace_back(kernel); 6 | } 7 | }; -------------------------------------------------------------------------------- /examples/sgemm/results/rtx2070-result-cuda10.1.csv: -------------------------------------------------------------------------------- 1 | mnk,cuBLAS,PTX,GAS,GAS-mimic 2 | 2048,4.28,5.67,5.06,5.31,5.22 3 | 4096,5.01,7.80,7.29,7.65,7.54 4 | 8192,6.15,7.76,7.33,7.74,7.63 5 | -------------------------------------------------------------------------------- /examples/hgemm/rtx2070-result.csv: -------------------------------------------------------------------------------- 1 | mnk,cuBLAS,PTX,GAS,GAS-mimic 2 | 2048,23.16,29.29,34.06,33.79 3 | 4096,37.34,35.05,37.18,35.98 4 | 8192,39.41,48.40,53.55,49.46 5 | 16384,22.84,34.11,52.60,40.20 6 | -------------------------------------------------------------------------------- /examples/hgemm/results/rtx2070-result.csv: -------------------------------------------------------------------------------- 1 | mnk,cuBLAS,PTX,GAS,GAS-mimic 2 | 2048,35.18,33.73,38.04,33.80 3 | 4096,40.30,35.86,39.85,36.55 4 | 8192,39.67,49.25,56.50,51.57 5 | 16384,24.75,37.48,56.86,32.49 6 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathLexer.tokens: -------------------------------------------------------------------------------- 1 | TOKEN_REF=1 2 | RULE_REF=2 3 | ANYWHERE=3 4 | ROOT=4 5 | WILDCARD=5 6 | BANG=6 7 | ID=7 8 | STRING=8 9 | '//'=3 10 | '/'=4 11 | '*'=5 12 | '!'=6 13 | -------------------------------------------------------------------------------- /examples/sgemm/results/rtx2070-result-cuda11.0.csv: -------------------------------------------------------------------------------- 1 | mnk,cuda,cuBLAS,PTX,GAS,GAS-mimic 2 | 2048,4.29,5.66,5.24,5.30,5.30 3 | 4096,5.01,7.88,7.57,7.64,7.65 4 | 8192,6.19,7.78,7.65,7.74,7.74 5 | 10240,6.23,7.75,7.64,7.68,7.66 6 | -------------------------------------------------------------------------------- /src/arch/arch-common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base_arch.h" 4 | #include "arch_sm7x.h" 5 | #include "arch_sm70.h" 6 | #include "arch_sm75.h" 7 | 8 | namespace dada { 9 | BaseArch* makeArch(int arch); 10 | } -------------------------------------------------------------------------------- /examples/sgemm/results/v100-result-wo-yield.csv: -------------------------------------------------------------------------------- 1 | mnk,cuda,cuBLAS,PTX,GAS,GAS-mimic 2 | 2048,8.28,11.51,9.63,9.77,9.78 3 | 4096,10.18,13.98,13.90,14.15,14.15 4 | 8192,12.17,14.33,13.99,14.19,14.19 5 | 10240,12.30,14.54,14.21,14.41,14.41 6 | -------------------------------------------------------------------------------- /examples/sgemm/results/rtx2070-result.csv: -------------------------------------------------------------------------------- 1 | mnk,cuda,cuBLAS,PTX,GAS,GAS-mimic,GAS-yield 2 | 2048,4.29,5.66,5.23,5.30,5.29,5.25 3 | 4096,4.98,7.84,7.57,7.66,7.63,7.60 4 | 8192,6.19,7.78,7.65,7.74,7.74,7.67 5 | 10240,6.21,7.73,7.63,7.69,7.71,7.66 6 | -------------------------------------------------------------------------------- /examples/benchmark/cpi/Makefile: -------------------------------------------------------------------------------- 1 | ARCH = 75 2 | NAME = benchmark 3 | GAS = $(GAS_HOME)/build/gas 4 | 5 | all: 6 | $(GAS) $(NAME).gas -o $(NAME).cubin 7 | nvcc main.cu -lcuda -arch=sm_$(ARCH) -o $(NAME) 8 | 9 | clean: 10 | rm $(NAME).cubin $(NAME) -------------------------------------------------------------------------------- /examples/sgemm/results/v100-result.csv: -------------------------------------------------------------------------------- 1 | mnk,cuda,cuBLAS,PTX,GAS,GAS-mimic,GAS-yield 2 | 2048,10.47,13.63,11.28,11.45,11.44,11.33 3 | 4096,12.38,14.05,13.95,14.15,14.15,13.92 4 | 8192,13.10,14.31,13.97,14.17,14.17,14.05 5 | 10240,13.24,14.25,14.15,14.35,14.35,14.23 6 | -------------------------------------------------------------------------------- /examples/benchmark/L0-i-cache/Makefile: -------------------------------------------------------------------------------- 1 | ARCH = 75 2 | NAME = l0-icache 3 | GAS = $(GAS_HOME)/build/gas 4 | 5 | all: 6 | # python codegen.py > $(NAME).gas 7 | $(GAS) $(NAME).gas -o $(NAME).cubin 8 | nvcc main.cu -lcuda -arch=sm_$(ARCH) -o $(NAME) 9 | 10 | clean: 11 | rm $(NAME).cubin $(NAME) -------------------------------------------------------------------------------- /examples/benchmark/L1-i-cache/Makefile: -------------------------------------------------------------------------------- 1 | ARCH = 75 2 | NAME = l1-icache 3 | GAS = $(GAS_HOME)/build/gas 4 | 5 | all: 6 | # python codegen.py > $(NAME).gas 7 | $(GAS) $(NAME).gas -o $(NAME).cubin 8 | nvcc main.cu -lcuda -arch=sm_$(ARCH) -o $(NAME) 9 | 10 | clean: 11 | rm $(NAME).cubin $(NAME) -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | file(GLOB_RECURSE core_src "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") 4 | file(GLOB_RECURSE core_header "${CMAKE_CURRENT_SOURCE_DIR}/*.h") 5 | 6 | add_library(dada_src STATIC ${core_src} ${core_header}) 7 | 8 | target_include_directories(dada_src PUBLIC ${CMAKE_SOURCE_DIR}) -------------------------------------------------------------------------------- /src/core/module.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "kernel.h" 7 | 8 | namespace dada{ 9 | class Module { 10 | public: 11 | std::vector> kernels_; 12 | public: 13 | void addKernel(Kernel* kernel); 14 | }; 15 | } // namespace dada -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/Token.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | 8 | antlr4::Token::~Token() { 9 | } 10 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/TokenSource.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenSource.h" 7 | 8 | antlr4::TokenSource::~TokenSource() { 9 | } 10 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/WritableToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "WritableToken.h" 7 | 8 | antlr4::WritableToken::~WritableToken() { 9 | } 10 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ErrorNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | 8 | antlr4::tree::ErrorNode::~ErrorNode() { 9 | } 10 | -------------------------------------------------------------------------------- /examples/hgemm/run.sh: -------------------------------------------------------------------------------- 1 | m_size=(2048 4096 8192 16384) 2 | d=rtx2070 3 | f=${d}-result.csv 4 | 5 | if [[ -f $f ]] 6 | then 7 | printf "$f already exists.\nTerminate.\n" 8 | exit 0 9 | else 10 | echo "Writing result to $f" 11 | echo "mnk,cuBLAS,PTX,GAS,GAS-mimic" >> $f 12 | fi 13 | 14 | for i in ${m_size[@]} 15 | do 16 | ./hgemm $i >> $f 17 | done -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "LexerAction.h" 7 | 8 | antlr4::atn::LexerAction::~LexerAction() { 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | tmp/ 3 | fig/ 4 | 5 | # example binaries 6 | # copy 7 | cta_copy 8 | saxpy 9 | examples/sgemm/sgemm 10 | examples/hgemm/hgemm 11 | examples/benchmark/cpi/benchmark 12 | 13 | *.cubin 14 | *.out 15 | *.nsight-cuprof-report 16 | *.sass 17 | *.bin 18 | 19 | # antrl 20 | .antlr 21 | grammar/generated/ 22 | 23 | # temporary files 24 | todo.md -------------------------------------------------------------------------------- /src/dada-common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "core/module.h" 4 | #include "core/kernel.h" 5 | #include "core/instruction.h" 6 | #include "core/operand.h" 7 | 8 | #include "algorithms/cfg.h" 9 | #include "algorithms/register_allocator.h" 10 | #include "algorithms/stall_setter.h" 11 | #include "algorithms/barrier_setter.h" 12 | 13 | #include "elf/cu_elf.h" -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/pattern/Chunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/Chunk.h" 7 | 8 | antlr4::tree::pattern::Chunk::~Chunk() { 9 | } 10 | -------------------------------------------------------------------------------- /examples/copy/copy.gas: -------------------------------------------------------------------------------- 1 | // Copy 4 elements 2 | 3 | copy(s64 dst, s64 src) { 4 | // declare variables 5 | b32 .v4 Fragment[4]; 6 | s64 LoadPtr, StorePtr; 7 | 8 | // load parameters 9 | ldc.64 LoadPtr, src; 10 | ldc.64 StorePtr, dst; 11 | 12 | // copy 13 | ldg.128 Fragment[0:3], [LoadPtr]; 14 | stg.128 [StorePtr], Fragment[0:3]; 15 | exit; 16 | } -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/cmake/antlr4-runtime.cmake.in: -------------------------------------------------------------------------------- 1 | set(ANTLR_VERSION @ANTLR_VERSION@) 2 | 3 | @PACKAGE_INIT@ 4 | 5 | set_and_check(ANTLR4_INCLUDE_DIR "@PACKAGE_ANTLR4_INCLUDE_DIR@") 6 | set_and_check(ANTLR4_LIB_DIR "@PACKAGE_ANTLR4_LIB_DIR@") 7 | 8 | include(${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake) 9 | 10 | check_required_components(antlr) 11 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/CharStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "CharStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | CharStream::~CharStream() { 11 | } 12 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/TerminalNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/TerminalNode.h" 7 | 8 | antlr4::tree::TerminalNode::~TerminalNode() { 9 | } 10 | -------------------------------------------------------------------------------- /examples/sgemm/run.sh: -------------------------------------------------------------------------------- 1 | m_size=(2048 4096 8192 10240) 2 | d=v100 3 | f=${d}-result.csv 4 | 5 | if [[ -f $f ]] 6 | then 7 | printf "$f already exists.\nTerminate.\n" 8 | exit 0 9 | else 10 | echo "Writing result to $f" 11 | echo "mnk,cuda,cuBLAS,PTX,GAS,GAS-mimic,GAS-yield" >> $f 12 | fi 13 | 14 | for i in ${m_size[@]} 15 | do 16 | ./sgemm $i >> $f 17 | done 18 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/TokenStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | TokenStream::~TokenStream() { 11 | } 12 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/BlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BlockStartState.h" 7 | 8 | antlr4::atn::BlockStartState::~BlockStartState() { 9 | } 10 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/ANTLRErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorListener.h" 7 | 8 | antlr4::ANTLRErrorListener::~ANTLRErrorListener() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/ANTLRErrorStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorStrategy.h" 7 | 8 | antlr4::ANTLRErrorStrategy::~ANTLRErrorStrategy() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/support/Any.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Any.h" 7 | 8 | using namespace antlrcpp; 9 | 10 | Any::~Any() 11 | { 12 | delete _ptr; 13 | } 14 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ParseTreeVisitor.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeVisitor.h" 7 | 8 | antlr4::tree::ParseTreeVisitor::~ParseTreeVisitor() { 9 | } 10 | -------------------------------------------------------------------------------- /src/arch/arch-common.cpp: -------------------------------------------------------------------------------- 1 | #include "arch-common.h" 2 | 3 | namespace dada { 4 | BaseArch* makeArch(int arch){ 5 | BaseArch* return_ptr = nullptr; 6 | switch(arch){ 7 | case 70: 8 | return_ptr = new SM70; 9 | break; 10 | case 75: 11 | return_ptr = new SM75; 12 | break; 13 | } 14 | return return_ptr; 15 | } 16 | } -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ParseTreeListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeListener.h" 7 | 8 | antlr4::tree::ParseTreeListener::~ParseTreeListener() { 9 | } 10 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/BasicState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicState::getStateType() { 11 | return BASIC; 12 | } 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LoopEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LoopEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t LoopEndState::getStateType() { 11 | return LOOP_END; 12 | } 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/RuleStopState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStopState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t RuleStopState::getStateType() { 11 | return RULE_STOP; 12 | } 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/TokensStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/TokensStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t TokensStartState::getStateType() { 11 | return TOKEN_START; 12 | } 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/IntStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "IntStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | const std::string IntStream::UNKNOWN_SOURCE_NAME = ""; 11 | 12 | IntStream::~IntStream() = default; 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PlusLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusLoopbackState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusLoopbackState::getStateType() { 11 | return PLUS_LOOP_BACK; 12 | } 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/BasicBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicBlockStartState::getStateType() { 11 | return BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PlusBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusBlockStartState::getStateType() { 11 | return PLUS_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/StarBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t StarBlockStartState::getStateType() { 11 | return STAR_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/OrderedATNConfigSet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/OrderedATNConfigSet.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t OrderedATNConfigSet::getHash(ATNConfig *c) { 11 | return c->hashCode(); 12 | } 13 | -------------------------------------------------------------------------------- /examples/sgemm/Makefile: -------------------------------------------------------------------------------- 1 | ARCH = 70 # modify this 2 | NAME = sgemm 3 | GAS = $(GAS_HOME)/build/gas 4 | 5 | all: 6 | /usr/local/cuda-11.0/bin/ptxas -arch=sm_$(ARCH) sgemm-gen.ptx -o sgemm-ptx.cubin 7 | $(GAS) -arch sm_$(ARCH) sgemm-fused.gas -o sgemm-gas.cubin 8 | $(GAS) -arch sm_$(ARCH) sgemm-mimic.gas -o sgemm-gas-mimic.cubin 9 | /usr/local/cuda-10.1/bin/nvcc main.cu -lcuda -lcublas -arch=sm_$(ARCH) -o $(NAME) 10 | 11 | clean: 12 | rm $(NAME).cubin $(NAME) 13 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/BlockEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BlockEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | BlockEndState::BlockEndState() : startState(nullptr) { 11 | } 12 | 13 | size_t BlockEndState::getStateType() { 14 | return BLOCK_END; 15 | } 16 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ParseTree.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | 8 | using namespace antlr4::tree; 9 | 10 | ParseTree::ParseTree() : parent(nullptr) { 11 | } 12 | 13 | bool ParseTree::operator == (const ParseTree &other) const { 14 | return &other == this; 15 | } 16 | -------------------------------------------------------------------------------- /examples/hgemm/Makefile: -------------------------------------------------------------------------------- 1 | ARCH ?= 75 2 | NAME = hgemm 3 | GAS = $(GAS_HOME)/build/gas 4 | PTXAS ?= /usr/local/cuda-11.0/bin/ptxas 5 | NVCC ?= /usr/local/cuda-10.1/bin/nvcc # nvcc 11.0's support for C++17 is broken 6 | 7 | all: 8 | $(PTXAS) -arch=sm_$(ARCH) hgemm_gen.ptx -o hgemm-ptx.cubin 9 | $(GAS) hgemm_fused.gas -o hgemm-gas.cubin 10 | $(GAS) hgemm-mimic.gas -o hgemm-gas-mimic.cubin 11 | $(NVCC) main.cu -lcuda -lcublas -arch=sm_$(ARCH) -o $(NAME) 12 | 13 | clean: 14 | rm $(NAME).cubin $(NAME) 15 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/RuleStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | RuleStartState::RuleStartState() { 11 | isLeftRecursiveRule = false; 12 | } 13 | 14 | size_t RuleStartState::getStateType() { 15 | return RULE_START; 16 | } 17 | -------------------------------------------------------------------------------- /grammar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | set(ANTLR_EXECUTABLE /usr/local/lib/antlr-4.7.2-complete.jar) 4 | find_package(ANTLR REQUIRED) 5 | 6 | antlr_target(GrammarOutput dada.g4 OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/generated VISITOR) 7 | 8 | add_library( 9 | grammar 10 | ${ANTLR_GrammarOutput_CXX_OUTPUTS} 11 | visitor.cpp 12 | ) 13 | 14 | target_link_libraries( 15 | grammar PUBLIC 16 | antlr4_static 17 | ) 18 | 19 | target_include_directories(grammar PUBLIC ${CMAKE_SOURCE_DIR}) -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) # C++17 required 2 | 3 | project(gas LANGUAGES CXX VERSION 0.1) 4 | 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | set(CMAKE_CXX_STANDARD 17) 7 | 8 | add_executable(gas main.cpp) 9 | 10 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) 11 | 12 | add_subdirectory(src) 13 | add_subdirectory(thirdparty) 14 | add_subdirectory(grammar) 15 | 16 | target_link_libraries(gas PRIVATE grammar dada_src antlr4_static) 17 | target_include_directories(gas INTERFACE ${PROJECT_SOURCE_DIR}) 18 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/StarLoopEntryState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | StarLoopEntryState::StarLoopEntryState() : DecisionState(), isPrecedenceDecision(false) { 11 | } 12 | 13 | size_t StarLoopEntryState::getStateType() { 14 | return STAR_LOOP_ENTRY; 15 | } 16 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/AbstractPredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AbstractPredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | AbstractPredicateTransition::AbstractPredicateTransition(ATNState *target) : Transition(target) { 11 | } 12 | 13 | AbstractPredicateTransition::~AbstractPredicateTransition() { 14 | } 15 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ErrorNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ErrorNode : public virtual TerminalNode { 14 | public: 15 | ~ErrorNode() override; 16 | }; 17 | 18 | } // namespace tree 19 | } // namespace antlr4 20 | -------------------------------------------------------------------------------- /src/algorithms/reuse_setter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "src/core/kernel.h" 6 | #include "register_allocator.h" 7 | #include "cfg.h" 8 | 9 | namespace dada{ 10 | class ReuseSetter{ 11 | public: 12 | std::vector reuse_masks_; 13 | Kernel const* kernel_; 14 | CFG const* cfg_; 15 | RegisterAllocator const* register_allocator_; 16 | int const arch_; 17 | 18 | public: 19 | ReuseSetter(Kernel const*, CFG const*, RegisterAllocator const*, int arch); 20 | void set(); 21 | }; 22 | } -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ATNType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Represents the type of recognizer an ATN applies to. 14 | enum class ATNType { 15 | LEXER = 0, 16 | PARSER = 1, 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/DecisionState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | void DecisionState::InitializeInstanceFields() { 11 | decision = -1; 12 | nonGreedy = false; 13 | } 14 | 15 | std::string DecisionState::toString() const { 16 | return "DECISION " + ATNState::toString(); 17 | } 18 | -------------------------------------------------------------------------------- /src/algorithms/stall_setter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "src/core/kernel.h" 4 | #include "src/algorithms/cfg.h" 5 | 6 | using namespace std; 7 | 8 | namespace dada { 9 | class StallSetter { 10 | private: 11 | CFG const* cfg_ = nullptr; 12 | Kernel const* kernel_ = nullptr; 13 | int arch_ = 0; 14 | 15 | public: 16 | std::vector stalls_; 17 | 18 | public: 19 | StallSetter(Kernel const* kernel, CFG const* cfg, int arch); 20 | void set(); 21 | std::vector const& getStalls() const; 22 | }; 23 | } -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/BasicState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC BasicState final : public ATNState { 14 | 15 | public: 16 | virtual size_t getStateType() override; 17 | 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/misc/Predicate.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | class ANTLR4CPP_PUBLIC Predicate { 14 | public: 15 | virtual ~Predicate(); 16 | 17 | virtual bool test(tree::ParseTree *t) = 0; 18 | }; 19 | 20 | } // namespace tree 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /examples/benchmark/L0-i-cache/codgen.py: -------------------------------------------------------------------------------- 1 | 2 | tail = """ 3 | cs2r.32 end, clock_lo; 4 | 5 | s32 time; 6 | iadd3 time, -start, end, rz; 7 | 8 | s64 ptr; 9 | s32 tid, imm4; 10 | s2r tid, threadIdx_x; 11 | mov imm4, 4; 12 | imad.wide ptr, tid, imm4, result; 13 | 14 | stg.32 [ptr], time; 15 | exit; 16 | } 17 | """ 18 | 19 | for i in range(100): 20 | header = f""" 21 | list{i}(s64 result){{ 22 | s32 start, end; 23 | cs2r.32 start, clock_lo; 24 | """ 25 | body = [] 26 | for n in range(i): 27 | body.append("nop;") 28 | print(header, '\n'.join(body), tail) -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/OrderedATNConfigSet.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNConfigSet.h" 9 | #include "atn/ATNConfig.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC OrderedATNConfigSet : public ATNConfigSet { 15 | protected: 16 | virtual size_t getHash(ATNConfig *c) override; 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathLexerErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPathLexerErrorListener.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::tree::xpath; 10 | 11 | void XPathLexerErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 12 | size_t /*line*/, size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ContextSensitivityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ContextSensitivityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | ContextSensitivityInfo::ContextSensitivityInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, 12 | size_t startIndex, size_t stopIndex) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, true) { 14 | } 15 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ErrorInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNConfigSet.h" 7 | 8 | #include "atn/ErrorInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | ErrorInfo::ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 14 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 15 | } 16 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/StarLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopbackState final : public ATNState { 14 | public: 15 | StarLoopEntryState *getLoopEntryState(); 16 | 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/BasicBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | #include "atn/BlockStartState.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC BasicBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/StarBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The block that begins a closure loop. 14 | class ANTLR4CPP_PUBLIC StarBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/BlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The start of a regular {@code (...)} block. 14 | class ANTLR4CPP_PUBLIC BlockStartState : public DecisionState { 15 | public: 16 | ~BlockStartState(); 17 | BlockEndState *endState = nullptr; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LoopEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Mark the end of a * or + loop. 14 | class ANTLR4CPP_PUBLIC LoopEndState final : public ATNState { 15 | public: 16 | ATNState *loopBackState = nullptr; 17 | 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/StarLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/StarLoopbackState.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | StarLoopEntryState *StarLoopbackState::getLoopEntryState() { 14 | return dynamic_cast(transitions[0]->target); 15 | } 16 | 17 | size_t StarLoopbackState::getStateType() { 18 | return STAR_LOOP_BACK; 19 | } 20 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/DecisionEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | DecisionEventInfo::DecisionEventInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, 12 | size_t stopIndex, bool fullCtx) 13 | : decision(decision), configs(configs), input(input), startIndex(startIndex), stopIndex(stopIndex), fullCtx(fullCtx) { 14 | } 15 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/TokensStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The Tokens rule start state linking to each lexer rule start state. 14 | class ANTLR4CPP_PUBLIC TokensStartState final : public DecisionState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/InputMismatchException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "InputMismatchException.h" 9 | 10 | using namespace antlr4; 11 | 12 | InputMismatchException::InputMismatchException(Parser *recognizer) 13 | : RecognitionException(recognizer, recognizer->getInputStream(), recognizer->getContext(), 14 | recognizer->getCurrentToken()) { 15 | } 16 | 17 | InputMismatchException::~InputMismatchException() { 18 | } 19 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/AbstractPredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTState; 14 | 15 | class ANTLR4CPP_PUBLIC AbstractPredicateTransition : public Transition { 16 | 17 | public: 18 | AbstractPredicateTransition(ATNState *target); 19 | ~AbstractPredicateTransition(); 20 | 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LookaheadEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LookaheadEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | LookaheadEventInfo::LookaheadEventInfo(size_t decision, ATNConfigSet *configs, size_t predictedAlt, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->predictedAlt = predictedAlt; 16 | } 17 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/RuleStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleStartState final : public ATNState { 14 | public: 15 | RuleStartState(); 16 | 17 | RuleStopState *stopState = nullptr; 18 | bool isLeftRecursiveRule = false; 19 | 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/dfa/LexerDFASerializer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Vocabulary.h" 7 | 8 | #include "dfa/LexerDFASerializer.h" 9 | 10 | using namespace antlr4::dfa; 11 | 12 | LexerDFASerializer::LexerDFASerializer(DFA *dfa) : DFASerializer(dfa, Vocabulary::EMPTY_VOCABULARY) { 13 | } 14 | 15 | LexerDFASerializer::~LexerDFASerializer() { 16 | } 17 | 18 | std::string LexerDFASerializer::getEdgeLabel(size_t i) const { 19 | return std::string("'") + static_cast(i) + "'"; 20 | } 21 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/dfa/LexerDFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "dfa/DFASerializer.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | class ANTLR4CPP_PUBLIC LexerDFASerializer : public DFASerializer { 14 | public: 15 | LexerDFASerializer(DFA *dfa); 16 | virtual ~LexerDFASerializer(); 17 | 18 | protected: 19 | virtual std::string getEdgeLabel(size_t i) const override; 20 | }; 21 | 22 | } // namespace atn 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathWildcardElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardElement : public XPathElement { 15 | public: 16 | XPathWildcardElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/ConsoleErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ConsoleErrorListener.h" 7 | 8 | using namespace antlr4; 9 | 10 | ConsoleErrorListener ConsoleErrorListener::INSTANCE; 11 | 12 | void ConsoleErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 13 | size_t line, size_t charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) { 14 | std::cerr << "line " << line << ":" << charPositionInLine << " " << msg << std::endl; 15 | } 16 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/BlockEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Terminal node of a simple {@code (a|b|c)} block. 14 | class ANTLR4CPP_PUBLIC BlockEndState final : public ATNState { 15 | public: 16 | BlockStartState *startState = nullptr; 17 | 18 | BlockEndState(); 19 | 20 | virtual size_t getStateType() override; 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/AmbiguityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AmbiguityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | AmbiguityInfo::AmbiguityInfo(size_t decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->ambigAlts = ambigAlts; 16 | } 17 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathWildcardAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardAnywhereElement : public XPathElement { 15 | public: 16 | XPathWildcardAnywhereElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ErrorNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "tree/ParseTreeVisitor.h" 8 | 9 | #include "tree/ErrorNodeImpl.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::misc; 13 | using namespace antlr4::tree; 14 | 15 | ErrorNodeImpl::ErrorNodeImpl(Token *token) : TerminalNodeImpl(token) { 16 | } 17 | 18 | ErrorNodeImpl::~ErrorNodeImpl() { 19 | } 20 | 21 | antlrcpp::Any ErrorNodeImpl::accept(ParseTreeVisitor *visitor) { 22 | return visitor->visitErrorNode(this); 23 | } 24 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/InterpreterRuleContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "InterpreterRuleContext.h" 7 | 8 | using namespace antlr4; 9 | 10 | InterpreterRuleContext::InterpreterRuleContext() : ParserRuleContext() { 11 | } 12 | 13 | InterpreterRuleContext::InterpreterRuleContext(ParserRuleContext *parent, size_t invokingStateNumber, size_t ruleIndex) 14 | : ParserRuleContext(parent, invokingStateNumber), _ruleIndex(ruleIndex) { 15 | } 16 | 17 | size_t InterpreterRuleContext::getRuleIndex() const { 18 | return _ruleIndex; 19 | } 20 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PlusLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Decision state for {@code A+} and {@code (A|B)+}. It has two transitions: 14 | /// one to the loop back to start of the block and one to exit. 15 | class ANTLR4CPP_PUBLIC PlusLoopbackState final : public DecisionState { 16 | 17 | public: 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /examples/benchmark/L1-i-cache/codegen.py: -------------------------------------------------------------------------------- 1 | tail = """ 2 | @p0 bra l1; 3 | cs2r.32 end, clock_lo; 4 | 5 | s32 time; 6 | iadd3 time, -start, end, rz; 7 | 8 | s64 ptr; 9 | s32 tid, imm4; 10 | s2r tid, threadIdx_x; 11 | mov imm4, 4; 12 | imad.wide ptr, tid, imm4, result; 13 | 14 | stg.32 [ptr], time; 15 | exit; 16 | } 17 | """ 18 | 19 | for i in range(1024): 20 | header = f""" 21 | list{i}(s64 result){{ 22 | s32 loop; 23 | mov loop, 1; 24 | s32 start, end; 25 | cs2r.32 start, clock_lo; 26 | 27 | pred p0; 28 | l1: 29 | isetp.lt.and p0, pt, loop, 512, pt; 30 | iadd3 loop, loop, 1, rz; 31 | """ 32 | body = [] 33 | for n in range(i): 34 | body.append("nop;") 35 | print(header, '\n'.join(body), tail) -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/DecisionState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC DecisionState : public ATNState { 14 | public: 15 | int decision; 16 | bool nonGreedy; 17 | 18 | private: 19 | void InitializeInstanceFields(); 20 | 21 | public: 22 | DecisionState() { 23 | InitializeInstanceFields(); 24 | } 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathWildcardElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardElement::XPathWildcardElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | 23 | return t->children; 24 | } 25 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathLexerErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathLexerErrorListener : public BaseErrorListener { 15 | public: 16 | virtual void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, 17 | size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override; 18 | }; 19 | 20 | } // namespace xpath 21 | } // namespace tree 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathRuleElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathRuleElement : public XPathElement { 15 | public: 16 | XPathRuleElement(const std::string &ruleName, size_t ruleIndex); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _ruleIndex = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PredicateEvalInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "SemanticContext.h" 7 | 8 | #include "atn/PredicateEvalInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | PredicateEvalInfo::PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex, 14 | Ref const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx) 15 | : DecisionEventInfo(decision, nullptr, input, startIndex, stopIndex, fullCtx), 16 | semctx(semctx), predictedAlt(predictedAlt), evalResult(evalResult) { 17 | } 18 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/pattern/TextChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TextChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TextChunk::TextChunk(const std::string &text) : text(text) { 13 | if (text == "") { 14 | throw IllegalArgumentException("text cannot be nul"); 15 | } 16 | 17 | } 18 | 19 | TextChunk::~TextChunk() { 20 | } 21 | 22 | std::string TextChunk::getText() { 23 | return text; 24 | } 25 | 26 | std::string TextChunk::toString() { 27 | return std::string("'") + text + std::string("'"); 28 | } 29 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathRuleAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "tree/xpath/XPathRuleAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleAnywhereElement::XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllRuleNodes(t, _ruleIndex); 20 | } 21 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathTokenAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathTokenAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathTokenAnywhereElement::XPathTokenAnywhereElement(const std::string &tokenName, int tokenType) : XPathElement(tokenName) { 15 | this->tokenType = tokenType; 16 | } 17 | 18 | std::vector XPathTokenAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllTokenNodes(t, tokenType); 20 | } 21 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathTokenElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenElement : public XPathElement { 15 | public: 16 | XPathTokenElement(const std::string &tokenName, size_t tokenType); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _tokenType = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathTokenAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenAnywhereElement : public XPathElement { 15 | protected: 16 | int tokenType = 0; 17 | public: 18 | XPathTokenAnywhereElement(const std::string &tokenName, int tokenType); 19 | 20 | virtual std::vector evaluate(ParseTree *t) override; 21 | }; 22 | 23 | } // namespace xpath 24 | } // namespace tree 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/WritableToken.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Token.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC WritableToken : public Token { 13 | public: 14 | virtual ~WritableToken(); 15 | virtual void setText(const std::string &text) = 0; 16 | virtual void setType(size_t ttype) = 0; 17 | virtual void setLine(size_t line) = 0; 18 | virtual void setCharPositionInLine(size_t pos) = 0; 19 | virtual void setChannel(size_t channel) = 0; 20 | virtual void setTokenIndex(size_t index) = 0; 21 | }; 22 | 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/WildcardTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC WildcardTransition final : public Transition { 14 | public: 15 | WildcardTransition(ATNState *target); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathWildcardAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardAnywhereElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardAnywhereElement::XPathWildcardAnywhereElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardAnywhereElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | return Trees::getDescendants(t); 23 | } 24 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/RuleStopState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The last node in the ATN for a rule, unless that rule is the start symbol. 14 | /// In that case, there is one transition to EOF. Later, we might encode 15 | /// references to all calls to this rule to compute FOLLOW sets for 16 | /// error handling. 17 | class ANTLR4CPP_PUBLIC RuleStopState final : public ATNState { 18 | 19 | public: 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/NotSetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SetTransition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC NotSetTransition final : public SetTransition { 14 | public: 15 | NotSetTransition(ATNState *target, const misc::IntervalSet &set); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathRuleAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | /// Either {@code ID} at start of path or {@code ...//ID} in middle of path. 15 | class ANTLR4CPP_PUBLIC XPathRuleAnywhereElement : public XPathElement { 16 | public: 17 | XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex); 18 | 19 | virtual std::vector evaluate(ParseTree *t) override; 20 | 21 | protected: 22 | int _ruleIndex = 0; 23 | }; 24 | 25 | } // namespace xpath 26 | } // namespace tree 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/RuleContextWithAltNum.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATN.h" 7 | 8 | #include "RuleContextWithAltNum.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RuleContextWithAltNum::RuleContextWithAltNum() : ParserRuleContext() { 14 | altNum = ATN::INVALID_ALT_NUMBER; 15 | } 16 | 17 | RuleContextWithAltNum::RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber) 18 | : ParserRuleContext(parent, invokingStateNumber) { 19 | } 20 | 21 | size_t RuleContextWithAltNum::getAltNumber() const { 22 | return altNum; 23 | } 24 | 25 | void RuleContextWithAltNum::setAltNumber(size_t number) { 26 | altNum = number; 27 | } 28 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/WildcardTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNState.h" 7 | 8 | #include "atn/WildcardTransition.h" 9 | 10 | using namespace antlr4::atn; 11 | 12 | WildcardTransition::WildcardTransition(ATNState *target) : Transition(target) { 13 | } 14 | 15 | Transition::SerializationType WildcardTransition::getSerializationType() const { 16 | return WILDCARD; 17 | } 18 | 19 | bool WildcardTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 20 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol; 21 | } 22 | 23 | std::string WildcardTransition::toString() const { 24 | return "WILDCARD " + Transition::toString() + " {}"; 25 | } 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | project(antlr4) 4 | 5 | set(CXX_STANDARD_REQUIRED ON) 6 | set(CXX_STANDARD 11) 7 | 8 | file(GLOB_RECURSE libantlrcpp_src 9 | "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" 10 | ) 11 | 12 | add_library(antlr4_static STATIC ${libantlrcpp_src}) 13 | 14 | set(libantlrcpp_include 15 | ${CMAKE_CURRENT_SOURCE_DIR}/src 16 | ${CMAKE_CURRENT_SOURCE_DIR}/src/atn 17 | ${CMAKE_CURRENT_SOURCE_DIR}/src/dfa 18 | ${CMAKE_CURRENT_SOURCE_DIR}/src/misc 19 | ${CMAKE_CURRENT_SOURCE_DIR}/src/support 20 | ${CMAKE_CURRENT_SOURCE_DIR}/src/tree 21 | ${CMAKE_CURRENT_SOURCE_DIR}/src/tree/pattern 22 | ${CMAKE_CURRENT_SOURCE_DIR}/src/tree/xpath 23 | ) 24 | 25 | 26 | target_include_directories(antlr4_static PUBLIC ${libantlrcpp_include}) 27 | 28 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 29 | target_link_libraries(antlr4_static ${UUID_LIBRARIES}) 30 | endif() 31 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/InputMismatchException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// 13 | /// This signifies any kind of mismatched input exceptions such as 14 | /// when the current input does not match the expected token. 15 | /// 16 | class ANTLR4CPP_PUBLIC InputMismatchException : public RecognitionException { 17 | public: 18 | InputMismatchException(Parser *recognizer); 19 | InputMismatchException(InputMismatchException const&) = default; 20 | ~InputMismatchException(); 21 | InputMismatchException& operator=(InputMismatchException const&) = default; 22 | }; 23 | 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/CPPUtils.h" 7 | 8 | #include "XPathElement.h" 9 | 10 | using namespace antlr4::tree; 11 | using namespace antlr4::tree::xpath; 12 | 13 | XPathElement::XPathElement(const std::string &nodeName) { 14 | _nodeName = nodeName; 15 | } 16 | 17 | XPathElement::~XPathElement() { 18 | } 19 | 20 | std::vector XPathElement::evaluate(ParseTree * /*t*/) { 21 | return {}; 22 | } 23 | 24 | std::string XPathElement::toString() const { 25 | std::string inv = _invert ? "!" : ""; 26 | return antlrcpp::toString(*this) + "[" + inv + _nodeName + "]"; 27 | } 28 | 29 | void XPathElement::setInvert(bool value) { 30 | _invert = value; 31 | } 32 | -------------------------------------------------------------------------------- /src/arch/base_arch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "src/core/instruction.h" 4 | #include "src/algorithms/register_allocator.h" 5 | 6 | namespace dada { 7 | struct CtrlLogic { 8 | int stalls = 1; 9 | int read_barrier_idx = -1; 10 | int write_barrier_idx = -1; 11 | int wait_barriers_mask = 0; 12 | int reuse_mask = 0; // bit mask 13 | bool yield = false; 14 | }; 15 | 16 | class BaseArch { 17 | public: 18 | virtual bool isVariableLatency(Instruction const* instr) = 0; 19 | virtual int getLatency(Instruction const* instr) = 0; 20 | virtual int getTputLatency(Instruction const* instr1, Instruction const* instr2) = 0; 21 | virtual int getParameterBaseOffset() const = 0; 22 | public: 23 | virtual std::vector getInstructionBinary( 24 | Instruction const* instr, RegisterAllocator const*, CtrlLogic const&) const = 0; 25 | }; // class BaseArch 26 | } // namespace dada -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PlusBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Start of {@code (A|B|...)+} loop. Technically a decision state, but 14 | /// we don't use for code generation; somebody might need it, so I'm defining 15 | /// it for completeness. In reality, the node is the 16 | /// real decision-making note for {@code A+}. 17 | class ANTLR4CPP_PUBLIC PlusBlockStartState final : public BlockStartState { 18 | public: 19 | PlusLoopbackState *loopBackState = nullptr; 20 | 21 | virtual size_t getStateType() override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/RangeTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RangeTransition final : public Transition { 14 | public: 15 | const size_t from; 16 | const size_t to; 17 | 18 | RangeTransition(ATNState *target, size_t from, size_t to); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | 22 | virtual misc::IntervalSet label() const override; 23 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 24 | 25 | virtual std::string toString() const override; 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/EmptyPredictionContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SingletonPredictionContext.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EmptyPredictionContext : public SingletonPredictionContext { 14 | public: 15 | EmptyPredictionContext(); 16 | 17 | virtual bool isEmpty() const override; 18 | virtual size_t size() const override; 19 | virtual Ref getParent(size_t index) const override; 20 | virtual size_t getReturnState(size_t index) const override; 21 | virtual std::string toString() const override; 22 | 23 | virtual bool operator == (const PredictionContext &o) const override; 24 | }; 25 | 26 | } // namespace atn 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/ANTLRFileStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | #include "ANTLRFileStream.h" 9 | 10 | using namespace antlr4; 11 | 12 | ANTLRFileStream::ANTLRFileStream(const std::string &fileName) { 13 | _fileName = fileName; 14 | loadFromFile(fileName); 15 | } 16 | 17 | void ANTLRFileStream::loadFromFile(const std::string &fileName) { 18 | _fileName = fileName; 19 | if (_fileName.empty()) { 20 | return; 21 | } 22 | 23 | #ifdef _MSC_VER 24 | std::ifstream stream(antlrcpp::s2ws(fileName), std::ios::binary); 25 | #else 26 | std::ifstream stream(fileName, std::ios::binary); 27 | #endif 28 | 29 | ANTLRInputStream::load(stream); 30 | } 31 | 32 | std::string ANTLRFileStream::getSourceName() const { 33 | return _fileName; 34 | } 35 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/TerminalNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ParseTree.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNode : public ParseTree { 14 | public: 15 | ~TerminalNode() override; 16 | 17 | virtual Token* getSymbol() = 0; 18 | 19 | /** Set the parent for this leaf node. 20 | * 21 | * Technically, this is not backward compatible as it changes 22 | * the interface but no one was able to create custom 23 | * TerminalNodes anyway so I'm adding as it improves internal 24 | * code quality. 25 | * 26 | * @since 4.7 27 | */ 28 | virtual void setParent(RuleContext *parent) = 0; 29 | }; 30 | 31 | } // namespace tree 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /src/algorithms/reuse_setter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "reuse_setter.h" 4 | 5 | using namespace std; 6 | 7 | namespace dada { 8 | ReuseSetter::ReuseSetter( 9 | Kernel const* kernel, CFG const* cfg, 10 | RegisterAllocator const* register_allocator, int arch 11 | ) : kernel_(kernel), cfg_(cfg), register_allocator_(register_allocator), arch_(arch) {} 12 | 13 | void ReuseSetter::set() { 14 | reuse_masks_.resize(kernel_->instructions_.size(), 0); 15 | unordered_set const reuseable_opcodes { 16 | HADD2, HMUL2, HFMA2, 17 | FADD, FMUL, FFMA, MUFU, 18 | IADD3, IMAD, 19 | }; 20 | for(BasicBlock* bb : cfg_->basic_blocks_){ 21 | for(int instr_idx = bb->start_; instr_idx <= bb->end_; ++instr_idx){ 22 | auto const& instr = kernel_->instructions_[instr_idx]; 23 | if(instr->opcode_ == FFMA) 24 | reuse_masks_[instr_idx] = 3; 25 | } // for each instruction 26 | } // for each basic block 27 | } 28 | } -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/SetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// A transition containing a set of values. 15 | class ANTLR4CPP_PUBLIC SetTransition : public Transition { 16 | public: 17 | const misc::IntervalSet set; 18 | 19 | SetTransition(ATNState *target, const misc::IntervalSet &set); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/ANTLRFileStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRInputStream.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// This is an ANTLRInputStream that is loaded from a file all at once 13 | /// when you construct the object (or call load()). 14 | // TODO: this class needs testing. 15 | class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream { 16 | protected: 17 | std::string _fileName; // UTF-8 encoded file name. 18 | 19 | public: 20 | // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM). 21 | ANTLRFileStream(const std::string &fileName); 22 | 23 | virtual void loadFromFile(const std::string &fileName); 24 | virtual std::string getSourceName() const override; 25 | }; 26 | 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/dfa/DFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Vocabulary.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | /// A DFA walker that knows how to dump them to serialized strings. 14 | class ANTLR4CPP_PUBLIC DFASerializer { 15 | public: 16 | DFASerializer(const DFA *dfa, const std::vector& tnames); 17 | DFASerializer(const DFA *dfa, const Vocabulary &vocabulary); 18 | virtual ~DFASerializer(); 19 | 20 | virtual std::string toString() const; 21 | 22 | protected: 23 | virtual std::string getEdgeLabel(size_t i) const; 24 | virtual std::string getStateString(DFAState *s) const; 25 | 26 | private: 27 | const DFA *_dfa; 28 | const Vocabulary &_vocabulary; 29 | }; 30 | 31 | } // namespace atn 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/pattern/TagChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TagChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TagChunk::TagChunk(const std::string &tag) : TagChunk("", tag) { 13 | } 14 | 15 | TagChunk::TagChunk(const std::string &label, const std::string &tag) : _tag(tag), _label(label) { 16 | if (tag.empty()) { 17 | throw IllegalArgumentException("tag cannot be null or empty"); 18 | } 19 | 20 | } 21 | 22 | TagChunk::~TagChunk() { 23 | } 24 | 25 | std::string TagChunk::getTag() { 26 | return _tag; 27 | } 28 | 29 | std::string TagChunk::getLabel() { 30 | return _label; 31 | } 32 | 33 | std::string TagChunk::toString() { 34 | if (!_label.empty()) { 35 | return _label + ":" + _tag; 36 | } 37 | 38 | return _tag; 39 | } 40 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/AtomTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// TO_DO: make all transitions sets? no, should remove set edges. 14 | class ANTLR4CPP_PUBLIC AtomTransition final : public Transition { 15 | public: 16 | /// The token type or character value; or, signifies special label. 17 | const size_t _label; 18 | 19 | AtomTransition(ATNState *target, size_t label); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/DecisionInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ErrorInfo.h" 7 | #include "atn/LookaheadEventInfo.h" 8 | 9 | #include "atn/DecisionInfo.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | DecisionInfo::DecisionInfo(size_t decision) : decision(decision) { 14 | } 15 | 16 | std::string DecisionInfo::toString() const { 17 | std::stringstream ss; 18 | 19 | ss << "{decision=" << decision << ", contextSensitivities=" << contextSensitivities.size() << ", errors="; 20 | ss << errors.size() << ", ambiguities=" << ambiguities.size() << ", SLL_lookahead=" << SLL_TotalLook; 21 | ss << ", SLL_ATNTransitions=" << SLL_ATNTransitions << ", SLL_DFATransitions=" << SLL_DFATransitions; 22 | ss << ", LL_Fallback=" << LL_Fallback << ", LL_lookahead=" << LL_TotalLook << ", LL_ATNTransitions=" << LL_ATNTransitions << '}'; 23 | 24 | return ss.str(); 25 | } 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/AtomTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/AtomTransition.h" 10 | 11 | using namespace antlr4::misc; 12 | using namespace antlr4::atn; 13 | 14 | AtomTransition::AtomTransition(ATNState *target, size_t label) : Transition(target), _label(label) { 15 | } 16 | 17 | Transition::SerializationType AtomTransition::getSerializationType() const { 18 | return ATOM; 19 | } 20 | 21 | IntervalSet AtomTransition::label() const { 22 | return IntervalSet::of((int)_label); 23 | } 24 | 25 | bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 26 | return _label == symbol; 27 | } 28 | 29 | std::string AtomTransition::toString() const { 30 | return "ATOM " + Transition::toString() + " { label: " + std::to_string(_label) + " }"; 31 | } 32 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/EmptyPredictionContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EmptyPredictionContext.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EmptyPredictionContext::EmptyPredictionContext() : SingletonPredictionContext(nullptr, EMPTY_RETURN_STATE) { 11 | } 12 | 13 | bool EmptyPredictionContext::isEmpty() const { 14 | return true; 15 | } 16 | 17 | size_t EmptyPredictionContext::size() const { 18 | return 1; 19 | } 20 | 21 | Ref EmptyPredictionContext::getParent(size_t /*index*/) const { 22 | return nullptr; 23 | } 24 | 25 | size_t EmptyPredictionContext::getReturnState(size_t /*index*/) const { 26 | return returnState; 27 | } 28 | 29 | bool EmptyPredictionContext::operator == (const PredictionContext &o) const { 30 | return this == &o; 31 | } 32 | 33 | std::string EmptyPredictionContext::toString() const { 34 | return "$"; 35 | } 36 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/TerminalNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNodeImpl : public virtual TerminalNode { 14 | public: 15 | Token *symbol; 16 | 17 | TerminalNodeImpl(Token *symbol); 18 | 19 | virtual Token* getSymbol() override; 20 | virtual void setParent(RuleContext *parent) override; 21 | virtual misc::Interval getSourceInterval() override; 22 | 23 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 24 | 25 | virtual std::string getText() override; 26 | virtual std::string toStringTree(Parser *parser) override; 27 | virtual std::string toString() override; 28 | virtual std::string toStringTree() override; 29 | 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/LexerNoViableAltException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | #include "atn/ATNConfigSet.h" 10 | 11 | namespace antlr4 { 12 | 13 | class ANTLR4CPP_PUBLIC LexerNoViableAltException : public RecognitionException { 14 | public: 15 | LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs); 17 | 18 | virtual size_t getStartIndex(); 19 | virtual atn::ATNConfigSet* getDeadEndConfigs(); 20 | virtual std::string toString(); 21 | 22 | private: 23 | /// Matching attempted at what input index? 24 | const size_t _startIndex; 25 | 26 | /// Which configurations did we try at input.index() that couldn't match input.LA(1)? 27 | atn::ATNConfigSet *_deadEndConfigs; 28 | 29 | }; 30 | 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/NotSetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/NotSetTransition.h" 7 | #include "atn/ATNState.h" 8 | #include "misc/IntervalSet.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | NotSetTransition::NotSetTransition(ATNState *target, const misc::IntervalSet &set) : SetTransition(target, set) { 14 | } 15 | 16 | Transition::SerializationType NotSetTransition::getSerializationType() const { 17 | return NOT_SET; 18 | } 19 | 20 | bool NotSetTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 21 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol 22 | && !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol); 23 | } 24 | 25 | std::string NotSetTransition::toString() const { 26 | return "NOT_SET " + Transition::toString() + " { " + SetTransition::toString() + " }"; 27 | } 28 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PrecedencePredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC PrecedencePredicateTransition final : public AbstractPredicateTransition { 15 | public: 16 | const int precedence; 17 | 18 | PrecedencePredicateTransition(ATNState *target, int precedence); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | virtual bool isEpsilon() const override; 22 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 23 | Ref getPredicate() const; 24 | virtual std::string toString() const override; 25 | 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /src/algorithms/cfg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "src/core/kernel.h" 6 | 7 | namespace dada { 8 | class BasicBlock; 9 | class Edge; 10 | class CFG; 11 | 12 | class BasicBlock { 13 | public: 14 | int start_; 15 | int end_; 16 | std::vector inEdges_; 17 | std::vector outEdges_; 18 | friend CFG; 19 | public: 20 | BasicBlock(int start); 21 | 22 | void setEnd(int end); 23 | 24 | Edge* addSuccessor(BasicBlock* successor); 25 | Edge* addPredecessor(BasicBlock* predecessor); 26 | }; 27 | 28 | class Edge { 29 | public: 30 | BasicBlock* tail_; 31 | BasicBlock* head_; 32 | friend CFG; 33 | public: 34 | Edge(BasicBlock* tail, BasicBlock* head); 35 | }; 36 | 37 | class CFG { 38 | public: 39 | std::vector basic_blocks_; 40 | std::vector edges_; 41 | BasicBlock* root_; 42 | 43 | public: 44 | CFG(Kernel const* kernel); 45 | ~CFG(); 46 | 47 | void printCFG() const; 48 | }; 49 | } // namespace dada -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/misc/InterpreterDataReader.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | struct InterpreterData { 14 | atn::ATN atn; 15 | dfa::Vocabulary vocabulary; 16 | std::vector ruleNames; 17 | std::vector channels; // Only valid for lexer grammars. 18 | std::vector modes; // ditto 19 | 20 | InterpreterData() {}; // For invalid content. 21 | InterpreterData(std::vector const& literalNames, std::vector const& symbolicNames); 22 | }; 23 | 24 | // A class to read plain text interpreter data produced by ANTLR. 25 | class ANTLR4CPP_PUBLIC InterpreterDataReader { 26 | public: 27 | static InterpreterData parseFile(std::string const& fileName); 28 | }; 29 | 30 | } // namespace atn 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/SetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | #include "misc/IntervalSet.h" 8 | 9 | #include "atn/SetTransition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | SetTransition::SetTransition(ATNState *target, const misc::IntervalSet &aSet) 15 | : Transition(target), set(aSet.isEmpty() ? misc::IntervalSet::of(Token::INVALID_TYPE) : aSet) { 16 | } 17 | 18 | Transition::SerializationType SetTransition::getSerializationType() const { 19 | return SET; 20 | } 21 | 22 | misc::IntervalSet SetTransition::label() const { 23 | return set; 24 | } 25 | 26 | bool SetTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return set.contains(symbol); 28 | } 29 | 30 | std::string SetTransition::toString() const { 31 | return "SET " + Transition::toString() + " { set: " + set.toString() + "}"; 32 | } 33 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/StarLoopEntryState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopEntryState final : public DecisionState { 14 | public: 15 | StarLoopEntryState(); 16 | 17 | /** 18 | * Indicates whether this state can benefit from a precedence DFA during SLL 19 | * decision making. 20 | * 21 | *

This is a computed property that is calculated during ATN deserialization 22 | * and stored for use in {@link ParserATNSimulator} and 23 | * {@link ParserInterpreter}.

24 | * 25 | * @see DFA#isPrecedenceDfa() 26 | */ 27 | bool isPrecedenceDecision = false; 28 | 29 | StarLoopbackState *loopBackState = nullptr; 30 | 31 | virtual size_t getStateType() override; 32 | }; 33 | 34 | } // namespace atn 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ActionTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ActionTransition final : public Transition { 14 | public: 15 | const size_t ruleIndex; 16 | const size_t actionIndex; 17 | const bool isCtxDependent; // e.g., $i ref in action 18 | 19 | ActionTransition(ATNState *target, size_t ruleIndex); 20 | 21 | ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent); 22 | 23 | virtual SerializationType getSerializationType() const override; 24 | 25 | virtual bool isEpsilon() const override; 26 | 27 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 28 | 29 | virtual std::string toString() const override; 30 | }; 31 | 32 | } // namespace atn 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/RangeTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | 8 | #include "atn/RangeTransition.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RangeTransition::RangeTransition(ATNState *target, size_t from, size_t to) : Transition(target), from(from), to(to) { 14 | } 15 | 16 | Transition::SerializationType RangeTransition::getSerializationType() const { 17 | return RANGE; 18 | } 19 | 20 | misc::IntervalSet RangeTransition::label() const { 21 | return misc::IntervalSet::of((int)from, (int)to); 22 | } 23 | 24 | bool RangeTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 25 | return symbol >= from && symbol <= to; 26 | } 27 | 28 | std::string RangeTransition::toString() const { 29 | return "RANGE " + Transition::toString() + " { from: " + std::to_string(from) + ", to: " + std::to_string(to) + " }"; 30 | } 31 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathRuleElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathRuleElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleElement::XPathRuleElement(const std::string &ruleName, size_t ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleElement::evaluate(ParseTree *t) { 19 | // return all children of t that match nodeName 20 | std::vector nodes; 21 | for (auto c : t->children) { 22 | if (antlrcpp::is(c)) { 23 | ParserRuleContext *ctx = dynamic_cast(c); 24 | if ((ctx->getRuleIndex() == _ruleIndex && !_invert) || (ctx->getRuleIndex() != _ruleIndex && _invert)) { 25 | nodes.push_back(ctx); 26 | } 27 | } 28 | } 29 | return nodes; 30 | } 31 | -------------------------------------------------------------------------------- /examples/benchmark/L0-i-cache/main.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void load_n_launch(CUmodule& module, int i, int* output, int* output_d){ 7 | CUfunction kernel; 8 | string kernel_name = "list" + to_string(i); 9 | cuModuleGetFunction(&kernel, module, kernel_name.c_str()); 10 | 11 | void * args[] = {&output_d}; 12 | cuLaunchKernel(kernel, 1, 1, 1, 13 | 32, 1, 1, 14 | 128, 0, args, 0); 15 | cudaDeviceSynchronize(); 16 | 17 | cudaMemcpy(output, output_d, 32*sizeof(int), cudaMemcpyDeviceToHost); 18 | 19 | cout << "nops: \t" << i << ", cycles needed:\t" 20 | << output[0] << '\n'; 21 | } 22 | 23 | int main() { 24 | int * output; 25 | int * output_d; 26 | 27 | output = (int*)malloc(32*sizeof(int)); 28 | 29 | for(int i=0; i<32; ++i) output[i] = 0; 30 | 31 | cudaMalloc((void**)&output_d, 32*sizeof(int)); 32 | 33 | CUmodule module; 34 | 35 | 36 | cuModuleLoad(&module, "l0-icache.cubin"); 37 | for(int i=0; i<100; ++i){ 38 | load_n_launch(module, i, output, output_d); 39 | } 40 | 41 | return 0; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/pattern/TokenTagToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/TokenTagToken.h" 7 | 8 | using namespace antlr4::tree::pattern; 9 | 10 | TokenTagToken::TokenTagToken(const std::string &/*tokenName*/, int type) 11 | : CommonToken(type), tokenName(""), label("") { 12 | } 13 | 14 | TokenTagToken::TokenTagToken(const std::string &tokenName, int type, const std::string &label) 15 | : CommonToken(type), tokenName(tokenName), label(label) { 16 | } 17 | 18 | std::string TokenTagToken::getTokenName() const { 19 | return tokenName; 20 | } 21 | 22 | std::string TokenTagToken::getLabel() const { 23 | return label; 24 | } 25 | 26 | std::string TokenTagToken::getText() const { 27 | if (!label.empty()) { 28 | return "<" + label + ":" + tokenName + ">"; 29 | } 30 | 31 | return "<" + tokenName + ">"; 32 | } 33 | 34 | std::string TokenTagToken::toString() const { 35 | return tokenName + ":" + std::to_string(_type); 36 | } 37 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/RuleContextWithAltNum.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ParserRuleContext.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A handy class for use with 13 | /// 14 | /// options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;} 15 | /// 16 | /// that provides a backing field / impl for the outer alternative number 17 | /// matched for an internal parse tree node. 18 | /// 19 | /// I'm only putting into Java runtime as I'm certain I'm the only one that 20 | /// will really every use this. 21 | class ANTLR4CPP_PUBLIC RuleContextWithAltNum : public ParserRuleContext { 22 | public: 23 | size_t altNum = 0; 24 | 25 | RuleContextWithAltNum(); 26 | RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber); 27 | 28 | virtual size_t getAltNumber() const override; 29 | virtual void setAltNumber(size_t altNum) override; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ParseTreeWalker.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ParseTreeWalker { 14 | public: 15 | static ParseTreeWalker &DEFAULT; 16 | 17 | virtual ~ParseTreeWalker(); 18 | 19 | virtual void walk(ParseTreeListener *listener, ParseTree *t) const; 20 | 21 | protected: 22 | /// The discovery of a rule node, involves sending two events: the generic 23 | /// and a 24 | /// -specific event. First we trigger the generic and then 25 | /// the rule specific. We do them in reverse order upon finishing the node. 26 | virtual void enterRule(ParseTreeListener *listener, ParseTree *r) const; 27 | virtual void exitRule(ParseTreeListener *listener, ParseTree *r) const; 28 | }; 29 | 30 | } // namespace tree 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/support/Arrays.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "Exceptions.h" 8 | 9 | #include "support/Arrays.h" 10 | 11 | using namespace antlrcpp; 12 | 13 | std::string Arrays::listToString(const std::vector &list, const std::string &separator) 14 | { 15 | std::stringstream ss; 16 | bool firstEntry = true; 17 | 18 | ss << '['; 19 | for (auto &entry : list) { 20 | ss << entry; 21 | if (firstEntry) { 22 | ss << separator; 23 | firstEntry = false; 24 | } 25 | } 26 | 27 | ss << ']'; 28 | return ss.str(); 29 | } 30 | 31 | template <> 32 | std::string Arrays::toString(const std::vector &source) { 33 | std::string result = "["; 34 | bool firstEntry = true; 35 | for (auto value : source) { 36 | result += value->toStringTree(); 37 | if (firstEntry) { 38 | result += ", "; 39 | firstEntry = false; 40 | } 41 | } 42 | return result + "]"; 43 | } 44 | -------------------------------------------------------------------------------- /examples/benchmark/L1-i-cache/main.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void load_n_launch(CUmodule& module, int i, int* output, int* output_d){ 7 | CUfunction kernel; 8 | string kernel_name = "list" + to_string(i); 9 | cuModuleGetFunction(&kernel, module, kernel_name.c_str()); 10 | 11 | void * args[] = {&output_d}; 12 | cuLaunchKernel(kernel, 1, 1, 1, 13 | 32, 1, 1, 14 | 128, 0, args, 0); 15 | cudaDeviceSynchronize(); 16 | 17 | cudaMemcpy(output, output_d, 32*sizeof(int), cudaMemcpyDeviceToHost); 18 | 19 | cout << "nops: \t" << i << ", cycles needed:\t" 20 | << output[0] << ".\t Cycles per loop:\t" << output[0]/512 << "\n"; 21 | } 22 | 23 | int main() { 24 | int * output; 25 | int * output_d; 26 | 27 | output = (int*)malloc(32*sizeof(int)); 28 | 29 | for(int i=0; i<32; ++i) output[i] = 0; 30 | 31 | cudaMalloc((void**)&output_d, 32*sizeof(int)); 32 | 33 | CUmodule module; 34 | 35 | 36 | cuModuleLoad(&module, "l1-icache.cubin"); 37 | for(int i=0; i<1024; ++i){ 38 | load_n_launch(module, i, output, output_d); 39 | } 40 | 41 | return 0; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ErrorNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ErrorNode.h" 9 | #include "tree/TerminalNodeImpl.h" 10 | #include "misc/Interval.h" 11 | 12 | #include "support/Any.h" 13 | 14 | namespace antlr4 { 15 | namespace tree { 16 | 17 | /// 18 | /// Represents a token that was consumed during resynchronization 19 | /// rather than during a valid match operation. For example, 20 | /// we will create this kind of a node during single token insertion 21 | /// and deletion as well as during "consume until error recovery set" 22 | /// upon no viable alternative exceptions. 23 | /// 24 | class ANTLR4CPP_PUBLIC ErrorNodeImpl : public virtual TerminalNodeImpl, public virtual ErrorNode { 25 | public: 26 | ErrorNodeImpl(Token *token); 27 | ~ErrorNodeImpl() override; 28 | 29 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/support/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | namespace antlrcpp { 9 | 10 | void replaceAll(std::string& str, std::string const& from, std::string const& to) 11 | { 12 | if (from.empty()) 13 | return; 14 | 15 | size_t start_pos = 0; 16 | while ((start_pos = str.find(from, start_pos)) != std::string::npos) { 17 | str.replace(start_pos, from.length(), to); 18 | start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'. 19 | } 20 | } 21 | 22 | std::string ws2s(std::wstring const& wstr) { 23 | std::wstring_convert> converter; 24 | std::string narrow = converter.to_bytes(wstr); 25 | 26 | return narrow; 27 | } 28 | 29 | std::wstring s2ws(const std::string &str) { 30 | std::wstring_convert> converter; 31 | std::wstring wide = converter.from_bytes(str); 32 | 33 | return wide; 34 | } 35 | 36 | } // namespace antrlcpp 37 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/EpsilonTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EpsilonTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EpsilonTransition::EpsilonTransition(ATNState *target) : EpsilonTransition(target, INVALID_INDEX) { 11 | } 12 | 13 | EpsilonTransition::EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn) 14 | : Transition(target), _outermostPrecedenceReturn(outermostPrecedenceReturn) { 15 | } 16 | 17 | size_t EpsilonTransition::outermostPrecedenceReturn() { 18 | return _outermostPrecedenceReturn; 19 | } 20 | 21 | Transition::SerializationType EpsilonTransition::getSerializationType() const { 22 | return EPSILON; 23 | } 24 | 25 | bool EpsilonTransition::isEpsilon() const { 26 | return true; 27 | } 28 | 29 | bool EpsilonTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 30 | return false; 31 | } 32 | 33 | std::string EpsilonTransition::toString() const { 34 | return "EPSILON " + Transition::toString() + " {}"; 35 | } 36 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathTokenElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | #include "support/CPPUtils.h" 9 | #include "Token.h" 10 | 11 | #include "XPathTokenElement.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | using namespace antlr4::tree::xpath; 16 | 17 | XPathTokenElement::XPathTokenElement(const std::string &tokenName, size_t tokenType) : XPathElement(tokenName) { 18 | _tokenType = tokenType; 19 | } 20 | 21 | std::vector XPathTokenElement::evaluate(ParseTree *t) { 22 | // return all children of t that match nodeName 23 | std::vector nodes; 24 | for (auto c : t->children) { 25 | if (antlrcpp::is(c)) { 26 | TerminalNode *tnode = dynamic_cast(c); 27 | if ((tnode->getSymbol()->getType() == _tokenType && !_invert) || (tnode->getSymbol()->getType() != _tokenType && _invert)) { 28 | nodes.push_back(tnode); 29 | } 30 | } 31 | } 32 | return nodes; 33 | } 34 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/ConsoleErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC ConsoleErrorListener : public BaseErrorListener { 13 | public: 14 | /** 15 | * Provides a default instance of {@link ConsoleErrorListener}. 16 | */ 17 | static ConsoleErrorListener INSTANCE; 18 | 19 | /** 20 | * {@inheritDoc} 21 | * 22 | *

23 | * This implementation prints messages to {@link System#err} containing the 24 | * values of {@code line}, {@code charPositionInLine}, and {@code msg} using 25 | * the following format.

26 | * 27 | *
28 |      * line line:charPositionInLine msg
29 |      * 
30 | */ 31 | virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine, 32 | const std::string &msg, std::exception_ptr e) override; 33 | }; 34 | 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | class ParseTree; 13 | 14 | namespace xpath { 15 | 16 | class ANTLR4CPP_PUBLIC XPathElement { 17 | public: 18 | /// Construct element like {@code /ID} or {@code ID} or {@code /*} etc... 19 | /// op is null if just node 20 | XPathElement(const std::string &nodeName); 21 | XPathElement(XPathElement const&) = default; 22 | virtual ~XPathElement(); 23 | 24 | XPathElement& operator=(XPathElement const&) = default; 25 | 26 | /// Given tree rooted at {@code t} return all nodes matched by this path 27 | /// element. 28 | virtual std::vector evaluate(ParseTree *t); 29 | virtual std::string toString() const; 30 | 31 | void setInvert(bool value); 32 | 33 | protected: 34 | std::string _nodeName; 35 | bool _invert = false; 36 | }; 37 | 38 | } // namespace xpath 39 | } // namespace tree 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/FailedPredicateException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A semantic predicate failed during validation. Validation of predicates 13 | /// occurs when normally parsing the alternative just like matching a token. 14 | /// Disambiguating predicate evaluation occurs when we test a predicate during 15 | /// prediction. 16 | class ANTLR4CPP_PUBLIC FailedPredicateException : public RecognitionException { 17 | public: 18 | FailedPredicateException(Parser *recognizer); 19 | FailedPredicateException(Parser *recognizer, const std::string &predicate); 20 | FailedPredicateException(Parser *recognizer, const std::string &predicate, const std::string &message); 21 | 22 | virtual size_t getRuleIndex(); 23 | virtual size_t getPredIndex(); 24 | virtual std::string getPredicate(); 25 | 26 | private: 27 | size_t _ruleIndex; 28 | size_t _predicateIndex; 29 | std::string _predicate; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/Transition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "support/Arrays.h" 8 | 9 | #include "atn/Transition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | using namespace antlrcpp; 15 | 16 | const std::vector Transition::serializationNames = { 17 | "INVALID", "EPSILON", "RANGE", "RULE", "PREDICATE", "ATOM", "ACTION", "SET", "NOT_SET", "WILDCARD", "PRECEDENCE" 18 | }; 19 | 20 | Transition::Transition(ATNState *target) { 21 | if (target == nullptr) { 22 | throw NullPointerException("target cannot be null."); 23 | } 24 | 25 | this->target = target; 26 | } 27 | 28 | Transition::~Transition() { 29 | } 30 | 31 | bool Transition::isEpsilon() const { 32 | return false; 33 | } 34 | 35 | misc::IntervalSet Transition::label() const { 36 | return misc::IntervalSet::EMPTY_SET; 37 | } 38 | 39 | std::string Transition::toString() const { 40 | std::stringstream ss; 41 | ss << "(Transition " << std::hex << this << ", target: " << std::hex << target << ')'; 42 | 43 | return ss.str(); 44 | } 45 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/BaseErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BaseErrorListener.h" 7 | #include "RecognitionException.h" 8 | 9 | using namespace antlr4; 10 | 11 | void BaseErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, size_t /*line*/, 12 | size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | 15 | void BaseErrorListener::reportAmbiguity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 16 | size_t /*stopIndex*/, bool /*exact*/, const antlrcpp::BitSet &/*ambigAlts*/, atn::ATNConfigSet * /*configs*/) { 17 | } 18 | 19 | void BaseErrorListener::reportAttemptingFullContext(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 20 | size_t /*stopIndex*/, const antlrcpp::BitSet &/*conflictingAlts*/, atn::ATNConfigSet * /*configs*/) { 21 | } 22 | 23 | void BaseErrorListener::reportContextSensitivity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 24 | size_t /*stopIndex*/, size_t /*prediction*/, atn::ATNConfigSet * /*configs*/) { 25 | } 26 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PrecedencePredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PrecedencePredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | PrecedencePredicateTransition::PrecedencePredicateTransition(ATNState *target, int precedence) 11 | : AbstractPredicateTransition(target), precedence(precedence) { 12 | } 13 | 14 | Transition::SerializationType PrecedencePredicateTransition::getSerializationType() const { 15 | return PRECEDENCE; 16 | } 17 | 18 | bool PrecedencePredicateTransition::isEpsilon() const { 19 | return true; 20 | } 21 | 22 | bool PrecedencePredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 23 | return false; 24 | } 25 | 26 | Ref PrecedencePredicateTransition::getPredicate() const { 27 | return std::make_shared(precedence); 28 | } 29 | 30 | std::string PrecedencePredicateTransition::toString() const { 31 | return "PRECEDENCE " + Transition::toString() + " { precedence: " + std::to_string(precedence) + " }"; 32 | } 33 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/TokenFactory.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// The default mechanism for creating tokens. It's used by default in Lexer and 13 | /// the error handling strategy (to create missing tokens). Notifying the parser 14 | /// of a new factory means that it notifies it's token source and error strategy. 15 | template 16 | class ANTLR4CPP_PUBLIC TokenFactory { 17 | public: 18 | virtual ~TokenFactory() {} 19 | 20 | /// This is the method used to create tokens in the lexer and in the 21 | /// error handling strategy. If text!=null, than the start and stop positions 22 | /// are wiped to -1 in the text override is set in the CommonToken. 23 | virtual std::unique_ptr create(std::pair source, size_t type, const std::string &text, 24 | size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) = 0; 25 | 26 | /// Generically useful 27 | virtual std::unique_ptr create(size_t type, const std::string &text) = 0; 28 | }; 29 | 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerMoreAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerMoreAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerMoreAction::getInstance() { 16 | static Ref instance(new LexerMoreAction()); 17 | return instance; 18 | } 19 | 20 | LexerMoreAction::LexerMoreAction() { 21 | } 22 | 23 | LexerActionType LexerMoreAction::getActionType() const { 24 | return LexerActionType::MORE; 25 | } 26 | 27 | bool LexerMoreAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerMoreAction::execute(Lexer *lexer) { 32 | lexer->more(); 33 | } 34 | 35 | size_t LexerMoreAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerMoreAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerMoreAction::toString() const { 46 | return "more"; 47 | } 48 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerSkipAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerSkipAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerSkipAction::getInstance() { 16 | static Ref instance(new LexerSkipAction()); 17 | return instance; 18 | } 19 | 20 | LexerSkipAction::LexerSkipAction() { 21 | } 22 | 23 | LexerActionType LexerSkipAction::getActionType() const { 24 | return LexerActionType::SKIP; 25 | } 26 | 27 | bool LexerSkipAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerSkipAction::execute(Lexer *lexer) { 32 | lexer->skip(); 33 | } 34 | 35 | size_t LexerSkipAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerSkipAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerSkipAction::toString() const { 46 | return "skip"; 47 | } 48 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/NoViableAltException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "NoViableAltException.h" 9 | 10 | using namespace antlr4; 11 | 12 | NoViableAltException::NoViableAltException(Parser *recognizer) 13 | : NoViableAltException(recognizer, recognizer->getTokenStream(), recognizer->getCurrentToken(), 14 | recognizer->getCurrentToken(), nullptr, recognizer->getContext(), false) { 15 | } 16 | 17 | NoViableAltException::NoViableAltException(Parser *recognizer, TokenStream *input,Token *startToken, 18 | Token *offendingToken, atn::ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx, bool deleteConfigs) 19 | : RecognitionException("No viable alternative", recognizer, input, ctx, offendingToken), 20 | _deadEndConfigs(deadEndConfigs), _startToken(startToken), _deleteConfigs(deleteConfigs) { 21 | } 22 | 23 | NoViableAltException::~NoViableAltException() { 24 | if (_deleteConfigs) 25 | delete _deadEndConfigs; 26 | } 27 | 28 | Token* NoViableAltException::getStartToken() const { 29 | return _startToken; 30 | } 31 | 32 | atn::ATNConfigSet* NoViableAltException::getDeadEndConfigs() const { 33 | return _deadEndConfigs; 34 | } 35 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ParseTreeListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | /** This interface describes the minimal core of methods triggered 14 | * by {@link ParseTreeWalker}. E.g., 15 | * 16 | * ParseTreeWalker walker = new ParseTreeWalker(); 17 | * walker.walk(myParseTreeListener, myParseTree); <-- triggers events in your listener 18 | * 19 | * If you want to trigger events in multiple listeners during a single 20 | * tree walk, you can use the ParseTreeDispatcher object available at 21 | * 22 | * https://github.com/antlr/antlr4/issues/841 23 | */ 24 | class ANTLR4CPP_PUBLIC ParseTreeListener { 25 | public: 26 | virtual ~ParseTreeListener(); 27 | 28 | virtual void visitTerminal(TerminalNode *node) = 0; 29 | virtual void visitErrorNode(ErrorNode *node) = 0; 30 | virtual void enterEveryRule(ParserRuleContext *ctx) = 0; 31 | virtual void exitEveryRule(ParserRuleContext *ctx) = 0; 32 | 33 | bool operator == (const ParseTreeListener &other) { 34 | return this == &other; 35 | } 36 | }; 37 | 38 | } // namespace tree 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/RuleTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | #include "atn/RuleTransition.h" 8 | 9 | using namespace antlr4::atn; 10 | 11 | RuleTransition::RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState) 12 | : RuleTransition(ruleStart, ruleIndex, 0, followState) { 13 | } 14 | 15 | RuleTransition::RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState) 16 | : Transition(ruleStart), ruleIndex(ruleIndex), precedence(precedence) { 17 | this->followState = followState; 18 | } 19 | 20 | Transition::SerializationType RuleTransition::getSerializationType() const { 21 | return RULE; 22 | } 23 | 24 | bool RuleTransition::isEpsilon() const { 25 | return true; 26 | } 27 | 28 | bool RuleTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 29 | return false; 30 | } 31 | 32 | std::string RuleTransition::toString() const { 33 | std::stringstream ss; 34 | ss << "RULE " << Transition::toString() << " { ruleIndex: " << ruleIndex << ", precedence: " << precedence << 35 | ", followState: " << std::hex << followState << " }"; 36 | return ss.str(); 37 | } 38 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/LexerNoViableAltException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "support/CPPUtils.h" 8 | #include "CharStream.h" 9 | #include "Lexer.h" 10 | 11 | #include "LexerNoViableAltException.h" 12 | 13 | using namespace antlr4; 14 | 15 | LexerNoViableAltException::LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs) 17 | : RecognitionException(lexer, input, nullptr, nullptr), _startIndex(startIndex), _deadEndConfigs(deadEndConfigs) { 18 | } 19 | 20 | size_t LexerNoViableAltException::getStartIndex() { 21 | return _startIndex; 22 | } 23 | 24 | atn::ATNConfigSet* LexerNoViableAltException::getDeadEndConfigs() { 25 | return _deadEndConfigs; 26 | } 27 | 28 | std::string LexerNoViableAltException::toString() { 29 | std::string symbol; 30 | if (_startIndex < getInputStream()->size()) { 31 | symbol = static_cast(getInputStream())->getText(misc::Interval(_startIndex, _startIndex)); 32 | symbol = antlrcpp::escapeWhitespace(symbol, false); 33 | } 34 | std::string format = "LexerNoViableAltException('" + symbol + "')"; 35 | return format; 36 | } 37 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ActionTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ActionTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex) 11 | : Transition(target), ruleIndex(ruleIndex), actionIndex(INVALID_INDEX), isCtxDependent(false) { 12 | } 13 | 14 | ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent) 15 | : Transition(target), ruleIndex(ruleIndex), actionIndex(actionIndex), isCtxDependent(isCtxDependent) { 16 | } 17 | 18 | Transition::SerializationType ActionTransition::getSerializationType() const { 19 | return ACTION; 20 | } 21 | 22 | bool ActionTransition::isEpsilon() const { 23 | return true; // we are to be ignored by analysis 'cept for predicates 24 | } 25 | 26 | bool ActionTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return false; 28 | } 29 | 30 | std::string ActionTransition::toString() const { 31 | return " ACTION " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + ", actionIndex: " + 32 | std::to_string(actionIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 33 | } 34 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/EpsilonTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EpsilonTransition final : public Transition { 14 | public: 15 | EpsilonTransition(ATNState *target); 16 | EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn); 17 | 18 | /** 19 | * @return the rule index of a precedence rule for which this transition is 20 | * returning from, where the precedence value is 0; otherwise, INVALID_INDEX. 21 | * 22 | * @see ATNConfig#isPrecedenceFilterSuppressed() 23 | * @see ParserATNSimulator#applyPrecedenceFilter(ATNConfigSet) 24 | * @since 4.4.1 25 | */ 26 | size_t outermostPrecedenceReturn(); 27 | virtual SerializationType getSerializationType() const override; 28 | 29 | virtual bool isEpsilon() const override; 30 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 31 | 32 | virtual std::string toString() const override; 33 | 34 | private: 35 | const size_t _outermostPrecedenceReturn; // A rule index. 36 | }; 37 | 38 | } // namespace atn 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerPopModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerPopModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerPopModeAction::getInstance() { 16 | static Ref instance(new LexerPopModeAction()); 17 | return instance; 18 | } 19 | 20 | LexerPopModeAction::LexerPopModeAction() { 21 | } 22 | 23 | LexerActionType LexerPopModeAction::getActionType() const { 24 | return LexerActionType::POP_MODE; 25 | } 26 | 27 | bool LexerPopModeAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerPopModeAction::execute(Lexer *lexer) { 32 | lexer->popMode(); 33 | } 34 | 35 | size_t LexerPopModeAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerPopModeAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerPopModeAction::toString() const { 46 | return "popMode"; 47 | } 48 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | PredicateTransition::PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent) : AbstractPredicateTransition(target), ruleIndex(ruleIndex), predIndex(predIndex), isCtxDependent(isCtxDependent) { 11 | } 12 | 13 | Transition::SerializationType PredicateTransition::getSerializationType() const { 14 | return PREDICATE; 15 | } 16 | 17 | bool PredicateTransition::isEpsilon() const { 18 | return true; 19 | } 20 | 21 | bool PredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 22 | return false; 23 | } 24 | 25 | Ref PredicateTransition::getPredicate() const { 26 | return std::make_shared(ruleIndex, predIndex, isCtxDependent); 27 | } 28 | 29 | std::string PredicateTransition::toString() const { 30 | return "PREDICATE " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + 31 | ", predIndex: " + std::to_string(predIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 32 | 33 | // Generate and add a predicate context here? 34 | } 35 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ATNDeserializationOptions.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ATNDeserializationOptions { 14 | private: 15 | static ATNDeserializationOptions defaultOptions; 16 | 17 | bool readOnly; 18 | bool verifyATN; 19 | bool generateRuleBypassTransitions; 20 | 21 | public: 22 | ATNDeserializationOptions(); 23 | ATNDeserializationOptions(ATNDeserializationOptions *options); 24 | ATNDeserializationOptions(ATNDeserializationOptions const&) = default; 25 | virtual ~ATNDeserializationOptions(); 26 | ATNDeserializationOptions& operator=(ATNDeserializationOptions const&) = default; 27 | 28 | static const ATNDeserializationOptions& getDefaultOptions(); 29 | 30 | bool isReadOnly(); 31 | 32 | void makeReadOnly(); 33 | 34 | bool isVerifyATN(); 35 | 36 | void setVerifyATN(bool verify); 37 | 38 | bool isGenerateRuleBypassTransitions(); 39 | 40 | void setGenerateRuleBypassTransitions(bool generate); 41 | 42 | protected: 43 | virtual void throwIfReadOnly(); 44 | 45 | private: 46 | void InitializeInstanceFields(); 47 | }; 48 | 49 | } // namespace atn 50 | } // namespace antlr4 51 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathLexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar XPathLexer; 2 | 3 | tokens { TOKEN_REF, RULE_REF } 4 | 5 | /* 6 | path : separator? word (separator word)* EOF ; 7 | 8 | separator 9 | : '/' '!' 10 | | '//' '!' 11 | | '/' 12 | | '//' 13 | ; 14 | 15 | word: TOKEN_REF 16 | | RULE_REF 17 | | STRING 18 | | '*' 19 | ; 20 | */ 21 | 22 | ANYWHERE : '//' ; 23 | ROOT : '/' ; 24 | WILDCARD : '*' ; 25 | BANG : '!' ; 26 | 27 | ID : NameStartChar NameChar* 28 | { 29 | if (isupper(getText()[0])) 30 | setType(TOKEN_REF); 31 | else 32 | setType(RULE_REF); 33 | } 34 | ; 35 | 36 | fragment 37 | NameChar : NameStartChar 38 | | '0'..'9' 39 | | '_' 40 | | '\u00B7' 41 | | '\u0300'..'\u036F' 42 | | '\u203F'..'\u2040' 43 | ; 44 | 45 | fragment 46 | NameStartChar 47 | : 'A'..'Z' | 'a'..'z' 48 | | '\u00C0'..'\u00D6' 49 | | '\u00D8'..'\u00F6' 50 | | '\u00F8'..'\u02FF' 51 | | '\u0370'..'\u037D' 52 | | '\u037F'..'\u1FFF' 53 | | '\u200C'..'\u200D' 54 | | '\u2070'..'\u218F' 55 | | '\u2C00'..'\u2FEF' 56 | | '\u3001'..'\uD7FF' 57 | | '\uF900'..'\uFDCF' 58 | | '\uFDF0'..'\uFFFF' // implicitly includes ['\u10000-'\uEFFFF] 59 | ; 60 | 61 | STRING : '\'' .*? '\''; 62 | 63 | //WS : [ \t\r\n]+ -> skip ; 64 | 65 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/CommonTokenFactory.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "CommonToken.h" 8 | #include "CharStream.h" 9 | 10 | #include "CommonTokenFactory.h" 11 | 12 | using namespace antlr4; 13 | 14 | const Ref> CommonTokenFactory::DEFAULT = std::make_shared(); 15 | 16 | CommonTokenFactory::CommonTokenFactory(bool copyText_) : copyText(copyText_) { 17 | } 18 | 19 | CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) { 20 | } 21 | 22 | std::unique_ptr CommonTokenFactory::create(std::pair source, size_t type, 23 | const std::string &text, size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) { 24 | 25 | std::unique_ptr t(new CommonToken(source, type, channel, start, stop)); 26 | t->setLine(line); 27 | t->setCharPositionInLine(charPositionInLine); 28 | if (text != "") { 29 | t->setText(text); 30 | } else if (copyText && source.second != nullptr) { 31 | t->setText(source.second->getText(misc::Interval(start, stop))); 32 | } 33 | 34 | return t; 35 | } 36 | 37 | std::unique_ptr CommonTokenFactory::create(size_t type, const std::string &text) { 38 | return std::unique_ptr(new CommonToken(type, text)); 39 | } 40 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/RuleTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleTransition : public Transition { 14 | public: 15 | /// Ptr to the rule definition object for this rule ref. 16 | const size_t ruleIndex; // no Rule object at runtime 17 | 18 | const int precedence; 19 | 20 | /// What node to begin computations following ref to rule. 21 | ATNState *followState; 22 | 23 | /// @deprecated Use 24 | /// instead. 25 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState); 26 | 27 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState); 28 | RuleTransition(RuleTransition const&) = delete; 29 | RuleTransition& operator=(RuleTransition const&) = delete; 30 | 31 | virtual SerializationType getSerializationType() const override; 32 | 33 | virtual bool isEpsilon() const override; 34 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 35 | 36 | virtual std::string toString() const override; 37 | }; 38 | 39 | } // namespace atn 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/PredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// TO_DO: this is old comment: 15 | /// A tree of semantic predicates from the grammar AST if label==SEMPRED. 16 | /// In the ATN, labels will always be exactly one predicate, but the DFA 17 | /// may have to combine a bunch of them as it collects predicates from 18 | /// multiple ATN configurations into a single DFA state. 19 | class ANTLR4CPP_PUBLIC PredicateTransition final : public AbstractPredicateTransition { 20 | public: 21 | const size_t ruleIndex; 22 | const size_t predIndex; 23 | const bool isCtxDependent; // e.g., $i ref in pred 24 | 25 | PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent); 26 | 27 | virtual SerializationType getSerializationType() const override; 28 | 29 | virtual bool isEpsilon() const override; 30 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 31 | 32 | Ref getPredicate() const; 33 | 34 | virtual std::string toString() const override; 35 | 36 | }; 37 | 38 | } // namespace atn 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/BaseErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRErrorListener.h" 9 | 10 | namespace antlrcpp { 11 | class BitSet; 12 | } 13 | 14 | namespace antlr4 { 15 | 16 | /** 17 | * Provides an empty default implementation of {@link ANTLRErrorListener}. The 18 | * default implementation of each method does nothing, but can be overridden as 19 | * necessary. 20 | */ 21 | class ANTLR4CPP_PUBLIC BaseErrorListener : public ANTLRErrorListener { 22 | 23 | virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine, 24 | const std::string &msg, std::exception_ptr e) override; 25 | 26 | virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact, 27 | const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override; 28 | 29 | virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 30 | const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override; 31 | 32 | virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 33 | size_t prediction, atn::ATNConfigSet *configs) override; 34 | }; 35 | 36 | } // namespace antlr4 37 | -------------------------------------------------------------------------------- /src/algorithms/register_allocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "cfg.h" 8 | #include "src/core/kernel.h" 9 | 10 | namespace dada { 11 | struct PhysReg { 12 | int index = 0; // 0...224 13 | int width = 0; // 1, 2, 4 14 | }; 15 | 16 | class RegisterAllocator { 17 | public: 18 | int max_registers_ = 255; 19 | int max_predicate_registers_ = 7; 20 | Kernel const* kernel_ = nullptr; 21 | CFG const* cfg_ = nullptr; 22 | 23 | std::map, PhysReg> reg_alloc_result_; 24 | std::map, int> preg_alloc_result_; 25 | public: 26 | RegisterAllocator(Kernel const* kernel, CFG const* cfg); 27 | virtual void allocate() = 0; 28 | 29 | void setMaxRegisters(int); 30 | void setMaxPredicateRegisters(int); 31 | 32 | int getRegisterCount() const; 33 | 34 | void printResult() const; 35 | }; 36 | 37 | class LinearScanAllocator : public RegisterAllocator { 38 | private: 39 | std::map, std::pair> computeRegisterLiveness(); 40 | void lsAllocate(); 41 | public: 42 | LinearScanAllocator(Kernel const* kernel, CFG const* cfg); 43 | void allocate() override; 44 | }; 45 | 46 | class BinPackingAllocator : public RegisterAllocator { 47 | public: 48 | void allocate() override; 49 | }; 50 | 51 | class GraphColoringAllocator : public RegisterAllocator { 52 | public: 53 | void allocate() override; 54 | }; 55 | } -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/TerminalNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "Token.h" 8 | #include "RuleContext.h" 9 | #include "tree/ParseTreeVisitor.h" 10 | 11 | #include "tree/TerminalNodeImpl.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | 16 | TerminalNodeImpl::TerminalNodeImpl(Token *symbol_) : symbol(symbol_) { 17 | } 18 | 19 | Token* TerminalNodeImpl::getSymbol() { 20 | return symbol; 21 | } 22 | 23 | void TerminalNodeImpl::setParent(RuleContext *parent_) { 24 | this->parent = parent_; 25 | } 26 | 27 | misc::Interval TerminalNodeImpl::getSourceInterval() { 28 | if (symbol == nullptr) { 29 | return misc::Interval::INVALID; 30 | } 31 | 32 | size_t tokenIndex = symbol->getTokenIndex(); 33 | return misc::Interval(tokenIndex, tokenIndex); 34 | } 35 | 36 | antlrcpp::Any TerminalNodeImpl::accept(ParseTreeVisitor *visitor) { 37 | return visitor->visitTerminal(this); 38 | } 39 | 40 | std::string TerminalNodeImpl::getText() { 41 | return symbol->getText(); 42 | } 43 | 44 | std::string TerminalNodeImpl::toStringTree(Parser * /*parser*/) { 45 | return toString(); 46 | } 47 | 48 | std::string TerminalNodeImpl::toString() { 49 | if (symbol->getType() == Token::EOF) { 50 | return ""; 51 | } 52 | return symbol->getText(); 53 | } 54 | 55 | std::string TerminalNodeImpl::toStringTree() { 56 | return toString(); 57 | } 58 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerModeAction::LexerModeAction(int mode) : _mode(mode) { 16 | } 17 | 18 | int LexerModeAction::getMode() { 19 | return _mode; 20 | } 21 | 22 | LexerActionType LexerModeAction::getActionType() const { 23 | return LexerActionType::MODE; 24 | } 25 | 26 | bool LexerModeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerModeAction::execute(Lexer *lexer) { 31 | lexer->setMode(_mode); 32 | } 33 | 34 | size_t LexerModeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _mode); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerModeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerModeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _mode == action->_mode; 52 | } 53 | 54 | std::string LexerModeAction::toString() const { 55 | return "mode(" + std::to_string(_mode) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerTypeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerTypeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerTypeAction::LexerTypeAction(int type) : _type(type) { 16 | } 17 | 18 | int LexerTypeAction::getType() const { 19 | return _type; 20 | } 21 | 22 | LexerActionType LexerTypeAction::getActionType() const { 23 | return LexerActionType::TYPE; 24 | } 25 | 26 | bool LexerTypeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerTypeAction::execute(Lexer *lexer) { 31 | lexer->setType(_type); 32 | } 33 | 34 | size_t LexerTypeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _type); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerTypeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerTypeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _type == action->_type; 52 | } 53 | 54 | std::string LexerTypeAction::toString() const { 55 | return "type(" + std::to_string(_type) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/CharStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "IntStream.h" 9 | #include "misc/Interval.h" 10 | 11 | namespace antlr4 { 12 | 13 | /// A source of characters for an ANTLR lexer. 14 | class ANTLR4CPP_PUBLIC CharStream : public IntStream { 15 | public: 16 | virtual ~CharStream(); 17 | 18 | /// This method returns the text for a range of characters within this input 19 | /// stream. This method is guaranteed to not throw an exception if the 20 | /// specified interval lies entirely within a marked range. For more 21 | /// information about marked ranges, see IntStream::mark. 22 | /// 23 | /// an interval within the stream 24 | /// the text of the specified interval 25 | /// 26 | /// if {@code interval} is {@code null} 27 | /// if {@code interval.a < 0}, or if 28 | /// {@code interval.b < interval.a - 1}, or if {@code interval.b} lies at or 29 | /// past the end of the stream 30 | /// if the stream does not support 31 | /// getting the text of the specified interval 32 | virtual std::string getText(const misc::Interval &interval) = 0; 33 | 34 | virtual std::string toString() const = 0; 35 | }; 36 | 37 | } // namespace antlr4 38 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerChannelAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerChannelAction.h" 10 | 11 | using namespace antlr4::atn; 12 | using namespace antlr4::misc; 13 | 14 | LexerChannelAction::LexerChannelAction(int channel) : _channel(channel) { 15 | } 16 | 17 | int LexerChannelAction::getChannel() const { 18 | return _channel; 19 | } 20 | 21 | LexerActionType LexerChannelAction::getActionType() const { 22 | return LexerActionType::CHANNEL; 23 | } 24 | 25 | bool LexerChannelAction::isPositionDependent() const { 26 | return false; 27 | } 28 | 29 | void LexerChannelAction::execute(Lexer *lexer) { 30 | lexer->setChannel(_channel); 31 | } 32 | 33 | size_t LexerChannelAction::hashCode() const { 34 | size_t hash = MurmurHash::initialize(); 35 | hash = MurmurHash::update(hash, static_cast(getActionType())); 36 | hash = MurmurHash::update(hash, _channel); 37 | return MurmurHash::finish(hash, 2); 38 | } 39 | 40 | bool LexerChannelAction::operator == (const LexerAction &obj) const { 41 | if (&obj == this) { 42 | return true; 43 | } 44 | 45 | const LexerChannelAction *action = dynamic_cast(&obj); 46 | if (action == nullptr) { 47 | return false; 48 | } 49 | 50 | return _channel == action->_channel; 51 | } 52 | 53 | std::string LexerChannelAction::toString() const { 54 | return "channel(" + std::to_string(_channel) + ")"; 55 | } 56 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/pattern/Chunk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace pattern { 13 | 14 | /// 15 | /// A chunk is either a token tag, a rule tag, or a span of literal text within a 16 | /// tree pattern. 17 | ///

18 | /// The method returns a list of 19 | /// chunks in preparation for creating a token stream by 20 | /// . From there, we get a parse 21 | /// tree from with . These 22 | /// chunks are converted to , , or the 23 | /// regular tokens of the text surrounding the tags. 24 | ///

25 | class ANTLR4CPP_PUBLIC Chunk { 26 | public: 27 | Chunk() = default; 28 | Chunk(Chunk const&) = default; 29 | virtual ~Chunk(); 30 | 31 | Chunk& operator=(Chunk const&) = default; 32 | 33 | /// This method returns a text representation of the tag chunk. Labeled tags 34 | /// are returned in the form {@code label:tag}, and unlabeled tags are 35 | /// returned as just the tag name. 36 | virtual std::string toString() { 37 | std::string str; 38 | return str; 39 | } 40 | }; 41 | 42 | } // namespace pattern 43 | } // namespace tree 44 | } // namespace antlr4 45 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerPushModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerPushModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerPushModeAction::LexerPushModeAction(int mode) : _mode(mode) { 16 | } 17 | 18 | int LexerPushModeAction::getMode() const { 19 | return _mode; 20 | } 21 | 22 | LexerActionType LexerPushModeAction::getActionType() const { 23 | return LexerActionType::PUSH_MODE; 24 | } 25 | 26 | bool LexerPushModeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerPushModeAction::execute(Lexer *lexer) { 31 | lexer->pushMode(_mode); 32 | } 33 | 34 | size_t LexerPushModeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _mode); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerPushModeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerPushModeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _mode == action->_mode; 52 | } 53 | 54 | std::string LexerPushModeAction::toString() const { 55 | return "pushMode(" + std::to_string(_mode) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ParseTreeProperty.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | /// 14 | /// Associate a property with a parse tree node. Useful with parse tree listeners 15 | /// that need to associate values with particular tree nodes, kind of like 16 | /// specifying a return value for the listener event method that visited a 17 | /// particular node. Example: 18 | /// 19 | ///
20 |   /// ParseTreeProperty<Integer> values = new ParseTreeProperty<Integer>();
21 |   /// values.put(tree, 36);
22 |   /// int x = values.get(tree);
23 |   /// values.removeFrom(tree);
24 |   /// 
25 | /// 26 | /// You would make one decl (values here) in the listener and use lots of times 27 | /// in your event methods. 28 | ///
29 | template 30 | class ANTLR4CPP_PUBLIC ParseTreeProperty { 31 | public: 32 | virtual ~ParseTreeProperty() {} 33 | virtual V get(ParseTree *node) { 34 | return _annotations[node]; 35 | } 36 | virtual void put(ParseTree *node, V value) { 37 | _annotations[node] = value; 38 | } 39 | virtual V removeFrom(ParseTree *node) { 40 | auto value = _annotations[node]; 41 | _annotations.erase(node); 42 | return value; 43 | } 44 | 45 | protected: 46 | std::map _annotations; 47 | }; 48 | 49 | } // namespace tree 50 | } // namespace antlr4 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Simplifying Low-Level GPU Programming with GAS 2 | 3 | ### Requirements 4 | * cmake >= 3.8 5 | * g++ >= 9.2 6 | * nvcc >= 11.0 and nvcc 10.1 (since nvcc 11.0 is incompatible with c++17) 7 | 8 | ### Target 9 | NVIDIA GPUs, arch >= sm_70 10 | 11 | ### Example 12 | ```c++ 13 | // vector copy one element 14 | copy(s64 dst, s64 src) { 15 | // declare variables 16 | b32 .v4 Fragment[4]; 17 | s64 LoadPtr, StorePtr; 18 | 19 | // load parameters 20 | ldc.64 LoadPtr, src; 21 | ldc.64 StorePtr, dst; 22 | 23 | // copy 24 | ldg.128 Fragment[0:3], [LoadPtr]; 25 | stg.128 [StorePtr], Fragment[0:3]; 26 | exit; 27 | } 28 | ``` 29 | 30 | ### Build 31 | ```bash 32 | export GAS_HOME=$PWD 33 | 34 | mkdir build 35 | cd build 36 | cmake .. 37 | make # -j6 38 | ``` 39 | 40 | ### Run examples 41 | 1. benchmarks 42 | ```bash 43 | cd examples/benchmark 44 | # can replace cpi with L0-i-cache/L1-i-cache 45 | cd cpi 46 | # Set target arch 47 | export ARCH= # e.g., export ARCH=75 48 | make 49 | ./benchmark 50 | ``` 51 | 52 | 2. hgemm (Require Turing devices) 53 | ```bash 54 | cd examples/hgemm 55 | # Set nvcc's and ptxas' paths 56 | # ptxas' path is usually /usr/local/cuda-11.0/bin/ptxas 57 | export PTXAS= # We need ptxas 11.0 for better performance, 58 | # and the support for mma instructions 59 | export NVCC= # We need nvcc 10.1 to compile c++17 code 60 | make 61 | ./run.sh 62 | ``` 63 | 64 | 3. sgemm 65 | ```bash 66 | cd examples/sgemm 67 | make 68 | ./run.sh 69 | ``` 70 | 71 | ### Troubleshooting 72 | If cmake cannot find ANTRL. Copy bin/antlr-4.7.2-complete.jar to /usr/local/lib/antlr-4.7.2-complete.jar 73 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/ParseTreeWalker.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | #include "ParserRuleContext.h" 8 | #include "tree/ParseTreeListener.h" 9 | #include "support/CPPUtils.h" 10 | 11 | #include "tree/IterativeParseTreeWalker.h" 12 | #include "tree/ParseTreeWalker.h" 13 | 14 | using namespace antlr4::tree; 15 | using namespace antlrcpp; 16 | 17 | static IterativeParseTreeWalker defaultWalker; 18 | ParseTreeWalker &ParseTreeWalker::DEFAULT = defaultWalker; 19 | 20 | ParseTreeWalker::~ParseTreeWalker() { 21 | } 22 | 23 | void ParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const { 24 | if (is(t)) { 25 | listener->visitErrorNode(dynamic_cast(t)); 26 | return; 27 | } else if (is(t)) { 28 | listener->visitTerminal(dynamic_cast(t)); 29 | return; 30 | } 31 | 32 | enterRule(listener, t); 33 | for (auto &child : t->children) { 34 | walk(listener, child); 35 | } 36 | exitRule(listener, t); 37 | } 38 | 39 | void ParseTreeWalker::enterRule(ParseTreeListener *listener, ParseTree *r) const { 40 | ParserRuleContext *ctx = dynamic_cast(r); 41 | listener->enterEveryRule(ctx); 42 | ctx->enterRule(listener); 43 | } 44 | 45 | void ParseTreeWalker::exitRule(ParseTreeListener *listener, ParseTree *r) const { 46 | ParserRuleContext *ctx = dynamic_cast(r); 47 | ctx->exitRule(listener); 48 | listener->exitEveryRule(ctx); 49 | } 50 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerActionType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// Represents the serialization type of a . 15 | /// 16 | /// @author Sam Harwell 17 | /// @since 4.2 18 | /// 19 | enum class LexerActionType : size_t { 20 | /// 21 | /// The type of a action. 22 | /// 23 | CHANNEL, 24 | /// 25 | /// The type of a action. 26 | /// 27 | CUSTOM, 28 | /// 29 | /// The type of a action. 30 | /// 31 | MODE, 32 | /// 33 | /// The type of a action. 34 | /// 35 | MORE, 36 | /// 37 | /// The type of a action. 38 | /// 39 | POP_MODE, 40 | /// 41 | /// The type of a action. 42 | /// 43 | PUSH_MODE, 44 | /// 45 | /// The type of a action. 46 | /// 47 | SKIP, 48 | /// 49 | /// The type of a action. 50 | /// 51 | TYPE, 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/SingletonPredictionContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/PredictionContext.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC SingletonPredictionContext : public PredictionContext { 14 | public: 15 | // Usually a parent is linked via a weak ptr. Not so here as we have kinda reverse reference chain. 16 | // There are no child contexts stored here and often the parent context is left dangling when it's 17 | // owning ATNState is released. In order to avoid having this context released as well (leaving all other contexts 18 | // which got this one as parent with a null reference) we use a shared_ptr here instead, to keep those left alone 19 | // parent contexts alive. 20 | const Ref parent; 21 | const size_t returnState; 22 | 23 | SingletonPredictionContext(Ref const& parent, size_t returnState); 24 | virtual ~SingletonPredictionContext(); 25 | 26 | static Ref create(Ref const& parent, size_t returnState); 27 | 28 | virtual size_t size() const override; 29 | virtual Ref getParent(size_t index) const override; 30 | virtual size_t getReturnState(size_t index) const override; 31 | virtual bool operator == (const PredictionContext &o) const override; 32 | virtual std::string toString() const override; 33 | }; 34 | 35 | } // namespace atn 36 | } // namespace antlr4 37 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/pattern/TextChunk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Chunk.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace pattern { 13 | 14 | /// 15 | /// Represents a span of raw text (concrete syntax) between tags in a tree 16 | /// pattern string. 17 | /// 18 | class ANTLR4CPP_PUBLIC TextChunk : public Chunk { 19 | private: 20 | /// 21 | /// This is the backing field for . 22 | /// 23 | const std::string text; 24 | 25 | /// 26 | /// Constructs a new instance of with the specified text. 27 | /// 28 | /// The text of this chunk. 29 | /// if {@code text} is {@code null}. 30 | public: 31 | TextChunk(const std::string &text); 32 | virtual ~TextChunk(); 33 | 34 | /// 35 | /// Gets the raw text of this chunk. 36 | /// 37 | /// The text of the chunk. 38 | std::string getText(); 39 | 40 | /// 41 | /// {@inheritDoc} 42 | ///

43 | /// The implementation for returns the result of 44 | /// in single quotes. 45 | ///

46 | virtual std::string toString() override; 47 | }; 48 | 49 | } // namespace pattern 50 | } // namespace tree 51 | } // namespace antlr4 52 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ArrayPredictionContext.h: -------------------------------------------------------------------------------- 1 | 2 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 | * Use of this file is governed by the BSD 3-clause license that 4 | * can be found in the LICENSE.txt file in the project root. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "atn/PredictionContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class SingletonPredictionContext; 15 | 16 | class ANTLR4CPP_PUBLIC ArrayPredictionContext : public PredictionContext { 17 | public: 18 | /// Parent can be empty only if full ctx mode and we make an array 19 | /// from EMPTY and non-empty. We merge EMPTY by using null parent and 20 | /// returnState == EMPTY_RETURN_STATE. 21 | // Also here: we use a strong reference to our parents to avoid having them freed prematurely. 22 | // See also SinglePredictionContext. 23 | const std::vector> parents; 24 | 25 | /// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last. 26 | const std::vector returnStates; 27 | 28 | ArrayPredictionContext(Ref const& a); 29 | ArrayPredictionContext(std::vector> const& parents_, std::vector const& returnStates); 30 | virtual ~ArrayPredictionContext(); 31 | 32 | virtual bool isEmpty() const override; 33 | virtual size_t size() const override; 34 | virtual Ref getParent(size_t index) const override; 35 | virtual size_t getReturnState(size_t index) const override; 36 | bool operator == (const PredictionContext &o) const override; 37 | 38 | virtual std::string toString() const override; 39 | }; 40 | 41 | } // namespace atn 42 | } // namespace antlr4 43 | 44 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerATNConfig.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNConfig.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC LexerATNConfig : public ATNConfig { 14 | public: 15 | LexerATNConfig(ATNState *state, int alt, Ref const& context); 16 | LexerATNConfig(ATNState *state, int alt, Ref const& context, Ref const& lexerActionExecutor); 17 | 18 | LexerATNConfig(Ref const& c, ATNState *state); 19 | LexerATNConfig(Ref const& c, ATNState *state, Ref const& lexerActionExecutor); 20 | LexerATNConfig(Ref const& c, ATNState *state, Ref const& context); 21 | 22 | /** 23 | * Gets the {@link LexerActionExecutor} capable of executing the embedded 24 | * action(s) for the current configuration. 25 | */ 26 | Ref getLexerActionExecutor() const; 27 | bool hasPassedThroughNonGreedyDecision(); 28 | 29 | virtual size_t hashCode() const override; 30 | 31 | bool operator == (const LexerATNConfig& other) const; 32 | 33 | private: 34 | /** 35 | * This is the backing field for {@link #getLexerActionExecutor}. 36 | */ 37 | const Ref _lexerActionExecutor; 38 | const bool _passedThroughNonGreedyDecision; 39 | 40 | static bool checkNonGreedyDecision(Ref const& source, ATNState *target); 41 | }; 42 | 43 | } // namespace atn 44 | } // namespace antlr4 45 | -------------------------------------------------------------------------------- /src/arch/arch_sm7x.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "base_arch.h" 4 | 5 | namespace dada { 6 | class SM7X : public BaseArch { 7 | protected: 8 | static inline uint32_t const parameter_base_offset = 0x160; 9 | 10 | static inline std::map const sreg_encoding = { 11 | {"laneid", 0x0}, 12 | {"threadIdx_x", 0x21}, {"threadIdx_y", 0x22}, {"threadIdx_z", 0x23}, 13 | {"blockIdx_x", 0x25}, {"blockIdx_y", 0x26}, {"blockIdx_z", 0x27}, 14 | {"clock_lo", 0x50}, {"srz", 0x1ff}, 15 | }; 16 | 17 | static inline std::map const predfined_const_bank1 = { 18 | {"blockDim_x", 0x0}, {"blockDim_y", 0x4}, {"blockDim_z", 0x8}, 19 | {"gridDim_x", 0xc}, {"gridDim_y", 0x10}, {"gridDim_z", 0x14}, 20 | }; 21 | 22 | protected: 23 | uint64_t getSm7xPredMask(Instruction const* instr, RegisterAllocator const*) const; 24 | uint64_t getSm7xCtrlLogicEncoding(CtrlLogic const& ctrl_logic) const; 25 | 26 | void setSm7xDstOpEncoding(uint64_t& first, Operand const*, RegisterAllocator const*) const; 27 | void setSm7xSrcOpEncoding(uint64_t& first, uint64_t& second, Operand const*, 28 | RegisterAllocator const*, int loc) const; 29 | 30 | void setSm7xDstPredEncoding(uint64_t& second, Operand const*, RegisterAllocator const*, int dst_loc) const; 31 | void setSm7xSrcPredEncoding(uint64_t& second, Operand const*, RegisterAllocator const*, int src_loc) const; 32 | 33 | void setSm7xDstPredEncodingDefault(uint64_t& second, int dst_loc) const; 34 | void setSm7xSrcPredEncodingDefault(uint64_t& second, int src_loc) const; 35 | 36 | void setSm7xIIMDEncoding(uint64_t& second, Operand const*, int offset, int width) const; 37 | }; 38 | } // namespace dada -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/InterpreterRuleContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ParserRuleContext.h" 9 | 10 | namespace antlr4 { 11 | 12 | /** 13 | * This class extends {@link ParserRuleContext} by allowing the value of 14 | * {@link #getRuleIndex} to be explicitly set for the context. 15 | * 16 | *

17 | * {@link ParserRuleContext} does not include field storage for the rule index 18 | * since the context classes created by the code generator override the 19 | * {@link #getRuleIndex} method to return the correct value for that context. 20 | * Since the parser interpreter does not use the context classes generated for a 21 | * parser, this class (with slightly more memory overhead per node) is used to 22 | * provide equivalent functionality.

23 | */ 24 | class ANTLR4CPP_PUBLIC InterpreterRuleContext : public ParserRuleContext { 25 | public: 26 | InterpreterRuleContext(); 27 | 28 | /** 29 | * Constructs a new {@link InterpreterRuleContext} with the specified 30 | * parent, invoking state, and rule index. 31 | * 32 | * @param parent The parent context. 33 | * @param invokingStateNumber The invoking state number. 34 | * @param ruleIndex The rule index for the current context. 35 | */ 36 | InterpreterRuleContext(ParserRuleContext *parent, size_t invokingStateNumber, size_t ruleIndex); 37 | 38 | virtual size_t getRuleIndex() const override; 39 | 40 | protected: 41 | /** This is the backing field for {@link #getRuleIndex}. */ 42 | const size_t _ruleIndex = INVALID_INDEX; 43 | }; 44 | 45 | } // namespace antlr4 46 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CXXFLAGS += -g -std=c++0x -Wall #-Wextra 3 | CXXFLAGS += -I. -I../ -I../misc/ -I../tree/ -I../dfa/ \ 4 | -I../../../../../antlrcpp/ 5 | 6 | #TODO LDFLAGS += ? 7 | 8 | ALL_CXXFLAGS = $(CPPFLAGS) $(CXXFLAGS) 9 | ALL_LDFLAGS = $(LDFLAGS) 10 | 11 | # Escote's files 12 | SRCS = \ 13 | AbstractPredicateTransition.cpp \ 14 | ActionTransition.cpp \ 15 | ArrayPredictionContext.cpp \ 16 | ATNDeserializationOptions.cpp \ 17 | ATNDeserializer.cpp \ 18 | ATNState.cpp \ 19 | ATNType.cpp \ 20 | AtomTransition.cpp \ 21 | BasicBlockStartState.cpp \ 22 | BasicState.cpp \ 23 | BlockEndState.cpp \ 24 | BlockStartState.cpp \ 25 | DecisionState.cpp \ 26 | EmptyPredictionContext.cpp \ 27 | EpsilonTransition.cpp \ 28 | LexerATNConfig.cpp \ 29 | LoopEndState.cpp 30 | # Escote's TODO: LL1Analyzer.cpp LexerATNSimulator.cpp ATNSimulator.cpp \ 31 | ATNSerializer.cpp ATNConfigSet.cpp ATNConfig.cpp \ 32 | ATN.cpp 33 | 34 | # Alejandro's files 35 | SRCS += \ 36 | NotSetTransition.cpp \ 37 | OrderedATNConfigSet.cpp \ 38 | PlusBlockStartState.cpp \ 39 | PlusLoopbackState.cpp \ 40 | PredicateTransition.cpp \ 41 | PredictionMode.cpp \ 42 | RangeTransition.cpp \ 43 | RuleStartState.cpp \ 44 | RuleStopState.cpp \ 45 | RuleTransition.cpp \ 46 | SemanticContext.cpp \ 47 | SetTransition.cpp \ 48 | SingletonPredictionContext.cpp \ 49 | StarBlockStartState.cpp \ 50 | StarLoopbackState.cpp \ 51 | StarLoopEntryState.cpp \ 52 | TokensStartState.cpp \ 53 | Transition.cpp \ 54 | WildcardTransition.cpp 55 | # Alejandro's TODO: PredictionContext.cpp PredictionContextCache.cpp \ 56 | PrecedencePredicateTransition.cpp ParserATNSimulator.cpp 57 | 58 | OBJS = $(SRCS:.cpp=.o) 59 | 60 | all: $(OBJS) 61 | 62 | %.o: %.cpp 63 | $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 64 | 65 | clean: 66 | $(RM) $(OBJS) 67 | 68 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/ProxyErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRErrorListener.h" 9 | #include "Exceptions.h" 10 | 11 | namespace antlr4 { 12 | 13 | /// This implementation of ANTLRErrorListener dispatches all calls to a 14 | /// collection of delegate listeners. This reduces the effort required to support multiple 15 | /// listeners. 16 | class ANTLR4CPP_PUBLIC ProxyErrorListener : public ANTLRErrorListener { 17 | private: 18 | std::set _delegates; // Not owned. 19 | 20 | public: 21 | void addErrorListener(ANTLRErrorListener *listener); 22 | void removeErrorListener(ANTLRErrorListener *listener); 23 | void removeErrorListeners(); 24 | 25 | void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, size_t charPositionInLine, 26 | const std::string &msg, std::exception_ptr e) override; 27 | 28 | virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact, 29 | const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override; 30 | 31 | virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 32 | const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override; 33 | 34 | virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 35 | size_t prediction, atn::ATNConfigSet *configs) override; 36 | }; 37 | 38 | } // namespace antlr4 39 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/NoViableAltException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | #include "Token.h" 10 | #include "atn/ATNConfigSet.h" 11 | 12 | namespace antlr4 { 13 | 14 | /// Indicates that the parser could not decide which of two or more paths 15 | /// to take based upon the remaining input. It tracks the starting token 16 | /// of the offending input and also knows where the parser was 17 | /// in the various paths when the error. Reported by reportNoViableAlternative() 18 | class ANTLR4CPP_PUBLIC NoViableAltException : public RecognitionException { 19 | public: 20 | NoViableAltException(Parser *recognizer); // LL(1) error 21 | NoViableAltException(Parser *recognizer, TokenStream *input,Token *startToken, 22 | Token *offendingToken, atn::ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx, bool deleteConfigs); 23 | ~NoViableAltException(); 24 | 25 | virtual Token* getStartToken() const; 26 | virtual atn::ATNConfigSet* getDeadEndConfigs() const; 27 | 28 | private: 29 | /// Which configurations did we try at input.index() that couldn't match input.LT(1)? 30 | atn::ATNConfigSet* _deadEndConfigs; 31 | 32 | // Flag that indicates if we own the dead end config set and have to delete it on destruction. 33 | bool _deleteConfigs; 34 | 35 | /// The token object at the start index; the input stream might 36 | /// not be buffering tokens so get a reference to it. (At the 37 | /// time the error occurred, of course the stream needs to keep a 38 | /// buffer all of the tokens but later we might not have access to those.) 39 | Token *_startToken; 40 | 41 | }; 42 | 43 | } // namespace antlr4 44 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerCustomAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "support/CPPUtils.h" 8 | #include "Lexer.h" 9 | 10 | #include "atn/LexerCustomAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | 16 | LexerCustomAction::LexerCustomAction(size_t ruleIndex, size_t actionIndex) : _ruleIndex(ruleIndex), _actionIndex(actionIndex) { 17 | } 18 | 19 | size_t LexerCustomAction::getRuleIndex() const { 20 | return _ruleIndex; 21 | } 22 | 23 | size_t LexerCustomAction::getActionIndex() const { 24 | return _actionIndex; 25 | } 26 | 27 | LexerActionType LexerCustomAction::getActionType() const { 28 | return LexerActionType::CUSTOM; 29 | } 30 | 31 | bool LexerCustomAction::isPositionDependent() const { 32 | return true; 33 | } 34 | 35 | void LexerCustomAction::execute(Lexer *lexer) { 36 | lexer->action(nullptr, _ruleIndex, _actionIndex); 37 | } 38 | 39 | size_t LexerCustomAction::hashCode() const { 40 | size_t hash = MurmurHash::initialize(); 41 | hash = MurmurHash::update(hash, static_cast(getActionType())); 42 | hash = MurmurHash::update(hash, _ruleIndex); 43 | hash = MurmurHash::update(hash, _actionIndex); 44 | return MurmurHash::finish(hash, 3); 45 | } 46 | 47 | bool LexerCustomAction::operator == (const LexerAction &obj) const { 48 | if (&obj == this) { 49 | return true; 50 | } 51 | 52 | const LexerCustomAction *action = dynamic_cast(&obj); 53 | if (action == nullptr) { 54 | return false; 55 | } 56 | 57 | return _ruleIndex == action->_ruleIndex && _actionIndex == action->_actionIndex; 58 | } 59 | 60 | std::string LexerCustomAction::toString() const { 61 | return antlrcpp::toString(this); 62 | } 63 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ATNDeserializationOptions.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNDeserializationOptions.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | ATNDeserializationOptions ATNDeserializationOptions::defaultOptions; 11 | 12 | ATNDeserializationOptions::ATNDeserializationOptions() { 13 | InitializeInstanceFields(); 14 | } 15 | 16 | ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *options) : ATNDeserializationOptions() { 17 | this->verifyATN = options->verifyATN; 18 | this->generateRuleBypassTransitions = options->generateRuleBypassTransitions; 19 | } 20 | 21 | ATNDeserializationOptions::~ATNDeserializationOptions() { 22 | } 23 | 24 | const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() { 25 | return defaultOptions; 26 | } 27 | 28 | bool ATNDeserializationOptions::isReadOnly() { 29 | return readOnly; 30 | } 31 | 32 | void ATNDeserializationOptions::makeReadOnly() { 33 | readOnly = true; 34 | } 35 | 36 | bool ATNDeserializationOptions::isVerifyATN() { 37 | return verifyATN; 38 | } 39 | 40 | void ATNDeserializationOptions::setVerifyATN(bool verify) { 41 | throwIfReadOnly(); 42 | verifyATN = verify; 43 | } 44 | 45 | bool ATNDeserializationOptions::isGenerateRuleBypassTransitions() { 46 | return generateRuleBypassTransitions; 47 | } 48 | 49 | void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generate) { 50 | throwIfReadOnly(); 51 | generateRuleBypassTransitions = generate; 52 | } 53 | 54 | void ATNDeserializationOptions::throwIfReadOnly() { 55 | if (isReadOnly()) { 56 | throw "The object is read only."; 57 | } 58 | } 59 | 60 | void ATNDeserializationOptions::InitializeInstanceFields() { 61 | readOnly = false; 62 | verifyATN = true; 63 | generateRuleBypassTransitions = false; 64 | } 65 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerIndexedCustomAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | #include "support/CPPUtils.h" 9 | 10 | #include "atn/LexerIndexedCustomAction.h" 11 | 12 | using namespace antlr4; 13 | using namespace antlr4::atn; 14 | using namespace antlr4::misc; 15 | 16 | LexerIndexedCustomAction::LexerIndexedCustomAction(int offset, Ref const& action) 17 | : _offset(offset), _action(action) { 18 | } 19 | 20 | int LexerIndexedCustomAction::getOffset() const { 21 | return _offset; 22 | } 23 | 24 | Ref LexerIndexedCustomAction::getAction() const { 25 | return _action; 26 | } 27 | 28 | LexerActionType LexerIndexedCustomAction::getActionType() const { 29 | return _action->getActionType(); 30 | } 31 | 32 | bool LexerIndexedCustomAction::isPositionDependent() const { 33 | return true; 34 | } 35 | 36 | void LexerIndexedCustomAction::execute(Lexer *lexer) { 37 | // assume the input stream position was properly set by the calling code 38 | _action->execute(lexer); 39 | } 40 | 41 | size_t LexerIndexedCustomAction::hashCode() const { 42 | size_t hash = MurmurHash::initialize(); 43 | hash = MurmurHash::update(hash, _offset); 44 | hash = MurmurHash::update(hash, _action); 45 | return MurmurHash::finish(hash, 2); 46 | } 47 | 48 | bool LexerIndexedCustomAction::operator == (const LexerAction &obj) const { 49 | if (&obj == this) { 50 | return true; 51 | } 52 | 53 | const LexerIndexedCustomAction *action = dynamic_cast(&obj); 54 | if (action == nullptr) { 55 | return false; 56 | } 57 | 58 | return _offset == action->_offset && *_action == *action->_action; 59 | } 60 | 61 | std::string LexerIndexedCustomAction::toString() const { 62 | return antlrcpp::toString(this); 63 | } 64 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/FailedPredicateException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ParserATNSimulator.h" 7 | #include "Parser.h" 8 | #include "atn/PredicateTransition.h" 9 | #include "atn/ATN.h" 10 | #include "atn/ATNState.h" 11 | #include "support/CPPUtils.h" 12 | 13 | #include "FailedPredicateException.h" 14 | 15 | using namespace antlr4; 16 | using namespace antlrcpp; 17 | 18 | FailedPredicateException::FailedPredicateException(Parser *recognizer) : FailedPredicateException(recognizer, "", "") { 19 | } 20 | 21 | FailedPredicateException::FailedPredicateException(Parser *recognizer, const std::string &predicate): FailedPredicateException(recognizer, predicate, "") { 22 | } 23 | 24 | FailedPredicateException::FailedPredicateException(Parser *recognizer, const std::string &predicate, const std::string &message) 25 | : RecognitionException(!message.empty() ? message : "failed predicate: " + predicate + "?", recognizer, 26 | recognizer->getInputStream(), recognizer->getContext(), recognizer->getCurrentToken()) { 27 | 28 | atn::ATNState *s = recognizer->getInterpreter()->atn.states[recognizer->getState()]; 29 | atn::Transition *transition = s->transitions[0]; 30 | if (is(transition)) { 31 | _ruleIndex = static_cast(transition)->ruleIndex; 32 | _predicateIndex = static_cast(transition)->predIndex; 33 | } else { 34 | _ruleIndex = 0; 35 | _predicateIndex = 0; 36 | } 37 | 38 | _predicate = predicate; 39 | } 40 | 41 | size_t FailedPredicateException::getRuleIndex() { 42 | return _ruleIndex; 43 | } 44 | 45 | size_t FailedPredicateException::getPredIndex() { 46 | return _predicateIndex; 47 | } 48 | 49 | std::string FailedPredicateException::getPredicate() { 50 | return _predicate; 51 | } 52 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerSkipAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code skip} lexer action by calling . 16 | /// 17 | /// The {@code skip} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerSkipAction final : public LexerAction { 24 | public: 25 | /// Provides a singleton instance of this parameterless lexer action. 26 | static const Ref getInstance(); 27 | 28 | /// 29 | /// {@inheritDoc} 30 | /// This method returns . 31 | virtual LexerActionType getActionType() const override; 32 | 33 | /// 34 | /// {@inheritDoc} 35 | /// This method returns {@code false}. 36 | virtual bool isPositionDependent() const override; 37 | 38 | /// 39 | /// {@inheritDoc} 40 | /// 41 | /// This action is implemented by calling . 42 | /// 43 | virtual void execute(Lexer *lexer) override; 44 | 45 | virtual size_t hashCode() const override; 46 | virtual bool operator == (const LexerAction &obj) const override; 47 | virtual std::string toString() const override; 48 | 49 | private: 50 | /// Constructs the singleton instance of the lexer {@code skip} command. 51 | LexerSkipAction(); 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/ErrorInfo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionEventInfo.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// This class represents profiling event information for a syntax error 15 | /// identified during prediction. Syntax errors occur when the prediction 16 | /// algorithm is unable to identify an alternative which would lead to a 17 | /// successful parse. 18 | /// 19 | /// 20 | /// 23 | class ANTLR4CPP_PUBLIC ErrorInfo : public DecisionEventInfo { 24 | public: 25 | /// 26 | /// Constructs a new instance of the class with the 27 | /// specified detailed syntax error information. 28 | /// 29 | /// The decision number 30 | /// The final configuration set reached during prediction 31 | /// prior to reaching the state 32 | /// The input token stream 33 | /// The start index for the current prediction 34 | /// The index at which the syntax error was identified 35 | /// {@code true} if the syntax error was identified during LL 36 | /// prediction; otherwise, {@code false} if the syntax error was identified 37 | /// during SLL prediction 38 | ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, 39 | bool fullCtx); 40 | }; 41 | 42 | } // namespace atn 43 | } // namespace antlr4 44 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/xpath/XPathLexer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "antlr4-runtime.h" 5 | 6 | 7 | 8 | 9 | class XPathLexer : public antlr4::Lexer { 10 | public: 11 | enum { 12 | TOKEN_REF = 1, RULE_REF = 2, ANYWHERE = 3, ROOT = 4, WILDCARD = 5, BANG = 6, 13 | ID = 7, STRING = 8 14 | }; 15 | 16 | XPathLexer(antlr4::CharStream *input); 17 | ~XPathLexer(); 18 | 19 | virtual std::string getGrammarFileName() const override; 20 | virtual const std::vector& getRuleNames() const override; 21 | 22 | virtual const std::vector& getChannelNames() const override; 23 | virtual const std::vector& getModeNames() const override; 24 | virtual const std::vector& getTokenNames() const override; // deprecated, use vocabulary instead 25 | virtual antlr4::dfa::Vocabulary& getVocabulary() const override; 26 | 27 | virtual const std::vector getSerializedATN() const override; 28 | virtual const antlr4::atn::ATN& getATN() const override; 29 | 30 | virtual void action(antlr4::RuleContext *context, size_t ruleIndex, size_t actionIndex) override; 31 | private: 32 | static std::vector _decisionToDFA; 33 | static antlr4::atn::PredictionContextCache _sharedContextCache; 34 | static std::vector _ruleNames; 35 | static std::vector _tokenNames; 36 | static std::vector _channelNames; 37 | static std::vector _modeNames; 38 | 39 | static std::vector _literalNames; 40 | static std::vector _symbolicNames; 41 | static antlr4::dfa::Vocabulary _vocabulary; 42 | static antlr4::atn::ATN _atn; 43 | static std::vector _serializedATN; 44 | 45 | 46 | // Individual action functions triggered by action() above. 47 | void IDAction(antlr4::RuleContext *context, size_t actionIndex); 48 | 49 | // Individual semantic predicate functions triggered by sempred() above. 50 | 51 | struct Initializer { 52 | Initializer(); 53 | }; 54 | static Initializer _init; 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerMoreAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code more} lexer action by calling . 16 | /// 17 | /// The {@code more} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerMoreAction final : public LexerAction { 24 | public: 25 | /// 26 | /// Provides a singleton instance of this parameterless lexer action. 27 | /// 28 | static const Ref getInstance(); 29 | 30 | /// 31 | /// {@inheritDoc} 32 | /// This method returns . 33 | virtual LexerActionType getActionType() const override; 34 | 35 | /// 36 | /// {@inheritDoc} 37 | /// This method returns {@code false}. 38 | virtual bool isPositionDependent() const override; 39 | 40 | /// 41 | /// {@inheritDoc} 42 | /// 43 | /// This action is implemented by calling . 44 | /// 45 | virtual void execute(Lexer *lexer) override; 46 | 47 | virtual size_t hashCode() const override; 48 | virtual bool operator == (const LexerAction &obj) const override; 49 | virtual std::string toString() const override; 50 | 51 | private: 52 | /// Constructs the singleton instance of the lexer {@code more} command. 53 | LexerMoreAction(); 54 | }; 55 | 56 | } // namespace atn 57 | } // namespace antlr4 58 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/BailErrorStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "ParserRuleContext.h" 8 | #include "InputMismatchException.h" 9 | #include "Parser.h" 10 | 11 | #include "BailErrorStrategy.h" 12 | 13 | using namespace antlr4; 14 | 15 | void BailErrorStrategy::recover(Parser *recognizer, std::exception_ptr e) { 16 | ParserRuleContext *context = recognizer->getContext(); 17 | do { 18 | context->exception = e; 19 | if (context->parent == nullptr) 20 | break; 21 | context = static_cast(context->parent); 22 | } while (true); 23 | 24 | try { 25 | std::rethrow_exception(e); // Throw the exception to be able to catch and rethrow nested. 26 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026 27 | } catch (RecognitionException &inner) { 28 | throw ParseCancellationException(inner.what()); 29 | #else 30 | } catch (RecognitionException & /*inner*/) { 31 | std::throw_with_nested(ParseCancellationException()); 32 | #endif 33 | } 34 | } 35 | 36 | Token* BailErrorStrategy::recoverInline(Parser *recognizer) { 37 | InputMismatchException e(recognizer); 38 | std::exception_ptr exception = std::make_exception_ptr(e); 39 | 40 | ParserRuleContext *context = recognizer->getContext(); 41 | do { 42 | context->exception = exception; 43 | if (context->parent == nullptr) 44 | break; 45 | context = static_cast(context->parent); 46 | } while (true); 47 | 48 | try { 49 | throw e; 50 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026 51 | } catch (InputMismatchException &inner) { 52 | throw ParseCancellationException(inner.what()); 53 | #else 54 | } catch (InputMismatchException & /*inner*/) { 55 | std::throw_with_nested(ParseCancellationException()); 56 | #endif 57 | } 58 | } 59 | 60 | void BailErrorStrategy::sync(Parser * /*recognizer*/) { 61 | } 62 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/support/StringUtils.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlrcpp { 11 | 12 | // For all conversions utf8 <-> utf32. 13 | // VS 2015 and VS 2017 have different bugs in std::codecvt_utf8 (VS 2013 works fine). 14 | #if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000 15 | typedef std::wstring_convert, __int32> UTF32Converter; 16 | #else 17 | typedef std::wstring_convert, char32_t> UTF32Converter; 18 | #endif 19 | 20 | // The conversion functions fails in VS2017, so we explicitly use a workaround. 21 | template 22 | inline std::string utf32_to_utf8(T const& data) 23 | { 24 | // Don't make the converter static or we have to serialize access to it. 25 | UTF32Converter converter; 26 | 27 | #if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000 28 | auto p = reinterpret_cast(data.data()); 29 | return converter.to_bytes(p, p + data.size()); 30 | #else 31 | return converter.to_bytes(data); 32 | #endif 33 | } 34 | 35 | inline UTF32String utf8_to_utf32(const char* first, const char* last) 36 | { 37 | UTF32Converter converter; 38 | 39 | #if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000 40 | auto r = converter.from_bytes(first, last); 41 | i32string s = reinterpret_cast(r.data()); 42 | #else 43 | std::u32string s = converter.from_bytes(first, last); 44 | #endif 45 | 46 | return s; 47 | } 48 | 49 | void replaceAll(std::string &str, std::string const& from, std::string const& to); 50 | 51 | // string <-> wstring conversion (UTF-16), e.g. for use with Window's wide APIs. 52 | ANTLR4CPP_PUBLIC std::string ws2s(std::wstring const& wstr); 53 | ANTLR4CPP_PUBLIC std::wstring s2ws(std::string const& str); 54 | } 55 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerPopModeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerAction.h" 9 | #include "atn/LexerActionType.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// 15 | /// Implements the {@code popMode} lexer action by calling . 16 | /// 17 | /// The {@code popMode} command does not have any parameters, so this action is 18 | /// implemented as a singleton instance exposed by . 19 | /// 20 | /// @author Sam Harwell 21 | /// @since 4.2 22 | /// 23 | class ANTLR4CPP_PUBLIC LexerPopModeAction final : public LexerAction { 24 | public: 25 | /// 26 | /// Provides a singleton instance of this parameterless lexer action. 27 | /// 28 | static const Ref getInstance(); 29 | 30 | /// 31 | /// {@inheritDoc} 32 | /// This method returns . 33 | virtual LexerActionType getActionType() const override; 34 | 35 | /// 36 | /// {@inheritDoc} 37 | /// This method returns {@code false}. 38 | virtual bool isPositionDependent() const override; 39 | 40 | /// 41 | /// {@inheritDoc} 42 | /// 43 | /// This action is implemented by calling . 44 | /// 45 | virtual void execute(Lexer *lexer) override; 46 | 47 | virtual size_t hashCode() const override; 48 | virtual bool operator == (const LexerAction &obj) const override; 49 | virtual std::string toString() const override; 50 | 51 | private: 52 | /// Constructs the singleton instance of the lexer {@code popMode} command. 53 | LexerPopModeAction(); 54 | }; 55 | 56 | } // namespace atn 57 | } // namespace antlr4 58 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LexerTypeAction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/LexerActionType.h" 9 | #include "atn/LexerAction.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// Implements the {@code type} lexer action by calling 15 | /// with the assigned type. 16 | class ANTLR4CPP_PUBLIC LexerTypeAction : public LexerAction { 17 | public: 18 | /// 19 | /// Constructs a new {@code type} action with the specified token type value. 20 | /// The type to assign to the token using . 21 | LexerTypeAction(int type); 22 | 23 | /// 24 | /// Gets the type to assign to a token created by the lexer. 25 | /// The type to assign to a token created by the lexer. 26 | virtual int getType() const; 27 | 28 | /// 29 | /// {@inheritDoc} 30 | /// This method returns . 31 | virtual LexerActionType getActionType() const override; 32 | 33 | /// 34 | /// {@inheritDoc} 35 | /// This method returns {@code false}. 36 | virtual bool isPositionDependent() const override; 37 | 38 | /// 39 | /// {@inheritDoc} 40 | /// 41 | /// This action is implemented by calling with the 42 | /// value provided by . 43 | /// 44 | virtual void execute(Lexer *lexer) override; 45 | 46 | virtual size_t hashCode() const override; 47 | virtual bool operator == (const LexerAction &obj) const override; 48 | virtual std::string toString() const override; 49 | 50 | private: 51 | const int _type; 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/atn/LookaheadEventInfo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionEventInfo.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// This class represents profiling event information for tracking the lookahead 14 | /// depth required in order to make a prediction. 15 | class ANTLR4CPP_PUBLIC LookaheadEventInfo : public DecisionEventInfo { 16 | public: 17 | /// The alternative chosen by adaptivePredict(), not necessarily 18 | /// the outermost alt shown for a rule; left-recursive rules have 19 | /// user-level alts that differ from the rewritten rule with a (...) block 20 | /// and a (..)* loop. 21 | size_t predictedAlt = 0; 22 | 23 | /// 24 | /// Constructs a new instance of the class with 25 | /// the specified detailed lookahead information. 26 | /// 27 | /// The decision number 28 | /// The final configuration set containing the necessary 29 | /// information to determine the result of a prediction, or {@code null} if 30 | /// the final configuration set is not available 31 | /// The input token stream 32 | /// The start index for the current prediction 33 | /// The index at which the prediction was finally made 34 | /// {@code true} if the current lookahead is part of an LL 35 | /// prediction; otherwise, {@code false} if the current lookahead is part of 36 | /// an SLL prediction 37 | LookaheadEventInfo(size_t decision, ATNConfigSet *configs, size_t predictedAlt, TokenStream *input, size_t startIndex, 38 | size_t stopIndex, bool fullCtx); 39 | }; 40 | 41 | } // namespace atn 42 | } // namespace antlr4 43 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/tree/pattern/ParseTreePattern.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/pattern/ParseTreePatternMatcher.h" 8 | #include "tree/pattern/ParseTreeMatch.h" 9 | 10 | #include "tree/xpath/XPath.h" 11 | #include "tree/xpath/XPathElement.h" 12 | 13 | #include "tree/pattern/ParseTreePattern.h" 14 | 15 | using namespace antlr4::tree; 16 | using namespace antlr4::tree::pattern; 17 | 18 | using namespace antlrcpp; 19 | 20 | ParseTreePattern::ParseTreePattern(ParseTreePatternMatcher *matcher, const std::string &pattern, int patternRuleIndex_, 21 | ParseTree *patternTree) 22 | : patternRuleIndex(patternRuleIndex_), _pattern(pattern), _patternTree(patternTree), _matcher(matcher) { 23 | } 24 | 25 | ParseTreePattern::~ParseTreePattern() { 26 | } 27 | 28 | ParseTreeMatch ParseTreePattern::match(ParseTree *tree) { 29 | return _matcher->match(tree, *this); 30 | } 31 | 32 | bool ParseTreePattern::matches(ParseTree *tree) { 33 | return _matcher->match(tree, *this).succeeded(); 34 | } 35 | 36 | std::vector ParseTreePattern::findAll(ParseTree *tree, const std::string &xpath) { 37 | xpath::XPath finder(_matcher->getParser(), xpath); 38 | std::vector subtrees = finder.evaluate(tree); 39 | std::vector matches; 40 | for (auto t : subtrees) { 41 | ParseTreeMatch aMatch = match(t); 42 | if (aMatch.succeeded()) { 43 | matches.push_back(aMatch); 44 | } 45 | } 46 | return matches; 47 | } 48 | 49 | 50 | ParseTreePatternMatcher *ParseTreePattern::getMatcher() const { 51 | return _matcher; 52 | } 53 | 54 | std::string ParseTreePattern::getPattern() const { 55 | return _pattern; 56 | } 57 | 58 | int ParseTreePattern::getPatternRuleIndex() const { 59 | return patternRuleIndex; 60 | } 61 | 62 | ParseTree* ParseTreePattern::getPatternTree() const { 63 | return _patternTree; 64 | } 65 | -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/CommonTokenStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | 8 | #include "CommonTokenStream.h" 9 | 10 | using namespace antlr4; 11 | 12 | CommonTokenStream::CommonTokenStream(TokenSource *tokenSource) : CommonTokenStream(tokenSource, Token::DEFAULT_CHANNEL) { 13 | } 14 | 15 | CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, size_t channel_) 16 | : BufferedTokenStream(tokenSource), channel(channel_) { 17 | } 18 | 19 | ssize_t CommonTokenStream::adjustSeekIndex(size_t i) { 20 | return nextTokenOnChannel(i, channel); 21 | } 22 | 23 | Token* CommonTokenStream::LB(size_t k) { 24 | if (k == 0 || k > _p) { 25 | return nullptr; 26 | } 27 | 28 | ssize_t i = static_cast(_p); 29 | size_t n = 1; 30 | // find k good tokens looking backwards 31 | while (n <= k) { 32 | // skip off-channel tokens 33 | i = previousTokenOnChannel(i - 1, channel); 34 | n++; 35 | } 36 | if (i < 0) { 37 | return nullptr; 38 | } 39 | 40 | return _tokens[i].get(); 41 | } 42 | 43 | Token* CommonTokenStream::LT(ssize_t k) { 44 | lazyInit(); 45 | if (k == 0) { 46 | return nullptr; 47 | } 48 | if (k < 0) { 49 | return LB(static_cast(-k)); 50 | } 51 | size_t i = _p; 52 | ssize_t n = 1; // we know tokens[p] is a good one 53 | // find k good tokens 54 | while (n < k) { 55 | // skip off-channel tokens, but make sure to not look past EOF 56 | if (sync(i + 1)) { 57 | i = nextTokenOnChannel(i + 1, channel); 58 | } 59 | n++; 60 | } 61 | 62 | return _tokens[i].get(); 63 | } 64 | 65 | int CommonTokenStream::getNumberOfOnChannelTokens() { 66 | int n = 0; 67 | fill(); 68 | for (size_t i = 0; i < _tokens.size(); i++) { 69 | Token *t = _tokens[i].get(); 70 | if (t->getChannel() == channel) { 71 | n++; 72 | } 73 | if (t->getType() == Token::EOF) { 74 | break; 75 | } 76 | } 77 | return n; 78 | } 79 | -------------------------------------------------------------------------------- /src/core/kernel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "operand.h" 9 | #include "instruction.h" 10 | 11 | namespace dada { 12 | class Parameter { 13 | public: 14 | std::string name_; 15 | DataType data_type_; 16 | int size_; 17 | int offset_; 18 | 19 | public: 20 | Parameter(std::string name, DataType data_type); 21 | 22 | int getSize() const; 23 | 24 | void setOffset(int offset); 25 | }; 26 | 27 | class Symbol { 28 | public: 29 | std::string const name_; 30 | DataType const data_type_; 31 | int const array_size_ = -1; 32 | int const vector_size_ = 1; 33 | public: 34 | Symbol(std::string name, DataType type, int array_size); 35 | Symbol(std::string name, DataType type, int array_size, int vector_size); 36 | }; 37 | 38 | class Statement{ 39 | public: 40 | Instruction* instr_ = nullptr; 41 | std::vector symbols_; 42 | std::string label_name_; 43 | 44 | bool is_instruction_ = false; 45 | bool is_symbol_ = false; 46 | bool is_label_ = false; 47 | 48 | public: 49 | Statement(Instruction*); 50 | Statement(std::vector); // variable 51 | Statement(std::string); // label 52 | 53 | bool isInstruction() const; 54 | bool isSymbol() const; 55 | bool isLabel() const; 56 | }; 57 | 58 | class Kernel { 59 | public: 60 | std::string const name_; 61 | std::vector> parameters_; 62 | std::vector> instructions_; 63 | std::map> symbol_table_; 64 | std::map labels_; 65 | 66 | public: 67 | Kernel(std::string kernel_name); 68 | 69 | void addParameters(std::vector params); 70 | void addStatements(std::vector stmts); 71 | 72 | std::string const& getName() const; 73 | 74 | 75 | private: 76 | void symbolTableLookUp(Instruction*, int); 77 | 78 | 79 | }; 80 | } // namespace dada -------------------------------------------------------------------------------- /thirdparty/antlr4-runtime/src/support/BitSet.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlrcpp { 11 | 12 | class ANTLR4CPP_PUBLIC BitSet : public std::bitset<1024> { 13 | public: 14 | size_t nextSetBit(size_t pos) const { 15 | for (size_t i = pos; i < size(); i++){ 16 | if (test(i)) { 17 | return i; 18 | } 19 | } 20 | 21 | return INVALID_INDEX; 22 | } 23 | 24 | // Prints a list of every index for which the bitset contains a bit in true. 25 | friend std::wostream& operator << (std::wostream& os, const BitSet& obj) 26 | { 27 | os << "{"; 28 | size_t total = obj.count(); 29 | for (size_t i = 0; i < obj.size(); i++){ 30 | if (obj.test(i)){ 31 | os << i; 32 | --total; 33 | if (total > 1){ 34 | os << ", "; 35 | } 36 | } 37 | } 38 | 39 | os << "}"; 40 | return os; 41 | } 42 | 43 | static std::string subStringRepresentation(const std::vector::iterator &begin, 44 | const std::vector::iterator &end) { 45 | std::string result; 46 | std::vector::iterator vectorIterator; 47 | 48 | for (vectorIterator = begin; vectorIterator != end; vectorIterator++) { 49 | result += vectorIterator->toString(); 50 | } 51 | // Grab the end 52 | result += end->toString(); 53 | 54 | return result; 55 | } 56 | 57 | std::string toString(){ 58 | std::stringstream stream; 59 | stream << "{"; 60 | bool valueAdded = false; 61 | for (size_t i = 0; i < size(); ++i){ 62 | if (test(i)){ 63 | if (valueAdded) { 64 | stream << ", "; 65 | } 66 | stream << i; 67 | valueAdded = true; 68 | } 69 | } 70 | 71 | stream << "}"; 72 | return stream.str(); 73 | } 74 | 75 | }; 76 | } 77 | --------------------------------------------------------------------------------