mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-28 21:34:23 +00:00
Fix for PR1452. Removed "define" keyword from the C code. Added "<div
class="doc_code">" to code examples. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37335 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
848377d533
commit
2f7a8b091a
@ -252,9 +252,11 @@ LLVM assembly language. There is a difference between what the parser
|
|||||||
accepts and what is considered 'well formed'. For example, the
|
accepts and what is considered 'well formed'. For example, the
|
||||||
following instruction is syntactically okay, but not well formed:</p>
|
following instruction is syntactically okay, but not well formed:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
%x = <a href="#i_add">add</a> i32 1, %x
|
%x = <a href="#i_add">add</a> i32 1, %x
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>...because the definition of <tt>%x</tt> does not dominate all of
|
<p>...because the definition of <tt>%x</tt> does not dominate all of
|
||||||
its uses. The LLVM infrastructure provides a verification pass that may
|
its uses. The LLVM infrastructure provides a verification pass that may
|
||||||
@ -263,6 +265,7 @@ automatically run by the parser after parsing input assembly and by
|
|||||||
the optimizer before it outputs bytecode. The violations pointed out
|
the optimizer before it outputs bytecode. The violations pointed out
|
||||||
by the verifier pass indicate bugs in transformation passes or input to
|
by the verifier pass indicate bugs in transformation passes or input to
|
||||||
the parser.</p>
|
the parser.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Describe the typesetting conventions here. --> </div>
|
<!-- Describe the typesetting conventions here. --> </div>
|
||||||
|
|
||||||
@ -310,23 +313,29 @@ none of them start with a '%' character.</p>
|
|||||||
|
|
||||||
<p>The easy way:</p>
|
<p>The easy way:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
%result = <a href="#i_mul">mul</a> i32 %X, 8
|
%result = <a href="#i_mul">mul</a> i32 %X, 8
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>After strength reduction:</p>
|
<p>After strength reduction:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
%result = <a href="#i_shl">shl</a> i32 %X, i8 3
|
%result = <a href="#i_shl">shl</a> i32 %X, i8 3
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>And the hard way:</p>
|
<p>And the hard way:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
|
<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
|
||||||
<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
|
<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
|
||||||
%result = <a href="#i_add">add</a> i32 %1, %1
|
%result = <a href="#i_add">add</a> i32 %1, %1
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
|
<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
|
||||||
important lexical features of LLVM:</p>
|
important lexical features of LLVM:</p>
|
||||||
@ -367,6 +376,7 @@ combined together with the LLVM linker, which merges function (and
|
|||||||
global variable) definitions, resolves forward declarations, and merges
|
global variable) definitions, resolves forward declarations, and merges
|
||||||
symbol table entries. Here is an example of the "hello world" module:</p>
|
symbol table entries. Here is an example of the "hello world" module:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre><i>; Declare the string constant as a global constant...</i>
|
<pre><i>; Declare the string constant as a global constant...</i>
|
||||||
<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
|
<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
|
||||||
href="#globalvars">constant</a> <a href="#t_array">[13 x i8 ]</a> c"hello world\0A\00" <i>; [13 x i8 ]*</i>
|
href="#globalvars">constant</a> <a href="#t_array">[13 x i8 ]</a> c"hello world\0A\00" <i>; [13 x i8 ]*</i>
|
||||||
@ -384,7 +394,9 @@ define i32 %main() { <i>; i32()*
|
|||||||
<a
|
<a
|
||||||
href="#i_call">call</a> i32 %puts(i8 * %cast210) <i>; i32</i>
|
href="#i_call">call</a> i32 %puts(i8 * %cast210) <i>; i32</i>
|
||||||
<a
|
<a
|
||||||
href="#i_ret">ret</a> i32 0<br>}<br></pre>
|
href="#i_ret">ret</a> i32 0<br>}<br>
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>This example is made up of a <a href="#globalvars">global variable</a>
|
<p>This example is made up of a <a href="#globalvars">global variable</a>
|
||||||
named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
|
named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
|
||||||
@ -647,9 +659,11 @@ a power of 2.</p>
|
|||||||
<p>For example, the following defines a global with an initializer, section,
|
<p>For example, the following defines a global with an initializer, section,
|
||||||
and alignment:</p>
|
and alignment:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
%G = constant float 1.0, section "foo", align 4
|
%G = constant float 1.0, section "foo", align 4
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -719,9 +733,11 @@ a power of 2.</p>
|
|||||||
|
|
||||||
<h5>Syntax:</h5>
|
<h5>Syntax:</h5>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
@<Name> = [Linkage] [Visibility] alias <AliaseeTy> @<Aliasee>
|
@<Name> = [Linkage] [Visibility] alias <AliaseeTy> @<Aliasee>
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -739,9 +755,15 @@ a power of 2.</p>
|
|||||||
|
|
||||||
<p>Parameter attributes are simple keywords that follow the type specified. If
|
<p>Parameter attributes are simple keywords that follow the type specified. If
|
||||||
multiple parameter attributes are needed, they are space separated. For
|
multiple parameter attributes are needed, they are space separated. For
|
||||||
example:</p><pre>
|
example:</p>
|
||||||
%someFunc = i16 (i8 sext %someParam) zext
|
|
||||||
%someFunc = i16 (i8 zext %someParam) zext</pre>
|
<div class="doc_code">
|
||||||
|
<pre>
|
||||||
|
%someFunc = i16 (i8 sext %someParam) zext
|
||||||
|
%someFunc = i16 (i8 zext %someParam) zext
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>Note that the two function types above are unique because the parameter has
|
<p>Note that the two function types above are unique because the parameter has
|
||||||
a different attribute (sext in the first one, zext in the second). Also note
|
a different attribute (sext in the first one, zext in the second). Also note
|
||||||
that the attribute for the function result (zext) comes immediately after the
|
that the attribute for the function result (zext) comes immediately after the
|
||||||
@ -787,10 +809,12 @@ LLVM and treated as a single unit, but may be separated in the .ll file if
|
|||||||
desired. The syntax is very simple:
|
desired. The syntax is very simple:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="doc_code"><pre>
|
<div class="doc_code">
|
||||||
module asm "inline asm code goes here"
|
<pre>
|
||||||
module asm "more can go here"
|
module asm "inline asm code goes here"
|
||||||
</pre></div>
|
module asm "more can go here"
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>The strings can contain any character by escaping non-printable characters.
|
<p>The strings can contain any character by escaping non-printable characters.
|
||||||
The escape sequence used is simply "\xx" where "xx" is the two digit hex code
|
The escape sequence used is simply "\xx" where "xx" is the two digit hex code
|
||||||
@ -1015,6 +1039,7 @@ value.</p>
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- _______________________________________________________________________ -->
|
<!-- _______________________________________________________________________ -->
|
||||||
<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
|
<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
|
||||||
@ -1398,11 +1423,13 @@ href="#identifiers">identifier for the global</a> is used and always have <a
|
|||||||
href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
|
href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
|
||||||
file:</p>
|
file:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
%X = global i32 17
|
%X = global i32 17
|
||||||
%Y = global i32 42
|
%Y = global i32 42
|
||||||
%Z = global [2 x i32*] [ i32* %X, i32* %Y ]
|
%Z = global [2 x i32*] [ i32* %X, i32* %Y ]
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -1556,18 +1583,22 @@ indicates whether or not the inline asm expression has side effects. An example
|
|||||||
inline assembler expression is:
|
inline assembler expression is:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
i32 (i32) asm "bswap $0", "=r,r"
|
i32 (i32) asm "bswap $0", "=r,r"
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Inline assembler expressions may <b>only</b> be used as the callee operand of
|
Inline assembler expressions may <b>only</b> be used as the callee operand of
|
||||||
a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
|
a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
|
%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Inline asms with side effects not visible in the constraint list must be marked
|
Inline asms with side effects not visible in the constraint list must be marked
|
||||||
@ -1575,9 +1606,11 @@ as having side effects. This is done through the use of the
|
|||||||
'<tt>sideeffect</tt>' keyword, like so:
|
'<tt>sideeffect</tt>' keyword, like so:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
call void asm sideeffect "eieio", ""()
|
call void asm sideeffect "eieio", ""()
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>TODO: The format of the asm and constraints string still need to be
|
<p>TODO: The format of the asm and constraints string still need to be
|
||||||
documented here. Constraints on what can be done (e.g. duplication, moving, etc
|
documented here. Constraints on what can be done (e.g. duplication, moving, etc
|
||||||
@ -2663,8 +2696,8 @@ instructions), the memory is reclaimed.</p>
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
%ptr = alloca i32 <i>; yields {i32*}:ptr</i>
|
%ptr = alloca i32 <i>; yields {i32*}:ptr</i>
|
||||||
%ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
|
%ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
|
||||||
%ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
|
%ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
|
||||||
%ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
|
%ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
@ -2754,35 +2787,39 @@ be sign extended to 64-bit values.</p>
|
|||||||
<p>For example, let's consider a C code fragment and how it gets
|
<p>For example, let's consider a C code fragment and how it gets
|
||||||
compiled to LLVM:</p>
|
compiled to LLVM:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
struct RT {
|
struct RT {
|
||||||
char A;
|
char A;
|
||||||
i32 B[10][20];
|
i32 B[10][20];
|
||||||
char C;
|
char C;
|
||||||
};
|
};
|
||||||
struct ST {
|
struct ST {
|
||||||
i32 X;
|
i32 X;
|
||||||
double Y;
|
double Y;
|
||||||
struct RT Z;
|
struct RT Z;
|
||||||
};
|
};
|
||||||
|
|
||||||
define i32 *foo(struct ST *s) {
|
i32 *foo(struct ST *s) {
|
||||||
return &s[1].Z.B[5][13];
|
return &s[1].Z.B[5][13];
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>The LLVM code generated by the GCC frontend is:</p>
|
<p>The LLVM code generated by the GCC frontend is:</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
%RT = type { i8 , [10 x [20 x i32]], i8 }
|
%RT = type { i8 , [10 x [20 x i32]], i8 }
|
||||||
%ST = type { i32, double, %RT }
|
%ST = type { i32, double, %RT }
|
||||||
|
|
||||||
define i32* %foo(%ST* %s) {
|
define i32* %foo(%ST* %s) {
|
||||||
entry:
|
entry:
|
||||||
%reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
|
%reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
|
||||||
ret i32* %reg
|
ret i32* %reg
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h5>Semantics:</h5>
|
<h5>Semantics:</h5>
|
||||||
|
|
||||||
@ -3694,6 +3731,7 @@ the type used.</p>
|
|||||||
instruction and the variable argument handling intrinsic functions are
|
instruction and the variable argument handling intrinsic functions are
|
||||||
used.</p>
|
used.</p>
|
||||||
|
|
||||||
|
<div class="doc_code">
|
||||||
<pre>
|
<pre>
|
||||||
define i32 @test(i32 %X, ...) {
|
define i32 @test(i32 %X, ...) {
|
||||||
; Initialize variable argument processing
|
; Initialize variable argument processing
|
||||||
@ -3721,6 +3759,8 @@ declare void @llvm.va_end(i8*)
|
|||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- _______________________________________________________________________ -->
|
<!-- _______________________________________________________________________ -->
|
||||||
<div class="doc_subsubsection">
|
<div class="doc_subsubsection">
|
||||||
<a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
|
<a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user