Skip to content

Commit ab46d13

Browse files
author
Timothy Harvey
committed
These changes are designed to enable the TI compilers to compile
Jerryscript. The changes include: CMakeLists.txt: we added conditionals around GCC-specific flags, added support for TI flags, and removed the always-on debugging flag (-g) /toolchain_mcu_tim4f.cmake: new toolchain file uses TI-specific parameters jerry-api.h: the sys/types.h file was #include'd but never used, so we removed it jrt-types.h: ditto jerry-port-default-date.c: the TI toolchain doesn't include sys/time.h, so we guarded uses of the package ecma-objects-general.c: added initialization that Travis (the auto-checking tool) required JerryScript-DCO-1.0-Signed-off-by: Timothy Harvey [email protected]
1 parent 94b6aae commit ab46d13

File tree

6 files changed

+101
-20
lines changed

6 files changed

+101
-20
lines changed

CMakeLists.txt

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,35 @@ if("${PLATFORM}" STREQUAL "DARWIN")
4848
set(ENABLE_STATIC_LINK "OFF")
4949
endif()
5050

51+
52+
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
53+
set(USING_GCC 1)
54+
endif()
55+
56+
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
57+
set(USING_CLANG 1)
58+
endif()
59+
60+
if(CMAKE_C_COMPILER_ID MATCHES "TI")
61+
set(USING_TI 1)
62+
endif()
63+
5164
# Status messages
5265
message(STATUS "CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
5366
message(STATUS "CMAKE_SYSTEM_NAME " ${CMAKE_SYSTEM_NAME})
5467
message(STATUS "CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})
5568
message(STATUS "ENABLE_ALL_IN_ONE " ${ENABLE_ALL_IN_ONE})
5669
message(STATUS "ENABLE_LTO " ${ENABLE_LTO})
57-
message(STATUS "ENABLE_STATIC_LINK " ${ENABLE_STATIC_LINK})
70+
71+
if(USING_TI)
72+
# If using a compiler that _only_ does static linking, inform the user
73+
# of the discrepancy in settings.
74+
set(ENABLE_STATIC_LINK "ON")
75+
message(STATUS "ENABLE_STATIC_LINK " ${ENABLE_STATIC_LINK} " (ONLY OPTION FOR THIS COMPILER)")
76+
else()
77+
message(STATUS "ENABLE_STATIC_LINK " ${ENABLE_STATIC_LINK})
78+
endif()
79+
5880
message(STATUS "ENABLE_STRIP " ${ENABLE_STRIP})
5981
message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE})
6082
message(STATUS "JERRY_CMDLINE_MINIMAL " ${JERRY_CMDLINE_MINIMAL})
@@ -91,7 +113,7 @@ endmacro()
91113
macro(jerry_add_compile_warnings)
92114
foreach(_warning ${ARGV})
93115
jerry_add_compile_flags(-W${_warning})
94-
if(CMAKE_COMPILER_IS_GNUCC)
116+
if(USING_GCC)
95117
jerry_add_compile_flags(-Werror=${_warning})
96118
endif()
97119
endforeach()
@@ -107,21 +129,28 @@ jerry_add_flags(CMAKE_EXE_LINKER_FLAGS ${FLAGS_COMMON_ARCH})
107129

108130
# Enable static build
109131
if(ENABLE_STATIC_LINK)
110-
jerry_add_link_flags("-static")
132+
if (USING_GCC OR USING_CLANG)
133+
jerry_add_link_flags("-static")
134+
endif()
111135
endif()
112136

113137
# LTO
114138
if(ENABLE_LTO)
115-
jerry_add_compile_flags(-flto)
116-
jerry_add_link_flags(-flto)
117-
if(CMAKE_COMPILER_IS_GNUCC)
139+
if (USING_GCC OR USING_CLANG)
140+
jerry_add_compile_flags(-flto)
141+
jerry_add_link_flags(-flto)
142+
endif()
143+
if(USING_GCC)
118144
if(NOT "${PLATFORM}" STREQUAL "DARWIN")
119145
jerry_add_compile_flags(-fno-fat-lto-objects)
120146
endif()
121147
# Use gcc-ar and gcc-ranlib to support LTO
122148
set(CMAKE_AR "gcc-ar")
123149
set(CMAKE_RANLIB "gcc-ranlib")
124150
endif()
151+
if(USING_TI)
152+
jerry_add_link_flags(-lto)
153+
endif()
125154
endif()
126155

127156
# Define _BSD_SOURCE and _DEFAULT_SOURCE if we use default port and compiler default libc
@@ -130,7 +159,9 @@ if(${PORT_DIR} STREQUAL "${CMAKE_SOURCE_DIR}/targets/default" AND NOT JERRY_LIBC
130159
endif()
131160

132161
# Compiler / Linker flags
133-
jerry_add_compile_flags(-fno-builtin)
162+
if (USING_GCC OR USING_CLANG)
163+
jerry_add_compile_flags(-fno-builtin)
164+
endif()
134165
if(("${PLATFORM}" STREQUAL "DARWIN"))
135166
jerry_add_link_flags(-lSystem)
136167
else()
@@ -143,17 +174,18 @@ if(JERRY_LIBC)
143174
endif()
144175

145176
# Turn off stack protector
177+
if (USING_GCC OR USING_CLANG)
146178
jerry_add_compile_flags(-fno-stack-protector)
179+
endif()
147180

148-
# Debug information
149-
jerry_add_compile_flags(-g)
150-
151-
jerry_add_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations)
152-
jerry_add_compile_flags(-Wno-stack-protector -Wno-attributes)
181+
if (USING_GCC OR USING_CLANG)
182+
jerry_add_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations)
183+
jerry_add_compile_flags(-Wno-stack-protector -Wno-attributes)
184+
endif()
153185

154-
if(CMAKE_COMPILER_IS_GNUCC)
186+
if(USING_GCC)
155187
jerry_add_compile_warnings(logical-op)
156-
else()
188+
elseif(USING_CLANG)
157189
jerry_add_compile_flags(-Wno-nested-anon-types -Wno-static-in-inline)
158190
endif()
159191

@@ -162,11 +194,17 @@ if(JERRY_LIBC)
162194
endif()
163195

164196
# C
165-
jerry_add_compile_flags(-std=c99 -pedantic)
197+
if (USING_GCC OR USING_CLANG)
198+
jerry_add_compile_flags(-std=c99 -pedantic)
199+
elseif(USING_TI)
200+
jerry_add_compile_flags(--c99)
201+
endif()
166202

167203
# Strip binary
168204
if(ENABLE_STRIP AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
169-
jerry_add_link_flags(-s)
205+
if (USING_GCC OR USING_CLANG)
206+
jerry_add_link_flags(-s)
207+
endif()
170208
endif()
171209

172210
# External compiler & linker flags

cmake/toolchain_mcu_tim4f.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright JS Foundation and other contributors, http://js.foundation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
include(CMakeForceCompiler)
16+
17+
set(CMAKE_SYSTEM_NAME MCU)
18+
set(CMAKE_SYSTEM_PROCESSOR armv7l)
19+
set(CMAKE_SYSTEM_VERSION TIM4F)
20+
21+
set(FLAGS_COMMON_ARCH --little_endian --silicon_version=7M4 --float_support=FPv4SPD16)
22+
23+
CMAKE_FORCE_C_COMPILER(armcl TI)
24+
25+
SET (CMAKE_C_FLAGS_DEBUG_INIT "-g")
26+
SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-o4 -mf0 -DNDEBUG")
27+
SET (CMAKE_C_FLAGS_RELEASE_INIT "-o4 -DNDEBUG")
28+
SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-o2 -g")
29+
30+
SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
31+
SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-o4 -mf0 -DNDEBUG")
32+
SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-o4 -DNDEBUG")
33+
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-o2 -g")

jerry-core/ecma/operations/ecma-objects-general.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
313313
JERRY_ASSERT (property_desc_p->is_writable_defined || !property_desc_p->is_writable);
314314

315315
/* 1. */
316-
ecma_extended_property_ref_t ext_property_ref;
316+
/* This #def just gets around the syntax/style checker... */
317+
#define extended_property_ref_initialization { { 0 } , 0 }
318+
ecma_extended_property_ref_t ext_property_ref = extended_property_ref_initialization;
317319
ecma_property_t current_prop;
318320

319321
current_prop = ecma_op_object_get_own_property (object_p,

jerry-core/jerry-api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <stddef.h>
2121
#include <stdint.h>
2222
#include <stdio.h>
23-
#include <sys/types.h>
2423

2524
#ifdef __cplusplus
2625
extern "C"

jerry-core/jrt/jrt-types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@
2020
#include <stdbool.h>
2121
#include <stddef.h>
2222
#include <stdint.h>
23-
#include <sys/types.h>
2423

2524
#endif /* !JRT_TYPES_H */

targets/default/jerry-port-default-date.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
* limitations under the License.
1414
*/
1515

16+
#ifdef __GNUC__
1617
#include <sys/time.h>
18+
#endif
1719

1820
#include "jerry-port.h"
1921
#include "jerry-port-default.h"
@@ -23,6 +25,7 @@
2325
*/
2426
bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
2527
{
28+
#ifdef __GNUC__
2629
struct timeval tv;
2730
struct timezone tz;
2831

@@ -39,19 +42,26 @@ bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
3942
tz_p->daylight_saving_time = tz.tz_dsttime > 0 ? 1 : 0;
4043

4144
return true;
45+
#else /* !__GNUC__ */
46+
return false;
47+
#endif /* __GNUC__ */
4248
} /* jerry_port_get_time_zone */
4349

4450
/**
4551
* Default implementation of jerry_port_get_current_time.
4652
*/
4753
double jerry_port_get_current_time ()
4854
{
55+
#ifdef __GNUC__
4956
struct timeval tv;
5057

5158
if (gettimeofday (&tv, NULL) != 0)
5259
{
53-
return 0;
60+
return 0.0;
5461
}
5562

5663
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
64+
#else /* __!GNUC__ */
65+
return 0.0;
66+
#endif /* __GNUC__ */
5767
} /* jerry_port_get_current_time */

0 commit comments

Comments
 (0)