-------------------------------------------------------------------------*/
#include <math.h>
+#include <ctype.h>
#ifdef _WIN32
-#include <ctype.h>
#include <windows.h>
#endif
#include <sys/stat.h>
return (SDCC_BUILD_NUMBER);
}
-/*-----------------------------------------------------------------*/
-/* doubleFromFixed16x16 - convert a fixed16x16 to double */
-/*-----------------------------------------------------------------*/
-double doubleFromFixed16x16(TYPE_UDWORD value)
-{
-#if 0
- /* This version is incorrect negative values. */
- double tmp=0, exp=2;
-
- tmp = (value & 0xffff0000) >> 16;
-
- while(value) {
- value &= 0xffff;
- if(value & 0x8000)tmp += 1/exp;
- exp *= 2;
- value <<= 1;
- }
-
- return (tmp);
-#else
- return ((double)(value * 1.0) / (double)(1UL << 16));
-#endif
-}
-
-TYPE_UDWORD fixed16x16FromDouble(double value)
-{
-#if 0
- /* This version is incorrect negative values. */
- unsigned int tmp=0, pos=16;
- TYPE_UDWORD res;
-
- tmp = floor( value );
- res = tmp << 16;
- value -= tmp;
-
- tmp = 0;
- while(pos--) {
- value *= 2;
- if(value >= 1.0)tmp |= (1 << pos);
- value -= floor( value );
- }
-
- res |= tmp;
-
- return (res);
-#else
- return (TYPE_UDWORD)(value * (double)(1UL << 16));
-#endif
-}
-
-
#if defined(HAVE_VSNPRINTF) || defined(HAVE_VSPRINTF)
size_t SDCCsnprintf(char *dst, size_t n, const char *fmt, ...)
{
return len;
}
-
#endif
+
+/** Pragma tokenizer
+ */
+void
+init_pragma_token(struct pragma_token_s *token)
+{
+ dbuf_init(&token->dbuf, 16);
+ token->type = TOKEN_UNKNOWN;
+}
+
+char *
+get_pragma_token(const char *s, struct pragma_token_s *token)
+{
+ dbuf_set_size(&token->dbuf, 0);
+
+ /* skip leading spaces */
+ while ('\n' != *s && isspace(*s))
+ ++s;
+
+ if ('\0' == *s || '\n' == *s)
+ {
+ token->type = TOKEN_EOL;
+ }
+ else
+ {
+ char *end;
+
+ long val = strtol(s, &end, 0);
+
+ if (end != s && ('\0' == *end || isspace(*end)))
+ {
+ token->val.int_val = val;
+ token->type = TOKEN_INT;
+ dbuf_append(&token->dbuf, s, end - s);
+ s = end;
+ }
+ else
+ {
+ while ('\0' != *s && !isspace(*s))
+ {
+ dbuf_append(&token->dbuf, s, 1);
+ ++s;
+ }
+
+ token->type = TOKEN_STR;
+ }
+ }
+
+ return (char *)s;
+}
+
+const char *
+get_pragma_string(struct pragma_token_s *token)
+{
+ return dbuf_c_str(&token->dbuf);
+}
+
+void
+free_pragma_token(struct pragma_token_s *token)
+{
+ dbuf_destroy(&token->dbuf);
+}