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
0.7.2
Peter Johnson 17 years ago
parent 811d7ad566
commit b7f2fbc64f
  1. 47
      CMakeLists.txt
  2. 70
      ConfigureChecks.cmake
  3. 1
      cmake/CMakeLists.txt
  4. 2
      cmake/modules/CMakeLists.txt
  5. 4
      cmake/modules/DummyCFile.c
  6. 89
      cmake/modules/YasmMacros.cmake
  7. 51
      config.h.cmake
  8. 1
      frontends/CMakeLists.txt
  9. 26
      frontends/yasm/CMakeLists.txt
  10. 41
      frontends/yasm/genstring.py
  11. 119
      frontends/yasm/yasm-plugin.c
  12. 34
      frontends/yasm/yasm-plugin.h
  13. 53
      frontends/yasm/yasm.c
  14. 20
      libyasm-stdint.h.cmake
  15. 70
      libyasm/CMakeLists.txt
  16. 127
      libyasm/cmake-module.c
  17. 89
      modules/CMakeLists.txt
  18. 2
      modules/arch/CMakeLists.txt
  19. 11
      modules/arch/lc3b/CMakeLists.txt
  20. 50
      modules/arch/x86/CMakeLists.txt
  21. 4
      modules/dbgfmts/CMakeLists.txt
  22. 5
      modules/dbgfmts/codeview/CMakeLists.txt
  23. 6
      modules/dbgfmts/dwarf2/CMakeLists.txt
  24. 3
      modules/dbgfmts/null/CMakeLists.txt
  25. 3
      modules/dbgfmts/stabs/CMakeLists.txt
  26. 1
      modules/listfmts/CMakeLists.txt
  27. 3
      modules/listfmts/nasm/CMakeLists.txt
  28. 9
      modules/objfmts/CMakeLists.txt
  29. 3
      modules/objfmts/bin/CMakeLists.txt
  30. 27
      modules/objfmts/coff/CMakeLists.txt
  31. 3
      modules/objfmts/dbg/CMakeLists.txt
  32. 8
      modules/objfmts/elf/CMakeLists.txt
  33. 5
      modules/objfmts/macho/CMakeLists.txt
  34. 3
      modules/objfmts/rdf/CMakeLists.txt
  35. 3
      modules/objfmts/xdf/CMakeLists.txt
  36. 2
      modules/parsers/CMakeLists.txt
  37. 11
      modules/parsers/gas/CMakeLists.txt
  38. 21
      modules/parsers/nasm/CMakeLists.txt
  39. 3
      modules/preprocs/CMakeLists.txt
  40. 3
      modules/preprocs/cpp/CMakeLists.txt
  41. 25
      modules/preprocs/nasm/CMakeLists.txt
  42. 3
      modules/preprocs/raw/CMakeLists.txt
  43. 20
      plugins/README
  44. 45
      plugins/dbg/CMakeLists.txt
  45. 15
      plugins/dbg/README
  46. 175
      plugins/dbg/dbg-objfmt.c
  47. 13
      plugins/dbg/init_plugin.c
  48. 117
      plugins/x86/CMakeLists.txt
  49. 10
      plugins/x86/README
  50. 13
      plugins/x86/init_plugin.c
  51. 3
      tools/CMakeLists.txt
  52. 3
      tools/genmacro/CMakeLists.txt
  53. 7
      tools/genperf/CMakeLists.txt
  54. 11
      tools/re2c/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
)

@ -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)

@ -0,0 +1 @@
ADD_SUBDIRECTORY(modules)

@ -0,0 +1,2 @@
FILE(GLOB cmakeFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.cmake")

@ -0,0 +1,4 @@
int main()
{
return 0;
}

@ -0,0 +1,89 @@
# Portions based on kdelibs KDE4Macros.cmake:
#
# Copyright (c) 2006, 2007, Alexander Neundorf, <neundorf@kde.org>
# Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
# Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
#
# 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 <testname>, if it is
# not given the macro will default to the <name>
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)

@ -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 <libgen.h> header file. */
#cmakedefine HAVE_LIBGEN_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1
/* Define to 1 if you have the <direct.h> 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@"

@ -0,0 +1 @@
ADD_SUBDIRECTORY(yasm)

@ -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)

@ -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 <string> <outfile> <file>"
sys.exit(2)
file_to_string(open(sys.argv[2], "w"), sys.argv[1], sys.argv[3])

@ -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 <util.h>
/*@unused@*/ RCSID("$Id$");
#include <string.h>
#include "yasm-plugin.h"
#if defined(_MSC_VER)
#include <windows.h>
#elif defined(__GNUC__)
#include <dlfcn.h>
#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;
}

@ -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

@ -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()
{

@ -0,0 +1,20 @@
#cmakedefine HAVE_STDINT_H
#ifdef HAVE_STDINT_H
#include <stdint.h>
#elif defined(_MSC_VER)
#ifndef _UINTPTR_T_DEFINED
#ifdef _WIN64
#include <vadefs.h>
#else
typedef unsigned long uintptr_t;
#endif
#define _UINTPTR_T_DEFINED
#endif
#else
typedef unsigned long uintptr_t;
#endif
#undef HAVE_STDINT_H

@ -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
)

@ -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 <util.h>
/*@unused@*/ RCSID("$Id: module.in 2080 2008-04-30 04:40:29Z peter $");
#include <libyasm.h>
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);
}

@ -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 <libyasm.h>\n")
FILE(APPEND ${INIT_PLUGIN_C} "#include <libyasm/module.h>\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)

@ -0,0 +1,2 @@
INCLUDE(arch/lc3b/CMakeLists.txt)
INCLUDE(arch/x86/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
)

@ -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}"
)

@ -0,0 +1,4 @@
INCLUDE(dbgfmts/codeview/CMakeLists.txt)
INCLUDE(dbgfmts/dwarf2/CMakeLists.txt)
INCLUDE(dbgfmts/null/CMakeLists.txt)
INCLUDE(dbgfmts/stabs/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
)

@ -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
)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(dbgfmt_null
dbgfmts/null/null-dbgfmt.c
)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(dbgfmt_stabs
dbgfmts/stabs/stabs-dbgfmt.c
)

@ -0,0 +1 @@
INCLUDE(listfmts/nasm/CMakeLists.txt)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(listfmt_nasm
listfmts/nasm/nasm-listfmt.c
)

@ -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)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(objfmt_bin
objfmts/bin/bin-objfmt.c
)

@ -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)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(objfmt_dbg
objfmts/dbg/dbg-objfmt.c
)

@ -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)

@ -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)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(objfmt_rdf
objfmts/rdf/rdf-objfmt.c
)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(objfmt_xdf
objfmts/xdf/xdf-objfmt.c
)

@ -0,0 +1,2 @@
INCLUDE(parsers/gas/CMakeLists.txt)
INCLUDE(parsers/nasm/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
)

@ -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
)

@ -0,0 +1,3 @@
INCLUDE(preprocs/nasm/CMakeLists.txt)
INCLUDE(preprocs/raw/CMakeLists.txt)
INCLUDE(preprocs/cpp/CMakeLists.txt)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(preproc_cpp
preprocs/cpp/cpp-preproc.c
)

@ -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
)

@ -0,0 +1,3 @@
YASM_ADD_MODULE(preproc_raw
preprocs/raw/raw-preproc.c
)

@ -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.

@ -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})

@ -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)

@ -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 <stdio.h>
#include <libyasm.h>
#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
};

@ -0,0 +1,13 @@
#include <libyasm.h>
#include <libyasm/module.h>
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);
}

@ -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})

@ -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

@ -0,0 +1,13 @@
#include <libyasm.h>
#include <libyasm/module.h>
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);
}

@ -0,0 +1,3 @@
ADD_SUBDIRECTORY(genmacro)
ADD_SUBDIRECTORY(genperf)
ADD_SUBDIRECTORY(re2c)

@ -0,0 +1,3 @@
add_executable(genmacro
genmacro.c
)

@ -0,0 +1,7 @@
add_executable(genperf
genperf.c
perfect.c
../../libyasm/phash.c
../../libyasm/xmalloc.c
../../libyasm/xstrdup.c
)

@ -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
)
Loading…
Cancel
Save