Skip to content

Commit

Permalink
Compiler options cleanup (#10)
Browse files Browse the repository at this point in the history
* Removed compiler -f and -W flags

* Removed all warnings and added -Wall -Werror

* Reverted to -fno-rtti -fno-exceptions to save Flash space
  • Loading branch information
orenskl authored Jan 18, 2024
1 parent 2d65871 commit 8471f44
Show file tree
Hide file tree
Showing 43 changed files with 453 additions and 183 deletions.
9 changes: 0 additions & 9 deletions .vscode/c_cpp_properties.json

This file was deleted.

2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
"cSpell.words": [
"Pico"
],
"cmake.mergedCompileCommands": "${workspaceFolder}/build/merged_compile_commands.json",
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/merged_compile_commands.json"
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
26 changes: 18 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ if (${TARGET} STREQUAL PICO)
pico_sdk_init()
endif()

ExternalProject_Add(libjvm SOURCE_DIR ${CMAKE_SOURCE_DIR}/lib
CMAKE_ARGS -DLIBJVM_INSTALL_DIR=${CMAKE_BINARY_DIR}
-DLIBJVM_VERSION=${PROJECT_VERSION}
-DCMAKE_BUILD_TYPE:STRING=MinSizeRel
-DTARGET:STRING=${TARGET}
USES_TERMINAL_BUILD TRUE
ExternalProject_Add(jvm_lib SOURCE_DIR ${CMAKE_SOURCE_DIR}/lib
CMAKE_ARGS -DLIBJVM_INSTALL_DIR:STRING=${CMAKE_BINARY_DIR}
-DLIBJVM_VERSION:STRING=${PROJECT_VERSION}
-DCMAKE_BUILD_TYPE:STRING=MinSizeRel
-DTARGET:STRING=${TARGET}
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE
USES_TERMINAL_BUILD TRUE
BUILD_ALWAYS TRUE
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/jvm_lib-prefix/src/jvm_lib-build/libjvm.a
)
ExternalProject_Get_property(jvm_lib BINARY_DIR)
add_library(jvm STATIC IMPORTED)
set_property(TARGET jvm PROPERTY IMPORTED_LOCATION ${BINARY_DIR}/libjvm.a)
add_dependencies(jvm jvm_lib)

if (${TARGET} STREQUAL PICO)
set(PJVM_SOURCES src/pico/Main.cpp src/pico/OS.cpp src/pico/Natives.cpp)
Expand All @@ -42,8 +49,11 @@ if (${TARGET} STREQUAL LINUX)
set(PJVM_SOURCES src/linux/Main.cpp src/linux/OS.cpp)
endif()

#add_library(libjvm STATIC IMPORTED)
#set_property(TARGET libjvm PROPERTY IMPORTED_LOCATION ${BINARY_DIR}/libjvm.a)
#add_dependencies(jvmprojlib jvmproj)

add_executable(pjvm ${PJVM_SOURCES})
add_dependencies(pjvm libjvm)

if (${TARGET} STREQUAL PICO)
set(PJVM_INCLUDE_OS_DIRS lib/src/vm/os/pico)
Expand All @@ -68,7 +78,7 @@ if (${TARGET} STREQUAL PICO)
endif()
if (${TARGET} STREQUAL LINUX)
target_compile_definitions(pjvm PRIVATE PRODUCT)
target_compile_options(pjvm PRIVATE -m32 -fpermissive)
target_compile_options(pjvm PRIVATE -m32)
target_link_options(pjvm PRIVATE -m32)
endif()

Expand Down
27 changes: 8 additions & 19 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ include(ExternalProject)
project(jvm)

ExternalProject_Add(romgen SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/romgen
CMAKE_ARGS -DROMGEN_INSTALL_DIR=${CMAKE_BINARY_DIR}
-DROMGEN_VERSION=${LIBJVM_VERSION}
CMAKE_ARGS -DROMGEN_VERSION=${LIBJVM_VERSION}
-DCMAKE_BUILD_TYPE:STRING=Release
USES_TERMINAL_BUILD TRUE
BUILD_ALWAYS TRUE
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/romgen-prefix/src/romgen-build/romgen
INSTALL_COMMAND cmake -E echo "Skipping install step."
)
ExternalProject_Get_property(romgen BINARY_DIR)

if (${TARGET} STREQUAL PICO)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
Expand Down Expand Up @@ -131,14 +134,14 @@ set(JVM_CLASSES
)

add_custom_command(OUTPUT ROMImage.cpp
DEPENDS ${JVM_CLASSES}
DEPENDS ${JVM_CLASSES} ${BINARY_DIR}/romgen
COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/classes
COMMAND javac ARGS -source 1.4 -target 1.4 -d ${CMAKE_BINARY_DIR}/classes -bootclasspath ${CMAKE_BINARY_DIR}/classes ${JVM_CLASSES}
COMMAND ${CMAKE_SOURCE_DIR}/tools/preverify/bin/preverify ARGS -d ${CMAKE_BINARY_DIR}/classes.preverify ${CMAKE_BINARY_DIR}/classes
COMMAND cd ARGS ${CMAKE_BINARY_DIR}/classes.preverify
COMMAND jar ARGS -cfM0 ${CMAKE_BINARY_DIR}/classes.jar .
COMMAND cd ARGS ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_BINARY_DIR}/romgen
COMMAND ${BINARY_DIR}/romgen
-cp ${CMAKE_BINARY_DIR}/classes.jar
+RewriteROMConstantPool
+EnableAllROMOptimizations
Expand Down Expand Up @@ -422,20 +425,7 @@ target_include_directories(jvm PRIVATE

target_compile_definitions(jvm PRIVATE JVM_RELEASE_VERSION="${LIBJVM_VERSION}" ROMIZING=1 PRODUCT)

set(JVM_COMPILE_OPTIONS -Wuninitialized
-Wreturn-type
-Wcomment
-Wparentheses
-Wformat
-Wno-narrowing
-fstrict-aliasing
-fpermissive
-fno-gnu-keywords
-fno-operator-names
-fno-exceptions
-fno-optional-diags
-fno-rtti
)
set(JVM_COMPILE_OPTIONS -Wall -Werror -fno-rtti -fno-exceptions)

if (${TARGET} STREQUAL PICO)
target_compile_definitions(jvm PRIVATE PICO)
Expand All @@ -446,7 +436,6 @@ if (${TARGET} STREQUAL LINUX)
target_compile_options(jvm PRIVATE -m32 ${JVM_COMPILE_OPTIONS})
endif()

install(TARGETS jvm DESTINATION ${LIBJVM_INSTALL_DIR})
install(FILES ${CMAKE_BINARY_DIR}/classes.jar DESTINATION ${LIBJVM_INSTALL_DIR})
if (${TARGET} STREQUAL PICO)
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc DESTINATION ${LIBJVM_INSTALL_DIR})
Expand Down
78 changes: 43 additions & 35 deletions lib/src/vm/cpu/c/FloatSupport_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
* - remove all ASM
*/

/*
* Modified (C) Oren Sokoler (https://github.com/orenskl)
*/

#include "jvmconfig.h"

#include "BuildFlags.hpp"
Expand Down Expand Up @@ -84,19 +88,20 @@ extern "C" {

jdouble jvm_l2d(jlong x) { return (jdouble)x; }

jint jvm_f2i(jfloat x) {
jint jvm_f2i(jfloat x)
{
jint rv, bits = float_bits(x);

if ((bits & 0x7FFFFFFF) >= 0x4F000000) {
if ((bits >= F_L_POS_NAN && bits <= F_H_POS_NAN) ||
(bits >= F_L_NEG_NAN && bits <= F_H_NEG_NAN)) {
rv = 0; /* NaN */
if ((bits >= (jint)F_L_POS_NAN && bits <= (jint)F_H_POS_NAN) ||
(bits >= (jint)F_L_NEG_NAN && bits <= (jint)F_H_NEG_NAN)) {
rv = 0; /* NaN */
} else if (bits > 0) {
rv = MAX_INT; /* +Infinity */
rv = MAX_INT; /* +Infinity */
} else if (bits < 0) {
rv = MIN_INT; /* -Infinity */
rv = MIN_INT; /* -Infinity */
} else {
rv = 0;
rv = 0;
}
} else {
rv = (jint)x;
Expand All @@ -106,28 +111,29 @@ extern "C" {

jdouble jvm_f2d(jfloat x) { return (jdouble)x; }

jlong jvm_f2l(jfloat x) {
jlong jvm_f2l(jfloat x)
{
jint bits = float_bits(x);
jlong rv;
jlong rv;
/*
* 0x5F000000 = (0x4F000000 + 2E28) magic number for Float
* any number >= this number will be a special case
*/
if ((bits & 0x7FFFFFFF) >= 0x5F000000) {
if ((bits >= F_L_POS_NAN && bits <= F_H_POS_NAN) ||
(bits >= F_L_NEG_NAN && bits <= F_H_NEG_NAN)) {
rv = 0; /* NaN */
if ((bits >= (jint)F_L_POS_NAN && bits <= (jint)F_H_POS_NAN) ||
(bits >= (jint)F_L_NEG_NAN && bits <= (jint)F_H_NEG_NAN)) {
rv = 0; /* NaN */
} else if (bits > 0) {
rv = MAX_LONG; /* +Infinity */
rv = MAX_LONG; /* +Infinity */
} else if (bits < 0) {
rv = MIN_LONG; /* -Infinity */
rv = MIN_LONG; /* -Infinity */
} else {
rv = 0;
rv = 0;
}
} else {
rv = (jlong)x;
}
return rv;
return rv;
}

jfloat jvm_i2f(jint x) { return (jfloat)x; }
Expand All @@ -136,52 +142,54 @@ extern "C" {

jfloat jvm_l2f(jlong x) { return (jfloat)x; }

jfloat jvm_d2f(jdouble x) { return (jfloat)x; }
jfloat jvm_d2f(jdouble x) { return (jfloat)x; }

jlong jvm_d2l(jdouble x) {
jlong jvm_d2l(jdouble x)
{
jlong bits = double_bits(x);
jlong rv;
/*
* 0x43E0000000000000L = (0x41E0000000000000L + 2e57) magic number
* for Float any number >= this number will be a special case
*/
if ((bits & JVM_LL(0x7FFFFFFFFFFFFFFF)) >= JVM_LL(0x43E0000000000000)) {
if ((bits >= D_L_POS_NAN && bits <= D_H_POS_NAN) ||
(bits >= D_L_NEG_NAN && bits <= D_H_NEG_NAN)) {
rv = 0; /* NaN */
if ((bits >= (jlong)D_L_POS_NAN && bits <= (jlong)D_H_POS_NAN) ||
(bits >= (jlong)D_L_NEG_NAN && bits <= (jlong)D_H_NEG_NAN)) {
rv = 0; /* NaN */
} else if (bits > 0) {
rv = MAX_LONG; /* +Infinity */
rv = MAX_LONG; /* +Infinity */
} else if (bits < 0) {
rv = MIN_LONG; /* -Infinity */
rv = MIN_LONG; /* -Infinity */
} else {
rv = 0;
rv = 0;
}
} else {
rv = (jlong)x;
}
return rv;
return rv;
}

jint jvm_d2i(jdouble x) {
jint jvm_d2i(jdouble x)
{
jlong bits = double_bits(x);
jint rv;
if ((bits & JVM_LL(0x7FFFFFFFFFFFFFFF)) >= JVM_LL(0x41E0000000000000)) {
if ((bits >= D_L_POS_NAN && bits <= D_H_POS_NAN) ||
(bits >= D_L_NEG_NAN && bits <= D_H_NEG_NAN)) {
rv = 0; /* NaN */
if ((bits >= (jlong)D_L_POS_NAN && bits <= (jlong)D_H_POS_NAN) ||
(bits >= (jlong)D_L_NEG_NAN && bits <= (jlong)D_H_NEG_NAN)) {
rv = 0; /* NaN */
} else if (bits > 0) {
rv = MAX_INT; /* +Infinity */
rv = MAX_INT; /* +Infinity */
} else if (bits < 0) {
rv = MIN_INT; /* -Infinity */
rv = MIN_INT; /* -Infinity */
} else {
rv = 0;
rv = 0;
}
} else {
rv = (jint)x;
}
return rv;
return rv;
}

jint jvm_fcmpg(jfloat x, jfloat y) {
return ((x > y) ? 1 :
(x == y) ? 0 :
Expand Down
14 changes: 9 additions & 5 deletions lib/src/vm/cpu/c/Interpreter_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
* information or have any questions.
*/

/*
* Modified (C) Oren Sokoler (https://github.com/orenskl)
*/

#include "jvmconfig.h"

#include "BuildFlags.hpp"
Expand Down Expand Up @@ -1545,8 +1549,7 @@ enum {

_jvm_in_quick_native_method = 1;
jint r1, r2;
va_list ap;
invoke_native_entry(native_ptr, return_type, 0, ap, r1, r2);
invoke_native_entry(native_ptr, return_type, 0, va_list(), r1, r2);
_jvm_in_quick_native_method = 0;

if (_jvm_quick_native_exception != NULL) {
Expand Down Expand Up @@ -2279,6 +2282,7 @@ enum {
case T_DOUBLE : DOUBLE_PUSH(rv.double_val); break;
case T_OBJECT : OBJ_PUSH(rv.object_val); break;
case T_VOID : break;
default : break;
}
}

Expand Down Expand Up @@ -3081,7 +3085,7 @@ enum {
return;
}
jint rv = val1;
if (val1 != 0x80000000 || val2 != -1) {
if (val1 != (jint)0x80000000 || val2 != -1) {
rv /= val2;
}
PUSH(rv);
Expand Down Expand Up @@ -3121,7 +3125,7 @@ enum {
interpreter_throw_ArithmeticException();
return;
}
if (val1 == 0x80000000 && val2 == -1) {
if (val1 == (jint)0x80000000 && val2 == -1) {
PUSH(val1 % 1);
} else {
PUSH(val1 % val2);
Expand Down Expand Up @@ -4511,7 +4515,7 @@ static void init() {
#endif

// make it clean
for (int i=0; i < ARRAY_SIZE(interpreter_dispatch_table); i++) {
for (unsigned int i=0; i < ARRAY_SIZE(interpreter_dispatch_table); i++) {
interpreter_dispatch_table[i] = &undef_bc;
}
// init bytecodes dispatch table
Expand Down
Loading

0 comments on commit 8471f44

Please sign in to comment.