]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/AssemblerDef.java
3 * Copyright 2001-2005 The Ant-Contrib project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package net
.sf
.antcontrib
.cpptasks
;
19 import java
.io
.BufferedReader
;
21 import java
.io
.FileReader
;
22 import java
.util
.Vector
;
24 import net
.sf
.antcontrib
.cpptasks
.compiler
.Assembler
;
25 import net
.sf
.antcontrib
.cpptasks
.compiler
.Processor
;
26 import net
.sf
.antcontrib
.cpptasks
.gcc
.GccAssembler
;
27 import net
.sf
.antcontrib
.cpptasks
.types
.AssemblerArgument
;
28 import net
.sf
.antcontrib
.cpptasks
.types
.ConditionalPath
;
29 import net
.sf
.antcontrib
.cpptasks
.types
.IncludePath
;
30 import net
.sf
.antcontrib
.cpptasks
.types
.SystemIncludePath
;
32 import org
.apache
.tools
.ant
.BuildException
;
33 import org
.apache
.tools
.ant
.Project
;
36 * A assembler definition. Assembler elements may be placed either as children
37 * of a cc element or the project element. A assembler element with an id
38 * attribute may be referenced from assembler elements with refid or extends
42 public final class AssemblerDef
extends ProcessorDef
{
44 private final Vector includePaths
= new Vector();
46 private final Vector sysIncludePaths
= new Vector();
48 private Boolean defaultflag
= new Boolean(true);
50 public AssemblerDef () {
54 * Adds a assembler command-line arg.
56 public void addConfiguredAssemblerArg(AssemblerArgument arg
) {
58 throw noChildrenAllowed();
60 addConfiguredProcessorArg(arg
);
64 * Creates an include path.
66 public IncludePath
createIncludePath() {
67 Project p
= getProject();
69 throw new java
.lang
.IllegalStateException("project must be set");
72 throw noChildrenAllowed();
74 IncludePath path
= new IncludePath(p
);
75 includePaths
.addElement(path
);
80 * Creates an include path.
82 public SystemIncludePath
createSysIncludePath() {
83 Project p
= getProject();
85 throw new java
.lang
.IllegalStateException("project must be set");
88 throw noChildrenAllowed();
90 SystemIncludePath path
= new SystemIncludePath(p
);
91 sysIncludePaths
.addElement(path
);
96 * Add a <includepath>or <sysincludepath> if specify the file attribute
98 * @throws BuildException
99 * if the specify file not exist
101 protected void loadFile(Vector activePath
, File file
) throws BuildException
{
102 FileReader fileReader
;
105 if (!file
.exists()) {
106 throw new BuildException("The file " + file
+ " is not existed");
109 fileReader
= new FileReader(file
);
110 in
= new BufferedReader(fileReader
);
111 while ((str
= in
.readLine()) != null) {
112 if (str
.trim() == "") {
115 str
= getProject().replaceProperties(str
);
116 activePath
.addElement(str
.trim());
118 } catch (Exception e
) {
119 throw new BuildException(e
.getMessage());
123 public void execute() throws org
.apache
.tools
.ant
.BuildException
{
124 throw new org
.apache
.tools
.ant
.BuildException(
125 "Not an actual task, but looks like one for documentation purposes");
129 * Returns the assembler-specific include path.
131 public String
[] getActiveIncludePaths() {
133 return ((AssemblerDef
) getCheckedRef(AssemblerDef
.class,
134 "AssemblerDef")).getActiveIncludePaths();
136 return getActivePaths(includePaths
);
140 * Returns the assembler-specific sysinclude path.
142 public String
[] getActiveSysIncludePaths() {
144 return ((AssemblerDef
) getCheckedRef(AssemblerDef
.class,
145 "AssemblerDef")).getActiveSysIncludePaths();
147 return getActivePaths(sysIncludePaths
);
150 private String
[] getActivePaths(Vector paths
) {
151 Project p
= getProject();
153 throw new java
.lang
.IllegalStateException("project not set");
155 Vector activePaths
= new Vector(paths
.size());
156 for (int i
= 0; i
< paths
.size(); i
++) {
157 ConditionalPath path
= (ConditionalPath
) paths
.elementAt(i
);
158 if (path
.isActive(p
)) {
159 if (path
.getFile() == null) {
160 String
[] pathEntries
= path
.list();
161 for (int j
= 0; j
< pathEntries
.length
; j
++) {
162 activePaths
.addElement(pathEntries
[j
]);
165 loadFile(activePaths
, path
.getFile());
169 String
[] pathNames
= new String
[activePaths
.size()];
170 activePaths
.copyInto(pathNames
);
174 public final Boolean
getDefaultflag(AssemblerDef
[] defaultProviders
,
177 return ((AssemblerDef
) getCheckedRef(AssemblerDef
.class,
178 "AssemblerDef")).getDefaultflag(defaultProviders
,
184 public Processor
getProcessor() {
185 Processor processor
= super.getProcessor();
186 if (processor
== null) {
187 processor
= GccAssembler
.getInstance();
195 * <table width="100%" border="1"> <thead>Supported assemblers</thead>
197 * <td>gcc (default)</td>
198 * <td>GAS assembler</td>
202 * <td>MASM assembler</td>
207 public void setName(AssemblerEnum name
) throws BuildException
{
209 throw tooManyAttributes();
211 Assembler assembler
= name
.getAssembler();
212 setProcessor(assembler
);
215 protected void setProcessor(Processor proc
) throws BuildException
{
217 super.setProcessor((Assembler
) proc
);
218 } catch (ClassCastException ex
) {
219 throw new BuildException(ex
);
224 * Enables or disables default flags.
227 * if true, default flags will add to command line.
230 public void setDefaultflag(boolean defaultflag
) {
232 throw tooManyAttributes();
234 this.defaultflag
= booleanValueOf(defaultflag
);