Commit graph

10 commits

Author SHA1 Message Date
Jeff Epler
523a88ad3a Free memory in exit paths
.. the previous arrangement lead to compiler diagnostics when
building with 'scan-build make', such as:

libtvm/tvm_parser.c:218:12: warning: Potential leak of memory pointed to by 'args'
                        return -1;
                                ^
2018-03-17 14:00:36 -05:00
Joseph Kogut
488b88f867 tvm_preprocess: update *src after (re)allocating memory
During preprocessing, we find directives, and if they specify including
other source files, we remove the directive, allocate a new block of
memory, copy the first block, append the new source file, and append the
second block.

Previously, the value of the source pointer was passed into the
preprocessing function. When the memory would be (re)allocated, the
pointer value could change, but the original pointer would not be
updated.

Now, the pointer is passed by address, and updated when the memory it
points to changes.
2017-02-12 11:51:06 -08:00
Joseph Kogut
ca87b3c5e9 Refactor with a consistent coding style
This commit refactors the project using a single, consistent coding
style, derived from the Linux Kernel Coding Style, available here:

https://www.kernel.org/doc/Documentation/CodingStyle

This includes, but is not limited to:
* Removal of typedefs, especially for structs
* Limiting lines to a reasonable length, 80 characters, mostly
* K&R style braces
* Removal of CamelCase
2016-08-28 20:31:12 -07:00
Payton Turnage
ae63e45c65 Rename htab functions; rewrite find to be generic.
The htab functions find_str and add_str have been renamed to include _ref in
the places they previously noted _str. These are intended to manage an htab
containing references to any data; string or not.

The htab_find function has been divided up. htab_find_core now handles actually
finding the correct node. htab_find and htab_find_ref are just outward facing
functions for retrieving a specific kind of data from the node, depending on
what the htab is used for.
2014-01-14 19:09:35 -05:00
Payton Turnage
e99a0428f3 Implement defines using the htab structure.
The htab_structure has been modified in two ways, which should not break
compatability with any of its uses.

It includes a void pointer, which is in this commit used to point to a
string for defines, and will in the future be used to point to the address
space for words, bytes, and double words.

It now includes a function htab_add_str specifically for storing strings.
It calls htab_add so as not to be redundant, but makes the node's value
their index for the lexer to fetch using htab_find, and assigns their
void pointer.

The lexer will now use htab_find on all tokens to see if they are a define
string, and if so, substitute them with the appropriate token.

The defines htab is destroyed after lexing, because that memory is done.
2014-01-13 10:20:21 -05:00
Payton Turnage
ed12ce05db Remove all traces of the tvm_tree structure.
It is to be replaced with a htab hash table.
2014-01-13 09:45:27 -05:00
Payton Turnage
b208237960 Allow the preprocessor to abort.
If the preprocessor encounters a problem, such as failing to load a source
file or an improperly formatted define, it should be able to abort running
the program.
2014-01-12 21:56:54 -05:00
Payton Turnage
27cde3f429 Warn on redefining. 2014-01-12 21:54:21 -05:00
Payton Turnage
23e72a8ca7 Implement preprocessor defines.
This commit adds behavior to the preprocessor which fills a tree with
defines and their replacements. In future commits, the parser will
substitute instances of the defines with their replacements in the
source code.
2014-01-12 21:11:31 -05:00
Joseph Kogut
f60fb720b6 Fixed filename typo 2013-03-07 14:42:53 -07:00
Renamed from libtvm/tvm_preprocesor.c (Browse further)