Commit Graph

34710 Commits

Author SHA1 Message Date
Chris Lattner db91b16755 stub out codegen of binary plus. We now compile:
if (11 + 42) {

to:

        %tmp = add i32 11, 42           ; <i32> [#uses=1]
        %tobool = icmp ne i32 %tmp, 0           ; <i1> [#uses=1]
        br i1 %tobool, label %ifthen, label %ifend


but this doesn't handle any of the interesting/hard stuff yet.

llvm-svn: 39545
2007-06-02 00:16:28 +00:00
Chris Lattner 3e450f947b add new files.
llvm-svn: 39544
2007-06-02 00:01:41 +00:00
Steve Naroff 4555292b1e Bug #:
Submitted by:
Reviewed by:
After speaking with Chris, decided not to have GCC "attributes" inherit
from Decl. This will enable us to grow the attribute hierarchy over time
without effecting Decls.

llvm-svn: 39543
2007-06-01 21:56:17 +00:00
Steve Naroff 6a0675f8a4 Bug #:
Submitted by:
Reviewed by:
Add implemention file for GCC attributes

llvm-svn: 39542
2007-06-01 21:54:34 +00:00
Steve Naroff ff12778709 Bug #:
Submitted by:
Reviewed by:
Interface file for GCC attributes.

llvm-svn: 39541
2007-06-01 21:53:25 +00:00
Chris Lattner e47e440c42 split stmt/expr codegen into their own files.
llvm-svn: 39540
2007-06-01 18:02:12 +00:00
Steve Naroff 0f2fe17ff1 Bug #:
Submitted by:
Reviewed by:
Implement support for GCC __attribute__.

- Implement "TODO" in Parser::ParseAttributes. Changed the return type from
void to Parser::DeclTy. Changed all call sites to accept the return value.
- Added Action::ParseAttribute and Sema::ParseAttribute to return an
appropriate AST node. Added new node AttributeDecl to Decl.h.

Still to do...hook up to the Decl...

llvm-svn: 39539
2007-06-01 17:11:19 +00:00
Chris Lattner a076fde1e3 more minor improvements to pretty printer.
llvm-svn: 39538
2007-05-31 18:21:33 +00:00
Chris Lattner b4619481e6 add some ;'s
llvm-svn: 39537
2007-05-31 06:00:14 +00:00
Chris Lattner 1c31050d21 add fixme
llvm-svn: 39536
2007-05-31 06:00:00 +00:00
Chris Lattner df3cafb796 fix a small printer bug, to emit:
a = b;
  {
    int c;
    c = a + b;
    int d;
    d++;
  }
  int e;

instead of:

  a = b;
  {
    int c;
    c = a + b;
    int d;
    d++;
  }  int e;

llvm-svn: 39535
2007-05-31 05:08:56 +00:00
Chris Lattner dc6e3feade emit a return at the end of the function. Run the llvm verifier.
llvm-svn: 39534
2007-05-30 22:55:31 +00:00
Chris Lattner 5269c0377c Add support for codegen'ing paren exprs and if stmts. We can now codegen:
void test() {
  goto l;

l:
  if (11) {
    j: ;
  }
}

into:

define void @test() {
entry:
        br label %l

l:              ; preds = %entry
        icmp ne i32 11, 0               ; <i1>:0 [#uses=1]
        br i1 %0, label %ifthen, label %ifend

ifthen:         ; preds = %l
        br label %j

j:              ; preds = %ifthen
        br label %ifend

ifend:          ; preds = %j, %l
}

whoa... :)

llvm-svn: 39533
2007-05-30 21:03:58 +00:00
Chris Lattner b2e723bed4 add accessor
llvm-svn: 39532
2007-05-30 20:59:30 +00:00
Chris Lattner fc068c15d9 pretty print exprs in stmt contexts with a trailing semicolon.
llvm-svn: 39531
2007-05-30 17:57:36 +00:00
Chris Lattner 208ae96a8c implement codegen of integer literals.
llvm-svn: 39530
2007-05-30 17:57:17 +00:00
Chris Lattner b5217858ee Update
llvm-svn: 39529
2007-05-30 17:01:31 +00:00
Steve Naroff 9992bbab14 Bug #:
Submitted by:
Reviewed by:
- ParseForStatement(): Put back a test/assignment. My removal of
ParseExprStmt() was a bit over zealous:-(thanks to Chris for pointing it out)
- Add assert to VisitDeclStmt().
- Removed an out-of-date FIXME
- Added some curlies for a couple multi-line calls to Diag().

llvm-svn: 39528
2007-05-30 16:27:15 +00:00
Bill Wendling 216423bbd7 Submitted by: Bill Wendling
Comment format changes.

llvm-svn: 39527
2007-05-30 06:30:29 +00:00
Steve Naroff 56faab2d4f Bug #:
Submitted by:
Reviewed by:
- Many tweaks to various diagnostics.
- Fixed some location/range issues.
- Bug fix to Sema::ParseDeclStmt() - error return code is "true", not 0.

llvm-svn: 39526
2007-05-30 04:20:12 +00:00
Bill Wendling 4447083418 Submitted by: Bill Wendling
- Conjugate "diagnostic" correctly for 1 diagnostic.

llvm-svn: 39525
2007-05-30 02:38:09 +00:00
Chris Lattner ac24820fa5 Implement codegen support for labels and gotos. We now compile:
void test1() {
  foo:
    goto foo;
    goto foo;
    goto foo;
}

void test() {
  goto l;

l:
  ;
}
into:

define void @test1() {
entry:
        br label %foo

foo:            ; preds = %0, %foo, %entry
        br label %foo
                ; No predecessors!
        br label %foo
                ; No predecessors!
}

define void @test() {
entry:
        br label %l

l:              ; preds = %entry
}

llvm-svn: 39524
2007-05-30 00:13:02 +00:00
Steve Naroff eb9da94d37 Bug #:
Submitted by:
Reviewed by:
Unified the diagnostics for function calls. Since we have range support,
there is no need for including the argument number. Instead, I've made
the diags more expressive by including more type info.

Also improved the indentation of many calls to Diag (which can be 2-3
lines now).

llvm-svn: 39523
2007-05-30 00:06:37 +00:00
Chris Lattner 308f431017 Add codegen support for NullStmt and CompoundStmt. {;;{};;} is now ours!
llvm-svn: 39522
2007-05-29 23:50:05 +00:00
Chris Lattner d5322cd27e Don't print billions of spaces for a label with no indent.
llvm-svn: 39521
2007-05-29 23:49:07 +00:00
Chris Lattner da8a4f467b add accessors.
llvm-svn: 39520
2007-05-29 23:48:32 +00:00
Chris Lattner d1af2d2956 Implement conversion of clang ast types to LLVM types, at least for some trivial
cases.

llvm-svn: 39519
2007-05-29 23:17:50 +00:00
Steve Naroff 2a8ad18e71 Bug #:
Submitted by:
Reviewed by:
Implement some FIXME's that stand in the way of fully typechecking "for"
statements. This involved:

- Adding a DeclStmt AST node (with statement visitor). The DeclStmt
printer is preliminary.
- Added a ParseDeclStmt action, called from Parser::ParseForStatement()
and Parser::ParseStatementOrDeclaration(). DID NOT add to
Parser::ParseIdentifierStatement()...probably could have, however didn't
really understand the context of this rule (will speak with Chris).
- Removed ParseExprStmt (and it's clients)...it was vestigial.

llvm-svn: 39518
2007-05-29 22:59:26 +00:00
Steve Naroff 6f49f5df03 Bug #:
Submitted by:
Reviewed by:
- Finished Sema::ParseReturnStmt(). Still need to tweak ranges.
- Tweaked location for function arguments (they now point at the expression directly, no parens or commas).
- Added InvalidOperands helper...was sick of looking at the same 3 lines in ~9 Check functions.
- Added a few diags and moved a group of statement diags to the proper comment/category.

llvm-svn: 39517
2007-05-29 14:23:36 +00:00
Chris Lattner e64a1b5275 Fix two bugs that fell out from a testcase steve noticed. for this testcase:
extern int pintFunc(int *, int *);

int test() {
  pintFunc(0,
           3);
}

We now print:

t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
  pintFunc(0,
  ~~~~~~~~  ^

instead of:

t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
  pintFunc(0,
  ~~~~~~~~

llvm-svn: 39516
2007-05-29 05:53:15 +00:00
Steve Naroff 86272ea1fe Bug #:
Submitted by:
Reviewed by:
Implement type checking for ParseDoStmt, ParseWhileStmt, ParseIfStmt, and
ParseForStmt. ParseForStmt still under construction (contains a FIXME).

llvm-svn: 39515
2007-05-29 02:14:17 +00:00
Steve Naroff 3c87a57a2c Bug #:
Submitted by:
Reviewed by:
Add range support to Sema::CheckConditionalOperands().

llvm-svn: 39514
2007-05-28 19:40:22 +00:00
Steve Naroff 8563f65042 Bug #:
Submitted by:
Reviewed by:
Refine Sema::ParseCallExpr() diags (range support, add types).

Before:

func-assign.c:27:11: warning: passing argument 1 from incompatible pointer type
  pintFunc(&FOO);
          ^
func-assign.c:28:12: error: incompatible type for argument 1
  floatFunc(&FOO);
           ^
func-assign.c:29:12: error: too many arguments to function
  floatFunc(1,2,3);
           ^
After:

func-assign.c:27:11: warning: passing incompatible pointer 'struct foo *' to function expecting 'int *'
  pintFunc(&FOO);
  ~~~~~~~~^~~~~
func-assign.c:28:12: error: passing incompatible type 'struct foo *' to function expecting 'float'
  floatFunc(&FOO);
  ~~~~~~~~~^~~~~
func-assign.c:29:12: error: too many arguments to function
  floatFunc(1,2,3);
  ~~~~~~~~~^  ~

llvm-svn: 39513
2007-05-28 19:25:56 +00:00
Steve Naroff 758ada12f4 Bug #:
Submitted by:
Reviewed by:
- Implement FIXME in Sema::CheckIndirectionOperand().
- Added "const" to FunctionDecl::getResultType().

llvm-svn: 39512
2007-05-28 16:15:57 +00:00
Chris Lattner 010015a11e Add a note about an unimplemented gnu extension.
llvm-svn: 39511
2007-05-28 07:23:54 +00:00
Chris Lattner eefa10e78a implement full sema support for the GCC address-of-label extension.
llvm-svn: 39510
2007-05-28 06:56:27 +00:00
Chris Lattner e2473068d4 Change GotoStmt's to have a pointer to the LabelStmt instead of a pointer to
the label identifier.  Handle fwd references etc.  This allows us to detect
uses of undefined labels and label redefinitions, such as:

t.c:2:12: error: redefinition of label 'abc'
  abc: ;   abc:
           ^
t.c:2:3: error: previous definition is here
  abc: ;   abc:
  ^
t.c:12:12: error: use of undeclared label 'hijl'
      goto hijl;
           ^

llvm-svn: 39509
2007-05-28 06:28:18 +00:00
Chris Lattner ac4471c963 Improve the parsers resilience to sematic errors. This allows us to turn:
void foo() {
  if (0) break;
  abc:
  def:
  hij:
    break;

into:

void foo() {
  if ((0)')
    ;
abc:
def:
hij:
  ;

instead of dropping the if and labels (due to break not being in a loop).

llvm-svn: 39508
2007-05-28 05:38:24 +00:00
Chris Lattner 2f6ac263ef Null pointers in the ast are no longer considered to be the null stmt.
llvm-svn: 39507
2007-05-28 01:47:47 +00:00
Chris Lattner 0f203a7c1c add action for null stmt, create ast node.
llvm-svn: 39506
2007-05-28 01:45:28 +00:00
Chris Lattner 012a6cf1de add a NullStmt ast node.
llvm-svn: 39505
2007-05-28 01:41:58 +00:00
Chris Lattner bed314465a Reorganize codegen files.
llvm-svn: 39504
2007-05-28 01:07:47 +00:00
Chris Lattner 7a50aa98f0 Stop generating code after the first error is emitted.
llvm-svn: 39503
2007-05-28 00:47:06 +00:00
Chris Lattner c49b9051f4 track whether an error has been emitted.
llvm-svn: 39502
2007-05-28 00:46:44 +00:00
Steve Naroff 9358c715da Bug #:
Submitted by:
Reviewed by:
- Added type checking to Sema::ParseReturnStmt (still under construction).
- Improved Expr::isLvalue() and Expr::isModifiableLvalue() to return more
info. Used the info in Sema::CheckAssignmentOperands() to produce more
descriptive diagnostics. Added FIXME to other clients of isLvalue()/etc.
- Added a SourceLocation slot to MemberExpr...changed the implementation
of getSourceRange().
- Added getResultType() helper to FunctionDecl.
- Changed many Diag calls to use the SourceRange support (now that it's
a big hit...we better milk it:-).

llvm-svn: 39501
2007-05-27 23:58:33 +00:00
Bill Wendling c5fc5f197d Bug #:
Submitted by: Bill Wendling
Reviewed by:

- Can do just a 'cast<>()' because we're checking that it's Tagged.

llvm-svn: 39500
2007-05-27 23:36:18 +00:00
Bill Wendling 229f243f5f Bug #:
Submitted by: Bill Wendling
Reviewed by: Steve Naroff

- Steve suggested avoiding the dyn_cast by using the "Tagged" type class
  and having the "default" just return false.

llvm-svn: 39499
2007-05-27 23:31:02 +00:00
Bill Wendling 21862c3fbd Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Rework the isDerivedType method so that if a language doesn't support
  references, it won't have to pay the price for them. This inlines the
  checks for derived types and turns it into a switch statement instead.

llvm-svn: 39498
2007-05-27 22:46:14 +00:00
Bill Wendling 6811c0b5f3 Bug #:
Submitted by: Bill Wendling
Reviewed by:

C++ references testcase.

llvm-svn: 39497
2007-05-27 10:16:12 +00:00
Bill Wendling 3708c18559 Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Initial support for C++ references. Adding to the AST and Parser.
  Skeletal support added in the semantic analysis portion. Full semantic
  analysis is to be done soon.

llvm-svn: 39496
2007-05-27 10:15:43 +00:00