diff --git a/src/obj.cpp b/src/obj.cpp index 2d1ca1e5..a4ff2dd3 100644 --- a/src/obj.cpp +++ b/src/obj.cpp @@ -94,7 +94,9 @@ static uint64_t readParenExpression(const string &s, const map &d, exit(1); } +int lexerBits; Obj *AsmReader::read(std::istream &input) { + lexerBits = wordSize; FlexLexer *f = new yyFlexLexer(&input); Obj *o = new Obj(); std::vector::reverse_iterator cur; diff --git a/src/scanner.lex b/src/scanner.lex index e9aea7b0..b8ca051b 100644 --- a/src/scanner.lex +++ b/src/scanner.lex @@ -14,15 +14,24 @@ #include #include "include/asm-tokens.h" +#include "include/harpfloat.h" +extern int lexerBits; static int64_t read_number(const char *s) { - long long u; while (!isdigit(*s) && *s != '-' && *s != '+') s++; - sscanf(s, "%lli", &u); - return u; + if (strchr(s, 'f') || strchr(s, '.')) { + double d; + sscanf(s, "%f", &d); + return Harp::Word_u(Harp::Float(d, lexerBits)); + } else { + long long u; + sscanf(s, "%lli", &u); + return u; + } } + static std::string label_name(const char *cs) { return std::string(cs, strlen(cs)-1); } @@ -40,8 +49,9 @@ using namespace HarpTools; sym [A-Za-z_.][A-Za-z0-9_.]* decnum [1-9][0-9]* hexnum 0x[0-9a-f]+ -octnum 0[0-9]* -num [+-]?({decnum}|{hexnum}|{octnum}) +octnum 0[0-7]* +floatnum ([0-9]+f|[0-9]*\.[0-9]+) +num [+-]?({decnum}|{hexnum}|{octnum}|{floatnum}) space [ \t]* peoperator ("+"|"-"|"*"|"/"|"%"|"&"|"|"|"^"|"<<"|">>") parenexp "("({num}|{sym}|{peoperator}|{space}|"("|")")+")" @@ -52,7 +62,7 @@ endl \r?\n /* Ignore comments but keep line count consistent. */ for (const char *c = YYText(); *c; c++) if (*c == '\n') yyline++; } - +to \.def { BEGIN DEFARGS; return ASM_T_DIR_DEF; } \.perm { BEGIN PERMARGS; return ASM_T_DIR_PERM; } \.byte { BEGIN WORDARGS; return ASM_T_DIR_BYTE; } diff --git a/src/test/dotprod.s b/src/test/dotprod.s new file mode 100644 index 00000000..a73886c7 --- /dev/null +++ b/src/test/dotprod.s @@ -0,0 +1,39 @@ +/******************************************************************************* + HARPtools by Chad D. Kersey, Summer 2011 +******************************************************************************** + + Sample HARP assmebly program. + +*******************************************************************************/ +/* sieve of eratosthanes: Find some primes. */ +.def SIZE 0x1000 + +.align 4096 +.perm x +.entry +.global +entry: /* . . . */ + + trap; + +/* Return in r0 dot product of vectors of real values pointed to by r0 and r1, + length in r2 */ +dotprod: ldi %r3, #0; +dploop: ld %r4, %r0, #0; + ld %r5, %r1, #0; + subi %r2, %r2, #1; + addi %r0, %r0, __WORD; + addi %r1, %r1, __WORD; + rtop @p0, %r2; + fadd %r4, %r4, %r5; + fadd %r3, %r3, %r4; + @p0 ? jmpi dploop; + +.perm rw + +array_a: .word 1.0 2.0 3.0 0.5 1.0 1.5 0.33 0.67 1.0 1.33 +array_b: .word 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 + +.global +array: .space 0x1000 /* SIZE words of space. */ +