Renaming core -> jerry-core.

This commit is contained in:
Ruben Ayrapetyan
2015-02-17 19:00:34 +03:00
parent b6d018d019
commit 88353e93cf
183 changed files with 14 additions and 14 deletions
+62
View File
@@ -0,0 +1,62 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jrt.h"
#include "jrt-bit-fields.h"
/**
* Extract a bit-field from the integer.
*
* @return bit-field's value
*/
uint64_t __attr_const___
jrt_extract_bit_field (uint64_t container, /**< container to extract bit-field from */
uint32_t lsb, /**< least significant bit of the value
* to be extracted */
uint32_t width) /**< width of the bit-field to be extracted */
{
JERRY_ASSERT (lsb < JERRY_BITSINBYTE * sizeof (uint64_t));
JERRY_ASSERT (width < JERRY_BITSINBYTE * sizeof (uint64_t));
JERRY_ASSERT ((lsb + width) <= JERRY_BITSINBYTE * sizeof (uint64_t));
uint64_t shifted_value = container >> lsb;
uint64_t bit_field_mask = (1ull << width) - 1;
return (shifted_value & bit_field_mask);
} /* jrt_extract_bit_field */
/**
* Extract a bit-field from the integer.
*
* @return bit-field's value
*/
uint64_t __attr_const___
jrt_set_bit_field_value (uint64_t container, /**< container to insert bit-field to */
uint64_t new_bit_field_value, /**< value of bit-field to insert */
uint32_t lsb, /**< least significant bit of the value
* to be extracted */
uint32_t width) /**< width of the bit-field to be extracted */
{
JERRY_ASSERT (lsb < JERRY_BITSINBYTE * sizeof (uint64_t));
JERRY_ASSERT (width < JERRY_BITSINBYTE * sizeof (uint64_t));
JERRY_ASSERT ((lsb + width) <= JERRY_BITSINBYTE * sizeof (uint64_t));
JERRY_ASSERT (new_bit_field_value <= (1ull << width));
uint64_t bit_field_mask = (1ull << width) - 1;
uint64_t shifted_bit_field_mask = bit_field_mask << lsb;
uint64_t shifted_new_bit_field_value = new_bit_field_value << lsb;
return (container & ~shifted_bit_field_mask) | shifted_new_bit_field_value;
} /* jrt_set_bit_field_value */
+24
View File
@@ -0,0 +1,24 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef JERRY_BIT_FIELDS_H
#define JERRY_BIT_FIELDS_H
extern uint64_t __attr_const___ jrt_extract_bit_field (uint64_t value, uint32_t lsb,
uint32_t width);
extern uint64_t __attr_const___ jrt_set_bit_field_value (uint64_t value, uint64_t bit_field_value,
uint32_t lsb, uint32_t width);
#endif /* !JERRY_BIT_FIELDS_H */
+142
View File
@@ -0,0 +1,142 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Implementation of exit with specified status code.
*/
#include "jrt.h"
#include "jrt-libc-includes.h"
/*
* Exit with specified status code.
*
* If !JERRY_NDEBUG and code != 0, print status code with description
* and call assertion fail handler.
*/
void __noreturn
jerry_fatal (jerry_fatal_code_t code) /**< status code */
{
#ifndef JERRY_NDEBUG
printf ("Error: ");
switch (code)
{
case ERR_OUT_OF_MEMORY:
{
printf ("ERR_OUT_OF_MEMORY\n");
break;
}
case ERR_SYSCALL:
{
/* print nothing as it may invoke syscall recursively */
break;
}
case ERR_PARSER:
{
printf ("ERR_PARSER\n");
break;
}
case ERR_UNIMPLEMENTED_CASE:
{
printf ("ERR_UNIMPLEMENTED_CASE\n");
break;
}
case ERR_FAILED_INTERNAL_ASSERTION:
{
printf ("ERR_FAILED_INTERNAL_ASSERTION\n");
break;
}
}
#endif /* !JERRY_NDEBUG */
exit (code);
} /* jerry_fatal */
/**
* Handle failed assertion
*/
void __noreturn
jerry_assert_fail (const char *assertion, /**< assertion condition string */
const char *file, /**< file name */
const char *function, /**< function name */
const uint32_t line) /** line */
{
#ifndef JERRY_NDEBUG
printf ("ICE: Assertion '%s' failed at %s(%s):%lu.\n",
assertion, file, function, (unsigned long) line);
#else /* !JERRY_NDEBUG */
(void) assertion;
(void) file;
(void) function;
(void) line;
#endif /* JERRY_NDEBUG */
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */
/**
* Handle execution of control path that should be unreachable
*/
void __noreturn
jerry_unreachable (const char *comment, /**< comment to unreachable mark if exists,
NULL - otherwise */
const char *file, /**< file name */
const char *function, /**< function name */
const uint32_t line) /**< line */
{
#ifndef JERRY_NDEBUG
printf ("ICE: Unreachable control path at %s(%s):%lu was executed", file, function, (unsigned long) line);
#else /* !JERRY_NDEBUG */
(void) file;
(void) function;
(void) line;
#endif /* JERRY_NDEBUG */
if (comment != NULL)
{
printf ("(%s)", comment);
}
printf (".\n");
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
/**
* Handle unimplemented case execution
*/
void __noreturn
jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if exists,
NULL - otherwise */
const char *file, /**< file name */
const char *function, /**< function name */
const uint32_t line) /**< line */
{
#ifndef JERRY_NDEBUG
printf ("SORRY: Unimplemented case at %s(%s):%lu was executed", file, function, (unsigned long) line);
#else /* !JERRY_NDEBUG */
(void) file;
(void) function;
(void) line;
#endif /* JERRY_NDEBUG */
if (comment != NULL)
{
printf ("(%s)", comment);
}
printf (".\n");
jerry_fatal (ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */
+53
View File
@@ -0,0 +1,53 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef JRT_LIBC_INCLUDES_H
#define JRT_LIBC_INCLUDES_H
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Ensuring no macro implementation of functions declared in the headers are used */
#undef isspace
#undef isalpha
#undef islower
#undef isupper
#undef isdigit
#undef isxdigit
#undef memset
#undef memcmp
#undef memcpy
#undef memmove
#undef strcmp
#undef strncmp
#undef strncpy
#undef strlen
#undef putchar
#undef puts
#undef exit
#undef fopen
#undef rewind
#undef fclose
#undef fseek
#undef ftell
#undef fread
#undef fwrite
#undef vfprintf
#undef fprintf
#undef printf
#endif /* !JRT_LIBC_INCLUDES_H */
+25
View File
@@ -0,0 +1,25 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef JRT_TYPES_H
#define JRT_TYPES_H
#include <float.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#endif /* !JRT_TYPES_H */
+186
View File
@@ -0,0 +1,186 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef JERRY_GLOBALS_H
#define JERRY_GLOBALS_H
#include "jerry.h"
#include "jrt-types.h"
/**
* Attributes
*/
#define __attr_unused___ __attribute__((unused))
#define __attr_used___ __attribute__((used))
#define __attr_packed___ __attribute__((packed))
#define __noreturn __attribute__((noreturn))
#define __attr_noinline___ __attribute__((noinline))
#define __attr_used___ __attribute__((used))
#ifndef __attr_always_inline___
# define __attr_always_inline___ __attribute__((always_inline))
#endif /* !__attr_always_inline___ */
#ifndef __attr_const___
# define __attr_const___ __attribute__((const))
#endif /* !__attr_const___ */
#ifndef __attr_pure___
# define __attr_pure___ __attribute__((pure))
#endif /* !__attr_pure___ */
/**
* Constants
*/
#define JERRY_BITSINBYTE 8
/**
* Asserts
*
* Warning:
* Don't use JERRY_STATIC_ASSERT in headers, because
* __LINE__ may be the same for asserts in a header
* and in an implementation file.
*/
#define JERRY_STATIC_ASSERT_GLUE_(a, b) a ## b
#define JERRY_STATIC_ASSERT_GLUE(a, b) JERRY_STATIC_ASSERT_GLUE_ (a, b)
#define JERRY_STATIC_ASSERT(x) \
typedef char JERRY_STATIC_ASSERT_GLUE (static_assertion_failed_, __LINE__) \
[ (x) ? 1 : -1 ] __attr_unused___
#define CALL_PRAGMA(x) _Pragma (#x)
#ifdef JERRY_PRINT_TODO
#define TODO(x) CALL_PRAGMA (message ("TODO - " #x))
#else /* !JERRY_PRINT_TODO */
#define TODO(X)
#endif /* !JERRY_PRINT_TODO */
#ifdef JERRY_PRINT_FIXME
#define FIXME(x) CALL_PRAGMA (message ("FIXME - " #x))
#else /* !JERRY_PRINT_FIXME */
#define FIXME(X)
#endif /* !JERRY_PRINT_FIXME */
/**
* Variable that must not be referenced.
*
* May be used for static assertion checks.
*/
extern uint32_t jerry_unreferenced_expression;
extern void __noreturn jerry_assert_fail (const char *assertion, const char *file, const char *function,
const uint32_t line);
extern void __noreturn jerry_unreachable (const char *comment, const char *file, const char *function,
const uint32_t line);
extern void __noreturn jerry_unimplemented (const char *comment, const char *file, const char *function,
const uint32_t line);
#ifndef JERRY_NDEBUG
#define JERRY_ASSERT(x) do { if (__builtin_expect (!(x), 0)) { \
jerry_assert_fail (#x, __FILE__, __FUNCTION__, __LINE__); } } while (0)
#else /* !JERRY_NDEBUG */
#define JERRY_ASSERT(x) do { if (false) { (void)(x); } } while (0)
#endif /* !JERRY_NDEBUG */
/**
* Mark for unreachable points and unimplemented cases
*/
template<typename... values> extern void jerry_ref_unused_variables (const values & ... unused);
#ifndef JERRY_NDEBUG
#define JERRY_UNREACHABLE() \
do \
{ \
jerry_unreachable (NULL, __FILE__, __FUNCTION__, __LINE__); \
} while (0)
#define JERRY_UNIMPLEMENTED(comment) \
do \
{ \
jerry_unimplemented (comment, __FILE__, __FUNCTION__, __LINE__); \
} while (0)
#define JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(comment, ...) \
do \
{ \
jerry_unimplemented (comment, __FILE__, __FUNCTION__, __LINE__); \
if (false) \
{ \
jerry_ref_unused_variables (0, __VA_ARGS__); \
} \
} while (0)
#else /* !JERRY_NDEBUG */
#define JERRY_UNREACHABLE() \
do \
{ \
jerry_unreachable (NULL, NULL, NULL, 0); \
} while (0)
#define JERRY_UNIMPLEMENTED(comment) \
do \
{ \
jerry_unimplemented (comment, NULL, NULL, 0); \
} while (0)
#define JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(comment, ...) \
do \
{ \
jerry_unimplemented (comment, NULL, NULL, 0); \
if (false) \
{ \
jerry_ref_unused_variables (0, __VA_ARGS__); \
} \
} while (0)
#endif /* JERRY_NDEBUG */
/**
* Conditions' likeliness, unlikeliness.
*/
#define likely(x) __builtin_expect (!!(x), 1)
#define unlikely(x) __builtin_expect (!!(x) , 0)
/**
* Exit
*/
extern void __noreturn jerry_fatal (jerry_fatal_code_t code);
/**
* sizeof, offsetof, ...
*/
#define JERRY_SIZE_OF_STRUCT_MEMBER(struct_name, member_name) sizeof (((struct_name*)NULL)->member_name)
/**
* Alignment
*/
/**
* Aligns @value to @alignment.
*
* Returns maximum positive value, that divides @alignment and is less than or equal to @value
*/
#define JERRY_ALIGNDOWN(value, alignment) ((alignment) * ((value) / (alignment)))
/**
* Aligns @value to @alignment.
*
* Returns minimum positive value, that divides @alignment and is more than or equal to @value
*/
#define JERRY_ALIGNUP(value, alignment) ((alignment) * (((value) + (alignment) - 1) / (alignment)))
/**
* min, max
*/
#define JERRY_MIN(v1, v2) ((v1 < v2) ? v1 : v2)
#define JERRY_MAX(v1, v2) ((v1 < v2) ? v2 : v1)
#endif /* !JERRY_GLOBALS_H */