Creating libruntime, moving jerry-libc and pretty-printer to libruntime, creating platform-dependent handlers of failed assertions.

This commit is contained in:
Ruben Ayrapetyan
2014-07-10 15:39:43 +04:00
parent 8641b79ed5
commit c132f6aa3c
9 changed files with 85 additions and 14 deletions
+272
View File
@@ -0,0 +1,272 @@
/* Copyright 2014 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.
*/
/**
* Jerry libc implementation
*/
#include "jerry-libc.h"
#include <stdarg.h>
extern int vprintf (__const char *__restrict __format, __builtin_va_list __arg);
extern void __noreturn exit(int status);
/**
* memset
*
* @return @s
*/
void*
__memset(void *s, /**< area to set values in */
int c, /**< value to set */
size_t n) /**< area size */
{
uint8_t *pArea = s;
for ( size_t index = 0; index < n; index++ )
{
pArea[ index ] = (uint8_t)c;
}
return s;
} /* __memset */
/**
* memcmp
*
* @return 0, if areas are equal;
* -1, if first area's content is lexicographically less, than second area's content;
* 1, otherwise
*/
int
__memcmp(const void *s1, /**< first area */
const void *s2, /**< second area */
size_t n) /**< area size */
{
const uint8_t *pArea1 = s1, *pArea2 = s2;
for ( size_t index = 0; index < n; index++ )
{
if ( pArea1[ index ] < pArea2[ index ] )
{
return -1;
} else if ( pArea1[ index ] > pArea2[ index ] )
{
return 1;
}
}
return 0;
} /* __memcmp */
/**
* memcpy
*/
void *
__memcpy(void *s1, /**< destination */
const void *s2, /**< source */
size_t n) /**< bytes number */
{
uint8_t *pArea1 = s1;
const uint8_t *pArea2 = s2;
for ( size_t index = 0; index < n; index++ )
{
pArea1[ index ] = pArea2[ index ];
}
return s1;
} /* __memcpy */
/**
* printf
*
* @return number of characters printed
*/
int
__printf(const char *format, /**< format string */
...) /**< parameters' values */
{
va_list args;
va_start( args, format);
int ret = vprintf( format, args);
va_end( args);
return ret;
} /* __printf */
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */
int
__putchar (int c)
{
return __printf ("%c", c);
}
/** exit - cause normal process termination */
void __noreturn
__exit (int status)
{
exit( status);
}
/** 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)
{
size_t i;
if (s1 == NULL)
{
if (s2 != NULL)
return -1;
else
return 0;
}
if (s2 == NULL)
return 1;
for (i = 0; s1[i]; i++)
{
if (s1[i] > s2[i])
return 1;
else if (s1[i] < s2[i])
return -1;
}
if (s2[i])
return -1;
return 0;
}
/** Compare two strings. return an integer less than, equal to, or greater than zero
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)
{
size_t i;
if (s1 == NULL)
{
if (s2 != NULL)
return -1;
else
return 0;
}
if (s2 == NULL)
return 1;
for (i = 0; i < n; i++)
{
if (s1[i] > s2[i])
return 1;
else if (s1[i] < s2[i])
return -1;
}
return 0;
}
/** Copy a string. At most n bytes of src are copied. Warning: If there is no
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)
{
size_t i;
for (i = 0; i < n; i++)
dest[i] = src[i];
return dest;
}
/** Convert the initial portion of the string pointed to by nptr to float representation. */
float
__strtof (const char *nptr, char **endptr)
{
(void) nptr;
(void) endptr;
JERRY_UNIMPLEMENTED ();
}
/** Calculate the length of a string. */
size_t
__strlen (const char *s)
{
size_t i;
for (i = 0; s[i]; i++)
;
return i;
}
/** 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)
{
switch (c)
{
case ' ':
case '\f':
case '\n':
case '\r':
case '\t':
case '\v':
return 1;
default:
return 0;
}
}
/** Checks for an uppercase letter. */
int
__isupper (int c)
{
return c >= 'A' && c <= 'Z';
}
/** Checks for an lowercase letter. */
int
__islower (int c)
{
return c >= 'a' && c <= 'z';
}
/** Checks for an alphabetic character.
In the standard "C" locale, it is equivalent to (isupper(c) || islower(c)). */
int
__isalpha (int c)
{
return __isupper (c) || __islower (c);
}
/** Checks for a digit (0 through 9). */
int
__isdigit (int c)
{
return c >= '0' && c <= '9';
}
/** 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)
{
return __isdigit (c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
+50
View File
@@ -0,0 +1,50 @@
/* Copyright 2014 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.
*/
/**
* Jerry libc declarations
*/
#ifndef JERRY_LIBC_H
#define JERRY_LIBC_H
#include "globals.h"
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 int __printf (const char *format, ...);
extern int __putchar (int);
extern 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 float __strtof (const char *, 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);
#define DBL_MANT_DIG ( 52)
#define DBL_DIG ( 10)
#define DBL_MIN_EXP (-324)
#define DBL_MAX_EXP ( 308)
#define HUGE_VAL (1e37)
#endif /* JERRY_LIBC_H */
+31
View File
@@ -0,0 +1,31 @@
/* Copyright 2014 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 "globals.h"
#include "jerry-libc.h"
/**
* Handle failed assertion
*/
void __noreturn
jerry_AssertFail( const char *assertion, /**< assertion condition string */
const char *file, /**< file name */
const uint32_t line) /** line */
{
__printf("Assertion '%s' failed at %s:%u\n",
assertion, file, line);
__exit( 1);
} /* jerry_AssertFail */
File diff suppressed because it is too large Load Diff
+28
View File
@@ -0,0 +1,28 @@
/* Copyright 2014 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 PRETTY_PRINTER_H
#define PRETTY_PRINTER_H
#include "lexer.h"
#include "parser.h"
void pp_reset (void);
void pp_finish (void);
void pp_token (token);
void pp_keyword (keyword);
void pp_statement (statement);
#endif
+32
View File
@@ -0,0 +1,32 @@
/* Copyright 2014 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 "globals.h"
#include "jerry-libc.h"
/**
* Handle failed assertion
*/
void __noreturn
jerry_AssertFail( const char *assertion, /**< assertion condition string */
const char *file, /**< file name */
const uint32_t line) /** line */
{
/**
* TODO: Blink with LEDs.
* Save call stack?
*/
while( true );
} /* jerry_AssertFail */