aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/compile-i386.c
AgeCommit message (Collapse)AuthorFilesLines
2021-01-27Makefile: fix version.h dependenciesKyle Russell1-2/+1
This guarantees the generated version.h will exist before attempting to compile any c files that include it. Several source files include the generated version.h, but not all declare a proper make dependency. $ grep -r 'version\.h' *.c compile-i386.c:#include "version.h" lib.c:#include "version.h" options.c:#include "version.h" This allows a sufficiently parallelized make invocation to encounter ENOENT. CC compile-i386.o compile-i386.c:60:21: fatal error: version.h: No such file or directory compilation terminated. Makefile:253: recipe for target 'compile-i386.o' failed make: *** [compile-i386.o] Error 1 Signed-off-by: Kyle Russell <bkylerussell@gmail.com> [luc.vanoostenryck@gmail.com: modified so that only version.c depends on version.h] Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-02-20ban use of 'true' or 'false'Luc Van Oostenryck1-9/+9
The idea being, of course, to be able for some functions to return a bool, making clear what's their possible returned values. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2018-02-20use '%lld' for printing long longsLuc Van Oostenryck1-2/+2
The used '%Ld' is a non-portable GNU extension (whcih I suppose predate the standization of '%lld'). Use the standard '%lld' instead. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2017-11-16add is_signed_type()Luc Van Oostenryck1-12/+2
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2017-11-11Merge branches 'volatile-loads-are-side-effects', ↵Luc Van Oostenryck1-1/+1
'fix-volatile-simplification', 'struct-asm-ops', 'restricted-pointers', 'fix-f2i-casts', 'symaddr-description', 'flush-stdout' and 'diet-simple' into tip
2017-10-02compile-i386: Use SPARSE_VERSION instead of __DATE__Uwe Kleine-König1-1/+2
The compile date isn't very informative for a tool, the version is what really matters. Additionally using __DATE__ makes the build unreprodicible. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> Acked-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2017-09-19compile-i386: make use of expression_list_size()Martin Kepplinger1-5/+1
Instead of doing it my hand, there is the expression_list_size() API we can use here. Signed-off-by: Martin Kepplinger <martink@posteo.de> Signed-off-by: Christopher Li <sparse@chrisli.org>
2017-09-19diet: remove unused struct symbol::valueLuc Van Oostenryck1-1/+1
This member seemed to be used for: - current value of an enum during parsing - index into the virtual frame but is currently not used and never set, it's only displayed in compile-i386 & show_parse (as zero since never initialized). Remove it to make struct symbol a bit more light. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2017-09-12compile-i386.c: fix a memory leak in sort_array()Martin Kepplinger1-0/+1
sort_array() locally allocates a list it. Let's free it before returning in order to avoid memory to leak. Signed-off-by: Martin Kepplinger <martink@posteo.de> Signed-off-by: Christopher Li <sparse@chrisli.org>
2014-11-10compile-i386.c: don't ignore return value of write(2)Ramsay Jones1-4/+4
Some versions of gcc (e.g. v4.8.2) complain about ignoring the return value of a call to the write(2) system call, since the system header files have marked its declaration with the warn_unused_result attribute. In order to suppress the compiler warning, check the return value from 'write' and, if it indicates an error (a negative return value), exit the process using 'die' to display an error message. Replace a second call to 'write', which does not provoke a compiler warning, with similar code for consistency. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Christopher Li <sparse@chrisli.org>
2013-11-29sparse: Relicense under the MIT licenseFranz Schrober1-1/+17
The old code was relicensed by Novafora Corporation, successor in interest to Transmeta Corporation, in 2009. Other authors were also asked about the change of their contributions to the MIT license and all with copyrightable changes agreed to it. Signed-off-by: Franz Schrober <franzschrober@yahoo.de> Acked-by: Adam DiCarlo <adam@bikko.org> Acked-by: Al Viro <viro@ZenIV.linux.org.uk> Acked-by: Alberto Bertogli <albertito@blitiri.com.ar> Acked-by: Alecs King <alecs@perlchina.org> Acked-by: Alexander Shishkin <alexander.shishckin@gmail.com> Acked-by: Alexey Dobriyan <adobriyan@gmail.com> Acked-by: Alexey Zaytsev <alexey.zaytsev@gmail.com> Acked-by: Andries E. Brouwer <Andries.Brouwer@cwi.nl> Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Acked-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Acked-by: Ben Pfaff <blp@nicira.com> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Acked-by: Bernd Petrovitsch <bernd@petrovitsch.priv.at> Acked-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> Acked-by: Blue Swirl <blauwirbel@gmail.com> Acked-by: Chris Forbes <chrisf@ijw.co.nz> Acked-by: Chris Wedgwood <cw@f00f.org> Acked-by: Christopher Li <sparse@chrisli.org> Acked-by: Damien Lespiau <damien.lespiau@gmail.com> Acked-by: Dan Carpenter <error27@gmail.com> Acked-by: Dan McGee <dan@archlinux.org> Acked-by: Daniel De Graaf <danieldegraaf@gmail.com> Acked-by: Daniel Sheridan <dan.sheridan@postman.org.uk> Acked-by: Dave Jones <davej@redhat.com> Acked-by: David Given <dg@cowlark.com> Acked-by: David Miller <davem@redhat.com> Acked-by: David Mosberger-Tang <dmosberger@gmail.com> Acked-by: David Olien <David.Olien@lsi.com> Acked-by: Diego Elio Pettenò <flameeyes@flameeyes.eu> Acked-by: Emil Medve <Emilian.Medve@Freescale.com> Acked-by: Ethan Jackson <jacksone@nicira.com> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Acked-by: Frank Zago <fzago@systemfabricworks.com> Acked-by: Frederic Crozat <fcrozat@suse.com> Acked-by: Geoff Johnstone <geoff.johnstone@gmail.com> Acked-by: Hannes Eder <hannes@hanneseder.net> Acked-by: Jan Pokorný <pokorny_jan@seznam.cz> Acked-by: Jeff Garzik <jgarzik@redhat.com> Acked-by: Jiri Slaby <jslaby@suse.cz> Acked-by: Joe Perches <joe@perches.com> Acked-by: Joel Soete <rubisher@scarlet.be> Acked-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net> Acked-by: Josh Triplett <josh@kernel.org> Acked-by: Kamil Dudka <kdudka@redhat.com> Acked-by: Kim Phillips <kim.phillips@linaro.org> Acked-by: KOSAKI Motohiro <kosaki.motohiro@gmail.com> Acked-by: Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Acked-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Acked-by: Martin Nagy <nagy.martin@gmail.com> Acked-by: Masatake YAMATO <yamato@redhat.com> Acked-by: Mauro Dreissig <mukadr@gmail.com> Acked-by: Michael Büsch <m@bues.ch> Acked-by: Michael Stefaniuc <mstefani@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Mika Kukkonen <mikukkon@iki.fi> Acked-by: Mike Frysinger <vapier@gentoo.org> Acked-by: Mitesh Shah <Mitesh.Shah@synopsys.com> Acked-by: Morten Welinder <mortenw@gnome.org> Acked-by: Namhyung Kim <namhyung@gmail.com> Acked-by: Nicolas Kaiser <nikai@nikai.net> Acked-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Pavel Roskin <proski@gnu.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Acked-by: Peter Jones <pjones@redhat.com> Acked-by: Peter A Jonsson <pj@sics.se> Acked-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de> Acked-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Acked-by: Randy Dunlap <rdunlap@xenotime.net> Acked-by: Reinhard Tartler <siretart@tauware.de> Ached-by: Richard Knutsson <richard.knutsson@gmail.com> Acked-by: Rob Taylor <rob.taylor@codethink.co.uk> Acked-by: Rui Saraiva <rmpsaraiva@gmail.com> Acked-by: Ryan Anderson <ryan@michonline.com> Acked-by: Sam Ravnborg <sam@ravnborg.org> Acked-by: Samuel Bronson <naesten@gmail.com> Acked-by: Santtu Hyrkkö <santtu.hyrkko@gmail.com> Acked-by: Shakthi Kannan <shakthimaan@gmail.com> Acked-by: Stephen Hemminger <shemminger@linux-foundation.org> Acked-by: Thomas Schmid <Thomas.Schmid@br-automation.com> Acked-by: Tilman Sauerbeck <tilman@code-monkey.de> Acked-by: Vegard Nossum <vegardno@ifi.uio.no> Acked-by: Xi Wang <xi.wang@gmail.com> Acked-by: Yura Pakhuchiy <pakhuchiy@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2012-06-04compile-i386: fix use-after-free in func_cleanup()Xi Wang1-4/+4
compile-i386 sometimes crashes due a use-after-free error. Since f->pseudo_list is freed first, which invalidates some atom->op* in f->atom_list. Further checks like `atom->op1->flags & STOR_WANTS_FREE' will read garbage, which may lead to a double free. This patch switches the cleanup order and frees f->atom_list first. Those marked as STOR_WANTS_FREE won't appear in f->pseudo_list. Signed-off-by: Xi Wang <xi.wang@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org> Reviewed-by: Pekka Enberg <penberg@kernel.org>
2011-08-10fix a memory leak in compile-i386.cJonathan Neuschäfer1-1/+0
Don't allocate val twice in emit_divide. Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net> Acked-by: Jeff Garzik <jgarzik@redhat.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2009-07-22compile-i386: do not generate an infinite loopKamil Dudka1-4/+4
I've probably encountered a bug within compile-i386.c. It generates an infinite loop for 'while' statement. My testing example and proposed patch are enclosed. Kamil Signed-off-by: Kamil Dudka <kdudka@redhat.com> Acked-by: Jeff Garzik <jgarzik@redhat.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
2008-12-17Unhardcode byte size being 8 bits.David Given1-1/+1
Signed-off-by: David Given <dg@cowlark.com> [negative value division fixed by alexey.zaytsev@gmal.com] Signed-off-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
2007-07-10fix handling of address_space in casts and assignmentsAl Viro1-0/+1
Turn FORCE_MOD into storage class specifier (that's how it's actually used and that makes for much simpler logics). Introduce explicit EXPR_FORCE_CAST for forced casts; handle it properly. Kill the idiocy in get_as() (we end up picking the oddest things for address space - e.g. if we have int __attribute__((address_space(1))) *p, we'll get warnings about removal of address space when we do things like (unsigned short)*p. Fixed. BTW, that had caught a bunch of very odd bogosities in the kernel and eliminated several false positives in there. As the result, get_as() is gone now and evaluate_cast() got simpler. Kill the similar idiocy in handling pointer assignments; while we are at it, fix the qualifiers check for assignments to/from void * (you can't assign const int * to void * - qualifiers on the left side should be no less than on the right one; for normal codepath we get that checked, but the special case of void * skips these checks). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2007-05-01Fix most -Wshadow warnings in Sparse.0.3Josh Triplett1-2/+0
Signed-off-by: Josh Triplett <josh@freedesktop.org>
2007-04-20compile-i386.c: Declare regs_in_use staticJosh Triplett1-1/+1
Signed-off-by: Josh Triplett <josh@freedesktop.org>
2007-03-09Use GCC format and sentinel attributes on appropriate functionsJosh Triplett1-1/+1
Expose the FORMAT_ATTR portability macro in lib.h, and use it on the various printf-like functions in sparse. Add a new SENTINEL_ATTR portability macro for the GCC sentinel attribute, and use it on match_idents in parse.c. match_oplist in expression.c should use SENTINEL_ATTR, but GCC does not accept an integer 0 as a sentinel, only a pointer 0 like NULL. Signed-off-by: Josh Triplett <josh@freedesktop.org>
2005-12-31Make local declarations be statements of their ownLinus Torvalds1-1/+3
This removes the list of symbols for block statements, and instead makes a declaration be a statement of its own. This is necessary to correctly handle the case of mixed statements and declarations correctly, since the order of declarations and statements is meaningful. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-03Update the calling interface to "sparse()".Linus Torvalds1-0/+4
Start off with sparse_initialize(argc, argv); which will return the number of filenames found. You can then use that, or just check if *argv is NULL in a loop like while (*argv) list = sparse(argv); where you get the declaration list for each file in turn.
2005-06-27[PATCH] makes some needlessly global code staticLuc Van Oostenryck1-7/+7
This makes some needlessly global code static so that sparse don't complain when self checking. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@looxix.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-04-07Add "stream_name()" helper function, and use it.Linus Torvalds1-1/+1
Much prettier than "input_streams[x].name", since most users really don't want to know about the internals of how the preprocessor lays out its stream tracking.
2005-04-07Split out the blob allocator from lib.c into allocate.c.Linus Torvalds1-0/+1
It's disgusting how intimate lib.c is with all the types, and this is slowly trying to split things up a bit. Now the intimate part is in allocate.c, but maybe we can get to the point where each allocation user just declares its own allocation strategy, and just uses the generic routines in allocate.c
2005-04-07Make compile-i386.c get with the program. We don't just useLinus Torvalds1-3/+9
untyped "struct ptr_list **", we use properly typed ones.
2005-04-07Remove EXPR_BITFIELD entirely.Linus Torvalds1-10/+0
I used to think I needed it. That's no longer the case: we just follow the "bit_offset" in the type information. There may be cases where we inadvertently cast the information away, and those places will break now, but that's a bug really, not an excuse for EXPR_BITFIELD.
2005-04-07Separate explicit and implied casts.Linus Torvalds1-0/+1
This also makes our evaluation simplification only happen for the implied ones. If you put an explicit cast somewhere, it does _not_ get combined with an implied one.
2005-04-07Remove "fieldwidth" member of struct symbolLinus Torvalds1-3/+1
It's always the same as bit_size now, and having it just confuses things. We now check whether we have examined a type by looking at the "examined" bitfield, which allows us to set bit_size in the early parsing phase.
2005-04-07Remove remnants of two-expression x ? : y handling..Linus Torvalds1-10/+3
We turn it into a proper (tmp = x, tmp ? tmp : y) at evaluation time, so later phases never have to worry about the issue. But some of the old code lingered.
2005-04-07Get rid of the old "iterate()" interfaces.Linus Torvalds1-13/+12
Use FOR_EACH_PTR() instead, or the much fancier iterators for basic blocks.
2005-04-07Totally re-do how we build up the initializer tree: make theLinus Torvalds1-1/+1
positional markers be hierarchical rather than a flat list. This makes the data structure a bit more complex, but it simplifies some of the code, and makes it possible to evaluate complex initializers without going insane. In particular, we how support struct xxxx var = { .a.b[10] = 1; }; which we couldn't handle at all before (it had to be written as struct xxxx var = { .a = { .b = { [10] = 1; } } } or similar. The new code changes all array indexes and structure members to EXPR_POS expressions offset from the "outer" scope (either start of the symbol, or an outer EXPR_POS).
2005-04-07Janitorial trivialities.welinder@darter.rentec.com1-5/+5
2005-04-07Many files:welinder@darter.rentec.com1-10/+10
warn->warning error->error_die new error lib.h: warn->warning error->error_die new error Add gcc format checking to warning/error/...
2005-04-07Make END_FOR_EACH_PTR[_REVERSE] take the ptr name as an argument.Linus Torvalds1-15/+15
..and switch us entirely over to the new naming scheme. All the nasty work of going through the users thanks to Chris Li.
2005-04-07Fix "compile-i386.c" incestuous list internal knowledge.Linus Torvalds1-1/+1
Use the existing access macro instead.
2005-04-07Fix up the worst regcache thinko's.Linus Torvalds1-28/+31
In particular: - we should only test (and not mark busy) the things a register aliases when we allocate it. This bug kept us from using %edx, because when we used %eax, we bogusly marked the 64-bit combination %eax:%edx as being busy, and refused to use %edx later. - "get_reg_value()" should take a regclass, so that we can allocate a new reg from a valid class.
2005-04-07Add the proper accessor functions to turn a 32-bit regLinus Torvalds1-0/+2
into a 16-bit one, and into the "high byte" version.
2005-04-07Make "emit_conditional_test()" use register caches.Linus Torvalds1-2/+5
2005-04-07Improve "emit_move()" handling.Linus Torvalds1-6/+34
If we are loading something into a register, and another register has that value already cached, used the cached register value.
2005-04-07Make binops use the new register tracking in compile-i386.cLinus Torvalds1-33/+13
2005-04-07Do some rudimentary register content tracking.Linus Torvalds1-34/+116
This still does just mainly EXPR_SELECT, since that is what I'm familiar with. It's also extremely lazy about invalidating register content info, since any code that hasn't been moved to the new format won't do things properly. Very much a work-in-progress, designed to eventually allow us to generate some kind of half-readable code from the SSA form.
2005-04-07Start infrastructure for more dynamic register allocation.Linus Torvalds1-14/+112
Instead of using fixed register names, we keep track of busy registers, and allocate them as needed. Also changed EXPR_SELECT to actually use this.
2005-04-07Let compile-i386 know about more registers.Linus Torvalds1-56/+54
We don't actually _use_ any of them yet, but this lists them, and adds the information about which register conflicts with which register (eg %al conflicts with %eax, but not with %ah)
2005-04-07Simplify the interface between compile.c and the actualLinus Torvalds1-11/+4
code emitter. Don't make the code emission have to know about symbol lists etc. Thus the code emitter can do whatever it wants to do to the symbols as they are encountered, as part of the main loop rather than as a separate phase afterwards. Straightforward.
2005-04-07Make compile-i386.c create pseudo-code for the logical binops.Linus Torvalds1-0/+8
It gets them wrong right now: we can't just use "and" and "or", we need to convert to canonical logical form (0/1) too. But it's documentation.
2005-04-07Teach compile-i386.c to emit select instructions.Linus Torvalds1-1/+31
They are valid now that we have a EXPR_SELECT type for safe conditionals.
2005-04-07EXPR_SAFELOGICAL is unnecessary. It ends up being the same as EXPR_BINOP.Linus Torvalds1-1/+0
Make linearize.h show the right ops for the logical (as opposed to binary) and/or EXPR_BINOP.
2005-04-07Make expression expansion calculate the "cost" of theLinus Torvalds1-0/+1
expression. This is just a very high-level cost, mainly distinguishing between "safe" and "unsafe" operations, so that we can determine if we can turn a C conditional into a select statement, or a logical op into one without short-ciruiting.
2005-04-07Add "select" expression.Linus Torvalds1-0/+1
It's the same as a regular C conditional, except you could evaluate both sides first. Right now we treat it exactly the same as an EXPR_CONDITIONAL.
2005-04-07[be] fix amazingly stupid conditional expression handlingJeff Garzik1-61/+69
By virtue of attempting to be too smart, the conditional expression handling ("x ? foo : bar") would evaluate both 'foo' and 'bar', and then use the cmov instruction to determine the result, avoiding a branch in the process. Unfortunately this only makes sense for simple things (EXPR_VALUE, EXPR_SYMBOL) and is quite wrong for everything else. Changed so that 'if' statements and conditional expressions use largely the same code.
2005-04-07[be] minor fixesJeff Garzik1-1/+13
* Mostly revert function call stack frame construction ("correctly generate push* instruction") * Add comment regarding ABI-dictated function call argument size * Clamp function call arg size to 32-bit minimum. This will copy the correct value to the stack at the correct alignment, but (SECURITY/FIXME) will also copy extra bits (24 bits for an 8-bit value, 16 bits for a 16-bit value). * Add EXPR_FVALUE to the 'unhandled' portion of the master emit-expression 'switch' statement.
2005-04-07[be] fix some of the brokenness related to non-32-bit variablesJeff Garzik1-23/+37
Assumptions that values are 32-bit still remain in places, but some simple test cases involving 8-bit and 16-bit variables seem much more sane now.
2005-04-07[PATCH] Generate correct push* instruction.Alexey Dobriyan1-2/+1
Pay attention to size of function arguments when pushing them to stack. Generate "pushb" for char, "pushw" for short, ... [ Linus' note: this is likely "wrong". In a real x86 compiler, we'd expand the width of the argument to 32 bits regardless, but from a demonstration standpoint this is better ]
2005-04-07[PATCH] Simplify mnemonic generation for mov* instructions.Alexey Dobriyan1-23/+7
We already have a function that adds correct {b,w,l,q} suffix.
2005-04-07[PATCH] Print instruction's suffix in a human-readable form.Alexey Dobriyan1-1/+1
{'b', 'w', 'l', 'q'} instead of {ascii 8, ascii 16, ' ', '@'}
2005-04-07Make "compile" assert more readable.Linus Torvalds1-1/+1
Quite frankly, anybody who uses assert() should be shot. It's a fundamentally broken thing.
2005-04-07[PATCH] comparison operations fixAlexander Viro1-17/+12
simplify_int_binop() was completely broken for comparisons - there the signedness of (converted) arguments can not be obtained from type of result. IOW, we had all comparisons in constant expressions done as signed ones. Fixed by introducing new primitives for unsigned versions of comparions (SPECIAL_UNSIGNED_LT, etc.) and remapping in evaluate_compare() once we know the types. That also fixes similar mess in compile-i386 and linearize.
2005-04-07[PATCH] teach sparse about __alignof__Stephen Hemminger1-0/+1
This teaches sparse what __alignof__ really means, instead of just using the same code as "__sizeof__" It gets rid of the warnings in ebtables that does: struct ebt_entries { ... char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))); }; Which caused warning because sparse was evaluating __alignof__ as the same as sizeof, and sizeof was 57 (ie non-power of 2). This is just based on the existing code and a peek at the data structures in expression and symbol.
2005-04-07Fix integer/pointer errors in sparse.Linus Torvalds1-9/+9
Shown by running sparse on itself.
2005-04-07Make sparse sources themselves be sparse-clean.Linus Torvalds1-1/+3
This actually showed a bug ("assignment in conditional") in evaluate.c.
2005-04-07Now that BITS_IN_XXXX aren't defined contstants any more,Linus Torvalds1-4/+4
rename them lower cased to match standard C naming rules.
2005-04-07Support C types as first-class citizens, allowing typeLinus Torvalds1-0/+3
comparisons etc: if (typeof(a) == int) { ... (although right now I don't actually do the proper comparison expansion and all comparisons return "true").
2005-04-07Remove now-obsolete temporary statement types.Linus Torvalds1-16/+0
They were only used for the original pre-instruction linearization.
2005-04-07Add proper linearization of switch statements.Linus Torvalds1-0/+8
2005-04-07Split "STMT_GOTO_BB" into "STMT_CONDTRUE" and "STMT_CONDFALSE".Linus Torvalds1-2/+6
This lets us get the type of comparison right.
2005-04-07Add "goto/label" support for linearization.Linus Torvalds1-0/+3
This required making the inter-BB trampoline to be done using indirection through a symbol, rather than as direct pointers from one BB to another. Fix up code to match. Avoid a few warnings by handling GOTO_BB in the case statements.
2005-04-07[be] get operand size correct on mem->mem copiesJeff Garzik1-8/+26
2005-04-07[be] Fix binops. We should now get operand size and sign correct.Jeff Garzik1-22/+114
2005-04-07[be] fix function name emitted for .size directiveJeff Garzik1-0/+1
We were using the output of show_ident() without remembering that that function uses static storage.
2005-04-07[be] Handle 'break' and 'continue' inside loops.Jeff Garzik1-2/+12
2005-04-07[be] handle 'break' and 'continue' in loop emit codeJeff Garzik1-18/+53
The loop generator should be correct now; all that remains is to actually generate the jumps based on the loop label info we now store in the "loop stack".
2005-04-07[be] Get most of loops working.Jeff Garzik1-12/+46
The thing that remains is getting 'break' and 'continue' assigned to the correct jump targets.
2005-04-07Merge kernel.bkbits.net:sparse.be into redhat.com:/garz/repo/sparse.beJeff Garzik1-23/+30
2005-04-07Allow variable-sized array size declarations.Linus Torvalds1-2/+2
This doesn't actually get them _right_, but as long as they end up being constant when used, we at least silently ignore them until then.
2005-04-07A much-needed stack allocation facelift.Jeff Garzik1-19/+25
Instead of assuming that all stack objects were 4 bytes in size, we now properly account for both stack variables (sym->bit_size / 8) and compiler temporaries (fixed 32 bits). Function new_pseudo() became stack_alloc(), which takes a number of bytes to allocate on the stack.
2005-04-07[be] rename pseudo_nr to stack_sizeJeff Garzik1-8/+9
More properly describe what the variable represents, and also prepare for upcoming stack allocation improvements.
2005-04-07[be] properly emit switch statements.Jeff Garzik1-67/+173
Also create helpers for emitted labels (emit_label), labels based on symbol pointer values (emit_labelsym), and creating various struct storage types (new_val, new_labelsym). Use these new helpers where appropriate.
2005-04-07[be] prefer "mov $0, %eax" to "xor %eax, %eax"Jeff Garzik1-4/+8
2005-04-07[be] Store "free() me?" flag in struct storage, where it belongs,Jeff Garzik1-66/+64
rather than as multiple flags in struct atom. This allows us to eliminate the final arg passed to {insn, emit_move, stor_op_name}. Also, fix two memory leaks noticed during the cleanup.
2005-04-07[be] temporarily ignore size of a callee func call's return value.Jeff Garzik1-1/+1
Now, we just assume it's the ABI size (32 bits) rather than care about the distinction between what we want to return up the parse tree stack (possibly not 32 bits), and what the ABI gives us (32 bits). Also, add new file validation/test-be.c, to house a growing collection of basic sanity checks I can run, to help avoid regressions.
2005-04-07[be] add to-do list compile-i386.c headerJeff Garzik1-0/+13
2005-04-07[be] clean up binop selection. add support for shift left/rightJeff Garzik1-14/+14
2005-04-07[be] properly emit "regular preops"Jeff Garzik1-26/+38
* properly emit '!', '~', '-' * handle operand size in inc/dec * simplify EXPR_ACCESS test in x86_address_gen()
2005-04-07[be] move existing (non-working) loop code to its own functionJeff Garzik1-46/+51
2005-04-07[be] Properly load address de-references.Jeff Garzik1-7/+23
2005-04-07[be] fixesJeff Garzik1-10/+16
* remove bogus "toplevel symbol" check I put in. Needs reworking. * Don't emit subl/addl %esp stack frame adjustments, if no stack frame exists.
2005-04-07[be] Don't emit move based on value returned from a function'sJeff Garzik1-10/+3
toplevel STMT_COMPOUND. If a function returns a value, then the C code must have explicit 'return' statements. Since we already emit a move when handling return statements, that eliminates the need to ever emit a move for the non-'return' case. Of course, incorrect C code can still omit the return statement, in which case you're left with a random %eax return value.
2005-04-07[be] fix indirect func callsJeff Garzik1-1/+1
2005-04-07[be] In assignments, don't perform a mem->mem copy (two mov's) whenJeff Garzik1-1/+16
we don't have to.
2005-04-07[be] return fixes: move return jump target, emit return value properlyJeff Garzik1-5/+8
Still needs some work.
2005-04-07[be] emit casts, prettier emit_copy output, fix segfault,Jeff Garzik1-38/+47
smarter val storage. * fix segfault in emit_symbol_expr_init. we don't yet properly reference toplevel variables. workaround, print out "FIXME!" and create a new pseudo. * directly inline constants, instead of assigning them stack slots as pseudos. * properly emit cast expressions; quite easy with my type-aware emit_move function. alas, since we assume values will fit into a machine register, emit_move is [known-]broken for 64-bit ints. * make asm comments in pseudo-pseudo copy prettier
2005-04-07[be] properly emit strings, indirect func calls, andJeff Garzik1-47/+105
func call return values.
2005-04-07[be] Handle 'if' using test/jz insns rather than xor/cmp/jeJeff Garzik1-5/+2
Suggested by Arjan van de Ven.
2005-04-07[be] generate code for "x ? 1 : 0" type conditionalsJeff Garzik1-16/+30
2005-04-07[be] comparison, signedness, and operand size updateJeff Garzik1-38/+129
* rename emit_move() to emit_copy() (it copies stack slotX -> slotY) * create a size- and sign-aware emit_move() * create opbits(), to help determine instruction suffix based on memory operand * update emit_compare() to be operand sign- and size-aware * update emit_compare() to use SETcc instead of CMOVcc. (suggested by Arjan van de Ven)
2005-04-07[be] comparison expression update:Jeff Garzik1-22/+9
* fix comparison order. was using Intel not AT&T order of operands. * replace nested-if tree of string comparisons with a switch on expr->op value.
2005-04-07[be] calculate offset of func args on stack correctlyJeff Garzik1-23/+5
And remove code warning people it's wrong, as it should no longer be.
2005-04-07[be] Convert insn() function to take struct storage arguments,Jeff Garzik1-75/+186
instead of char* arguments. This uses the previously-added 'atom' instructure. It also necessitates adding new struct storage types: STOR_REG (machine register), STOR_VALUE (constant), and STOR_LABEL (label / jump target). Updated all insn() callers to provide struct storage arguments.
2005-04-07[be] Instead of buffering output with a hand-rolled list ofJeff Garzik1-7/+92
text buffers, update code to use a ptr_list of "atoms". Atoms basically correspond to a single line of assembly. There are ATOM_TEXT atoms for ASCII text (the only kind of atom currently in use) and ATOM_INSN for instructions.
2005-04-07[be] get return values and jump targets workingJeff Garzik1-31/+33
2005-04-07[PATCH] "silly sparse x86 backend"Jeff Garzik1-0/+1452
Here's what I have so far. Comments welcome. It cannot be considered anywhere near complete, but it acts like it generates x86 asm for a bunch of small test cases anyway :) It started out as show-parse.c. The emit_xxx stuff is what I have converted from show-parse pseudo-code into x86 code generation. The x86_xxx stuff is the stuff that remains. FIXMEs abound. I haven't actually tried to assmble anything yet. Just studying what gcc generates, and then what I generate. A few random notes in closing: * function-at-a-time * just does one subl and one addl for stack manipulation, which implies that it has to output everything from post-function cleanup pass (emit_func_post). * however, x86_xxx stuff (not yet converted) will still print out pseudocode. So your output will look like function header psuedocode (i.e. stuff not yet handled) real x86 code If you don't see any pseudocode... you may actually be lucky enough to be able to compile your asm ;-)