Browse Source
Move lemon parser generation into build directory
Move lemon parser generation into build directory
This moves the generated files out of the source tree and into the build directory. They are now regenerated each time they are needed, based on the timestamp of the generated file compared to the timestamp of the lemon file. To do this, we also bundle lemon into the thirdparty directory and build it for ourselves since it is a very tiny program and not all platforms seem to distribute it in a consistent manner. Fixes https://gitlab.com/kicad/code/kicad/issues/5013pull/16/head
17 changed files with 6036 additions and 1776 deletions
-
1CMakeLists.txt
-
51CMakeModules/Functions.cmake
-
50CMakeModules/LemonParserGenerator.cmake
-
2LICENSE.README
-
30common/CMakeLists.txt
-
38common/libeval/CMakeLists.txt
-
12common/libeval/grammar.h
-
4common/libeval/numeric_evaluator.cpp
-
38common/libeval_compiler/CMakeLists.txt
-
1389common/libeval_compiler/grammar.c
-
24common/libeval_compiler/grammar.h
-
6common/libeval_compiler/libeval_compiler.cpp
-
1thirdparty/CMakeLists.txt
-
14thirdparty/lemon/CMakeLists.txt
-
10thirdparty/lemon/README.md
-
5851thirdparty/lemon/lemon.c
-
291thirdparty/lemon/lempar.c
@ -0,0 +1,50 @@ |
|||
# This program source code file is part of KICAD, a free EDA CAD application. |
|||
# |
|||
# Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors. |
|||
# |
|||
# This program is free software; you can redistribute it and/or |
|||
# modify it under the terms of the GNU General Public License |
|||
# as published by the Free Software Foundation; either version 2 |
|||
# of the License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, you may find one here: |
|||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
# or you may search the http://www.gnu.org website for the version 2 license, |
|||
# or you may write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
# |
|||
|
|||
# This file takes the following variables as arguments: |
|||
# * LEMON_EXE - The absolute path to the lemon executable |
|||
# * LEMON_TEMPLATE - The absolute path to the lemon template file |
|||
# * GRAMMAR_FILE - The file of the grammar to use |
|||
# * GRAMMAR_DIR - An absolute path to where the grammar should be generated |
|||
|
|||
|
|||
# Get the name without extension |
|||
get_filename_component( GRAMMAR_BASE ${GRAMMAR_FILE} NAME_WE ) |
|||
|
|||
# Only regenerate the lemon code if the grammar is newer than the current code |
|||
if( ${GRAMMAR_FILE} IS_NEWER_THAN ${GRAMMAR_DIR}/${GRAMMAR_BASE}.c ) |
|||
|
|||
execute_process( |
|||
COMMAND ${LEMON_EXE} -T${LEMON_TEMPLATE} -d${GRAMMAR_DIR} -q ${GRAMMAR_FILE} |
|||
WORKING_DIRECTORY ${GRAMMAR_DIR} |
|||
OUTPUT_VARIABLE _lemon_output |
|||
ERROR_VARIABLE _lemon_error |
|||
RESULT_VARIABLE _lemon_result |
|||
OUTPUT_STRIP_TRAILING_WHITESPACE |
|||
) |
|||
|
|||
if( NOT ${_lemon_result} EQUAL 0) |
|||
message( FATAL_ERROR "Lemon generator for ${GRAMMAR_FILE} has failed\n" |
|||
"Error: ${_lemon_error}" ) |
|||
endif() |
|||
|
|||
endif() |
|||
@ -1,38 +0,0 @@ |
|||
# |
|||
# This program source code file is part of KICAD, a free EDA CAD application. |
|||
# |
|||
# Copyright (C) 2018 Kicad Developers, see AUTHORS.txt for contributors. |
|||
# |
|||
# This program is free software; you can redistribute it and/or |
|||
# modify it under the terms of the GNU General Public License |
|||
# as published by the Free Software Foundation; either version 2 |
|||
# of the License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, you may find one here: |
|||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
# or you may search the http://www.gnu.org website for the version 2 license, |
|||
# or you may write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
|
|||
find_program(LEMON lemon) |
|||
|
|||
if( LEMON ) |
|||
|
|||
macro( generate_lemon_grammar TGT_NAME GRAMMAR_LEMON GRAMMAR_C ) |
|||
add_custom_target( ${TGT_NAME} |
|||
DEPENDS ${GRAMMAR_LEMON} |
|||
COMMAND ${LEMON} -q ${GRAMMAR_LEMON} |
|||
COMMENT "Running Lemon on ${GRAMMAR_LEMON} -> ${GRAMMAR_C}" |
|||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
|||
) |
|||
endmacro() |
|||
|
|||
generate_lemon_grammar( libeval_grammar grammar.lemon grammar.c ) |
|||
|
|||
endif() |
|||
@ -1,12 +0,0 @@ |
|||
#define VAR 1 |
|||
#define ASSIGN 2 |
|||
#define SEMCOL 3 |
|||
#define PLUS 4 |
|||
#define MINUS 5 |
|||
#define UNIT 6 |
|||
#define DIVIDE 7 |
|||
#define MULT 8 |
|||
#define ENDS 9 |
|||
#define VALUE 10 |
|||
#define PARENL 11 |
|||
#define PARENR 12 |
|||
@ -1,38 +0,0 @@ |
|||
# |
|||
# This program source code file is part of KICAD, a free EDA CAD application. |
|||
# |
|||
# Copyright (C) 2018 Kicad Developers, see AUTHORS.txt for contributors. |
|||
# |
|||
# This program is free software; you can redistribute it and/or |
|||
# modify it under the terms of the GNU General Public License |
|||
# as published by the Free Software Foundation; either version 2 |
|||
# of the License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, you may find one here: |
|||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
# or you may search the http://www.gnu.org website for the version 2 license, |
|||
# or you may write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
|
|||
find_program(LEMON lemon) |
|||
|
|||
if( LEMON ) |
|||
|
|||
macro( generate_lemon_grammar TGT_NAME GRAMMAR_LEMON GRAMMAR_C ) |
|||
add_custom_target( ${TGT_NAME} |
|||
DEPENDS ${GRAMMAR_LEMON} |
|||
COMMAND ${LEMON} -q ${GRAMMAR_LEMON} |
|||
COMMENT "Running Lemon on ${GRAMMAR_LEMON} -> ${GRAMMAR_C}" |
|||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
|||
) |
|||
endmacro() |
|||
|
|||
generate_lemon_grammar( libeval_grammar2 grammar.lemon grammar.c ) |
|||
|
|||
endif() |
|||
1389
common/libeval_compiler/grammar.c
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,24 +0,0 @@ |
|||
#define G_IDENTIFIER 1 |
|||
#define G_ASSIGN 2 |
|||
#define G_SEMCOL 3 |
|||
#define G_BOOL_AND 4 |
|||
#define G_BOOL_OR 5 |
|||
#define G_BOOL_XOR 6 |
|||
#define G_LESS_THAN 7 |
|||
#define G_GREATER_THAN 8 |
|||
#define G_LESS_EQUAL_THAN 9 |
|||
#define G_GREATER_EQUAL_THAN 10 |
|||
#define G_EQUAL 11 |
|||
#define G_NOT_EQUAL 12 |
|||
#define G_BOOL_NOT 13 |
|||
#define G_PLUS 14 |
|||
#define G_MINUS 15 |
|||
#define G_DIVIDE 16 |
|||
#define G_MULT 17 |
|||
#define G_STRUCT_REF 18 |
|||
#define G_UNIT 19 |
|||
#define G_ENDS 20 |
|||
#define G_VALUE 21 |
|||
#define G_STRING 22 |
|||
#define G_PARENL 23 |
|||
#define G_PARENR 24 |
|||
@ -0,0 +1,14 @@ |
|||
add_executable( lemon |
|||
lemon.c |
|||
) |
|||
|
|||
# The location of the template file for lemon is passed as a property on the lemon target |
|||
define_property( TARGET |
|||
PROPERTY lemon_template |
|||
BRIEF_DOCS "Location of the template file for the lemon parser" |
|||
FULL_DOCS "Location of the template file for the lemon parser" |
|||
) |
|||
|
|||
set_property( TARGET lemon |
|||
PROPERTY lemon_template ${CMAKE_CURRENT_SOURCE_DIR}/lempar.c |
|||
) |
|||
@ -0,0 +1,10 @@ |
|||
This directory contains the lemon parser main program file and template file. |
|||
It is used for building several parsers in common, and is provided because not |
|||
all distributions package it in a nice way. Note, this program is not installed |
|||
with KiCad and is only used as a build-time utility. |
|||
|
|||
The files come from: |
|||
* lempar.c - https://www.sqlite.org/src/file/tool/lempar.c |
|||
* lemon.c - https://www.sqlite.org/src/file/tool/lemon.c |
|||
|
|||
It has been released into the public domain with the sqlite project. |
|||
5851
thirdparty/lemon/lemon.c
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue