Compare commits

..

5 Commits

Author SHA1 Message Date
Dibyendu Majumdar cadee5563f issue #198 add another test for sieve - but using while loop
4 years ago
Dibyendu Majumdar 66bf2c6c17 issue #198 tests for farray opcodes
4 years ago
Dibyendu Majumdar faff7902b3 issue #198 tests for iarray opcodes
4 years ago
Dibyendu Majumdar 4b9c746526 issue #169 debug output
4 years ago
Dibyendu Majumdar ba0c697c9a issue #169 non-ssa branch
4 years ago

@ -1,7 +0,0 @@
# [Choice] Debian / Ubuntu version: debian-10, debian-9, ubuntu-20.04, ubuntu-18.04
ARG VARIANT=buster
FROM mcr.microsoft.com/vscode/devcontainers/cpp:dev-${VARIANT}
# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

@ -1,12 +0,0 @@
# [Choice] Debian / Ubuntu version: debian-10, debian-9, ubuntu-20.04, ubuntu-18.04
ARG VARIANT=buster
FROM mcr.microsoft.com/vscode/devcontainers/base:${VARIANT}
# Install needed packages. Use a separate RUN statement to add your own dependencies.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install build-essential cmake cppcheck valgrind clang lldb llvm gdb \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

@ -1,28 +0,0 @@
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-10, debian-9, ubuntu-20.04, ubuntu-18.04
"args": { "VARIANT": "debian-10" }
},
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}

@ -12,11 +12,8 @@ env:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

@ -3,17 +3,23 @@ os:
- linux
arch:
- amd64
- arm64
compiler:
- gcc
cache: ccache
dist: focal
dist: bionic
addons:
apt:
packages:
- g++
- gcc
- ccache
install:
- curl https://releases.llvm.org/6.0.1/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz | tar -xJf -
script:
- mkdir $TRAVIS_BUILD_DIR/build
- cd $TRAVIS_BUILD_DIR/build && cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_DIR=$TRAVIS_BUILD_DIR/clang+llvm-6.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/cmake/llvm -G "Unix Makefiles" -DLLVM_JIT=ON ..
- cd $TRAVIS_BUILD_DIR/build && make
- cd $TRAVIS_BUILD_DIR/tests && sh ./run_tests.sh $TRAVIS_BUILD_DIR/build/ravi
- mkdir $TRAVIS_BUILD_DIR/buildmir
- cd $TRAVIS_BUILD_DIR/buildmir && cmake -DCMAKE_BUILD_TYPE=Debug -DLTESTS=ON -DMIR_JIT=ON -G "Unix Makefiles" ..
- cd $TRAVIS_BUILD_DIR/buildmir && make

@ -1,22 +1,29 @@
cmake_minimum_required(VERSION 3.12)
project(Ravi VERSION 1.0.4 LANGUAGES C)
project(Ravi VERSION 1.0.4 LANGUAGES C CXX)
# By default MIR JIT backend is automatically enabled. To disable user must specify
# By default on platforms where MIR is supported (right now Linux X86_64)
# MIR JIT backend is automatically enabled. To disable user must specify
# NO_JIT=ON
# LLVM has to be explicitly specified using LLVM_JIT=ON
option(LLVM_JIT "Controls whether LLVM JIT compilation will be enabled, default is OFF" OFF)
option(NO_JIT "Controls whether JIT should be disabled, default is OFF" OFF)
option(STATIC_BUILD "Build static version of Ravi, default is OFF" OFF)
option(COMPUTED_GOTO "Controls whether the interpreter switch will use computed gotos on gcc/clang, default is ON" ON)
option(LTESTS "Controls whether ltests are enabled in Debug mode; note requires Debug build" ON)
option(ASAN "Controls whether address sanitizer should be enabled" OFF)
option(RAVICOMP "Controls whether to link in RaviComp" ON)
option(RAVICOMP "Controls whether to link in RaviComp" OFF)
# By we enable MIR JIT
if (NOT NO_JIT)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# By default on non-Windows platforms we enable MIR JIT
if (NOT LLVM_JIT
AND NOT NO_JIT)
set(MIR_JIT ON)
endif ()
if (MIR_JIT)
set(LLVM_JIT OFF)
set(STATIC_BUILD OFF) # Because we need to expose the symbols in the library
endif ()
@ -44,6 +51,17 @@ set(LUA_CORE_SRCS src/lapi.c src/lcode.c src/lctype.c src/ldebug.c src/ldo.c src
set(LUA_LIB_SRCS src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcorolib.c src/ldblib.c src/liolib.c
src/lmathlib.c src/loslib.c src/ltablib.c src/lstrlib.c src/loadlib.c src/linit.c src/lutf8lib.c)
set(LUA_HEADERS include/lua.h include/luaconf.h include/lualib.h include/lauxlib.h)
# LLVM code gen
set(LLVM_JIT_SRCS src/ravi_llvmjit.cpp src/ravi_llvmtypes.cpp
src/ravi_llvmcodegen.cpp src/ravi_llvmforprep.cpp src/ravi_llvmcomp.cpp
src/ravi_llvmreturn.cpp src/ravi_llvmload.cpp src/ravi_llvmforloop.cpp
src/ravi_llvmarith1.cpp src/ravi_llvmcall.cpp src/ravi_llvmtable.cpp
src/ravi_llvmarith2.cpp src/ravi_llvmtforcall.cpp src/ravi_llvmrest.cpp)
set(MIR_HEADERS mir/mir.h mir/mir-gen.h mir/mir-varr.h mir/mir-dlist.h mir/mir-htab.h
mir/mir-hash.h mir/mir-bitmap.h)
set(MIR_SRCS mir/mir.c mir/mir-gen.c)
set(C2MIR_SRCS mir/c2mir/c2mir.c)
# MIR code gen
set(MIR_JIT_SRCS src/ravi_mirjit.c)
set(NO_JIT_SRCS src/ravi_nojit.c)
set(LUA_CMD_SRCS src/lua.c)
@ -71,19 +89,69 @@ if (ASAN)
endif ()
endif ()
if (MIR_JIT)
message(STATUS "MIRJIT enabled")
add_subdirectory(mir)
set(MIRJIT_LIBRARIES c2mir)
set(JIT_SRCS ${MIR_JIT_SRCS})
if (LLVM_JIT)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "LLVM Definitions ${LLVM_DEFINITIONS}")
message(STATUS "LLVMJIT enabled")
set(JIT_SRCS ${LLVM_JIT_SRCS})
if (NOT MSVC)
set_source_files_properties(${LLVM_JIT_SRCS} PROPERTIES
COMPILE_FLAGS "-fno-rtti -fno-exceptions ${LLVM_DEFINITIONS}")
endif ()
set_property(
SOURCE ${LLVM_JIT_SRCS}
APPEND
PROPERTY INCLUDE_DIRECTORIES ${LLVM_INCLUDE_DIRS}
)
# FIXME get rid of this dependency
set_property(
SOURCE ${LUA_CMD_SRCS}
APPEND
PROPERTY INCLUDE_DIRECTORIES ${LLVM_INCLUDE_DIRS})
if ($ENV{CLION_IDE})
# CLion seems unable to handle include paths set on sources
include_directories(${LLVM_INCLUDE_DIRS})
endif ()
else ()
set(JIT_SRCS ${NO_JIT_SRCS})
if (MIR_JIT)
message(STATUS "MIRJIT enabled")
set(JIT_SRCS ${MIR_SRCS} ${C2MIR_SRCS} ${MIR_JIT_SRCS})
set_property(SOURCE ${MIR_SRCS} ${C2MIR_SRCS} ${MIR_JIT_SRCS}
APPEND
PROPERTY INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/mir;${CMAKE_SOURCE_DIR}/mir/c2mir")
set_property(SOURCE ${MIR_SRCS} ${C2MIR_SRCS} ${MIR_JIT_SRCS}
APPEND
PROPERTY COMPILE_DEFINITIONS "MIR_NO_IO=0;MIR_NO_SCAN=1;MIR_NO_INTERP=1")
if ($ENV{CLION_IDE})
# CLion seems unable to handle include paths set on sources
include_directories("${CMAKE_SOURCE_DIR}/mir;${CMAKE_SOURCE_DIR}/mir/c2mir")
endif ()
else ()
set(JIT_SRCS ${NO_JIT_SRCS})
endif ()
endif ()
if (RAVICOMP)
# Need MIR_JIT for the compiler add-on
find_package(RaviComp REQUIRED)
set(ADDON_SRCS ${RAVICOMP_SRCS})
add_subdirectory(ravicomp)
set(RAVICOMP_LIBRARIES ravicomp)
set_property(SOURCE ${RAVICOMP_SRCS}
APPEND
PROPERTY INCLUDE_DIRECTORIES ${RAVICOMP_INCLUDE_DIRS})
if (MIR_JIT)
set_property(SOURCE ${RAVICOMP_SRCS}
APPEND
PROPERTY INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/mir;${CMAKE_SOURCE_DIR}/mir/c2mir")
endif ()
if ($ENV{CLION_IDE})
# CLion seems unable to handle include paths set on sources
include_directories(${RAVICOMP_INCLUDE_DIRS})
endif ()
endif ()
# IDE stuff
@ -104,6 +172,64 @@ elseif (NOT WIN32)
set(EXTRA_LIBRARIES m dl readline)
endif ()
# Enable minimal required LLVM components so that the
# the size of the resulting binary is manageable
if (LLVM_JIT)
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.8")
set(LLVM_EXTRA_LIBS ipa)
endif ()
if (NOT ${LLVM_PACKAGE_VERSION} VERSION_LESS "5.0.0")
set(LLVM_EXTRA_LIBS orcjit)
endif ()
message(STATUS "SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
set(LLVM_LIBS_PROCESSOR
X86CodeGen
X86AsmParser
X86Disassembler
X86Desc
X86Info
X86Utils
)
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "9.0.0")
list(APPEND LLVM_LIBS_PROCESSOR X86AsmPrinter)
endif ()
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
set(LLVM_LIBS_PROCESSOR
ARMCodeGen
ARMAsmParser
ARMDisassembler
ARMAsmPrinter
ARMDesc
ARMInfo
)
endif ()
llvm_map_components_to_libnames(LLVM_LIBS
Analysis
AsmParser
AsmPrinter
BitReader
Core
CodeGen
ExecutionEngine
InstCombine
${LLVM_EXTRA_LIBS}
ipo
MC
MCJIT
MCParser
Object
RuntimeDyld
ScalarOpts
Support
Target
TransformUtils
${LLVM_LIBS_PROCESSOR}
)
message(STATUS "LLVM_LIBS ${LLVM_LIBS}")
endif ()
set(LIBRAVI_NAME libravi)
#Main library
@ -113,7 +239,7 @@ add_library(${LIBRAVI_NAME} ${LIBRAVI_BUILD_TYPE}
${LUA_CORE_SRCS}
${JIT_SRCS}
${ADDON_SRCS})
target_link_libraries(${LIBRAVI_NAME} LINK_PUBLIC ${EXTRA_LIBRARIES} ${MIRJIT_LIBRARIES} ${RAVICOMP_LIBRARIES})
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${MIRJIT_LIBRARIES} ${RAVICOMP_LIBRARIES})
# Main Ravi executable
add_executable(ravi ${LUA_CMD_SRCS})
@ -150,7 +276,13 @@ if (NOT LTESTS)
PROPERTY COMPILE_DEFINITIONS NO_LUA_DEBUG)
set(NO_LUA_DEBUG 1)
endif ()
if (MIR_JIT)
if (LLVM_JIT)
set_property(
TARGET ${LIBRAVI_NAME} ravi
APPEND
PROPERTY COMPILE_DEFINITIONS "USE_LLVM=1")
set(USE_LLVM 1)
elseif (MIR_JIT)
set_property(
TARGET ${LIBRAVI_NAME} ravi
APPEND
@ -188,6 +320,8 @@ elseif (UNIX)
APPEND
PROPERTY COMPILE_DEFINITIONS "LUA_USE_LINUX=1")
endif ()
set_property(TARGET ${LIBRAVI_NAME} PROPERTY CXX_STANDARD 14)
set_property(TARGET ${LIBRAVI_NAME} PROPERTY CXX_EXTENSIONS OFF)
include(GNUInstallDirs)
configure_file(ravi-config.h.in ravi-config.h @ONLY)

@ -1,195 +0,0 @@
Ravi Programming Language
=========================
![image](https://travis-ci.org/dibyendumajumdar/ravi.svg?branch=master%0A%20:target:%20https://travis-ci.org/dibyendumajumdar/ravi)
Ravi is a dialect of [Lua](http://www.lua.org/) with limited optional
static typing and features [MIR](https://github.com/vnmakarov/mir)
powered JIT compilers. The name Ravi comes from the Sanskrit word for
the Sun. Interestingly a precursor to Lua was
[Sol](http://www.lua.org/history.html) which had support for static
types; Sol means the Sun in Portugese.
Lua is perfect as a small embeddable dynamic language so why a
derivative? Ravi extends Lua with static typing for improved performance
when JIT compilation is enabled. However, the static typing is optional
and therefore Lua programs are also valid Ravi programs.
There are other attempts to add static typing to Lua - e.g. [Typed
Lua](https://github.com/andremm/typedlua) but these efforts are mostly
about adding static type checks in the language while leaving the VM
unmodified. The Typed Lua effort is very similar to the approach taken
by Typescript in the JavaScript world. The static typing is to aid
programming in the large - the code is eventually translated to standard
Lua and executed in the unmodified Lua VM.
My motivation is somewhat different - I want to enhance the VM to
support more efficient operations when types are known. Type information
can be exploited by JIT compilation technology to improve performance.
At the same time, I want to keep the language safe and therefore usable
by non-expert programmers.
Of course there is the fantastic [LuaJIT](http://luajit.org)
implementation. Ravi has a different goal compared to LuaJIT. Ravi
prioritizes ease of maintenance and support, language safety, and
compatibility with Lua 5.3, over maximum performance. For more detailed
comparison please refer to the documentation links below.
Features
--------
- Optional static typing - for details [see the reference
manual](https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-reference.html).
- Type specific bytecodes to improve performance
- Compatibility with Lua 5.3 (see Compatibility section below)
- Generational GC from Lua 5.4
- `defer` statement for releasing resources
- Compact JIT backend [MIR](https://github.com/vnmakarov/mir).
- A [distribution with
batteries](https://github.com/dibyendumajumdar/Suravi).
- A [Visual Studio Code debugger
extension](https://marketplace.visualstudio.com/items?itemName=ravilang.ravi-debug)
- interpreted mode debugger.
Documentation
-------------
- For the Lua extensions in Ravi see the [Reference
Manual](https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-reference.html).
- [MIR JIT Build
instructions](https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-mir-instructions.html).
- Also see [Ravi
Documentation](http://the-ravi-programming-language.readthedocs.org/en/latest/index.html).
- and the slides I presented at the [Lua 2015
Workshop](http://www.lua.org/wshop15.html).
Lua Goodies
-----------
- [An Introduction to
Lua](http://the-ravi-programming-language.readthedocs.io/en/latest/lua-introduction.html)
attempts to provide a quick overview of Lua for folks coming from
other languages.
- [Lua 5.3 Bytecode
Reference](http://the-ravi-programming-language.readthedocs.io/en/latest/lua_bytecode_reference.html)
is my attempt to bring up to date the [Lua 5.1 Bytecode
Reference](http://luaforge.net/docman/83/98/ANoFrillsIntroToLua51VMInstructions.pdf).
- A [patch for Lua
5.3](https://github.com/dibyendumajumdar/ravi/blob/master/patches/defer_statement_for_Lua_5_3.patch)
implements the 'defer' statement.
- A [patch for Lua
5.4.[0-2]](https://github.com/dibyendumajumdar/ravi/blob/master/patches/defer_statement_for_Lua_5_4.patch)
implements the 'defer' statement.
- Updated [patch for Lua
5.4.3](https://github.com/dibyendumajumdar/ravi/blob/master/patches/defer_statement_patch_for_Lua_5_4_3.patch)
implements the 'defer' statement.
Lua 5.4 Position Statement
--------------------------
Lua 5.4 relationship to Ravi is as follows:
- Generational GC - back-ported to Ravi.
- New random number generator - back-ported to Ravi.
- Multiple user values can be associated with userdata - under
consideration.
- `<const>` variables - not planned.
- `<close>` variables - Ravi has `'defer'` statement which is the
better option in my opinion, hence no plans to support `<close>`
variables.
- Interpreter performance improvements - these are beneficial to Lua
interpreter but not to the JIT backends, hence not much point in
back-porting.
- Table implementation changes - under consideration.
- String to number coercion is now part of string library metamethods
- back-ported to Ravi.
- utf8 library accepts codepoints up to 2\^31 - back-ported to Ravi.
- Removal of compatibility layers for 5.1, and 5.2 - not implemented
as Ravi continues to provide these layers as per Lua 5.3.
Compatibility with Lua 5.3
--------------------------
Ravi should be able to run all Lua 5.3 programs in interpreted mode, but
following should be noted:
- Ravi supports optional typing and enhanced types such as arrays (see
the documentation). Programs using these features cannot be run by
standard Lua. However all types in Ravi can be passed to Lua
functions; operations on Ravi arrays within Lua code will be subject
to restrictions as described in the section above on arrays.
- Values crossing from Lua to Ravi will be subjected to typechecks
should these values be assigned to typed variables.
- Upvalues cannot subvert the static typing of local variables (issue
\#26) when types are annotated.
- Certain Lua limits are reduced due to changed byte code structure.
These are described below.
- Ravi uses an extended bytecode which means it is not compatible with
Lua 5.x bytecode.
- Ravi incorporates the new Generational GC from Lua 5.4, hence the GC
interface has changed.
Limit name Lua value Ravi value
------------------ -------------- --------------
MAXUPVAL 255 125
LUAI\_MAXCCALLS 200 125
MAXREGS 255 125
MAXVARS 200 125
MAXARGLINE 250 120
When JIT compilation is enabled there are following additional
constraints:
- Ravi will only execute JITed code from the main Lua thread; any
secondary threads (coroutines) execute in interpreter mode.
- In JITed code tailcalls are implemented as regular calls so unlike
the interpreter VM which supports infinite tail recursion JIT
compiled code only supports tail recursion to a depth of about 110
(issue \#17)
- Debug api and hooks are not supported in JIT mode
History
-------
- 2015
: - Implemented JIT compilation using LLVM
- Implemented [libgccjit based alternative
JIT](https://github.com/dibyendumajumdar/ravi/tree/gccjit-ravi534)
(now discontinued)
- 2016
: - Implemented debugger for Ravi and Lua 5.3 for [Visual Studio
Code](https://github.com/dibyendumajumdar/ravi/tree/master/vscode-debugger)
- 2017
: - Embedded C compiler using dmrC project (C JIT compiler) (now
discontinued)
- Additional type-annotations
- 2018
: - Implemented [Eclipse OMR JIT
backend](https://github.com/dibyendumajumdar/ravi/tree/omrjit)
(now discontinued)
- Created [Ravi with
batteries](https://github.com/dibyendumajumdar/Suravi).
- 2019
: - New language feature - defer statement
- New JIT backend [MIR](https://github.com/vnmakarov/mir).
- 2020
: - [New parser / type checker /
compiler](https://github.com/dibyendumajumdar/ravi-compiler)
- Generational GC back-ported from Lua 5.4
- Support for [LLVM
backend](https://github.com/dibyendumajumdar/ravi/tree/llvm)
archived
- 2021 (Plan)
: - Integrated AOT and JIT compilation support
- Ravi 1.0 release
License
-------
MIT License

@ -0,0 +1,127 @@
=========================
Ravi Programming Language
=========================
.. image:: https://travis-ci.org/dibyendumajumdar/ravi.svg?branch=master
:target: https://travis-ci.org/dibyendumajumdar/ravi
Ravi is a dialect of `Lua <http://www.lua.org/>`_ with limited optional static typing and
features `MIR <https://github.com/vnmakarov/mir>`_ and `LLVM <http://www.llvm.org/>`_ powered JIT compilers.
The name Ravi comes from the Sanskrit word for the Sun.
Interestingly a precursor to Lua was `Sol <http://www.lua.org/history.html>`_ which had support for
static types; Sol means the Sun in Portugese.
Lua is perfect as a small embeddable dynamic language so why a derivative? Ravi extends Lua with
static typing for improved performance when JIT compilation is enabled. However, the static typing is
optional and therefore Lua programs are also valid Ravi programs.
There are other attempts to add static typing to Lua - e.g. `Typed Lua <https://github.com/andremm/typedlua>`_ but
these efforts are mostly about adding static type checks in the language while leaving the VM unmodified.
The Typed Lua effort is very similar to the approach taken by Typescript in the JavaScript world.
The static typing is to aid programming in the large - the code is eventually translated to standard Lua
and executed in the unmodified Lua VM.
My motivation is somewhat different - I want to enhance the VM to support more efficient operations when types are
known. Type information can be exploited by JIT compilation technology to improve performance. At the same time,
I want to keep the language safe and therefore usable by non-expert programmers.
Of course there is the fantastic `LuaJIT <http://luajit.org>`_ implementation. Ravi has a different goal compared to
LuaJIT. Ravi prioritizes ease of maintenance and support, language safety, and compatibility with Lua 5.3,
over maximum performance. For more detailed comparison please refer to the documentation links below.
Features
========
* Optional static typing - for details `see the reference manual <https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-reference.html>`_.
* Type specific bytecodes to improve performance
* Compatibility with Lua 5.3 (see Compatibility section below)
* Generational GC from Lua 5.4
* ``defer`` statement for releasing resources
* Compact JIT backend `MIR <https://github.com/vnmakarov/mir>`_; only Linux and x86-64 supported for now.
* `LLVM <http://www.llvm.org/>`_ supported as alternative JIT backend.
* A `distribution with batteries <https://github.com/dibyendumajumdar/Suravi>`_.
* A `Visual Studio Code debugger extension <https://marketplace.visualstudio.com/items?itemName=ravilang.ravi-debug>`_ - interpreted mode debugger.
Documentation
=============
* For the Lua extensions in Ravi see the `Reference Manual <https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-reference.html>`_.
* `MIR JIT Build instructions <https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-mir-instructions.html>`_.
* `LLVM JIT Build instructions <https://the-ravi-programming-language.readthedocs.io/en/latest/ravi-llvm-instructions.html>`_.
* Also see `Ravi Documentation <http://the-ravi-programming-language.readthedocs.org/en/latest/index.html>`_.
* and the slides I presented at the `Lua 2015 Workshop <http://www.lua.org/wshop15.html>`_.
Lua Goodies
===========
* `An Introduction to Lua <http://the-ravi-programming-language.readthedocs.io/en/latest/lua-introduction.html>`_ attempts to provide a quick overview of Lua for folks coming from other languages.
* `Lua 5.3 Bytecode Reference <http://the-ravi-programming-language.readthedocs.io/en/latest/lua_bytecode_reference.html>`_ is my attempt to bring up to date the `Lua 5.1 Bytecode Reference <http://luaforge.net/docman/83/98/ANoFrillsIntroToLua51VMInstructions.pdf>`_.
* A `patch for Lua 5.3 <https://github.com/dibyendumajumdar/ravi/blob/master/patches/defer_statement_for_Lua_5_3.patch>`_ implements the 'defer' statement.
* A `patch for Lua 5.4 <https://github.com/dibyendumajumdar/ravi/blob/master/patches/defer_statement_for_Lua_5_4.patch>`_ implements the 'defer' statement.
Lua 5.4 Position Statement
==========================
Lua 5.4 relationship to Ravi is as follows:
* Generational GC - back-ported to Ravi.
* New random number generator - back-ported to Ravi.
* Multiple user values can be associated with userdata - under consideration.
* ``<const>`` variables - not planned.
* ``<close>`` variables - Ravi has ``'defer'`` statement which is the better option in my opinion, hence no plans to support ``<close>`` variables.
* Interpreter performance improvements - these are beneficial to Lua interpreter but not to the JIT backends, hence not much point in back-porting.
* Table implementation changes - under consideration.
* String to number coercion is now part of string library metamethods - back-ported to Ravi.
* utf8 library accepts codepoints up to 2^31 - back-ported to Ravi.
* Removal of compatibility layers for 5.1, and 5.2 - not implemented as Ravi continues to provide these layers as per Lua 5.3.
Compatibility with Lua 5.3
==========================
Ravi should be able to run all Lua 5.3 programs in interpreted mode, but following should be noted:
* Ravi supports optional typing and enhanced types such as arrays (see the documentation). Programs using these features cannot be run by standard Lua. However all types in Ravi can be passed to Lua functions; operations on Ravi arrays within Lua code will be subject to restrictions as described in the section above on arrays.
* Values crossing from Lua to Ravi will be subjected to typechecks should these values be assigned to typed variables.
* Upvalues cannot subvert the static typing of local variables (issue #26) when types are annotated.
* Certain Lua limits are reduced due to changed byte code structure. These are described below.
* Ravi uses an extended bytecode which means it is not compatible with Lua 5.x bytecode.
* Ravi incorporates the new Generational GC from Lua 5.4, hence the GC interface has changed.
+-----------------+-------------+-------------+
| Limit name | Lua value | Ravi value |
+=================+=============+=============+
| MAXUPVAL | 255 | 125 |
+-----------------+-------------+-------------+
| LUAI_MAXCCALLS | 200 | 125 |
+-----------------+-------------+-------------+
| MAXREGS | 255 | 125 |
+-----------------+-------------+-------------+
| MAXVARS | 200 | 125 |
+-----------------+-------------+-------------+
| MAXARGLINE | 250 | 120 |
+-----------------+-------------+-------------+
When JIT compilation is enabled there are following additional constraints:
* Ravi will only execute JITed code from the main Lua thread; any secondary threads (coroutines) execute in interpreter mode.
* In JITed code tailcalls are implemented as regular calls so unlike the interpreter VM which supports infinite tail recursion JIT compiled code only supports tail recursion to a depth of about 110 (issue #17)
History
=======
* 2015
- Implemented JIT compilation using LLVM
- Implemented `libgccjit based alternative JIT <https://github.com/dibyendumajumdar/ravi/tree/gccjit-ravi534>`_ (now discontinued)
* 2016
- Implemented debugger for Ravi and Lua 5.3 for `Visual Studio Code <https://github.com/dibyendumajumdar/ravi/tree/master/vscode-debugger>`_
* 2017
- Embedded C compiler using dmrC project (C JIT compiler) (now discontinued)
- Additional type-annotations
* 2018
- Implemented `Eclipse OMR JIT backend <https://github.com/dibyendumajumdar/ravi/tree/omrjit>`_ (now discontinued)
- Created `Ravi with batteries <https://github.com/dibyendumajumdar/Suravi>`_.
* 2019
- New language feature - `defer` statement
- New JIT backend `MIR <https://github.com/vnmakarov/mir>`_.
* 2020 (Plan)
- `New optimizing byte code generator based on new parser / type checker <https://github.com/dibyendumajumdar/ravi-compiler>`_
- Generational GC back-ported from Lua 5.4
- Ravi 1.0 release
License
=======
MIT License

@ -5,4 +5,4 @@ The scripts here are unsupported - these are just my personal
build scripts.
The debug builds enable 'ltests' and address sanitizer.
The unix LLVM debug builds enable 'ltests' and address sanitizer.

@ -0,0 +1,16 @@
# Run this on LLVM 10 source dir
mkdir build
cd build
cmake3 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/Software/llvm10 \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_BUILD_TOOLS=OFF \
-DLLVM_INCLUDE_TOOLS=OFF \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_BUILD_TESTS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
..
make install

@ -0,0 +1,5 @@
mkdir llvm32
cd llvm32
rem cmake -DCMAKE_INSTALL_PREFIX=\d\ravi32 -G "Visual Studio 14" -DLLVM_JIT=ON -DLLVM_DIR=\d\LLVM37_32\share\llvm\cmake -DBUILD_STATIC=OFF ..
cmake -DCMAKE_INSTALL_PREFIX=\d\ravi32 -G "Visual Studio 14" -DLLVM_JIT=ON -DLLVM_DIR=\d\LLVM39_32\lib\cmake\llvm -DSTATIC_BUILD=OFF ..
cd ..

@ -0,0 +1,5 @@
mkdir llvm32
cd llvm32
rem cmake -DCMAKE_INSTALL_PREFIX=\d\ravi32 -G "Visual Studio 14" -DLLVM_JIT=ON -DLLVM_DIR=\d\LLVM37_32\share\llvm\cmake ..
cmake -DCMAKE_INSTALL_PREFIX=\d\ravi32 -G "Visual Studio 14" -DLLVM_JIT=ON -DLLVM_DIR=\d\LLVM39\lib\cmake\llvm -DSTATIC_BUILD=ON ..
cd ..

@ -0,0 +1,5 @@
mkdir llvm32d
cd llvm32d
rem cmake -DCMAKE_INSTALL_PREFIX=\d\ravi32 -G "Visual Studio 14" -DLLVM_JIT=ON -DLLVM_DIR=\d\LLVM37_32\share\llvm\cmake ..
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=\d\ravi32 -G "Visual Studio 14" -DLLVM_JIT=ON -DLLVM_DIR=\d\LLVM39D_32\lib\cmake\llvm -DSTATIC_BUILD=ON ..
cd ..

@ -0,0 +1,6 @@
mkdir llvm64d
cd llvm64d
rem cmake -DCMAKE_INSTALL_PREFIX=c:\ravi64llvmd -G "Visual Studio 14 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\LLVM37debug\share\llvm\cmake ..
rem cmake -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=c:\d\ravi64llvmd -G "Visual Studio 15 2017 Win64" -DLLVM_JIT=ON -DEMBEDDED_DMRC=ON -DLLVM_DIR=c:\d\LLVM39D64\lib\cmake\llvm ..
cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DLLVM_JIT=ON -DLLVM_DIR=c:\Software\llvm501d\lib\cmake\llvm ..
cd ..

@ -0,0 +1,7 @@
mkdir llvm64
cd llvm64
rem pre LLVM 3.9
rem cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -G "Visual Studio 14 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\LLVM37\share\llvm\cmake ..
rem cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -G "Visual Studio 15 2017 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\d\LLVM40_64\lib\cmake\llvm ..
cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 15 2017 Win64" -DSTATIC_BUILD=ON -DLLVM_JIT=ON -DLLVM_DIR=c:\Software\llvm601r\lib\cmake\llvm ..
cd ..

@ -0,0 +1,5 @@
rmdir /s llvm8
mkdir llvm8
cd llvm8
cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release -DLLVM_JIT=ON -DLLVM_DIR=c:\Software\llvm801\lib\cmake\llvm ..
cd ..

@ -0,0 +1,5 @@
rmdir /s llvm10d
mkdir llvm10d
cd llvm10d
cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 16 2019" -DLLVM_JIT=ON -DLLVM_DIR=c:\Software\llvm10d\lib\cmake\llvm ..
cd ..

@ -0,0 +1,6 @@
rmdir /s llvm9r
mkdir llvm9r
cd llvm9r
rem cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 15 2017 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\Software\llvm900r\lib\cmake\llvm ..
cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 16 2019" -DLLVM_JIT=ON -DLLVM_DIR=c:\Software\llvm900r\lib\cmake\llvm ..
cd ..

@ -0,0 +1,4 @@
mkdir omrjit
cd omrjit
cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DOMR_JIT=ON ..
cd ..

@ -0,0 +1,4 @@
mkdir xcodellvm
cd xcodellvm
#cmake -DCMAKE_BUILD_TYPE=Debug -G Xcode -DLLVM_JIT=ON -DCMAKE_INSTALL_PREFIX=$HOME/ravi -DLLVM_DIR=$HOME/LLVM/share/llvm/cmake ..
cmake -DCMAKE_BUILD_TYPE=Debug -G Xcode -DLLVM_JIT=ON -DCMAKE_INSTALL_PREFIX=$HOME/ravi -DLLVM_DIR=$HOME/LLVM5/lib/cmake/llvm ..

@ -0,0 +1,5 @@
mkdir buildllvmd
cd buildllvmd
#cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_JIT=ON -DCMAKE_INSTALL_PREFIX=$HOME/ravi -DLLVM_DIR=$HOME/LLVM/share/llvm/cmake ..
#cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_JIT=ON -DLTESTS=ON -DCMAKE_INSTALL_PREFIX=$HOME/ravi -DLLVM_DIR=$HOME/LLVM5/lib/cmake/llvm ..
cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_JIT=ON -DLTESTS=ON -DCMAKE_INSTALL_PREFIX=$HOME/ravillvm -DLLVM_DIR=$HOME/Software/llvm600/lib/cmake/llvm ..

@ -0,0 +1,7 @@
rm -rf buildllvm
mkdir buildllvm
cd buildllvm
#cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_JIT=ON -DCMAKE_INSTALL_PREFIX=$HOME/ravi -DLLVM_DIR=$HOME/LLVM/share/llvm/cmake ..
#cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_JIT=ON -DCMAKE_INSTALL_PREFIX=$HOME/ravi -DLLVM_DIR=$HOME/LLVM5/lib/cmake/llvm ..
#cmake -DCMAKE_BUILD_TYPE=Release -DSTATIC_BUILD=ON -DLLVM_JIT=ON -DCMAKE_INSTALL_PREFIX=$HOME/Software/ravi -DLLVM_DIR=$HOME/Software/llvm801/lib/cmake/llvm ..
cmake3 -DCMAKE_BUILD_TYPE=Release -DSTATIC_BUILD=ON -DLLVM_JIT=ON -DCMAKE_INSTALL_PREFIX=$HOME/Software/ravi -DLLVM_DIR=$HOME/Software/llvm10/lib/cmake/llvm ..

@ -0,0 +1,3 @@
mkdir omrjit
cd omrjit
cmake -DCMAKE_BUILD_TYPE=Release -DOMR_JIT=ON -DCMAKE_INSTALL_PREFIX=$HOME/ravi ..

@ -0,0 +1,15 @@
find_path(RAVICOMP_INCLUDE_DIRS ravi_compiler.h
PATHS
c:/Software/ravicomp/include/ravicomp
~/Software/ravicomp/include/ravicomp
NO_DEFAULT_PATH
)
find_library(RAVICOMP_LIBRARIES
NAMES ravicomp
PATHS
c:/Software/ravicomp/lib
~/Software/ravicomp/lib
~/Software/ravicomp/lib64
)

@ -12,15 +12,20 @@ RUN set -x \
&& cd /Software \
&& tar xvf "cmake-3.14.5-Linux-x86_64.tar.gz" \
&& rm -rf "/Software/cmake-3.14.5-Linux-x86_64.tar.gz" \
&& wget -O "/Software/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz" "http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz" \
&& cd /Software \
&& tar xvf "clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz" \
&& rm -rf "/Software/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz" \
&& mkdir -p /sources \
&& cd /sources \
&& git clone https://github.com/dibyendumajumdar/ravi.git \
&& cd /sources/ravi \
&& mkdir build \
&& cd build \
&& /Software/cmake-3.14.5-Linux-x86_64/bin/cmake -DCMAKE_INSTALL_PREFIX=/Software/ravi -DCMAKE_BUILD_TYPE=Release .. \
&& /Software/cmake-3.14.5-Linux-x86_64/bin/cmake -DSTATIC_BUILD=ON -DCMAKE_INSTALL_PREFIX=/Software/ravi -DLLVM_JIT=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_DIR=/Software/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/cmake/llvm .. \
&& make install \
&& rm -rf /Software/cmake-3.14.5-Linux-x86_64 \
&& rm -rf /Software/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04 \
&& rm -rf /sources \
&& apt-get autoremove \
&& apt-get remove -y --purge git wget build-essential \

@ -32,6 +32,7 @@
#define upisopen(up) ((up)->v != &(up)->u.value)
#ifdef RAVI_DEFER_STATEMENT
/*
** Special "status" for 'luaF_close'
*/
@ -41,17 +42,22 @@
/* close upvalues running all closing methods in protected mode */
#define CLOSEPROTECT (-2)
#endif
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);
LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);
LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
#ifdef RAVI_DEFER_STATEMENT
LUAI_FUNC int luaF_close (lua_State *L, StkId level, int status);
#else
LUAI_FUNC void luaF_close (lua_State *L, StkId level);
#endif
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
/* The additional type argument is a Ravi extension */
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
int pc, ravi_type_map* type, TString **usertype);
int pc, ravitype_t* type);
#endif

@ -12,16 +12,16 @@
#include "lstate.h"
/*
** Collectable objects may have one of three colors: white, which means
** the object is not marked; gray, which means the object is marked, but
** its references may be not marked; and black, which means that the
** object and all its references are marked. The main invariant of the
** garbage collector, while marking objects, is that a black object can
** never point to a white one. Moreover, any gray object must be in a
** "gray list" (gray, grayagain, weak, allweak, ephemeron) so that it
** can be visited again before finishing the collection cycle. (Open
** upvalues are an exception to this rule.) These lists have no meaning
** when the invariant is not being enforced (e.g., sweep phase).
** Collectable objects may have one of three colors: white, which
** means the object is not marked; gray, which means the
** object is marked, but its references may be not marked; and
** black, which means that the object and all its references are marked.
** The main invariant of the garbage collector, while marking objects,
** is that a black object can never point to a white one. Moreover,
** any gray object must be in a "gray list" (gray, grayagain, weak,
** allweak, ephemeron) so that it can be visited again before finishing
** the collection cycle. These lists have no meaning when the invariant
** is not being enforced (e.g., sweep phase).
*/
@ -69,16 +69,14 @@
/*
** Layout for bit use in 'marked' field. First three bits are
** used for object "age" in generational mode. Last bit is used
** by tests.
** used for object "age" in generational mode. Last bit is free
** to be used by respective objects.
*/
#define WHITE0BIT 3 /* object is white (type 0) */
#define WHITE1BIT 4 /* object is white (type 1) */
#define BLACKBIT 5 /* object is black */
#define FINALIZEDBIT 6 /* object has been marked for finalization */
#define TESTBIT 7
#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
@ -96,8 +94,7 @@
#define isdead(g,v) isdeadm(otherwhite(g), (v)->marked)
#define changewhite(x) ((x)->marked ^= WHITEBITS)
#define nw2black(x) \
check_exp(!iswhite(x), l_setbit((x)->marked, BLACKBIT))
#define gray2black(x) l_setbit((x)->marked, BLACKBIT)
#define luaC_white(g) cast_byte((g)->currentwhite & WHITEBITS)
@ -187,6 +184,7 @@ LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);
LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);
LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o);
LUAI_FUNC void luaC_upvalbarrier_(lua_State* L, GCObject* o);
LUAI_FUNC void luaC_upvalbarrier_compat(lua_State* L, UpVal* uv);
LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);
LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv);
LUAI_FUNC void luaC_changemode (lua_State *L, int newmode);

@ -27,7 +27,11 @@ enum RESERVED {
/* terminal symbols denoted by reserved words */
TK_AND = FIRST_RESERVED, TK_BREAK,
TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
#ifdef RAVI_DEFER_STATEMENT
TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_DEFER, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
#else
TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
#endif
TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
/* other terminal symbols */
TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,

@ -54,66 +54,18 @@ typedef uint16_t LuaType;
** we care about from a performance point of view - if any
** other types appear then they are all treated as ANY
**/
typedef enum {
RAVI_TI_NIL,
RAVI_TI_FALSE,
RAVI_TI_TRUE,
RAVI_TI_INTEGER,
RAVI_TI_FLOAT,
RAVI_TI_INTEGER_ARRAY,
RAVI_TI_FLOAT_ARRAY,
RAVI_TI_TABLE,
RAVI_TI_STRING,
RAVI_TI_FUNCTION,
RAVI_TI_USERDATA,
RAVI_TI_OTHER
} ravi_type_index;
typedef uint32_t ravi_type_map;
#define RAVI_TM_NIL (((ravi_type_map)1)<<RAVI_TI_NIL)
#define RAVI_TM_FALSE (((ravi_type_map)1)<<RAVI_TI_FALSE)
#define RAVI_TM_TRUE (((ravi_type_map)1)<<RAVI_TI_TRUE)
#define RAVI_TM_INTEGER (((ravi_type_map)1)<<RAVI_TI_INTEGER)
#define RAVI_TM_FLOAT (((ravi_type_map)1)<<RAVI_TI_FLOAT)
#define RAVI_TM_INTEGER_ARRAY (((ravi_type_map)1)<<RAVI_TI_INTEGER_ARRAY)
#define RAVI_TM_FLOAT_ARRAY (((ravi_type_map)1)<<RAVI_TI_FLOAT_ARRAY)
#define RAVI_TM_TABLE (((ravi_type_map)1)<<RAVI_TI_TABLE)
#define RAVI_TM_STRING (((ravi_type_map)1)<<RAVI_TI_STRING)
#define RAVI_TM_FUNCTION (((ravi_type_map)1)<<RAVI_TI_FUNCTION)
#define RAVI_TM_USERDATA (((ravi_type_map)1)<<RAVI_TI_USERDATA)
#define RAVI_TM_OTHER (((ravi_type_map)1)<<RAVI_TI_OTHER)
#define RAVI_TM_FALSISH (RAVI_TM_NIL | RAVI_TM_FALSE)
#define RAVI_TM_TRUISH (~RAVI_TM_FALSISH)
#define RAVI_TM_BOOLEAN (RAVI_TM_FALSE | RAVI_TM_TRUE)
#define RAVI_TM_NUMBER (RAVI_TM_INTEGER | RAVI_TM_FLOAT)
#define RAVI_TM_STRING_OR_NIL (RAVI_TM_STRING | RAVI_TM_NIL)
#define RAVI_TM_FUNCTION_OR_NIL (RAVI_TM_FUNCTION | RAVI_TM_NIL)
#define RAVI_TM_BOOLEAN_OR_NIL (RAVI_TM_BOOLEAN | RAVI_TM_NIL)
#define RAVI_TM_USERDATA_OR_NIL (RAVI_TM_USERDATA | RAVI_TM_NIL)
#define RAVI_TM_INTEGER_OR_NIL (RAVI_TM_INTEGER | RAVI_TM_NIL)
#define RAVI_TM_FLOAT_OR_NIL (RAVI_TM_FLOAT | RAVI_TM_NIL)
#define RAVI_TM_TABLE_OR_NIL (RAVI_TM_TABLE | RAVI_TM_NIL)
#define RAVI_TM_INDEXABLE (RAVI_TM_INTEGER_ARRAY | RAVI_TM_FLOAT_ARRAY | RAVI_TM_TABLE)
#define RAVI_TM_ANY (~0)
typedef enum {
RAVI_TNIL = RAVI_TM_NIL, /* NIL */
RAVI_TNUMINT = RAVI_TM_INTEGER, /* integer number */
RAVI_TNUMFLT = RAVI_TM_FLOAT, /* floating point number */
RAVI_TNUMBER = RAVI_TM_NUMBER,
RAVI_TARRAYINT = RAVI_TM_INTEGER_ARRAY, /* array of ints */
RAVI_TARRAYFLT = RAVI_TM_FLOAT_ARRAY, /* array of doubles */
RAVI_TTABLE = RAVI_TM_TABLE, /* Lua table */
RAVI_TSTRING = RAVI_TM_STRING, /* string */
RAVI_TFUNCTION = RAVI_TM_FUNCTION, /* Lua or C Function */
RAVI_TBOOLEAN = RAVI_TM_BOOLEAN, /* boolean */
RAVI_TTRUE = RAVI_TM_TRUE,
RAVI_TFALSE = RAVI_TM_FALSE,
RAVI_TUSERDATA = RAVI_TM_USERDATA, /* userdata or lightuserdata */
RAVI_TANY = RAVI_TM_ANY, /* Lua dynamic type */
RAVI_TANY = 0, /* Lua dynamic type */
RAVI_TNUMINT = 1, /* integer number */
RAVI_TNUMFLT, /* floating point number */
RAVI_TARRAYINT, /* array of ints */
RAVI_TARRAYFLT, /* array of doubles */
RAVI_TFUNCTION, /* Lua or C Function */
RAVI_TTABLE, /* Lua table */
RAVI_TSTRING, /* string */
RAVI_TNIL, /* NIL */
RAVI_TBOOLEAN, /* boolean */
RAVI_TUSERDATA /* userdata or lightuserdata */
} ravitype_t;
/*
@ -480,7 +432,7 @@ typedef union UUdata {
typedef struct Upvaldesc {
TString *name; /* upvalue name (for debug information) */
TString *usertype; /* RAVI extension: name of user type */
ravi_type_map ravi_type_map; /* RAVI type of upvalue */
lu_byte ravi_type; /* RAVI type of upvalue */
lu_byte instack; /* whether it is in stack (register) */
lu_byte idx; /* index of upvalue (in stack or in outer function's list) */
} Upvaldesc;
@ -495,7 +447,7 @@ typedef struct LocVar {
TString *usertype; /* RAVI extension: name of user type */
int startpc; /* first point where variable is active */
int endpc; /* first point where variable is dead */
ravi_type_map ravi_type_map; /* RAVI type of the variable - RAVI_TANY if unknown */
lu_byte ravi_type; /* RAVI type of the variable - RAVI_TANY if unknown */
} LocVar;
/** RAVI changes start */
@ -648,8 +600,12 @@ typedef struct Proto {
typedef struct UpVal {
TValue *v; /* points to stack or to its own value */
#ifdef RAVI_DEFER_STATEMENT
unsigned int refcount; /* reference counter */
unsigned int flags; /* Used to mark deferred values */
#else
lu_mem refcount; /* reference counter */
#endif
union {
struct { /* (when open) */
struct UpVal *next; /* linked list */
@ -838,10 +794,6 @@ typedef struct RaviArray {
struct Table *metatable;
} RaviArray;
#define getsliceunderlying(L,s,o) \
{ TValue *io=(o); const RaviArray *is = (s); \
io->value_.gc = obj2gco(is->parent); settt_(io, ctb(is->parent->tt)); \
checkliveness(L,io); }
/*
** 'module' operation for hashing (size is always a power of 2)
@ -879,8 +831,5 @@ LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t srclen);
LUAI_FUNC int ravi_checktype(lua_State *L, StkId input, ravi_type_map type, TString* usertype);
#endif

@ -219,23 +219,13 @@ OP_RAVI_DIVII, /* A B C R(A) := RK(B) / RK(C) */
OP_RAVI_TOINT, /* A R(A) := toint(R(A)) */
OP_RAVI_TOFLT, /* A R(A) := tofloat(R(A)) */
OP_RAVI_TOIARRAY, /* A R(A) := to_arrayi(R(A)) */
OP_RAVI_TOFARRAY, /* A R(A) := to_arrayf(R(A)) */
OP_RAVI_TOTAB, /* A R(A) := to_table(R(A)) */
OP_RAVI_TOSTRING, /* A R(A) := assert_string(R(A)) */
OP_RAVI_TOBOOLEAN, /* A R(A) := assert_string(R(A)) */
OP_RAVI_TOCLOSURE, /* A R(A) := assert_closure(R(A)) */
OP_RAVI_TOTYPE, /* A R(A) := assert_usertype(R(A)), where usertype has metatable in Lua registry */
OP_RAVI_TOINT_NIL, /* A R(A) := toint(R(A)) */
OP_RAVI_TOFLT_NIL, /* A R(A) := tofloat(R(A)) */
OP_RAVI_TOTAB_NIL, /* A R(A) := to_table(R(A)) */
OP_RAVI_TOSTRING_NIL, /* A R(A) := assert_string(R(A)) */
OP_RAVI_TOBOOLEAN_NIL, /* A R(A) := assert_string(R(A)) */
OP_RAVI_TOCLOSURE_NIL, /* A R(A) := assert_closure(R(A)) */
OP_RAVI_TOTYPE_NIL, /* A R(A) := assert_usertype(R(A)), where usertype has metatable in Lua registry */
OP_RAVI_TOIARRAY, /* A R(A) := to_arrayi(R(A)) */
OP_RAVI_TOFARRAY, /* A R(A) := to_arrayf(R(A)) */
OP_RAVI_MOVEI, /* A B R(A) := R(B), check R(B) is int */
OP_RAVI_MOVEF, /* A B R(A) := R(B), check R(B) is float */
OP_RAVI_MOVEIARRAY, /* A B R(A) := R(B), check R(B) is array of int */
@ -290,10 +280,16 @@ OP_RAVI_GETFIELD, /* A B C R(A) := R(B)[RK(C)], string key */
OP_RAVI_SELF_SK, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key */
OP_RAVI_SETFIELD, /* A B C R(A)[RK(B)] := RK(C), string key */
OP_RAVI_GETTABUP_SK, /* A B C R(A) := UpValue[B][RK(C)], string key */
#ifdef RAVI_DEFER_STATEMENT
OP_RAVI_DEFER, /* A mark variable A "deferred" */
#endif
} OpCode;
#ifdef RAVI_DEFER_STATEMENT
#define NUM_OPCODES (cast(int, OP_RAVI_DEFER) + 1)
#else
#define NUM_OPCODES (cast(int, OP_RAVI_GETTABUP_SK) + 1)
#endif
/*===========================================================================
Notes:

@ -66,15 +66,13 @@ typedef struct expdesc {
short idx; /* index (R/K) */
lu_byte t; /* table (register or upvalue) */
lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
ravi_type_map key_ravi_type_map; /* Map of possible types the key could have */
// lu_byte key_ravi_type; /* RAVI change: key type */
lu_byte key_ravi_type; /* RAVI change: key type */
TString *usertype; /* RAVI change: usertype name */
} ind;
} u;
int t; /* patch list of 'exit when true' */
int f; /* patch list of 'exit when false' */
ravi_type_map ravi_type_map; /* Map of possible types this expression could have */
// lu_byte ravi_type; /* RAVI change: type of the expression if known, else RAVI_TANY */
lu_byte ravi_type; /* RAVI change: type of the expression if known, else RAVI_TANY */
TString *usertype; /* RAVI change: usertype name */
int pc; /* RAVI change: holds the program counter for OP_NEWTABLE instruction when a constructor expression is parsed */
} expdesc;
@ -243,9 +241,7 @@ LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
Dyndata *dyd, const char *name, int firstchar);
/** RAVI extensions **/
#define RAVI_TYPEMAP_MAX_LEN (sizeof("nil|boolean|integer|number|integer[]|number[]|table|string|function|userdata|?|"))
LUAI_FUNC void raviY_typemap_string(ravi_type_map tm, char* buf);
LUAI_FUNC const char *raviY_typename(ravitype_t tt);
/* Special printf that recognises following conversions:
* %e - expdesc *
@ -263,7 +259,7 @@ LUAI_FUNC void raviY_printf(FuncState *fs, const char *format, ...);
* Else RAVI_TANY is returned. Note that this function only looks
* at active local variables - see note on FuncState on what this means.
*/
LUAI_FUNC ravi_type_map raviY_get_register_typeinfo(FuncState *fs, int reg, TString **);
LUAI_FUNC ravitype_t raviY_get_register_typeinfo(FuncState *fs, int reg, TString **);
#define DEBUG_EXPR(p) \
if ((ravi_parser_debug & 1) != 0) { \

@ -15,6 +15,7 @@
#include "lopcodes.h"
/*
** Some notes about garbage-collected objects: All objects in Lua must
** be kept somehow accessible until being freed, so all objects always
** belong to one (and only one) of these lists, using field 'next' of
@ -32,29 +33,13 @@
**
** 'allgc' -> 'survival': new objects;
** 'survival' -> 'old': objects that survived one collection;
** 'old1' -> 'reallyold': objects that became old in last collection;
** 'old' -> 'reallyold': objects that became old in last collection;
** 'reallyold' -> NULL: objects old for more than one cycle.
**
** 'finobj' -> 'finobjsur': new objects marked for finalization;
** 'finobjsur' -> 'finobjold1': survived """";
** 'finobjold1' -> 'finobjrold': just old """";
** 'finobjsur' -> 'finobjold': survived """";
** 'finobjold' -> 'finobjrold': just old """";
** 'finobjrold' -> NULL: really old """".
**
** All lists can contain elements older than their main ages, due
** to 'luaC_checkfinalizer' and 'udata2finalize', which move
** objects between the normal lists and the "marked for finalization"
** lists. Moreover, barriers can age young objects in young lists as
** OLD0, which then become OLD1. However, a list never contains
** elements younger than their main ages.
**
** The generational collector also uses a pointer 'firstold1', which
** points to the first OLD1 object in the list. It is used to optimize
** 'markold'. (Potentially OLD1 objects can be anywhere between 'allgc'
** and 'reallyold', but often the list has no OLD1 objects or they are
** after 'old1'.) Note the difference between it and 'old1':
** 'firstold1': no OLD1 objects before this point; there can be all
** ages after it.
** 'old1': no objects younger than OLD1 after this point.
*/
/*
@ -63,7 +48,7 @@
** can become gray have such a field. The field is not the same
** in all objects, but it always has this name.) Any gray object
** must belong to one of these lists, and all objects in these lists
** must be gray (with two exceptions explained below):
** must be gray:
**
** 'gray': regular gray objects, still waiting to be visited.
** 'grayagain': objects that must be revisited at the atomic phase.
@ -74,17 +59,9 @@
** 'weak': tables with weak values to be cleared;
** 'ephemeron': ephemeron tables with white->white entries;
** 'allweak': tables with weak keys and/or weak values to be cleared.
**
** The exceptions to that "gray rule" are:
** - TOUCHED2 objects in generational mode stay in a gray list (because
** they must be visited again at the end of the cycle), but they are
** marked black because assignments to them must activate barriers (to
** move them back to TOUCHED1).
** - Open upvales are kept gray to avoid barriers, but they stay out
** of gray lists. (They don't even have a 'gclist' field.)
*/
*/
struct lua_longjmp; /* defined in ldo.c */
@ -106,8 +83,6 @@ struct lua_longjmp; /* defined in ldo.c */
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
#define stacksize(th) cast_int((th)->stack_last - (th)->stack)
/* kinds of Garbage Collection */
#define KGC_INC 0 /* incremental gc */
@ -214,11 +189,10 @@ typedef struct global_State {
GCObject *fixedgc; /* list of objects not to be collected */
/* fields for generational collector */
GCObject *survival; /* start of objects that survived one GC cycle */
GCObject *old1; /* start of old1 objects */
GCObject *reallyold; /* objects more than one cycle old ("really old") */
GCObject *firstold1; /* first OLD1 object in the list (if any) */
GCObject *old; /* start of old objects */
GCObject *reallyold; /* old objects with more than one cycle */
GCObject *finobjsur; /* list of survival objects with finalizers */
GCObject *finobjold1; /* list of old1 objects with finalizers */
GCObject *finobjold; /* list of old objects with finalizers */
GCObject *finobjrold; /* list of really old objects with finalizers */
struct lua_State *twups; /* list of threads with open upvalues */
lua_CFunction panic; /* to be called in unprotected errors */

@ -124,7 +124,7 @@ LUAI_FUNC lua_Unsigned luaH_getn (Table *t);
/* Creates a specialized version of Lua Table to support Ravi's
* integer[] and number[] arrays.
*/
LUAI_FUNC RaviArray *raviH_new(lua_State *L, ravi_type_map array_type, int is_slice);
LUAI_FUNC RaviArray *raviH_new(lua_State *L, ravitype_t array_type, int is_slice);
LUAI_FUNC void raviH_free(lua_State* L, RaviArray* t);
LUAI_FUNC int raviH_next(lua_State* L, RaviArray* t, StkId key);

@ -226,7 +226,10 @@ extern const char lua_ident[];
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
#ifdef RAVI_DEFER_STATEMENT
LUA_API int (lua_resetthread) (lua_State *L);
#endif
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API const lua_Number *(lua_version) (lua_State *L);
@ -363,14 +366,11 @@ LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
lua_KContext ctx, lua_KFunction k);
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
/* A Lua Closure must be on top of the stack. This will set _ENV upvalue */
LUA_API void (ravi_closure_setenv) (lua_State* L);
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname, const char *mode);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
LUA_API void (raviV_raise_error) (lua_State *L, int errorcode);
/*
** coroutine functions

@ -281,17 +281,14 @@
** give a warning about it. To avoid these warnings, change to the
** default definition.
*/
#if 0
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__) /* { */
#define LUAI_FUNC __attribute__((visibility("internal"))) extern
#else /* }{ */
#define LUAI_FUNC extern
#endif /* } */
#endif
#define LUAI_FUNC LUA_API /* AOT code needs to access symbols */
#define LUAI_DDEC extern
#define LUAI_DDEC LUAI_FUNC
#define LUAI_DDEF /* empty */
/* }================================================================== */
@ -852,6 +849,12 @@
/* Following cause the first hash lookup to be inlined,
and if value is 2 then the second hash lookup is also inlined. */
#define RAVI_USE_INLINE_SHORTSTR_TGET 1
#define RAVI_USE_LLVM_BRANCH_WEIGHTS 1
/* If following is defined as true then LLVM instructions emitted for arithmetic ops
priority floating point ops, else default is to prioritise integer ops */
#define RAVI_USE_LLVM_ARITH_FLOATPRIORITY 1
/* Enables the 'defer' statement - RAVI extension */
#define RAVI_DEFER_STATEMENT
#endif

@ -20,7 +20,7 @@
#define MYINT(s) (s[0]-'0')
#define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))
#define LUAC_FORMAT 1 /* this is the official format */
#define LUAC_FORMAT 0 /* this is the official format */
/* load one chunk; from lundump.c */
LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);

@ -172,9 +172,10 @@ LUAI_FUNC void raviV_settable_sskey(lua_State *L, const TValue *t, TValue *key,
LUAI_FUNC void raviV_gettable_i(lua_State *L, const TValue *t, TValue *key, StkId val);
LUAI_FUNC void raviV_settable_i(lua_State *L, const TValue *t, TValue *key, StkId val);
LUAI_FUNC void raviV_op_totype(lua_State *L, TValue *ra, TValue *rb);
LUAI_FUNC int raviV_checktype(lua_State *L, TValue *input, ravi_type_map type, TString *usertype);
LUAI_FUNC int raviV_check_usertype(lua_State *L, TString *name, const TValue *o);
#ifdef RAVI_DEFER_STATEMENT
LUAI_FUNC void raviV_op_defer(lua_State *L, TValue *ra);
#endif
LUAI_FUNC void raviV_debug_trace(lua_State *L, int opCode, int pc);
#endif

@ -48,6 +48,7 @@
#error "No support for this architecture (yet)"
#define RAVI__TARGET RAVI__ARCH_ARM
#elif defined(__aarch64__)
#error "No support for this architecture (yet)"
#define RAVI__TARGET RAVI__ARCH_ARM64
#elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)
#error "No support for this architecture (yet)"
@ -120,6 +121,10 @@
#endif
#define RAVI_TARGET_X86 1
#define RAVI_TARGET_X86ORX64 1
#define RAVI_TARGET_EHRETREG 0
#define RAVI_TARGET_MASKSHIFT 1
#define RAVI_TARGET_MASKROT 1
#define RAVI_TARGET_UNALIGNED 1
#elif RAVI__TARGET == RAVI__ARCH_X64
@ -133,21 +138,14 @@
#endif
#define RAVI_TARGET_X64 1
#define RAVI_TARGET_X86ORX64 1
#elif RAVI__TARGET == RAVI__ARCH_ARM64
#define RAVI_ARCH_BITS 64
#if defined(__AARCH64EB__)
#define RAVI_ARCH_NAME "arm64be"
#define RAVI_ARCH_ENDIAN RAVI__ARCH_BE
#else
#define RAVI_ARCH_NAME "arm64"
#define RAVI_ARCH_ENDIAN RAVI__ARCH_LE
#endif
#define RAVI_TARGET_ARM64 1
#define RAVI_TARGET_EHRETREG 0
#define RAVI_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */
#define RAVI_TARGET_MASKSHIFT 1
#define RAVI_TARGET_MASKROT 1
#define RAVI_TARGET_UNALIGNED 1
#else
#error "No target architecture defined"
#error "No target architecture defined"
#endif
#ifndef RAVI_PAGESIZE
@ -174,4 +172,8 @@
#define RAVI_64 1
#endif
#ifndef RAVI_TARGET_UNALIGNED
#define RAVI_TARGET_UNALIGNED 0
#endif
#endif

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2015-2021 Dibyendu Majumdar
* Copyright (C) 2015-2020 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2015-2021 Dibyendu Majumdar
* Copyright (C) 2015-2020 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -54,7 +54,7 @@ extern "C" {
#include "lua.h"
#include "lvm.h"
#include "ravi_membuf.h"
#include <ravi_membuf.h>
#define RA(i) (base + GETARG_A(i))
/* to be used after possible stack reallocation */
@ -122,8 +122,6 @@ LUAI_FUNC bool raviJ_cancompile(Proto *p);
LUAI_FUNC bool raviJ_codegen(struct lua_State *L, struct Proto *p,
struct ravi_compile_options_t *options,
const char *fname, membuff_t *buf);
void raviV_raise_error(lua_State *L, int errorcode);
void raviV_raise_error_with_info(lua_State *L, int errorcode, const char *info);
#ifdef __cplusplus
};

@ -0,0 +1,121 @@
/******************************************************************************
* Copyright (C) 2015 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#ifndef RAVI_LLVM_H
#define RAVI_LLVM_H
#ifdef USE_LLVM
#include "llvm/Config/llvm-config.h"
#if (LLVM_VERSION_MAJOR < 3 || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 5 || LLVM_VERSION_MAJOR == 7)
#error Unsupported LLVM version
#endif
#if LLVM_VERSION_MAJOR >= 5
#define USE_ORC_JIT 1
#else
#define USE_ORC_JIT 0
#endif
#if LLVM_VERSION_MAJOR >= 8 && !defined(_WIN32)
#define USE_ORCv2_JIT 0
#else
#define USE_ORCv2_JIT 0
#endif
#if LLVM_VERSION_MAJOR >= 10
#undef USE_ORCv2_JIT
#define USE_ORCv2_JIT 1
#endif
// In lua.c we include this just to get version numbers
// We cannot have C++ headers in that case
#ifdef __cplusplus
#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IR/Metadata.h"
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 7
#include "llvm/PassManager.h"
#else
#include "llvm/IR/LegacyPassManager.h"
#endif
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Support/FormattedStream.h"
#if USE_ORC_JIT || USE_ORCv2_JIT
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/Error.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Scalar/GVN.h"
#if LLVM_VERSION_MAJOR >= 8
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/Legacy.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#endif
#endif
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <memory>
#include <string>
#include <cstdio>
#include <vector>
#endif //__cplusplus
#endif //USE_LLVM
#endif

File diff suppressed because it is too large Load Diff

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (C) 2019-2021 Dibyendu Majumdar
* Copyright (C) 2019-2020 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -23,7 +23,7 @@
#ifndef RAVI_MIRJIT_H
#define RAVI_MIRJIT_H
#include "ravi_jitshared.h"
#include <ravi_jitshared.h>
#ifdef USE_MIRJIT
#include "c2mir.h"

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.12)
project(mir LANGUAGES C)
project(mir)
enable_language(C)
message(STATUS "OS type is ${CMAKE_SYSTEM_NAME}")
message(STATUS "System processor is ${CMAKE_HOST_SYSTEM_PROCESSOR}")
@ -24,23 +25,13 @@ set(C2MIR_SRCS
c2mir/c2mir.c
)
set(LIBS ${CMAKE_DL_LIBS})
if (WIN32)
set(MIR_BUILD_TYPE STATIC)
else()
set(MIR_BUILD_TYPE SHARED)
endif()
set(LIBS dl)
#add_definitions(-DMIR_NO_IO=0)
#add_definitions(-DMIR_NO_SCAN=1)
set_property(SOURCE ${MIR_SRCS} ${C2MIR_SRCS} ${MIR_JIT_SRCS}
APPEND
PROPERTY COMPILE_DEFINITIONS "MIR_NO_IO=0;MIR_NO_SCAN=1;MIR_NO_INTERP=1")
add_definitions(-DMIR_NO_IO=0)
add_definitions(-DMIR_NO_SCAN=1)
if ($ENV{CLION_IDE})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/c2mir)
endif()
include_directories(".")
include_directories("./c2mir")
include(CheckCCompilerFlag)
check_c_compiler_flag("-fsigned-char" COMPILER_OPT_SIGNED_CHAR_SUPPORTED)
@ -56,16 +47,10 @@ if (COMPILER_OPT_NO_IPA_CP_CLONE_SUPPORTED AND NOT CMAKE_C_FLAGS MATCHES "-fno-i
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-ipa-cp-clone")
endif()
include(GNUInstallDirs)
add_library(c2mir ${MIR_BUILD_TYPE}
add_library(c2mir
${MIR_HEADERS}
${MIR_SRCS}
${C2MIR_SRCS})
target_link_libraries(c2mir ${LIBS})
target_include_directories(c2mir PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/c2mir)
set_property(TARGET c2mir PROPERTY C_STANDARD 11)
install(TARGETS c2mir
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT mir_Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT mir_Development
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT mir_Runtime)

@ -46,10 +46,7 @@
or IEEE quad precision FP values. If it is the same as double, the double type will be used instead.
So please don't expect machine-independence of MIR code working with long double values
* `MIR_T_P` -- pointer values. Depending on the target pointer value is actually 32-bit or 64-bit integer value
* `MIR_T_BLK` .. `MIR_T_BLK + MIR_BLK_NUM - 1` -- block data with given case. This type can be used only
for argument of function. Different case numbers can denote different ways to pass the block data
on a particular target to implement the target call ABI. Currently there are 5 block
types (`MIR_BLK_NUM = 5`)
* `MIR_T_BLK` -- block data. This type can be used only for argument of function
* `MIR_T_RBLK` -- return block data. This type can be used only for argument of function
* MIR textual representation of the types are correspondingly `i8`,
`u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `f`, `d`, `ld`, `p`,
@ -103,8 +100,7 @@
* A variable should have an unique name in the function
* A variable is represented by a structure of type `MIR_var_t`
* The structure contains variable name and its type
* The structure contains also type size for variable of block types (`MIR_T_BLK`..`MIR_T_BLK + MIR_BLK_NUM - 1`)
or `MIR_T_RBLK` type
* The structure contains also type size for variable of `MIR_T_BLK` or `MIR_T_RBLK` type
* MIR function with its arguments is created through API function `MIR_item_t MIR_new_func (MIR_context_t ctx, const
char *name, size_t nres, MIR_type_t *res_types, size_t nargs, ...)`
or function `MIR_item_t MIR_new_func_arr (MIR_context_t ctx, const char *name, size_t nres, MIR_type_t *res_types, size_t nargs, MIR_var_t *arg_vars)`
@ -404,7 +400,7 @@
* The first insn saves the stack pointer in the operand
* The second insn restores stack pointer from the operand
### MIR_VA_START, MIR_VA_ARG, MIR_VA_BLOCK_ARG, and MIR_VA_END insns
### MIR_VA_START, MIR_VA_ARG, MIR_VA_STACK_ARG, and MIR_VA_END insns
* These insns are only for variable number arguments functions
* `MIR_VA_START` and `MIR_VA_END` have one input operand, an address
of va_list structure (see C stdarg.h for more details). Unlike C
@ -412,9 +408,9 @@
* `MIR_VA_ARG` takes va_list and any memory operand and returns
address of the next argument in the 1st insn operand. The memory
operand type defines the type of the argument
* `MIR_VA_BLOCK_ARG` takes result address, va_list address, integer operand (size),
and block type (case) number and moves the next argument passed as block of given
size and type to the result address
* `MIR_VA_STACK_ARG` takes va_list and integer operand and returns
address of the next argument passed as a block argument
of the size given by the integer operand
* va_list operand can be memory with undefined type. In this case
address of the va_list is not in the memory but is the
memory address
@ -610,23 +606,17 @@ main: func
works only on the same targets as MIR generator
# MIR generator (file mir-gen.h)
* Before use of MIR generator for given context you should initialize it by API function
`MIR_gen_init (MIR_context ctx, int gens_num)`. `gens_num` defines how many generator instances you need.
Each generator instance can be used in a different thread to compile different MIR functions from the same context.
If you pass a negative or zero number `gens_num`, it will have the same effect as value `1`
* API function `MIR_gen_finish (MIR_context ctx)` frees all internal generator data (and its instances) for the context.
If you want to generate code for the context again after the `MIR_gen_finish` call, you should call
`MIR_gen_init` again first
* API function `void *MIR_gen (MIR_context ctx, int gen_num, MIR_item_t func_item)` generates machine code
of given MIR function in generator instance `gen_num` and returns an address to call it. You can call
the code as usual C function by using this address as the called function address.
`gen_num` should be a number in the range `0` .. `gens_num - 1` from corresponding `MIR_gen_init`
* API function `void MIR_gen_set_debug_file (MIR_context_t ctx, int gen_num, FILE *f)` sets up MIR generator
debug file to `f` for generator instance `gen_num`.
* Before use of MIR generator for given context you should initialize it by API function `MIR_gen_init (MIR_context ctx)`
* API function `MIR_gen_finish (MIR_context ctx)` frees all internal generator data for the context.
If you want to generate code for the context again after the `MIR_gen_finish` call, you should call `MIR_gen_init` again first
* API function `void *MIR_gen (MIR_context ctx, MIR_item_t func_item)` generates machine code of given MIR function
and returns an address to call it. You can call the code as usual C function by using this address
as the called function address
* API function `void MIR_gen_set_debug_file (MIR_context_t ctx, FILE *f)` sets up MIR generator debug file to `f`.
If it is not NULL a lot of debugging and optimization information will be output to the file. It is useful mostly
for MIR developers
* API function `void MIR_gen_set_optimize_level (MIR_context_t ctx, int gen_num, unsigned int level)` sets up optimization
level for MIR generator instance `gen_num`:
* API function `void MIR_gen_set_optimize_level (MIR_context_t ctx, unsigned int level)` sets up optimization
level for MIR generator:
* `0` means only register allocator and machine code generator work
* `1` means additional code selection task. On this level MIR generator creates more compact and faster
code than on zero level with practically on the same speed

@ -3,5 +3,3 @@ project. Following changes have been made:
* A CMake build script added to create a library
* Unused files / tests have been removed to avoid clutter
Last update: 7th Jan 2021

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
aarch64 call ABI target specific code.
*/
@ -78,10 +78,6 @@ static void target_add_ret_ops (c2m_ctx_t c2m_ctx, struct type *ret_type, op_t r
gen_multiple_load_store (c2m_ctx, ret_type, VARR_ADDR (MIR_op_t, ret_ops), res.mir_op, TRUE);
}
static MIR_type_t target_get_blk_type (c2m_ctx_t c2m_ctx, struct type *arg_type) {
return MIR_T_BLK; /* one BLK is enough */
}
static void target_add_arg_proto (c2m_ctx_t c2m_ctx, const char *name, struct type *arg_type,
target_arg_info_t *arg_info, VARR (MIR_var_t) * arg_vars) {
simple_add_arg_proto (c2m_ctx, name, arg_type, arg_info, arg_vars);

@ -1,18 +1,13 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#include "../mirc.h"
#include "mirc_aarch64_linux.h"
#include "mirc-aarch64-linux.h"
#include "mirc_aarch64_float.h"
#include "mirc_aarch64_limits.h"
#include "mirc_aarch64_stdarg.h"
#include "mirc_aarch64_stdint.h"
#include "mirc_aarch64_stddef.h"
static const char *standard_includes[] = {mirc, aarch64_mirc};
static string_include_t standard_includes[]
= {{NULL, mirc}, {NULL, aarch64_mirc}, TARGET_STD_INCLUDES};
static const char *standard_include_dirs[] = {"include/mirc/", "include/mirc/aarch64/"};
#define MAX_ALIGNMENT 16

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#include <stdint.h>
@ -28,17 +28,12 @@ typedef uint16_t mir_ushort;
typedef uint32_t mir_uint;
typedef uint64_t mir_ulong;
typedef uint64_t mir_ullong;
typedef uint32_t mir_wchar;
typedef uint16_t mir_char16;
typedef uint32_t mir_char32;
#define MIR_UCHAR_MAX UINT8_MAX
#define MIR_USHORT_MAX UINT16_MAX
#define MIR_UINT_MAX UINT32_MAX
#define MIR_ULONG_MAX UINT64_MAX
#define MIR_ULLONG_MAX UINT64_MAX
#define MIR_WCHAR_MIN 0
#define MIR_WCHAR_MAX UINT32_MAX
typedef mir_schar mir_char;
#define MIR_CHAR_MIN MIR_SCHAR_MIN

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char aarch64_mirc[]

@ -1,60 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 5.2.4.2.2 */
static char float_str[]
= "#ifndef __FLOAT_H\n"
"#define __FLOAT_H\n"
"\n"
"#define FLT_RADIX 2\n"
"\n"
"#define FLT_MANT_DIG 24\n"
"#define DBL_MANT_DIG 53\n"
"#define LDBL_MANT_DIG DBL_MANT_DIG\n"
"\n"
"#define FLT_DECIMAL_DIG 9\n"
"#define DBL_DECIMAL_DIG 17\n"
"#define LDBL_DECIMAL_DIG DBL_DECIMAL_DIG\n"
"#define FLT_DIG FLT_DECIMAL_DIG\n"
"#define DBL_DIG DBL_DECIMAL_DIG\n"
"#define LDBL_DIG LDBL_DECIMAL_DIG\n"
"\n"
"#define DECIMAL_DIG LDBL_DECIMAL_DIG\n"
"\n"
"#define FLT_MIN_EXP -125\n"
"#define DBL_MIN_EXP -1021\n"
"#define LDBL_MIN_EXP DBL_MIN_EXP\n"
"\n"
"#define FLT_MIN_10_EXP -37\n"
"#define DBL_MIN_10_EXP -307\n"
"#define LDBL_MIN_10_EXP DBL_MIN_10_EXP\n"
"\n"
"#define FLT_MAX_EXP 128\n"
"#define DBL_MAX_EXP 1024\n"
"#define LDBL_MAX_EXP DBL_MAX_EXP\n"
"\n"
"#define FLT_MAX_10_EXP 38\n"
"#define DBL_MAX_10_EXP 308\n"
"#define LDBL_MAX_10_EXP DBL_MAX_10_EXP\n"
"\n"
"#define FLT_MAX 0x1.fffffep+127\n"
"#define DBL_MAX 0x1.fffffffffffffp+1023\n"
"#define LDBL_MAX DBL_MAX\n"
"\n"
"#define FLT_EPSILON 0x1p-23\n"
"#define DBL_EPSILON 0x1p-52\n"
"#define LDBL_EPSILON DBL_EPSILON\n"
"\n"
"#define FLT_MIN 0x1p-126\n"
"#define DBL_MIN 0x1p-1022\n"
"#define LDBL_MIN DBL_MIN\n"
"\n"
"#define FLT_TRUE_MIN 0x1p-149\n"
"#define DBL_TRUE_MIN 0x0.0000000000001p-1022\n"
"#define LDBL_TRUE_MIN DBL_TRUE_MIN\n"
"\n"
"#define FLT_EVAL_METHOD 0\n"
"#define FLT_ROUNDS 1 /* round to the nearest */\n"
"\n"
"#endif /* #ifndef __FLOAT_H */\n";

@ -1,38 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See 5.2.4.2 */
static char limits_str[]
= "#ifndef __LIMITS_H\n"
"#define __LIMITS_H\n"
"\n"
"#define CHAR_BIT 8\n"
"\n"
"#define SCHAR_MIN (-SCHAR_MAX - 1)\n"
"#define SCHAR_MAX 127\n"
"#define UCHAR_MAX (SCHAR_MAX * 2 + 1)\n"
"\n"
"#define MB_LEN_MAX 1\n"
"\n"
"#define SHRT_MIN (-SHRT_MAX - 1)\n"
"#define SHRT_MAX 32767\n"
"#define USHRT_MAX (SHRT_MAX * 2 + 1)\n"
"\n"
"#define INT_MIN (-INT_MAX - 1)\n"
"#define INT_MAX 2147483647\n"
"#define UINT_MAX (INT_MAX * 2u + 1u)\n"
"\n"
"#define LONG_MIN (-LONG_MAX - 1l)\n"
"#define LONG_MAX 9223372036854775807l\n"
"#define ULONG_MAX (LONG_MAX * 2ul + 1ul)\n"
"\n"
"#define LLONG_MIN LONG_MIN\n"
"#define LLONG_MAX LONG_MAX\n"
"#define ULLONG_MAX ULONG_MAX\n"
"\n"
"/* signed char by default */\n"
"#define CHAR_MIN SCHAR_MIN\n"
"#define CHAR_MAX SCHAR_MAX\n"
"\n"
"#endif /* #ifndef __LIMITS_H */\n";

@ -1,27 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char stdarg_str[]
= "#ifndef __STDARG_H\n"
"#define __STDARG_H\n"
"\n"
"typedef struct {\n"
" void *__stack;\n"
" void *__gr_top;\n"
" void *__vr_top;\n"
" int __gr_offs;\n"
" int __vr_offs;\n"
"} va_list;\n"
"\n"
"#define va_start(ap, param) __builtin_va_start (ap)\n"
"#define va_arg(ap, type) __builtin_va_arg(ap, (type *) 0)\n"
"#define va_end(ap) 0\n"
"#define va_copy(dest, src) ((dest)[0] = (src)[0])\n"
"\n"
"/* For standard headers of a GNU system: */\n"
"#ifndef __GNUC_VA_LIST\n"
"#define __GNUC_VA_LIST 1\n"
"#endif\n"
"typedef va_list __gnuc_va_list;\n"
"#endif /* #ifndef __STDARG_H */\n";

@ -1,19 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.19 */
static char stddef_str[]
= "#ifndef __STDDEF_H\n"
"#define __STDDEF_H\n"
"\n"
"typedef long ptrdiff_t;\n"
"typedef unsigned long size_t;\n"
"typedef long double max_align_t;\n"
"typedef unsigned int wchar_t;\n"
"\n"
"#define NULL ((void *) 0)\n"
"\n"
"#define offsetof(type, member_designator) ((size_t) & ((type *) 0)->member_designator)\n"
"\n"
"#endif /* #ifndef __STDDEF_H */\n";

@ -1,130 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.20 */
static char stdint_str[]
= "#ifndef _STDINT_H\n"
"#define _STDINT_H 1\n"
"\n"
"#ifndef __int8_t_defined\n"
"#define __int8_t_defined\n"
"typedef signed char int8_t;\n"
"#endif\n"
"typedef short int int16_t;\n"
"typedef int int32_t;\n"
"typedef long int int64_t;\n"
"\n"
"typedef unsigned char uint8_t;\n"
"typedef unsigned short int uint16_t;\n"
"typedef unsigned int uint32_t;\n"
"typedef unsigned long int uint64_t;\n"
"\n"
"typedef signed char int_least8_t;\n"
"typedef short int int_least16_t;\n"
"typedef int int_least32_t;\n"
"typedef long int int_least64_t;\n"
"\n"
"typedef unsigned char uint_least8_t;\n"
"typedef unsigned short int uint_least16_t;\n"
"typedef unsigned int uint_least32_t;\n"
"typedef unsigned long int uint_least64_t;\n"
"\n"
"typedef signed char int_fast8_t;\n"
"typedef long int int_fast16_t;\n"
"typedef long int int_fast32_t;\n"
"typedef long int int_fast64_t;\n"
"\n"
"typedef unsigned char uint_fast8_t;\n"
"typedef unsigned long int uint_fast16_t;\n"
"typedef unsigned long int uint_fast32_t;\n"
"typedef unsigned long int uint_fast64_t;\n"
"\n"
"#define __intptr_t_defined\n"
"typedef long int intptr_t;\n"
"typedef unsigned long int uintptr_t;\n"
"\n"
"typedef long int intmax_t;\n"
"typedef unsigned long int uintmax_t;\n"
"\n"
"#define __INT64_C(c) c##L\n"
"#define __UINT64_C(c) c##UL\n"
"\n"
"#define INT8_MIN (-128)\n"
"#define INT16_MIN (-32768)\n"
"#define INT32_MIN (-2147483648)\n"
"#define INT64_MIN (-9223372036854775808l)\n"
"\n"
"#define INT8_MAX (127)\n"
"#define INT16_MAX (32767)\n"
"#define INT32_MAX (2147483647)\n"
"#define INT64_MAX (9223372036854775807l)\n"
"\n"
"#define UINT8_MAX (255)\n"
"#define UINT16_MAX (65535)\n"
"#define UINT32_MAX (4294967295u)\n"
"#define UINT64_MAX (18446744073709551615ul)\n"
"\n"
"#define INT_LEAST8_MIN (-128)\n"
"#define INT_LEAST16_MIN (-32768)\n"
"#define INT_LEAST32_MIN (-2147483648)\n"
"#define INT_LEAST64_MIN (-9223372036854775808L)\n"
"\n"
"#define INT_LEAST8_MAX (127)\n"
"#define INT_LEAST16_MAX (32767)\n"
"#define INT_LEAST32_MAX (2147483647)\n"
"#define INT_LEAST64_MAX (9223372036854775807L)\n"
"\n"
"#define UINT_LEAST8_MAX (255)\n"
"#define UINT_LEAST16_MAX (65535)\n"
"#define UINT_LEAST32_MAX (4294967295U)\n"
"#define UINT_LEAST64_MAX (18446744073709551615UL)\n"
"\n"
"#define INT_FAST8_MIN (-128)\n"
"#define INT_FAST16_MIN (-9223372036854775808L)\n"
"#define INT_FAST32_MIN (-9223372036854775808L)\n"
"#define INT_FAST64_MIN (-9223372036854775808L)\n"
"\n"
"#define INT_FAST8_MAX (127)\n"
"#define INT_FAST16_MAX (9223372036854775807L)\n"
"#define INT_FAST32_MAX (9223372036854775807L)\n"
"#define INT_FAST64_MAX (9223372036854775807L)\n"
"\n"
"#define UINT_FAST8_MAX (255)\n"
"#define UINT_FAST16_MAX (18446744073709551615UL)\n"
"#define UINT_FAST32_MAX (18446744073709551615UL)\n"
"#define UINT_FAST64_MAX (18446744073709551615UL)\n"
"\n"
"#define INTPTR_MIN (-9223372036854775808L)\n"
"#define INTPTR_MAX (9223372036854775807L)\n"
"#define UINTPTR_MAX (18446744073709551615UL)\n"
"\n"
"#define INTMAX_MIN (-9223372036854775808L)\n"
"#define INTMAX_MAX (9223372036854775807L)\n"
"#define UINTMAX_MAX (18446744073709551615UL)\n"
"\n"
"#define PTRDIFF_MIN (-9223372036854775808L)\n"
"#define PTRDIFF_MAX (9223372036854775807L)\n"
"\n"
"#define SIZE_MAX (18446744073709551615UL)\n"
"\n"
"/* For signed wchar_t and wint_t: */\n"
"#define WCHAR_MIN INT32_MIN\n"
"#define WCHAR_MAX INT32_MAX\n"
"#define WINT_MIN WCHAR_MIN\n"
"#define WINT_MAX WCHAR_MAX\n"
"\n"
"#define INT8_C(value) value\n"
"#define INT16_C(value) value\n"
"#define INT32_C(value) value\n"
"#define INT64_C(value) value##L\n"
"\n"
"#define UINT8_C(value) value\n"
"#define UINT16_C(value) value\n"
"#define UINT32_C(value) value##U\n"
"#define UINT64_C(value) value##UL\n"
"\n"
"#define INTMAX_C(value) value##L\n"
"#define UINTMAX_C(value) value##UL\n"
"\n"
"#endif /* #ifndef _STDINT_H */\n";

File diff suppressed because it is too large Load Diff

@ -1,11 +1,3 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#ifndef C2MIR_H
#define C2MIR_H
#include "mir.h"
#define COMMAND_LINE_SOURCE_NAME "<command-line>"
@ -32,5 +24,3 @@ void c2mir_init (MIR_context_t ctx);
void c2mir_finish (MIR_context_t ctx);
int c2mir_compile (MIR_context_t ctx, struct c2mir_options *ops, int (*getc_func) (void *),
void *getc_data, const char *source_name, FILE *output_file);
#endif

@ -1,7 +1,3 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static const char mirc[]
= "#define __mirc__ 1\n"
"#define __MIRC__ 1\n"
@ -25,15 +21,3 @@ static const char mirc[]
"#define __signed__ signed\n"
"#define __volatile volatile\n"
"#define __volatile__ volatile\n";
#include "mirc_iso646.h"
#include "mirc_stdalign.h"
#include "mirc_stdbool.h"
#include "mirc_stdnoreturn.h"
#define TARGET_STD_INCLUDES \
{"iso646.h", iso646_str}, {"stdalign.h", stdalign_str}, {"stdbool.h", stdbool_str}, \
{"stdnoreturn.h", stdnoreturn_str}, {"float.h", float_str}, {"limits.h", limits_str}, \
{"stdarg.h", stdarg_str}, {"stdint.h", stdint_str}, { \
"stddef.h", stddef_str \
}

@ -1,21 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.9 */
static char iso646_str[]
= "#ifndef __ISO646_H\n"
"#define __ISO646_H\n"
"\n"
"#define and &&\n"
"#define and_eq &=\n"
"#define bitand &\n"
"#define bitor |\n"
"#define compl ~\n"
"#define not !\n"
"#define not_eq !=\n"
"#define or ||\n"
"#define or_eq |=\n"
"#define xor ^\n"
"#define xor_eq ^=\n"
"#endif /* #ifndef __ISO646_H */\n";

@ -1,14 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.15 */
static char stdalign_str[]
= "#ifndef __STDALIGN_H\n"
"#define __STDALIGN_H\n"
"\n"
"#define alignas _Alignas\n"
"#define alignof _Alignof\n"
"#define __alignas_is_defined 1\n"
"#define __alignof_is_defined 1\n"
"#endif /* #ifndef __STDALIGN_H */\n";

@ -1,14 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.18 */
static char stdbool_str[]
= "#ifndef __STDBOOL_H\n"
"#define __STDBOOL_H\n"
"\n"
"#define bool _Bool\n"
"#define true 1\n"
"#define false 0\n"
"#define __bool_true_false_are_defined 1\n"
"#endif /* #ifndef __STDBOOL_H */\n";

@ -1,11 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.23 */
static char stdnoreturn_str[]
= "#ifndef __STDNORETURN_H\n"
"#define __STDNORETURN_H\n"
"\n"
"#define noreturn _Noreturn\n"
"#endif /* #ifndef __STDNORETURN_H */\n";

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
ppc64 call ABI target specific code.
*/
@ -219,10 +219,6 @@ static void target_add_ret_ops (c2m_ctx_t c2m_ctx, struct type *ret_type, op_t r
}
}
static MIR_type_t target_get_blk_type (c2m_ctx_t c2m_ctx, struct type *arg_type) {
return MIR_T_BLK; /* one BLK is enough */
}
static void target_add_arg_proto (c2m_ctx_t c2m_ctx, const char *name, struct type *arg_type,
target_arg_info_t *arg_info, VARR (MIR_var_t) * arg_vars) {
MIR_var_t var;

@ -1,22 +1,18 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#include "../mirc.h"
#include "mirc_ppc64_linux.h"
#include "mirc-ppc64-linux.h"
#include "mirc_ppc64_float.h"
#include "mirc_ppc64_limits.h"
#include "mirc_ppc64_stdarg.h"
#include "mirc_ppc64_stdint.h"
#include "mirc_ppc64_stddef.h"
static const char *standard_includes[] = {mirc, ppc64_mirc};
static string_include_t standard_includes[]
= {{NULL, mirc}, {NULL, ppc64_mirc}, TARGET_STD_INCLUDES};
static const char *standard_include_dirs[] = {"include/mirc/", "include/mirc/ppc64/"};
#define MAX_ALIGNMENT 16
#define ADJUST_VAR_ALIGNMENT(c2m_ctx, align, type) ppc64_adjust_var_alignment (c2m_ctx, align, type)
#define ADJUST_VAR_ALIGNMENT(c2m_ctx, align, type) \
ppc64_adjust_var_alignment (c2m_ctx, align, type)
static int ppc64_adjust_var_alignment (c2m_ctx_t c2m_ctx, int align, struct type *type) {
return align;

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#include <stdint.h>
@ -28,17 +28,12 @@ typedef uint16_t mir_ushort;
typedef uint32_t mir_uint;
typedef uint64_t mir_ulong;
typedef uint64_t mir_ullong;
typedef uint32_t mir_wchar;
typedef uint16_t mir_char16;
typedef uint32_t mir_char32;
#define MIR_UCHAR_MAX UINT8_MAX
#define MIR_USHORT_MAX UINT16_MAX
#define MIR_UINT_MAX UINT32_MAX
#define MIR_ULONG_MAX UINT64_MAX
#define MIR_ULLONG_MAX UINT64_MAX
#define MIR_WCHAR_MIN 0
#define MIR_WCHAR_MAX UINT32_MAX
typedef mir_schar mir_char;
#define MIR_CHAR_MIN MIR_SCHAR_MIN

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char ppc64_mirc[]
@ -15,7 +15,7 @@ static char ppc64_mirc[]
"#define _CALL_ELF 2\n"
#endif
"\n"
"#define __LONG_DOUBLE_128__ 1\n" // ???
"#define __LONG_DOUBLE_128__ 1\n" // ???
"#define __SIZEOF_DOUBLE__ 8\n"
"#define __SIZEOF_FLOAT__ 4\n"
"#define __SIZEOF_INT__ 4\n"

@ -1,60 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 5.2.4.2.2 */
static char float_str[]
= "#ifndef __FLOAT_H\n"
"#define __FLOAT_H\n"
"\n"
"#define FLT_RADIX 2\n"
"\n"
"#define FLT_MANT_DIG 24\n"
"#define DBL_MANT_DIG 53\n"
"#define LDBL_MANT_DIG DBL_MANT_DIG\n"
"\n"
"#define FLT_DECIMAL_DIG 9\n"
"#define DBL_DECIMAL_DIG 17\n"
"#define LDBL_DECIMAL_DIG DBL_DECIMAL_DIG\n"
"#define FLT_DIG FLT_DECIMAL_DIG\n"
"#define DBL_DIG DBL_DECIMAL_DIG\n"
"#define LDBL_DIG LDBL_DECIMAL_DIG\n"
"\n"
"#define DECIMAL_DIG LDBL_DECIMAL_DIG\n"
"\n"
"#define FLT_MIN_EXP -125\n"
"#define DBL_MIN_EXP -1021\n"
"#define LDBL_MIN_EXP DBL_MIN_EXP\n"
"\n"
"#define FLT_MIN_10_EXP -37\n"
"#define DBL_MIN_10_EXP -307\n"
"#define LDBL_MIN_10_EXP DBL_MIN_10_EXP\n"
"\n"
"#define FLT_MAX_EXP 128\n"
"#define DBL_MAX_EXP 1024\n"
"#define LDBL_MAX_EXP DBL_MAX_EXP\n"
"\n"
"#define FLT_MAX_10_EXP 38\n"
"#define DBL_MAX_10_EXP 308\n"
"#define LDBL_MAX_10_EXP DBL_MAX_10_EXP\n"
"\n"
"#define FLT_MAX 0x1.fffffep+127\n"
"#define DBL_MAX 0x1.fffffffffffffp+1023\n"
"#define LDBL_MAX DBL_MAX\n"
"\n"
"#define FLT_EPSILON 0x1p-23\n"
"#define DBL_EPSILON 0x1p-52\n"
"#define LDBL_EPSILON DBL_EPSILON\n"
"\n"
"#define FLT_MIN 0x1p-126\n"
"#define DBL_MIN 0x1p-1022\n"
"#define LDBL_MIN DBL_MIN\n"
"\n"
"#define FLT_TRUE_MIN 0x1p-149\n"
"#define DBL_TRUE_MIN 0x0.0000000000001p-1022\n"
"#define LDBL_TRUE_MIN DBL_TRUE_MIN\n"
"\n"
"#define FLT_EVAL_METHOD 0\n"
"#define FLT_ROUNDS 1 /* round to the nearest */\n"
"\n"
"#endif /* #ifndef __FLOAT_H */\n";

@ -1,38 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See 5.2.4.2 */
static char limits_str[]
= "#ifndef __LIMITS_H\n"
"#define __LIMITS_H\n"
"\n"
"#define CHAR_BIT 8\n"
"\n"
"#define SCHAR_MIN (-SCHAR_MAX - 1)\n"
"#define SCHAR_MAX 127\n"
"#define UCHAR_MAX (SCHAR_MAX * 2 + 1)\n"
"\n"
"#define MB_LEN_MAX 1\n"
"\n"
"#define SHRT_MIN (-SHRT_MAX - 1)\n"
"#define SHRT_MAX 32767\n"
"#define USHRT_MAX (SHRT_MAX * 2 + 1)\n"
"\n"
"#define INT_MIN (-INT_MAX - 1)\n"
"#define INT_MAX 2147483647\n"
"#define UINT_MAX (INT_MAX * 2u + 1u)\n"
"\n"
"#define LONG_MIN (-LONG_MAX - 1l)\n"
"#define LONG_MAX 9223372036854775807l\n"
"#define ULONG_MAX (LONG_MAX * 2ul + 1ul)\n"
"\n"
"#define LLONG_MIN LONG_MIN\n"
"#define LLONG_MAX LONG_MAX\n"
"#define ULLONG_MAX ULONG_MAX\n"
"\n"
"/* unsigned char by default */\n"
"#define CHAR_MIN 0\n"
"#define CHAR_MAX UCHAR_MAX\n"
"\n"
"#endif /* #ifndef __LIMITS_H */\n";

@ -1,21 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char stdarg_str[]
= "#ifndef __STDARG_H\n"
"#define __STDARG_H\n"
"\n"
"typedef void *va_list[1];\n"
"\n"
"#define va_start(ap, param) __builtin_va_start (ap)\n"
"#define va_arg(ap, type) __builtin_va_arg(ap, (type *) 0)\n"
"#define va_end(ap) 0\n"
"#define va_copy(dest, src) ((dest) = (src))\n"
"\n"
"/* For standard headers of a GNU system: */\n"
"#ifndef __GNUC_VA_LIST\n"
"#define __GNUC_VA_LIST 1\n"
"#endif\n"
"typedef va_list __gnuc_va_list;\n"
"#endif /* #ifndef __STDARG_H */\n";

@ -1,19 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.19 */
static char stddef_str[]
= "#ifndef __STDDEF_H\n"
"#define __STDDEF_H\n"
"\n"
"typedef long ptrdiff_t;\n"
"typedef unsigned long size_t;\n"
"typedef long double max_align_t;\n"
"typedef unsigned int wchar_t;\n"
"\n"
"#define NULL ((void *) 0)\n"
"\n"
"#define offsetof(type, member_designator) ((size_t) & ((type *) 0)->member_designator)\n"
"\n"
"#endif /* #ifndef __STDDEF_H */\n";

@ -1,130 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.20 */
static char stdint_str[]
= "#ifndef _STDINT_H\n"
"#define _STDINT_H 1\n"
"\n"
"#ifndef __int8_t_defined\n"
"#define __int8_t_defined\n"
"typedef signed char int8_t;\n"
"#endif\n"
"typedef short int int16_t;\n"
"typedef int int32_t;\n"
"typedef long int int64_t;\n"
"\n"
"typedef unsigned char uint8_t;\n"
"typedef unsigned short int uint16_t;\n"
"typedef unsigned int uint32_t;\n"
"typedef unsigned long int uint64_t;\n"
"\n"
"typedef signed char int_least8_t;\n"
"typedef short int int_least16_t;\n"
"typedef int int_least32_t;\n"
"typedef long int int_least64_t;\n"
"\n"
"typedef unsigned char uint_least8_t;\n"
"typedef unsigned short int uint_least16_t;\n"
"typedef unsigned int uint_least32_t;\n"
"typedef unsigned long int uint_least64_t;\n"
"\n"
"typedef signed char int_fast8_t;\n"
"typedef long int int_fast16_t;\n"
"typedef long int int_fast32_t;\n"
"typedef long int int_fast64_t;\n"
"\n"
"typedef unsigned char uint_fast8_t;\n"
"typedef unsigned long int uint_fast16_t;\n"
"typedef unsigned long int uint_fast32_t;\n"
"typedef unsigned long int uint_fast64_t;\n"
"\n"
"#define __intptr_t_defined\n"
"typedef long int intptr_t;\n"
"typedef unsigned long int uintptr_t;\n"
"\n"
"typedef long int intmax_t;\n"
"typedef unsigned long int uintmax_t;\n"
"\n"
"#define __INT64_C(c) c##L\n"
"#define __UINT64_C(c) c##UL\n"
"\n"
"#define INT8_MIN (-128)\n"
"#define INT16_MIN (-32768)\n"
"#define INT32_MIN (-2147483648)\n"
"#define INT64_MIN (-9223372036854775808l)\n"
"\n"
"#define INT8_MAX (127)\n"
"#define INT16_MAX (32767)\n"
"#define INT32_MAX (2147483647)\n"
"#define INT64_MAX (9223372036854775807l)\n"
"\n"
"#define UINT8_MAX (255)\n"
"#define UINT16_MAX (65535)\n"
"#define UINT32_MAX (4294967295u)\n"
"#define UINT64_MAX (18446744073709551615ul)\n"
"\n"
"#define INT_LEAST8_MIN (-128)\n"
"#define INT_LEAST16_MIN (-32768)\n"
"#define INT_LEAST32_MIN (-2147483648)\n"
"#define INT_LEAST64_MIN (-9223372036854775808L)\n"
"\n"
"#define INT_LEAST8_MAX (127)\n"
"#define INT_LEAST16_MAX (32767)\n"
"#define INT_LEAST32_MAX (2147483647)\n"
"#define INT_LEAST64_MAX (9223372036854775807L)\n"
"\n"
"#define UINT_LEAST8_MAX (255)\n"
"#define UINT_LEAST16_MAX (65535)\n"
"#define UINT_LEAST32_MAX (4294967295U)\n"
"#define UINT_LEAST64_MAX (18446744073709551615UL)\n"
"\n"
"#define INT_FAST8_MIN (-128)\n"
"#define INT_FAST16_MIN (-9223372036854775808L)\n"
"#define INT_FAST32_MIN (-9223372036854775808L)\n"
"#define INT_FAST64_MIN (-9223372036854775808L)\n"
"\n"
"#define INT_FAST8_MAX (127)\n"
"#define INT_FAST16_MAX (9223372036854775807L)\n"
"#define INT_FAST32_MAX (9223372036854775807L)\n"
"#define INT_FAST64_MAX (9223372036854775807L)\n"
"\n"
"#define UINT_FAST8_MAX (255)\n"
"#define UINT_FAST16_MAX (18446744073709551615UL)\n"
"#define UINT_FAST32_MAX (18446744073709551615UL)\n"
"#define UINT_FAST64_MAX (18446744073709551615UL)\n"
"\n"
"#define INTPTR_MIN (-9223372036854775808L)\n"
"#define INTPTR_MAX (9223372036854775807L)\n"
"#define UINTPTR_MAX (18446744073709551615UL)\n"
"\n"
"#define INTMAX_MIN (-9223372036854775808L)\n"
"#define INTMAX_MAX (9223372036854775807L)\n"
"#define UINTMAX_MAX (18446744073709551615UL)\n"
"\n"
"#define PTRDIFF_MIN (-9223372036854775808L)\n"
"#define PTRDIFF_MAX (9223372036854775807L)\n"
"\n"
"#define SIZE_MAX (18446744073709551615UL)\n"
"\n"
"/* For signed wchar_t and wint_t: */\n"
"#define WCHAR_MIN INT32_MIN\n"
"#define WCHAR_MAX INT32_MAX\n"
"#define WINT_MIN WCHAR_MIN\n"
"#define WINT_MAX WCHAR_MAX\n"
"\n"
"#define INT8_C(value) value\n"
"#define INT16_C(value) value\n"
"#define INT32_C(value) value\n"
"#define INT64_C(value) value##L\n"
"\n"
"#define UINT8_C(value) value\n"
"#define UINT16_C(value) value\n"
"#define UINT32_C(value) value##U\n"
"#define UINT64_C(value) value##UL\n"
"\n"
"#define INTMAX_C(value) value##L\n"
"#define UINTMAX_C(value) value##UL\n"
"\n"
"#endif /* #ifndef _STDINT_H */\n";

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
s390x call ABI target specific code.
*/
@ -36,10 +36,6 @@ static int reg_aggregate_p (c2m_ctx_t c2m_ctx, struct type *arg_type) {
return size == 1 || size == 2 || size == 4 || size == 8;
}
static MIR_type_t target_get_blk_type (c2m_ctx_t c2m_ctx, struct type *arg_type) {
return MIR_T_BLK; /* one BLK is enough */
}
static void target_add_arg_proto (c2m_ctx_t c2m_ctx, const char *name, struct type *arg_type,
target_arg_info_t *arg_info, VARR (MIR_var_t) * arg_vars) {
MIR_var_t var;

@ -1,22 +1,18 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#include "../mirc.h"
#include "mirc_s390x_linux.h"
#include "mirc-s390x-linux.h"
#include "mirc_s390x_float.h"
#include "mirc_s390x_limits.h"
#include "mirc_s390x_stdarg.h"
#include "mirc_s390x_stdint.h"
#include "mirc_s390x_stddef.h"
static const char *standard_includes[] = {mirc, s390x_mirc};
static string_include_t standard_includes[]
= {{NULL, mirc}, {NULL, s390x_mirc}, TARGET_STD_INCLUDES};
static const char *standard_include_dirs[] = {"include/mirc/", "include/mirc/s390x/"};
#define MAX_ALIGNMENT 16
#define ADJUST_VAR_ALIGNMENT(c2m_ctx, align, type) s390x_adjust_var_alignment (c2m_ctx, align, type)
#define ADJUST_VAR_ALIGNMENT(c2m_ctx, align, type) \
s390x_adjust_var_alignment (c2m_ctx, align, type)
static int s390x_adjust_var_alignment (c2m_ctx_t c2m_ctx, int align, struct type *type) {
return align;

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#include <stdint.h>
@ -28,17 +28,12 @@ typedef uint16_t mir_ushort;
typedef uint32_t mir_uint;
typedef uint64_t mir_ulong;
typedef uint64_t mir_ullong;
typedef uint32_t mir_wchar;
typedef uint16_t mir_char16;
typedef uint32_t mir_char32;
#define MIR_UCHAR_MAX UINT8_MAX
#define MIR_USHORT_MAX UINT16_MAX
#define MIR_UINT_MAX UINT32_MAX
#define MIR_ULONG_MAX UINT64_MAX
#define MIR_ULLONG_MAX UINT64_MAX
#define MIR_WCHAR_MIN 0
#define MIR_WCHAR_MAX UINT32_MAX
typedef mir_schar mir_char;
#define MIR_CHAR_MIN MIR_SCHAR_MIN

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char s390x_mirc[]
@ -11,7 +11,7 @@ static char s390x_mirc[]
"#define __ELF__ 1\n"
"\n"
#if __SIZEOF_LONG_DOUBLE__ == 16
"#define __LONG_DOUBLE_128__ 1\n" // ???
"#define __LONG_DOUBLE_128__ 1\n" // ???
"#define __SIZEOF_LONG_DOUBLE__ 16\n"
#else
"#define __SIZEOF_LONG_DOUBLE__ 8\n"

@ -1,60 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 5.2.4.2.2 */
static char float_str[]
= "#ifndef __FLOAT_H\n"
"#define __FLOAT_H\n"
"\n"
"#define FLT_RADIX 2\n"
"\n"
"#define FLT_MANT_DIG 24\n"
"#define DBL_MANT_DIG 53\n"
"#define LDBL_MANT_DIG DBL_MANT_DIG\n"
"\n"
"#define FLT_DECIMAL_DIG 9\n"
"#define DBL_DECIMAL_DIG 17\n"
"#define LDBL_DECIMAL_DIG DBL_DECIMAL_DIG\n"
"#define FLT_DIG FLT_DECIMAL_DIG\n"
"#define DBL_DIG DBL_DECIMAL_DIG\n"
"#define LDBL_DIG LDBL_DECIMAL_DIG\n"
"\n"
"#define DECIMAL_DIG LDBL_DECIMAL_DIG\n"
"\n"
"#define FLT_MIN_EXP -125\n"
"#define DBL_MIN_EXP -1021\n"
"#define LDBL_MIN_EXP DBL_MIN_EXP\n"
"\n"
"#define FLT_MIN_10_EXP -37\n"
"#define DBL_MIN_10_EXP -307\n"
"#define LDBL_MIN_10_EXP DBL_MIN_10_EXP\n"
"\n"
"#define FLT_MAX_EXP 128\n"
"#define DBL_MAX_EXP 1024\n"
"#define LDBL_MAX_EXP DBL_MAX_EXP\n"
"\n"
"#define FLT_MAX_10_EXP 38\n"
"#define DBL_MAX_10_EXP 308\n"
"#define LDBL_MAX_10_EXP DBL_MAX_10_EXP\n"
"\n"
"#define FLT_MAX 0x1.fffffep+127\n"
"#define DBL_MAX 0x1.fffffffffffffp+1023\n"
"#define LDBL_MAX DBL_MAX\n"
"\n"
"#define FLT_EPSILON 0x1p-23\n"
"#define DBL_EPSILON 0x1p-52\n"
"#define LDBL_EPSILON DBL_EPSILON\n"
"\n"
"#define FLT_MIN 0x1p-126\n"
"#define DBL_MIN 0x1p-1022\n"
"#define LDBL_MIN DBL_MIN\n"
"\n"
"#define FLT_TRUE_MIN 0x1p-149\n"
"#define DBL_TRUE_MIN 0x0.0000000000001p-1022\n"
"#define LDBL_TRUE_MIN DBL_TRUE_MIN\n"
"\n"
"#define FLT_EVAL_METHOD 0\n"
"#define FLT_ROUNDS 1 /* round to the nearest */\n"
"\n"
"#endif /* #ifndef __FLOAT_H */\n";

@ -1,38 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See 5.2.4.2 */
static char limits_str[]
= "#ifndef __LIMITS_H\n"
"#define __LIMITS_H\n"
"\n"
"#define CHAR_BIT 8\n"
"\n"
"#define SCHAR_MIN (-SCHAR_MAX - 1)\n"
"#define SCHAR_MAX 127\n"
"#define UCHAR_MAX (SCHAR_MAX * 2 + 1)\n"
"\n"
"#define MB_LEN_MAX 1\n"
"\n"
"#define SHRT_MIN (-SHRT_MAX - 1)\n"
"#define SHRT_MAX 32767\n"
"#define USHRT_MAX (SHRT_MAX * 2 + 1)\n"
"\n"
"#define INT_MIN (-INT_MAX - 1)\n"
"#define INT_MAX 2147483647\n"
"#define UINT_MAX (INT_MAX * 2u + 1u)\n"
"\n"
"#define LONG_MIN (-LONG_MAX - 1l)\n"
"#define LONG_MAX 9223372036854775807l\n"
"#define ULONG_MAX (LONG_MAX * 2ul + 1ul)\n"
"\n"
"#define LLONG_MIN LONG_MIN\n"
"#define LLONG_MAX LONG_MAX\n"
"#define ULLONG_MAX ULONG_MAX\n"
"\n"
"/* unsigned char by default */\n"
"#define CHAR_MIN 0\n"
"#define CHAR_MAX UCHAR_MAX\n"
"\n"
"#endif /* #ifndef __LIMITS_H */\n";

@ -1,25 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char stdarg_str[]
= "#ifndef __STDARG_H\n"
"#define __STDARG_H\n"
"\n"
"typedef struct {\n"
" long __gpr, __fpr;\n"
" void *__overflow_arg_area;\n"
" void *__reg_save_area;\n"
"} va_list[1];\n"
"\n"
"#define va_start(ap, param) __builtin_va_start (ap)\n"
"#define va_arg(ap, type) __builtin_va_arg(ap, (type *) 0)\n"
"#define va_end(ap) 0\n"
"#define va_copy(dest, src) ((dest) = (src))\n"
"\n"
"/* For standard headers of a GNU system: */\n"
"#ifndef __GNUC_VA_LIST\n"
"#define __GNUC_VA_LIST 1\n"
"#endif\n"
"typedef va_list __gnuc_va_list;\n"
"#endif /* #ifndef __STDARG_H */\n";

@ -1,19 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.19 */
static char stddef_str[]
= "#ifndef __STDDEF_H\n"
"#define __STDDEF_H\n"
"\n"
"typedef long ptrdiff_t;\n"
"typedef unsigned long size_t;\n"
"typedef long double max_align_t;\n"
"typedef unsigned int wchar_t;\n"
"\n"
"#define NULL ((void *) 0)\n"
"\n"
"#define offsetof(type, member_designator) ((size_t) & ((type *) 0)->member_designator)\n"
"\n"
"#endif /* #ifndef __STDDEF_H */\n";

@ -1,130 +0,0 @@
/* This file is a part of MIR project.
Copyright (C) 2020-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
/* See C11 7.20 */
static char stdint_str[]
= "#ifndef _STDINT_H\n"
"#define _STDINT_H 1\n"
"\n"
"#ifndef __int8_t_defined\n"
"#define __int8_t_defined\n"
"typedef signed char int8_t;\n"
"#endif\n"
"typedef short int int16_t;\n"
"typedef int int32_t;\n"
"typedef long int int64_t;\n"
"\n"
"typedef unsigned char uint8_t;\n"
"typedef unsigned short int uint16_t;\n"
"typedef unsigned int uint32_t;\n"
"typedef unsigned long int uint64_t;\n"
"\n"
"typedef signed char int_least8_t;\n"
"typedef short int int_least16_t;\n"
"typedef int int_least32_t;\n"
"typedef long int int_least64_t;\n"
"\n"
"typedef unsigned char uint_least8_t;\n"
"typedef unsigned short int uint_least16_t;\n"
"typedef unsigned int uint_least32_t;\n"
"typedef unsigned long int uint_least64_t;\n"
"\n"
"typedef signed char int_fast8_t;\n"
"typedef long int int_fast16_t;\n"
"typedef long int int_fast32_t;\n"
"typedef long int int_fast64_t;\n"
"\n"
"typedef unsigned char uint_fast8_t;\n"
"typedef unsigned long int uint_fast16_t;\n"
"typedef unsigned long int uint_fast32_t;\n"
"typedef unsigned long int uint_fast64_t;\n"
"\n"
"#define __intptr_t_defined\n"
"typedef long int intptr_t;\n"
"typedef unsigned long int uintptr_t;\n"
"\n"
"typedef long int intmax_t;\n"
"typedef unsigned long int uintmax_t;\n"
"\n"
"#define __INT64_C(c) c##L\n"
"#define __UINT64_C(c) c##UL\n"
"\n"
"#define INT8_MIN (-128)\n"
"#define INT16_MIN (-32768)\n"
"#define INT32_MIN (-2147483648)\n"
"#define INT64_MIN (-9223372036854775808l)\n"
"\n"
"#define INT8_MAX (127)\n"
"#define INT16_MAX (32767)\n"
"#define INT32_MAX (2147483647)\n"
"#define INT64_MAX (9223372036854775807l)\n"
"\n"
"#define UINT8_MAX (255)\n"
"#define UINT16_MAX (65535)\n"
"#define UINT32_MAX (4294967295u)\n"
"#define UINT64_MAX (18446744073709551615ul)\n"
"\n"
"#define INT_LEAST8_MIN (-128)\n"
"#define INT_LEAST16_MIN (-32768)\n"
"#define INT_LEAST32_MIN (-2147483648)\n"
"#define INT_LEAST64_MIN (-9223372036854775808L)\n"
"\n"
"#define INT_LEAST8_MAX (127)\n"
"#define INT_LEAST16_MAX (32767)\n"
"#define INT_LEAST32_MAX (2147483647)\n"
"#define INT_LEAST64_MAX (9223372036854775807L)\n"
"\n"
"#define UINT_LEAST8_MAX (255)\n"
"#define UINT_LEAST16_MAX (65535)\n"
"#define UINT_LEAST32_MAX (4294967295U)\n"
"#define UINT_LEAST64_MAX (18446744073709551615UL)\n"
"\n"
"#define INT_FAST8_MIN (-128)\n"
"#define INT_FAST16_MIN (-9223372036854775808L)\n"
"#define INT_FAST32_MIN (-9223372036854775808L)\n"
"#define INT_FAST64_MIN (-9223372036854775808L)\n"
"\n"
"#define INT_FAST8_MAX (127)\n"
"#define INT_FAST16_MAX (9223372036854775807L)\n"
"#define INT_FAST32_MAX (9223372036854775807L)\n"
"#define INT_FAST64_MAX (9223372036854775807L)\n"
"\n"
"#define UINT_FAST8_MAX (255)\n"
"#define UINT_FAST16_MAX (18446744073709551615UL)\n"
"#define UINT_FAST32_MAX (18446744073709551615UL)\n"
"#define UINT_FAST64_MAX (18446744073709551615UL)\n"
"\n"
"#define INTPTR_MIN (-9223372036854775808L)\n"
"#define INTPTR_MAX (9223372036854775807L)\n"
"#define UINTPTR_MAX (18446744073709551615UL)\n"
"\n"
"#define INTMAX_MIN (-9223372036854775808L)\n"
"#define INTMAX_MAX (9223372036854775807L)\n"
"#define UINTMAX_MAX (18446744073709551615UL)\n"
"\n"
"#define PTRDIFF_MIN (-9223372036854775808L)\n"
"#define PTRDIFF_MAX (9223372036854775807L)\n"
"\n"
"#define SIZE_MAX (18446744073709551615UL)\n"
"\n"
"/* For signed wchar_t and wint_t: */\n"
"#define WCHAR_MIN INT32_MIN\n"
"#define WCHAR_MAX INT32_MAX\n"
"#define WINT_MIN WCHAR_MIN\n"
"#define WINT_MAX WCHAR_MAX\n"
"\n"
"#define INT8_C(value) value\n"
"#define INT16_C(value) value\n"
"#define INT32_C(value) value\n"
"#define INT64_C(value) value##L\n"
"\n"
"#define UINT8_C(value) value\n"
"#define UINT16_C(value) value\n"
"#define UINT32_C(value) value##U\n"
"#define UINT64_C(value) value##UL\n"
"\n"
"#define INTMAX_C(value) value##L\n"
"#define UINTMAX_C(value) value##UL\n"
"\n"
"#endif /* #ifndef _STDINT_H */\n";

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
x86_64 ABI target specific code.
*/
@ -8,7 +8,7 @@
enum add_arg_class { NO_CLASS = MIR_T_BOUND + 1, X87UP_CLASS };
#ifndef _WIN32
#ifndef _WIN64
#define MAX_QWORDS 2
#else
#define MAX_QWORDS 1
@ -44,7 +44,7 @@ static int classify_arg (c2m_ctx_t c2m_ctx, struct type *type, MIR_type_t types[
if (n_qwords > MAX_QWORDS) return 0; /* too big aggregate */
#ifndef _WIN32
#ifndef _WIN64
for (i = 0; i < n_qwords; i++) types[i] = (MIR_type_t) NO_CLASS;
switch (type->mode) {
@ -112,6 +112,16 @@ static void target_init_arg_vars (c2m_ctx_t c2m_ctx, target_arg_info_t *arg_info
arg_info->n_iregs = arg_info->n_fregs = 0;
}
static const char *qword_name (c2m_ctx_t c2m_ctx, const char *name, int num) {
char prefix[50];
sprintf (prefix, "Q%u_", num);
VARR_TRUNC (char, temp_string, 0);
add_to_temp_string (c2m_ctx, prefix);
add_to_temp_string (c2m_ctx, name);
return uniq_cstr (c2m_ctx, VARR_ADDR (char, temp_string)).s;
}
static void update_last_qword_type (c2m_ctx_t c2m_ctx, struct type *type,
MIR_type_t qword_types[MAX_QWORDS], int n) {
size_t last_size, size = type_size (c2m_ctx, type);
@ -316,44 +326,21 @@ static int process_aggregate_arg (c2m_ctx_t c2m_ctx, struct type *arg_type,
return n_qwords;
}
static MIR_type_t get_blk_type (int n_qwords, MIR_type_t *qword_types) {
int n, n_iregs = 0, n_fregs = 0;
assert (n_qwords <= 2);
if (n_qwords == 0) return MIR_T_BLK;
for (n = 0; n < n_qwords; n++) { /* start from the last qword */
switch ((int) qword_types[n]) {
case MIR_T_I8:
case MIR_T_I16:
case MIR_T_I32:
case MIR_T_I64: n_iregs++; break;
case MIR_T_F:
case MIR_T_D: n_fregs++; break;
case X87UP_CLASS:
case MIR_T_LD: return MIR_T_BLK;
default: assert (FALSE);
}
}
if (n_iregs == n_qwords) return MIR_T_BLK + 1;
if (n_fregs == n_qwords) return MIR_T_BLK + 2;
if (qword_types[0] == MIR_T_F || qword_types[0] == MIR_T_D) return MIR_T_BLK + 4;
return MIR_T_BLK + 3;
}
static MIR_type_t target_get_blk_type (c2m_ctx_t c2m_ctx, struct type *arg_type) {
MIR_type_t qword_types[MAX_QWORDS];
int n_qwords = classify_arg (c2m_ctx, arg_type, qword_types, FALSE);
assert (arg_type->mode == TM_STRUCT || arg_type->mode == TM_UNION);
return get_blk_type (n_qwords, qword_types);
}
static void target_add_arg_proto (c2m_ctx_t c2m_ctx, const char *name, struct type *arg_type,
target_arg_info_t *arg_info, VARR (MIR_var_t) * arg_vars) {
MIR_var_t var;
MIR_type_t type;
MIR_type_t qword_types[MAX_QWORDS];
int n_qwords = process_aggregate_arg (c2m_ctx, arg_type, arg_info, qword_types);
int n, n_qwords = process_aggregate_arg (c2m_ctx, arg_type, arg_info, qword_types);
if (n_qwords != 0) {
for (n = 0; n < n_qwords; n++) {
var.name = qword_name (c2m_ctx, name, n);
var.type = promote_mir_int_type (qword_types[n]);
VARR_PUSH (MIR_var_t, arg_vars, var);
}
return;
}
/* pass aggregates on the stack and pass by value for others: */
var.name = name;
if (arg_type->mode != TM_STRUCT && arg_type->mode != TM_UNION) {
@ -364,7 +351,7 @@ static void target_add_arg_proto (c2m_ctx_t c2m_ctx, const char *name, struct ty
else if (type != MIR_T_LD)
arg_info->n_iregs++;
} else {
var.type = get_blk_type (n_qwords, qword_types);
var.type = MIR_T_BLK;
var.size = type_size (c2m_ctx, arg_type);
}
VARR_PUSH (MIR_var_t, arg_vars, var);
@ -376,8 +363,22 @@ static void target_add_call_arg_op (c2m_ctx_t c2m_ctx, struct type *arg_type,
MIR_context_t ctx = c2m_ctx->ctx;
MIR_type_t type;
MIR_type_t qword_types[MAX_QWORDS];
int n_qwords = process_aggregate_arg (c2m_ctx, arg_type, arg_info, qword_types);
op_t temp;
int n, n_qwords = process_aggregate_arg (c2m_ctx, arg_type, arg_info, qword_types);
if (n_qwords != 0) {
assert (arg.mir_op.mode == MIR_OP_MEM);
arg = mem_to_address (c2m_ctx, arg, TRUE);
for (n = 0; n < n_qwords; n++) {
type = qword_types[n];
temp = get_new_temp (c2m_ctx, promote_mir_int_type (type));
MIR_append_insn (ctx, curr_func,
MIR_new_insn (ctx, tp_mov (type), temp.mir_op,
MIR_new_mem_op (ctx, type, 8 * n, arg.mir_op.u.reg, 0, 1)));
VARR_PUSH (MIR_op_t, call_ops, temp.mir_op);
}
return;
}
/* pass aggregates on the stack and pass by value for others: */
if (arg_type->mode != TM_STRUCT && arg_type->mode != TM_UNION) {
type = get_mir_type (c2m_ctx, arg_type);
@ -389,13 +390,40 @@ static void target_add_call_arg_op (c2m_ctx_t c2m_ctx, struct type *arg_type,
} else {
assert (arg.mir_op.mode == MIR_OP_MEM);
arg = mem_to_address (c2m_ctx, arg, TRUE);
type = get_blk_type (n_qwords, qword_types);
VARR_PUSH (MIR_op_t, call_ops,
MIR_new_mem_op (ctx, type, type_size (c2m_ctx, arg_type), arg.mir_op.u.reg, 0, 1));
MIR_new_mem_op (ctx, MIR_T_BLK, type_size (c2m_ctx, arg_type), arg.mir_op.u.reg, 0,
1));
}
}
static int target_gen_gather_arg (c2m_ctx_t c2m_ctx, const char *name, struct type *arg_type,
decl_t param_decl, target_arg_info_t *arg_info) {
return FALSE;
gen_ctx_t gen_ctx = c2m_ctx->gen_ctx;
MIR_context_t ctx = c2m_ctx->ctx;
MIR_type_t type;
reg_var_t reg_var;
MIR_type_t qword_types[MAX_QWORDS];
int i, n_qwords = process_aggregate_arg (c2m_ctx, arg_type, arg_info, qword_types);
if (arg_type->mode != TM_STRUCT && arg_type->mode != TM_UNION) {
assert (n_qwords == 0);
type = get_mir_type (c2m_ctx, arg_type);
if (type == MIR_T_F || type == MIR_T_D)
arg_info->n_fregs++;
else if (type != MIR_T_LD)
arg_info->n_iregs++;
return FALSE;
}
if (n_qwords == 0) return FALSE;
for (i = 0; i < n_qwords; i++) {
assert (!param_decl->reg_p);
type = qword_types[i];
reg_var = get_reg_var (c2m_ctx, type, qword_name (c2m_ctx, name, i));
MIR_append_insn (ctx, curr_func,
MIR_new_insn (ctx, tp_mov (type),
MIR_new_mem_op (ctx, type, param_decl->offset + 8 * i,
MIR_reg (ctx, FP_NAME, curr_func->u.func), 0, 1),
MIR_new_reg_op (ctx, reg_var.reg)));
}
return TRUE;
}

@ -1,23 +1,19 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#include "../mirc.h"
#ifndef _WIN32
#include "mirc_x86_64_linux.h"
#include "mirc-x86_64-linux.h"
#else
#include "mirc_x86_64_win.h"
#include "mirc-x86_64-win.h"
#endif
#include "mirc_x86_64_float.h"
#include "mirc_x86_64_limits.h"
#include "mirc_x86_64_stdarg.h"
#include "mirc_x86_64_stdint.h"
#include "mirc_x86_64_stddef.h"
static string_include_t standard_includes[]
= {{NULL, mirc}, {NULL, x86_64_mirc}, TARGET_STD_INCLUDES};
static const char *standard_includes[] = {mirc, x86_64_mirc};
static const char *standard_include_dirs[] = {"include/mirc/", "include/mirc/x86-64/"};
#define MAX_ALIGNMENT 16

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2018-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2018-2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
#include <stdint.h>
@ -9,11 +9,7 @@
typedef int8_t mir_schar;
typedef int16_t mir_short;
typedef int32_t mir_int;
#ifdef _WIN32
typedef int32_t mir_long;
#else
typedef int64_t mir_long;
#endif
typedef int64_t mir_llong;
#define MIR_SCHAR_MIN INT8_MIN
@ -22,41 +18,21 @@ typedef int64_t mir_llong;
#define MIR_SHORT_MAX INT16_MAX
#define MIR_INT_MIN INT32_MIN
#define MIR_INT_MAX INT32_MAX
#ifdef _WIN32
#define MIR_LONG_MIN INT32_MIN
#define MIR_LONG_MAX INT32_MAX
#else
#define MIR_LONG_MIN INT64_MIN
#define MIR_LONG_MAX INT64_MAX
#endif
#define MIR_LLONG_MIN INT64_MIN
#define MIR_LLONG_MAX INT64_MAX
typedef uint8_t mir_uchar;
typedef uint16_t mir_ushort;
typedef uint32_t mir_uint;
typedef uint64_t mir_ullong;
#ifdef _WIN32
typedef uint32_t mir_ulong;
typedef uint16_t mir_wchar;
#else
typedef uint64_t mir_ulong;
typedef uint32_t mir_wchar;
#endif
typedef uint16_t mir_char16;
typedef uint32_t mir_char32;
typedef uint64_t mir_ullong;
#define MIR_UCHAR_MAX UINT8_MAX
#define MIR_USHORT_MAX UINT16_MAX
#define MIR_UINT_MAX UINT32_MAX
#ifdef _WIN32
#define MIR_ULONG_MAX UINT32_MAX
#define MIR_WCHAR_MAX UINT16_MAX
#else
#define MIR_ULONG_MAX UINT64_MAX
#define MIR_WCHAR_MAX UINT32_MAX
#endif
#define MIR_WCHAR_MIN 0
#define MIR_ULLONG_MAX UINT64_MAX
typedef mir_schar mir_char;
@ -65,11 +41,7 @@ typedef mir_schar mir_char;
typedef float mir_float;
typedef double mir_double;
#ifdef _WIN32
typedef double mir_ldouble;
#else
typedef long double mir_ldouble;
#endif
typedef uint8_t mir_bool;
typedef int64_t mir_ptrdiff_t;

@ -1,5 +1,5 @@
/* This file is a part of MIR project.
Copyright (C) 2019-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
Copyright (C) 2019-2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char x86_64_mirc[]
@ -92,7 +92,6 @@ static char x86_64_mirc[]
"#define __unix__ 1\n"
#elif defined(__APPLE__)
"#define __APPLE__ 1\n"
"#define __DARWIN_OS_INLINE static inline\n"
"typedef struct {\n"
" unsigned int gp_offset;\n"
" unsigned int fp_offset;\n"

@ -1,116 +1,101 @@
/* This file is a part of MIR project.
Copyright (C) 2019-2021 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char x86_64_mirc[]
= "#define __amd64 1\n"
"#define __amd64__ 1\n"
"#define __x86_64 1\n"
"#define __x86_64__ 1\n"
"#define _M_AMD64 1\n"
"#define _M_X64 1\n"
"\n"
"#define __SIZEOF_DOUBLE__ 8\n"
"#define __SIZEOF_FLOAT__ 4\n"
"#define __SIZEOF_INT__ 4\n"
#if !defined(_WIN32) && __SIZEOF_LONG_DOUBLE__ == 16
"#define __SIZEOF_LONG_DOUBLE__ 16\n"
#else
"#define __SIZEOF_LONG_DOUBLE__ 8\n"
#endif
"#define __SIZEOF_LONG_LONG__ 8\n"
"#define __SIZEOF_LONG__ 4\n"
"#define __SIZEOF_POINTER__ 8\n"
"#define __SIZEOF_PTRDIFF_T__ 8\n"
"#define __SIZEOF_SHORT__ 2\n"
"#define __SIZEOF_SIZE_T__ 8\n"
"\n"
"#define __BYTE_ORDER__ 1234\n"
"#define __ORDER_LITTLE_ENDIAN__ 1234\n"
"#define __ORDER_BIG_ENDIAN__ 4321\n"
"\n"
"/* Some type macros: */\n"
"#define __SIZE_TYPE__ long long unsigned int\n"
"#define __PTRDIFF_TYPE__ long long int\n"
"#define __INTMAX_TYPE__ long long int\n"
"#define __UINTMAX_TYPE__ long long unsigned int\n"
"#define __INT8_TYPE__ signed char\n"
"#define __INT16_TYPE__ short\n"
"#define __INT32_TYPE__ int\n"
"#define __INT64_TYPE__ long long int\n"
"#define __UINT8_TYPE__ unsigned char\n"
"#define __UINT16_TYPE__ unsigned short\n"
"#define __UINT32_TYPE__ unsigned int\n"
"#define __UINT64_TYPE__ long long unsigned int\n"
"#define __INTPTR_TYPE__ long long int\n"
"#define __UINTPTR_TYPE__ long long unsigned int\n"
"\n"
"#define __int8 __INT8_TYPE__\n"
"#define __int16 __INT16_TYPE__\n"
"#define __int32 __INT32_TYPE__\n"
"#define __int64 __INT64_TYPE__\n"
"\n"
"#define __ptr32\n"
"#define __ptr64\n"
"#define __forceinline inline\n"
"#define __cdecl\n"
"#define __pragma(p)\n"
"#define __declspec(attr)\n"
"#define __unaligned\n"
"\n"
"#define __CHAR_BIT__ 8\n"
"#define __INT8_MAX__ 127\n"
"#define __INT16_MAX__ 32767\n"
"#define __INT32_MAX__ 2147483647\n"
"#define __INT64_MAX__ 9223372036854775807LL\n"
"#define __UINT8_MAX__ (__INT8_MAX__ * 2u + 1u)\n"
"#define __UINT16_MAX__ (__INT16_MAX__ * 2u + 1u)\n"
"#define __UINT32_MAX__ (__INT32_MAX__ * 2u + 1u)\n"
"#define __UINT64_MAX__ (__INT64_MAX__ * 2u + 1u)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
"#define __LONG_MAX__ __INT32_MAX__\n"
"#define __LONG_LONG_MAX__ __INT64_MAX__\n"
"#define __SIZE_MAX__ __UINT64_MAX__\n"
"#define __PTRDIFF_MAX__ __INT64_MAX__\n"
"#define __INTMAX_MAX__ __INT64_MAX__\n"
"#define __UINTMAX_MAX__ __UINT64_MAX__\n"
"#define __INTPTR_MAX__ __INT64_MAX__\n"
"#define __UINTPTR_MAX__ __UINT64_MAX__\n"
"\n"
"#define __FLT_MIN_EXP__ (-125)\n"
"#define __FLT_MAX_EXP__ 128\n"
"#define __FLT_DIG__ 6\n"
"#define __FLT_DECIMAL_DIG__ 9\n"
"#define __FLT_MANT_DIG__ 24\n"
"#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F\n"
"#define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F\n"
"#define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F\n"
"\n"
"#define __DBL_MIN_EXP__ (-1021)\n"
"#define __DBL_MAX_EXP__ 1024\n"
"#define __DBL_DIG__ 15\n"
"#define __DBL_DECIMAL_DIG__ 17\n"
"#define __DBL_MANT_DIG__ 53\n"
"#define __DBL_MAX__ ((double) 1.79769313486231570814527423731704357e+308L)\n"
"#define __DBL_MIN__ ((double) 2.22507385850720138309023271733240406e-308L)\n"
"#define __DBL_EPSILON__ ((double) 2.22044604925031308084726333618164062e-16L)\n"
"\n"
"typedef unsigned short char16_t;\n"
"typedef unsigned int char32_t;\n"
"\n"
"#define WIN32 1\n"
"#define _WIN32 1\n"
"#define __WIN32 1\n"
"#define __WIN32__ 1\n"
"#define WIN64 1\n"
"#define _WIN64 1\n"
"#define __WIN64 1\n"
"#define __WIN64__ 1\n"
"#define WINNT 1\n"
"#define __WINNT 1\n"
"#define __WINNT__ 1\n"
"#define __MSVCRT__ 1\n"
"\n"
"void *alloca (long long unsigned);\n";
/* This file is a part of MIR project.
Copyright (C) 2019-2020 Vladimir Makarov <vmakarov.gcc@gmail.com>.
*/
static char x86_64_mirc[]
= "#define __amd64 1\n"
"#define __amd64__ 1\n"
"#define __x86_64 1\n"
"#define __x86_64__ 1\n"
"\n"
"#define __SIZEOF_DOUBLE__ 8\n"
"#define __SIZEOF_FLOAT__ 4\n"
"#define __SIZEOF_INT__ 4\n"
#if __SIZEOF_LONG_DOUBLE__ == 16
"#define __SIZEOF_LONG_DOUBLE__ 16\n"
#else
"#define __SIZEOF_LONG_DOUBLE__ 8\n"
#endif
"#define __SIZEOF_LONG_LONG__ 8\n"
"#define __SIZEOF_LONG__ 4\n"
"#define __SIZEOF_POINTER__ 8\n"
"#define __SIZEOF_PTRDIFF_T__ 8\n"
"#define __SIZEOF_SHORT__ 2\n"
"#define __SIZEOF_SIZE_T__ 8\n"
"\n"
"#define __BYTE_ORDER__ 1234\n"
"#define __ORDER_LITTLE_ENDIAN__ 1234\n"
"#define __ORDER_BIG_ENDIAN__ 4321\n"
"\n"
"/* Some type macros: */\n"
"#define __SIZE_TYPE__ long long unsigned int\n"
"#define __PTRDIFF_TYPE__ long long int\n"
"#define __INTMAX_TYPE__ long long int\n"
"#define __UINTMAX_TYPE__ long long unsigned int\n"
"#define __INT8_TYPE__ signed char\n"
"#define __INT16_TYPE__ short\n"
"#define __INT32_TYPE__ int\n"
"#define __INT64_TYPE__ long long int\n"
"#define __UINT8_TYPE__ unsigned char\n"
"#define __UINT16_TYPE__ unsigned short\n"
"#define __UINT32_TYPE__ unsigned int\n"
"#define __UINT64_TYPE__ long long unsigned int\n"
"#define __INTPTR_TYPE__ long long int\n"
"#define __UINTPTR_TYPE__ long long unsigned int\n"
"\n"
"#define __CHAR_BIT__ 8\n"
"#define __INT8_MAX__ 127\n"
"#define __INT16_MAX__ 32767\n"
"#define __INT32_MAX__ 2147483647\n"
"#define __INT64_MAX__ 9223372036854775807LL\n"
"#define __UINT8_MAX__ (__INT8_MAX__ * 2u + 1u)\n"
"#define __UINT16_MAX__ (__INT16_MAX__ * 2u + 1u)\n"
"#define __UINT32_MAX__ (__INT32_MAX__ * 2u + 1u)\n"
"#define __UINT64_MAX__ (__INT64_MAX__ * 2u + 1u)\n"
"#define __SCHAR_MAX__ __INT8_MAX__\n"
"#define __SHRT_MAX__ __INT16_MAX__\n"
"#define __INT_MAX__ __INT32_MAX__\n"
"#define __LONG_MAX__ __INT32_MAX__\n"
"#define __LONG_LONG_MAX__ __INT64_MAX__\n"
"#define __SIZE_MAX__ __UINT64_MAX__\n"
"#define __PTRDIFF_MAX__ __INT64_MAX__\n"
"#define __INTMAX_MAX__ __INT64_MAX__\n"
"#define __UINTMAX_MAX__ __UINT64_MAX__\n"
"#define __INTPTR_MAX__ __INT64_MAX__\n"
"#define __UINTPTR_MAX__ __UINT64_MAX__\n"
"\n"
"#define __FLT_MIN_EXP__ (-125)\n"
"#define __FLT_MAX_EXP__ 128\n"
"#define __FLT_DIG__ 6\n"
"#define __FLT_DECIMAL_DIG__ 9\n"
"#define __FLT_MANT_DIG__ 24\n"
"#define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F\n"
"#define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F\n"
"#define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F\n"
"\n"
"#define __DBL_MIN_EXP__ (-1021)\n"
"#define __DBL_MAX_EXP__ 1024\n"
"#define __DBL_DIG__ 15\n"
"#define __DBL_DECIMAL_DIG__ 17\n"
"#define __DBL_MANT_DIG__ 53\n"
"#define __DBL_MAX__ ((double) 1.79769313486231570814527423731704357e+308L)\n"
"#define __DBL_MIN__ ((double) 2.22507385850720138309023271733240406e-308L)\n"
"#define __DBL_EPSILON__ ((double) 2.22044604925031308084726333618164062e-16L)\n"
"\n"
"typedef unsigned short char16_t;\n"
"typedef unsigned int char32_t;\n"
"\n"
"#define WIN32 1\n"
"#define _WIN32 1\n"
"#define __WIN32 1\n"
"#define __WIN32__ 1\n"
"#define WIN64 1\n"
"#define _WIN64 1\n"
"#define __WIN64 1\n"
"#define __WIN64__ 1\n"
"#define WINNT 1\n"
"#define __WINNT 1\n"
"#define __WINNT__ 1\n"
"#define __MSVCRT__ 1\n"
"\n"
"void *alloca (long long unsigned);\n";

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save