blob: 2596aab923fdd85be56e991935572f1d360dab15 [file] [log] [blame]
Ben Chengba4fc8b2009-06-01 13:00:29 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Dalvik.h"
18#include "CompilerInternals.h"
19
20/* Allocate a new basic block */
21BasicBlock *dvmCompilerNewBB(BBType blockType)
22{
23 BasicBlock *bb = dvmCompilerNew(sizeof(BasicBlock), true);
24 bb->blockType = blockType;
25 return bb;
26}
27
28/* Insert an MIR instruction to the end of a basic block */
29void dvmCompilerAppendMIR(BasicBlock *bb, MIR *mir)
30{
31 if (bb->firstMIRInsn == NULL) {
32 assert(bb->firstMIRInsn == NULL);
33 bb->lastMIRInsn = bb->firstMIRInsn = mir;
34 mir->prev = mir->next = NULL;
35 } else {
36 bb->lastMIRInsn->next = mir;
37 mir->prev = bb->lastMIRInsn;
38 mir->next = NULL;
39 bb->lastMIRInsn = mir;
40 }
41}
42
43/*
44 * Append an LIR instruction to the LIR list maintained by a compilation
45 * unit
46 */
47void dvmCompilerAppendLIR(CompilationUnit *cUnit, LIR *lir)
48{
49 if (cUnit->firstLIRInsn == NULL) {
50 assert(cUnit->lastLIRInsn == NULL);
51 cUnit->lastLIRInsn = cUnit->firstLIRInsn = lir;
52 lir->prev = lir->next = NULL;
53 } else {
54 cUnit->lastLIRInsn->next = lir;
55 lir->prev = cUnit->lastLIRInsn;
56 lir->next = NULL;
57 cUnit->lastLIRInsn = lir;
58 }
59}