aboutsummaryrefslogtreecommitdiff
path: root/qbe.c
AgeCommit message (Collapse)Author
2022-05-19Add unreachable returns to silence compiler warningsMichael Forney
2022-03-22Allow unnamed parameters in function definitionsMichael Forney
2022-03-10qbe: Only return 0 from main if it has type intMichael Forney
Though C11 5.1.2.2.1 says that main must have a return type of int, we could still encounter a program which declares it as something else. This is undefined behavior, but we should not produce invalid QBE IL in this case. Also, 5.1.2.2.3 specifies that the implicit return 0 should only apply when main's return type is compatible with int.
2022-02-10qbe: Switch to new unsigned-float conversion operatorsMichael Forney
2022-02-10qbe: Switch to unary negationMichael Forney
This fixes bugs involving floating point negative zero.
2022-01-22Handle unary minus specially instead of 0 - xMichael Forney
This is necessary to fix unary negation of floating-point 0 (also depends on a pending qbe patch).
2022-01-22Remove most usage of fixed-width integer typesMichael Forney
We only require a type of at least 64 bits, so just use unsigned long long. Only siphash remains as the last user of uint64_t.
2022-01-22Port to C99Michael Forney
2021-11-25Add __builtin_unreachable stubMichael Forney
2021-10-25decl: Allow alignment > 16 of localsMichael Forney
This is not yet supported by QBE, so for now we allocate a bit extra and choose the address in the allocated region with an aligned address.
2021-10-25qbe: Add helper function for mkinstMichael Forney
This simplifies the creation of allocation instructions in the start block.
2021-10-25qbe: Use ... to separate named and variadic argumentsMichael Forney
This requires a not-yet-upstream QBE patch, and is needed for riscv64 support, since the calling convention may be different depending on whether the argument is named or variadic.
2021-10-18expr: Make sure __builtin_va_end argument is evaluated for side-effectsMichael Forney
2021-10-18qbe: Fix jnz controlled by short/char typeMichael Forney
Although we don't need the cnew in this case, we still need to do the appropriate extension to 32-bit.
2021-10-03expr: Use end pointer to detect string-to-number conversion failuresMichael Forney
We explicitly ignore ERANGE for strtod, and in any other error case, the end pointer is set to the beginning of the string.
2021-10-03qbe: Remove some unused includesMichael Forney
We now hard-code the float precision in the format string instead of using the float.h macros. The other headers were never used (except maybe prior to the first commit).
2021-10-02qbe: Re-add conversion to bool RHS of logical and/orMichael Forney
7e838669 removed conversion to bool for int expressions used only to control jnz, but incorrectly dropped the conversion for the right-hand-side of logical and/or as well. We need the result of the expression to be 0 or 1, so we still need that conversion.
2021-09-29qbe: Add missing check that binary operator is + for address constantMichael Forney
2021-09-29Rename uint64_t field of constant union to uMichael Forney
This will prepare us for adding a signed int64_t field called i.
2021-09-29Use unsigned long long for sizes and offsetsMichael Forney
We don't need exact-width integer types here.
2021-09-28Skip unnecessary conversion to bool for logical and conditional expressionsMichael Forney
As in ede6a5c9, if an expression is used only to control a jnz, we don't need to convert it to a 0 or 1 value. QBE ignores the upper 32-bits of the argument to jnz, so the conversion is still needed for pointer, long, and floating point types (including float since -0 has non-zero bit representation).
2021-09-14qbe: Support more aligned types in funccopyMichael Forney
We don't have any of these currently, but it's easier to support than to error out.
2021-09-14qbe: Fix temporary type for < 8 byte aligned struct copiesMichael Forney
2021-09-13qbe, init: Handle prefixed string literalsNihal Jere
2021-09-13Make string literal data unsigned charMichael Forney
2021-09-07qbe: Add default cases to avoid uninitialized warningMichael Forney
2021-09-04Use architecture-specific va_list typeMichael Forney
Previously, cproc effectively used used typedef struct { /* 32 bytes, 8-byte aligned */ } __builtin_va_list[1]; However, this is not quite correct for x86_64 nor aarch64, though it was close enough for both to work in most cases. In actuality, for x86_64 we want typedef struct { /* 24 bytes, 8-byte aligned */ } __builtin_va_list[1]; and for aarch64 we want typedef struct { /* 32 bytes, 8-byte aligned */ } __builtin_va_list; The difference only appears when the size of va_list matters, or when va_list is passed as a parameter. However, the former is not often the case, and the aarch64 ABI replaces aggregate arguments with pointers to caller-allocated memory, which is quite similar to arrays decaying to pointers in C except that the struct is not copied. Additionally, riscv64 simply uses typedef void *__builtin_va_list; which again has a different size and calling convention. To fix this, make the __builtin_va_list type architecture-specific and use architecture-specific tests for varargs-related functionality.
2021-09-02qbe: Error on use of long double rather than trigger assertionMichael Forney
2021-07-05qbe: StyleMichael Forney
2021-07-05qbe: Fix bitfield sign extension with types shorter than intMichael Forney
2021-07-02qbe: Mark static const data as suchMichael Forney
2021-07-02qbe: Remove more unnecessary copy instructionsMichael Forney
Now that we don't track QBE types within values, we don't have to worry about generating incorrect SSA when passing an 'l' value to a function taking a 'w'. So we can just return the source value instead of emitting a dummy copy instruction.
2021-07-02qbe: Remove repr from struct value and use per-instruction class insteadMichael Forney
This way we avoid leaking backend-specific details of type representation outside qbe.c. It also facilitates some future simplifications.
2021-07-01qbe: Remove unnecessary distinction between loaduw and loadswMichael Forney
We always store the result to a w temporary, so there is no difference. In fact, QBE provides loadw as an alias for loadsw precisely for this reason.
2021-07-01qbe: Reorganize struct value to reduce size to 8 bytesMichael Forney
Make the ID an unsigned int. This will make it small enough to efficiently pass struct value by value. It also simplifies things slightly.
2021-06-30qbe: Move aggregate copying to separate functionMichael Forney
2021-06-30qbe: Remove before unnecessary adds during copyMichael Forney
2021-05-02qbe: Use fixed precision of 17 when printing floating point constantsMichael Forney
It appears that some operating systems don't yet support the C11 DBL_DECIMAL_DIG. In order to ensure consistent output no matter the precision of long double (which varies from arch to arch), just use a fixed 17, which is sufficient for IEEE 754 binary64.
2021-04-23Make some static data constMichael Forney
2021-04-21qbe: Print floating point with DBL_DECIMAL_DIG precisionMichael Forney
DECIMAL_DIG may vary from system to system depending on the width of long double, causing one of the tests to fail.
2021-04-08qbe: Remove unnecessary value copy for struct/union typesMichael Forney
Previously, this was needed so that an aggregate type value was updated to be an 'l' type value. However, since 5ff1d2fa the aggregate type name is stored in a separate parameter in IARG/ICALL instructions, so we can just re-use the same pointer value.
2021-04-08qbe: Remove unnecessary extension for relational operandsMichael Forney
The operands are already promoted, so never need to be extended. These extend()s were added in 7d746860 in an attempt to fix a bug related to the comparison of values with type smaller than int. However, the real bug was that the operands should have been promoted to int by usual arithmetic conversions, which was fixed later in a8131372.
2021-04-07qbe: Remove __PRETTY_FUNCTION__ declarationMichael Forney
We no longer define __GNUC__ so we don't have to work around glibc's assert definition anymore.
2021-04-06qbe: Shorten a few overly long linesMichael Forney
2021-03-31qbe: Slight simplificationMichael Forney
2021-03-31qbe: Use second argument of call/arg to store type nameMichael Forney
2021-03-31qbe: Use separate type for block/labelMichael Forney
Labels are no longer used as instruction arguments.
2021-03-31qbe: Switch to fixed-size instruction structMichael Forney
Move jump and phi instructions to struct block, and function arguments to their own instruction. This will facilitate allocating instructions as an array.
2021-03-27qbe: Change value kind naming schemeMichael Forney
2020-05-24qbe: Omit unnecessary add to help QBE's memopt passMichael Forney