From b7f2fbc64fcfe8e30650a32e3354613aceaceb0c Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 22 May 2008 09:08:03 +0000 Subject: [PATCH] Add cmake build infrastructure. Not default nor even distributed in the .tar.gz, the cmake build allows for loadable yasm plugins by building libyasm as a shared library. Example plugins are in the plugins/ directory, and may be loaded into a cmake-built yasm using the -N command line option (non-cmake builds will not have this option). Tested only on Linux so far, but should be relatively painless to port to Windows thanks to the use of cmake rather than libtool to create shared libraries. The only modification to the main source tree is some conditional-compiled additions to yasm.c. svn path=/trunk/yasm/; revision=2098 --- CMakeLists.txt | 47 +++++++ ConfigureChecks.cmake | 70 ++++++++++ cmake/CMakeLists.txt | 1 + cmake/modules/CMakeLists.txt | 2 + cmake/modules/DummyCFile.c | 4 + cmake/modules/YasmMacros.cmake | 89 ++++++++++++ config.h.cmake | 51 +++++++ frontends/CMakeLists.txt | 1 + frontends/yasm/CMakeLists.txt | 26 ++++ frontends/yasm/genstring.py | 41 ++++++ frontends/yasm/yasm-plugin.c | 119 ++++++++++++++++ frontends/yasm/yasm-plugin.h | 34 +++++ frontends/yasm/yasm.c | 53 +++++-- libyasm-stdint.h.cmake | 20 +++ libyasm/CMakeLists.txt | 70 ++++++++++ libyasm/cmake-module.c | 127 +++++++++++++++++ modules/CMakeLists.txt | 89 ++++++++++++ modules/arch/CMakeLists.txt | 2 + modules/arch/lc3b/CMakeLists.txt | 11 ++ modules/arch/x86/CMakeLists.txt | 50 +++++++ modules/dbgfmts/CMakeLists.txt | 4 + modules/dbgfmts/codeview/CMakeLists.txt | 5 + modules/dbgfmts/dwarf2/CMakeLists.txt | 6 + modules/dbgfmts/null/CMakeLists.txt | 3 + modules/dbgfmts/stabs/CMakeLists.txt | 3 + modules/listfmts/CMakeLists.txt | 1 + modules/listfmts/nasm/CMakeLists.txt | 3 + modules/objfmts/CMakeLists.txt | 9 ++ modules/objfmts/bin/CMakeLists.txt | 3 + modules/objfmts/coff/CMakeLists.txt | 27 ++++ modules/objfmts/dbg/CMakeLists.txt | 3 + modules/objfmts/elf/CMakeLists.txt | 8 ++ modules/objfmts/macho/CMakeLists.txt | 5 + modules/objfmts/rdf/CMakeLists.txt | 3 + modules/objfmts/xdf/CMakeLists.txt | 3 + modules/parsers/CMakeLists.txt | 2 + modules/parsers/gas/CMakeLists.txt | 11 ++ modules/parsers/nasm/CMakeLists.txt | 21 +++ modules/preprocs/CMakeLists.txt | 3 + modules/preprocs/cpp/CMakeLists.txt | 3 + modules/preprocs/nasm/CMakeLists.txt | 25 ++++ modules/preprocs/raw/CMakeLists.txt | 3 + plugins/README | 20 +++ plugins/dbg/CMakeLists.txt | 45 ++++++ plugins/dbg/README | 15 ++ plugins/dbg/dbg-objfmt.c | 175 ++++++++++++++++++++++++ plugins/dbg/init_plugin.c | 13 ++ plugins/x86/CMakeLists.txt | 117 ++++++++++++++++ plugins/x86/README | 10 ++ plugins/x86/init_plugin.c | 13 ++ tools/CMakeLists.txt | 3 + tools/genmacro/CMakeLists.txt | 3 + tools/genperf/CMakeLists.txt | 7 + tools/re2c/CMakeLists.txt | 11 ++ 54 files changed, 1483 insertions(+), 10 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 ConfigureChecks.cmake create mode 100644 cmake/CMakeLists.txt create mode 100644 cmake/modules/CMakeLists.txt create mode 100644 cmake/modules/DummyCFile.c create mode 100644 cmake/modules/YasmMacros.cmake create mode 100644 config.h.cmake create mode 100644 frontends/CMakeLists.txt create mode 100644 frontends/yasm/CMakeLists.txt create mode 100755 frontends/yasm/genstring.py create mode 100644 frontends/yasm/yasm-plugin.c create mode 100644 frontends/yasm/yasm-plugin.h create mode 100644 libyasm-stdint.h.cmake create mode 100644 libyasm/CMakeLists.txt create mode 100644 libyasm/cmake-module.c create mode 100644 modules/CMakeLists.txt create mode 100644 modules/arch/CMakeLists.txt create mode 100644 modules/arch/lc3b/CMakeLists.txt create mode 100644 modules/arch/x86/CMakeLists.txt create mode 100644 modules/dbgfmts/CMakeLists.txt create mode 100644 modules/dbgfmts/codeview/CMakeLists.txt create mode 100644 modules/dbgfmts/dwarf2/CMakeLists.txt create mode 100644 modules/dbgfmts/null/CMakeLists.txt create mode 100644 modules/dbgfmts/stabs/CMakeLists.txt create mode 100644 modules/listfmts/CMakeLists.txt create mode 100644 modules/listfmts/nasm/CMakeLists.txt create mode 100644 modules/objfmts/CMakeLists.txt create mode 100644 modules/objfmts/bin/CMakeLists.txt create mode 100644 modules/objfmts/coff/CMakeLists.txt create mode 100644 modules/objfmts/dbg/CMakeLists.txt create mode 100644 modules/objfmts/elf/CMakeLists.txt create mode 100644 modules/objfmts/macho/CMakeLists.txt create mode 100644 modules/objfmts/rdf/CMakeLists.txt create mode 100644 modules/objfmts/xdf/CMakeLists.txt create mode 100644 modules/parsers/CMakeLists.txt create mode 100644 modules/parsers/gas/CMakeLists.txt create mode 100644 modules/parsers/nasm/CMakeLists.txt create mode 100644 modules/preprocs/CMakeLists.txt create mode 100644 modules/preprocs/cpp/CMakeLists.txt create mode 100644 modules/preprocs/nasm/CMakeLists.txt create mode 100644 modules/preprocs/raw/CMakeLists.txt create mode 100644 plugins/README create mode 100644 plugins/dbg/CMakeLists.txt create mode 100644 plugins/dbg/README create mode 100644 plugins/dbg/dbg-objfmt.c create mode 100644 plugins/dbg/init_plugin.c create mode 100644 plugins/x86/CMakeLists.txt create mode 100644 plugins/x86/README create mode 100644 plugins/x86/init_plugin.c create mode 100644 tools/CMakeLists.txt create mode 100644 tools/genmacro/CMakeLists.txt create mode 100644 tools/genperf/CMakeLists.txt create mode 100644 tools/re2c/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..bc49eeec --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,47 @@ +PROJECT(yasm) +CMAKE_MINIMUM_REQUIRED(VERSION 2.4) + +SET(BUILD_SHARED_LIBS ON) + +# Where to look first for cmake modules +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") + +INCLUDE(YasmMacros) + +OPTION(ENABLE_NLS "Enable message translations" OFF) + +OPTION(YASM_BUILD_TESTS "Enable building of tests" ON) + +IF(YASM_BUILD_TESTS) + ENABLE_TESTING() +ENDIF(YASM_BUILD_TESTS) + +# Default build type to debug if not set +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE Debug CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + FORCE) +ENDIF(NOT CMAKE_BUILD_TYPE) + +set (YASM_VERSION_MAJOR 0) +set (YASM_VERSION_MINOR 6) +set (YASM_VERSION_SUBMINOR 99) +set (PACKAGE_INTVER "${YASM_VERSION_MAJOR}.${YASM_VERSION_MINOR}.${YASM_VERSION_SUBMINOR}") +set (PACKAGE_BUILD "HEAD") +set (PACKAGE_VERSION ${PACKAGE_BUILD}) +set (PACKAGE_STRING "yasm ${PACKAGE_VERSION}") + +INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR} ${yasm_SOURCE_DIR}) + +INCLUDE(ConfigureChecks.cmake) + +ADD_SUBDIRECTORY(tools) +ADD_SUBDIRECTORY(libyasm) +ADD_SUBDIRECTORY(modules) +ADD_SUBDIRECTORY(frontends) + +INSTALL(FILES + libyasm.h + ${CMAKE_BINARY_DIR}/libyasm-stdint.h + DESTINATION include + ) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake new file mode 100644 index 00000000..05a3523f --- /dev/null +++ b/ConfigureChecks.cmake @@ -0,0 +1,70 @@ +INCLUDE(CheckCSourceCompiles) +INCLUDE(CheckCCompilerFlag) +INCLUDE(CheckFunctionExists) +INCLUDE(CheckIncludeFile) +INCLUDE(CheckSymbolExists) +INCLUDE(CheckTypeSize) +INCLUDE(CheckLibraryExists) + +FIND_PROGRAM(CPP_PROG NAMES cpp) + +# Platform-specific include files (POSIX, Win32) +CHECK_INCLUDE_FILE(locale.h HAVE_LOCALE_H) +CHECK_INCLUDE_FILE(libgen.h HAVE_LIBGEN_H) +CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) +CHECK_INCLUDE_FILE(direct.h HAVE_DIRECT_H) +CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H) + +CHECK_SYMBOL_EXISTS(abort "stdlib.h" HAVE_ABORT) + +CHECK_FUNCTION_EXISTS(getcwd HAVE_GETCWD) +CHECK_FUNCTION_EXISTS(toascii HAVE_TOASCII) + +CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL) + +IF (HAVE_LIBDL) + SET(LIBDL "dl") +ELSE (HAVE_LIBDL) + SET(LIBDL "") +ENDIF (HAVE_LIBDL) + +CONFIGURE_FILE(libyasm-stdint.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/libyasm-stdint.h) +CONFIGURE_FILE(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) + +ADD_DEFINITIONS(-DHAVE_CONFIG_H) +INCLUDE(FindPythonInterp) + +IF (CMAKE_COMPILER_IS_GNUCXX) + CHECK_C_COMPILER_FLAG(-pipe C_ACCEPTS_PIPE) + CHECK_C_COMPILER_FLAG(-ansi C_ACCEPTS_ANSI) + CHECK_C_COMPILER_FLAG(-pedantic C_ACCEPTS_PEDANTIC) + CHECK_C_COMPILER_FLAG(-Wall C_ACCEPTS_WALL) + CHECK_C_COMPILER_FLAG(-Wno-unused-parameter C_ACCEPTS_WNOUNUSEDPARAM) + + IF (C_ACCEPTS_PIPE) + ADD_DEFINITIONS(-pipe) + ENDIF (C_ACCEPTS_PIPE) + + IF (C_ACCEPTS_ANSI) + ADD_DEFINITIONS(-ansi) + ENDIF (C_ACCEPTS_ANSI) + + IF (C_ACCEPTS_PEDANTIC) + ADD_DEFINITIONS(-pedantic) + ENDIF (C_ACCEPTS_PEDANTIC) + + IF (C_ACCEPTS_WALL) + ADD_DEFINITIONS(-Wall) + ENDIF (C_ACCEPTS_WALL) + + IF (C_ACCEPTS_WNOUNUSEDPARAM) + ADD_DEFINITIONS(-Wno-unused-parameter) + ENDIF (C_ACCEPTS_WNOUNUSEDPARAM) +ENDIF (CMAKE_COMPILER_IS_GNUCXX) + +# Disable some annoying Visual Studio warnings +IF (MSVC) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) + ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS) +ENDIF (MSVC) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 00000000..5e4ef796 --- /dev/null +++ b/cmake/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(modules) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt new file mode 100644 index 00000000..e4351fc9 --- /dev/null +++ b/cmake/modules/CMakeLists.txt @@ -0,0 +1,2 @@ +FILE(GLOB cmakeFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.cmake") + diff --git a/cmake/modules/DummyCFile.c b/cmake/modules/DummyCFile.c new file mode 100644 index 00000000..f8b643af --- /dev/null +++ b/cmake/modules/DummyCFile.c @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/cmake/modules/YasmMacros.cmake b/cmake/modules/YasmMacros.cmake new file mode 100644 index 00000000..ab1be00e --- /dev/null +++ b/cmake/modules/YasmMacros.cmake @@ -0,0 +1,89 @@ +# Portions based on kdelibs KDE4Macros.cmake: +# +# Copyright (c) 2006, 2007, Alexander Neundorf, +# Copyright (c) 2006, 2007, Laurent Montel, +# Copyright (c) 2007 Matthias Kretz +# +# Redistribution and use is allowed according to the terms of the BSD license. +# +# Changes for Yasm Copyright (c) 2007 Peter Johnson + +# add a unit test, which is executed when running make test +# it will be built with RPATH pointing to the build dir +# The targets are always created, but only built for the "all" +# target if the option YASM_BUILD_TESTS is enabled. Otherwise the rules for +# the target are created but not built by default. You can build them by +# manually building the target. +# The name of the target can be specified using TESTNAME , if it is +# not given the macro will default to the +macro (YASM_ADD_UNIT_TEST _test_NAME) + set(_srcList ${ARGN}) + set(_targetName ${_test_NAME}) + if( ${ARGV1} STREQUAL "TESTNAME" ) + set(_targetName ${ARGV2}) + LIST(REMOVE_AT _srcList 0 1) + endif( ${ARGV1} STREQUAL "TESTNAME" ) + yasm_add_test_executable( ${_test_NAME} ${_srcList} ) + add_test( ${_targetName} ${EXECUTABLE_OUTPUT_PATH}/${_test_NAME} ) +endmacro (YASM_ADD_UNIT_TEST) + +# add an test executable +# it will be built with RPATH pointing to the build dir +# The targets are always created, but only built for the "all" +# target if the option YASM_BUILD_TESTS is enabled. Otherwise the rules for +# the target are created but not built by default. You can build them by +# manually building the target. +macro (YASM_ADD_TEST_EXECUTABLE _target_NAME) + + set(_add_executable_param) + + if (NOT YASM_BUILD_TESTS) + set(_add_executable_param EXCLUDE_FROM_ALL) + endif (NOT YASM_BUILD_TESTS) + + set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) + + set(_SRCS ${ARGN}) + add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS}) + + set_target_properties(${_target_NAME} PROPERTIES + SKIP_BUILD_RPATH FALSE + BUILD_WITH_INSTALL_RPATH FALSE) + +endmacro (YASM_ADD_TEST_EXECUTABLE) + +macro (YASM_ADD_MODULE _module_NAME) + list(APPEND YASM_MODULES_SRC ${ARGN}) + list(APPEND YASM_MODULES ${_module_NAME}) +endmacro (YASM_ADD_MODULE) + +macro (YASM_GENPERF _in_NAME _out_NAME) + get_target_property(_tmp_GENPERF_EXE genperf LOCATION) + add_custom_command( + OUTPUT ${_out_NAME} + COMMAND ${_tmp_GENPERF_EXE} ${_in_NAME} ${_out_NAME} + DEPENDS ${_tmp_GENPERF_EXE} + MAIN_DEPENDENCY ${_in_NAME} + ) +endmacro (YASM_GENPERF) + +macro (YASM_RE2C _in_NAME _out_NAME) + get_target_property(_tmp_RE2C_EXE re2c LOCATION) + add_custom_command( + OUTPUT ${_out_NAME} + COMMAND ${_tmp_RE2C_EXE} ${ARGN} -o ${_out_NAME} ${_in_NAME} + DEPENDS ${_tmp_RE2C_EXE} + MAIN_DEPENDENCY ${_in_NAME} + ) +endmacro (YASM_RE2C) + +macro (YASM_GENMACRO _in_NAME _out_NAME _var_NAME) + get_target_property(_tmp_GENMACRO_EXE genmacro LOCATION) + add_custom_command( + OUTPUT ${_out_NAME} + COMMAND ${_tmp_GENMACRO_EXE} ${_out_NAME} ${_var_NAME} ${_in_NAME} + DEPENDS ${_tmp_GENMACRO_EXE} + MAIN_DEPENDENCY ${_in_NAME} + ) +endmacro (YASM_GENMACRO) + diff --git a/config.h.cmake b/config.h.cmake new file mode 100644 index 00000000..d282b931 --- /dev/null +++ b/config.h.cmake @@ -0,0 +1,51 @@ +/* config.h. Generated by cmake from config.h.cmake */ + +#define CMAKE_BUILD 1 + +/* Define if messsage translations are enabled */ +#cmakedefine ENABLE_NLS 1 + +/* */ +#undef HAVE_GETTEXT + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIBGEN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DIRECT_H 1 + +/* Define to 1 if you have the `getcwd' function. */ +#cmakedefine HAVE_GETCWD 1 + +/* Define to 1 if you have the `toascii' function. */ +#cmakedefine HAVE_TOASCII 1 + +/* Name of package */ +#define PACKAGE "yasm" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "bug-yasm@tortall.net" + +/* Define to internal version of this package. */ +#define PACKAGE_INTVER "@PACKAGE_INTVER@" + +/* Define to build version of this package. */ +#define PACKAGE_BUILD "@PACKAGE_BUILD@" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "yasm" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "@PACKAGE_VERSION@" + +#define VERSION PACKAGE_VERSION + +/* Command name to run C preprocessor */ +#define CPP_PROG "@CPP_PROG@" + diff --git a/frontends/CMakeLists.txt b/frontends/CMakeLists.txt new file mode 100644 index 00000000..b8b55d2d --- /dev/null +++ b/frontends/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(yasm) diff --git a/frontends/yasm/CMakeLists.txt b/frontends/yasm/CMakeLists.txt new file mode 100644 index 00000000..6d963eb4 --- /dev/null +++ b/frontends/yasm/CMakeLists.txt @@ -0,0 +1,26 @@ +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/license.c + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/genstring.py + license_msg + ${CMAKE_CURRENT_BINARY_DIR}/license.c + ${CMAKE_SOURCE_DIR}/COPYING + MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/COPYING + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/genstring.py + ) + +SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) + +ADD_EXECUTABLE(yasm + yasm.c + yasm-options.c + yasm-plugin.c + ) +TARGET_LINK_LIBRARIES(yasm libyasm ${LIBDL}) + +SET_SOURCE_FILES_PROPERTIES(yasm.c PROPERTIES + OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/license.c + ) + +INSTALL(TARGETS yasm RUNTIME DESTINATION bin) diff --git a/frontends/yasm/genstring.py b/frontends/yasm/genstring.py new file mode 100755 index 00000000..96f49d9f --- /dev/null +++ b/frontends/yasm/genstring.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# Generate array-of-const-string from text file. +# +# Copyright (C) 2006-2007 Peter Johnson +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +def file_to_string(fout, str_name, fin_name): + from os.path import basename + print >>fout, "/* This file auto-generated from %s by genstring.py - don't edit it */\n" % basename(fin_name) + print >>fout, "static const char* %s[] = {" % str_name + print >>fout, "\n".join(' "%s",' % + l.strip().replace('\\', '\\\\').replace('"', '\\"') + for l in open(fin_name)) + print >>fout, "};" + +if __name__ == "__main__": + import sys + if len(sys.argv) != 4: + print >>sys.stderr, "Usage: genstring.py " + sys.exit(2) + file_to_string(open(sys.argv[2], "w"), sys.argv[1], sys.argv[3]) diff --git a/frontends/yasm/yasm-plugin.c b/frontends/yasm/yasm-plugin.c new file mode 100644 index 00000000..55b3f75d --- /dev/null +++ b/frontends/yasm/yasm-plugin.c @@ -0,0 +1,119 @@ +/* + * Semi-portable (Windows and Unix) plugin loading + * + * Copyright (C) 2008 Peter Johnson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +/*@unused@*/ RCSID("$Id$"); + +#include + +#include "yasm-plugin.h" + +#if defined(_MSC_VER) +#include +#elif defined(__GNUC__) +#include +#endif + +static void **loaded_plugins = NULL; +static int num_loaded_plugins = 0; + +static void * +load_dll(const char *name) +{ +#if defined(_MSC_VER) + return LoadLibrary(name); +#elif defined(__GNUC__) + return dlopen(name, RTLD_NOW); +#else + return NULL; +#endif +} + +int +load_plugin(const char *name) +{ + char *path; + void *lib = NULL; + void (*init_plugin) (void) = NULL; + + /* Load library */ + + path = yasm_xmalloc(strlen(name)+5); + strcpy(path, name); +#if defined(_MSC_VER) + strcat(path, ".dll"); + lib = load_dll(path); +#elif defined(__GNUC__) + strcat(path, ".so"); + lib = load_dll(path); +#endif + yasm_xfree(path); + if (!lib) + lib = load_dll(name); + + if (!lib) + return 0; /* Didn't load successfully */ + + /* Add to array of loaded plugins */ + loaded_plugins = + yasm_xrealloc(loaded_plugins, (num_loaded_plugins+1)*sizeof(void *)); + loaded_plugins[num_loaded_plugins] = lib; + num_loaded_plugins++; + + /* Get yasm_init_plugin() function and run it */ + +#if defined(_MSC_VER) + init_plugin = + (void (*)(void))GetProcAddress((HINSTANCE)lib, "yasm_init_plugin"); +#elif defined(__GNUC__) + init_plugin = (void (*)(void))dlsym(lib, "yasm_init_plugin"); +#endif + + if (!init_plugin) + return 0; /* Didn't load successfully */ + + init_plugin(); + return 1; +} + +void +unload_plugins(void) +{ + int i; + + if (!loaded_plugins) + return; + + for (i = 0; i < num_loaded_plugins; i++) { +#if defined(_MSC_VER) + FreeLibrary((HINSTANCE)loaded_plugins[i]); +#elif defined(__GNUC__) + dlclose(loaded_plugins[i]); +#endif + } + yasm_xfree(loaded_plugins); + num_loaded_plugins = 0; +} diff --git a/frontends/yasm/yasm-plugin.h b/frontends/yasm/yasm-plugin.h new file mode 100644 index 00000000..efb1bf51 --- /dev/null +++ b/frontends/yasm/yasm-plugin.h @@ -0,0 +1,34 @@ +/* + * Semi-portable (Windows and Unix) plugin loading + * + * Copyright (C) 2008 Peter Johnson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef YASM_PLUGIN_H +#define YASM_PLUGIN_H + +/* Load a plugin. Returns 0 on failure. */ +int load_plugin(const char *name); +void unload_plugins(void); + +#endif diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index b5f47080..bf3121f2 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -38,6 +38,10 @@ #include "yasm-options.h" +#ifdef CMAKE_BUILD +#include "yasm-plugin.h" +#endif + #include "license.c" /* Preprocess-only buffer size */ @@ -102,6 +106,9 @@ static int opt_include_option(char *cmd, /*@null@*/ char *param, int extra); static int opt_preproc_option(char *cmd, /*@null@*/ char *param, int extra); static int opt_ewmsg_handler(char *cmd, /*@null@*/ char *param, int extra); static int opt_makedep_handler(char *cmd, /*@null@*/ char *param, int extra); +#ifdef CMAKE_BUILD +static int opt_plugin_handler(char *cmd, /*@null@*/ char *param, int extra); +#endif static /*@only@*/ char *replace_extension(const char *orig, /*@null@*/ const char *ext, const char *def); @@ -189,6 +196,10 @@ static opt_option options[] = N_("undefine a macro"), N_("macro") }, { 'X', NULL, 1, opt_ewmsg_handler, 0, N_("select error/warning message style (`gnu' or `vc')"), N_("style") }, +#ifdef CMAKE_BUILD + { 'N', "plugin", 1, opt_plugin_handler, 0, + N_("load plugin module"), N_("plugin") }, +#endif }; /* version message */ @@ -560,6 +571,24 @@ main(int argc, char *argv[]) yasm_gettext_hook = handle_yasm_gettext; yasm_errwarn_initialize(); + /* Initialize BitVector (needed for intnum/floatnum). */ + if (BitVector_Boot() != ErrCode_Ok) { + print_error(_("%s: could not initialize BitVector"), _("FATAL")); + return EXIT_FAILURE; + } + + /* Initialize intnum and floatnum */ + yasm_intnum_initialize(); + yasm_floatnum_initialize(); + +#ifdef CMAKE_BUILD + /* Load standard modules */ + if (!load_plugin("libyasmstd")) { + print_error(_("%s: could not load standard modules"), _("FATAL")); + return EXIT_FAILURE; + } +#endif + /* Initialize parameter storage */ STAILQ_INIT(&preproc_options); @@ -591,16 +620,6 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - /* Initialize BitVector (needed for intnum/floatnum). */ - if (BitVector_Boot() != ErrCode_Ok) { - print_error(_("%s: could not initialize BitVector"), _("FATAL")); - return EXIT_FAILURE; - } - - /* Initialize intnum and floatnum */ - yasm_intnum_initialize(); - yasm_floatnum_initialize(); - /* If not already specified, default to bin as the object format. */ if (!cur_objfmt_module) { if (!objfmt_keyword) @@ -764,6 +783,9 @@ cleanup(yasm_object *object) if (errfile != stderr && errfile != stdout) fclose(errfile); +#ifdef CMAKE_BUILD + unload_plugins(); +#endif } /* @@ -1118,6 +1140,17 @@ opt_makedep_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, return 0; } +#ifdef CMAKE_BUILD +static int +opt_plugin_handler(/*@unused@*/ char *cmd, char *param, + /*@unused@*/ int extra) +{ + if (!load_plugin(param)) + print_error(_("warning: could not load plugin `%s'"), param); + return 0; +} +#endif + static void apply_preproc_builtins() { diff --git a/libyasm-stdint.h.cmake b/libyasm-stdint.h.cmake new file mode 100644 index 00000000..261a6182 --- /dev/null +++ b/libyasm-stdint.h.cmake @@ -0,0 +1,20 @@ +#cmakedefine HAVE_STDINT_H + +#ifdef HAVE_STDINT_H +#include +#elif defined(_MSC_VER) + +#ifndef _UINTPTR_T_DEFINED +#ifdef _WIN64 +#include +#else +typedef unsigned long uintptr_t; +#endif +#define _UINTPTR_T_DEFINED +#endif + +#else +typedef unsigned long uintptr_t; +#endif + +#undef HAVE_STDINT_H diff --git a/libyasm/CMakeLists.txt b/libyasm/CMakeLists.txt new file mode 100644 index 00000000..8be337e5 --- /dev/null +++ b/libyasm/CMakeLists.txt @@ -0,0 +1,70 @@ +SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) + +ADD_LIBRARY(libyasm SHARED + assocdat.c + bitvect.c + bc-align.c + bc-data.c + bc-incbin.c + bc-org.c + bc-reserve.c + bytecode.c + cmake-module.c + errwarn.c + expr.c + file.c + floatnum.c + hamt.c + insn.c + intnum.c + inttree.c + linemap.c + md5.c + mergesort.c + phash.c + section.c + strcasecmp.c + strsep.c + symrec.c + valparam.c + value.c + xmalloc.c + xstrdup.c + ) +SET_TARGET_PROPERTIES(libyasm PROPERTIES OUTPUT_NAME "yasm") + +INSTALL(TARGETS libyasm + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) + +INSTALL(FILES + arch.h + assocdat.h + bitvect.h + bytecode.h + compat-queue.h + coretype.h + dbgfmt.h + errwarn.h + expr.h + file.h + floatnum.h + hamt.h + insn.h + intnum.h + inttree.h + linemap.h + listfmt.h + md5.h + module.h + objfmt.h + parser.h + phash.h + preproc.h + section.h + symrec.h + valparam.h + value.h + DESTINATION include/libyasm + ) diff --git a/libyasm/cmake-module.c b/libyasm/cmake-module.c new file mode 100644 index 00000000..85309946 --- /dev/null +++ b/libyasm/cmake-module.c @@ -0,0 +1,127 @@ +/* + * YASM module loader + * + * Copyright (C) 2004-2007 Peter Johnson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +/*@unused@*/ RCSID("$Id: module.in 2080 2008-04-30 04:40:29Z peter $"); + +#include + + +typedef struct loaded_module { + const char *keyword; /* module keyword */ + void *data; /* associated data */ +} loaded_module; + +static HAMT *loaded_modules[] = {NULL, NULL, NULL, NULL, NULL, NULL}; + +static void +load_module_destroy(/*@only@*/ void *data) +{ + /* do nothing */ +} + +void * +yasm_load_module(yasm_module_type type, const char *keyword) +{ + if (!loaded_modules[type]) + return NULL; + return HAMT_search(loaded_modules[type], keyword); +} + +void +yasm_register_module(yasm_module_type type, const char *keyword, void *data) +{ + int replace = 1; + + assert(type < sizeof(loaded_modules)); + + if (!loaded_modules[type]) + loaded_modules[type] = HAMT_create(0, yasm_internal_error_); + + HAMT_insert(loaded_modules[type], keyword, data, &replace, + load_module_destroy); +} + +typedef struct { + yasm_module_type type; + void (*printfunc) (const char *name, const char *keyword); +} list_one_data; + +static int +yasm_list_one_module(void *node, void *d) +{ + list_one_data *data = (list_one_data *)d; + yasm_arch_module *arch; + yasm_dbgfmt_module *dbgfmt; + yasm_objfmt_module *objfmt; + yasm_listfmt_module *listfmt; + yasm_parser_module *parser; + yasm_preproc_module *preproc; + + switch (data->type) { + case YASM_MODULE_ARCH: + arch = node; + data->printfunc(arch->name, arch->keyword); + break; + case YASM_MODULE_DBGFMT: + dbgfmt = node; + data->printfunc(dbgfmt->name, dbgfmt->keyword); + break; + case YASM_MODULE_OBJFMT: + objfmt = node; + data->printfunc(objfmt->name, objfmt->keyword); + break; + case YASM_MODULE_LISTFMT: + listfmt = node; + data->printfunc(listfmt->name, listfmt->keyword); + break; + case YASM_MODULE_PARSER: + parser = node; + data->printfunc(parser->name, parser->keyword); + break; + case YASM_MODULE_PREPROC: + preproc = node; + data->printfunc(preproc->name, preproc->keyword); + break; + } + return 0; +} + +void +yasm_list_modules(yasm_module_type type, + void (*printfunc) (const char *name, const char *keyword)) +{ + list_one_data data; + + /* Go through available list, and try to load each one */ + if (!loaded_modules[type]) + return; + + data.type = type; + data.printfunc = printfunc; + + HAMT_traverse(loaded_modules[type], &data, yasm_list_one_module); +} diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt new file mode 100644 index 00000000..ebb7b6d6 --- /dev/null +++ b/modules/CMakeLists.txt @@ -0,0 +1,89 @@ +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + +INCLUDE(arch/CMakeLists.txt) +INCLUDE(listfmts/CMakeLists.txt) +INCLUDE(parsers/CMakeLists.txt) +INCLUDE(preprocs/CMakeLists.txt) +INCLUDE(dbgfmts/CMakeLists.txt) +INCLUDE(objfmts/CMakeLists.txt) + +MESSAGE(STATUS "Standard modules: ${YASM_MODULES}") + +# +# Generate init_plugin.c +# This file provides the yasm_init_plugin() function for yasmstd. +# + +SET(INIT_PLUGIN_C ${CMAKE_CURRENT_BINARY_DIR}/init_plugin.c) +SET(INIT_PLUGIN_C_REV 1) + +# Don't regen if no changes; default to regen +SET(regen_init_plugin_c TRUE) +IF(EXISTS ${INIT_PLUGIN_C}) + FILE(READ ${INIT_PLUGIN_C} _old_init_plugin_c) + STRING(REGEX MATCHALL "[^\n]*\n" _lines "${_old_init_plugin_c}") + #MESSAGE(STATUS "Lines: ${_lines}") + + LIST(GET _lines 0 _line0) + STRING(REGEX MATCH "([A-Za-z][A-Za-z0-9_]+[ ]?)+" _old_modules "${_line0}") + #MESSAGE(STATUS "Old modules: ${_old_modules}") + STRING(REPLACE ";" " " _modules_str "${YASM_MODULES}") + STRING(COMPARE EQUAL "${_old_modules}" "${_modules_str} " _modules_match) + + LIST(GET _lines 1 _line1) + STRING(REGEX MATCH "rev [0-9]+" _old_modules_rev "${_line1}") + #MESSAGE(STATUS "Old modules rev: ${_old_modules_rev}") + STRING(COMPARE EQUAL "${_old_modules_rev}" "rev ${INIT_PLUGIN_C_REV}" + _modules_rev_match) + + IF(_modules_match AND _modules_rev_match) + SET(regen_init_plugin_c FALSE) + ENDIF(_modules_match AND _modules_rev_match) +ENDIF(EXISTS ${INIT_PLUGIN_C}) + +IF(regen_init_plugin_c) + MESSAGE(STATUS "Generating standard plugin initialization file") + STRING(REPLACE ";" " " _modules_str "${YASM_MODULES}") + FILE(WRITE ${INIT_PLUGIN_C} "/* ${_modules_str} \n") + FILE(APPEND ${INIT_PLUGIN_C} " rev ${INIT_PLUGIN_C_REV}\n") + FILE(APPEND ${INIT_PLUGIN_C} " */\n\n") + FILE(APPEND ${INIT_PLUGIN_C} "#include \n") + FILE(APPEND ${INIT_PLUGIN_C} "#include \n\n") + FOREACH(module ${YASM_MODULES}) + STRING(REGEX MATCHALL "[a-zA-Z][a-zA-Z0-9]+" _modulepath ${module}) + LIST(GET _modulepath 0 _type) + LIST(GET _modulepath 1 _keyword) + FILE(APPEND ${INIT_PLUGIN_C} + "extern yasm_${_type}_module yasm_${_keyword}_LTX_${_type};\n") + ENDFOREACH(module) + FILE(APPEND ${INIT_PLUGIN_C} "\n#ifdef _MSC_VER\n") + FILE(APPEND ${INIT_PLUGIN_C} "__declspec(dllexport)\n") + FILE(APPEND ${INIT_PLUGIN_C} "#endif\n") + FILE(APPEND ${INIT_PLUGIN_C} "void\n") + FILE(APPEND ${INIT_PLUGIN_C} "yasm_init_plugin(void)\n") + FILE(APPEND ${INIT_PLUGIN_C} "{\n") + FOREACH(module ${YASM_MODULES}) + STRING(REGEX MATCHALL "[a-zA-Z][a-zA-Z0-9]+" _modulepath ${module}) + LIST(GET _modulepath 0 _type) + LIST(GET _modulepath 1 _keyword) + SET(_data "yasm_${_keyword}_LTX_${_type}") + STRING(TOUPPER "${_type}" _type) + FILE(APPEND ${INIT_PLUGIN_C} + " yasm_register_module(YASM_MODULE_${_type}, \"${_keyword}\", &${_data});\n") + ENDFOREACH(module) + FILE(APPEND ${INIT_PLUGIN_C} "}\n") +ELSE(regen_init_plugin_c) + MESSAGE(STATUS "Not regenerating static modules file (unchanged)") +ENDIF(regen_init_plugin_c) + +SET_SOURCE_FILES_PROPERTIES(init_plugin.c GENERATED) + +SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) + +ADD_LIBRARY(yasmstd MODULE + init_plugin.c + ${YASM_MODULES_SRC} + ) +TARGET_LINK_LIBRARIES(yasmstd libyasm) + +INSTALL(TARGETS yasmstd LIBRARY DESTINATION lib) diff --git a/modules/arch/CMakeLists.txt b/modules/arch/CMakeLists.txt new file mode 100644 index 00000000..ea65fbd0 --- /dev/null +++ b/modules/arch/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(arch/lc3b/CMakeLists.txt) +INCLUDE(arch/x86/CMakeLists.txt) diff --git a/modules/arch/lc3b/CMakeLists.txt b/modules/arch/lc3b/CMakeLists.txt new file mode 100644 index 00000000..0d5df705 --- /dev/null +++ b/modules/arch/lc3b/CMakeLists.txt @@ -0,0 +1,11 @@ +YASM_RE2C( + ${CMAKE_CURRENT_SOURCE_DIR}/arch/lc3b/lc3bid.re + ${CMAKE_CURRENT_BINARY_DIR}/lc3bid.c + -s + ) + +YASM_ADD_MODULE(arch_lc3b + arch/lc3b/lc3barch.c + arch/lc3b/lc3bbc.c + lc3bid.c + ) diff --git a/modules/arch/x86/CMakeLists.txt b/modules/arch/x86/CMakeLists.txt new file mode 100644 index 00000000..d15c9948 --- /dev/null +++ b/modules/arch/x86/CMakeLists.txt @@ -0,0 +1,50 @@ +ADD_CUSTOM_COMMAND( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86/gen_x86_insn.py + ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86/gen_x86_insn.py + ) + +YASM_GENPERF( + ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86/x86cpu.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86cpu.c + ) + +YASM_GENPERF( + ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86/x86regtmod.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86regtmod.c + ) + +YASM_GENPERF( + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.c + ) + +YASM_GENPERF( + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.c + ) + +YASM_ADD_MODULE(arch_x86 + arch/x86/x86arch.c + arch/x86/x86bc.c + arch/x86/x86expr.c + arch/x86/x86id.c + x86cpu.c + x86regtmod.c + ) + +SET(insn_DEPS + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.c + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.c + ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c + ) + +SET_SOURCE_FILES_PROPERTIES(arch/x86/x86id.c PROPERTIES + OBJECT_DEPENDS "${insn_DEPS}" + ) diff --git a/modules/dbgfmts/CMakeLists.txt b/modules/dbgfmts/CMakeLists.txt new file mode 100644 index 00000000..93c29fe8 --- /dev/null +++ b/modules/dbgfmts/CMakeLists.txt @@ -0,0 +1,4 @@ +INCLUDE(dbgfmts/codeview/CMakeLists.txt) +INCLUDE(dbgfmts/dwarf2/CMakeLists.txt) +INCLUDE(dbgfmts/null/CMakeLists.txt) +INCLUDE(dbgfmts/stabs/CMakeLists.txt) diff --git a/modules/dbgfmts/codeview/CMakeLists.txt b/modules/dbgfmts/codeview/CMakeLists.txt new file mode 100644 index 00000000..3ecd9fa5 --- /dev/null +++ b/modules/dbgfmts/codeview/CMakeLists.txt @@ -0,0 +1,5 @@ +YASM_ADD_MODULE(dbgfmt_cv8 + dbgfmts/codeview/cv-dbgfmt.c + dbgfmts/codeview/cv-symline.c + dbgfmts/codeview/cv-type.c + ) diff --git a/modules/dbgfmts/dwarf2/CMakeLists.txt b/modules/dbgfmts/dwarf2/CMakeLists.txt new file mode 100644 index 00000000..671910ee --- /dev/null +++ b/modules/dbgfmts/dwarf2/CMakeLists.txt @@ -0,0 +1,6 @@ +YASM_ADD_MODULE(dbgfmt_dwarf2 + dbgfmts/dwarf2/dwarf2-dbgfmt.c + dbgfmts/dwarf2/dwarf2-line.c + dbgfmts/dwarf2/dwarf2-aranges.c + dbgfmts/dwarf2/dwarf2-info.c + ) diff --git a/modules/dbgfmts/null/CMakeLists.txt b/modules/dbgfmts/null/CMakeLists.txt new file mode 100644 index 00000000..9f85b2fd --- /dev/null +++ b/modules/dbgfmts/null/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(dbgfmt_null + dbgfmts/null/null-dbgfmt.c + ) diff --git a/modules/dbgfmts/stabs/CMakeLists.txt b/modules/dbgfmts/stabs/CMakeLists.txt new file mode 100644 index 00000000..bd3b0268 --- /dev/null +++ b/modules/dbgfmts/stabs/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(dbgfmt_stabs + dbgfmts/stabs/stabs-dbgfmt.c + ) diff --git a/modules/listfmts/CMakeLists.txt b/modules/listfmts/CMakeLists.txt new file mode 100644 index 00000000..ce3c92a0 --- /dev/null +++ b/modules/listfmts/CMakeLists.txt @@ -0,0 +1 @@ +INCLUDE(listfmts/nasm/CMakeLists.txt) diff --git a/modules/listfmts/nasm/CMakeLists.txt b/modules/listfmts/nasm/CMakeLists.txt new file mode 100644 index 00000000..9d54f82f --- /dev/null +++ b/modules/listfmts/nasm/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(listfmt_nasm + listfmts/nasm/nasm-listfmt.c + ) diff --git a/modules/objfmts/CMakeLists.txt b/modules/objfmts/CMakeLists.txt new file mode 100644 index 00000000..c00a3a04 --- /dev/null +++ b/modules/objfmts/CMakeLists.txt @@ -0,0 +1,9 @@ +INCLUDE(objfmts/dbg/CMakeLists.txt) +INCLUDE(objfmts/bin/CMakeLists.txt) +INCLUDE(objfmts/elf/CMakeLists.txt) +INCLUDE(objfmts/coff/CMakeLists.txt) +INCLUDE(objfmts/macho/CMakeLists.txt) +INCLUDE(objfmts/rdf/CMakeLists.txt) +#INCLUDE(objfmts/win32/CMakeLists.txt) +#INCLUDE(objfmts/win64/CMakeLists.txt) +INCLUDE(objfmts/xdf/CMakeLists.txt) diff --git a/modules/objfmts/bin/CMakeLists.txt b/modules/objfmts/bin/CMakeLists.txt new file mode 100644 index 00000000..a3d396a5 --- /dev/null +++ b/modules/objfmts/bin/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(objfmt_bin + objfmts/bin/bin-objfmt.c + ) diff --git a/modules/objfmts/coff/CMakeLists.txt b/modules/objfmts/coff/CMakeLists.txt new file mode 100644 index 00000000..5f63d4f7 --- /dev/null +++ b/modules/objfmts/coff/CMakeLists.txt @@ -0,0 +1,27 @@ +YASM_GENMACRO( + ${CMAKE_CURRENT_SOURCE_DIR}/objfmts/coff/win64-nasm.mac + ${CMAKE_CURRENT_BINARY_DIR}/win64-nasm.c + win64_nasm_stdmac + ) + +YASM_GENMACRO( + ${CMAKE_CURRENT_SOURCE_DIR}/objfmts/coff/win64-gas.mac + ${CMAKE_CURRENT_BINARY_DIR}/win64-gas.c + win64_gas_stdmac + ) + +SET(coff_DEPS + ${CMAKE_CURRENT_BINARY_DIR}/win64-nasm.c + ${CMAKE_CURRENT_BINARY_DIR}/win64-gas.c + ) + +SET_SOURCE_FILES_PROPERTIES(objfmts/coff/coff-objfmt.c PROPERTIES + OBJECT_DEPENDS "${coff_DEPS}" + ) + +YASM_ADD_MODULE(objfmt_coff + objfmts/coff/coff-objfmt.c + objfmts/coff/win64-except.c + ) +list(APPEND YASM_MODULES objfmt_win32) +list(APPEND YASM_MODULES objfmt_win64) diff --git a/modules/objfmts/dbg/CMakeLists.txt b/modules/objfmts/dbg/CMakeLists.txt new file mode 100644 index 00000000..ba5193fa --- /dev/null +++ b/modules/objfmts/dbg/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(objfmt_dbg + objfmts/dbg/dbg-objfmt.c + ) diff --git a/modules/objfmts/elf/CMakeLists.txt b/modules/objfmts/elf/CMakeLists.txt new file mode 100644 index 00000000..c06b81d8 --- /dev/null +++ b/modules/objfmts/elf/CMakeLists.txt @@ -0,0 +1,8 @@ +YASM_ADD_MODULE(objfmt_elf + objfmts/elf/elf.c + objfmts/elf/elf-objfmt.c + objfmts/elf/elf-x86-x86.c + objfmts/elf/elf-x86-amd64.c + ) +list(APPEND YASM_MODULES objfmt_elf32) +list(APPEND YASM_MODULES objfmt_elf64) diff --git a/modules/objfmts/macho/CMakeLists.txt b/modules/objfmts/macho/CMakeLists.txt new file mode 100644 index 00000000..cb5f4934 --- /dev/null +++ b/modules/objfmts/macho/CMakeLists.txt @@ -0,0 +1,5 @@ +YASM_ADD_MODULE(objfmt_macho + objfmts/macho/macho-objfmt.c + ) +list(APPEND YASM_MODULES objfmt_macho32) +list(APPEND YASM_MODULES objfmt_macho64) diff --git a/modules/objfmts/rdf/CMakeLists.txt b/modules/objfmts/rdf/CMakeLists.txt new file mode 100644 index 00000000..6cf9157d --- /dev/null +++ b/modules/objfmts/rdf/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(objfmt_rdf + objfmts/rdf/rdf-objfmt.c + ) diff --git a/modules/objfmts/xdf/CMakeLists.txt b/modules/objfmts/xdf/CMakeLists.txt new file mode 100644 index 00000000..681ec2b0 --- /dev/null +++ b/modules/objfmts/xdf/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(objfmt_xdf + objfmts/xdf/xdf-objfmt.c + ) diff --git a/modules/parsers/CMakeLists.txt b/modules/parsers/CMakeLists.txt new file mode 100644 index 00000000..db1e371f --- /dev/null +++ b/modules/parsers/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(parsers/gas/CMakeLists.txt) +INCLUDE(parsers/nasm/CMakeLists.txt) diff --git a/modules/parsers/gas/CMakeLists.txt b/modules/parsers/gas/CMakeLists.txt new file mode 100644 index 00000000..de23426f --- /dev/null +++ b/modules/parsers/gas/CMakeLists.txt @@ -0,0 +1,11 @@ +YASM_RE2C( + ${CMAKE_CURRENT_SOURCE_DIR}/parsers/gas/gas-token.re + ${CMAKE_CURRENT_BINARY_DIR}/gas-token.c + -b + ) + +YASM_ADD_MODULE(parser_gas + parsers/gas/gas-parser.c + parsers/gas/gas-parse.c + gas-token.c + ) diff --git a/modules/parsers/nasm/CMakeLists.txt b/modules/parsers/nasm/CMakeLists.txt new file mode 100644 index 00000000..7a060d29 --- /dev/null +++ b/modules/parsers/nasm/CMakeLists.txt @@ -0,0 +1,21 @@ +YASM_GENMACRO( + ${CMAKE_CURRENT_SOURCE_DIR}/parsers/nasm/nasm-std.mac + ${CMAKE_CURRENT_BINARY_DIR}/nasm-macros.c + nasm_standard_mac + ) + +SET_SOURCE_FILES_PROPERTIES(parsers/nasm/nasm-parser.c PROPERTIES + OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/nasm-macros.c + ) + +YASM_RE2C( + ${CMAKE_CURRENT_SOURCE_DIR}/parsers/nasm/nasm-token.re + ${CMAKE_CURRENT_BINARY_DIR}/nasm-token.c + -b + ) + +YASM_ADD_MODULE(parser_nasm + parsers/nasm/nasm-parser.c + parsers/nasm/nasm-parse.c + nasm-token.c + ) diff --git a/modules/preprocs/CMakeLists.txt b/modules/preprocs/CMakeLists.txt new file mode 100644 index 00000000..dccecbe5 --- /dev/null +++ b/modules/preprocs/CMakeLists.txt @@ -0,0 +1,3 @@ +INCLUDE(preprocs/nasm/CMakeLists.txt) +INCLUDE(preprocs/raw/CMakeLists.txt) +INCLUDE(preprocs/cpp/CMakeLists.txt) diff --git a/modules/preprocs/cpp/CMakeLists.txt b/modules/preprocs/cpp/CMakeLists.txt new file mode 100644 index 00000000..202787cb --- /dev/null +++ b/modules/preprocs/cpp/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(preproc_cpp + preprocs/cpp/cpp-preproc.c + ) diff --git a/modules/preprocs/nasm/CMakeLists.txt b/modules/preprocs/nasm/CMakeLists.txt new file mode 100644 index 00000000..e10a9dd1 --- /dev/null +++ b/modules/preprocs/nasm/CMakeLists.txt @@ -0,0 +1,25 @@ +add_executable(genversion preprocs/nasm/genversion.c) +get_target_property(_tmp_GENVERSION_EXE genversion LOCATION) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.mac + COMMAND ${_tmp_GENVERSION_EXE} ${CMAKE_CURRENT_BINARY_DIR}/version.mac + DEPENDS ${_tmp_GENVERSION_EXE} + ) + +YASM_GENMACRO( + ${CMAKE_CURRENT_BINARY_DIR}/version.mac + ${CMAKE_CURRENT_BINARY_DIR}/nasm-version.c + nasm_version_mac + ) + +SET_SOURCE_FILES_PROPERTIES(preprocs/nasm/nasm-preproc.c PROPERTIES + OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/nasm-version.c + ) + +YASM_ADD_MODULE(preproc_nasm + preprocs/nasm/nasm-preproc.c + preprocs/nasm/nasm-pp.c + preprocs/nasm/nasmlib.c + preprocs/nasm/nasm-eval.c + ) + diff --git a/modules/preprocs/raw/CMakeLists.txt b/modules/preprocs/raw/CMakeLists.txt new file mode 100644 index 00000000..fc345386 --- /dev/null +++ b/modules/preprocs/raw/CMakeLists.txt @@ -0,0 +1,3 @@ +YASM_ADD_MODULE(preproc_raw + preprocs/raw/raw-preproc.c + ) diff --git a/plugins/README b/plugins/README new file mode 100644 index 00000000..c16a8fd0 --- /dev/null +++ b/plugins/README @@ -0,0 +1,20 @@ +These directories contain example yasm plugins. +Yasm is only capable of loading plugins when it was built using cmake. +To build yasm with cmake on Unix, from the yasm source tree, do: + mkdir objdir + cd objdir + cmake .. + make + +The plugins are written to be compiled against an *installed* yasm. +Plugins may be loaded on the yasm command line using the -N command line +option, e.g.: + yasm -N ./libdbgmod.so + yasm -N /usr/local/lib/libx86mod +(the .so will be automatically appended) +If no directory path is specified, yasm will search in standard library +locations (e.g. LD_LIBRARY_PATH, the rpath of the yasm executable, etc) to +try to load the plugin. Thus the last example could likely be written: + yasm -N libx86mod + +Plugins may override builtin modules like x86. diff --git a/plugins/dbg/CMakeLists.txt b/plugins/dbg/CMakeLists.txt new file mode 100644 index 00000000..fa51498b --- /dev/null +++ b/plugins/dbg/CMakeLists.txt @@ -0,0 +1,45 @@ +FIND_PROGRAM(YASM_PATH yasm) + +SET (YASM_POSSIBLE_INCLUDE_PATHS + "${YASM_PATH}" + "${YASM_PATH}/../include" + "$ENV{ProgramFiles}/Yasm/Include" + /usr/include + /usr/local/include + ) + +FIND_PATH(YASM_INCLUDE_PATH NAMES libyasm.h + DOC "The path to the libyasm include files" + PATHS ${YASM_POSSIBLE_INCLUDE_PATHS} + ) + +IF (NOT YASM_INCLUDE_PATH) + MESSAGE(FATAL_ERROR "Could not find yasm include files") +ENDIF (NOT YASM_INCLUDE_PATH) + +INCLUDE_DIRECTORIES(${YASM_INCLUDE_PATH}) + +SET (YASM_POSSIBLE_LIB_PATHS + "${YASM_PATH}" + "${YASM_PATH}/../lib" + "${YASM_INCLUDE_PATH}/../lib" + "$ENV{ProgramFiles}/Yasm/Lib" + /usr/lib + /usr/local/lib + ) + +FIND_LIBRARY(YASM_LIBRARY + NAMES yasm + DOC "The path to the libyasm library" + PATHS ${YASM_POSSIBLE_LIB_PATHS} + ) + +IF (NOT YASM_LIBRARY) + MESSAGE(FATAL_ERROR "Could not find yasm library") +ENDIF (NOT YASM_LIBRARY) + +ADD_LIBRARY(dbgmod MODULE + init_plugin.c + dbg-objfmt.c + ) +TARGET_LINK_LIBRARIES(dbgmod ${YASM_LIBRARY}) diff --git a/plugins/dbg/README b/plugins/dbg/README new file mode 100644 index 00000000..3a1f5cb7 --- /dev/null +++ b/plugins/dbg/README @@ -0,0 +1,15 @@ +This directory demonstrates how to build a basic plugin. +It does not need access to the yasm source, only an installed yasm. + +To build: + mkdir objdir + cd objdir + cmake .. + make + +Testing: + yasm -N ./libdbgmod.so -f dbg - + db 5 + ^D +(result lines will have PLUGIN prefixed to the function calls; this +demonstrates the plugin is being used rather than the builtin dbg module) diff --git a/plugins/dbg/dbg-objfmt.c b/plugins/dbg/dbg-objfmt.c new file mode 100644 index 00000000..1aef7c20 --- /dev/null +++ b/plugins/dbg/dbg-objfmt.c @@ -0,0 +1,175 @@ +/* + * Debugging object format (used to debug object format module interface) + * + * Copyright (C) 2001-2007 Peter Johnson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include + +#define N_(String) (String) + +typedef struct yasm_objfmt_dbg { + yasm_objfmt_base objfmt; /* base structure */ + + FILE *dbgfile; +} yasm_objfmt_dbg; + +yasm_objfmt_module yasm_dbg_LTX_objfmt; + + +static yasm_objfmt * +dbg_objfmt_create(yasm_object *object) +{ + yasm_objfmt_dbg *objfmt_dbg = yasm_xmalloc(sizeof(yasm_objfmt_dbg)); + + objfmt_dbg->objfmt.module = &yasm_dbg_LTX_objfmt; + + objfmt_dbg->dbgfile = tmpfile(); + if (!objfmt_dbg->dbgfile) { + fprintf(stderr, N_("could not open temporary file")); + return 0; + } + fprintf(objfmt_dbg->dbgfile, "PLUGIN create()\n"); + return (yasm_objfmt *)objfmt_dbg; +} + +static void +dbg_objfmt_output(yasm_object *object, FILE *f, int all_syms, + yasm_errwarns *errwarns) +{ + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; + char buf[1024]; + size_t i; + + /* Copy temp file to real output file */ + rewind(objfmt_dbg->dbgfile); + while ((i = fread(buf, 1, 1024, objfmt_dbg->dbgfile))) { + if (fwrite(buf, 1, i, f) != i) + break; + } + + /* Reassign objfmt debug file to output file */ + fclose(objfmt_dbg->dbgfile); + objfmt_dbg->dbgfile = f; + + fprintf(objfmt_dbg->dbgfile, "PLUGIN output(f, object->\n"); + yasm_object_print(object, objfmt_dbg->dbgfile, 1); + fprintf(objfmt_dbg->dbgfile, "%d)\n", all_syms); + fprintf(objfmt_dbg->dbgfile, " Symbol Table:\n"); + yasm_symtab_print(object->symtab, objfmt_dbg->dbgfile, 1); +} + +static void +dbg_objfmt_destroy(yasm_objfmt *objfmt) +{ + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)objfmt; + fprintf(objfmt_dbg->dbgfile, "PLUGIN destroy()\n"); + yasm_xfree(objfmt); +} + +static yasm_section * +dbg_objfmt_add_default_section(yasm_object *object) +{ + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; + yasm_section *retval; + int isnew; + + retval = yasm_object_get_general(object, ".text", 0, 0, 0, &isnew, 0); + if (isnew) { + fprintf(objfmt_dbg->dbgfile, "(new) "); + yasm_symtab_define_label(object->symtab, ".text", + yasm_section_bcs_first(retval), 1, 0); + yasm_section_set_default(retval, 1); + } + return retval; +} + +static /*@observer@*/ /*@null@*/ yasm_section * +dbg_objfmt_section_switch(yasm_object *object, yasm_valparamhead *valparams, + /*@unused@*/ /*@null@*/ + yasm_valparamhead *objext_valparams, + unsigned long line) +{ + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; + yasm_valparam *vp; + yasm_section *retval; + int isnew; + + fprintf(objfmt_dbg->dbgfile, "PLUGIN section_switch(headp, "); + yasm_vps_print(valparams, objfmt_dbg->dbgfile); + fprintf(objfmt_dbg->dbgfile, ", "); + yasm_vps_print(objext_valparams, objfmt_dbg->dbgfile); + fprintf(objfmt_dbg->dbgfile, ", %lu), returning ", line); + + vp = yasm_vps_first(valparams); + if (!yasm_vp_string(vp)) { + fprintf(objfmt_dbg->dbgfile, "NULL\n"); + return NULL; + } + retval = yasm_object_get_general(object, yasm_vp_string(vp), 0, 0, 0, + &isnew, line); + if (isnew) { + fprintf(objfmt_dbg->dbgfile, "(new) "); + yasm_symtab_define_label(object->symtab, vp->val, + yasm_section_bcs_first(retval), 1, line); + } + yasm_section_set_default(retval, 0); + fprintf(objfmt_dbg->dbgfile, "\"%s\" section\n", vp->val); + return retval; +} + +static /*@observer@*/ /*@null@*/ yasm_symrec * +dbg_objfmt_get_special_sym(yasm_object *object, const char *name, + const char *parser) +{ + yasm_objfmt_dbg *objfmt_dbg = (yasm_objfmt_dbg *)object->objfmt; + fprintf(objfmt_dbg->dbgfile, + "PLUGIN get_special_sym(object, \"%s\", \"%s\")\n", + name, parser); + return NULL; +} + +/* Define valid debug formats to use with this object format */ +static const char *dbg_objfmt_dbgfmt_keywords[] = { + "null", + NULL +}; + +/* Define objfmt structure -- see objfmt.h for details */ +yasm_objfmt_module yasm_dbg_LTX_objfmt = { + "Trace of all info passed to object format module", + "dbg", + "dbg", + 32, + dbg_objfmt_dbgfmt_keywords, + "null", + NULL, /* no directives */ + NULL, /* no standard macros */ + dbg_objfmt_create, + dbg_objfmt_output, + dbg_objfmt_destroy, + dbg_objfmt_add_default_section, + dbg_objfmt_section_switch, + dbg_objfmt_get_special_sym +}; diff --git a/plugins/dbg/init_plugin.c b/plugins/dbg/init_plugin.c new file mode 100644 index 00000000..e8e53dc5 --- /dev/null +++ b/plugins/dbg/init_plugin.c @@ -0,0 +1,13 @@ +#include +#include + +extern yasm_arch_module yasm_dbg_LTX_objfmt; + +#ifdef _MSC_VER +__declspec(dllexport) +#endif +void +yasm_init_plugin(void) +{ + yasm_register_module(YASM_MODULE_OBJFMT, "dbg", &yasm_dbg_LTX_objfmt); +} diff --git a/plugins/x86/CMakeLists.txt b/plugins/x86/CMakeLists.txt new file mode 100644 index 00000000..55d273d5 --- /dev/null +++ b/plugins/x86/CMakeLists.txt @@ -0,0 +1,117 @@ +SET(SOURCE_DIR "${YASM_SOURCE_DIR}/modules/arch/x86") + +FIND_PROGRAM(YASM_PATH yasm) + +FIND_PROGRAM(GENPERF_PATH genperf + DOC "The path to the yasm genperf executable" + PATHS ${YASM_SOURCE_DIR}/objdir/tools/genperf + ) + +IF (NOT GENPERF_PATH) + MESSAGE(FATAL_ERROR "Could not find genperf executable") +ENDIF (NOT GENPERF_PATH) + +SET (YASM_POSSIBLE_INCLUDE_PATHS + "${YASM_PATH}" + "${YASM_PATH}/../include" + "$ENV{ProgramFiles}/Yasm/Include" + /usr/include + /usr/local/include + ) + +FIND_PATH(YASM_INCLUDE_PATH NAMES libyasm.h + DOC "The path to the libyasm include files" + PATHS ${YASM_POSSIBLE_INCLUDE_PATHS} + ) + +IF (NOT YASM_INCLUDE_PATH) + MESSAGE(FATAL_ERROR "Could not find yasm include files") +ENDIF (NOT YASM_INCLUDE_PATH) + +INCLUDE_DIRECTORIES(${YASM_INCLUDE_PATH}) +INCLUDE_DIRECTORIES(${YASM_SOURCE_DIR}) + +SET (YASM_POSSIBLE_LIB_PATHS + "${YASM_PATH}" + "${YASM_PATH}/../lib" + "${YASM_INCLUDE_PATH}/../lib" + "$ENV{ProgramFiles}/Yasm/Lib" + /usr/lib + /usr/local/lib + ) + +FIND_LIBRARY(YASM_LIBRARY + NAMES yasm + DOC "The path to the libyasm library" + PATHS ${YASM_POSSIBLE_LIB_PATHS} + ) + +IF (NOT YASM_LIBRARY) + MESSAGE(FATAL_ERROR "Could not find yasm library") +ENDIF (NOT YASM_LIBRARY) + +INCLUDE(FindPythonInterp) + +INCLUDE_DIRECTORIES(${SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_CUSTOM_COMMAND( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf + COMMAND ${PYTHON_EXECUTABLE} ${SOURCE_DIR}/gen_x86_insn.py + ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf + MAIN_DEPENDENCY ${SOURCE_DIR}/gen_x86_insn.py + ) + +macro (YASM_GENPERF _in_NAME _out_NAME) + add_custom_command( + OUTPUT ${_out_NAME} + COMMAND ${GENPERF_PATH} ${_in_NAME} ${_out_NAME} + MAIN_DEPENDENCY ${_in_NAME} + ) +endmacro (YASM_GENPERF) + +YASM_GENPERF( + ${SOURCE_DIR}/x86cpu.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86cpu.c + ) + +YASM_GENPERF( + ${SOURCE_DIR}/x86regtmod.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86regtmod.c + ) + +YASM_GENPERF( + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.c + ) + +YASM_GENPERF( + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.c + ) + +SET(insn_DEPS + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.c + ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.c + ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c + ) + +SET_SOURCE_FILES_PROPERTIES(${SOURCE_DIR}/x86id.c PROPERTIES + OBJECT_DEPENDS "${insn_DEPS}" + ) + +ADD_LIBRARY(x86mod MODULE + init_plugin.c + ${SOURCE_DIR}/x86arch.c + ${SOURCE_DIR}/x86bc.c + ${SOURCE_DIR}/x86expr.c + ${SOURCE_DIR}/x86id.c + x86cpu.c + x86regtmod.c + ) +TARGET_LINK_LIBRARIES(x86mod ${YASM_LIBRARY}) diff --git a/plugins/x86/README b/plugins/x86/README new file mode 100644 index 00000000..17346155 --- /dev/null +++ b/plugins/x86/README @@ -0,0 +1,10 @@ +This directory demonstrates how to build a yasm builtin module as a plugin. +This can be useful for integrating custom changes without +rebuilding/reinstalling yasm. +It requires access to the yasm source. + +The yasm source directory must be defined to cmake, e.g. + mkdir objdir + cd objdir + cmake -DYASM_SOURCE_DIR=/home/foo/yasm .. + make diff --git a/plugins/x86/init_plugin.c b/plugins/x86/init_plugin.c new file mode 100644 index 00000000..d2698b19 --- /dev/null +++ b/plugins/x86/init_plugin.c @@ -0,0 +1,13 @@ +#include +#include + +extern yasm_arch_module yasm_x86_LTX_arch; + +#ifdef _MSC_VER +__declspec(dllexport) +#endif +void +yasm_init_plugin(void) +{ + yasm_register_module(YASM_MODULE_ARCH, "x86", &yasm_x86_LTX_arch); +} diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 00000000..4b83d4eb --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,3 @@ +ADD_SUBDIRECTORY(genmacro) +ADD_SUBDIRECTORY(genperf) +ADD_SUBDIRECTORY(re2c) diff --git a/tools/genmacro/CMakeLists.txt b/tools/genmacro/CMakeLists.txt new file mode 100644 index 00000000..27ba5996 --- /dev/null +++ b/tools/genmacro/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(genmacro + genmacro.c + ) diff --git a/tools/genperf/CMakeLists.txt b/tools/genperf/CMakeLists.txt new file mode 100644 index 00000000..22afcc95 --- /dev/null +++ b/tools/genperf/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(genperf + genperf.c + perfect.c + ../../libyasm/phash.c + ../../libyasm/xmalloc.c + ../../libyasm/xstrdup.c + ) diff --git a/tools/re2c/CMakeLists.txt b/tools/re2c/CMakeLists.txt new file mode 100644 index 00000000..7125d496 --- /dev/null +++ b/tools/re2c/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(re2c + main.c + code.c + dfa.c + parser.c + actions.c + scanner.c + mbo_getopt.c + substr.c + translate.c + )