Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake #25

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: 2021-2022, Collabora, Ltd.
# SPDX-License-Identifier: CC0-1.0



with section("format"):
line_width = 100
tab_size = 4
use_tabchars = False
fractional_tab_policy = "use-space"

max_prefix_chars = 4

dangle_parens = False
dangle_align = "prefix-indent"
max_pargs_hwrap = 4
max_rows_cmdline = 1

keyword_case = "upper"


# Do not reflow comments

with section("markup"):
enable_markup = False
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ nohup.out

local_malloc
llvm

build*/
.cache/
103 changes: 103 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright 2022, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
cmake_minimum_required(VERSION 3.10)
project(oink-stack)

include(CTest)
include(GNUInstallDirs)

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

find_package(Perl REQUIRED)
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)

# find_package(M4)

set(RUN_FLEX
${CMAKE_CURRENT_SOURCE_DIR}/smbase/run-flex.pl
CACHE INTERNAL "" FORCE)

# Prefer normal flex_target if possible, but if it's not...
function(add_wrapped_flex NAME INPUT OUTPUT)
if(NOT IS_ABSOLUTE ${INPUT})
set(INPUT ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT})
endif()
if(NOT IS_ABSOLUTE ${OUTPUT})
set(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT})
endif()
add_custom_command(
OUTPUT ${OUTPUT}
COMMAND ${PERL_EXECUTABLE} ${RUN_FLEX} -nobackup -copies -o${OUTPUT} ${INPUT}
DEPENDS ${INPUT} ${RUN_FLEX}
COMMENT "Running run-flex.pl wrapper to generate ${OUTPUT}"
VERBATIM)
endfunction()

# Wrap adding a custom command for running astgen
function(add_astgen_command)
set(options)
set(oneValueArgs OUTPUT_PREFIX)
set(multiValueArgs INPUTS OUTPUTS TRANSLATE_OPTIONS)
cmake_parse_arguments(
_AST
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN})
if(_AST_TRANSLATE_OPTIONS)
string(REPLACE ";" "," _AST_TRANSLATE_OPTIONS "${_AST_TRANSLATE_OPTIONS}")
set(_AST_TRANSLATE_OPTIONS -tr ${_AST_TRANSLATE_OPTIONS})
endif()
add_custom_command(
OUTPUT ${_AST_OUTPUTS}
COMMAND ${CMAKE_COMMAND} -E rm -f ${_AST_OUTPUTS}
COMMAND astgen ${_AST_TRANSLATE_OPTIONS} -o${_AST_OUTPUT_PREFIX} ${_AST_INPUTS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS astgen ${_AST_INPUTS}
COMMENT
"Running astgen on ${_AST_INPUTS} to generate outputs prefixed by ${_AST_OUTPUT_PREFIX}"
VERBATIM)
endfunction()

# Wrap adding a custom command for running elkhound
function(add_elkhound_command)
set(options)
set(oneValueArgs OUTPUT_PREFIX CC_OUTPUT_VAR WORKING_DIRECTORY)
set(multiValueArgs INPUTS TRANSLATE_OPTIONS EXTRA_DEPENDS)
cmake_parse_arguments(
_ELK
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN})
if(_ELK_TRANSLATE_OPTIONS)
string(REPLACE ";" "," _ELK_TRANSLATE_OPTIONS "${_ELK_TRANSLATE_OPTIONS}")
set(_ELK_TRANSLATE_OPTIONS -tr ${_ELK_TRANSLATE_OPTIONS})
endif()
if(NOT _ELK_WORKING_DIRECTORY)
set(_ELK_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
set(CC_OUTPUTS "${_ELK_OUTPUT_PREFIX}.cc" "${_ELK_OUTPUT_PREFIX}.h")
set(Y_OUTPUTS "${_ELK_OUTPUT_PREFIX}.y")
set(LOG_OUTPUTS "${_ELK_OUTPUT_PREFIX}.out")
add_custom_command(
OUTPUT ${CC_OUTPUTS} ${Y_OUTPUTS} ${LOG_OUTPUTS}
COMMAND ${CMAKE_COMMAND} -E rm -f ${CC_OUTPUTS} ${Y_OUTPUTS} ${LOG_OUTPUTS}
COMMAND elkhound ${_ELK_TRANSLATE_OPTIONS} -o ${_ELK_OUTPUT_PREFIX} ${_ELK_INPUTS}
WORKING_DIRECTORY ${_ELK_WORKING_DIRECTORY}
DEPENDS elkhound ${_ELK_INPUTS} ${_ELK_EXTRA_DEPENDS}
COMMENT
"Running elkhound on ${_ELK_INPUTS} to generate outputs prefixed by ${_ELK_OUTPUT_PREFIX}"
VERBATIM)
if(_ELK_CC_OUTPUT_VAR)
set(${_ELK_CC_OUTPUT_VAR}
${CC_OUTPUTS}
PARENT_SCOPE)
endif()
endfunction()

add_subdirectory(smbase)
add_subdirectory(ast)
add_subdirectory(elkhound)
add_subdirectory(elsa)
81 changes: 81 additions & 0 deletions ast/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright 2022, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0

bison_target(
agrampar agrampar.y ${CMAKE_CURRENT_BINARY_DIR}/agrampar.tab.cc
COMPILE_FLAGS "--token-table"
DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/agrampar.tab.h)

flex_target(agramlex agramlex.lex ${CMAKE_CURRENT_BINARY_DIR}/agramlex.yy.cc)
add_flex_bison_dependency(agramlex agrampar)

add_executable(
ccsstr
ccsstr.cc
ccsstr.h
reporterr.cc
reporterr.h
embedded.cc
embedded.h)
target_compile_definitions(ccsstr PRIVATE TEST_CCSSTR)
target_link_libraries(ccsstr PRIVATE smbase)
target_include_directories(ccsstr PUBLIC ${CMAKE_CURRENT_BINARY_DIR} . ../smbase)

add_library(
ast
asthelp.cc
asthelp.h
ccsstr.cc
ccsstr.h
embedded.cc
embedded.h
locstr.cc
locstr.h
gramlex.cc
gramlex.h
reporterr.cc
reporterr.h
xmlhelp.cc
xmlhelp.h)

target_include_directories(ast PUBLIC .)
target_link_libraries(ast PUBLIC smbase)

add_executable(
astgen
agrampar.cc
ast.ast.h
ast.hand.cc
ast.hand.h
astgen.cc
${BISON_agrampar_OUTPUTS}
${FLEX_agramlex_OUTPUTS})
target_include_directories(astgen PUBLIC ${CMAKE_CURRENT_BINARY_DIR} .)
target_link_libraries(astgen PRIVATE ast)

install(TARGETS astgen RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

if(FALSE)
# TODO refactor in progress, doesn't build
set(EXAMPLE_CC ${CMAKE_CURRENT_BINARY_DIR}/example.cc)
set(EXAMPLE_H ${CMAKE_CURRENT_BINARY_DIR}/example.h)
add_astgen_command(
INPUTS
${CMAKE_CURRENT_SOURCE_DIR}/example.ast
OUTPUT_PREFIX
${CMAKE_CURRENT_BINARY_DIR}/example
OUTPUTS
${EXAMPLE_CC}
${EXAMPLE_H})

add_executable(
exampletest
exampletest.cc
asthelp.cc
asthelp.h
locstr.h
locstr.cc
${EXAMPLE_CC})
target_include_directories(exampletest PUBLIC ${CMAKE_CURRENT_BINARY_DIR} .)
target_link_libraries(exampletest PUBLIC smbase)
endif()
34 changes: 0 additions & 34 deletions ast/agrampar.codes.h

This file was deleted.

6 changes: 2 additions & 4 deletions ast/agrampar.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class GrammarLexer;
// name of extra parameter to yyparse (i.e. the context in
// which the parser operates, instead of that being stored
// in some collection of globals)
#define YYPARSE_PARAM parseParam

// type of thing extra param points at
struct ASTParseParams {
Expand All @@ -30,8 +29,7 @@ struct ASTParseParams {
// caller interface to Bison-generated parser; starts parsing
// (whatever stream lexer is reading) and returns 0 for success and
// 1 for error; the extra parameter is available to actions to use
#define YYPARSE_PARAM parseParam
int agrampar_yyparse(void *YYPARSE_PARAM);
int agrampar_yyparse(void *parseParam);

// when this is set to true, bison parser emits info about
// actions as it's taking them
Expand All @@ -53,7 +51,7 @@ CtorArg *parseCtorArg(rostring str);

// error routine
void agrampar_yyerror(char const *msg, void *parseParam);
#define yyerror(m) agrampar_yyerror(m, YYPARSE_PARAM)
#define yyerror(param, m) agrampar_yyerror(m, param)

// parser's view of the lexer
int agrampar_yylex(union YYSTYPE *lvalp, void *parseParam);
Expand Down
Loading