ansi_c.git
4 months agoRemove old scope/type/value analysis, fix omissions where Declaration.storage_class... master
Nick Downing [Wed, 27 Dec 2023 13:03:21 +0000 (00:03 +1100)]
Remove old scope/type/value analysis, fix omissions where Declaration.storage_class was not set and formal parameters were not analyzed by new type analysis

4 months agoSet up a way of comparing the old scope/type/value analysis result with the new,...
Nick Downing [Wed, 27 Dec 2023 05:14:37 +0000 (16:14 +1100)]
Set up a way of comparing the old scope/type/value analysis result with the new, fix a large number of bugs in both the old and the new so that they match up

4 months agoAdd value_analysis() method, called from post_process() after type_analysis()
Nick Downing [Wed, 27 Dec 2023 00:38:24 +0000 (11:38 +1100)]
Add value_analysis() method, called from post_process() after type_analysis()

4 months agoMove ExpressionCall parameters coercion from calc_type() into type_analysis()
Nick Downing [Wed, 27 Dec 2023 00:32:44 +0000 (11:32 +1100)]
Move ExpressionCall parameters coercion from calc_type() into type_analysis()

4 months agoIn /post_process.py and /type_analysis.py implement initializer stack, in /ansi_c...
Nick Downing [Tue, 26 Dec 2023 23:49:00 +0000 (10:49 +1100)]
In /post_process.py and /type_analysis.py implement initializer stack, in /ansi_c.[ty] and /pretty_print.t remove the InitializerOrExpression base class in favour of wrapping initializer expressions in an extra InitializerExpression node

4 months agoAdd post_process.Context object, to track return type and switch case type
Nick Downing [Tue, 26 Dec 2023 03:48:11 +0000 (14:48 +1100)]
Add post_process.Context object, to track return type and switch case type

4 months agoMake type_analysis() also call calc_type() and add_cast() on Expression nodes
Nick Downing [Tue, 26 Dec 2023 03:34:35 +0000 (14:34 +1100)]
Make type_analysis() also call calc_type() and add_cast() on Expression nodes

4 months agoAdd type_analysis() method, called from post_process() in post-order
Nick Downing [Mon, 25 Dec 2023 23:36:34 +0000 (10:36 +1100)]
Add type_analysis() method, called from post_process() in post-order

4 months agoImplement post_process() which recurses through the tree calling scope_analysis(...
Nick Downing [Mon, 25 Dec 2023 09:37:15 +0000 (20:37 +1100)]
Implement post_process() which recurses through the tree calling scope_analysis(), the scope_analysis() routine now just processes one node with no recursion

4 months agoModify scope_analysis() to process the tree in strict pre-order
Nick Downing [Mon, 25 Dec 2023 09:29:01 +0000 (20:29 +1100)]
Modify scope_analysis() to process the tree in strict pre-order

4 months agoAdd location tracking, syntax error and invalid character reporting
Nick Downing [Mon, 25 Dec 2023 08:18:18 +0000 (19:18 +1100)]
Add location tracking, syntax error and invalid character reporting

4 months agoMove code out of ansi_c.t into base_type.py, calc_type.py, calc_value.py, declarator...
Nick Downing [Mon, 25 Dec 2023 07:51:53 +0000 (18:51 +1100)]
Move code out of ansi_c.t into base_type.py, calc_type.py, calc_value.py, declarator.py, storage_class.py

4 months agoNew scope analysis in a separate module (clobbers the type analysis currently)
Nick Downing [Tue, 19 Dec 2023 12:22:18 +0000 (23:22 +1100)]
New scope analysis in a separate module (clobbers the type analysis currently)

4 months agoNew way of tracking typedef names so that the full scope analysis can be moved out...
Nick Downing [Tue, 19 Dec 2023 09:45:27 +0000 (20:45 +1100)]
New way of tracking typedef names so that the full scope analysis can be moved out of the parser and into a separate pass, rationalize DeclaratorFunction and TypeFunction everywhere so that both have derived classes for ANSI or KAndR

4 months agoMake typedef processing occur by intercepting yylex(), it is much simpler
Nick Downing [Tue, 19 Dec 2023 03:26:00 +0000 (14:26 +1100)]
Make typedef processing occur by intercepting yylex(), it is much simpler

4 months agoIn /pretty_print.t reorder the methods so that e.g. InitDeclaratorList comes after...
Nick Downing [Tue, 19 Dec 2023 00:34:44 +0000 (11:34 +1100)]
In /pretty_print.t reorder the methods so that e.g. InitDeclaratorList comes after InitDeclarator (my script had placed these backwards when one was a prefix of another) and fix a bug with StatementFor occurring twice, in /*.[ty] change ArrayOrStructOrUnion to ArrayOrStruct and StatementIfElse to StatementIf, in /ansi_c.y fix bugs with missing %space before (?E{MemberIdentifier}IDENTIFIER)

4 months agoRename /vm_test.asm to /vm_test_128.asm, implement 64-bit and 32-bit versions
Nick Downing [Mon, 18 Dec 2023 11:02:49 +0000 (22:02 +1100)]
Rename /vm_test.asm to /vm_test_128.asm, implement 64-bit and 32-bit versions

4 months agoIn /vm_asm.py implement imm.iXX and imm.fXX constant optimization using cvt.XX
Nick Downing [Mon, 18 Dec 2023 10:16:31 +0000 (21:16 +1100)]
In /vm_asm.py implement imm.iXX and imm.fXX constant optimization using cvt.XX

4 months agoIn /vm_test.asm use "offpc label@" instead of "imm.i32 label" for a significant space...
Nick Downing [Mon, 18 Dec 2023 09:11:36 +0000 (20:11 +1100)]
In /vm_test.asm use "offpc label@" instead of "imm.i32 label" for a significant space saving, in /vm_asm.py improve the listing file with auto operands

4 months agoIn /vm_test.asm add square-root calculation routine
Nick Downing [Mon, 18 Dec 2023 06:49:27 +0000 (17:49 +1100)]
In /vm_test.asm add square-root calculation routine

4 months agoIn /vm_test.asm add floating-point printing routine, in /vm.c fix order of operands...
Nick Downing [Mon, 18 Dec 2023 06:11:48 +0000 (17:11 +1100)]
In /vm_test.asm add floating-point printing routine, in /vm.c fix order of operands for the non-commutative operators sub(.r), div(.r|.u|.u.r) and relational operators, in /vm.c and /vm_asm.py add the forgotten mod(.r|.u|.u.r) operator (%)

4 months agoIn /vm_test.asm, add more test routines
Nick Downing [Mon, 18 Dec 2023 03:21:32 +0000 (14:21 +1100)]
In /vm_test.asm, add more test routines

4 months agoIn /vm_asm.py, add the ability to assemble float128 numbers
Nick Downing [Mon, 18 Dec 2023 00:22:24 +0000 (11:22 +1100)]
In /vm_asm.py, add the ability to assemble float128 numbers

4 months agoAdd stack-based VM for testing
Nick Downing [Sun, 17 Dec 2023 19:28:35 +0000 (06:28 +1100)]
Add stack-based VM for testing

4 months agoIn pretty printer, improve how base types are generated and structs printed
Nick Downing [Sat, 9 Dec 2023 22:01:51 +0000 (09:01 +1100)]
In pretty printer, improve how base types are generated and structs printed

4 months agoRationalize new scopes so they are only defined by an ItemList which can be either...
Nick Downing [Sat, 9 Dec 2023 21:39:26 +0000 (08:39 +1100)]
Rationalize new scopes so they are only defined by an ItemList which can be either a TranslationUnit or a BlockItemList, make the definitions of enums, structs and unions from each new scope be output at the start of the ItemList

4 months agoFix a bug which prevented (void) argument list from pretty printing correctly
Nick Downing [Sat, 9 Dec 2023 02:45:50 +0000 (13:45 +1100)]
Fix a bug which prevented (void) argument list from pretty printing correctly

4 months agoFix a bug which prevented the -> operator from pretty printing correctly
Nick Downing [Sat, 9 Dec 2023 02:35:09 +0000 (13:35 +1100)]
Fix a bug which prevented the -> operator from pretty printing correctly

4 months agoAdd indenting in the pretty printer
Nick Downing [Sat, 9 Dec 2023 02:24:40 +0000 (13:24 +1100)]
Add indenting in the pretty printer

4 months agoAdd declarator precedence in the pretty printer
Nick Downing [Sat, 9 Dec 2023 01:50:10 +0000 (12:50 +1100)]
Add declarator precedence in the pretty printer

4 months agoAdd expression precedence in the pretty printer
Nick Downing [Sat, 9 Dec 2023 01:09:23 +0000 (12:09 +1100)]
Add expression precedence in the pretty printer

4 months agoRationalize how ParameterDeclaration is handled in both the parser (convert to a...
Nick Downing [Sat, 9 Dec 2023 00:36:24 +0000 (11:36 +1100)]
Rationalize how ParameterDeclaration is handled in both the parser (convert to a name, type pair as soon as it is parsed and then use this later to build the TypeFunctionANSI), and the pretty printer (attach the names to the parameters)

4 months agoFirst cut at pretty printer, fix minor inconsistencies in ansi_c.[ty]
Nick Downing [Fri, 8 Dec 2023 04:29:06 +0000 (15:29 +1100)]
First cut at pretty printer, fix minor inconsistencies in ansi_c.[ty]

4 months agoAdd the Node.strip_redundancy() method, removes all text, declarators, etc
Nick Downing [Thu, 7 Dec 2023 23:32:27 +0000 (10:32 +1100)]
Add the Node.strip_redundancy() method, removes all text, declarators, etc

4 months agoSupport array or struct/union literals in expressions
Nick Downing [Thu, 7 Dec 2023 22:51:48 +0000 (09:51 +1100)]
Support array or struct/union literals in expressions

4 months agoAdd TagIdentifier class and extra annotations for array or struct/union indices
Nick Downing [Thu, 7 Dec 2023 20:55:47 +0000 (07:55 +1100)]
Add TagIdentifier class and extra annotations for array or struct/union indices

4 months agoFor array of indeterminate size with initializer, deduce the size
Nick Downing [Thu, 7 Dec 2023 21:06:22 +0000 (08:06 +1100)]
For array of indeterminate size with initializer, deduce the size

4 months agoRemove rough Expression.get_const_value() in favour of Expression.value
Nick Downing [Thu, 7 Dec 2023 06:53:32 +0000 (17:53 +1100)]
Remove rough Expression.get_const_value() in favour of Expression.value

4 months agoAdd type analysis for initializers, add some extra (s)size_t and bool casts
Nick Downing [Thu, 7 Dec 2023 05:56:35 +0000 (16:56 +1100)]
Add type analysis for initializers, add some extra (s)size_t and bool casts

4 months agoImplement mostly complete type analysis and constant folding, compiles nbench
Nick Downing [Wed, 6 Dec 2023 09:21:36 +0000 (20:21 +1100)]
Implement mostly complete type analysis and constant folding, compiles nbench

4 months agoImplement (un)signed_int_value() and float_value() for constructing Value objects...
Nick Downing [Wed, 6 Dec 2023 04:07:36 +0000 (15:07 +1100)]
Implement (un)signed_int_value() and float_value() for constructing Value objects directly with a specified precision, instead of cumbersome Value.cast() idea

4 months agoImplement build() in ansi_c.[ly] to make type analysis and constant folding occur...
Nick Downing [Wed, 6 Dec 2023 03:31:47 +0000 (14:31 +1100)]
Implement build() in ansi_c.[ly] to make type analysis and constant folding occur during parsing instead, requires new skeleton code from latest pilex, pitree

4 months agoAdd an extra pass for type analysis and constant folding, doesn't support all operato...
Nick Downing [Wed, 6 Dec 2023 00:23:11 +0000 (11:23 +1100)]
Add an extra pass for type analysis and constant folding, doesn't support all operators and has just enough implementation to compile the example test.i file

4 months agoImplement the value field for character constants and string literals
Nick Downing [Tue, 5 Dec 2023 23:20:01 +0000 (10:20 +1100)]
Implement the value field for character constants and string literals

4 months agoUpdate ansi_c.t for latest pitree, it has default value bug fixed and adds MPFR
Nick Downing [Tue, 5 Dec 2023 01:30:37 +0000 (12:30 +1100)]
Update ansi_c.t for latest pitree, it has default value bug fixed and adds MPFR

4 months agoUpgrade lexical analyzer to implement the C90 rules explicitly and to add markup...
Nick Downing [Sat, 2 Dec 2023 14:09:23 +0000 (01:09 +1100)]
Upgrade lexical analyzer to implement the C90 rules explicitly and to add markup to the individual parts of constants, strings etc, add number handling facilities so that we can store the type and (if constant) the value on an expression

5 months agoAdd the lex_yy.mask_typedefs flag so that typedef processing can be masked for the...
Nick Downing [Thu, 23 Nov 2023 08:14:48 +0000 (19:14 +1100)]
Add the lex_yy.mask_typedefs flag so that typedef processing can be masked for the identifier following a "struct", "union", "enum", "." or "->" keyword, fix a bug where the scope_(struct|union|enum)_tag was not declared and saved in XML

5 months agoRefactor parsing of function definitions so that the function is added to the scope...
Nick Downing [Thu, 23 Nov 2023 07:48:35 +0000 (18:48 +1100)]
Refactor parsing of function definitions so that the function is added to the scope as soon as we see the definition, hence can call itself without a prototype

5 months agoMake DeclaratorIdentifier store the identifier text directly in the same way as Expre...
Nick Downing [Thu, 23 Nov 2023 07:27:24 +0000 (18:27 +1100)]
Make DeclaratorIdentifier store the identifier text directly in the same way as ExpressionIdentifier does, make specifier list processing slightly more strict

5 months agoAdd /nbench containing source for the nbench benchmark from http://www.math.utah...
Nick Downing [Thu, 23 Nov 2023 07:00:01 +0000 (18:00 +1100)]
Add /nbench containing source for the nbench benchmark from math.utah.edu/~mayer/linux/nbench-byte-2.2.3.tar.gz preprocessed with musl-gcc from https://musl.libc.org/releases/musl-1.2.4.tar.gz, make the analysis cope with all constructs in this code except for some very tiny workarounds labeled /* Nick */

5 months agoInitial commit, has scope analysis and beginnings of type analysis
Nick Downing [Sun, 19 Nov 2023 12:28:48 +0000 (23:28 +1100)]
Initial commit, has scope analysis and beginnings of type analysis