Rename Jerry's libc functions: __function_name -> function_name.

This commit is contained in:
Ruben Ayrapetyan
2015-02-12 20:15:56 +03:00
parent af77eac8e4
commit 7e4c16e4e6
36 changed files with 484 additions and 532 deletions
+12 -12
View File
@@ -75,7 +75,7 @@ static void
libc_printf_putchar (_FILE *stream, /**< stream pointer */
char character) /**< character */
{
__fwrite (&character, 1, sizeof (character), stream);
fwrite (&character, 1, sizeof (character), stream);
} /* libc_printf_putchar */
/**
@@ -88,7 +88,7 @@ libc_printf_justified_string_output (_FILE *stream, /**< stream pointer */
bool is_left_justify, /**< justify to left (true) or right (false) */
bool is_zero_padding) /**< left-pad with zeroes (true) or spaces (false) */
{
const size_t str_length = __strlen (string_p);
const size_t str_length = strlen (string_p);
size_t outputted_length = 0;
@@ -103,7 +103,7 @@ libc_printf_justified_string_output (_FILE *stream, /**< stream pointer */
}
}
__fwrite (string_p, 1, str_length * sizeof (*string_p), stream);
fwrite (string_p, 1, str_length * sizeof (*string_p), stream);
outputted_length += str_length;
if (is_left_justify)
@@ -476,7 +476,7 @@ libc_printf_write_u_o_x_X(_FILE *stream, /**< stream pointer */
* @return number of characters printed
*/
static int
__vfprintf (_FILE *stream, /**< stream pointer */
vfprintf (_FILE *stream, /**< stream pointer */
const char *format, /**< format string */
va_list args) /**< arguments */
{
@@ -696,7 +696,7 @@ __vfprintf (_FILE *stream, /**< stream pointer */
if (value == NULL)
{
__printf ("(nil)");
printf ("(nil)");
}
else
{
@@ -725,7 +725,7 @@ __vfprintf (_FILE *stream, /**< stream pointer */
va_end (args_copy);
return 0;
} /* __vfprintf */
} /* vfprintf */
/**
* fprintf
@@ -733,7 +733,7 @@ __vfprintf (_FILE *stream, /**< stream pointer */
* @return number of characters printed
*/
int
__fprintf (_FILE *stream, /**< stream pointer */
fprintf (_FILE *stream, /**< stream pointer */
const char *format, /**< format string */
...) /**< parameters' values */
{
@@ -741,12 +741,12 @@ __fprintf (_FILE *stream, /**< stream pointer */
va_start (args, format);
int ret = __vfprintf (stream, format, args);
int ret = vfprintf (stream, format, args);
va_end (args);
return ret;
} /* __fprintf */
} /* fprintf */
/**
* printf
@@ -754,17 +754,17 @@ __fprintf (_FILE *stream, /**< stream pointer */
* @return number of characters printed
*/
int
__printf (const char *format, /**< format string */
printf (const char *format, /**< format string */
...) /**< parameters' values */
{
va_list args;
va_start (args, format);
int ret = __vfprintf (LIBC_STDOUT, format, args);
int ret = vfprintf (LIBC_STDOUT, format, args);
va_end (args);
return ret;
} /* __printf */
} /* printf */
+47 -95
View File
@@ -20,26 +20,27 @@
#include "jerry-libc.h"
/**
* memcpy alias to __memcpy (for compiler usage)
* Unreachable stubs for routines that are never called,
* but referenced from third-party libraries.
*/
extern "C" void *memcpy (void *s1, const void*s2, size_t n);
#define JRT_UNREACHABLE_STUB_FOR(...) \
extern "C" __VA_ARGS__; \
__used __VA_ARGS__ \
{ \
JERRY_UNREACHABLE (); \
}
/**
* memset alias to __memset (for compiler usage)
*/
extern "C" void *memset (void *s, int c, size_t n);
JRT_UNREACHABLE_STUB_FOR(void abort (void))
JRT_UNREACHABLE_STUB_FOR(int raise (int sig_no __unused))
/**
* memmove alias to __memmove (for compiler usage)
*/
extern "C" void *memmove (void *s1, const void*s2, size_t n);
#undef JRT_UNREACHABLE_STUB_FOR
#ifdef __GNUC__
/*
* Making GCC not to replace:
* - __memcpy -> call to memcpy;
* - __memset -> call to memset;
* - __memmove -> call to memmove.
* - memcpy -> call to memcpy;
* - memset -> call to memset;
* - memmove -> call to memmove.
*/
CALL_PRAGMA(GCC diagnostic push)
CALL_PRAGMA(GCC diagnostic ignored "-Wpragmas")
@@ -47,69 +48,15 @@ CALL_PRAGMA(GCC push_options)
CALL_PRAGMA(GCC optimize ("-fno-tree-loop-distribute-patterns"))
#endif /* __GNUC__ */
/**
* memcpy alias to __memcpy (for compiler usage)
*/
void* __used
memcpy (void *s1, /**< destination */
const void* s2, /**< source */
size_t n) /**< bytes number */
{
return __memcpy (s1, s2, n);
} /* memcpy */
/**
* memset alias to __memset (for compiler usage)
*/
void* __used
memset (void *s, /**< area to set values in */
int c, /**< value to set */
size_t n) /**< area size */
{
return __memset (s, c, n);
} /* memset */
/**
* memmove alias to __memmove (for compiler usage)
*/
void* __used
memmove (void *s1, /**< destination*/
const void*s2, /**< source */
size_t n) /**< area size */
{
return __memmove (s1, s2, n);
} /* memmove */
#ifdef __GNUC__
CALL_PRAGMA(GCC pop_options)
CALL_PRAGMA(GCC diagnostic pop)
#endif /* __GNUC__ */
/**
* Unreachable stubs for routines that are never called,
* but referenced from third-party libraries.
*/
#define JRT_UNREACHABLE_STUB_FOR(...) \
extern "C" __VA_ARGS__; \
__used __VA_ARGS__ \
{ \
JERRY_UNREACHABLE (); \
}
JRT_UNREACHABLE_STUB_FOR(void abort (void))
JRT_UNREACHABLE_STUB_FOR(int raise (int sig_no __unused))
#undef JRT_UNREACHABLE_STUB_FOR
/**
* memset
*
* @return @s
*/
void*
__memset (void *s, /**< area to set values in */
int c, /**< value to set */
size_t n) /**< area size */
memset (void *s, /**< area to set values in */
int c, /**< value to set */
size_t n) /**< area size */
{
uint8_t *area_p = (uint8_t *) s;
for (size_t index = 0; index < n; index++)
@@ -118,7 +65,7 @@ __memset (void *s, /**< area to set values in */
}
return s;
} /* __memset */
} /* memset */
/**
* memcmp
@@ -128,9 +75,9 @@ __memset (void *s, /**< area to set values in */
* 1, otherwise
*/
int
__memcmp (const void *s1, /**< first area */
const void *s2, /**< second area */
size_t n) /**< area size */
memcmp (const void *s1, /**< first area */
const void *s2, /**< second area */
size_t n) /**< area size */
{
const uint8_t *area1_p = (uint8_t *) s1, *area2_p = (uint8_t *) s2;
for (size_t index = 0; index < n; index++)
@@ -146,15 +93,15 @@ __memcmp (const void *s1, /**< first area */
}
return 0;
} /* __memcmp */
} /* memcmp */
/**
* memcpy
*/
void *
__memcpy (void *s1, /**< destination */
const void *s2, /**< source */
size_t n) /**< bytes number */
memcpy (void *s1, /**< destination */
const void *s2, /**< source */
size_t n) /**< bytes number */
{
uint8_t *area1_p = (uint8_t *) s1;
const uint8_t *area2_p = (const uint8_t *) s2;
@@ -165,7 +112,7 @@ __memcpy (void *s1, /**< destination */
}
return s1;
} /* __memcpy */
} /* memcpy */
/**
* memmove
@@ -173,9 +120,9 @@ __memcpy (void *s1, /**< destination */
* @return the dest pointer's value
*/
void *
__memmove (void *s1, /**< destination */
const void *s2, /**< source */
size_t n) /**< bytes number */
memmove (void *s1, /**< destination */
const void *s2, /**< source */
size_t n) /**< bytes number */
{
uint8_t *dest_p = (uint8_t *) s1;
const uint8_t *src_p = (const uint8_t *) s2;
@@ -196,12 +143,17 @@ __memmove (void *s1, /**< destination */
}
return s1;
} /* __memmove */
} /* memmove */
#ifdef __GNUC__
CALL_PRAGMA(GCC pop_options)
CALL_PRAGMA(GCC diagnostic pop)
#endif /* __GNUC__ */
/** Compare two strings. return an integer less than, equal to, or greater than zero
if s1 is found, respectively, to be less than, to match, or be greater than s2. */
int
__strcmp (const char *s1, const char *s2)
strcmp (const char *s1, const char *s2)
{
size_t i;
if (s1 == NULL)
@@ -244,7 +196,7 @@ __strcmp (const char *s1, const char *s2)
if the first n character of s1 is found, respectively, to be less than, to match,
or be greater than the first n character of s2. */
int
__strncmp (const char *s1, const char *s2, size_t n)
strncmp (const char *s1, const char *s2, size_t n)
{
size_t i;
if (s1 == NULL)
@@ -282,7 +234,7 @@ __strncmp (const char *s1, const char *s2, size_t n)
null byte among the first n bytes of src, the string placed in dest will not be null-terminated.
@return a pointer to the destination string dest. */
char *
__strncpy (char *dest, const char *src, size_t n)
strncpy (char *dest, const char *src, size_t n)
{
size_t i;
@@ -300,7 +252,7 @@ __strncpy (char *dest, const char *src, size_t n)
/** Calculate the length of a string. */
size_t
__strlen (const char *s)
strlen (const char *s)
{
size_t i;
for (i = 0; s[i]; i++)
@@ -314,7 +266,7 @@ __strlen (const char *s)
/** Checks for white-space characters. In the "C" and "POSIX" locales, these are: space,
form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). */
int
__isspace (int c)
isspace (int c)
{
switch (c)
{
@@ -336,14 +288,14 @@ __isspace (int c)
/** Checks for an uppercase letter. */
int
__isupper (int c)
isupper (int c)
{
return c >= 'A' && c <= 'Z';
}
/** Checks for an lowercase letter. */
int
__islower (int c)
islower (int c)
{
return c >= 'a' && c <= 'z';
}
@@ -351,14 +303,14 @@ __islower (int c)
/** Checks for an alphabetic character.
In the standard "C" locale, it is equivalent to (isupper (c) || islower (c)). */
int
__isalpha (int c)
isalpha (int c)
{
return __isupper (c) || __islower (c);
return isupper (c) || islower (c);
}
/** Checks for a digit (0 through 9). */
int
__isdigit (int c)
isdigit (int c)
{
return c >= '0' && c <= '9';
}
@@ -366,7 +318,7 @@ __isdigit (int c)
/** checks for a hexadecimal digits, that is, one of
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F. */
int
__isxdigit (int c)
isxdigit (int c)
{
return __isdigit (c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
return isdigit (c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
+26 -26
View File
@@ -38,29 +38,29 @@ typedef void _FILE;
*/
#define LIBC_STDERR (_FILE*)2
extern void* __memset (void *s, int c, size_t n);
extern int __memcmp (const void *s1, const void *s2, size_t n);
extern void* __memcpy (void *s1, const void *s2, size_t n);
extern void* __memmove (void *dest, const void *src, size_t n);
extern int __printf (const char *format, ...);
extern int __putchar (int);
extern "C" void __noreturn __exit (int);
extern void* memset (void *s, int c, size_t n);
extern int memcmp (const void *s1, const void *s2, size_t n);
extern void* memcpy (void *s1, const void *s2, size_t n);
extern void* memmove (void *dest, const void *src, size_t n);
extern int printf (const char *format, ...);
extern int putchar (int);
extern "C" void __noreturn exit (int);
extern int __strcmp (const char *, const char *);
extern int __strncmp (const char *, const char *, size_t);
extern char* __strncpy (char *, const char *, size_t);
extern int strcmp (const char *, const char *);
extern int strncmp (const char *, const char *, size_t);
extern char* strncpy (char *, const char *, size_t);
extern float __strtof (const char *, char **);
extern size_t __strlen (const char *);
extern size_t strlen (const char *);
extern int __isspace (int);
extern int __isupper (int);
extern int __islower (int);
extern int __isalpha (int);
extern int __isdigit (int);
extern int __isxdigit (int);
extern int isspace (int);
extern int isupper (int);
extern int islower (int);
extern int isalpha (int);
extern int isdigit (int);
extern int isxdigit (int);
/**
* 'whence' argument of __fseek that identifies position
* 'whence' argument of fseek that identifies position
* the 'offset' argument is added to.
*/
typedef enum
@@ -70,14 +70,14 @@ typedef enum
__SEEK_END /**< relative to end of file */
} _whence_t;
extern _FILE* __fopen (const char *, const char *);
extern int __fclose (_FILE *);
extern int __fseek (_FILE *, long offset, _whence_t);
extern long __ftell (_FILE *);
extern void __rewind (_FILE *);
extern size_t __fread (void *, size_t, size_t, _FILE *);
extern size_t __fwrite (const void *, size_t, size_t, _FILE *);
extern int __fprintf (_FILE *, const char *, ...);
extern _FILE* fopen (const char *, const char *);
extern int fclose (_FILE *);
extern int fseek (_FILE *, long offset, _whence_t);
extern long ftell (_FILE *);
extern void rewind (_FILE *);
extern size_t fread (void *, size_t, size_t, _FILE *);
extern size_t fwrite (const void *, size_t, size_t, _FILE *);
extern int fprintf (_FILE *, const char *, ...);
extern void jrt_set_mem_limits (size_t data_size, size_t stack_size);
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright 2014 Samsung Electronics Co., Ltd.
/* 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.
@@ -72,7 +72,7 @@
add r1, sp, #4; \
bl main; \
\
bl __exit; \
bl exit; \
1: \
b 1b
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright 2014 Samsung Electronics Co., Ltd.
/* 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.
@@ -62,7 +62,7 @@
callq main; \
\
mov %rax, %rdi; \
callq __exit; \
callq exit; \
1: \
jmp 1b
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright 2014 Samsung Electronics Co., Ltd.
/* 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.
@@ -65,7 +65,7 @@ FIXME(Implement x86 ABI);
callq main; \
\
mov %rax, %rdi; \
callq __exit; \
callq exit; \
1: \
jmp 1b
+20 -20
View File
@@ -120,18 +120,18 @@ syscall_3 (long int syscall_no, /**< syscall number */
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */
int
__putchar (int c)
putchar (int c)
{
__fwrite (&c, 1, sizeof (char), LIBC_STDOUT);
fwrite (&c, 1, sizeof (char), LIBC_STDOUT);
return c;
} /* __putchar */
} /* putchar */
/**
* Exit - cause normal process termination with specified status code
*/
void __noreturn
__exit (int status) /**< status code */
void __noreturn __used
exit (int status) /**< status code */
{
syscall_1 (__NR_close, (long int)LIBC_STDIN);
syscall_1 (__NR_close, (long int)LIBC_STDOUT);
@@ -143,7 +143,7 @@ __exit (int status) /**< status code */
{
/* unreachable */
}
} /* __exit */
} /* exit */
/**
* fopen
@@ -152,7 +152,7 @@ __exit (int status) /**< status code */
* NULL - otherwise
*/
_FILE*
__fopen (const char *path, /**< file path */
fopen (const char *path, /**< file path */
const char *mode) /**< file open mode */
{
bool may_read = false;
@@ -233,17 +233,17 @@ __fopen (const char *path, /**< file path */
long int ret = syscall_3 (__NR_open, (long int) path, flags, access);
return (void*) (uintptr_t) (ret);
} /* __fopen */
} /* fopen */
/**
* The rewind () function sets the file position indicator
* for the stream pointed to by STREAM to the beginning of the file.
*/
void
__rewind (_FILE *stream) /**< stream pointer */
rewind (_FILE *stream) /**< stream pointer */
{
syscall_3 (__NR_lseek, (long int) stream, 0, SEEK_SET);
} /* __rewind */
} /* rewind */
/**
* fclose
@@ -252,18 +252,18 @@ __rewind (_FILE *stream) /**< stream pointer */
* non-zero value - otherwise.
*/
int
__fclose (_FILE *fp) /**< stream pointer */
fclose (_FILE *fp) /**< stream pointer */
{
syscall_2 (__NR_close, (long int)fp, 0);
return 0;
} /* __fclose */
} /* fclose */
/**
* fseek
*/
int
__fseek (_FILE * fp, /**< stream pointer */
fseek (_FILE * fp, /**< stream pointer */
long offset, /**< offset */
_whence_t whence) /**< specifies position type
to add offset to */
@@ -291,18 +291,18 @@ __fseek (_FILE * fp, /**< stream pointer */
syscall_3 (__NR_lseek, (long int)fp, offset, whence_real);
return 0;
} /* __fseek */
} /* fseek */
/**
* ftell
*/
long
__ftell (_FILE * fp) /**< stream pointer */
ftell (_FILE * fp) /**< stream pointer */
{
long int ret = syscall_3 (__NR_lseek, (long int)fp, 0, SEEK_CUR);
return ret;
} /* __ftell */
} /* ftell */
/**
* fread
@@ -310,7 +310,7 @@ __ftell (_FILE * fp) /**< stream pointer */
* @return number of bytes read
*/
size_t
__fread (void *ptr, /**< address of buffer to read to */
fread (void *ptr, /**< address of buffer to read to */
size_t size, /**< size of elements to read */
size_t nmemb, /**< number of elements to read */
_FILE *stream) /**< stream pointer */
@@ -330,7 +330,7 @@ __fread (void *ptr, /**< address of buffer to read to */
while (bytes_read != size * nmemb && ret != 0);
return bytes_read;
} /* __fread */
} /* fread */
/**
* fwrite
@@ -338,7 +338,7 @@ __fread (void *ptr, /**< address of buffer to read to */
* @return number of bytes written
*/
size_t
__fwrite (const void *ptr, /**< data to write */
fwrite (const void *ptr, /**< data to write */
size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */
_FILE *stream) /**< stream pointer */
@@ -357,7 +357,7 @@ __fwrite (const void *ptr, /**< data to write */
while (bytes_written != size * nmemb);
return bytes_written;
} /* __fwrite */
} /* fwrite */
/**
* Setup new memory limits
+8 -8
View File
@@ -1,4 +1,4 @@
/* Copyright 2014 Samsung Electronics Co., Ltd.
/* 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.
@@ -25,14 +25,14 @@ extern void __noreturn exit (int status);
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */
int
__putchar (int c)
putchar (int c)
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS("putchar is not implemented for STM32F3.", c);
} /* __putchar */
} /* putchar */
/** exit - cause normal process termination */
void __noreturn
__exit (int status __unused)
void __noreturn __used
exit (int status __unused)
{
/**
* TODO: Blink LEDs? status -> binary -> LEDs?
@@ -41,7 +41,7 @@ __exit (int status __unused)
while (true)
{
}
} /* __exit */
} /* exit */
/**
* fwrite
@@ -49,11 +49,11 @@ __exit (int status __unused)
* @return number of bytes written
*/
size_t
__fwrite (const void *ptr, /**< data to write */
fwrite (const void *ptr, /**< data to write */
size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */
_FILE *stream) /**< stream pointer */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS("fwrite is not implemented for STM32F3.", ptr, size, nmemb, stream);
} /* __fwrite */
} /* fwrite */
+8 -8
View File
@@ -1,4 +1,4 @@
/* Copyright 2014 Samsung Electronics Co., Ltd.
/* 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.
@@ -25,14 +25,14 @@ extern void __noreturn exit (int status);
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */
int
__putchar (int c)
putchar (int c)
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS("putchar is not implemented for STM32F4.", c);
} /* __putchar */
} /* putchar */
/** exit - cause normal process termination */
void __noreturn
__exit (int status __unused)
void __noreturn __used
exit (int status __unused)
{
/**
* TODO: Blink LEDs? status -> binary -> LEDs?
@@ -41,7 +41,7 @@ __exit (int status __unused)
while (true)
{
}
} /* __exit */
} /* exit */
/**
* fwrite
@@ -49,11 +49,11 @@ __exit (int status __unused)
* @return number of bytes written
*/
size_t
__fwrite (const void *ptr, /**< data to write */
fwrite (const void *ptr, /**< data to write */
size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */
_FILE *stream) /**< stream pointer */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS("fwrite is not implemented for STM32F4.", ptr, size, nmemb, stream);
} /* __fwrite */
} /* fwrite */