dart-sdk/runtime/vm/instructions_ia32.h
kmillikin@google.com 41e77a0a9e Initial implementation of a flow-graph builder for Dart's AST.
Visit the AST and generate an instruction (ie, not basic-block) flow
graph.

The flow graph for the simple function:

main() {
  var f = 1;
  var n = 5;
  while (n > 0) {
    f = f * n;
    n = n - 1;
  }
  print(f);
}

is:

       1: StoreLocal(f, #1)
       2: StoreLocal(n, #5)
       3: [join]
       4: t0 <-LoadLocal(n)
       5: t0 <-InstanceCall(>, t0, #0)
       6: if t0 goto(7, 15)
       7: [target]
       8: t0 <-LoadLocal(f)
       9: t1 <-LoadLocal(n)
      10: t0 <-InstanceCall(*, t0, t1)
      11: StoreLocal(f, t0)
      12: t0 <-LoadLocal(n)
      13: t0 <-InstanceCall(-, t0, #1)
      14: StoreLocal(n, t0) goto 3
      15: [target]
      16: t0 <-LoadLocal(f)
      17: StaticCall(print, t0)
      18: return #null

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9414003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4460 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-22 15:20:13 +00:00

100 lines
2.5 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Classes that describe assembly patterns as used by inline caches.
#ifndef VM_INSTRUCTIONS_IA32_H_
#define VM_INSTRUCTIONS_IA32_H_
#ifndef VM_INSTRUCTIONS_H_
#error Do not include instructions_ia32.h directly; use instructions.h instead.
#endif
#include "vm/allocation.h"
namespace dart {
// Forward declarations.
class RawClass;
class Immediate;
class RawObject;
// Abstract class for all instruction pattern classes.
class InstructionPattern : public ValueObject {
public:
explicit InstructionPattern(uword pc) : start_(pc) {
ASSERT(pc != 0);
}
virtual ~InstructionPattern() {}
// Call to check if the instruction pattern at 'pc' match the instruction.
virtual bool IsValid() const {
return TestBytesWith(pattern(), pattern_length_in_bytes());
}
// 'pattern' returns the expected byte pattern in form of an integer array
// with length of 'pattern_length_in_bytes'. A '-1' element means 'any byte'.
virtual const int* pattern() const = 0;
virtual int pattern_length_in_bytes() const = 0;
protected:
uword start() const { return start_; }
private:
// Returns true if the 'num_bytes' bytes at 'start_' correspond to
// array of integers 'data'. 'data' elements are either a byte or -1, which
// represents any byte.
bool TestBytesWith(const int* data, int num_bytes) const;
const uword start_;
DISALLOW_COPY_AND_ASSIGN(InstructionPattern);
};
class CallOrJumpPattern : public InstructionPattern {
public:
virtual int pattern_length_in_bytes() const {
return kLengthInBytes;
}
uword TargetAddress() const;
void SetTargetAddress(uword new_target) const;
protected:
explicit CallOrJumpPattern(uword pc) : InstructionPattern(pc) {}
static const int kLengthInBytes = 5;
private:
DISALLOW_COPY_AND_ASSIGN(CallOrJumpPattern);
};
class CallPattern : public CallOrJumpPattern {
public:
explicit CallPattern(uword pc) : CallOrJumpPattern(pc) {}
static int InstructionLength() {
return kLengthInBytes;
}
private:
virtual const int* pattern() const;
DISALLOW_COPY_AND_ASSIGN(CallPattern);
};
class JumpPattern : public CallOrJumpPattern {
public:
explicit JumpPattern(uword pc) : CallOrJumpPattern(pc) {}
private:
virtual const int* pattern() const;
DISALLOW_COPY_AND_ASSIGN(JumpPattern);
};
} // namespace dart
#endif // VM_INSTRUCTIONS_IA32_H_