-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathMacro.cpp
890 lines (840 loc) · 19.4 KB
/
Macro.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
/*******************************************************************************
* Copyright IBM Corp. and others 2015
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include "ddr/ir/Macro.hpp"
#include "ddr/ir/Type.hpp"
#include <ctype.h>
#include <stdint.h>
#include <string.h>
enum Symbol {
OR_OR, /* || */
AND_AND, /* && */
OR, /* | */
XOR, /* ^ */
AND, /* & */
EQ_EQ, /* == */
NOT_EQ, /* != */
GT, /* > */
LT, /* < */
GT_EQ, /* >= */
LT_EQ, /* <= */
GT_GT, /* >> */
LT_LT, /* << */
PLUS, /* + */
MINUS, /* - */
MULT, /* * */
DIV, /* / */
REM, /* % */
NOT, /* ! */
TILDE, /* ~ */
LPAREN, /* ( */
RPAREN, /* ) */
END /* '\0' or null terminator */
};
class MacroScanner
{
private:
char const *_cursor;
static bool isDigit(char c, int32_t base);
static int32_t digitValue(char c);
void skipWhitespace();
public:
MacroScanner(char const *cString)
: _cursor(cString)
{
}
bool validTypeCast(bool *isSigned, size_t *bitWidth);
bool atSymbol(Symbol sym);
bool readNumber(int64_t *ret);
};
class MacroParser
{
/* data members */
private:
MacroScanner _scanner; /* handles reading characters from expression string */
/* function members */
private:
bool logicalOr(int64_t *ret);
bool logicalAnd(int64_t *ret);
bool bitwiseOr(int64_t *ret);
bool bitwiseXor(int64_t *ret);
bool bitwiseAnd(int64_t *ret);
bool equalNeq(int64_t *ret);
bool comparison(int64_t *ret);
bool bitshift(int64_t *ret);
bool addSub(int64_t *ret);
bool multDivRem(int64_t *ret);
bool unaryExpression(int64_t *ret);
bool parentheses(int64_t *ret);
bool validSingleTerm(int64_t *ret);
public:
MacroParser(char const *cExpression) :
_scanner(cExpression)
{
}
bool evaluate(int64_t *ret);
};
/**
* Helper function to check if a character is a digit in a specified base.
*
* @param[in] c: character being checked
* @param[in] base: the base used to check if the char is valid
*
* @return: if the character is a valid digit in the specified base
*/
bool
MacroScanner::isDigit(char c, int32_t base)
{
if (base > 10) {
return (('0' <= c) && (c <= '9'))
|| (('a' <= c) && (c < ('a' + base - 10)))
|| (('A' <= c) && (c < ('A' + base - 10)));
} else {
return ('0' <= c) && (c < ('0' + base));
}
}
/**
* Helper function to read the value of a number from a string, this gets the
* value of a single digit, assuming digits go 0-9 then A-Z case-insensitive
* (36 possible digits)
*
* @param[in] c: digit whose value is sought
*
* @return: integer value of the digit
*/
int32_t
MacroScanner::digitValue(char c)
{
if (('a' <= c) && (c <= 'z')) {
return 10 + c - 'a';
} else if (('A' <= c) && (c <= 'Z')) {
return 10 + c - 'A';
} else {
return c - '0';
}
}
void
MacroScanner::skipWhitespace()
{
while (isspace(*_cursor)) {
_cursor += 1;
}
}
/**
* Checks if the cursor is at a valid type cast expression, after encountering
* a left parenthesis. If it is, determine the signedness and bit width of the
* type cast. If not, move the cursor back to the left parenthesis.
*
* @param[out] isSigned: the signedness of the resulting typecast
* @param[out] bitWidth: the bit width of the resulting typecast
*
* @return: if the typecast expression is valid
*/
bool
MacroScanner::validTypeCast(bool *isSigned, size_t *bitWidth)
{
char const *const savedCursor = _cursor;
if (!atSymbol(LPAREN)) {
return false;
}
skipWhitespace();
const char *start = _cursor;
const char *end = start;
while (isalpha(*_cursor)) {
do {
_cursor += 1;
} while (('_' == *_cursor) || isalnum(*_cursor));
end = _cursor;
skipWhitespace();
}
if (!atSymbol(RPAREN)) {
_cursor = savedCursor;
return false;
}
return Type::isStandardType(start, (size_t)(end - start), isSigned, bitWidth);
}
/**
* Check if the cursor is at a specific symbol, and if it is, consume the
* symbol and move the cursor forward.
*/
bool
MacroScanner::atSymbol(Symbol sym)
{
skipWhitespace();
switch (sym) {
case OR_OR:
if (0 == strncmp(_cursor, "||", 2)) {
_cursor += 2;
return true;
}
break;
case AND_AND:
if (0 == strncmp(_cursor, "&&", 2)) {
_cursor += 2;
return true;
}
break;
case OR:
if (('|' == _cursor[0]) && ('|' != _cursor[1]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case XOR:
if ('^' == _cursor[0] && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case AND:
if (('&' == _cursor[0]) && ('&' != _cursor[1]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case EQ_EQ:
if (0 == strncmp(_cursor, "==", 2)) {
_cursor += 2;
return true;
}
break;
case NOT_EQ:
if (0 == strncmp(_cursor, "!=", 2)) {
_cursor += 2;
return true;
}
break;
case GT:
if (('>' == _cursor[0]) && ('>' != _cursor[1]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case LT:
if (('<' == _cursor[0]) && ('<' != _cursor[1]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case GT_EQ:
if (0 == strncmp(_cursor, ">=", 2)) {
_cursor += 2;
return true;
}
break;
case LT_EQ:
if (0 == strncmp(_cursor, "<=", 2)) {
_cursor += 2;
return true;
}
break;
case GT_GT:
if (0 == strncmp(_cursor, ">>", 2) && ('=' != _cursor[2])) {
_cursor += 2;
return true;
}
break;
case LT_LT:
if (0 == strncmp(_cursor, "<<", 2) && ('=' != _cursor[2])) {
_cursor += 2;
return true;
}
break;
case PLUS:
if (('+' == _cursor[0]) && ('+' != _cursor[1]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case MINUS:
if (('-' == _cursor[0]) && ('-' != _cursor[1]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case MULT:
if (('*' == _cursor[0]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case DIV:
if (('/' == _cursor[0]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case REM:
if (('%' == _cursor[0]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case NOT:
if (('!' == _cursor[0]) && ('=' != _cursor[1])) {
_cursor += 1;
return true;
}
break;
case TILDE:
if ('~' == _cursor[0]) {
_cursor += 1;
return true;
}
break;
case LPAREN:
if ('(' == _cursor[0]) {
_cursor += 1;
return true;
}
break;
case RPAREN:
if (')' == _cursor[0]) {
_cursor += 1;
return true;
}
break;
case END:
return '\0' == _cursor[0];
default:
break;
}
return false;
}
/**
* Reads an integer number starting at the cursor in the expression string.
* Number is read as a 64bit integer.
*/
bool
MacroScanner::readNumber(int64_t *ret)
{
uint64_t retval = 0;
int32_t base = 0;
skipWhitespace();
if (!(isdigit(_cursor[0]))) {
return false;
}
if ('0' == _cursor[0]) {
_cursor += 1;
if (('b' == _cursor[0]) || ('B' == _cursor[0])) {
base = 2;
_cursor += 1;
} else if (('x' == _cursor[0]) || ('X' == _cursor[0])) {
base = 16;
_cursor += 1;
} else {
base = 8;
}
} else {
base = 10;
}
while (isDigit(_cursor[0], base)) {
retval *= base;
retval += digitValue(_cursor[0]);
_cursor += 1;
}
/* type suffixes do nothing since we treat each literal as an uint64_t.
* so we just verify the suffix is correct
*/
bool seenL = false;
bool seenU = false;
for (int32_t i = 0; _cursor[0] && (i < 3); ++i, ++_cursor) {
if (('l' == _cursor[0]) || ('L' == _cursor[0])) {
if (seenL) {
return false;
}
seenL = true;
// case of 'L's must match
if (_cursor[0] == _cursor[1]) {
_cursor += 1;
} else if (('l' == _cursor[1]) || ('L' == _cursor[1])) {
return false;
}
} else if (('u' == _cursor[0]) || ('U' == _cursor[0])){
if (seenU) {
return false;
}
seenU = true;
} else {
break;
}
}
*ret = retval;
return true;
}
/**
* Evaluates a constant expression found in a macro. The parser assumes that
* all values have all been resolved into constants. Thus it does not handle
* any of the operators that require an lvalue (i.e. increment).
*
* @param[out] ret: the integer value the expression evaluates to
*
* @return: whether the expression is valid or not
*/
bool
MacroParser::evaluate(int64_t *ret)
{
return logicalOr(ret) && _scanner.atSymbol(END);
}
/**
* Evaluates a logical or expression (a || b) by recursively calling the
* functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the logical or expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::logicalOr(int64_t *ret)
{
int64_t term2 = 0;
if (logicalAnd(ret)) {
for (;;) {
if (_scanner.atSymbol(OR_OR)) {
if (logicalAnd(&term2)) {
*ret = *ret || term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates a logical and expression (a && b) by recursively calling the
* functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the logical and expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::logicalAnd(int64_t *ret)
{
int64_t term2 = 0;
if (bitwiseOr(ret)) {
for (;;) {
if (_scanner.atSymbol(AND_AND)) {
if (bitwiseOr(&term2)) {
*ret = *ret && term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates a bitwise or expression (a | b) by recursively calling the
* functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the bitwise or expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::bitwiseOr(int64_t *ret)
{
int64_t term2 = 0;
if (bitwiseXor(ret)) {
for (;;) {
if (_scanner.atSymbol(OR)) {
if (bitwiseXor(&term2)) {
*ret = *ret | term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates a bitwise xor expression (a ^ b) by recursively calling the
* functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the bitwise xor expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::bitwiseXor(int64_t *ret)
{
int64_t term2 = 0;
if (bitwiseAnd(ret)) {
for (;;) {
if (_scanner.atSymbol(XOR)) {
if (bitwiseAnd(&term2)) {
*ret = *ret ^ term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates a bitwise and expression (a & b) by recursively calling the
* functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the bitwise and expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::bitwiseAnd(int64_t *ret)
{
int64_t term2 = 0;
if (equalNeq(ret)) {
for (;;) {
if (_scanner.atSymbol(AND)) {
if (equalNeq(&term2)) {
*ret = *ret & term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates the 2 expressions: equality (a == b), and inequality (a != b),
* which have the same operator precedence, by recursively calling the
* functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the logical and expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::equalNeq(int64_t *ret)
{
int64_t term2 = 0;
if (comparison(ret)) {
for (;;) {
if (_scanner.atSymbol(EQ_EQ)) {
if (comparison(&term2)) {
*ret = *ret == term2;
} else {
return false;
}
} else if (_scanner.atSymbol(NOT_EQ)) {
if (comparison(&term2)) {
*ret = *ret != term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates the comparison expressions: greater than (a > b), less than (a < b),
* greater than or equal to (a >= b), less than or equal to (a <= b),
* which have the same operator precedence, by recursively calling the
* functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the logical and expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::comparison(int64_t *ret)
{
int64_t term2 = 0;
if (bitshift(ret)) {
for (;;) {
if (_scanner.atSymbol(GT_EQ)) {
if (bitshift(&term2)) {
*ret = *ret >= term2;
} else {
return false;
}
} else if (_scanner.atSymbol(LT_EQ)) {
if (bitshift(&term2)) {
*ret = *ret <= term2;
} else {
return false;
}
} else if (_scanner.atSymbol(GT)) {
if (bitshift(&term2)) {
*ret = *ret > term2;
} else {
return false;
}
} else if (_scanner.atSymbol(LT)) {
if (bitshift(&term2)) {
*ret = *ret < term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates the bitshift expressions: shift left (a << b), and shift right
* (a >> b), which have the same operator precedence, by recursively calling
* the functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the logical and expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::bitshift(int64_t *ret)
{
int64_t term2 = 0;
if (addSub(ret)) {
for (;;) {
if (_scanner.atSymbol(GT_GT)) {
if (addSub(&term2)) {
*ret = *ret >> term2;
} else {
return false;
}
} else if (_scanner.atSymbol(LT_LT)) {
if (addSub(&term2)) {
*ret = *ret << term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates the addition expression (a + b), and the subtraction expression
* (a - b), which have the same operator precedence, by recursively calling
* the functions for evaluating expressions with higher precedence.
*
* @param[out] ret: the integer value the logical and expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::addSub(int64_t *ret)
{
int64_t term2 = 0;
if (multDivRem(ret)) {
for (;;) {
if (_scanner.atSymbol(PLUS)) {
if (multDivRem(&term2)) {
*ret = *ret + term2;
} else {
return false;
}
} else if (_scanner.atSymbol(MINUS)) {
if (multDivRem(&term2)) {
*ret = *ret - term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates the multiplication (a * b), division (a / b), and remainder
* (a % b) expressions, which have the same operator precedence, by recursively
* calling the functions for evaluating expressions with higher precedence.
* Since this is the highest precedence binary expression, it will attempt to
* evaluate its operands as either unary expressions, parenthesized
* expressions, or numbers.
*
* @param[out] ret: the integer value the logical and expression evaluates to
*
* @return: whether at the current location the expression can be evaluated
*/
bool
MacroParser::multDivRem(int64_t *ret)
{
int64_t term2 = 0;
if (validSingleTerm(ret)) {
for (;;) {
if (_scanner.atSymbol(MULT)) {
if (validSingleTerm(&term2)) {
*ret = *ret * term2;
} else {
return false;
}
} else if (_scanner.atSymbol(DIV)) {
if (validSingleTerm(&term2)) {
*ret = *ret / term2;
} else {
return false;
}
} else if (_scanner.atSymbol(REM)) {
if (validSingleTerm(&term2)) {
*ret = *ret % term2;
} else {
return false;
}
} else {
return true;
}
}
}
return false;
}
/**
* Evaluates a unary expression from the current index in the expression
* string recursively.
*
* @param[out] ret: the integer value the unary expression evaluates to
*
* @return: whether at the current location can be evaluated as a unary
* expression
*/
bool
MacroParser::unaryExpression(int64_t *ret)
{
int64_t operand = 0;
size_t bitWidth = 0;
bool isSigned = true;
if (_scanner.atSymbol(PLUS)) {
if (validSingleTerm(&operand)) {
*ret = +operand;
return true;
}
} else if (_scanner.atSymbol(MINUS)) {
if (validSingleTerm(&operand)) {
*ret = -operand;
return true;
}
} else if (_scanner.atSymbol(NOT)) {
if (validSingleTerm(&operand)) {
*ret = !operand;
return true;
}
} else if (_scanner.atSymbol(TILDE)) {
if (validSingleTerm(&operand)) {
*ret = ~operand;
return true;
}
} else if (_scanner.validTypeCast(&isSigned, &bitWidth)) {
if (validSingleTerm(&operand)) {
switch (bitWidth) {
case 8:
*ret = isSigned ? (int8_t) operand : (uint8_t) operand;
break;
case 16:
*ret = isSigned ? (int16_t) operand : (uint16_t) operand;
break;
case 32:
*ret = isSigned ? (int32_t) operand : (uint32_t) operand;
break;
default:
/*
* If the bit-width is 64 it has no meaningful effect.
* Ignore casts of unknown widths.
*/
*ret = operand;
break;
}
return true;
}
}
return false;
}
/**
* Evaluates a parenthesized expression from the current index in the
* expression string recursively.
*
* @param[out] ret: the integer value the expression evaluates to
*
* @return: whether at the current location can be evaluated as a parenthesized
* expression
*/
bool
MacroParser::parentheses(int64_t *ret)
{
int64_t innerValue = 0;
if (_scanner.atSymbol(LPAREN)) {
if (logicalOr(&innerValue)) {
if (_scanner.atSymbol(RPAREN)) {
*ret = innerValue;
return true;
}
}
}
return false;
}
/**
* Checks if the expression at the cursor is one of: unary expression,
* parenthesized expression, or a number, then evaluates it.
*
* @param[out] ret: the value after evaluating the expression
*
* return: whether at the current location can be evaluated as one of the
* expressions listed
*/
bool
MacroParser::validSingleTerm(int64_t *ret)
{
return unaryExpression(ret) || parentheses(ret) || _scanner.readNumber(ret);
}
/*
* evaluates the numeric value of a constant expression from a macro
*
* @param[out] ret: the integer value of the expression in an long long
*
* return: DDR return code indicating success or error
*/
DDR_RC
Macro::getNumeric(long long *ret) const
{
DDR_RC rc = DDR_RC_ERROR;
int64_t retVal = 0;
MacroParser parser(_value.c_str());
if (parser.evaluate(&retVal)) {
if (NULL != ret) {
*ret = retVal;
}
rc = DDR_RC_OK;
}
return rc;
}