C parser modification & questions

2010-01-19 Thread Nikola Ikonic
Hello,

I am working on a modification of C parser and I need some help since
I am having difficulties understanding some issues (I am complete
newbie on GCC). Long story short, I am trying to add a new attribute
to function types (similar to "inline", for example). Let's say that
this new keyword is _Something.
So, my new parser should be able to parse c function declared/defined like this:

_Something int Function_Name(unsigned a, int b);

Of course, I need to add new keyword "_Something", but that is the easiest part.

I am having difficulties understanding c-parser.c code. I tried to
debug cc1 (c-parser.c file) to see where the function declarator is
parsed (I used simple code which has main() and Hi_World() functions).
I have several questions about debugging:

1. Which part of code parses "Hi_World" string?
2. How can I see the tree which contains "Hi_World" string (during debugging)?
3. Which part of code parses parameters of "Hi_World"? (In general,
which part of code parses function parameters)
4. If Hi_World has parameters a and b, how can I see the tree nodes
which contain values/names of these parameters?

(As it's obvious I have problem understanding/viewing data during
debugging parser).

5. In which part of code I need to add parsing of my new reserved word
_Something?

I would be very grateful if someone could answer any of these
questions. Thank you in advance!

Best regards,
Nikola


GCC calling GNU assembler

2010-02-03 Thread Nikola Ikonic
Hello all,

Could anybody please answer me on following question:

where is GCC callin assembler where it recognizes assembler code in C
function? For example, let's say that there is this line in C code:

asm("mov r1,r0");

So, the parser parses this as an assembler string. But where, in GCC
code, is assembler called to process this string?
Or maybe the question is where this "mov r1, r0" string is passed to
assembler. Anyway, I think you got my question.

Thanks in advance!

Best regards,
 Nikola


_cpp_line_note structure in front end

2010-02-05 Thread Nikola Ikonic
Hello all,

Could anybody please answer me on one question which is related to
_cpp_line_note structure (GCC front end)?

 I am currently working on modifying FE to "swallow" piece of code
similar to this one:

_Asm void DoSomething(some_parameters) {
mov r1, r2
mov r2, r3
... and similar assembler code
}

The idea is to just take assembler body and parse it as there was
asm("") statement.

I've managed to lex/parse whole this. However, when FE lexes assembler
body of this function, my code fails starting from here:

skipped_white:
  if (buffer->cur >= buffer->notes[buffer->cur_note].pos
  && !pfile->overlaid_buffer)
{
  _cpp_process_line_notes (pfile, false);
  result->src_loc = pfile->line_table->highest_line;
}

It goes into _cpp_process_line_notes and then into abort()

Above quoted code is located in _cpp_lex_direct() in lex.c file.

In short, (buffer->cur>= buffer->notes[buffer->cur_note].pos) is true.
I understand that I need to reposition
pos field of _cpp_line_note structure, but I don't know where to
position it. At the end of assembler body?
At the closing parenthesis of DoSomething() function? Where should it
go? What is the purpose of _cpp_line_note structure
and this field at all?

Any suggestion/help/advice would be much appreciated.

Thanks in advance!

Best regards,
Nikola


Possible bug in GCC front end

2010-02-08 Thread Nikola Ikonic
Hello all,

I have noticed something that is creating problems in my modified GCC,
and I see it as a bug, maybe I don't do something right. If you take a
look at cpp_interpret_string() function in charset.c you will see the
following part:

for (;;)
{
  base = p;
  while (p < limit && *p != '\\')
p++;
  if (p > base)
{
  /* We have a run of normal characters; these can be fed
 directly to convert_cset.  */
  if (!APPLY_CONVERSION (cvt, base, p - base, &tbuf))
goto fail;
}
  if (p == limit)
break;

  p = convert_escape (pfile, p + 1, limit, &tbuf, wide);
}

and if you have a string that ends with "\\n", what will happen is the
following:

When p points to that last "\\", right before 'n' it p will be bigger
than base and smaller than limit for 1 (because p will be pointing to
"\\". p=convert_escape() will be called next with p+1 as one of the
arguments, which is OK, but convert_escape returns position for 1
increased, which means that after convert_escape() call, p will be
actually increased for two and there for be bigger than limit. But
there is no check for p bigger than limit, only p equals limit,
therefore loop will constantly call convert_escape. Therefore, I think
it would be better to have "p>=limit" instead of "p==limit". After
all, it does make no difference if we are checking that p is bigger
limit additionally to original condition. I hope I've contributed and
if not, I apologize for inconvenience.

Best regards,
  Nikola


Adding statement to an already defined function

2010-03-01 Thread Nikola Ikonic
Hello,

I am working on modifying GCC and I would like to ask you one question.

I am trying figure out a way to add an external statement to already
generated function. Is that possible?

For example, let's say that if I want to check is function with name
"DoSomething" already generated/parsed (bottom line, does it exist).
Can I do that somehow? And if I can, is there a way to add new
statement (e.g call of some function) into to
body of "DoSomething"?

This situation could for example happen when the "DoSomething" is in
A.c file and the compiler is currently parsing B.c and it needs to
look has DoSomething been already processed in files before (in this
case A.c file).

Is that possible somehow?

Thank you in advance!

Best regards,
  Nikola