1478
1493
gen_expr (exp, pc, ax, &value1);
1479
1494
gen_usual_unary (exp, ax, &value1);
1480
gen_expr (exp, pc, ax, &value2);
1481
gen_usual_unary (exp, ax, &value2);
1482
gen_usual_arithmetic (exp, ax, &value1, &value2);
1486
if (TYPE_CODE (value1.type) == TYPE_CODE_INT
1487
&& TYPE_CODE (value2.type) == TYPE_CODE_PTR)
1489
/* Swap the values and proceed normally. */
1490
ax_simple (ax, aop_swap);
1491
gen_ptradd (ax, value, &value2, &value1);
1493
else if (TYPE_CODE (value1.type) == TYPE_CODE_PTR
1494
&& TYPE_CODE (value2.type) == TYPE_CODE_INT)
1495
gen_ptradd (ax, value, &value1, &value2);
1497
gen_binop (ax, value, &value1, &value2,
1498
aop_add, aop_add, 1, "addition");
1501
if (TYPE_CODE (value1.type) == TYPE_CODE_PTR
1502
&& TYPE_CODE (value2.type) == TYPE_CODE_INT)
1503
gen_ptrsub (ax,value, &value1, &value2);
1504
else if (TYPE_CODE (value1.type) == TYPE_CODE_PTR
1505
&& TYPE_CODE (value2.type) == TYPE_CODE_PTR)
1506
/* FIXME --- result type should be ptrdiff_t */
1507
gen_ptrdiff (ax, value, &value1, &value2,
1508
builtin_type (exp->gdbarch)->builtin_long);
1510
gen_binop (ax, value, &value1, &value2,
1511
aop_sub, aop_sub, 1, "subtraction");
1514
gen_binop (ax, value, &value1, &value2,
1515
aop_mul, aop_mul, 1, "multiplication");
1518
gen_binop (ax, value, &value1, &value2,
1519
aop_div_signed, aop_div_unsigned, 1, "division");
1522
gen_binop (ax, value, &value1, &value2,
1523
aop_rem_signed, aop_rem_unsigned, 1, "remainder");
1525
case BINOP_SUBSCRIPT:
1526
gen_ptradd (ax, value, &value1, &value2);
1527
if (TYPE_CODE (value->type) != TYPE_CODE_PTR)
1528
error (_("Invalid combination of types in array subscripting."));
1529
gen_deref (ax, value);
1531
case BINOP_BITWISE_AND:
1532
gen_binop (ax, value, &value1, &value2,
1533
aop_bit_and, aop_bit_and, 0, "bitwise and");
1536
case BINOP_BITWISE_IOR:
1537
gen_binop (ax, value, &value1, &value2,
1538
aop_bit_or, aop_bit_or, 0, "bitwise or");
1541
case BINOP_BITWISE_XOR:
1542
gen_binop (ax, value, &value1, &value2,
1543
aop_bit_xor, aop_bit_xor, 0, "bitwise exclusive-or");
1547
gen_binop (ax, value, &value1, &value2,
1548
aop_equal, aop_equal, 0, "equal");
1551
case BINOP_NOTEQUAL:
1552
gen_binop (ax, value, &value1, &value2,
1553
aop_equal, aop_equal, 0, "equal");
1554
gen_logical_not (ax, value,
1555
language_bool_type (exp->language_defn,
1560
gen_binop (ax, value, &value1, &value2,
1561
aop_less_signed, aop_less_unsigned, 0, "less than");
1565
ax_simple (ax, aop_swap);
1566
gen_binop (ax, value, &value1, &value2,
1567
aop_less_signed, aop_less_unsigned, 0, "less than");
1571
ax_simple (ax, aop_swap);
1572
gen_binop (ax, value, &value1, &value2,
1573
aop_less_signed, aop_less_unsigned, 0, "less than");
1574
gen_logical_not (ax, value,
1575
language_bool_type (exp->language_defn,
1580
gen_binop (ax, value, &value1, &value2,
1581
aop_less_signed, aop_less_unsigned, 0, "less than");
1582
gen_logical_not (ax, value,
1583
language_bool_type (exp->language_defn,
1588
/* We should only list operators in the outer case statement
1589
that we actually handle in the inner case statement. */
1590
internal_error (__FILE__, __LINE__,
1591
_("gen_expr: op case sets don't match"));
1495
gen_expr_binop_rest (exp, op, pc, ax, value, &value1, &value2);
1498
case BINOP_LOGICAL_AND:
1500
/* Generate the obvious sequence of tests and jumps. */
1501
gen_expr (exp, pc, ax, &value1);
1502
gen_usual_unary (exp, ax, &value1);
1503
if1 = ax_goto (ax, aop_if_goto);
1504
go1 = ax_goto (ax, aop_goto);
1505
ax_label (ax, if1, ax->len);
1506
gen_expr (exp, pc, ax, &value2);
1507
gen_usual_unary (exp, ax, &value2);
1508
if2 = ax_goto (ax, aop_if_goto);
1509
go2 = ax_goto (ax, aop_goto);
1510
ax_label (ax, if2, ax->len);
1512
end = ax_goto (ax, aop_goto);
1513
ax_label (ax, go1, ax->len);
1514
ax_label (ax, go2, ax->len);
1516
ax_label (ax, end, ax->len);
1517
value->kind = axs_rvalue;
1518
value->type = language_bool_type (exp->language_defn, exp->gdbarch);
1521
case BINOP_LOGICAL_OR:
1523
/* Generate the obvious sequence of tests and jumps. */
1524
gen_expr (exp, pc, ax, &value1);
1525
gen_usual_unary (exp, ax, &value1);
1526
if1 = ax_goto (ax, aop_if_goto);
1527
gen_expr (exp, pc, ax, &value2);
1528
gen_usual_unary (exp, ax, &value2);
1529
if2 = ax_goto (ax, aop_if_goto);
1531
end = ax_goto (ax, aop_goto);
1532
ax_label (ax, if1, ax->len);
1533
ax_label (ax, if2, ax->len);
1535
ax_label (ax, end, ax->len);
1536
value->kind = axs_rvalue;
1537
value->type = language_bool_type (exp->language_defn, exp->gdbarch);
1542
gen_expr (exp, pc, ax, &value1);
1543
gen_usual_unary (exp, ax, &value1);
1544
/* For (A ? B : C), it's easiest to generate subexpression
1545
bytecodes in order, but if_goto jumps on true, so we invert
1546
the sense of A. Then we can do B by dropping through, and
1548
gen_logical_not (ax, &value1,
1549
language_bool_type (exp->language_defn, exp->gdbarch));
1550
if1 = ax_goto (ax, aop_if_goto);
1551
gen_expr (exp, pc, ax, &value2);
1552
gen_usual_unary (exp, ax, &value2);
1553
end = ax_goto (ax, aop_goto);
1554
ax_label (ax, if1, ax->len);
1555
gen_expr (exp, pc, ax, &value3);
1556
gen_usual_unary (exp, ax, &value3);
1557
ax_label (ax, end, ax->len);
1558
/* This is arbitary - what if B and C are incompatible types? */
1559
value->type = value2.type;
1560
value->kind = value2.kind;
1565
if ((*pc)[0].opcode == OP_INTERNALVAR)
1567
char *name = internalvar_name ((*pc)[1].internalvar);
1568
struct trace_state_variable *tsv;
1570
gen_expr (exp, pc, ax, value);
1571
tsv = find_trace_state_variable (name);
1574
ax_tsv (ax, aop_setv, tsv->number);
1576
ax_tsv (ax, aop_tracev, tsv->number);
1579
error (_("$%s is not a trace state variable, may not assign to it"), name);
1582
error (_("May only assign to trace state variables"));
1585
case BINOP_ASSIGN_MODIFY:
1587
op2 = (*pc)[0].opcode;
1590
if ((*pc)[0].opcode == OP_INTERNALVAR)
1592
char *name = internalvar_name ((*pc)[1].internalvar);
1593
struct trace_state_variable *tsv;
1595
tsv = find_trace_state_variable (name);
1598
/* The tsv will be the left half of the binary operation. */
1599
ax_tsv (ax, aop_getv, tsv->number);
1601
ax_tsv (ax, aop_tracev, tsv->number);
1602
/* Trace state variables are always 64-bit integers. */
1603
value1.kind = axs_rvalue;
1604
value1.type = builtin_type (exp->gdbarch)->builtin_long_long;
1605
/* Now do right half of expression. */
1606
gen_expr_binop_rest (exp, op2, pc, ax, value, &value1, &value2);
1607
/* We have a result of the binary op, set the tsv. */
1608
ax_tsv (ax, aop_setv, tsv->number);
1610
ax_tsv (ax, aop_tracev, tsv->number);
1613
error (_("$%s is not a trace state variable, may not assign to it"), name);
1616
error (_("May only assign to trace state variables"));
1595
1619
/* Note that we need to be a little subtle about generating code
1766
1828
error (_("Unsupported operator in expression."));
1832
/* This handles the middle-to-right-side of code generation for binary
1833
expressions, which is shared between regular binary operations and
1834
assign-modify (+= and friends) expressions. */
1837
gen_expr_binop_rest (struct expression *exp,
1838
enum exp_opcode op, union exp_element **pc,
1839
struct agent_expr *ax, struct axs_value *value,
1840
struct axs_value *value1, struct axs_value *value2)
1842
gen_expr (exp, pc, ax, value2);
1843
gen_usual_unary (exp, ax, value2);
1844
gen_usual_arithmetic (exp, ax, value1, value2);
1848
if (TYPE_CODE (value1->type) == TYPE_CODE_INT
1849
&& pointer_type (value2->type))
1851
/* Swap the values and proceed normally. */
1852
ax_simple (ax, aop_swap);
1853
gen_ptradd (ax, value, value2, value1);
1855
else if (pointer_type (value1->type)
1856
&& TYPE_CODE (value2->type) == TYPE_CODE_INT)
1857
gen_ptradd (ax, value, value1, value2);
1859
gen_binop (ax, value, value1, value2,
1860
aop_add, aop_add, 1, "addition");
1863
if (pointer_type (value1->type)
1864
&& TYPE_CODE (value2->type) == TYPE_CODE_INT)
1865
gen_ptrsub (ax,value, value1, value2);
1866
else if (pointer_type (value1->type)
1867
&& pointer_type (value2->type))
1868
/* FIXME --- result type should be ptrdiff_t */
1869
gen_ptrdiff (ax, value, value1, value2,
1870
builtin_type (exp->gdbarch)->builtin_long);
1872
gen_binop (ax, value, value1, value2,
1873
aop_sub, aop_sub, 1, "subtraction");
1876
gen_binop (ax, value, value1, value2,
1877
aop_mul, aop_mul, 1, "multiplication");
1880
gen_binop (ax, value, value1, value2,
1881
aop_div_signed, aop_div_unsigned, 1, "division");
1884
gen_binop (ax, value, value1, value2,
1885
aop_rem_signed, aop_rem_unsigned, 1, "remainder");
1887
case BINOP_SUBSCRIPT:
1891
if (binop_types_user_defined_p (op, value1->type, value2->type))
1894
cannot subscript requested type: cannot call user defined functions"));
1898
/* If the user attempts to subscript something that is not
1899
an array or pointer type (like a plain int variable for
1900
example), then report this as an error. */
1901
type = check_typedef (value1->type);
1902
if (TYPE_CODE (type) != TYPE_CODE_ARRAY
1903
&& TYPE_CODE (type) != TYPE_CODE_PTR)
1905
if (TYPE_NAME (type))
1906
error (_("cannot subscript something of type `%s'"),
1909
error (_("cannot subscript requested type"));
1913
if (!is_integral_type (value2->type))
1914
error (_("Argument to arithmetic operation not a number or boolean."));
1916
gen_ptradd (ax, value, value1, value2);
1917
gen_deref (ax, value);
1920
case BINOP_BITWISE_AND:
1921
gen_binop (ax, value, value1, value2,
1922
aop_bit_and, aop_bit_and, 0, "bitwise and");
1925
case BINOP_BITWISE_IOR:
1926
gen_binop (ax, value, value1, value2,
1927
aop_bit_or, aop_bit_or, 0, "bitwise or");
1930
case BINOP_BITWISE_XOR:
1931
gen_binop (ax, value, value1, value2,
1932
aop_bit_xor, aop_bit_xor, 0, "bitwise exclusive-or");
1936
gen_binop (ax, value, value1, value2,
1937
aop_equal, aop_equal, 0, "equal");
1940
case BINOP_NOTEQUAL:
1941
gen_binop (ax, value, value1, value2,
1942
aop_equal, aop_equal, 0, "equal");
1943
gen_logical_not (ax, value,
1944
language_bool_type (exp->language_defn,
1949
gen_binop (ax, value, value1, value2,
1950
aop_less_signed, aop_less_unsigned, 0, "less than");
1954
ax_simple (ax, aop_swap);
1955
gen_binop (ax, value, value1, value2,
1956
aop_less_signed, aop_less_unsigned, 0, "less than");
1960
ax_simple (ax, aop_swap);
1961
gen_binop (ax, value, value1, value2,
1962
aop_less_signed, aop_less_unsigned, 0, "less than");
1963
gen_logical_not (ax, value,
1964
language_bool_type (exp->language_defn,
1969
gen_binop (ax, value, value1, value2,
1970
aop_less_signed, aop_less_unsigned, 0, "less than");
1971
gen_logical_not (ax, value,
1972
language_bool_type (exp->language_defn,
1977
/* We should only list operators in the outer case statement
1978
that we actually handle in the inner case statement. */
1979
internal_error (__FILE__, __LINE__,
1980
_("gen_expr: op case sets don't match"));
1985
/* Given a single variable and a scope, generate bytecodes to trace
1986
its value. This is for use in situations where we have only a
1987
variable's name, and no parsed expression; for instance, when the
1988
name comes from a list of local variables of a function. */
1991
gen_trace_for_var (CORE_ADDR scope, struct symbol *var)
1993
struct cleanup *old_chain = 0;
1994
struct agent_expr *ax = new_agent_expr (scope);
1995
struct axs_value value;
1997
old_chain = make_cleanup_free_agent_expr (ax);
2000
gen_var_ref (NULL, ax, &value, var);
2002
/* Make sure we record the final object, and get rid of it. */
2003
gen_traced_pop (ax, &value);
2005
/* Oh, and terminate. */
2006
ax_simple (ax, aop_end);
2008
/* We have successfully built the agent expr, so cancel the cleanup
2009
request. If we add more cleanups that we always want done, this
2010
will have to get more complicated. */
2011
discard_cleanups (old_chain);
1772
2015
/* Generating bytecode from GDB expressions: driver */